fix:五院杭州中心 业务职务积分库更新需求变更处理
This commit is contained in:
parent
7092bde9fa
commit
ed0934ba8d
|
|
@ -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<PostionPoints> 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<PostionPoints> 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<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.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;
|
||||
if (CollectionUtils.isNotEmpty(pointsList)) {
|
||||
//1.业务职务信息分组
|
||||
Map<Integer, List<PostionPoints>> listMap = pointsList.stream()
|
||||
.collect(Collectors.groupingBy(PostionPoints::getResourceId));
|
||||
|
||||
listMap.forEach((xm, postionPoints) -> {
|
||||
List<PostionPoints> 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;
|
||||
}
|
||||
try {
|
||||
|
||||
//只处理最新数据
|
||||
//1.根据xm和年度匹配绩效考核最新数据
|
||||
List<PostionPoints> 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 (maxIdRecord.getChangeType() == 1 || maxIdRecord.getChangeType() == 2) {
|
||||
//调整类型是降职和平调
|
||||
maxIdRecord.setPoints(resultPoint + extraPoints);
|
||||
}else {
|
||||
maxIdRecord.setPoints(resultPoint);
|
||||
}
|
||||
|
||||
// 计算任职年限
|
||||
Date startDate = sdf.parse(point.getJobStartDate());
|
||||
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);
|
||||
point.setJobYears(years.toString());
|
||||
|
||||
// 根据 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;
|
||||
}
|
||||
}
|
||||
|
||||
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());
|
||||
maxIdRecord.setJobYears(years.toString());
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
rs.writeLog("PostionPointsUpdateCron:日期格式解析异常");
|
||||
}
|
||||
|
||||
rs.executeUpdate("update uf_ywzwxx set rbywzwcjnx = ?,rbywzwcjljjf = ? where id = ?",maxIdRecord.getJobYears(),maxIdRecord.getPoints(),maxIdRecord.getId());
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue