Ver Fonte

数据看板优化补充

hu há 1 ano atrás
pai
commit
23b219ed15

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

@@ -0,0 +1 @@
+select CAST(count(1) AS DECIMAL(16,0)) typestatistics from sa_agents t1 inner join sys_enterprise t2 on  t1.sys_enterpriseid=t2.sys_enterpriseid and t1.siteid=t2.siteid where t1.siteid =$siteid$ and  t1.status='启用'

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

@@ -13,7 +13,9 @@ import common.data.RowsMap;
 import common.data.SQLFactory;
 import org.apache.commons.lang.StringUtils;
 import restcontroller.R;
+import restcontroller.webmanage.sale.salestarget.personnel;
 
+import javax.annotation.processing.SupportedSourceVersion;
 import java.math.BigDecimal;
 import java.text.SimpleDateFormat;
 import java.util.*;
@@ -176,6 +178,10 @@ public class databoard extends Controller {
         String datetype = content.getStringValue("datetype");
         String begindate = "";
         String enddate = "";
+        Calendar c = Calendar.getInstance();
+        int currentMonth = c.get(Calendar.MONTH) + 1;
+        int currentYear = c.get(Calendar.YEAR);
+        ArrayList<Integer> monthList = new ArrayList();
         switch (datetype) {
             case "日":
                 begindate =getDate_Str();
@@ -184,22 +190,49 @@ public class databoard extends Controller {
             case "月":
                 begindate = getMonthFirstDay();
                 enddate = getMonthLastDay();
+                monthList.add(currentMonth);
                 break;
             case "年":
                 begindate = new SimpleDateFormat("yyyy").format(new Date()) + "-01-01";
                 enddate = new SimpleDateFormat("yyyy").format(new Date()) + "-12-31";
+                for (int i=1;i<13;i++) {
+                    monthList.add(i);
+                }
                 break;
             case "季":
                 begindate = sdf.format(getQuarterStart(new Date()).getTime());
                 enddate = sdf.format(getQuarterEnd(new Date()).getTime());
+                if (currentMonth >= 1 && currentMonth <= 3){
+                    monthList.add(1);
+                    monthList.add(2);
+                    monthList.add(3);
+                }else if (currentMonth >= 4 && currentMonth <= 6){
+                    monthList.add(4);
+                    monthList.add(5);
+                    monthList.add(6);
+                }else if (currentMonth >= 7 && currentMonth <= 9){
+                    monthList.add(7);
+                    monthList.add(8);
+                    monthList.add(9);
+                }else if (currentMonth >= 10 && currentMonth <= 12){
+                    monthList.add(10);
+                    monthList.add(11);
+                    monthList.add(12);
+                }
                 break;
             case "上半年":
                 begindate = new SimpleDateFormat("yyyy").format(new Date()) + "-01-01";
                 enddate = new SimpleDateFormat("yyyy").format(new Date()) + "-06-30";
+                for (int i=1;i<7;i++) {
+                    monthList.add(i);
+                }
                 break;
             case "下半年":
                 begindate = new SimpleDateFormat("yyyy").format(new Date()) + "-07-01";
                 enddate = new SimpleDateFormat("yyyy").format(new Date()) + "-12-31";
+                for (int i=6;i<13;i++) {
+                    monthList.add(i);
+                }
                 break;
             default:
                 break;
@@ -296,6 +329,12 @@ public class databoard extends Controller {
         factory.addParameter_SQL("where", where);
         rows = dbConnect.runSqlQuery(factory.getSQL(false));
 
+        //总客户数
+        jsonObject = new JSONObject();
+        SQLFactory allfactory = new SQLFactory(this, "客户数统计查询");
+        allfactory.addParameter("siteid", siteid);
+        Rows allRows = dbConnect.runSqlQuery(allfactory.getSQL(false));
+
         factoryLastYear = new SQLFactory(this, "销售客户数统计查询");
         factoryLastYear.addParameter("siteid", siteid);
         factoryLastYear.addParameter_SQL("where", whereLastYear);
@@ -303,12 +342,18 @@ public class databoard extends Controller {
 
         jsonObject.put("type", "客户数");
         jsonObject.put("currentData", rows.get(0).getBigDecimal("typestatistics"));
+        jsonObject.put("allcurrentData", allRows.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));
         }
+        if (allRows.get(0).getBigDecimal("typestatistics").compareTo(BigDecimal.ZERO) == 0) {
+            jsonObject.put("allrate", 0);
+        } else {
+            jsonObject.put("allrate", (rows.get(0).getBigDecimal("typestatistics")).divide(allRows.get(0).getBigDecimal("typestatistics"), 4, BigDecimal.ROUND_HALF_UP));
+        }
         jsonArray.add(jsonObject);
 
         //回款
@@ -323,6 +368,22 @@ public class databoard extends Controller {
         factoryLastYear.addParameter_SQL("where", whereLastYear);
         rowsLastYear = dbConnect.runSqlQuery(factoryLastYear.getSQL(false));
 
+        Rows salestargetbillrows =dbConnect.runSqlQuery("select * from sa_salestargetbill where siteid='"+siteid+"' and year="+currentYear+" and targettype='人员目标' and assessmentindicators='收款'");
+        long sa_salestargetbillid=0;
+        if(salestargetbillrows.isNotEmpty()){
+            sa_salestargetbillid=salestargetbillrows.get(0).getLong("sa_salestargetbillid");
+        }
+        SQLFactory personnelsqlFactory = new SQLFactory(new personnel(new JSONObject()), "人员-目标详情列表");
+        personnelsqlFactory.addParameter("sa_salestargetbillid", sa_salestargetbillid);
+        personnelsqlFactory.addParameter_SQL("where", "t.type!='区域汇总'");
+        personnelsqlFactory.addParameter("siteid", siteid);
+        Rows salestargetrows = dbConnect.runSqlQuery(personnelsqlFactory.getSQL());
+        BigDecimal sumAmount =BigDecimal.ZERO;
+        for (int month:monthList) {
+            String colum="m"+month+"l";
+            //System.out.println(colum+":"+salestargetrows.sum(colum));
+            sumAmount=sumAmount.add(salestargetrows.sum(colum));
+        }
         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")));
@@ -330,6 +391,12 @@ public class databoard extends Controller {
             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));
+        }
+         //System.out.println(sumAmount);
+        if (sumAmount.compareTo(BigDecimal.ZERO) == 0) {
+            jsonObject.put("rate", 0);
+        } else {
+            jsonObject.put("rate", (rows.get(0).getBigDecimal("typestatistics")).divide(sumAmount.multiply(new BigDecimal(100)), 4, BigDecimal.ROUND_HALF_UP));
         }
         jsonArray.add(jsonObject);