82f6758dbda9bc42199fd042c5ba499d356caa4a.svn-base 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. package UIM;
  2. import java.sql.Connection;
  3. import java.sql.PreparedStatement;
  4. import java.sql.ResultSet;
  5. import java.sql.SQLException;
  6. import java.text.DateFormat;
  7. import java.text.DecimalFormat;
  8. import java.text.SimpleDateFormat;
  9. import java.util.ArrayList;
  10. import java.util.Date;
  11. import java.util.Iterator;
  12. import java.util.List;
  13. import java.util.Map;
  14. import UIB.COM.ProduceFactory;
  15. import UIB.COM.XmlSqlParsersFactory;
  16. import UIM.UIM01.BEANS.ColdCoilComm;
  17. import CoreFS.SA01.CoreIComponent;
  18. import CoreFS.SA06.CoreReturnObject;
  19. /**
  20. * 冷轧中间库盘入盘出
  21. *
  22. * @author siy
  23. * @date 2010-08-27
  24. */
  25. public class UIM010190 extends CoreIComponent {
  26. /**
  27. * 查询钢卷信息
  28. *
  29. * @param coilNo
  30. * 酸轧卷号
  31. * @return CoreReturnObject
  32. * @throws SQLException
  33. */
  34. public CoreReturnObject queryCoilInfo(String coilNo) throws SQLException {
  35. CoreReturnObject cro = new CoreReturnObject();
  36. String sql = XmlSqlParsersFactory.getSql("UIM010190_01.SELECT");
  37. cro = this.getDao("KgDao").ExcuteQuery(sql, new Object[] { coilNo });
  38. return cro;
  39. }
  40. /**
  41. * 盘入盘出操作
  42. *
  43. * @param type
  44. * 盘入/盘出 0/1
  45. * @param coilNo
  46. * 钢卷号
  47. * @param curLoadLoc
  48. * 垛位
  49. * @param regId
  50. * 盘入人
  51. * @return
  52. * @throws SQLException
  53. */
  54. public CoreReturnObject save(Integer type, String coilNo,
  55. String curLoadLoc, String regId, String trnfShift, String trnfGroup,String wdlivno)
  56. throws SQLException {
  57. CoreReturnObject cro = new CoreReturnObject();
  58. // 判断是做盘入操作还是做盘出操作
  59. if (0 == type.intValue()) {
  60. // 盘入操作,首先要检查钢卷号是否存在系统。不存在的情况下给予提示
  61. ColdCoilComm coldCoil = findCoil(coilNo, 0);
  62. if (null != coldCoil && !isNull(coldCoil.getCoilNo())) {
  63. // 正常出库的卷暂时不允许发货
  64. if ("3".equals(coldCoil.getCoilStat())
  65. && ("DFF".equals(coldCoil.getCurProgCd()) || "CCC"
  66. .equals(coldCoil.getCurProgCd()))
  67. && !isNull(coldCoil.getTrnfDTime())) {
  68. // 抛出异常
  69. cro.setV_errCode(new Integer(1));
  70. cro.setV_errMsg("需要盘入库的钢卷属于正常出库,不能进行盘入操作!");
  71. } else {
  72. // 输入垛位为空或不存在此垛位
  73. if (!isNull(curLoadLoc) && hasYard(curLoadLoc)) {
  74. // 检查要盘入的垛位上是否存在钢卷
  75. String coilNoTmp = this.hasCoilOnYard(curLoadLoc);
  76. if (isNull(coilNoTmp)) {
  77. Map result = this.getDao("KgDao")
  78. .CoreBeginTranscation();
  79. try {
  80. // 插入移垛记录
  81. String insSql = XmlSqlParsersFactory
  82. .getSql("UIM010110_01.INSERT");
  83. this.getDao("KgDao").ExcuteNonQuery(
  84. insSql,
  85. new Object[] { "", curLoadLoc, coilNo,
  86. regId, trnfShift, trnfGroup,
  87. "04" });
  88. // 人工盘入库的卷改为余材
  89. String sqlComm = XmlSqlParsersFactory
  90. .getSql("UIM010190_01.UPDATE");
  91. this.getDao("KgDao").ExcuteNonQuery(
  92. sqlComm,
  93. new Object[] { curLoadLoc, regId,
  94. coilNo });
  95. // 更新原料公共_D表
  96. String sqlCommD = XmlSqlParsersFactory
  97. .getSql("UIM010190_02.UPDATE");
  98. this.getDao("KgDao").ExcuteNonQuery(sqlCommD,
  99. new Object[] { coilNo });
  100. // 将钢卷信息录入垛位表
  101. String sqlYard = XmlSqlParsersFactory
  102. .getSql("UIM010190_03.UPDATE");
  103. this.getDao("KgDao").ExcuteNonQuery(
  104. sqlYard,
  105. new Object[] { coilNo, curLoadLoc,
  106. curLoadLoc, curLoadLoc,
  107. curLoadLoc });
  108. this.getDao("KgDao").CoreCommit(result);
  109. //调用存货异动点存储过程
  110. ProduceFactory PD= new ProduceFactory();
  111. PD.ErpDataCover("CCOIL",coilNo,"14A","1","O",regId,"酸轧盘入");
  112. } catch (Exception ex) {
  113. this.getDao("KgDao").CoreRollBack(result);
  114. cro.setV_errCode(new Integer(-1));
  115. cro.setV_errMsg("系统忙,请稍后再操作!");
  116. }
  117. }
  118. } else {
  119. cro.setV_errCode(new Integer(2));
  120. cro.setV_errMsg("需要盘入库的钢卷垛位信息不正确,请输入正确的垛位后再进行相应操作!");
  121. }
  122. }
  123. } else {
  124. cro.setV_errCode(new Integer(3));
  125. cro.setV_errMsg("需要盘入库的钢卷在库存中,请确认后再进行相应操作!");
  126. }
  127. } else if(1 == type.intValue()){
  128. // 盘出操作,首先要检查钢卷号是否存在系统。不存在的情况下给予提示
  129. ColdCoilComm coldCoil = findCoil(coilNo, 1);
  130. if (null != coldCoil && !isNull(coldCoil.getCoilNo())) {
  131. if ("CCB".equals(coldCoil.getCurProgCd())
  132. || "DFB".equals(coldCoil.getCurProgCd())) {
  133. cro.setV_errCode(new Integer(4));
  134. cro.setV_errMsg("需要盘出库的钢卷已经下发连退或发运计划,请撤销计划后再进行相应操作!");
  135. } else {
  136. Map result = this.getDao("KgDao").CoreBeginTranscation();
  137. try {
  138. // 插入移垛记录
  139. String insSql = XmlSqlParsersFactory
  140. .getSql("UIM010110_01.INSERT");
  141. this.getDao("KgDao").ExcuteNonQuery(
  142. insSql,
  143. new Object[] { coldCoil.getCurLoadLoc(), "", coilNo,
  144. regId, trnfShift, trnfGroup,
  145. "15" });
  146. // 更新原料公共表
  147. String sqlComm = XmlSqlParsersFactory
  148. .getSql("UIM010190_04.UPDATE");
  149. this.getDao("KgDao").ExcuteNonQuery(sqlComm,
  150. new Object[] { regId, coilNo });
  151. // 更新原料公共_D表
  152. String sqlCommD = XmlSqlParsersFactory
  153. .getSql("UIM010190_05.UPDATE");
  154. this.getDao("KgDao").ExcuteNonQuery(
  155. sqlCommD.toString(), new Object[] { coilNo });
  156. // 更新垛位表
  157. String sqlYard = XmlSqlParsersFactory
  158. .getSql("UIM010190_06.UPDATE");
  159. this.getDao("KgDao").ExcuteNonQuery(sqlYard.toString(),
  160. new Object[] { coilNo });
  161. this.getDao("KgDao").CoreCommit(result);
  162. //调用存货异动点存储过程
  163. ProduceFactory PD= new ProduceFactory();
  164. PD.ErpDataCover("CCOIL",coilNo,"64A","1","O",regId,"酸轧盘出");
  165. } catch (Exception ex) {
  166. this.getDao("KgDao").CoreRollBack(result);
  167. cro.setV_errCode(new Integer(-1));
  168. cro.setV_errMsg("系统忙,请稍后再操作!");
  169. }
  170. }
  171. } else {
  172. cro.setV_errCode(new Integer(5));
  173. cro.setV_errMsg("需要盘出库的钢卷不在库存中,请确认后再进行相应操作!");
  174. }
  175. }
  176. else{
  177. // 废钢外卖盘出操作,首先要检查钢卷号是否存在系统。不存在的情况下给予提示
  178. DateFormat formatter = new SimpleDateFormat("yyyyMMdd");
  179. String currDate = formatter.format(new Date());
  180. String seqno="FG"+currDate;
  181. String dlivnoNEXT;
  182. dlivnoNEXT=dlivno(seqno);//生成废钢编号
  183. ColdCoilComm coldCoil = findCoil(coilNo, 1);
  184. if (null != coldCoil && !isNull(coldCoil.getCoilNo())) {
  185. if ("CCB".equals(coldCoil.getCurProgCd())
  186. || "DFB".equals(coldCoil.getCurProgCd())) {
  187. cro.setV_errCode(new Integer(4));
  188. cro.setV_errMsg("需要盘出库的钢卷已经下发连退或发运计划,请撤销计划后再进行相应操作!");
  189. } else {
  190. Map result = this.getDao("KgDao").CoreBeginTranscation();
  191. try {
  192. // 插入移垛记录
  193. String insSql = XmlSqlParsersFactory
  194. .getSql("UIM010110_01.INSERT");
  195. this.getDao("KgDao").ExcuteNonQuery(
  196. insSql,
  197. new Object[] { coldCoil.getCurLoadLoc(), "", coilNo,
  198. regId, trnfShift, trnfGroup,
  199. "15" });
  200. // 更新原料公共表
  201. String sqlComm = XmlSqlParsersFactory
  202. .getSql("UIM010190_07.UPDATE");
  203. this.getDao("KgDao").ExcuteNonQuery(sqlComm,
  204. new Object[] { regId,dlivnoNEXT, coilNo });
  205. // 更新原料公共_D表
  206. String sqlCommD = XmlSqlParsersFactory
  207. .getSql("UIM010190_05.UPDATE");
  208. this.getDao("KgDao").ExcuteNonQuery(
  209. sqlCommD.toString(), new Object[] { coilNo });
  210. // 更新垛位表
  211. String sqlYard = XmlSqlParsersFactory
  212. .getSql("UIM010190_06.UPDATE");
  213. this.getDao("KgDao").ExcuteNonQuery(sqlYard.toString(),
  214. new Object[] { coilNo });
  215. this.getDao("KgDao").CoreCommit(result);
  216. } catch (Exception ex) {
  217. this.getDao("KgDao").CoreRollBack(result);
  218. cro.setV_errCode(new Integer(-1));
  219. cro.setV_errMsg("系统忙,请稍后再操作!");
  220. }
  221. }
  222. } else {
  223. cro.setV_errCode(new Integer(5));
  224. cro.setV_errMsg("需要盘出库的钢卷不在库存中,请确认后再进行相应操作!");
  225. }
  226. }
  227. return cro;
  228. }
  229. /**
  230. * 查找钢卷号是否存在
  231. *
  232. * @param coilNo
  233. * @param type
  234. * 0盘入 1盘出
  235. * @return
  236. */
  237. private ColdCoilComm findCoil(String coilNo, int type) {
  238. PreparedStatement prepStat = null;
  239. ColdCoilComm coldCoil = null;
  240. ResultSet rs = null;
  241. Connection conn = null;
  242. try {
  243. String sql = XmlSqlParsersFactory.getSql("UIM010190_03.SELECT");
  244. if (type == 0) {
  245. sql += " AND A.CUR_LOAD_LOC IS NULL";
  246. } else {
  247. sql += " AND A.COIL_STAT = '2'";
  248. }
  249. prepStat = this.getDao("KgDao").getPreparedStatement(sql);
  250. prepStat.setString(1, coilNo);
  251. conn = prepStat.getConnection();
  252. rs = prepStat.executeQuery();
  253. if (rs.next()) {
  254. coldCoil = new ColdCoilComm();
  255. coldCoil.setCoilNo(rs.getString("COIL_NO"));
  256. coldCoil.setCoilStat(rs.getString("COIL_STAT"));
  257. coldCoil.setCurProgCd(rs.getString("CUR_PROG_CD"));
  258. coldCoil.setSlabNo(rs.getString("SLAB_NO"));
  259. coldCoil.setTrnfDTime(rs.getString("TRNF_DTIME"));
  260. coldCoil.setCurLoadLoc(rs.getString("CUR_LOAD_LOC"));
  261. }
  262. } catch (SQLException sqle) {
  263. } finally {
  264. try {
  265. if (null != rs) {
  266. rs.close();
  267. }
  268. if (null != prepStat) {
  269. prepStat.close();
  270. }
  271. if (null != conn) {
  272. conn.close();
  273. }
  274. } catch (Exception e) {
  275. }
  276. }
  277. return coldCoil;
  278. }
  279. private String dlivno(String syddate) {
  280. String dlivno = "";
  281. StringBuffer sqlBuffer = new StringBuffer();
  282. sqlBuffer
  283. .append("SELECT MAX(A.WDLIVNO) WDLIVNO FROM C_TBL02_COIL_COMM A WHERE\n");
  284. sqlBuffer.append(" A.WDLIVNO LIKE ?||'%'");
  285. PreparedStatement prep = null;
  286. ResultSet rs = null;
  287. Connection con = null;
  288. try {
  289. prep = this.getDao("KgDao").getPreparedStatement(
  290. sqlBuffer.toString());
  291. prep.setString(1, syddate);
  292. rs = prep.executeQuery();
  293. con=prep.getConnection();
  294. if (rs.next()) {
  295. String temp="";
  296. if("".equals(rs.getString("WDLIVNO"))||rs.getString("WDLIVNO")==null)
  297. {
  298. dlivno=syddate+"01";
  299. }else{
  300. temp = rs.getString("WDLIVNO").substring(10);
  301. int aa=Integer.parseInt(temp) + 1;
  302. temp = new DecimalFormat("00").format(aa);
  303. dlivno=syddate+temp;
  304. }
  305. }
  306. else
  307. {
  308. dlivno=syddate+"01";
  309. }
  310. } catch (SQLException sqle) {
  311. } finally {
  312. try {
  313. if (null != rs) {
  314. rs.close();
  315. }
  316. if (null != prep) {
  317. prep.close();
  318. }
  319. if (null != con) {
  320. con.close();
  321. }
  322. } catch (Exception e) {
  323. }
  324. }
  325. return dlivno;
  326. }
  327. /**
  328. * 判断中间库垛位上是否存在有钢卷
  329. *
  330. * @param curLoadLoc
  331. * 堆放位置
  332. * @return String
  333. */
  334. private String hasCoilOnYard(String curLoadLoc) {
  335. String coilNo = "";
  336. String sql = XmlSqlParsersFactory.getSql("UIM010190_04.SELECT");
  337. Connection conn = null;
  338. PreparedStatement prep = null;
  339. ResultSet rs = null;
  340. try {
  341. prep = this.getDao("KgDao").getPreparedStatement(sql);
  342. prep.setString(1, curLoadLoc);
  343. conn = prep.getConnection();
  344. rs = prep.executeQuery();
  345. if (rs.next()) {
  346. coilNo = rs.getString("COIL_NO");
  347. }
  348. } catch (SQLException sqle) {
  349. } finally {
  350. try {
  351. if (null != rs) {
  352. rs.close();
  353. }
  354. if (null != prep) {
  355. prep.close();
  356. }
  357. if (null != conn) {
  358. conn.close();
  359. }
  360. } catch (Exception e) {
  361. }
  362. }
  363. return coilNo;
  364. }
  365. /**
  366. * 判断对象是否为空
  367. *
  368. * @param obj
  369. * @return boolean
  370. */
  371. private boolean isNull(Object obj) {
  372. boolean isNull = true;
  373. if (null != obj && !"".equals(obj)) {
  374. isNull = false;
  375. }
  376. return isNull;
  377. }
  378. /**
  379. * 查询垛位是否存在
  380. *
  381. * @param curLoadLoc
  382. * @return
  383. */
  384. private boolean hasYard(String curLoadLoc) {
  385. boolean b = false;
  386. String sql = XmlSqlParsersFactory.getSql("UIM010190_02.SELECT");
  387. Connection conn = null;
  388. PreparedStatement prep = null;
  389. ResultSet rs = null;
  390. try {
  391. prep = this.getDao("KgDao").getPreparedStatement(sql);
  392. prep.setString(1, curLoadLoc);
  393. conn = prep.getConnection();
  394. rs = prep.executeQuery();
  395. if (rs.next()) {
  396. b = true;
  397. }
  398. } catch (SQLException sqle) {
  399. } finally {
  400. try {
  401. if (null != rs) {
  402. rs.close();
  403. }
  404. if (null != prep) {
  405. prep.close();
  406. }
  407. if (null != conn) {
  408. conn.close();
  409. }
  410. } catch (Exception e) {
  411. }
  412. }
  413. return b;
  414. }
  415. }