|
@@ -11,18 +11,13 @@ import kd.bos.orm.query.QFilter;
|
|
import kd.bos.schedule.api.StopTask;
|
|
import kd.bos.schedule.api.StopTask;
|
|
import kd.bos.schedule.executor.AbstractTask;
|
|
import kd.bos.schedule.executor.AbstractTask;
|
|
import kd.bos.servicehelper.QueryServiceHelper;
|
|
import kd.bos.servicehelper.QueryServiceHelper;
|
|
-import kd.bos.util.StringUtils;
|
|
|
|
import nckd.jimin.jyyy.fi.common.constant.BillTypeConstants;
|
|
import nckd.jimin.jyyy.fi.common.constant.BillTypeConstants;
|
|
|
|
+import nckd.jimin.jyyy.fi.common.util.CommonUtils;
|
|
import nckd.jimin.jyyy.fi.plugin.operate.Helper.PersonReimQuotaHelper;
|
|
import nckd.jimin.jyyy.fi.plugin.operate.Helper.PersonReimQuotaHelper;
|
|
|
|
|
|
-import java.time.LocalDate;
|
|
|
|
-import java.time.LocalDateTime;
|
|
|
|
-import java.time.LocalTime;
|
|
|
|
-import java.time.ZoneId;
|
|
|
|
-import java.time.format.DateTimeFormatter;
|
|
|
|
-import java.util.Date;
|
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
import java.util.Optional;
|
|
import java.util.Optional;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -38,76 +33,38 @@ public class PersonReimLeverSyncTask extends AbstractTask implements StopTask {
|
|
protected PersonReimQuotaHelper getPersonReimQuotaHelper() {
|
|
protected PersonReimQuotaHelper getPersonReimQuotaHelper() {
|
|
return Optional.ofNullable(personReimQuotaHelper).orElse(new PersonReimQuotaHelper());
|
|
return Optional.ofNullable(personReimQuotaHelper).orElse(new PersonReimQuotaHelper());
|
|
}
|
|
}
|
|
- private static final String SYNCDATE = "syncdate";
|
|
|
|
@Override
|
|
@Override
|
|
public void execute(RequestContext requestContext, Map<String, Object> map) throws KDException {
|
|
public void execute(RequestContext requestContext, Map<String, Object> map) throws KDException {
|
|
log.info("-------- PersonReimLeverSyncTask 启动同步人员报销级别任务 --------");
|
|
log.info("-------- PersonReimLeverSyncTask 启动同步人员报销级别任务 --------");
|
|
|
|
|
|
- LocalDate yesterday = getYesterday(map);
|
|
|
|
- // 昨天最早的日期时间(00:00:00)
|
|
|
|
- LocalDateTime startOfYesterday = yesterday.atStartOfDay();
|
|
|
|
- Date beginDate = Date.from(startOfYesterday.atZone(ZoneId.systemDefault()).toInstant());
|
|
|
|
- // 昨天最晚的日期时间(23:59:59)
|
|
|
|
- LocalDateTime endOfYesterday = yesterday.atTime(LocalTime.MAX);
|
|
|
|
- Date endDate = Date.from(endOfYesterday.atZone(ZoneId.systemDefault()).toInstant());
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- // 获取昨天
|
|
|
|
- DynamicObjectCollection changeJobCol = QueryServiceHelper.query(BillTypeConstants.HRPI_EMPJOBREL, "person.id,person.number,joblevel.id", new QFilter[]{
|
|
|
|
- new QFilter("startdate", QCP.large_equals, beginDate),
|
|
|
|
- new QFilter("startdate", QCP.less_equals, endDate),
|
|
|
|
|
|
+ // 查询当前生效的人员岗位信息
|
|
|
|
+ DynamicObjectCollection positionCol = QueryServiceHelper.query(BillTypeConstants.HRPI_EMPPOSORGREL, "person.id,position.id,company.id", new QFilter[]{
|
|
new QFilter("businessstatus", QCP.equals, "1"),
|
|
new QFilter("businessstatus", QCP.equals, "1"),
|
|
- new QFilter("iscurrentversion", QCP.equals, "1")
|
|
|
|
|
|
+ new QFilter("iscurrentversion", QCP.equals, "1"),
|
|
|
|
+ new QFilter("datastatus", QCP.equals, "1"),
|
|
|
|
+ new QFilter("isprimary", QCP.equals, "1")
|
|
});
|
|
});
|
|
- log.info("changeJobCol size : {}" , changeJobCol.size());
|
|
|
|
- changeJobCol.stream().forEach(changeJob -> syncReunimLever(changeJob));
|
|
|
|
- log.info("-------- PersonReimLeverSyncTask 同步人员报销级别任务结束 --------");
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 获取同步日期
|
|
|
|
- * @param map
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- protected LocalDate getYesterday(Map<String, Object> map) {
|
|
|
|
- if(map.containsKey(SYNCDATE) && StringUtils.isNotEmpty((String)map.get(SYNCDATE))){
|
|
|
|
- return LocalDate.parse((String)map.get(SYNCDATE), DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
|
- }else{
|
|
|
|
- return LocalDate.now().minusDays(1);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- /**
|
|
|
|
- * 同步人员报销级别
|
|
|
|
- * @param changeJob
|
|
|
|
- */
|
|
|
|
- protected void syncReunimLever(DynamicObject changeJob) {
|
|
|
|
- // 获取人员ID
|
|
|
|
- Long personId = changeJob.getLong("person.id");
|
|
|
|
- // 人员编码
|
|
|
|
- String personNumber = changeJob.getString("person.number");
|
|
|
|
- // 获取职级ID
|
|
|
|
- Long jobId = changeJob.getLong("joblevel.id");
|
|
|
|
- DynamicObject potisionInfo = fetchPositionInfo(personId);
|
|
|
|
- if(potisionInfo == null) {
|
|
|
|
- log.info("人员 {} 职位信息不存在", personId);
|
|
|
|
- return;
|
|
|
|
|
|
+ Map<Long, Long> personCompanyMap = positionCol.stream().collect(Collectors.toMap(r -> r.getLong("person.id"), r -> r.getLong("company.id"), (k1, k2) -> k1));
|
|
|
|
+ // 获取所有人员最新的职级
|
|
|
|
+ Map<Long, Long> personJobMap = QueryServiceHelper.query(BillTypeConstants.HRPI_EMPJOBREL, "person.id,joblevel.id", new QFilter[]{
|
|
|
|
+ new QFilter("businessstatus", QCP.equals, "1"),
|
|
|
|
+ new QFilter("datastatus", QCP.equals, "1"),
|
|
|
|
+ new QFilter("iscurrentversion", QCP.equals, "1")
|
|
|
|
+ }).stream().collect(Collectors.toMap(r -> r.getLong("person.id"), r -> r.getLong("joblevel.id"), (k1, k2) -> k1));
|
|
|
|
+
|
|
|
|
+ // 获取人员最新的报销级别
|
|
|
|
+ PersonReimQuotaHelper helper = getPersonReimQuotaHelper();
|
|
|
|
+
|
|
|
|
+ for(Map.Entry<Long, Long> entryRow : personJobMap.entrySet()){
|
|
|
|
+ Long personId = entryRow.getKey();
|
|
|
|
+ Long jobLeverId = entryRow.getValue();
|
|
|
|
+ if(personJobMap.containsKey(personId)){
|
|
|
|
+ DynamicObject userInfo = CommonUtils.getUserByHrPersonId(personId);
|
|
|
|
+ helper.syncReimLever(userInfo.getLong("id"),personCompanyMap.get(personId),jobLeverId);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- String companyNumber = potisionInfo.getString("company.number");
|
|
|
|
- DynamicObject company = QueryServiceHelper.queryOne("bos_org", "id", new QFilter("number", QCP.equals, companyNumber).toArray());
|
|
|
|
- DynamicObject userInfo = QueryServiceHelper.queryOne("bos_user", "id", new QFilter("number", QCP.equals, personNumber).toArray());
|
|
|
|
- getPersonReimQuotaHelper().syncReimLever(userInfo.getLong("id"),jobId,company.getLong("id"));
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- private DynamicObject fetchPositionInfo(Long personId) {
|
|
|
|
- return QueryServiceHelper.queryOne(BillTypeConstants.HRPI_EMPPOSORGREL, "company.number", new QFilter[]{
|
|
|
|
- new QFilter("businessstatus", QCP.less_equals, "1"),
|
|
|
|
- new QFilter("iscurrentversion", QCP.less_equals, "1"),
|
|
|
|
- new QFilter("person.id", QCP.equals, personId),
|
|
|
|
- new QFilter("isprimary", QCP.less_equals, "1")
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+ log.info("-------- PersonReimLeverSyncTask 同步人员报销级别任务结束 --------");
|
|
|
|
+ }
|
|
}
|
|
}
|