From 9d95997dd26b415fdd525403c1cdb5f8059b1aec Mon Sep 17 00:00:00 2001 From: liangcheng <1546584672@qq.com> Date: Thu, 24 Jul 2025 11:02:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=9A=E5=8A=A1=E8=81=8C=E5=8A=A1=E7=A7=AF?= =?UTF-8?q?=E5=88=86=E6=9B=B4=E6=96=B0=E8=A1=A8=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wysecond/PostionPointsUpdateCron.java | 52 +++++++++---------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/src/weaver/interfaces/wysecond/PostionPointsUpdateCron.java b/src/weaver/interfaces/wysecond/PostionPointsUpdateCron.java index 0d4588d..f5db642 100644 --- a/src/weaver/interfaces/wysecond/PostionPointsUpdateCron.java +++ b/src/weaver/interfaces/wysecond/PostionPointsUpdateCron.java @@ -6,6 +6,8 @@ import weaver.common.DateUtil; import weaver.conn.RecordSet; import weaver.interfaces.schedule.BaseCronJob; +import java.math.BigDecimal; +import java.math.RoundingMode; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; @@ -49,6 +51,7 @@ public class PostionPointsUpdateCron extends BaseCronJob { .build()); } + // 处理考核结果表数据,按xm分组,筛选最新记录 Map resultMap = checkList.stream() .collect(Collectors.groupingBy( @@ -64,18 +67,12 @@ public class PostionPointsUpdateCron extends BaseCronJob { )); //合并 - pointsList.removeIf(point -> { + pointsList.forEach(point -> { PostionPoints matchedPoint = resultMap.get(point.getResourceId()); - if (matchedPoint == null) { - return true; // 如果在 resultMap 中找不到对应元素,返回 true 表示移除该元素 - } - if (matchedPoint.getYear() != null) { + if (matchedPoint != null) { point.setYear(matchedPoint.getYear()); - } - if (matchedPoint.getCheckResult() != null) { point.setCheckResult(matchedPoint.getCheckResult()); } - return false; }); @@ -85,35 +82,36 @@ public class PostionPointsUpdateCron extends BaseCronJob { Date currentDate = new Date(); for (PostionPoints point : pointsList) { + if (point.getJobStartDate() == null || point.getJobStartDate().isEmpty()) { + continue; + } try { // 计算任职年限 Date startDate = sdf.parse(point.getJobStartDate()); long diffInMillis = currentDate.getTime() - startDate.getTime(); - long diffInDays = diffInMillis / (1000 * 60 * 60 * 24); - double years = (double) diffInDays / 365; - point.setJobYears(String.format("%.2f", years)); + BigDecimal millisPerDay = BigDecimal.valueOf(1000 * 60 * 60 * 24); + BigDecimal diffDays = BigDecimal.valueOf(diffInMillis).divide(millisPerDay, 10, RoundingMode.HALF_UP); + BigDecimal years = diffDays.divide(BigDecimal.valueOf(365), 2, RoundingMode.HALF_UP); + point.setJobYears(years.toString()); // 根据 checkResult 获取额外积分 int extraPoints; - switch (point.getCheckResult()) { - case 0: - extraPoints = 3; - break; - case 1: - extraPoints = 2; - break; - case 2: - extraPoints = 1; - break; - default: - extraPoints = 0; - break; + Integer checkResult = point.getCheckResult(); + if (checkResult == null) { + extraPoints = 0; + } else { + switch (checkResult) { + case 0: extraPoints = 3; break; + case 1: extraPoints = 2; break; + case 2: extraPoints = 1; break; + default: extraPoints = 0; break; + } } - if (point.getChangeType() == 0) { - point.setPoints(extraPoints); - } else if (point.getChangeType() == 1 || point.getChangeType() == 2) { + if (point.getChangeType() == 1 || point.getChangeType() == 2) { point.setPoints(point.getPoints() + extraPoints); + }else { + point.setPoints(extraPoints); } rs.executeUpdate("update uf_ywzwxx set rbywzwcjnx = ?,rbywzwcjljjf = ? where id = ?",point.getJobYears(),point.getPoints(),point.getId());