Parcourir la source

增加经销商首页(数据看板)完成

hu il y a 2 ans
Parent
commit
f02f46d930

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

@@ -5217,6 +5217,14 @@ public class R {
         public static class v1 {
         }
     }
+    public static class ID20230803143703 {
+        public static class v1 {
+        }
+    }
+    public static class ID20230803165003 {
+        public static class v1 {
+        }
+    }
 
 
 }

+ 3 - 0
src/custom/restcontroller/webmanage/sale/databoard/SQL/账户余额_经销商.sql

@@ -0,0 +1,3 @@
+select t2.accountname,t1.balance from sa_accountbalance t1 inner join sa_accountclass t2 on t1.sa_accountclassid=t2.sa_accountclassid and t1.siteid=t2.siteid where t1.sys_enterpriseid=$sys_enterpriseid$ and  t1.siteid=$siteid$ and (JSON_TYPE(t2.bindingcategories) = 'NULL' || JSON_LENGTH(t2.bindingcategories) = 0)
+UNION all
+select '专款账户' accountname,ifnull(sum(ifnull(t1.balance,0)),0) balance from sa_accountbalance t1 inner join sa_accountclass t2 on t1.sa_accountclassid=t2.sa_accountclassid and t1.siteid=t2.siteid where t1.sys_enterpriseid=$sys_enterpriseid$ and t1.siteid=$siteid$ and (JSON_TYPE(t2.bindingcategories) != 'NULL' && JSON_LENGTH(t2.bindingcategories) != 0)

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

@@ -0,0 +1 @@
+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='审核'

+ 143 - 7
src/custom/restcontroller/webmanage/sale/databoard/databoard.java

@@ -3,24 +3,17 @@ 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 com.sun.tools.internal.xjc.reader.gbind.ElementSets;
 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 jdk.nashorn.internal.objects.annotations.Where;
 import org.apache.commons.lang.StringUtils;
 import restcontroller.R;
 
-import javax.naming.InsufficientResourcesException;
-import javax.swing.tree.RowMapper;
 import java.math.BigDecimal;
-import java.math.RoundingMode;
 import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.stream.Collectors;
@@ -40,6 +33,138 @@ public class databoard extends Controller {
 
     SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
 
+
+    /**
+     * 经销商订货分析
+     *
+     * @return
+     */
+    @API(title = "经销商订货分析", apiversion = R.ID20230803143703.v1.class)
+    @CACHEING
+    public String agentOrderAndPaymentAnalysis() throws Exception {
+
+        String datetype = content.getStringValue("datetype");
+        String begindate = "";
+        String enddate = "";
+
+        //
+        String begindate1 = "";
+        String enddate1 = "";
+
+        String begindate2 = "";
+        String enddate2 = "";
+
+
+
+        switch (datetype) {
+            case "月":
+                begindate = getMonthFirstDay();
+                begindate1=caluteDate(Calendar.MONTH,begindate);
+                begindate2=caluteDate(Calendar.YEAR,begindate);
+                enddate = getMonthLastDay();
+                enddate1= caluteDate(Calendar.MONTH,enddate);
+                enddate2= caluteDate(Calendar.YEAR,enddate);
+
+                break;
+            case "年":
+                begindate = new SimpleDateFormat("yyyy").format(new Date()) + "-01-01";
+                begindate1=caluteDate(Calendar.YEAR,begindate);
+                enddate = new SimpleDateFormat("yyyy").format(new Date()) + "-12-31";
+                enddate1= caluteDate(Calendar.YEAR,enddate);
+                break;
+            case "日":
+                begindate = sdf.format(new Date().getTime());
+                begindate1=caluteDate(Calendar.DAY_OF_MONTH,begindate);
+                enddate = sdf.format(new Date().getTime());
+                enddate1= caluteDate(Calendar.DAY_OF_MONTH,enddate);
+                break;
+            default:
+                break;
+        }
+
+
+        StringBuffer where = new StringBuffer(" 1=1 and t1.sys_enterpriseid="+sys_enterpriseid);
+        StringBuffer whereLast1 = new StringBuffer(" 1=1 and t1.sys_enterpriseid="+sys_enterpriseid);
+        StringBuffer whereLast2 = new StringBuffer(" 1=1 and t1.sys_enterpriseid="+sys_enterpriseid);
+
+        if (begindate != "") {
+            where.append(" and DATE_FORMAT(t1.billdate, '%Y-%m-%d') >='").append(begindate).append("' ");
+        }
+        if (enddate != "") {
+            where.append(" and DATE_FORMAT(t1.billdate, '%Y-%m-%d') <='").append(enddate).append("' ");
+        }
+        if (begindate1 != "") {
+            whereLast1.append(" and DATE_FORMAT(t1.billdate, '%Y-%m-%d') >='").append(begindate1).append("' ");
+        }
+        if (enddate1 != "") {
+            whereLast1.append(" and DATE_FORMAT(t1.billdate, '%Y-%m-%d') <='").append(enddate1).append("' ");
+        }
+        if (begindate2 != "") {
+            whereLast2.append(" and DATE_FORMAT(t1.billdate, '%Y-%m-%d') >='").append(begindate2).append("' ");
+        }
+        if (enddate2 != "") {
+            whereLast2.append(" and DATE_FORMAT(t1.billdate, '%Y-%m-%d') <='").append(enddate2).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 factoryLast1 = new SQLFactory(this, "销售额统计查询_经销商");
+        factoryLast1.addParameter("siteid", siteid);
+        factoryLast1.addParameter_SQL("where", whereLast1);
+        Rows rowsLast1 = dbConnect.runSqlQuery(factoryLast1.getSQL(false));
+        //同比
+        SQLFactory factoryLast2 = new SQLFactory(this, "销售额统计查询_经销商");
+        factoryLast2.addParameter("siteid", siteid);
+        factoryLast2.addParameter_SQL("where", whereLast2);
+        Rows rowsLast2 = dbConnect.runSqlQuery(factoryLast2.getSQL(false));
+
+        BigDecimal typestatistics =rows.get(0).getBigDecimal("typestatistics");
+        BigDecimal typestatistics1 =rowsLast1.get(0).getBigDecimal("typestatistics");
+        BigDecimal typestatistics2 =rowsLast2.get(0).getBigDecimal("typestatistics");
+        BigDecimal huanbirate=BigDecimal.ZERO;
+        BigDecimal tongbirate=BigDecimal.ZERO;
+        if(typestatistics1.compareTo(BigDecimal.ZERO)>0){
+             huanbirate=(typestatistics.subtract(typestatistics1)).divide(typestatistics1, 4, BigDecimal.ROUND_HALF_UP);
+        }
+        if(typestatistics2.compareTo(BigDecimal.ZERO)>0){
+            tongbirate=(typestatistics.subtract(typestatistics2)).divide(typestatistics2, 4, BigDecimal.ROUND_HALF_UP);
+        }
+
+        jsonObject = new JSONObject();
+        jsonObject.put("typestatistics",typestatistics);
+        jsonObject.put("huanbirate", huanbirate);
+        jsonObject.put("tongbirate", tongbirate);
+        jsonArray.add(jsonObject);
+
+        return getSucReturnObject().setData(jsonArray).toString();
+    }
+
+
+    /**
+     * 经销商余额
+     *
+     * @return
+     */
+    @API(title = "经销商余额", apiversion = R.ID20230803165003.v1.class)
+    @CACHEING
+    public String agentBalanceAnalysis() throws Exception {
+
+
+        //账户余额
+        SQLFactory balancefactory= new SQLFactory(this, "账户余额_经销商");
+        balancefactory.addParameter("siteid", siteid);
+        balancefactory.addParameter("sys_enterpriseid", sys_enterpriseid);
+        Rows balanceRows = dbConnect.runSqlQuery(balancefactory.getSQL(false));
+
+        return getSucReturnObject().setData(balanceRows).toString();
+    }
     /**
      * 订货额类别占比分析
      *
@@ -995,5 +1120,16 @@ public class databoard extends Controller {
         return result;
     }
 
+    public String caluteDate(int datetype,String selectdate) throws Exception {
+        Date date = sdf.parse(selectdate);
+        //创建Calendar实例
+        Calendar cal = Calendar.getInstance();
+        //设置当前时间
+        cal.setTime(date);
+        //在当前时间基础上减一年
+        cal.add(datetype, -1);
+        return sdf.format(cal.getTime());
+    }
+
 
 }