فهرست منبع

1、任务系数只在存货大类为集成灶时取,其他品类取默认1;
2、任务系数按季/年取,若没有取到则默认1
3、价格系数列表查询排除删除状态的数据,接口:2025020710553803

shenjingwei 1 هفته پیش
والد
کامیت
e27141b04e

+ 12 - 7
src/custom/common/crm/bean/saorder.java

@@ -11,9 +11,6 @@ import common.data.*;
 import org.apache.logging.log4j.Logger;
 
 import java.math.BigDecimal;
-import java.time.Year;
-import java.time.YearMonth;
-import java.time.temporal.IsoFields;
 
 public class saorder extends CrmBase {
     public saorder(Logger logger) {
@@ -58,10 +55,11 @@ public class saorder extends CrmBase {
                 long sys_enterpriseid = agentRows.get(0).getLong("sys_enterpriseid");
 
                 BigDecimal rwpricerate = new BigDecimal(1);
-                if (agentRows.get(0).getDouble("pricerate") > 0 && agentRows.get(0).getInteger("year") == Year.now().getValue() && agentRows.get(0).getInteger("quarter") == YearMonth.now().get(IsoFields.QUARTER_OF_YEAR)) {
+                int year = agentRows.get(0).getInteger("year");
+                int quarter = agentRows.get(0).getInteger("quarter");
+                if (year == getYear() && getQuarterOfYear() >= quarter && agentRows.get(0).getDouble("pricerate") > 0) {
                     rwpricerate = agentRows.get(0).getBigDecimal("pricerate");
                 }
-
                 Row enterprise = Enterprise.getEnterprise(controller, sys_enterpriseid);
 
                 Rows financeRows = dbConnect.runSqlQuery("select * from sys_enterprise_finance where siteid='MD' and sys_enterpriseid='" + sys_enterpriseid + "' and isdefault=1");
@@ -108,6 +106,7 @@ public class saorder extends CrmBase {
 
                     BigDecimal qty = detail.getBigDecimal("fqty");
                     long itemid = itemRows.get(0).getLong("itemid");
+                    String topclassnum = itemRows.get(0).getString("topclassnum");
                     ItemPrice itemPrice = ItemPrice.getItemPrice(controller, sys_enterpriseid, itemid);
                     InsertSQL orderitemInsert = SQLFactory.createInsertSQL(dbConnect, "sa_orderitems");
                     orderitemInsert.setValue("siteid", "MD");
@@ -125,7 +124,14 @@ public class saorder extends CrmBase {
                     orderitemInsert.setValue("undeliqty", qty.doubleValue());
                     orderitemInsert.setValue("saleprice", itemPrice.getGraderateprice().doubleValue());//销售单价
                     orderitemInsert.setValue("custamount", custamount.doubleValue());//客户档案资料费
-                    BigDecimal defaultprice = itemPrice.getGraderateprice().multiply(rwpricerate);
+
+                    BigDecimal defaultprice = itemPrice.getGraderateprice();
+                    if (topclassnum.equals("集成灶")) {
+                        defaultprice = defaultprice.multiply(rwpricerate);
+                        orderitemInsert.setValue("rwpricerate", rwpricerate.doubleValue());
+                    } else {
+                        orderitemInsert.setValue("rwpricerate", 1);
+                    }
                     orderitemInsert.setValue("defaultprice", defaultprice.doubleValue());//折前价(元)
                     orderitemInsert.setValue("defaultamount", defaultprice.multiply(qty).doubleValue());//折前金额(元)
                     orderitemInsert.setValue("marketprice", itemPrice.getMarketprice().doubleValue());//牌价(元)
@@ -137,7 +143,6 @@ public class saorder extends CrmBase {
                     orderitemInsert.setValue("spec", itemRows.get(0).getBoolean("spec"));
                     orderitemInsert.setValue("pricerate", itemPrice.getGradediscountrate().doubleValue());
 
-                    orderitemInsert.setValue("rwpricerate", rwpricerate.doubleValue());
                     orderitemInsert.setValue("delivery", detail.getStringValue("fsendmode"));
                     orderitemInsert.setValue("remarks", detail.getStringValue("fnotes"));
                     sqlDump.add(orderitemInsert);

+ 30 - 48
src/custom/restcontroller/sale/shoppingcart/ShoppingCart.java

@@ -15,9 +15,6 @@ import restcontroller.R;
 
 import java.io.IOException;
 import java.math.BigDecimal;
-import java.time.Year;
-import java.time.YearMonth;
-import java.time.temporal.IsoFields;
 import java.util.ArrayList;
 import java.util.HashMap;
 
@@ -52,10 +49,7 @@ public class ShoppingCart extends Controller {
         colors = colors.equals("0") ? "" : colors;
         material = material.equals("0") ? "" : material;
 
-        if (dbConnect.runSqlQuery("SELECT * from sa_shoppingcart " +
-                "WHERE ifnull(length,0)=" + length + " and ifnull(width,0)=" + width +
-                " and ifnull(colors,'') ='" + colors + "' and ifnull(cheek,'')='" + cheek + "' and ifnull(material,'')='" + material + "'" +
-                " and sa_promotionid=" + sa_promotionid + " and itemid = " + itemid + " and sys_enterpriseid=" + sys_enterpriseid + " and siteid='" + siteid + "'").isNotEmpty()) {
+        if (dbConnect.runSqlQuery("SELECT * from sa_shoppingcart " + "WHERE ifnull(length,0)=" + length + " and ifnull(width,0)=" + width + " and ifnull(colors,'') ='" + colors + "' and ifnull(cheek,'')='" + cheek + "' and ifnull(material,'')='" + material + "'" + " and sa_promotionid=" + sa_promotionid + " and itemid = " + itemid + " and sys_enterpriseid=" + sys_enterpriseid + " and siteid='" + siteid + "'").isNotEmpty()) {
 
             return getErrReturnObject().setErrMsg("商品【" + itemno + "】已添加至购物车,不能再次添加。").toString();
         }
@@ -67,12 +61,7 @@ public class ShoppingCart extends Controller {
 
         SQLFactory sqlFactory = new SQLFactory(this, "购物车新增");
         Long sa_shoppingcartid = 0L;
-        Rows rows = dbConnect.runSqlQuery("SELECT sa_shoppingcartid FROM sa_shoppingcart WHERE siteid = '" + siteid +
-                "' AND sa_brandid = " + sa_brandid +
-                " and length=" + length + " and width=" + width + " AND itemid = " + itemid +
-                " AND sys_enterpriseid = " + sys_enterpriseid +
-                " AND tradefield = '" + tradefield +
-                "' AND itemno = '" + itemno + "' and sa_promotionid=" + sa_promotionid);
+        Rows rows = dbConnect.runSqlQuery("SELECT sa_shoppingcartid FROM sa_shoppingcart WHERE siteid = '" + siteid + "' AND sa_brandid = " + sa_brandid + " and length=" + length + " and width=" + width + " AND itemid = " + itemid + " AND sys_enterpriseid = " + sys_enterpriseid + " AND tradefield = '" + tradefield + "' AND itemno = '" + itemno + "' and sa_promotionid=" + sa_promotionid);
         if (rows.isNotEmpty()) {
             sa_shoppingcartid = rows.get(0).getLong("sa_shoppingcartid");
         }
@@ -145,10 +134,7 @@ public class ShoppingCart extends Controller {
                 return getErrReturnObject().setErrMsg("商品【" + itemno + "】已售罄,不能添加。").toString();
             }
 
-            if (dbConnect.runSqlQuery("SELECT * from sa_shoppingcart " +
-                    "WHERE ifnull(length,0)=" + length + " and ifnull(width,0)=" + width +
-                    " and ifnull(colors,'') ='" + colors + "' and ifnull(cheek,'')='" + cheek + "' and ifnull(material,'')='" + material + "'" +
-                    " and sa_promotionid=" + sa_promotionid + " and itemid = " + itemid + " and sys_enterpriseid=" + sys_enterpriseid + " and siteid='" + siteid + "'").isNotEmpty()) {
+            if (dbConnect.runSqlQuery("SELECT * from sa_shoppingcart " + "WHERE ifnull(length,0)=" + length + " and ifnull(width,0)=" + width + " and ifnull(colors,'') ='" + colors + "' and ifnull(cheek,'')='" + cheek + "' and ifnull(material,'')='" + material + "'" + " and sa_promotionid=" + sa_promotionid + " and itemid = " + itemid + " and sys_enterpriseid=" + sys_enterpriseid + " and siteid='" + siteid + "'").isNotEmpty()) {
 
                 return getErrReturnObject().setErrMsg("商品【" + itemno + "】已添加至购物车,不能再次添加。").toString();
             }
@@ -156,12 +142,7 @@ public class ShoppingCart extends Controller {
 
             SQLFactory sqlFactory = new SQLFactory(this, "购物车新增");
             Long sa_shoppingcartid = 0L;
-            Rows rows = dbConnect.runSqlQuery("SELECT sa_shoppingcartid FROM sa_shoppingcart WHERE siteid = '" + siteid +
-                    "' AND sa_brandid = " + sa_brandid +
-                    " and length=" + length + " and width=" + width + " AND itemid = " + itemid +
-                    " AND sys_enterpriseid = " + sys_enterpriseid +
-                    " AND tradefield = '" + tradefield +
-                    "' AND itemno = '" + itemno + "' and sa_promotionid=" + sa_promotionid);
+            Rows rows = dbConnect.runSqlQuery("SELECT sa_shoppingcartid FROM sa_shoppingcart WHERE siteid = '" + siteid + "' AND sa_brandid = " + sa_brandid + " and length=" + length + " and width=" + width + " AND itemid = " + itemid + " AND sys_enterpriseid = " + sys_enterpriseid + " AND tradefield = '" + tradefield + "' AND itemno = '" + itemno + "' and sa_promotionid=" + sa_promotionid);
             if (rows.isNotEmpty()) {
                 sa_shoppingcartid = rows.get(0).getLong("sa_shoppingcartid");
             }
@@ -207,8 +188,8 @@ public class ShoppingCart extends Controller {
     public String updateQty() throws YosException {
         Long sa_shoppingcartid = content.getLong("sa_shoppingcartid");
         BigDecimal qty = content.getBigDecimal("qty");
-        if(qty.compareTo(BigDecimal.ZERO)==0){
-            qty=BigDecimal.valueOf(1);
+        if (qty.compareTo(BigDecimal.ZERO) == 0) {
+            qty = BigDecimal.valueOf(1);
         }
 
         BigDecimal length = content.getBigDecimal("length");
@@ -288,25 +269,22 @@ public class ShoppingCart extends Controller {
 //        String sql = sqlFactory.getSQL();
 //        Rows rows = dbConnect.runSqlQuery(sql);
 
-        QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_shoppingcart", "sa_shoppingcartid", "sa_brandid",
-                "itemid","itemno","sa_promotionid","sa_promotion_itemsid","qty","length","width","cheek","colors","material","","","");
+        QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_shoppingcart", "sa_shoppingcartid", "sa_brandid", "itemid", "itemno", "sa_promotionid", "sa_promotion_itemsid", "qty", "length", "width", "cheek", "colors", "material", "", "", "");
         querySQL.setTableAlias("t1");
-        querySQL.addJoinTable(JOINTYPE.left, "sa_brand", "t2", "t2.sa_brandid = t1.sa_brandid AND t2.siteid = t1.siteid","brandname");
-        querySQL.addJoinTable(JOINTYPE.left, "plm_item", "t3", "t3.itemid = t1.itemid AND t3.siteid = t1.siteid","itemname","model","spec"
-                ,"orderminqty","orderaddqty","orderminqty_auxunit","orderaddqty_auxunit","iscustomsize","pricingmetod","widthschemeid","lengthschemeid","materialschemeid"
-                ,"colorschemeid","cheekschemeid","sa_customschemeid","custamount");
-        querySQL.addJoinTable(JOINTYPE.left, "plm_unit", "t4", "t4.unitid = t3.unitid AND t4.siteid = t1.siteid","unitname");
-        querySQL.addJoinTable(JOINTYPE.left, "plm_unitgroup", "t5", "t5.unitgroupid = t3.unitgroupid AND t5.siteid = t1.siteid","unitgroupname");
+        querySQL.addJoinTable(JOINTYPE.left, "sa_brand", "t2", "t2.sa_brandid = t1.sa_brandid AND t2.siteid = t1.siteid", "brandname");
+        querySQL.addJoinTable(JOINTYPE.left, "plm_item", "t3", "t3.itemid = t1.itemid AND t3.siteid = t1.siteid", "topclassnum", "itemname", "model", "spec", "orderminqty", "orderaddqty", "orderminqty_auxunit", "orderaddqty_auxunit", "iscustomsize", "pricingmetod", "widthschemeid", "lengthschemeid", "materialschemeid", "colorschemeid", "cheekschemeid", "sa_customschemeid", "custamount");
+        querySQL.addJoinTable(JOINTYPE.left, "plm_unit", "t4", "t4.unitid = t3.unitid AND t4.siteid = t1.siteid", "unitname");
+        querySQL.addJoinTable(JOINTYPE.left, "plm_unitgroup", "t5", "t5.unitgroupid = t3.unitgroupid AND t5.siteid = t1.siteid", "unitgroupname");
         querySQL.addJoinTable(JOINTYPE.left, "plm_unit", "t6", "t6.unitid = t5.auxunitid AND t5.siteid = t1.siteid");
         querySQL.addJoinTable(JOINTYPE.left, "sa_promotion_items", "t7", "t7.sa_promotion_itemsid = t1.sa_promotion_itemsid AND t7.siteid = t1.siteid");
-        querySQL.addQueryFields("tradefield_shoppingcart","t1.tradefield");
-        querySQL.addQueryFields("auxunitname","t6.unitname");
-        querySQL.addQueryFields("packageqty","if(t1.sa_promotionid>0,ifnull(t7.packageqty,0),ifnull(t3.packageqty,0))");
+        querySQL.addQueryFields("tradefield_shoppingcart", "t1.tradefield");
+        querySQL.addQueryFields("auxunitname", "t6.unitname");
+        querySQL.addQueryFields("packageqty", "if(t1.sa_promotionid>0,ifnull(t7.packageqty,0),ifnull(t3.packageqty,0))");
 
         querySQL.setSiteid(siteid);
-        querySQL.setWhere("t3.istool",istool);
-        querySQL.setWhere("t1.sys_enterpriseid",sys_enterpriseid);
-        querySQL.setWhere("t1.sa_promotionid",content.getLongValue("sa_promotionid"));
+        querySQL.setWhere("t3.istool", istool);
+        querySQL.setWhere("t1.sys_enterpriseid", sys_enterpriseid);
+        querySQL.setWhere("t1.sa_promotionid", content.getLongValue("sa_promotionid"));
         querySQL.setWhere(where.toString());
         querySQL.setPage(pageSize, pageNumber);
         Rows rows = querySQL.query();
@@ -326,10 +304,12 @@ public class ShoppingCart extends Controller {
         CustomScheme customScheme = new CustomScheme(this);
 
         BigDecimal rwpricerate = new BigDecimal(1);
-        Rows custamountrows = dbConnect.runSqlQuery("select * from sa_agents where sys_enterpriseid=" + sys_enterpriseid + " and siteid='" + siteid + "'");
-        if (!custamountrows.isEmpty()) {
-            if (custamountrows.get(0).getBigDecimal("pricerate").compareTo(BigDecimal.ZERO) > 0) {
-                rwpricerate = custamountrows.get(0).getBigDecimal("pricerate");
+        Rows agentrows = dbConnect.runSqlQuery("select * from sa_agents where sys_enterpriseid=" + sys_enterpriseid + " and siteid='" + siteid + "'");
+        if (!agentrows.isEmpty()) {
+            int year = agentrows.get(0).getInteger("year");
+            int quarter = agentrows.get(0).getInteger("quarter");
+            if (getYear() == year && getQuarterOfYear() >= quarter && agentrows.get(0).getBigDecimal("pricerate").compareTo(BigDecimal.ZERO) > 0) {
+                rwpricerate = agentrows.get(0).getBigDecimal("pricerate");
             }
         }
         for (Row row : rows) {
@@ -348,12 +328,11 @@ public class ShoppingCart extends Controller {
                             row.put("orderminqty", promotionItemsByIdRowsMap.get(row.getString("sa_promotion_itemsid")).get(0).getBigDecimal("orderminqty"));
                             row.put("orderaddqty", promotionItemsByIdRowsMap.get(row.getString("sa_promotion_itemsid")).get(0).getBigDecimal("orderaddqty"));
                         }
-
                     }
                     if (row.getBoolean("iscustomsize") && row.getLong("pricingmetod") == 1) {
-                        row.put("gradeprice", itemPrice.getPromotionPrice(content.getLongValue("sa_promotionid"),row.getLong("sa_promotion_itemsid")).multiply(row.getBigDecimal("length").multiply(row.getBigDecimal("width")).divide(new BigDecimal("1000000"), 4, BigDecimal.ROUND_HALF_UP)));
+                        row.put("gradeprice", itemPrice.getPromotionPrice(content.getLongValue("sa_promotionid"), row.getLong("sa_promotion_itemsid")).multiply(row.getBigDecimal("length").multiply(row.getBigDecimal("width")).divide(new BigDecimal("1000000"), 4, BigDecimal.ROUND_HALF_UP)));
                     } else {
-                        row.put("gradeprice", itemPrice.getPromotionPrice(content.getLongValue("sa_promotionid"),row.getLong("sa_promotion_itemsid")));
+                        row.put("gradeprice", itemPrice.getPromotionPrice(content.getLongValue("sa_promotionid"), row.getLong("sa_promotion_itemsid")));
                     }
                 } else {
                     if (row.getBoolean("iscustomsize") && row.getLong("pricingmetod") == 1) {
@@ -363,9 +342,12 @@ public class ShoppingCart extends Controller {
                     }
                 }
                 row.put("defaultprice", row.getBigDecimal("gradeprice"));
-                row.put("gradeprice", row.getBigDecimal("gradeprice").multiply(rwpricerate).add(row.getBigDecimal("custamount")));
-
 
+                if ("集成灶".equals(row.getString("topclassnum"))) {
+                    row.put("gradeprice", row.getBigDecimal("gradeprice").multiply(rwpricerate).add(row.getBigDecimal("custamount")));
+                } else {
+                    row.put("gradeprice", row.getBigDecimal("gradeprice").add(row.getBigDecimal("custamount")));
+                }
 //                row.put("gradeprice", istool == 0 ?itemPrice.getContractprice():itemPrice.getMarketprice());
             } catch (Exception e) {
                 e.printStackTrace();

+ 37 - 38
src/custom/restcontroller/webmanage/sale/item/quarterpricenum.java

@@ -36,7 +36,7 @@ public class quarterpricenum extends Controller {
         Long sa_agentsid = content.getLongValue("sa_agentsid");
         Long quarter = content.getLongValue("quarter");
         BigDecimal pricerate = content.getBigDecimal("pricerate");
-        if (sa_quarterpricenumid <= 0 || dbConnect.runSqlQuery("select * from sa_quarterpricenum where sa_quarterpricenumid="+sa_quarterpricenumid).isEmpty()) {
+        if (sa_quarterpricenumid <= 0 || dbConnect.runSqlQuery("select * from sa_quarterpricenum where sa_quarterpricenumid=" + sa_quarterpricenumid).isEmpty()) {
             sa_quarterpricenumid = createTableID(tableName);
             InsertSQL insertSQL = SQLFactory.createInsertSQL(this, tableName);
             insertSQL.setUniqueid(sa_quarterpricenumid).setSiteid(siteid);
@@ -52,9 +52,9 @@ public class quarterpricenum extends Controller {
             insertSQL.setValue("changeby", username);
             sqlList.add(insertSQL.getSQL());
             sqlList.add(DataContrlLog.createLog(this, tableName, sa_quarterpricenumid, "新增", "季度价格系数新增成功").getSQL());
-        } else{
-            Rows rows = dbConnect.runSqlQuery("select * from sa_quarterpricenum where sa_quarterpricenumid="+sa_quarterpricenumid);
-            if(rows.isNotEmpty() && rows.get(0).getString("status").equals("新建")){
+        } else {
+            Rows rows = dbConnect.runSqlQuery("select * from sa_quarterpricenum where sa_quarterpricenumid=" + sa_quarterpricenumid);
+            if (rows.isNotEmpty() && rows.get(0).getString("status").equals("新建")) {
                 UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, tableName);
                 updateSQL.setUniqueid(sa_quarterpricenumid).setSiteid(siteid);
                 updateSQL.setValue("year", year);
@@ -65,7 +65,7 @@ public class quarterpricenum extends Controller {
                 updateSQL.setValue("changeby", username);
                 sqlList.add(updateSQL.getSQL());
                 sqlList.add(DataContrlLog.createLog(this, tableName, sa_quarterpricenumid, "编辑", "季度价格系数编辑成功").getSQL());
-            }else{
+            } else {
                 return getErrReturnObject().setErrMsg("非新建状态的季度价格系数无法更新").toString();
             }
 
@@ -105,10 +105,11 @@ public class quarterpricenum extends Controller {
 //        Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL());
         QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_quarterpricenum");
         querySQL.setTableAlias("t1");
-        querySQL.addJoinTable(JOINTYPE.inner, "sa_agents", "t2", "t1.siteid = t2.siteid and t1.sa_agentsid = t2.sa_agentsid","agentnum");
-        querySQL.addJoinTable(JOINTYPE.inner, "sys_enterprise", "t3", "t3.siteid = t2.siteid and t3.sys_enterpriseid = t2.sys_enterpriseid","enterprisename");
+        querySQL.addJoinTable(JOINTYPE.inner, "sa_agents", "t2", "t1.siteid = t2.siteid and t1.sa_agentsid = t2.sa_agentsid", "agentnum");
+        querySQL.addJoinTable(JOINTYPE.inner, "sys_enterprise", "t3", "t3.siteid = t2.siteid and t3.sys_enterpriseid = t2.sys_enterpriseid", "enterprisename");
         querySQL.setSiteid(siteid);
         querySQL.setWhere(where.toString());
+        querySQL.setWhere("t1.status!='删除'");
         querySQL.setOrderBy("t1.createdate desc");
         querySQL.setPage(pageSize, pageNumber);
         Rows rows = querySQL.query();
@@ -120,10 +121,10 @@ public class quarterpricenum extends Controller {
     public String queryquarterpricenumMain() throws YosException {
         QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_quarterpricenum");
         querySQL.setTableAlias("t1");
-        querySQL.addJoinTable(JOINTYPE.inner, "sa_agents", "t2", "t1.siteid = t2.siteid and t1.sa_agentsid = t2.sa_agentsid","agentnum");
-        querySQL.addJoinTable(JOINTYPE.inner, "sys_enterprise", "t3", "t3.siteid = t2.siteid and t3.sys_enterpriseid = t2.sys_enterpriseid","enterprisename");
+        querySQL.addJoinTable(JOINTYPE.inner, "sa_agents", "t2", "t1.siteid = t2.siteid and t1.sa_agentsid = t2.sa_agentsid", "agentnum");
+        querySQL.addJoinTable(JOINTYPE.inner, "sys_enterprise", "t3", "t3.siteid = t2.siteid and t3.sys_enterpriseid = t2.sys_enterpriseid", "enterprisename");
         querySQL.setSiteid(siteid);
-        querySQL.setWhere("sa_quarterpricenumid",content.getLongValue("sa_quarterpricenumid"));
+        querySQL.setWhere("sa_quarterpricenumid", content.getLongValue("sa_quarterpricenumid"));
         Rows rows = querySQL.query();
         return getSucReturnObject().setData(rows).toString();
     }
@@ -131,13 +132,13 @@ public class quarterpricenum extends Controller {
     @API(title = "检查", apiversion = R.ID2025020711080903.v1.class)
     @CACHEING_CLEAN(apiClass = {quarterpricenum.class})
     public String check() throws YosException {
-        Rows rows = dbConnect.runSqlQuery("select * from sa_quarterpricenum where status='新建' and siteid='"+siteid+"'");
-        Rows agentRows = dbConnect.runSqlQuery("select sa_agentsid,year,quarter,pricerate from sa_agents where siteid='"+siteid+"' and sa_agentsid in (select sa_agentsid from sa_quarterpricenum where status='新建' and siteid='"+siteid+"')");
+        Rows rows = dbConnect.runSqlQuery("select * from sa_quarterpricenum where status='新建' and siteid='" + siteid + "'");
+        Rows agentRows = dbConnect.runSqlQuery("select sa_agentsid,year,quarter,pricerate from sa_agents where siteid='" + siteid + "' and sa_agentsid in (select sa_agentsid from sa_quarterpricenum where status='新建' and siteid='" + siteid + "')");
         RowsMap agentRowsMap = agentRows.toRowsMap("sa_agentsid");
         ArrayList<String> sqlList = new ArrayList<>();
-        for(Row row :rows){
-            if(agentRowsMap.containsKey(row.getString("sa_agentsid"))){
-                if(row.getBigDecimal("pricerate").compareTo(BigDecimal.ZERO)<=0){
+        for (Row row : rows) {
+            if (agentRowsMap.containsKey(row.getString("sa_agentsid"))) {
+                if (row.getBigDecimal("pricerate").compareTo(BigDecimal.ZERO) <= 0) {
                     UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sa_quarterpricenum");
                     updateSQL.setUniqueid(row.getLong("sa_quarterpricenumid")).setSiteid(siteid);
                     updateSQL.setValue("ischeck", true);
@@ -148,26 +149,26 @@ public class quarterpricenum extends Controller {
                     updateSQL.setDateValue("operatedate");
                     updateSQL.setValue("changeby", username);
                     sqlList.add(updateSQL.getSQL());
-                }else{
-                    if(agentRowsMap.get(row.getString("sa_agentsid")).get(0).getLong("year")==row.getLong("year") &&
-                            agentRowsMap.get(row.getString("sa_agentsid")).get(0).getLong("quarter")==row.getLong("quarter") &&
-                            agentRowsMap.get(row.getString("sa_agentsid")).get(0).getBigDecimal("pricerate").compareTo(row.getBigDecimal("pricerate"))==0){
+                } else {
+                    if (agentRowsMap.get(row.getString("sa_agentsid")).get(0).getLong("year") == row.getLong("year") &&
+                            agentRowsMap.get(row.getString("sa_agentsid")).get(0).getLong("quarter") == row.getLong("quarter") &&
+                            agentRowsMap.get(row.getString("sa_agentsid")).get(0).getBigDecimal("pricerate").compareTo(row.getBigDecimal("pricerate")) == 0) {
                         UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sa_quarterpricenum");
                         updateSQL.setUniqueid(row.getLong("sa_quarterpricenumid")).setSiteid(siteid);
                         updateSQL.setValue("ischeck", true);
                         updateSQL.setValue("isright", false);
-                        updateSQL.setValue("result", "原有系数:" +  (agentRowsMap.get(row.getString("sa_agentsid")).get(0).getBigDecimal("pricerate").compareTo(BigDecimal.ZERO)==0?1:agentRowsMap.get(row.getString("sa_agentsid")).get(0).getBigDecimal("pricerate"))+ " , 待导入系数:" + row.getBigDecimal("pricerate"));
+                        updateSQL.setValue("result", "原有系数:" + (agentRowsMap.get(row.getString("sa_agentsid")).get(0).getBigDecimal("pricerate").compareTo(BigDecimal.ZERO) == 0 ? 1 : agentRowsMap.get(row.getString("sa_agentsid")).get(0).getBigDecimal("pricerate")) + " , 待导入系数:" + row.getBigDecimal("pricerate"));
                         updateSQL.setValue("status", "已检验");
                         updateSQL.setDateValue("changedate");
                         updateSQL.setDateValue("operatedate");
                         updateSQL.setValue("changeby", username);
                         sqlList.add(updateSQL.getSQL());
-                    }else{
+                    } else {
                         UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sa_quarterpricenum");
                         updateSQL.setUniqueid(row.getLong("sa_quarterpricenumid")).setSiteid(siteid);
                         updateSQL.setValue("ischeck", true);
                         updateSQL.setValue("isright", true);
-                        updateSQL.setValue("result", "原有系数:" +  (agentRowsMap.get(row.getString("sa_agentsid")).get(0).getBigDecimal("pricerate").compareTo(BigDecimal.ZERO)==0?1:agentRowsMap.get(row.getString("sa_agentsid")).get(0).getBigDecimal("pricerate"))+ " , 待导入系数:" + row.getBigDecimal("pricerate"));
+                        updateSQL.setValue("result", "原有系数:" + (agentRowsMap.get(row.getString("sa_agentsid")).get(0).getBigDecimal("pricerate").compareTo(BigDecimal.ZERO) == 0 ? 1 : agentRowsMap.get(row.getString("sa_agentsid")).get(0).getBigDecimal("pricerate")) + " , 待导入系数:" + row.getBigDecimal("pricerate"));
                         updateSQL.setValue("status", "已检验");
                         updateSQL.setDateValue("changedate");
                         updateSQL.setDateValue("operatedate");
@@ -176,7 +177,7 @@ public class quarterpricenum extends Controller {
                     }
                 }
 
-            }else{
+            } else {
                 UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sa_quarterpricenum");
                 updateSQL.setUniqueid(row.getLong("sa_quarterpricenumid")).setSiteid(siteid);
                 updateSQL.setValue("ischeck", true);
@@ -194,13 +195,13 @@ public class quarterpricenum extends Controller {
     }
 
     @API(title = "更新经销商季度价格系数", apiversion = R.ID2025020713110003.v1.class)
-    @CACHEING_CLEAN(apiClass = {Item.class, restcontroller.sale.item.Item.class,quarterpricenum.class})
+    @CACHEING_CLEAN(apiClass = {Item.class, restcontroller.sale.item.Item.class, quarterpricenum.class})
     public String UpdateQuarterPriceNum() throws YosException {
-        Rows rows = dbConnect.runSqlQuery("select * from sa_quarterpricenum where status='已检验' and ischeck=1 and isright=1 and siteid='"+siteid+"'");
+        Rows rows = dbConnect.runSqlQuery("select * from sa_quarterpricenum where status='已检验' and ischeck=1 and isright=1 and siteid='" + siteid + "'");
         ArrayList<String> sqlList = new ArrayList<>();
-        for(Row row :rows){
-            sqlList.add("update sa_agents set year="+row.getLong("year")+",quarter="+row.getLong("quarter")+",pricerate="+row.getBigDecimal("pricerate")+" where sa_agentsid="+row.getLong("sa_agentsid"));
-            sqlList.add("update sa_quarterpricenum set  status='已更新' where sa_quarterpricenumid="+row.getLong("sa_quarterpricenumid"));
+        for (Row row : rows) {
+            sqlList.add("update sa_agents set year=" + row.getLong("year") + ",quarter=" + row.getLong("quarter") + ",pricerate=" + row.getBigDecimal("pricerate") + " where sa_agentsid=" + row.getLong("sa_agentsid"));
+            sqlList.add("update sa_quarterpricenum set  status='已更新' where sa_quarterpricenumid=" + row.getLong("sa_quarterpricenumid"));
         }
         dbConnect.runSqlUpdate(sqlList);
         return getSucReturnObject().toString();
@@ -228,7 +229,6 @@ public class quarterpricenum extends Controller {
     }
 
 
-
     @API(title = "下载导入模板", apiversion = R.ID2025020713403803.v1.class)
     @CACHEING_CLEAN(apiClass = {quarterpricenum.class})
     public String downloadExcel() throws YosException {
@@ -261,8 +261,6 @@ public class quarterpricenum extends Controller {
     }
 
 
-
-
     @API(title = "季度价格系数导入", apiversion = R.ID2025020713405203.v1.class)
     @CACHEING_CLEAN(apiClass = {quarterpricenum.class})
     public String importQuarterpricenum() throws YosException {
@@ -302,19 +300,19 @@ public class quarterpricenum extends Controller {
                     rowserr.add(row);
                     continue;
                 }
-                if(!isNumeric(row.getString("year"))){
+                if (!isNumeric(row.getString("year"))) {
                     iserr = true;
                     row.put("msg", "年份不为数字格式,请检查");
                     rowserr.add(row);
                     continue;
                 }
-                if(!isNumeric(row.getString("quarter"))){
+                if (!isNumeric(row.getString("quarter"))) {
                     iserr = true;
                     row.put("msg", "季度不为数字格式,请检查");
                     rowserr.add(row);
                     continue;
                 }
-                if(!isNumeric(row.getString("pricerate"))){
+                if (!isNumeric(row.getString("pricerate"))) {
                     iserr = true;
                     row.put("msg", "价格系数不为数字格式,请检查");
                     rowserr.add(row);
@@ -338,14 +336,14 @@ public class quarterpricenum extends Controller {
             }
 
             if (!rowssuc.isEmpty()) {
-                for(Row row : rowssuc){
+                for (Row row : rowssuc) {
                     long sa_quarterpricenumid = createTableID("sa_quarterpricenum");
                     InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sa_quarterpricenum");
                     insertSQL.setUniqueid(sa_quarterpricenumid).setSiteid(siteid);
                     insertSQL.setValue("year", row.getString("year"));
-                    insertSQL.setValue("sa_agentsid",  row.getString("sa_agentsid"));
-                    insertSQL.setValue("quarter",  row.getString("quarter"));
-                    insertSQL.setValue("pricerate",  row.getString("pricerate"));
+                    insertSQL.setValue("sa_agentsid", row.getString("sa_agentsid"));
+                    insertSQL.setValue("quarter", row.getString("quarter"));
+                    insertSQL.setValue("pricerate", row.getString("pricerate"));
                     insertSQL.setValue("status", "新建");
                     insertSQL.setDateValue("operatedate");
                     insertSQL.setDateValue("createdate");
@@ -448,6 +446,7 @@ public class quarterpricenum extends Controller {
         }
         return sheet;
     }
+
     public static boolean isNumeric(String strNum) {
         if (strNum == null) {
             return false;

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

@@ -24,9 +24,6 @@ import utility.ERPDocking;
 import java.io.IOException;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
-import java.time.Year;
-import java.time.YearMonth;
-import java.time.temporal.IsoFields;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.HashMap;
@@ -75,7 +72,7 @@ public class OrderItems extends Controller {
         RowsMap itemRowsMap = orderItemsHelper.getItemRowsMap(items);
 
         BigDecimal sumqty = BigDecimal.ZERO;
-        ArrayList<Long> sa_orderitemsids_insert =new ArrayList<>();
+        ArrayList<Long> sa_orderitemsids_insert = new ArrayList<>();
         for (Object obj : items) {
 
             JSONObject item = (JSONObject) obj;
@@ -145,21 +142,21 @@ public class OrderItems extends Controller {
             defaultprice = price;
             if (isInsert) {
                 sa_orderitemsids_insert.add(sa_orderitemsid);
-                sqlList.add(orderItemsHelper.getInsertSQL(customproperties, sa_orderitemsid, item, itemRow, type, defaultprice, price, saleprice, itemPrice.getMarketprice(), "", new Rows(), 0, 0, BigDecimal.ZERO, BigDecimal.valueOf(1),  BigDecimal.valueOf(1)).getSQL());
+                sqlList.add(orderItemsHelper.getInsertSQL(customproperties, sa_orderitemsid, item, itemRow, type, defaultprice, price, saleprice, itemPrice.getMarketprice(), "", new Rows(), 0, 0, BigDecimal.ZERO, BigDecimal.valueOf(1), BigDecimal.valueOf(1)).getSQL());
                 if (item.getLongValue("sa_workorderid") != 0) {
                     sqlList.add("update sa_workorder_node_items set sourceid=" + sa_orderid + ",sourcetable='sa_order' where sa_workorderid=" + item.getLongValue("sa_workorderid") + " and itemid=" + item.getLong("itemid"));
                 }
             } else {
-                Rows itemidRows =  dbConnect.runSqlQuery("select itemid from sa_orderitems where sa_orderitemsid="+sa_orderitemsid);
+                Rows itemidRows = dbConnect.runSqlQuery("select itemid from sa_orderitems where sa_orderitemsid=" + sa_orderitemsid);
                 price = item.getBigDecimal("price");
-                defaultprice=item.getBigDecimal("defaultprice");
-                if(itemidRows.isNotEmpty()){
-                    if(itemidRows.get(0).getLong("itemid")!=itemid){
+                defaultprice = item.getBigDecimal("defaultprice");
+                if (itemidRows.isNotEmpty()) {
+                    if (itemidRows.get(0).getLong("itemid") != itemid) {
                         defaultprice = orderItemsHelper.getPrice(orderRows.get(0), itemPrice, item);
-                        price=orderItemsHelper.getPrice(orderRows.get(0), itemPrice, item);
+                        price = orderItemsHelper.getPrice(orderRows.get(0), itemPrice, item);
                     }
                 }
-                sqlList.add(orderItemsHelper.getUpdateSQL(sa_orderitemsid, item, itemRow, type, defaultprice, price, saleprice, 0,0).getSQL());
+                sqlList.add(orderItemsHelper.getUpdateSQL(sa_orderitemsid, item, itemRow, type, defaultprice, price, saleprice, 0, 0).getSQL());
 //                if(StringUtils.isNotBlank(item.getStringValue("cardno"))){
 //                    Rows aftersalesbomrows = dbConnect.runSqlQuery("select t2.sa_aftersalesbomid from sa_warrantycard t1 inner join sa_aftersalesbom_items t2 on t1.itemid=t2.itemid inner join sa_aftersalesbom t3 on t2.sa_aftersalesbomid=t3.sa_aftersalesbomid where t1.cardno='"+item.getStringValue("cardno")+"' and t3.status='审核'");
 //                    if(aftersalesbomrows.isNotEmpty()){
@@ -184,14 +181,12 @@ public class OrderItems extends Controller {
         //更新订单扣款信息
         updateAccountclassinfos(sa_orderid);
 
-        if(type.equals("配件订单")){
-            dbConnect.runSqlUpdate("UPDATE sa_order o JOIN (SELECT  sa_orderid,GROUP_CONCAT(DISTINCT delivery SEPARATOR '+') AS delivery FROM sa_orderitems where sa_orderid="+sa_orderid+" GROUP BY sa_orderid) od ON o.sa_orderid = od.sa_orderid SET  o.delivery = od.delivery ");
+        if (type.equals("配件订单")) {
+            dbConnect.runSqlUpdate("UPDATE sa_order o JOIN (SELECT  sa_orderid,GROUP_CONCAT(DISTINCT delivery SEPARATOR '+') AS delivery FROM sa_orderitems where sa_orderid=" + sa_orderid + " GROUP BY sa_orderid) od ON o.sa_orderid = od.sa_orderid SET  o.delivery = od.delivery ");
         }
-        sqlList=new ArrayList<>();
+        sqlList = new ArrayList<>();
         if (type.equals("配件订单")) {
-            Rows rowsdetails = dbConnect.runSqlQuery("select t1.price,t1.amount,t1.sa_orderitemsid,t1.itemid,ifnull(t2.iswriteoff,0) iswriteoff,t3.begdate,t3.enddate from sa_orderitems t1 " +
-                    "left join plm_item t2 on t1.itemid=t2.itemid and t1.siteid=t2.siteid " +
-                    "left join sa_warrantycard t3 on t1.cardno=t3.cardno and t1.siteid=t3.siteid and t3.isvoid=0 and t3.deleted=0 where t1.sa_orderid=" + sa_orderid);
+            Rows rowsdetails = dbConnect.runSqlQuery("select t1.price,t1.amount,t1.sa_orderitemsid,t1.itemid,ifnull(t2.iswriteoff,0) iswriteoff,t3.begdate,t3.enddate from sa_orderitems t1 " + "left join plm_item t2 on t1.itemid=t2.itemid and t1.siteid=t2.siteid " + "left join sa_warrantycard t3 on t1.cardno=t3.cardno and t1.siteid=t3.siteid and t3.isvoid=0 and t3.deleted=0 where t1.sa_orderid=" + sa_orderid);
             for (Row rowsdetail : rowsdetails) {
                 String billingstatus = "";
                 BigDecimal price = rowsdetail.getBigDecimal("price");
@@ -207,18 +202,18 @@ public class OrderItems extends Controller {
                             billingstatus = "保内收费";
                         } else {
                             billingstatus = "保内免费";
-                            if(sa_orderitemsids_insert.contains(rowsdetail.getLong("sa_orderitemsid"))){
+                            if (sa_orderitemsids_insert.contains(rowsdetail.getLong("sa_orderitemsid"))) {
                                 price = BigDecimal.ZERO;
                                 amount = BigDecimal.ZERO;
                             }
 
                         }
-                    }else{
+                    } else {
                         billingstatus = "保外收费";
                     }
                 }
-                if(!billingstatus.equals("保内收费") ){
-                    if(sa_orderitemsids_insert.contains(rowsdetail.getLong("sa_orderitemsid"))){
+                if (!billingstatus.equals("保内收费")) {
+                    if (sa_orderitemsids_insert.contains(rowsdetail.getLong("sa_orderitemsid"))) {
                         sqlList.add("update sa_orderitems set canoffqty=0 where sa_orderitemsid=" + rowsdetail.getLong("sa_orderitemsid"));
                     }
 
@@ -364,10 +359,13 @@ public class OrderItems extends Controller {
             custamount = item.getBigDecimal("custamount");
 //            int year = Year.now().getValue();
 //            int quarter = YearMonth.now().get(IsoFields.QUARTER_OF_YEAR);
-            Rows custamountrows = dbConnect.runSqlQuery("select * from sa_agents where sys_enterpriseid=" + sys_enterpriseid + " and siteid='" + siteid + "'");
-            if (custamountrows.isNotEmpty() && !type.equals("配件订单")) {
-                if (custamountrows.get(0).getDouble("pricerate") > 0) {
-                    rwpricerate = custamountrows.get(0).getBigDecimal("pricerate");
+            Rows agentrows = dbConnect.runSqlQuery("select * from sa_agents where sys_enterpriseid=" + sys_enterpriseid + " and siteid='" + siteid + "'");
+            Rows itemrows = dbConnect.runSqlQuery("select topclassnum from plm_item where itemid=" + itemid + " and siteid='" + siteid + "'");
+            if (agentrows.isNotEmpty() && !type.equals("配件订单")) {
+                int year = agentrows.get(0).getInteger("year");
+                int quarter = agentrows.get(0).getInteger("quarter");
+                if (getYear() == year && getQuarterOfYear() >= quarter && "集成灶".equals(itemrows.get(0).getString("topclassnum")) && agentrows.get(0).getDouble("pricerate") > 0) {
+                    rwpricerate = agentrows.get(0).getBigDecimal("pricerate");
                 }
             }
 
@@ -388,8 +386,8 @@ public class OrderItems extends Controller {
                 }
             } else {
                 price = price.multiply(rwpricerate).add(item.getBigDecimal("custamount"));
-                if(item.containsKey("defaultprice")){
-                    defaultprice=item.getBigDecimal("defaultprice");
+                if (item.containsKey("defaultprice")) {
+                    defaultprice = item.getBigDecimal("defaultprice");
                     price = defaultprice.multiply(rwpricerate).add(custamount);
                 }
                 sqlList.add(orderItemsHelper.getUpdateSQL(sa_orderitemsid, item, itemRow, type, defaultprice, price, saleprice, width, length).getSQL());
@@ -443,9 +441,7 @@ public class OrderItems extends Controller {
         }
         sqlList = new ArrayList<>();
         if (type.equals("配件订单")) {
-            Rows rowsdetails = dbConnect.runSqlQuery("select t1.price,t1.amount,t1.sa_orderitemsid,t1.itemid,ifnull(t2.iswriteoff,0) iswriteoff,t3.begdate,t3.enddate from sa_orderitems t1 " +
-                    "left join plm_item t2 on t1.itemid=t2.itemid and t1.siteid=t2.siteid " +
-                    "left join sa_warrantycard t3 on t1.cardno=t3.cardno and t1.siteid=t3.siteid and t3.isvoid=0 and t3.deleted=0 where t1.sa_orderid=" + sa_orderid);
+            Rows rowsdetails = dbConnect.runSqlQuery("select t1.price,t1.amount,t1.sa_orderitemsid,t1.itemid,ifnull(t2.iswriteoff,0) iswriteoff,t3.begdate,t3.enddate from sa_orderitems t1 " + "left join plm_item t2 on t1.itemid=t2.itemid and t1.siteid=t2.siteid " + "left join sa_warrantycard t3 on t1.cardno=t3.cardno and t1.siteid=t3.siteid and t3.isvoid=0 and t3.deleted=0 where t1.sa_orderid=" + sa_orderid);
             for (Row rowsdetail : rowsdetails) {
                 String billingstatus = "";
                 BigDecimal price = rowsdetail.getBigDecimal("price");
@@ -489,11 +485,11 @@ public class OrderItems extends Controller {
 
     @API(title = "一键设置发货方式", apiversion = R.ID2025121316011603.v1.class)
     public String oneclickchangedelivery() throws YosException {
-        String delivery= content.getString("delivery");
-        long sa_orderid= content.getLong("sa_orderid");
+        String delivery = content.getString("delivery");
+        long sa_orderid = content.getLong("sa_orderid");
         ArrayList<String> sqlList = new ArrayList<>();
-        sqlList.add("update sa_orderitems set delivery='"+delivery+"' where sa_orderid="+sa_orderid);
-        sqlList.add("update sa_order set delivery='"+delivery+"' where sa_orderid="+sa_orderid);
+        sqlList.add("update sa_orderitems set delivery='" + delivery + "' where sa_orderid=" + sa_orderid);
+        sqlList.add("update sa_order set delivery='" + delivery + "' where sa_orderid=" + sa_orderid);
         dbConnect.runSqlUpdate(sqlList);
         return getSucReturnObject().toString();
     }
@@ -1343,7 +1339,7 @@ public class OrderItems extends Controller {
         itemquery.setSiteid(siteid);
         itemquery.setCondition("t1.itemno", "t1.itemname", "t1.model", "t1.spec", "t1.standards", "t3.material", "t3.erpitemno");
         itemquery.setWhere("status", "审核");
-        if(!ismanage){
+        if (!ismanage) {
             itemquery.setWhere("t1.isonsale=1 and t1.isused=1");
         }
         itemquery.setWhere("t1.ismodule=0");
@@ -1665,8 +1661,7 @@ public class OrderItems extends Controller {
                     sqlList.add("delete from  sa_accountbalance_freez where sa_accountbalance_freezid=" + freezRow.getLong("sa_accountbalance_freezid"));
                 }
             }
-            sqlList.add(DataContrlLog.createLog(this, "sa_order", sa_orderid, "关闭", "行" + rowsdetails.toJsonArray("rowno") + "关闭成功")
-                    .getSQL());
+            sqlList.add(DataContrlLog.createLog(this, "sa_order", sa_orderid, "关闭", "行" + rowsdetails.toJsonArray("rowno") + "关闭成功").getSQL());
         } else {
             if (freezRow == null) {
                 Rows accountbalanceRows = dbConnect.runSqlQuery("select * from sa_accountbalance where sys_enterpriseid=" + row.getLong("sys_enterpriseid") + " and sa_accountclassid=" + row.getLong("sa_accountclassid"));
@@ -1691,8 +1686,7 @@ public class OrderItems extends Controller {
                 sqlList.add("update sa_accountbalance_freez set amount=" + amount.add(returnamount) + " where sa_accountbalance_freezid=" + freezRow.getLong("sa_accountbalance_freezid"));
                 sqlList.add("update sa_accountbalance set freezamount=freezamount+" + returnamount + " where sa_accountbalanceid=" + freezRow.getLong("sa_accountbalanceid"));
             }
-            sqlList.add(DataContrlLog.createLog(this, "sa_order", sa_orderid, "反关闭", "行" + rowsdetails.toJsonArray("rowno") + "反关闭成功")
-                    .getSQL());
+            sqlList.add(DataContrlLog.createLog(this, "sa_order", sa_orderid, "反关闭", "行" + rowsdetails.toJsonArray("rowno") + "反关闭成功").getSQL());
         }
         /******** 增加总仓可销售量 ********/
         if (isclose) {
@@ -1700,17 +1694,14 @@ public class OrderItems extends Controller {
         } else {
             sqlList.addAll(updateIcinvbal_sale(rowsdetails, false, true));
         }
-        int i=dbConnect.runSqlUpdate(sqlList);
-        if(i>=0){
+        int i = dbConnect.runSqlUpdate(sqlList);
+        if (i >= 0) {
             if (isclose) {
-                if(dbConnect.runSqlQuery("select * from sa_orderitems where isclose=0 and undeliqty!=0 and sa_orderid="+sa_orderid).isEmpty()){
-                    dbConnect.runSqlUpdate("update sa_order set status='关闭',closeby='"+username+"',closedate=CURRENT_TIME where sa_orderid=" +sa_orderid);
+                if (dbConnect.runSqlQuery("select * from sa_orderitems where isclose=0 and undeliqty!=0 and sa_orderid=" + sa_orderid).isEmpty()) {
+                    dbConnect.runSqlUpdate("update sa_order set status='关闭',closeby='" + username + "',closedate=CURRENT_TIME where sa_orderid=" + sa_orderid);
                     Rows accountbalancerows = dbConnect.runSqlQuery("select * from  sa_accountbalance t1 inner join sa_accountclass t2 on  t1.sa_accountclassid=t2.sa_accountclassid and t1.siteid=t2.siteid where t2.accountname='现金账户' and t1.sys_enterpriseid=" + row.getLong("sys_enterpriseid"));
-                    dbConnect.runSqlUpdate("UPDATE sa_accountbalance t1 " +
-                            "INNER JOIN sa_accountbalance_freez t2 ON t1.sa_accountbalanceid = t2.sa_accountbalanceid " +
-                            "SET t1.freezamount = case when ifnull(t1.freezamount,0)>t2.amount then t1.freezamount-t2.amount else 0 end " +
-                            "WHERE t1.sa_accountbalanceid="+accountbalancerows.get(0).getLong("sa_accountbalanceid")+" and t2.sourcetable='sa_order' and t2.sourceid="+sa_orderid);
-                    dbConnect.runSqlUpdate("delete from sa_accountbalance_freez t1 WHERE t1.sourcetable='sa_order' and t1.sourceid="+sa_orderid);
+                    dbConnect.runSqlUpdate("UPDATE sa_accountbalance t1 " + "INNER JOIN sa_accountbalance_freez t2 ON t1.sa_accountbalanceid = t2.sa_accountbalanceid " + "SET t1.freezamount = case when ifnull(t1.freezamount,0)>t2.amount then t1.freezamount-t2.amount else 0 end " + "WHERE t1.sa_accountbalanceid=" + accountbalancerows.get(0).getLong("sa_accountbalanceid") + " and t2.sourcetable='sa_order' and t2.sourceid=" + sa_orderid);
+                    dbConnect.runSqlUpdate("delete from sa_accountbalance_freez t1 WHERE t1.sourcetable='sa_order' and t1.sourceid=" + sa_orderid);
                 }
             } else {
                 dbConnect.runSqlUpdate("update sa_order set status='审核',closeby='',closedate=null where sa_orderid=" + sa_orderid);
@@ -1718,7 +1709,6 @@ public class OrderItems extends Controller {
         }
 
 
-
         return getSucReturnObject().toString();
     }
 
@@ -1746,17 +1736,14 @@ public class OrderItems extends Controller {
             int rownum = row.getInteger("rowno");
             if (isclose) {
                 if (row.getBoolean("isclose")) {
-                    throw new YosException("行" + rownum
-                            + "已经关闭,不可重复关闭");
+                    throw new YosException("行" + rownum + "已经关闭,不可重复关闭");
                 }
                 if (row.getBigDecimal("undeliqty").compareTo(BigDecimal.ZERO) == 0) {
-                    throw new YosException("行" + rownum
-                            + "已发货完毕,不可关闭");
+                    throw new YosException("行" + rownum + "已发货完毕,不可关闭");
                 }
 
                 if (rowsMap.containsKey(row.getString("sa_orderitemsid"))) {
-                    throw new YosException("行" + rownum
-                            + "存在新建的销售出库单,不可关闭");
+                    throw new YosException("行" + rownum + "存在新建的销售出库单,不可关闭");
                 }
 //                if (saorderdetail.getPao(i).getPaoSet("SAINVOICEDETAIL")
 //                        .count() > 0) {
@@ -1765,12 +1752,10 @@ public class OrderItems extends Controller {
 //                }
             } else {
                 if (!row.getBoolean("isclose")) {
-                    throw new YosException("行" + rownum
-                            + "未关闭,不可取消关闭");
+                    throw new YosException("行" + rownum + "未关闭,不可取消关闭");
                 }
                 if (row.getDouble("undeliqty") == 0) {
-                    throw new YosException("行" + rownum
-                            + "已发货完毕,不可取消关闭");
+                    throw new YosException("行" + rownum + "已发货完毕,不可取消关闭");
                 }
             }
         }
@@ -1864,8 +1849,7 @@ public class OrderItems extends Controller {
             if (close) {
                 qty = isinstock ? row.getBigDecimal("undeliqty") : row.getBigDecimal("undeliqty").negate();// 如果是扣减则根据数量进行扣减,反之根据未发货数量进行增加
             } else {
-                qty = isinstock ? row.getBigDecimal("undeliqty")
-                        : row.getBigDecimal("qty").negate();// 如果是扣减则根据数量进行扣减,反之根据未发货数量进行增加
+                qty = isinstock ? row.getBigDecimal("undeliqty") : row.getBigDecimal("qty").negate();// 如果是扣减则根据数量进行扣减,反之根据未发货数量进行增加
             }
             sqlList.add("update st_invbal_sale set cansaleqty=cansaleqty+" + qty + " where st_invbal_saleid=" + st_invbal_saleid);
         }