|
|
@@ -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月 到 指定月份
|