|
|
@@ -3,22 +3,23 @@ package restcontroller.webmanage.sale.databoard;
|
|
|
import beans.itemclass.ItemClass;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.sun.org.apache.bcel.internal.generic.NEW;
|
|
|
import common.Controller;
|
|
|
import common.YosException;
|
|
|
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 restcontroller.R;
|
|
|
|
|
|
+import javax.swing.tree.RowMapper;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Calendar;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.HashMap;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 数据看板
|
|
|
@@ -34,6 +35,7 @@ public class databoard extends Controller {
|
|
|
}
|
|
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+
|
|
|
/**
|
|
|
* 订货额类别占比分析
|
|
|
*
|
|
|
@@ -43,9 +45,9 @@ public class databoard extends Controller {
|
|
|
@CACHEING
|
|
|
public String orderAndPaymentAnalysis() throws Exception {
|
|
|
|
|
|
- String datetype =content.getStringValue("datetype");
|
|
|
- String begindate="";
|
|
|
- String enddate="";
|
|
|
+ String datetype = content.getStringValue("datetype");
|
|
|
+ String begindate = "";
|
|
|
+ String enddate = "";
|
|
|
switch (datetype) {
|
|
|
case "月":
|
|
|
begindate = getMonthFirstDay();
|
|
|
@@ -56,8 +58,8 @@ public class databoard extends Controller {
|
|
|
enddate = new SimpleDateFormat("yyyy").format(new Date()) + "-12-31";
|
|
|
break;
|
|
|
case "季":
|
|
|
- begindate =sdf.format(getQuarterStart(new Date()).getTime());
|
|
|
- enddate =sdf.format(getQuarterEnd(new Date()).getTime());
|
|
|
+ begindate = sdf.format(getQuarterStart(new Date()).getTime());
|
|
|
+ enddate = sdf.format(getQuarterEnd(new Date()).getTime());
|
|
|
break;
|
|
|
case "上半年":
|
|
|
begindate = new SimpleDateFormat("yyyy").format(new Date()) + "-01-01";
|
|
|
@@ -83,7 +85,7 @@ public class databoard extends Controller {
|
|
|
StringBuffer whereLastYear = new StringBuffer(" 1=1 ");
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
|
|
- if (begindate!="") {
|
|
|
+ if (begindate != "") {
|
|
|
where.append(" and DATE_FORMAT(t1.checkdate, '%Y-%m-%d') >='").append(begindate).append("' ");
|
|
|
Date date = sdf.parse(begindate);
|
|
|
//创建Calendar实例
|
|
|
@@ -94,7 +96,7 @@ public class databoard extends Controller {
|
|
|
cal.add(Calendar.YEAR, -1);
|
|
|
whereLastYear.append(" and DATE_FORMAT(t1.checkdate, '%Y-%m-%d') >='").append(sdf.format(cal.getTime())).append("' ");
|
|
|
}
|
|
|
- if (enddate!="") {
|
|
|
+ if (enddate != "") {
|
|
|
where.append(" and DATE_FORMAT(t1.checkdate, '%Y-%m-%d') <='").append(enddate).append("' ");
|
|
|
Date date = sdf.parse(enddate);
|
|
|
//创建Calendar实例
|
|
|
@@ -108,96 +110,148 @@ public class databoard extends Controller {
|
|
|
|
|
|
JSONArray jsonArray = new JSONArray();
|
|
|
//订货额
|
|
|
- JSONObject jsonObject =new JSONObject();
|
|
|
- SQLFactory factory= new SQLFactory(this, "销售额统计查询");
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ 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, "销售额统计查询");
|
|
|
+ SQLFactory factoryLastYear = new SQLFactory(this, "销售额统计查询");
|
|
|
factoryLastYear.addParameter("siteid", siteid);
|
|
|
factoryLastYear.addParameter_SQL("where", whereLastYear);
|
|
|
Rows rowsLastYear = dbConnect.runSqlQuery(factoryLastYear.getSQL(false));
|
|
|
- jsonObject.put("type","订货额");
|
|
|
- jsonObject.put("currentData",rows.get(0).getBigDecimal("typestatistics"));
|
|
|
- jsonObject.put("yearonyeargrowth",rows.get(0).getBigDecimal("typestatistics").subtract(rowsLastYear.get(0).getBigDecimal("typestatistics")));
|
|
|
- if(rowsLastYear.get(0).getBigDecimal("typestatistics").compareTo(BigDecimal.ZERO)==0){
|
|
|
- jsonObject.put("yearonyearrate",0);
|
|
|
- }else{
|
|
|
- jsonObject.put("yearonyearrate",(rows.get(0).getBigDecimal("typestatistics").subtract(rowsLastYear.get(0).getBigDecimal("typestatistics"))).divide(rowsLastYear.get(0).getBigDecimal("typestatistics"), 4, BigDecimal.ROUND_HALF_UP));
|
|
|
+ jsonObject.put("type", "订货额");
|
|
|
+ jsonObject.put("currentData", rows.get(0).getBigDecimal("typestatistics"));
|
|
|
+ jsonObject.put("yearonyeargrowth", rows.get(0).getBigDecimal("typestatistics").subtract(rowsLastYear.get(0).getBigDecimal("typestatistics")));
|
|
|
+ if (rowsLastYear.get(0).getBigDecimal("typestatistics").compareTo(BigDecimal.ZERO) == 0) {
|
|
|
+ jsonObject.put("yearonyearrate", 0);
|
|
|
+ } else {
|
|
|
+ jsonObject.put("yearonyearrate", (rows.get(0).getBigDecimal("typestatistics").subtract(rowsLastYear.get(0).getBigDecimal("typestatistics"))).divide(rowsLastYear.get(0).getBigDecimal("typestatistics"), 4, BigDecimal.ROUND_HALF_UP));
|
|
|
}
|
|
|
jsonArray.add(jsonObject);
|
|
|
|
|
|
//订单量
|
|
|
- jsonObject =new JSONObject();
|
|
|
- factory= new SQLFactory(this, "销售单量统计查询");
|
|
|
+ jsonObject = new JSONObject();
|
|
|
+ factory = new SQLFactory(this, "销售单量统计查询");
|
|
|
factory.addParameter("siteid", siteid);
|
|
|
factory.addParameter_SQL("where", where);
|
|
|
rows = dbConnect.runSqlQuery(factory.getSQL(false));
|
|
|
|
|
|
- factoryLastYear= new SQLFactory(this, "销售单量统计查询");
|
|
|
+ factoryLastYear = new SQLFactory(this, "销售单量统计查询");
|
|
|
factoryLastYear.addParameter("siteid", siteid);
|
|
|
factoryLastYear.addParameter_SQL("where", whereLastYear);
|
|
|
rowsLastYear = dbConnect.runSqlQuery(factoryLastYear.getSQL(false));
|
|
|
|
|
|
- jsonObject.put("type","订单量");;
|
|
|
- jsonObject.put("currentData",rows.get(0).getBigDecimal("typestatistics"));
|
|
|
- jsonObject.put("yearonyeargrowth",rows.get(0).getBigDecimal("typestatistics").subtract(rowsLastYear.get(0).getBigDecimal("typestatistics")));
|
|
|
- if(rowsLastYear.get(0).getBigDecimal("typestatistics").compareTo(BigDecimal.ZERO)==0){
|
|
|
- jsonObject.put("yearonyearrate",0);
|
|
|
- }else{
|
|
|
- jsonObject.put("yearonyearrate",(rows.get(0).getBigDecimal("typestatistics").subtract(rowsLastYear.get(0).getBigDecimal("typestatistics"))).divide(rowsLastYear.get(0).getBigDecimal("typestatistics"), 4, BigDecimal.ROUND_HALF_UP));
|
|
|
+ jsonObject.put("type", "订单量");
|
|
|
+ ;
|
|
|
+ jsonObject.put("currentData", rows.get(0).getBigDecimal("typestatistics"));
|
|
|
+ jsonObject.put("yearonyeargrowth", rows.get(0).getBigDecimal("typestatistics").subtract(rowsLastYear.get(0).getBigDecimal("typestatistics")));
|
|
|
+ if (rowsLastYear.get(0).getBigDecimal("typestatistics").compareTo(BigDecimal.ZERO) == 0) {
|
|
|
+ jsonObject.put("yearonyearrate", 0);
|
|
|
+ } else {
|
|
|
+ jsonObject.put("yearonyearrate", (rows.get(0).getBigDecimal("typestatistics").subtract(rowsLastYear.get(0).getBigDecimal("typestatistics"))).divide(rowsLastYear.get(0).getBigDecimal("typestatistics"), 4, BigDecimal.ROUND_HALF_UP));
|
|
|
}
|
|
|
jsonArray.add(jsonObject);
|
|
|
|
|
|
//客户数
|
|
|
- jsonObject =new JSONObject();
|
|
|
- factory= new SQLFactory(this, "销售客户数统计查询");
|
|
|
+ jsonObject = new JSONObject();
|
|
|
+ factory = new SQLFactory(this, "销售客户数统计查询");
|
|
|
factory.addParameter("siteid", siteid);
|
|
|
factory.addParameter_SQL("where", where);
|
|
|
rows = dbConnect.runSqlQuery(factory.getSQL(false));
|
|
|
|
|
|
- factoryLastYear= new SQLFactory(this, "销售客户数统计查询");
|
|
|
+ factoryLastYear = new SQLFactory(this, "销售客户数统计查询");
|
|
|
factoryLastYear.addParameter("siteid", siteid);
|
|
|
factoryLastYear.addParameter_SQL("where", whereLastYear);
|
|
|
rowsLastYear = dbConnect.runSqlQuery(factoryLastYear.getSQL(false));
|
|
|
|
|
|
- jsonObject.put("type","客户数");
|
|
|
- jsonObject.put("currentData",rows.get(0).getBigDecimal("typestatistics"));
|
|
|
- jsonObject.put("yearonyeargrowth",rows.get(0).getBigDecimal("typestatistics").subtract(rowsLastYear.get(0).getBigDecimal("typestatistics")));
|
|
|
- if(rowsLastYear.get(0).getBigDecimal("typestatistics").compareTo(BigDecimal.ZERO)==0){
|
|
|
- jsonObject.put("yearonyearrate",0);
|
|
|
- }else{
|
|
|
- jsonObject.put("yearonyearrate",(rows.get(0).getBigDecimal("typestatistics").subtract(rowsLastYear.get(0).getBigDecimal("typestatistics"))).divide(rowsLastYear.get(0).getBigDecimal("typestatistics"), 4, BigDecimal.ROUND_HALF_UP));
|
|
|
+ jsonObject.put("type", "客户数");
|
|
|
+ jsonObject.put("currentData", rows.get(0).getBigDecimal("typestatistics"));
|
|
|
+ jsonObject.put("yearonyeargrowth", rows.get(0).getBigDecimal("typestatistics").subtract(rowsLastYear.get(0).getBigDecimal("typestatistics")));
|
|
|
+ if (rowsLastYear.get(0).getBigDecimal("typestatistics").compareTo(BigDecimal.ZERO) == 0) {
|
|
|
+ jsonObject.put("yearonyearrate", 0);
|
|
|
+ } else {
|
|
|
+ jsonObject.put("yearonyearrate", (rows.get(0).getBigDecimal("typestatistics").subtract(rowsLastYear.get(0).getBigDecimal("typestatistics"))).divide(rowsLastYear.get(0).getBigDecimal("typestatistics"), 4, BigDecimal.ROUND_HALF_UP));
|
|
|
}
|
|
|
jsonArray.add(jsonObject);
|
|
|
|
|
|
//回款
|
|
|
- jsonObject =new JSONObject();
|
|
|
- factory= new SQLFactory(this, "回款统计查询");
|
|
|
+ jsonObject = new JSONObject();
|
|
|
+ factory = new SQLFactory(this, "回款统计查询");
|
|
|
factory.addParameter("siteid", siteid);
|
|
|
factory.addParameter_SQL("where", where);
|
|
|
rows = dbConnect.runSqlQuery(factory.getSQL(false));
|
|
|
|
|
|
- factoryLastYear= new SQLFactory(this, "回款统计查询");
|
|
|
+ factoryLastYear = new SQLFactory(this, "回款统计查询");
|
|
|
factoryLastYear.addParameter("siteid", siteid);
|
|
|
factoryLastYear.addParameter_SQL("where", whereLastYear);
|
|
|
rowsLastYear = dbConnect.runSqlQuery(factoryLastYear.getSQL(false));
|
|
|
|
|
|
- jsonObject.put("type","回款");
|
|
|
- jsonObject.put("currentData",rows.get(0).getBigDecimal("typestatistics"));
|
|
|
- jsonObject.put("yearonyeargrowth",rows.get(0).getBigDecimal("typestatistics").subtract(rowsLastYear.get(0).getBigDecimal("typestatistics")));
|
|
|
- if(rowsLastYear.get(0).getBigDecimal("typestatistics").compareTo(BigDecimal.ZERO)==0){
|
|
|
- jsonObject.put("yearonyearrate",0);
|
|
|
- }else{
|
|
|
- jsonObject.put("yearonyearrate",(rows.get(0).getBigDecimal("typestatistics").subtract(rowsLastYear.get(0).getBigDecimal("typestatistics"))).divide(rowsLastYear.get(0).getBigDecimal("typestatistics"), 4, BigDecimal.ROUND_HALF_UP));
|
|
|
+ jsonObject.put("type", "回款");
|
|
|
+ jsonObject.put("currentData", rows.get(0).getBigDecimal("typestatistics"));
|
|
|
+ jsonObject.put("yearonyeargrowth", rows.get(0).getBigDecimal("typestatistics").subtract(rowsLastYear.get(0).getBigDecimal("typestatistics")));
|
|
|
+ if (rowsLastYear.get(0).getBigDecimal("typestatistics").compareTo(BigDecimal.ZERO) == 0) {
|
|
|
+ jsonObject.put("yearonyearrate", 0);
|
|
|
+ } else {
|
|
|
+ jsonObject.put("yearonyearrate", (rows.get(0).getBigDecimal("typestatistics").subtract(rowsLastYear.get(0).getBigDecimal("typestatistics"))).divide(rowsLastYear.get(0).getBigDecimal("typestatistics"), 4, BigDecimal.ROUND_HALF_UP));
|
|
|
}
|
|
|
jsonArray.add(jsonObject);
|
|
|
|
|
|
return getSucReturnObject().setData(jsonArray).toString();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 销售类型分析
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @API(title = "销售订单按月份分析", apiversion = R.ID20230729142603.v1.class)
|
|
|
+ @CACHEING
|
|
|
+ public String SalesOrderByMonthAnalysis() throws Exception {
|
|
|
|
|
|
+ String datatype = content.getString("datatype");
|
|
|
+ /*
|
|
|
+ * 过滤条件设置
|
|
|
+ */
|
|
|
+// if (content.containsKey("where")) {
|
|
|
+// JSONObject whereObject = content.getJSONObject("where");
|
|
|
+// if (whereObject.containsKey("begindate") && !"".equals(whereObject.getString("begindate"))) {
|
|
|
+// begindate = whereObject.getString("begindate");
|
|
|
+// }
|
|
|
+// if (whereObject.containsKey("enddate") && !"".equals(whereObject.getString("enddate"))) {
|
|
|
+// enddate = whereObject.getString("enddate");
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
+ SQLFactory factory;
|
|
|
+ if (datatype.equals("订货额")) {
|
|
|
+ factory = new SQLFactory(this, "销售额统计查询_月份");
|
|
|
+ } else if (datatype.equals("订货单量")) {
|
|
|
+ factory = new SQLFactory(this, "销售单量统计查询_月份");
|
|
|
+ } else {
|
|
|
+ return getErrReturnObject().setErrMsg("datatype类型错误").toString();
|
|
|
+ }
|
|
|
+ factory.addParameter("siteid", siteid);
|
|
|
+ Rows rows = dbConnect.runSqlQuery(factory.getSQL(false));
|
|
|
+ String year = new SimpleDateFormat("yyyy").format(new Date());
|
|
|
+ String lastyear = String.valueOf(Integer.parseInt(new SimpleDateFormat("yyyy").format(new Date())) - 1);
|
|
|
+ List<DataTrans> list = new ArrayList();
|
|
|
+
|
|
|
+ for (Row row : rows) {
|
|
|
+ DataTrans dataTrans = new DataTrans();
|
|
|
+ if(row.getString("y").equals(year) || row.getString("y").equals(lastyear)){
|
|
|
+ dataTrans.setName(row.getString("y")+"-"+ row.getString("m"));
|
|
|
+ dataTrans.setMonth(row.getString("m"));
|
|
|
+ dataTrans.setYear(row.getString("y"));
|
|
|
+ dataTrans.setValue(row.getBigDecimal("typestatistics"));
|
|
|
+ list.add(dataTrans);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ list=supplementDate(Integer.parseInt(year),list);
|
|
|
+ list=supplementDate(Integer.parseInt(lastyear),list);
|
|
|
+
|
|
|
+ return getSucReturnObject().setData(list).toString();
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 销售类型分析
|
|
|
@@ -208,10 +262,10 @@ public class databoard extends Controller {
|
|
|
@CACHEING
|
|
|
public String SalesTypeAnalysis() throws YosException {
|
|
|
|
|
|
- String datetype =content.getStringValue("datetype");
|
|
|
- String datatype =content.getString("datatype");
|
|
|
- String begindate="";
|
|
|
- String enddate="";
|
|
|
+ String datetype = content.getStringValue("datetype");
|
|
|
+ String datatype = content.getString("datatype");
|
|
|
+ String begindate = "";
|
|
|
+ String enddate = "";
|
|
|
switch (datetype) {
|
|
|
case "月":
|
|
|
begindate = getMonthFirstDay();
|
|
|
@@ -242,20 +296,20 @@ public class databoard extends Controller {
|
|
|
}
|
|
|
|
|
|
StringBuffer where = new StringBuffer(" 1=1 ");
|
|
|
- if (begindate!="") {
|
|
|
+ if (begindate != "") {
|
|
|
where.append(" and DATE_FORMAT(t1.checkdate, '%Y-%m-%d') >='").append(begindate).append("' ");
|
|
|
}
|
|
|
- if (enddate!="") {
|
|
|
+ if (enddate != "") {
|
|
|
where.append(" and DATE_FORMAT(t1.checkdate, '%Y-%m-%d') <='").append(enddate).append("' ");
|
|
|
}
|
|
|
|
|
|
|
|
|
SQLFactory factory;
|
|
|
- if(datatype.equals("销售额")){
|
|
|
- factory= new SQLFactory(this, "销售额统计查询_类型");
|
|
|
- }else if(datatype.equals("销售单量")){
|
|
|
- factory= new SQLFactory(this, "销售单量统计查询_类型");
|
|
|
- }else{
|
|
|
+ if (datatype.equals("销售额")) {
|
|
|
+ factory = new SQLFactory(this, "销售额统计查询_类型");
|
|
|
+ } else if (datatype.equals("销售单量")) {
|
|
|
+ factory = new SQLFactory(this, "销售单量统计查询_类型");
|
|
|
+ } else {
|
|
|
return getErrReturnObject().setErrMsg("datatype类型错误").toString();
|
|
|
}
|
|
|
|
|
|
@@ -276,10 +330,10 @@ public class databoard extends Controller {
|
|
|
@CACHEING
|
|
|
public String orderAmountCategoriesAnalysis() throws Exception {
|
|
|
|
|
|
- String datetype =content.getStringValue("datetype");
|
|
|
- String datatype =content.getString("datatype");
|
|
|
- String begindate="";
|
|
|
- String enddate="";
|
|
|
+ String datetype = content.getStringValue("datetype");
|
|
|
+ String datatype = content.getString("datatype");
|
|
|
+ String begindate = "";
|
|
|
+ String enddate = "";
|
|
|
switch (datetype) {
|
|
|
case "月":
|
|
|
begindate = getMonthFirstDay();
|
|
|
@@ -313,7 +367,7 @@ public class databoard extends Controller {
|
|
|
StringBuffer whereLastYear = new StringBuffer(" 1=1 ");
|
|
|
|
|
|
|
|
|
- if (begindate!="") {
|
|
|
+ if (begindate != "") {
|
|
|
where.append(" and DATE_FORMAT(t1.checkdate, '%Y-%m-%d') >='").append(begindate).append("' ");
|
|
|
Date date = sdf.parse(begindate);
|
|
|
//创建Calendar实例
|
|
|
@@ -324,7 +378,7 @@ public class databoard extends Controller {
|
|
|
cal.add(Calendar.YEAR, -1);
|
|
|
whereLastYear.append(" and DATE_FORMAT(t1.checkdate, '%Y-%m-%d') >='").append(sdf.format(cal.getTime())).append("' ");
|
|
|
}
|
|
|
- if (enddate!="") {
|
|
|
+ if (enddate != "") {
|
|
|
where.append(" and DATE_FORMAT(t1.checkdate, '%Y-%m-%d') <='").append(enddate).append("' ");
|
|
|
Date date = sdf.parse(enddate);
|
|
|
//创建Calendar实例
|
|
|
@@ -336,57 +390,57 @@ public class databoard extends Controller {
|
|
|
whereLastYear.append(" and DATE_FORMAT(t1.checkdate, '%Y-%m-%d') <='").append(sdf.format(cal.getTime())).append("' ");
|
|
|
}
|
|
|
|
|
|
- if(datatype.equals("标准")){
|
|
|
+ if (datatype.equals("标准")) {
|
|
|
where.append(" and t1.type='标准订单' ");
|
|
|
whereLastYear.append(" and t1.type='标准订单' ");
|
|
|
- }else if(datatype.equals("促销")){
|
|
|
+ } else if (datatype.equals("促销")) {
|
|
|
where.append(" and t1.type='促销订单' ");
|
|
|
whereLastYear.append(" and t1.type='标准订单' ");
|
|
|
- }else if(datatype.equals("特殊")){
|
|
|
+ } else if (datatype.equals("特殊")) {
|
|
|
where.append(" and t1.type='特殊订单' ");
|
|
|
whereLastYear.append(" and t1.type='标准订单' ");
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
where.append(" and 1=1 ");
|
|
|
whereLastYear.append(" and 1=1 ");
|
|
|
}
|
|
|
|
|
|
|
|
|
- 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, "订货额类别统计分析");
|
|
|
+ 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, "订货额类别统计分析");
|
|
|
+ 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",rows.get(0).getBigDecimal("typestatistics"));
|
|
|
- }else{
|
|
|
- row.put("amount",BigDecimal.ZERO);
|
|
|
+ if (rows.isNotEmpty()) {
|
|
|
+ row.put("amount", rows.get(0).getBigDecimal("typestatistics"));
|
|
|
+ } else {
|
|
|
+ row.put("amount", BigDecimal.ZERO);
|
|
|
}
|
|
|
- if(rowsLastYear.isNotEmpty()){
|
|
|
- row.put("lastyearamount",rowsLastYear.get(0).getBigDecimal("typestatistics"));
|
|
|
- }else{
|
|
|
- row.put("lastyearamount",BigDecimal.ZERO);
|
|
|
+ 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){
|
|
|
- row.put("yearonyear",BigDecimal.ZERO);
|
|
|
- }else{
|
|
|
- row.put("yearonyear",(row.getBigDecimal("amount").subtract(row.getBigDecimal("lastyearamount"))).divide(row.getBigDecimal("lastyearamount"),4,BigDecimal.ROUND_HALF_UP));
|
|
|
+ if (row.getBigDecimal("lastyearamount").compareTo(BigDecimal.ZERO) == 0) {
|
|
|
+ row.put("yearonyear", BigDecimal.ZERO);
|
|
|
+ } else {
|
|
|
+ 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) {
|
|
|
- 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));
|
|
|
+ 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));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -423,4 +477,37 @@ public class databoard extends Controller {
|
|
|
return endCalendar;
|
|
|
}
|
|
|
|
|
|
+ public static List<DataTrans> supplementDate(int year,List<DataTrans> params){
|
|
|
+ String[] monthAndDay = new String[]{"01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"};
|
|
|
+ List<DataTrans> list = new ArrayList<>();
|
|
|
+ for (DataTrans data:params){
|
|
|
+ list.add(data);
|
|
|
+ for (String s:monthAndDay){
|
|
|
+ DataTrans dataTrans = new DataTrans();
|
|
|
+ String date = year+"-"+s;
|
|
|
+ if (!date.equals(data.getName())){
|
|
|
+ dataTrans.setName(date);
|
|
|
+ dataTrans.setMonth(s);
|
|
|
+ dataTrans.setYear(String.valueOf(year));
|
|
|
+ dataTrans.setValue(BigDecimal.ZERO);
|
|
|
+ list.add(dataTrans);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 集合中相同属性去重、值合并
|
|
|
+ return merge(list);
|
|
|
+ }
|
|
|
+ public static List<DataTrans> merge(List<DataTrans> list) {
|
|
|
+ List<DataTrans> result = list.stream()
|
|
|
+ // 表示name为key,接着如果有重复的,那么从DataTrans对象o1与o2中筛选出一个,这里选择o1,
|
|
|
+ // 并把name重复,需要将value与o1进行合并的o2, 赋值给o1,最后返回o1
|
|
|
+ .collect(Collectors.toMap(DataTrans::getName, a -> a, (o1, o2)-> {
|
|
|
+ o1.setValue(o1.getValue().add(o2.getValue()));
|
|
|
+ return o1;
|
|
|
+ })).values().stream().collect(Collectors.toList());
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|