hu 2 лет назад
Родитель
Сommit
cffb47097d

+ 4 - 0
src/custom/restcontroller/R.java

@@ -5181,6 +5181,10 @@ public class R {
         public static class v1 {
         }
     }
+    public static class ID20230729103203 {
+        public static class v1 {
+        }
+    }
 
 }
 

+ 1 - 0
src/custom/restcontroller/webmanage/sale/databoard/SQL/回款统计查询.sql

@@ -0,0 +1 @@
+select sum(t1.amount) typestatistics from sa_cashbill t1 where t1.status='审核' and t1.type=1 and t1.siteid=$siteid$ and $where$

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

@@ -1 +1 @@
-select sum(if(t2.isclose,t2.deliedqty*t2.price,t2.amount)) 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 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$)

+ 1 - 1
src/custom/restcontroller/webmanage/sale/databoard/SQL/销售单量统计查询.sql

@@ -1 +1 @@
-select type,count(1) typestatistics from sa_order where status not in('新建','提交') and siteid =$siteid$ and $where$ group by type
+select CAST(count(1) AS DECIMAL(16,0)) typestatistics from sa_order t1 where t1.status not in('新建','提交') and t1.siteid =$siteid$ and $where$

+ 1 - 0
src/custom/restcontroller/webmanage/sale/databoard/SQL/销售单量统计查询_类型.sql

@@ -0,0 +1 @@
+select type,CAST(count(1) AS DECIMAL(16,0)) typestatistics from sa_order t1 where t1.status not in('新建','提交') and t1.siteid =$siteid$ and $where$ group by t1.type

+ 1 - 0
src/custom/restcontroller/webmanage/sale/databoard/SQL/销售客户数统计查询.sql

@@ -0,0 +1 @@
+select CAST(count(1) AS DECIMAL(16,0)) typestatistics from (select sys_enterpriseid from sa_order t1 where t1.status not in('新建','提交') and t1.siteid =$siteid$ and $where$ GROUP BY t1.sys_enterpriseid) t

+ 1 - 1
src/custom/restcontroller/webmanage/sale/databoard/SQL/销售额统计查询.sql

@@ -1 +1 @@
-select t1.type,sum(if(t2.isclose,t2.deliedqty*t2.price,t2.amount)) 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('新建','提交') group by t1.type
+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('新建','提交')

+ 1 - 0
src/custom/restcontroller/webmanage/sale/databoard/SQL/销售额统计查询_类型.sql

@@ -0,0 +1 @@
+select t1.type,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('新建','提交') group by t1.type

+ 200 - 3
src/custom/restcontroller/webmanage/sale/databoard/databoard.java

@@ -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;
+    }
 
 }