diff --git a/zi-wms-pda/src/main/java/com/cim/idm/controller/FGStockInController.java b/zi-wms-pda/src/main/java/com/cim/idm/controller/FGStockInController.java index 3cf1c7b..e31def9 100644 --- a/zi-wms-pda/src/main/java/com/cim/idm/controller/FGStockInController.java +++ b/zi-wms-pda/src/main/java/com/cim/idm/controller/FGStockInController.java @@ -101,9 +101,9 @@ public class FGStockInController { return AjaxResult.me().setSuccess(false).setMessage("未同步标签信息或者标签发生变更无法入库,请联系IT处理!"); } - if (list2.get(0).get("MAKEDATE") == null) { - return AjaxResult.me().setSuccess(false).setMessage("生产日期为空,请联系IT处理!"); - } +// if (list2.get(0).get("MAKEDATE") == null) { +// return AjaxResult.me().setSuccess(false).setMessage("生产日期为空,请联系IT处理!"); +// } // if ("101".equals(erpFactory) || "102".equals(erpFactory)) { diff --git a/zi-wms-pda/src/main/java/com/cim/idm/controller/NoInvoiceManagerContoller.java b/zi-wms-pda/src/main/java/com/cim/idm/controller/NoInvoiceManagerContoller.java index 0881541..28b2876 100644 --- a/zi-wms-pda/src/main/java/com/cim/idm/controller/NoInvoiceManagerContoller.java +++ b/zi-wms-pda/src/main/java/com/cim/idm/controller/NoInvoiceManagerContoller.java @@ -264,7 +264,7 @@ public class NoInvoiceManagerContoller { } if (!erpFactory.equals(list.get(0).get("ERPFACTORY").toString()) || !erpLocation.equals(list.get(0).get("ERPLOCATION").toString()) ) { - throw new GlobalException("目标仓库与组织与原库存不一致!组织:"+erpFactory+"库存组织:"+list.get(0).get("ERPFACTORY").toString()+"仓库:"+erpLocation+"目标仓库:"+list.get(0).get("ERPLOCATION").toString()); + throw new GlobalException("目标仓库与组织与原库存不一致!组织:"+erpFactory+"库存组织:"+list.get(0).get("ERPFACTORY")+"仓库:"+erpLocation+"目标仓库:"+list.get(0).get("ERPLOCATION")); } String preLocation = list.get(0).get("LOCATIONNAME") == null ? "" : list.get(0).get("LOCATIONNAME").toString(); if (list.get(0).get("LOCATIONNAME") != null && locationName.equals(preLocation) ) { diff --git a/zi-wms-pda/src/main/java/com/cim/idm/controller/PalletizingController.java b/zi-wms-pda/src/main/java/com/cim/idm/controller/PalletizingController.java new file mode 100644 index 0000000..4e24cd6 --- /dev/null +++ b/zi-wms-pda/src/main/java/com/cim/idm/controller/PalletizingController.java @@ -0,0 +1,165 @@ +package com.cim.idm.controller; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.cim.idm.framework.IDMFrameServiceProxy; +import com.cim.idm.model.PalletizingDto; +import com.cim.idm.utils.AjaxResult; +import com.cim.idm.utils.CodeGenerator; +import io.swagger.annotations.Api; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Api("库内管理组托拆托接口") +@RestController +@RequestMapping("/api/Palletizing") +@EnableAutoConfiguration +public class PalletizingController { + + private static Log log = LogFactory.getLog(PalletizingController.class); + + + @Autowired + private CodeGenerator codeGenerator; + + + @RequestMapping(value = "/scanCode", method = RequestMethod.POST) + public AjaxResult ScanCode(@RequestBody JSONObject in ) throws Exception{ + + PalletizingDto pallet = JSON.toJavaObject(in, PalletizingDto.class); + + String materialPackingName = pallet.getMaterialPackingName(); + String palletNo = pallet.getPalletNo(); + + Map map = new HashMap(); + map.put("MATERIALPACKINGNAME", materialPackingName); + + String PackSql = "SELECT * FROM MATERIALPACKING m WHERE STOCKSTATE = 'Stocked' AND MATERIALPACKINGNAME = :MATERIALPACKINGNAME"; + + List> pckList = IDMFrameServiceProxy.getSqlTemplate().queryForList(PackSql, map); + + if(pckList.isEmpty()) { + return AjaxResult.me().setSuccess(false).setMessage("未找到在库的相关扫描条码!"); + } + + String charge = pckList.get(0).get("CHARGE").toString(); + + String malSql = "SELECT * FROM MATERIALPACKINGPALLET m WHERE MATERIALPACKINGNAME = :MATERIALPACKINGNAME AND UNBINDFLAG != 'Y'"; + + List> list = IDMFrameServiceProxy.getSqlTemplate().queryForList(malSql, map); + + String newPalletNo; + + if(list.isEmpty() && palletNo.isEmpty()) { + // 生成条码 + newPalletNo = CodeGenerator.generateCode(); + ArrayList arr = new ArrayList<>(); + Map objMap = new HashMap(); + objMap.put("MATERIALPACKINGNAME", materialPackingName); + objMap.put("PALLETNO", newPalletNo); + objMap.put("CHARGE", charge); + arr.add(objMap); + + return AjaxResult.me().setResultObj(arr); + + }else { + + // 如果扫描的托盘号不存在,则用之前扫的条码托盘号,如果扫描的托盘号存在,则用扫的托盘号带出所有的这个托盘号的条码 + if(list.isEmpty()) { + ArrayList arrList = new ArrayList<>(); + Map plMap = new HashMap(); + plMap.put("MATERIALPACKINGNAME", materialPackingName); + plMap.put("PALLETNO", palletNo); + plMap.put("CHARGE", charge); + arrList.add(plMap); + + return AjaxResult.me().setResultObj(arrList); + }else { + newPalletNo = list.get(0).get("PALLETNO") == null ? "" : list.get(0).get("PALLETNO").toString(); + + if(!palletNo.isEmpty() && !palletNo.equals(newPalletNo)) { + return AjaxResult.me().setSuccess(false).setMessage("扫描条码已绑定的托盘号与之前扫描的条码托盘号不一致"); + } + String pallNoSql = "SELECT * FROM MATERIALPACKINGPALLET m WHERE PALLETNO = :PALLETNO AND UNBINDFLAG != 'Y'"; + map.put("PALLETNO", newPalletNo); + List> pallNoList = IDMFrameServiceProxy.getSqlTemplate().queryForList(pallNoSql, map); + + return AjaxResult.me().setResultObj(pallNoList); + } + + } + + } + + @RequestMapping(value = "/addPalletizing", method = RequestMethod.POST) + @Transactional + public AjaxResult AddPalletizing(@RequestBody JSONObject in ) throws Exception{ + PalletizingDto pallet = JSON.toJavaObject(in, PalletizingDto.class); + String userId = pallet.getUserId(); + + List> boxList = pallet.getBoxList(); + for (Map map : boxList) { + String materialPackingName = map.get("MATERIALPACKINGNAME").toString(); + String palletNo = map.get("PALLETNO").toString(); + String charge = map.get("CHARGE").toString(); + + Map map1 = new HashMap(); + map1.put("MATERIALPACKINGNAME", materialPackingName); + map1.put("PALLETNO", palletNo); + map1.put("CHARGE", charge); + map1.put("USERID", userId); + map1.put("UNBINDFLAG", "N"); + String qSql = "SELECT * FROM MATERIALPACKINGPALLET m WHERE m.MATERIALPACKINGNAME = :MATERIALPACKINGNAME AND m.PALLETNO = :PALLETNO AND m.UNBINDFLAG != 'Y'"; + List> queryForList = IDMFrameServiceProxy.getSqlTemplate().queryForList(qSql, map1); + if(queryForList.size() == 0) { + String sql = "INSERT INTO MATERIALPACKINGPALLET (MATERIALPACKINGNAME,PALLETNO,CHARGE,USERID,MAKEDATE,UNBINDFLAG) VALUES (:MATERIALPACKINGNAME,:PALLETNO,:CHARGE,:USERID,SYSDATE,:UNBINDFLAG)"; + IDMFrameServiceProxy.getSqlTemplate().update(sql, map1); + }else { + String updSql = "UPDATE MATERIALPACKINGPALLET m SET m.UNBINDFLAG=:UNBINDFLAG,m.MAKEDATE=SYSDATE,m.USERID=:USERID WHERE m.MATERIALPACKINGNAME = :MATERIALPACKINGNAME AND m.PALLETNO = :PALLETNO"; + IDMFrameServiceProxy.getSqlTemplate().update(updSql, map1); + } + + } + return AjaxResult.me().setResultObj(null); + } + + @RequestMapping(value = "/delPalletizing", method = RequestMethod.POST) + public AjaxResult DelPalletizing(@RequestBody JSONObject in ) throws Exception{ + PalletizingDto pallet = JSON.toJavaObject(in, PalletizingDto.class); + String materialPackingName = pallet.getMaterialPackingName(); + String palletNo = pallet.getPalletNo(); + String unbindUserId = pallet.getUnbindUserId(); + + + + Map map = new HashMap(); + map.put("MATERIALPACKINGNAME", materialPackingName); + map.put("PALLETNO", palletNo); + String qsql = "SELECT * FROM MATERIALPACKINGPALLET m WHERE m.MATERIALPACKINGNAME = :MATERIALPACKINGNAME AND m.PALLETNO = :PALLETNO"; + List> queryForList = IDMFrameServiceProxy.getSqlTemplate().queryForList(qsql, map); + if(queryForList.size() == 0) { + return AjaxResult.me().setSuccess(false).setMessage("此标签不存在,未先组托保存,请先组托!"); + } + +// String sql = "DELETE FROM MATERIALPACKINGPALLET m WHERE m.MATERIALPACKINGNAME = :MATERIALPACKINGNAME AND m.PALLETNO = :PALLETNO"; + String sql = "UPDATE MATERIALPACKINGPALLET m SET m.UNBINDFLAG=:UNBINDFLAG,m.UNBINDDATE=SYSDATE,m.UNBINDUSERID=:UNBINDUSERID WHERE m.MATERIALPACKINGNAME = :MATERIALPACKINGNAME AND m.PALLETNO = :PALLETNO"; + map.put("UNBINDFLAG", "Y"); + map.put("UNBINDUSERID", unbindUserId); + IDMFrameServiceProxy.getSqlTemplate().update(sql, map); + + return AjaxResult.me().setResultObj(null); + } + +} diff --git a/zi-wms-pda/src/main/java/com/cim/idm/exception/AllExceptionHandler.java b/zi-wms-pda/src/main/java/com/cim/idm/exception/AllExceptionHandler.java index f2273a8..9e7f44c 100644 --- a/zi-wms-pda/src/main/java/com/cim/idm/exception/AllExceptionHandler.java +++ b/zi-wms-pda/src/main/java/com/cim/idm/exception/AllExceptionHandler.java @@ -24,7 +24,7 @@ public class AllExceptionHandler { e.printStackTrace(); return AjaxResult.me().setSuccess(false) .setErrorCode(500) - .setMessage("系统异常"); + .setMessage(e.getMessage() == null ? "系统异常" : e.getMessage()); } diff --git a/zi-wms-pda/src/main/java/com/cim/idm/model/PalletizingDto.java b/zi-wms-pda/src/main/java/com/cim/idm/model/PalletizingDto.java new file mode 100644 index 0000000..dbc842a --- /dev/null +++ b/zi-wms-pda/src/main/java/com/cim/idm/model/PalletizingDto.java @@ -0,0 +1,19 @@ +package com.cim.idm.model; + +import lombok.Data; + +import java.util.List; +import java.util.Map; + +@Data +public class PalletizingDto { + + private String palletNo; + private String materialPackingName; + private String userId; + private String unbindDate; + private String unbindUserId; + private String unbindFlag; + private List> boxList; + +} diff --git a/zi-wms-pda/src/main/java/com/cim/idm/service/Impl/InvoiceServiceImpl.java b/zi-wms-pda/src/main/java/com/cim/idm/service/Impl/InvoiceServiceImpl.java index c14cff7..043ced2 100644 --- a/zi-wms-pda/src/main/java/com/cim/idm/service/Impl/InvoiceServiceImpl.java +++ b/zi-wms-pda/src/main/java/com/cim/idm/service/Impl/InvoiceServiceImpl.java @@ -3,6 +3,7 @@ package com.cim.idm.service.Impl; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.cim.idm.data.ErpMessageLog; +import com.cim.idm.exception.GlobalException; import com.cim.idm.framework.IDMFrameServiceProxy; import com.cim.idm.framework.data.EventInfo; import com.cim.idm.framework.exception.IDMFrameDBErrorSignal; @@ -464,7 +465,11 @@ public class InvoiceServiceImpl implements InvoiceService { } else { + billCode=ProductionStockOut_NEW(shipRequestName, "SDK", eventUser,materialPackingKeyList); + if (billCode.isEmpty()) { + throw new CustomException("SAP过账异常!"); + } // billCode=toSAPService.ProductionStockOut_NEW(shipRequestName, "SDK", eventUser,materialPackingKeyList); //抛送MES数据 untils.sendMaterialInfoToMES_NEW(shipRequestName, "", materialPackingKeyList); @@ -1834,10 +1839,11 @@ public class InvoiceServiceImpl implements InvoiceService { MessageLogUtil.writeMessageLog(erplog); } catch (Exception e) { // log.info(e.getMessage(), e); - throw new RuntimeException("SAP返回" + rmsg); + throw new GlobalException("SAP返回" + rmsg); } if (!"S".equals(rcode)) { - throw new RuntimeException("SAP返回" + rmsg); + throw new GlobalException("SAP返回" + rmsg); +// throw new CustomException("SAP返回" + rmsg); } return undoId; } diff --git a/zi-wms-pda/src/main/java/com/cim/idm/service/Impl/MESToWMSServiceImpl.java b/zi-wms-pda/src/main/java/com/cim/idm/service/Impl/MESToWMSServiceImpl.java index 23f54b4..72282e6 100644 --- a/zi-wms-pda/src/main/java/com/cim/idm/service/Impl/MESToWMSServiceImpl.java +++ b/zi-wms-pda/src/main/java/com/cim/idm/service/Impl/MESToWMSServiceImpl.java @@ -428,6 +428,7 @@ public class MESToWMSServiceImpl implements MESToWMSService { String erpLocation = jo.getString("erpLocation"); String locationName = jo.getString("locationName"); String gxId = jo.getString("gxId"); // 增加管芯字段 +// String makeDate = jo.getString("makeDate"); erpFactory = jo.getString("erpFactory"); if (i == 0) { stockInType = jo.getString("stockInType"); @@ -468,6 +469,7 @@ public class MESToWMSServiceImpl implements MESToWMSService { bindMap.put("MATERIALSPECTYPE", stockInType); bindMap.put("CHARGE", charge); bindMap.put("GXID", gxId); +// bindMap.put("makeDate", makeDate); if ("1".equals(operationType)) { // 自动入库 if ("FG".equals(stockInType) || "BFG".equals(stockInType)) { // 产成品入库 增加回收例子入库 diff --git a/zi-wms-pda/src/main/java/com/cim/idm/utils/CodeGenerator.java b/zi-wms-pda/src/main/java/com/cim/idm/utils/CodeGenerator.java new file mode 100644 index 0000000..a94b07f --- /dev/null +++ b/zi-wms-pda/src/main/java/com/cim/idm/utils/CodeGenerator.java @@ -0,0 +1,61 @@ +package com.cim.idm.utils; + +import com.cim.idm.framework.IDMFrameServiceProxy; +import com.cim.idm.wmsextend.generic.errorHandler.CustomException; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.stereotype.Component; + +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +@Component +public class CodeGenerator { + + private static Log log = LogFactory.getLog(CodeGenerator.class); + + private static final String DATE_FORMAT = "yyyyMMdd"; + private static final String PREFIX = "PT"; + public static String generateCode() throws CustomException { + + + String currentDateStr = new SimpleDateFormat(DATE_FORMAT).format(new Date()); + String newPalletNo = null; + boolean success = false; + + while (!success) { + + String maxSeqNoQuery = "SELECT NVL(MAX(TO_NUMBER(SUBSTR(PALLETNO, " + + "(LENGTH('" + PREFIX + "') + LENGTH(:dateStr) + 1), 3))), 0) + 1 AS new_seq " + + "FROM MATERIALPACKINGPALLET " + + "WHERE SUBSTR(PALLETNO, 1, LENGTH('" + PREFIX + "') + LENGTH(:dateStr)) = '" + PREFIX + "' || :dateStr"; + + try { + log.info("maxSeqNoQuery: " + maxSeqNoQuery); + Map bindMap = new HashMap(); + bindMap.put("dateStr", currentDateStr); + Map maxSeqNoResult = IDMFrameServiceProxy.getSqlTemplate().queryForMap(maxSeqNoQuery,bindMap); + + int newSeqNo = 0; + if (maxSeqNoResult != null && maxSeqNoResult.containsKey("new_seq")) { + newSeqNo = Integer.parseInt(maxSeqNoResult.get("new_seq").toString()); + } + // 确保流水码不超过999 + if (newSeqNo > 999) { + throw new CustomException("流水码超过了数字999"); + } + String newSeqNoStr = String.format("%03d", newSeqNo); + newPalletNo = PREFIX + currentDateStr + newSeqNoStr; + + success = true; + }catch (Exception e) { + log.error("Failed to generate pallet number: " + e.getMessage()); + throw new CustomException("生成流水码错误: " + e.getMessage()); + } + + } + return newPalletNo; + } +}