|
@@ -23,6 +23,7 @@ import kd.bos.servicehelper.QueryServiceHelper;
|
|
|
import kd.bos.servicehelper.operation.SaveServiceHelper;
|
|
import kd.bos.servicehelper.operation.SaveServiceHelper;
|
|
|
import kd.sdk.plugin.Plugin;
|
|
import kd.sdk.plugin.Plugin;
|
|
|
import nckd.jxccl.base.common.constant.FormConstant;
|
|
import nckd.jxccl.base.common.constant.FormConstant;
|
|
|
|
|
+import nckd.jxccl.base.common.utils.ConvertUtil;
|
|
|
import nckd.jxccl.base.common.utils.DateUtil;
|
|
import nckd.jxccl.base.common.utils.DateUtil;
|
|
|
import nckd.jxccl.base.common.utils.QueryFieldBuilder;
|
|
import nckd.jxccl.base.common.utils.QueryFieldBuilder;
|
|
|
import nckd.jxccl.base.common.utils.StrFormatter;
|
|
import nckd.jxccl.base.common.utils.StrFormatter;
|
|
@@ -31,15 +32,7 @@ import nckd.jxccl.opmc.pm.helper.PerfManagerHelper;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
-import java.util.ArrayList;
|
|
|
|
|
-import java.util.Arrays;
|
|
|
|
|
-import java.util.Collections;
|
|
|
|
|
-import java.util.Date;
|
|
|
|
|
-import java.util.HashMap;
|
|
|
|
|
-import java.util.List;
|
|
|
|
|
-import java.util.Map;
|
|
|
|
|
-import java.util.Objects;
|
|
|
|
|
-import java.util.StringJoiner;
|
|
|
|
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -51,11 +44,9 @@ import java.util.stream.Collectors;
|
|
|
*/
|
|
*/
|
|
|
public class PerfManagerSaveOpPlugin extends AbstractOperationServicePlugIn implements Plugin {
|
|
public class PerfManagerSaveOpPlugin extends AbstractOperationServicePlugIn implements Plugin {
|
|
|
|
|
|
|
|
- private List<PersonPerfInfo> personPerfInfos = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
- private Map<Long, DynamicObject> lastPerfManagerMap;
|
|
|
|
|
|
|
|
|
|
- private List<Long> personIds;
|
|
|
|
|
|
|
+ Map<Long, Date> personBeginYearMap = new HashMap<>();
|
|
|
private List<Long> ids = new ArrayList<>();
|
|
private List<Long> ids = new ArrayList<>();
|
|
|
|
|
|
|
|
private final static String INTERACTION_SPONORE = PerfManagerSaveOpPlugin.class.getName();
|
|
private final static String INTERACTION_SPONORE = PerfManagerSaveOpPlugin.class.getName();
|
|
@@ -63,80 +54,158 @@ public class PerfManagerSaveOpPlugin extends AbstractOperationServicePlugIn impl
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public void onAddValidators(AddValidatorsEventArgs e) {
|
|
public void onAddValidators(AddValidatorsEventArgs e) {
|
|
|
|
|
+ String invoker = (String)this.getOption().getVariables().get(FormConstant.HR_INVOKER_PARAM_INVOKER);
|
|
|
|
|
+ boolean dataMigration = FormConstant.DATA_MIGRATION.equalsIgnoreCase(invoker);
|
|
|
|
|
+ boolean isUpdate = ConvertUtil.toBoolean(this.getOption().getVariableValue("isUpdate",StringUtils.EMPTY),Boolean.FALSE);
|
|
|
e.addValidator(new AbstractValidator() {
|
|
e.addValidator(new AbstractValidator() {
|
|
|
@Override
|
|
@Override
|
|
|
public void validate() {
|
|
public void validate() {
|
|
|
|
|
+ Boolean isCycleGenerate = ConvertUtil.toBoolean(this.getOption().getVariableValue("cyclegenerate", StringUtils.EMPTY), Boolean.FALSE);
|
|
|
//第一个循环先获取表单数据,这里需要兼容单人和批量的数据包
|
|
//第一个循环先获取表单数据,这里需要兼容单人和批量的数据包
|
|
|
|
|
+ Map<Long, List<PersonPerfInfo>> currentBatchData = new HashMap<>();
|
|
|
for (ExtendedDataEntity rowDataEntity : getDataEntities()) {
|
|
for (ExtendedDataEntity rowDataEntity : getDataEntities()) {
|
|
|
DynamicObject data = rowDataEntity.getDataEntity();
|
|
DynamicObject data = rowDataEntity.getDataEntity();
|
|
|
int dataEntityIndex = rowDataEntity.getDataEntityIndex();
|
|
int dataEntityIndex = rowDataEntity.getDataEntityIndex();
|
|
|
long id = data.getLong(FormConstant.ID_KEY);
|
|
long id = data.getLong(FormConstant.ID_KEY);
|
|
|
-
|
|
|
|
|
DynamicObject person = data.getDynamicObject(FormConstant.NCKD_PERSON);
|
|
DynamicObject person = data.getDynamicObject(FormConstant.NCKD_PERSON);
|
|
|
|
|
+ person = person == null ? data.getDynamicObject(FormConstant.NCKD_EMPPOSORGREL).getDynamicObject(FormConstant.EMPLOYEE_KEY) : person;
|
|
|
|
|
+ data.set(FormConstant.NCKD_PERSON, person);
|
|
|
Date beginYear = data.getDate(PerfManagerFormConstant.NCKD_BEGINYEAR);
|
|
Date beginYear = data.getDate(PerfManagerFormConstant.NCKD_BEGINYEAR);
|
|
|
Date endYear = data.getDate(PerfManagerFormConstant.NCKD_ENDYEAR);
|
|
Date endYear = data.getDate(PerfManagerFormConstant.NCKD_ENDYEAR);
|
|
|
String description = data.getString(FormConstant.DESCRIPTION_KEY);
|
|
String description = data.getString(FormConstant.DESCRIPTION_KEY);
|
|
|
DynamicObjectCollection perfManagerEntry = data.getDynamicObjectCollection(PerfManagerFormConstant.NCKD_PERFMANAGERENTRY);
|
|
DynamicObjectCollection perfManagerEntry = data.getDynamicObjectCollection(PerfManagerFormConstant.NCKD_PERFMANAGERENTRY);
|
|
|
- PersonPerfInfo personPerfInfo = new PersonPerfInfo(person, beginYear, endYear, description, dataEntityIndex, perfManagerEntry);
|
|
|
|
|
- if(id > 0){
|
|
|
|
|
- personPerfInfo.setId(id);
|
|
|
|
|
|
|
+ Long personId = person.getLong(FormConstant.ID_KEY);
|
|
|
|
|
+ if (beginYear != null) {
|
|
|
|
|
+ personBeginYearMap.put(personId, beginYear);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (id > 0) {
|
|
|
ids.add(id);
|
|
ids.add(id);
|
|
|
}
|
|
}
|
|
|
- personPerfInfos.add(personPerfInfo);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ PersonPerfInfo perfInfo = new PersonPerfInfo(person, null,
|
|
|
|
|
+ data.getDate(PerfManagerFormConstant.NCKD_BEGINYEAR),
|
|
|
|
|
+ data.getDate(PerfManagerFormConstant.NCKD_ENDYEAR),
|
|
|
|
|
+ data.getString(FormConstant.DESCRIPTION_KEY),
|
|
|
|
|
+ rowDataEntity.getDataEntityIndex());
|
|
|
|
|
+
|
|
|
|
|
+ currentBatchData.computeIfAbsent(personId, k -> new ArrayList<>()).add(perfInfo);
|
|
|
|
|
+ }
|
|
|
|
|
+ if(!isUpdate) {
|
|
|
|
|
+ if (!dataMigration) {
|
|
|
|
|
+ if (!isCycleGenerate) {
|
|
|
|
|
+ //检查同一批次内同一人员的周期重叠
|
|
|
|
|
+ for (Map.Entry<Long, List<PersonPerfInfo>> entry : currentBatchData.entrySet()) {
|
|
|
|
|
+ List<PersonPerfInfo> personPerfList = entry.getValue();
|
|
|
|
|
+ if (personPerfList.size() > 1) {
|
|
|
|
|
+ // 对同一人员的多个周期进行相互比较
|
|
|
|
|
+ for (int i = 0; i < personPerfList.size(); i++) {
|
|
|
|
|
+ PersonPerfInfo info1 = personPerfList.get(i);
|
|
|
|
|
+ for (int j = i + 1; j < personPerfList.size(); j++) {
|
|
|
|
|
+ PersonPerfInfo info2 = personPerfList.get(j);
|
|
|
|
|
+ String personName = info2.getPerson().getString(FormConstant.NAME_KEY);
|
|
|
|
|
+
|
|
|
|
|
+ // 检查开始年份是否相同
|
|
|
|
|
+ if (isSameYear(info1.getBeginYear(), info2.getBeginYear())) {
|
|
|
|
|
+ addFatalErrorMessage(getDataEntities()[info1.getDataEntityIndex()],
|
|
|
|
|
+ StrFormatter.format("同批次数据中,人员【{}】存在相同的周期开始年份:{}",
|
|
|
|
|
+ personName, info1.getBeginYear().getYear()));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 只有开始年份不相同时才检查重叠
|
|
|
|
|
+ // 检查周期是否重叠
|
|
|
|
|
+ String overlapInfo = getCycleOverlapInfo(
|
|
|
|
|
+ info1.getBeginYear(), info1.getEndYear(), null,
|
|
|
|
|
+ info2.getBeginYear(), info2.getEndYear(), null);
|
|
|
|
|
+
|
|
|
|
|
+ if (StringUtils.isNotBlank(overlapInfo)) {
|
|
|
|
|
+ addFatalErrorMessage(getDataEntities()[info1.getDataEntityIndex()],
|
|
|
|
|
+ StrFormatter.format("同批次数据中,人员【{}】存在重叠周期:{}", personName, overlapInfo));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
QueryFieldBuilder queryFieldBuilder = QueryFieldBuilder.create()
|
|
QueryFieldBuilder queryFieldBuilder = QueryFieldBuilder.create()
|
|
|
.addIdNumberName(FormConstant.NCKD_PERSON)
|
|
.addIdNumberName(FormConstant.NCKD_PERSON)
|
|
|
.add(PerfManagerFormConstant.NCKD_BEGINYEAR)
|
|
.add(PerfManagerFormConstant.NCKD_BEGINYEAR)
|
|
|
- .add(PerfManagerFormConstant.NCKD_ENDYEAR);
|
|
|
|
|
- personIds = personPerfInfos.stream()
|
|
|
|
|
- .map(personPerfInfo -> personPerfInfo.getPerson().getLong(FormConstant.ID_KEY))
|
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
|
- QFilter filter = new QFilter(FormConstant.NCKD_PERSON, QCP.in, personIds)
|
|
|
|
|
- .and(PerfManagerFormConstant.NCKD_THESTATUS,QCP.equals,"1");
|
|
|
|
|
- if(!ids.isEmpty()){
|
|
|
|
|
|
|
+ .add(PerfManagerFormConstant.NCKD_ENDYEAR)
|
|
|
|
|
+ .add(PerfManagerFormConstant.NCKD_ACTENDYEAR);
|
|
|
|
|
+ QFilter filter = new QFilter(FormConstant.NCKD_PERSON, QCP.in, personBeginYearMap.keySet());
|
|
|
|
|
+ if(!ids.isEmpty()) {
|
|
|
filter = filter.and(new QFilter(FormConstant.ID_KEY, QCP.not_in, ids));
|
|
filter = filter.and(new QFilter(FormConstant.ID_KEY, QCP.not_in, ids));
|
|
|
}
|
|
}
|
|
|
|
|
+ //根据人员查询出当前自己之外的其他考核周期
|
|
|
DynamicObjectCollection query = QueryServiceHelper.query(PerfManagerFormConstant.PERFMANAGER_ENTITYID, queryFieldBuilder.buildSelect(), new QFilter[]{filter});
|
|
DynamicObjectCollection query = QueryServiceHelper.query(PerfManagerFormConstant.PERFMANAGER_ENTITYID, queryFieldBuilder.buildSelect(), new QFilter[]{filter});
|
|
|
-
|
|
|
|
|
- //开始校验 - 优化后的代码
|
|
|
|
|
|
|
+ //按人员分组
|
|
|
Map<Long, List<DynamicObject>> groupedQueryResults = query.stream()
|
|
Map<Long, List<DynamicObject>> groupedQueryResults = query.stream()
|
|
|
.collect(Collectors.groupingBy(
|
|
.collect(Collectors.groupingBy(
|
|
|
dynamicObject -> dynamicObject.getLong(String.join(".", FormConstant.NCKD_PERSON, FormConstant.ID_KEY))
|
|
dynamicObject -> dynamicObject.getLong(String.join(".", FormConstant.NCKD_PERSON, FormConstant.ID_KEY))
|
|
|
));
|
|
));
|
|
|
-
|
|
|
|
|
- for (PersonPerfInfo personPerfInfo : personPerfInfos) {
|
|
|
|
|
-
|
|
|
|
|
- long personId = personPerfInfo.getPerson().getLong(FormConstant.ID_KEY);
|
|
|
|
|
- LocalDateTime beginYear = personPerfInfo.getBeginYear();
|
|
|
|
|
- LocalDateTime endYear = personPerfInfo.getEndYear();
|
|
|
|
|
|
|
+ for (ExtendedDataEntity rowDataEntity : getDataEntities()) {
|
|
|
|
|
+ DynamicObject data = rowDataEntity.getDataEntity();
|
|
|
|
|
+ DynamicObject person = data.getDynamicObject(FormConstant.NCKD_PERSON);
|
|
|
|
|
+ person = person == null ? data.getDynamicObject(FormConstant.NCKD_EMPPOSORGREL).getDynamicObject(FormConstant.EMPLOYEE_KEY) : person;
|
|
|
|
|
+ long personId = person.getLong(FormConstant.ID_KEY);
|
|
|
|
|
+ String personName = person.getString(FormConstant.NAME_KEY);
|
|
|
|
|
+ LocalDateTime beginYear = ConvertUtil.toLocalDateTime(data.getDate(PerfManagerFormConstant.NCKD_BEGINYEAR));
|
|
|
|
|
+ LocalDateTime endYear = ConvertUtil.toLocalDateTime(data.getDate(PerfManagerFormConstant.NCKD_ENDYEAR));
|
|
|
|
|
|
|
|
// 判断beginYear和endYear是不是间隔3年,例如:开始2025年,结束必须为2027年
|
|
// 判断beginYear和endYear是不是间隔3年,例如:开始2025年,结束必须为2027年
|
|
|
if (beginYear != null && endYear != null) {
|
|
if (beginYear != null && endYear != null) {
|
|
|
int beginYearValue = beginYear.getYear();
|
|
int beginYearValue = beginYear.getYear();
|
|
|
int endYearValue = endYear.getYear();
|
|
int endYearValue = endYear.getYear();
|
|
|
if (endYearValue - beginYearValue != 2) {
|
|
if (endYearValue - beginYearValue != 2) {
|
|
|
- addFatalErrorMessage(getDataEntities()[personPerfInfo.getDataEntityIndex()],
|
|
|
|
|
|
|
+ addFatalErrorMessage(rowDataEntity,
|
|
|
StrFormatter.format("周期开始年份【{}】与结束年份【{}】必须间隔3年,请检查!",
|
|
StrFormatter.format("周期开始年份【{}】与结束年份【{}】必须间隔3年,请检查!",
|
|
|
beginYearValue, endYearValue));
|
|
beginYearValue, endYearValue));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
//校验是否存在相同周期开始年的记录 begin
|
|
//校验是否存在相同周期开始年的记录 begin
|
|
|
List<DynamicObject> personRecords = groupedQueryResults.getOrDefault(personId, Collections.emptyList());
|
|
List<DynamicObject> personRecords = groupedQueryResults.getOrDefault(personId, Collections.emptyList());
|
|
|
for (DynamicObject dynamicObject : personRecords) {
|
|
for (DynamicObject dynamicObject : personRecords) {
|
|
|
LocalDateTime dbBeginYear = DateUtil.toLocalDateTime(dynamicObject.getDate(PerfManagerFormConstant.NCKD_BEGINYEAR));
|
|
LocalDateTime dbBeginYear = DateUtil.toLocalDateTime(dynamicObject.getDate(PerfManagerFormConstant.NCKD_BEGINYEAR));
|
|
|
- //判断beginYear和dbBeginYear的年份是否相同
|
|
|
|
|
- if (isSameYear(beginYear, dbBeginYear)) {
|
|
|
|
|
- addFatalErrorMessage(getDataEntities()[personPerfInfo.getDataEntityIndex()],
|
|
|
|
|
- StrFormatter.format("人员【{}】已经存在周期开始年份【{}】的周期,无需进行创建。",
|
|
|
|
|
- personPerfInfo.getPerson().getString(FormConstant.NAME_KEY),
|
|
|
|
|
- beginYear.getYear()));
|
|
|
|
|
|
|
+ LocalDateTime dbEndYear = DateUtil.toLocalDateTime(dynamicObject.getDate(PerfManagerFormConstant.NCKD_ENDYEAR));
|
|
|
|
|
+ Date actEndYear = dynamicObject.getDate(PerfManagerFormConstant.NCKD_ACTENDYEAR);
|
|
|
|
|
+ LocalDateTime dbActEndYear = actEndYear != null ? DateUtil.toLocalDateTime(actEndYear) : null;
|
|
|
|
|
+ if(!isUpdate) {
|
|
|
|
|
+ if (!dataMigration) {
|
|
|
|
|
+ if (!isCycleGenerate) {
|
|
|
|
|
+ // 判断周期是否重叠并获取重叠信息,已结束周期使用实际结束时间
|
|
|
|
|
+ String overlapInfo = getCycleOverlapInfo(beginYear, endYear, null, dbBeginYear, dbEndYear, dbActEndYear);
|
|
|
|
|
+ if (StringUtils.isNotBlank(overlapInfo)) {
|
|
|
|
|
+ addFatalErrorMessage(rowDataEntity,
|
|
|
|
|
+ StrFormatter.format("人员【{}】的考核周期与已有周期在{}重叠,请检查!",
|
|
|
|
|
+ personName, overlapInfo));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //判断beginYear和dbBeginYear的年份是否相同
|
|
|
|
|
+ if (isSameYear(beginYear, dbBeginYear)) {
|
|
|
|
|
+ addFatalErrorMessage(rowDataEntity,
|
|
|
|
|
+ StrFormatter.format("人员【{}】已经存在周期开始年份【{}】的周期,无需进行创建。",
|
|
|
|
|
+ personName,
|
|
|
|
|
+ beginYear.getYear()));
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ //当前周期必须大于之前周期的开始时间
|
|
|
|
|
+ /*if (beginYear != null && beginYear.isBefore(dbBeginYear)) {
|
|
|
|
|
+ addFatalErrorMessage(rowDataEntity,
|
|
|
|
|
+ StrFormatter.format("人员【{}】当前周期开始时间【{}】必须大于之前周期开始时间【{}】。",
|
|
|
|
|
+ personName,
|
|
|
|
|
+ beginYear.getYear(),
|
|
|
|
|
+ dbBeginYear.getYear()));
|
|
|
|
|
+ }*/
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
//校验是否存在相同周期开始年的记录 end
|
|
//校验是否存在相同周期开始年的记录 end
|
|
|
- DynamicObjectCollection entrys = personPerfInfo.getEntrys();
|
|
|
|
|
|
|
+ DynamicObjectCollection entrys = data.getDynamicObjectCollection(PerfManagerFormConstant.NCKD_PERFMANAGERENTRY);
|
|
|
if(entrys != null) {
|
|
if(entrys != null) {
|
|
|
List<Date> dateList = entrys.stream().map(entry -> entry.getDate(PerfManagerFormConstant.NCKD_APPRAISALYEAR)).collect(Collectors.toList());
|
|
List<Date> dateList = entrys.stream().map(entry -> entry.getDate(PerfManagerFormConstant.NCKD_APPRAISALYEAR)).collect(Collectors.toList());
|
|
|
if (beginYear != null && endYear != null) {
|
|
if (beginYear != null && endYear != null) {
|
|
@@ -151,7 +220,7 @@ public class PerfManagerSaveOpPlugin extends AbstractOperationServicePlugIn impl
|
|
|
|
|
|
|
|
if (!outOfRangeYears.isEmpty()) {
|
|
if (!outOfRangeYears.isEmpty()) {
|
|
|
String outOfRangeYearsStr = String.join(",", outOfRangeYears);
|
|
String outOfRangeYearsStr = String.join(",", outOfRangeYears);
|
|
|
- addFatalErrorMessage(getDataEntities()[personPerfInfo.getDataEntityIndex()],
|
|
|
|
|
|
|
+ addFatalErrorMessage(rowDataEntity,
|
|
|
StrFormatter.format("考评年份【{}】不在周期范围内,请检查!", outOfRangeYearsStr));
|
|
StrFormatter.format("考评年份【{}】不在周期范围内,请检查!", outOfRangeYearsStr));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -159,11 +228,13 @@ public class PerfManagerSaveOpPlugin extends AbstractOperationServicePlugIn impl
|
|
|
List<String> duplicateYears = getDuplicateYears(dateList);
|
|
List<String> duplicateYears = getDuplicateYears(dateList);
|
|
|
if (!duplicateYears.isEmpty()) {
|
|
if (!duplicateYears.isEmpty()) {
|
|
|
String duplicateYearsStr = String.join(",", duplicateYears);
|
|
String duplicateYearsStr = String.join(",", duplicateYears);
|
|
|
- addFatalErrorMessage(getDataEntities()[personPerfInfo.getDataEntityIndex()],
|
|
|
|
|
|
|
+ addFatalErrorMessage(rowDataEntity,
|
|
|
StrFormatter.format("考评结果存在重复的考核年份【{}】,请检查!", duplicateYearsStr));
|
|
StrFormatter.format("考评结果存在重复的考核年份【{}】,请检查!", duplicateYearsStr));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ //规则: 如果年度排名管理中已存在某年度的考核结果,则不允许在人员考评管理中修改该年度的考核结果。
|
|
|
|
|
+ //规则: 对于已处理的调薪情况,不允许修改或删除相关的年度考核结果。
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -173,36 +244,71 @@ public class PerfManagerSaveOpPlugin extends AbstractOperationServicePlugIn impl
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 判断两个考核周期是否重叠,并返回重叠描述
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param beginYear1 第一个周期开始年份
|
|
|
|
|
+ * @param endYear1 第一个周期结束年份
|
|
|
|
|
+ * @param actEndYear1 第一个周期实际结束年份(如果已结束)
|
|
|
|
|
+ * @param beginYear2 第二个周期开始年份
|
|
|
|
|
+ * @param endYear2 第二个周期结束年份
|
|
|
|
|
+ * @param actEndYear2 第二个周期实际结束年份(如果已结束)
|
|
|
|
|
+ * @return 如果周期重叠返回重叠描述,否则返回空字符串
|
|
|
|
|
+ */
|
|
|
|
|
+ private String getCycleOverlapInfo(LocalDateTime beginYear1, LocalDateTime endYear1, LocalDateTime actEndYear1,
|
|
|
|
|
+ LocalDateTime beginYear2, LocalDateTime endYear2, LocalDateTime actEndYear2) {
|
|
|
|
|
+ if (beginYear1 == null || endYear1 == null || beginYear2 == null || endYear2 == null) {
|
|
|
|
|
+ return "";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 如果周期已结束,使用实际结束时间,否则使用计划结束时间
|
|
|
|
|
+ LocalDateTime realEndYear1 = actEndYear1 != null ? actEndYear1 : endYear1;
|
|
|
|
|
+ LocalDateTime realEndYear2 = actEndYear2 != null ? actEndYear2 : endYear2;
|
|
|
|
|
+
|
|
|
|
|
+ // 两个区间重叠的条件是:一个区间的开始时间小于等于另一个区间的结束时间,
|
|
|
|
|
+ // 且该区间的结束时间大于等于另一个区间的开始时间
|
|
|
|
|
+ if (!beginYear1.isAfter(realEndYear2) && !realEndYear1.isBefore(beginYear2)) {
|
|
|
|
|
+ // 计算重叠区间
|
|
|
|
|
+ LocalDateTime overlapStart = beginYear1.isAfter(beginYear2) ? beginYear1 : beginYear2;
|
|
|
|
|
+ LocalDateTime overlapEnd = realEndYear1.isBefore(realEndYear2) ? realEndYear1 : realEndYear2;
|
|
|
|
|
+
|
|
|
|
|
+ if (overlapStart.equals(overlapEnd)) {
|
|
|
|
|
+ return StrFormatter.format("{}年", overlapStart.getYear());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return StrFormatter.format("{}年~{}年", overlapStart.getYear(), overlapEnd.getYear());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return "";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public void beforeExecuteOperationTransaction(BeforeOperationArgs e) {
|
|
public void beforeExecuteOperationTransaction(BeforeOperationArgs e) {
|
|
|
- //最新上一考核周期
|
|
|
|
|
- QFilter filter = null;
|
|
|
|
|
- if(!ids.isEmpty()) {
|
|
|
|
|
- filter = new QFilter(FormConstant.ID_KEY, QCP.not_in, ids);
|
|
|
|
|
|
|
+ if(!this.getOperationResult().isSuccess()){
|
|
|
|
|
+ e.setCancel(true);
|
|
|
|
|
+ return;
|
|
|
}
|
|
}
|
|
|
- List<DynamicObject> newestPerfManagerByPerson = PerfManagerHelper.getNewestPerfManagerByPersonAndBeginYear(personIds,filter);
|
|
|
|
|
- lastPerfManagerMap = newestPerfManagerByPerson.stream()
|
|
|
|
|
- .collect(Collectors.toMap(
|
|
|
|
|
- perfManager -> perfManager.getDynamicObject(FormConstant.NCKD_PERSON).getLong(FormConstant.ID_KEY),
|
|
|
|
|
- perfManager -> perfManager,
|
|
|
|
|
- (existing, replacement) -> existing
|
|
|
|
|
- ));
|
|
|
|
|
-
|
|
|
|
|
- String ignoreInteraction = this.getOption().getVariableValue(OperateOptionConst.IGNOREINTERACTION, "");
|
|
|
|
|
- if(!"true".equalsIgnoreCase(ignoreInteraction)){
|
|
|
|
|
- personIds = personPerfInfos.stream()
|
|
|
|
|
- .map(personPerfInfo -> personPerfInfo.getPerson().getLong(FormConstant.ID_KEY))
|
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
|
-
|
|
|
|
|
- StringJoiner confirMmsg = new StringJoiner(",");
|
|
|
|
|
- for (DynamicObject lastPerfManager : lastPerfManagerMap.values()) {
|
|
|
|
|
- String personName = lastPerfManager.getDynamicObject(FormConstant.NCKD_PERSON).getString(FormConstant.NAME_KEY);
|
|
|
|
|
- LocalDateTime beginYear = DateUtil.toLocalDateTime(lastPerfManager.getDate(PerfManagerFormConstant.NCKD_BEGINYEAR));
|
|
|
|
|
- LocalDateTime endYear = DateUtil.toLocalDateTime(lastPerfManager.getDate(PerfManagerFormConstant.NCKD_ENDYEAR));
|
|
|
|
|
- confirMmsg.add(StrFormatter.format("{}(周期:{}~{})", personName, beginYear.getYear(), endYear.getYear()));
|
|
|
|
|
|
|
+ String ignoreInteraction = this.getOption().getVariableValue(OperateOptionConst.IGNOREINTERACTION,StringUtils.EMPTY);
|
|
|
|
|
+ if(StringUtils.isBlank(ignoreInteraction) || !"true".equalsIgnoreCase(ignoreInteraction)) {
|
|
|
|
|
+ StringJoiner confirmMsg = new StringJoiner(",");
|
|
|
|
|
+ for (DynamicObject dataEntity : e.getDataEntities()) {
|
|
|
|
|
+ long id = dataEntity.getLong(FormConstant.ID_KEY);
|
|
|
|
|
+ Date date = dataEntity.getDate(PerfManagerFormConstant.NCKD_BEGINYEAR);
|
|
|
|
|
+ long personId = dataEntity.getDynamicObject(FormConstant.NCKD_PERSON).getLong(FormConstant.ID_KEY);
|
|
|
|
|
+ QFilter filter = null;
|
|
|
|
|
+ if (id > 0) {
|
|
|
|
|
+ filter = new QFilter(FormConstant.ID_KEY, QCP.not_in, id);
|
|
|
|
|
+ }
|
|
|
|
|
+ DynamicObject[] lastPerfManagerArray = PerfManagerHelper.getBeforeBeginYear(date, Collections.singletonList(personId), filter);
|
|
|
|
|
+ for (DynamicObject lastPerfManager : lastPerfManagerArray) {
|
|
|
|
|
+ String personName = lastPerfManager.getDynamicObject(FormConstant.NCKD_PERSON).getString(FormConstant.NAME_KEY);
|
|
|
|
|
+ LocalDateTime beginYear = DateUtil.toLocalDateTime(lastPerfManager.getDate(PerfManagerFormConstant.NCKD_BEGINYEAR));
|
|
|
|
|
+ LocalDateTime endYear = DateUtil.toLocalDateTime(lastPerfManager.getDate(PerfManagerFormConstant.NCKD_ENDYEAR));
|
|
|
|
|
+ confirmMsg.add(StrFormatter.format("{}(周期:{}~{})", personName, beginYear.getYear(), endYear.getYear()));
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- if(!lastPerfManagerMap.isEmpty()){
|
|
|
|
|
- e.cancel = !this.showInteractionMessage(confirMmsg.toString());
|
|
|
|
|
|
|
+ if (confirmMsg.length() > 0) {
|
|
|
|
|
+ e.cancel = !this.showInteractionMessage(confirmMsg.toString());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -210,10 +316,16 @@ public class PerfManagerSaveOpPlugin extends AbstractOperationServicePlugIn impl
|
|
|
@Override
|
|
@Override
|
|
|
public void beginOperationTransaction(BeginOperationTransactionArgs e) {
|
|
public void beginOperationTransaction(BeginOperationTransactionArgs e) {
|
|
|
//事务开始之后将其他考核周期设置为非最新
|
|
//事务开始之后将其他考核周期设置为非最新
|
|
|
- PerfManagerHelper.markAsNotCurrentNewest(personIds.toArray(new Long[0]));
|
|
|
|
|
|
|
+ PerfManagerHelper.markAsNotCurrentNewest(personBeginYearMap.keySet().toArray(new Long[0]));
|
|
|
|
|
|
|
|
|
|
+ Boolean isCycleGenerate = ConvertUtil.toBoolean(this.getOption().getVariableValue("cyclegenerate",StringUtils.EMPTY),Boolean.FALSE);
|
|
|
|
|
+ Boolean isUpdate = ConvertUtil.toBoolean(this.getOption().getVariableValue("isUpdate",StringUtils.EMPTY),Boolean.FALSE);
|
|
|
|
|
+ List<DynamicObject> updatePerManager = new ArrayList<>();
|
|
|
for (DynamicObject dataEntity : e.getDataEntities()) {
|
|
for (DynamicObject dataEntity : e.getDataEntities()) {
|
|
|
|
|
+ long id = dataEntity.getLong(FormConstant.ID_KEY);
|
|
|
DynamicObject person = dataEntity.getDynamicObject(FormConstant.NCKD_PERSON);
|
|
DynamicObject person = dataEntity.getDynamicObject(FormConstant.NCKD_PERSON);
|
|
|
|
|
+ person = person == null ? dataEntity.getDynamicObject(FormConstant.NCKD_EMPPOSORGREL).getDynamicObject(FormConstant.EMPLOYEE_KEY) : person;
|
|
|
|
|
+ dataEntity.set(FormConstant.NCKD_PERSON, person);
|
|
|
LocalDateTime beginYear = DateUtil.toLocalDateTime(dataEntity.getDate(PerfManagerFormConstant.NCKD_BEGINYEAR));
|
|
LocalDateTime beginYear = DateUtil.toLocalDateTime(dataEntity.getDate(PerfManagerFormConstant.NCKD_BEGINYEAR));
|
|
|
LocalDateTime endYear = DateUtil.toLocalDateTime(dataEntity.getDate(PerfManagerFormConstant.NCKD_ENDYEAR));
|
|
LocalDateTime endYear = DateUtil.toLocalDateTime(dataEntity.getDate(PerfManagerFormConstant.NCKD_ENDYEAR));
|
|
|
long personId = person.getLong(FormConstant.ID_KEY);
|
|
long personId = person.getLong(FormConstant.ID_KEY);
|
|
@@ -224,25 +336,259 @@ public class PerfManagerSaveOpPlugin extends AbstractOperationServicePlugIn impl
|
|
|
if(StringUtils.isBlank(name)){
|
|
if(StringUtils.isBlank(name)){
|
|
|
dataEntity.set(FormConstant.NAME_KEY, StrFormatter.format("【{}】{}~{}的考核周期",personName,beginYear.getYear(),endYear.getYear()));
|
|
dataEntity.set(FormConstant.NAME_KEY, StrFormatter.format("【{}】{}~{}的考核周期",personName,beginYear.getYear(),endYear.getYear()));
|
|
|
}
|
|
}
|
|
|
- //上一周期标记为“已结束”并设置“实际结束时间” begin
|
|
|
|
|
- DynamicObject lastPerfManager = lastPerfManagerMap.get(personId);
|
|
|
|
|
- if(lastPerfManager != null && "1".equalsIgnoreCase(lastPerfManager.getString(PerfManagerFormConstant.NCKD_THESTATUS))) {
|
|
|
|
|
- lastPerfManager.set(PerfManagerFormConstant.NCKD_THESTATUS, "3");
|
|
|
|
|
- LocalDateTime localDateTime = DateUtil.minusYears(beginYear, 1);
|
|
|
|
|
- lastPerfManager.set(PerfManagerFormConstant.NCKD_ACTENDYEAR, DateUtil.toDate(localDateTime));
|
|
|
|
|
- dataEntity.set(PerfManagerFormConstant.NCKD_LASTPERFMANAGER, lastPerfManagerMap.get(personId));
|
|
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /*DynamicObject lastPerfManager = lastPerfManagerMap.get(personId);
|
|
|
|
|
+ if(lastPerfManager != null) {
|
|
|
|
|
+ LocalDateTime date = DateUtil.toLocalDateTime(lastPerfManager.getDate(PerfManagerFormConstant.NCKD_BEGINYEAR));
|
|
|
|
|
+ if("1".equalsIgnoreCase(lastPerfManager.getString(PerfManagerFormConstant.NCKD_THESTATUS)) && date.getYear() >= beginYear.getYear()) {
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ LocalDateTime lastBeginYear = DateUtil.toLocalDateTime(lastPerfManager.getDate(PerfManagerFormConstant.NCKD_BEGINYEAR));
|
|
|
|
|
+ LocalDateTime lastEndYear = DateUtil.toLocalDateTime(lastPerfManager.getDate(PerfManagerFormConstant.NCKD_ENDYEAR));
|
|
|
|
|
+ if(!Objects.equals(lastBeginYear, beginYear) || !Objects.equals(lastEndYear, endYear)) {
|
|
|
|
|
+ //当周期范围发生变化,需要保障数据连续性:若新旧考评周期存在重叠年份,且该年份在旧周期中已存在来源于【年度绩效排名】的考核结果,则新周期将自动继承该结果。
|
|
|
|
|
+ DynamicObjectCollection lastPerfManagerEntrys = lastPerfManager.getDynamicObjectCollection(PerfManagerFormConstant.NCKD_PERFMANAGERENTRY);
|
|
|
|
|
+ DynamicObjectCollection perfManagerEntrys = dataEntity.getDynamicObjectCollection(PerfManagerFormConstant.NCKD_PERFMANAGERENTRY);
|
|
|
|
|
+ for (DynamicObject lastPerfManagerEntry : lastPerfManagerEntrys) {
|
|
|
|
|
+ Date lastAppraisalYear = lastPerfManagerEntry.getDate(PerfManagerFormConstant.NCKD_APPRAISALYEAR);
|
|
|
|
|
+ DynamicObject appraisalResult = lastPerfManagerEntry.getDynamicObject(PerfManagerFormConstant.NCKD_APPRAISALRESULT);
|
|
|
|
|
+ if (lastAppraisalYear != null && appraisalResult != null) {
|
|
|
|
|
+ boolean isAllRankSource = lastPerfManagerEntry.getBoolean(PerfManagerFormConstant.NCKD_ISALLRANKSOURCE);
|
|
|
|
|
+ if (isAllRankSource) {
|
|
|
|
|
+ LocalDateTime lastAppraisalYearLocalDateTime = DateUtil.toLocalDateTime(lastAppraisalYear);
|
|
|
|
|
+ //判断appraisalYearLocalDateTime是不是在beginYear和endYear之间
|
|
|
|
|
+ if (DateUtil.isInRange(lastAppraisalYearLocalDateTime, beginYear, endYear)) {
|
|
|
|
|
+ boolean isExist = false;
|
|
|
|
|
+ for (DynamicObject perfManager : perfManagerEntrys) {
|
|
|
|
|
+ Date appraisalYear = perfManager.getDate(PerfManagerFormConstant.NCKD_APPRAISALYEAR);
|
|
|
|
|
+ if(appraisalYear != null){
|
|
|
|
|
+ //如果分录存在相同年份则更新
|
|
|
|
|
+ LocalDateTime appraisalYearLocalDateTime = DateUtil.toLocalDateTime(appraisalYear);
|
|
|
|
|
+ if(appraisalYearLocalDateTime.getYear() == lastAppraisalYearLocalDateTime.getYear()){
|
|
|
|
|
+ perfManager.set(PerfManagerFormConstant.NCKD_APPRAISALRESULT, appraisalResult);
|
|
|
|
|
+ isExist = true;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if(!isExist) {
|
|
|
|
|
+ //分录不存在当前年份,则添加
|
|
|
|
|
+ DynamicObject dynamicObject = perfManagerEntrys.addNew();
|
|
|
|
|
+ dynamicObject.set(PerfManagerFormConstant.NCKD_APPRAISALYEAR, lastAppraisalYear);
|
|
|
|
|
+ dynamicObject.set(PerfManagerFormConstant.NCKD_APPRAISALRESULT, appraisalResult);
|
|
|
|
|
+ dynamicObject.set(PerfManagerFormConstant.NCKD_ISALLRANKSOURCE, true);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }*/
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ //分录考核结果写入到表头 begin
|
|
|
|
|
+ dataEntity.set(PerfManagerFormConstant.NCKD_FIRSTYEARRESULT, null);
|
|
|
|
|
+ dataEntity.set(PerfManagerFormConstant.NCKD_SECONDYEARRESULT, null);
|
|
|
|
|
+ dataEntity.set(PerfManagerFormConstant.NCKD_THIRDYEARRESULT, null);
|
|
|
|
|
+ DynamicObjectCollection entrys = dataEntity.getDynamicObjectCollection(PerfManagerFormConstant.NCKD_PERFMANAGERENTRY);
|
|
|
|
|
+ for (DynamicObject entry : entrys) {
|
|
|
|
|
+ boolean isAllRankSource = entry.getBoolean(PerfManagerFormConstant.NCKD_ISALLRANKSOURCE);
|
|
|
|
|
+ Date appraisalYear = entry.getDate(PerfManagerFormConstant.NCKD_APPRAISALYEAR);
|
|
|
|
|
+ DynamicObject appraisalResult = entry.getDynamicObject(PerfManagerFormConstant.NCKD_APPRAISALRESULT);
|
|
|
|
|
+
|
|
|
|
|
+ if (appraisalYear != null && appraisalResult != null) {
|
|
|
|
|
+ LocalDateTime appraisalLocalDate = DateUtil.toLocalDateTime(appraisalYear);
|
|
|
|
|
+ LocalDateTime beginLocalDate = beginYear;
|
|
|
|
|
+
|
|
|
|
|
+ // 计算是第几年(分录中的年份-(周期开始时间 + 1))
|
|
|
|
|
+ long yearsDiff = appraisalLocalDate.getYear() - beginLocalDate.getYear() + 1;
|
|
|
|
|
+ // 根据年份差异设置表头对应的考核结果字段
|
|
|
|
|
+ switch ((int) yearsDiff) {
|
|
|
|
|
+ case 1:
|
|
|
|
|
+ dataEntity.set(PerfManagerFormConstant.NCKD_FIRSTYEARRESULT, appraisalResult);
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 2:
|
|
|
|
|
+ dataEntity.set(PerfManagerFormConstant.NCKD_SECONDYEARRESULT, appraisalResult);
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 3:
|
|
|
|
|
+ dataEntity.set(PerfManagerFormConstant.NCKD_THIRDYEARRESULT, appraisalResult);
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- //上一周期标记为“已结束”并设置“实际结束时间” end
|
|
|
|
|
|
|
+ //分录考核结果写入到表头 end
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 查找给定日期之后的第一个考核周期
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param allPerfManagerList 该人员的所有考核周期列表
|
|
|
|
|
+ * @param currentDate 当前周期的开始日期
|
|
|
|
|
+ * @return 下一个考核周期,如果不存在则返回null
|
|
|
|
|
+ */
|
|
|
|
|
+ private DynamicObject findNextCycle(List<DynamicObject> allPerfManagerList, Date currentDate) {
|
|
|
|
|
+ if (allPerfManagerList == null || allPerfManagerList.isEmpty() || currentDate == null) {
|
|
|
|
|
+ return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ LocalDateTime currentLocalDate = DateUtil.toLocalDateTime(currentDate);
|
|
|
|
|
|
|
|
- DynamicObject[] lastPerfManagerArray = lastPerfManagerMap.values().toArray(new DynamicObject[0]);
|
|
|
|
|
- SaveServiceHelper.update(lastPerfManagerArray);
|
|
|
|
|
|
|
+ return allPerfManagerList.stream()
|
|
|
|
|
+ .filter(Objects::nonNull)
|
|
|
|
|
+ .filter(perfManager -> {
|
|
|
|
|
+ Date beginYear = perfManager.getDate(PerfManagerFormConstant.NCKD_BEGINYEAR);
|
|
|
|
|
+ if (beginYear != null) {
|
|
|
|
|
+ LocalDateTime beginYearLocal = DateUtil.toLocalDateTime(beginYear);
|
|
|
|
|
+ return beginYearLocal.isAfter(currentLocalDate);
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
|
|
+ })
|
|
|
|
|
+ .min((perf1, perf2) -> {
|
|
|
|
|
+ LocalDateTime begin1 = DateUtil.toLocalDateTime(perf1.getDate(PerfManagerFormConstant.NCKD_BEGINYEAR));
|
|
|
|
|
+ LocalDateTime begin2 = DateUtil.toLocalDateTime(perf2.getDate(PerfManagerFormConstant.NCKD_BEGINYEAR));
|
|
|
|
|
+ return begin1.compareTo(begin2);
|
|
|
|
|
+ })
|
|
|
|
|
+ .orElse(null);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 查找给定日期之前的最后一个考核周期
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param allPerfManagerList 该人员的所有考核周期列表
|
|
|
|
|
+ * @param currentDate 当前周期的开始日期
|
|
|
|
|
+ * @return 上一个考核周期,如果不存在则返回null
|
|
|
|
|
+ */
|
|
|
|
|
+ private DynamicObject findPreviousCycle(List<DynamicObject> allPerfManagerList, Date currentDate) {
|
|
|
|
|
+ if (allPerfManagerList == null || allPerfManagerList.isEmpty() || currentDate == null) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ LocalDateTime currentLocalDate = DateUtil.toLocalDateTime(currentDate);
|
|
|
|
|
+
|
|
|
|
|
+ return allPerfManagerList.stream()
|
|
|
|
|
+ .filter(Objects::nonNull)
|
|
|
|
|
+ .filter(perfManager -> {
|
|
|
|
|
+ Date beginYear = perfManager.getDate(PerfManagerFormConstant.NCKD_BEGINYEAR);
|
|
|
|
|
+ if (beginYear != null) {
|
|
|
|
|
+ LocalDateTime beginYearLocal = DateUtil.toLocalDateTime(beginYear);
|
|
|
|
|
+ return beginYearLocal.isBefore(currentLocalDate);
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
|
|
+ })
|
|
|
|
|
+ .max((perf1, perf2) -> {
|
|
|
|
|
+ LocalDateTime begin1 = DateUtil.toLocalDateTime(perf1.getDate(PerfManagerFormConstant.NCKD_BEGINYEAR));
|
|
|
|
|
+ LocalDateTime begin2 = DateUtil.toLocalDateTime(perf2.getDate(PerfManagerFormConstant.NCKD_BEGINYEAR));
|
|
|
|
|
+ return begin1.compareTo(begin2);
|
|
|
|
|
+ })
|
|
|
|
|
+ .orElse(null);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public void endOperationTransaction(EndOperationTransactionArgs e) {
|
|
public void endOperationTransaction(EndOperationTransactionArgs e) {
|
|
|
- PerfManagerHelper.markAsCurrentNewest(personIds,null);
|
|
|
|
|
|
|
+ PerfManagerHelper.markAsCurrentNewest(personBeginYearMap.keySet(),null);
|
|
|
|
|
+
|
|
|
|
|
+ //上一周期标记为“已结束”并设置“实际结束时间” begin
|
|
|
|
|
+ Set<Long> personIds = new HashSet<>();
|
|
|
|
|
+ for (DynamicObject dataEntity : e.getDataEntities()) {
|
|
|
|
|
+ DynamicObject person = dataEntity.getDynamicObject(FormConstant.NCKD_PERSON);
|
|
|
|
|
+ person = person == null ? dataEntity.getDynamicObject(FormConstant.NCKD_EMPPOSORGREL).getDynamicObject(FormConstant.EMPLOYEE_KEY) : person;
|
|
|
|
|
+ long personId = person.getLong(FormConstant.ID_KEY);
|
|
|
|
|
+ personIds.add(personId);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ Boolean isCycleGenerate = ConvertUtil.toBoolean(this.getOption().getVariableValue("cyclegenerate",StringUtils.EMPTY),Boolean.FALSE);
|
|
|
|
|
+ Boolean isUpdate = ConvertUtil.toBoolean(this.getOption().getVariableValue("isUpdate",StringUtils.EMPTY),Boolean.FALSE);
|
|
|
|
|
+ DynamicObject[] beforeBeginYearList = null;
|
|
|
|
|
+ if(!isUpdate){
|
|
|
|
|
+ beforeBeginYearList = PerfManagerHelper.getByPersonId(personIds, null);
|
|
|
|
|
+ }
|
|
|
|
|
+ List<DynamicObject> updatePerManager = new ArrayList<>();
|
|
|
|
|
+ List<DynamicObject> updateDataEntity = new ArrayList<>();
|
|
|
|
|
+ for (DynamicObject dataEntity : e.getDataEntities()) {
|
|
|
|
|
+ long id = dataEntity.getLong(FormConstant.ID_KEY);
|
|
|
|
|
+ DynamicObject person = dataEntity.getDynamicObject(FormConstant.NCKD_PERSON);
|
|
|
|
|
+ person = person == null ? dataEntity.getDynamicObject(FormConstant.NCKD_EMPPOSORGREL).getDynamicObject(FormConstant.EMPLOYEE_KEY) : person;
|
|
|
|
|
+ dataEntity.set(FormConstant.NCKD_PERSON, person);
|
|
|
|
|
+ LocalDateTime beginYear = DateUtil.toLocalDateTime(dataEntity.getDate(PerfManagerFormConstant.NCKD_BEGINYEAR));
|
|
|
|
|
+ LocalDateTime endYear = DateUtil.toLocalDateTime(dataEntity.getDate(PerfManagerFormConstant.NCKD_ENDYEAR));
|
|
|
|
|
+ long personId = person.getLong(FormConstant.ID_KEY);
|
|
|
|
|
+
|
|
|
|
|
+ if(!isUpdate) {
|
|
|
|
|
+ //找出当前周期前还未结束的考核周期
|
|
|
|
|
+ QFilter filter = null;
|
|
|
|
|
+ if (id > 0) {
|
|
|
|
|
+ filter = new QFilter(FormConstant.ID_KEY, QCP.not_in, id);
|
|
|
|
|
+ }
|
|
|
|
|
+// DynamicObject[] beforeBeginYear = PerfManagerHelper.getBeforeBeginYear(DateUtil.toDate(beginYear), Collections.singletonList(personId), filter);
|
|
|
|
|
+ List<DynamicObject> beforeBeginYear = Arrays.stream(beforeBeginYearList)
|
|
|
|
|
+ .filter(obj -> {
|
|
|
|
|
+ Date dbBeginYear = obj.getDate(PerfManagerFormConstant.NCKD_BEGINYEAR);
|
|
|
|
|
+ Long dbPersonId = obj.getDynamicObject(FormConstant.NCKD_PERSON).getLong(FormConstant.ID_KEY);
|
|
|
|
|
+ Long dbId = obj.getLong(FormConstant.ID_KEY);
|
|
|
|
|
+ String theStatus = obj.getString(PerfManagerFormConstant.NCKD_THESTATUS);
|
|
|
|
|
+ return dbBeginYear != null && dbBeginYear.compareTo(DateUtil.toDate(beginYear)) <= 0 && dbPersonId.equals(personId) && !dbId.equals(id) && theStatus.equalsIgnoreCase(EnableEnum.YES.getCode());
|
|
|
|
|
+ })
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+ if (!beforeBeginYear.isEmpty()) {
|
|
|
|
|
+// DynamicObject[] allPerfManagerArray = PerfManagerHelper.getByPersonId(Collections.singletonList(personId), filter);
|
|
|
|
|
+ List<DynamicObject> allPerfManagerList = Arrays.stream(beforeBeginYearList)
|
|
|
|
|
+ .filter(obj -> {
|
|
|
|
|
+ Long dbPersonId = obj.getDynamicObject(FormConstant.NCKD_PERSON).getLong(FormConstant.ID_KEY);
|
|
|
|
|
+ Long dbId = obj.getLong(FormConstant.ID_KEY);
|
|
|
|
|
+ return dbPersonId.equals(personId) && !dbId.equals(id);
|
|
|
|
|
+ })
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+ allPerfManagerList.add(dataEntity);
|
|
|
|
|
+ for (DynamicObject lastPerfManager : beforeBeginYear) {
|
|
|
|
|
+ lastPerfManager.set(PerfManagerFormConstant.NCKD_THESTATUS, "3");
|
|
|
|
|
+ //找到当前周期的下一周期
|
|
|
|
|
+ Date currentBeginYear = lastPerfManager.getDate(PerfManagerFormConstant.NCKD_BEGINYEAR);
|
|
|
|
|
+ Date currentEndYear = lastPerfManager.getDate(PerfManagerFormConstant.NCKD_ENDYEAR);
|
|
|
|
|
+
|
|
|
|
|
+ DynamicObject nextCycle = findNextCycle(allPerfManagerList, currentBeginYear);
|
|
|
|
|
+ if (nextCycle != null) {
|
|
|
|
|
+ // 获取下一周期的开始年份
|
|
|
|
|
+ Date nextBeginYear = nextCycle.getDate(PerfManagerFormConstant.NCKD_BEGINYEAR);
|
|
|
|
|
+ LocalDateTime nextBeginLocalDateTime = DateUtil.toLocalDateTime(nextBeginYear);
|
|
|
|
|
+ // 计算预期的实际结束年份:下一周期开始时间-1年
|
|
|
|
|
+ LocalDateTime expectedActEndYear = DateUtil.minusYears(nextBeginLocalDateTime, 1);
|
|
|
|
|
+ LocalDateTime currentEndLocalDateTime = DateUtil.toLocalDateTime(currentEndYear);
|
|
|
|
|
+ // 如果预期结束时间大于等于当前周期的结束时间,说明中间有断层
|
|
|
|
|
+ // 则实际结束时间设置为当前周期的结束时间
|
|
|
|
|
+ // 否则设置为预期的实际结束时间(下一周期开始时间-1年)
|
|
|
|
|
+ LocalDateTime actEndYear = expectedActEndYear.isAfter(currentEndLocalDateTime) ?
|
|
|
|
|
+ currentEndLocalDateTime : expectedActEndYear;
|
|
|
|
|
+ lastPerfManager.set(PerfManagerFormConstant.NCKD_ACTENDYEAR, DateUtil.toDate(actEndYear));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 如果没有找到下一周期,则实际结束时间设置为当前周期的结束时间
|
|
|
|
|
+ lastPerfManager.set(PerfManagerFormConstant.NCKD_ACTENDYEAR, currentEndYear);
|
|
|
|
|
+ }
|
|
|
|
|
+ String str = isCycleGenerate ? "周期生成" : "手动/导入新增周期";
|
|
|
|
|
+ lastPerfManager.set(PerfManagerFormConstant.NCKD_WHYEND, StrFormatter.format("{}({}~{}),系统自动结束前周期", str, beginYear.getYear(), endYear.getYear()));
|
|
|
|
|
+ updatePerManager.add(lastPerfManager);
|
|
|
|
|
+ }
|
|
|
|
|
+ //找到当前周期的上一周期
|
|
|
|
|
+ DynamicObject previousCycle = findPreviousCycle(allPerfManagerList, DateUtil.toDate(beginYear));
|
|
|
|
|
+ if (previousCycle != null) {
|
|
|
|
|
+ dataEntity.set(PerfManagerFormConstant.NCKD_LASTPERFMANAGER, previousCycle);
|
|
|
|
|
+ updateDataEntity.add(dataEntity);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ if(!updatePerManager.isEmpty()) {
|
|
|
|
|
+ DynamicObject[] lastPerfManagerArray = updatePerManager.toArray(new DynamicObject[0]);
|
|
|
|
|
+ SaveServiceHelper.update(lastPerfManagerArray);
|
|
|
|
|
+ }
|
|
|
|
|
+ if(!updateDataEntity.isEmpty()) {
|
|
|
|
|
+ SaveServiceHelper.update(updateDataEntity.toArray(new DynamicObject[0]));
|
|
|
|
|
+ }
|
|
|
|
|
+ //上一周期标记为“已结束”并设置“实际结束时间” end
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private boolean showInteractionMessage(String confirMmsg) {
|
|
private boolean showInteractionMessage(String confirMmsg) {
|
|
@@ -260,7 +606,7 @@ public class PerfManagerSaveOpPlugin extends AbstractOperationServicePlugIn impl
|
|
|
InteractionContext interactionContext = new InteractionContext();
|
|
InteractionContext interactionContext = new InteractionContext();
|
|
|
interactionContext.setSimpleMessage("存在【未结束】的考核周期");
|
|
interactionContext.setSimpleMessage("存在【未结束】的考核周期");
|
|
|
OperateErrorInfo errorInfo = new OperateErrorInfo();
|
|
OperateErrorInfo errorInfo = new OperateErrorInfo();
|
|
|
- errorInfo.setMessage(StrFormatter.format("检测到本次新增的人员中存在【未结束】的考核周期,新周期新增成功后会自动结束上一周期。{}", confirMmsg));
|
|
|
|
|
|
|
+ errorInfo.setMessage(StrFormatter.format("检测到本次新增的人员中存在【未结束】的考核周期,新周期新增成功后会自动结束上一周期,并将上一周期结束时间更新为当前新周期开始年前一年。{}", confirMmsg));
|
|
|
errorInfo.setLevel(ErrorLevel.Warning);
|
|
errorInfo.setLevel(ErrorLevel.Warning);
|
|
|
|
|
|
|
|
Map<String, String> custInfos = new HashMap<>();
|
|
Map<String, String> custInfos = new HashMap<>();
|
|
@@ -297,34 +643,35 @@ public class PerfManagerSaveOpPlugin extends AbstractOperationServicePlugIn impl
|
|
|
public static class PersonPerfInfo {
|
|
public static class PersonPerfInfo {
|
|
|
private Long id;
|
|
private Long id;
|
|
|
private final DynamicObject person;
|
|
private final DynamicObject person;
|
|
|
|
|
+ private final DynamicObject empPosOrgRel;
|
|
|
private final LocalDateTime beginYear;
|
|
private final LocalDateTime beginYear;
|
|
|
private final LocalDateTime endYear;
|
|
private final LocalDateTime endYear;
|
|
|
private final String description;
|
|
private final String description;
|
|
|
private int dataEntityIndex;
|
|
private int dataEntityIndex;
|
|
|
private DynamicObjectCollection entrys;
|
|
private DynamicObjectCollection entrys;
|
|
|
- private DynamicObject useorg;
|
|
|
|
|
- private DynamicObject org;
|
|
|
|
|
- private DynamicObject createorg;
|
|
|
|
|
private String whyEnd;
|
|
private String whyEnd;
|
|
|
private LocalDateTime actEndYear;
|
|
private LocalDateTime actEndYear;
|
|
|
|
|
|
|
|
- public PersonPerfInfo(DynamicObject person, Date beginYear, Date endYear, String description) {
|
|
|
|
|
|
|
+ public PersonPerfInfo(DynamicObject person,DynamicObject empPosOrgRel, Date beginYear, Date endYear, String description) {
|
|
|
this.person = person;
|
|
this.person = person;
|
|
|
|
|
+ this.empPosOrgRel = empPosOrgRel;
|
|
|
this.beginYear = DateUtil.toLocalDateTime(beginYear);
|
|
this.beginYear = DateUtil.toLocalDateTime(beginYear);
|
|
|
this.endYear = DateUtil.toLocalDateTime(endYear);
|
|
this.endYear = DateUtil.toLocalDateTime(endYear);
|
|
|
this.description = description;
|
|
this.description = description;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public PersonPerfInfo(DynamicObject person, Date beginYear, Date endYear, String description, int dataEntityIndex) {
|
|
|
|
|
|
|
+ public PersonPerfInfo(DynamicObject person, DynamicObject empPosOrgRel, Date beginYear, Date endYear, String description, int dataEntityIndex) {
|
|
|
this.person = person;
|
|
this.person = person;
|
|
|
|
|
+ this.empPosOrgRel = empPosOrgRel;
|
|
|
this.beginYear = DateUtil.toLocalDateTime(beginYear);
|
|
this.beginYear = DateUtil.toLocalDateTime(beginYear);
|
|
|
this.endYear = DateUtil.toLocalDateTime(endYear);
|
|
this.endYear = DateUtil.toLocalDateTime(endYear);
|
|
|
this.description = description;
|
|
this.description = description;
|
|
|
this.dataEntityIndex = dataEntityIndex;
|
|
this.dataEntityIndex = dataEntityIndex;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public PersonPerfInfo(DynamicObject person, Date beginYear, Date endYear, String description, int dataEntityIndex, DynamicObjectCollection entrys) {
|
|
|
|
|
|
|
+ public PersonPerfInfo(DynamicObject person, DynamicObject empPosOrgRel, Date beginYear, Date endYear, String description, int dataEntityIndex, DynamicObjectCollection entrys) {
|
|
|
this.person = person;
|
|
this.person = person;
|
|
|
|
|
+ this.empPosOrgRel = empPosOrgRel;
|
|
|
this.beginYear = DateUtil.toLocalDateTime(beginYear);
|
|
this.beginYear = DateUtil.toLocalDateTime(beginYear);
|
|
|
this.endYear = DateUtil.toLocalDateTime(endYear);
|
|
this.endYear = DateUtil.toLocalDateTime(endYear);
|
|
|
this.description = description;
|
|
this.description = description;
|
|
@@ -352,33 +699,14 @@ public class PerfManagerSaveOpPlugin extends AbstractOperationServicePlugIn impl
|
|
|
return person;
|
|
return person;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public DynamicObjectCollection getEntrys() {
|
|
|
|
|
- return entrys;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public DynamicObject getCreateorg() {
|
|
|
|
|
- return createorg;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public void setCreateorg(DynamicObject createorg) {
|
|
|
|
|
- this.createorg = createorg;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public DynamicObject getOrg() {
|
|
|
|
|
- return org;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public void setOrg(DynamicObject org) {
|
|
|
|
|
- this.org = org;
|
|
|
|
|
|
|
+ public DynamicObject getEmpPosOrgRel() {
|
|
|
|
|
+ return empPosOrgRel;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public DynamicObject getUseorg() {
|
|
|
|
|
- return useorg;
|
|
|
|
|
|
|
+ public DynamicObjectCollection getEntrys() {
|
|
|
|
|
+ return entrys;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public void setUseorg(DynamicObject useorg) {
|
|
|
|
|
- this.useorg = useorg;
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
public Long getId() {
|
|
public Long getId() {
|
|
|
return id;
|
|
return id;
|