97a26fbfac09ec0924bc418236cdab94bf58a16e.svn-base 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. package xin.glue.ui.B;
  2. import java.io.BufferedInputStream;
  3. import java.io.ByteArrayOutputStream;
  4. import java.io.IOException;
  5. import java.io.InputStream;
  6. import java.sql.Connection;
  7. import java.sql.DriverManager;
  8. import java.sql.PreparedStatement;
  9. import java.util.ArrayList;
  10. import java.util.List;
  11. import java.util.zip.GZIPInputStream;
  12. import javax.servlet.http.HttpServletRequest;
  13. import xin.glue.ui.B.B02.MutilConditionFind;
  14. import xin.glue.ui.common.PosDBEngine;
  15. import xin.glue.ui.common.blob.PosExcelInterface;
  16. import com.posdata.glue.PosException;
  17. import com.posdata.glue.biz.constants.PosBizControlConstants;
  18. import com.posdata.glue.biz.control.PosBizProvider;
  19. import com.posdata.glue.context.PosContext;
  20. import com.posdata.glue.dao.vo.PosParameter;
  21. import com.posdata.glue.dao.vo.PosRow;
  22. import com.posdata.glue.dao.vo.PosRowSet;
  23. public class PosCertSave extends PosDBEngine {
  24. /*
  25. * 传入参数:
  26. * TMPL_NM - 模板名
  27. * 数据传入字段参数:
  28. * BLOBFILE
  29. */
  30. public String runActivity(PosContext ctx) {
  31. List dataList = new ArrayList();
  32. String[] resultKeys;
  33. HttpServletRequest request = (HttpServletRequest)ctx.findRequestAttr("HttpServletRequest");
  34. if (request.getParameter("resultKey") != null) {
  35. resultKeys = request.getParameter("resultKey").split("\\|");
  36. } else {
  37. resultKeys = (String[])ctx.get("ResultKeyList");
  38. }
  39. for (int i = 0, length = resultKeys.length; i < length; i++) {
  40. Object obj = ctx.get(resultKeys[i]);
  41. if (obj != null)
  42. dataList.add(obj);
  43. }
  44. //获取模板
  45. ctx.put(PosBizControlConstants.SERVICE_NAME, "Excel-Template-service");
  46. PosBizProvider.getController().doSubController(ctx, false);
  47. PosRowSet rowSet = (PosRowSet)ctx.get("ListResult_0");
  48. if (rowSet == null || !rowSet.hasNext())
  49. return PosBizControlConstants.SUCCESS;
  50. Initialize();
  51. PosRow row = rowSet.next();
  52. InputStream in = (InputStream)row.getAttribute("TMPL_CONTENT");
  53. if (in == null)
  54. return PosBizControlConstants.SUCCESS;
  55. String clsName = (String)row.getAttribute("JAVA_CLASS");
  56. if (clsName == null)
  57. return PosBizControlConstants.SUCCESS;
  58. PosExcelInterface excelInferface;
  59. try {
  60. excelInferface = (PosExcelInterface)Class.forName(clsName).newInstance();
  61. } catch (Exception e) {
  62. throw new PosException("Class " + clsName + " not exist!");
  63. }
  64. ByteArrayOutputStream bout = new ByteArrayOutputStream();
  65. try {
  66. excelInferface.setData(dataList, new BufferedInputStream(new GZIPInputStream(in)), bout,
  67. Integer.parseInt(row.getAttribute("DATA_ROW").toString()),
  68. Integer.parseInt(row.getAttribute("PAGE_SIZE").toString()));
  69. excelInferface = null;
  70. dataList.clear();
  71. in.close();
  72. } catch (IOException e) {
  73. e.printStackTrace();
  74. }
  75. // try
  76. // {
  77. // File f1 = File.createTempFile("temp008", ".html");
  78. //// String sPath = f1.getCanonicalPath();
  79. // FileOutputStream fos = new FileOutputStream(f1);
  80. // fos.write(bout.toByteArray());
  81. // fos.close();
  82. //
  83. // }catch(Exception ex)
  84. // {
  85. // ex.printStackTrace();
  86. // }
  87. setParamMap(ctx, "sqlkey", "param");
  88. ctx.put("BLOBFILE", bout.toByteArray());
  89. // Execute(ctx, "sqlkey", "param", 'i');
  90. String[]INV_NO = (String[])ctx.get("INV_NO");
  91. String[]ORD_NO = (String[])ctx.get("ORD_NO");
  92. String[]ORD_SEQ = (String[])ctx.get("ORD_SEQ");
  93. String[]CUST_CD = (String[])ctx.get("CUST_CD");
  94. String[]ORDCUST_CD = (String[])ctx.get("ORDCUST_CD");
  95. String[]ORD_USE_TP = (String[])ctx.get("ORD_USE_TP");
  96. String[]SPEC_ABBSYM = (String[])ctx.get("SPEC_ABBSYM");
  97. String[]CAR_GP = (String[])ctx.get("CAR_GP");
  98. String[]SUM_WGT = (String[])ctx.get("SUM_WGT");
  99. String[]SUM_CNT = (String[])ctx.get("SUM_CNT");
  100. String[]ORD_DEVLMT_DATE=(String[])ctx.get("ORD_DEVLMT_DATE");//交货日期
  101. String[]TRNF_DTIME = (String[])ctx.get("TRNF_DTIME");//发货日期
  102. // String[]BLOBFILE = (String[])ctx.get("BLOBFILE");
  103. Connection con = null;
  104. PreparedStatement pstm = null;
  105. String[]CRET_NO = (String[])ctx.get("CRET_NO");
  106. try
  107. {
  108. String driverClassName = "oracle.jdbc.driver.OracleDriver";
  109. Class.forName(driverClassName);
  110. //连接数据库
  111. String url = "jdbc:oracle:thin:@172.16.0.109:1521:mestest";
  112. String userName = "XSUSER";
  113. String userPsw = "XSUSER";
  114. // String url = "jdbc:oracle:thin:@10.10.0.8:1521:SQMESDB"; //测试
  115. // String userName = "XG3Q";
  116. // String userPsw = "XG3Q123";
  117. con = DriverManager.getConnection(url , userName , userPsw);
  118. String SQL2 = "DELETE FROM ZL_ZBS_DETAIL_DATA T WHERE T.ZBS_BH = ? ";
  119. String SQL3 = "DELETE FROM ZL_ZBS_MAIN_DATA T WHERE T.ZBS_BH = ? ";
  120. String SQL4 = "UPDATE TBB02_MS_COM T SET T.SEND_TP = 'Y' , T.SEND_DTIME = TO_CHAR(SYSDATE,'YYYYMMDDHH24MISS') WHERE T.CRET_NO = ? ";
  121. String SQL5 = "UPDATE TBB03_MS_COM T SET T.SEND_TP = 'Y' , T.SEND_DTIME = TO_CHAR(SYSDATE,'YYYYMMDDHH24MISS') WHERE T.CRET_NO = ? ";
  122. con.setAutoCommit(false);
  123. //delete
  124. pstm = con.prepareStatement(SQL2);
  125. pstm.setString(1, CRET_NO[0]);
  126. pstm.execute();
  127. //delete
  128. pstm = con.prepareStatement(SQL3);
  129. pstm.setString(1, CRET_NO[0]);
  130. pstm.execute();
  131. PosParameter param = new PosParameter();
  132. param.setWhereClauseParameter(0, CRET_NO[0]);
  133. if("XR".equals(CRET_NO[0].subSequence(0, 2)))//热轧
  134. {
  135. //UPDATE,已发送的标志
  136. this.getDao("mesdao").updateByQueryStatement(SQL4 , param);
  137. }
  138. else if("BR".equals(CRET_NO[0].subSequence(0, 2)))//板加
  139. {
  140. this.getDao("mesdao").updateByQueryStatement(SQL5 , param);
  141. }
  142. // pstm = con.prepareStatement(SQL4);
  143. // pstm.setString(1, CRET_NO[0]);
  144. // pstm.execute();
  145. //insert
  146. MutilConditionFind mcf = new MutilConditionFind();
  147. String sql = mcf.getQuerySql("UIB021100_01.INSERT").toString();
  148. System.out.println(sql);
  149. pstm = con.prepareStatement(sql);
  150. pstm.setString(1, INV_NO[0]);
  151. pstm.setString(2, ORD_NO[0]);
  152. pstm.setString(3, ORD_SEQ[0]);
  153. pstm.setString(4, CUST_CD[0]);
  154. pstm.setString(5, ORDCUST_CD[0]);
  155. pstm.setString(6, ORD_USE_TP[0]);
  156. pstm.setString(7, SPEC_ABBSYM[0]);
  157. pstm.setString(8, CAR_GP[0]);
  158. // param.setValueParamter(8, SUM_WGT[0]);
  159. // param.setValueParamter(9, SUM_CNT[0]);
  160. // System.out.println("####################"+TRNF_DTIME[0]+"#####################"+ORD_DEVLMT_DATE[0]+"###########");
  161. pstm.setFloat(9, Float.valueOf(SUM_WGT[0]).floatValue());
  162. pstm.setInt(10, Integer.valueOf(SUM_CNT[0]).intValue());
  163. pstm.setBytes(11, bout.toByteArray());
  164. pstm.setString(12, CRET_NO[0]);
  165. pstm.setString(13, TRNF_DTIME[0]);
  166. pstm.setString(14, ORD_DEVLMT_DATE[0]);
  167. // pstm.setBytes(15, bout.toByteArray());
  168. // DateFormat df = new SimpleDateFormat("yyyyMMdd");
  169. // String strDate= df.format(TRNF_DTIME[0]);
  170. // pstm.setDate(13, Date.valueOf(TRNF_DTIME[0]));
  171. // pstm.setString(13, strDate);
  172. pstm.execute();
  173. param = new PosParameter();
  174. param.setWhereClauseParameter(0, CRET_NO[0]);
  175. PosRowSet rowset = this.getDao("mesdao").find("UIB021100_001.SELECT", param);
  176. // sql = mcf.getQuerySql("UIB021100_001.SELECT").toString();
  177. // pstm = con.prepareStatement(sql);
  178. // pstm.setString(1, CRET_NO[0]);
  179. // ResultSet rs = pstm.executeQuery();
  180. pstm = null;
  181. String sql1 = mcf.getQuerySql("UIB021100_02.INSERT").toString();
  182. // System.out.println("!!!!!!!!"+sql1);
  183. pstm = con.prepareStatement(sql1);
  184. while(rowset.hasNext())
  185. {
  186. PosRow rs = rowset.next();
  187. pstm.setString(1 , rs.getAttribute("SHIP_INVNO").toString());
  188. pstm.setString(2 , rs.getAttribute("OLD_SAMPL_NO").toString());
  189. pstm.setString(3 , rs.getAttribute("SLAB_NO").toString());
  190. pstm.setString(4 , rs.getAttribute("SPEC_STL_GRD").toString());
  191. pstm.setString(5 , rs.getAttribute("INSTR_COIL_THK")== null ?"" : rs.getAttribute("INSTR_COIL_THK").toString());
  192. pstm.setString(6 , rs.getAttribute("COIL_LEN")== null ?"" : rs.getAttribute("COIL_LEN").toString());
  193. pstm.setString(7 , rs.getAttribute("INSTR_COIL_WTH")== null ?"" : rs.getAttribute("INSTR_COIL_WTH").toString());
  194. pstm.setInt(8 , Integer.valueOf(rs.getAttribute("SUM_CNT").toString()).intValue());
  195. pstm.setInt(9 , Integer.valueOf(rs.getAttribute("SUM_WGT").toString()).intValue());
  196. pstm.setString(10, rs.getAttribute("PRODNM_CD").toString());
  197. pstm.setString(11, CRET_NO[0]);
  198. pstm.execute();
  199. con.commit();
  200. }
  201. }catch(Exception ex)
  202. {
  203. ex.printStackTrace();
  204. try
  205. {
  206. con.rollback();
  207. }catch(Exception e)
  208. {
  209. e.printStackTrace();
  210. }
  211. }
  212. finally
  213. {
  214. try
  215. {
  216. if(pstm != null) pstm.close();
  217. if(con != null) con.close();
  218. }catch(Exception e)
  219. {
  220. e.printStackTrace();
  221. }
  222. }
  223. return PosBizControlConstants.SUCCESS;
  224. }
  225. }