|
|
@@ -30,12 +30,14 @@ import nckd.jxccl.base.common.utils.StrFormatter;
|
|
|
import nckd.jxccl.base.hrpi.helper.EmpPosOrgRelHelper;
|
|
|
import nckd.jxccl.base.orm.helper.QFilterCommonHelper;
|
|
|
import nckd.jxccl.hr.psms.common.PerfRankMgmtConstant;
|
|
|
+import nckd.jxccl.hr.psms.common.PositionStructureConstant;
|
|
|
import nckd.jxccl.hr.psms.plugin.operate.performance.validate.PerfRankMgmtSaveValidate;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.atomic.AtomicInteger;
|
|
|
import java.util.stream.Collectors;
|
|
|
import kd.bos.dataentity.utils.ObjectUtils;
|
|
|
|
|
|
@@ -72,34 +74,109 @@ public class PerfRankMgmtSaveOpPlugin extends AbstractOperationServicePlugIn imp
|
|
|
} else{
|
|
|
dataMigration = FormConstant.DATA_MIGRATION.equalsIgnoreCase(invoker.toString());
|
|
|
}
|
|
|
+ List<Long> ids = new ArrayList<>();
|
|
|
+ List<Long> personids = new ArrayList<>();
|
|
|
+ //用来判断后续有没有必要查询任职经历,避免浪费资源
|
|
|
+ boolean isQueryEmpPosOrg = false;
|
|
|
for (DynamicObject dataEntity : e.getDataEntities()) {
|
|
|
+ long id = dataEntity.getLong(FormConstant.ID_KEY);
|
|
|
+ if(id > 0){
|
|
|
+ ids.add(id);
|
|
|
+ }
|
|
|
+ DynamicObjectCollection entryList = dataEntity.getDynamicObjectCollection(PerfRankMgmtConstant.NCKD_PERFRANKMGMTENTRY);
|
|
|
+ for (DynamicObject entry : entryList) {
|
|
|
+ DynamicObject person = entry.getDynamicObject(FormConstant.NCKD_PERSON);
|
|
|
+ if(person != null) {
|
|
|
+ personids.add(person.getLong(FormConstant.ID_KEY));
|
|
|
+ }
|
|
|
+ if(entry.getDynamicObject(FormConstant.NCKD_DEP) == null){
|
|
|
+ isQueryEmpPosOrg = true;
|
|
|
+ }
|
|
|
+ if(entry.getDynamicObject(PositionStructureConstant.NCKD_POSITIONHR) == null){
|
|
|
+ isQueryEmpPosOrg = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- //事务开始前先查询数据库中的排名名单,找出哪些是此次被删除的人员
|
|
|
+ Map<Long, List<DynamicObject>> dbEntryMap = new HashMap<>();
|
|
|
+ if(!ids.isEmpty()) {
|
|
|
+ // 获取数据库中存在的人员ID列表
|
|
|
QueryFieldBuilder queryFieldBuilder = QueryFieldBuilder.create()
|
|
|
- .addIdNumberName(PerfRankMgmtConstant.NCKD_PERFRANKMGMTENTRY,FormConstant.NCKD_PERSON);
|
|
|
- QFilter qFilter = new QFilter(FormConstant.ID_KEY, QCP.equals, dataEntity.getLong(FormConstant.ID_KEY));
|
|
|
+ .add(FormConstant.ID_KEY)
|
|
|
+ .addIdNumberName(PerfRankMgmtConstant.NCKD_PERFRANKMGMTENTRY, FormConstant.NCKD_PERSON);
|
|
|
+ QFilter qFilter = new QFilter(FormConstant.ID_KEY, QCP.in, ids);
|
|
|
DynamicObjectCollection dbEntryList = QueryServiceHelper.query(PerfRankMgmtConstant.NCKD_PERFRANKMGMT_ENTITYID, queryFieldBuilder.buildSelect(), new QFilter[]{qFilter});
|
|
|
+ // 获取数据库中存在的记录,按记录ID分组
|
|
|
+ dbEntryMap = dbEntryList.stream()
|
|
|
+ .collect(Collectors.groupingBy(
|
|
|
+ entry -> entry.getLong(FormConstant.ID_KEY) // 按记录ID分组
|
|
|
+ ));
|
|
|
+ }
|
|
|
+ Map<Long, DynamicObject> empPosOrgRelByEmployeesMap = new HashMap<>();
|
|
|
+ if(!personids.isEmpty() && isQueryEmpPosOrg){
|
|
|
+ //获取人员最新任职
|
|
|
+ empPosOrgRelByEmployeesMap = EmpPosOrgRelHelper.queryEmpPosOrgRelByEmployeesMap(personids);
|
|
|
+ }
|
|
|
|
|
|
- // 获取数据库中存在的人员ID列表
|
|
|
- List<Long> dbPersonIds = dbEntryList.stream()
|
|
|
+
|
|
|
+
|
|
|
+ for (DynamicObject dataEntity : e.getDataEntities()) {
|
|
|
+
|
|
|
+ //事务开始前先查询数据库中的排名名单,找出哪些是此次被删除的人员(删除的人员同步删除人员考评的考核结果)
|
|
|
+ List<DynamicObject> dbEntryList = dbEntryMap.get(dataEntity.getLong(FormConstant.ID_KEY));
|
|
|
+ List<Long> dbPersonIds = Optional.ofNullable(dbEntryList)
|
|
|
+ .orElse(Collections.emptyList())
|
|
|
+ .stream()
|
|
|
.map(dbEntry -> dbEntry.getLong(String.join(".", PerfRankMgmtConstant.NCKD_PERFRANKMGMTENTRY,FormConstant.NCKD_PERSON, FormConstant.ID_KEY)))
|
|
|
.collect(Collectors.toList());
|
|
|
dbPersonMap.put(dataEntity.getLong(FormConstant.ID_KEY), dbPersonIds);
|
|
|
|
|
|
- List<Long> personids = new ArrayList<>();
|
|
|
+
|
|
|
DynamicObjectCollection entryList = dataEntity.getDynamicObjectCollection(PerfRankMgmtConstant.NCKD_PERFRANKMGMTENTRY);
|
|
|
+ entryList.sort((o1, o2) -> {
|
|
|
+ Integer toprank1 = (Integer) o1.get(PerfRankMgmtConstant.NCKD_TOPRANK);
|
|
|
+ Integer toprank2 = (Integer) o2.get(PerfRankMgmtConstant.NCKD_TOPRANK);
|
|
|
+
|
|
|
+ // 如果两个值都为空或为0,则认为相等
|
|
|
+ if ((toprank1 == null || toprank1 == 0) && (toprank2 == null || toprank2 == 0)) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ // 如果第一个值为空或为0,则排在后面
|
|
|
+ if (toprank1 == null || toprank1 == 0) {
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ // 如果第二个值为空或为0,则排在前面
|
|
|
+ if (toprank2 == null || toprank2 == 0) {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ // 都不为空且不为0则比较数值大小
|
|
|
+ return toprank1.compareTo(toprank2);
|
|
|
+ });
|
|
|
+ AtomicInteger rankIndex = new AtomicInteger(1);
|
|
|
for (DynamicObject entry : entryList) {
|
|
|
DynamicObject person = entry.getDynamicObject(FormConstant.NCKD_PERSON);
|
|
|
- DynamicObject empPosOrgRel = entry.getDynamicObject(FormConstant.NCKD_EMPPOSORGREL);
|
|
|
- if(person == null && empPosOrgRel != null){
|
|
|
- entry.set(FormConstant.NCKD_PERSON, empPosOrgRel.getDynamicObject(FormConstant.EMPLOYEE_KEY));
|
|
|
+ personids.add(person.getLong(FormConstant.ID_KEY));
|
|
|
+ DynamicObject empPosOrg = empPosOrgRelByEmployeesMap.get(person.getLong(FormConstant.ID_KEY));
|
|
|
+ if(entry.getDynamicObject(FormConstant.NCKD_DEP) == null){
|
|
|
+ //赋值组织
|
|
|
+ entry.set(FormConstant.NCKD_DEP,empPosOrg.get(FormConstant.ADMINORG));
|
|
|
}
|
|
|
- person = entry.getDynamicObject(FormConstant.NCKD_PERSON);
|
|
|
- if(person != null) {
|
|
|
- personids.add(person.getLong(FormConstant.ID_KEY));
|
|
|
+ if(entry.getDynamicObject(PositionStructureConstant.NCKD_POSITIONHR) == null){
|
|
|
+ //赋值岗位
|
|
|
+ entry.set(PositionStructureConstant.NCKD_POSITIONHR,empPosOrg.get(FormConstant.POSITION_KEY));
|
|
|
+ }
|
|
|
+
|
|
|
+ //生成R排名
|
|
|
+ boolean isRanking = entry.getBoolean(PerfRankMgmtConstant.NCKD_ISRANKING);
|
|
|
+ boolean postAllowance = entry.getBoolean(PerfRankMgmtConstant.NCKD_POSTALLOWANCE);
|
|
|
+ if(isRanking && postAllowance){
|
|
|
+ entry.set(PerfRankMgmtConstant.NCKD_ALLOWANCERANK, rankIndex.getAndIncrement());
|
|
|
+ }else{
|
|
|
+ entry.set(PerfRankMgmtConstant.NCKD_ALLOWANCERANK, null);
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
- if(dataMigration){
|
|
|
+ /*if(dataMigration){
|
|
|
//数据迁移逻辑
|
|
|
DynamicObject[] dbEmpPosOrgRelList = EmpPosOrgRelHelper.queryEmpPosOrgRelByEmployees(personids);
|
|
|
for (DynamicObject entry : entryList) {
|
|
|
@@ -116,7 +193,7 @@ public class PerfRankMgmtSaveOpPlugin extends AbstractOperationServicePlugIn imp
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
+ }*/
|
|
|
}
|
|
|
|
|
|
}
|
|
|
@@ -156,6 +233,8 @@ public class PerfRankMgmtSaveOpPlugin extends AbstractOperationServicePlugIn imp
|
|
|
if(!deletedPersonIds.isEmpty()){
|
|
|
personIds.addAll(deletedPersonIds);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
//获取考核周期
|
|
|
List<Long> perfManagerIds = findPerfManager(theYear, personIds);
|
|
|
QFilter filter = QFilterCommonHelper.getIdInFilter(perfManagerIds);
|