郭齐峰 2 anni fa
parent
commit
ddb20b4536

+ 30 - 31
src/custom/restcontroller/sale/aftersalesmag/aftersalesmag.java

@@ -73,21 +73,21 @@ public class aftersalesmag extends Controller {
 
         sqlFactory.addParameter_SQL("where", where);
         Rows rows = dbConnect.runSqlQuery(sqlFactory);
-        
+
         ArrayList<Long> ids = rows.toArrayList("sa_aftersalesmagid", new ArrayList<>());
         //查询反退金额
         RowsMap aftersalesmagReturnAmountRowsMap = Aftersalesmag.getAftersalesmagReturnAmount(this, ids);
-        if(!rows.isEmpty()) {
-        	  for (Row row : rows) {
-
-        	       	 Long id = row.getLong("sa_aftersalesmagid");
-        	            if (aftersalesmagReturnAmountRowsMap.get(id.toString()).isNotEmpty()) {
-        	                   row.put("returnamount", aftersalesmagReturnAmountRowsMap.get(id.toString()).get(0).getBigDecimal("returnamount").toPlainString());
-        	               } else {
-        	                   row.put("returnamount", 0);
-        	               }
-        	       
-        			}
+        if (!rows.isEmpty()) {
+            for (Row row : rows) {
+
+                Long id = row.getLong("sa_aftersalesmagid");
+                if (aftersalesmagReturnAmountRowsMap.get(id.toString()).isNotEmpty()) {
+                    row.put("returnamount", aftersalesmagReturnAmountRowsMap.get(id.toString()).get(0).getBigDecimal("returnamount").toPlainString());
+                } else {
+                    row.put("returnamount", 0);
+                }
+
+            }
         }
         return getSucReturnObject().setData(rows).toString();
     }
@@ -96,16 +96,13 @@ public class aftersalesmag extends Controller {
     @CACHEING_CLEAN(apiversions = {R.ID20230104160603.v1.class, R.ID20230104160703.v1.class, R.ID20230105110903.class, R.ID20230105161503.v1.class})
     public String sumbit() throws YosException {
         Long sa_aftersalesmagid = content.getLong("sa_aftersalesmagid");
-        Long sa_orderid = 0L;
-        Long sys_enterpriseid = 0L;
+
         Rows rows = dbConnect.runSqlQuery(
                 "select sa_aftersalesmagid,status,billno,sa_orderid,sys_enterpriseid,type from sa_aftersalesmag where sa_aftersalesmagid ='"
                         + sa_aftersalesmagid + "' and  siteid='" + siteid + "'");
         if (rows.isEmpty()) {
             return getErrReturnObject().setErrMsg("该返退单不存在").toString();
         } else {
-            sa_orderid = rows.get(0).getLong("sa_orderid");
-            sys_enterpriseid = rows.get(0).getLong("sys_enterpriseid");
             if (!rows.get(0).getString("status").equals("新建")) {
                 return getErrReturnObject().setErrMsg("单号为:【" + rows.get(0).getString("billno") + "】的返退单为非新建状态,无法提交")
                         .toString();
@@ -116,16 +113,20 @@ public class aftersalesmag extends Controller {
                         + sa_aftersalesmagid + "' and  siteid='" + siteid + "'").isEmpty()) {
             return getErrReturnObject().setErrMsg("返退明细为空不可提交").toString();
         }
-        Rows rowsOrderDetail = dbConnect.runSqlQuery("select t1.undeliqty,t1.deliedqty,t1.qty,t1.returnqty,t1.sa_orderitemsid from sa_orderitems t1 where t1.sa_orderid=" + sa_orderid);
+
+        Long sa_orderid = rows.get(0).getLong("sa_orderid");
+//        Long sys_enterpriseid = rows.get(0).getLong("sys_enterpriseid");
+
+        Rows rowsOrderDetail = dbConnect.runSqlQuery("select t1.undeliqty,t1.deliedqty,t1.qty,t1.returnqty,t1.sa_orderitemsid from sa_orderitems t1 where t1.siteid='" + siteid + "' and t1.sa_orderid=" + sa_orderid);
         RowsMap rowsMap = rowsOrderDetail.toRowsMap("sa_orderitemsid");
-        Rows sa_aftersalesmag_itemsRows = dbConnect.runSqlQuery("select t1.qty,t1.sa_orderitemsid,t2.itemno,t2.itemname,t2.skucontrol from sa_aftersalesmag_items t1 left join plm_item t2 on t1.itemid=t2.itemid and t1.siteid=t2.siteid  where t1.sa_aftersalesmagid=" + sa_aftersalesmagid);
+        Rows sa_aftersalesmag_itemsRows = dbConnect.runSqlQuery("select t1.qty,t1.sa_orderitemsid,t2.itemno,t2.itemname,t2.skucontrol from sa_aftersalesmag_items t1 left join plm_item t2 on t1.itemid=t2.itemid and t1.siteid=t2.siteid  where t1.siteid='" + siteid + "' and t1.sa_aftersalesmagid=" + sa_aftersalesmagid);
         for (Row row : sa_aftersalesmag_itemsRows) {
             Rows orderitemsRows = rowsMap.get(row.getString("sa_orderitemsid"));
             if (orderitemsRows.isEmpty()) {
                 //return getErrReturnObject().setErrMsg("对应的订单行不存在").toString();
-            }else{
-                if(rows.get(0).getString("type").equals("退货单")){
-                    BigDecimal returnqty =orderitemsRows.get(0).getBigDecimal("returnqty");
+            } else {
+                if (rows.get(0).getString("type").equals("退货单")) {
+                    BigDecimal returnqty = orderitemsRows.get(0).getBigDecimal("returnqty");
                     BigDecimal qty = orderitemsRows.get(0).getBigDecimal("qty");
                     BigDecimal undeliqty = orderitemsRows.get(0).getBigDecimal("undeliqty");
                     BigDecimal canreturnqty = (qty.subtract(undeliqty)).subtract(returnqty);
@@ -170,14 +171,14 @@ public class aftersalesmag extends Controller {
 
         for (Row row : sa_aftersalesmag_itemsRows) {
             BigDecimal returnqty = row.getBigDecimal("qty");
-            if(rows.get(0).getString("type").equals("退货单")){
-                sqlList.add("update sa_orderitems set returnqty=returnqty+" + returnqty + " where sa_orderitemsid=" + row.getString("sa_orderitemsid"));
+            if (rows.get(0).getString("type").equals("退货单")) {
+                sqlList.add("update sa_orderitems set returnqty=returnqty+" + returnqty + " where siteid='" + siteid + "' and sa_orderitemsid=" + row.getString("sa_orderitemsid"));
             }
-            Rows sumamountrows = dbConnect.runSqlQuery("select sum(amount) sumamount from sa_aftersalesmag_items where sa_aftersalesmagid=" + sa_aftersalesmagid + " and siteid = '" + siteid + "'");
+            Rows sumamountrows = dbConnect.runSqlQuery("select sum(amount) sumamount from sa_aftersalesmag_items where siteid='" + siteid + "' and sa_aftersalesmagid=" + sa_aftersalesmagid + " and siteid = '" + siteid + "'");
             if (!sumamountrows.isEmpty()) {
-                sqlList.add("update sa_aftersalesmag set returnamount=" + sumamountrows.get(0).getBigDecimal("sumamount") + " where sa_aftersalesmagid=" + sa_aftersalesmagid);
+                sqlList.add("update sa_aftersalesmag set returnamount=" + sumamountrows.get(0).getBigDecimal("sumamount") + " where siteid='" + siteid + "' and sa_aftersalesmagid=" + sa_aftersalesmagid);
             } else {
-                sqlList.add("update sa_aftersalesmag set returnamount=0 where sa_aftersalesmagid=" + sa_aftersalesmagid);
+                sqlList.add("update sa_aftersalesmag set returnamount=0 where siteid='" + siteid + "' and sa_aftersalesmagid=" + sa_aftersalesmagid);
             }
         }
 
@@ -196,14 +197,12 @@ public class aftersalesmag extends Controller {
     @CACHEING_CLEAN(apiversions = {R.ID20230104160603.v1.class, R.ID20230104160703.v1.class, R.ID20230105110903.class, R.ID20230105161503.v1.class})
     public String unsumbit() throws YosException {
         Long sa_aftersalesmagid = content.getLong("sa_aftersalesmagid");
-        Long sa_orderid = 0L;
         Rows rows = dbConnect.runSqlQuery(
                 "select sa_aftersalesmagid,status,billno,sa_orderid,type from sa_aftersalesmag where sa_aftersalesmagid ='"
                         + sa_aftersalesmagid + "' and  siteid='" + siteid + "'");
         if (rows.isEmpty()) {
             return getErrReturnObject().setErrMsg("该返退单不存在").toString();
         } else {
-            sa_orderid = rows.get(0).getLong("sa_orderid");
             if (!rows.get(0).getString("status").equals("提交")) {
                 return getErrReturnObject().setErrMsg("单号为:【" + rows.get(0).getString("billno") + "】的返退单为非提交状态,无法反提交")
                         .toString();
@@ -211,11 +210,11 @@ public class aftersalesmag extends Controller {
         }
 
         ArrayList<String> sqlList = new ArrayList<>();
-        Rows sa_aftersalesmag_itemsRows = dbConnect.runSqlQuery("select t1.qty,t1.sa_orderitemsid,t2.itemno,t2.itemname from sa_aftersalesmag_items t1 left join plm_item t2 on t1.itemid=t2.itemid and t1.siteid=t2.siteid  where t1.sa_aftersalesmagid=" + sa_aftersalesmagid);
+        Rows sa_aftersalesmag_itemsRows = dbConnect.runSqlQuery("select t1.qty,t1.sa_orderitemsid,t2.itemno,t2.itemname from sa_aftersalesmag_items t1 left join plm_item t2 on t1.itemid=t2.itemid and t1.siteid=t2.siteid  where t1.siteid='" + siteid + "' and t1.sa_aftersalesmagid=" + sa_aftersalesmagid);
         for (Row row : sa_aftersalesmag_itemsRows) {
             BigDecimal returnqty = row.getBigDecimal("qty");
-            if(rows.get(0).getString("type").equals("退货单")){
-                sqlList.add("update sa_orderitems set returnqty=returnqty-" + returnqty + " where sa_orderitemsid=" + row.getString("sa_orderitemsid"));
+            if (rows.get(0).getString("type").equals("退货单")) {
+                sqlList.add("update sa_orderitems set returnqty=returnqty-" + returnqty + " where siteid='" + siteid + "' and sa_orderitemsid=" + row.getString("sa_orderitemsid"));
             }
         }
         SQLFactory sqlFactoryupdate = new SQLFactory(this, "返退单反提交");

+ 27 - 29
src/custom/restcontroller/sale/creditbill/creditbill.java

@@ -167,9 +167,6 @@ public class creditbill extends Controller {
         Rows rows = dbConnect
                 .runSqlQuery("select sa_creditbillid,status,billno from sa_creditbill where sa_creditbillid ='"
                         + sa_creditbillid + "' and  siteid='" + siteid + "'");
-        Rows rowsdetail = dbConnect.runSqlQuery(
-                "select sa_creditbillid,sys_enterpriseid,sa_accountclassid,creditquota from sa_creditbilldetail where sa_creditbillid ='"
-                        + sa_creditbillid + "' and  siteid='" + siteid + "'");
         for (Row row : rows) {
             if (row.getString("status").equals("审核")) {
                 return getErrReturnObject().setErrMsg("单号为:【" + row.getString("billno") + "】的信用额度调整单已审核,无法再次审核")
@@ -180,6 +177,9 @@ public class creditbill extends Controller {
                         .toString();
             }
         }
+        Rows rowsdetail = dbConnect.runSqlQuery(
+                "select sa_creditbillid,sys_enterpriseid,sa_accountclassid,creditquota from sa_creditbilldetail where sa_creditbillid ='"
+                        + sa_creditbillid + "' and  siteid='" + siteid + "'");
         ArrayList<String> sqlList = new ArrayList<>();
 
         Rows rowsaccountbalance = dbConnect.runSqlQuery(
@@ -190,12 +190,24 @@ public class creditbill extends Controller {
         sqlFactoryupdate.addParameter_in("sa_creditbillid", sa_creditbillid);
         sqlFactoryupdate.addParameter("checkby", username);
         sqlList.add(sqlFactoryupdate.getSQL());
-        if (!rows.isEmpty()) {
-            for (Row row : rowsdetail) {
-                long sys_enterpriseid = row.getLong("sys_enterpriseid");
-                long sa_accountclassid = row.getLong("sa_accountclassid");
-                BigDecimal creditquota = row.getBigDecimal("creditquota");
-                if (rowsMaAaccountbalance.get(sys_enterpriseid).isEmpty()) {
+        for (Row row : rowsdetail) {
+            long sys_enterpriseid = row.getLong("sys_enterpriseid");
+            long sa_accountclassid = row.getLong("sa_accountclassid");
+            BigDecimal creditquota = row.getBigDecimal("creditquota");
+            if (rowsMaAaccountbalance.get(sys_enterpriseid).isEmpty()) {
+                SQLFactory sqlFactory = new SQLFactory(this, "营销账户余额新增");
+                sqlFactory.addParameter("sa_accountbalanceid", createTableID("sa_accountbalance"));
+                sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
+                sqlFactory.addParameter("sa_accountclassid", sa_accountclassid);
+                sqlFactory.addParameter("siteid", siteid);
+                sqlFactory.addParameter("creditquota", creditquota);
+                sqlFactory.addParameter("userid", userid);
+                sqlFactory.addParameter("username", username);
+                // content.put("sa_creditbillid", sa_creditbillid);
+                sqlList.add(sqlFactory.getSQL());
+            } else {
+                if (rowsMaAaccountbalance.get(sys_enterpriseid).toRowsMap("sa_accountclassid")
+                        .get(sa_accountclassid).isEmpty()) {
                     SQLFactory sqlFactory = new SQLFactory(this, "营销账户余额新增");
                     sqlFactory.addParameter("sa_accountbalanceid", createTableID("sa_accountbalance"));
                     sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
@@ -207,29 +219,15 @@ public class creditbill extends Controller {
                     // content.put("sa_creditbillid", sa_creditbillid);
                     sqlList.add(sqlFactory.getSQL());
                 } else {
-                    if (rowsMaAaccountbalance.get(sys_enterpriseid).toRowsMap("sa_accountclassid")
-                            .get(sa_accountclassid).isEmpty()) {
-                        SQLFactory sqlFactory = new SQLFactory(this, "营销账户余额新增");
-                        sqlFactory.addParameter("sa_accountbalanceid", createTableID("sa_accountbalance"));
-                        sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
-                        sqlFactory.addParameter("sa_accountclassid", sa_accountclassid);
-                        sqlFactory.addParameter("siteid", siteid);
-                        sqlFactory.addParameter("creditquota", creditquota);
-                        sqlFactory.addParameter("userid", userid);
-                        sqlFactory.addParameter("username", username);
-                        // content.put("sa_creditbillid", sa_creditbillid);
-                        sqlList.add(sqlFactory.getSQL());
-                    } else {
-                        sqlList.add("update sa_accountbalance set creditquota=creditquota+" + creditquota
-                                + ",changedate=CURRENT_TIME,changeby ='" + username + "',changeuserid='" + userid
-                                + "' where sys_enterpriseid ='" + sys_enterpriseid + "' and  sa_accountclassid='"
-                                + sa_accountclassid + "' and siteid='" + siteid + "'");
-                    }
-
+                    sqlList.add("update sa_accountbalance set creditquota=creditquota+" + creditquota
+                            + ",changedate=CURRENT_TIME,changeby ='" + username + "',changeuserid='" + userid
+                            + "' where sys_enterpriseid ='" + sys_enterpriseid + "' and  sa_accountclassid='"
+                            + sa_accountclassid + "' and siteid='" + siteid + "'");
                 }
-            }
 
+            }
         }
+
         sqlList.add(DataContrlLog.createLog(this, "sa_creditbill", sa_creditbillid, "审核", "信用额度调整单审核成功").getSQL());
         dbConnect.runSqlUpdate(sqlList);
         return getSucReturnObject().toString();

+ 2 - 4
src/custom/restcontroller/sale/enterprise/enterprise.java

@@ -33,7 +33,7 @@ public class enterprise extends Controller {
                 sys_enterpriseid = rows.get(0).getLong("sys_enterpriseid");
             }
         }
-        if(sys_enterpriseid==0){
+        if (sys_enterpriseid == 0) {
             return getSucReturnObject().setData(new Row()).toString();
         }
 
@@ -60,7 +60,6 @@ public class enterprise extends Controller {
         String county = content.getString("county", "sys_enterprise");
         String abbreviation = content.getString("abbreviation", "sys_enterprise");
 
-        ArrayList<String> sqllist = new ArrayList<>();
         SQLFactory sqlFactory = new SQLFactory(this, "商户档案修改");
         sqlFactory.addParameter("siteid", siteid);
         sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
@@ -75,10 +74,9 @@ public class enterprise extends Controller {
         sqlFactory.addParameter("county", county);
         sqlFactory.addParameter("taxno", taxno);
         sqlFactory.addParameter("abbreviation", abbreviation);
-        sqllist.add(sqlFactory.getSQL());
 
 
-        dbConnect.runSqlUpdate(sqllist);
+        dbConnect.runSqlUpdate(sqlFactory.getSQL());
         return query_enterpriseMain();
     }
 

+ 36 - 33
src/custom/restcontroller/sale/invoice/invoiceapply.java

@@ -80,7 +80,6 @@ public class invoiceapply extends Controller {
     @CACHEING_CLEAN(apiversions = {R.ID20221216143003.v1.class, R.ID20221216143103.v1.class, R.ID20221219133703.v1.class})
     public String check() throws YosException {
         Long sa_invoiceapplyid = content.getLong("sa_invoiceapplyid");
-        Long sa_orderid = 0L;
 
         int invoicingpoint = 99; //开票节点 1为订单审核,2为订单发货
 
@@ -89,6 +88,32 @@ public class invoiceapply extends Controller {
                 "select sa_invoiceapplyid,status,billno,sys_enterpriseid from sa_invoiceapply where sa_invoiceapplyid ='"
                         + sa_invoiceapplyid + "' and  siteid='" + siteid + "'");
 
+        if (rows.isEmpty()) {
+            return getErrReturnObject().setErrMsg("该开票申请单不存在").toString();
+        } else {
+            if (!rows.get(0).getString("status").equals("新建")) {
+                return getErrReturnObject().setErrMsg("单号为:【" + rows.get(0).getString("billno") + "】的开票申请单为非新建状态,无法提交")
+                        .toString();
+            } else {
+                Rows sys_enterpriseRows = dbConnect
+                        .runSqlQuery("select invoicingpoint from sys_enterprise where sys_enterpriseid=" + rows.get(0).getLong("sys_enterpriseid"));
+                if (!sys_enterpriseRows.isEmpty()) {
+                    invoicingpoint = sys_enterpriseRows.get(0).getInteger("invoicingpoint");
+                }
+            }
+        }
+        if (dbConnect.runSqlQuery(
+                "select sa_invoiceapplyid from sa_invoiceapply_order where sa_invoiceapplyid ='"
+                        + sa_invoiceapplyid + "' and  siteid='" + siteid + "'").isEmpty()) {
+            return getErrReturnObject().setErrMsg("订单信息为空不可提交").toString();
+        }
+
+        if ((dbConnect.runSqlQuery(
+                "select sa_invoiceapplyid,invoiceamount from sa_invoiceapply_order where sa_invoiceapplyid ='"
+                        + sa_invoiceapplyid + "' and  siteid='" + siteid + "' order by invoiceamount asc").get(0).getBigDecimal("invoiceamount")).compareTo(BigDecimal.ZERO) <= 0) {
+            return getErrReturnObject().setErrMsg("订单行开票金额必须大于0").toString();
+        }
+
         Rows rowsDetail = dbConnect.runSqlQuery(
                 "select * from sa_invoiceapply_order where sa_invoiceapplyid ='" + sa_invoiceapplyid + "' and  siteid='" + siteid + "'");  //获取开票申请单表体
 
@@ -108,36 +133,13 @@ public class invoiceapply extends Controller {
                 "group by t1.siteid,t1.sa_orderid,t2.sa_orderitemsid,t3.returnqty,t3.qty,t3.price,t3.amount");
         RowsMap saorderRecviceRowsMap = saorderRecviceRows.toRowsMap("sa_orderitemsid"); //获取订单已收货数量、金额的rowsmap
 
-        if (rows.isEmpty()) {
-            return getErrReturnObject().setErrMsg("该开票申请单不存在").toString();
-        } else {
-            if (!rows.get(0).getString("status").equals("新建")) {
-                return getErrReturnObject().setErrMsg("单号为:【" + rows.get(0).getString("billno") + "】的开票申请单为非新建状态,无法提交")
-                        .toString();
-            } else {
-                Rows sys_enterpriseRows = dbConnect
-                        .runSqlQuery("select invoicingpoint from sys_enterprise where sys_enterpriseid=" + rows.get(0).getLong("sys_enterpriseid"));
-                if (!sys_enterpriseRows.isEmpty()) {
-                    invoicingpoint = sys_enterpriseRows.get(0).getInteger("invoicingpoint");
-                }
-            }
-        }
 
-        if (dbConnect.runSqlQuery(
-                "select sa_invoiceapplyid from sa_invoiceapply_order where sa_invoiceapplyid ='"
-                        + sa_invoiceapplyid + "' and  siteid='" + siteid + "'").isEmpty()) {
-            return getErrReturnObject().setErrMsg("订单信息为空不可提交").toString();
-        }
 //        if (dbConnect.runSqlQuery(
 //				"select sa_invoiceapplyid from sa_invoicebill where sa_invoiceapplyid ='"
 //						+ sa_invoiceapplyid + "' and  siteid='" + siteid + "'").isEmpty()) {
 //        	return getErrReturnObject().setErrMsg("开票信息为空不可提交").toString();
 //        }      
-        if ((dbConnect.runSqlQuery(
-                "select sa_invoiceapplyid,invoiceamount from sa_invoiceapply_order where sa_invoiceapplyid ='"
-                        + sa_invoiceapplyid + "' and  siteid='" + siteid + "' order by invoiceamount asc").get(0).getBigDecimal("invoiceamount")).compareTo(BigDecimal.ZERO) <= 0) {
-            return getErrReturnObject().setErrMsg("订单行开票金额必须大于0").toString();
-        }
+
 //        Rows tinvoiceapply_totalview =dbConnect.runSqlQuery("select t1.* from (\r\n" + 
 //        		"select sa_invoiceapplyid,sum(orderamount) as orderamount,sum(billamount) as billamount,sum(redbillamount) as redbillamount from \r\n" + 
 //        		"						(select sa_invoiceapplyid,ifnull(SUM(invoiceamount),0) as orderamount,0 as billamount,0 as redbillamount  from sa_invoiceapply_order group by sa_invoiceapplyid\r\n" + 
@@ -151,19 +153,20 @@ public class invoiceapply extends Controller {
 
 
         for (Row row : rowsDetail) {
-            BigDecimal invoiceamount_order = saorderitemsRowsMap.get(row.getLong("sa_orderitemsid")).get(0).getBigDecimal("invoiceamount");//订单已开票金额
+            String sa_orderitemsid = row.getString("sa_orderitemsid");
+            BigDecimal invoiceamount_order = saorderitemsRowsMap.get(sa_orderitemsid).get(0).getBigDecimal("invoiceamount");//订单已开票金额
             BigDecimal invoiceamount = row.getBigDecimal("invoiceamount");//本次开票金额
-            BigDecimal price = saorderitemsRowsMap.get(row.getLong("sa_orderitemsid")).get(0).getBigDecimal("price");//单价
+//            BigDecimal price = saorderitemsRowsMap.get(row.getLong("sa_orderitemsid")).get(0).getBigDecimal("price");//单价
             BigDecimal receivedamount = new BigDecimal(0);
             if (invoicingpoint == 1) {
-                receivedamount = saorderitemsRowsMap.get(row.getLong("sa_orderitemsid")).get(0).getBigDecimal("amount");//订单金额
+                receivedamount = saorderitemsRowsMap.get(sa_orderitemsid).get(0).getBigDecimal("amount");//订单金额
             } else if (invoicingpoint == 2) {
-                if (!saorderRecviceRowsMap.get(row.getLong("sa_orderitemsid")).isEmpty()) {
-                    receivedamount = saorderRecviceRowsMap.get(row.getLong("sa_orderitemsid")).get(0).getBigDecimal("receivedamount");//订单已收货金额
+                if (!saorderRecviceRowsMap.get(sa_orderitemsid).isEmpty()) {
+                    receivedamount = saorderRecviceRowsMap.get(sa_orderitemsid).get(0).getBigDecimal("receivedamount");//订单已收货金额
                 }
             }
-            String fsonum = OrderDetailRowsMap.get(row.getLong("sa_orderitemsid")).get(0).getString("sonum");//订单号
-            String fitemname = OrderDetailRowsMap.get(row.getLong("sa_orderitemsid")).get(0).getString("itemname");//商品名称
+            String fsonum = OrderDetailRowsMap.get(sa_orderitemsid).get(0).getString("sonum");//订单号
+            String fitemname = OrderDetailRowsMap.get(sa_orderitemsid).get(0).getString("itemname");//商品名称
             if (invoiceamount.compareTo(receivedamount.subtract(invoiceamount_order)) > 0) {
                 return getErrReturnObject().setErrMsg("订单" + fsonum + "商品" + fitemname + "本次开票金额" + invoiceamount + "超过订单可开票金额" + receivedamount.subtract(invoiceamount_order)).toString();
             }
@@ -176,7 +179,7 @@ public class invoiceapply extends Controller {
         sqlList.add(sqlFactoryupdate.getSQL());
         sqlList.add(DataContrlLog.createLog(this, "sa_invoiceapply", sa_invoiceapplyid, "提交", "开票申请单提交成功").getSQL());
         dbConnect.runSqlUpdate(sqlList);
-        Executor.sendEml(this, "invoiceapplysub", sa_invoiceapplyid,new ArrayList<>());
+        Executor.sendEml(this, "invoiceapplysub", sa_invoiceapplyid, new ArrayList<>());
         return getSucReturnObject().toString();
 
     }

+ 117 - 121
src/custom/restcontroller/sale/itemgroup/itemgroup.java

@@ -133,8 +133,8 @@ public class itemgroup extends Controller {
                 list.add(whereObject.getLong("itemclassid"));
                 ArrayList<Long> listNew = new ArrayList<>();
                 listNew.add((long) 0);
-                for (long itemclassid:list) {
-                    if(itemclassList.contains(itemclassid)){
+                for (long itemclassid : list) {
+                    if (itemclassList.contains(itemclassid)) {
                         listNew.add(itemclassid);
                     }
                 }
@@ -193,10 +193,10 @@ public class itemgroup extends Controller {
             BigDecimal max = new BigDecimal(0);
             BigDecimal min = ((ItemPrice) ItemPriceList.values().toArray()[0]).getPrice();
             for (ItemPrice itemPrice : ItemPriceList.values()) {
-                if (itemPrice.getPrice().compareTo(max) == 1) {
+                if (itemPrice.getPrice().compareTo(max) > 0) {
                     max = itemPrice.getPrice();
                 }
-                if (itemPrice.getPrice().compareTo(min) == -1) {
+                if (itemPrice.getPrice().compareTo(min) < 0) {
                     min = itemPrice.getPrice();
                 }
             }
@@ -298,18 +298,6 @@ public class itemgroup extends Controller {
         sqlFactory.addParameter("siteid", siteid);
         Rows rows = dbConnect.runSqlQuery(sqlFactory);
 
-        for (Row row : rows) {
-            ItemPrice itemPrice = ItemPrice.getItemPrice(this, sys_enterpriseid, row.getLong("itemid"));
-            row.put("oldprice", itemPrice.getMarketprice());
-            if (sys_enterpriseid > 0 || (usertype == 21 || usertype == 22)) {
-                row.put("gradeprice", itemPrice.getContractprice());
-            } else {
-                row.put("gradeprice", itemPrice.getMarketprice());
-            }
-
-//            row.put("pricegrade", itemPrice.getEnterpriseGrade().getPricegrade());
-        }
-
         ArrayList<Long> ids = rows.toArrayList("itemid", new ArrayList<>());
 
         //默认商品图片
@@ -332,7 +320,18 @@ public class itemgroup extends Controller {
                         + siteid + "'");
         RowsMap itemclassRowsMap = rowsitemclass.toRowsMap("itemid");
 
+        HashMap<Long, ItemPrice> itemPriceHashMap = ItemPrice.getItemPrice(this, sys_enterpriseid, rows.toArrayList("itemid", new ArrayList<>()));
         for (Row row : rows) {
+            long itemid = row.getLong("itemid");
+            ItemPrice itemPrice = itemPriceHashMap.get(itemid);
+
+            row.put("oldprice", itemPrice.getMarketprice());
+            if (sys_enterpriseid > 0 || (usertype == 21 || usertype == 22)) {
+                row.put("gradeprice", itemPrice.getContractprice());
+            } else {
+                row.put("gradeprice", itemPrice.getMarketprice());
+            }
+
             Rows jsonArray = new Rows();
             Rows coverRows = coverRowsMap.get(row.getString("itemid"));
             if (coverRows.isEmpty()) {
@@ -393,12 +392,12 @@ public class itemgroup extends Controller {
         SQLFactory factory = new SQLFactory(this, "商品组明细查询");
         factory.addParameter("sa_itemgroupid", content.getString("sa_itemgroupid"));
         factory.addParameter("siteid", siteid);
-        String where1=" 1=1 ";
+        String where1 = " 1=1 ";
         Rows tradefieldRows = dbConnect.runSqlQuery("SELECT DISTINCT t1.tradefield from sys_enterprise_tradefield t1  WHERE t1.sys_enterpriseid = " + sys_enterpriseid + " and t1.siteid='" + siteid + "'");
 
-        if(!tradefieldRows.isEmpty()){
-            for (Row row: tradefieldRows) {
-                where1= where1 +" or t4.tradefield like '%"+row.getString("tradefield")+"%' ";
+        if (!tradefieldRows.isEmpty()) {
+            for (Row row : tradefieldRows) {
+                where1 = where1 + " or t4.tradefield like '%" + row.getString("tradefield") + "%' ";
             }
         }
         factory.addParameter_SQL("where1", where1);
@@ -445,22 +444,22 @@ public class itemgroup extends Controller {
             for (Row row : rows) {
                 for (String value : listParmBlank) {
                     if (value.equals("color")) {
-                        JSONObject jsonObject =new JSONObject();
+                        JSONObject jsonObject = new JSONObject();
                         jsonObject.put("parm", row.getString("color"));
                         jsonObject.put("flag", true);
                         colormap.add(jsonObject);
                     } else if (value.equals("spec")) {
-                        JSONObject jsonObject =new JSONObject();
+                        JSONObject jsonObject = new JSONObject();
                         jsonObject.put("parm", row.getString("spec"));
                         jsonObject.put("flag", true);
                         specmap.add(jsonObject);
                     } else if (value.equals("material")) {
-                        JSONObject jsonObject =new JSONObject();
+                        JSONObject jsonObject = new JSONObject();
                         jsonObject.put("parm", row.getString("material"));
                         jsonObject.put("flag", true);
                         materialmap.add(jsonObject);
                     } else if (value.equals("cheek")) {
-                        JSONObject jsonObject =new JSONObject();
+                        JSONObject jsonObject = new JSONObject();
                         jsonObject.put("parm", row.getString("cheek"));
                         jsonObject.put("flag", true);
                         cheekmap.add(jsonObject);
@@ -513,11 +512,11 @@ public class itemgroup extends Controller {
             for (String value : listAll) {
                 if (value.equals("color")) {
                     factory.addParameter_SQL("where", " 1=1 " + specwhere + materialwhere + cheekwhere);
-                     System.out.println(" 1=1 " + specwhere + materialwhere + cheekwhere);
+                    System.out.println(" 1=1 " + specwhere + materialwhere + cheekwhere);
                     rows = dbConnect.runSqlQuery(factory.getSQL());
                     if (!rows.isEmpty()) {
                         for (Row row : rows) {
-                            JSONObject jsonObject =new JSONObject();
+                            JSONObject jsonObject = new JSONObject();
                             jsonObject.put("parm", row.getString("color"));
                             jsonObject.put("flag", true);
                             colormap.add(jsonObject);
@@ -528,7 +527,7 @@ public class itemgroup extends Controller {
                     rows = dbConnect.runSqlQuery(factory.getSQL());
                     if (!rows.isEmpty()) {
                         for (Row row : rows) {
-                            JSONObject jsonObject =new JSONObject();
+                            JSONObject jsonObject = new JSONObject();
                             jsonObject.put("parm", row.getString("spec"));
                             jsonObject.put("flag", true);
                             specmap.add(jsonObject);
@@ -539,7 +538,7 @@ public class itemgroup extends Controller {
                     rows = dbConnect.runSqlQuery(factory.getSQL());
                     if (!rows.isEmpty()) {
                         for (Row row : rows) {
-                            JSONObject jsonObject =new JSONObject();
+                            JSONObject jsonObject = new JSONObject();
                             jsonObject.put("parm", row.getString("material"));
                             jsonObject.put("flag", true);
                             materialmap.add(jsonObject);
@@ -550,7 +549,7 @@ public class itemgroup extends Controller {
                     rows = dbConnect.runSqlQuery(factory.getSQL());
                     if (!rows.isEmpty()) {
                         for (Row row : rows) {
-                            JSONObject jsonObject =new JSONObject();
+                            JSONObject jsonObject = new JSONObject();
                             jsonObject.put("parm", row.getString("cheek"));
                             jsonObject.put("flag", true);
                             cheekmap.add(jsonObject);
@@ -560,76 +559,76 @@ public class itemgroup extends Controller {
             }
 
             for (String firstcolor : firstcolorList) {
-                boolean isexistParm=false;
-                for (Object object:colormap) {
+                boolean isexistParm = false;
+                for (Object object : colormap) {
                     JSONObject jsonObject = (JSONObject) object;
-                    if(jsonObject.getString("parm").equals(firstcolor)){
-                        isexistParm=true;
+                    if (jsonObject.getString("parm").equals(firstcolor)) {
+                        isexistParm = true;
                         break;
                     }
                 }
                 if (!isexistParm) {
-                    JSONObject jsonObject =new JSONObject();
+                    JSONObject jsonObject = new JSONObject();
                     jsonObject.put("parm", firstcolor);
                     jsonObject.put("flag", false);
                     colormap.add(jsonObject);
                 }
             }
             for (String firstspec : firstspecList) {
-                boolean isexistParm=false;
-                for (Object object:specmap) {
+                boolean isexistParm = false;
+                for (Object object : specmap) {
                     JSONObject jsonObject = (JSONObject) object;
-                    if(jsonObject.getString("parm").equals(firstspec)){
-                        isexistParm=true;
+                    if (jsonObject.getString("parm").equals(firstspec)) {
+                        isexistParm = true;
                         break;
                     }
                 }
                 if (!isexistParm) {
-                    JSONObject jsonObject =new JSONObject();
+                    JSONObject jsonObject = new JSONObject();
                     jsonObject.put("parm", firstspec);
                     jsonObject.put("flag", false);
                     specmap.add(jsonObject);
                 }
             }
             for (String firstmaterial : firstmaterialList) {
-                boolean isexistParm=false;
-                for (Object object:materialmap) {
+                boolean isexistParm = false;
+                for (Object object : materialmap) {
                     JSONObject jsonObject = (JSONObject) object;
-                    if(jsonObject.getString("parm").equals(firstmaterial)){
-                        isexistParm=true;
+                    if (jsonObject.getString("parm").equals(firstmaterial)) {
+                        isexistParm = true;
                         break;
                     }
                 }
                 if (!isexistParm) {
-                    JSONObject jsonObject =new JSONObject();
+                    JSONObject jsonObject = new JSONObject();
                     jsonObject.put("parm", firstmaterial);
                     jsonObject.put("flag", false);
                     materialmap.add(jsonObject);
                 }
             }
             for (String firstcheek : firstcheekList) {
-                boolean isexistParm=false;
-                for (Object object:cheekmap) {
+                boolean isexistParm = false;
+                for (Object object : cheekmap) {
                     JSONObject jsonObject = (JSONObject) object;
-                    if(jsonObject.getString("parm").equals(firstcheek)){
-                        isexistParm=true;
+                    if (jsonObject.getString("parm").equals(firstcheek)) {
+                        isexistParm = true;
                         break;
                     }
                 }
                 if (!isexistParm) {
-                    JSONObject jsonObject =new JSONObject();
+                    JSONObject jsonObject = new JSONObject();
                     jsonObject.put("parm", firstcheek);
                     jsonObject.put("flag", false);
                     cheekmap.add(jsonObject);
                 }
             }
 
-            factory.addParameter_SQL("where", " 1=1 " + colorwhere + specwhere + materialwhere+cheekwhere);
+            factory.addParameter_SQL("where", " 1=1 " + colorwhere + specwhere + materialwhere + cheekwhere);
         } else {
             String where = " 1=1 ";
             for (String value : listParmNotBlank) {
                 if (value.equals("color")) {
-                    JSONObject jsonObject =new JSONObject();
+                    JSONObject jsonObject = new JSONObject();
                     jsonObject.put("parm", content.getString("color"));
                     jsonObject.put("flag", true);
                     colormap.add(jsonObject);
@@ -642,7 +641,7 @@ public class itemgroup extends Controller {
 //                        }
 //                    }
                 } else if (value.equals("spec")) {
-                    JSONObject jsonObject =new JSONObject();
+                    JSONObject jsonObject = new JSONObject();
                     jsonObject.put("parm", content.getString("spec"));
                     jsonObject.put("flag", true);
                     specmap.add(jsonObject);
@@ -655,7 +654,7 @@ public class itemgroup extends Controller {
 //                        }
 //                    }
                 } else if (value.equals("material")) {
-                    JSONObject jsonObject =new JSONObject();
+                    JSONObject jsonObject = new JSONObject();
                     jsonObject.put("parm", content.getString("material"));
                     jsonObject.put("flag", true);
                     materialmap.add(jsonObject);
@@ -668,7 +667,7 @@ public class itemgroup extends Controller {
 //                        }
 //                    }
                 } else if (value.equals("cheek")) {
-                    JSONObject jsonObject =new JSONObject();
+                    JSONObject jsonObject = new JSONObject();
                     jsonObject.put("parm", content.getString("cheek"));
                     jsonObject.put("flag", true);
                     cheekmap.add(jsonObject);
@@ -689,7 +688,7 @@ public class itemgroup extends Controller {
                     rows = dbConnect.runSqlQuery(factory.getSQL());
                     if (!rows.isEmpty()) {
                         for (Row row : rows) {
-                            JSONObject jsonObject =new JSONObject();
+                            JSONObject jsonObject = new JSONObject();
                             jsonObject.put("parm", row.getString("color"));
                             jsonObject.put("flag", true);
                             colormap.add(jsonObject);
@@ -700,7 +699,7 @@ public class itemgroup extends Controller {
                     rows = dbConnect.runSqlQuery(factory.getSQL());
                     if (!rows.isEmpty()) {
                         for (Row row : rows) {
-                            JSONObject jsonObject =new JSONObject();
+                            JSONObject jsonObject = new JSONObject();
                             jsonObject.put("parm", row.getString("spec"));
                             jsonObject.put("flag", true);
                             specmap.add(jsonObject);
@@ -710,7 +709,7 @@ public class itemgroup extends Controller {
                     rows = dbConnect.runSqlQuery(factory.getSQL());
                     if (!rows.isEmpty()) {
                         for (Row row : rows) {
-                            JSONObject jsonObject =new JSONObject();
+                            JSONObject jsonObject = new JSONObject();
                             jsonObject.put("parm", row.getString("material"));
                             jsonObject.put("flag", true);
                             materialmap.add(jsonObject);
@@ -720,7 +719,7 @@ public class itemgroup extends Controller {
                     rows = dbConnect.runSqlQuery(factory.getSQL());
                     if (!rows.isEmpty()) {
                         for (Row row : rows) {
-                            JSONObject jsonObject =new JSONObject();
+                            JSONObject jsonObject = new JSONObject();
                             jsonObject.put("parm", row.getString("cheek"));
                             jsonObject.put("flag", true);
                             cheekmap.add(jsonObject);
@@ -731,66 +730,65 @@ public class itemgroup extends Controller {
             }
 
 
-
             for (String firstcolor : firstcolorList) {
-                boolean isexistParm=false;
-                for (Object object:colormap) {
+                boolean isexistParm = false;
+                for (Object object : colormap) {
                     JSONObject jsonObject = (JSONObject) object;
-                    if(jsonObject.getString("parm").equals(firstcolor)){
-                        isexistParm=true;
+                    if (jsonObject.getString("parm").equals(firstcolor)) {
+                        isexistParm = true;
                         break;
                     }
                 }
                 if (!isexistParm) {
-                    JSONObject jsonObject =new JSONObject();
+                    JSONObject jsonObject = new JSONObject();
                     jsonObject.put("parm", firstcolor);
                     jsonObject.put("flag", false);
                     colormap.add(jsonObject);
                 }
             }
             for (String firstspec : firstspecList) {
-                boolean isexistParm=false;
-                for (Object object:specmap) {
+                boolean isexistParm = false;
+                for (Object object : specmap) {
                     JSONObject jsonObject = (JSONObject) object;
-                    if(jsonObject.getString("parm").equals(firstspec)){
-                        isexistParm=true;
+                    if (jsonObject.getString("parm").equals(firstspec)) {
+                        isexistParm = true;
                         break;
                     }
                 }
                 if (!isexistParm) {
-                    JSONObject jsonObject =new JSONObject();
+                    JSONObject jsonObject = new JSONObject();
                     jsonObject.put("parm", firstspec);
                     jsonObject.put("flag", false);
                     specmap.add(jsonObject);
                 }
             }
             for (String firstmaterial : firstmaterialList) {
-                boolean isexistParm=false;
-                for (Object object:materialmap) {
+                boolean isexistParm = false;
+                for (Object object : materialmap) {
                     JSONObject jsonObject = (JSONObject) object;
-                    if(jsonObject.getString("parm").equals(firstmaterial)){
-                        isexistParm=true;
+                    if (jsonObject.getString("parm").equals(firstmaterial)) {
+                        isexistParm = true;
                         break;
                     }
                 }
                 if (!isexistParm) {
-                    JSONObject jsonObject =new JSONObject();
+                    JSONObject jsonObject = new JSONObject();
                     jsonObject.put("parm", firstmaterial);
                     jsonObject.put("flag", false);
                     materialmap.add(jsonObject);
                 }
             }
             for (String firstcheek : firstcheekList) {
-                boolean isexistParm=false;
-                for (Object object:cheekmap) {
+                boolean isexistParm = false;
+                for (Object object : cheekmap) {
                     JSONObject jsonObject = (JSONObject) object;
-                    if(jsonObject.getString("parm").equals(firstcheek)){
-                        isexistParm=true;
+                    if (jsonObject.getString("parm").equals(firstcheek)) {
+                        isexistParm = true;
                         break;
                     }
                 }
                 if (!isexistParm) {
-                    JSONObject jsonObject =new JSONObject();
+                    JSONObject jsonObject = new JSONObject();
                     jsonObject.put("parm", firstcheek);
                     jsonObject.put("flag", false);
                     cheekmap.add(jsonObject);
@@ -799,62 +797,61 @@ public class itemgroup extends Controller {
         }
 
 
-        colormap=jsonArraySortByField(colormap.toJSONString(),"parm","0");
-        specmap=jsonArraySortByField(specmap.toJSONString(),"parm","0");
-        materialmap=jsonArraySortByField(materialmap.toJSONString(),"parm","0");
-        cheekmap=jsonArraySortByField(cheekmap.toJSONString(),"parm","0");
-
+        colormap = jsonArraySortByField(colormap.toJSONString(), "parm", "0");
+        specmap = jsonArraySortByField(specmap.toJSONString(), "parm", "0");
+        materialmap = jsonArraySortByField(materialmap.toJSONString(), "parm", "0");
+        cheekmap = jsonArraySortByField(cheekmap.toJSONString(), "parm", "0");
 
 
-        for (Object object:colormap) {
-            boolean flag=false;
-            parm parm =JSON.parseObject(((JSONObject)object).toJSONString(),parm.class);
-            for (parm parm1:colorList) {
-                if(parm1.getParm().equals(parm.getParm())){
-                    flag=true;
+        for (Object object : colormap) {
+            boolean flag = false;
+            parm parm = JSON.parseObject(((JSONObject) object).toJSONString(), parm.class);
+            for (parm parm1 : colorList) {
+                if (parm1.getParm().equals(parm.getParm())) {
+                    flag = true;
                     break;
                 }
             }
-            if(!flag){
+            if (!flag) {
                 colorList.add(parm);
             }
         }
-        for (Object object:specmap) {
-            boolean flag=false;
-            parm parm =JSON.parseObject(((JSONObject)object).toJSONString(),parm.class);
-            for (parm parm1:specList) {
-                if(parm1.getParm().equals(parm.getParm())){
-                    flag=true;
+        for (Object object : specmap) {
+            boolean flag = false;
+            parm parm = JSON.parseObject(((JSONObject) object).toJSONString(), parm.class);
+            for (parm parm1 : specList) {
+                if (parm1.getParm().equals(parm.getParm())) {
+                    flag = true;
                     break;
                 }
             }
-            if(!flag){
+            if (!flag) {
                 specList.add(parm);
             }
         }
-        for (Object object:materialmap) {
-            boolean flag=false;
-            parm parm =JSON.parseObject(((JSONObject)object).toJSONString(),parm.class);
-            for (parm parm1:materialList) {
-                if(parm1.getParm().equals(parm.getParm())){
-                    flag=true;
+        for (Object object : materialmap) {
+            boolean flag = false;
+            parm parm = JSON.parseObject(((JSONObject) object).toJSONString(), parm.class);
+            for (parm parm1 : materialList) {
+                if (parm1.getParm().equals(parm.getParm())) {
+                    flag = true;
                     break;
                 }
             }
-            if(!flag){
+            if (!flag) {
                 materialList.add(parm);
             }
         }
-        for (Object object:cheekmap) {
-            boolean flag=false;
-            parm parm =JSON.parseObject(((JSONObject)object).toJSONString(),parm.class);
-            for (parm parm1:cheekList) {
-                if(parm1.getParm().equals(parm.getParm())){
-                    flag=true;
+        for (Object object : cheekmap) {
+            boolean flag = false;
+            parm parm = JSON.parseObject(((JSONObject) object).toJSONString(), parm.class);
+            for (parm parm1 : cheekList) {
+                if (parm1.getParm().equals(parm.getParm())) {
+                    flag = true;
                     break;
                 }
             }
-            if(!flag){
+            if (!flag) {
                 cheekList.add(parm);
             }
         }
@@ -865,8 +862,8 @@ public class itemgroup extends Controller {
         rows = dbConnect.runSqlQuery(factory.getSQL());
 
         String itemno = "";
-        if(!rows.isEmpty()){
-            itemno=rows.get(0).getString("itemno");
+        if (!rows.isEmpty()) {
+            itemno = rows.get(0).getString("itemno");
         }
 
         /**
@@ -938,16 +935,15 @@ public class itemgroup extends Controller {
     }
 
 
-
     /**
-     *	 按照JSONArray中的对象的某个字段进行排序(采用fastJson)
+     * 按照JSONArray中的对象的某个字段进行排序(采用fastJson)
      *
      * @param jsonArrayStr json数组字符串
-     * @param sortkeyname 根据哪个字段进行排序
-     * @param order 倒序:0;非0顺序
+     * @param sortkeyname  根据哪个字段进行排序
+     * @param order        倒序:0;非0顺序
      * @return 排序后的jsonarray
      */
-    public  JSONArray jsonArraySortByField(String jsonArrayStr,String sortkeyname, String order)  throws YosException  {
+    public JSONArray jsonArraySortByField(String jsonArrayStr, String sortkeyname, String order) throws YosException {
 
         JSONArray sortedJsonArray = new JSONArray();
 
@@ -969,7 +965,7 @@ public class itemgroup extends Controller {
                     String strA = new String();
                     String strB = new String();
 
-                    String regEx="[\n`~!@#$%^&*()+=|{}':;',\\-_\\[\\].<>/?~!@#¥%……&*()——+|{}【】‘;:”“’。, 、?]";
+                    String regEx = "[\n`~!@#$%^&*()+=|{}':;',\\-_\\[\\].<>/?~!@#¥%……&*()——+|{}【】‘;:”“’。, 、?]";
 
                     String aStr = a.getStringValue(sortkeyname);
                     strA = aStr.replaceAll(regEx, "");
@@ -978,7 +974,7 @@ public class itemgroup extends Controller {
 
                     if ("0".equals(order)) {
                         return -strA.compareTo(strB);
-                    }else {
+                    } else {
                         return strA.compareTo(strB);
                     }