فهرست منبع

总部数据看板,判断是区域经理账号的,按营销组织层级查看数据

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

+ 1 - 1
src/custom/restcontroller/webmanage/sale/databoard/SQL/战区数据_区域.sql

@@ -11,4 +11,4 @@ itemclassname= '配件',cast(ifnull(if(t2.isclose,t2.deliedqty*t2.price,t2.amoun
 						left join sys_hr t4 on t3.siteid = t4.siteid and t3.hrid = t4.hrid
 						left join sys_department t5 on t5.siteid = t4.siteid and t5.departmentid = t4.departmentid
 						where t5.depname='销售部'
-						) t5 on t1.sa_saleareaid=t5.sa_saleareaid and t1.siteid=t5.siteid
+						) t5 on t1.sa_saleareaid=t5.sa_saleareaid and t1.siteid=t5.siteid where $where2$

+ 1 - 1
src/custom/restcontroller/webmanage/sale/databoard/SQL/战区数据_经销商.sql

@@ -12,4 +12,4 @@ sum(if(t4.itemclassname= '配件',cast(ifnull(if(t2.isclose,t2.deliedqty*t2.pric
 						left join sys_hr t4 on t3.siteid = t4.siteid and t3.hrid = t4.hrid
 						left join sys_department t5 on t5.siteid = t4.siteid and t5.departmentid = t4.departmentid 
 						where t5.depname='销售部'
-						) t5 on t1.sys_enterpriseid=t5.sys_enterpriseid and t1.siteid=t5.siteid
+						) t5 on t1.sys_enterpriseid=t5.sys_enterpriseid and t1.siteid=t5.siteid where $where2$

+ 1 - 1
src/custom/restcontroller/webmanage/sale/databoard/SQL/新品销售走势.sql

@@ -1,4 +1,4 @@
  select  DATE_FORMAT(t1.checkdate,'%Y') y,DATE_FORMAT(t1.checkdate,'%m') m,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
  left join plm_item t3 on t2.itemid=t3.itemid and t2.siteid=t3.siteid
- where t1.siteid=$siteid$ and t1.status not in('新建','提交') and DATE_FORMAT(t1.checkdate,'%Y')=$year$ and t3.delistingstatus='新品' group by DATE_FORMAT(t1.checkdate,'%Y'),DATE_FORMAT(t1.checkdate,'%m')
+ where t1.siteid=$siteid$ and $where$ and t1.status not in('新建','提交') and DATE_FORMAT(t1.checkdate,'%Y')=$year$ and t3.delistingstatus='新品' group by DATE_FORMAT(t1.checkdate,'%Y'),DATE_FORMAT(t1.checkdate,'%m')

+ 85 - 4
src/custom/restcontroller/webmanage/sale/databoard/databoard.java

@@ -1,6 +1,7 @@
 package restcontroller.webmanage.sale.databoard;
 
 import beans.itemclass.ItemClass;
+import beans.salearea.SaleArea;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import common.Controller;
@@ -13,6 +14,7 @@ import common.data.RowsMap;
 import common.data.SQLFactory;
 import org.apache.commons.lang.StringUtils;
 import restcontroller.R;
+import restcontroller.sale.promotion.promotion;
 import restcontroller.webmanage.sale.salestarget.personnel;
 
 import javax.annotation.processing.SupportedSourceVersion;
@@ -253,6 +255,10 @@ public class databoard extends Controller {
         StringBuffer where = new StringBuffer(" 1=1 ");
         StringBuffer whereLastYear = new StringBuffer(" 1=1 ");
         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        //区域经理判断
+        where.append(getManangerSqlWhere("t1",hrid));
+        whereLastYear.append(getManangerSqlWhere("t1",hrid));
+
 
         if (!begindate.equals("")) {
             where.append(" and t1.checkdate >='").append(begindate).append(" 00:00:00'");
@@ -417,6 +423,10 @@ public class databoard extends Controller {
         if (sys_enterpriseid > 0) {
             where = where + " and t1.sys_enterpriseid=" + sys_enterpriseid;
         }
+        if(hrid>0){
+            //区域经理判断
+            where = where + getManangerSqlWhere("t1",hrid);
+        }
         /*
          * 过滤条件设置
          */
@@ -510,7 +520,8 @@ public class databoard extends Controller {
         if (!enddate.equals("")) {
             where.append(" and DATE_FORMAT(t1.checkdate, '%Y-%m-%d') <='").append(enddate).append("' ");
         }
-
+        //区域经理判断
+       where.append(getManangerSqlWhere("t1", hrid));
 
         SQLFactory factory;
         if (datatype.equals("销售额")) {
@@ -573,7 +584,9 @@ public class databoard extends Controller {
 
         StringBuffer where = new StringBuffer(" 1=1 ");
         StringBuffer whereLastYear = new StringBuffer(" 1=1 ");
-
+        //区域经理判断
+        where.append(getManangerSqlWhere("t1", hrid));
+        whereLastYear.append(getManangerSqlWhere("t1", hrid));
 
         if (!begindate.equals("")) {
             where.append(" and DATE_FORMAT(t1.checkdate, '%Y-%m-%d') >='").append(begindate).append("' ");
@@ -677,6 +690,10 @@ public class databoard extends Controller {
         String enddate = "";
         StringBuffer where = new StringBuffer(" 1=1 ");
         SQLFactory factory;
+
+        //区域经理判断
+        where.append(getManangerSqlWhere("", hrid));
+
         switch (datetype) {
             case "月":
                 factory = new SQLFactory(this, "财务统计_月");
@@ -818,6 +835,9 @@ public class databoard extends Controller {
         StringBuffer where = new StringBuffer(" 1=1 ");
         StringBuffer whereLastYear = new StringBuffer(" 1=1 ");
 
+        //区域经理判断
+        where.append(getManangerSqlWhere("t1", hrid));
+        whereLastYear.append(getManangerSqlWhere("t1", hrid));
 
         if (!begindate.equals("")) {
             where.append(" and DATE_FORMAT(t1.checkdate, '%Y-%m-%d') >='").append(begindate).append("' ");
@@ -858,10 +878,15 @@ public class databoard extends Controller {
     @API(title = "新品销售走势", apiversion = R.ID20230802103303.v1.class)
     @CACHEING
     public String newProductSalesTrend() throws Exception {
+        StringBuffer where = new StringBuffer(" 1=1 ");
+        //区域经理判断
+        where.append(getManangerSqlWhere("t1", hrid));
+
         SQLFactory factory = new SQLFactory(this, "新品销售走势");
         String year = new SimpleDateFormat("yyyy").format(new Date());
         factory.addParameter("siteid", siteid);
-        factory.addParameter_SQL("year", year);
+        factory.addParameter("year", year);
+        factory.addParameter_SQL("where", where);
         Rows rows = dbConnect.runSqlQuery(factory.getSQL(false));
         List<DataTrans> list = new ArrayList();
         for (Row row : rows) {
@@ -922,6 +947,7 @@ public class databoard extends Controller {
         }
 
         StringBuffer where = new StringBuffer(" 1=1 ");
+        StringBuffer where2 = new StringBuffer(" 1=1 ");
         if (!begindate.equals("")) {
             where.append(" and DATE_FORMAT(t1.checkdate, '%Y-%m-%d') >='").append(begindate).append("' ");
         }
@@ -933,14 +959,19 @@ public class databoard extends Controller {
         SQLFactory factory;
         if (datatype.equals("经销商")) {
             factory = new SQLFactory(this, "战区数据_经销商");
+            //区域经理判断
+            where2.append(getManangerSqlWhere("t1", hrid));
         } else if (datatype.equals("区域")) {
             factory = new SQLFactory(this, "战区数据_区域");
+            //区域经理判断
+            where2.append(getManangerSqlWhere_area("t4", hrid));
         } else {
             return getErrReturnObject().setErrMsg("datatype类型错误").toString();
         }
 
         factory.addParameter("siteid", siteid);
         factory.addParameter_SQL("where", where);
+        factory.addParameter_SQL("where2", where2);
         Rows rows = dbConnect.runSqlQuery(factory.getSQL(false));
 
         BigDecimal totalamount= rows.sum("totalamount");
@@ -968,7 +999,9 @@ public class databoard extends Controller {
         StringBuffer where = new StringBuffer(" 1=1 ");
         if (sys_enterpriseid > 0) {
             where.append(" and t1.sys_enterpriseid=" + sys_enterpriseid);
-
+        }
+        if (hrid > 0) {
+            where.append(getManangerSqlWhere("t1", hrid));
         }
         if (content.containsKey("where")) {
             JSONObject whereObject = content.getJSONObject("where");
@@ -1234,5 +1267,53 @@ public class databoard extends Controller {
         return sdf.format(cal.getTime());
     }
 
+    public String getManangerSqlWhere(String alias,long hrid) throws YosException {
+        String where =" and 1=1 ";
+        SQLFactory areasqlFactory = new SQLFactory(new promotion(content), "区域经理查询下属营销区域");
+        areasqlFactory.addParameter("siteid", siteid);
+        areasqlFactory.addParameter("hrid", hrid);
+        Rows arearows = dbConnect.runSqlQuery(areasqlFactory);
+
+
+        if(arearows.isNotEmpty()){
+            ArrayList<Long> arrayList =arearows.toArrayList("sa_saleareaid", new ArrayList<Long>());
+            arrayList.addAll(SaleArea.getSubSaleAreaIds(this, arrayList));
+            String sql ="";
+            if(alias.equals("")){
+                 sql = " and sys_enterpriseid in (select sys_enterpriseid from sys_enterprise_tradefield where sa_saleareaid in "+arrayList+") ";
+            }else{
+                 sql = " and "+alias+".sys_enterpriseid in (select sys_enterpriseid from sys_enterprise_tradefield where sa_saleareaid in "+arrayList+") ";
+            }
+
+            sql = sql.replace("[", "(").replace("]", ")");
+            where=where+sql;
+        }
+        return where;
+    }
+
+    public String getManangerSqlWhere_area(String alias,long hrid) throws YosException {
+        String where =" and 1=1 ";
+        SQLFactory areasqlFactory = new SQLFactory(new promotion(content), "区域经理查询下属营销区域");
+        areasqlFactory.addParameter("siteid", siteid);
+        areasqlFactory.addParameter("hrid", hrid);
+        Rows arearows = dbConnect.runSqlQuery(areasqlFactory);
+
+
+        if(arearows.isNotEmpty()){
+            ArrayList<Long> arrayList =arearows.toArrayList("sa_saleareaid", new ArrayList<Long>());
+            arrayList.addAll(SaleArea.getSubSaleAreaIds(this, arrayList));
+            String sql ="";
+            if(alias.equals("")){
+                sql = " and sa_saleareaid in "+arrayList;
+            }else{
+                sql = " and "+alias+".sa_saleareaid in "+arrayList;
+            }
+
+            sql = sql.replace("[", "(").replace("]", ")");
+            where=where+sql;
+        }
+        return where;
+    }
+
 
 }