|
@@ -16,43 +16,54 @@ import nckd.jxccl.hrmp.haos.common.adminorg.AdminOrgConstant;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
import java.util.Arrays;
|
|
|
|
|
+import java.util.HashMap;
|
|
|
|
|
+import java.util.HashSet;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
+import java.util.Set;
|
|
|
import java.util.function.Function;
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 组织快速维护确认变更操作插件
|
|
* 组织快速维护确认变更操作插件
|
|
|
|
|
+ * @entity: nckd_haos_adminorgdet_ext
|
|
|
|
|
+ * @operate: confirmchange
|
|
|
* @author: jtd
|
|
* @author: jtd
|
|
|
* @date: 2025-10-16 9:47
|
|
* @date: 2025-10-16 9:47
|
|
|
*/
|
|
*/
|
|
|
public class AdminOrgDetailConfirmChangeOpPlugin extends AbstractOperationServicePlugIn {
|
|
public class AdminOrgDetailConfirmChangeOpPlugin extends AbstractOperationServicePlugIn {
|
|
|
|
|
|
|
|
- private DynamicObjectCollection adminOrgOldDyColl;
|
|
|
|
|
-
|
|
|
|
|
- private Boolean canDo(DynamicObject[] dataEntities) {
|
|
|
|
|
- if (dataEntities == null || dataEntities.length <= 0) {
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ /** 上级变更 */
|
|
|
|
|
+ private static final String CHANGETYPE_PARENT = "1020_S";
|
|
|
|
|
|
|
|
- DynamicObject data = dataEntities[0];
|
|
|
|
|
- // 非(上级调整或变更信息)或未来生效
|
|
|
|
|
- if (!("1020_S".equals(data.getDynamicObject(AdminOrgConstant.CHANGETYPE).getString(AdminOrgConstant.NUMBER_KEY)) || "1030_S".equals(data.getDynamicObject(AdminOrgConstant.CHANGETYPE).getString(AdminOrgConstant.NUMBER_KEY))) || HRDateTimeUtils.dayAfter(data.getDate(AdminOrgConstant.BSED), HRDateTimeUtils.getNowDate())) {
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ /** 变更信息 */
|
|
|
|
|
+ private static final String CHANGETYPE_INFO = "1030_S";
|
|
|
|
|
|
|
|
- return true;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ /** 变更前组织信息 */
|
|
|
|
|
+ private DynamicObjectCollection adminOrgOldDyColl;
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public void beginOperationTransaction(BeginOperationTransactionArgs e) {
|
|
public void beginOperationTransaction(BeginOperationTransactionArgs e) {
|
|
|
super.beginOperationTransaction(e);
|
|
super.beginOperationTransaction(e);
|
|
|
|
|
|
|
|
DynamicObject[] dataEntities = e.getDataEntities();
|
|
DynamicObject[] dataEntities = e.getDataEntities();
|
|
|
- if (!canDo(dataEntities)) {
|
|
|
|
|
|
|
+ DynamicObject data = dataEntities[0];
|
|
|
|
|
+ // 未来生效不处理
|
|
|
|
|
+ if (HRDateTimeUtils.dayAfter(data.getDate(AdminOrgConstant.BSED), HRDateTimeUtils.getNowDate())) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ String changtype = data.getDynamicObject(AdminOrgConstant.CHANGETYPE).getString(AdminOrgConstant.NUMBER_KEY);
|
|
|
|
|
+ if (CHANGETYPE_PARENT.equals(changtype)) {
|
|
|
|
|
+ beginOpParentHandler(dataEntities);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 处理调整上级数据
|
|
|
|
|
+ * @param dataEntities
|
|
|
|
|
+ */
|
|
|
|
|
+ private void beginOpParentHandler(DynamicObject[] dataEntities) {
|
|
|
// 获取组织及下级组织(旧数据)
|
|
// 获取组织及下级组织(旧数据)
|
|
|
QFilter qFilter = QFilter.of("1!=1");
|
|
QFilter qFilter = QFilter.of("1!=1");
|
|
|
Arrays.stream(dataEntities).map(dataEntity -> dataEntity.getString(AdminOrgConstant.STRUCTLONGNUMBER)+"%").forEach(structlongnumber -> {
|
|
Arrays.stream(dataEntities).map(dataEntity -> dataEntity.getString(AdminOrgConstant.STRUCTLONGNUMBER)+"%").forEach(structlongnumber -> {
|
|
@@ -66,10 +77,26 @@ public class AdminOrgDetailConfirmChangeOpPlugin extends AbstractOperationServic
|
|
|
super.endOperationTransaction(e);
|
|
super.endOperationTransaction(e);
|
|
|
|
|
|
|
|
DynamicObject[] dataEntities = e.getDataEntities();
|
|
DynamicObject[] dataEntities = e.getDataEntities();
|
|
|
- if (!canDo(dataEntities)) {
|
|
|
|
|
|
|
+ DynamicObject data = dataEntities[0];
|
|
|
|
|
+ // 未来生效不处理
|
|
|
|
|
+ if (HRDateTimeUtils.dayAfter(data.getDate(AdminOrgConstant.BSED), HRDateTimeUtils.getNowDate())) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ String changtype = data.getDynamicObject(AdminOrgConstant.CHANGETYPE).getString(AdminOrgConstant.NUMBER_KEY);
|
|
|
|
|
+ switch (changtype) {
|
|
|
|
|
+ case CHANGETYPE_PARENT:
|
|
|
|
|
+ endOpParentHandler();
|
|
|
|
|
+ break;
|
|
|
|
|
+ case CHANGETYPE_INFO:
|
|
|
|
|
+ endOpInfoHandler(dataEntities);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 处理调整上级数据
|
|
|
|
|
+ */
|
|
|
|
|
+ private void endOpParentHandler() {
|
|
|
// 获取组织及下级组织(新数据)含历史版本
|
|
// 获取组织及下级组织(新数据)含历史版本
|
|
|
List<Long> adminOrgBoIds = adminOrgOldDyColl.stream().map(adminOrg -> adminOrg.getLong(AdminOrgConstant.BOID_KEY)).collect(Collectors.toList());
|
|
List<Long> adminOrgBoIds = adminOrgOldDyColl.stream().map(adminOrg -> adminOrg.getLong(AdminOrgConstant.BOID_KEY)).collect(Collectors.toList());
|
|
|
String selectProperties = String.join(",", AdminOrgConstant.BOID_KEY, AdminOrgConstant.STRUCTLONGNUMBER, AdminOrgConstant.LEVEL, String.join(",", AdminOrgConstant.ADMINORG_STRUCT_FIELDS));
|
|
String selectProperties = String.join(",", AdminOrgConstant.BOID_KEY, AdminOrgConstant.STRUCTLONGNUMBER, AdminOrgConstant.LEVEL, String.join(",", AdminOrgConstant.ADMINORG_STRUCT_FIELDS));
|
|
@@ -100,4 +127,57 @@ public class AdminOrgDetailConfirmChangeOpPlugin extends AbstractOperationServic
|
|
|
// 保存数据
|
|
// 保存数据
|
|
|
SaveServiceHelper.save(adminOrgDys);
|
|
SaveServiceHelper.save(adminOrgDys);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 处理变更信息数据
|
|
|
|
|
+ * @param dataEntities
|
|
|
|
|
+ */
|
|
|
|
|
+ private void endOpInfoHandler(DynamicObject[] dataEntities) {
|
|
|
|
|
+ // 获取组织结构编码
|
|
|
|
|
+ Map<String, Long> structNumberMap = new HashMap<String, Long>();
|
|
|
|
|
+ // 拼接过滤条件
|
|
|
|
|
+ QFilter qFilter = QFilter.of("1!=1");
|
|
|
|
|
+ for (DynamicObject data : dataEntities) {
|
|
|
|
|
+ structNumberMap.put(data.getString(AdminOrgConstant.STRUCTNUMBER), data.getLong(AdminOrgConstant.ID_KEY));
|
|
|
|
|
+ qFilter.or(QFilter.like(AdminOrgConstant.STRUCTLONGNUMBER, data.getString(AdminOrgConstant.STRUCTLONGNUMBER)+"%"));
|
|
|
|
|
+ }
|
|
|
|
|
+ qFilter.and(QFilterCommonHelper.getCurrentVersionFilter());
|
|
|
|
|
+
|
|
|
|
|
+ // 查询字段
|
|
|
|
|
+ String adminOrgStructField = String.join(",", AdminOrgConstant.ADMINORG_STRUCT_FIELDS);
|
|
|
|
|
+ String selectProperties = String.join(",", AdminOrgConstant.BOID_KEY, AdminOrgConstant.SOURCEVID_KEY, AdminOrgConstant.STRUCTLONGNUMBER, adminOrgStructField);
|
|
|
|
|
+
|
|
|
|
|
+ // 存放关联历史版本ID和要更新的字段以及值
|
|
|
|
|
+ Map<Long, String> sourceIdMap = new HashMap<Long, String>();
|
|
|
|
|
+ // 查询需要更新的组织(当前版本含本身)
|
|
|
|
|
+ DynamicObject[] adminOrgDys = BusinessDataServiceHelper.load(AdminOrgConstant.ADMINORGHR_ENTITYID, selectProperties, new QFilter[]{qFilter}, AdminOrgConstant.LEVEL);
|
|
|
|
|
+ for (DynamicObject adminOrgDy : adminOrgDys) {
|
|
|
|
|
+ for (String structNumber : structNumberMap.keySet()) {
|
|
|
|
|
+ if (adminOrgDy.getString(AdminOrgConstant.STRUCTLONGNUMBER).contains(structNumber)) {
|
|
|
|
|
+ int index = Arrays.asList(adminOrgDy.getString(AdminOrgConstant.STRUCTLONGNUMBER).split("!")).indexOf(structNumber);
|
|
|
|
|
+ String fieldKey = AdminOrgConstant.ADMINORG_STRUCT_FIELDS[index];
|
|
|
|
|
+ Long value = structNumberMap.get(structNumber);
|
|
|
|
|
+ adminOrgDy.set(fieldKey, value);
|
|
|
|
|
+ sourceIdMap.put(adminOrgDy.getLong(AdminOrgConstant.SOURCEVID_KEY), String.join("@", fieldKey, value.toString()));
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 查询出历史版本记录
|
|
|
|
|
+ Set<Long> sourceIds = new HashSet<>(sourceIdMap.keySet());
|
|
|
|
|
+ DynamicObject[] adminOrgHisDys = BusinessDataServiceHelper.load(AdminOrgConstant.ADMINORGHR_ENTITYID, String.join(",", AdminOrgConstant.ADMINORG_STRUCT_FIELDS), new QFilter[]{new QFilter(AdminOrgConstant.ID_KEY, QCP.in, sourceIds)}, AdminOrgConstant.LEVEL);
|
|
|
|
|
+ for (DynamicObject adminOrgHisDy : adminOrgHisDys) {
|
|
|
|
|
+ String[] sourceId = sourceIdMap.get(adminOrgHisDy.getLong(AdminOrgConstant.ID_KEY)).split("@");
|
|
|
|
|
+ adminOrgHisDy.set(sourceId[0], Long.valueOf(sourceId[1]));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 合并数据
|
|
|
|
|
+ DynamicObject[] result = new DynamicObject[adminOrgDys.length + adminOrgHisDys.length];
|
|
|
|
|
+ System.arraycopy(adminOrgDys, 0, result, 0, adminOrgDys.length);
|
|
|
|
|
+ System.arraycopy(adminOrgHisDys, 0, result, adminOrgDys.length, adminOrgHisDys.length);
|
|
|
|
|
+ // 保存数据
|
|
|
|
|
+ SaveServiceHelper.save(result);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|