فهرست منبع

区域经理经销商统计接口

hu 1 سال پیش
والد
کامیت
a37671e7b1

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

@@ -5346,6 +5346,10 @@ public class R {
         public static class v1 {
         }
     }
+    public static class ID20231103100503 {
+        public static class v1 {
+        }
+    }
 
 }
 

+ 9 - 2
src/custom/restcontroller/webmanage/sale/salestarget/SQL/企业-业绩目标完成列表.sql

@@ -44,7 +44,9 @@ SELECT DISTINCT m.year,
                 m11.target_l                               m11l,
                 m11.target_h                               m11h,
                 m12.target_l                               m12l,
-                m12.target_h                               m12h
+                m12.target_h                               m12h,
+							  ifnull(t3.sumamount_year,0) sumamount_year,
+								ifnull(t4.sumamount_currentmonth,0) sumamount_currentmonth
 from sa_salestarget m
          LEFT JOIN sa_salestarget m1 ON m1.year = m.year and m1.point = 1 and m.sys_enterpriseid = m1.sys_enterpriseid
          LEFT JOIN sa_salestarget m2 ON m2.year = m.year and m2.point = 2 and m.sys_enterpriseid = m2.sys_enterpriseid
@@ -60,4 +62,9 @@ from sa_salestarget m
          LEFT JOIN sa_salestarget m12 ON m12.year = m.year and m12.point = 12 and m.sys_enterpriseid = m12.sys_enterpriseid
          LEFT JOIN sys_enterprise t1 on t1.sys_enterpriseid=m.sys_enterpriseid
          LEFT JOIN sa_agents t2 on t1.sys_enterpriseid=t2.sys_enterpriseid and t1.siteid=t2.siteid
-ORDER BY m.year desc
+				 left join (select * from(select  sys_enterpriseid,siteid,DATE_FORMAT(checkdate,'%Y') date,sum(amount) sumamount_year from sa_cashbill where type=1 group by sys_enterpriseid,siteid,DATE_FORMAT(checkdate,'%Y')) t
+           where  DATE_FORMAT(NOW(), '%Y')=date) t3 on t1.sys_enterpriseid=t3.sys_enterpriseid and t1.siteid=t3.siteid
+        left join (select * from(select  sys_enterpriseid,siteid,DATE_FORMAT(checkdate,'%Y-%m') date,sum(amount) sumamount_currentmonth from sa_cashbill where type=1 group by sys_enterpriseid,siteid,DATE_FORMAT(checkdate,'%Y-%m')) t
+           where  DATE_FORMAT(NOW(), '%Y-%m')=date) t4 on t1.sys_enterpriseid=t4.sys_enterpriseid and t1.siteid=t4.siteid
+ORDER BY m.year desc
+

+ 178 - 0
src/custom/restcontroller/webmanage/sale/salestarget/enterprisetarget.java

@@ -1,6 +1,7 @@
 package restcontroller.webmanage.sale.salestarget;
 
 import beans.datacontrllog.DataContrlLog;
+import beans.salearea.SaleArea;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import common.Controller;
@@ -12,9 +13,13 @@ import common.data.*;
 import org.apache.commons.lang.StringUtils;
 import org.apache.poi.xssf.usermodel.*;
 import restcontroller.R;
+import restcontroller.sale.promotion.promotion;
+import restcontroller.sale.salestarget.enterprise;
 import restcontroller.webmanage.saletool.orderclue.ExportExcel;
 
+import java.math.BigDecimal;
 import java.util.ArrayList;
+import java.util.Calendar;
 import java.util.HashMap;
 
 public class enterprisetarget extends Controller {
@@ -193,6 +198,101 @@ public class enterprisetarget extends Controller {
         return getSucReturnObject().setData(rows).toString();
     }
 
+    @API(title = "经销商业绩列表(区域经理)", apiversion = R.ID20231103100503.v1.class)
+    public String selectAgentTargetList() throws YosException {
+         /*
+          过滤条件设置
+         */
+        Calendar calendar = Calendar.getInstance();
+        int curryear = calendar.get(Calendar.YEAR);
+        StringBuffer where = new StringBuffer(" 1=1 and year="+curryear);
+
+        SQLFactory areasqlFactory = new SQLFactory(new promotion(content), "区域经理查询下属营销区域");
+        areasqlFactory.addParameter("siteid", siteid);
+        areasqlFactory.addParameter("hrid", hrid);
+        Rows arearows = dbConnect.runSqlQuery(areasqlFactory);
+
+
+        if(arearows.isNotEmpty() && arearows.size()>1){
+            ArrayList<Long> arrayList =arearows.toArrayList("sa_saleareaid", new ArrayList<Long>());
+            arrayList.addAll(SaleArea.getSubSaleAreaIds(this, arrayList));
+            String sql = " and sys_enterpriseid in (select sys_enterpriseid from sys_enterprise_tradefield where sa_saleareaid in "+arrayList+") ";
+            sql = sql.replace("[", "(").replace("]", ")");
+            where=where.append(sql);
+        }
+
+
+
+        //考核指标类型
+        String assessmentindicators="";
+        if(curryear!=0){
+            Rows rows =dbConnect.runSqlQuery("SELECT assessmentindicators FROM sa_salestargetbill WHERE `year` = " + curryear + " AND targettype ='企业目标' AND siteid = '" + siteid + "'");
+            if(rows.isNotEmpty()){
+                assessmentindicators=rows.get(0).getString("assessmentindicators");
+            }
+        }
+
+
+        SQLFactory sqlFactory = new SQLFactory(this, "企业-业绩目标完成列表");
+        sqlFactory.addParameter_SQL("where", where);
+        sqlFactory.addParameter("siteid", siteid);
+        String sql = sqlFactory.getSQL();
+        Rows rows = dbConnect.runSqlQuery(sql);
+
+        Rows actualRows = new Rows();
+        //开票
+//        if (assessmentindicators.equals("开票")) {
+//            sqlFactory = new SQLFactory(this, "企业-开票");
+//        }
+//        //订单
+//        if (assessmentindicators.equals("订单")) {
+//            sqlFactory = new SQLFactory(this, "企业-订单");
+//        }
+//        //出货
+//        if (assessmentindicators.equals("出货")) {
+//            sqlFactory = new SQLFactory(this, "企业-出货");
+//        }
+        //收款
+        if (assessmentindicators.equals("收款")) {
+            sqlFactory = new SQLFactory(this, "企业-收款");
+            sqlFactory.addParameter_in("sys_enterpriseid", rows.toArrayList("sys_enterpriseid",new ArrayList<Long>()));
+            sqlFactory.addParameter("siteid", siteid);
+            sqlFactory.addParameter("year", curryear);
+            actualRows = dbConnect.runSqlQuery(sqlFactory);
+        }
+        for (Row row : rows) {
+            //初始化
+            if (assessmentindicators.equals("收款")) {
+                row = addActualRow(row);
+                Long year = row.getLong("year");
+                Long sys_enterpriseid = row.getLong("sys_enterpriseid");
+                Row actualRow = new Row();
+                for (Row tempActualRow : actualRows) {
+                    if (tempActualRow.getLong("year") == year && tempActualRow.getLong("sys_enterpriseid")==sys_enterpriseid) {
+                        actualRow.putAll(tempActualRow);
+                    }
+                }
+                row.putAll(actualRow);
+                row.putAll(calculate(row, actualRow));
+                Rows monthRows = new Rows();
+                for (int i = 1; i < 13; i++) {
+                    Row monthRow = new Row();
+                    monthRow.put("l", row.getString("m" + i + "l"));
+                    monthRow.put("h", row.getString("m" + i + "h"));
+                    monthRow.put("a", row.getString("m" + i + "a"));
+                    monthRow.put("pl", row.getString("m" + i + "pl"));
+                    monthRow.put("ph", row.getString("m" + i + "ph"));
+                    monthRow.put("month", i);
+                    monthRows.add(monthRow);
+                }
+                row.put("month", monthRows);
+            }
+
+        }
+
+        return getSucReturnObject().setData(rows).toString();
+    }
+
     public String getSql(String target_l, String target_h, Long id, Long sys_enterpriseid, String type, int point) {
 
         return " UPDATE sa_salestarget SET target_l=" + target_l + ",target_h = " + target_h + "   WHERE sa_salestargetbillid =" + id + " and sys_enterpriseid =" + sys_enterpriseid + " and type ='" + type + "' AND point = " + point;
@@ -495,5 +595,83 @@ public class enterprisetarget extends Controller {
         }
         return sheet;
     }
+    //添加实际数据
+    public Row addActualRow(Row targetRow) {
+        String key = "y1a";
+        targetRow.put(key, 0);
+        for (int i = 1; i < 5; i++) {
+            key = "s" + i + "a";
+            targetRow.put(key, 0);
+        }
+        for (int i = 1; i < 13; i++) {
+            key = "m" + i + "a";
+            targetRow.put(key, 0);
+        }
+
+        return targetRow;
+    }
+
+    public Row calculate(Row targetRow, Row actualRow) {
+
+        Row row = new Row();
+        String key_l = "y1l";
+        String key_h = "y1h";
+        String key_a = "y1a";
+        String key_p_l = "y1pl";
+        String key_p_h = "y1ph";
+        if (targetRow.getDouble(key_l) == 0) {
+            row.put(key_p_l, 0);
+        } else {
+            row.put(key_p_l, getPercent(actualRow.getDouble(key_a), targetRow.getDouble(key_l)));
+        }
+        if (targetRow.getDouble(key_h) == 0) {
+            row.put(key_p_h, 0);
+        } else {
+            row.put(key_p_h, getPercent(actualRow.getDouble(key_a), targetRow.getDouble(key_h)));
+        }
+
+        for (int i = 1; i < 5; i++) {
+            key_l = "s" + i + "l";
+            key_h = "s" + i + "h";
+            key_a = "s" + i + "a";
+            key_p_l = "s" + i + "pl";
+            key_p_h = "s" + i + "ph";
+            if (targetRow.getDouble(key_l) == 0) {
+                row.put(key_p_l, 0);
+            } else {
+                row.put(key_p_l, getPercent(actualRow.getDouble(key_a), targetRow.getDouble(key_l)));
+            }
+            if (targetRow.getDouble(key_h) == 0) {
+                row.put(key_p_h, 0);
+            } else {
+                row.put(key_p_h, getPercent(actualRow.getDouble(key_a), targetRow.getDouble(key_h)));
+            }
+        }
+        for (int i = 1; i < 13; i++) {
+            key_l = "m" + i + "l";
+            key_h = "m" + i + "h";
+            key_a = "m" + i + "a";
+            key_p_l = "m" + i + "pl";
+            key_p_h = "m" + i + "ph";
+            if (targetRow.getDouble(key_l) == 0) {
+                row.put(key_p_l, 0);
+            } else {
+                row.put(key_p_l, getPercent(actualRow.getDouble(key_a), targetRow.getDouble(key_l)));
+            }
+            if (targetRow.getDouble(key_h) == 0) {
+                row.put(key_p_h, 0);
+            } else {
+                row.put(key_p_h, getPercent(actualRow.getDouble(key_a), targetRow.getDouble(key_h)));
+            }
+        }
+
+        return row;
+    }
 
+    //(实际-目标)/目标
+    public double getPercent(Double a, Double b) {
+        double c = a * 100 / b;
+        BigDecimal bigDecimal = new BigDecimal(c);
+        return bigDecimal.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
+    }
 }