From 08b4403ec8d6b69528d161cfcad80b5d64dea76c Mon Sep 17 00:00:00 2001
From: Administrator <876263681@qq.com>
Date: 星期三, 02 七月 2025 15:12:43 +0800
Subject: [PATCH] #优化库位检索

---
 src/main/java/com/zy/asrs/service/impl/OpenServiceImpl.java |  254 ++++++++------------------------------------------
 1 files changed, 42 insertions(+), 212 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 8407805..37ff2a8 100644
--- a/src/main/java/com/zy/asrs/service/impl/OpenServiceImpl.java
+++ b/src/main/java/com/zy/asrs/service/impl/OpenServiceImpl.java
@@ -1,7 +1,5 @@
 package com.zy.asrs.service.impl;
 
-import com.alibaba.fastjson.JSONArray;
-import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.mapper.EntityWrapper;
 import com.core.common.Cools;
 import com.core.common.DateUtils;
@@ -9,17 +7,17 @@
 import com.core.common.SnowflakeIdWorker;
 import com.core.exception.CoolException;
 import com.zy.asrs.entity.*;
-import com.zy.asrs.entity.param.*;
+import com.zy.asrs.entity.param.MatSyncParam;
+import com.zy.asrs.entity.param.OpenOrderPakinParam;
+import com.zy.asrs.entity.param.OpenOrderPakoutParam;
+import com.zy.asrs.entity.param.PackParam;
 import com.zy.asrs.entity.result.InOutCountDto;
-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.asrs.utils.Utils;
 import com.zy.common.model.DetlDto;
 import com.zy.common.utils.NodeUtils;
-import com.zy.common.utils.Synchro;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -60,6 +58,8 @@
     private NodeService nodeService;
     @Autowired
     private ManLocDetlService manLocDetlService;
+    @Autowired
+    private MatV2Service matV2Service;
 
     @Override
     @Transactional
@@ -125,11 +125,16 @@
         }
         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);
+            if (Cools.isEmpty(mat)) {
+                MatV2 matV2 = matV2Service.selectOne(new EntityWrapper<MatV2>().eq("matnr", detlDto.getMatnr()));
+                if(Cools.isEmpty(matV2)){
+                    throw new CoolException(detlDto.getMatnr() + "缂栧彿鍟嗗搧妫�绱㈠け璐ワ紝璇峰厛娣诲姞鍟嗗搧");
+                }
+                orderDetl.sync(matV2);
+            } else {
+                orderDetl.sync(mat);
+            }
 
             //鎵瑰彿涓虹┖浼氬嚭鐜伴棶棰橈紝璁剧疆涓�涓粯璁ゅ��
             if (detlDto.getBatch() == null) {
@@ -267,11 +272,16 @@
         }
         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);
+            if (Cools.isEmpty(mat)) {
+                MatV2 matV2 = matV2Service.selectOne(new EntityWrapper<MatV2>().eq("matnr", detlDto.getMatnr()));
+                if(Cools.isEmpty(matV2)){
+                    throw new CoolException(detlDto.getMatnr() + "缂栧彿鍟嗗搧妫�绱㈠け璐ワ紝璇峰厛娣诲姞鍟嗗搧");
+                }
+                orderDetl.sync(matV2);
+            } else {
+                orderDetl.sync(mat);
+            }
             orderDetl.setBatch(detlDto.getBatch() == null ? "" : detlDto.getBatch());
             orderDetl.setAnfme(detlDto.getAnfme());
             orderDetl.setOrderId(order.getId());
@@ -353,7 +363,7 @@
         Date now = new Date();
         pack = new Pack(
                 param.getBarcode(),    // 鏉$爜[闈炵┖]
-                analyse.getMatnr(),    // 鍟嗗搧缂栧彿
+                analyse.getMatnr(),    // 鍝佸彿
                 analyse.getBarcode(),    // 搴忓垪鐮�
                 1L,    // 璁㈠崟鐘舵��
                 1,    // 鐘舵��
@@ -449,7 +459,7 @@
             if (!matService.insert(mat)) {
                 throw new CoolException("鏈嶅姟鍣ㄥ唴閮ㄩ敊璇紝璇疯仈绯荤鐞嗗憳");
             } else {
-                log.info("鎵撳寘涓婄嚎娣诲姞鏂扮墿鏂橻鍟嗗搧缂栧彿锛歿}]", mat.getMatnr());
+                log.info("鎵撳寘涓婄嚎娣诲姞鏂扮墿鏂橻鍝佸彿锛歿}]", mat.getMatnr());
             }
         }
     }
@@ -463,7 +473,7 @@
 
         for (MatSyncParam.MatParam matParam : param.getMatDetails()) {
             if (Cools.isEmpty(matParam.getMatnr())) {
-                throw new CoolException("鍟嗗搧缂栫爜涓嶈兘涓虹┖");
+                throw new CoolException("鍝佸彿涓嶈兘涓虹┖");
             }
 
             Date now = new Date();
@@ -473,49 +483,17 @@
                 // 鍒嗙被
                 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("鏈嶅姟鍣ㄥ唴閮ㄩ敊璇紝璇疯仈绯荤鐞嗗憳");
-                        }
-                    }
+                if (!Cools.isEmpty(matParam.getGroupName())) {
                     // 浜岀骇鍒嗙被
                     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(),    // 鍏宠仈璺緞鍚�
+                                10010L,    // 鐖剁骇
+                                "鍏ㄩ儴",    // 鐖剁骇鍚嶇О
+                                "10009,10010",    // 鍏宠仈璺緞
+                                "鍏ㄩ儴,鍏ㄩ儴",    // 鍏宠仈璺緞鍚�
                                 0,    // 绫诲瀷
                                 null,    // 璐熻矗浜�
                                 null,    // 鍥剧墖
@@ -533,17 +511,20 @@
                         if (tagMapper.insert(secTag) == 0) {
                             throw new CoolException("鏈嶅姟鍣ㄥ唴閮ㄩ敊璇紝璇疯仈绯荤鐞嗗憳");
                         }
+                        Tag tag = tagService.selectByName(matParam.getGroupName(), 3);
+                        tagId = tag.getId();
+                    } else {
+                        tagId = secTag.getId();
                     }
-                    tagId = secTag.getId();
                 } else {
-                    tagId = tagService.getTop().getId();
+                    throw new CoolException("鍟嗗搧鍒嗙被涓嶈兘涓虹┖");
+//                    tagId = tagService.getTop().getId();
                 }
                 mat.sync(matParam);
 //            mat.setMatnr(para);
 //            mat.setMaktx(param.getMaktx());
 //            mat.setSpecs(param.getSpecs());
 //            mat.setModel(param.getModel());
-
                 mat.setTagId(tagId);
                 mat.setStatus(1);
                 mat.setCreateTime(now);
@@ -551,10 +532,12 @@
                 if (!matService.insert(mat)) {
                     throw new CoolException("鏈嶅姟鍣ㄥ唴閮ㄩ敊璇紝璇疯仈绯荤鐞嗗憳");
                 } else {
-                    log.info("鍚屾鏂扮墿鏂橻鍟嗗搧缂栧彿锛歿}]", mat.getMatnr());
+                    log.info("鍚屾鏂扮墿鏂橻鍝佸彿锛歿}]", mat.getMatnr());
                 }
             } else {
-                mat.sync(param);
+//                mat.sync(param);
+                mat.setMaktx(matParam.getMaktx());
+                mat.setSpecs(matParam.getSpecs());
                 if (!matService.update(mat, new EntityWrapper<Mat>().eq("matnr", matParam.getMatnr()))) {
                     throw new CoolException("鏇存柊宸插瓨鍦ㄥ晢鍝佷俊鎭け璐ワ紝璇疯仈绯荤鐞嗗憳");
                 }
@@ -567,159 +550,6 @@
     public R getInOutDetl() {
         List<InOutCountDto> top100 = wrkMastService.selectTop100();
         return R.ok().add(top100);
-    }
-
-    @Transactional
-    @Override
-    public R manDetlIn(JSONObject json) {
-        Date date = new Date();
-        String jsonLocNo = (String) json.get("locNo");
-        Node node = nodeService.selectOne(new EntityWrapper<Node>()
-                .eq("name", jsonLocNo));
-       //鏌ヨ鍗�
-        String jsonOrderNo = (String) json.get("orderNo");
-        Order order = orderService.selectOne(new EntityWrapper<Order>()
-                .eq("order_no", jsonOrderNo));
-        if (Cools.isEmpty(node, order)) {
-            return R.error("鍙傛暟涓虹┖");
-        }
-
-        //鍒ゆ柇璁㈠崟绫诲瀷鏄惁鏄叆搴�
-        DocType docType=docTypeService.selectById(order.getDocType());
-        if(docType.getPakin()!=1 || docType.getStatus()!=1){
-            return R.error("璇ヨ鍗曟槸鍑哄簱璁㈠崟锛屾棤娉曞叆搴�");
-        }
-
-        JSONArray combMats = json.getJSONArray("combMats");
-        for (int i = 0; i < combMats.size(); i++) {
-            OrderDetl jsonOrderDetl = combMats.getObject(i, OrderDetl.class);
-            OrderDetl orderDetl = orderDetlService.selectOne(new EntityWrapper<OrderDetl>()
-                    .eq("order_no", jsonOrderNo)
-                    .and()
-                    .eq("maktx",jsonOrderDetl.getMaktx()));
-            if (Cools.isEmpty(orderDetl)) {
-                return R.error("鍗曟嵁鏄庣粏鏈夎,璇锋鏌�");
-            }
-            if (orderDetl.getAnfme() - (jsonOrderDetl.getAnfme() + orderDetl.getWorkQty()) < 0) {
-                return R.error("鍏ュ簱鏁伴噺澶т簬鍙叆鏁伴噺");
-            }
-            ManLocDetl checkManLocDetl = manLocDetlService.selectOne(new EntityWrapper<ManLocDetl>()
-                    .eq("loc_no", jsonLocNo)
-                    .eq("matnr", orderDetl.getMatnr()));
-            if (checkManLocDetl == null) {
-                ManLocDetl manLocDetl = new ManLocDetl();
-                Synchro.Copy(orderDetl, manLocDetl);
-                manLocDetl.setLocNo(node.getName());
-                manLocDetl.setNodeId(node.getId());
-                manLocDetl.setMatnr(orderDetl.getMatnr());
-                manLocDetl.setMaktx(jsonOrderDetl.getMaktx());
-                manLocDetl.setAnfme(jsonOrderDetl.getAnfme());
-                manLocDetl.setModiTime(date);
-                manLocDetl.setCreateTime(date);
-                manLocDetlService.insert(manLocDetl);
-            } else {
-                checkManLocDetl.setAnfme(checkManLocDetl.getAnfme() + jsonOrderDetl.getAnfme());
-                checkManLocDetl.setModiTime(date);
-                manLocDetlService.update(checkManLocDetl, new EntityWrapper<ManLocDetl>()
-                        .eq("loc_no", jsonLocNo)
-                        .eq("matnr", orderDetl.getMatnr()));
-            }
-            orderDetl.setQty(orderDetl.getQty() + jsonOrderDetl.getAnfme());
-            orderDetl.setWorkQty(orderDetl.getWorkQty() + jsonOrderDetl.getAnfme());
-            orderDetl.setUpdateTime(date);
-            orderDetlService.updateById(orderDetl);
-
-            //鏇存柊璁㈠崟鐘舵��
-            //宸ヤ綔涓殑鏁伴噺灏忎簬鎬昏鍗曟暟鏃讹紝璁㈠崟鐘舵�佹敼涓�2锛屼綔涓氫腑
-            if(orderDetl.getWorkQty() + jsonOrderDetl.getAnfme() < orderDetl.getAnfme()){
-                order.setSettle(2L);
-            }else{
-                //宸ヤ綔涓殑鏁伴噺绛変簬鎬昏鍗曟暟鏃讹紝璁㈠崟鐘舵�佹敼涓�4,瀹屾垚
-                order.setSettle(4L);
-            }
-            if(!orderService.updateById(order)){
-                return R.error("鏇存柊璁㈠崟鐘舵�佸け璐�");
-            }
-
-        }
-        orderService.checkComplete(order.getOrderNo());
-
-
-        return R.ok("涓婃灦瀹屾垚");
-    }
-
-    @Transactional
-    @Override
-    public R manDetlOut(JSONObject json) {
-        Date date = new Date();
-        String jsonLocNo = (String) json.get("locNo");
-        Node node = nodeService.selectOne(new EntityWrapper<Node>()
-                .eq("name", jsonLocNo));
-        String jsonOrderNo = (String) json.get("orderNo");
-        Order order = orderService.selectOne(new EntityWrapper<Order>()
-                .eq("order_no", jsonOrderNo));
-
-        //鍒ゆ柇璁㈠崟绫诲瀷鏄惁鏄叆搴�
-        DocType docType=docTypeService.selectById(order.getDocType());
-        if(docType.getPakout()!=1 || docType.getStatus()!=1){
-            return R.error("璇ヨ鍗曟槸鍑哄簱璁㈠崟锛屾棤娉曞叆搴�");
-        }
-        if (Cools.isEmpty(node, order)) {
-            return R.error("鍙傛暟涓虹┖");
-        }
-
-        JSONArray combMats = json.getJSONArray("combMats");
-        for (int i = 0; i < combMats.size(); i++) {
-            OrderDetl jsonOrderDetl = combMats.getObject(i, OrderDetl.class);
-            OrderDetl orderDetl = orderDetlService.selectOne(new EntityWrapper<OrderDetl>()
-                    .eq("order_no", jsonOrderNo));
-            if (Cools.isEmpty(orderDetl)) {
-                return R.error("鍗曟嵁鏄庣粏鏈夎,璇锋鏌�");
-            }
-            if (jsonOrderDetl.getAnfme() > (orderDetl.getAnfme() - orderDetl.getWorkQty())) {
-                return R.error("鍑哄簱鏁伴噺澶т簬鍗曟嵁鍙嚭鏁伴噺");
-            }
-            ManLocDetl manLocDetl = manLocDetlService.selectOne(new EntityWrapper<ManLocDetl>()
-                    .eq("loc_no", jsonLocNo)
-                    .eq("matnr", orderDetl.getMatnr()));
-            if (manLocDetl == null) {
-                return R.error("璇ュ簱浣嶆病鏈夊嚭搴撶殑鐗╂枡淇℃伅");
-            }
-            if (jsonOrderDetl.getAnfme() > manLocDetl.getAnfme()) {
-                return R.error("鍑哄簱鏁伴噺澶т簬鍙嚭鏁伴噺");
-            }
-            Double finalQty = manLocDetl.getAnfme() - jsonOrderDetl.getAnfme();
-            if (finalQty <= 0){
-                manLocDetlService.delete(new EntityWrapper<ManLocDetl>()
-                        .eq("loc_no", jsonLocNo)
-                        .eq("matnr", orderDetl.getMatnr()));
-            }else {
-                manLocDetl.setAnfme(finalQty);
-                manLocDetl.setModiTime(date);
-                manLocDetlService.update(manLocDetl,new EntityWrapper<ManLocDetl>()
-                        .eq("loc_no", jsonLocNo)
-                        .eq("matnr", orderDetl.getMatnr()));
-            }
-            orderDetl.setQty(orderDetl.getQty() + jsonOrderDetl.getAnfme());
-            orderDetl.setWorkQty(orderDetl.getWorkQty() + jsonOrderDetl.getAnfme());
-            orderDetl.setUpdateTime(date);
-            orderDetlService.updateById(orderDetl);
-
-            //鏇存柊璁㈠崟鐘舵��
-            //宸ヤ綔涓殑鏁伴噺灏忎簬鎬昏鍗曟暟鏃讹紝璁㈠崟鐘舵�佹敼涓�2锛屼綔涓氫腑
-            if(orderDetl.getWorkQty() + jsonOrderDetl.getAnfme() < orderDetl.getAnfme()){
-                order.setSettle(2L);
-            }else{
-                //宸ヤ綔涓殑鏁伴噺绛変簬鎬昏鍗曟暟鏃讹紝璁㈠崟鐘舵�佹敼涓�4,瀹屾垚
-                order.setSettle(4L);
-            }
-            if(!orderService.updateById(order)){
-                return R.error("鏇存柊璁㈠崟鐘舵�佸け璐�");
-            }
-
-            orderService.checkComplete(order.getOrderNo());
-        }
-        return R.ok("涓嬫灦瀹屾垚");
     }
 
 }

--
Gitblit v1.9.1