You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
weaver-develop/src/weaver/interfaces/wysecond/PostionPointsUpdateCron.java

131 lines
4.9 KiB
Java

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package weaver.interfaces.wysecond;
import com.engine.wysecond.entity.PostionPoints;
import com.weaver.general.Util;
import weaver.common.DateUtil;
import weaver.conn.RecordSet;
import weaver.interfaces.schedule.BaseCronJob;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
/**
* @Author liang.cheng
* @Date 2025/4/1 18:00
* @Description: 业务职务积分库更新
* @Version 1.0
*/
public class PostionPointsUpdateCron extends BaseCronJob {
@Override
public void execute() {
RecordSet rs = new RecordSet();
List<PostionPoints> pointsList = new ArrayList<>();
rs.executeQuery("select id,xm,zwdzlx,rbywzwcjqssj,rbywzwcjnx,rbywzwcjljjf from uf_ywzwxx");
while (rs.next()) {
pointsList.add(PostionPoints.builder()
.id(Util.getIntValue(rs.getString("id")))
.resourceId(Util.getIntValue(rs.getString("xm")))
.changeType(Util.getIntValue(rs.getString("zwdzlx")))
.jobStartDate(Util.null2String(rs.getString("rbywzwcjqssj")))
.jobYears(Util.null2String(rs.getString("rbywzwcjnx")))
.points(Util.getIntValue(rs.getString("rbywzwcjljjf"),0))
.build());
}
List<PostionPoints> checkList = new ArrayList<>();
String year = DateUtil.getYear();
rs.executeQuery("select id,xm,khgzq,khjg from uf_khxx where khgzq = ?",year);
while (rs.next()) {
checkList.add(PostionPoints.builder()
.id(Util.getIntValue(rs.getString("id")))
.resourceId(Util.getIntValue(rs.getString("xm")))
.year(Util.getIntValue(rs.getString("khgzq")))
.checkResult(Util.getIntValue(rs.getString("khjg")))
.build());
}
// 处理考核结果表数据按xm分组筛选最新记录
Map<Integer, PostionPoints> 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.removeIf(point -> {
PostionPoints matchedPoint = resultMap.get(point.getResourceId());
if (matchedPoint == null) {
return true; // 如果在 resultMap 中找不到对应元素,返回 true 表示移除该元素
}
if (matchedPoint.getYear() != null) {
point.setYear(matchedPoint.getYear());
}
if (matchedPoint.getCheckResult() != null) {
point.setCheckResult(matchedPoint.getCheckResult());
}
return false;
});
//积分统计 任职年限计算
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
// 获取当前日期
Date currentDate = new Date();
for (PostionPoints point : pointsList) {
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));
// 根据 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;
}
if (point.getChangeType() == 0) {
point.setPoints(extraPoints);
} else if (point.getChangeType() == 1 || point.getChangeType() == 2) {
point.setPoints(point.getPoints() + extraPoints);
}
rs.executeUpdate("update uf_ywzwxx set rbywzwcjnx = ?,rbywzwcjljjf = ? where id = ?",point.getJobYears(),point.getPoints(),point.getId());
} catch (ParseException e) {
e.printStackTrace();
}
}
}
}