From b97ab3e077df3665663eb3a5b0c23d54c83a5548 Mon Sep 17 00:00:00 2001
From: tzsk <Administrator@qq.com>
Date: 星期五, 31 五月 2024 12:02:25 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/common/service/erp/task/ErpScheduler.java |  190 +++++++++++-----------------------------------
 1 files changed, 47 insertions(+), 143 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 1b531da..9819fde 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,28 +1,21 @@
 package com.zy.common.service.erp.task;
 
-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.*;
-import com.zy.asrs.service.*;
+import com.zy.asrs.entity.AllLocDetl;
+import com.zy.asrs.entity.InventoryVariance;
+import com.zy.asrs.service.AllLocDetlService;
+import com.zy.asrs.service.InventoryVarianceService;
+import com.zy.asrs.service.MatService;
+import com.zy.asrs.service.TagService;
 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 com.zy.common.service.erp.entity.WlzhVStRd;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
-import org.springframework.transaction.annotation.Transactional;
 
-import java.util.Date;
+import java.util.ArrayList;
 import java.util.List;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
 
 /**
  * erp浠诲姟鎺у埗鍣�
@@ -39,145 +32,56 @@
     @Autowired
     private MatService matService;
     @Autowired
-    private OrderService orderService;
+    private AllLocDetlService allLocDetlService;
     @Autowired
-    private DocTypeService docTypeService;
-    @Autowired
-    private OrderDetlService orderDetlService;
-    @Autowired
-    private SnowflakeIdWorker snowflakeIdWorker;
+    private InventoryVarianceService inventoryVarianceService;
 
-    @Scheduled(cron = "0/5 * * * * ? ")
-    @Synchronized
-    @Transactional
-    public synchronized void syncMat() {
-        Tag top = tagService.getTop();
-        List<Goods> goods = erpService.selectGoods(0);
-        Date now = new Date();
-        if (!Cools.isEmpty(goods)) {
-            for (Goods good : goods) {
-                Mat mat = matService.selectByMatnr(good.getBarCode());
-                if (mat == null) {
-                    mat = new Mat();
-                    mat.setTagId(top.getId());
-                    mat.setMatnr(good.getBarCode());
-                    mat.setMaktx(good.getMaterialNO());
-                    mat.setSpecs(good.getProdSpec());
-                    mat.setModel(good.getBatch());
-                    mat.setWeight(good.getNWT());
-                    mat.setUnits(good.getNumOfBobbins()==null?null:good.getNumOfBobbins().doubleValue());
-                    mat.setManuDate(good.getProdDate());
 
-                    mat.setCreateTime(now);
-                    mat.setSku(good.getLocation());
-                    if (!Cools.isEmpty(good.getLastUpdatedDate())) {
-                        mat.setUpdateTime(DateUtils.convert(good.getLastUpdatedDate().substring(0, 19)));
-                    }
+    @Scheduled(cron = "0 0 2 * * ? ")
+    public void syncLocDetl(){
+        log.info("搴撳瓨宸紓淇℃伅娓呴櫎");
+        inventoryVarianceService.deleteAll();
 
-                    if (!matService.insert(mat)) {
-                        throw new CoolException(good.getBarCode() + "鍟嗗搧鍚屾澶辫触");
-                    } else {
-                        int state = 1;
-                        if (!erpService.updateStateForGoods(good.getBarCode(), state)) {
-                            throw new CoolException(good.getBarCode() + "鍟嗗搧淇敼State涓�"+state+"澶辫触");
-                        }
-                    }
-                }
+        log.info("涓嶦RP姣斿寮�濮�");
+        int pageSize = 500;
+        int pageNumber = 0;
+        while (true){
+            List<InventoryVariance> inventoryVariances = new ArrayList<>();
+            List<WlzhVStRd> wlzhVStRds = erpService.selectPage(pageSize, pageNumber);
+            if(wlzhVStRds.size() < pageSize){
+                break;
             }
+
+            //ERP搴撳瓨涓庣珛搴撳簱瀛樻瘮瀵�
+            compileStock(wlzhVStRds,inventoryVariances);
+            pageNumber ++;
+            inventoryVarianceService.insertBatch(inventoryVariances);
         }
+
     }
 
-    @Scheduled(cron = "0/5 * * * * ? ")
-    @Synchronized
-    @Transactional
-    public synchronized void syncOrder() {
-        List<VoucherDto> list = erpService.selectOrder(0);
-        for (VoucherDto dto : list) {
-            Voucher voucher = dto.getVoucher();
-            Order order = orderService.selectByNo(voucher.getVoucherID());
-            if (Cools.isEmpty(order)) {
+    private void compileStock(List<WlzhVStRd> wlzhVStRds, List<InventoryVariance> inventoryVariances){
+        wlzhVStRds.forEach(wlzhVStRd -> {
+            String matnr = wlzhVStRd.getCinvcode();
+            String csocode = wlzhVStRd.getCsocode();
+            String isoseq = wlzhVStRd.getIsoseq();
+            Double iQuantity = wlzhVStRd.getIquantity();
 
-                String regEx = "[^0-9]";
-                Pattern compile = Pattern.compile(regEx);
-                Matcher matcher = compile.matcher(voucher.getMT());
-                String docTypeVal = matcher.replaceAll("").trim();
+            Double anfme = 0.0;
 
-                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 {
-                log.warn("{}璁㈠崟宸插瓨鍦�", voucher.getVoucherID());
+            List<AllLocDetl> allLocDetlList = allLocDetlService.getByMatnrAndCsocodeAndIsoseq(matnr, csocode, isoseq);
+            for(AllLocDetl allLocDetl : allLocDetlList){
+                anfme += allLocDetl.getAnfme();
             }
-        }
+
+            int compare = Double.compare(iQuantity, anfme);
+            if(compare != 0){
+                InventoryVariance inventoryVarianceParam = new InventoryVariance(matnr,csocode,isoseq,iQuantity,anfme);
+                inventoryVariances.add(inventoryVarianceParam);
+            }
+
+        });
     }
 
+
 }

--
Gitblit v1.9.1