From c1702cc51a4d94ed37d5083494c87fe0f2cbe5b3 Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期五, 18 六月 2021 10:20:13 +0800
Subject: [PATCH] # 销售单取消后回滚立库出库至A99

---
 src/main/java/zy/cloud/wms/common/service/erp/ErpScheduler.java |  261 +++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 198 insertions(+), 63 deletions(-)

diff --git a/src/main/java/zy/cloud/wms/common/service/erp/ErpScheduler.java b/src/main/java/zy/cloud/wms/common/service/erp/ErpScheduler.java
index efeef38..9a1378a 100644
--- a/src/main/java/zy/cloud/wms/common/service/erp/ErpScheduler.java
+++ b/src/main/java/zy/cloud/wms/common/service/erp/ErpScheduler.java
@@ -13,6 +13,7 @@
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RestController;
+import zy.cloud.wms.common.entity.Parameter;
 import zy.cloud.wms.common.service.erp.entity.*;
 import zy.cloud.wms.common.utils.VersionUtils;
 import zy.cloud.wms.manager.entity.*;
@@ -34,7 +35,7 @@
 @RestController
 public class ErpScheduler {
 
-    public static final String URI = "http://8.133.182.21:8080/api";
+    public static final String URI = "http://8.133.182.21:6220/api";
     public static final String GET_ORDERS = "cM/basis/getOrders";
     public static final String GET_BASIS = "cM/basis/getBasis";
     public static final String UPLOAD_BILL = "cM/basis/uploadBill";
@@ -58,6 +59,10 @@
     private OrderDetlService orderDetlService;
     @Autowired
     private SnowflakeIdWorker snowflakeIdWorker;
+    @Autowired
+    private PakoutService pakoutService;
+    @Autowired
+    private NodeService nodeService;
 
     /**
      * 鍟嗗搧涓嬭浇
@@ -78,6 +83,151 @@
                     .doPost();
             if (!Cools.isEmpty(response)) {
                 log.info(response);
+                Date now = new Date();
+                Result result = JSON.parseObject(response, Result.class);
+                if (result.getCode() != 1) {
+                    return;
+                }
+                List<GetBasisResult> list = JSON.parseArray(result.getData(), GetBasisResult.class);
+                Tag first = null;
+                for (GetBasisResult data : list) {
+                    Mat mat = matService.selectByMatnr(data.getUserCode());
+                    String modifyDate = data.getModifyDate();
+                    Date updateTime = null;
+                    if (!Cools.isEmpty(modifyDate)) {
+                        updateTime = DateUtils.convert(data.getModifyDate());
+                    }
+
+                    // 鍒嗙被
+                    Tag second = tagService.selectOne(new EntityWrapper<Tag>().eq("name", data.getYjfl()).eq("level", 2));
+                    if (second == null) {
+                        if (first == null) {
+                            first = tagService.selectOne(new EntityWrapper<Tag>().eq("level", 1));
+                            if (first == null) {
+                                throw new CoolException("鍏ㄩ儴鍒嗙被鍑洪敊");
+                            }
+                        }
+                        NodeUtils nodeUtils = new NodeUtils();
+                        nodeUtils.executePath(first.getId());
+                        second = new Tag(
+                                null,    // 缂栧彿
+                                data.getYjfl(),    // 鍚嶇О
+                                first.getId(),    // 鐖剁骇
+                                first.getName(),    // 鐖剁骇鍚嶇О
+                                nodeUtils.path.toString(),    // 鍏宠仈璺緞
+                                nodeUtils.pathName.toString(),    // 鍏宠仈璺緞鍚�
+                                0,    // 绫诲瀷
+                                null,    // 璐熻矗浜�
+                                null,    // 鍥剧墖
+                                null,    // 绠�瑕佹弿杩�
+                                null,    // 鏁伴噺
+                                2,    // 绛夌骇
+                                null,    // 鎺掑簭
+                                1,    // 鐘舵��
+                                now,    // 娣诲姞鏃堕棿
+                                null,    // 娣诲姞浜哄憳
+                                now,    // 淇敼鏃堕棿
+                                null,    // 淇敼浜哄憳
+                                null    // 澶囨敞
+                        );
+                        if (tagMapper.insert(second) == 0) {
+                            throw new CoolException("鎻掑叆鍒嗙被澶辫触");
+                        }
+                    }
+
+                    Tag third = tagService.selectOne(new EntityWrapper<Tag>().eq("level", 3).eq("name", data.getEjfl()).eq("parent_name", data.getYjfl()));
+                    if (third == null) {
+                        NodeUtils nodeUtils = new NodeUtils();
+                        nodeUtils.executePath(second.getId());
+                        third = new Tag(
+                                null,    // 缂栧彿
+                                data.getEjfl(),    // 鍚嶇О
+                                second.getId(),    // 鐖剁骇
+                                second.getName(),    // 鐖剁骇鍚嶇О
+                                nodeUtils.path.toString(),    // 鍏宠仈璺緞
+                                nodeUtils.pathName.toString(),    // 鍏宠仈璺緞鍚�
+                                0,    // 绫诲瀷
+                                null,    // 璐熻矗浜�
+                                null,    // 鍥剧墖
+                                null,    // 绠�瑕佹弿杩�
+                                null,    // 鏁伴噺
+                                3,    // 绛夌骇
+                                null,    // 鎺掑簭
+                                1,    // 鐘舵��
+                                now,    // 娣诲姞鏃堕棿
+                                null,    // 娣诲姞浜哄憳
+                                now,    // 淇敼鏃堕棿
+                                null,    // 淇敼浜哄憳
+                                null    // 澶囨敞
+                        );
+                        if (tagMapper.insert(third) == 0) {
+                            throw new CoolException("鎻掑叆鍒嗙被澶辫触");
+                        }
+                    }
+
+                    if (null == mat) {
+                        mat = new Mat(
+                                String.valueOf(data.getRec()),    // 缂栧彿
+                                null,    // 鎵�灞炲尯鍩�
+                                third.getId(),    // 鎵�灞炲綊绫�
+                                data.getUserCode(),    // 鍟嗗搧缂栧彿
+                                data.getFullName(),    // 鍟嗗搧鍚嶇О
+                                null,    // 鍚嶇О
+                                data.getStandard(),    // 瑙勬牸
+                                null,    // 鍨嬪彿
+                                null,    // 鎵瑰彿
+                                data.getUnit3(),    // 鍗曚綅
+                                data.getBarcode(),    // 鏉$爜
+                                null,    // 鍗曟嵁绫诲瀷
+                                null,    // 鍗曟嵁缂栧彿
+                                null,    // 瀹㈡埛鍚嶇О
+                                null,    // 鍝侀」鏁�
+                                null,    // 搴撳瓨浣欓噺
+                                null,    // 閲嶉噺
+                                1,    //
+                                null,    // 娣诲姞浜哄憳
+                                now,    // 娣诲姞鏃堕棿
+                                null,    // 淇敼浜哄憳
+                                updateTime,    // 淇敼鏃堕棿
+                                null    // 澶囨敞
+                        );
+                        matService.insert(mat);
+                    } else {
+                        mat.setUuid(String.valueOf(data.getRec()));
+                        mat.setMatnr(data.getUserCode());
+                        mat.setMaktx(data.getFullName());
+                        mat.setSpecs(data.getStandard());
+                        mat.setUpdateTime(updateTime);
+                        mat.setBarcode(data.getBarcode());
+                        mat.setUnit(data.getUnit3());
+                        matService.updateById(mat);
+                    }
+                    log.info("====>> 鏇存柊鐗╂枡锛歿}", data.getUserCode());
+                }
+
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+            throw new RuntimeException(e.getMessage());
+        }
+    }
+
+    /**
+     * 鍟嗗搧涓嬭浇
+     */
+    @Scheduled(cron = "0/5 * * * * ? ")
+    public void updateMatExecute(){
+        try {
+            Map<String, Object> param = new HashMap<>();
+            param.put("Flag", 6);
+            String response = new HttpHandler.Builder()
+                    .setUri(URI)
+                    .setPath(GET_BASIS)
+                    .setJson(JSON.toJSONString(param))
+                    .build()
+                    .doPost();
+            if (!Cools.isEmpty(response)) {
+//                log.info(response);
                 Date now = new Date();
                 Result result = JSON.parseObject(response, Result.class);
                 if (result.getCode() != 1) {
@@ -279,7 +429,7 @@
     public void getOrdersExecute(){
         try {
             Map<String, Object> json = new HashMap<>();
-            json.put("vchType", 151);
+            json.put("vchType", 11);
             String response = new HttpHandler.Builder()
                     .setUri(URI)
                     .setPath(GET_ORDERS)
@@ -405,7 +555,7 @@
 
                     // 澶�
                     getOrderResult0.setNumber(order.getOrderNo());
-                    getOrderResult0.setVchType(11); // todo:luxiaotao
+                    getOrderResult0.setVchType(11);
                     getOrderResult0.setBillDate(order.getOrderTime());
                     getOrderResult0.setBTypeID(order.getTel());
                     getOrderResult0.setKTypeID("瀹忔尯浠撳簱");
@@ -425,8 +575,7 @@
                         list.add(detl0);
                     }
 
-                    System.out.println(JSON.toJSONString(getOrderResult0));
-
+                    log.warn(JSON.toJSONString(getOrderResult0));
 
                     String response = new HttpHandler.Builder()
                             .setUri(URI)
@@ -440,7 +589,7 @@
                         if (result.getCode() != 1) {
                             continue;
                         }
-                        if (!orderService.updateSettle(getOrderResult0.getNumber(), 6L)) {
+                        if (!orderService.updateSettle(order.getOrderNo(), 6L)) {
                             throw new CoolException("淇敼璁㈠崟鐘舵�佸け璐�");
                         }
 //                        // 杞巻鍙叉。
@@ -483,7 +632,7 @@
 
                     // 澶�
                     getOrderResult0.setNumber(order.getOrderNo());
-                    getOrderResult0.setVchType(6); // todo:luxiaotao
+                    getOrderResult0.setVchType(6);
                     getOrderResult0.setBillDate(order.getOrderTime());
                     getOrderResult0.setBTypeID(order.getTel());
                     getOrderResult0.setKTypeID("瀹忔尯浠撳簱");
@@ -602,7 +751,7 @@
     public void getCancelOrdersExecute(){
         try {
             Map<String, Object> json = new HashMap<>();
-            json.put("vchType", 151);
+            json.put("vchType", 11);
             json.put("flag", 2);
             String response = new HttpHandler.Builder()
                     .setUri(URI)
@@ -624,8 +773,47 @@
                         existNumbers.add(result0.getNumber());
                     }
                     for (String number : existNumbers) {
-                        if (!orderService.updateSettle(number, 3L)) {
-//                            throw new CoolException("淇敼璁㈠崟鐘舵�佸け璐�");
+                        Order order = orderService.selectByOrderNo(number);
+                        if (order != null) {
+                            if (order.getSettle() != 3L && order.getSettle() != 5L) {
+                                if (orderService.updateSettle(number, 5L)) {
+                                    // 绔嬪簱鍑哄簱璐т綅杞嚦A99
+                                    List<Pakout> pakouts = pakoutService.selectList(new EntityWrapper<Pakout>()
+                                            .eq("node_id", -1).eq("doc_num", number).ne("memo", "1"));
+                                    Node node = nodeService.selectByUuid(Parameter.get().getUniNode());
+                                    for (Pakout pakout : pakouts) {
+                                        // 绔嬪簱鍑哄簱璐т綅
+                                        if (pakout.getLocNo().length() == 7) {
+                                            LocDetl locDetl = locDetlService.getLocDetl(node.getId(), pakout.getMatnr());
+                                            if (locDetl == null) {
+                                                locDetl = new LocDetl();
+                                                locDetl.setLocNo(node.getName());
+                                                locDetl.setNodeId(node.getId());
+                                                locDetl.setAnfme(pakout.getAnfme());
+                                                VersionUtils.setLocDetl(locDetl, pakout);
+                                                locDetl.setStatus(1);
+                                                locDetl.setCreateBy(9527L);
+                                                locDetl.setCreateTime(now);
+                                                locDetl.setUpdateBy(9527L);
+                                                locDetl.setUpdateTime(now);
+                                                boolean insert = locDetlService.insert(locDetl);
+                                                if (!insert) {
+                                                    throw new CoolException("鏂板搴撳瓨鏄庣粏妗eけ璐�");
+                                                }
+                                            } else {
+                                                if (!locDetlService.incrementStock(node.getId(), pakout.getMatnr(), pakout.getAnfme())) {
+                                                    throw new CoolException("鏂板搴撳瓨鏄庣粏妗eけ璐�");
+                                                }
+                                            }
+                                            if (!pakoutService.updateStep(pakout.getWrkNo(), pakout.getDocNum())) {
+                                                throw new CoolException("鍙栨秷璁㈠崟鍚庡洖婊氱珛搴撴嫞璐у崟澶辫触");
+                                            }
+                                        }
+                                    }
+                                } else {
+//                                    throw new CoolException("淇敼璁㈠崟鐘舵�佸け璐�");
+                                }
+                            }
                         }
                     }
 
@@ -635,59 +823,6 @@
             e.printStackTrace();
             throw new RuntimeException(e.getMessage());
         }
-
-    }
-
-    /**
-     * 涓婁紶閿�鍞鍗曞彇娑堢粨鏋�
-     */
-    @Scheduled(cron = "0/5 * * * * ? ")
-    @Transactional
-//    @PostConstruct
-    public void uploadCancelOrdersExecute(){
-//        try {
-//            List<Order> orders = orderService.selectList(new EntityWrapper<Order>().eq("settle", 3).isNotNull("number"));
-//            if (Cools.isEmpty(orders)) {
-//                return;
-//            }
-//            Map<String, Object> json = new HashMap<>();
-//            List<UploadCancelResult> list = new ArrayList<>();
-//            for (CustOrder custOrder : custOrders) {
-//                UploadCancelResult result = new UploadCancelResult();
-//                result.setNumber(custOrder.getNumber());
-//                result.setUserCode(custOrder.getUserCode());
-//                result.setQty(custOrder.getTotal());
-//                result.setStatus(1);
-//                list.add(result);
-//            }
-//            json.put("data", list);
-//            String response = new HttpHandler.Builder()
-//                    .setUri(URI)
-//                    .setPath(UPLOAD_CANCEL_RESULT)
-//                    .setJson(JSON.toJSONString(json))
-//                    .build()
-//                    .doPost();
-//            if (!Cools.isEmpty(response)) {
-////                log.info(response);
-//                Date now = new Date();
-//                Result result = JSON.parseObject(response, Result.class);
-//                if (result.getCode() != 1) {
-//                    return;
-//                }
-//                for (UploadCancelResult result1 : list) {
-//                    // 杞巻鍙叉。
-//                    int save = custOrderMapper.saveLog(result1.getNumber(), result1.getUserCode());
-//                    if (save > 0) {
-//                        if (custOrderMapper.delete(new EntityWrapper<CustOrder>().eq("number", result1.getNumber()).eq("user_code", result1.getUserCode())) == 0) {
-//                            throw new CoolException("鍒犻櫎閿�鍞鍗曞け璐�");
-//                        }
-//                    }
-//                }
-//            }
-//        } catch (IOException e) {
-//            e.printStackTrace();
-//            throw new RuntimeException(e.getMessage());
-//        }
 
     }
 

--
Gitblit v1.9.1