From ed0934ba8dd532237071c9aa4cff255894e7144a Mon Sep 17 00:00:00 2001 From: liangcheng <1546584672@qq.com> Date: Wed, 13 Aug 2025 13:51:45 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BA=94=E9=99=A2=E6=9D=AD=E5=B7=9E?= =?UTF-8?q?=E4=B8=AD=E5=BF=83=20=E4=B8=9A=E5=8A=A1=E8=81=8C=E5=8A=A1?= =?UTF-8?q?=E7=A7=AF=E5=88=86=E5=BA=93=E6=9B=B4=E6=96=B0=E9=9C=80=E6=B1=82?= =?UTF-8?q?=E5=8F=98=E6=9B=B4=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wysecond/PostionPointsUpdateCron.java | 131 +++++++++--------- 1 file changed, 69 insertions(+), 62 deletions(-) diff --git a/src/weaver/interfaces/wysecond/PostionPointsUpdateCron.java b/src/weaver/interfaces/wysecond/PostionPointsUpdateCron.java index f5db642..b3f7a9b 100644 --- a/src/weaver/interfaces/wysecond/PostionPointsUpdateCron.java +++ b/src/weaver/interfaces/wysecond/PostionPointsUpdateCron.java @@ -2,6 +2,7 @@ package weaver.interfaces.wysecond; import com.engine.wysecond.entity.PostionPoints; import com.weaver.general.Util; +import org.apache.commons.collections.CollectionUtils; import weaver.common.DateUtil; import weaver.conn.RecordSet; import weaver.interfaces.schedule.BaseCronJob; @@ -25,8 +26,10 @@ public class PostionPointsUpdateCron extends BaseCronJob { public void execute() { RecordSet rs = new RecordSet(); + String year = DateUtil.getYear(); + List pointsList = new ArrayList<>(); - rs.executeQuery("select id,xm,zwdzlx,rbywzwcjqssj,rbywzwcjnx,rbywzwcjljjf from uf_ywzwxx"); + rs.executeQuery("select id,xm,zwdzlx,rbywzwcjqssj,rbywzwcjnx,rbywzwcjljjf,nd from uf_ywzwxx"); while (rs.next()) { pointsList.add(PostionPoints.builder() .id(Util.getIntValue(rs.getString("id"))) @@ -35,12 +38,12 @@ public class PostionPointsUpdateCron extends BaseCronJob { .jobStartDate(Util.null2String(rs.getString("rbywzwcjqssj"))) .jobYears(Util.null2String(rs.getString("rbywzwcjnx"))) .points(Util.getIntValue(rs.getString("rbywzwcjljjf"),0)) + .year(Util.getIntValue("nd")) .build()); } List checkList = new ArrayList<>(); - String year = DateUtil.getYear(); rs.executeQuery("select id,xm,nd,ndjxkhjl from uf_ndjxkhdjtzzxld where nd = ?",year); while (rs.next()) { checkList.add(PostionPoints.builder() @@ -51,78 +54,82 @@ public class PostionPointsUpdateCron extends BaseCronJob { .build()); } - - // 处理考核结果表数据,按xm分组,筛选最新记录 - Map resultMap = checkList.stream() - .collect(Collectors.groupingBy( - PostionPoints::getResourceId, - Collectors.collectingAndThen( - Collectors.maxBy( - Comparator.comparingInt(PostionPoints::getYear) - .thenComparingInt(PostionPoints::getId) - .reversed() - ), - optional -> optional.orElse(null) - ) - )); - - //合并 - pointsList.forEach(point -> { - PostionPoints matchedPoint = resultMap.get(point.getResourceId()); - if (matchedPoint != null) { - point.setYear(matchedPoint.getYear()); - point.setCheckResult(matchedPoint.getCheckResult()); - } - }); - - //积分统计 任职年限计算 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); // 获取当前日期 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(); - 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()); + if (CollectionUtils.isNotEmpty(pointsList)) { + //1.业务职务信息分组 + Map> listMap = pointsList.stream() + .collect(Collectors.groupingBy(PostionPoints::getResourceId)); - // 根据 checkResult 获取额外积分 - int extraPoints; - 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; + listMap.forEach((xm, postionPoints) -> { + List sortedList = postionPoints.stream() + .sorted(Comparator.comparingInt(PostionPoints::getId).reversed()) + .collect(Collectors.toList()); + + PostionPoints maxIdRecord = sortedList.isEmpty() ? null : sortedList.get(0); + PostionPoints secondMaxIdRecord = sortedList.size() >= 2 ? sortedList.get(1) : null; + + if (maxIdRecord == null || maxIdRecord.getJobStartDate() == null || maxIdRecord.getJobStartDate().isEmpty()) { + return; + } + + //只处理最新数据 + //1.根据xm和年度匹配绩效考核最新数据 + List filteredList = checkList.stream() + .filter(p -> Objects.equals(p.getResourceId(), maxIdRecord.getResourceId()) && Objects.equals(p.getYear(), maxIdRecord.getYear())) + .collect(Collectors.toList()); + + //维护默认值 + int extraPoints = 0; + if (secondMaxIdRecord != null) { + extraPoints = secondMaxIdRecord.getPoints(); + } + + int resultPoint = 0; + if (CollectionUtils.isNotEmpty(filteredList)) { + PostionPoints maxInFiltered = filteredList.stream() + .max(Comparator.comparingInt(PostionPoints::getId)) + .orElse(null); + + if (maxInFiltered != null) { + // 根据 checkResult 获取额外积分 + Integer checkResult = maxInFiltered.getCheckResult(); + switch (checkResult) { + case 0: resultPoint = 3; break; + case 1: resultPoint = 2; break; + case 2: resultPoint = 1; break; + default: resultPoint = 0; break; + } } } - if (point.getChangeType() == 1 || point.getChangeType() == 2) { - point.setPoints(point.getPoints() + extraPoints); + //计算业务积分 + if (maxIdRecord.getChangeType() == 1 || maxIdRecord.getChangeType() == 2) { + //调整类型是降职和平调 + maxIdRecord.setPoints(resultPoint + extraPoints); }else { - point.setPoints(extraPoints); + maxIdRecord.setPoints(resultPoint); } - rs.executeUpdate("update uf_ywzwxx set rbywzwcjnx = ?,rbywzwcjljjf = ? where id = ?",point.getJobYears(),point.getPoints(),point.getId()); - } catch (ParseException e) { - e.printStackTrace(); - } + // 计算任职年限 + Date startDate = null; + try { + startDate = sdf.parse(maxIdRecord.getJobStartDate()); + long diffInMillis = currentDate.getTime() - startDate.getTime(); + 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); + maxIdRecord.setJobYears(years.toString()); + } catch (ParseException e) { + rs.writeLog("PostionPointsUpdateCron:日期格式解析异常"); + } + + rs.executeUpdate("update uf_ywzwxx set rbywzwcjnx = ?,rbywzwcjljjf = ? where id = ?",maxIdRecord.getJobYears(),maxIdRecord.getPoints(),maxIdRecord.getId()); + + }); } - - } - - - }