Explorar o código

feat(cycle): 添加绩效管理列表插件动态列支持和保存操作插件校验逻辑

- 在 PerfManagerListPlugin 中实现 beforeCreateListDataProvider 方法以支持动态列值设置
- 为 PerfManagerSaveOpPlugin 增加同批次数据周期重叠与重复年份校验
- 引入必要的类库以支持新增功能逻辑
wyc hai 1 semana
pai
achega
cb1b965af4

+ 21 - 0
code/opmc/nckd-jxccl-opmc/src/main/java/nckd/jxccl/opmc/pm/plugin/form/cycle/PerfManagerListPlugin.java

@@ -2,7 +2,9 @@ package nckd.jxccl.opmc.pm.plugin.form.cycle;
 
 import kd.bos.dataentity.OperateOption;
 import kd.bos.dataentity.entity.DynamicObject;
+import kd.bos.dataentity.entity.DynamicObjectCollection;
 import kd.bos.entity.datamodel.ListSelectedRowCollection;
+import kd.bos.entity.datamodel.events.PackageDataEvent;
 import kd.bos.entity.operate.OperateOptionConst;
 import kd.bos.entity.operate.result.OperationResult;
 import kd.bos.form.CloseCallBack;
@@ -12,9 +14,11 @@ import kd.bos.form.ShowType;
 import kd.bos.form.StyleCss;
 import kd.bos.form.control.events.ItemClickEvent;
 import kd.bos.form.events.AfterDoOperationEventArgs;
+import kd.bos.form.events.BeforeCreateListDataProviderArgs;
 import kd.bos.form.events.BeforeDoOperationEventArgs;
 import kd.bos.form.operate.FormOperate;
 import kd.bos.list.plugin.AbstractListPlugin;
+import kd.bos.mvc.list.ListDataProvider;
 import kd.bos.servicehelper.operation.OperationServiceHelper;
 import kd.sdk.plugin.Plugin;
 import nckd.jxccl.base.common.constant.FormConstant;
@@ -49,6 +53,23 @@ public class PerfManagerListPlugin extends AbstractListPlugin implements Plugin
         }
     }
 
+    @Override
+    public void beforeCreateListDataProvider(BeforeCreateListDataProviderArgs args) {
+        args.setListDataProvider(new ListDataProvider() {
+            @Override
+            public DynamicObjectCollection getData(int start, int size) {
+                DynamicObjectCollection rows = super.getData(start, size);
+
+                // 为动态列设置值
+                for (DynamicObject row : rows) {
+                    DynamicObject adminOrg = row.getDynamicObject(FormConstant.NCKD_EMPPOSORGREL).getDynamicObject(FormConstant.ADMINORG);
+                }
+
+                return rows;
+            }
+        });
+    }
+
     @Override
     public void beforeDoOperation(BeforeDoOperationEventArgs args) {
         String operateKey = ((FormOperate) args.getSource()).getOperateKey();

+ 42 - 0
code/opmc/nckd-jxccl-opmc/src/main/java/nckd/jxccl/opmc/pm/plugin/operate/cycle/PerfManagerSaveOpPlugin.java

@@ -66,6 +66,7 @@ public class PerfManagerSaveOpPlugin extends AbstractOperationServicePlugIn impl
             @Override
             public void validate() {
                 //第一个循环先获取表单数据,这里需要兼容单人和批量的数据包
+                Map<Long, List<PersonPerfInfo>> currentBatchData = new HashMap<>();
                 for (ExtendedDataEntity rowDataEntity : getDataEntities()) {
                     DynamicObject data = rowDataEntity.getDataEntity();
                     int dataEntityIndex = rowDataEntity.getDataEntityIndex();
@@ -82,6 +83,47 @@ public class PerfManagerSaveOpPlugin extends AbstractOperationServicePlugIn impl
                         personBeginYearMap.put(personId, beginYear);
                     }
                     ids.add(id);
+
+                    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);
+                }
+
+                //检查同一批次内同一人员的周期重叠
+                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()