From 83c548d3dba59aaed9b52b5d413c6912a87d2efc Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期日, 16 六月 2024 15:50:14 +0800
Subject: [PATCH] #

---
 zy-asrs-common/src/main/java/com/zy/asrs/common/openapi/service/impl/ApiServiceImpl.java |  209 ++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 170 insertions(+), 39 deletions(-)

diff --git a/zy-asrs-common/src/main/java/com/zy/asrs/common/openapi/service/impl/ApiServiceImpl.java b/zy-asrs-common/src/main/java/com/zy/asrs/common/openapi/service/impl/ApiServiceImpl.java
index 276473f..13b0042 100644
--- a/zy-asrs-common/src/main/java/com/zy/asrs/common/openapi/service/impl/ApiServiceImpl.java
+++ b/zy-asrs-common/src/main/java/com/zy/asrs/common/openapi/service/impl/ApiServiceImpl.java
@@ -3,9 +3,7 @@
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.zy.asrs.common.domain.dto.DetlDto;
 import com.zy.asrs.common.openapi.entity.dto.OrderListDto;
-import com.zy.asrs.common.openapi.entity.param.GenerateOrderPakInParam;
-import com.zy.asrs.common.openapi.entity.param.GenerateOrderPakOutParam;
-import com.zy.asrs.common.openapi.entity.param.OrderListParam;
+import com.zy.asrs.common.openapi.entity.param.*;
 import com.zy.asrs.common.openapi.service.ApiService;
 import com.zy.asrs.common.wms.entity.*;
 import com.zy.asrs.common.wms.service.*;
@@ -15,6 +13,7 @@
 import com.zy.asrs.framework.exception.CoolException;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.util.ArrayList;
 import java.util.Date;
@@ -35,6 +34,8 @@
     private MatService matService;
     @Autowired
     private OrderSettleService orderSettleService;
+    @Autowired
+    private TagService tagService;
 
     @Override
     public void generateOrderPakIn(GenerateOrderPakInParam param) {
@@ -88,28 +89,20 @@
         if (!orderService.save(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.getOne(new LambdaQueryWrapper<Mat>().eq(Mat::getMatnr, detlDto.getMatnr()).eq(Mat::getHostId, param.getHostId()));
+        List<GenerateOrderMatParam> mats = param.getMats();
+        for (GenerateOrderMatParam matParam : mats) {
+            Mat mat = matService.getOne(new LambdaQueryWrapper<Mat>().eq(Mat::getMatnr, matParam.getMatnr()).eq(Mat::getHostId, param.getHostId()));
             if (Cools.isEmpty(mat)) {
-                throw new CoolException(detlDto.getMatnr() + "缂栧彿鍟嗗搧妫�绱㈠け璐ワ紝璇峰厛娣诲姞鍟嗗搧");
+                throw new CoolException(matParam.getMatnr() + "缂栧彿鍟嗗搧妫�绱㈠け璐ワ紝璇峰厛娣诲姞鍟嗗搧");
             }
             OrderDetl orderDetl = new OrderDetl();
             orderDetl.sync(mat);
-            orderDetl.setBatch(detlDto.getBatch());
-            orderDetl.setAnfme(detlDto.getAnfme());
+            orderDetl.setBatch(matParam.getBatch());
+            orderDetl.setAnfme(matParam.getAnfme());
+            orderDetl.setUnit(matParam.getUnit());
+            orderDetl.setThreeCode(matParam.getWarehouse());//浠撳簱鍙�
+            orderDetl.setSupp(matParam.getOrigin());//鏉ユ簮鍗曞彿
+            orderDetl.setSuppCode(matParam.getOriginNo());//鏉ユ簮搴忓彿
             orderDetl.setOrderId(order.getId());
             orderDetl.setOrderNo(order.getOrderNo());
             orderDetl.setCreateBy(9527L);
@@ -180,28 +173,16 @@
         if (!orderService.save(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.getOne(new LambdaQueryWrapper<Mat>().eq(Mat::getMatnr, detlDto.getMatnr()).eq(Mat::getHostId, param.getHostId()));
+        List<GenerateOrderMatParam> mats = param.getMats();
+        for (GenerateOrderMatParam matParam : mats) {
+            Mat mat = matService.getOne(new LambdaQueryWrapper<Mat>().eq(Mat::getMatnr, matParam.getMatnr()).eq(Mat::getHostId, param.getHostId()));
             if (Cools.isEmpty(mat)) {
-                throw new CoolException(detlDto.getMatnr() + "缂栧彿鍟嗗搧妫�绱㈠け璐ワ紝璇峰厛娣诲姞鍟嗗搧");
+                throw new CoolException(matParam.getMatnr() + "缂栧彿鍟嗗搧妫�绱㈠け璐ワ紝璇峰厛娣诲姞鍟嗗搧");
             }
             OrderDetl orderDetl = new OrderDetl();
             orderDetl.sync(mat);
-            orderDetl.setBatch(detlDto.getBatch());
-            orderDetl.setAnfme(detlDto.getAnfme());
+            orderDetl.setBatch(matParam.getBatch());
+            orderDetl.setAnfme(matParam.getAnfme());
             orderDetl.setOrderId(order.getId());
             orderDetl.setOrderNo(order.getOrderNo());
             orderDetl.setCreateBy(9527L);
@@ -253,4 +234,154 @@
         }
         return listDtos;
     }
+
+    @Override
+    @Transactional
+    public int createMat(CreateMatParam param) {
+        int count = 0;
+        Long hostId = param.getHostId();
+        for (MatParam matParam : param.getMats()) {
+            //鑾峰彇鍒嗙被
+            Tag tag = tagService.getTag(matParam.getFirstTag(), matParam.getSecondTag(), hostId);
+
+            matService.remove(new LambdaQueryWrapper<Mat>()
+                    .eq(Mat::getMatnr, matParam.getMatnr())
+                    .eq(Mat::getHostId, hostId));
+            Mat mat = new Mat();
+            mat.setMatnr(matParam.getMatnr());//鐗╂枡鍙�
+            mat.setHostId(hostId);//浠撳簱ID
+            mat.setTagId(tag.getId());//鍒嗙被ID
+            if (!Cools.isEmpty(matParam.getShopCategory())) {
+                Tag shopTag = tagService.getOne(new LambdaQueryWrapper<Tag>()
+                        .eq(Tag::getName, matParam.getShopCategory())
+                        .eq(Tag::getHostId, hostId));
+                if (shopTag == null) {
+                    //鍟嗗搧鍒嗙被涓虹┖锛屽垱寤哄晢鍝佸垎绫�
+                    shopTag = new Tag();
+                    shopTag.setName(matParam.getShopCategory());
+                    shopTag.setParentId(tag.getId());
+                    shopTag.setStatus(1);
+                    shopTag.setHostId(hostId);
+                    shopTag.setCreateTime(new Date());
+                    shopTag.setUpdateTime(new Date());
+                    tagService.save(shopTag);
+                }
+                mat.setTagId(shopTag.getId());//鍒嗙被ID
+            }
+
+            if (!Cools.isEmpty(matParam.getMaktx())) {
+                mat.setMaktx(matParam.getMaktx());
+            }
+            if (!Cools.isEmpty(matParam.getMaktx())) {
+                mat.setMaktx(matParam.getMaktx());
+            }
+            if (!Cools.isEmpty(matParam.getName())) {
+                mat.setName(matParam.getName());
+            }
+            if (!Cools.isEmpty(matParam.getSpecs())) {
+                mat.setSpecs(matParam.getSpecs());
+            }
+            if (!Cools.isEmpty(matParam.getMemo())) {
+                mat.setMemo(matParam.getMemo());
+            }
+            if (!Cools.isEmpty(matParam.getStatus())) {
+                mat.setStatus(matParam.getStatus());
+            }else {
+                mat.setStatus(1);
+            }
+
+            if (!Cools.isEmpty(matParam.getMainHost())) {
+                mat.setMainHost(matParam.getMainHost());
+            }
+            if (!Cools.isEmpty(matParam.getMainSource())) {
+                mat.setMainSource(matParam.getMainSource());
+            }
+            if (!Cools.isEmpty(matParam.getBarcode())) {
+                mat.setBarcode(matParam.getBarcode());
+            }
+            if (!Cools.isEmpty(matParam.getCyclePickCode())) {
+                mat.setCyclePickCode(matParam.getCyclePickCode());
+            }
+            if (!Cools.isEmpty(matParam.getLocationStock())) {
+                mat.setLocationStock(matParam.getLocationStock());
+            }
+            if (!Cools.isEmpty(matParam.getMaterial())) {
+                mat.setMaterial(matParam.getMaterial());
+            }
+            if (!Cools.isEmpty(matParam.getModel())) {
+                mat.setModel(matParam.getModel());
+            }
+            if (!Cools.isEmpty(matParam.getDecrees())) {
+                mat.setDecrees(matParam.getDecrees());
+            }
+            if (!Cools.isEmpty(matParam.getWeight())) {
+                mat.setWeight(matParam.getWeight());
+            }
+            if (!Cools.isEmpty(matParam.getImgNum())) {
+                mat.setImgNum(matParam.getImgNum());
+            }
+            if (!Cools.isEmpty(matParam.getPurchasingUnits())) {
+                mat.setPurchasingUnits(matParam.getPurchasingUnits());
+            }
+            if (!Cools.isEmpty(matParam.getProcessNumber())) {
+                mat.setProcessNumber(matParam.getProcessNumber());
+            }
+            if (!Cools.isEmpty(matParam.getBom())) {
+                mat.setBom(matParam.getBom());
+            }
+            if (!Cools.isEmpty(matParam.getSafeNum())) {
+                mat.setSafeNum(matParam.getSafeNum());
+            }
+            if (!Cools.isEmpty(matParam.getMiniCount())) {
+                mat.setMiniCount(matParam.getMiniCount());
+            }
+            if (!Cools.isEmpty(matParam.getReplenishmentNum())) {
+                mat.setReplenishmentNum(matParam.getReplenishmentNum());
+            }
+            if (!Cools.isEmpty(matParam.getTmp1())) {
+                mat.setTmp1(matParam.getTmp1());
+            }
+            if (!Cools.isEmpty(matParam.getTmp2())) {
+                mat.setTmp2(matParam.getTmp2());
+            }
+            if (!Cools.isEmpty(matParam.getTmp3())) {
+                mat.setTmp3(matParam.getTmp3());
+            }
+            if (!Cools.isEmpty(matParam.getRestockDemand())) {
+                mat.setRestockDemand(matParam.getRestockDemand());
+            }
+            if (!Cools.isEmpty(matParam.getLapse())) {
+                mat.setLapse(matParam.getLapse());
+            }
+            if (!Cools.isEmpty(matParam.getShortcuts())) {
+                mat.setShortcuts(matParam.getShortcuts());
+            }
+            if (!Cools.isEmpty(matParam.getUnits())) {
+                mat.setUnits(matParam.getUnits());
+            }
+            if (!Cools.isEmpty(matParam.getLength())) {
+                mat.setLength(matParam.getLength());
+            }
+            if (!Cools.isEmpty(matParam.getWidth())) {
+                mat.setWidth(matParam.getWidth());
+            }
+            if (!Cools.isEmpty(matParam.getHeight())) {
+                mat.setHeight(matParam.getHeight());
+            }
+            if (!Cools.isEmpty(matParam.getAccountingClass())) {
+                mat.setAccountingClass(matParam.getAccountingClass());
+            }
+            if (!Cools.isEmpty(matParam.getBatch())) {
+                mat.setBatch(matParam.getBatch());
+            }
+            if (!Cools.isEmpty(matParam.getInventoryAccount())) {
+                mat.setInventoryAccount(matParam.getInventoryAccount());
+            }
+
+            if (matService.save(mat)) {
+                count++;
+            }
+        }
+        return count;
+    }
 }

--
Gitblit v1.9.1