Browse Source

feat(datacomparison): 优化数据比对逻辑并完善险种相关功能

- 移除未使用的 JoinHint 导入
- 新增常量类引用以支持险种和核算人员查询
- 重构字段数组定义,拆分为 mapFields 和 leftFields
- 增加获取所有核算人员与险种笛卡尔积的方法
- 实现险种 ID 查询及其对应的 DataSet 构造方法
- 更新最终数据集连接逻辑,引入中间映射数据集确保完整数据覆盖
- 在编辑界面增加空值校验避免无效比对,提升比对结果准确性
Tyx 6 days ago
parent
commit
70900af76a

+ 56 - 8
code/swc/nckd-jxccl-swc/src/main/java/nckd/jxccl/sit/hcsi/business/datacomparison/DataComparisonQueryService.java

@@ -3,7 +3,6 @@ package nckd.jxccl.sit.hcsi.business.datacomparison;
 
 import kd.bos.algo.DataSet;
 import kd.bos.algo.JoinDataSet;
-import kd.bos.algo.JoinHint;
 import kd.bos.algo.JoinType;
 import kd.bos.dataentity.entity.DynamicObject;
 import kd.bos.dataentity.entity.DynamicObjectCollection;
@@ -14,6 +13,7 @@ import kd.bos.logging.LogFactory;
 import kd.bos.orm.query.QCP;
 import kd.bos.orm.query.QFilter;
 import kd.hr.hbp.business.servicehelper.HRBaseServiceHelper;
+import nckd.jxccl.sit.hcsi.common.constant.SitConstant;
 import nckd.jxccl.sit.hcsi.utils.ReportUtils;
 
 import java.util.List;
@@ -26,7 +26,8 @@ import java.util.stream.Collectors;
 public class DataComparisonQueryService {
     private static final Log logger = LogFactory.getLog(DataComparisonQueryService.class);
     private static final String SINSURTASK = "hcsi_sinsurtask";
-    String[] leftFields = new String[]{"welfarepayer", "welfaretypeid", "empnumber", "empname", "empidcard", "employee", "type", "personSysValue", "personSysValuea", "companySysValue", "companySysValuea"};
+    String[] mapFields = new String[]{"welfarepayer", "welfaretypeid", "empnumber", "empname", "empidcard", "employee"};
+    String[] leftFields = new String[]{"type", "personSysValue", "personSysValuea", "companySysValue", "companySysValuea"};
     String[] rightFields =  new String[]{"personOutValue", "personOutValuea","companyOutValue", "companyOutValuea"};
     IDataModel model = null;
     IFormView view = null;
@@ -44,6 +45,8 @@ public class DataComparisonQueryService {
         logger.info("Tyx begin DataComparisonQueryService.doQuery");
         // 查询任务ID
         List<Long> taskIds = queryTask();
+        // Map数据集,用于获取全量人员+险种数据,用于最后join的底表用
+        DataSet dataSetMap = queryAllCalPersonAndWelfareTypeByTaskId(taskIds);
         // 根据计算任务Id+险种获取到计算结果明细数据
         DataSet calPersonDataSet = queryCalPersonDetail(taskIds);
         // 按照个人和单位分组汇总 type = 1为个人,type = 2为单位,这里仅为系统内数据
@@ -52,9 +55,8 @@ public class DataComparisonQueryService {
         DataSet outsidePersonDetail = queryOutsidePersonDetail();
         // 按照个人和单位分组汇总 type = 1为个人,type = 2为单位,这里仅为系统外数据
         DataSet groupDataSetOut = groupCalPersonDetailOut(outsidePersonDetail);
-
         // 再join
-        DataSet finalDataSet = joinFinallyDataSet(groupDataSet, groupDataSetOut);
+        DataSet finalDataSet = joinFinallyDataSet(dataSetMap, groupDataSet, groupDataSetOut);
         return finalDataSet;
     }
 
@@ -82,15 +84,55 @@ public class DataComparisonQueryService {
         return cols;
     }
 
+    /**
+     * 根据任务ID获取所有核算人员+险种的笛卡尔积
+     * @return
+     */
+    public DataSet queryAllCalPersonAndWelfareTypeByTaskId(List<Long> taskIds) {
+        // 获取核算任务下的所有人
+        QFilter filter = new QFilter("sinsurtask.id", QCP.in, taskIds);
+        String selectFields = "welfarepayer.id as welfarepayer, empnumberdb as empnumber,namedb as empname,percre.number as empidcard,employee.id as employee, '1' as flag ";
+        DataSet dataSet1 = SitConstant.CALPERSON_HELPER.queryDataSet("queryAllCalPerson", selectFields, filter.toArray());
+
+        // 获取所有险种
+        DataSet dataSet2 = getWelfAreTypeIdsDataSet();
+
+        DataSet dataSetMap = dataSet1.fullJoin(dataSet2).on("flag", "flag").select(new String[]{"welfarepayer", "empnumber", "empname", "empidcard", "employee"}, new String[]{"id as welfaretypeid"}).finish();
+        return dataSetMap;
+    }
+
+
+
+
     /**
      * 获取人员计算详情数据-系统内数据
      * @param taskIds
      * @return
      */
     public DataSet queryCalPersonDetail(List<Long> taskIds) {
+        List<Long> welfareTypeIds = getWelfAreTypeIds();
+        return ReportUtils.queryCalPersonDetail(welfareTypeIds, taskIds);
+    }
+
+
+    /**
+     * 获取险种ID
+     * @return
+     */
+    public List<Long> getWelfAreTypeIds() {
         DynamicObjectCollection welfareTypeCols = (DynamicObjectCollection)model.getValue("nckd_welfaretype");
         List<Long> welfareTypeIds = welfareTypeCols.stream().map(obj -> obj.getDynamicObject("fbasedataid").getLong("id")).collect(Collectors.toList());
-        return ReportUtils.queryCalPersonDetail(welfareTypeIds, taskIds);
+        return welfareTypeIds;
+    }
+
+    /**
+     * 返回险种的DataSet
+     * @return
+     */
+    public DataSet getWelfAreTypeIdsDataSet() {
+        List<Long> welfareTypeIds = getWelfAreTypeIds();
+        QFilter filter = new QFilter("id", QCP.in, welfareTypeIds);
+        return SitConstant.WELFARETYPE_HELPER.queryDataSet("queryWelfAreType", "id, '1' as flag", filter.toArray());
     }
 
     /**
@@ -143,10 +185,16 @@ public class DataComparisonQueryService {
         return dataSet;
     }
 
-    public DataSet joinFinallyDataSet (DataSet groupDataSet, DataSet groupDataSetOut) {
-        DataSet finalDataSet = groupDataSet.join(groupDataSetOut, JoinType.LEFT).on("welfarepayer", "welfarepayer").on("welfaretypeid", "welfaretypeid").
+    public DataSet joinFinallyDataSet (DataSet dataSetMap, DataSet groupDataSet, DataSet groupDataSetOut) {
+        // 中间过度用DataSet
+        DataSet midDataSet = dataSetMap.leftJoin(groupDataSet).on("welfarepayer", "welfarepayer").on("welfaretypeid", "welfaretypeid").
+                on("empname", "empname").
+                on("empidcard", "empidcard").select(mapFields, leftFields).finish();
+        // 最终返回DataSet
+        DataSet finalDataSet = midDataSet.leftJoin(groupDataSetOut).on("welfarepayer", "welfarepayer").on("welfaretypeid", "welfaretypeid").
                 on("empname", "empname").
-                on("empidcard", "empidcard").select(leftFields, rightFields).finish();
+                on("empidcard", "empidcard").select(midDataSet.getRowMeta().getFieldNames(), rightFields).finish();
+
         return finalDataSet;
     }
 

+ 4 - 0
code/swc/nckd-jxccl-swc/src/main/java/nckd/jxccl/sit/hcsi/common/constant/SitConstant.java

@@ -7,6 +7,10 @@ public class SitConstant {
     public static final HRBaseServiceHelper SINSURFILE_HELPER = new HRBaseServiceHelper("hcsi_sinsurfile");
     /*业务项目*/
     public static final HRBaseServiceHelper BIZITEM_HELPER = new HRBaseServiceHelper("hsbs_bizitem");
+    /* 社保核算任务-明细人员 */
+    public static final HRBaseServiceHelper CALPERSON_HELPER = new HRBaseServiceHelper("hcsi_calperson");
+    /* 险种 */
+    public static final HRBaseServiceHelper WELFARETYPE_HELPER = new HRBaseServiceHelper("sitbs_welfaretype");
     /*薪酬年收入统计单*/
     public static final HRBaseServiceHelper SALINCOMEBILL_HELPER = new HRBaseServiceHelper("nckd_salannualincomebill");
     /*查询字段*/

+ 12 - 5
code/swc/nckd-jxccl-swc/src/main/java/nckd/jxccl/sit/hcsi/formplugin/web/datacomparison/DetailCompareBillEdit.java

@@ -257,17 +257,24 @@ public class DetailCompareBillEdit extends AbstractFormPlugin {
         while(dataSet.hasNext()) {
             Row rowData = dataSet.next();
             List<String> excludeFields = Arrays.asList("type");
+
+            // 比对,单位/个人缴费金额系统内<>单位/个人缴费金额系统外的话,比对结果=不一致
+            BigDecimal value1 = rowData.getBigDecimal("companysysvalue") == null ? BigDecimal.ZERO : rowData.getBigDecimal("companysysvalue");
+            BigDecimal value2 = rowData.getBigDecimal("companyoutvalue") == null ? BigDecimal.ZERO : rowData.getBigDecimal("companyoutvalue");
+            BigDecimal value3 = rowData.getBigDecimal("personsysvalue") == null ? BigDecimal.ZERO : rowData.getBigDecimal("personsysvalue");
+            BigDecimal value4 = rowData.getBigDecimal("personoutvalue") == null ? BigDecimal.ZERO : rowData.getBigDecimal("personoutvalue");
+
+            if(value1.add(value2).add(value3).add(value4).compareTo(BigDecimal.ZERO) == 0) {
+                continue;
+            }
+
             // 赋值
             for(String columnKey : columnName) {
                 if(excludeFields.contains(columnKey))
                     continue;
                 setter.set(columnKey, rowData.get(columnKey), rowIndex);
             }
-            // 比对,单位/个人缴费金额系统内<>单位/个人缴费金额系统外的话,比对结果=不一致
-            BigDecimal value1 = rowData.getBigDecimal("companysysvalue") == null ? BigDecimal.ZERO : rowData.getBigDecimal("companysysvalue");
-            BigDecimal value2 = rowData.getBigDecimal("companyoutvalue") == null ? BigDecimal.ZERO : rowData.getBigDecimal("companyoutvalue");
-            BigDecimal value3 = rowData.getBigDecimal("personsysvalue") == null ? BigDecimal.ZERO : rowData.getBigDecimal("personsysvalue");
-            BigDecimal value4 = rowData.getBigDecimal("personoutvalue") == null ? BigDecimal.ZERO : rowData.getBigDecimal("personoutvalue");
+
 
             if(value1.compareTo(value2) != 0 || value3.compareTo(value4) != 0) {
                 setter.set("compareresult", "C", rowIndex);