From d3234825d804a6a205dba1c6092acc8e29981b81 Mon Sep 17 00:00:00 2001
From: lfd <1>
Date: 星期四, 06 三月 2025 10:11:23 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/ints/task/scheduler/ErpDetTbScheduler.java |  125 ++++++++++++++++++++++++++++-------------
 1 files changed, 84 insertions(+), 41 deletions(-)

diff --git a/src/main/java/com/zy/ints/task/scheduler/ErpDetTbScheduler.java b/src/main/java/com/zy/ints/task/scheduler/ErpDetTbScheduler.java
index 79f1b65..0e41258 100644
--- a/src/main/java/com/zy/ints/task/scheduler/ErpDetTbScheduler.java
+++ b/src/main/java/com/zy/ints/task/scheduler/ErpDetTbScheduler.java
@@ -1,12 +1,10 @@
 package com.zy.ints.task.scheduler;
 
+import com.baomidou.mybatisplus.mapper.EntityWrapper;
 import com.core.common.Cools;
 import com.core.common.DateUtils;
 import com.core.common.SnowflakeIdWorker;
-import com.zy.asrs.entity.DocType;
-import com.zy.asrs.entity.Mat;
-import com.zy.asrs.entity.Order;
-import com.zy.asrs.entity.OrderDetl;
+import com.zy.asrs.entity.*;
 import com.zy.asrs.service.*;
 import com.zy.ints.entity.ErpDetTb;
 import com.zy.ints.entity.ErpDetTbBak;
@@ -34,6 +32,8 @@
      */
     @Value("${erp.enabled}")
     private Boolean erpEnabled;
+    @Value("${erp.enabledErpDetTb}")
+    private Boolean erpEnabledErpDetTb;
     @Value("${erp.useName.ip}")
     private String ip;
     @Autowired
@@ -56,10 +56,10 @@
      */
     @Scheduled(cron = "${erp.refreshtime}")
     public void InOrOutOrder() {
-        if (!erpEnabled) return;
-        String sqlSelectErpDetTb = "select bill_no as billNo,prd_no as prdNo,iokindid,add_id as addId,qty,prd_mark as prdMark,wh,billdate,status,temp1,temp2,temp3 from erp_det_tb where 1=1";
-        String sqlUpDateErpDetTbOne = "update erp_det_tb set status=1 where 1=1 and prd_no=";
-        String sqlUpDateErpDetTbTwo = "update erp_det_tb set status=2 ";
+        if (!erpEnabledErpDetTb) return;
+        String sqlSelectErpDetTb = "select BIL_NO as billNo,prd_no as prdNo,ITM as itm,ADD_ID as addId2,QTY as qty,PRD_MARK as prdMark,WH as wh,STATUS as status,Temp1 as temp1,Temp2 as temp2,Temp3 as temp3 from ERP_DETTB where 1=1";
+        String sqlUpDateErpDetTbOne = "update ERP_DETTB set STATUS=1 where 1=1 and PRD_NO=";
+        String sqlUpDateErpDetTbTwo = "update ERP_DETTB set STATUS=2 ";
 
         try {
             List<ErpDetTb> erpDetTbs = erpSqlServer.select(sqlSelectErpDetTb, ErpDetTb.class);
@@ -70,14 +70,19 @@
                     if (status == 0) {
                         Mat mat = matService.selectByMatnr(erpDetTb.getPrdNo());
                         if (Cools.isEmpty(mat)) {
-                            erpSqlServer.update(sqlUpDateErpDetTbTwo + ",temp1='鍝佸彿淇℃伅鍦ㄧ珛搴撲笉瀛樺湪锛岃鍏堟坊鍔犲晢鍝侊紒锛侊紒'" + "where 1=1 and prd_no=" + "'" + erpDetTb.getPrdNo() + "'");
-                            callApiLogSave(erpDetTb, "erp_det_tb", "鍝佸彿淇℃伅鍦ㄧ珛搴撲笉瀛樺湪锛岃鍏堟坊鍔犲晢鍝侊紒锛侊紒", false);
+                            if(Cools.isEmpty(erpDetTb.getTemp1())){
+                                erpSqlServer.update(sqlUpDateErpDetTbTwo + ",Temp1='鍝佸彿淇℃伅鍦ㄧ珛搴撲笉瀛樺湪锛岃鍏堟坊鍔犲晢鍝侊紒锛侊紒'" + "where 1=1 "
+                                        +" and PRD_NO=" + "'" + erpDetTb.getPrdNo() + "'"
+                                        +" and ITM=" + "'" + erpDetTb.getItm() + "'"
+                                        +" and BIL_NO=" + "'" + erpDetTb.getBillNo() + "'");
+                                callApiLogSave(erpDetTb, "ERP_DETTB", "鍝佸彿淇℃伅鍦ㄧ珛搴撲笉瀛樺湪锛岃鍏堟坊鍔犲晢鍝侊紒锛侊紒", false);
+                            }
                         } else {
-                            Order order = orderService.selectByNo(erpDetTb.getBillNo());
+                            Order order = orderService.selectByNo(erpDetTb.getBillNo()+"---"+erpDetTb.getItm());
                             if (Cools.isEmpty(order)) {
                                 order = new Order(
                                         String.valueOf(snowflakeIdWorker.nextId()),    // 缂栧彿[闈炵┖]
-                                        erpDetTb.getBillNo(),    // 璁㈠崟缂栧彿
+                                        erpDetTb.getBillNo()+"---"+erpDetTb.getItm(),    // 璁㈠崟缂栧彿
                                         DateUtils.convert(now),    // 鍗曟嵁鏃ユ湡
                                         null,    // 鍗曟嵁绫诲瀷
                                         null,    // 椤圭洰缂栧彿
@@ -111,25 +116,26 @@
                                         now,    // 淇敼鏃堕棿
                                         null    // 澶囨敞
                                 );
-                                String InAndOut = erpDetTb.getAddId().equals("2") ? "锛堝嚭搴擄級" : "锛堝叆搴擄級";
-                                DocType docType = docTypeService.selectOrAdd(erpDetTb.getIokindid$() + InAndOut, erpDetTb.getAddId().equals("1"));
+                                String InAndOut = erpDetTb.getAddId2().equals(2) ? "锛堝嚭搴擄級" : "锛堝叆搴擄級";
+                                DocType docType = docTypeService.selectOrAdd("ERP璁㈠崟"+InAndOut, erpDetTb.getAddId2().equals(1));
                                 if (!Cools.isEmpty(docType)) {
                                     order.setDocType(docType.getDocId());
                                     if (!orderService.insert(order)) {
-                                        callApiLogSave(erpDetTb, "erp_det_tb", "璁㈠崟涓绘。娣诲姞澶辫触锛侊紒", false);
+                                        callApiLogSave(erpDetTb, "ERP_DETTB", "璁㈠崟涓绘。娣诲姞澶辫触锛侊紒", false);
                                         continue;
                                     } else {
-                                        callApiLogSave(erpDetTb, "erp_det_tb", "璁㈠崟涓绘。娣诲姞鎴愬姛锛侊紒", true);
+                                        callApiLogSave(erpDetTb, "ERP_DETTB", "璁㈠崟涓绘。娣诲姞鎴愬姛锛侊紒", true);
                                     }
                                 }
                             }
-                            Order order1 = orderService.selectByNo(erpDetTb.getBillNo());
+                            Order order1 = orderService.selectByNo(erpDetTb.getBillNo()+"---"+erpDetTb.getItm());
                             if (!Cools.isEmpty(order1)) {
-                                OrderDetl orderDetl = orderDetlService.selectItem(order1.getId(), erpDetTb.getBillNo(), erpDetTb.getPrdMark());
+//                                OrderDetl orderDetl = orderDetlService.selectItem(order1.getId(), erpDetTb.getBillNo(), erpDetTb.getPrdMark());
+                                OrderDetl orderDetl = orderDetlService.selectOne(new EntityWrapper<OrderDetl>().eq("order_no",erpDetTb.getBillNo()+"---"+erpDetTb.getItm()).eq("matnr",erpDetTb.getPrdNo()));
                                 if (Cools.isEmpty(orderDetl)) {
                                     orderDetl = new OrderDetl();
                                     orderDetl.setOrderId(order1.getId());
-                                    orderDetl.setOrderNo(erpDetTb.getBillNo());
+                                    orderDetl.setOrderNo(erpDetTb.getBillNo()+"---"+erpDetTb.getItm());
                                     orderDetl.setAnfme(erpDetTb.getQty());
                                     orderDetl.setQty(0.0D);
                                     orderDetl.setMatnr(erpDetTb.getPrdNo());
@@ -137,6 +143,7 @@
                                     orderDetl.setBatch(erpDetTb.getPrdMark());
                                     orderDetl.setSpecs(mat.getSpecs());
                                     orderDetl.setUnit(mat.getUnit());
+                                    orderDetl.setOrigin(erpDetTb.getItm().toString());
 
                                     orderDetl.setStatus(1);
                                     orderDetl.setCreateBy(9999L);
@@ -146,10 +153,39 @@
                                     orderDetl.setMemo(erpDetTb.getWh());
                                     if (orderDetlService.insert(orderDetl)) {
                                         erpSqlServer.update(sqlUpDateErpDetTbOne + "'" + erpDetTb.getPrdNo() + "'");
-                                        callApiLogSave(erpDetTb, "erp_det_tb", "鎺ユ敹ERP涓嬪彂璁㈠崟鎺ユ敹鎴愬姛锛侊紒", true);
+                                        callApiLogSave(erpDetTb, "ERP_DETTB", "鎺ユ敹ERP涓嬪彂璁㈠崟鎺ユ敹鎴愬姛锛侊紒", true);
                                     } else {
-                                        erpSqlServer.update(sqlUpDateErpDetTbTwo + ",temp1='娣诲姞璁㈠崟鏄庣粏妗eけ璐ワ紒锛侊紒'" + "where 1=1 and prd_no=" + "'" + erpDetTb.getPrdNo() + "'");
-                                        callApiLogSave(erpDetTb, "erp_det_tb", "ERP涓嬪彂璁㈠崟鎺ユ敹澶辫触锛侊紒", false);
+                                        if (Cools.isEmpty(erpDetTb.getTemp2())){
+                                            erpSqlServer.update(sqlUpDateErpDetTbTwo + ",temp2='娣诲姞璁㈠崟鏄庣粏妗eけ璐ワ紒锛侊紒'" + "where 1=1 "
+                                                    +" and PRD_NO=" + "'" + erpDetTb.getPrdNo() + "'"
+                                                    +" and ITM=" + "'" + erpDetTb.getItm() + "'"
+                                                    +" and BIL_NO=" + "'" + erpDetTb.getBillNo() + "'");
+                                            callApiLogSave(erpDetTb, "ERP_DETTB", "ERP涓嬪彂璁㈠崟鎺ユ敹澶辫触锛侊紒", false);
+                                        }
+                                    }
+                                }else if (!erpDetTb.getItm().toString().equals(orderDetl.getOrigin())){
+                                    orderDetl.setAnfme(orderDetl.getAnfme()+erpDetTb.getQty());
+                                    EntityWrapper<OrderDetl> wrapper = new EntityWrapper<>();
+                                    wrapper.eq("id", orderDetl.getId());
+                                    if (orderDetlService.update(orderDetl,wrapper)) {
+                                        erpSqlServer.update(sqlUpDateErpDetTbOne + "'" + erpDetTb.getPrdNo() + "'");
+                                        callApiLogSave(erpDetTb, "ERP_DETTB", "鎺ユ敹ERP涓嬪彂璁㈠崟鎺ユ敹鎴愬姛锛侊紒", true);
+                                    } else {
+                                        if (Cools.isEmpty(erpDetTb.getTemp2())){
+                                            erpSqlServer.update(sqlUpDateErpDetTbTwo + ",temp2='鏇存柊璁㈠崟鏄庣粏妗eけ璐ワ紒锛侊紒'" + "where 1=1 "
+                                                    +" and PRD_NO=" + "'" + erpDetTb.getPrdNo() + "'"
+                                                    +" and ITM=" + "'" + erpDetTb.getItm() + "'"
+                                                    +" and BIL_NO=" + "'" + erpDetTb.getBillNo() + "'");
+                                            callApiLogSave(erpDetTb, "ERP_DETTB", "ERP涓嬪彂璁㈠崟鎺ユ敹澶辫触锛侊紒", false);
+                                        }
+                                    }
+                                }else {
+                                    if (Cools.isEmpty(erpDetTb.getTemp3())){
+                                        erpSqlServer.update(sqlUpDateErpDetTbTwo + ",temp3='鏇存柊璁㈠崟鏄庣粏妗eけ璐ワ紒锛侊紒璁㈠崟鏄庣粏宸插瓨鍦紒锛�'" + "where 1=1 "
+                                                +" and PRD_NO=" + "'" + erpDetTb.getPrdNo() + "'"
+                                                +" and ITM=" + "'" + erpDetTb.getItm() + "'"
+                                                +" and BIL_NO=" + "'" + erpDetTb.getBillNo() + "'");
+                                        callApiLogSave(erpDetTb, "ERP_DETTB", "ERP涓嬪彂璁㈠崟鎺ユ敹澶辫触锛侊紒", false);
                                     }
                                 }
                             }
@@ -157,38 +193,45 @@
                     } else if (status == 1) {
                         String format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(now);
                         HashMap<String, Object> condition = new HashMap<>();
-                        condition.put("bill_no", "'" + erpDetTb.getBillNo() + "'");
-                        condition.put("prd_no", "'" + erpDetTb.getPrdNo() + "'");
-                        condition.put("iokindid", "'" + erpDetTb.getIokindid() + "'");
-                        condition.put("add_id", "'" + erpDetTb.getAddId() + "'");
-                        condition.put("qty", "'" + erpDetTb.getQty() + "'");
-                        condition.put("prd_mark", "'" + erpDetTb.getPrdMark() + "'");
-                        condition.put("wh", "'" + erpDetTb.getWh() + "'");
-                        condition.put("billdate", "'" + format + "'");
-                        condition.put("status", "'" + erpDetTb.getStatus() + "'");
-                        condition.put("temp1", "'" + erpDetTb.getTemp1() + "'");
-                        condition.put("temp2", "'" + erpDetTb.getTemp2() + "'");
-                        condition.put("temp3", "'" + erpDetTb.getTemp3() + "'");
+                        condition.put("BIL_NO", "'" + erpDetTb.getBillNo() + "'");
+                        condition.put("PRD_NO", "'" + erpDetTb.getPrdNo() + "'");
+                        condition.put("ITM", "'" + erpDetTb.getItm() + "'");
+                        condition.put("ADD_ID", "'" + erpDetTb.getAddId2() + "'");
+                        condition.put("QTY", "'" + erpDetTb.getQty() + "'");
+                        condition.put("PRD_MARK", "'" + erpDetTb.getPrdMark() + "'");
+                        condition.put("WH", "'" + erpDetTb.getWh() + "'");
+                        condition.put("BIL_DATE", "'" + format + "'");
+                        condition.put("STATUS", "'" + erpDetTb.getStatus() + "'");
+                        condition.put("Temp1", "'" + erpDetTb.getTemp1() + "'");
+                        condition.put("Temp2", "'" + erpDetTb.getTemp2() + "'");
+                        condition.put("Temp3", "'" + erpDetTb.getTemp3() + "'");
                         erpSqlServer.insert(ErpDetTbBak.class, condition);
 
-//                        callApiLogSave(erpDetTb, "erp_det_tb_bak", "ERP涓嬪彂璁㈠崟澶囦唤鎴愬姛锛侊紒", true);
+//                        callApiLogSave(erpDetTb, "ERP_DETTB_BAK", "ERP涓嬪彂璁㈠崟澶囦唤鎴愬姛锛侊紒", true);
 
                         HashMap<String, String> condition2 = new HashMap<>();
-                        condition2.put("bill_no", "'" + erpDetTb.getBillNo() + "'");
-                        condition2.put("prd_no", "'" + erpDetTb.getPrdNo() + "'");
-                        condition2.put("prd_mark", "'" + erpDetTb.getPrdMark() + "'");
+                        condition2.put("BIL_NO", "'" + erpDetTb.getBillNo() + "'");
+                        condition2.put("PRD_NO", "'" + erpDetTb.getPrdNo() + "'");
+                        condition2.put("ITM", "'" + erpDetTb.getItm() + "'");
+//                        condition2.put("PRD_MARK", "'" + erpDetTb.getPrdMark() + "'");
                         erpSqlServer.delete(ErpDetTb.class, condition2);
 
-//                        callApiLogSave(erpDetTb, "erp_det_tb", "ERP涓嬪彂璁㈠崟澶囦唤鍚庡垹闄ゆ垚鍔燂紒锛�", true);
+//                        callApiLogSave(erpDetTb, "ERP_DETTB", "ERP涓嬪彂璁㈠崟澶囦唤鍚庡垹闄ゆ垚鍔燂紒锛�", true);
 
                     } else {
-                        callApiLogSave(erpDetTb, "erp_det_tb", "鎺ユ敹ERP涓嬪彂璁㈠崟澶辫触锛侊紒锛佺姸鎬佸紓甯革紒锛侊紒", false);
+                        if (Cools.isEmpty(erpDetTb.getTemp1()) && Cools.isEmpty(erpDetTb.getTemp2()) && Cools.isEmpty(erpDetTb.getTemp3())){
+                            erpSqlServer.update(sqlUpDateErpDetTbTwo + ",Temp1='鎺ユ敹ERP涓嬪彂璁㈠崟澶辫触锛侊紒锛佺姸鎬佸紓甯革紒锛侊紒璇稥RP銆佺珛搴撳弻鏂瑰崗鍔╄В鍐炽��'" + "where 1=1 "
+                                    +" and PRD_NO=" + "'" + erpDetTb.getPrdNo() + "'"
+                                    +" and ITM=" + "'" + erpDetTb.getItm() + "'"
+                                    +" and BIL_NO=" + "'" + erpDetTb.getBillNo() + "'");
+                            callApiLogSave(erpDetTb, "ERP_DETTB", "鎺ユ敹ERP涓嬪彂璁㈠崟澶辫触锛侊紒锛佺姸鎬佸紓甯革紒锛侊紒", false);
+                        }
                     }
                 }
             }
         } catch (Exception e) {
             Date date = new Date();
-            log.error(date + ": 琛ㄥ悕锛歟rp_det_tb :" + e);
+            log.error(date + ": 琛ㄥ悕锛欵RP_DETTB :" + e);
         }
     }
 

--
Gitblit v1.9.1