From b47369fbc73269f0661ba169c6387e04fb037e87 Mon Sep 17 00:00:00 2001
From: cl <1442464845@qq.com>
Date: 星期一, 16 三月 2026 14:26:23 +0800
Subject: [PATCH] 发货通知单打印日志

---
 src/main/java/com/zy/common/service/erp/task/ErpScheduler.java |   40 ++++++++++++++++++++++++++++++++++------
 1 files changed, 34 insertions(+), 6 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 cf2464e..5975b76 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
@@ -16,6 +16,7 @@
 import com.zy.common.service.erp.ErpService;
 import com.zy.common.service.erp.dto.InStockDto;
 import com.zy.common.service.erp.entity.*;
+import lombok.Synchronized;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Scheduled;
@@ -23,6 +24,7 @@
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.PostConstruct;
+import java.math.BigDecimal;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
@@ -52,10 +54,13 @@
     /**
      * 鍘熸潗鏂欏叆搴撳崟
      */
-    @Scheduled(cron = "0/5 * * * * ? ")
+    @Scheduled(cron = "0/30 * * * * ? ")
+    @Synchronized
 //    @PostConstruct
     public void inStockExecute(){
+//        inStock鐨勮〃澶村拰琛ㄨ韩
         List<InStockDto> readyInStock = erpService.getReadyInStock();
+
         for (InStockDto dto : readyInStock) {
 
             //鍚屼竴鍗曞彿瀛樺湪鐩稿悓鐗╂枡缂栫爜鏁版嵁锛岃鍗曞彿涓嶄簣澶勭悊
@@ -66,7 +71,9 @@
                 }
                 continue;
             }
-
+            if (Cools.isEmpty(dto) || Cools.isEmpty(dto.getInStockBillEntries())) {
+                continue;
+            }
             for (InStockBillEntry entry : dto.getInStockBillEntries()) {
                 MatCode matCode = matCodeService.selectById(entry.getFnumber());
                 if (null != matCode) {
@@ -91,6 +98,7 @@
                     try {
                         if (one == null) {
                             waitPakin.setAnfme(entry.getFAuxQty());
+                            waitPakin.setNqty(entry.getFAuxQty());
                             if (!waitPakinService.insert(waitPakin)) {
                                 log.error("鎻愬彇鍘熸潗鏂欏叆搴撻�氱煡鍗旾nStockBillEntry澶辫触[FBillNo={},Fnumber={}]", waitPakin.getSupplier(), waitPakin.getMatnr());
                             } else {
@@ -98,6 +106,7 @@
                             }
                         } else {
                             waitPakin.setAnfme(entry.getFAuxQty());
+                            waitPakin.setNqty(entry.getFAuxQty());
                             if (!waitPakinService.update(waitPakin, wrapper)) {
                                 log.error("鏇存柊鍘熸潗鏂欏叆搴撻�氱煡鍗旾nStockBillEntry澶辫触[FBillNo={},Fnumber={}]", waitPakin.getSupplier(), waitPakin.getMatnr());
                             } else {
@@ -105,6 +114,7 @@
                             }
                         }
                     } catch (Exception e) {
+                        log.error("fail", e);
                         e.printStackTrace();
                         System.out.println(JSON.toJSON(waitPakin));
                     }
@@ -121,7 +131,8 @@
     /**
      * 鎴愬搧鍏ュ簱鍗�
      */
-    @Scheduled(cron = "0/5 * * * * ? ")
+    @Scheduled(cron = "0/20 * * * * ? ")
+    @Synchronized
 //    @PostConstruct
     public void inCPICMOExecute(){
         List<CPICMO> cpicmos = erpService.getReadyCPICMO();
@@ -158,6 +169,7 @@
                 WaitPakin one = waitPakinService.selectOne(wrapper);
                 if (one == null) {
                     waitPakin.setAnfme(cpicmo.getFAuxQty());
+                    waitPakin.setNqty(cpicmo.getFAuxQty());
                     if (!waitPakinService.insert(waitPakin)) {
                         log.error("鎻愬彇鎴愬搧鍏ュ簱閫氱煡鍗旵PICMO澶辫触[FBillNo={},Fnumber={}]", waitPakin.getSupplier(), waitPakin.getMatnr());
                     } else {
@@ -165,6 +177,7 @@
                     }
                 } else {
                     waitPakin.setAnfme(cpicmo.getFAuxQty());
+                    waitPakin.setNqty(cpicmo.getFAuxQty());
                     if (!waitPakinService.update(waitPakin, wrapper)) {
                         log.error("鍚屾鏇存柊鎴愬搧鍏ュ簱閫氱煡鍗旵PICMO澶辫触[FBillNo={},Fnumber={}]", waitPakin.getSupplier(), waitPakin.getMatnr());
                     } else {
@@ -178,7 +191,8 @@
         }
     }
 
-    @Scheduled(cron = "0/5 * * * * ? ")
+    @Scheduled(cron = "0/30 * * * * ? ")
+    @Synchronized
     public void syncMat(){
         List<M_item> items = erpService.getItem();
         for (M_item item : items) {
@@ -213,15 +227,21 @@
      * 鎴愬搧鍑哄簱 鍙戣揣閫氱煡鍗曡〃澶�,琛ㄦ槑缁�
      */
     @Scheduled(cron = "0/15 * * * * ? ")
+    @Synchronized
     @Transactional
     public void syncOutStock(){
         List<OutStockBill> outStockBills = erpService.syncOutStock();
+        log.info("鍑哄簱鍚屾寮�濮嬶紝ERP鏈鍗曟暟={}", outStockBills != null ? outStockBills.size() : 0);
+        if (outStockBills == null || outStockBills.isEmpty()) {
+            return;
+        }
         for (Integer i = 0; i < outStockBills.size(); i++) {
             OutStockBill outStockBill = outStockBills.get(i);
 
             //鍚屼竴鍗曞彿瀛樺湪鐩稿悓鐗╂枡缂栫爜鏁版嵁锛岃鍗曞彿涓嶄簣澶勭悊
             Number fnumberCount = erpService.QueryFnumberOutCount(outStockBill.getFInterID());
             if(fnumberCount.intValue() > 1){
+                log.info("鍑哄簱鍚屾璺宠繃锛氬悓涓�鍗曞彿瀛樺湪鐩稿悓鐗╂枡[FBillNo={},FInterID={}]锛屼笉浜堝悓姝�", outStockBill.getFBillNo(), outStockBill.getFInterID());
                 if (!erpService.haveReadOutBill(outStockBill.getFBillNo(),outStockBill.getFInterID(),-1)) {
                     log.error("鏇存柊鍑哄簱閫氱煡鍗曡鍙栫姸鎬佷负-1澶辫触[FBrNo={},FInterID={}]", outStockBill.getFBrNo(),outStockBill.getFInterID());
                 }
@@ -230,12 +250,17 @@
 
             OutStockBill main = outStockMainService.selectOne(new EntityWrapper<OutStockBill>().eq("FBillNo",outStockBill.getFBillNo()).and().eq("FInterID", outStockBill.getFInterID()));
             if (null == main) {
+                log.info("鍑哄簱鍚屾鏂板崟锛欶BillNo={}, FInterID={}锛屼粠ERP鍚屾鍒癢MS", outStockBill.getFBillNo(), outStockBill.getFInterID());
                 outStockBill.setFflag_rw(1);
                 if (!outStockMainService.insert(outStockBill)) {
-                    log.info("鍚屾鍑哄簱閫氱煡涓昏〃OutStockBill澶辫触");
+                    log.error("鍑哄簱鍚屾澶辫触锛氬悓姝ュ嚭搴撻�氱煡涓昏〃OutStockBill澶辫触[FBillNo={},FInterID={}]", outStockBill.getFBillNo(), outStockBill.getFInterID());
                     exceptionHandle("鍚屾鍑哄簱閫氱煡涓昏〃OutStockBill澶辫触[FBillNo={0},FInterID={1}]",outStockBill.getFBillNo(),outStockBill.getFInterID());
                 };
                 List<OutStockBillEntry> outStockBillEntries = erpService.syncOutStockDetail(outStockBill.getFInterID());
+                if (outStockBillEntries == null || outStockBillEntries.isEmpty()) {
+                    log.warn("鍑哄簱鍚屾锛欵RP璇ュ崟鏄庣粏鏁颁负0锛孎BillNo={}, FInterID={}锛堝彲鑳紼RP鏉′欢FAuxCommitQty=0鏃犳暟鎹級", outStockBill.getFBillNo(), outStockBill.getFInterID());
+                }
+                if (outStockBillEntries != null) {
                 for (Integer j = 0; j < outStockBillEntries.size(); j++) {
                     OutStockBillEntry outStockBillEntry = outStockBillEntries.get(j);
                     Wrapper<OutStockBillEntry> wrapper = new EntityWrapper<OutStockBillEntry>().eq("FInterID", outStockBillEntry.getFInterID()).
@@ -244,6 +269,7 @@
                     if (null == one) {
 //                        String Fnumber = (Cools.isEmpty(outStockBillEntry.getFSourceBillNo())) ? outStockBillEntry.getFnumber() : outStockBillEntry.getFnumber()+"|"+outStockBillEntry.getFSourceBillNo();
 //                        outStockBillEntry.setFnumber(Fnumber);  //浜у搧浠g爜|鐢熶骇鍗曞彿
+                        outStockBillEntry.setFAmount(new BigDecimal(0));
                         if (!outStockService.insert(outStockBillEntry)) {
                             log.info("鎻愬彇鍑哄簱閫氱煡鏄庣粏琛∣utStockBillEntry澶辫触[FBrNo={},FInterID={},FEntryID={}]",outStockBillEntry.getFBrNo(),
                                     outStockBillEntry.getFInterID(),outStockBillEntry.getFEntryID());
@@ -256,6 +282,7 @@
                     } else {
                         // 鏁伴噺鏈夊彉鍖栬繘琛屾洿鏂�
                         if (Double.doubleToLongBits(one.getFAuxQty().doubleValue()) != Double.doubleToLongBits(outStockBillEntry.getFAuxQty().doubleValue())) {
+                            outStockBillEntry.setFAmount(new BigDecimal(0));
                             if (!outStockService.update(outStockBillEntry, wrapper)) {
                                 log.info("鍚屾鏇存柊閫氱煡鏄庣粏琛∣utStockBillEntry澶辫触[FBrNo={},FInterID={},FEntryID={}]",outStockBillEntry.getFBrNo(),
                                         outStockBillEntry.getFInterID(),outStockBillEntry.getFEntryID());
@@ -268,8 +295,9 @@
                         }
                     }
                 }
+                }
             } else {
-
+                log.debug("鍑哄簱鍚屾锛歐MS宸插瓨鍦ㄨ鍗曪紝璺宠繃鍚屾鏄庣粏 FBillNo={}, FInterID={}", outStockBill.getFBillNo(), outStockBill.getFInterID());
             }
 
             if (!erpService.haveReadOutBill(outStockBill.getFBillNo(),outStockBill.getFInterID(),1)) {

--
Gitblit v1.9.1