From 3aed7236f2db67dd90115a39bc8f1465e4cc8b73 Mon Sep 17 00:00:00 2001
From: skyouc <creaycat@gmail.com>
Date: 星期二, 16 十二月 2025 14:34:08 +0800
Subject: [PATCH] 立库完成入库添加库区信息

---
 src/main/java/com/zy/api/service/impl/KopenApiServiceImpl.java |  240 ++++++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 209 insertions(+), 31 deletions(-)

diff --git a/src/main/java/com/zy/api/service/impl/KopenApiServiceImpl.java b/src/main/java/com/zy/api/service/impl/KopenApiServiceImpl.java
index 2fe7ea8..640c170 100644
--- a/src/main/java/com/zy/api/service/impl/KopenApiServiceImpl.java
+++ b/src/main/java/com/zy/api/service/impl/KopenApiServiceImpl.java
@@ -2,10 +2,13 @@
 
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.mapper.EntityWrapper;
-import com.core.common.DateUtils;
 import com.core.common.R;
 import com.core.exception.CoolException;
 import com.zy.api.entity.OrderParams;
+import com.zy.api.entity.PubOrderParams;
+import com.zy.api.entity.ReportOrderParam;
+import com.zy.api.entity.SyncMatParmas;
+import com.zy.api.enums.MatLocType;
 import com.zy.api.enums.OrderType;
 import com.zy.api.enums.OrderWkType;
 import com.zy.api.service.KopenApiService;
@@ -14,16 +17,18 @@
 import com.zy.asrs.entity.OrderDetl;
 import com.zy.asrs.enums.CommonEnum;
 import com.zy.asrs.enums.OrderSettle;
+import com.zy.asrs.service.MatService;
 import com.zy.asrs.service.OrderDetlService;
 import com.zy.asrs.service.OrderService;
 
+import com.zy.asrs.utils.Utils;
+import com.zy.common.utils.HttpHandler;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.util.Date;
-import java.util.List;
 import java.util.Objects;
 
 @Service("kopenApiServiceImpl")
@@ -33,6 +38,8 @@
     private OrderService orderService;
     @Autowired
     private OrderDetlService orderDetlService;
+    @Autowired
+    private MatService matService;
 
     /**
      * 鎺ユ敹涓嬪彂璁㈠崟淇℃伅
@@ -43,7 +50,7 @@
      * @return com.core.common.R
      */
     @Override
-    public R receiveOrders(OrderParams params) {
+    public R receiveOrders(PubOrderParams params) {
         if (params.getType().equals(OrderWkType.getTypeVal(params.getType()))) {
             return R.error("褰撳墠绫诲瀷涓嶆槸涓婃灦娲惧伐鍗曪紒锛�");
         }
@@ -52,27 +59,80 @@
     }
 
     /**
-     * 鍩虹闆朵欢鍙樻洿
-     *
+     * 涓婃灦娲惧伐鍗曞弽棣�
+     * 
      * @author Ryan
-     * @date 2025/11/24 15:05
-     * @param matnrs
-     * @return com.core.common.R
-     */
-    @Override
-    public R basMatupdate(List<Mat> matnrs) {
-        return null;
-    }
-
-    /**
-     * 鏂板鎴栦慨鏀硅鍗曚俊鎭�
-     *
-     * @author Ryan
-     * @date 2025/11/24 15:32
+     * @date 2025/11/24 15:33
      */
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public void addOrUpdateOrders(OrderParams params, String type) {
+    public R getInDispatchResult(ReportOrderParam params) {
+        if (Objects.isNull(params)) {
+            return R.error("鍙傛暟涓嶈兘涓虹┖锛侊紒");
+        }
+        String response = null;
+        try {
+            response = new HttpHandler.Builder()
+                    .setUri("127.0.0.1:8081")
+                    .setPath("/wms/order/getInDispatchResult")
+                    .setJson(JSONObject.toJSONString(params))
+                    .build()
+                    .doPost();
+            if (Objects.isNull(response) || response.trim().isEmpty()) {
+                return R.error("澶栫綉鎺ュ彛鏃犲搷搴旓紒锛�");
+            }
+            JSONObject jsonObject = JSONObject.parseObject(response);
+            Integer code = jsonObject.getInteger("code");
+            if (!Objects.isNull(code) && code.equals(1)) {
+                return R.ok("鍏ュ簱鍗曚笂鎶ュ畬鎴愶紒锛�");
+            } else {
+                String msg = jsonObject.getString("message");
+                return R.error(Objects.isNull(msg) ? "涓婃姤澶辫触锛侊紒" : msg);
+            }
+        } catch (Exception e) {
+            return R.error(e.getMessage());
+        }
+    }
+
+    /* */
+    /**
+     * 澶囪揣鎸囩ず娲惧伐鍗曚笅鍙�
+     * 
+     * @author Ryan
+     * @date 2025/11/24 15:21
+     * @param params
+     * @return com.core.common.R
+     */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public R sendOutDispatch(PubOrderParams params) {
+        if (Objects.isNull(params)) {
+            return R.error("鍙傛暟涓嶈兘涓虹┖锛侊紒");
+        }
+        // 鏍¢獙鍙傛暟
+        if (Objects.isNull(params.getDispatch_no())) {
+            return R.error("娲惧伐鍗曠紪鍙蜂笉鑳戒负绌猴紒锛�");
+        }
+        if (Objects.isNull(params.getKopen_id())) {
+            return R.error("娴佹按鍙蜂笉鑳戒负绌猴紒锛�");
+        }
+        if (Objects.isNull(params.getCompany_id())) {
+            return R.error("鍏徃ID涓嶈兘涓虹┖锛侊紒");
+        }
+
+        addOrUpdateOrders(params, "add");
+
+        return R.ok("澶囪揣鎸囩ず娲惧伐鍗曚笅鍙戞垚鍔燂紒锛�");
+    }
+
+    /**
+     * 澶囪揣鎸囩ず娲惧伐鍗�
+     * 
+     * @author Ryan
+     * @date 2025/12/16 9:15
+     * @param params
+     */
+    private void outOrderAddAndUpdate(PubOrderParams params, String type) {
         if (Objects.isNull(params)) {
             throw new CoolException("鍙傛暟涓嶈兘涓虹┖锛侊紒");
         }
@@ -94,7 +154,107 @@
             // 鍒犻櫎鏃ц鍗曟槑缁�
             if (!orderDetlService.delete(new EntityWrapper<OrderDetl>().eq("order_id", order.getId()))) {
                 throw new CoolException("璁㈠崟鏄庣粏鍒犻櫎澶辫触锛侊紒");
-            };
+            }
+            ;
+            if (!orderService.deleteById(order.getId())) {
+                throw new CoolException("鍘熷崟鎹垹闄ゅけ璐ワ紒锛�");
+            }
+            generateOrders(params);
+        }
+
+    }
+
+    /**
+     * 鍩虹闆朵欢鍙樻洿
+     *
+     * @author Ryan
+     * @date 2025/11/24 15:05
+     * @param params
+     * @return com.core.common.R
+     */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public synchronized R basMatupdate(SyncMatParmas params) {
+        if (Objects.isNull(params.getPro_komcode())) {
+            return R.error("闆朵欢缂栫爜涓嶈兘涓虹┖锛侊紒");
+        }
+        Mat matnr = matService.selectOne(new EntityWrapper<Mat>().eq("matnr", params.getPro_komcode()));
+        if (!Objects.isNull(matnr)) {
+            // 璁㈠崟鏃堕棿
+            if (Utils.isValidFormat(params.getUpdate_time(), "yyyy-MM-dd HH:mm:ss")) {
+                Date date1 = Utils.getFormateDate(params.getUpdate_time());
+                matnr.setUpdateTime(date1);
+            }
+            matnr.setMaktx(params.getPro_name());
+            matnr.setSpecs(params.getPro_size());
+            matnr.setWeight(Double.parseDouble(params.getPro_wet()));
+            matnr.setSuppCode(params.getPro_id());
+            matnr.setTagId(MatLocType.getTag(params.getPro_type()));
+            matnr.setManu(params.getCompany_id());
+            if (!matService.updateById(matnr)) {
+                throw new CoolException("鐗╂枡鏇存柊澶辫触鎴栨棤闇�鏇存柊锛侊紒");
+            }
+        } else {
+            if (Objects.isNull(matnr)) {
+                matnr = new Mat();
+            }
+            // 璁㈠崟鏃堕棿
+            if (Utils.isValidFormat(params.getUpdate_time(), "yyyy-MM-dd HH:mm:ss")) {
+                Date date1 = Utils.getFormateDate(params.getUpdate_time());
+                matnr.setUpdateTime(date1);
+            }
+            matnr.setMaktx(params.getPro_name());
+            matnr.setMatnr(params.getPro_komcode());
+            matnr.setSpecs(params.getPro_size());
+            matnr.setWeight(Double.parseDouble(params.getPro_wet()));
+            matnr.setSuppCode(params.getPro_id());
+            matnr.setTagId(MatLocType.getTag(params.getPro_type()));
+            matnr.setManu(params.getCompany_id());
+            if (!matService.insert(matnr)) {
+                throw new CoolException("鐗╂枡鏇存柊澶辫触锛侊紒");
+            }
+        }
+        return R.ok("淇濆瓨鎴愬姛锛侊紒");
+    }
+
+    /**
+     * 鏂板鎴栦慨鏀硅鍗曚俊鎭�
+     *
+     * @author Ryan
+     * @date 2025/11/24 15:32
+     */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void addOrUpdateOrders(PubOrderParams params, String type) {
+        if (Objects.isNull(params)) {
+            throw new CoolException("鍙傛暟涓嶈兘涓虹┖锛侊紒");
+        }
+        if (Objects.isNull(params.getType())) {
+            throw new CoolException("璁㈠崟绫诲瀷涓嶈兘涓虹┖锛侊紒");
+        }
+        OrderParams orderParams = JSONObject.parseObject(JSONObject.toJSONString(params), OrderParams.class);
+        Order order = new Order();
+        if (OrderType.ORDER_IN.type.equals(OrderWkType.getTypeVal(params.getType()))) {
+            // 鍏ュ簱
+          order = orderService.selectOne(new EntityWrapper<Order>().eq("order_no", orderParams.getInv_no()));
+        } else if (OrderType.ORDER_OUT.type.equals(OrderWkType.getTypeVal(params.getType()))) {
+            // 鍑哄簱
+           order = orderService.selectOne(new EntityWrapper<Order>().eq("order_no", orderParams.getDispatch_no()));
+        }
+        if (type.equals("add") && !Objects.isNull(order)) {
+            throw new CoolException("鍗曟嵁宸插瓨鍦�, 涓嶅彲閲嶅娣诲姞锛侊紒");
+        }
+        // 鍒ゆ柇璁㈠崟鏄惁瀛樺湪
+        if (Objects.isNull(order)) {
+            /** 涓嶅瓨鍦紝鏂板璁㈠崟 */
+            generateOrders(params);
+        } else {
+            /** 瀛樺湪锛屽垹闄よ�佽鍗曪紝鏇存柊鎻掑叆鏂拌鍗� */
+            // 鍒犻櫎鏃ц鍗曟槑缁�
+            if (!orderDetlService.delete(new EntityWrapper<OrderDetl>().eq("order_id", order.getId()))) {
+                throw new CoolException("璁㈠崟鏄庣粏鍒犻櫎澶辫触锛侊紒");
+            }
+
             if (!orderService.deleteById(order.getId())) {
                 throw new CoolException("鍘熷崟鎹垹闄ゅけ璐ワ紒锛�");
             }
@@ -105,25 +265,27 @@
     public static String generateUUID(OrderParams params) {
         return java.util.UUID.randomUUID().toString();
     }
-    
 
     /**
      * 鐢熸垚璁㈠崟淇℃伅
+     * 
      * @param params
      */
     @Transactional(rollbackFor = Exception.class)
-    public void generateOrders(OrderParams params) {
+    public void generateOrders(PubOrderParams params) {
         // 灏嗘暟鎹綋鏂拌鍗曟彃鍏�
         Order newOrder = new Order();
         if (OrderType.ORDER_IN.type.equals(OrderWkType.getTypeVal(params.getType()))) {
             // 鍏ュ簱
             newOrder.setPakinPakoutStatus(1);
+            newOrder.setDocType(Long.parseLong(params.getType()));
+            newOrder.setOrderNo(params.getInv_no());
         } else if (OrderType.ORDER_OUT.type.equals(OrderWkType.getTypeVal(params.getType()))) {
             // 鍑哄簱
             newOrder.setPakinPakoutStatus(2);
+            newOrder.setDocType(5L);
+            newOrder.setOrderNo(params.getDispatch_no());
         }
-        newOrder.setDocType(Long.parseLong(params.getType()));
-        newOrder.setOrderNo(params.getInv_no());
         newOrder.setUuid(generateUUID(params));
         // 娴佹按鍙凤紙鍞竴锛�
         newOrder.setDefNumber(params.getKopen_id());
@@ -131,10 +293,12 @@
         newOrder.setNumber(params.getDispatch_no());
         // 绠卞彿
         newOrder.setItemName(params.getPm_tktid());
-        newOrder.setSettle(OrderSettle.ORDER_SETTLE_INIT.type);
+        newOrder.setSettle(OrderSettle.ORDER_SETTLE_HOLDING.type);
         newOrder.setStatus(CommonEnum.COMMON_ENUM_Y.type);
         // 璁㈠崟鏃堕棿
-        newOrder.setOrderTime(DateUtils.convert(new Date(), "yyyy-MM-dd HH:mm:ss"));
+        if (Utils.isValidFormat(params.getUpdate_time(), "yyyy-MM-dd HH:mm:ss")) {
+            newOrder.setOrderTime(params.getUpdate_time());
+        }
         // 鍏徃ID
         newOrder.setCstmrName(params.getCompany_id());
         newOrder.setCreateTime(new Date());
@@ -144,15 +308,29 @@
         }
         if (!Objects.isNull(params.getDetails()) && !params.getDetails().isEmpty()) {
             params.getDetails().forEach(item -> {
+                Mat matnr = matService.selectOne(new EntityWrapper<Mat>().eq("matnr", item.getPro_komcode()));
+                if (Objects.isNull(matnr)) {
+                    throw new CoolException("鐗╂枡缂栫爜涓嶅瓨鍦紒锛�");
+                }
                 OrderDetl orderItem = new OrderDetl();
-                BeanUtils.copyProperties(item, orderItem);
+                BeanUtils.copyProperties(matnr, orderItem);
                 orderItem.setOrderId(newOrder.getId());
                 orderItem.setOrderNo(newOrder.getOrderNo());
-                orderItem.setAnfme(Math.round(item.getInv_qty() * 10000) / 10000.0);
-                orderItem.setMatnr(item.getPro_komcode());
+
+                if (OrderType.ORDER_IN.type.equals(OrderWkType.getTypeVal(params.getType()))) {
+                    // 鍏ュ簱
+                    orderItem.setAnfme(Math.round(item.getInv_qty() * 10000) / 10000.0);
+                } else if (OrderType.ORDER_OUT.type.equals(OrderWkType.getTypeVal(params.getType()))) {
+                    // 鍑哄簱
+                    newOrder.setPakinPakoutStatus(2);
+                    orderItem.setAnfme(Math.round(item.getOrder_qty() * 10000) / 10000.0);
+                }
+                orderItem.setMatnr(matnr.getMatnr());
+                orderItem.setMaktx(matnr.getMaktx());
+                orderItem.setBrand(matnr.getBrand());
                 orderItem.setBatch(1 + "");
                 orderItem.setStandby1(item.getPro_id());
-                //鍏宠仈涓婂姞娲惧伐鍗曞彿+闆朵欢浠g爜+渚涘簲鍟嗕唬鐮�
+                // 鍏宠仈涓婂姞娲惧伐鍗曞彿+闆朵欢浠g爜+渚涘簲鍟嗕唬鐮�
                 orderItem.setThreeCode(item.getTotal_serial());
                 // 渚涘簲鍟嗕唬鐮�
                 orderItem.setSuppCode(item.getPro_id());

--
Gitblit v1.9.1