|
@@ -11,6 +11,8 @@ import kd.bos.dataentity.OperateOption;
|
|
|
import kd.bos.dataentity.entity.DynamicObject;
|
|
import kd.bos.dataentity.entity.DynamicObject;
|
|
|
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
|
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
|
|
import kd.bos.dataentity.entity.ILocaleString;
|
|
import kd.bos.dataentity.entity.ILocaleString;
|
|
|
|
|
+import kd.bos.dataentity.metadata.IDataEntityProperty;
|
|
|
|
|
+import kd.bos.dataentity.metadata.dynamicobject.DynamicProperty;
|
|
|
import kd.bos.dataentity.serialization.SerializationUtils;
|
|
import kd.bos.dataentity.serialization.SerializationUtils;
|
|
|
import kd.bos.db.tx.Propagation;
|
|
import kd.bos.db.tx.Propagation;
|
|
|
import kd.bos.db.tx.TX;
|
|
import kd.bos.db.tx.TX;
|
|
@@ -51,13 +53,15 @@ import org.apache.commons.lang3.time.DateUtils;
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
import java.util.Arrays;
|
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
|
|
|
+import java.util.LinkedHashMap;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
import java.util.Set;
|
|
import java.util.Set;
|
|
|
|
|
+import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 岗位申请单帮组类
|
|
|
|
|
|
|
+ * 岗位申请单帮助类
|
|
|
* @from: kd.hr.homs.business.domain.batchbill.repository.AdminOrgBatchChgHelper
|
|
* @from: kd.hr.homs.business.domain.batchbill.repository.AdminOrgBatchChgHelper
|
|
|
* @author: jtd
|
|
* @author: jtd
|
|
|
* @date: 2025-10-31 14:33
|
|
* @date: 2025-10-31 14:33
|
|
@@ -65,6 +69,96 @@ import java.util.stream.Collectors;
|
|
|
public class PositionBillServiceHelper {
|
|
public class PositionBillServiceHelper {
|
|
|
private static final Log log = LogFactory.getLog(PositionBillServiceHelper.class);
|
|
private static final Log log = LogFactory.getLog(PositionBillServiceHelper.class);
|
|
|
|
|
|
|
|
|
|
+ public static void setChangeDes(List<DynamicObject> changeDyos) {
|
|
|
|
|
+ setChangeDes(changeDyos, false);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public static void setChangeDes(List<DynamicObject> changeDyos, Boolean isEntry) {
|
|
|
|
|
+ String positionKey = isEntry ? String.format("%s_%s.%s", PositionBillConstant.NCKD_POSITION_KEY, PositionBillConstant.CHANGE_TAG, PositionBillConstant.BOID_KEY) : String.join(".", PositionBillConstant.NCKD_POSITION_KEY, PositionBillConstant.BOID_KEY);
|
|
|
|
|
+ List<Long> changeIds = changeDyos.stream().map(changeDyo -> changeDyo.getLong(positionKey)).collect(Collectors.toList());
|
|
|
|
|
+
|
|
|
|
|
+ // 获取要记录的变更字段
|
|
|
|
|
+ Map<String, String> changeFieldMap = Arrays.stream(HRBaseServiceHelper.create(PositionBillConstant.NCKD_PBENTRY_CHANGE_FIELD_ENTITY).queryOriginalArray(PositionBillConstant.NUMBER_KEY, null, PositionBillConstant.INDEX_KEY)).map(changeFieldDy -> changeFieldDy.getString(PositionBillConstant.NUMBER_KEY)).collect(Collectors.toMap(Function.identity(), Function.identity(), (oldValue, newValue) -> newValue, LinkedHashMap::new));
|
|
|
|
|
+ // 获取岗位要转换的键值
|
|
|
|
|
+ Map<String, String> positionTransKeyMap = getPositionTransKeyMap();
|
|
|
|
|
+ for (Map.Entry<String, String> entry : changeFieldMap.entrySet()) {
|
|
|
|
|
+ if (positionTransKeyMap.containsKey(entry.getKey())) {
|
|
|
|
|
+ changeFieldMap.put(entry.getKey(), positionTransKeyMap.get(entry.getKey()));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (isEntry) {
|
|
|
|
|
+ // 获取分录要转换的键值
|
|
|
|
|
+ Map<String, String> posBillEntryReverseTransKeyMap = getPosBillEntryTransKeyMap().entrySet().stream().collect(Collectors.toMap(Map.Entry::getValue, Map.Entry::getKey, (oldValue, newValue) -> newValue));
|
|
|
|
|
+ changeFieldMap = changeFieldMap.entrySet().stream().collect(Collectors.toMap(entry -> {
|
|
|
|
|
+ String entryChangeField = String.join("_", entry.getKey(), PositionBillConstant.CHANGE_TAG);
|
|
|
|
|
+ if (posBillEntryReverseTransKeyMap.containsKey(entry.getKey())) {
|
|
|
|
|
+ entryChangeField = String.join("_", posBillEntryReverseTransKeyMap.get(entry.getKey()), PositionBillConstant.CHANGE_TAG);
|
|
|
|
|
+ }
|
|
|
|
|
+ return entryChangeField;
|
|
|
|
|
+ }, Map.Entry::getValue, (oldValue, newValue) -> newValue, LinkedHashMap::new));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Map<String, IDataEntityProperty> positionAllFields = EntityMetadataCache.getDataEntityType(PositionBillConstant.HBPM_POSITIONHR).getAllFields();
|
|
|
|
|
+ Map<Long, DynamicObject> dbPositionDyMap = Arrays.stream(HRBaseServiceHelper.create(PositionBillConstant.HBPM_POSITIONHR).loadDynamicObjectArray(changeIds.toArray())).collect(Collectors.toMap(dbPositionDy -> dbPositionDy.getLong(PositionBillConstant.BOID_KEY), Function.identity()));
|
|
|
|
|
+ for (DynamicObject changeDyo : changeDyos) {
|
|
|
|
|
+ List<String> changeDesList = new ArrayList<String>();
|
|
|
|
|
+ DynamicObject dbPositionDyo = dbPositionDyMap.get(changeDyo.getLong(positionKey));
|
|
|
|
|
+ for (Map.Entry<String, String> entry : changeFieldMap.entrySet()) {
|
|
|
|
|
+ String positionField = entry.getValue();
|
|
|
|
|
+ if (!positionAllFields.containsKey(positionField)) {
|
|
|
|
|
+ log.warn(HRStringUtils.format("PositionBillServiceHelper.setChangeDes not find field '{}' in position.", positionField));
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ boolean isChange;
|
|
|
|
|
+ Object oldValue = dbPositionDyo.get(positionField);
|
|
|
|
|
+ Object newValue = changeDyo.get(entry.getKey());
|
|
|
|
|
+ if (HRObjectUtils.isEmpty(oldValue) && HRObjectUtils.isEmpty(newValue)) {
|
|
|
|
|
+ isChange = false;
|
|
|
|
|
+ } else if ((HRObjectUtils.isEmpty(oldValue) && !HRObjectUtils.isEmpty(newValue)) || (!HRObjectUtils.isEmpty(oldValue) && HRObjectUtils.isEmpty(newValue))) {
|
|
|
|
|
+ isChange = true;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ isChange = !HRDynamicObjectUtils.compareValues(oldValue, newValue);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (isChange) {
|
|
|
|
|
+ String fieldName = changeDyo.getDynamicObjectType().getProperty(entry.getKey()).getDisplayName().getLocaleValue();
|
|
|
|
|
+ changeDesList.add(HRStringUtils.format("{}:\"{}\" -> \"{}\"", fieldName, getValue(dbPositionDyo, positionField, oldValue), getValue(changeDyo, entry.getKey(), newValue)));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ changeDyo.set(isEntry ? String.join("_", PositionBillConstant.NCKD_CHANGEDES_KEY, PositionBillConstant.CHANGE_TAG) : PositionBillConstant.NCKD_CHANGEDES_KEY, changeDesList.isEmpty() ? null : String.join(System.lineSeparator(), changeDesList));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static String getValue(DynamicObject dyo, String field, Object val) {
|
|
|
|
|
+ if (!HRObjectUtils.isEmpty(val)) {
|
|
|
|
|
+ if (val instanceof DynamicObject) {
|
|
|
|
|
+ return ((DynamicObject) val).getString(PositionBillConstant.NAME_KEY);
|
|
|
|
|
+ } else if (val instanceof DynamicObjectCollection) {
|
|
|
|
|
+ if (((DynamicObjectCollection) val).isEmpty()) {
|
|
|
|
|
+ return " ";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ List<String> list = new ArrayList<String>();
|
|
|
|
|
+ for (DynamicObject d : (DynamicObjectCollection) val) {
|
|
|
|
|
+ DynamicProperty baseDataProp = d.getDynamicObjectType().getProperty(PositionBillConstant.FBASEDATAID_KEY);
|
|
|
|
|
+ if (baseDataProp == null) {
|
|
|
|
|
+ list.add(d.getString(PositionBillConstant.NAME_KEY));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ list.add(d.getDynamicObject(PositionBillConstant.FBASEDATAID_KEY).getString(PositionBillConstant.NAME_KEY));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return String.join(";", list);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return dyo.getString(field);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return " ";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public static String getNoLineSuffixProp(String prop, String lineSuffix) {
|
|
public static String getNoLineSuffixProp(String prop, String lineSuffix) {
|
|
|
if (prop.endsWith(lineSuffix)) {
|
|
if (prop.endsWith(lineSuffix)) {
|
|
|
return prop.substring(0, prop.lastIndexOf(lineSuffix));
|
|
return prop.substring(0, prop.lastIndexOf(lineSuffix));
|
|
@@ -101,8 +195,8 @@ public class PositionBillServiceHelper {
|
|
|
return transKeyMap;
|
|
return transKeyMap;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public static Set<String> getPositionAllEntities() {
|
|
|
|
|
- return EntityMetadataCache.getDataEntityType(PositionBillConstant.HBPM_POSITIONHR).getAllEntities().keySet();
|
|
|
|
|
|
|
+ public static Set<String> getPositionProperties() {
|
|
|
|
|
+ return EntityMetadataCache.getDataEntityType(PositionBillConstant.HBPM_POSITIONHR).getProperties().stream().map(IDataEntityProperty::getName).collect(Collectors.toSet());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|