Parcourir la source

【工单批量审核】

wuyx il y a 6 ans
Parent
commit
29c7dcdb46
1 fichiers modifiés avec 51 ajouts et 24 suppressions
  1. 51 24
      src/com/uas/mes/pm/service/impl/MakePrepareServiceImpl.java

+ 51 - 24
src/com/uas/mes/pm/service/impl/MakePrepareServiceImpl.java

@@ -645,7 +645,20 @@ public class MakePrepareServiceImpl implements MakePrepareService {
 				Response response = HttpUtil.doPost(outmatbyqtyUrl.toString()+"/outmatbyqty", sendMpList,false,null);
 				if (response.getStatusCode() == HttpStatus.OK.value()) {// 上传成功修改单据状态
 					String res = response.getResponseText();
-					//String res = "{\"color\":3,\"matlist\":[{\"totalqty\":2000,\"productionDate\":\"2018-12-07 10:12:46\",\"position\":475,\"qty\":2000,\"uid\":\"6002100502994681812070028\",\"matid\":\"TEST010004\",\"shelfid\":\"SWHY004\",\"productLine\":\"SMT-02\",\"feederLocation\":\"2\"},{\"totalqty\":8800,\"productionDate\":\"2019-04-30 12:04:00\",\"position\":1069,\"qty\":1000,\"uid\":\"0102100800000111904300221\",\"matid\":\"0210080000011\",\"shelfid\":\"SWHY004\",\"productLine\":\"SMT-02\",\"feederLocation\":\"A041\"}],\"qtylist\":[{\"matid\":\"0210050299468\",\"missqty\":500,\"needqty\":2500,\"factqty\":2000,\"totalqty\":2000,\"planqty\":2000},{\"matid\":\"0210080000011\",\"missqty\":0,\"needqty\":3,\"factqty\":1000,\"totalqty\":8800,\"planqty\":1000}],\"result\":true}";
+//					String res = "{\"color\":3,\"matlist\":[" +
+//							"{\"totalqty\":2000,\"productionDate\":\"2018-12-07 10:12:46\"," +
+//							"\"position\":475,\"qty\":11,\"uid\":\"0208080299967-01\"," +
+//							"\"matid\":\"0210050299993\",\"shelfid\":\"SWHY004\",\"productLine\":\"SMT-02\"," +
+//							"\"feederLocation\":\"L107\"}," +
+//							"{\"totalqty\":8800,\"productionDate\":\"2019-04-30 12:04:00\"," +
+//							"\"position\":1069,\"qty\":11,\"uid\":\"0208080299967-02\"," +
+//							"\"matid\":\"0210050299993\",\"shelfid\":\"SWHY004\",\"productLine\":\"SMT-02\"," +
+//							"\"feederLocation\":\"L107\"}," +
+//							"{\"totalqty\":8800,\"productionDate\":\"2019-04-30 12:04:00\"," +
+//							"\"position\":1069,\"qty\":10,\"uid\":\"0210050299993-01\"," +
+//							"\"matid\":\"0208080299964\",\"shelfid\":\"SWHY004\",\"productLine\":\"SMT-02\"," +
+//							"\"feederLocation\":\"L108\"}," +
+//							"],\"qtylist\":[{\"matid\":\"0210050299468\",\"missqty\":500,\"needqty\":2500,\"factqty\":2000,\"totalqty\":2000,\"planqty\":2000},{\"matid\":\"0210080000011\",\"missqty\":0,\"needqty\":3,\"factqty\":1000,\"totalqty\":8800,\"planqty\":1000}],\"result\":true}";
 					if(res!=null){
 							Map<Object, Object> result = BaseUtil.parseFormStoreToMap(res);
 							if(result.get("result").equals(true) || result.get("result").equals("true")){
@@ -659,8 +672,13 @@ public class MakePrepareServiceImpl implements MakePrepareService {
 									List<Map<Object, Object>> resMatlist = (List<Map<Object, Object>>) resMatlistStr;
 									for (Iterator iterator = resMatlist.iterator(); iterator.hasNext();) {
 										Map<Object, Object> map = (Map<Object, Object>) iterator.next();
-										sqls.add("update makePreparedetail set MD_COLOR = "+color+",MD_BARCODE ='"+map.get("uid")+"', md_qty = "+map.get("qty")+", MD_SHELFID = '"+map.get("shelfid")+"' "
+										sqls.add("update makePreparedetail set MD_COLOR = "+color+"," +
+												"MD_BARCODE = (case when MD_BARCODE is null then '"+map.get("uid")+"|' else MD_BARCODE||'"+map.get("uid")+"|' end), " +
+												" md_qty = nvl(md_qty,0) + "+map.get("qty")+", " +
+												"MD_SHELFID = (case when MD_SHELFID is null then '"+map.get("shelfid")+"|' else MD_SHELFID||'"+map.get("shelfid")+"|' end)"
 												+ "where MD_PRODCODE = '"+map.get("matid")+"' and MD_LOCATION ='"+map.get("feederLocation")+"' and md_mpid = "+id);
+										sqls.add("insert into MakePrepareDetaildet (MDD_ID,MDD_MPID,MDD_PRODCODE,MDD_LOCATION,MDD_BARCODE,MDD_QTY,MD_SHELFID) " +
+												"values (MAKEPREPAREDETAILDET_SEQ.nextval,"+id+",'"+map.get("matid")+"','"+map.get("feederLocation")+"','"+map.get("uid")+"',"+map.get("qty")+",'"+map.get("shelfid")+"')");
 										//sqls.add("update barcode set bar_place='"+mpCode+"' where bar_code='" + map.get("uid") + "'");
 									}
 									baseDao.execute(sqls);
@@ -702,9 +720,9 @@ public class MakePrepareServiceImpl implements MakePrepareService {
 		}
 		// 检查料卷是否已经备料,或者在其他状态
 		String dets = baseDao.getJdbcTemplate().queryForObject(
-				"select wm_concat(md_barcode) from MakePrepareDetail where md_barcode=? and md_mpid=?", String.class, barcode, mpid);
-		if (dets != null) {
-			throw new SystemException("料卷号:" + barcode + ",已备料!");
+				"select wm_concat(md_detno) from MakePrepareDetail where instr(MD_barcode,'"+barcode+"'||'|')>0 and md_mpid="+mpid, String.class);
+		if (StringUtil.hasText(dets)) {
+			throw new SystemException("行:"+dets+",料卷号:" + barcode + ",已备料!");
 		}
 		// 料卷是否存在,数量以及状态
 //		Object ob = baseDao.getFieldDataByCondition("barcode", "nvl(bar_place,'1')", "bar_code='" + barcode + "'");
@@ -717,8 +735,14 @@ public class MakePrepareServiceImpl implements MakePrepareService {
 //		}
 		Object[] obs = baseDao.getFieldsDataByCondition("barcode left join product on pr_code=bar_prodcode", new String[] { "bar_remain",
 				"bar_prodcode" }, "bar_code='" + barcode + "'");
+		if(obs == null){
+			throw new SystemException("料卷号:" + barcode + ",无效或不存在");
+		}
+		if(NumberUtil.isEmpty(obs[0])){
+			throw new SystemException("料卷号:" + barcode + ",无剩余库存!");
+		}
 		// 判断料卷号是否属于该备料单
-		rs = baseDao.queryForRowSet("select md_location,md_barcode,md_lastlocation,md_lastbarcode,md_lastqty,mp_whcode from makePrepareDetail left join makePrepare on mp_id=md_mpid where md_mpid="
+		rs = baseDao.queryForRowSet("select md_location,md_barcode,md_lastlocation,md_lastbarcode,md_lastqty,mp_whcode,md_needqty,md_qty from makePrepareDetail left join makePrepare on mp_id=md_mpid where md_mpid="
 						+ mpid + " and md_prodcode='" + obs[1] + "'");
 		if (rs.next()) {// 属于备料单主料
 			if (rs.size() > 1) {// 一个物料有多个站位可选
@@ -727,14 +751,15 @@ public class MakePrepareServiceImpl implements MakePrepareService {
 				getQty = Double.valueOf(map.get("getQty").toString());
 				location = map.get("location").toString();
 			} else if (rs.getString("md_barcode") == null || "".equals(rs.getString("md_barcode"))) {// 站位唯一,并且没有备料
-				double bar_remain = Double.valueOf(obs[0].toString());
-				if (bar_remain == 0) {// 判断bar_remain等于0
-					throw new SystemException("料卷数量为0");
-				}
-				getQty = bar_remain;
+				getQty = Double.valueOf(obs[0].toString());
 				location = rs.getString("md_location");
-			} else {// 站位已备料
-				throw new SystemException("料卷对应的站位:" + rs.getString("md_location") + ",已备料!");
+			} else {// 站位已备料 备料数小于需求数则可以备多卷料 md_needqty,md_qty
+				if(rs.getGeneralDouble("md_needqty") > rs.getGeneralDouble("md_qty")){
+					getQty = Double.valueOf(obs[0].toString());
+					location = rs.getString("md_location");
+				}else{
+					throw new SystemException("料卷对应的站位:" + rs.getString("md_location") + ",已备料!");
+				}
 			}
 		} else {// 不属于主料,判断是否属于替代料
 			rs = baseDao
@@ -760,10 +785,13 @@ public class MakePrepareServiceImpl implements MakePrepareService {
 				throw new SystemException("料卷:" + barcode + "所属物料,不在站位表中");
 			}
 		}
-		// 更新备料单明细备料料卷数量等
-		baseDao.updateByCondition("makePrepareDetail", "md_barcode='" + barcode + "', md_qty=" + getQty + ",md_record='" + barcode + "'",
+		// 更新备料单明细备料料卷数量等 barcode
+		baseDao.updateByCondition("makePrepareDetail",
+				"md_barcode=(case when MD_BARCODE is null then '"+barcode+"|' else MD_BARCODE||'"+barcode+"|' end)," +
+						" md_qty=nvl(md_qty,0)+" + getQty + ",md_record='" + barcode + "'",
 				"md_location='" + location + "' and md_mpid=" + mpid);
-		
+		baseDao.execute("insert into MakePrepareDetaildet (MDD_ID,MDD_MPID,MDD_PRODCODE,MDD_LOCATION,MDD_BARCODE,MDD_QTY,MD_SHELFID) " +
+				"values (MAKEPREPAREDETAILDET_SEQ.nextval,"+mpid+",'"+obs[1]+"','"+location+"','"+barcode+"',"+getQty+",'')");
 		// 更新料卷所在场所bar_place
 		//baseDao.updateByCondition("barcode", "bar_place=(select mp_code from makePrepare where mp_id=" + mpid + ")", "bar_code='" + barcode+"'");
 		rs = baseDao
@@ -792,11 +820,7 @@ public class MakePrepareServiceImpl implements MakePrepareService {
 		if (list.size() == 0) {// 都已经备料
 			throw new SystemException("料卷对应的站位[" + los + "]都已备料!");
 		} else {// 剩余未备料的
-			double bar_remain = Double.valueOf(obs[0].toString());
-			if (bar_remain == 0) {// 判断bar_remain等于0
-				throw new SystemException("料卷数量为0");
-			}
-			rmap.put("getQty", bar_remain);
+			rmap.put("getQty", Double.valueOf(obs[0].toString()));
 			rmap.put("location", list.get(0).get("md_location").toString());
 		}
 		return rmap;
@@ -821,7 +845,7 @@ public class MakePrepareServiceImpl implements MakePrepareService {
 			throw new SystemException("料卷号:" + barcode + "不存在!");
 		}
 		//MD_COLOR 不为空 料架备料不允许退回
-		rs = baseDao.queryForRowSet("select md_location,md_barcode,md_color,md_status from MakePrepareDetail where md_barcode='" + barcode + "'");
+		rs = baseDao.queryForRowSet("select md_location,md_barcode,md_color,md_status,md_prodcode from MakePrepareDetail where instr(MD_barcode,'"+barcode+"'||'|')>0 ");
 		if(!rs.next()){
 			throw new SystemException("料卷号:" + barcode + ",未备料!");
 		}
@@ -832,8 +856,11 @@ public class MakePrepareServiceImpl implements MakePrepareService {
 			BaseUtil.showError("料卷号:" + barcode + ",已领料,不允许退回!");
 		}
 		// 更新备料明细中料卷已备数量为空
-		baseDao.execute("update  MakePrepareDetail set md_barcode='',md_qty=0,md_record='' where md_mpid=" + mpid + " and md_barcode='"
-				+ barcode + "'");
+		baseDao.execute("update  MakePrepareDetail set md_barcode = replace(MD_BARCODE,'"+barcode+"|','')," +
+				"md_qty = md_qty - nvl((select sum(MDD_QTY) from MakePrepareDetaildet where MDD_MPID = md_mpid and MDD_PRODCODE = md_prodcode and MDD_LOCATION = MD_LOCATION and MDD_barcode = '"+barcode+"' ),0) " +
+				"where md_mpid=" + mpid + " and md_prodcode ='"+rs.getGeneralString("md_prodcode")+"' and MD_LOCATION ='"+rs.getGeneralString("md_location")+"' and instr(MD_barcode,'"+barcode+"'||'|')>0 ");
+		baseDao.execute("delete MakePrepareDetaildet where MDD_MPID ="+mpid+" and MDD_PRODCODE = '"+rs.getGeneralString("md_prodcode")+"' and MDD_LOCATION = '"+rs.getGeneralString("md_location")+"' and MDD_barcode='"+barcode+"'");
+
 		// 更新条码所在场所bar_place
 		//baseDao.updateByCondition("barcode", "bar_place=''", "bar_code='" + barcode + "'");
 		baseDao.execute(baseDao.logger.getMessageLog("备料退回", "退回成功,料卷号:"+barcode, "MakePrepare2", "mp_id", mpid).getSql());