From 557cda61a3c85a620335d28b9c0e1f0d482cd41e Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@63.com>
Date: 星期四, 08 十二月 2022 15:58:39 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/common/service/erp/task/ErpScheduler.java |  116 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 109 insertions(+), 7 deletions(-)

diff --git a/src/main/java/com/zy/common/service/erp/task/ErpScheduler.java b/src/main/java/com/zy/common/service/erp/task/ErpScheduler.java
index 64efa11..dc5b068 100644
--- a/src/main/java/com/zy/common/service/erp/task/ErpScheduler.java
+++ b/src/main/java/com/zy/common/service/erp/task/ErpScheduler.java
@@ -1,17 +1,17 @@
 package com.zy.common.service.erp.task;
 
-import com.alibaba.fastjson.JSON;
 import com.core.common.Cools;
 import com.core.common.DateUtils;
+import com.core.common.SnowflakeIdWorker;
 import com.core.exception.CoolException;
-import com.zy.asrs.entity.Mat;
-import com.zy.asrs.entity.Tag;
-import com.zy.asrs.service.MatService;
-import com.zy.asrs.service.TagService;
+import com.zy.asrs.entity.*;
+import com.zy.asrs.service.*;
 import com.zy.asrs.task.AbstractHandler;
 import com.zy.common.service.erp.ErpService;
 import com.zy.common.service.erp.dto.VoucherDto;
 import com.zy.common.service.erp.entity.Goods;
+import com.zy.common.service.erp.entity.Voucher;
+import com.zy.common.service.erp.entity.VoucherDetail;
 import lombok.Synchronized;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -21,6 +21,8 @@
 
 import java.util.Date;
 import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 /**
  * erp浠诲姟鎺у埗鍣�
@@ -36,6 +38,14 @@
     private TagService tagService;
     @Autowired
     private MatService matService;
+    @Autowired
+    private OrderService orderService;
+    @Autowired
+    private DocTypeService docTypeService;
+    @Autowired
+    private OrderDetlService orderDetlService;
+    @Autowired
+    private SnowflakeIdWorker snowflakeIdWorker;
 
     @Scheduled(cron = "0/5 * * * * ? ")
     @Synchronized
@@ -65,7 +75,12 @@
                     }
 
                     if (!matService.insert(mat)) {
-                        throw new CoolException(JSON.toJSONString(good) + "鍟嗗搧鍚屾澶辫触");
+                        throw new CoolException(good.getBarCode() + "鍟嗗搧鍚屾澶辫触");
+                    } else {
+                        int state = 1;
+                        if (!erpService.updateStateForGoods(good.getBarCode(), state)) {
+                            throw new CoolException(good.getBarCode() + "鍟嗗搧淇敼State涓�"+state+"澶辫触");
+                        }
                     }
                 }
             }
@@ -77,7 +92,94 @@
     @Transactional
     public synchronized void syncOrder() {
         List<VoucherDto> list = erpService.selectOrder(0);
-        System.out.println(JSON.toJSONString(list));
+        for (VoucherDto dto : list) {
+            Voucher voucher = dto.getVoucher();
+            Order order = orderService.selectByNo(voucher.getVoucherID());
+            if (Cools.isEmpty(order)) {
+
+                String regEx = "[^0-9]";
+                Pattern compile = Pattern.compile(regEx);
+                Matcher matcher = compile.matcher(voucher.getMT());
+                String docTypeVal = matcher.replaceAll("").trim();
+
+                DocType docType = docTypeService.selectOrAdd(docTypeVal, null);
+                Date now = new Date();
+                // 鍗曟嵁涓绘。
+                order = new Order(
+                        String.valueOf(snowflakeIdWorker.nextId()),    // 缂栧彿[闈炵┖]
+                        voucher.getVoucherID(),    // 璁㈠崟缂栧彿
+                        DateUtils.convert(now),    // 鍗曟嵁鏃ユ湡
+                        docType.getDocId(),    // 鍗曟嵁绫诲瀷
+                        null,    // 椤圭洰缂栧彿
+                        null,    //
+                        null,    // 璋冩嫧椤圭洰缂栧彿
+                        voucher.getBatch(),    // 鍒濆绁ㄦ嵁鍙�
+                        voucher.getMaterialNO(),    // 绁ㄦ嵁鍙�
+                        null,    // 瀹㈡埛缂栧彿
+                        voucher.getCustomer(),    // 瀹㈡埛
+                        voucher.getCenterID(),    // 鑱旂郴鏂瑰紡
+                        voucher.getPlant(),    // 鎿嶄綔浜哄憳
+                        voucher.getTotalNum(),    // 鍚堣閲戦  ********************
+                        null,    // 浼樻儬鐜�
+                        null,    // 浼樻儬閲戦
+                        null,    // 閿�鍞垨閲囪喘璐圭敤鍚堣
+                        null,    // 瀹炰粯閲戦
+                        null,    // 浠樻绫诲瀷
+                        voucher.getLoc(),    // 涓氬姟鍛�
+                        voucher.getTotalCount(),    // 缁撶畻澶╂暟  ********************
+                        null,    // 閭垂鏀粯绫诲瀷
+                        null,    // 閭垂
+                        null,    // 浠樻鏃堕棿
+                        null,    // 鍙戣揣鏃堕棿
+                        null,    // 鐗╂祦鍚嶇О
+                        null,    // 鐗╂祦鍗曞彿
+                        1L,    // 璁㈠崟鐘舵��
+                        1,    // 鐘舵��
+                        9527L,    // 娣诲姞浜哄憳
+                        now,    // 娣诲姞鏃堕棿
+                        9527L,    // 淇敼浜哄憳
+                        now,    // 淇敼鏃堕棿
+                        null    // 澶囨敞
+                );
+                if (!orderService.insert(order)) {
+                    throw new CoolException(order.getOrderNo() + "鐢熸垚鍗曟嵁涓绘。澶辫触锛岃鑱旂郴绠$悊鍛�");
+                }
+                for (VoucherDetail detail : dto.getDetails()) {
+
+                    Mat mat = matService.selectByMatnr(detail.getBarcode());
+                    if (mat == null) {
+                        throw new CoolException(detail.getBarcode() + "鍗曟嵁鍙蜂笉瀛樺湪");
+                    }
+
+                    OrderDetl orderDetl = new OrderDetl();
+                    orderDetl.sync(mat);
+//                    orderDetl.setBatch(detlDto.getBatch());
+                    orderDetl.setAnfme(1.0D);
+                    orderDetl.setOrderId(order.getId());
+                    orderDetl.setOrderNo(order.getOrderNo());
+                    orderDetl.setCreateBy(9527L);
+                    orderDetl.setCreateTime(now);
+                    orderDetl.setUpdateBy(9527L);
+                    orderDetl.setUpdateTime(now);
+                    orderDetl.setStatus(1);
+                    orderDetl.setQty(0.0D);
+                    if (!orderDetlService.insert(orderDetl)) {
+                        throw new CoolException(order.getOrderNo() + "鐢熸垚鍗曟嵁鏄庣粏澶辫触锛岃鑱旂郴绠$悊鍛�");
+                    }
+                }
+
+                // erp 鍚屾
+                int state = 1;
+                if (!erpService.updateStateForVoucher(voucher.getVoucherID(), 1)) {
+                    throw new CoolException(voucher.getVoucherID() + "璁㈠崟淇敼State涓�"+state+"澶辫触");
+                } else {
+                    erpService.updateTimeForVoucherDetail(voucher.getVoucherID());
+                }
+
+            } else {
+                log.warn("{}璁㈠崟宸插瓨鍦�", voucher.getVoucherID());
+            }
+        }
     }
 
 }

--
Gitblit v1.9.1