Browse Source

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

hu 2 years ago
parent
commit
6870344663

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

@@ -1,3 +1 @@
-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
-
+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$)

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

@@ -9,7 +9,6 @@ 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;
@@ -544,32 +543,28 @@ 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");
-
-        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) {
+        Rows topItemclassRows = dbConnect.runSqlQuery("select itemclassid,itemclassname marketingcategory 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));
             if (rows.isNotEmpty()) {
-                row.put("amount", row.getBigDecimal("typestatistics"));
+                row.put("amount", rows.get(0).getBigDecimal("typestatistics"));
             } else {
                 row.put("amount", BigDecimal.ZERO);
             }
-            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{
+            if (rowsLastYear.isNotEmpty()) {
+                row.put("lastyearamount", rowsLastYear.get(0).getBigDecimal("typestatistics"));
+            } else {
                 row.put("lastyearamount", BigDecimal.ZERO);
             }
             if (row.getBigDecimal("lastyearamount").compareTo(BigDecimal.ZERO) == 0) {
@@ -578,17 +573,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 = rows.sum("amount");
-        for (Row row : rows) {
+        BigDecimal sumamount = topItemclassRows.sum("amount");
+        for (Row row : topItemclassRows) {
             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));
             }
         }
-        rows.sort(Comparator.comparingDouble(o ->o.getDouble("amount")));
-        Collections.reverse(rows);
-        return getSucReturnObject().setData(rows).toString();
+        topItemclassRows.sort(Comparator.comparingDouble(o ->o.getDouble("amount")));
+        Collections.reverse(topItemclassRows);
+        return getSucReturnObject().setData(topItemclassRows).toString();
     }
 
     /**