From 57936e11434f6614f818a0a0a495918dc1af6dd6 Mon Sep 17 00:00:00 2001 From: pang.jiabao <pang_jiabao@163.com> Date: 星期一, 02 十二月 2024 08:07:01 +0800 Subject: [PATCH] 单据出库完成 --- src/main/java/com/zy/asrs/service/impl/MobileServiceImpl.java | 503 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 481 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/zy/asrs/service/impl/MobileServiceImpl.java b/src/main/java/com/zy/asrs/service/impl/MobileServiceImpl.java index d7b397b..e4c1241 100644 --- a/src/main/java/com/zy/asrs/service/impl/MobileServiceImpl.java +++ b/src/main/java/com/zy/asrs/service/impl/MobileServiceImpl.java @@ -3,26 +3,32 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.mapper.EntityWrapper; -import com.core.common.BaseRes; -import com.core.common.Cools; -import com.core.common.DateUtils; -import com.core.common.SnowflakeIdWorker; +import com.baomidou.mybatisplus.mapper.Wrapper; +import com.core.common.*; import com.core.exception.CoolException; import com.zy.asrs.entity.*; import com.zy.asrs.entity.param.CombParam; import com.zy.asrs.entity.param.MobileAdjustParam; +import com.zy.asrs.entity.param.OffSaleParam; import com.zy.asrs.entity.param.OpenOrderPakinParam; +import com.zy.asrs.mapper.ManLocDetlMapper; +import com.zy.asrs.mapper.OrderDetlMapper; import com.zy.asrs.service.*; +import com.zy.asrs.utils.MatUtils; +import com.zy.asrs.utils.SaasUtils; import com.zy.common.constant.MesConstant; import com.zy.common.entity.Parameter; import com.zy.common.model.DetlDto; import com.zy.common.model.MesCombParam; +import com.zy.common.service.CommonService; import com.zy.common.utils.HttpHandler; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import javax.annotation.Resource; +import java.math.BigDecimal; import java.util.ArrayList; import java.util.Date; import java.util.Iterator; @@ -40,6 +46,10 @@ private MatService matService; @Autowired private WaitPakinService waitPakinService; + + @Resource + private WaitPakinLogService waitPakinLogService; + @Autowired private OrderService orderService; @Autowired @@ -56,6 +66,201 @@ private OpenService openService; @Autowired private SnowflakeIdWorker snowflakeIdWorker; + @Autowired + private ApiLogService apiLogService; + @Autowired + private BasCrnpService basCrnpService; + @Autowired + private LocMastService locMastService; + @Autowired + private LocDetlService locDetlService; + @Autowired + private StaDescService staDescService; + @Autowired + private CommonService commonService; + @Autowired + private NodeService nodeService; + @Autowired + private ManLocDetlService manLocDetlService; + @Autowired + private ManLocDetlMapper manLocDetlMapper; + + @Resource + private OrderDetlMapper orderDetlMapper; + + @Override + @Transactional + public R WarehouseOut(CombParam combParam, Long userId) { + + //鏌ヨ搴撳瓨鏁版嵁 + for (CombParam.CombMat combMat : combParam.getCombMats()) { + ManLocDetl locDetl = manLocDetlService.selectOne(new EntityWrapper<ManLocDetl>() + .eq("loc_no", combParam.getLocno()) + .eq("zpallet", combMat.getZpallet()) + .eq("matnr", combMat.getMatnr()) +// .eq(LocDetl::getBatch, combMat.getBatch()) + ); + if (Cools.isEmpty(locDetl)) { + return R.error("鏈煡璇㈠埌搴撳瓨鏁版嵁"); + } + if (combMat.getAnfme() > locDetl.getAnfme()) { + return R.error("涓嬫灦鏁伴噺閿欒锛岃秴鍑哄簱瀛樻暟閲�"); + } + if (!Cools.isEmpty(combParam.getOrderNo())) { + Order order = orderService.selectByNo(combParam.getOrderNo()); + if (Cools.isEmpty(order)) { + continue; + } + if (order.getSettle() == 1) { + orderService.updateSettle(order.getId(), 2L, userId); + } + OrderDetl orderDetl = orderDetlService.selectItem(order.getId(), combMat.getMatnr(), combMat.getBatch()); + if (Cools.isEmpty(orderDetl)) { + continue; + } + if (orderDetl.getAnfme() < orderDetl.getWorkQty() + combMat.getAnfme()) { + combMat.setAnfme(orderDetl.getAnfme() - orderDetl.getWorkQty()); + } + // 淇敼璁㈠崟鏄庣粏浣滀笟鏁伴噺 + if (orderDetlMapper.increaseWorkQtyByOrderNo(combParam.getOrderNo(), combMat.getMatnr(), combMat.getBatch(), combMat.getAnfme()) <= 0) { + throw new CoolException("淇敼鍗曟嵁鏄庣粏宸ヤ綔鏁伴噺澶辫触"); + } + // 淇敼璁㈠崟鏄庣粏瀹屾垚鏁伴噺 + if (!orderDetlService.increase(order.getId(), combMat.getMatnr(), combMat.getBatch(), combMat.getAnfme())) { + throw new CoolException("淇敼鍗曟嵁鏄庣粏瀹屾垚鏁伴噺澶辫触"); + } + // 淇敼璁㈠崟鐘舵�� 浣滀笟涓� ===>> 宸插畬鎴� + orderService.checkComplete(combParam.getOrderNo()); + } + try { + double i = 0.0; + double j = locDetl.getAnfme(); + //澶勭悊搴撳瓨淇℃伅 + if (combMat.getAnfme().equals(locDetl.getAnfme())) { + //搴撳瓨鐩哥瓑鍒犻櫎鏁版嵁 + manLocDetlMapper.deleteLocNo0(combParam.getLocno(), combMat.getMatnr()); + int count = manLocDetlMapper.selectCount(new EntityWrapper<ManLocDetl>().eq("loc_no", combParam.getLocno())); + if (count == 0) { + Node node = nodeService.selectByUuid(combParam.getLocno()); + node.setUpdateTime(new Date()); + node.setUpdateBy(userId); + node.setBarcode(""); + nodeService.updateById(node); + } + } else { + BigDecimal subtract = BigDecimal.valueOf(locDetl.getAnfme()).subtract(BigDecimal.valueOf(combMat.getAnfme())); + i = subtract.byteValue(); + locDetl.setAnfme(subtract.doubleValue()); + // 鏇存柊搴撳瓨 + manLocDetlMapper.updateAnfme(subtract.doubleValue(), combParam.getLocno(), combMat.getMatnr(), combMat.getBatch()); + } + // 璁板綍鏃ュ織 + SaasUtils.insertLog(1, combParam.getLocno(), combMat.getMatnr(), combMat.getAnfme(), userId,combMat.getBatch()); + } catch (Exception e) { + throw new CoolException("鏇存柊搴撳瓨鏁版嵁鍑洪敊" + e.getMessage()); + } + } + return R.ok(); + } + + @Override + @Transactional + public R WarehouseIn(String locNo, String barcode, Long userId) { + + //鏌ヨ缁勬墭鏁版嵁 + List<WaitPakin> list = waitPakinService.selectList(new EntityWrapper<WaitPakin>().eq("zpallet", barcode)); + if (Cools.isEmpty(list)) { + return R.error("鏈壘鍒扮粍鎵樹俊鎭�"); + } + Date now = new Date(); + + //鎻掑叆搴撳瓨鏁版嵁 + for (WaitPakin waitPakin : list) { + + Mat mat = matService.selectOne(new EntityWrapper<Mat>() + .eq("matnr", waitPakin.getMatnr())); + + ManLocDetl locDetl1 = manLocDetlService.selectOne(new EntityWrapper<ManLocDetl>().eq("loc_no", locNo).eq("matnr", waitPakin.getMatnr()). + eq("batch", waitPakin.getBatch())); + + Node node = nodeService.selectByUuid(locNo); + if (Cools.isEmpty(node)) { + throw new CoolException(locNo + ":搴撲綅涓嶅瓨鍦�"); + } + if (!Cools.isEmpty(locDetl1)) { + locDetl1.setAnfme(waitPakin.getAnfme() + waitPakin.getAnfme()); + locDetl1.setUpdateBy(userId); + locDetl1.setModiTime(now); + manLocDetlService.update(locDetl1, new EntityWrapper<ManLocDetl>().eq("loc_no", locNo).eq("matnr", waitPakin.getMatnr()). + eq("batch", waitPakin.getBatch())); + } else { + ManLocDetl manLocDetl = new ManLocDetl(); + manLocDetl.setLocNo(locNo); +// manLocDetl.setBarcode(barcode); + manLocDetl.setZpallet(barcode); + manLocDetl.setNodeId(node.getId()); + manLocDetl.setMaktx(mat.getMaktx()); + manLocDetl.setMatnr(mat.getMatnr()); + manLocDetl.setSpecs(mat.getSpecs()); + manLocDetl.setBatch(Cools.isEmpty(waitPakin.getBatch()) ? "" : waitPakin.getBatch()); + manLocDetl.setAnfme(waitPakin.getAnfme()); + manLocDetl.setCreateBy(userId); + manLocDetl.setCreateTime(now); + manLocDetl.setUpdateBy(userId); + manLocDetl.setModiTime(now); + if (!manLocDetlService.insert(manLocDetl)) { + throw new CoolException("鍟嗗搧涓婃灦澶辫触锛�"); + } + + // 鏇存柊搴撲綅鏉$爜 + node.setBarcode(barcode); + node.setUpdateBy(userId); + node.setUpdateTime(now); + nodeService.updateById(node); + } + + // 璁板綍鏃ュ織 + SaasUtils.insertLog(0, locNo, waitPakin.getMatnr(), waitPakin.getAnfme(), userId,waitPakin.getBatch()); + + //鏄惁灞炰簬璁㈠崟鏁版嵁 +// if (!Cools.isEmpty(waitPakin.getOrderNo())){ +// Order order = orderService.selectByNo(waitPakin.getOrderNo(), hostId); +// if (Cools.isEmpty(order)){ +// continue; +// } +// OrderDetl orderDetl = orderDetlService.selectItem(order.getId(), waitPakin.getMatnr(), waitPakin.getBatch(),hostId); +// if (Cools.isEmpty(orderDetl)){ +// continue; +// } +// // 淇敼璁㈠崟鏄庣粏瀹屾垚鏁伴噺 +// if (!orderDetlService.increase(order.getId(), hostId, waitPakin.getMatnr(), waitPakin.getBatch(), waitPakin.getAnfme())) { +// throw new CoolException("淇敼鍗曟嵁鏄庣粏鏁伴噺澶辫触"); +// } +// // 淇敼璁㈠崟鐘舵�� 浣滀笟涓� ===>> 宸插畬鎴� +// orderService.checkComplete(waitPakin.getOrderNo(), hostId); +// +// } + + // 鏇存柊鍏ュ簱宸ヤ綔妗� + waitPakin.setLocNo(locNo); + waitPakin.setIoStatus("Y"); + waitPakin.setModiUser(userId); + waitPakin.setModiTime(now); + waitPakinService.update(waitPakin,new EntityWrapper<WaitPakin>().eq("zpallet", barcode).eq("matnr",waitPakin.getMatnr()) + .eq("batch",waitPakin.getBatch())); + + // 淇濆瓨鍏ュ簱閫氱煡妗e巻鍙叉。 + if (!waitPakinLogService.save(barcode)) { + throw new CoolException("淇濆瓨缁勬墭鏁版嵁澶辫触"); + } + // 鍒犻櫎鍏ュ簱閫氱煡妗� + if (!waitPakinService.delete(new EntityWrapper<WaitPakin>().eq("zpallet", barcode))) { + throw new CoolException("鍒犻櫎缁勬墭鏁版嵁澶辫触"); + } + } + + return R.ok("涓婃灦鎴愬姛"); + } @Override @Transactional @@ -63,11 +268,29 @@ if (Cools.isEmpty(param.getBarcode(), param.getCombMats())) { throw new CoolException(BaseRes.PARAM); } + if(param.getCombMats().size()>1){ + throw new CoolException("璇锋彁鍙栦竴涓晢鍝侊紝鎴栬�呭埛鏂伴噸鏂扮粍鎵橈紒"); + } // 鍒ゆ柇鏄惁鏈夌浉鍚屾潯鐮佺殑鏁版嵁 if (waitPakinService.selectCount(new EntityWrapper<WaitPakin>(). eq("zpallet", param.getBarcode()).eq("io_status", "N")) > 0) { throw new CoolException(param.getBarcode() + "鏁版嵁姝e湪杩涜鍏ュ簱"); } + + if(param.getBarcode().length()!=8){ + throw new CoolException("鏉$爜闀垮害涓嶆槸8浣�===>>" + param.getBarcode()); + } + if (param.getCombMats().size()>1){ + throw new CoolException("涓嶅厑璁告贩鏂�===>>" + param.getBarcode()); + } + + int countLoc = locDetlService.selectCount(new EntityWrapper<LocDetl>().eq("zpallet",param.getBarcode())); + int countWrk = wrkDetlService.selectCount(new EntityWrapper<WrkDetl>().eq("zpallet",param.getBarcode())); + int countwait = waitPakinService.selectCount(new EntityWrapper<WaitPakin>().eq("zpallet",param.getBarcode())); + if (countLoc > 0 || countWrk > 0 || countwait > 0) { + throw new CoolException("缁勬墭妗�/宸ヤ綔妗�/搴撳瓨鏉$爜鏁版嵁宸插瓨鍦�===>>" + param.getBarcode()); + } + Date now = new Date(); // 鏃犲崟缁勬墭 @@ -110,7 +333,7 @@ // 鍏宠仈缁勬墭 } else { Order order = orderService.selectByNo(param.getOrderNo()); - if (order.getSettle() > 2) { + if (Cools.isEmpty(order) || order.getSettle() > 2) { throw new CoolException("鍗曟嵁缂栧彿宸茶繃鏈�"); } // 鐢熸垚鍏ュ簱閫氱煡妗� @@ -122,9 +345,9 @@ if (elem.getAnfme() > orderDetl.getEnableQty()) { throw new CoolException(orderDetl.getMatnr() + "鍏ュ簱鏁伴噺涓嶅悎娉�"); } - // 淇敼璁㈠崟鏄庣粏鏁伴噺 - if (!orderDetlService.increase(order.getId(), elem.getMatnr(), elem.getBatch(), elem.getAnfme())) { - throw new CoolException("淇敼鍗曟嵁鏄庣粏鏁伴噺澶辫触"); + // 淇敼璁㈠崟浣滀笟鏁伴噺 + if (!orderDetlService.increaseWorkQty(order.getId(), elem.getMatnr(), elem.getBatch(), elem.getAnfme())) { + throw new CoolException("淇敼鍗曟嵁浣滀笟鏁伴噺澶辫触"); } DetlDto detlDto = new DetlDto(elem.getMatnr(), elem.getBatch(), elem.getAnfme()); @@ -144,7 +367,7 @@ WaitPakin waitPakin = new WaitPakin(); waitPakin.sync(mat); waitPakin.setOrderNo(order.getOrderNo()); // 鍗曟嵁缂栧彿 - waitPakin.setBatch(detlDto.getBatch()); // 鎵瑰彿 + waitPakin.setBatch(detlDto.getBatch()); // 搴忓垪鐮� waitPakin.setZpallet(param.getBarcode()); // 鎵樼洏鐮� waitPakin.setIoStatus("N"); // 鍏ュ嚭鐘舵�� waitPakin.setAnfme(detlDto.getAnfme()); // 鏁伴噺 @@ -161,6 +384,86 @@ } } + + // 鍟嗗搧涓婃灦 + @Override + public void onSale(CombParam param, Long userId) { + + Date now = new Date(); + // 鑾峰彇搴撲綅鍙� + String locno = param.getLocno(); + Node node = nodeService.selectByUuid(locno); + if (Cools.isEmpty(node)) { + throw new CoolException(param.getLocno() + ":搴撲綅涓嶅瓨鍦�"); + } + + String barcode = param.getBarcode(); + if (Cools.isEmpty(barcode)) { + throw new CoolException("鏉$爜涓嶈兘涓虹┖锛�"); + } + + // 鑾峰彇鍟嗗搧鍒楄〃 + for(CombParam.CombMat combMat : param.getCombMats()){ + Mat mat = matService.selectByMatnr(combMat.getMatnr()); + if (Cools.isEmpty(mat)){ + throw new CoolException(combMat.getMatnr() + ":鍟嗗搧妗f涓嶅瓨鍦紒"); + } + if (Cools.isEmpty(combMat.getAnfme()) || combMat.getAnfme()==0){ + throw new CoolException(combMat.getMatnr() + ":鍟嗗搧鏁伴噺鏈夎锛�"); + } + + ManLocDetl manLocDetl = new ManLocDetl(); + manLocDetl.setLocNo(locno); +// manLocDetl.setBarcode(barcode); + manLocDetl.setZpallet(barcode); + manLocDetl.setNodeId(node.getId()); + manLocDetl.setMaktx(mat.getMaktx()); + manLocDetl.setMatnr(mat.getMatnr()); + manLocDetl.setSpecs(mat.getSpecs()); + manLocDetl.setBatch(Cools.isEmpty(combMat.getBatch()) ? "" : combMat.getBatch()); + manLocDetl.setAnfme(combMat.getAnfme()); + manLocDetl.setCreateBy(userId); + manLocDetl.setCreateTime(now); + manLocDetl.setUpdateBy(userId); + manLocDetl.setModiTime(now); + if (!manLocDetlService.insert(manLocDetl)) { + throw new CoolException("鍟嗗搧涓婃灦澶辫触锛�"); + } + + // 鏇存柊搴撲綅鏉$爜 + node.setBarcode(barcode); + node.setUpdateBy(userId); + node.setUpdateTime(now); + nodeService.updateById(node); + SaasUtils.insertLog(0,manLocDetl.getLocNo(), manLocDetl.getMatnr(),combMat.getAnfme(),userId,manLocDetl.getBatch()); + + } + } + + // 鍟嗗搧涓嬫灦 + @Override + public void offSale(OffSaleParam offSaleParam, Long userId) { + ManLocDetl manLocDetl = manLocDetlMapper.selectLocNo0(offSaleParam.getLocNo(), offSaleParam.getMatnr()); + if (Cools.isEmpty(manLocDetl)){ + throw new CoolException("鏃犳鍟嗗搧锛�"); + } + double anfme = manLocDetl.getAnfme() - offSaleParam.getAnfme(); + if (anfme < 0) { + throw new CoolException("鍟嗗搧搴撳瓨涓嶈冻锛�"); + } else if (anfme == 0){ + SaasUtils.insertLog(1,manLocDetl.getLocNo(), manLocDetl.getMatnr(),offSaleParam.getAnfme(),userId,manLocDetl.getBatch()); + manLocDetlMapper.deleteLocNo0(offSaleParam.getLocNo(), offSaleParam.getMatnr()); + // 娓呯┖搴撲綅鏉$爜 + Node node = nodeService.selectByUuid(offSaleParam.getLocNo()); + node.setUpdateTime(new Date()); + node.setUpdateBy(userId); + node.setBarcode(""); + } + manLocDetlMapper.updateAnfme0(anfme,manLocDetl.getNodeId()); + } + + // 鏌ユ壘鍟嗗搧 + @Override @Transactional @@ -271,7 +574,10 @@ throw new CoolException(elem.getMatnr() + "鏉$爜宸蹭笅绾匡紝璇锋鏌ワ紒"); } } - DetlDto detlDto = new DetlDto(elem.getMatnr(), elem.getBatch(), elem.getAnfme()); + Mat analyse = MatUtils.analyseMat(elem.getMatnr()); + // 鏉$爜銆佺墿鏂欎唬鐮併�佸簭鍒楀彿銆佹暟閲� + DetlDto detlDto = new DetlDto(elem.getMatnr(), analyse.getMatnr(), analyse.getBarcode(), elem.getAnfme()); +// DetlDto detlDto = new DetlDto(elem.getMatnr(), elem.getBatch(), elem.getAnfme()); if (DetlDto.has(detlDtos, detlDto)) { DetlDto one = DetlDto.find(detlDtos, detlDto.getMatnr(), detlDto.getBatch()); assert one != null; @@ -284,14 +590,18 @@ if (packDown) { MesCombParam mesCombParam = new MesCombParam(); mesCombParam.setZpallet(param.getBarcode()); - mesCombParam.setCombTime(DateUtils.convert(now)); + mesCombParam.setPakinTime(DateUtils.convert(now)); mesCombParam.setLgort("5008"); + mesCombParam.setPlantCode("5000"); + mesCombParam.setFromCode("5012-20"); + mesCombParam.setStationCode("JJQ-PFZPDB-XX"); for (DetlDto detlDto : detlDtos) { - mesCombParam.getList().add(new MesCombParam.Detl(detlDto.getMatnr(), detlDto.getAnfme())); + mesCombParam.getList().add(new MesCombParam.Detl(detlDto.getOrderNo(), detlDto.getAnfme())); } - String response; + String response = ""; + boolean success = false; try { - response = new HttpHandler.Builder() + response = new HttpHandler.Builder() .setUri(MesConstant.URL) .setPath(MesConstant.PACK_DOWN_URL) .setJson(JSON.toJSONString(mesCombParam)) @@ -299,8 +609,8 @@ .doPost(); JSONObject jsonObject = JSON.parseObject(response); if (jsonObject.getInteger("code").equals(200)) { - log.info("璇锋眰鎺ュ彛鎴愬姛锛侊紒锛�"); - } else if (jsonObject.getInteger("code").equals(500)) { + success = true; + } else if (jsonObject.getInteger("code").equals(500)) { log.error("璇锋眰鎺ュ彛澶辫触锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", MesConstant.URL+MesConstant.PACK_DOWN_URL, JSON.toJSONString(mesCombParam), response); throw new CoolException(jsonObject.getString("msg")); } else { @@ -309,8 +619,20 @@ } } catch (Exception e) { log.error("fail", e); - e.printStackTrace(); - throw new CoolException("涓婃姤mes绯荤粺澶辫触"); + throw new CoolException(e.getMessage()); + } finally { + try { + // 淇濆瓨鎺ュ彛鏃ュ織 + apiLogService.save( + "鎵撳寘涓嬬嚎甯墭涓婃姤", + MesConstant.URL + MesConstant.PACK_DOWN_URL, + null, + "127.0.0.1", + JSON.toJSONString(mesCombParam), + response, + success + ); + } catch (Exception e) { log.error("", e); } } } @@ -340,9 +662,9 @@ if (detlDto.getAnfme() > orderDetl.getEnableQty()) { throw new CoolException(orderDetl.getMatnr() + "鍏ュ簱鏁伴噺涓嶅悎娉�"); } - // 淇敼璁㈠崟鏄庣粏鏁伴噺 - if (!orderDetlService.increase(order.getId(), detlDto.getMatnr(), detlDto.getBatch(), detlDto.getAnfme())) { - throw new CoolException("淇敼鍗曟嵁鏄庣粏鏁伴噺澶辫触"); + // 淇敼璁㈠崟浣滀笟鏁伴噺 + if (!orderDetlService.increaseWorkQty(order.getId(), detlDto.getMatnr(), detlDto.getBatch(), detlDto.getAnfme())) { + throw new CoolException("淇敼鍗曟嵁浣滀笟鏁伴噺澶辫触"); } // 淇濆瓨鍏ュ簱閫氱煡妗� @@ -366,7 +688,7 @@ throw new CoolException("淇濆瓨鍏ュ簱閫氱煡妗eけ璐�"); } // 淇敼鎵撳寘鏁版嵁鐘舵�� - Pack pack = packService.selectByBarcode(detlDto.getMatnr()); + Pack pack = packService.selectByBarcode(detlDto.getOrderNo()); pack.setSettle(2L); pack.setUpdateTime(now); pack.setUpdateBy(userId); @@ -378,4 +700,141 @@ } } + @Override + @Transactional + public void pakoutByOrder(JSONObject param, Long userId) { + Integer staNo = param.containsKey("staNo") ? Integer.parseInt(param.get("staNo").toString()) : 0; + String orderNo = param.containsKey("orderNo") ? param.get("orderNo").toString() : ""; + + BasDevp sta = basDevpService.checkSiteStatus(staNo); + //鏍规嵁璁㈠崟鍙风敓鎴愬嚭搴撲换鍔″伐浣滄。 + Order order = orderService.selectOne(new EntityWrapper<Order>().eq("order_no", orderNo)); + if (order.getSettle() != 1 && order.getSettle() != 2){ + throw new CoolException("璇ヨ鍗曞凡澶勭悊"); + } + + List<OrderDetl> orderDetls = orderDetlService.selectList(new EntityWrapper<OrderDetl>().eq("order_no", orderNo)); + Date now = new Date(); + for(OrderDetl orderDetl : orderDetls){ + //鏌ヨ鎵�鏈夊簱浣嶇姸鎬佷负F鐨勫簱浣嶄俊鎭� + List<LocDetl> locDetls = locDetlService.queryStock(orderDetl.getMatnr(),orderDetl.getBatch(),null,null); + if (locDetls.size() == 0) { + throw new CoolException("搴撳瓨涓病鏈夎鐗╂枡"); + } + for(LocDetl locDetl : locDetls){ + //濡傛灉璇ュ簱浣嶅嚭搴撹矾绾挎墍鐢ㄧ殑鍫嗗灈鏈簅ut_enable涓嶄负Y,璺宠繃璇ュ惊鐜� + LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>() + .eq("loc_no", locDetl.getLocNo())); + if (Cools.isEmpty(locMast)) { + continue; + } + BasCrnp crn_no = basCrnpService.selectOne(new EntityWrapper<BasCrnp>() + .eq("crn_no", locMast.getCrnNo())); + if (Cools.isEmpty(crn_no) || !crn_no.getOutEnable().equals("Y")){ + continue; + } + + //鍙嚭搴撴暟閲� = 璁㈠崟鏁伴噺 - 浣滀笟涓暟閲� + Double outQty = orderDetl.getAnfme() - orderDetl.getWorkQty(); + if(outQty <= 0){ + break; + } + // 鍒ゆ柇鍏ュ嚭搴撶被鍨嬶細101.鍏ㄦ澘鍑哄簱 or 103.鎷f枡鍑哄簱 + Double sumCount = locDetlService.getLocDetlSumQty(locDetl.getLocNo()); + Double curOutQty = outQty >= locDetl.getAnfme() ? locDetl.getAnfme() : outQty; //鏈鍑哄簱閲� + int ioType = sumCount <= curOutQty ? 101 : 103; + + stockOut(orderDetl, sta, locDetl, curOutQty, ioType, userId, now); + order.setSettle(2L); + order.setUpdateBy(userId); + order.setUpdateTime(now); + if(!orderService.update(order, new EntityWrapper<Order>().eq("order_no", orderNo))){ + throw new CoolException("鏇存柊璁㈠崟鐘舵�佸け璐�"); + } + orderDetl.setWorkQty(orderDetl.getWorkQty() + curOutQty); + orderDetl.setUpdateBy(userId); + orderDetl.setUpdateTime(now); + Wrapper wrapper = new EntityWrapper<OrderDetl>().eq("order_no", orderNo) + .eq("matnr",orderDetl.getMatnr()); + if(!Cools.isEmpty(orderDetl.getBatch())){ + wrapper.eq("batch", orderDetl.getBatch()); + } + if(!orderDetlService.update(orderDetl, wrapper)){ + throw new CoolException("鏇存柊璁㈠崟鏄庣粏澶辫触"); + } + } + + } + } + + @Override + @Transactional + public void stockOut(OrderDetl orderDetl, BasDevp staNo, LocDetl locDetl, + Double curOutQty, Integer ioType, Long userId, Date now) { + // 鑾峰彇搴撲綅 + LocMast locMast = locMastService.selectById(locDetl.getLocNo()); + // 鑾峰彇璺緞 + Wrapper<StaDesc> wrapper = new EntityWrapper<StaDesc>() + .eq("type_no", ioType) + .eq("stn_no", staNo.getDevNo()) + .eq("crn_no", locMast.getCrnNo()); + + StaDesc staDesc = staDescService.selectOne(wrapper); + if (Cools.isEmpty(staDesc)) { + throw new CoolException("鍑哄簱璺緞涓嶅瓨鍦�"); + } + // 鐢熸垚宸ヤ綔鍙� + int workNo = commonService.getWorkNo(2); + // 鐢熸垚宸ヤ綔妗� + WrkMast wrkMast = new WrkMast(); + wrkMast.setWrkNo(workNo); + wrkMast.setIoTime(now); + wrkMast.setWrkSts(11L); // 宸ヤ綔鐘舵�侊細11.鐢熸垚鍑哄簱ID + wrkMast.setIoType(ioType); // 鍏ュ嚭搴撶姸鎬� + wrkMast.setIoPri(13D); // 浼樺厛绾э細13 + wrkMast.setCrnNo(locMast.getCrnNo()); + wrkMast.setSourceStaNo(staDesc.getCrnStn()); // 婧愮珯 + wrkMast.setStaNo(staDesc.getStnNo()); // 鐩爣绔� + wrkMast.setSourceLocNo(locDetl.getLocNo()); // 婧愬簱浣� + wrkMast.setFullPlt("Y"); // 婊℃澘锛歒 + wrkMast.setPicking("N"); // 鎷f枡 + wrkMast.setExitMk("N"); // 閫�鍑� + wrkMast.setEmptyMk("N"); // 绌烘澘 + wrkMast.setLinkMis("N"); + wrkMast.setAppeUser(userId); // 鎿嶄綔浜哄憳鏁版嵁 + wrkMast.setAppeTime(now); + wrkMast.setModiUser(userId); + wrkMast.setModiTime(now); + wrkMast.setBarcode(locMast.getBarcode()); + if (!wrkMastService.insert(wrkMast)) { + throw new CoolException("淇濆瓨宸ヤ綔妗eけ璐ワ紝鍑哄簱搴撲綅鍙凤細" + locDetl.getLocNo()); + } + + WrkDetl wrkDetl = new WrkDetl(); + wrkDetl.sync(locDetl); + wrkDetl.setWrkNo(workNo); + wrkDetl.setIoTime(now); + wrkDetl.setAnfme(curOutQty); // 鏁伴噺 + wrkDetl.setOrderNo(orderDetl.getOrderNo()); + wrkDetl.setAppeTime(now); + wrkDetl.setAppeUser(userId); + wrkDetl.setModiTime(now); + wrkDetl.setModiUser(userId); + if (!wrkDetlService.insert(wrkDetl)) { + throw new CoolException("淇濆瓨宸ヤ綔妗f槑缁嗗け璐�"); + } + + // 淇敼搴撲綅鐘舵��: F.鍦ㄥ簱 ====>>> R.鍑哄簱棰勭害/P.鎷f枡/鐩樼偣/骞舵澘鍑哄簱涓� + locMast = locMastService.selectById(locDetl.getLocNo()); + if (locMast.getLocSts().equals("F")) { + locMast.setLocSts(ioType == 101 ? "R" : "P"); + locMast.setModiUser(userId); + locMast.setModiTime(new Date()); + if (!locMastService.updateById(locMast)) { + throw new CoolException("棰勭害搴撲綅鐘舵�佸け璐ワ紝搴撲綅鍙凤細" + locDetl.getLocNo()); + } + } else { + throw new CoolException(locDetl.getLocNo() + "搴撲綅涓嶆槸鍦ㄥ簱鐘舵��"); + } + } } -- Gitblit v1.9.1