Преглед изворни кода

查询最上级大类的方法变更为查询商品档案中的大类字段

hu пре 2 година
родитељ
комит
6ae48b04ae

+ 3 - 1
src/custom/restcontroller/webmanage/sale/databoard/SQL/订货额类别统计分析.sql

@@ -1 +1,3 @@
-select cast(ifnull(sum(if(t2.isclose,t2.deliedqty*t2.price,t2.amount)),0) AS DECIMAL(16,6)) typestatistics  from sa_order t1 inner join sa_orderitems t2 on t1.sa_orderid=t2.sa_orderid and t1.siteid=t2.siteid where t1.siteid=$siteid$ and $where$ and t1.status not in('新建','提交') and exists(select * from sa_itemsaleclass s1 where s1.itemid=t2.itemid  and s1.itemclassid in $itemclassid$)
+select ifnull(t2.itemclassname,'其他') marketingcategory,t1.* from (
+select t3.marketingcategory,sum(cast(ifnull(if(t2.isclose,t2.deliedqty*t2.price,t2.amount),0) AS DECIMAL(16,6))) typestatistics  from sa_order t1 inner join sa_orderitems t2 on t1.sa_orderid=t2.sa_orderid and t1.siteid=t2.siteid left join plm_item t3 on t2.itemid=t3.itemid and t2.siteid=t3.siteid where t1.siteid=$siteid$ and $where$ and t1.status not in('新建','提交') group by t3.marketingcategory) t1 left join plm_itemclass t2 on t1.marketingcategory=t2.itemclassid
+

+ 28 - 23
src/custom/restcontroller/webmanage/sale/databoard/databoard.java

@@ -9,6 +9,7 @@ import common.annotation.API;
 import common.annotation.CACHEING;
 import common.data.Row;
 import common.data.Rows;
+import common.data.RowsMap;
 import common.data.SQLFactory;
 import org.apache.commons.lang.StringUtils;
 import restcontroller.R;
@@ -543,28 +544,32 @@ public class databoard extends Controller {
         }
 
 
-        Rows topItemclassRows = dbConnect.runSqlQuery("select itemclassid,itemclassname from plm_itemclass where classtype='营销' and siteid='" + siteid + "' and ifnull(parentid,0)=0");
-        for (Row row : topItemclassRows) {
-            ArrayList<Long> itemclassids = ItemClass.getSubItemClassIds(this, row.getLong("itemclassid"));
-            SQLFactory factory = new SQLFactory(this, "订货额类别统计分析");
-            factory.addParameter("siteid", siteid);
-            factory.addParameter_SQL("where", where);
-            factory.addParameter_in("itemclassid", itemclassids);
-            Rows rows = dbConnect.runSqlQuery(factory.getSQL(false));
-
-            SQLFactory factoryLastYear = new SQLFactory(this, "订货额类别统计分析");
-            factoryLastYear.addParameter("siteid", siteid);
-            factoryLastYear.addParameter_SQL("where", whereLastYear);
-            factoryLastYear.addParameter_in("itemclassid", itemclassids);
-            Rows rowsLastYear = dbConnect.runSqlQuery(factoryLastYear.getSQL(false));
+        //Rows topItemclassRows = dbConnect.runSqlQuery("select itemclassid,itemclassname from plm_itemclass where classtype='营销' and siteid='" + siteid + "' and ifnull(parentid,0)=0");
+
+        SQLFactory factory = new SQLFactory(this, "订货额类别统计分析");
+        factory.addParameter("siteid", siteid);
+        factory.addParameter_SQL("where", where);
+        Rows rows = dbConnect.runSqlQuery(factory.getSQL(false));
+
+
+        SQLFactory factoryLastYear = new SQLFactory(this, "订货额类别统计分析");
+        factoryLastYear.addParameter("siteid", siteid);
+        factoryLastYear.addParameter_SQL("where", whereLastYear);
+        Rows rowsLastYear = dbConnect.runSqlQuery(factoryLastYear.getSQL(false));
+        RowsMap rowsLastYearMap =rowsLastYear.toRowsMap("marketingcategory");
+        for (Row row : rows) {
             if (rows.isNotEmpty()) {
-                row.put("amount", rows.get(0).getBigDecimal("typestatistics"));
+                row.put("amount", row.getBigDecimal("typestatistics"));
             } else {
                 row.put("amount", BigDecimal.ZERO);
             }
-            if (rowsLastYear.isNotEmpty()) {
-                row.put("lastyearamount", rowsLastYear.get(0).getBigDecimal("typestatistics"));
-            } else {
+            if(rowsLastYearMap.containsKey(row.getString("marketingcategory"))){
+                if(rowsLastYearMap.get(row.getString("marketingcategory")).isNotEmpty()){
+                    row.put("lastyearamount", rowsLastYearMap.get(row.getString("marketingcategory")).get(0).getBigDecimal("typestatistics"));
+                }else {
+                    row.put("lastyearamount", BigDecimal.ZERO);
+                }
+            }else{
                 row.put("lastyearamount", BigDecimal.ZERO);
             }
             if (row.getBigDecimal("lastyearamount").compareTo(BigDecimal.ZERO) == 0) {
@@ -573,17 +578,17 @@ public class databoard extends Controller {
                 row.put("yearonyear", (row.getBigDecimal("amount").subtract(row.getBigDecimal("lastyearamount"))).divide(row.getBigDecimal("lastyearamount"), 4, BigDecimal.ROUND_HALF_UP));
             }
         }
-        BigDecimal sumamount = topItemclassRows.sum("amount");
-        for (Row row : topItemclassRows) {
+        BigDecimal sumamount = rows.sum("amount");
+        for (Row row : rows) {
             if (sumamount.compareTo(BigDecimal.ZERO) == 0) {
                 row.put("proportion", BigDecimal.ZERO);
             } else {
                 row.put("proportion", row.getBigDecimal("amount").divide(sumamount, 4, BigDecimal.ROUND_HALF_UP));
             }
         }
-        topItemclassRows.sort(Comparator.comparingDouble(o ->o.getDouble("amount")));
-        Collections.reverse(topItemclassRows);
-        return getSucReturnObject().setData(topItemclassRows).toString();
+        rows.sort(Comparator.comparingDouble(o ->o.getDouble("amount")));
+        Collections.reverse(rows);
+        return getSucReturnObject().setData(rows).toString();
     }
 
     /**

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

@@ -2850,7 +2850,7 @@ public class Order extends Controller {
 //        }
         JSONArray jsonArray =new JSONArray();
         BigDecimal orderSumamount = BigDecimal.ZERO;
-        Rows classamountrows =dbConnect.runSqlQuery("select t3.topitemclassid,t1.siteid,sum(ifnull(t1.amount,0)) sumamount  from sa_orderitems t1 inner join sa_itemsaleclass t2 on t1.itemid=t2.itemid and t1.siteid=t2.siteid inner join (select itemclassid,find_top(itemclassid) topitemclassid,siteid  from plm_itemclass where siteid!='ZZYOS') t3 on t2.itemclassid=t3.itemclassid and t2.siteid=t3.siteid  where t1.sa_orderid="+sa_orderid+" group by t3.topitemclassid,t1.siteid");
+        Rows classamountrows = dbConnect.runSqlQuery("select t2.marketingcategory topitemclassid,t1.siteid,sum(ifnull(t1.amount,0)) sumamount  from sa_orderitems t1 inner join plm_item t2 on t1.itemid=t2.itemid and t1.siteid=t2.siteid   where t1.sa_orderid='"+sa_orderid+"' group by t2.marketingcategory,t1.siteid");
         for (Row classamountrow:classamountrows) {
             orderSumamount=orderSumamount.add(classamountrow.getBigDecimal("sumamount"));
         }

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

@@ -353,8 +353,8 @@ public class OrderItems extends Controller {
         }
         JSONArray jsonArray = new JSONArray();
         BigDecimal orderSumamount = BigDecimal.ZERO;
-        Rows classamountrows = dbConnect.runSqlQuery("select t3.topitemclassid,t1.siteid,sum(ifnull(t1.amount,0)) sumamount  from sa_orderitems t1 inner join sa_itemsaleclass t2 on t1.itemid=t2.itemid and t1.siteid=t2.siteid inner join (select itemclassid,find_top(itemclassid) topitemclassid,siteid  from plm_itemclass where siteid!='ZZYOS') t3 on t2.itemclassid=t3.itemclassid and t2.siteid=t3.siteid  where t1.sa_orderid=" + sa_orderid + " group by t3.topitemclassid,t1.siteid");
-        for (Row classamountrow : classamountrows) {
+        Rows classamountrows = dbConnect.runSqlQuery("select t2.marketingcategory topitemclassid,t1.siteid,sum(ifnull(t1.amount,0)) sumamount  from sa_orderitems t1 inner join plm_item t2 on t1.itemid=t2.itemid and t1.siteid=t2.siteid   where t1.sa_orderid='"+sa_orderid+"' group by t2.marketingcategory,t1.siteid");
+            for (Row classamountrow : classamountrows) {
             orderSumamount = orderSumamount.add(classamountrow.getBigDecimal("sumamount"));
         }
         if (orderSumamount.compareTo(getAmount(this, sa_orderid)) != 0) {