cf1b11d868df865a218f486d534325b0953df450.svn-base 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. package UIM;
  2. import java.io.StringWriter;
  3. import java.sql.Connection;
  4. import java.sql.PreparedStatement;
  5. import java.sql.ResultSet;
  6. import java.sql.SQLException;
  7. import java.util.ArrayList;
  8. import java.util.List;
  9. import javax.xml.parsers.DocumentBuilder;
  10. import javax.xml.parsers.DocumentBuilderFactory;
  11. import javax.xml.parsers.ParserConfigurationException;
  12. import javax.xml.transform.OutputKeys;
  13. import javax.xml.transform.Transformer;
  14. import javax.xml.transform.TransformerException;
  15. import javax.xml.transform.TransformerFactory;
  16. import javax.xml.transform.dom.DOMSource;
  17. import javax.xml.transform.stream.StreamResult;
  18. import org.w3c.dom.Document;
  19. import org.w3c.dom.Element;
  20. import UIB.COM.XmlSqlParsersFactory;
  21. import UIM.UIM01.BEANS.YardArea;
  22. import CoreFS.SA01.CoreIComponent;
  23. import CoreFS.SA06.CoreReturnObject;
  24. /**
  25. * 冷轧原料库库存现况查询
  26. *
  27. * @author siy
  28. * @date 2010-09-02
  29. */
  30. public class UIM010070 extends CoreIComponent {
  31. /**
  32. * 查询库存区域信息
  33. *
  34. * @param areaType
  35. * @return
  36. * @throws SQLException
  37. */
  38. public CoreReturnObject queryYardArea(Integer areaType) throws SQLException {
  39. CoreReturnObject cro = new CoreReturnObject();
  40. // 查询区域信息
  41. String sql = XmlSqlParsersFactory.getSql("UIM010070_01.SELECT");
  42. PreparedStatement prepStat = this.getDao("KgDao").getPreparedStatement(
  43. sql);
  44. prepStat.setInt(1, areaType.intValue());
  45. ResultSet rs = prepStat.executeQuery();
  46. List<YardArea> list = new ArrayList<YardArea>();
  47. YardArea area = null;
  48. while (rs.next()) {
  49. area = new YardArea();
  50. area.setAreaNo(rs.getLong("area_no"));
  51. area.setAreaName(rs.getString("area_name"));
  52. // 查询区域下列信息
  53. StringBuffer sqlBuffer2 = new StringBuffer();
  54. sqlBuffer2
  55. .append("select distinct(y.clf_name||'-'||trim(to_char(y.clf_col,'00')))||'_'||y.area_no clf_name\n");
  56. sqlBuffer2.append(" from c_tbk08_coil_yard y\n");
  57. sqlBuffer2.append(" where area_no = ? order by clf_name\n");
  58. PreparedStatement prepStat2 = this.getDao("KgDao")
  59. .getPreparedStatement(sqlBuffer2.toString());
  60. prepStat2.setLong(1, area.getAreaNo());
  61. ResultSet rs2 = prepStat2.executeQuery();
  62. List<String> cols = new ArrayList<String>();
  63. while (rs2.next()) {
  64. cols.add(rs2.getString("clf_name"));
  65. }
  66. area.setYardCols(cols.toArray());
  67. rs2.close();
  68. Connection con2 = prepStat2.getConnection();
  69. prepStat2.close();
  70. con2.close();
  71. list.add(area);
  72. }
  73. rs.close();
  74. Connection con = prepStat.getConnection();
  75. prepStat.close();
  76. con.close();
  77. String xmlStr = areaToXMLString(list);
  78. cro.setResult(xmlStr);
  79. return cro;
  80. }
  81. /**
  82. * 区域列信息转换成XML字符串
  83. *
  84. * @param list
  85. * @return
  86. */
  87. private String areaToXMLString(List<YardArea> list) {
  88. String xmlStr = null;
  89. if (null != list && 0 < list.size()) {
  90. try {
  91. DocumentBuilderFactory dbf = DocumentBuilderFactory
  92. .newInstance();
  93. DocumentBuilder db = dbf.newDocumentBuilder();
  94. Document doc = db.newDocument();
  95. Element root = doc.createElement("areas");
  96. doc.appendChild(root);
  97. for (int i = 0; i < list.size(); i++) {
  98. YardArea area = list.get(i);
  99. Element areaEle = doc.createElement("area");
  100. areaEle
  101. .setAttribute("id", String
  102. .valueOf(area.getAreaNo()));
  103. areaEle.setAttribute("name", area.getAreaName());
  104. root.appendChild(areaEle);
  105. Object[] cols = area.getYardCols();
  106. if (null != cols) {
  107. for (int j = 0; j < cols.length; j++) {
  108. Element colElement = doc.createElement("col");
  109. colElement.setAttribute("name", cols[j].toString());
  110. areaEle.appendChild(colElement);
  111. }
  112. }
  113. }
  114. TransformerFactory transFactory = TransformerFactory
  115. .newInstance();
  116. Transformer transFormer = transFactory.newTransformer();
  117. transFormer.setOutputProperty(OutputKeys.ENCODING, "GB2312");
  118. DOMSource domSource = new DOMSource(doc);
  119. StringWriter sw = new StringWriter();
  120. StreamResult xmlResult = new StreamResult(sw);
  121. transFormer.transform(domSource, xmlResult);
  122. xmlStr = sw.toString();
  123. } catch (ParserConfigurationException e) {
  124. // TODO Auto-generated catch block
  125. e.printStackTrace();
  126. } catch (TransformerException te) {
  127. te.printStackTrace();
  128. }
  129. }
  130. return xmlStr;
  131. }
  132. /**
  133. * 查询每列垛位数及钢卷数
  134. *
  135. * @param areaType
  136. * @return
  137. * @throws SQLException
  138. */
  139. public CoreReturnObject queryColCoils(Integer areaType) throws SQLException {
  140. CoreReturnObject cro = new CoreReturnObject();
  141. StringBuffer sqlBuffer = new StringBuffer();
  142. sqlBuffer
  143. .append("select y.clf_name||'-'||trim(to_char(y.clf_col,'00'))||'_'||y.area_no col_name,\n");
  144. sqlBuffer
  145. .append(" count(y.area_no)||'_('||count(y.coil_no)||')' col_count\n");
  146. sqlBuffer
  147. .append(" from c_tbk08_coil_yard y,c_tbk08_coil_yard_area a\n");
  148. sqlBuffer.append(" where y.area_no = a.area_no and a.area_type = ?\n");
  149. sqlBuffer.append(" group by y.clf_name,y.clf_col,y.area_no\n");
  150. cro = this.getDao("KgDao").ExcuteQuery(sqlBuffer.toString(),
  151. new Object[] { areaType.intValue() });
  152. return cro;
  153. }
  154. /**
  155. * 查询钢卷总数及综合判定总数
  156. *
  157. * @param areaType
  158. * @return
  159. * @throws SQLException
  160. */
  161. public CoreReturnObject queryCoilCount(Integer areaType)
  162. throws SQLException {
  163. CoreReturnObject cro = new CoreReturnObject();
  164. StringBuffer sqlBuffer = new StringBuffer();
  165. sqlBuffer.append("select count(y.coil_no) coil_count,\n");
  166. sqlBuffer.append(" count(k.tot_dec_grd) tot_count from\n");
  167. sqlBuffer.append(" c_tbk08_coil_yard y, c_tbk02_coil_comm k,\n");
  168. sqlBuffer.append(" c_tbk08_coil_yard_area a\n");
  169. sqlBuffer.append(" where y.coil_no = k.coil_no\n");
  170. sqlBuffer.append(" and y.area_no = a.area_no\n");
  171. sqlBuffer.append(" and a.area_type = ?\n");
  172. cro = this.getDao("KgDao").ExcuteQuery(sqlBuffer.toString(),
  173. new Object[] { areaType.intValue() });
  174. return cro;
  175. }
  176. public CoreReturnObject queryYardRows(Integer areaType, Integer areaNo,
  177. String coilCol) {
  178. CoreReturnObject cro = new CoreReturnObject();
  179. StringBuffer sqlBuffer = new StringBuffer();
  180. sqlBuffer
  181. .append("select y.clf_no,y.clf_name,y.clf_col,clf_row,y.clf_fl from\n");
  182. sqlBuffer.append(" c_tbk08_coil_yard y,c_tbk08_coil_yard_area a\n");
  183. sqlBuffer.append(" where y.area_no = a.area_no\n");
  184. sqlBuffer.append(" and a.area_type = ?\n");
  185. sqlBuffer.append(" and a.area_no = ?\n");
  186. sqlBuffer
  187. .append(" and y.clf_name||'-'||trim(to_char(y.clf_col,'00'))= ?\n");
  188. cro = this.getDao("KgDao")
  189. .ExcuteQuery(
  190. sqlBuffer.toString(),
  191. new Object[] { areaType.intValue(), areaNo.intValue(),
  192. coilCol });
  193. return cro;
  194. }
  195. /**
  196. * 查询区域下一行的垛位中钢卷信息
  197. *
  198. * @param areaType
  199. * @param coilCol
  200. * @return
  201. */
  202. public CoreReturnObject queryYardRowCoils(Integer areaType, Integer areaNo,
  203. String coilCol) {
  204. CoreReturnObject cro = new CoreReturnObject();
  205. StringBuffer sqlBuffer = new StringBuffer();
  206. sqlBuffer.append("select y.clf_row,y.clf_fl,k.cur_load_loc, --位置\n");
  207. sqlBuffer.append(" k.coil_no,k.stl_grd,\n");
  208. sqlBuffer.append(" k.coil_outdia,k.coil_india,--外径,内径\n");
  209. sqlBuffer
  210. .append(" k.instr_coil_thk||'*'||k.instr_coil_wth it_iw,--订单规格\n");
  211. sqlBuffer.append(" k.coil_thk||'*'||k.coil_wth t_w,--实际规格\n");
  212. sqlBuffer.append(" k.act_wgt,k.devlmt_dtime,\n");
  213. sqlBuffer.append(" k.ord_no,k.ord_seq,\n");
  214. sqlBuffer
  215. .append(" decode(k.tot_dec_grd,'1','合格','2','不合格','3','次品','4','废品') tot_dec_grd,\n");
  216. sqlBuffer.append(" decode(k.ord_fl,'1','订单材','2','余材') ord_fl\n");
  217. sqlBuffer.append(" from c_tbk08_coil_yard y,\n");
  218. sqlBuffer.append(" c_tbk02_coil_comm k,\n");
  219. sqlBuffer.append(" c_tbk08_coil_yard_area a\n");
  220. sqlBuffer.append(" where y.coil_no = k.coil_no\n");
  221. sqlBuffer.append(" and y.area_no = a.area_no\n");
  222. sqlBuffer.append(" and a.area_type = ?\n");
  223. sqlBuffer.append(" and a.area_no = ?\n");
  224. sqlBuffer
  225. .append(" and y.clf_name||'-'||trim(to_char(y.clf_col,'00')) = ?\n");
  226. cro = this.getDao("KgDao")
  227. .ExcuteQuery(
  228. sqlBuffer.toString(),
  229. new Object[] { areaType.intValue(), areaNo.intValue(),
  230. coilCol });
  231. return cro;
  232. }
  233. /**
  234. * 查询一行中编号最小的列
  235. *
  236. * @param areaType
  237. * @param areaNo
  238. * @param coilCol
  239. * @return
  240. * @throws SQLException
  241. */
  242. public CoreReturnObject queryMinYardRow(Integer areaType, Integer areaNo,
  243. String coilCol) throws SQLException {
  244. CoreReturnObject cro = new CoreReturnObject();
  245. StringBuffer sqlBuffer = new StringBuffer();
  246. sqlBuffer.append("select min(clf_row) clf_row from\n");
  247. sqlBuffer.append(" c_tbk08_coil_yard y,c_tbk08_coil_yard_area a\n");
  248. sqlBuffer.append(" where y.area_no = a.area_no\n");
  249. sqlBuffer.append(" and a.area_type = ?\n");
  250. sqlBuffer.append(" and a.area_no = ?\n");
  251. sqlBuffer
  252. .append(" and y.clf_name||'-'||trim(to_char(y.clf_col,'00'))= ?\n");
  253. PreparedStatement pSta = this.getDao("KgDao").getPreparedStatement(
  254. sqlBuffer.toString());
  255. pSta.setInt(1, areaType.intValue());
  256. pSta.setInt(2, areaNo.intValue());
  257. pSta.setString(3, coilCol);
  258. ResultSet rs = pSta.executeQuery();
  259. int minRow = 1;
  260. if (rs.next()) {
  261. minRow = rs.getInt("CLF_ROW");
  262. }
  263. cro.setResult(minRow);
  264. rs.close();
  265. Connection con = pSta.getConnection();
  266. pSta.close();
  267. con.close();
  268. return cro;
  269. }
  270. }