From 12067f657bc3dc169a7a466e433374368e8daf73 Mon Sep 17 00:00:00 2001
From: chen.llin <1442464845@qq.comm>
Date: 星期日, 18 一月 2026 16:14:27 +0800
Subject: [PATCH] 越库订单逻辑调整

---
 src/main/java/com/zy/asrs/service/impl/OpenServiceImpl.java |  664 +++++++++++++++++++++++++++++++++----------------------
 1 files changed, 399 insertions(+), 265 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 4fe2a16..c4c7790 100644
--- a/src/main/java/com/zy/asrs/service/impl/OpenServiceImpl.java
+++ b/src/main/java/com/zy/asrs/service/impl/OpenServiceImpl.java
@@ -3,6 +3,7 @@
 import com.baomidou.mybatisplus.mapper.EntityWrapper;
 import com.core.common.Cools;
 import com.core.common.DateUtils;
+import com.core.common.R;
 import com.core.common.SnowflakeIdWorker;
 import com.core.exception.CoolException;
 import com.zy.asrs.entity.*;
@@ -19,6 +20,7 @@
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import javax.annotation.Resource;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
@@ -53,94 +55,223 @@
     @Autowired
     private TagMapper tagMapper;
 
+    @Resource
+    private TaskService taskService;
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public R agvCallback(AgvCallbackDto param) {
+        log.debug("agv鍥炶皟 param:{}", param);
+        // 浼樺厛浣跨敤taskId锛屽鏋滄病鏈夊垯浣跨敤id锛堝悜鍚庡吋瀹癸級
+        String taskId = Cools.isEmpty(param.getTaskId()) ? param.getId() : param.getTaskId();
+        if (Cools.isEmpty(taskId)) {
+            return R.error("浠诲姟id涓嶈兘涓虹┖");
+        }
+        
+        log.info("鏀跺埌AGV浠诲姟鍥炶皟璇锋眰锛宼askId锛歿}锛宖romBin锛歿}锛宼oBin锛歿}锛宺obotGroup锛歿}锛宬ind锛歿}", 
+            taskId, param.getFromBin(), param.getToBin(), 
+            Cools.isEmpty(param.getRobotGroup()) ? param.getRobotName() : param.getRobotGroup(), 
+            param.getKind());
+        
+        // 鏍规嵁taskId鏌ヨ浠诲姟
+        Task task = null;
+        try {
+            // 澶勭悊"T"鍓嶇紑鏍煎紡锛堝"T130"锛夛紝杩欐槸AGV浠诲姟鍒涘缓鏃剁殑鏍煎紡
+            String numericId = taskId;
+            if (taskId.startsWith("T") && taskId.length() > 1) {
+                numericId = taskId.substring(1);
+                log.debug("妫�娴嬪埌T鍓嶇紑鏍煎紡鐨則askId锛屾彁鍙栨暟瀛桰D锛歿}", numericId);
+            }
+            // 灏濊瘯灏唗askId瑙f瀽涓篖ong绫诲瀷鐨刬d
+            Long taskIdLong = Long.parseLong(numericId);
+            task = taskService.selectById(taskIdLong);
+        } catch (NumberFormatException e) {
+            // 濡傛灉涓嶆槸鏁板瓧锛屽皾璇曢�氳繃鍏朵粬瀛楁鏌ヨ锛堝sheetNo绛夛級
+            log.debug("taskId涓嶆槸鏁板瓧鏍煎紡锛屽皾璇曢�氳繃鍏朵粬瀛楁鏌ヨ锛宼askId锛歿}", taskId);
+            task = taskService.selectOne(
+                new EntityWrapper<Task>().eq("sheet_no", taskId)
+            );
+        }
+        
+        if (task == null) {
+            log.warn("鏈壘鍒板搴旂殑浠诲姟锛宼askId锛歿}", taskId);
+            return R.error("浠诲姟涓嶅瓨鍦紝taskId锛�" + taskId);
+        }
+        
+        // 鏇存柊浠诲姟淇℃伅
+        if (!Cools.isEmpty(param.getFromBin())) {
+            task.setSourceStaNo(param.getFromBin());
+        }
+        if (!Cools.isEmpty(param.getToBin())) {
+            task.setLocNo(param.getToBin());
+        }
+        
+        // 浼樺厛浣跨敤robotGroup锛屽鏋滄病鏈夊垯浣跨敤robotName锛堝悜鍚庡吋瀹癸級
+        String robotGroup = Cools.isEmpty(param.getRobotGroup()) ? param.getRobotName() : param.getRobotGroup();
+        if (!Cools.isEmpty(robotGroup)) {
+            task.setInvWh(robotGroup);
+        }
+        
+        task.setModiTime(new Date());
+        
+        // 濡傛灉鏈塻tatus瀛楁锛屾寜鍘熸湁閫昏緫澶勭悊锛堝悜鍚庡吋瀹癸級
+        if (!Cools.isEmpty(param.getStatus())) {
+            switch (param.getStatus()) {
+                case "Assigned":
+                    if (Cools.isEmpty(robotGroup)) {
+                        task.setInvWh(param.getRobotName());
+                    }
+                    break;
+                case "Done":
+                    task.setWrkSts(9L);
+                    break;
+                case "Failed":
+                case "Cancelled":
+                default:
+                    break;
+            }
+        }
+        
+        // 鏍规嵁浠诲姟绫诲瀷杩涜鐩稿簲澶勭悊
+        if (!Cools.isEmpty(param.getKind())) {
+            String kind = param.getKind();
+            if ("璐х墿杞繍".equals(kind)) {
+                log.info("澶勭悊璐х墿杞繍浠诲姟锛宼askId锛歿}", taskId);
+            } else if ("瀹炴墭鍏ュ簱".equals(kind) || "绌烘墭鍏ュ簱".equals(kind)) {
+                log.info("澶勭悊鍏ュ簱浠诲姟锛宼askId锛歿}", taskId);
+                // 鍏ュ簱浠诲姟锛氬鏋滄敹鍒扮‘璁ゅ彇璐у洖璋冿紙loaded=true锛夛紝瀹岀粨AGV鍛煎彨鍗�
+                if (Boolean.TRUE.equals(param.getLoaded())) {
+                    // 濡傛灉浠诲姟鐘舵�佹槸8锛堝凡鍛煎彨AGV锛夛紝鏇存柊涓�9锛堜换鍔″畬鎴愶級
+                    if (task.getWrkSts() != null && task.getWrkSts() == 8L) {
+                        task.setWrkSts(9L);
+                        log.info("鍏ュ簱浠诲姟鏀跺埌纭鍙栬揣鍥炶皟锛屽畬缁揂GV鍛煎彨鍗曪紝taskId锛歿}", taskId);
+                    }
+                }
+            } else if ("瀹炴墭鍑哄簱".equals(kind)) {
+                log.info("澶勭悊瀹炴墭鍑哄簱浠诲姟锛宼askId锛歿}", taskId);
+            }
+        }
+        
+        // 淇濆瓨浠诲姟鏇存柊
+        if (!taskService.updateById(task)) {
+            log.error("鏇存柊浠诲姟澶辫触锛宼askId锛歿}", taskId);
+            return R.error("鏇存柊浠诲姟澶辫触");
+        }
+        
+        log.info("AGV浠诲姟鍥炶皟澶勭悊鎴愬姛锛宼askId锛歿}", taskId);
+        return R.ok();
+    }
+
     @Override
     @Transactional
     public void pakinOrderCreate(OpenOrderPakinParam param) {
+        String orderNo = param.getOrderNo();
+        String orderType = param.getOrderType();
+        String optType = param.getOptType();
         OrderPakin order = orderPakinService.selectByNo(param.getOrderNo());
-        if (!Cools.isEmpty(order)) {
-            throw new CoolException(param.getOrderNo() + "鍗曟嵁宸插瓨鍦紝璇峰嬁閲嶅鎻愪氦");
-        }
-        DocType docType = docTypeService.selectOrAdd(param.getOrderType(), Boolean.TRUE);
-        Date now = new Date();
-        // 鍗曟嵁涓绘。
-        order = new OrderPakin(
-                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 (!orderPakinService.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.getBrand(), detail.getStandby1(), detail.getStandby2(), detail.getStandby3(), detail.getLineNumber(), detail.getBoxType1(), detail.getBoxType2(), detail.getBoxType3(), detail.getAnfme());
-            if (DetlDto.hasLineNumber(list, dto)) {
-                DetlDto detlDto = DetlDto.findLineNumber(list, dto.getMatnr(), dto.getBatch(), dto.getBrand(), dto.getStandby1(), dto.getStandby2(), dto.getStandby3(), dto.getLineNumber(), dto.getBoxType1(), dto.getBoxType2(), dto.getBoxType3());
-                assert detlDto != null;
-                detlDto.setAnfme(detlDto.getAnfme() + detail.getAnfme());
+        if (optType.equals("add")) {
+            if (!Cools.isEmpty(order)) {
+                throw new CoolException(param.getOrderNo() + "鍗曟嵁宸插瓨鍦紝璇峰嬁閲嶅鎻愪氦");
+            }
+            DocType docType = docTypeService.selectOrAdd(orderType, Boolean.TRUE);
+            Date now = new Date();
+            // 鍗曟嵁涓绘。
+            order = new OrderPakin(
+                    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,    // 鐘舵��
+                    null,    // 娣诲姞浜哄憳
+                    now,    // 娣诲姞鏃堕棿
+                    null,    // 淇敼浜哄憳
+                    now,    // 淇敼鏃堕棿
+                    null  // 澶囨敞
+            );
+            if (!orderPakinService.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.getBrand(), detail.getStandby1(), detail.getStandby2(), detail.getStandby3(), detail.getLineNumber(), detail.getBoxType1(), detail.getBoxType2(), detail.getBoxType3(), detail.getAnfme());
+                if (DetlDto.hasLineNumber(list, dto)) {
+                    DetlDto detlDto = DetlDto.findLineNumber(list, dto.getMatnr(), dto.getBatch(), dto.getBrand(), dto.getStandby1(), dto.getStandby2(), dto.getStandby3(), dto.getLineNumber(), dto.getBoxType1(), dto.getBoxType2(), dto.getBoxType3());
+                    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() + "缂栧彿鍟嗗搧妫�绱㈠け璐ワ紝璇峰厛娣诲姞鍟嗗搧");
+                }
+                OrderDetlPakin orderDetl = new OrderDetlPakin();
+                orderDetl.sync(mat);
+                orderDetl.setLineNumber(detlDto.getLineNumber());
+                orderDetl.setBatch(detlDto.getBatch());
+                orderDetl.setAnfme(detlDto.getAnfme());
+                orderDetl.setBrand(detlDto.getBrand());
+                orderDetl.setStandby1(detlDto.getStandby1());
+                orderDetl.setStandby2(detlDto.getStandby2());
+                orderDetl.setStandby3(detlDto.getStandby3());
+                orderDetl.setOrderId(order.getId());
+                orderDetl.setOrderNo(order.getOrderNo());
+                orderDetl.setCreateBy(null);
+                orderDetl.setCreateTime(now);
+                orderDetl.setUpdateBy(null);
+                orderDetl.setUpdateTime(now);
+                orderDetl.setStatus(1);
+                orderDetl.setQty(0.0D);
+                orderDetl.setPakinPakoutStatus(1);
+                if (!orderDetlPakinService.insert(orderDetl)) {
+                    throw new CoolException("鐢熸垚鍗曟嵁鏄庣粏澶辫触锛岃鑱旂郴绠$悊鍛�");
+                }
+            }
+        } else if (optType.equals("delete")) {
+            if (Cools.isEmpty(order)) {
+                throw new CoolException(orderNo + "鍗曟嵁涓嶅瓨鍦紒");
+            }
+
+            // 璁㈠崟鐘舵��
+            Long settle = order.getSettle();
+            if (settle == 1) {
+                // 鍒犻櫎璁㈠崟鏄庣粏
+                orderDetlPakinService.delete(new EntityWrapper<OrderDetlPakin>().eq("order_id", order.getId()));
+                // 鍒犻櫎璁㈠崟涓昏〃
+                orderPakinService.delete(new EntityWrapper<OrderPakin>().eq("id", order.getId()));
             } else {
-                list.add(dto);
+                throw new CoolException(orderNo + ":璁㈠崟宸插鐞嗭紝鏃犳硶鍙栨秷");
             }
-        }
-        for (DetlDto detlDto : list) {
-            Mat mat = matService.selectByMatnr(detlDto.getMatnr());
-            if (Cools.isEmpty(mat)) {
-                throw new CoolException(detlDto.getMatnr() + "缂栧彿鍟嗗搧妫�绱㈠け璐ワ紝璇峰厛娣诲姞鍟嗗搧");
-            }
-            OrderDetlPakin orderDetl = new OrderDetlPakin();
-            orderDetl.sync(mat);
-            orderDetl.setLineNumber(detlDto.getLineNumber());
-            orderDetl.setBatch(detlDto.getBatch());
-            orderDetl.setAnfme(detlDto.getAnfme());
-            orderDetl.setBrand(detlDto.getBrand());
-            orderDetl.setStandby1(detlDto.getStandby1());
-            orderDetl.setStandby2(detlDto.getStandby2());
-            orderDetl.setStandby3(detlDto.getStandby3());
-            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);
-            orderDetl.setPakinPakoutStatus(1);
-            if (!orderDetlPakinService.insert(orderDetl)) {
-                throw new CoolException("鐢熸垚鍗曟嵁鏄庣粏澶辫触锛岃鑱旂郴绠$悊鍛�");
-            }
+        } else {
+            throw new CoolException(orderNo + "锛屾搷浣滅被鍨嬩笉瀛樺湪锛�" + optType);
         }
     }
 
@@ -204,97 +335,118 @@
     @Override
     @Transactional
     public void pakoutOrderCreate(OpenOrderPakoutParam param) {
+        String orderNo = param.getOrderNo();
+        String optType = param.getOptType();
+        String orderType = param.getOrderType();
         OrderPakout order = orderPakoutService.selectByNo(param.getOrderNo());
         // 濡傛灉鍗曟嵁涓嶅瓨鍦ㄥ垯娣诲姞锛涘鏋滃崟鎹瓨鍦紝浣滀笟涓棤娉曚慨鏀癸紝鍙嶄箣鍒欎慨鏀瑰崟鎹�
-        if (!Cools.isEmpty(order)) {
-            if (order.getSettle() > 1L) {
-                throw new CoolException(param.getOrderNo() + "姝e湪鍑哄簱锛屾棤娉曚慨鏀瑰崟鎹�");
+        if (optType.equals("add")) {
+            if (!Cools.isEmpty(order)) {
+                if (order.getSettle() > 1L) {
+                    throw new CoolException(param.getOrderNo() + "璁㈠崟宸插瓨鍦�");
+                }
+                orderPakoutService.remove(order.getId());
             }
-            orderPakoutService.remove(order.getId());
-        }
-        DocType docType = docTypeService.selectOrAdd(param.getOrderType(), Boolean.FALSE);
-        Date now = new Date();
-        // 鍗曟嵁涓绘。
-        order = new OrderPakout(
-                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 (!orderPakoutService.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.getBrand(), detail.getStandby1(), detail.getStandby2(), detail.getStandby3(), detail.getLineNumber(),
-                    detail.getBoxType1(), detail.getBoxType2(), detail.getBoxType3(), detail.getAnfme());
-            if (DetlDto.hasLineNumber(list, dto)) {
-                DetlDto detlDto = DetlDto.findLineNumber(list, dto.getMatnr(), dto.getBatch(), dto.getBrand(), dto.getStandby1(), dto.getStandby2(), dto.getStandby3(), dto.getLineNumber(),
-                        dto.getBoxType1(), dto.getBoxType2(), dto.getBoxType3());
-                assert detlDto != null;
-                detlDto.setAnfme(detlDto.getAnfme() + detail.getAnfme());
+            DocType docType = docTypeService.selectOrAdd(orderType, Boolean.FALSE);
+            Date now = new Date();
+            // 鍗曟嵁涓绘。
+            order = new OrderPakout(
+                    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,    // 鐘舵��
+                    null,    // 娣诲姞浜哄憳
+                    now,    // 娣诲姞鏃堕棿
+                    null,    // 淇敼浜哄憳
+                    now,    // 淇敼鏃堕棿
+                    null    // 澶囨敞
+            );
+            if (!orderPakoutService.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.getBrand(), detail.getStandby1(), detail.getStandby2(), detail.getStandby3(), detail.getLineNumber(),
+                        detail.getBoxType1(), detail.getBoxType2(), detail.getBoxType3(), detail.getAnfme());
+                if (DetlDto.hasLineNumber(list, dto)) {
+                    DetlDto detlDto = DetlDto.findLineNumber(list, dto.getMatnr(), dto.getBatch(), dto.getBrand(), dto.getStandby1(), dto.getStandby2(), dto.getStandby3(), dto.getLineNumber(),
+                            dto.getBoxType1(), dto.getBoxType2(), dto.getBoxType3());
+                    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() + "缂栧彿鍟嗗搧妫�绱㈠け璐ワ紝璇峰厛娣诲姞鍟嗗搧");
+                }
+                OrderDetlPakout orderDetl = new OrderDetlPakout();
+                orderDetl.sync(mat);
+                orderDetl.setLineNumber(detlDto.getLineNumber());
+                orderDetl.setBatch(detlDto.getBatch());
+                orderDetl.setAnfme(detlDto.getAnfme());
+                orderDetl.setBrand(detlDto.getBrand());
+                orderDetl.setStandby1(detlDto.getStandby1());
+                orderDetl.setStandby2(detlDto.getStandby2());
+                orderDetl.setStandby3(detlDto.getStandby3());
+                orderDetl.setOrderId(order.getId());
+                orderDetl.setOrderNo(order.getOrderNo());
+                orderDetl.setCreateBy(null);
+                orderDetl.setCreateTime(now);
+                orderDetl.setUpdateBy(null);
+                orderDetl.setUpdateTime(now);
+                orderDetl.setStatus(1);
+                orderDetl.setQty(0.0D);
+                orderDetl.setPakinPakoutStatus(2);
+                if (!orderDetlPakoutService.insert(orderDetl)) {
+                    throw new CoolException("鐢熸垚鍗曟嵁鏄庣粏澶辫触锛岃鑱旂郴绠$悊鍛�");
+                }
+            }
+        } else if (optType.equals("delete")) {
+            if (Cools.isEmpty(order)) {
+                throw new CoolException(orderNo + "鍗曟嵁涓嶅瓨鍦紒");
+            }
+            // 璁㈠崟鐘舵��
+            Long settle = order.getSettle();
+            if (settle == 1) {
+                // 鍒犻櫎璁㈠崟鏄庣粏
+                orderDetlPakoutService.delete(new EntityWrapper<OrderDetlPakout>().eq("order_id", order.getId()));
+                // 鍒犻櫎璁㈠崟涓昏〃
+                orderPakoutService.delete(new EntityWrapper<OrderPakout>().eq("id", order.getId()));
             } else {
-                list.add(dto);
+                throw new CoolException(orderNo + ":璁㈠崟宸插鐞嗭紝鏃犳硶鍙栨秷");
             }
-        }
-        for (DetlDto detlDto : list) {
-            Mat mat = matService.selectByMatnr(detlDto.getMatnr());
-            if (Cools.isEmpty(mat)) {
-                throw new CoolException(detlDto.getMatnr() + "缂栧彿鍟嗗搧妫�绱㈠け璐ワ紝璇峰厛娣诲姞鍟嗗搧");
-            }
-            OrderDetlPakout orderDetl = new OrderDetlPakout();
-            orderDetl.sync(mat);
-            orderDetl.setLineNumber(detlDto.getLineNumber());
-            orderDetl.setBatch(detlDto.getBatch());
-            orderDetl.setAnfme(detlDto.getAnfme());
-            orderDetl.setBrand(detlDto.getBrand());
-            orderDetl.setStandby1(detlDto.getStandby1());
-            orderDetl.setStandby2(detlDto.getStandby2());
-            orderDetl.setStandby3(detlDto.getStandby3());
-            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);
-            orderDetl.setPakinPakoutStatus(2);
-            if (!orderDetlPakoutService.insert(orderDetl)) {
-                throw new CoolException("鐢熸垚鍗曟嵁鏄庣粏澶辫触锛岃鑱旂郴绠$悊鍛�");
-            }
+        } else {
+            throw new CoolException(orderNo + "锛屾搷浣滅被鍨嬩笉瀛樺湪锛�" + optType);
         }
     }
 
@@ -473,111 +625,93 @@
     @Override
     @Transactional
     public void syncMat(MatSyncParam param) {
-        if (Cools.isEmpty(param.getMatDetails()) || param.getMatDetails().size() <= 0) {
-            throw new CoolException("鍟嗗搧鏁版嵁涓虹┖");
-        }
-
+        Date now = new Date();
         for (MatSyncParam.MatParam matParam : param.getMatDetails()) {
-            if (Cools.isEmpty(matParam.getMatnr())) {
-                throw new CoolException("鍟嗗搧缂栫爜涓嶈兘涓虹┖");
+            String logInfo = "optType:" + matParam.getOptType() + ",matnr:" + matParam.getMatnr() + ",maktx:" + matParam.getMaktx() + ",specs:" + matParam.getSpecs();
+            if (Cools.isEmpty(matParam.getOptType(), matParam.getMatnr(), matParam.getMaktx())) {
+                throw new CoolException("鍟嗗搧淇℃伅涓嶈兘涓虹┖[" + logInfo + "]");
             }
-
-            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("鏈嶅姟鍣ㄥ唴閮ㄩ敊璇紝璇疯仈绯荤鐞嗗憳");
-                        }
+            switch (matParam.getOptType()) {
+                case "add":
+                    if (mat != null) {
+                        throw new CoolException("鍟嗗搧淇℃伅宸茬粡瀛樺湪[" + logInfo + "]");
                     }
-                    // 浜岀骇鍒嗙被
-                    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("鏈嶅姟鍣ㄥ唴閮ㄩ敊璇紝璇疯仈绯荤鐞嗗憳");
+                    mat = new Mat();
+                    // 鍒嗙被
+                    Long tagId;
+                    // 涓�绾у垎绫�
+                    if (!Cools.isEmpty(matParam.getGroupName())) {
+                        Tag priTag = tagService.selectByName(matParam.getGroupName(), 2);
+                        if (priTag == null) {
+                            Tag top = tagService.getTop();
+                            NodeUtils nodeUtils = new NodeUtils();
+                            nodeUtils.executePath(top.getId());
+                            priTag = new Tag(
+                                    null,    // 缂栧彿
+                                    matParam.getGroupName(),    // 鍚嶇О
+                                    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("鏈嶅姟鍣ㄥ唴閮ㄩ敊璇紝璇疯仈绯荤鐞嗗憳");
+                            }
                         }
+                        tagId = priTag.getId();
+                    } else {
+                        tagId = tagService.getTop().getId();
                     }
-                    tagId = secTag.getId();
-                } else {
-                    tagId = tagService.getTop().getId();
-                }
-                mat.sync(matParam);
-//            mat.setMatnr(param.getMatnr());
-//            mat.setMaktx(param.getMaktx());
-//            mat.setSpecs(param.getSpecs());
-//            mat.setModel(param.getModel());
-
-                mat.setTagId(tagId);
-                mat.setLocType(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(matParam);
-                if (!matService.update(mat, new EntityWrapper<Mat>().eq("matnr", matParam.getMatnr()))) {
-                    throw new CoolException("鏇存柊宸插瓨鍦ㄥ晢鍝佷俊鎭け璐ワ紝璇疯仈绯荤鐞嗗憳");
-                }
+                    mat.sync(matParam);
+                    mat.setTagId(tagId);
+                    mat.setStatus(1);
+                    mat.setCreateTime(now);
+                    mat.setUpdateTime(now);
+                    if (!matService.insert(mat)) {
+                        throw new CoolException("鍚屾鏂扮墿鏂欓敊璇痆" + logInfo + "]");
+                    } else {
+                        log.info("鍚屾鏂扮墿鏂橻{}]", logInfo);
+                    }
+                    break;
+                case "delete":
+                    if (mat == null) {
+                        throw new CoolException("鍟嗗搧淇℃伅涓嶅瓨鍦╗" + logInfo + "]");
+                    }
+                    if (matService.delete(new EntityWrapper<Mat>().eq("matnr", matParam.getMatnr()))) {
+                        log.info("鍒犻櫎鐗╂枡[{}]", logInfo);
+                    } else {
+                        throw new CoolException("鍒犻櫎宸插瓨鍦ㄥ晢鍝佷俊鎭け璐" + logInfo + "]");
+                    }
+                    break;
+                case "update":
+                    if (mat == null) {
+                        throw new CoolException("鍟嗗搧淇℃伅涓嶅瓨鍦╗" + logInfo + "]");
+                    }
+                    mat.sync(matParam);
+                    if (!matService.update(mat, new EntityWrapper<Mat>().eq("matnr", matParam.getMatnr()))) {
+                        throw new CoolException("鏇存柊宸插瓨鍦ㄥ晢鍝佷俊鎭け璐" + logInfo + "]");
+                    } else {
+                        log.info("鏇存柊鐗╂枡[锛歿}]", logInfo);
+                    }
+                    break;
+                default:
+                    throw new CoolException("鍟嗗搧淇℃伅鎿嶄綔绫诲瀷涓嶅瓨鍦╗" + logInfo + "]");
             }
         }
-
     }
 
 }

--
Gitblit v1.9.1