eb4d4de672d90702bf2aaa0a1433e0e27cd282b9.svn-base 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. package UIB.UIB03;
  2. import java.io.ByteArrayInputStream;
  3. import java.io.ByteArrayOutputStream;
  4. import java.io.File;
  5. import java.io.InputStream;
  6. import java.sql.Connection;
  7. import java.sql.DriverManager;
  8. import java.sql.PreparedStatement;
  9. import java.sql.ResultSet;
  10. import java.sql.SQLException;
  11. import java.util.ArrayList;
  12. import java.util.List;
  13. import java.util.Iterator;
  14. import java.util.HashMap;
  15. import java.util.Set;
  16. import java.util.HashSet;
  17. import java.util.Map;
  18. import org.springframework.jdbc.support.rowset.SqlRowSet;
  19. import UIB.COM.ComDBProcedure;
  20. import UIB.COM.XmlSqlParsersFactory;
  21. import UIB.UIB03.ZBS.DataRowList;
  22. import UIB.UIB03.ZBS.IQltyGuaranteeEngine;
  23. import UIB.UIB03.ZBS.QltyCodeDef;
  24. import UIB.UIB03.ZBS.QltyGuaranteeEngine;
  25. import UIB.UIB03.ZBS.RowSetConverter;
  26. import UIB.UIB03.ZBS.MapConverter;
  27. import CoreFS.SA01.CoreIComponent;
  28. import CoreFS.SA06.CoreReturnObject;
  29. /**
  30. * @desc 质保书发行主要包含质保书引擎、质保书构造器、字段标准定义,以及所衍生的行对象数据结构、行对象转换器、质保书行列转换、EXCEL风格设置器
  31. * 质保书引擎:获取模板以及填充模板方式
  32. * 质保书构造器: 按照不同类型模板进行填充
  33. * 字段标准定义:对质保书中所需要的字段名,特殊文字及符号等进行定义
  34. * 行对象数据结构:将查询出来的行对象转换为指定类型
  35. * 行对象转换器:将查询出来的RowSet集合按照不同的钢卷号(包号)进行转换
  36. * 质保书行列转换:质保书上的A、AB行列等转换为与jxl对应的行或者列
  37. * EXCEL风格设置器:质保书可否读写、修改,以及单元格的颜色、字体大小、自动换行、自动缩小字体等属性设置
  38. * @author meiguiping
  39. * @date 2010 9:23:12 PM
  40. */
  41. public class UIB030320 extends CoreIComponent
  42. {
  43. /**
  44. * @desc 质保打印次数
  45. * @param tmplNo 模板号
  46. * @param cretNo 质保书编号
  47. * @return
  48. */
  49. public CoreReturnObject PrintCnt(String print_ID, String cretNo)
  50. {
  51. CoreReturnObject cro = new CoreReturnObject();
  52. Connection con = this.getDao("KgDao").getConnection();
  53. String printCnt = null;
  54. try
  55. {
  56. printCnt = "UIB030320_ZBS_02.UPDATES";
  57. cro = this.getDao("KgDao").ExcuteNonQuery(XmlSqlParsersFactory.getSql(printCnt) , new Object[]{print_ID ,cretNo });//次数
  58. }
  59. catch(Exception ex)
  60. {
  61. ex.printStackTrace();
  62. }
  63. return cro;
  64. }
  65. /**
  66. * @desc 质保书发行预览
  67. * @param tmplNo 模板号
  68. * @param cretNo 质保书编号
  69. * @param prodLine 产线
  70. * @parm language 语种
  71. * @return
  72. * @throws SQLException
  73. */
  74. public CoreReturnObject downLoad(String tmplNo , String cretNo , String prodLine , String invNo, String sendTP) throws SQLException
  75. {
  76. CoreReturnObject cro = new CoreReturnObject();
  77. Connection con = this.getDao("KgDao").getConnection();
  78. PreparedStatement pstm = null;
  79. SqlRowSet srs = null;
  80. String headSQL = null;//表头
  81. String chemSQL = null;//成分
  82. String qltySQL = null;//性能
  83. //String printCnt = null;//次数
  84. try
  85. {
  86. if("热轧".equals(prodLine.trim()))
  87. {
  88. headSQL = "UIB030320_HOST_HEAD.SELECT";
  89. chemSQL = "UIB030320_HOST_CHEM.SELECT";
  90. qltySQL = "UIB030320_HOST_QLTY.SELECT";
  91. }
  92. else if("开平".equals(prodLine.trim()))
  93. {
  94. headSQL = "UIB030320_BANJIA_HEAD.SELECT";
  95. if("KF".equals(invNo.substring(0,2)))
  96. {
  97. chemSQL = "UIB030320_BANJIA_CHEM_KF.SELECT";
  98. qltySQL = "UIB030320_BANJIA_QLTY_KF.SELECT";
  99. }
  100. else
  101. {
  102. chemSQL = "UIB030320_BANJIA_CHEM.SELECT";
  103. qltySQL = "UIB030320_BANJIA_QLTY.SELECT";
  104. }
  105. }
  106. else if("酸轧".equals(prodLine.trim()))
  107. {
  108. headSQL = "UIB030320_SUAN_HEAD.SELECT";
  109. chemSQL = "UIB030320_SUAN_CHEM.SELECT";
  110. qltySQL = "UIB030320_SUAN_QLTY.SELECT";
  111. //printCnt = "UIB030320_ZBS_02.UPDATES";
  112. }
  113. else if("连退".equals(prodLine.trim()))
  114. {
  115. headSQL = "UIB030320_LIAN_HEAD.SELECT";
  116. chemSQL = "UIB030320_LIAN_CHEM.SELECT";
  117. qltySQL = "UIB030320_LIAN_QLTY.SELECT";
  118. //printCnt = "UIB030320_ZBS_02.UPDATES";
  119. }
  120. else if("板加(非)".equals(prodLine.trim()))
  121. {
  122. headSQL = "UIB030320_HOTBJ_HEAD.SELECT";
  123. chemSQL = "UIB030320_HOTBJ_CHEM.SELECT";
  124. qltySQL = "UIB030320_HOTBJ_QLTY.SELECT";
  125. //printCnt = "UIB030320_ZBS_02.UPDATES";
  126. }
  127. //1、获取查询数据,转换为指定数据类型
  128. ///表头
  129. RowSetConverter rsc = new RowSetConverter();
  130. MapConverter mc = new MapConverter();
  131. cro = this.getDao("KgDao").ExecutequeryForRowSet(XmlSqlParsersFactory.getSql(headSQL) , new Object[]{cretNo });//表头
  132. srs = (SqlRowSet)cro.getResult();
  133. HashMap map = rsc.getHeadMap(srs);
  134. ///成分
  135. cro = this.getDao("KgDao").ExecutequeryForRowSet(XmlSqlParsersFactory.getSql(chemSQL) , new Object[]{cretNo} );//成分
  136. List list = this.getDao("KgDao").ExcuteQueryReturnList(XmlSqlParsersFactory.getSql(chemSQL) , new Object[]{cretNo} );//成分
  137. //srs = (SqlRowSet)set;
  138. srs = (SqlRowSet)cro.getResult();
  139. ArrayList chemAl= rsc.getDataRowList(srs, QltyCodeDef.CHEM_CD);
  140. //ArrayList chemAl= mc.getDataRowList(list, QltyCodeDef.CHEM_CD);
  141. int chemLen = chemAl.size();
  142. DataRowList[] chemList = new DataRowList[chemLen];
  143. for(int i = 0; i < chemLen; i++)
  144. {
  145. chemList[i] = (DataRowList)chemAl.get(i);
  146. }
  147. if(chemList.length == 0) {
  148. chemList = null;
  149. //cro.setV_errMsg("质保书异常:\n缺少成分信息,可能是材质判定不合格或者综合判定不合格!");
  150. cro.setV_errCode(5);
  151. cro.setResult("质保书异常:\n缺少成分信息,可能是材质判定不合格或者综合判定不合格!");
  152. return cro;
  153. }
  154. ///材质
  155. cro = this.getDao("KgDao").ExecutequeryForRowSet(XmlSqlParsersFactory.getSql(qltySQL) , new Object[]{cretNo});//材质
  156. srs = (SqlRowSet)cro.getResult();
  157. ArrayList qltyAl= rsc.getDataRowList(srs , QltyCodeDef.QLTY_CD);
  158. int qltyLen = qltyAl.size();
  159. DataRowList[] qltyList = new DataRowList[qltyLen];
  160. for(int i = 0; i < qltyLen; i++)
  161. {
  162. qltyList[i] = (DataRowList)qltyAl.get(i);
  163. }
  164. ///2、获取模板,转换为输入流
  165. pstm = con.prepareStatement(XmlSqlParsersFactory.getSql("UIB030310_03.SELECT"));
  166. pstm.setString(1, tmplNo);
  167. /*
  168. Connection con1 = dbso.getDataSource2().getConnection();
  169. String sql = "SELECT TMPL_EXCEL FROM tbb03_grte_tmpl WHERE tmpl_no='B00001'";
  170. pstm = con1.prepareStatement(sql); */
  171. ResultSet rs = pstm.executeQuery();
  172. if(rs.next())
  173. {
  174. //java.sql.Blob blob = rs.getBlob("TMPL_EXCEL");
  175. //oracle.sql.BLOB blob = (oracle.sql.BLOB)rs.getBlob("TMPL_EXCEL");
  176. //InputStream is = blob.getBinaryStream();
  177. //InputStream is = new ByteArrayInputStream(blob.getBytes(1 , (int)blob.length()));
  178. InputStream is = new ByteArrayInputStream(this.dbproxy.getLobHandler().getBlobAsBytes(rs , "TMPL_EXCEL"));
  179. ///3、调用引擎,返回输出流,生成质保书
  180. IQltyGuaranteeEngine engine = new QltyGuaranteeEngine(tmplNo , map , chemList , qltyList);
  181. ByteArrayOutputStream baos = (ByteArrayOutputStream)engine.getOutputStream(is);
  182. ///发送质保书到外网
  183. if("SEND".equals(sendTP))
  184. {
  185. sendWWW(cretNo ,prodLine , baos);
  186. }
  187. baos.close();
  188. is.close();
  189. rs.close();
  190. //注意,必须关闭流后才能从内存中获取字节流,否则获取到的会为0字节
  191. // System.out.println("##############################################");
  192. cro = new CoreReturnObject();
  193. cro.setResult(baos.toByteArray());
  194. // cro.setResult("dd");
  195. //删除二维码图片
  196. if(map.get("cdPath") != null){
  197. File file = new File(map.get("cdPath").toString());
  198. file.delete();
  199. }
  200. }
  201. pstm.close();
  202. con.close();
  203. //cro = this.getDao("KgDao").ExcuteNonQuery(XmlSqlParsersFactory.getSql(printCnt) , new Object[]{cretNo });//次数+1
  204. }
  205. catch(Exception ex)
  206. {
  207. cro.setV_errMsg("质保书异常:\n"+ex.getMessage());
  208. ex.printStackTrace();
  209. } finally {
  210. try{
  211. //添加了最终关闭连接
  212. if (pstm != null) {
  213. pstm.close();
  214. }
  215. if (con != null && !con.isClosed()) {
  216. con.close();
  217. }
  218. } catch (Exception e) {
  219. }
  220. }
  221. return cro;
  222. }//downLoad end
  223. /**
  224. * @desc 质保书审核,区分板加、热轧(冷轧)
  225. * @param prodLine 产线区分
  226. * @parm cretNO 质保书号
  227. * @param checkTp 审核或者取消审核
  228. * @param regNm 操作人
  229. * @return
  230. */
  231. public CoreReturnObject ZBSCheckTP(String prodLine , ArrayList cretNO , String checkTp , String regNm )throws Exception
  232. {
  233. CoreReturnObject cro = new CoreReturnObject();
  234. //质保书审核
  235. if(cretNO != null)
  236. {
  237. String sql = "";
  238. if("热轧".equals(prodLine.trim()) || "酸轧".equals(prodLine.trim()) || "连退".equals(prodLine.trim()) || "板加(非)".equals(prodLine.trim()))//热轧,冷轧,板加(非)
  239. {
  240. sql = "UIB030320_01.CALL";
  241. }
  242. else if("开平".equals(prodLine.trim()))
  243. {
  244. sql = "UIB030320_02.CALL";
  245. }
  246. ZBSCheck(cretNO , checkTp , regNm , sql);
  247. }
  248. return cro;
  249. }
  250. /**
  251. * @desc 质保书审核
  252. * @param cretNO 质保书号
  253. * @param checkTp 审核或者取消审核
  254. * @param regNm 操作人
  255. */
  256. public void ZBSCheck(ArrayList cretNO , String checkTp , String regNm , String sql) throws Exception
  257. {
  258. ComDBProcedure cdbp = new ComDBProcedure();
  259. HashMap map = null;
  260. for(int i = 0; i < cretNO.size(); i++)
  261. {
  262. map = new HashMap();
  263. map.put("i1", cretNO.get(i));
  264. map.put("i2", checkTp);
  265. map.put("i3", regNm);
  266. map.put("o4", "");
  267. cdbp.doXmlProcedure(sql, map);
  268. }
  269. }
  270. /**
  271. * @desc 热轧(冷轧)、板加,发送质保书到外网
  272. * @param cretNO 质保书号
  273. * @param baos 质保书输入流
  274. */
  275. public void sendWWW(String cretNO , String prodLine ,ByteArrayOutputStream baos) throws Exception
  276. {
  277. ///增加信息到ZL_ZBS_DETAIL_DATA和ZL_ZBS_MAIN_DATA表
  278. ComDBProcedure cdbp = new ComDBProcedure();
  279. HashMap map = map = new HashMap();
  280. String sqlID = "";
  281. if("热轧".equals(prodLine) || "酸轧".equals(prodLine)|| "连退".equals(prodLine) || "板加(非)".equals(prodLine))
  282. {
  283. sqlID = "UIB030320_HOST_01.CALL";
  284. }
  285. else if("开平".equals(prodLine))
  286. {
  287. sqlID = "UIB030320_BANJA_02.CALL";
  288. }
  289. else
  290. return;
  291. //填入其它信息
  292. map.put("i1", cretNO);
  293. map.put("o2", "");
  294. cdbp.doXmlProcedure(sqlID, map);
  295. ///添加质保书EXCEL信息
  296. Connection con = null;
  297. PreparedStatement pstm = null;
  298. try
  299. {
  300. // con = this.getDao("KgDao").getConnection();
  301. String driverClassName = "oracle.jdbc.driver.OracleDriver";
  302. Class.forName(driverClassName);
  303. //连接数据库
  304. String url = "jdbc:oracle:thin:@172.16.0.109:1521:mestest";
  305. String userName = "xsuser";
  306. String userPsw = "xsuser";
  307. // this.getDao("KgDao").ExceuteNonQueryForBlobList(XmlSqlParsersFactory.getSql("UIB030320_ZBS_01.UPDATES") , new Object[]{bData,tmplNo });
  308. con = DriverManager.getConnection(url , userName , userPsw);
  309. con.setAutoCommit(false);
  310. //
  311. // //填入质保书EXCEL
  312. pstm = con.prepareStatement(XmlSqlParsersFactory.getSql("UIB030320_ZBS_01.UPDATES"));
  313. this.dbproxy.getLobHandler().getLobCreator().setBlobAsBytes(pstm, 1, baos.toByteArray());
  314. pstm.setString(2, cretNO);
  315. pstm.executeUpdate();
  316. // pstm.setString(1, cretNO);
  317. // ResultSet rs = pstm.executeQuery();
  318. //
  319. // if(rs.next())
  320. // {
  321. // oracle.sql.BLOB blob = (oracle.sql.BLOB)rs.getBlob("ZBSXLS");
  322. // OutputStream os = blob.getBinaryOutputStream();
  323. //
  324. // InputStream is = new ByteArrayInputStream(baos.toByteArray());
  325. //
  326. // byte[] bb = new byte[blob.getBufferSize()];
  327. // int len = 0;
  328. // while((len = is.read(bb)) != -1)
  329. // {
  330. // os.write(bb , 0 , len);
  331. // }
  332. //
  333. // is.close();
  334. // os.flush();
  335. // os.close();
  336. con.commit();
  337. // }
  338. // rs.close();
  339. }catch(Exception ex)
  340. {
  341. //2015-09-23 添加:若质保书内容发送到外网失败,则修改质保书为未发送 状态
  342. String sql5 = XmlSqlParsersFactory.getSql("UIB030320_ZBS_05.UPDATES");
  343. this.getDao("KgDao").ExcuteNonQuery(sql5, new Object[]{cretNO});
  344. throw new Exception("质保书发送异常,请重新发送!\n"+ex.getMessage());
  345. // ex.printStackTrace();
  346. }
  347. finally
  348. {
  349. try
  350. {
  351. if(pstm != null)
  352. pstm.close();
  353. if(con !=null)
  354. con.close();
  355. }catch(Exception e)
  356. {
  357. throw new Exception("数据库连接关闭异常!\n"+e.getMessage());
  358. }
  359. }
  360. }//sendWWW end
  361. }