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/asrs/controller/SaleOrderController.java |  140 ++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 132 insertions(+), 8 deletions(-)

diff --git a/src/main/java/com/zy/asrs/controller/SaleOrderController.java b/src/main/java/com/zy/asrs/controller/SaleOrderController.java
index c527da6..a0e80fc 100644
--- a/src/main/java/com/zy/asrs/controller/SaleOrderController.java
+++ b/src/main/java/com/zy/asrs/controller/SaleOrderController.java
@@ -7,7 +7,9 @@
 import com.baomidou.mybatisplus.plugins.Page;
 import com.core.common.DateUtils;
 import com.zy.asrs.entity.SaleOrder;
+import com.zy.asrs.entity.WaitPakin;
 import com.zy.asrs.service.SaleOrderService;
+import com.zy.asrs.service.WaitPakinService;
 import com.core.annotations.ManagerAuth;
 import com.core.common.BaseRes;
 import com.core.common.Cools;
@@ -16,7 +18,10 @@
 import com.zy.common.web.BaseController;
 
 import org.apache.poi.xssf.usermodel.*;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.dao.DeadlockLoserDataAccessException;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
@@ -31,8 +36,12 @@
 @RestController
 public class SaleOrderController extends BaseController {
 
+    private static final Logger logger = LoggerFactory.getLogger(SaleOrderController.class);
+
     @Autowired
     private SaleOrderService saleOrderService;
+    @Autowired
+    private WaitPakinService waitPakinService;
 
     @RequestMapping(value = "/saleOrder/{id}/auth")
     @ManagerAuth
@@ -234,6 +243,7 @@
         }
         int successCount = 0;
         int updateCount = 0;
+        int skipCount = 0;
         for (Map<String, Object> data : dataList) {
             try {
                 // 妫�鏌ユ槸鍚﹀凡瀛樺湪锛堟牴鎹鍗曞彿鍜岀墿鏂欑紪鐮侊級
@@ -242,11 +252,39 @@
                 
                 SaleOrder saleOrder;
                 boolean isUpdate = false;
+                boolean hasQtyChange = false;
+                
                 if (existOrder != null) {
-                    // 宸插瓨鍦紝鏇存柊鏁版嵁
-                    saleOrder = existOrder;
-                    isUpdate = true;
-                    updateCount++;
+                    // 宸插瓨鍦紝妫�鏌ユ暟閲忓瓧娈垫槸鍚︽湁鍙樺寲
+                    Double newOrderQty = parseDoubleSafely(data.get("orderQty"));
+                    Double newProductQty = parseDoubleSafely(data.get("productQty"));
+                    Double newInQty = parseDoubleSafely(data.get("inQty"));
+                    Double newOutQty = parseDoubleSafely(data.get("outQty"));
+                    Double newOutAmount = parseDoubleSafely(data.get("outAmount"));
+                    Double newOutPrice = parseDoubleSafely(data.get("outPrice"));
+                    Double newIcsbeqty = parseDoubleSafely(data.get("icsbeqty"));
+                    Double newSeoseqty = parseDoubleSafely(data.get("seoseqty"));
+                    
+                    // 姣旇緝鏁伴噺瀛楁鏄惁鏈夊彉鍖�
+                    hasQtyChange = !isDoubleEqual(existOrder.getOrderQty(), newOrderQty)
+                            || !isDoubleEqual(existOrder.getProductQty(), newProductQty)
+                            || !isDoubleEqual(existOrder.getInQty(), newInQty)
+                            || !isDoubleEqual(existOrder.getOutQty(), newOutQty)
+                            || !isDoubleEqual(existOrder.getOutAmount(), newOutAmount)
+                            || !isDoubleEqual(existOrder.getOutPrice(), newOutPrice)
+                            || !isDoubleEqual(existOrder.getIcsbeqty(), newIcsbeqty)
+                            || !isDoubleEqual(existOrder.getSeoseqty(), newSeoseqty);
+                    
+                    // 鍙湁褰撴暟閲忔湁鍙樺寲鏃舵墠鏇存柊
+                    if (hasQtyChange) {
+                        saleOrder = existOrder;
+                        isUpdate = true;
+                        updateCount++;
+                    } else {
+                        // 鏁伴噺娌℃湁鍙樺寲锛岃烦杩囨洿鏂�
+                        skipCount++;
+                        continue;
+                    }
                 } else {
                     // 涓嶅瓨鍦紝鍒涘缓鏂拌褰�
                     saleOrder = new SaleOrder();
@@ -285,6 +323,8 @@
                 // 淇濆瓨鎴栨洿鏂�
                 if (isUpdate) {
                     saleOrderService.updateById(saleOrder);
+                    // 閿�鍞鍗曟洿鏂板悗锛岄『甯︽洿鏂� xtyasrs 搴� cust_wait_pakin 鐨勬暟閲忥紙mobile/bill/query 鐨� count 鍙栬嚜 anfme锛夛紝浠呮洿鏂般�佷笉鎻掑叆锛屽け璐ヤ笉褰卞搷涓绘祦绋�
+                    updateWaitPakinQuantity(data);
                 } else {
                     saleOrderService.insert(saleOrder);
                 }
@@ -293,7 +333,90 @@
                 e.printStackTrace();
             }
         }
-        return R.ok("鎴愬姛淇濆瓨 " + successCount + " 鏉℃柊鏁版嵁锛屾洿鏂� " + updateCount + " 鏉″凡瀛樺湪鏁版嵁");
+        String message = "鎴愬姛淇濆瓨 " + successCount + " 鏉℃柊鏁版嵁锛屾洿鏂� " + updateCount + " 鏉″凡瀛樺湪鏁版嵁";
+        if (skipCount > 0) {
+            message += "锛岃烦杩� " + skipCount + " 鏉℃暟閲忔湭鍙樺寲鐨勬暟鎹�";
+        }
+        return R.ok(message);
+    }
+    
+    /**
+     * 姣旇緝涓や釜Double鍊兼槸鍚︾浉绛夛紙澶勭悊null鍊煎拰0鍊硷級
+     * 閲嶈锛歯ull鍜�0琚涓烘槸涓嶅悓鐨勫�硷紝闇�瑕佹洿鏂�
+     * @param d1 绗竴涓狣ouble鍊�
+     * @param d2 绗簩涓狣ouble鍊�
+     * @return true-鐩哥瓑锛宖alse-涓嶇浉绛�
+     */
+    private boolean isDoubleEqual(Double d1, Double d2) {
+        // 涓や釜閮芥槸null锛岃涓虹浉绛�
+        if (d1 == null && d2 == null) {
+            return true;
+        }
+        // 涓�涓负null锛屽彟涓�涓笉涓簄ull锛岃涓轰笉鐩哥瓑锛堥渶瑕佹洿鏂帮級
+        // 娉ㄦ剰锛歯ull鍜�0鏄笉鍚岀殑锛宯ull鍜�0.0浼氳繑鍥瀎alse锛岃Е鍙戞洿鏂�
+        if (d1 == null || d2 == null) {
+            return false;
+        }
+        // 涓や釜閮戒笉涓簄ull锛屼娇鐢ㄨ宸寖鍥存瘮杈冿紝閬垮厤娴偣鏁扮簿搴﹂棶棰�
+        // 娉ㄦ剰锛�0鍊间細琚纭瘮杈冿紝渚嬪锛�0.0鍜�0.0浼氳繑鍥瀟rue锛�100.0鍜�0.0浼氳繑鍥瀎alse
+        return Math.abs(d1 - d2) < 0.0001;
+    }
+
+    /** 姝婚攣閲嶈瘯娆℃暟 */
+    private static final int CUST_WAIT_PAKIN_DEADLOCK_RETRIES = 2;
+    /** 姝婚攣閲嶈瘯闂撮殧锛堟绉掞級 */
+    private static final int CUST_WAIT_PAKIN_RETRY_DELAY_MS = 80;
+
+    /**
+     * 閿�鍞鍗曟暟閲忔洿鏂板悗锛岄『甯︽洿鏂� cust_wait_pakin 鐨� anfme/nqty锛坢obile/bill/query 鐨� count 鍙栬嚜 anfme锛夈��
+     * 浠呮寜 matnr+mnemonic 鏇存柊锛屼笉鎻掑叆锛涙棤鍖归厤鎴栧紓甯镐笉褰卞搷涓绘祦绋嬨��
+     * 鍙戠敓姝婚攣鏃惰嚜鍔ㄩ噸璇曪紝鍑忓皯骞跺彂鏇存柊瀵艰嚧鐨勬閿佺壓鐗层��
+     */
+    private void updateWaitPakinQuantity(Map<String, Object> data) {
+        String invCode = data.get("invCode") != null ? String.valueOf(data.get("invCode")).trim() : null;
+        String orderCode = data.get("orderCode") != null ? String.valueOf(data.get("orderCode")).trim() : null;
+        if (Cools.isEmpty(invCode) || Cools.isEmpty(orderCode)) {
+            logger.debug("cust_wait_pakin 璺宠繃鏇存柊锛氳鍗曞彿鎴栫墿鏂欑紪鐮佷负绌猴紝orderCode={}锛宨nvCode={}", orderCode, invCode);
+            return;
+        }
+        Double productQty = parseDoubleSafely(data.get("productQty"));
+        if (productQty == null) {
+            productQty = parseDoubleSafely(data.get("orderQty"));
+        }
+        logger.info("cust_wait_pakin 寮�濮嬫洿鏂帮細璁㈠崟鍙�={}锛岀墿鏂欑紪鐮�={}锛屾暟閲�={}", orderCode, invCode, productQty);
+        String invName = data.get("invName") != null ? String.valueOf(data.get("invName")) : null;
+        WaitPakin updateEntity = new WaitPakin();
+        updateEntity.setMaktx(invName);
+        updateEntity.setAnfme(productQty);
+        updateEntity.setNqty(productQty);
+        updateEntity.setModiTime(new Date());
+        Wrapper<WaitPakin> wrapper = new EntityWrapper<WaitPakin>().eq("matnr", invCode).eq("mnemonic", orderCode);
+
+        for (int attempt = 0; attempt <= CUST_WAIT_PAKIN_DEADLOCK_RETRIES; attempt++) {
+            try {
+                boolean updated = waitPakinService.update(updateEntity, wrapper);
+                if (updated) {
+                    logger.info("cust_wait_pakin 鏇存柊鎴愬姛锛氳鍗曞彿={}锛岀墿鏂欑紪鐮�={}锛屾暟閲�={}", orderCode, invCode, productQty);
+                } else {
+                    logger.warn("cust_wait_pakin 鏇存柊鏈奖鍝嶈锛堝彲鑳芥棤鍖归厤璁板綍锛夛細璁㈠崟鍙�={}锛岀墿鏂欑紪鐮�={}", orderCode, invCode);
+                }
+                return;
+            } catch (Exception e) {
+                if (e instanceof DeadlockLoserDataAccessException || (e.getCause() != null && e.getCause().getClass().getSimpleName().contains("Deadlock"))) {
+                    if (attempt < CUST_WAIT_PAKIN_DEADLOCK_RETRIES) {
+                        try {
+                            Thread.sleep(CUST_WAIT_PAKIN_RETRY_DELAY_MS);
+                        } catch (InterruptedException ie) {
+                            Thread.currentThread().interrupt();
+                        }
+                        logger.warn("cust_wait_pakin 鏇存柊姝婚攣锛岀{}娆¢噸璇曪細璁㈠崟鍙�={}锛岀墿鏂欑紪鐮�={}", attempt + 1, orderCode, invCode);
+                        continue;
+                    }
+                }
+                logger.error("cust_wait_pakin 鏇存柊寮傚父锛歰rderCode={}锛宨nvCode={}锛宔rror={}", data.get("orderCode"), data.get("invCode"), e.getMessage(), e);
+                return;
+            }
+        }
     }
 
     @RequestMapping(value = "/saleOrder/update/auth")
@@ -496,11 +619,12 @@
 
             // 琛ㄥご
             String[] headers = { "鐢熶骇鍗曞彿", "涓氬姟鍛�", "鍥惧彿", "鐗╂枡鍚嶇О", "瑙勬牸", "璁㈠崟鏁伴噺", "浜よ揣鏃ユ湡",
-                    "浠诲姟鍗曟暟閲�", "鎴愬搧鏁伴噺", "鍑鸿揣閫氱煡鏁�", "瀹炲嚭鏁伴噺", "瀵硅处鏁伴噺", "瀵硅处鍗曚环", "瀵硅处閲戦",
+                    "浠诲姟鍗曟暟閲�", "鎴愬搧鏁伴噺", "鍑鸿揣閫氱煡鏁�", /* "瀹炲嚭鏁伴噺", */ "瀵硅处鏁伴噺", "瀵硅处鍗曚环", "瀵硅处閲戦",
                     "鍖呮潗鐗堣垂", "閫�绋庤祫鏂�", "寮�绁�", "鍐呴檰璐�", "鏀舵", "搴旀敹娆句綑棰�",
                     "瀵硅处鏁伴噺娈嬩綑", "瀵硅处閲戦娈嬩綑", "浠诲姟鍗曟畫浣�", "瀹炲嚭鏁伴噺娈嬩綑", "鏀舵娈嬩綑" };
+            // 瀹炲嚭鏁伴噺瀛楁宸查殣钘忥紝isCalc鏁扮粍闇�瑕佺浉搴旇皟鏁达紙绉婚櫎涓�涓猣alse锛�
             boolean[] isCalc = { false, false, false, false, false, false, false,
-                    false, false, false, false, false, false, false,
+                    false, false, false, /* false, */ false, false, false,
                     false, false, false, false, false, false,
                     true, true, true, true, true };
 
@@ -528,7 +652,7 @@
                 createNumCell(row, col++, order.getProductQty(), dataStyle);
                 createNumCell(row, col++, order.getInQty(), dataStyle);
                 createNumCell(row, col++, order.getIcsbeqty(), dataStyle);
-                createNumCell(row, col++, order.getSeoseqty(), dataStyle);
+                // createNumCell(row, col++, order.getSeoseqty(), dataStyle);
                 createNumCell(row, col++, order.getOutQty(), dataStyle);
                 createNumCell(row, col++, order.getOutPrice(), dataStyle);
                 createNumCell(row, col++, order.getOutAmount(), dataStyle);

--
Gitblit v1.9.1