|
|
@@ -1,6 +1,7 @@
|
|
|
package restcontroller.webmanage.sale.databoard;
|
|
|
|
|
|
import beans.itemclass.ItemClass;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import common.Controller;
|
|
|
import common.YosException;
|
|
|
@@ -17,6 +18,7 @@ import java.text.SimpleDateFormat;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Calendar;
|
|
|
import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
|
|
|
/**
|
|
|
* 数据看板
|
|
|
@@ -31,6 +33,172 @@ public class databoard extends Controller {
|
|
|
super(content);
|
|
|
}
|
|
|
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ /**
|
|
|
+ * 订货额类别占比分析
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @API(title = "订货分析", apiversion = R.ID20230729103203.v1.class)
|
|
|
+ @CACHEING
|
|
|
+ public String orderAndPaymentAnalysis() throws Exception {
|
|
|
+
|
|
|
+ String datetype =content.getStringValue("datetype");
|
|
|
+ String begindate="";
|
|
|
+ String enddate="";
|
|
|
+ switch (datetype) {
|
|
|
+ case "月":
|
|
|
+ begindate = getMonthFirstDay();
|
|
|
+ enddate = getMonthLastDay();
|
|
|
+ break;
|
|
|
+ case "年":
|
|
|
+ begindate = new SimpleDateFormat("yyyy").format(new Date()) + "-01-01";
|
|
|
+ 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());
|
|
|
+ break;
|
|
|
+ case "上半年":
|
|
|
+ begindate = new SimpleDateFormat("yyyy").format(new Date()) + "-01-01";
|
|
|
+ enddate = new SimpleDateFormat("yyyy").format(new Date()) + "-06-30";
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ /*
|
|
|
+ * 过滤条件设置
|
|
|
+ */
|
|
|
+ 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");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ StringBuffer where = new StringBuffer(" 1=1 ");
|
|
|
+ StringBuffer whereLastYear = new StringBuffer(" 1=1 ");
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+
|
|
|
+ if (begindate!="") {
|
|
|
+ where.append(" and DATE_FORMAT(t1.checkdate, '%Y-%m-%d') >='").append(begindate).append("' ");
|
|
|
+ Date date = sdf.parse(begindate);
|
|
|
+ //创建Calendar实例
|
|
|
+ Calendar cal = Calendar.getInstance();
|
|
|
+ //设置当前时间
|
|
|
+ cal.setTime(date);
|
|
|
+ //在当前时间基础上减一年
|
|
|
+ cal.add(Calendar.YEAR, -1);
|
|
|
+ whereLastYear.append(" and DATE_FORMAT(t1.checkdate, '%Y-%m-%d') >='").append(sdf.format(cal.getTime())).append("' ");
|
|
|
+ }
|
|
|
+ if (enddate!="") {
|
|
|
+ where.append(" and DATE_FORMAT(t1.checkdate, '%Y-%m-%d') <='").append(enddate).append("' ");
|
|
|
+ Date date = sdf.parse(enddate);
|
|
|
+ //创建Calendar实例
|
|
|
+ Calendar cal = Calendar.getInstance();
|
|
|
+ //设置当前时间
|
|
|
+ cal.setTime(date);
|
|
|
+ //在当前时间基础上减一年
|
|
|
+ cal.add(Calendar.YEAR, -1);
|
|
|
+ whereLastYear.append(" and DATE_FORMAT(t1.checkdate, '%Y-%m-%d') <='").append(sdf.format(cal.getTime())).append("' ");
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONArray jsonArray = new JSONArray();
|
|
|
+ //订货额
|
|
|
+ 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, "销售额统计查询");
|
|
|
+ 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));
|
|
|
+ }
|
|
|
+ jsonArray.add(jsonObject);
|
|
|
+
|
|
|
+ //订单量
|
|
|
+ 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.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));
|
|
|
+ }
|
|
|
+ jsonArray.add(jsonObject);
|
|
|
+
|
|
|
+ //客户数
|
|
|
+ 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.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));
|
|
|
+ }
|
|
|
+ jsonArray.add(jsonObject);
|
|
|
+
|
|
|
+ //回款
|
|
|
+ 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.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));
|
|
|
+ }
|
|
|
+ jsonArray.add(jsonObject);
|
|
|
+
|
|
|
+ return getSucReturnObject().setData(jsonArray).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 销售类型分析
|
|
|
*
|
|
|
@@ -84,9 +252,9 @@ public class databoard extends Controller {
|
|
|
|
|
|
SQLFactory factory;
|
|
|
if(datatype.equals("销售额")){
|
|
|
- factory= new SQLFactory(this, "销售额统计查询");
|
|
|
+ factory= new SQLFactory(this, "销售额统计查询_类型");
|
|
|
}else if(datatype.equals("销售单量")){
|
|
|
- factory= new SQLFactory(this, "销售单量统计查询");
|
|
|
+ factory= new SQLFactory(this, "销售单量统计查询_类型");
|
|
|
}else{
|
|
|
return getErrReturnObject().setErrMsg("datatype类型错误").toString();
|
|
|
}
|
|
|
@@ -143,7 +311,7 @@ public class databoard extends Controller {
|
|
|
|
|
|
StringBuffer where = new StringBuffer(" 1=1 ");
|
|
|
StringBuffer whereLastYear = new StringBuffer(" 1=1 ");
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+
|
|
|
|
|
|
if (begindate!="") {
|
|
|
where.append(" and DATE_FORMAT(t1.checkdate, '%Y-%m-%d') >='").append(begindate).append("' ");
|
|
|
@@ -225,5 +393,34 @@ public class databoard extends Controller {
|
|
|
return getSucReturnObject().setData(topItemclassRows).toString();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @Description: 获取季度第一天
|
|
|
+ * 1.根据给定日期计算当前季度的第一个月份
|
|
|
+ * 2.设置日历的月份为当前季度的第一个月份
|
|
|
+ * 3.最后设置日历月份天数为第一天即可
|
|
|
+ * @Author: wsp
|
|
|
+ **/
|
|
|
+ public static Calendar getQuarterStart(Date date) {
|
|
|
+ Calendar startCalendar = Calendar.getInstance();
|
|
|
+ startCalendar.setTime(date);
|
|
|
+ //get方法:获取给定日历属性的值,如 endCalendar.get(Calendar.MONTH) 获取日历的月份
|
|
|
+ //计算季度数:由于月份从0开始,即1月份的Calendar.MONTH值为0,所以计算季度的第一个月份只需 月份 / 3 * 3
|
|
|
+ startCalendar.set(Calendar.MONTH, (((int) startCalendar.get(Calendar.MONTH)) / 3) * 3);
|
|
|
+ startCalendar.set(Calendar.DAY_OF_MONTH, 1);
|
|
|
+ return startCalendar;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Description: 获取季度最后一天
|
|
|
+ * @Author: wsp
|
|
|
+ **/
|
|
|
+ public static Calendar getQuarterEnd(Date date) { // 季度结束
|
|
|
+ Calendar endCalendar = Calendar.getInstance();
|
|
|
+ endCalendar.setTime(date);
|
|
|
+ //计算季度数:由于月份从0开始,即1月份的Calendar.MONTH值为0,所以计算季度的第三个月份只需 月份 / 3 * 3 + 2
|
|
|
+ endCalendar.set(Calendar.MONTH, (((int) endCalendar.get(Calendar.MONTH)) / 3) * 3 + 2);
|
|
|
+ endCalendar.set(Calendar.DAY_OF_MONTH, endCalendar.getActualMaximum(Calendar.DAY_OF_MONTH));
|
|
|
+ return endCalendar;
|
|
|
+ }
|
|
|
|
|
|
}
|