Просмотр исходного кода

发货计划订单信息刷新测试(新接口)

hxh 1 неделя назад
Родитель
Сommit
227bb01f81

+ 4 - 0
src/custom/restcontroller/R.java

@@ -7008,6 +7008,10 @@ public class R {
         public static class v1 {
         }
     }
+    public static class ID2025122609083103 {
+        public static class v1 {
+        }
+    }
 
 }
 

+ 126 - 14
src/custom/restcontroller/webmanage/sale/sendplan/sendplandetail.java

@@ -20,6 +20,119 @@ public class sendplandetail extends Controller {
         super(content);
     }
 
+    @API(title = "订单信息刷新(新)", apiversion = R.ID2025122609083103.v1.class)
+    public String orderRefresh_newtest() throws YosException {
+        long sa_sendplanid = content.getLongValue("sa_sendplanid");
+        Rows sendplanRows = dbConnect.runSqlQuery("select * from sa_sendplan where sa_sendplanid='" + sa_sendplanid + "' and siteid='" + siteid + "'");
+        if (sendplanRows.isEmpty()) {
+            return getErrReturnObject().setErrMsg("发货计划不存在,无法进行订单信息刷新").toString();
+        }
+        dbConnect.runSqlUpdate("delete from sa_sendplandetail where sa_sendplanid='" + sa_sendplanid + "' and siteid='" + siteid + "'");
+        /*
+          过滤条件设置
+         */
+        StringBuffer where = new StringBuffer(" 1=1 and t1.undeliqty>0 and t3.type='" + sendplanRows.get(0).getString("type")
+                + "' and  DATE_FORMAT(t3.checkdate, '%Y-%m-%d') >='" + sendplanRows.get(0).getString("begindate")
+                + "' and  DATE_FORMAT(t3.checkdate, '%Y-%m-%d') <='" + sendplanRows.get(0).getString("enddate")
+                + "' and ( \n" +
+                "\t\t(t3.type in('标准订单','网销订单')) or\n" +
+                "\t\t(\n" +
+                "\t\t\tt3.type='配件订单'\n" +
+                "\t\t\tand t3.sys_enterpriseid in (\n" +
+                "\t\t\tselect distinct sys_enterpriseid from st_stockbill \n" +
+                "\t\t\twhere type='销售出库'  and status='审核' and \n" +
+                "\t\t\tbilldate= '" + sendplanRows.get(0).getString("senddate") + "'\n" +
+                "\t\t\t)\n" +
+                "\t\t))");
+
+        SQLFactory sqlFactory = new SQLFactory(this, "发货计划订单未发货量(新)");
+        sqlFactory.addParameter_SQL("where", where);
+        sqlFactory.addParameter("siteid", siteid);
+        Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL());
+
+        Rows stockbillrows = dbConnect.runSqlQuery("select t2.itemid,sum(t2.undeliqty) qty from sa_order t1 " +
+                " inner join sa_orderitems t2 on t1.sa_orderid=t2.sa_orderid " +
+                " where t1.status='审核' and t2.isclose=0 and t2.undeliqty>0 and t1.siteid='" + siteid + "' " +
+                " group by t2.itemid ");
+        Rows invbalSalerows = dbConnect.runSqlQuery("select itemid,qty from st_invbal_sale");
+
+        RowsMap stockbillrowsMap = stockbillrows.toRowsMap("itemid");
+        RowsMap invbalSalerowsMap = invbalSalerows.toRowsMap("itemid");
+
+        ArrayList<String> list = new ArrayList<>();
+
+        long oldItemid= 0;
+        BigDecimal oldWilloutqty = BigDecimal.ZERO;
+        BigDecimal oldCanuseqty = BigDecimal.ZERO;
+        BigDecimal oldSendqty = BigDecimal.ZERO;
+        long[] sendplandetailids = createTableID("sa_sendplandetail", rows.size());
+        int i=0;
+        for (Row row :rows) {
+            InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sa_sendplandetail");
+            insertSQL.setUniqueid(sendplandetailids[i++]);
+            insertSQL.setSiteid(siteid);
+            insertSQL.setValue("sa_sendplanid", sa_sendplanid);
+            insertSQL.setValue("sa_orderid", row.getLong("sa_orderid"));
+            insertSQL.setValue("sa_orderitemsid", row.getLong("sa_orderitemsid"));
+            insertSQL.setValue("outplace", row.getString("outplace"));
+            insertSQL.setValue("sa_agentsid", row.getString("sa_agentsid"));
+            BigDecimal willoutqty = BigDecimal.ZERO;
+            BigDecimal invbalqty = BigDecimal.ZERO;
+            if (stockbillrowsMap.containsKey(row.getString("itemid"))) {
+                willoutqty = stockbillrowsMap.get(row.getString("itemid")).get(0).getBigDecimal("qty");
+            }
+            if (invbalSalerowsMap.containsKey(row.getString("itemid"))) {
+                // 查询库存总量
+                invbalqty = invbalSalerowsMap.get(row.getString("itemid")).get(0).getBigDecimal("qty");
+            }
+            insertSQL.setValue("willinqty", willoutqty);
+            insertSQL.setValue("sendqty", getBigDecimalOrZero(row.getBigDecimal("sendqty")));
+
+
+            long currentitemid = row.getLong("itemid");
+
+            if (oldItemid == 0 || oldItemid!=currentitemid) {
+                // 新物料
+                oldWilloutqty =willoutqty;
+
+                oldCanuseqty = invbalqty.subtract(oldWilloutqty);
+            } else {
+                // 相同物料
+                oldCanuseqty = oldCanuseqty.subtract(oldSendqty);
+                oldWilloutqty = oldWilloutqty.add(oldSendqty);
+            }
+
+            // 设置计算后的值
+            insertSQL.setValue("canuseqty",oldCanuseqty);
+            insertSQL.setValue("willinqty",oldWilloutqty);
+
+
+            // 如果可用量<=0,设置发货量为0
+            if (oldCanuseqty.compareTo(BigDecimal.ZERO) <= 0) {
+                insertSQL.setValue("sendqty",BigDecimal.ZERO);
+                insertSQL.setValue("colorflag", 0);
+            }else{
+                if (oldCanuseqty.compareTo(row.getBigDecimal("sendqty")) >= 0) {
+                    insertSQL.setValue("colorflag", 2);
+                } else {
+                    insertSQL.setValue("colorflag", 3);
+                }
+            }
+
+            // 保存当前值供下次循环使用
+            oldItemid = currentitemid;
+            oldSendqty = getBigDecimalOrZero(row.getBigDecimal("sendqty")).compareTo(BigDecimal.ZERO)>0?getBigDecimalOrZero(row.getBigDecimal("sendqty")):BigDecimal.ZERO;
+            list.add(insertSQL.getSQL());
+        }
+        dbConnect.runSqlUpdate(list);
+        list = new ArrayList<>();
+        Rows rows1 = dbConnect.runSqlQuery("select t1.sa_orderid from (select sa_orderid,count(0)count from sa_sendplandetail where sa_sendplanid=" + sa_sendplanid + " group by sa_orderid) t1 inner join (select sa_orderid,count(0)count from sa_sendplandetail where colorflag='2' and  sa_sendplanid=" + sa_sendplanid + "  group by sa_orderid) t2 on  t1.sa_orderid=t2.sa_orderid and t1.count=t2.count");
+        for (Row row : rows1) {
+            list.add("update sa_sendplandetail set colorflag=1 where sa_sendplanid=" + sa_sendplanid + " and sa_orderid =" + row.getLong("sa_orderid"));
+        }
+        return getSucReturnObject().toString();
+    }
+
     //ID2025120110193103
     @API(title = "订单信息刷新(新)", apiversion = R.ID2025120110193103.v1.class)
     public String orderRefresh_new() throws YosException {
@@ -63,6 +176,7 @@ public class sendplandetail extends Controller {
         ArrayList<String> list = new ArrayList<>();
         long olditemid = 0;
         BigDecimal oldcanuseqty = BigDecimal.ZERO;
+        BigDecimal oldwilloutqty = BigDecimal.ZERO;
         BigDecimal oldsendqty = BigDecimal.ZERO;
         long[] sendplandetailids = createTableID("sa_sendplandetail", rows.size());
         int i = 0;
@@ -89,31 +203,27 @@ public class sendplandetail extends Controller {
             }
             canuseqty = invbalqty.subtract(willoutqty);
 
-            insertSQL.setValue("willoutqty", willoutqty);
+
             insertSQL.setValue("willinqty", 0);
             insertSQL.setValue("canuseqty", canuseqty);
-            if(row.getLong("itemid")==3853){
-                logger.info("监测到canuseqty1", canuseqty);
-            }
+
+
 
             if (row.getLong("itemid") == olditemid) {
+                insertSQL.setValue("willoutqty", (oldwilloutqty.compareTo(BigDecimal.ZERO) == 0 ? willoutqty : oldwilloutqty).add(oldsendqty));
                 insertSQL.setValue("canuseqty", (oldcanuseqty.compareTo(BigDecimal.ZERO) == 0 ? canuseqty : oldcanuseqty).subtract(oldsendqty));
-                if(row.getLong("itemid")==3853){
-                    logger.info("监测到canuseqty2", (oldcanuseqty.compareTo(BigDecimal.ZERO) == 0 ? canuseqty : oldcanuseqty).subtract(oldsendqty));
-
-                }
                 newcanuseqty=(oldcanuseqty.compareTo(BigDecimal.ZERO) == 0 ? canuseqty : oldcanuseqty).subtract(oldsendqty);
-                oldcanuseqty = (oldcanuseqty.compareTo(BigDecimal.ZERO) == 0 ? canuseqty : oldcanuseqty).subtract(oldsendqty);
+                oldcanuseqty=(oldcanuseqty.compareTo(BigDecimal.ZERO) == 0 ? canuseqty : oldcanuseqty).subtract(oldsendqty);
+
             } else {
-                if(row.getLong("itemid")==3853){
-                    System.err.println("监测到canuseqty3:"+canuseqty);
-                }
+                insertSQL.setValue("willoutqty", willoutqty);
                 insertSQL.setValue("canuseqty", canuseqty);
                 newcanuseqty=canuseqty;
             }
 
             if (newcanuseqty.compareTo(BigDecimal.ZERO) <= 0) {
-                insertSQL.setValue("sendqty", 0);
+                sendqty=BigDecimal.ZERO;
+                insertSQL.setValue("sendqty", sendqty);
                 insertSQL.setValue("colorflag", 0);
             } else {
                 sendqty = row.getBigDecimal("sendqty");
@@ -612,5 +722,7 @@ public class sendplandetail extends Controller {
 
         return result.toString();
     }
-
+    private BigDecimal getBigDecimalOrZero(BigDecimal value) {
+        return value != null ? value : BigDecimal.ZERO;
+    }
 }