From 485dabe1952c39eeb83291247e9ee1fe77a51df1 Mon Sep 17 00:00:00 2001
From: LSH
Date: 星期一, 24 七月 2023 16:51:20 +0800
Subject: [PATCH] #入库逻辑待完善

---
 src/main/java/com/zy/asrs/service/impl/OpenServiceImpl.java |  776 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 751 insertions(+), 25 deletions(-)

diff --git a/src/main/java/com/zy/asrs/service/impl/OpenServiceImpl.java b/src/main/java/com/zy/asrs/service/impl/OpenServiceImpl.java
index 529ad91..8bcba1e 100644
--- a/src/main/java/com/zy/asrs/service/impl/OpenServiceImpl.java
+++ b/src/main/java/com/zy/asrs/service/impl/OpenServiceImpl.java
@@ -5,16 +5,17 @@
 import com.core.common.DateUtils;
 import com.core.common.SnowflakeIdWorker;
 import com.core.exception.CoolException;
-import com.zy.asrs.entity.DocType;
-import com.zy.asrs.entity.Mat;
-import com.zy.asrs.entity.Order;
-import com.zy.asrs.entity.OrderDetl;
-import com.zy.asrs.entity.param.OpenOrderCompleteParam;
-import com.zy.asrs.entity.param.OpenOrderPakinParam;
+import com.zy.asrs.entity.*;
+import com.zy.asrs.entity.param.*;
 import com.zy.asrs.entity.result.OpenOrderCompeteResult;
 import com.zy.asrs.entity.result.StockVo;
+import com.zy.asrs.mapper.TagMapper;
 import com.zy.asrs.service.*;
+import com.zy.asrs.utils.MatUtils;
 import com.zy.common.model.DetlDto;
+import com.zy.common.model.enums.WorkNoType;
+import com.zy.common.service.CommonService;
+import com.zy.common.utils.NodeUtils;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -43,6 +44,22 @@
     private MatService matService;
     @Autowired
     private LocDetlService locDetlService;
+    @Autowired
+    private PackService packService;
+    @Autowired
+    private TagService tagService;
+    @Autowired
+    private TagMapper tagMapper;
+    @Autowired
+    private WrkMastService wrkMastService;
+    @Autowired
+    private BasDevpService basDevpService;
+    @Autowired
+    private WrkDetlService wrkDetlService;
+    @Autowired
+    private WaitPakinService waitPakinService;
+    @Autowired
+    private CommonService commonService;
 
     @Override
     @Transactional
@@ -114,6 +131,7 @@
             OrderDetl orderDetl = new OrderDetl();
             orderDetl.sync(mat);
             orderDetl.setBatch(detlDto.getBatch());
+            orderDetl.setAnfme(detlDto.getAnfme());
             orderDetl.setOrderId(order.getId());
             orderDetl.setOrderNo(order.getOrderNo());
             orderDetl.setCreateBy(9527L);
@@ -132,25 +150,7 @@
     @Transactional
     public List<OpenOrderCompeteResult> pakinOrderComplete(OpenOrderCompleteParam param) {
         List<OpenOrderCompeteResult> results = new ArrayList<>();
-        if (Cools.isEmpty(param.getOrderNo())) {
-            // 鎵�鏈夎鍗�
-            List<Order> orders = orderService.selectList(new EntityWrapper<Order>().eq("settle", 4L));
-            for (Order order : orders) {
-                OpenOrderCompeteResult result = new OpenOrderCompeteResult();
-                results.add(result);
-                result.setOrderNo(order.getOrderNo());
-                result.setOrderTime(order.getOrderTime());
-                result.setOrderType(order.getDocType$());
-                List<OrderDetl> orderDetls = orderDetlService.selectByOrderId(order.getId());
-                for (OrderDetl orderDetl : orderDetls) {
-                    result.getOrderDetails().add(new DetlDto(orderDetl.getOrderNo(), orderDetl.getMatnr(), orderDetl.getBatch(), orderDetl.getQty()));
-                }
-                // 淇敼璁㈠崟鐘舵�� 4.瀹屾垚 ===>> 6.宸蹭笂鎶�
-                if (!orderService.updateSettle(order.getId(), 6L, null)) {
-                    throw new CoolException("鏈嶅姟鍣ㄥ唴閮ㄩ敊璇紝璇疯仈绯荤鐞嗗憳");
-                }
-            }
-        } else {
+        if (!Cools.isEmpty(param) && !Cools.isEmpty(param.getOrderNo())) {
             // 鎸囧畾璁㈠崟
             Order order = orderService.selectByNo(param.getOrderNo());
             if (null != order) {
@@ -170,6 +170,158 @@
                     }
                 }
             }
+        } else {
+            // 鎵�鏈夎鍗�
+            List<Order> orders = orderService.selectList(new EntityWrapper<Order>().eq("settle", 4L));
+            for (Order order : orders) {
+                OpenOrderCompeteResult result = new OpenOrderCompeteResult();
+                results.add(result);
+                result.setOrderNo(order.getOrderNo());
+                result.setOrderTime(order.getOrderTime());
+                result.setOrderType(order.getDocType$());
+                List<OrderDetl> orderDetls = orderDetlService.selectByOrderId(order.getId());
+                for (OrderDetl orderDetl : orderDetls) {
+                    result.getOrderDetails().add(new DetlDto(orderDetl.getOrderNo(), orderDetl.getMatnr(), orderDetl.getBatch(), orderDetl.getQty()));
+                }
+                // 淇敼璁㈠崟鐘舵�� 4.瀹屾垚 ===>> 6.宸蹭笂鎶�
+                if (!orderService.updateSettle(order.getId(), 6L, null)) {
+                    throw new CoolException("鏈嶅姟鍣ㄥ唴閮ㄩ敊璇紝璇疯仈绯荤鐞嗗憳");
+                }
+            }
+        }
+        return results;
+    }
+
+    @Override
+    @Transactional
+    public void pakoutOrderCreate(OpenOrderPakoutParam param) {
+        Order order = orderService.selectByNo(param.getOrderNo());
+        // 濡傛灉鍗曟嵁涓嶅瓨鍦ㄥ垯娣诲姞锛涘鏋滃崟鎹瓨鍦紝浣滀笟涓棤娉曚慨鏀癸紝鍙嶄箣鍒欎慨鏀瑰崟鎹�
+        if (!Cools.isEmpty(order)) {
+            if (order.getSettle() > 1L) {
+                throw new CoolException(param.getOrderNo() + "姝e湪鍑哄簱锛屾棤娉曚慨鏀瑰崟鎹�");
+            }
+            orderService.remove(order.getId());
+        }
+        DocType docType = docTypeService.selectOrAdd(param.getOrderType(), Boolean.FALSE);
+        Date now = new Date();
+        // 鍗曟嵁涓绘。
+        order = new Order(
+                String.valueOf(snowflakeIdWorker.nextId()),    // 缂栧彿[闈炵┖]
+                param.getOrderNo(),    // 璁㈠崟缂栧彿
+                DateUtils.convert(now),    // 鍗曟嵁鏃ユ湡
+                docType.getDocId(),    // 鍗曟嵁绫诲瀷
+                null,    // 椤圭洰缂栧彿
+                null,    //
+                null,    // 璋冩嫧椤圭洰缂栧彿
+                null,    // 鍒濆绁ㄦ嵁鍙�
+                null,    // 绁ㄦ嵁鍙�
+                null,    // 瀹㈡埛缂栧彿
+                null,    // 瀹㈡埛
+                null,    // 鑱旂郴鏂瑰紡
+                null,    // 鎿嶄綔浜哄憳
+                null,    // 鍚堣閲戦
+                null,    // 浼樻儬鐜�
+                null,    // 浼樻儬閲戦
+                null,    // 閿�鍞垨閲囪喘璐圭敤鍚堣
+                null,    // 瀹炰粯閲戦
+                null,    // 浠樻绫诲瀷
+                null,    // 涓氬姟鍛�
+                null,    // 缁撶畻澶╂暟
+                null,    // 閭垂鏀粯绫诲瀷
+                null,    // 閭垂
+                null,    // 浠樻鏃堕棿
+                null,    // 鍙戣揣鏃堕棿
+                null,    // 鐗╂祦鍚嶇О
+                null,    // 鐗╂祦鍗曞彿
+                1L,    // 璁㈠崟鐘舵��
+                1,    // 鐘舵��
+                9527L,    // 娣诲姞浜哄憳
+                now,    // 娣诲姞鏃堕棿
+                9527L,    // 淇敼浜哄憳
+                now,    // 淇敼鏃堕棿
+                null    // 澶囨敞
+        );
+        if (!orderService.insert(order)) {
+            throw new CoolException("鐢熸垚鍗曟嵁涓绘。澶辫触锛岃鑱旂郴绠$悊鍛�");
+        }
+        // 鍗曟嵁鏄庣粏妗�
+        List<DetlDto> list = new ArrayList<>();
+        List<DetlDto> orderDetails = param.getOrderDetails();
+        for (DetlDto detail : orderDetails) {
+            DetlDto dto = new DetlDto(detail.getMatnr(), detail.getBatch(), detail.getAnfme());
+            if (DetlDto.has(list, dto)) {
+                DetlDto detlDto = DetlDto.find(list, dto.getMatnr(), dto.getBatch());
+                assert detlDto != null;
+                detlDto.setAnfme(detlDto.getAnfme() + detail.getAnfme());
+            } else {
+                list.add(dto);
+            }
+        }
+        for (DetlDto detlDto : list) {
+            Mat mat = matService.selectByMatnr(detlDto.getMatnr());
+            if (Cools.isEmpty(mat)) {
+                throw new CoolException(detlDto.getMatnr() + "缂栧彿鍟嗗搧妫�绱㈠け璐ワ紝璇峰厛娣诲姞鍟嗗搧");
+            }
+            OrderDetl orderDetl = new OrderDetl();
+            orderDetl.sync(mat);
+            orderDetl.setBatch(detlDto.getBatch());
+            orderDetl.setAnfme(detlDto.getAnfme());
+            orderDetl.setOrderId(order.getId());
+            orderDetl.setOrderNo(order.getOrderNo());
+            orderDetl.setCreateBy(9527L);
+            orderDetl.setCreateTime(now);
+            orderDetl.setUpdateBy(9527L);
+            orderDetl.setUpdateTime(now);
+            orderDetl.setStatus(1);
+            orderDetl.setQty(0.0D);
+            if (!orderDetlService.insert(orderDetl)) {
+                throw new CoolException("鐢熸垚鍗曟嵁鏄庣粏澶辫触锛岃鑱旂郴绠$悊鍛�");
+            }
+        }
+    }
+
+    @Override
+    public List<OpenOrderCompeteResult> pakoutOrderComplete(OpenOrderCompleteParam param) {
+        List<OpenOrderCompeteResult> results = new ArrayList<>();
+        if (!Cools.isEmpty(param) && !Cools.isEmpty(param.getOrderNo())) {
+            // 鎸囧畾璁㈠崟
+            Order order = orderService.selectByNo(param.getOrderNo());
+            if (null != order) {
+                OpenOrderCompeteResult result = new OpenOrderCompeteResult();
+                results.add(result);
+                result.setOrderNo(order.getOrderNo());
+                result.setOrderTime(order.getOrderTime());
+                result.setOrderType(order.getDocType$());
+                List<OrderDetl> orderDetls = orderDetlService.selectByOrderId(order.getId());
+                for (OrderDetl orderDetl : orderDetls) {
+                    result.getOrderDetails().add(new DetlDto(orderDetl.getOrderNo(), orderDetl.getMatnr(), orderDetl.getBatch(), orderDetl.getQty()));
+                }
+                if (order.getSettle() == 4L) {
+                    // 淇敼璁㈠崟鐘舵�� 4.瀹屾垚 ===>> 6.宸蹭笂鎶�
+                    if (!orderService.updateSettle(order.getId(), 6L, null)) {
+                        throw new CoolException("鏈嶅姟鍣ㄥ唴閮ㄩ敊璇紝璇疯仈绯荤鐞嗗憳");
+                    }
+                }
+            }
+        } else {
+            // 鎵�鏈夎鍗�
+            List<Order> orders = orderService.selectList(new EntityWrapper<Order>().eq("settle", 4L));
+            for (Order order : orders) {
+                OpenOrderCompeteResult result = new OpenOrderCompeteResult();
+                results.add(result);
+                result.setOrderNo(order.getOrderNo());
+                result.setOrderTime(order.getOrderTime());
+                result.setOrderType(order.getDocType$());
+                List<OrderDetl> orderDetls = orderDetlService.selectByOrderId(order.getId());
+                for (OrderDetl orderDetl : orderDetls) {
+                    result.getOrderDetails().add(new DetlDto(orderDetl.getOrderNo(), orderDetl.getMatnr(), orderDetl.getBatch(), orderDetl.getQty()));
+                }
+                // 淇敼璁㈠崟鐘舵�� 4.瀹屾垚 ===>> 6.宸蹭笂鎶�
+                if (!orderService.updateSettle(order.getId(), 6L, null)) {
+                    throw new CoolException("鏈嶅姟鍣ㄥ唴閮ㄩ敊璇紝璇疯仈绯荤鐞嗗憳");
+                }
+            }
         }
         return results;
     }
@@ -180,4 +332,578 @@
         return locDetlService.queryStockTotal();
     }
 
+    @Override
+    @Transactional
+    public void packageUp(PackParam param) {
+        if (Cools.isEmpty(param.getBarcode())) {
+            throw new CoolException("barcode涓嶈兘涓虹┖");
+        }
+        Mat analyse = MatUtils.analyseMat(param.getBarcode());
+        Pack pack = packService.selectByBarcode(param.getBarcode());
+        if (null != pack) {
+            throw new CoolException(param.getBarcode() + "閲嶅鎻愪氦");
+        }
+        Date now = new Date();
+        pack = new Pack(
+                param.getBarcode(),    // 鏉$爜[闈炵┖]
+                analyse.getMatnr(),    // 鍟嗗搧缂栧彿
+                analyse.getBarcode(),    // 搴忓垪鐮�
+                1L,    // 璁㈠崟鐘舵��
+                1,    // 鐘舵��
+                now,    // 娣诲姞鏃堕棿
+                null,    // 娣诲姞浜哄憳
+                now,    // 淇敼鏃堕棿
+                null,    // 淇敼浜哄憳
+                null    // 澶囨敞
+        );
+        if (!packService.insert(pack)) {
+            throw new CoolException("鏈嶅姟鍣ㄥ唴閮ㄩ敊璇紝璇疯仈绯荤鐞嗗憳");
+        }
+
+        Mat mat = matService.selectByMatnr(analyse.getMatnr());
+        if (mat == null) {
+            mat = new Mat();
+            // 鍒嗙被
+            Long tagId;
+            // 涓�绾у垎绫�
+            if (!Cools.isEmpty(param.getGroupCode()) && !Cools.isEmpty(param.getGroupName())) {
+                Tag priTag = tagService.selectByName(param.getGroupCode(), 2);
+                if (priTag == null) {
+                    Tag top = tagService.getTop();
+                    NodeUtils nodeUtils = new NodeUtils();
+                    nodeUtils.executePath(top.getId());
+                    priTag = new Tag(
+                            null,    // 缂栧彿
+                            param.getGroupCode(),    // 鍚嶇О
+                            top.getId(),    // 鐖剁骇
+                            top.getName(),    // 鐖剁骇鍚嶇О
+                            nodeUtils.path.toString(),    // 鍏宠仈璺緞
+                            nodeUtils.pathName.toString(),    // 鍏宠仈璺緞鍚�
+                            0,    // 绫诲瀷
+                            null,    // 璐熻矗浜�
+                            null,    // 鍥剧墖
+                            null,    // 绠�瑕佹弿杩�
+                            null,    // 鏁伴噺
+                            2,    // 绛夌骇
+                            null,    // 鎺掑簭
+                            1,    // 鐘舵��
+                            now,    // 娣诲姞鏃堕棿
+                            null,    // 娣诲姞浜哄憳
+                            now,    // 淇敼鏃堕棿
+                            null,    // 淇敼浜哄憳
+                            null    // 澶囨敞
+                    );
+                    if (tagMapper.insert(priTag) == 0) {
+                        throw new CoolException("鏈嶅姟鍣ㄥ唴閮ㄩ敊璇紝璇疯仈绯荤鐞嗗憳");
+                    }
+                }
+                // 浜岀骇鍒嗙被
+                Tag secTag = tagService.selectByName(param.getGroupName(), 3);
+                if (secTag == null) {
+                    NodeUtils nodeUtils = new NodeUtils();
+                    nodeUtils.executePath(priTag.getId());
+                    secTag = new Tag(
+                            null,    // 缂栧彿
+                            param.getGroupName(),    // 鍚嶇О
+                            priTag.getId(),    // 鐖剁骇
+                            priTag.getName(),    // 鐖剁骇鍚嶇О
+                            nodeUtils.path.toString(),    // 鍏宠仈璺緞
+                            nodeUtils.pathName.toString(),    // 鍏宠仈璺緞鍚�
+                            0,    // 绫诲瀷
+                            null,    // 璐熻矗浜�
+                            null,    // 鍥剧墖
+                            null,    // 绠�瑕佹弿杩�
+                            null,    // 鏁伴噺
+                            3,    // 绛夌骇
+                            null,    // 鎺掑簭
+                            1,    // 鐘舵��
+                            now,    // 娣诲姞鏃堕棿
+                            null,    // 娣诲姞浜哄憳
+                            now,    // 淇敼鏃堕棿
+                            null,    // 淇敼浜哄憳
+                            null    // 澶囨敞
+                    );
+                    if (tagMapper.insert(secTag) == 0) {
+                        throw new CoolException("鏈嶅姟鍣ㄥ唴閮ㄩ敊璇紝璇疯仈绯荤鐞嗗憳");
+                    }
+                }
+                tagId = secTag.getId();
+            } else {
+                tagId = tagService.getTop().getId();
+            }
+            mat.setTagId(tagId);
+            mat.setMatnr(analyse.getMatnr());
+            mat.setMaktx(param.getMaterialName());
+            mat.setSpecs(param.getConfigureDesc());
+            mat.setModel(analyse.getModel());
+            mat.setStatus(1);
+            mat.setCreateTime(now);
+            mat.setUpdateTime(now);
+            if (!matService.insert(mat)) {
+                throw new CoolException("鏈嶅姟鍣ㄥ唴閮ㄩ敊璇紝璇疯仈绯荤鐞嗗憳");
+            } else {
+                log.info("鎵撳寘涓婄嚎娣诲姞鏂扮墿鏂橻鍟嗗搧缂栧彿锛歿}]", mat.getMatnr());
+            }
+        }
+    }
+
+    @Override
+    @Transactional
+    public void syncMat(MatSyncParam param) {
+        if (Cools.isEmpty(param.getMatDetails()) || param.getMatDetails().size() <=0 ) {
+            throw new CoolException("鍟嗗搧鏁版嵁涓虹┖");
+        }
+
+        for(MatSyncParam.MatParam matParam : param.getMatDetails()){
+            if(Cools.isEmpty(matParam.getMatnr())){
+                throw new CoolException("鍟嗗搧缂栫爜涓嶈兘涓虹┖");
+            }
+
+            Date now = new Date();
+            Mat mat = matService.selectByMatnr(matParam.getMatnr());
+            if (mat == null) {
+                mat = new Mat();
+                // 鍒嗙被
+                Long tagId;
+                // 涓�绾у垎绫�
+                if (!Cools.isEmpty(matParam.getGroupCode()) && !Cools.isEmpty(matParam.getGroupName())) {
+                    Tag priTag = tagService.selectByName(matParam.getGroupCode(), 2);
+                    if (priTag == null) {
+                        Tag top = tagService.getTop();
+                        NodeUtils nodeUtils = new NodeUtils();
+                        nodeUtils.executePath(top.getId());
+                        priTag = new Tag(
+                                null,    // 缂栧彿
+                                matParam.getGroupCode(),    // 鍚嶇О
+                                top.getId(),    // 鐖剁骇
+                                top.getName(),    // 鐖剁骇鍚嶇О
+                                nodeUtils.path.toString(),    // 鍏宠仈璺緞
+                                nodeUtils.pathName.toString(),    // 鍏宠仈璺緞鍚�
+                                0,    // 绫诲瀷
+                                null,    // 璐熻矗浜�
+                                null,    // 鍥剧墖
+                                null,    // 绠�瑕佹弿杩�
+                                null,    // 鏁伴噺
+                                2,    // 绛夌骇
+                                null,    // 鎺掑簭
+                                1,    // 鐘舵��
+                                now,    // 娣诲姞鏃堕棿
+                                null,    // 娣诲姞浜哄憳
+                                now,    // 淇敼鏃堕棿
+                                null,    // 淇敼浜哄憳
+                                null    // 澶囨敞
+                        );
+                        if (tagMapper.insert(priTag) == 0) {
+                            throw new CoolException("鏈嶅姟鍣ㄥ唴閮ㄩ敊璇紝璇疯仈绯荤鐞嗗憳");
+                        }
+                    }
+                    // 浜岀骇鍒嗙被
+                    Tag secTag = tagService.selectByName(matParam.getGroupName(), 3);
+                    if (secTag == null) {
+                        NodeUtils nodeUtils = new NodeUtils();
+                        nodeUtils.executePath(priTag.getId());
+                        secTag = new Tag(
+                                null,    // 缂栧彿
+                                matParam.getGroupName(),    // 鍚嶇О
+                                priTag.getId(),    // 鐖剁骇
+                                priTag.getName(),    // 鐖剁骇鍚嶇О
+                                nodeUtils.path.toString(),    // 鍏宠仈璺緞
+                                nodeUtils.pathName.toString(),    // 鍏宠仈璺緞鍚�
+                                0,    // 绫诲瀷
+                                null,    // 璐熻矗浜�
+                                null,    // 鍥剧墖
+                                null,    // 绠�瑕佹弿杩�
+                                null,    // 鏁伴噺
+                                3,    // 绛夌骇
+                                null,    // 鎺掑簭
+                                1,    // 鐘舵��
+                                now,    // 娣诲姞鏃堕棿
+                                null,    // 娣诲姞浜哄憳
+                                now,    // 淇敼鏃堕棿
+                                null,    // 淇敼浜哄憳
+                                null    // 澶囨敞
+                        );
+                        if (tagMapper.insert(secTag) == 0) {
+                            throw new CoolException("鏈嶅姟鍣ㄥ唴閮ㄩ敊璇紝璇疯仈绯荤鐞嗗憳");
+                        }
+                    }
+                    tagId = secTag.getId();
+                } else {
+                    tagId = tagService.getTop().getId();
+                }
+                mat.sync(param);
+//            mat.setMatnr(param.getMatnr());
+//            mat.setMaktx(param.getMaktx());
+//            mat.setSpecs(param.getSpecs());
+//            mat.setModel(param.getModel());
+
+                mat.setTagId(tagId);
+                mat.setStatus(1);
+                mat.setCreateTime(now);
+                mat.setUpdateTime(now);
+                if (!matService.insert(mat)) {
+                    throw new CoolException("鏈嶅姟鍣ㄥ唴閮ㄩ敊璇紝璇疯仈绯荤鐞嗗憳");
+                } else {
+                    log.info("鍚屾鏂扮墿鏂橻鍟嗗搧缂栧彿锛歿}]", mat.getMatnr());
+                }
+            } else {
+                mat.sync(param);
+                if (!matService.update(mat, new EntityWrapper<Mat>().eq("matnr",matParam.getMatnr()))) {
+                    throw new CoolException("鏇存柊宸插瓨鍦ㄥ晢鍝佷俊鎭け璐ワ紝璇疯仈绯荤鐞嗗憳");
+                }
+            }
+        }
+
+    }
+
+    /*...........................寰愬伐姹変簯..............浠ヤ笅.............涓婇ザ姹熼摐...........................*/
+    /*............................Created by Monkey D. Luffy on 2023.07.19.............................*/
+
+    /*
+     * 璐存爣鏈虹敵璇疯幏鍙栬揣鐗╀俊鎭�
+     * */
+    @Override
+    @Transactional
+    public LabellerMatParam labellerMat(LabellerMatParam param){
+        if (Cools.isEmpty(param.getDevNo())){
+            throw new CoolException("鍙傛暟锛氱珯鐐瑰彿 devNo涓虹┖");
+        }else if (Cools.isEmpty(param.getLabNo())){
+            throw new CoolException("鍙傛暟锛氳创鏍囨満鍙� labNo涓虹┖");
+        }
+        BasDevp basDevp = basDevpService.selectById(param.getDevNo());
+        if (Cools.isEmpty(basDevp)){
+            throw new CoolException("鍙傛暟锛氱珯鐐瑰彿 devNo涓嶅瓨鍦�");
+        }else if (Cools.isEmpty(basDevp.getWrkNo()) || basDevp.getWrkNo()==0){
+            throw new CoolException("绔欑偣:"+param.getDevNo()+" 涓嶅瓨鍦ㄥ伐浣滀腑浠诲姟");
+        }
+
+        WrkMast wrkMast = wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("wrk_no", basDevp.getWrkNo()));
+        if (Cools.isEmpty(wrkMast)){
+            throw new CoolException("绔欑偣:"+param.getDevNo()+" 宸ヤ綔涓换鍔′笉瀛樺湪,浠诲姟鍙凤細"+basDevp.getWrkNo());
+        }else if (!wrkMast.getWrkSts().equals(52L)){
+            throw new CoolException("绔欑偣:"+param.getDevNo()+" 宸ヤ綔涓换鍔$姸鎬佸凡鍙樻洿锛岃鍕块噸澶嶇敵璇�,浠诲姟鍙凤細"+basDevp.getWrkNo()+",浠诲姟鐘舵��:"+wrkMast.getWrkSts$());
+        }
+
+        List<WrkDetl> wrkDetls = wrkDetlService.selectList(new EntityWrapper<WrkDetl>().eq("wrk_no", basDevp.getWrkNo()));
+        if (Cools.isEmpty(wrkDetls) || wrkDetls.size()==0){
+            throw new CoolException("绔欑偣:"+param.getDevNo()+" 宸ヤ綔涓换鍔′笉瀛樺湪浠诲姟鏄庣粏,浠诲姟鍙凤細"+basDevp.getWrkNo());
+        }
+
+        LabellerMatParam labellerMatParam = new LabellerMatParam();
+        labellerMatParam.setDevNo(param.getDevNo());
+        labellerMatParam.setLabNo(param.getLabNo());
+        ArrayList<LabellerMatParam.CombMat> combMats = new ArrayList<>();
+        String orderNo = "";
+
+        for (WrkDetl wrkDetl:wrkDetls){
+            LabellerMatParam.CombMat combMat = new LabellerMatParam.CombMat(wrkDetl);
+            orderNo=wrkDetl.getOrderNo();
+            combMat.setTemp1("1");
+            combMats.add(combMat);
+        }
+
+        labellerMatParam.setCombMats(combMats);
+        labellerMatParam.setLabellingTime(DateUtils.convert(new Date()));
+        labellerMatParam.setWrkNo(basDevp.getWrkNo().toString());
+        labellerMatParam.setLabTemplate("1");
+        labellerMatParam.setOrderNo(orderNo);
+        wrkMast.setWrkSts(53L);
+        if (!wrkMastService.updateById(wrkMast)){
+            throw new CoolException("寮傚父锛岃閲嶆柊鐢宠");
+        }
+        return labellerMatParam;
+    }
+
+    /*
+    * 璐存爣鏈鸿创鏍囧畬鎴�
+    * */
+    @Override
+    @Transactional
+    public void labellerComplete(LabellerCompleteParam param) {
+        if (Cools.isEmpty(param.getDevNo())){
+            throw new CoolException("鍙傛暟锛氱珯鐐瑰彿 devNo涓虹┖");
+        }else if (Cools.isEmpty(param.getLabNo())){
+            throw new CoolException("鍙傛暟锛氳创鏍囨満鍙� labNo涓虹┖");
+        }else if (Cools.isEmpty(param.getLabResult())){
+            throw new CoolException("鍙傛暟锛氳创鏍囩粨鏋� labResult涓虹┖");
+        }else if (Cools.isEmpty(param.getWrkNo())){
+            throw new CoolException("鍙傛暟锛氳创鏍囦换鍔″彿 wrkNo涓虹┖");
+        }
+        BasDevp basDevp = basDevpService.selectById(param.getDevNo());
+        if (Cools.isEmpty(basDevp)){
+            throw new CoolException("鍙傛暟锛氱珯鐐瑰彿 devNo="+param.getDevNo()+"涓嶅瓨鍦�");
+        }else if (Cools.isEmpty(basDevp.getWrkNo()) || basDevp.getWrkNo()==0 ){
+            throw new CoolException("绔欑偣:"+param.getDevNo()+" 涓嶅瓨鍦ㄥ伐浣滀腑浠诲姟");
+        }else if(!basDevp.getWrkNo().toString().equals(param.getWrkNo())){
+            throw new CoolException("绔欑偣:"+param.getDevNo()+" 杩涜涓换鍔″彿="+basDevp.getWrkNo()+" 涓庤创鏍囩粨鏋滆繑鍥炰换鍔″彿="+param.getWrkNo()+" 涓嶄竴鑷�");
+        }
+
+        WrkMast wrkMast = wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("wrk_no", basDevp.getWrkNo()));
+        if (Cools.isEmpty(wrkMast)){
+            throw new CoolException("绔欑偣:"+param.getDevNo()+" 宸ヤ綔涓换鍔′笉瀛樺湪,浠诲姟鍙凤細"+basDevp.getWrkNo());
+        }else if (!wrkMast.getWrkSts().equals(53L)){
+            throw new CoolException("绔欑偣:"+param.getDevNo()+" 宸ヤ綔涓换鍔$姸鎬佸凡鍙樻洿锛岃鍕块噸澶嶇敵璇�,浠诲姟鍙凤細"+basDevp.getWrkNo()+",浠诲姟鐘舵��:"+wrkMast.getWrkSts$());
+        }
+
+        if (param.getLabResult().equals("OK")){
+            wrkMast.setWrkSts(54L);
+            if (!wrkMastService.updateById(wrkMast)){
+                throw new CoolException("寮傚父锛岃閲嶆柊鐢宠");
+            }
+        }else if (param.getLabResult().equals("NG")){
+            wrkMast.setWrkSts(52L);
+            if (!wrkMastService.updateById(wrkMast)){
+                throw new CoolException("寮傚父锛岃閲嶆柊鐢宠");
+            }
+        }else {
+            throw new CoolException("鍙傛暟锛氳创鏍囩粨鏋�:labResult"+param.getLabResult()+";璇锋寜瑙勫垯鍙戦�侊細鎴愬姛锛歄K 銆佸け璐�:NG");
+        }
+
+    }
+
+    /*
+     * 涓帶锛氱爜鍨涘畬鎴愪笅鍙戝叆搴撲俊鎭�
+     * */
+    @Override
+    @Transactional
+    public void palletizingComplete(PalletizingCompleteParam param) {
+        Long userId = 7777L;//涓帶
+        //鍒ゆ柇param鍙傛暟
+        if (Cools.isEmpty(param.getBarcode())){
+            throw new CoolException("鍙傛暟锛氭墭鐩樼爜 barcode涓虹┖");
+        }else if (Cools.isEmpty(param.getPalletizingNo())){
+            throw new CoolException("鍙傛暟锛氱爜鍨涗綅缂栧彿 palletizingNo涓虹┖");
+        }else if (Cools.isEmpty(param.getBoxType())){
+            throw new CoolException("鍙傛暟锛氭湪绠辩被鍨� boxType涓虹┖");
+        }else if (Cools.isEmpty(param.getMatLists()) || param.getMatLists().size()==0){
+            throw new CoolException("鍙傛暟锛氱墿鏂欐槑缁� matLists涓虹┖");
+        }
+
+        ArrayList<String> positions = new ArrayList<>();   //鏈ㄧ浣嶇疆鏌ラ噸      (orgin)
+        ArrayList<String> boxNos = new ArrayList<>();   //鏈ㄧ鍞竴缂栫爜鏌ラ噸  锛坆atch锛�
+        //鍒ゆ柇matLists鍙傛暟
+        for (PalletizingCompleteParam.MatList matList:param.getMatLists()){
+            if (Cools.isEmpty(matList.getMatnr())){
+                throw new CoolException("鍙傛暟锛氱墿鏂欑紪鐮� matnr涓虹┖");
+            }else if (Cools.isEmpty(matList.getPosition())){
+                throw new CoolException("鐗╂枡缂栫爜锛�"+matList.getMatnr()+"銆佸弬鏁帮細鐮佸灈浣嶇疆 position涓虹┖");
+            }else if (Cools.isEmpty(matList.getBoxNo())){
+                throw new CoolException("鐗╂枡缂栫爜锛�"+matList.getMatnr()+"銆佸弬鏁帮細鏈ㄧ缂栧彿 boxNo涓虹┖");
+            }else if (Cools.isEmpty(matList.getAnfme()) || matList.getAnfme().equals(0)){
+                throw new CoolException("鐗╂枡缂栫爜锛�"+matList.getMatnr()+"銆佸弬鏁帮細鏈ㄧ涓摐绠旀暟閲� anfme涓虹┖");
+            }else if (Cools.isEmpty(matList.getWeight()) || matList.getWeight().equals(0D)){
+                throw new CoolException("鐗╂枡缂栫爜锛�"+matList.getMatnr()+"銆佸弬鏁帮細閲嶉噺 weight涓虹┖");
+            }
+
+            if (!positions.contains(matList.getPosition())){
+                positions.add(matList.getPosition());
+            }else {
+                throw new CoolException("鍙傛暟锛氭湪绠辩紪鍙� boxNo:"+matList.getBoxNo()+",鏈ㄧ浣嶇疆瀛樺湪閲嶅锛�"+matList.getPosition());
+            }
+
+            if (!boxNos.contains(matList.getBoxNo())){
+                boxNos.add(matList.getBoxNo());
+            }else {
+                throw new CoolException("鍙傛暟锛氭湪绠辩紪鍙� boxNo:"+matList.getBoxNo()+",鏈ㄧ缂栫爜瀛樺湪閲嶅");
+            }
+        }
+
+//        BasDevp basDevp = basDevpService.selectById(Integer.parseInt(param.getDevNo$()));
+//        if (Cools.isEmpty(basDevp)){
+//            throw new CoolException("鍙傛暟锛氱爜鍨涗綅缂栧彿 palletizingNo="+param.getPalletizingNo()+"涓嶅瓨鍦�");
+//        }
+//        if (Cools.isEmpty(basDevp.getAutoing()) || !basDevp.getAutoing().equals("Y")){
+//            throw new CoolException("鐮佸灈浣嶇紪鍙� palletizingNo="+param.getPalletizingNo()+" 鎵�澶勭珯鐐逛笉鏄嚜鍔ㄧ姸鎬�");
+//        }
+//        if (Cools.isEmpty(basDevp.getLoading()) || !basDevp.getLoading().equals("Y")){
+//            throw new CoolException("鐮佸灈浣嶇紪鍙� palletizingNo="+param.getPalletizingNo()+" 鎵�澶勭珯鐐逛笉鏄湁鐗╃姸鎬�");
+//        }
+//        if (Cools.isEmpty(basDevp.getCanining()) || !basDevp.getCanining().equals("Y")){
+//            throw new CoolException("鐮佸灈浣嶇紪鍙� palletizingNo="+param.getPalletizingNo()+" 鎵�澶勭珯鐐逛笉鏄兘鍏ョ姸鎬�");
+//        }
+
+
+        WrkMast wrkMast = wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("io_type",201).eq("barcode", param.getBarcode()).eq("sta_no",param.getDevNo$()));
+        if (Cools.isEmpty(wrkMast) || !wrkMast.getWrkSts().equals(42L)){
+            throw new CoolException("鏌ヨ鎵樼洏澶辫触");
+        }else {
+            wrkMast.setWrkSts(wrkMast.getWrkSts()+1);
+        }
+
+
+        if (locDetlService.selectCount(new EntityWrapper<LocDetl>().eq("zpallet", param.getBarcode()))!=0
+            || wrkDetlService.selectCount(new EntityWrapper<WrkDetl>().eq("zpallet", param.getBarcode()))!=0
+            || waitPakinService.selectCount(new EntityWrapper<WaitPakin>().eq("zpallet", param.getBarcode()))!=0){
+            throw new CoolException("鎵樼洏鏉$爜锛�"+param.getBarcode()+"宸插瓨鍦紝璇峰嬁閲嶅缁勬墭");
+        }
+
+
+        Date now = new Date();
+        for (PalletizingCompleteParam.MatList matList:param.getMatLists()){
+            Mat mat = matService.selectByMatnr(matList.getMatnr());
+            if (Cools.isEmpty(mat)) {
+                throw new CoolException(matList.getMatnr() + "鍟嗗搧妗f涓嶅瓨鍦�");
+            }
+            WaitPakin waitPakin = new WaitPakin();
+            waitPakin.sync(mat);
+            waitPakin.setModel(matList.getBatch());     //鎵规
+            waitPakin.setSpecs(matList.getSpecs());     //瑙勬牸
+            waitPakin.setBatch(matList.getBoxNo());       //鏈ㄧ缂栫爜
+            waitPakin.setBrand(param.getBoxType());     //鏈ㄧ绫诲瀷
+            waitPakin.setZpallet(param.getBarcode());   //鎵樼洏鐮�
+            waitPakin.setOrigin(matList.getPosition()); //鏈ㄧ鍦ㄦ墭鐩樹笂鐨勪綅缃�
+            waitPakin.setIoStatus("N");     // 鍏ュ嚭鐘舵��
+            waitPakin.setAnfme(matList.getAnfme().doubleValue());  // 鏈ㄧ涓摐绠旀暟閲�
+            waitPakin.setStatus("Y");    // 鐘舵��
+            waitPakin.setAppeUser(userId);
+            waitPakin.setAppeTime(now);
+            waitPakin.setModiUser(userId);
+            waitPakin.setModiTime(now);
+            if (!waitPakinService.insert(waitPakin)) {
+                throw new CoolException("淇濆瓨鍏ュ簱閫氱煡妗eけ璐�");
+            }
+        }
+        if (!wrkMastService.updateById(wrkMast)){
+            throw new CoolException("寮傚父锛岃閲嶆柊鐢宠");
+        }
+
+    }
+
+    /*
+     * 妗佹灦涓婁綅杞欢锛氬崟娆℃媶鍨涘畬鎴愰�氱煡
+     * */
+    @Override
+    @Transactional
+    public void singleUnstackingComplete(SingleUnstackingCompleteParam param) {
+        Long userId = 8888L;//妗佹灦涓婁綅杞欢
+        //鍒ゆ柇param鍙傛暟
+        if (Cools.isEmpty(param.getBarcode())){
+            throw new CoolException("鍙傛暟锛氭墭鐩樼爜 barcode涓虹┖");
+        }else if (Cools.isEmpty(param.getPalletizingNo())){
+            throw new CoolException("鍙傛暟锛氱爜鍨涗綅缂栧彿 palletizingNo涓虹┖");
+        }else if (Cools.isEmpty(param.getMatLists()) || param.getMatLists().size()==0){
+            throw new CoolException("鍙傛暟锛氱墿鏂欐槑缁� matLists涓虹┖");
+        }
+        WrkMast wrkMastMatrix = wrkMastService.selectByBarcode(param.getBarcode());
+        if (Cools.isEmpty(wrkMastMatrix)){
+            throw new CoolException("鍙傛暟锛氭墭鐩樼爜鏌ヨ宸ヤ綔妗eけ璐ワ細"+param.getBarcode());
+        }
+
+        List<WrkDetl> wrkDetls = wrkDetlService.selectByWrkNoUnstacking(wrkMastMatrix.getWrkNo());
+        ArrayList<WrkDetl> wrkDetlsNew = new ArrayList<>();
+        //鍒ゆ柇matLists鍙傛暟
+        for (SingleUnstackingCompleteParam.MatList matList:param.getMatLists()){
+            if (Cools.isEmpty(matList.getPosition())){
+                throw new CoolException("鍙傛暟锛氱爜鍨涗綅缃� position涓虹┖");
+            }else if (Cools.isEmpty(matList.getBoxNo())){
+                throw new CoolException("鍙傛暟锛氭湪绠辩紪鍙� boxNo涓虹┖");
+            }
+            boolean sign=true;
+            for (WrkDetl wrkDetl:wrkDetls){
+                if (wrkDetl.getBatch().equals(matList.getBoxNo())){//鏈ㄧ缂栫爜
+                    wrkDetl.setInspect(1);
+                    wrkDetlService.updateById(wrkDetl);
+                    wrkDetlsNew.add(wrkDetl);
+                    sign=false;
+                    break;
+                }
+            }
+            if (sign){
+                throw new CoolException("鍙傛暟锛氭湪绠辩紪鍙� boxNo鏈煡璇㈠埌瀵瑰簲鐨勫伐浣滄槑缁嗭紒");
+            }
+        }
+
+        // 鐢熸垚宸ヤ綔鍙�
+        int workNo = commonService.getWorkNo(WorkNoType.getWorkNoType(202));
+        Date now = new Date();
+
+        // 鐢熸垚宸ヤ綔妗�
+        WrkMast wrkMast = new WrkMast();
+        wrkMast.setWrkNo(workNo);
+        wrkMast.setIoTime(now);
+        wrkMast.setWrkSts(51L); // 宸ヤ綔鐘舵�侊細鐢熸垚鍏ュ簱ID
+        wrkMast.setIoType(202); // 鍏ュ嚭搴撶姸鎬侊細202.鎷嗗灈鍚庡嚭搴�
+        wrkMast.setIoPri(13D); // 浼樺厛绾�
+        wrkMast.setSourceStaNo(param.getDevNo$());
+        wrkMast.setStaNo(140); //璐存爣绔欑偣
+        // 鎿嶄綔浜哄憳鏁版嵁
+        wrkMast.setAppeUser(userId);
+        wrkMast.setAppeTime(now);
+        wrkMast.setModiUser(userId);
+        wrkMast.setModiTime(now);
+        if (!wrkMastService.insert(wrkMast)) {
+            throw new CoolException("鐢熸垚宸ヤ綔妗eけ璐�==銆嬫鏋朵笂浣嶈蒋浠讹細鍗曟鎷嗗灈瀹屾垚閫氱煡");
+        }
+
+        for (WrkDetl wrkDetl : wrkDetlsNew){
+            wrkDetl.setWrkNo(wrkMast.getWrkNo());
+            wrkDetl.setIoTime(wrkMast.getIoTime());
+            wrkDetl.setAppeTime(now);
+            wrkDetl.setModiTime(now);
+            if (!wrkDetlService.insert(wrkDetl)) {
+                throw new CoolException("淇濆瓨宸ヤ綔鏄庣粏澶辫触==銆嬫鏋朵笂浣嶈蒋浠讹細鍗曟鎷嗗灈瀹屾垚閫氱煡");
+            }
+        }
+
+    }
+
+    /*
+     * 妗佹灦涓婁綅杞欢锛氬崟鎵樻媶鍨涘畬鎴愰�氱煡
+     * */
+    @Override
+    @Transactional
+    public void singleMountUnstackingComplete(SingleMountUnstackingCompleteParam param) {
+        Long userId = 8888L;//妗佹灦涓婁綅杞欢
+        //鍒ゆ柇param鍙傛暟
+        if (Cools.isEmpty(param.getBarcode())){
+            throw new CoolException("鍙傛暟锛氭墭鐩樼爜 barcode涓虹┖");
+        }else if (Cools.isEmpty(param.getPalletizingNo())){
+            throw new CoolException("鍙傛暟锛氱爜鍨涗綅缂栧彿 palletizingNo涓虹┖");
+        }
+        WrkMast wrkMastMatrix = wrkMastService.selectByBarcode(param.getBarcode());
+        if (Cools.isEmpty(wrkMastMatrix)){
+            throw new CoolException("鍙傛暟锛氭墭鐩樼爜鏌ヨ宸ヤ綔妗eけ璐ワ細"+param.getBarcode());
+        }else {
+            if (!wrkMastMatrix.getIoType().equals(101)){
+                List<WrkDetl> wrkDetls = wrkDetlService.selectByWrkNoUnstacking(wrkMastMatrix.getWrkNo());
+                if (Cools.isEmpty(param.getMatLists()) || param.getMatLists().size()==0 || param.getMatLists().size()!=wrkDetls.size()){
+                    throw new CoolException("杩斿洖鐗╂枡鏄庣粏鏁颁负"+param.getMatLists().size()+",鎵樼洏鐮侊細"+param.getBarcode()+"搴斿墿浣欑墿鏂欐暟锛�"+wrkDetls.size());
+                }
+
+                ArrayList<String> orgin = new ArrayList<>();
+                //鍒ゆ柇matLists鍙傛暟
+                for (SingleMountUnstackingCompleteParam.MatList matList : param.getMatLists()){
+                    if (Cools.isEmpty(matList.getPosition())){
+                        throw new CoolException("鍙傛暟锛氱爜鍨涗綅缃� position涓虹┖");
+                    }else if (Cools.isEmpty(matList.getBoxNo())){
+                        throw new CoolException("鍙傛暟锛氭湪绠辩紪鍙� boxNo涓虹┖");
+                    }
+                    if (!orgin.contains(matList.getPosition())){
+                        orgin.add(matList.getPosition());
+                    }else {
+                        throw new CoolException("鍙傛暟锛氭湪绠辩紪鍙� boxNo:"+matList.getBoxNo()+",鏈ㄧ浣嶇疆瀛樺湪閲嶅");
+                    }
+                    boolean sign=true;
+                    for (WrkDetl wrkDetl:wrkDetls){
+                        if (wrkDetl.getBatch().equals(matList.getBoxNo())){//鏈ㄧ缂栫爜
+                            wrkDetl.setOrigin(matList.getPosition());
+                            wrkDetlService.updateById(wrkDetl);
+                            sign=false;
+                            break;
+                        }
+                    }
+                    if (sign){
+                        throw new CoolException("鍙傛暟锛氭湪绠辩紪鍙� boxNo:"+matList.getBoxNo()+"鏈煡璇㈠埌瀵瑰簲鐨勫伐浣滄槑缁嗭紒");
+                    }
+                }
+            }
+        }
+
+        wrkMastMatrix.setSheetNo("1");
+        if (!wrkMastService.updateById(wrkMastMatrix)){
+            throw new CoolException("鏇存柊宸ヤ綔妗eけ璐�==銆嬫鏋朵笂浣嶈蒋浠讹細鍗曟墭鎷嗗灈瀹屾垚閫氱煡");
+        }
+    }
+
+    /*...........................涓婇ザ姹熼摐..............浠ヤ笂.............寰愬伐姹変簯...........................*/
 }

--
Gitblit v1.9.1