Explorar el Código

订货额类别占比分析接口

hu hace 2 años
padre
commit
77069be58a

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

@@ -5173,6 +5173,15 @@ public class R {
         public static class v1 {
         }
     }
+    public static class ID20230728133003 {
+        public static class v1 {
+        }
+    }
+    public static class ID20230728143503 {
+        public static class v1 {
+        }
+    }
+
 }
 
 

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

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

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

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

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

@@ -0,0 +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

+ 229 - 0
src/custom/restcontroller/webmanage/sale/databoard/databoard.java

@@ -0,0 +1,229 @@
+package restcontroller.webmanage.sale.databoard;
+
+import beans.itemclass.ItemClass;
+import com.alibaba.fastjson.JSONObject;
+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.SQLFactory;
+import restcontroller.R;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+
+/**
+ * 数据看板
+ */
+public class databoard extends Controller {
+    /**
+     * 构造函数
+     *
+     * @param content
+     */
+    public databoard(JSONObject content) throws YosException {
+        super(content);
+    }
+
+    /**
+     * 销售类型分析
+     *
+     * @return
+     */
+    @API(title = "销售类型分析", apiversion = R.ID20230728133003.v1.class)
+    @CACHEING
+    public String SalesTypeAnalysis() throws YosException {
+
+        String datetype =content.getStringValue("datetype");
+        String datatype =content.getString("datatype");
+        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 = getWeekFirstDay();
+                enddate = getWeekLastDay();
+                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 ");
+        if (begindate!="") {
+            where.append(" and DATE_FORMAT(t1.checkdate, '%Y-%m-%d') >='").append(begindate).append("' ");
+        }
+        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{
+            return getErrReturnObject().setErrMsg("datatype类型错误").toString();
+        }
+
+        factory.addParameter("siteid", siteid);
+        factory.addParameter_SQL("where", where);
+        Rows rows = dbConnect.runSqlQuery(factory.getSQL(false));
+
+        return getSucReturnObject().setData(rows).toString();
+    }
+
+
+    /**
+     * 订货额类别占比分析
+     *
+     * @return
+     */
+    @API(title = "订货额类别占比分析", apiversion = R.ID20230728143503.v1.class)
+    @CACHEING
+    public String orderAmountCategoriesAnalysis() throws Exception {
+
+        String datetype =content.getStringValue("datetype");
+        String datatype =content.getString("datatype");
+        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 = getWeekFirstDay();
+                enddate = getWeekLastDay();
+                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("' ");
+        }
+
+        if(datatype.equals("标准")){
+            where.append(" and t1.type='标准订单' ");
+            whereLastYear.append(" and t1.type='标准订单' ");
+        }else if(datatype.equals("促销")){
+            where.append(" and t1.type='促销订单' ");
+            whereLastYear.append(" and t1.type='标准订单' ");
+        }else if(datatype.equals("特殊")){
+            where.append(" and t1.type='特殊订单' ");
+            whereLastYear.append(" and t1.type='标准订单' ");
+        }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, "订货额类别统计分析");
+            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",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(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));
+            }
+        }
+
+        return getSucReturnObject().setData(topItemclassRows).toString();
+    }
+
+
+}