From c65db22f67af8018ae7105ea00d8743e42835e13 Mon Sep 17 00:00:00 2001
From: ZY <zc857179121@qq.com>
Date: 星期六, 29 三月 2025 15:52:09 +0800
Subject: [PATCH] 1

---
 src/main/java/com/zy/asrs/service/impl/OpenServiceImpl.java |  221 +++++++++++++++++++++++++++++--------------------------
 1 files changed, 117 insertions(+), 104 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 a80a11a..db118c7 100644
--- a/src/main/java/com/zy/asrs/service/impl/OpenServiceImpl.java
+++ b/src/main/java/com/zy/asrs/service/impl/OpenServiceImpl.java
@@ -1,5 +1,6 @@
 package com.zy.asrs.service.impl;
 
+import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.mapper.EntityWrapper;
 import com.core.common.BaseRes;
 import com.core.common.Cools;
@@ -24,9 +25,8 @@
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.StringUtils;
 
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
+import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * Created by vincent on 2022/4/9
@@ -76,8 +76,7 @@
         DocType docType = docTypeService.selectOrAdd(param.getOrderType(), Boolean.TRUE);
         Date now = new Date();
         // 鍗曟嵁涓绘。
-        order = new Order(
-                String.valueOf(snowflakeIdWorker.nextId()),    // 缂栧彿[闈炵┖]
+        order = new Order(String.valueOf(snowflakeIdWorker.nextId()),    // 缂栧彿[闈炵┖]
                 param.getOrderNo(),    // 璁㈠崟缂栧彿
                 DateUtils.convert(now),    // 鍗曟嵁鏃ユ湡
                 docType.getDocId(),    // 鍗曟嵁绫诲瀷
@@ -121,7 +120,7 @@
         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(),dto.getCsocode(),dto.getIsoseq(),null);
+                DetlDto detlDto = DetlDto.find(list, dto.getMatnr(), dto.getBatch(), dto.getCsocode(), dto.getIsoseq(), null);
                 assert detlDto != null;
                 detlDto.setAnfme(detlDto.getAnfme() + detail.getAnfme());
             } else {
@@ -135,6 +134,9 @@
             }
             OrderDetl orderDetl = new OrderDetl();
             orderDetl.sync(mat);
+            if (!Cools.isEmpty(detlDto.getCFree1())) {
+                orderDetl.setSpecs(detlDto.getCFree1());
+            }
             orderDetl.setBatch(detlDto.getBatch());
             orderDetl.setAnfme(detlDto.getAnfme());
             orderDetl.setOrderId(order.getId());
@@ -152,8 +154,7 @@
         }
 // 鐢熸垚璋冩嫧鍗�
         if (docType.getDocId().intValue() == 32) {
-            order = new Order(
-                    String.valueOf(snowflakeIdWorker.nextId()),    // 缂栧彿[闈炵┖]
+            order = new Order(String.valueOf(snowflakeIdWorker.nextId()),    // 缂栧彿[闈炵┖]
                     "DB" + param.getOrderNo(),    // 璁㈠崟缂栧彿
                     DateUtils.convert(now),    // 鍗曟嵁鏃ユ湡
                     33L,    // 鍗曟嵁绫诲瀷
@@ -197,7 +198,7 @@
             for (DetlDto detail : orderDetails) {
                 DetlDto dto = new DetlDto(detail.getMatnr(), detail.getBatch(), detail.getAnfme());
                 if (DetlDto.has(dbList, dto)) {
-                    DetlDto detlDto = DetlDto.find(dbList, dto.getMatnr(), dto.getBatch(),dto.getCsocode(),dto.getIsoseq(),null);
+                    DetlDto detlDto = DetlDto.find(dbList, dto.getMatnr(), dto.getBatch(), dto.getCsocode(), dto.getIsoseq(), null);
                     assert detlDto != null;
                     detlDto.setAnfme(detlDto.getAnfme() + detail.getAnfme());
                 } else {
@@ -250,7 +251,7 @@
                 if (order.getSettle() == 4L) {
                     // 淇敼璁㈠崟鐘舵�� 4.瀹屾垚 ===>> 6.宸蹭笂鎶�
                     if (!orderService.updateSettle(order.getId(), 6L, null)) {
-                        throw new CoolException("鏈嶅姟鍣ㄥ唴閮ㄩ敊璇紝璇疯仈绯荤鐞嗗憳");
+                        throw new CoolException("璁㈠崟鐘舵�佷慨鏀�(4-6)澶辫触");
                     }
                 }
             }
@@ -269,7 +270,7 @@
                 }
                 // 淇敼璁㈠崟鐘舵�� 4.瀹屾垚 ===>> 6.宸蹭笂鎶�
                 if (!orderService.updateSettle(order.getId(), 6L, null)) {
-                    throw new CoolException("鏈嶅姟鍣ㄥ唴閮ㄩ敊璇紝璇疯仈绯荤鐞嗗憳");
+                    throw new CoolException("璁㈠崟鐘舵�佷慨鏀�(4-6)澶辫触");
                 }
             }
         }
@@ -290,8 +291,7 @@
         DocType docType = docTypeService.selectOrAdd(param.getOrderType(), Boolean.FALSE);
         Date now = new Date();
         // 鍗曟嵁涓绘。
-        order = new Order(
-                String.valueOf(snowflakeIdWorker.nextId()),    // 缂栧彿[闈炵┖]
+        order = new Order(String.valueOf(snowflakeIdWorker.nextId()),    // 缂栧彿[闈炵┖]
                 param.getOrderNo(),    // 璁㈠崟缂栧彿
                 DateUtils.convert(now),    // 鍗曟嵁鏃ユ湡
                 docType.getDocId(),    // 鍗曟嵁绫诲瀷
@@ -335,7 +335,7 @@
         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(),dto.getCsocode(),dto.getIsoseq(),null);
+                DetlDto detlDto = DetlDto.find(list, dto.getMatnr(), dto.getBatch(), dto.getCsocode(), dto.getIsoseq(), null);
                 assert detlDto != null;
                 detlDto.setAnfme(detlDto.getAnfme() + detail.getAnfme());
             } else {
@@ -365,8 +365,7 @@
             }
         }
         if (docType.getDocId().intValue() == 32) {
-            order = new Order(
-                    String.valueOf(snowflakeIdWorker.nextId()),    // 缂栧彿[闈炵┖]
+            order = new Order(String.valueOf(snowflakeIdWorker.nextId()),    // 缂栧彿[闈炵┖]
                     "DB" + param.getOrderNo(),    // 璁㈠崟缂栧彿
                     DateUtils.convert(now),    // 鍗曟嵁鏃ユ湡
                     33L,    // 鍗曟嵁绫诲瀷
@@ -410,7 +409,7 @@
             for (DetlDto detail : orderDetails) {
                 DetlDto dto = new DetlDto(detail.getMatnr(), detail.getBatch(), detail.getAnfme());
                 if (DetlDto.has(dbList, dto)) {
-                    DetlDto detlDto = DetlDto.find(dbList, dto.getMatnr(), dto.getBatch(),dto.getCsocode(),dto.getIsoseq(),null);
+                    DetlDto detlDto = DetlDto.find(dbList, dto.getMatnr(), dto.getBatch(), dto.getCsocode(), dto.getIsoseq(), null);
                     assert detlDto != null;
                     detlDto.setAnfme(detlDto.getAnfme() + detail.getAnfme());
                 } else {
@@ -461,7 +460,7 @@
                 if (order.getSettle() == 4L) {
                     // 淇敼璁㈠崟鐘舵�� 4.瀹屾垚 ===>> 6.宸蹭笂鎶�
                     if (!orderService.updateSettle(order.getId(), 6L, null)) {
-                        throw new CoolException("鏈嶅姟鍣ㄥ唴閮ㄩ敊璇紝璇疯仈绯荤鐞嗗憳");
+                        throw new CoolException("璁㈠崟鐘舵�佷慨鏀�(4-6)澶辫触");
                     }
                 }
             }
@@ -480,7 +479,7 @@
                 }
                 // 淇敼璁㈠崟鐘舵�� 4.瀹屾垚 ===>> 6.宸蹭笂鎶�
                 if (!orderService.updateSettle(order.getId(), 6L, null)) {
-                    throw new CoolException("鏈嶅姟鍣ㄥ唴閮ㄩ敊璇紝璇疯仈绯荤鐞嗗憳");
+                    throw new CoolException("璁㈠崟鐘舵�佷慨鏀�(4-6)澶辫触");
                 }
             }
         }
@@ -505,8 +504,7 @@
             throw new CoolException(param.getBarcode() + "閲嶅鎻愪氦");
         }
         Date now = new Date();
-        pack = new Pack(
-                param.getBarcode(),    // 鏉$爜[闈炵┖]
+        pack = new Pack(param.getBarcode(),    // 鏉$爜[闈炵┖]
                 analyse.getMatnr(),    // 鐗╂枡鍙�
                 analyse.getBarcode(),    // 搴忓垪鐮�
                 1L,    // 璁㈠崟鐘舵��
@@ -518,7 +516,7 @@
                 null    // 澶囨敞
         );
         if (!packService.insert(pack)) {
-            throw new CoolException("鏈嶅姟鍣ㄥ唴閮ㄩ敊璇紝璇疯仈绯荤鐞嗗憳");
+            throw new CoolException("鎵撳寘澶辫触");
         }
 
         Mat mat = matService.selectByMatnr(analyse.getMatnr());
@@ -533,8 +531,7 @@
                     Tag top = tagService.getTop();
                     NodeUtils nodeUtils = new NodeUtils();
                     nodeUtils.executePath(top.getId());
-                    priTag = new Tag(
-                            null,    // 缂栧彿
+                    priTag = new Tag(null,    // 缂栧彿
                             param.getGroupCode(),    // 鍚嶇О
                             top.getId(),    // 鐖剁骇
                             top.getName(),    // 鐖剁骇鍚嶇О
@@ -555,7 +552,7 @@
                             null    // 澶囨敞
                     );
                     if (tagMapper.insert(priTag) == 0) {
-                        throw new CoolException("鏈嶅姟鍣ㄥ唴閮ㄩ敊璇紝璇疯仈绯荤鐞嗗憳");
+                        throw new CoolException("鍒嗙被娣诲姞澶辫触");
                     }
                 }
                 // 浜岀骇鍒嗙被
@@ -563,8 +560,7 @@
                 if (secTag == null) {
                     NodeUtils nodeUtils = new NodeUtils();
                     nodeUtils.executePath(priTag.getId());
-                    secTag = new Tag(
-                            null,    // 缂栧彿
+                    secTag = new Tag(null,    // 缂栧彿
                             param.getGroupName(),    // 鍚嶇О
                             priTag.getId(),    // 鐖剁骇
                             priTag.getName(),    // 鐖剁骇鍚嶇О
@@ -585,7 +581,7 @@
                             null    // 澶囨敞
                     );
                     if (tagMapper.insert(secTag) == 0) {
-                        throw new CoolException("鏈嶅姟鍣ㄥ唴閮ㄩ敊璇紝璇疯仈绯荤鐞嗗憳");
+                        throw new CoolException("鍒嗙被娣诲姞澶辫触");
                     }
                 }
                 tagId = secTag.getId();
@@ -601,16 +597,17 @@
             mat.setCreateTime(now);
             mat.setUpdateTime(now);
             if (!matService.insert(mat)) {
-                throw new CoolException("鏈嶅姟鍣ㄥ唴閮ㄩ敊璇紝璇疯仈绯荤鐞嗗憳");
+                throw new CoolException("鐗╂枡娣诲姞澶辫触");
             } else {
                 log.info("鎵撳寘涓婄嚎娣诲姞鏂扮墿鏂橻鐗╂枡鍙凤細{}]", mat.getMatnr());
             }
         }
     }
+
     @Override
     @Transactional
     public Mat syncMat(MatSyncParam param) {
-        if (Cools.isEmpty(param.getCInvCode()) ) {
+        if (Cools.isEmpty(param.getCInvCode())) {
             throw new CoolException("鍟嗗搧鏁版嵁涓虹┖");
         }
         Tag tag = tagService.selectByName("鍏ㄩ儴", 1);
@@ -619,7 +616,7 @@
         if (Cools.isEmpty(mat)) {
             mat = new Mat();
             mat.setTagId(tag.getId());
-            syncMat(mat,param);
+            syncMat(mat, param);
             if (matService.insert(mat)) {
                 callApiLogSave(mat, "/open/asrs/mat/v1", "鎺ユ敹ERP涓嬪彂鍟嗗搧淇℃伅鎴愬姛锛佹坊鍔犲晢鍝佷俊鎭垚鍔燂紒", true);
             } else {
@@ -629,7 +626,8 @@
 
         } else {
             mat.setTagId(tag.getId());
-            syncMat(mat,param);
+            syncMat(mat, param);
+            System.out.println(mat.getMaktx().length());
             if (matService.updateById(mat)) {
                 callApiLogSave(mat, "/open/asrs/mat/v1", "鎺ユ敹ERP涓嬪彂鍟嗗搧淇℃伅鎴愬姛锛佹坊鍔犲晢鍝佷俊鎭垚鍔燂紒", true);
             } else {
@@ -640,15 +638,16 @@
         return mat;
     }
 
-    private void syncMat(Mat mat, MatSyncParam param){
+    private void syncMat(Mat mat, MatSyncParam param) {
         Date date = new Date();
         mat.setMatnr(param.getCInvCode());//鐗╂枡缂栫爜
         mat.setMaktx(param.getCInvName());//鐗╂枡鍚嶇О
         mat.setSpecs(param.getCInvStd());//瑙勬牸
         mat.setUnit(param.getCComUnitName());
-        mat.setBeBatch(Cools.eq("true",param.getBInvBatch()) ? 1 : 0);
+        mat.setBeBatch(Cools.eq("true", param.getBInvBatch()) ? 1 : 0);
         mat.setStatus(param.getStates());
 
+        mat.setModel(param.getIGroupType());//0:鏃犳崲绠� 1锛氬浐瀹氭崲绠� 2锛氭诞鍔ㄦ崲绠�      涓嶆槸0鐨勯兘寰椾紶  榛樿涓�0
         mat.setCreateBy(9999L);//9999琛ㄧずerp涓嬪彂
         mat.setCreateTime(date);
         mat.setUpdateBy(9999L);//9999琛ㄧずerp涓嬪彂
@@ -658,50 +657,47 @@
     }
 
     public void callApiLogSave(Mat mat, String tableName, String response, Boolean bool) {
-        apiLogService.save("ERP涓嬪彂鍟嗗搧淇℃伅", tableName, "null", "10.10.10.1",
-                "鐗╂枡缂栫爜锛�" + mat.getMatnr() + "銆佺墿鏂欏悕绉帮細" + mat.getMaktx() + "銆佽鏍硷細" + mat.getSpecs() + "銆佸娉細" + mat.getMemo(),
-                response, bool);
+        apiLogService.save("ERP涓嬪彂鍟嗗搧淇℃伅", tableName, "null", "10.10.10.1", "鐗╂枡缂栫爜锛�" + mat.getMatnr() + "銆佺墿鏂欏悕绉帮細" + mat.getMaktx() + "銆佽鏍硷細" + mat.getSpecs() + "銆佸娉細" + mat.getMemo(), response, bool);
     }
 
 
     @Override
     @Transactional
     public void combMes(CombParam param) {
-        Long userId=9999l;
+        Long userId = 9999l;
         if (Cools.isEmpty(param.getBarcode(), param.getCombMats())) {
             callApiLogSaveMES(null, null, BaseRes.PARAM, false);
             throw new CoolException(BaseRes.PARAM);
         }
-        if(param.getBarcode().length()!=8){
+        if (param.getBarcode().length() != 8) {
             callApiLogSaveMES(param, null, param.getBarcode() + "锛氭潯鐮侀暱搴︿笉鏄�8浣�", false);
             throw new CoolException("鏉$爜闀垮害涓嶆槸8浣�===>>" + param.getBarcode());
         }
         // 鍒ゆ柇鏄惁鏈夌浉鍚屾潯鐮佺殑鏁版嵁
-        if (waitPakinService.selectCount(new EntityWrapper<WaitPakin>().
-                eq("zpallet", param.getBarcode()).eq("io_status", "N")) > 0) {
+        if (waitPakinService.selectCount(new EntityWrapper<WaitPakin>().eq("zpallet", param.getBarcode()).eq("io_status", "N")) > 0) {
             callApiLogSaveMES(param, null, param.getBarcode() + "鏁版嵁姝e湪杩涜鍏ュ簱", false);
             throw new CoolException(param.getBarcode() + "鏁版嵁姝e湪杩涜鍏ュ簱");
         }
 
-        int countLoc = locDetlService.selectCount(new EntityWrapper<LocDetl>().eq("zpallet",param.getBarcode()));
-        int countWrk = wrkDetlService.selectCount(new EntityWrapper<WrkDetl>().eq("zpallet",param.getBarcode()));
+        int countLoc = locDetlService.selectCount(new EntityWrapper<LocDetl>().eq("zpallet", param.getBarcode()));
+        int countWrk = wrkDetlService.selectCount(new EntityWrapper<WrkDetl>().eq("zpallet", param.getBarcode()));
         if (countLoc > 0) {
             callApiLogSaveMES(param, null, param.getBarcode() + "锛氬簱瀛樻潯鐮佹暟鎹凡瀛樺湪", false);
             throw new CoolException("搴撳瓨鏉$爜鏁版嵁宸插瓨鍦�===>>" + param.getBarcode());
-        }else if (countWrk > 0){
+        } else if (countWrk > 0) {
             callApiLogSaveMES(param, null, param.getBarcode() + "锛氬伐浣滄槑缁嗘。宸插瓨鍦ㄦ鏁版嵁", false);
             throw new CoolException("宸ヤ綔鏄庣粏妗e凡瀛樺湪姝ゆ暟鎹�===>>" + param.getBarcode());
         }
 
         Date now = new Date();
-        try{
+        try {
             // 鐢熸垚鍏ュ簱閫氱煡妗�
             List<DetlDto> detlDtos = new ArrayList<>();
             param.getCombMats().forEach(elem -> {
                 DetlDto detlDto = new DetlDto(elem.getMatnr(), elem.getBatch(), elem.getAnfme());
                 detlDto.setContainerCode(elem.getContainerCode());
                 if (DetlDto.has(detlDtos, detlDto)) {
-                    DetlDto one = DetlDto.find(detlDtos, detlDto.getMatnr(), detlDto.getBatch(),detlDto.getCsocode(),detlDto.getIsoseq(),detlDto.getContainerCode());
+                    DetlDto one = DetlDto.find(detlDtos, detlDto.getMatnr(), detlDto.getBatch(), detlDto.getCsocode(), detlDto.getIsoseq(), detlDto.getContainerCode());
                     assert one != null;
                     one.setAnfme(one.getAnfme() + detlDto.getAnfme());
                 } else {
@@ -712,7 +708,7 @@
             for (DetlDto detlDto : detlDtos) {
                 Mat mat = matService.selectByMatnr(detlDto.getMatnr());
                 if (Cools.isEmpty(mat)) {
-                    callApiLogSaveMES(param, null,mat.getMatnr()+"鍟嗗搧妗f涓嶅瓨鍦�", false);
+                    callApiLogSaveMES(param, null, mat.getMatnr() + "鍟嗗搧妗f涓嶅瓨鍦�", false);
                     throw new CoolException(detlDto.getMatnr() + "鍟嗗搧妗f涓嶅瓨鍦�");
                 }
                 WaitPakin waitPakin = new WaitPakin();
@@ -727,28 +723,23 @@
                 waitPakin.setModiUser(userId);
                 waitPakin.setModiTime(now);
                 if (!waitPakinService.insert(waitPakin)) {
-                    callApiLogSaveMES(param, null,mat.getMatnr()+"淇濆瓨鍏ュ簱閫氱煡妗eけ璐�", false);
+                    callApiLogSaveMES(param, null, mat.getMatnr() + "淇濆瓨鍏ュ簱閫氱煡妗eけ璐�", false);
                     throw new CoolException("淇濆瓨鍏ュ簱閫氱煡妗eけ璐�");
                 }
             }
-        }catch (Exception e){
-            callApiLogSaveMES(null, null,""+e, false);
+        } catch (Exception e) {
+            callApiLogSaveMES(null, null, "" + e, false);
         }
-        callApiLogSaveMES(param, param.getCombMats().get(0),"缁勬墭鎴愬姛", true);
+        callApiLogSaveMES(param, param.getCombMats().get(0), "缁勬墭鎴愬姛", true);
     }
-    public void callApiLogSaveMES(CombParam combParam,CombParam.CombMat combMat, String response, Boolean bool) {
-        if (Cools.isEmpty(combParam)){
-            apiLogService.save("MES涓嬪彂鍏ュ簱閫氱煡鍗�", "/open/asrs/comb/v1", "null", "10.10.10.1",
-                    "",
-                    response, bool);
-        }else if (Cools.isEmpty(combMat)){
-            apiLogService.save("MES涓嬪彂鍏ュ簱閫氱煡鍗�", "/open/asrs/comb/v1", "null", "10.10.10.1",
-                    "鎵樼洏鐮侊細" + combParam.getBarcode(),
-                    response, bool);
-        }else {
-            apiLogService.save("MES涓嬪彂鍏ュ簱閫氱煡鍗�", "/open/asrs/comb/v1", "null", "10.10.10.1",
-                    "鎵樼洏鐮侊細" + combParam.getBarcode() + "銆佺墿鏂欑紪鍙凤細" + combMat.getMatnr() + "銆佹暟閲忥細" + combMat.getAnfme(),
-                    response, bool);
+
+    public void callApiLogSaveMES(CombParam combParam, CombParam.CombMat combMat, String response, Boolean bool) {
+        if (Cools.isEmpty(combParam)) {
+            apiLogService.save("MES涓嬪彂鍏ュ簱閫氱煡鍗�", "/open/asrs/comb/v1", "null", "10.10.10.1", "", response, bool);
+        } else if (Cools.isEmpty(combMat)) {
+            apiLogService.save("MES涓嬪彂鍏ュ簱閫氱煡鍗�", "/open/asrs/comb/v1", "null", "10.10.10.1", "鎵樼洏鐮侊細" + combParam.getBarcode(), response, bool);
+        } else {
+            apiLogService.save("MES涓嬪彂鍏ュ簱閫氱煡鍗�", "/open/asrs/comb/v1", "null", "10.10.10.1", "鎵樼洏鐮侊細" + combParam.getBarcode() + "銆佺墿鏂欑紪鍙凤細" + combMat.getMatnr() + "銆佹暟閲忥細" + combMat.getAnfme(), response, bool);
         }
     }
 
@@ -760,7 +751,7 @@
     public List<ViewWorkInBean> inlogERP() {
         List<ViewWorkInBean> viewWorkInERP = reportQueryMapper.getViewWorkInERP();
         ArrayList<ViewWorkInBean> viewWorkInBeans = new ArrayList<>();
-        for (ViewWorkInBean viewWorkInBean:viewWorkInERP){
+        for (ViewWorkInBean viewWorkInBean : viewWorkInERP) {
             viewWorkInBean.sype();
             viewWorkInBeans.add(viewWorkInBean);
         }
@@ -775,7 +766,7 @@
     public List<ViewWorkInBean> outlogERP() {
         List<ViewWorkInBean> viewWorkInERP = reportQueryMapper.getViewWorkOutERP();
         ArrayList<ViewWorkInBean> viewWorkInBeans = new ArrayList<>();
-        for (ViewWorkInBean viewWorkInBean:viewWorkInERP){
+        for (ViewWorkInBean viewWorkInBean : viewWorkInERP) {
             viewWorkInBean.sype();
             viewWorkInBeans.add(viewWorkInBean);
         }
@@ -787,7 +778,7 @@
         Date now = new Date();
         Mat mat = matService.selectByMatnr(param.getCinvcode());
         boolean update = true;
-        if(Cools.isEmpty(matService.selectByMatnr(param.getCinvcode()))){
+        if (Cools.isEmpty(matService.selectByMatnr(param.getCinvcode()))) {
             //鐗╂枡鍙�
             mat = new Mat();
             mat.setMatnr(param.getCinvcode());
@@ -832,8 +823,8 @@
 
         mat.setUpdateTime(now);
 
-        if(update){
-            if (matService.updateById(mat)){
+        if (update) {
+            if (matService.updateById(mat)) {
                 callApiLogSave(param, "/open/asrs/mat/v1", "鎺ユ敹ERP涓嬪彂鍟嗗搧淇℃伅鎴愬姛锛佹坊鍔犲晢鍝佷俊鎭垚鍔燂紒", true);
                 param.setUpdate(true);
             } else {
@@ -841,7 +832,7 @@
                 param.setError(true);
                 param.setMemo("娣诲姞ERP涓嬪彂鍟嗗搧淇℃伅澶辫触锛�");
             }
-        }else {
+        } else {
             if (matService.insert(mat)) {
                 callApiLogSave(param, "/open/asrs/mat/v1", "鎺ユ敹ERP涓嬪彂鍟嗗搧淇℃伅鎴愬姛锛佹坊鍔犲晢鍝佷俊鎭垚鍔燂紒", true);
                 param.setInsert(true);
@@ -853,23 +844,28 @@
         }
 
 
-
         return true;
     }
 
     @Transactional
     public boolean syncOrder(OrderSyncParam param, boolean pakin, String docName) {
-        if(Cools.isEmpty(param) || Cools.isEmpty(param.getChildren())){
+        if (Cools.isEmpty(param) || Cools.isEmpty(param.getChildren())) {
             callApiLogSave(param, "/order/pakout/default/v1", "鎺ュ彈鍗曟嵁澶辫触锛屽崟鎹弬鏁颁负绌烘垨鑰呭崟鎹鎯呬负绌猴紝鏃犳硶鐢熸垚鍗曟嵁淇℃伅", false);
             throw new CoolException("鍗曟嵁鍙傛暟涓虹┖鎴栬�呭崟鎹鎯呬负绌猴紝鏃犳硶鐢熸垚鍗曟嵁淇℃伅");
         }
 
+        if ("閾跺骇鐢熶骇閫�鏂欑敵璇峰崟".equalsIgnoreCase(docName)) {
+            if (Cools.isEmpty(param.getBackOrderNo())){
+                throw new CoolException("閫�鏂欏崟鐨勯��鏂欑紪鍙穊ackOrderNo涓嶈兘涓虹┖");
+            }
+        }
+
         Order orderOld = null;
 
-        if(!Cools.isEmpty(orderService.selectByNo(param.getCPOID()))){
+        if (!Cools.isEmpty(orderService.selectByNo(param.getCPOID()))) {
 
             orderOld = orderService.selectByNo(param.getCPOID());
-            if(orderOld.getSettle() > 1){
+            if (orderOld.getSettle() > 1) {
                 throw new CoolException("璇ュ崟鎹凡鍦ㄤ綔涓氫腑锛屾棤娉曟洿鏀瑰崟鎹俊鎭�");
             }
 
@@ -888,18 +884,28 @@
             //callApiLogSave(param, "/order/pakout/default/v1", "鎺ュ彈鍗曟嵁澶辫触锛岃鍗曟嵁宸插瓨鍦紝鏃犳硶鐢熸垚鍗曟嵁淇℃伅", false);
             //throw new CoolException("璇ュ崟鎹凡瀛樺湪锛屾棤娉曠敓鎴愬崟鎹俊鎭�");
         }
+        List<OrderSyncParam.OrderDetl> collect = param.getChildren().stream().distinct().collect(Collectors.toList());
+        if (collect.size() != param.getChildren().size()) {
+            callApiLogSave(param, "/order/pakout/default/v1", "鎺ュ彈鍗曟嵁澶辫触锛屽崟鎹槑缁嗛噸澶嶏紝鏃犳硶鐢熸垚鍗曟嵁淇℃伅", false);
+            throw new CoolException("鎺ュ彈鍗曟嵁澶辫触锛屽崟鎹槑缁嗛噸澶嶏紝鏃犳硶鐢熸垚鍗曟嵁淇℃伅");
+        }
         Date now = new Date();
-        Order order = orderMapping(param,now,pakin,docName);
+        Order order = orderMapping(param, now, pakin, docName);
+        Set<String> set = new HashSet<>();
+        for (OrderSyncParam.OrderDetl child : param.getChildren()) {
+            set.add(child.getCDefine22());
+        }
+        order.setTel(JSON.toJSONString(set));
         orderService.insert(order);
         param.getChildren().forEach(od -> {
-            OrderDetl orderDetl = orderDetlMapping(order,od,now);
+            OrderDetl orderDetl = orderDetlMapping(order, od, now);
             orderDetlService.insert(orderDetl);
         });
 
-        if(!Cools.isEmpty(orderOld)){
+        if (!Cools.isEmpty(orderOld)) {
             //鍒犻櫎鍘熸湁鍗曟嵁淇℃伅
-            orderService.delete(new EntityWrapper<Order>().eq("id",orderOld.getId()));
-            orderDetlService.delete(new EntityWrapper<OrderDetl>().eq("order_id",orderOld.getId()));
+            orderService.delete(new EntityWrapper<Order>().eq("id", orderOld.getId()));
+            orderDetlService.delete(new EntityWrapper<OrderDetl>().eq("order_id", orderOld.getId()));
         }
 
         callApiLogSave(param, "/order/pakout/default/v1", "鎺ュ彈鍗曟嵁鎴愬姛", true);
@@ -910,16 +916,16 @@
     @Transactional
     public boolean orderDelete(String orderNo) {
         Order order = orderService.selectByNo(orderNo);
-        if(Cools.isEmpty(order)){
+        if (Cools.isEmpty(order)) {
             throw new CoolException("鍗曟嵁涓嶅瓨鍦紝鏃犳硶鍒犻櫎鍗曟嵁");
         }
 
-        if(order.getSettle() != 1){
+        if (order.getSettle() != 1) {
             return false;
         }
 
         orderService.deleteById(order);
-        orderDetlService.delete(new EntityWrapper<OrderDetl>().eq("order_id",order.getId()));
+        orderDetlService.delete(new EntityWrapper<OrderDetl>().eq("order_id", order.getId()));
 
         return true;
     }
@@ -931,30 +937,30 @@
 
         //鍒ゆ柇搴撲綅鏄惁瀛樺湪
         AgvLocMast agvLocMast = agvLocMastService.selectById(params.getLocNo());
-        if(Cools.isEmpty(agvLocMast)){
+        if (Cools.isEmpty(agvLocMast)) {
             throw new CoolException("搴撲綅鍙蜂笉瀛樺湪");
         }
 
-        if(!Cools.eq("O",agvLocMast.getLocSts()) && !Cools.eq("F",agvLocMast.getLocSts())){
+        if (!Cools.eq("O", agvLocMast.getLocSts()) && !Cools.eq("F", agvLocMast.getLocSts())) {
             throw new CoolException("褰撳墠搴撲綅姝e湪浣滀笟涓紝鏃犳硶鐩樼偣璋冩暣");
         }
 
-        if(Cools.isEmpty(params.getLocDetls())){
+        if (Cools.isEmpty(params.getLocDetls())) {
             agvLocMast.setLocSts("O");
-        }else {
+        } else {
             agvLocMast.setLocSts("F");
         }
 
         agvLocMastService.updateById(agvLocMast);
 
         //鍒犻櫎鏃у簱瀛�
-        agvLocDetlService.delete(new EntityWrapper<AgvLocDetl>().eq("loc_no",params.getLocNo()));
+        agvLocDetlService.delete(new EntityWrapper<AgvLocDetl>().eq("loc_no", params.getLocNo()));
 
         //鏂板鐩樼偣搴撳瓨
-        for (DetlDto detlDto : params.getLocDetls()){
+        for (DetlDto detlDto : params.getLocDetls()) {
             AgvLocDetl agvLocDetl = new AgvLocDetl();
             Mat mat = matService.selectByMatnr(detlDto.getMatnr());
-            BeanUtils.copyProperties(mat,agvLocDetl);
+            BeanUtils.copyProperties(mat, agvLocDetl);
             agvLocDetl.setLocNo(params.getLocNo());
             agvLocDetl.setSuppCode(params.getContainerCode());
             agvLocDetl.setAnfme(detlDto.getAnfme());
@@ -967,7 +973,7 @@
         return true;
     }
 
-    private Order orderMapping(OrderSyncParam param, Date now, boolean pakin, String docName){
+    private Order orderMapping(OrderSyncParam param, Date now, boolean pakin, String docName) {
         Order order = new Order();
         //uuid
         order.setUuid(String.valueOf(snowflakeIdWorker.nextId()));
@@ -988,9 +994,12 @@
 
         order.setDefNumber(param.get鎿嶄綔绯荤粺鍙�());
 
+        order.setCreateBy(9999L);
         order.setCreateTime(now);
+        order.setUpdateBy(9999L);
         order.setUpdateTime(now);
-
+        order.setSalesman(param.getBackOrderNo());
+        order.setUpstreamcode(param.getUpstreamcode());
         //璁㈠崟鐘舵��
         order.setSettle(1L);
         //鐘舵��
@@ -998,10 +1007,10 @@
         return order;
     }
 
-    private OrderDetl orderDetlMapping(Order order, OrderSyncParam.OrderDetl odParam, Date now){
+    private OrderDetl orderDetlMapping(Order order, OrderSyncParam.OrderDetl odParam, Date now) {
 
         Mat mat = matService.selectByMatnr(odParam.getCInvCode());
-        if(Cools.isEmpty(mat)){
+        if (Cools.isEmpty(mat)) {
             throw new CoolException("瀛樿揣缂栫爜锛�" + odParam.getCInvCode() + "涓嶅瓨鍦紝璇峰厛鍚屾瀛樿揣妗f");
         }
 
@@ -1024,15 +1033,22 @@
         od.setAnfme(odParam.getIQuantity());
         //閿�鍞鍗曞彿
         od.setThreeCode(odParam.getCDefine22());
+        od.setDevNo(odParam.getDevNo());
         //鑷敱椤�
-        od.setDeadTime(odParam.getBFree1());
+        if (!Cools.isEmpty(odParam.getBatch()) || !Cools.isEmpty(odParam.getBFree1())) {
+            od.setBrand((Cools.isEmpty(odParam.getBatch()) ? "" : odParam.getBatch()) + "__" + (Cools.isEmpty(odParam.getBFree1()) ? "" : odParam.getBFree1()));
+        }
+        od.setWeight(odParam.getINum());
+        od.setVolume(odParam.getIinvexchrate());
         //IDs
         od.setSku(odParam.getId());
 
         od.setLength(odParam.getINum());
 
+        od.setSource(order.getDocType().intValue());
         od.setStatus(1);
         od.setQty(0.0D);
+        od.setReportQty(0.0D);
         od.setCreateBy(9999L);
         od.setCreateTime(now);
         od.setUpdateBy(9999L);
@@ -1041,31 +1057,28 @@
         return od;
     }
 
-    private String toString(Object o){
-        if(StringUtils.isEmpty(o)){
+    private String toString(Object o) {
+        if (StringUtils.isEmpty(o)) {
             return null;
-        }else{
+        } else {
             return o.toString();
         }
     }
 
 
     public void callApiLogSave(MatInfoParam matParam, String tableName, String response, Boolean bool) {
-        apiLogService.save("ERP涓嬪彂鍟嗗搧淇℃伅", tableName, "null", "10.10.10.1",
-                "鐗╂枡缂栫爜锛�" + matParam.getCinvcode() + "銆佺墿鏂欏悕绉帮細" + matParam.getCinvname() + "銆佽鏍硷細" + matParam.getCInvStd() + "銆佸娉細" + matParam.getMemo(),
-                response, bool);
+        apiLogService.save("ERP涓嬪彂鍟嗗搧淇℃伅", tableName, "null", "10.10.10.1", "鐗╂枡缂栫爜锛�" + matParam.getCinvcode() + "銆佺墿鏂欏悕绉帮細" + matParam.getCinvname() + "銆佽鏍硷細" + matParam.getCInvStd() + "銆佸娉細" + matParam.getMemo(), response, bool);
     }
 
     public void callApiLogSave(OrderSyncParam param, String tableName, String response, Boolean bool) {
-        apiLogService.save("ERP璁㈠崟鍚屾", tableName, "null", "10.10.10.1",
-                param.toString(), response, bool);
+        apiLogService.save("ERP璁㈠崟鍚屾", tableName, "null", "10.10.10.1", param.toString(), response, bool);
     }
 
     public static void main(String[] args) {
         Object s = null;
-        if(StringUtils.isEmpty(s)){
+        if (StringUtils.isEmpty(s)) {
             System.out.println("null");
-        }else {
+        } else {
             System.out.println(s.toString());
         }
     }

--
Gitblit v1.9.1