|
|
@@ -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,31 @@ public class databoard extends Controller {
|
|
|
}
|
|
|
|
|
|
|
|
|
- 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));
|
|
|
+ //Rows topItemclassRows = dbConnect.runSqlQuery("select itemclassid,itemclassname marketingcategory 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 +577,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();
|
|
|
}
|
|
|
|
|
|
/**
|