Browse Source

订单定制费用调整

eganwu 1 year ago
parent
commit
139164dd1d

+ 98 - 76
src/custom/function/OrderFeeCalculatePlan1.java

@@ -46,112 +46,134 @@ public class OrderFeeCalculatePlan1 extends DataFunction {
         //判断当前订单类型是否满足方案
         Row orderRow = Order.getOrderRows(controller, sa_orderid).get(0);
         String type = orderRow.getString("type");
-        if (!ordertype.contains(type)) {
-            return super.action();
-        }
-        //查询订单商品和方案
-        Rows itemRows = queryDataFunction(controller, sa_orderid, this.getClass().getSimpleName());
-        if (itemRows.isEmpty()) {
-            return super.action();
-        }
-        BigDecimal bdUnitfee = new BigDecimal(unitfee);
-        BigDecimal bdValue = new BigDecimal(value);
-        ArrayList<String> sqlList = new ArrayList<>();
-
         //清空费用表
         DeleteSQL deleteSQL = SQLFactory.createDeleteSQL(controller, "sa_order_cost");
         deleteSQL.setWhere("sa_orderid", sa_orderid);
-        deleteSQL.setWhere("sa_orderitemsid", itemRows.toArray("sa_orderitemsid"));
         deleteSQL.delete();
 
+        RowsMap itemRowsMap = queryDataFunction(controller, sa_orderid, this.getClass().getSimpleName()).toRowsMap("sys_datafunctionid");
+        //查询订单商品和方案
 
-        //组合内计算(分摊)
-        if (iscombination.equals("1")) {
-            //分摊总金额
-            BigDecimal totalprice = new BigDecimal(0);
-            //订货数量
-            BigDecimal qty = new BigDecimal(0);
-            //订货重量
-            BigDecimal weight = new BigDecimal(0);
-            //订货金额
-            BigDecimal amount = new BigDecimal(0);
-            for (Row row : itemRows) {
-                qty = qty.add(row.getBigDecimal("qty"));
-                amount = amount.add(row.getBigDecimal("amount"));
-                weight = weight.add(row.getBigDecimal("weight"));
+        Rows dfRows = dbConnect.runSqlQuery("select sys_datafunctionid from sys_datafunction WHERE classname='OrderFeeCalculatePlan1' and status='启用' ");
+        for (Row dfRow : dfRows) {
+            String sys_datafunctionid = dfRow.getString("sys_datafunctionid");
+            Rows itemRows = itemRowsMap.getOrDefault(sys_datafunctionid, new Rows());
+            if (itemRows.isEmpty()) {
+                return super.action();
             }
-            if (itemfield.equals("1")) {
-                totalprice = getTotalprice(bdValue, bdUnitfee, qty);
-            }
-            if (itemfield.equals("2")) {
-                totalprice = getTotalprice(bdValue, bdUnitfee, weight);
-            }
-            if (itemfield.equals("3")) {
-                totalprice = getTotalprice(bdValue, bdUnitfee, amount);
-            }
-            //分摊方式,订货数量
-            if (apportiontype.equals("1")) {
-                for (Row row : itemRows) {
-                    BigDecimal itemqty = row.getBigDecimal("qty");
-                    if (qty.compareTo(BigDecimal.ZERO) > 0) {
-                        BigDecimal price_apportion = totalprice.multiply(itemqty).divide(qty, 2, BigDecimal.ROUND_HALF_UP);
-                        sqlList.add(getInsertSQL(row, price_apportion).getSQL());
-                    } else {
-                        sqlList.add(getInsertSQL(row, BigDecimal.ZERO).getSQL());
-                    }
-                }
-
-
+            Rows paramsRows = dbConnect.runSqlQuery("SELECT * from sys_datafunction_params WHERE sys_datafunctionid=" + sys_datafunctionid);
+            if (paramsRows.isNotEmpty()) {
+                return super.action();
             }
-            //分摊方式,订货金额
-            if (apportiontype.equals("2")) {
-                for (Row row : itemRows) {
-                    BigDecimal itemamount = row.getBigDecimal("amount");
-                    if (amount.compareTo(BigDecimal.ZERO) > 0) {
-                        BigDecimal price_apportion = totalprice.multiply(itemamount).divide(amount, 2, BigDecimal.ROUND_HALF_UP);
-                        sqlList.add(getInsertSQL(row, price_apportion).getSQL());
-                    } else {
-                        sqlList.add(getInsertSQL(row, BigDecimal.ZERO).getSQL());
-                    }
-                }
+            RowsMap paramsRowsMap = paramsRows.toRowsMap("param");
+            String ordertype = paramsRowsMap.get("ordertype").get(0).getString("value");
+            BigDecimal unitfee = paramsRowsMap.get("unitfee").get(0).getBigDecimal("value");
+            BigDecimal value = paramsRowsMap.get("value").get(0).getBigDecimal("value");
+            String iscombination = paramsRowsMap.get("iscombination").get(0).getString("value");
+            String itemfield = paramsRowsMap.get("itemfield").get(0).getString("value");
+            String apportiontype = paramsRowsMap.get("apportiontype").get(0).getString("value");
+            String condition = paramsRowsMap.get("condition").get(0).getString("value");
+            String isaccumulation = paramsRowsMap.get("isaccumulation").get(0).getString("value");
+
+
+            if (!ordertype.contains(type)) {
+                return super.action();
             }
-            dbConnect.runSqlUpdate(sqlList);
-            //调整最后一行数据
-            adjustLastData(itemRows, totalprice);
 
-        }
+            BigDecimal bdUnitfee = unitfee;
+            BigDecimal bdValue = value;
+            ArrayList<String> sqlList = new ArrayList<>();
 
 
-        //不组合内计算(不分摊)
-        if (iscombination.equals("0")) {
-            for (Row row : itemRows) {
+            //组合内计算(分摊)
+            if (iscombination.equals("1")) {
                 //分摊总金额
                 BigDecimal totalprice = new BigDecimal(0);
                 //订货数量
-                BigDecimal qty = row.getBigDecimal("qty");
+                BigDecimal qty = new BigDecimal(0);
                 //订货重量
-                BigDecimal weight = row.getBigDecimal("weight");
+                BigDecimal weight = new BigDecimal(0);
                 //订货金额
-                BigDecimal amount = row.getBigDecimal("amount");
+                BigDecimal amount = new BigDecimal(0);
+                for (Row row : itemRows) {
+                    qty = qty.add(row.getBigDecimal("qty"));
+                    amount = amount.add(row.getBigDecimal("amount"));
+                    weight = weight.add(row.getBigDecimal("weight"));
+                }
                 if (itemfield.equals("1")) {
-                    totalprice = getTotalprice(bdValue, bdUnitfee, qty);
+                    totalprice = getTotalprice(bdValue, bdUnitfee, qty, condition, isaccumulation);
                 }
                 if (itemfield.equals("2")) {
-                    totalprice = getTotalprice(bdValue, bdUnitfee, weight);
+                    totalprice = getTotalprice(bdValue, bdUnitfee, weight, condition, isaccumulation);
                 }
                 if (itemfield.equals("3")) {
-                    totalprice = getTotalprice(bdValue, bdUnitfee, amount);
+                    totalprice = getTotalprice(bdValue, bdUnitfee, amount, condition, isaccumulation);
+                }
+                //分摊方式,订货数量
+                if (apportiontype.equals("1")) {
+                    for (Row row : itemRows) {
+                        BigDecimal itemqty = row.getBigDecimal("qty");
+                        if (qty.compareTo(BigDecimal.ZERO) > 0) {
+                            BigDecimal price_apportion = totalprice.multiply(itemqty).divide(qty, 2, BigDecimal.ROUND_HALF_UP);
+                            sqlList.add(getInsertSQL(row, price_apportion).getSQL());
+                        } else {
+                            sqlList.add(getInsertSQL(row, BigDecimal.ZERO).getSQL());
+                        }
+                    }
+
+
                 }
-                sqlList.add(getInsertSQL(row, totalprice).getSQL());
+                //分摊方式,订货金额
+                if (apportiontype.equals("2")) {
+                    for (Row row : itemRows) {
+                        BigDecimal itemamount = row.getBigDecimal("amount");
+                        if (amount.compareTo(BigDecimal.ZERO) > 0) {
+                            BigDecimal price_apportion = totalprice.multiply(itemamount).divide(amount, 2, BigDecimal.ROUND_HALF_UP);
+                            sqlList.add(getInsertSQL(row, price_apportion).getSQL());
+                        } else {
+                            sqlList.add(getInsertSQL(row, BigDecimal.ZERO).getSQL());
+                        }
+                    }
+                }
+                dbConnect.runSqlUpdate(sqlList);
+                //调整最后一行数据
+                adjustLastData(itemRows, totalprice);
+
             }
-            dbConnect.runSqlUpdate(sqlList);
+
+
+            //不组合内计算(不分摊)
+            if (iscombination.equals("0")) {
+                for (Row row : itemRows) {
+                    //分摊总金额
+                    BigDecimal totalprice = new BigDecimal(0);
+                    //订货数量
+                    BigDecimal qty = row.getBigDecimal("qty");
+                    //订货重量
+                    BigDecimal weight = row.getBigDecimal("weight");
+                    //订货金额
+                    BigDecimal amount = row.getBigDecimal("amount");
+                    if (itemfield.equals("1")) {
+                        totalprice = getTotalprice(bdValue, bdUnitfee, qty, condition, isaccumulation);
+                    }
+                    if (itemfield.equals("2")) {
+                        totalprice = getTotalprice(bdValue, bdUnitfee, weight, condition, isaccumulation);
+                    }
+                    if (itemfield.equals("3")) {
+                        totalprice = getTotalprice(bdValue, bdUnitfee, amount, condition, isaccumulation);
+                    }
+                    sqlList.add(getInsertSQL(row, totalprice).getSQL());
+                }
+                dbConnect.runSqlUpdate(sqlList);
+            }
+
         }
 
 
         return super.action();
     }
 
-    public BigDecimal getTotalprice(BigDecimal bdValue, BigDecimal bdUnitfee, BigDecimal itemFieldValue) {
+    public BigDecimal getTotalprice(BigDecimal bdValue, BigDecimal bdUnitfee, BigDecimal itemFieldValue, String condition, String isaccumulation) {
         if (itemFieldValue.compareTo(bdValue) <= 0
                 && (condition.equals("1") || condition.equals("2") || condition.equals("3") || condition.equals("4"))) {
             return bdUnitfee;

+ 1 - 1
src/custom/restcontroller/webmanage/sale/order/OrderItems.java

@@ -188,7 +188,7 @@ public class OrderItems extends Controller {
         Rows rows = dbConnect.runSqlQuery(sqlFactory);
         if (rows.isNotEmpty()) {
             String remarks = StringUtils.join(rows.toArray("remarks"), ";");
-            dbConnect.runSqlUpdate("UPDATE sa_order set remarks ='" + remarks + "' WHERE sa_orderid='" + sa_orderid + "'");
+            dbConnect.runSqlUpdate("UPDATE sa_order set abstract ='" + remarks + "' WHERE sa_orderid='" + sa_orderid + "'");
 
         }
 

+ 1 - 1
src/custom/restcontroller/webmanage/sale/order/SQL/查询定制费用统计.sql

@@ -1,5 +1,5 @@
 SELECT t2.functionname, CONCAT(t2.remarks, ':', sum(costamount)) remarks
 from sa_order_cost t1
          inner join sys_datafunction t2 ON t2.sys_datafunctionid = t1.sys_datafunctionid
-WHERE t1.sa_orderid = $sa_orderid$
+WHERE t1.sa_orderid = $sa_orderid$ and costamount>0
 GROUP by t2.functionname, t2.remarks