From 9f1da5a5ad0cdc826ca8dcbb5b9690a6a17208ee Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期一, 20 三月 2023 13:05:33 +0800
Subject: [PATCH] 入出库对外接口增加weight字段

---
 src/main/java/com/zy/asrs/service/impl/MobileServiceImpl.java |  507 ++++++++++++++++++++++++++++++++++++++------------------
 1 files changed, 344 insertions(+), 163 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 34c46a2..7450d05 100644
--- a/src/main/java/com/zy/asrs/service/impl/MobileServiceImpl.java
+++ b/src/main/java/com/zy/asrs/service/impl/MobileServiceImpl.java
@@ -9,13 +9,17 @@
 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.service.*;
 import com.zy.asrs.utils.MatUtils;
+import com.zy.common.CodeRes;
 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;
@@ -63,6 +67,17 @@
     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;
+
 
     @Override
     @Transactional
@@ -75,6 +90,28 @@
                 eq("zpallet", param.getBarcode()).eq("io_status", "N")) > 0) {
             throw new CoolException(param.getBarcode() + "鏁版嵁姝e湪杩涜鍏ュ簱");
         }
+
+        int countLoc = locDetlService.selectCount(new EntityWrapper<LocDetl>().eq("zpallet",param.getBarcode()));
+        WrkMast wrkMast = wrkMastService.selectByBarcode(param.getBarcode());
+        if (wrkMast != null && wrkMast.getIoType() < 100){
+            throw new CoolException("宸ヤ綔妗�/搴撳瓨鏉$爜鏁版嵁宸插瓨鍦�===>>" + param.getBarcode());
+
+        }
+        if (countLoc > 0 ) {
+            throw new CoolException("宸ヤ綔妗�/搴撳瓨鏉$爜鏁版嵁宸插瓨鍦�===>>" + param.getBarcode());
+        }
+
+
+        //璁剧疆闈瀗ull鎵瑰彿锛�
+        for (CombParam.CombMat combMat : param.getCombMats()) {
+            if (combMat.getBatch() == null){
+                combMat.setBatch("");
+            }
+        }
+
+
+
+
         Date now = new Date();
 
         // 鏃犲崟缁勬墭
@@ -116,16 +153,30 @@
             }
         // 鍏宠仈缁勬墭
         } else {
+            for (CombParam.CombMat combMat : param.getCombMats()) {
+                Integer sum = orderDetlService.sameOrderComb(param.getOrderNo(), combMat.getMatnr(),combMat.getBatch());
+                OrderDetl orderDetl = orderDetlService.selectItem(param.getOrderNo(), combMat.getMatnr(), combMat.getBatch());
+                if (orderDetl == null) {
+                    throw new CoolException("鎵句笉鍒扮粍鎵樼殑鍗曟嵁鏄庣粏");
+
+                }
+                Double anfme = orderDetl.getAnfme();
+                if ( anfme > (anfme - sum)) {
+                    throw new CoolException("缁勬墭鏁伴噺宸茶秴鍑鸿鍗曢渶姹傞噺锛岃妫�鏌ユ槸鍚︽湁鍏朵粬鐨勭粍鎵樺凡瀹屾垚");
+                }
+            }
             Order order = orderService.selectByNo(param.getOrderNo());
             if (order.getSettle() > 2) {
                 throw new CoolException("鍗曟嵁缂栧彿宸茶繃鏈�");
             }
             // 鐢熸垚鍏ュ簱閫氱煡妗�
             List<DetlDto> detlDtos = new ArrayList<>();
-            param.getCombMats().forEach(elem -> {
-
+            for (CombParam.CombMat elem : param.getCombMats()) {
                 // 璁㈠崟鏄庣粏鏁伴噺鏍¢獙
                 OrderDetl orderDetl = orderDetlService.selectItem(order.getId(), elem.getMatnr(), elem.getBatch());
+                if(orderDetl == null){
+                    throw new CoolException("璇ュ崟鎹腑涓嶅瓨鍦ㄨ鐗╂枡鏄庣粏锛�" + elem);
+                }
                 if (elem.getAnfme() > orderDetl.getEnableQty()) {
                     throw new CoolException(orderDetl.getMatnr() + "鍏ュ簱鏁伴噺涓嶅悎娉�");
                 }
@@ -142,7 +193,7 @@
                 } else {
                     detlDtos.add(detlDto);
                 }
-            });
+            }
             for (DetlDto detlDto : detlDtos) {
                 Mat mat = matService.selectByMatnr(detlDto.getMatnr());
                 if (Cools.isEmpty(mat)) {
@@ -168,6 +219,62 @@
         }
 
     }
+
+    // 鍟嗗搧涓婃灦
+    @Override
+    public void onSale(CombParam param) {
+        Date now = new Date();
+        // 鑾峰彇搴撲綅鍙�
+        String locno = param.getLocno();
+        Node node = nodeService.selectByUuid(locno);
+        if (Cools.isEmpty(node)) {
+            throw new CoolException(param.getLocno() + ":搴撲綅涓嶅瓨鍦�");
+        }
+
+        // 鑾峰彇鍟嗗搧鍒楄〃
+        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() + ":鍟嗗搧鏁伴噺鏈夎锛�");
+            }
+            if (Cools.isEmpty(combMat.getBatch())){
+//                throw new CoolException(combMat.getMatnr() + ":鍟嗗搧鎵瑰彿鏈夎锛�");
+            }
+            ManLocDetl manLocDetl = new ManLocDetl();
+            manLocDetl.setLocNo(locno);
+            manLocDetl.setNodeId(node.getId());
+            manLocDetl.setMaktx(mat.getMaktx());
+            manLocDetl.setMatnr(mat.getMatnr());
+            manLocDetl.setBatch(Cools.isEmpty(combMat.getBatch()) ? "" : combMat.getBatch());
+            manLocDetl.setAnfme(combMat.getAnfme());
+            manLocDetl.setModiTime(now);
+            if (!manLocDetlService.insert(manLocDetl)) {
+                throw new CoolException("鍟嗗搧涓婃灦澶辫触锛�");
+            }
+        }
+    }
+
+    // 鍟嗗搧涓嬫灦
+    @Override
+    public void offSale(OffSaleParam offSaleParam) {
+        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){
+            manLocDetlMapper.deleteLocNo0(offSaleParam.getLocNo(), offSaleParam.getMatnr());
+        }
+        manLocDetlMapper.updateAnfme0(anfme,manLocDetl.getNodeId());
+    }
+
+    // 鏌ユ壘鍟嗗搧
+
 
     @Override
     @Transactional
@@ -247,162 +354,162 @@
 
     }
 
-    @Override
-    @Transactional
-    public void packComb(CombParam param, Long userId) {
-        if (Cools.isEmpty(param.getBarcode(), param.getCombMats())) {
-            throw new CoolException(BaseRes.PARAM);
-        }
-        // 鍒ゆ柇鏄惁鏈夌浉鍚屾潯鐮佺殑鏁版嵁
-        if (waitPakinService.selectCount(new EntityWrapper<WaitPakin>().
-                eq("zpallet", param.getBarcode()).eq("io_status", "N")) > 0) {
-            throw new CoolException(param.getBarcode() + "鏁版嵁姝e湪杩涜鍏ュ簱");
-        }
-        Date now = new Date();
-
-        boolean packDown = Parameter.get().getPackDown().equals("true");
-
-        // 鏃犲崟缁勬墭
-        if (Cools.isEmpty(param.getOrderNo())) {
-
-            // 鐢熸垚鍏ュ簱閫氱煡妗�
-            List<DetlDto> detlDtos = new ArrayList<>();
-            param.getCombMats().forEach(elem -> {
-                // 鎵撳寘涓婄嚎鏁版嵁鏍¢獙
-                if (packDown) {
-                    Pack pack = packService.selectByBarcode(elem.getMatnr());
-                    if (pack == null) {
-                        throw new CoolException(elem.getMatnr() + "鏉$爜鍐椾綑锛岃妫�鏌ワ紒");
-                    }
-                    if (pack.getSettle() != 1) {
-                        throw new CoolException(elem.getMatnr() + "鏉$爜宸蹭笅绾匡紝璇锋鏌ワ紒");
-                    }
-                }
-                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;
-                    one.setAnfme(one.getAnfme() + detlDto.getAnfme());
-                } else {
-                    detlDtos.add(detlDto);
-                }
-            });
-
-            if (packDown) {
-                MesCombParam mesCombParam = new MesCombParam();
-                mesCombParam.setZpallet(param.getBarcode());
-                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.getOrderNo(), detlDto.getAnfme()));
-                }
-                String response = "";
-                boolean success = false;
-                try {
-                    response = new HttpHandler.Builder()
-                            .setUri(MesConstant.URL)
-                            .setPath(MesConstant.PACK_DOWN_URL)
-                            .setJson(JSON.toJSONString(mesCombParam))
-                            .build()
-                            .doPost();
-                    JSONObject jsonObject = JSON.parseObject(response);
-                    if (jsonObject.getInteger("code").equals(200)) {
-                        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 {
-                        log.error("璇锋眰鎺ュ彛澶辫触锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", MesConstant.URL+MesConstant.PACK_DOWN_URL, JSON.toJSONString(mesCombParam), response);
-                        throw new CoolException("涓婃姤mes绯荤粺澶辫触");
-                    }
-                } catch (Exception e) {
-                    log.error("fail", e);
-                    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); }
-                }
-
-            }
-
-            // 鐢熸垚鍏ュ簱鍗曟嵁
-            String orderNo = "PACK" + snowflakeIdWorker.nextId();
-            OpenOrderPakinParam openParam = new OpenOrderPakinParam();
-            openParam.setOrderNo(orderNo);
-            openParam.setOrderTime(DateUtils.convert(now));
-            openParam.setOrderType("鎵撳寘鍏ュ簱鍗�");
-            openParam.setOrderDetails(detlDtos);
-            openService.pakinOrderCreate(openParam);
-            Order order = orderService.selectByNo(orderNo);
-            if (null == order) {
-                throw new CoolException("鐢熸垚鍗曟嵁澶辫触");
-            }
-            if (!orderService.updateSettle(order.getId(), 2L, userId)) {
-                throw new CoolException("淇敼鍗曟嵁鐘舵�佸け璐�");
-            }
-
-            // 鐢熸垚鍏ュ簱閫氱煡妗�
-            for (DetlDto detlDto : detlDtos) {
-
-                // 淇敼浣滀笟鏁伴噺 ----------------------------------------
-                // 璁㈠崟鏄庣粏鏁伴噺鏍¢獙
-                OrderDetl orderDetl = orderDetlService.selectItem(order.getId(), detlDto.getMatnr(), detlDto.getBatch());
-                if (detlDto.getAnfme() > orderDetl.getEnableQty()) {
-                    throw new CoolException(orderDetl.getMatnr() + "鍏ュ簱鏁伴噺涓嶅悎娉�");
-                }
-                // 淇敼璁㈠崟浣滀笟鏁伴噺
-                if (!orderDetlService.increaseWorkQty(order.getId(), detlDto.getMatnr(), detlDto.getBatch(), detlDto.getAnfme())) {
-                    throw new CoolException("淇敼鍗曟嵁浣滀笟鏁伴噺澶辫触");
-                }
-
-                // 淇濆瓨鍏ュ簱閫氱煡妗�
-                Mat mat = matService.selectByMatnr(detlDto.getMatnr());
-                if (Cools.isEmpty(mat)) {
-                    throw new CoolException(detlDto.getMatnr() + "鍟嗗搧妗f涓嶅瓨鍦�");
-                }
-                WaitPakin waitPakin = new WaitPakin();
-                waitPakin.sync(mat);
-                waitPakin.setOrderNo(orderNo);
-                waitPakin.setBatch(detlDto.getBatch());
-                waitPakin.setZpallet(param.getBarcode());   // 鎵樼洏鐮�
-                waitPakin.setIoStatus("N");     // 鍏ュ嚭鐘舵��
-                waitPakin.setAnfme(detlDto.getAnfme());  // 鏁伴噺
-                waitPakin.setStatus("Y");    // 鐘舵��
-                waitPakin.setAppeUser(userId);
-                waitPakin.setAppeTime(now);
-                waitPakin.setModiUser(userId);
-                waitPakin.setModiTime(now);
-                if (!waitPakinService.insert(waitPakin)) {
-                    throw new CoolException("淇濆瓨鍏ュ簱閫氱煡妗eけ璐�");
-                }
-                // 淇敼鎵撳寘鏁版嵁鐘舵��
-                Pack pack = packService.selectByBarcode(detlDto.getOrderNo());
-                pack.setSettle(2L);
-                pack.setUpdateTime(now);
-                pack.setUpdateBy(userId);
-                if (!packService.updateById(pack)) {
-                    throw new CoolException("淇敼鎵撳寘鏁版嵁寮傚父");
-                }
-            }
-
-        }
-    }
+//    @Override
+//    @Transactional
+//    public void packComb(CombParam param, Long userId) {
+//        if (Cools.isEmpty(param.getBarcode(), param.getCombMats())) {
+//            throw new CoolException(BaseRes.PARAM);
+//        }
+//        // 鍒ゆ柇鏄惁鏈夌浉鍚屾潯鐮佺殑鏁版嵁
+//        if (waitPakinService.selectCount(new EntityWrapper<WaitPakin>().
+//                eq("zpallet", param.getBarcode()).eq("io_status", "N")) > 0) {
+//            throw new CoolException(param.getBarcode() + "鏁版嵁姝e湪杩涜鍏ュ簱");
+//        }
+//        Date now = new Date();
+//
+//        boolean packDown = Parameter.get().getPackDown().equals("true");
+//
+//        // 鏃犲崟缁勬墭
+//        if (Cools.isEmpty(param.getOrderNo())) {
+//
+//            // 鐢熸垚鍏ュ簱閫氱煡妗�
+//            List<DetlDto> detlDtos = new ArrayList<>();
+//            param.getCombMats().forEach(elem -> {
+//                // 鎵撳寘涓婄嚎鏁版嵁鏍¢獙
+//                if (packDown) {
+//                    Pack pack = packService.selectByBarcode(elem.getMatnr());
+//                    if (pack == null) {
+//                        throw new CoolException(elem.getMatnr() + "鏉$爜鍐椾綑锛岃妫�鏌ワ紒");
+//                    }
+//                    if (pack.getSettle() != 1) {
+//                        throw new CoolException(elem.getMatnr() + "鏉$爜宸蹭笅绾匡紝璇锋鏌ワ紒");
+//                    }
+//                }
+//                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;
+//                    one.setAnfme(one.getAnfme() + detlDto.getAnfme());
+//                } else {
+//                    detlDtos.add(detlDto);
+//                }
+//            });
+//
+//            if (packDown) {
+//                MesCombParam mesCombParam = new MesCombParam();
+//                mesCombParam.setZpallet(param.getBarcode());
+//                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.getOrderNo(), detlDto.getAnfme()));
+//                }
+//                String response = "";
+//                boolean success = false;
+//                try {
+//                    response = new HttpHandler.Builder()
+//                            .setUri(MesConstant.URL)
+//                            .setPath(MesConstant.PACK_DOWN_URL)
+//                            .setJson(JSON.toJSONString(mesCombParam))
+//                            .build()
+//                            .doPost();
+//                    JSONObject jsonObject = JSON.parseObject(response);
+//                    if (jsonObject.getInteger("code").equals(200)) {
+//                        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 {
+//                        log.error("璇锋眰鎺ュ彛澶辫触锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", MesConstant.URL+MesConstant.PACK_DOWN_URL, JSON.toJSONString(mesCombParam), response);
+//                        throw new CoolException("涓婃姤mes绯荤粺澶辫触");
+//                    }
+//                } catch (Exception e) {
+//                    log.error("fail", e);
+//                    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); }
+//                }
+//
+//            }
+//
+//            // 鐢熸垚鍏ュ簱鍗曟嵁
+//            String orderNo = "PACK" + snowflakeIdWorker.nextId();
+//            OpenOrderPakinParam openParam = new OpenOrderPakinParam();
+//            openParam.setOrderNo(orderNo);
+//            openParam.setOrderTime(DateUtils.convert(now));
+//            openParam.setOrderType("鎵撳寘鍏ュ簱鍗�");
+//            openParam.setOrderDetails(detlDtos);
+//            openService.pakinOrderCreate(openParam);
+//            Order order = orderService.selectByNo(orderNo);
+//            if (null == order) {
+//                throw new CoolException("鐢熸垚鍗曟嵁澶辫触");
+//            }
+//            if (!orderService.updateSettle(order.getId(), 2L, userId)) {
+//                throw new CoolException("淇敼鍗曟嵁鐘舵�佸け璐�");
+//            }
+//
+//            // 鐢熸垚鍏ュ簱閫氱煡妗�
+//            for (DetlDto detlDto : detlDtos) {
+//
+//                // 淇敼浣滀笟鏁伴噺 ----------------------------------------
+//                // 璁㈠崟鏄庣粏鏁伴噺鏍¢獙
+//                OrderDetl orderDetl = orderDetlService.selectItem(order.getId(), detlDto.getMatnr(), detlDto.getBatch());
+//                if (detlDto.getAnfme() > orderDetl.getEnableQty()) {
+//                    throw new CoolException(orderDetl.getMatnr() + "鍏ュ簱鏁伴噺涓嶅悎娉�");
+//                }
+//                // 淇敼璁㈠崟浣滀笟鏁伴噺
+//                if (!orderDetlService.increaseWorkQty(order.getId(), detlDto.getMatnr(), detlDto.getBatch(), detlDto.getAnfme())) {
+//                    throw new CoolException("淇敼鍗曟嵁浣滀笟鏁伴噺澶辫触");
+//                }
+//
+//                // 淇濆瓨鍏ュ簱閫氱煡妗�
+//                Mat mat = matService.selectByMatnr(detlDto.getMatnr());
+//                if (Cools.isEmpty(mat)) {
+//                    throw new CoolException(detlDto.getMatnr() + "鍟嗗搧妗f涓嶅瓨鍦�");
+//                }
+//                WaitPakin waitPakin = new WaitPakin();
+//                waitPakin.sync(mat);
+//                waitPakin.setOrderNo(orderNo);
+//                waitPakin.setBatch(detlDto.getBatch());
+//                waitPakin.setZpallet(param.getBarcode());   // 鎵樼洏鐮�
+//                waitPakin.setIoStatus("N");     // 鍏ュ嚭鐘舵��
+//                waitPakin.setAnfme(detlDto.getAnfme());  // 鏁伴噺
+//                waitPakin.setStatus("Y");    // 鐘舵��
+//                waitPakin.setAppeUser(userId);
+//                waitPakin.setAppeTime(now);
+//                waitPakin.setModiUser(userId);
+//                waitPakin.setModiTime(now);
+//                if (!waitPakinService.insert(waitPakin)) {
+//                    throw new CoolException("淇濆瓨鍏ュ簱閫氱煡妗eけ璐�");
+//                }
+//                // 淇敼鎵撳寘鏁版嵁鐘舵��
+//                Pack pack = packService.selectByBarcode(detlDto.getOrderNo());
+//                pack.setSettle(2L);
+//                pack.setUpdateTime(now);
+//                pack.setUpdateBy(userId);
+//                if (!packService.updateById(pack)) {
+//                    throw new CoolException("淇敼鎵撳寘鏁版嵁寮傚父");
+//                }
+//            }
+//
+//        }
+//    }
 
     @Override
     @Transactional
@@ -413,11 +520,15 @@
         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(),orderDetl.getOrderNo(),null);
+            List<LocDetl> locDetls = locDetlService.queryStock(orderDetl.getMatnr(),orderDetl.getBatch(),null,null);
             if (locDetls.size() == 0) {
                 throw new CoolException("搴撳瓨涓病鏈夎鐗╂枡");
             }
@@ -444,11 +555,11 @@
                 Double curOutQty = outQty >= locDetl.getAnfme() ? locDetl.getAnfme() : outQty;   //鏈鍑哄簱閲�
                 int ioType = sumCount <= curOutQty ? 101 : 103;
 
-//                stockOut(orderDetl, staNo, locDetl, curOutQty, ioType, userId);
+                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))){
+                if(!orderService.update(order, new EntityWrapper<Order>().eq("order_no", orderNo))){
                     throw new CoolException("鏇存柊璁㈠崟鐘舵�佸け璐�");
                 }
                 orderDetl.setWorkQty(orderDetl.getWorkQty() + curOutQty);
@@ -459,7 +570,7 @@
                 if(!Cools.isEmpty(orderDetl.getBatch())){
                     wrapper.eq("batch", orderDetl.getBatch());
                 }
-                if(orderDetlService.update(orderDetl, wrapper)){
+                if(!orderDetlService.update(orderDetl, wrapper)){
                     throw new CoolException("鏇存柊璁㈠崟鏄庣粏澶辫触");
                 }
             }
@@ -467,4 +578,74 @@
         }
     }
 
+    @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