Bläddra i källkod

feat(plugin): 添加日志记录和数据源处理优化

- 在PersonPosFileSaveOpPlugin中添加详细的日志记录,包括开始处理、收集数据、获取薪资标准等关键步骤
- 修复EmployeePrintPlugin中的数据源处理逻辑,添加MainDataSource和PrtDataSource导入
- 在EmployeePrintPlugin中新增mainDataSource私有变量记录主数据源
- 优化EmployeePrintPlugin的afterLoadData方法,仅处理主数据源并跳过自定义数据源
- 修复日志警告信息中缺少人员ID的问题,现在会正确输出员工姓名和ID
- 优化代码结构,添加适当的空行和格式化以提高可读性
wyc 4 dagar sedan
förälder
incheckning
b99e041d61

+ 27 - 2
code/hr/nckd-jxccl-hr/src/main/java/nckd/jxccl/hr/psms/plugin/operate/file/PersonPosFileSaveOpPlugin.java

@@ -46,6 +46,7 @@ public class PersonPosFileSaveOpPlugin extends AbstractOperationServicePlugIn im
 
     @Override
     public void beginOperationTransaction(BeginOperationTransactionArgs e) {
+        logger.info("beginOperationTransaction start: processing {} data entities", e.getDataEntities().length);
 
         //职位津贴=职位系数 X 所在岗级岗位工资一档金额
         List<Long> allPersonIds = new ArrayList<>(e.getDataEntities().length);
@@ -68,17 +69,27 @@ public class PersonPosFileSaveOpPlugin extends AbstractOperationServicePlugIn im
                 }
             }
         }
+        
+        logger.info("Collected person IDs count: {}, job level IDs count: {}", allPersonIds.size(), jobLevelIds.size());
 
         //====================================== 获取当前人员所在定调的岗位标准工资一档金额 begin ======================================
         try {
             Long salaryItemId = EntityHelper.getIdByNumber(FormConstant.HSBS_STANDARDITEM, FormConstant.POS_STANDARD_ITEM_NUMBER);
+            logger.info("Retrieved salary item ID: {}", salaryItemId);
+            
             Map<Long, BigDecimal> amountMap = new HashMap<>(e.getDataEntities().length);
             if (!allPersonIds.isEmpty() && !jobLevelIds.isEmpty()) {
+                logger.info("Processing salary adjustment records for {} person IDs", allPersonIds.size());
+                
                 //获取人员最新岗位工资标准定薪记录
                 List<AdjFileServiceHelper.SalaryAdjustmentResult> salaryAdjustmentResultList = AdjFileServiceHelper.getLastDecAdjRecords(allPersonIds, FormConstant.POS_STANDARD_ITEM_NUMBER);
+                logger.info("Retrieved {} salary adjustment results", salaryAdjustmentResultList.size());
+                
                 if (!salaryAdjustmentResultList.isEmpty()) {
                     //薪酬标准ID
                     List<Long> salaryStIds = salaryAdjustmentResultList.stream().map(result -> result.salaryStDv.getLong(FormConstant.ID_KEY)).collect(Collectors.toList());
+                    logger.info("Retrieved salary standard IDs: {}", salaryStIds.size());
+                    
                     QFilter filter = new QFilter(FormConstant.ID_KEY, QCP.in, salaryStIds)
                             .and(String.join(".", "rankentry", "rank", FormConstant.NUMBER_KEY), QCP.equals, "01");
                     //获取标准表中01档的薪档
@@ -86,6 +97,8 @@ public class PersonPosFileSaveOpPlugin extends AbstractOperationServicePlugIn im
                             .add(FormConstant.ID_KEY)
                             .addIdNumberNameWithExtras(new String[]{"rankentry", "rank"}, FormConstant.INDEX_KEY);
                     DynamicObjectCollection salaryStandardColl = QueryServiceHelper.query("hcdm_salarystandard", salaryStandFieldBuilder.buildSelect(), new QFilter[]{filter});
+                    logger.info("Retrieved {} salary standard records", salaryStandardColl.size());
+                    
                     Map<Long, DynamicObject> salaryStandardMap = salaryStandardColl.stream()
                             .collect(Collectors.toMap(
                                     obj -> obj.getLong(FormConstant.ID_KEY),
@@ -93,6 +106,7 @@ public class PersonPosFileSaveOpPlugin extends AbstractOperationServicePlugIn im
                             ));
 
                     if (!salaryStandardMap.isEmpty()) {
+                        logger.info("Created salary standard map with {} entries", salaryStandardMap.size());
                         List<StdTableDataMatchParam> matchParams = new ArrayList<>();
                         for (AdjFileServiceHelper.SalaryAdjustmentResult result : salaryAdjustmentResultList) {
                             StdTableDataMatchParam stdTableDataMatchParam = new StdTableDataMatchParam();
@@ -106,9 +120,13 @@ public class PersonPosFileSaveOpPlugin extends AbstractOperationServicePlugIn im
                                 matchParams.add(stdTableDataMatchParam);
                             }
                         }
+                        logger.info("Created {} match parameters", matchParams.size());
+                        
                         if (!matchParams.isEmpty()) {
                             //获取薪酬项目、薪等、薪档对应金额(入参params的数组下标和出参的数组下标一一对应)
                             List<StdTableDataMatchResult> stdTableDataMatchResults = HCDMSalaryStdServiceHelper.matchStdTableData(matchParams);
+                            logger.info("Retrieved {} standard table match results", stdTableDataMatchResults.size());
+                            
                             for (int i = 0; i < salaryAdjustmentResultList.size(); i++) {
                                 AdjFileServiceHelper.SalaryAdjustmentResult result = salaryAdjustmentResultList.get(i);
                                 if (i < stdTableDataMatchResults.size() && stdTableDataMatchResults.get(i) != null) {
@@ -116,6 +134,7 @@ public class PersonPosFileSaveOpPlugin extends AbstractOperationServicePlugIn im
                                     amountMap.put(result.employee.getLong(FormConstant.ID_KEY), stdTableDataMatchResults.get(i).getAmount());
                                 }
                             }
+                            logger.info("Populated amount map with {} entries", amountMap.size());
                         }
                     } else {
                         logger.warn("未获取薪酬标准表中01档的薪档数据,薪酬标准ID:{}", salaryStIds);
@@ -127,6 +146,7 @@ public class PersonPosFileSaveOpPlugin extends AbstractOperationServicePlugIn im
             //====================================== 获取当前人员所在定调的岗位标准工资一档金额 end ======================================
             Map<Long, DynamicObject> jobLevelMap = new HashMap<>(e.getDataEntities().length);
             if (!jobLevelIds.isEmpty()) {
+                logger.info("Loading job level information for {} IDs", jobLevelIds.size());
                 MainEntityType jobLevelEntityType = EntityMetadataCache.getDataEntityType(FormConstant.HBJM_JOBLEVELHR);
                 //重新加载职级信息,避免获取不到系数
                 DynamicObject[] load = BusinessDataServiceHelper.load(jobLevelIds.toArray(new Long[0]), jobLevelEntityType);
@@ -135,8 +155,10 @@ public class PersonPosFileSaveOpPlugin extends AbstractOperationServicePlugIn im
                                 obj -> obj.getLong(FormConstant.ID_KEY),
                                 obj -> obj
                         ));
+                logger.info("Loaded {} job level records", jobLevelMap.size());
             }
 
+            logger.info("Processing {} data entities for coefficient and salary calculation", e.getDataEntities().length);
             for (DynamicObject dataEntity : e.getDataEntities()) {
                 long jobLevelId = dataEntity.getLong(String.join(".", PositionStructureConstant.NCKD_JOBLEVELHR, FormConstant.ID_KEY));
                 DynamicObject jobLevel = jobLevelMap.get(jobLevelId);
@@ -151,14 +173,17 @@ public class PersonPosFileSaveOpPlugin extends AbstractOperationServicePlugIn im
                             dataEntity.set(PositionStructureConstant.NCKD_COEFFICIENT, coefficient);
                             dataEntity.set(PositionStructureConstant.NCKD_CURRENTPOSTSALARY, amount);
                             dataEntity.set(PositionStructureConstant.NCKD_POSTALLOWANCE, coefficient.multiply(amount));
+                            logger.info("Updated person ID: {}, coefficient: {}, current post salary: {}, post allowance: {}", 
+                                personId, coefficient, amount, coefficient.multiply(amount));
                         }
                     } else {
-                        logger.warn("未获取到员工【{}】最新岗位工资标准定薪记录01档的薪等金额,人员ID:", person.getString(FormConstant.NAME_KEY));
+                        logger.warn("未获取到员工【{}】最新岗位工资标准定薪记录01档的薪等金额,人员ID:{}", person.getString(FormConstant.NAME_KEY), personId);
                     }
                 }
             }
+            logger.info("beginOperationTransaction completed successfully");
         }catch (Exception e1){
-            logger.error("获取人员岗位工资标准定薪记录01档的薪等金额异常",e1);
+            logger.error("获取人员岗位工资标准定薪记录01档的薪等金额异常", e1);
         }
     }
 

+ 98 - 89
code/opmc/nckd-jxccl-opmc/src/main/java/nckd/jxccl/opmc/pm/plugin/form/print/EmployeePrintPlugin.java

@@ -13,6 +13,8 @@ import kd.bos.orm.query.QCP;
 import kd.bos.orm.query.QFilter;
 import kd.bos.print.core.data.DataRowSet;
 import kd.bos.print.core.data.datasource.CustomDataSource;
+import kd.bos.print.core.data.datasource.MainDataSource;
+import kd.bos.print.core.data.datasource.PrtDataSource;
 import kd.bos.print.core.data.field.CollectionField;
 import kd.bos.print.core.data.field.Field;
 import kd.bos.print.core.data.field.IntegerField;
@@ -46,6 +48,9 @@ import java.util.Map;
 */
 public class EmployeePrintPlugin extends AbstractPrintPlugin implements Plugin {
 
+    //记录主数据源
+    private MainDataSource mainDataSource;
+
     @Override
     public void loadCustomData(CustomDataLoadEvent evt) {
         Date printYear = HRAppCache.get("nckd_pm").get("printYear", Date.class);
@@ -104,109 +109,113 @@ public class EmployeePrintPlugin extends AbstractPrintPlugin implements Plugin {
 
     @Override
     public void afterLoadData(AfterLoadDataEvent evt) {
-        String dsName = evt.getDataSource().getDsName();
-        if(!dsName.contains("custom")) {
-            Date printYear = HRAppCache.get("nckd_pm").get("printYear", Date.class);
-            Map<Integer, Long> selectPrintPersonIdMap = HRAppCache.get("nckd_pm").get("employeePrintIdMap", Map.class);
-            if(selectPrintPersonIdMap == null){
-                throw new ValidationException("请选择要打印的日期!");
-            }
-            List<String> seqs = ConvertUtil.toList(selectPrintPersonIdMap.keySet(), ArrayList::new);
-            LocalDate now = LocalDate.now();
-            // 获取5年前的年份
-            int fiveYearsAgo = LocalDate.now().minusYears(5).getYear();
-            Date beginDate = DateUtil.toDate(LocalDate.of(fiveYearsAgo, 1, 1));
-
-            int currentYear = LocalDate.now().getYear() - 1; // 不包含今年
-            Date endDate = DateUtil.toDate(LocalDate.of(currentYear, 1, 1));
-
-            Map<String, String> positionMap = new HashMap<>();
-            Map<String, Integer> perfRankMgmtMap = new HashMap<>();
-            try (AlgoContext context = Algo.newContext()) {
-                Collection<Long> personIds = selectPrintPersonIdMap.values();
-                DataSet positionDateSet = getPositions(fiveYearsAgo, currentYear, personIds);
-                if (positionDateSet != null) {
-                    while (positionDateSet.hasNext()) {
-                        Row next = positionDateSet.next();
-                        Long personId = next.getLong(String.join(".", FormConstant.EMPLOYEE_KEY, FormConstant.ID_KEY));
-                        int tempIndex = 1;
-                        for (int year = fiveYearsAgo; year <= currentYear; year++) {
-                            String positionName = next.getString("position_" + tempIndex);
-                            positionMap.put(personId + "nckd_position_" + tempIndex, positionName);
-                            tempIndex++;
-                        }
+        PrtDataSource dataSource = evt.getDataSource();
+        if(!(dataSource instanceof MainDataSource)){
+            return;//非主数据源,立即返回
+        }
+        //记录主数据源,用于自定义数据源查询时,获取需要的信息
+        mainDataSource = (MainDataSource) dataSource;
+        Date printYear = HRAppCache.get("nckd_pm").get("printYear", Date.class);
+        Map<Integer, Long> selectPrintPersonIdMap = HRAppCache.get("nckd_pm").get("employeePrintIdMap", Map.class);
+        if(selectPrintPersonIdMap == null){
+            throw new ValidationException("请选择要打印的日期!");
+        }
+        List<String> seqs = ConvertUtil.toList(selectPrintPersonIdMap.keySet(), ArrayList::new);
+        LocalDate now = LocalDate.now();
+        // 获取5年前的年份
+        int fiveYearsAgo = LocalDate.now().minusYears(5).getYear();
+        Date beginDate = DateUtil.toDate(LocalDate.of(fiveYearsAgo, 1, 1));
+
+        int currentYear = LocalDate.now().getYear() - 1; // 不包含今年
+        Date endDate = DateUtil.toDate(LocalDate.of(currentYear, 1, 1));
+
+        Map<String, String> positionMap = new HashMap<>();
+        Map<String, Integer> perfRankMgmtMap = new HashMap<>();
+        try (AlgoContext context = Algo.newContext()) {
+            Collection<Long> personIds = selectPrintPersonIdMap.values();
+            DataSet positionDateSet = getPositions(fiveYearsAgo, currentYear, personIds);
+            if (positionDateSet != null) {
+                while (positionDateSet.hasNext()) {
+                    Row next = positionDateSet.next();
+                    Long personId = next.getLong(String.join(".", FormConstant.EMPLOYEE_KEY, FormConstant.ID_KEY));
+                    int tempIndex = 1;
+                    for (int year = fiveYearsAgo; year <= currentYear; year++) {
+                        String positionName = next.getString("position_" + tempIndex);
+                        positionMap.put(personId + "nckd_position_" + tempIndex, positionName);
+                        tempIndex++;
                     }
                 }
+            }
 
-                DataSet perfRankMgmtDataSet = getPerfRankMgmt(personIds, fiveYearsAgo, currentYear);
-                if (perfRankMgmtDataSet != null) {
-                    while (perfRankMgmtDataSet.hasNext()) {
-                        Row next = perfRankMgmtDataSet.next();
-                        Long personId = next.getLong(String.join(".", FormConstant.NCKD_PERSON, FormConstant.ID_KEY));
-                        int tempIndex = 1;
-                        for (int year = fiveYearsAgo; year <= currentYear; year++) {
-                            Integer topran = next.getInteger("perfrank_topran_" + tempIndex);
-                            Integer topranks = next.getInteger("perfrank_topranks_" + tempIndex);
-                            perfRankMgmtMap.put(personId + "nckd_perfrank_topran_" + tempIndex, topran);
-                            perfRankMgmtMap.put(personId + "nckd_perfrank_topranks_" + tempIndex, topranks);
-                            tempIndex++;
-                        }
+            DataSet perfRankMgmtDataSet = getPerfRankMgmt(personIds, fiveYearsAgo, currentYear);
+            if (perfRankMgmtDataSet != null) {
+                while (perfRankMgmtDataSet.hasNext()) {
+                    Row next = perfRankMgmtDataSet.next();
+                    Long personId = next.getLong(String.join(".", FormConstant.NCKD_PERSON, FormConstant.ID_KEY));
+                    int tempIndex = 1;
+                    for (int year = fiveYearsAgo; year <= currentYear; year++) {
+                        Integer topran = next.getInteger("perfrank_topran_" + tempIndex);
+                        Integer topranks = next.getInteger("perfrank_topranks_" + tempIndex);
+                        perfRankMgmtMap.put(personId + "nckd_perfrank_topran_" + tempIndex, topran);
+                        perfRankMgmtMap.put(personId + "nckd_perfrank_topranks_" + tempIndex, topranks);
+                        tempIndex++;
                     }
                 }
             }
+        }
 
 
-            // 获取当前打印的数据集并准备过滤后的集合
-            // 2. 获取当前打印的数据集
-            List<DataRowSet> dataRowSets = evt.getDataRowSets();
-            List<DataRowSet> filteredDataRowSets = new ArrayList<>();
-
-            for (DataRowSet dataRowSet : dataRowSets) {
-                if (dataRowSet.containerKey("reportEntry")) {
-                    CollectionField entryField = (CollectionField) dataRowSet.getField("reportEntry");
-                    List<DataRowSet> entryRows = entryField.getValue();
-                    List<DataRowSet> filteredEntryRows = new ArrayList<>();
-                    for (DataRowSet entryRow : entryRows) {
-                        String seq = ConvertUtil.toStr(entryRow.getField(FormConstant.SEQ_KEY).getValue());
-                        Long personId = selectPrintPersonIdMap.get(seq + "");
-                        // 判断该分录行是否在用户勾选的列表中
-                        if (seqs.contains(seq)) {
-                            for (String fieldKey : entryRow.getFieldKeys()) {
-                                if (fieldKey.startsWith("nckd_position_")) {
-                                    String positionName = positionMap.get(personId + fieldKey);
-                                    Field field = entryRow.getField(fieldKey);
-                                    field.setValue(positionName != null ? positionName : "");
-                                    entryRow.put(fieldKey, field);
-                                }
-                                if (fieldKey.startsWith("nckd_perfrank_topran_")) {
-                                    Integer perfRankMgmt = perfRankMgmtMap.get(personId + fieldKey);
-                                    Field field = entryRow.getField(fieldKey);
-                                    field.setValue(perfRankMgmt != null ? perfRankMgmt : 0);
-                                    entryRow.put(fieldKey, field);
-                                }
-                                if (fieldKey.startsWith("nckd_perfrank_topranks_")) {
-                                    Integer perfRankMgmt = perfRankMgmtMap.get(personId + fieldKey);
-                                    Field field = entryRow.getField(fieldKey);
-                                    field.setValue(perfRankMgmt != null ? perfRankMgmt : 0);
-                                    entryRow.put(fieldKey, field);
-                                }
+        // 获取当前打印的数据集并准备过滤后的集合
+        // 2. 获取当前打印的数据集
+        List<DataRowSet> dataRowSets = evt.getDataRowSets();
+        List<DataRowSet> filteredDataRowSets = new ArrayList<>();
+
+        for (DataRowSet dataRowSet : dataRowSets) {
+            if (dataRowSet.containerKey("reportEntry")) {
+                CollectionField entryField = (CollectionField) dataRowSet.getField("reportEntry");
+                List<DataRowSet> entryRows = entryField.getValue();
+                List<DataRowSet> filteredEntryRows = new ArrayList<>();
+                for (DataRowSet entryRow : entryRows) {
+                    String seq = ConvertUtil.toStr(entryRow.getField(FormConstant.SEQ_KEY).getValue());
+                    Long personId = selectPrintPersonIdMap.get(seq + "");
+                    // 判断该分录行是否在用户勾选的列表中
+                    if (seqs.contains(seq)) {
+                        for (String fieldKey : entryRow.getFieldKeys()) {
+                            if (fieldKey.startsWith("nckd_position_")) {
+                                String positionName = positionMap.get(personId + fieldKey);
+                                Field field = entryRow.getField(fieldKey);
+                                field.setValue(positionName != null ? positionName : "");
+                                entryRow.put(fieldKey, field);
+                            }
+                            if (fieldKey.startsWith("nckd_perfrank_topran_")) {
+                                Integer perfRankMgmt = perfRankMgmtMap.get(personId + fieldKey);
+                                Field field = entryRow.getField(fieldKey);
+                                field.setValue(perfRankMgmt != null ? perfRankMgmt : 0);
+                                entryRow.put(fieldKey, field);
+                            }
+                            if (fieldKey.startsWith("nckd_perfrank_topranks_")) {
+                                Integer perfRankMgmt = perfRankMgmtMap.get(personId + fieldKey);
+                                Field field = entryRow.getField(fieldKey);
+                                field.setValue(perfRankMgmt != null ? perfRankMgmt : 0);
+                                entryRow.put(fieldKey, field);
                             }
-                            filteredEntryRows.add(entryRow);
                         }
-
-                    }
-                    // 用过滤后的分录数据替换原数据
-                    if (!filteredEntryRows.isEmpty()) {
-                        DataRowSet newDataRowSet = dataRowSet.deepCopy(); // 深拷贝,避免影响原数据
-                        newDataRowSet.put("reportEntry", new CollectionField(filteredEntryRows));
-                        filteredDataRowSets.add(newDataRowSet);
+                        filteredEntryRows.add(entryRow);
                     }
+
+                }
+                // 用过滤后的分录数据替换原数据
+                if (!filteredEntryRows.isEmpty()) {
+                    DataRowSet newDataRowSet = dataRowSet.deepCopy(); // 深拷贝,避免影响原数据
+                    newDataRowSet.put("reportEntry", new CollectionField(filteredEntryRows));
+                    filteredDataRowSets.add(newDataRowSet);
                 }
             }
-
-            // 将过滤后的数据集设置回事件,实现只打印勾选行
-            evt.setDataRowSets(filteredDataRowSets);
         }
+
+        // 将过滤后的数据集设置回事件,实现只打印勾选行
+        evt.setDataRowSets(filteredDataRowSets);
+
     }