wu vor 3 Monaten
Ursprung
Commit
609cd92008

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

@@ -7698,6 +7698,11 @@ public class R {
         public static class v1 {
         }
     }
+
+    public static class ID2025122915143202 {
+        public static class v1 {
+        }
+    }
 }
 
 

+ 11 - 0
src/custom/restcontroller/webmanage/sale/salestarget2/SQL/看板人员统计目标.sql

@@ -0,0 +1,11 @@
+SELECT t5.itemclassname,
+       sum(ROUND((m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11+m12) * price,2))  amount
+from sa_salestargetbill t1
+         INNER JOIN sa_salestarget t2 ON t2.sa_salestargetbillid = t1.sa_salestargetbillid
+         INNER JOIN sa_itemsaleclass t4 ON t4.itemid=t2.itemid
+         INNER JOIN plm_itemclass t5 ON t5.itemclassid=t4.itemclassid
+WHERE t1.year =$year$
+  and t1.`status` = '审核'
+  and t1.siteid =$siteid$
+  and t1.createuserid=$userid$
+GROUP BY t5.itemclassname

+ 8 - 0
src/custom/restcontroller/webmanage/sale/salestarget2/SQL/看板人员统计订单.sql

@@ -0,0 +1,8 @@
+SELECT t5.itemclassname, sum(t2.amount) amount, year(t1.checkdate) y
+from sa_order t1
+    INNER JOIN sa_orderitems t2 ON t2.sa_orderid = t1.sa_orderid and t2.siteid = t1.siteid
+    INNER JOIN sys_hr t3 ON t3.hrid = t1.saler_hrid
+    INNER JOIN sa_itemsaleclass t4 ON t4.itemid=t2.itemid
+    INNER JOIN plm_itemclass t5 ON t5.itemclassid=t4.itemclassid
+WHERE t1.siteid = $siteid$ and t1.`status` in ('审核', '关闭') and YEAR (t1.checkdate) in ($year$, $befyear$) and t3.userid=$userid$
+GROUP BY t5.itemclassname, year(t1.checkdate)

+ 114 - 35
src/custom/restcontroller/webmanage/sale/salestarget2/salestargetstatistics.java

@@ -325,12 +325,77 @@ public class salestargetstatistics extends Controller {
         return getSucReturnObject().setData(arearows).toString();
     }
 
+    @API(title = "人员目标统计看板", apiversion = R.ID2025122915143202.v1.class)
+    public String peopleTargetPanel() throws YosException {
+        int year = content.getIntValue("year");
+        int befyear = year - 1;
+        Long userid = content.getLongValue("userid");
+
+        Rows itemclassrows = dbConnect.runSqlQuery("SELECT DISTINCT itemclassname from plm_itemclass WHERE siteid='" + siteid + "' ");
+
+        SQLFactory sqlFactory = new SQLFactory(this, "看板人员统计订单");
+        sqlFactory.addParameter("siteid", siteid);
+        sqlFactory.addParameter("year", year);
+        sqlFactory.addParameter("befyear", befyear);
+        sqlFactory.addParameter("userid", userid);
+        Rows rows = dbConnect.runSqlQuery(sqlFactory);
+        RowsMap salesRowsMap = rows.toRowsMap("itemclassname");
+
+        sqlFactory = new SQLFactory(this, "看板人员统计目标");
+        sqlFactory.addParameter("siteid", siteid);
+        sqlFactory.addParameter("year", year);
+        sqlFactory.addParameter("userid", userid);
+        Rows targetrows = dbConnect.runSqlQuery(sqlFactory);
+        RowsMap targetRowsMap = targetrows.toRowsMap("itemclassname");
+
+
+        for (Row itemclassrow : itemclassrows) {
+            String itemclassname = itemclassrow.getString("itemclassname");
+            Rows salesRows = salesRowsMap.getOrDefault(itemclassname, new Rows());
+            Rows targetRows = targetRowsMap.getOrDefault(itemclassname, new Rows());
+
+            BigDecimal saleamount = BigDecimal.ZERO;
+            BigDecimal saleamount_mom = BigDecimal.ZERO;
+            BigDecimal saleamount_yoy = BigDecimal.ZERO;
+            BigDecimal targetamount = BigDecimal.ZERO;
+            for (Row salesRow : salesRows) {
+                if (salesRow.getString("y").equals(String.valueOf(year))) {
+                    saleamount = salesRow.getBigDecimal("amount");
+                }
+                if (salesRow.getString("y").equals(String.valueOf(befyear))) {
+                    saleamount_mom = salesRow.getBigDecimal("amount");
+                }
+                if (salesRow.getString("y").equals(String.valueOf(befyear))) {
+                    saleamount_yoy = salesRow.getBigDecimal("amount");
+                }
+            }
+            for (Row targetRow : targetRows) {
+                targetamount = targetRow.getBigDecimal("amount");
+            }
+            itemclassrow.put("y_saleamount", saleamount);
+            itemclassrow.put("y_saleamount_mom", saleamount_mom);
+            itemclassrow.put("y_saleamount_yoy", saleamount_yoy);
+            itemclassrow.put("y_targetamount", targetamount);
+            itemclassrow.put("y_balanceamount", saleamount.subtract(targetamount));
+            //计算达成率
+            itemclassrow.put("y_rate_achieve", calculateAchieveRate(saleamount, targetamount));
+            //计算环比
+            itemclassrow.put("y_rate_mom", calculateRate(saleamount, saleamount_mom));
+            //计算同比
+            itemclassrow.put("y_rate_yoy", calculateRate(saleamount, saleamount_yoy));
+
+        }
+
+
+        return getSucReturnObject().setData(itemclassrows).toString();
+    }
+
 
     public void calculate(String key, Row arearow, Rows dataRows, ArrayList<String> dates) {
         BigDecimal saleamount = BigDecimal.ZERO;
         BigDecimal saleamount_mom = BigDecimal.ZERO;
         BigDecimal saleamount_yoy = BigDecimal.ZERO;
-        BigDecimal targetmount = BigDecimal.ZERO;
+        BigDecimal targetamount = BigDecimal.ZERO;
         for (String month : dates) {
             for (Row dataRow : dataRows) {
                 String ym = dataRow.getString("ym");
@@ -340,7 +405,7 @@ public class salestargetstatistics extends Controller {
                 BigDecimal target = dataRow.getBigDecimal("target");
                 if (ym.equals(month)) {
                     saleamount = saleamount.add(amount);
-                    targetmount = targetmount.add(target);
+                    targetamount = targetamount.add(target);
                 }
                 if (ym.equals(momMonth)) {
                     saleamount_mom = saleamount_mom.add(amount);
@@ -353,32 +418,20 @@ public class salestargetstatistics extends Controller {
         arearow.putIfAbsent(key + "_saleamount", saleamount);
         arearow.putIfAbsent(key + "_saleamount_mom", saleamount_mom);
         arearow.putIfAbsent(key + "_saleamount_yoy", saleamount_yoy);
-        arearow.putIfAbsent(key + "_targetamount", targetmount);
+        arearow.putIfAbsent(key + "_targetamount", targetamount);
         //计算达成率
-        if (targetmount.compareTo(BigDecimal.ZERO) == 0) {
-            arearow.put(key + "_rate_achieve", "-");
-        } else {
-            arearow.put(key + "_rate_achieve", (saleamount.divide(targetmount, 4, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100))).setScale(2, BigDecimal.ROUND_HALF_UP) + "%");
-        }
+        arearow.put(key + "_rate_achieve", calculateAchieveRate(saleamount, targetamount));
         //计算环比
-        if (saleamount_mom.compareTo(BigDecimal.ZERO) == 0) {
-            arearow.put(key + "_rate_mom", "-");
-        } else {
-            arearow.put(key + "_rate_mom", ((saleamount.subtract(saleamount_mom)).divide(saleamount_mom, 4, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100))).setScale(2, BigDecimal.ROUND_HALF_UP) + "%");
-        }
+        arearow.put(key + "_rate_mom", calculateRate(saleamount, saleamount_mom));
         //计算同比
-        if (saleamount_yoy.compareTo(BigDecimal.ZERO) == 0) {
-            arearow.put(key + "_rate_yoy", "-");
-        } else {
-            arearow.put(key + "_rate_yoy", ((saleamount.subtract(saleamount_yoy)).divide(saleamount_yoy, 4, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100))).setScale(2, BigDecimal.ROUND_HALF_UP) + "%");
-        }
+        arearow.put(key + "_rate_yoy", calculateRate(saleamount, saleamount_yoy));
     }
 
     public void calculate(String key, Row arearow, Rows dataRows, String month) {
         BigDecimal saleamount = BigDecimal.ZERO;
         BigDecimal saleamount_mom = BigDecimal.ZERO;
         BigDecimal saleamount_yoy = BigDecimal.ZERO;
-        BigDecimal targetmount = BigDecimal.ZERO;
+        BigDecimal targetamount = BigDecimal.ZERO;
 
         for (Row dataRow : dataRows) {
             String ym = dataRow.getString("ym");
@@ -388,7 +441,7 @@ public class salestargetstatistics extends Controller {
             BigDecimal target = dataRow.getBigDecimal("target");
             if (ym.equals(month)) {
                 saleamount = saleamount.add(amount);
-                targetmount = targetmount.add(target);
+                targetamount = targetamount.add(target);
             }
             if (ym.equals(momMonth)) {
                 saleamount_mom = saleamount_mom.add(amount);
@@ -401,26 +454,52 @@ public class salestargetstatistics extends Controller {
         arearow.putIfAbsent(key + "_saleamount", saleamount);
         arearow.putIfAbsent(key + "_saleamount_mom", saleamount_mom);
         arearow.putIfAbsent(key + "_saleamount_yoy", saleamount_yoy);
-        arearow.putIfAbsent(key + "_targetamount", targetmount);
+        arearow.putIfAbsent(key + "_targetamount", targetamount);
         //计算达成率
-        if (targetmount.compareTo(BigDecimal.ZERO) == 0) {
-            arearow.put(key + "_rate_achieve", "-");
-        } else {
-            arearow.put(key + "_rate_achieve", (saleamount.divide(targetmount, 4, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100))).setScale(2, BigDecimal.ROUND_HALF_UP) + "%");
-        }
+        arearow.put(key + "_rate_achieve", calculateAchieveRate(saleamount, targetamount));
         //计算环比
-        if (saleamount_mom.compareTo(BigDecimal.ZERO) == 0) {
-            arearow.put(key + "_rate_mom", "-");
-        } else {
-            arearow.put(key + "_rate_mom", ((saleamount.subtract(saleamount_mom)).divide(saleamount_mom, 4, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100))).setScale(2, BigDecimal.ROUND_HALF_UP) + "%");
-        }
+        arearow.put(key + "_rate_mom", calculateRate(saleamount, saleamount_mom));
         //计算同比
-        if (saleamount_yoy.compareTo(BigDecimal.ZERO) == 0) {
-            arearow.put(key + "_rate_yoy", "-");
+        arearow.put(key + "_rate_yoy", calculateRate(saleamount, saleamount_yoy));
+        arearow.put("month", month);
+    }
+
+    //计算达成率
+    public String calculateAchieveRate(BigDecimal saleamount, BigDecimal targetamount) {
+        // 参数校验
+        if (saleamount == null || targetamount == null) {
+            return "-";
+        }
+        // 检查目标金额是否为0
+        if (targetamount.compareTo(BigDecimal.ZERO) == 0) {
+            return "-";
+        }
+        try {
+            // 计算达成率:(saleamount / targetamount) * 100
+            BigDecimal rate = saleamount.divide(targetamount, 10, BigDecimal.ROUND_HALF_UP)
+                    .multiply(BigDecimal.valueOf(100))
+                    .setScale(2, BigDecimal.ROUND_HALF_UP);
+            return rate + "%";
+        } catch (ArithmeticException e) {
+            // 处理除法结果为无限循环小数的情况
+            return "-";
+        }
+    }
+
+    //计算环比
+    public String calculateRate(BigDecimal saleamount, BigDecimal saleamount2) {
+        if (saleamount2.compareTo(BigDecimal.ZERO) == 0) {
+            return "-";
         } else {
-            arearow.put(key + "_rate_yoy", ((saleamount.subtract(saleamount_yoy)).divide(saleamount_yoy, 4, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100))).setScale(2, BigDecimal.ROUND_HALF_UP) + "%");
+            // 先计算差值
+            BigDecimal difference = saleamount.subtract(saleamount2);
+            // 计算比率,使用指定精度避免无限循环小数
+            BigDecimal rate = difference.divide(saleamount2, 10, BigDecimal.ROUND_HALF_UP);
+            // 乘以100转换为百分比并保留2位小数
+            BigDecimal percentage = rate.multiply(BigDecimal.valueOf(100))
+                    .setScale(2, BigDecimal.ROUND_HALF_UP);
+            return percentage + "%";
         }
-        arearow.put("month", month);
     }
 
     //当年1月 到 指定月份