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/MobileServiceImpl.java |  255 +++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 199 insertions(+), 56 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 a8cb3bb..162604f 100644
--- a/src/main/java/com/zy/asrs/service/impl/MobileServiceImpl.java
+++ b/src/main/java/com/zy/asrs/service/impl/MobileServiceImpl.java
@@ -1,27 +1,23 @@
 package com.zy.asrs.service.impl;
 
-import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.mapper.EntityWrapper;
 import com.baomidou.mybatisplus.mapper.Wrapper;
-import com.core.common.*;
+import com.core.common.BaseRes;
+import com.core.common.Cools;
+import com.core.common.R;
+import com.core.common.SnowflakeIdWorker;
 import com.core.exception.CoolException;
 import com.zy.asrs.entity.*;
+import com.zy.asrs.entity.param.CheckBom;
 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 com.zy.common.utils.Synchro;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -79,14 +75,19 @@
     private ManLocDetlService manLocDetlService;
     @Autowired
     private ManLocDetlMapper manLocDetlMapper;
-
     @Autowired
     private  DocTypeService docTypeService;
+    @Autowired
+    private MatV2Service matV2Service;
+
     @Override
     @Transactional
     public void comb(CombParam param, Long userId) {
         if (Cools.isEmpty(param.getBarcode(), param.getCombMats())) {
             throw new CoolException(BaseRes.PARAM);
+        }
+        if(param.getCombMats().stream().anyMatch(obj -> obj.getAnfme() == null)){
+            throw new CoolException("鍏ュ簱鐗╂枡鏁伴噺涓嶈兘涓虹┖");
         }
         // 鍒ゆ柇鏄惁鏈夌浉鍚屾潯鐮佺殑鏁版嵁
         if (waitPakinService.selectCount(new EntityWrapper<WaitPakin>().
@@ -136,11 +137,17 @@
 
             for (DetlDto detlDto : detlDtos) {
                 Mat mat = matService.selectByMatnr(detlDto.getMatnr());
-                if (Cools.isEmpty(mat)) {
-                    throw new CoolException(detlDto.getMatnr() + "鍟嗗搧妗f涓嶅瓨鍦�");
-                }
                 WaitPakin waitPakin = new WaitPakin();
-                waitPakin.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() + "鍟嗗搧妗f涓嶅瓨鍦�");
+                    }
+                    waitPakin.sync(matV2);
+                    waitPakin.setBrand("缁勪欢");
+                } else {
+                    waitPakin.sync(mat);
+                }
                 waitPakin.setBatch(detlDto.getBatch());
                 waitPakin.setZpallet(param.getBarcode());   // 鎵樼洏鐮�
                 waitPakin.setIoStatus("N");     // 鍏ュ嚭鐘舵��
@@ -213,6 +220,159 @@
 
         }
 
+    }
+
+    @Override
+    @Transactional
+    public void comb2(CombParam param, Long userId) {
+
+        if (Cools.isEmpty(param.getBarcode(), param.getCombMats())) {
+            throw new CoolException(BaseRes.PARAM);
+        }
+        if(param.getCombMats().stream().anyMatch(obj -> obj.getAnfme() == null)){
+            throw new CoolException("鍏ュ簱鐗╂枡鏁伴噺涓嶈兘涓虹┖");
+        }
+        // 鍒ゆ柇鏄惁鏈夌浉鍚屾潯鐮佺殑鏁版嵁
+        if (waitPakinService.selectCount(new EntityWrapper<WaitPakin>().
+                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();
+
+        // 鏃犲崟缁勬墭
+        if (Cools.isEmpty(param.getCombMats().get(0).getOrderNo())) {
+
+            // 鐢熸垚鍏ュ簱閫氱煡妗�
+            List<DetlDto> detlDtos = new ArrayList<>();
+            param.getCombMats().forEach(elem -> {
+                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);
+                }
+            });
+
+
+            for (DetlDto detlDto : detlDtos) {
+                Mat mat = matService.selectByMatnr(detlDto.getMatnr());
+                WaitPakin waitPakin = new WaitPakin();
+                if (Cools.isEmpty(mat)) {
+                    MatV2 matV2 = matV2Service.selectOne(new EntityWrapper<MatV2>().eq("matnr", detlDto.getMatnr()));
+                    if(Cools.isEmpty(matV2)){
+                        throw new CoolException(detlDto.getMatnr() + "鍟嗗搧妗f涓嶅瓨鍦�");
+                    }
+                    waitPakin.sync(matV2);
+                    waitPakin.setBrand("缁勪欢");
+                } else {
+                    waitPakin.sync(mat);
+                }
+                waitPakin.setBatch(detlDto.getBatch());
+                waitPakin.setZpallet(param.getBarcode());   // 鎵樼洏鐮�
+                waitPakin.setIoStatus("N");     // 鍏ュ嚭鐘舵��
+                waitPakin.setAnfme(detlDto.getAnfme());  // 鏁伴噺
+                waitPakin.setStatus("Y");    // 鐘舵��
+                waitPakin.setAppeUser(userId);
+                waitPakin.setBomCode(param.getBomCode());
+                waitPakin.setAppeTime(now);
+                waitPakin.setModiUser(userId);
+                waitPakin.setModiTime(now);
+                if (!waitPakinService.insert(waitPakin)) {
+                    throw new CoolException("淇濆瓨鍏ュ簱閫氱煡妗eけ璐�");
+                }
+            }
+            // 鍏宠仈缁勬墭
+        } else {
+            for (CombParam.CombMat combMat : param.getCombMats()) {
+                // 鐢熸垚鍏ュ簱閫氱煡妗�
+                Order order = orderService.selectByNo(combMat.getOrderNo());
+
+                //鍒ゆ柇璁㈠崟绫诲瀷鏄惁鏄叆搴�
+                DocType docType=docTypeService.selectById(order.getDocType());
+                if(docType.getPakin()!=1 || docType.getStatus()!=1){
+                    throw new CoolException("璁㈠崟涓哄嚭搴撹鍗曪紝涓嶈兘缁勬墭锛�");
+                }
+
+                if (order.getSettle() > 2) {
+                    throw new CoolException("鍗曟嵁缂栧彿宸茶繃鏈�");
+                }
+                OrderDetl orderDetl = orderDetlService.selectItem(combMat.getOrderNo(), combMat.getMatnr(), combMat.getBatch());
+                if (orderDetl == null) {
+                    throw new CoolException("鎵句笉鍒扮粍鎵樼殑鍗曟嵁鏄庣粏");
+                }
+                //璁㈠崟鏁�-宸ヤ綔涓殑鏁伴噺-缁勬墭鏁伴噺
+                if ( orderDetl.getAnfme() - orderDetl.getWorkQty() - combMat.getAnfme()<0) {
+                    throw new CoolException("缁勬墭鏁伴噺宸茶秴鍑鸿鍗曢渶姹傞噺锛岃妫�鏌ユ槸鍚︽湁鍏朵粬鐨勭粍鎵樺凡瀹屾垚");
+                }
+                // 淇敼璁㈠崟浣滀笟鏁伴噺
+                if (!orderDetlService.increaseWorkQty(order.getId(), combMat.getMatnr(), combMat.getBatch(), combMat.getAnfme())) {
+                    throw new CoolException("淇敼鍗曟嵁浣滀笟鏁伴噺澶辫触");
+                }
+                Mat mat = matService.selectByMatnr(combMat.getMatnr());
+                if (Cools.isEmpty(mat)) {
+                    throw new CoolException(combMat.getMatnr() + "鍟嗗搧妗f涓嶅瓨鍦�");
+                }
+                WaitPakin waitPakin = new WaitPakin();
+                waitPakin.sync(mat);
+                waitPakin.setOrderNo(order.getOrderNo());   // 鍗曟嵁缂栧彿
+                waitPakin.setBatch(combMat.getBatch());     // 搴忓垪鐮�
+                waitPakin.setZpallet(param.getBarcode());   // 鎵樼洏鐮�
+                waitPakin.setIoStatus("N");     // 鍏ュ嚭鐘舵��
+                waitPakin.setAnfme(combMat.getAnfme());  // 鏁伴噺
+                waitPakin.setStatus("Y");    // 鐘舵��
+                waitPakin.setAppeUser(userId);
+                waitPakin.setAppeTime(now);
+                waitPakin.setBomCode(param.getBomCode());
+                waitPakin.setModiUser(userId);
+                waitPakin.setModiTime(now);
+                if (!waitPakinService.insert(waitPakin)) {
+                    throw new CoolException("淇濆瓨鍏ュ簱閫氱煡妗eけ璐�");
+                }
+
+//                DetlDto detlDto = new DetlDto(combMat.getMatnr(), combMat.getBatch(), combMat.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 {
+//                }
+                orderService.updateSettle(order.getId(), 2L, userId);
+            }
+
+        }
+
+    }
+
+    @Override
+    @Transactional
+    public R checkBom(CheckBom param, Long userId) {
+
+
+        return R.ok();
     }
 
     // 鍟嗗搧涓婃灦
@@ -669,20 +829,18 @@
                 return R.error("璇ヨ鍗曟槸鍑哄簱璁㈠崟锛屾棤娉曞叆搴�");
             }
 
-            OrderDetl orderDetl = orderDetlService.selectOne(new EntityWrapper<OrderDetl>()
-                    .eq("order_no", jsonOrderDetl.getOrderNo())
-                    .and()
-                    .eq("maktx",jsonOrderDetl.getMaktx()));
+            OrderDetl orderDetl = orderDetlService.selectItem(jsonOrderDetl.getOrderNo(),jsonOrderDetl.getMatnr(),jsonOrderDetl.getBatch());
             if (Cools.isEmpty(orderDetl)) {
                 return R.error("鍗曟嵁鏄庣粏鏈夎,璇锋鏌�");
+            }
+            if (Cools.isEmpty(orderDetl.getAnfme())) {
+                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())
-                    .eq("batch",orderDetl.getBatch()));
+            //鏌ヨ骞冲簱涓槸鍚︽湁涓�鏍风殑鍝佸彿锛屾湁鐨勮瘽鐩存帴澧炲姞鏁伴噺
+            ManLocDetl checkManLocDetl = manLocDetlService.selectInventory(jsonLocNo,orderDetl.getMatnr(),jsonOrderDetl.getBatch());
             if (checkManLocDetl == null) {
                 ManLocDetl manLocDetl = new ManLocDetl();
                 Synchro.Copy(orderDetl, manLocDetl);
@@ -694,13 +852,13 @@
                 manLocDetl.setModiTime(date);
                 manLocDetl.setCreateTime(date);
                 manLocDetl.setBatch(jsonOrderDetl.getBatch());
-                manLocDetlService.insert(manLocDetl);
+                if(!manLocDetlService.insert(manLocDetl)){
+                    return R.error("淇敼骞冲簱鐗╂枡澶辫触锛�");
+                }
             } else {
-                checkManLocDetl.setAnfme(checkManLocDetl.getAnfme() + jsonOrderDetl.getAnfme());
-                checkManLocDetl.setModiTime(date);
-                manLocDetlService.update(checkManLocDetl, new EntityWrapper<ManLocDetl>()
-                        .eq("loc_no", jsonLocNo)
-                        .eq("matnr", orderDetl.getMatnr()));
+                if(manLocDetlService.increase(checkManLocDetl.getAnfme() + jsonOrderDetl.getAnfme(), jsonOrderDetl.getOrderNo(), jsonOrderDetl.getMaktx(), jsonOrderDetl.getBatch())<=0){
+                    return R.error("淇敼骞冲簱鐗╂枡澶辫触锛�");
+                }
             }
             orderDetl.setQty(orderDetl.getQty() + jsonOrderDetl.getAnfme());
             orderDetl.setWorkQty(orderDetl.getWorkQty() + jsonOrderDetl.getAnfme());
@@ -748,46 +906,30 @@
             if (Cools.isEmpty(node, order)) {
                 return R.error("鍙傛暟涓虹┖");
             }
-            OrderDetl orderDetl = orderDetlService.selectOne(new EntityWrapper<OrderDetl>()
-                    .eq("order_no", jsonOrderDetl.getOrderNo())
-                    .and()
-                    .eq("maktx",jsonOrderDetl.getMaktx())
-                    .and()
-                    .eq("batch",jsonOrderDetl.getBatch()));
+            OrderDetl orderDetl = orderDetlService.selectItem(jsonOrderDetl.getOrderNo(),jsonOrderDetl.getMatnr(),jsonOrderDetl.getBatch());
             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)
-                    .and()
-                    .eq("maktx", jsonOrderDetl.getMaktx())
-                    .and()
-                    .eq("batch",jsonOrderDetl.getBatch()));
-            if (manLocDetl == null) {
+            //鏌ヨ骞冲簱涓槸鍚︽湁涓�鏍风殑鍝佸彿
+            ManLocDetl checkManLocDetl = manLocDetlService.selectInventory(jsonLocNo,orderDetl.getMatnr(),orderDetl.getBatch());
+            if (checkManLocDetl == null) {
                 return R.error("璇ュ簱浣嶆病鏈夊嚭搴撶殑鐗╂枡淇℃伅");
             }
-            if (jsonOrderDetl.getAnfme() > manLocDetl.getAnfme()) {
+            if (jsonOrderDetl.getAnfme() > checkManLocDetl.getAnfme()) {
                 return R.error("鍑哄簱鏁伴噺澶т簬鍙嚭鏁伴噺");
             }
-            Double finalQty = manLocDetl.getAnfme() - jsonOrderDetl.getAnfme();
+            Double finalQty = checkManLocDetl.getAnfme() - jsonOrderDetl.getAnfme();
             if (finalQty <= 0){
-                manLocDetlService.delete(new EntityWrapper<ManLocDetl>()
-                        .eq("loc_no", jsonLocNo)
-                        .and()
-                        .eq("matnr", orderDetl.getMatnr())
-                        .and()
-                        .eq("batch",jsonOrderDetl.getBatch()));
+                if(manLocDetlService.deleteDatailed(jsonLocNo, jsonOrderDetl.getMatnr(), jsonOrderDetl.getBatch())<=0){
+                    return R.error("淇敼骞冲簱鐗╂枡澶辫触锛�");
+                }
             }else {
-                manLocDetl.setAnfme(finalQty);
-                manLocDetl.setModiTime(date);
-                manLocDetlService.update(manLocDetl,new EntityWrapper<ManLocDetl>()
-                        .eq("loc_no", jsonLocNo)
-                        .eq("matnr", orderDetl.getMatnr())
-                        .and()
-                        .eq("batch",jsonOrderDetl.getBatch()));
+                if(manLocDetlService.increase(finalQty, jsonLocNo, jsonOrderDetl.getMatnr(), jsonOrderDetl.getBatch())<=0){
+                    return R.error("淇敼骞冲簱鐗╂枡澶辫触锛�");
+                }
             }
             orderDetl.setQty(orderDetl.getQty() + jsonOrderDetl.getAnfme());
             orderDetl.setWorkQty(orderDetl.getWorkQty() + jsonOrderDetl.getAnfme());
@@ -814,4 +956,5 @@
         return R.ok("涓嬫灦瀹屾垚");
     }
 
+
 }

--
Gitblit v1.9.1