Просмотр исходного кода

经销商业绩目标模块更新

hu 2 лет назад
Родитель
Сommit
48bb0f3c3e

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

@@ -5285,6 +5285,14 @@ public class R {
         public static class v1 {
         }
     }
+    public static class ID20231018142103 {
+        public static class v1 {
+        }
+    }
+    public static class ID20231018162103 {
+        public static class v1 {
+        }
+    }
 
 }
 

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

@@ -1,10 +1,10 @@
 with sa_salestarget as (
-    SELECT point, sum(target_l) target_l, sum(target_h) target_h, year,tradefield from sa_salestarget
-    WHERE sys_enterpriseid = $sys_enterpriseid$ and type = '月' and targettype='企业目标' and siteid=$siteid$ and $where$
-    GROUP  BY point ,year,tradefield
+    SELECT point, sum(target_l) target_l, sum(target_h) target_h, year,sys_enterpriseid from sa_salestarget
+    WHERE  type = '月' and targettype='企业目标' and siteid=$siteid$ and $where$
+    GROUP  BY point ,year,sys_enterpriseid
     )
 SELECT DISTINCT m.year,
-                m.tradefield,
+                m.sys_enterpriseid,
                 m1.target_l + m2.target_l + m3.target_l + m4.target_l + m5.target_l + m6.target_l +
                 m7.target_l + m8.target_l + m9.target_l + m10.target_l + m11.target_l +
                 m12.target_l                               y1l,
@@ -44,16 +44,16 @@ SELECT DISTINCT m.year,
                 m12.target_l                               m12l,
                 m12.target_h                               m12h
 from sa_salestarget m
-         LEFT JOIN sa_salestarget m1 ON m1.year = m.year and m1.point = 1 and m.tradefield = m1.tradefield
-         LEFT JOIN sa_salestarget m2 ON m2.year = m.year and m2.point = 2 and m.tradefield = m2.tradefield
-         LEFT JOIN sa_salestarget m3 ON m3.year = m.year and m3.point = 3 and m.tradefield = m3.tradefield
-         LEFT JOIN sa_salestarget m4 ON m4.year = m.year and m4.point = 4 and m.tradefield = m4.tradefield
-         LEFT JOIN sa_salestarget m5 ON m5.year = m.year and m5.point = 5 and m.tradefield = m5.tradefield
-         LEFT JOIN sa_salestarget m6 ON m6.year = m.year and m6.point = 6 and m.tradefield = m6.tradefield
-         LEFT JOIN sa_salestarget m7 ON m7.year = m.year and m7.point = 7 and m.tradefield = m7.tradefield
-         LEFT JOIN sa_salestarget m8 ON m8.year = m.year and m8.point = 8 and m.tradefield = m8.tradefield
-         LEFT JOIN sa_salestarget m9 ON m9.year = m.year and m9.point = 9 and m.tradefield = m9.tradefield
-         LEFT JOIN sa_salestarget m10 ON m10.year = m.year and m10.point = 10 and m.tradefield = m10.tradefield
-         LEFT JOIN sa_salestarget m11 ON m11.year = m.year and m11.point = 11 and m.tradefield = m11.tradefield
-         LEFT JOIN sa_salestarget m12 ON m12.year = m.year and m12.point = 12 and m.tradefield = m12.tradefield
+         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
+         LEFT JOIN sa_salestarget m3 ON m3.year = m.year and m3.point = 3 and m.sys_enterpriseid = m3.sys_enterpriseid
+         LEFT JOIN sa_salestarget m4 ON m4.year = m.year and m4.point = 4 and m.sys_enterpriseid = m4.sys_enterpriseid
+         LEFT JOIN sa_salestarget m5 ON m5.year = m.year and m5.point = 5 and m.sys_enterpriseid = m5.sys_enterpriseid
+         LEFT JOIN sa_salestarget m6 ON m6.year = m.year and m6.point = 6 and m.sys_enterpriseid = m6.sys_enterpriseid
+         LEFT JOIN sa_salestarget m7 ON m7.year = m.year and m7.point = 7 and m.sys_enterpriseid = m7.sys_enterpriseid
+         LEFT JOIN sa_salestarget m8 ON m8.year = m.year and m8.point = 8 and m.sys_enterpriseid = m8.sys_enterpriseid
+         LEFT JOIN sa_salestarget m9 ON m9.year = m.year and m9.point = 9 and m.sys_enterpriseid = m9.sys_enterpriseid
+         LEFT JOIN sa_salestarget m10 ON m10.year = m.year and m10.point = 10 and m.sys_enterpriseid = m10.sys_enterpriseid
+         LEFT JOIN sa_salestarget m11 ON m11.year = m.year and m11.point = 11 and m.sys_enterpriseid = m11.sys_enterpriseid
+         LEFT JOIN sa_salestarget m12 ON m12.year = m.year and m12.point = 12 and m.sys_enterpriseid = m12.sys_enterpriseid
 ORDER BY m.year desc

+ 28 - 17
src/custom/restcontroller/sale/salestarget/SQL/企业-出货.sql

@@ -1,11 +1,22 @@
 with sa_salestarget as (
-    SELECT  0+CAST(sum(deliedqty*price) AS CHAR) amount, MONTH(t2.billdate) point,YEAR(t2.billdate) year,t2.tradefield FROM sa_orderitems t1
-    INNER JOIN sa_order t2 ON t1.sa_orderid=t2.sa_orderid AND t1.siteid=t2.siteid
-WHERE t1.siteid = $siteid$ and sys_enterpriseid = $sys_enterpriseid$
-GROUP BY point,year,tradefield
+    select 0+CAST(sum(amount) AS CHAR) amount,point,sys_enterpriseid,year from(SELECT  (t5.sumqty*t1.price) amount, MONTH (t2.createdate) point,ifnull(t2.sys_enterpriseid,0) sys_enterpriseid,YEAR(t2.createdate) year
+FROM sa_orderitems t1
+    LEFT JOIN sa_order t2 ON t1.sa_orderid=t2.sa_orderid AND t1.siteid=t2.siteid
+		left join sys_enterprise_tradefield t3 on t2.sys_enterpriseid=t3.sys_enterpriseid and t2.siteid=t3.siteid
+		left join sa_salearea t4 on t4.sa_saleareaid=t3.sa_saleareaid and t4.siteid=t3.siteid
+ inner join (
+SELECT  t1.sa_orderitemsid,t1.siteid,
+        SUM(ifnull(t1.qty,0)) sumqty
+FROM st_stockbill_items t1
+         inner join st_stockbill t2 on t1.siteid = t2.siteid and t1.st_stockbillid = t2.st_stockbillid
+         inner join sa_orderitems t4 on t1.sa_orderitemsid=t4.sa_orderitemsid and t1.siteid = t4.siteid
+WHERE t2.STATUS ='审核' and t2.rb=1 group by t1.sa_orderitemsid,t1.siteid) t5 on t5.sa_orderitemsid=t1.sa_orderitemsid and t5.siteid=t1.siteid
+
+WHERE YEAR (t2.createdate)=$year$ and t2.sys_enterpriseid in $sys_enterpriseid$ AND t1.siteid=$siteid$) a
+GROUP BY point,sys_enterpriseid,year
     )
 SELECT DISTINCT m.year,
-                m.tradefield,
+                m.sys_enterpriseid,
                 ifnull(m1.amount,0)+ ifnull(m2.amount,0)+ifnull(m3.amount,0)+ ifnull(m4.amount,0)+ ifnull(m5.amount,0)+  ifnull(m6.amount,0)+ ifnull(m7.amount,0)+ ifnull(m8.amount,0)+  ifnull(m9.amount,0) + ifnull(m10.amount,0)+ ifnull(m11.amount,0)+  ifnull(m12.amount,0)  as y1a,
                 ifnull(m1.amount,0)+ ifnull(m2.amount,0)+ifnull(m3.amount,0)  as s1a,
                 ifnull(m4.amount,0)+ ifnull(m5.amount,0)+ifnull(m6.amount,0)  as s2a,
@@ -24,16 +35,16 @@ SELECT DISTINCT m.year,
                 ifnull(m11.amount,0) as m11a,
                 ifnull(m12.amount,0) as m12a
 from sa_salestarget m
-         LEFT JOIN sa_salestarget m1 ON m1.year = m.year and m1.point = 1 and m.tradefield = m1.tradefield
-         LEFT JOIN sa_salestarget m2 ON m2.year = m.year and m2.point = 2 and m.tradefield = m2.tradefield
-         LEFT JOIN sa_salestarget m3 ON m3.year = m.year and m3.point = 3 and m.tradefield = m3.tradefield
-         LEFT JOIN sa_salestarget m4 ON m4.year = m.year and m4.point = 4 and m.tradefield = m4.tradefield
-         LEFT JOIN sa_salestarget m5 ON m5.year = m.year and m5.point = 5 and m.tradefield = m5.tradefield
-         LEFT JOIN sa_salestarget m6 ON m6.year = m.year and m6.point = 6 and m.tradefield = m6.tradefield
-         LEFT JOIN sa_salestarget m7 ON m7.year = m.year and m7.point = 7 and m.tradefield = m7.tradefield
-         LEFT JOIN sa_salestarget m8 ON m8.year = m.year and m8.point = 8 and m.tradefield = m8.tradefield
-         LEFT JOIN sa_salestarget m9 ON m9.year = m.year and m9.point = 9 and m.tradefield = m9.tradefield
-         LEFT JOIN sa_salestarget m10 ON m10.year = m.year and m10.point = 10 and m.tradefield = m10.tradefield
-         LEFT JOIN sa_salestarget m11 ON m11.year = m.year and m11.point = 11 and m.tradefield = m11.tradefield
-         LEFT JOIN sa_salestarget m12 ON m12.year = m.year and m12.point = 12 and m.tradefield = m12.tradefield
+         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
+         LEFT JOIN sa_salestarget m3 ON m3.year = m.year and m3.point = 3 and m.sys_enterpriseid = m3.sys_enterpriseid
+         LEFT JOIN sa_salestarget m4 ON m4.year = m.year and m4.point = 4 and m.sys_enterpriseid = m4.sys_enterpriseid
+         LEFT JOIN sa_salestarget m5 ON m5.year = m.year and m5.point = 5 and m.sys_enterpriseid = m5.sys_enterpriseid
+         LEFT JOIN sa_salestarget m6 ON m6.year = m.year and m6.point = 6 and m.sys_enterpriseid = m6.sys_enterpriseid
+         LEFT JOIN sa_salestarget m7 ON m7.year = m.year and m7.point = 7 and m.sys_enterpriseid = m7.sys_enterpriseid
+         LEFT JOIN sa_salestarget m8 ON m8.year = m.year and m8.point = 8 and m.sys_enterpriseid = m8.sys_enterpriseid
+         LEFT JOIN sa_salestarget m9 ON m9.year = m.year and m9.point = 9 and m.sys_enterpriseid = m9.sys_enterpriseid
+         LEFT JOIN sa_salestarget m10 ON m10.year = m.year and m10.point = 10 and m.sys_enterpriseid = m10.sys_enterpriseid
+         LEFT JOIN sa_salestarget m11 ON m11.year = m.year and m11.point = 11 and m.sys_enterpriseid = m11.sys_enterpriseid
+         LEFT JOIN sa_salestarget m12 ON m12.year = m.year and m12.point = 12 and m.sys_enterpriseid = m12.sys_enterpriseid
 ORDER BY m.year desc

+ 16 - 16
src/custom/restcontroller/sale/salestarget/SQL/企业-开票.sql

@@ -1,11 +1,11 @@
 with sa_salestarget as (
-    SELECT 0+CAST(sum(invoiceamount) AS CHAR) amount, MONTH(t2.billdate) point,YEAR(t2.billdate) year,t2.tradefield FROM sa_orderitems t1
+      select point,year,sys_enterpriseid,sum(amount) amount from (SELECT  0+CAST(if(isclose,t1.price*t1.deliedqty,amount) AS CHAR) amount, MONTH(t2.billdate) point,YEAR(t2.billdate) year,t2.sys_enterpriseid FROM sa_orderitems t1
     INNER JOIN sa_order t2 ON t1.sa_orderid=t2.sa_orderid AND t1.siteid=t2.siteid
-    WHERE t1.siteid = $siteid$ and sys_enterpriseid = $sys_enterpriseid$
-    GROUP BY point,year,tradefield
+WHERE t1.siteid = $siteid$ and t2.sys_enterpriseid in $sys_enterpriseid$ and t2.status in('提交','审核','手工关闭','关闭') and YEAR(t2.billdate)=$year$) a
+GROUP BY point,year,sys_enterpriseid
     )
 SELECT DISTINCT m.year,
-                m.tradefield,
+                m.sys_enterpriseid,
                 ifnull(m1.amount,0)+ ifnull(m2.amount,0)+ifnull(m3.amount,0)+ ifnull(m4.amount,0)+ ifnull(m5.amount,0)+  ifnull(m6.amount,0)+ ifnull(m7.amount,0)+ ifnull(m8.amount,0)+  ifnull(m9.amount,0) + ifnull(m10.amount,0)+ ifnull(m11.amount,0)+  ifnull(m12.amount,0)  as y1a,
                 ifnull(m1.amount,0)+ ifnull(m2.amount,0)+ifnull(m3.amount,0)  as s1a,
                 ifnull(m4.amount,0)+ ifnull(m5.amount,0)+ifnull(m6.amount,0)  as s2a,
@@ -24,16 +24,16 @@ SELECT DISTINCT m.year,
                 ifnull(m11.amount,0) as m11a,
                 ifnull(m12.amount,0) as m12a
 from sa_salestarget m
-         LEFT JOIN sa_salestarget m1 ON m1.year = m.year and m1.point = 1 and m.tradefield = m1.tradefield
-         LEFT JOIN sa_salestarget m2 ON m2.year = m.year and m2.point = 2 and m.tradefield = m2.tradefield
-         LEFT JOIN sa_salestarget m3 ON m3.year = m.year and m3.point = 3 and m.tradefield = m3.tradefield
-         LEFT JOIN sa_salestarget m4 ON m4.year = m.year and m4.point = 4 and m.tradefield = m4.tradefield
-         LEFT JOIN sa_salestarget m5 ON m5.year = m.year and m5.point = 5 and m.tradefield = m5.tradefield
-         LEFT JOIN sa_salestarget m6 ON m6.year = m.year and m6.point = 6 and m.tradefield = m6.tradefield
-         LEFT JOIN sa_salestarget m7 ON m7.year = m.year and m7.point = 7 and m.tradefield = m7.tradefield
-         LEFT JOIN sa_salestarget m8 ON m8.year = m.year and m8.point = 8 and m.tradefield = m8.tradefield
-         LEFT JOIN sa_salestarget m9 ON m9.year = m.year and m9.point = 9 and m.tradefield = m9.tradefield
-         LEFT JOIN sa_salestarget m10 ON m10.year = m.year and m10.point = 10 and m.tradefield = m10.tradefield
-         LEFT JOIN sa_salestarget m11 ON m11.year = m.year and m11.point = 11 and m.tradefield = m11.tradefield
-         LEFT JOIN sa_salestarget m12 ON m12.year = m.year and m12.point = 12 and m.tradefield = m12.tradefield
+         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
+         LEFT JOIN sa_salestarget m3 ON m3.year = m.year and m3.point = 3 and m.sys_enterpriseid = m3.sys_enterpriseid
+         LEFT JOIN sa_salestarget m4 ON m4.year = m.year and m4.point = 4 and m.sys_enterpriseid = m4.sys_enterpriseid
+         LEFT JOIN sa_salestarget m5 ON m5.year = m.year and m5.point = 5 and m.sys_enterpriseid = m5.sys_enterpriseid
+         LEFT JOIN sa_salestarget m6 ON m6.year = m.year and m6.point = 6 and m.sys_enterpriseid = m6.sys_enterpriseid
+         LEFT JOIN sa_salestarget m7 ON m7.year = m.year and m7.point = 7 and m.sys_enterpriseid = m7.sys_enterpriseid
+         LEFT JOIN sa_salestarget m8 ON m8.year = m.year and m8.point = 8 and m.sys_enterpriseid = m8.sys_enterpriseid
+         LEFT JOIN sa_salestarget m9 ON m9.year = m.year and m9.point = 9 and m.sys_enterpriseid = m9.sys_enterpriseid
+         LEFT JOIN sa_salestarget m10 ON m10.year = m.year and m10.point = 10 and m.sys_enterpriseid = m10.sys_enterpriseid
+         LEFT JOIN sa_salestarget m11 ON m11.year = m.year and m11.point = 11 and m.sys_enterpriseid = m11.sys_enterpriseid
+         LEFT JOIN sa_salestarget m12 ON m12.year = m.year and m12.point = 12 and m.sys_enterpriseid = m12.sys_enterpriseid
 ORDER BY m.year desc

+ 38 - 0
src/custom/restcontroller/sale/salestarget/SQL/企业-收款.sql

@@ -0,0 +1,38 @@
+with sa_salestarget as (
+   select point,year,sys_enterpriseid,sum(amount) amount from (SELECT 0+CAST(amount AS CHAR) amount, MONTH(billdate) point,YEAR(billdate) year,sys_enterpriseid FROM sa_cashbill
+    WHERE siteid =$siteid$ AND status in('审核') and type=1 and YEAR (billdate)=$year$ and sys_enterpriseid in $sys_enterpriseid$) a
+    GROUP BY point,year,sys_enterpriseid
+    )
+SELECT DISTINCT m.year,
+                m.sys_enterpriseid,
+                ifnull(m1.amount,0)+ ifnull(m2.amount,0)+ifnull(m3.amount,0)+ ifnull(m4.amount,0)+ ifnull(m5.amount,0)+  ifnull(m6.amount,0)+ ifnull(m7.amount,0)+ ifnull(m8.amount,0)+  ifnull(m9.amount,0) + ifnull(m10.amount,0)+ ifnull(m11.amount,0)+  ifnull(m12.amount,0)  as y1a,
+                ifnull(m1.amount,0)+ ifnull(m2.amount,0)+ifnull(m3.amount,0)  as s1a,
+                ifnull(m4.amount,0)+ ifnull(m5.amount,0)+ifnull(m6.amount,0)  as s2a,
+                ifnull(m7.amount,0)+ ifnull(m8.amount,0)+ifnull(m9.amount,0)  as s3a,
+                ifnull(m10.amount,0)+ ifnull(m11.amount,0)+ifnull(m12.amount,0) as s4a,
+                ifnull(m1.amount,0) as m1a,
+                ifnull(m2.amount,0) as m2a,
+                ifnull(m3.amount,0) as m3a,
+                ifnull(m4.amount,0) as m4a,
+                ifnull(m5.amount,0) as m5a,
+                ifnull(m6.amount,0) as m6a,
+                ifnull(m7.amount,0) as m7a,
+                ifnull(m8.amount,0) as m8a,
+                ifnull(m9.amount,0) as m9a,
+                ifnull(m10.amount,0) as m10a,
+                ifnull(m11.amount,0) as m11a,
+                ifnull(m12.amount,0) as m12a
+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
+         LEFT JOIN sa_salestarget m3 ON m3.year = m.year and m3.point = 3 and m.sys_enterpriseid = m3.sys_enterpriseid
+         LEFT JOIN sa_salestarget m4 ON m4.year = m.year and m4.point = 4 and m.sys_enterpriseid = m4.sys_enterpriseid
+         LEFT JOIN sa_salestarget m5 ON m5.year = m.year and m5.point = 5 and m.sys_enterpriseid = m5.sys_enterpriseid
+         LEFT JOIN sa_salestarget m6 ON m6.year = m.year and m6.point = 6 and m.sys_enterpriseid = m6.sys_enterpriseid
+         LEFT JOIN sa_salestarget m7 ON m7.year = m.year and m7.point = 7 and m.sys_enterpriseid = m7.sys_enterpriseid
+         LEFT JOIN sa_salestarget m8 ON m8.year = m.year and m8.point = 8 and m.sys_enterpriseid = m8.sys_enterpriseid
+         LEFT JOIN sa_salestarget m9 ON m9.year = m.year and m9.point = 9 and m.sys_enterpriseid = m9.sys_enterpriseid
+         LEFT JOIN sa_salestarget m10 ON m10.year = m.year and m10.point = 10 and m.sys_enterpriseid = m10.sys_enterpriseid
+         LEFT JOIN sa_salestarget m11 ON m11.year = m.year and m11.point = 11 and m.sys_enterpriseid = m11.sys_enterpriseid
+         LEFT JOIN sa_salestarget m12 ON m12.year = m.year and m12.point = 12 and m.sys_enterpriseid = m12.sys_enterpriseid
+ORDER BY m.year desc

+ 16 - 16
src/custom/restcontroller/sale/salestarget/SQL/企业-订单.sql

@@ -1,11 +1,11 @@
 with sa_salestarget as (
-    SELECT  0+CAST(sum(amount) AS CHAR) amount, MONTH(t2.billdate) point,YEAR(t2.billdate) year,t2.tradefield FROM sa_orderitems t1
+      select point,year,sys_enterpriseid,sum(amount) amount from (SELECT  0+CAST(if(isclose,t1.price*t1.deliedqty,amount) AS CHAR) amount, MONTH(t2.billdate) point,YEAR(t2.billdate) year,t2.sys_enterpriseid FROM sa_orderitems t1
     INNER JOIN sa_order t2 ON t1.sa_orderid=t2.sa_orderid AND t1.siteid=t2.siteid
-WHERE t1.siteid = $siteid$ and sys_enterpriseid = $sys_enterpriseid$
-GROUP BY point,year,tradefield
+WHERE t1.siteid = $siteid$ and t2.sys_enterpriseid in $sys_enterpriseid$ and t2.status in('提交','审核','手工关闭','关闭') and YEAR(t2.billdate)=$year$ ) a
+GROUP BY point,year,sys_enterpriseid
     )
 SELECT DISTINCT m.year,
-                m.tradefield,
+                m.sys_enterpriseid,
                 ifnull(m1.amount,0)+ ifnull(m2.amount,0)+ifnull(m3.amount,0)+ ifnull(m4.amount,0)+ ifnull(m5.amount,0)+  ifnull(m6.amount,0)+ ifnull(m7.amount,0)+ ifnull(m8.amount,0)+  ifnull(m9.amount,0) + ifnull(m10.amount,0)+ ifnull(m11.amount,0)+  ifnull(m12.amount,0)  as y1a,
                 ifnull(m1.amount,0)+ ifnull(m2.amount,0)+ifnull(m3.amount,0)  as s1a,
                 ifnull(m4.amount,0)+ ifnull(m5.amount,0)+ifnull(m6.amount,0)  as s2a,
@@ -24,16 +24,16 @@ SELECT DISTINCT m.year,
                 ifnull(m11.amount,0) as m11a,
                 ifnull(m12.amount,0) as m12a
 from sa_salestarget m
-         LEFT JOIN sa_salestarget m1 ON m1.year = m.year and m1.point = 1 and m.tradefield = m1.tradefield
-         LEFT JOIN sa_salestarget m2 ON m2.year = m.year and m2.point = 2 and m.tradefield = m2.tradefield
-         LEFT JOIN sa_salestarget m3 ON m3.year = m.year and m3.point = 3 and m.tradefield = m3.tradefield
-         LEFT JOIN sa_salestarget m4 ON m4.year = m.year and m4.point = 4 and m.tradefield = m4.tradefield
-         LEFT JOIN sa_salestarget m5 ON m5.year = m.year and m5.point = 5 and m.tradefield = m5.tradefield
-         LEFT JOIN sa_salestarget m6 ON m6.year = m.year and m6.point = 6 and m.tradefield = m6.tradefield
-         LEFT JOIN sa_salestarget m7 ON m7.year = m.year and m7.point = 7 and m.tradefield = m7.tradefield
-         LEFT JOIN sa_salestarget m8 ON m8.year = m.year and m8.point = 8 and m.tradefield = m8.tradefield
-         LEFT JOIN sa_salestarget m9 ON m9.year = m.year and m9.point = 9 and m.tradefield = m9.tradefield
-         LEFT JOIN sa_salestarget m10 ON m10.year = m.year and m10.point = 10 and m.tradefield = m10.tradefield
-         LEFT JOIN sa_salestarget m11 ON m11.year = m.year and m11.point = 11 and m.tradefield = m11.tradefield
-         LEFT JOIN sa_salestarget m12 ON m12.year = m.year and m12.point = 12 and m.tradefield = m12.tradefield
+         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
+         LEFT JOIN sa_salestarget m3 ON m3.year = m.year and m3.point = 3 and m.sys_enterpriseid = m3.sys_enterpriseid
+         LEFT JOIN sa_salestarget m4 ON m4.year = m.year and m4.point = 4 and m.sys_enterpriseid = m4.sys_enterpriseid
+         LEFT JOIN sa_salestarget m5 ON m5.year = m.year and m5.point = 5 and m.sys_enterpriseid = m5.sys_enterpriseid
+         LEFT JOIN sa_salestarget m6 ON m6.year = m.year and m6.point = 6 and m.sys_enterpriseid = m6.sys_enterpriseid
+         LEFT JOIN sa_salestarget m7 ON m7.year = m.year and m7.point = 7 and m.sys_enterpriseid = m7.sys_enterpriseid
+         LEFT JOIN sa_salestarget m8 ON m8.year = m.year and m8.point = 8 and m.sys_enterpriseid = m8.sys_enterpriseid
+         LEFT JOIN sa_salestarget m9 ON m9.year = m.year and m9.point = 9 and m.sys_enterpriseid = m9.sys_enterpriseid
+         LEFT JOIN sa_salestarget m10 ON m10.year = m.year and m10.point = 10 and m.sys_enterpriseid = m10.sys_enterpriseid
+         LEFT JOIN sa_salestarget m11 ON m11.year = m.year and m11.point = 11 and m.sys_enterpriseid = m11.sys_enterpriseid
+         LEFT JOIN sa_salestarget m12 ON m12.year = m.year and m12.point = 12 and m.sys_enterpriseid = m12.sys_enterpriseid
 ORDER BY m.year desc

+ 13 - 0
src/custom/restcontroller/sale/salestarget/SQL/查询经销商.sql

@@ -0,0 +1,13 @@
+SELECT t1.sys_enterpriseid,
+       t1.enterprisename,
+       t1.province,
+       t1.city,
+       t1.county,
+       t1.address,
+       t1.contact,
+       t1.phonenumber,
+       t1.taxno,
+       t2.agentnum
+from sys_enterprise t1
+      inner join sa_agents t2 on t1.sys_enterpriseid=t2.sys_enterpriseid and t1.siteid=t2.siteid
+WHERE  t1.siteid = $siteid$ and t2.status='启用' and $where$ and  t1.sys_enterpriseid not in (select t2.sys_enterpriseid from sa_salestargetbill t1 inner join sa_salestargethr t2 on t1.sa_salestargetbillid=t2.sa_salestargetbillid and t1.siteid=t2.siteid where  t1.year=$year$ and t1.targettype='企业目标' )

+ 139 - 110
src/custom/restcontroller/sale/salestarget/enterprise.java

@@ -4,12 +4,14 @@ 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.util.ArrayList;
 
 
 /**
@@ -24,141 +26,70 @@ public class enterprise extends Controller {
     public enterprise(JSONObject content) throws YosException {
         super(content);
     }
-
-    @API(title = "企业业绩目标(经销商)", apiversion = R.ID20230110151902.v1.class)
-    public String selectList() throws YosException {
-         /*
+    @API(title = "经销商列表查询", apiversion = R.ID20231018162103.v1.class)
+    @CACHEING
+    public String query_agentList() throws YosException {
+        /*
           过滤条件设置
          */
         StringBuffer where = new StringBuffer(" 1=1 ");
-        StringBuffer where2 = new StringBuffer(" 1=1 ");
         if (content.containsKey("where")) {
             JSONObject whereObject = content.getJSONObject("where");
-            if (whereObject.containsKey("year") && !"".equals(whereObject.getString("year"))) {
-                where.append(" and(");
-                where.append("year like'%").append(whereObject.getString("year")).append("%' ");
-                where.append(")");
-
-                where2.append(" and(");
-                where2.append("YEAR(t2.billdate) like'%").append(whereObject.getString("year")).append("%' ");
-                where2.append(")");
-            }
-            if (whereObject.containsKey("tradefield") && !"".equals(whereObject.getString("tradefield"))) {
+            if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
                 where.append(" and(");
-                where.append("tradefield like'%").append(whereObject.getString("tradefield")).append("%' ");
+                where.append(" t1.enterprisename like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t2.agentnum like'%").append(whereObject.getString("condition")).append("%' ");
                 where.append(")");
-
-                where2.append(" and(");
-                where2.append("tradefield like'%").append(whereObject.getString("tradefield")).append("%' ");
-                where2.append(")");
             }
-
-        }
-
-        //考核指标类型
-        Long type = content.getLongValue("type");
-
-        if (content.containsKey("sys_enterpriseid")) {
-            sys_enterpriseid = content.getLongValue("sys_enterpriseid");
         }
-
-        SQLFactory sqlFactory = new SQLFactory(this, "企业-业绩目标完成列表");
-        sqlFactory.addParameter_SQL("where", where);
-        sqlFactory.addParameter_in("sys_enterpriseid", sys_enterpriseid);
+        SQLFactory sqlFactory = new SQLFactory(this, "查询经销商", pageSize, pageNumber, pageSorting);
         sqlFactory.addParameter_SQL("where", where);
         sqlFactory.addParameter("siteid", siteid);
-        String sql = sqlFactory.getSQL();
-        Rows rows = dbConnect.runSqlQuery(sql);
-
-        Rows actualRows = new Rows();
-        //开票
-        if (type == 0 || type == 1) {
-            sqlFactory = new SQLFactory(this, "企业-开票");
-        }
-        //订单
-        if (type == 2) {
-            sqlFactory = new SQLFactory(this, "企业-订单");
-        }
-        //出货
-        if (type == 3) {
-            sqlFactory = new SQLFactory(this, "企业-出货");
-        }
-        sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
-        sqlFactory.addParameter_SQL("where", where2);
-        sqlFactory.addParameter("siteid", siteid);
-        actualRows = dbConnect.runSqlQuery(sqlFactory);
-
-        for (Row row : rows) {
-            //初始化
-            row = addActualRow(row);
-            Long year = row.getLong("year");
-            String tradefield = row.getString("tradefield");
-            Row actualRow = new Row();
-            for (Row tempActualRow : actualRows) {
-                if (tempActualRow.getLong("year") == year && tempActualRow.getString("tradefield").equals(tradefield)) {
-                    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);
-        }
-
+        sqlFactory.addParameter("year", content.getLong("year"));
+        Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL());
         return getSucReturnObject().setData(rows).toString();
     }
 
-    @API(title = "企业业绩目标(业务员)", apiversion = R.ID20230111163102.v1.class)
-    public String selectSellerList() throws YosException {
-               /*
+
+    @API(title = "企业业绩目标(经销商)", apiversion = R.ID20230110151902.v1.class)
+    public String selectList() throws YosException {
+         /*
           过滤条件设置
          */
         StringBuffer where = new StringBuffer(" 1=1 ");
         StringBuffer where2 = new StringBuffer(" 1=1 ");
+        long curryear=0;
         if (content.containsKey("where")) {
             JSONObject whereObject = content.getJSONObject("where");
             if (whereObject.containsKey("year") && !"".equals(whereObject.getString("year"))) {
                 where.append(" and(");
-                where.append("year like'%").append(whereObject.getString("year")).append("%' ");
+                where.append("year ='").append(whereObject.getString("year")).append("' ");
                 where.append(")");
-
-                where2.append(" and(");
-                where2.append("YEAR(t2.billdate) like'%").append(whereObject.getString("year")).append("%' ");
-                where2.append(")");
+                curryear=whereObject.getLong("year");
             }
-            if (whereObject.containsKey("tradefield") && !"".equals(whereObject.getString("tradefield"))) {
+
+            if (whereObject.containsKey("sys_enterpriseid") && !"".equals(whereObject.getString("sys_enterpriseid"))) {
                 where.append(" and(");
-                where.append("tradefield like'%").append(whereObject.getString("tradefield")).append("%' ");
+                where.append("sys_enterpriseid ='").append(whereObject.getString("sys_enterpriseid")).append("' ");
                 where.append(")");
-
-                where2.append(" and(");
-                where2.append("tradefield like'%").append(whereObject.getString("tradefield")).append("%' ");
-                where2.append(")");
             }
 
         }
 
-        //考核指标类型
-        Long type = content.getLongValue("type");
 
-        if (content.containsKey("sys_enterpriseid")) {
-            sys_enterpriseid = content.getLongValue("sys_enterpriseid");
+        //考核指标类型
+        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 sqlFactory = new SQLFactory(this, "企业-业绩目标完成列表");
         sqlFactory.addParameter_SQL("where", where);
-        sqlFactory.addParameter_in("hrid", hrid);
+        sqlFactory.addParameter_in("sys_enterpriseid", sys_enterpriseid);
         sqlFactory.addParameter_SQL("where", where);
         sqlFactory.addParameter("siteid", siteid);
         String sql = sqlFactory.getSQL();
@@ -166,30 +97,34 @@ public class enterprise extends Controller {
 
         Rows actualRows = new Rows();
         //开票
-        if (type == 0 || type == 1) {
-            sqlFactory = new SQLFactory(this, "企业-开票-业务员");
+        if (assessmentindicators.equals("开票")) {
+            sqlFactory = new SQLFactory(this, "企业-开票");
         }
         //订单
-        if (type == 2) {
-            sqlFactory = new SQLFactory(this, "企业-订单-业务员");
+        if (assessmentindicators.equals("订单")) {
+            sqlFactory = new SQLFactory(this, "企业-订单");
         }
         //出货
-        if (type == 3) {
-            sqlFactory = new SQLFactory(this, "企业-出货-业务员");
+        if (assessmentindicators.equals("出货")) {
+            sqlFactory = new SQLFactory(this, "企业-出货");
+        }
+        //出货
+        if (assessmentindicators.equals("收款")) {
+            sqlFactory = new SQLFactory(this, "企业-收款");
         }
-        sqlFactory.addParameter_in("hrid", hrid);
-        sqlFactory.addParameter_SQL("where", where2);
+        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) {
             //初始化
             row = addActualRow(row);
             Long year = row.getLong("year");
-            String tradefield = row.getString("tradefield");
+            Long sys_enterpriseid = row.getLong("sys_enterpriseid");
             Row actualRow = new Row();
             for (Row tempActualRow : actualRows) {
-                if (tempActualRow.getLong("year") == year && tempActualRow.getString("tradefield").equals(tradefield)) {
+                if (tempActualRow.getLong("year") == year && tempActualRow.getLong("sys_enterpriseid")==sys_enterpriseid) {
                     actualRow.putAll(tempActualRow);
                 }
             }
@@ -208,9 +143,103 @@ public class enterprise extends Controller {
             }
             row.put("month", monthRows);
         }
+
         return getSucReturnObject().setData(rows).toString();
     }
 
+//    @API(title = "企业业绩目标(业务员)", apiversion = R.ID20230111163102.v1.class)
+//    public String selectSellerList() throws YosException {
+//               /*
+//          过滤条件设置
+//         */
+//        StringBuffer where = new StringBuffer(" 1=1 ");
+//        StringBuffer where2 = new StringBuffer(" 1=1 ");
+//        if (content.containsKey("where")) {
+//            JSONObject whereObject = content.getJSONObject("where");
+//            if (whereObject.containsKey("year") && !"".equals(whereObject.getString("year"))) {
+//                where.append(" and(");
+//                where.append("year like'%").append(whereObject.getString("year")).append("%' ");
+//                where.append(")");
+//
+//                where2.append(" and(");
+//                where2.append("YEAR(t2.billdate) like'%").append(whereObject.getString("year")).append("%' ");
+//                where2.append(")");
+//            }
+//            if (whereObject.containsKey("tradefield") && !"".equals(whereObject.getString("tradefield"))) {
+//                where.append(" and(");
+//                where.append("tradefield like'%").append(whereObject.getString("tradefield")).append("%' ");
+//                where.append(")");
+//
+//                where2.append(" and(");
+//                where2.append("tradefield like'%").append(whereObject.getString("tradefield")).append("%' ");
+//                where2.append(")");
+//            }
+//
+//        }
+//
+//        //考核指标类型
+//        Long type = content.getLongValue("type");
+//
+//        if (content.containsKey("sys_enterpriseid")) {
+//            sys_enterpriseid = content.getLongValue("sys_enterpriseid");
+//        }
+//
+//
+//        SQLFactory sqlFactory = new SQLFactory(this, "企业-业绩目标完成列表-业务员");
+//        sqlFactory.addParameter_SQL("where", where);
+//        sqlFactory.addParameter_in("hrid", hrid);
+//        sqlFactory.addParameter_SQL("where", where);
+//        sqlFactory.addParameter("siteid", siteid);
+//        String sql = sqlFactory.getSQL();
+//        Rows rows = dbConnect.runSqlQuery(sql);
+//
+//        Rows actualRows = new Rows();
+//        //开票
+//        if (type == 0 || type == 1) {
+//            sqlFactory = new SQLFactory(this, "企业-开票-业务员");
+//        }
+//        //订单
+//        if (type == 2) {
+//            sqlFactory = new SQLFactory(this, "企业-订单-业务员");
+//        }
+//        //出货
+//        if (type == 3) {
+//            sqlFactory = new SQLFactory(this, "企业-出货-业务员");
+//        }
+//        sqlFactory.addParameter_in("hrid", hrid);
+//        sqlFactory.addParameter_SQL("where", where2);
+//        sqlFactory.addParameter("siteid", siteid);
+//        actualRows = dbConnect.runSqlQuery(sqlFactory);
+//
+//        for (Row row : rows) {
+//            //初始化
+//            row = addActualRow(row);
+//            Long year = row.getLong("year");
+//            String tradefield = row.getString("tradefield");
+//            Row actualRow = new Row();
+//            for (Row tempActualRow : actualRows) {
+//                if (tempActualRow.getLong("year") == year && tempActualRow.getString("tradefield").equals(tradefield)) {
+//                    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 Row addActualRow(Row targetRow) {
         String key = "y1a";

+ 14 - 10
src/custom/restcontroller/webmanage/sale/salestarget/SQL/人员-目标详情列表.sql

@@ -4,16 +4,20 @@ with sa_salestarget as (
    , hrtarget as (
     select  t1.sa_saleareaid,
 					 t1.areaname,
-           y1.target_l  as y1l,
-           y1.target_h  as y1h,
-           s1.target_l  as s1l,
-           s1.target_h  as s1h,
-           s2.target_l  as s2l,
-           s2.target_h  as s2h,
-           s3.target_l  as s3l,
-           s3.target_h  as s3h,
-           s4.target_l  as s4l,
-           s4.target_h  as s4h,
+           m1.target_l + m2.target_l + m3.target_l + m4.target_l + m5.target_l + m6.target_l +
+           m7.target_l + m8.target_l + m9.target_l + m10.target_l + m11.target_l +
+           m12.target_l                               y1l,
+           m1.target_h + m2.target_h + m3.target_h + m4.target_h + m5.target_h + m6.target_h +
+           m7.target_h + m8.target_h + m9.target_h + m10.target_h + m11.target_h +
+           m12.target_h                               y1h,
+           m1.target_l + m2.target_l + m3.target_l    s1l,
+           m1.target_h + m2.target_h + m3.target_h    s1h,
+           m4.target_l + m5.target_l + m6.target_l    s2l,
+           m4.target_h + m5.target_h + m6.target_h    s2h,
+           m7.target_l + m8.target_l + m9.target_l    s3l,
+           m7.target_h + m8.target_h + m9.target_h    s3h,
+           m10.target_l + m11.target_l + m12.target_l s4l,
+           m10.target_h + m11.target_h + m12.target_h s4h,
            m1.target_l  as m1l,
            m1.target_h  as m1h,
            m2.target_l  as m2l,

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

@@ -0,0 +1,59 @@
+with sa_salestarget as (
+    SELECT point, sum(target_l) target_l, sum(target_h) target_h, year,sys_enterpriseid from sa_salestarget
+    WHERE  type = '月' and targettype='企业目标' and siteid=$siteid$ and $where$
+    GROUP  BY point ,year,sys_enterpriseid
+    )
+SELECT DISTINCT m.year,
+                m.sys_enterpriseid,
+                m1.target_l + m2.target_l + m3.target_l + m4.target_l + m5.target_l + m6.target_l +
+                m7.target_l + m8.target_l + m9.target_l + m10.target_l + m11.target_l +
+                m12.target_l                               y1l,
+                m1.target_h + m2.target_h + m3.target_h + m4.target_h + m5.target_h + m6.target_h +
+                m7.target_h + m8.target_h + m9.target_h + m10.target_h + m11.target_h +
+                m12.target_h                               y1h,
+                m1.target_l + m2.target_l + m3.target_l    s1l,
+                m1.target_h + m2.target_h + m3.target_h    s1h,
+                m4.target_l + m5.target_l + m6.target_l    s2l,
+                m4.target_h + m5.target_h + m6.target_h    s2h,
+                m7.target_l + m8.target_l + m9.target_l    s3l,
+                m7.target_h + m8.target_h + m9.target_h    s3h,
+                m10.target_l + m11.target_l + m12.target_l s4l,
+                m10.target_h + m11.target_h + m12.target_h s4h,
+                m1.target_l                                m1l,
+                m1.target_h                                m1h,
+                m2.target_l                                m2l,
+                m2.target_h                                m2h,
+                m3.target_l                                m3l,
+                m3.target_h                                m3h,
+                m4.target_l                                m4l,
+                m4.target_h                                m4h,
+                m5.target_l                                m5l,
+                m5.target_h                                m5h,
+                m6.target_l                                m6l,
+                m6.target_h                                m6h,
+                m7.target_l                                m7l,
+                m7.target_h                                m7h,
+                m8.target_l                                m8l,
+                m8.target_h                                m8h,
+                m9.target_l                                m9l,
+                m9.target_h                                m9h,
+                m10.target_l                               m10l,
+                m10.target_h                               m10h,
+                m11.target_l                               m11l,
+                m11.target_h                               m11h,
+                m12.target_l                               m12l,
+                m12.target_h                               m12h
+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
+         LEFT JOIN sa_salestarget m3 ON m3.year = m.year and m3.point = 3 and m.sys_enterpriseid = m3.sys_enterpriseid
+         LEFT JOIN sa_salestarget m4 ON m4.year = m.year and m4.point = 4 and m.sys_enterpriseid = m4.sys_enterpriseid
+         LEFT JOIN sa_salestarget m5 ON m5.year = m.year and m5.point = 5 and m.sys_enterpriseid = m5.sys_enterpriseid
+         LEFT JOIN sa_salestarget m6 ON m6.year = m.year and m6.point = 6 and m.sys_enterpriseid = m6.sys_enterpriseid
+         LEFT JOIN sa_salestarget m7 ON m7.year = m.year and m7.point = 7 and m.sys_enterpriseid = m7.sys_enterpriseid
+         LEFT JOIN sa_salestarget m8 ON m8.year = m.year and m8.point = 8 and m.sys_enterpriseid = m8.sys_enterpriseid
+         LEFT JOIN sa_salestarget m9 ON m9.year = m.year and m9.point = 9 and m.sys_enterpriseid = m9.sys_enterpriseid
+         LEFT JOIN sa_salestarget m10 ON m10.year = m.year and m10.point = 10 and m.sys_enterpriseid = m10.sys_enterpriseid
+         LEFT JOIN sa_salestarget m11 ON m11.year = m.year and m11.point = 11 and m.sys_enterpriseid = m11.sys_enterpriseid
+         LEFT JOIN sa_salestarget m12 ON m12.year = m.year and m12.point = 12 and m.sys_enterpriseid = m12.sys_enterpriseid
+ORDER BY m.year desc

+ 2 - 2
src/custom/restcontroller/webmanage/sale/salestarget/SQL/企业-目标明细新增.sql

@@ -1,4 +1,4 @@
 insert into sa_salestarget (siteid, sa_salestargetid, type, point, target_l, target_h, targettype, sys_enterpriseid,
-                            sa_salestargetbillid, year, sa_contractid, createby, createdate,tradefield)
+                            sa_salestargetbillid, year, sa_contractid, createby, createdate,tradefield,sa_saleareaid)
 values ($siteid$, $sa_salestargetid$, $type$, $point$, $target_l$, $target_h$, $targettype$, $sys_enterpriseid$,
-        $sa_salestargetbillid$, $year$, $sa_contractid$, $createby$, current_time,$tradefield$);
+        $sa_salestargetbillid$, $year$, $sa_contractid$, $createby$, current_time,$tradefield$,0);

+ 2 - 2
src/custom/restcontroller/webmanage/sale/salestarget/SQL/企业范围新增.sql

@@ -1,5 +1,5 @@
-insert into sa_salestargethr (siteid, sa_salestargethrid, sys_enterpriseid,  sa_salestargetbillid)
-select $siteid$, $sa_salestargethrid$, $sys_enterpriseid$,  $sa_salestargetbillid$
+insert into sa_salestargethr (siteid, sa_salestargethrid, sys_enterpriseid,  sa_salestargetbillid,sa_saleareaid)
+select $siteid$, $sa_salestargethrid$, $sys_enterpriseid$,  $sa_salestargetbillid$,0
 
 FROM dual
 WHERE not exists(SELECT 1

+ 105 - 72
src/custom/restcontroller/webmanage/sale/salestarget/enterprisetarget.java

@@ -8,6 +8,7 @@ import common.YosException;
 import common.annotation.API;
 import common.annotation.CACHEING_CLEAN;
 import common.annotation.cm;
+import common.data.Row;
 import common.data.Rows;
 import common.data.SQLFactory;
 import restcontroller.R;
@@ -29,83 +30,81 @@ public class enterprisetarget extends Controller {
     public String insert() throws YosException {
         Long year = content.getLong("year");
         Long sa_salestargetbillid = content.getLong("sa_salestargetbillid");
-        Long sys_enterpriseid = content.getLong("sys_enterpriseid");
-        Long sa_contractid = content.getLong("sa_contractid");
-        String tradefield = content.getString("tradefield");
+        JSONArray agentsArray = content.getJSONArray("agents");
+        String assessmentindicators=content.getString("assessmentindicators");
 
         ArrayList<String> sqlList = new ArrayList<>();
         if (sa_salestargetbillid <= 0) {
             //查询创建年度是否存在
-            String sql = "SELECT sa_salestargetbillid FROM sa_salestargetbill WHERE `year` = " + year + " AND targettype ='企业目标' AND siteid = '" + siteid + "' and sys_enterpriseid = " + sys_enterpriseid + " and tradefield='" + tradefield + "'";
+            String sql = "SELECT sa_salestargetbillid FROM sa_salestargetbill WHERE `year` = " + year + " AND targettype ='企业目标' AND siteid = '" + siteid + "'";
             Rows rows = dbConnect.runSqlQuery(sql);
             if (rows.isNotEmpty()) {
-                sa_salestargetbillid = rows.get(0).getLong("sa_salestargetbillid");
+                return getErrReturnObject().setErrMsg("当前业绩目标已存在,无法添加").toString();
             } else {
                 sa_salestargetbillid = createTableID("sa_salestargetbill");
                 SQLFactory sqlFactory = new SQLFactory(this, "创建新年度");
                 sqlFactory.addParameter("siteid", siteid);
                 sqlFactory.addParameter("sa_salestargetbillid", sa_salestargetbillid);
-                sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
+                sqlFactory.addParameter("sys_enterpriseid", 0);
                 sqlFactory.addParameter("username", username);
                 sqlFactory.addParameter("userid", userid);
                 sqlFactory.addParameter("year", year);
                 sqlFactory.addParameter("targettype", "企业目标");
-                sqlFactory.addParameter("tradefield", tradefield);
+                sqlFactory.addParameter("tradefield", "");
+                sqlFactory.addParameter("assessmentindicators", assessmentindicators);
+
                 sqlList.add(sqlFactory.getSQL());
             }
         }
 
-        if (dbConnect.runSqlQuery("SELECT * from sa_salestarget WHERE sa_salestargetbillid = " + sa_salestargetbillid + " and sa_contractid = " + sa_contractid + " and siteid = '" + siteid + "' and tradefield='" + tradefield + "'").isNotEmpty()) {
-            return getErrReturnObject().setErrMsg("当前领域业绩目标已存在,无法添加").toString();
-        }
-
 
         String[] types = {"年", "季", "月"};
 
-        String sql = "SELECT 1 FROM sa_salestargethr WHERE sa_salestargetbillid = " + sa_salestargetbillid + " and siteid = '" + siteid + "' and sys_enterpriseid = " + sys_enterpriseid;
-        Rows rows = dbConnect.runSqlQuery(sql);
-        if (rows.isEmpty()) {
+        for (Object obj : agentsArray) {
+            JSONObject saleObj = (JSONObject) obj;
+            System.out.println(saleObj.toString());
             SQLFactory saleFactory = new SQLFactory(this, "企业范围新增");
             saleFactory.addParameter("siteid", siteid);
             saleFactory.addParameter("sa_salestargethrid", createTableID("sa_salestargethr"));
-            saleFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
+            saleFactory.addParameter("sys_enterpriseid", saleObj.getLong("sys_enterpriseid"));
             saleFactory.addParameter("sa_salestargetbillid", sa_salestargetbillid);
             sqlList.add(saleFactory.getSQL());
-        }
 
 
-        for (String type : types) {
-            int point;
-            if (type.equals("年")) {
-                point = 1;
-            } else if (type.equals("季")) {
-                point = 4;
-            } else if (type.equals("月")) {
-                point = 12;
-            } else {
-                point = 0;
+            for (String type : types) {
+                int point;
+                if (type.equals("年")) {
+                    point = 1;
+                } else if (type.equals("季")) {
+                    point = 4;
+                } else if (type.equals("月")) {
+                    point = 12;
+                } else {
+                    point = 0;
+                }
+
+                for (int i = 0; i < point; i++) {
+                    SQLFactory targetFactory = new SQLFactory(this, "企业-目标明细新增");
+                    targetFactory.addParameter("siteid", siteid);
+                    targetFactory.addParameter("sa_salestargetid", createTableID("sa_salestarget"));
+                    targetFactory.addParameter("type", type);
+                    targetFactory.addParameter("point", i + 1);
+                    targetFactory.addParameter("targettype", "企业目标");
+                    targetFactory.addParameter("sys_enterpriseid", saleObj.getLong("sys_enterpriseid"));
+                    targetFactory.addParameter("sa_salestargetbillid", sa_salestargetbillid);
+                    targetFactory.addParameter("year", year);
+                    targetFactory.addParameter("sa_contractid", 0);
+                    targetFactory.addParameter("createby", username);
+                    targetFactory.addParameter("target_l", 0);
+                    targetFactory.addParameter("target_h", 0);
+                    targetFactory.addParameter("tradefield", "");
+                    sqlList.add(targetFactory.getSQL());
+                }
             }
 
-            for (int i = 0; i < point; i++) {
-                SQLFactory targetFactory = new SQLFactory(this, "企业-目标明细新增");
-                targetFactory.addParameter("siteid", siteid);
-                targetFactory.addParameter("sa_salestargetid", createTableID("sa_salestarget"));
-                targetFactory.addParameter("type", type);
-                targetFactory.addParameter("point", i + 1);
-                targetFactory.addParameter("targettype", "企业目标");
-                targetFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
-                targetFactory.addParameter("sa_salestargetbillid", sa_salestargetbillid);
-                targetFactory.addParameter("year", year);
-                targetFactory.addParameter("sa_contractid", sa_contractid);
-                targetFactory.addParameter("createby", username);
-                targetFactory.addParameter("target_l", 0);
-                targetFactory.addParameter("target_h", 0);
-                targetFactory.addParameter("tradefield", tradefield);
-                sqlList.add(targetFactory.getSQL());
-            }
+            sqlList.add(DataContrlLog.createLog(this, "sys_enterprise", sys_enterpriseid, "添加业绩目标", "添加业绩目标" + year + "年目标").getSQL());
         }
 
-        sqlList.add(DataContrlLog.createLog(this, "sa_contract", sa_contractid, "添加业绩目标", "添加业绩目标" + year + "年" + tradefield + "领域目标").getSQL());
 
         dbConnect.runSqlUpdate(sqlList);
         return getSucReturnObject().toString();
@@ -115,8 +114,13 @@ public class enterprisetarget extends Controller {
     @CACHEING_CLEAN(cms = {@cm(clazz = personnel.class, method = {"queryList", "queryDetailList"}), @cm(clazz = personnelstatistics.class, method = {"queryList"})})
     public String edit() throws YosException {
         Long sa_salestargetbillid = content.getLong("sa_salestargetbillid");
+        if(sa_salestargetbillid<=0){
+            Rows rows =dbConnect.runSqlQuery("SELECT sa_salestargetbillid FROM sa_salestargetbill WHERE `year` = " + content.getLong("year") + " AND targettype ='企业目标' AND siteid = '" + siteid + "'");
+            if(rows.isNotEmpty()){
+                sa_salestargetbillid=rows.get(0).getLong("sa_salestargetbillid");
+            }
+        }
         Long sys_enterpriseid = content.getLong("sys_enterpriseid");
-        Long sa_contractid = content.getLong("sa_contractid");
         if (sa_salestargetbillid <= 0) {
             return getErrReturnObject().setErrMsg("年度目标不存在").toString();
         }
@@ -125,13 +129,13 @@ public class enterprisetarget extends Controller {
         String key_l = "y1l";
         String key_h = "y1h";
         if (content.containsKey(key_l) && content.containsKey(key_h)) {
-            sqlList.add(getSql(content.getString(key_l), content.getString(key_h), sa_salestargetbillid, sys_enterpriseid, sa_contractid, "年", 1));
+            sqlList.add(getSql(content.getString(key_l), content.getString(key_h), sa_salestargetbillid, sys_enterpriseid, "年", 1));
         }
         for (int i = 1; i < 5; i++) {
             key_l = "s" + i + "l";
             key_h = "s" + i + "h";
             if (content.containsKey(key_l) && content.containsKey(key_h)) {
-                sqlList.add(getSql(content.getString(key_l), content.getString(key_h), sa_salestargetbillid, sys_enterpriseid, sa_contractid, "季", i));
+                sqlList.add(getSql(content.getString(key_l), content.getString(key_h), sa_salestargetbillid, sys_enterpriseid, "季", i));
             }
         }
 
@@ -139,53 +143,82 @@ public class enterprisetarget extends Controller {
             key_l = "m" + i + "l";
             key_h = "m" + i + "h";
             if (content.containsKey(key_l) && content.containsKey(key_h)) {
-                sqlList.add(getSql(content.getString(key_l), content.getString(key_h), sa_salestargetbillid, sys_enterpriseid, sa_contractid, "月", i));
+                sqlList.add(getSql(content.getString(key_l), content.getString(key_h), sa_salestargetbillid, sys_enterpriseid, "月", i));
             }
         }
 
         //操作记录
         Long year = 0L;
-        String tradefield = "";
-        Rows rows = dbConnect.runSqlQuery("SELECT year,tradefield from sa_salestargetbill  WHERE sa_salestargetbillid =" + sa_salestargetbillid + " and siteid='" + siteid + "'");
+        Rows rows = dbConnect.runSqlQuery("SELECT year from sa_salestargetbill  WHERE sa_salestargetbillid =" + sa_salestargetbillid + " and siteid='" + siteid + "'");
         if (rows.isNotEmpty()) {
             year = rows.get(0).getLong("year");
-            tradefield = rows.get(0).getString("tradefield");
         }
 
-        sqlList.add(DataContrlLog.createLog(this, "sa_contract", sa_contractid, "编辑业绩目标", "编辑业绩目标" + year + "年" + tradefield + "领域目标").getSQL());
+        sqlList.add(DataContrlLog.createLog(this, "sa_salestargetbill", sa_salestargetbillid, "编辑业绩目标", "编辑业绩目标" + year + "年目标").getSQL());
 
         dbConnect.runSqlUpdate(sqlList);
         return getSucReturnObject().toString();
     }
 
-    public String getSql(String target_l, String target_h, Long id, Long sys_enterpriseid, Long sa_contractid, 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 + " AND sa_contractid = " + sa_contractid;
-    }
+    @API(title = "企业业绩目标(经销商)", apiversion = R.ID20231018142103.v1.class)
+    public String selectList() throws YosException {
+         /*
+          过滤条件设置
+         */
+        StringBuffer where = new StringBuffer(" 1=1 ");
+        if (content.containsKey("where")) {
+            JSONObject whereObject = content.getJSONObject("where");
+            if (whereObject.containsKey("year") && !"".equals(whereObject.getString("year"))) {
+                where.append(" and(");
+                where.append("year like'%").append(whereObject.getString("year")).append("%' ");
+                where.append(")");
+            }
 
-    @API(title = "删除", apiversion = R.ID20221229141102.v1.class)
-    public String delete() throws YosException {
+            if (whereObject.containsKey("sys_enterpriseid") && !"".equals(whereObject.getString("sys_enterpriseid"))) {
+                where.append(" and(");
+                where.append("sys_enterpriseid ='").append(whereObject.getString("sys_enterpriseid")).append("' ");
+                where.append(")");
+            }
 
-        Long sa_salestargetbillid = content.getLong("sa_salestargetbillid");
-        Long sa_contractid = content.getLong("sa_contractid");
+        }
+        SQLFactory sqlFactory = new SQLFactory(this, "企业-业绩目标完成列表");
+        sqlFactory.addParameter_SQL("where", where);
+        sqlFactory.addParameter("siteid", siteid);
+        String sql = sqlFactory.getSQL();
+        Rows rows = dbConnect.runSqlQuery(sql);
 
-        ArrayList<String> sqlList = new ArrayList<>();
-        sqlList.add("delete from sa_salestarget WHERE siteid = '" + siteid + "' and sa_salestargetbillid = " + sa_salestargetbillid + " and sa_contractid = " + sa_contractid);
+        return getSucReturnObject().setData(rows).toString();
+    }
 
-        //操作记录
-        Long year = 0L;
-        String tradefield = "";
-        Rows rows = dbConnect.runSqlQuery("SELECT year,tradefield from sa_salestargetbill  WHERE sa_salestargetbillid =" + sa_salestargetbillid + " and siteid='" + siteid + "'");
-        if (rows.isNotEmpty()) {
-            year = rows.get(0).getLong("year");
-            tradefield = rows.get(0).getString("tradefield");
-        }
-        sqlList.add(DataContrlLog.createLog(this, "sa_contract", sa_contractid, "删除业绩目标", "删除业绩目标" + year + "年" + tradefield + "领域目标").getSQL());
-        dbConnect.runSqlUpdate(sqlList);
+    public String getSql(String target_l, String target_h, Long id, Long sys_enterpriseid, String type, int point) {
 
-        return getSucReturnObject().toString();
+        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;
     }
 
+//    @API(title = "删除", apiversion = R.ID20221229141102.v1.class)
+//    public String delete() throws YosException {
+//
+//        Long sa_salestargetbillid = content.getLong("sa_salestargetbillid");
+//        Long sa_contractid = content.getLong("sa_contractid");
+//
+//        ArrayList<String> sqlList = new ArrayList<>();
+//        sqlList.add("delete from sa_salestarget WHERE siteid = '" + siteid + "' and sa_salestargetbillid = " + sa_salestargetbillid + " and sa_contractid = " + sa_contractid);
+//
+//        //操作记录
+//        Long year = 0L;
+//        String tradefield = "";
+//        Rows rows = dbConnect.runSqlQuery("SELECT year,tradefield from sa_salestargetbill  WHERE sa_salestargetbillid =" + sa_salestargetbillid + " and siteid='" + siteid + "'");
+//        if (rows.isNotEmpty()) {
+//            year = rows.get(0).getLong("year");
+//            tradefield = rows.get(0).getString("tradefield");
+//        }
+//        sqlList.add(DataContrlLog.createLog(this, "sa_contract", sa_contractid, "删除业绩目标", "删除业绩目标" + year + "年" + tradefield + "领域目标").getSQL());
+//        dbConnect.runSqlUpdate(sqlList);
+//
+//        return getSucReturnObject().toString();
+//    }
+
     @API(title = "查询对应企业的年度", apiversion = R.ID20230103102302.v1.class)
     public String getYear() throws YosException {