From a0b733a8b19b1db43395a96408098596ac3d2a86 Mon Sep 17 00:00:00 2001 From: tqs <56479841@qq.com> Date: 星期二, 05 十二月 2023 08:16:06 +0800 Subject: [PATCH] # --- src/main/java/zy/cloud/wms/manager/service/impl/WorkServiceImpl.java | 269 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 260 insertions(+), 9 deletions(-) diff --git a/src/main/java/zy/cloud/wms/manager/service/impl/WorkServiceImpl.java b/src/main/java/zy/cloud/wms/manager/service/impl/WorkServiceImpl.java index b77dece..db257ec 100644 --- a/src/main/java/zy/cloud/wms/manager/service/impl/WorkServiceImpl.java +++ b/src/main/java/zy/cloud/wms/manager/service/impl/WorkServiceImpl.java @@ -1,6 +1,7 @@ package zy.cloud.wms.manager.service.impl; import com.baomidou.mybatisplus.mapper.EntityWrapper; +import com.core.common.Arith; import com.core.common.Cools; import com.core.common.R; import com.core.common.SnowflakeIdWorker; @@ -9,9 +10,14 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import zy.cloud.wms.common.config.CodeCoolException; +import zy.cloud.wms.common.model.BillDto; import zy.cloud.wms.common.model.MatnrDto; import zy.cloud.wms.common.model.OrderStoDto; import zy.cloud.wms.common.service.MainService; +import zy.cloud.wms.common.service.asrs.AsrsService; +import zy.cloud.wms.common.service.asrs.entity.Result1; +import zy.cloud.wms.common.service.erp.ErpR; import zy.cloud.wms.common.service.erp.ErpService; import zy.cloud.wms.common.utils.VersionUtils; import zy.cloud.wms.manager.entity.*; @@ -43,8 +49,6 @@ @Autowired private MatService matService; @Autowired - private ErpService erpService; - @Autowired private CheckService checkService; @Autowired private OrderService orderService; @@ -54,13 +58,23 @@ private ItemService itemService; @Autowired private CstmrService cstmrService; + @Autowired + private ErpService erpService; + @Autowired + private AsrsService asrsService; + @Autowired + private PakinService pakinService; @Override @Transactional public R stockPakin(PakinParam param, Long userId) { Node node = nodeService.selectByUuid(param.getNodeId()); if (node == null) { - node = nodeService.selectById(param.getNodeId()); + try { + node = nodeService.selectById(param.getNodeId()); + } catch (Exception e) { + return R.error("璐т綅涓嶅瓨鍦�"); + } } if (node == null) { return R.error("璐т綅涓嶅瓨鍦�"); @@ -68,11 +82,56 @@ if (Cools.isEmpty(param.getMats())) { return R.error("鍏ュ簱鐗╂枡涓嶈兘涓虹┖"); } + Integer docId = Optional.ofNullable(param.getDocType()).orElse(34); + String docNum = String.valueOf(snowflakeIdWorker.nextId()); + switch (docId) { + case 34: // 閲囪喘鍗� + docNum = "PU-" + String.valueOf(snowflakeIdWorker.nextId()).substring(0, 15); + break; + case 45: // 閿�鍞��璐у崟 + docNum = "SR-" + String.valueOf(snowflakeIdWorker.nextId()).substring(0, 15); + break; + default: + break; + } Date now = new Date(); for (MatnrDto dto : param.getMats()) { Mat mat = matService.selectByMatnr(dto.getMatnr()); if (mat == null) { throw new CoolException("鐗╂枡鏁版嵁閿欒锛岃鑱旂郴绠$悊鍛�"); + } + // 淇濆瓨鍏ュ簱璁板綍 + Pakin pakin = new Pakin( + "I" + String.valueOf(snowflakeIdWorker.nextId()), // 浠诲姟鍙穂闈炵┖] + null, // 宸ヤ綔鐘舵�� + null, // 鎵樼洏鍙� + dto.getCount(), // 鍏ュ簱鏁伴噺 + node.getId(), // 鍏宠仈璐т綅[闈炵┖] + node.getUuid(), // 璐т綅[闈炵┖] + mat.getMatnr(), // 鍟嗗搧缂栫爜[闈炵┖] + null, // 鍟嗗搧鍚嶇О + null, // 鍚嶇О + null, // 灏虹爜 + null, // 鍨嬪彿 + null, // 鎵瑰彿 + null, // 鍗曚綅 + null, // SKC + null, // 鍗曟嵁绫诲瀷 + null, // 鍗曟嵁缂栧彿 + null, // 瀹㈡埛鍚嶇О + null, // 鍝侀」鏁� + null, // 鏁伴噺 + null, // 閲嶉噺 + 1, // 鐘舵�� + userId, // 娣诲姞浜哄憳 + now, // 娣诲姞鏃堕棿 + userId, // 淇敼浜哄憳 + now, // 淇敼鏃堕棿 + null // 澶囨敞 + ); + VersionUtils.setPakin(pakin, mat); + if (!pakinService.insert(pakin)) { + throw new CoolException("淇濆瓨鍏ュ簱璁板綍澶辫触"); } LocDetl locDetl = locDetlService.getLocDetl(node.getId(), dto.getMatnr()); if (locDetl == null) { @@ -83,8 +142,8 @@ locDetl.setZpallet(""); locDetl.setAnfme(dto.getCount()); VersionUtils.setLocDetl(locDetl, mat); -// locDetl.setDocId(param.getDocType().longValue()); -// locDetl.setDocNum(docNum); + locDetl.setDocId(docId.longValue()); + locDetl.setDocNum(docNum); locDetl.setStatus(1); locDetl.setCreateBy(userId); locDetl.setCreateTime(now); @@ -101,7 +160,76 @@ } } + // 涓婃姤缁檈rp + List<BillDto> dtos = new ArrayList<>(); + for (MatnrDto dto : param.getMats()) { + BillDto billDto = new BillDto(); + billDto.setMatnr(dto.getMatnr()); + billDto.setQty(dto.getCount()); + dtos.add(billDto); + } + ErpR erpR = erpService.uploadBill(dtos, docId, docNum); + if (!erpR.getSuccess()) { + throw new CoolException("鏃犳硶涓婃姤鑷砮rp锛�"+erpR.getMsg()); + } + return R.ok("鍏ュ簱鎴愬姛"); + } + + @Override + @Transactional + public R stockPakout(PakoutParam param, Long userId) { + Mat mat = matService.selectByMatnr(param.getMatnr()); + Node node = nodeService.selectByUuid(param.getNodeUuid()); + LocDetl locDetl = locDetlService.getLocDetl(node.getId(), mat.getMatnr()); + if (locDetl == null || locDetl.getAnfme() < param.getCount()) { + return R.error(mat.getMaktx() + "搴撳瓨涓嶈冻"); + } + Pakout pakout = new Pakout( + String.valueOf(snowflakeIdWorker.nextId()), // 浠诲姟鍙穂闈炵┖] + 3L, // 宸ヤ綔鐘舵�� + null, // 鎵樼洏鍙� + param.getCount(), // 鍑哄簱鏁伴噺 + node.getId(), // 鍏宠仈璐т綅[闈炵┖] + node.getUuid(), // 璐т綅[闈炵┖] + mat.getMatnr(), // 鍟嗗搧缂栫爜[闈炵┖] + null, // 鍟嗗搧鍚嶇О + null, // 鍚嶇О + null, // 灏虹爜 + null, // 鍨嬪彿 + null, // 鎵瑰彿 + null, // 鍗曚綅 + null, // SKC + null, // 鍗曟嵁绫诲瀷 + null, // 鍗曟嵁缂栧彿 + null, // 瀹㈡埛鍚嶇О + null, // 鍝侀」鏁� + null, // 鏁伴噺 + null, // 閲嶉噺 + 1, // 鐘舵�� + userId, // 娣诲姞浜哄憳 + new Date(), // 娣诲姞鏃堕棿 + userId, // 淇敼浜哄憳 + new Date(), // 淇敼鏃堕棿 + null // 澶囨敞 + ); + VersionUtils.setPakout(pakout, mat); + // 淇濆瓨鍑哄簱閫氱煡鍗� + if (!pakoutService.insert(pakout)) { + throw new CoolException("淇濆瓨鍑哄簱閫氱煡鍗曞け璐�"); + } + if (param.getCount()>=locDetl.getAnfme()) { + // 鍒犻櫎搴撳瓨鏄庣粏 + if (!locDetlService.removeStock(node.getId(), mat.getMatnr())) { + throw new CoolException("鍒犻櫎搴撳瓨鏄庣粏澶辫触"); + } + } else { + // 淇敼搴撳瓨鏄庣粏鏁伴噺 + if (!locDetlService.reduceStock(node.getId(), mat.getMatnr(), param.getCount())) { + throw new CoolException("淇敼搴撳瓨鏄庣粏鏁伴噺澶辫触"); + } + } + return R.ok(); } @Override @@ -164,6 +292,19 @@ } } + + // 涓婃姤缁檈rp + List<BillDto> dtos = new ArrayList<>(); + for (Comb comb : combs) { + BillDto billDto = new BillDto(); + billDto.setMatnr(comb.getMatnr()); + billDto.setQty(comb.getAnfme()); + dtos.add(billDto); + } + ErpR erpR = erpService.uploadBill(dtos, param.getDocType(), docNum); + if (!erpR.getSuccess()) { + throw new CoolException("鏃犳硶涓婃姤鑷砮rp锛�"+erpR.getMsg()); + } return R.ok(); } @@ -196,6 +337,11 @@ if (Cools.isEmpty(orderDetls)) { return R.error("姝ゅ崟鎹凡澶辨晥锛岃鑱旂郴绠$悊鍛�"); } + for (OrderDetl orderDetl : orderDetls) { + if (Arith.remainder(orderDetl.getAnfme(), 1) > 0) { + return R.error(orderDetl.getMaktx() + "鏁伴噺蹇呴』涓烘暣鏁�"); + } + } OrderStoDto dto = new OrderStoDto().create(order.getOrderNo(), orderDetls); // 寮�濮嬫暣鐞嗗嚭搴撴暟鎹� mainService.stockOutProcess(dto); @@ -213,6 +359,7 @@ for (Pakout pakout : pakouts) { total = pakout.getAnfme() + total; } + StoPrintVo vo = new StoPrintVo(); vo.setDocNum(param.getOrderNo()); vo.setList(pakouts); @@ -414,6 +561,15 @@ Date now = new Date(); Item item = itemService.selectByName(param.getItem()); Cstmr cstmr = cstmrService.selectByName(param.getCstmr()); + // 閲囪喘閫�璐у崟妫�楠� + if (param.getDocType() == 6) { + for (MatnrDto dto : param.getList()) { + if (locDetlService.getStockByDocType34(dto.getMatnr()) < dto.getCount()) { + return R.error(dto.getMatnr() + "閲囪喘閲忎笉瓒充互鐢熸垚閫�璐у崟锛�"); + } + } + } + // 鏂板璁㈠崟琛ㄥご order = new Order( String.valueOf(snowflakeIdWorker.nextId()), // 缂栧彿[闈炵┖] @@ -475,6 +631,88 @@ } } return R.ok("鍒涘缓璁㈠崟鎴愬姛"); + } + + @Override + public R asrsStockTransfer(AsrsTransferParam param, Long userId) { + if (Cools.isEmpty(param.getNode_id(), param.getMatnr(), param.getSafe_qua(), param.getAmount())) { + return R.error("鏁伴噺閿欒"); + } + Node node = nodeService.selectById(param.getNode_id()); + Mat mat = matService.selectByMatnr(param.getMatnr()); + if (node == null || mat == null) { + return R.error(); + } + double anfme = Arith.subtract(2, param.getSafe_qua(), param.getAmount()); + List<StockTransferParam> params = new ArrayList<>(); + StockTransferParam transferParam = new StockTransferParam(); + transferParam.setMatnr(param.getMatnr()); + transferParam.setAnfme(anfme); + transferParam.setAllotNo(param.getNode_id()+ "_" +param.getMatnr()); + params.add(transferParam); + Result1 result = asrsService.stockTransfer(params); + if (result.getCode() == 500) { + if (Cools.isEmpty(result.getData())) { + throw new CoolException(result.getMsg()); + } else { + throw new CodeCoolException("20001-" + result.getData()); + } + } + // 鐩存帴澧炲姞搴撳瓨 +// LocDetl locDetl = locDetlService.getLocDetl(param.getNode_id(), param.getMatnr()); +// if (locDetl == null) { +// // 鏇存柊璐т綅搴撳瓨鏄庣粏 +// locDetl = new LocDetl(); +// locDetl.setLocNo(node.getName()); +// locDetl.setNodeId(node.getId()); +// locDetl.setAnfme(anfme); +// VersionUtils.setLocDetl(locDetl, mat); +// locDetl.setStatus(1); +// locDetl.setCreateBy(userId); +// locDetl.setCreateTime(new Date()); +// locDetl.setUpdateBy(userId); +// locDetl.setUpdateTime(new Date()); +// boolean insert = locDetlService.insert(locDetl); +// if (!insert) { +// throw new CoolException("鏂板搴撳瓨鏄庣粏妗eけ璐�"); +// } +// } else { +// if (!locDetlService.incrementStock(node.getId(), param.getMatnr(), anfme)) { +// throw new CoolException("鏂板搴撳瓨鏄庣粏妗eけ璐�"); +// } +// } + + return R.ok("琛ヤ粨鎴愬姛锛岀瓑寰呯珛搴撹皟鎷�"); + } + + @Override + public R asrsStockTransferLocMode(AsrsTransferParam param, Long userId) { + if (Cools.isEmpty(param.getNode_id(), param.getMatnr(), param.getSafe_qua(), param.getAmount())) { + return R.error("鏁伴噺閿欒"); + } + Node node = nodeService.selectById(param.getNode_id()); + Mat mat = matService.selectByMatnr(param.getMatnr()); + if (node == null || mat == null) { + return R.error(); + } + double anfme = Arith.subtract(2, param.getSafe_qua(), param.getAmount()); + List<StockTransferParam> params = new ArrayList<>(); + StockTransferParam transferParam = new StockTransferParam(); + transferParam.setMatnr(param.getMatnr()); + transferParam.setAnfme(anfme); + transferParam.setAllotNo(param.getNode_id()+ "_" +param.getMatnr()); + transferParam.setLocNo(param.getLocNo()); + params.add(transferParam); + Result1 result = asrsService.stockTransferLocMode(params); + if (result.getCode() == 500) { + if (Cools.isEmpty(result.getData())) { + throw new CoolException(result.getMsg()); + } else { + throw new CodeCoolException("20001-" + result.getData()); + } + } + + return R.ok("琛ヤ粨鎴愬姛锛岀瓑寰呯珛搴撹皟鎷�"); } @Override @@ -598,7 +836,7 @@ @Transactional public R stockCheckAuditing(Long checkId, Long userId) { Check check = checkService.selectById(checkId); - if (null == check) { + if (null == check || check.getStatus() != 1) { return R.error("鐩樼偣璁板綍宸插け鏁�"); } Date now = new Date(); @@ -650,9 +888,11 @@ String docNum = null; Long docId = null; switch (check.getSettle()) { - case 1: // 鐩樼泩 - docNum = "CS-" + String.valueOf(snowflakeIdWorker.nextId()).substring(0, 15); - docId = 14L; // 鎶ユ孩鍗� + case 1: // 鐩樼泩 todo 鍓嶆湡鐢ㄩ噰璐崟涓婃姤 +// docNum = "CS-" + String.valueOf(snowflakeIdWorker.nextId()).substring(0, 15); +// docId = 14L; // 鎶ユ孩鍗� + docNum = "PU-" + String.valueOf(snowflakeIdWorker.nextId()).substring(0, 15); + docId = 34L; // 閲囪喘鍗� break; case 2: // 鐩樹簭 docNum = "CD-" + String.valueOf(snowflakeIdWorker.nextId()).substring(0, 15); @@ -669,6 +909,17 @@ if (!checkService.updateById(check)) { throw new CoolException("淇敼鐩樼偣璁板綍鐘舵�佸け璐�"); } + + // 涓婃姤缁檈rp + List<BillDto> dtos = new ArrayList<>(); + BillDto billDto = new BillDto(); + billDto.setMatnr(check.getMatnr()); + billDto.setQty(Math.abs(check.getDiffQty())); + dtos.add(billDto); + ErpR erpR = erpService.uploadBill(dtos, docId.intValue(), docNum); + if (!erpR.getSuccess()) { + throw new CoolException("鏃犳硶涓婃姤鑷砮rp锛�"+erpR.getMsg()); + } return R.ok(); } -- Gitblit v1.9.1