Jelajahi Sumber

收支明细功能调整

lipf 4 minggu lalu
induk
melakukan
8057f2c78f

+ 3 - 1
.gitignore

@@ -83,4 +83,6 @@ tenant/insurance/quotation-yongcheng/outPath/
 tenant/insurance/quotation-zhongan/outPath/
 tenant/insurance/quotation-zhongmei/outPath/
 tenant/insurance/quotation-zijin/outPath/
-tenant/organization/outPath/
+tenant/organization/outPath/
+
+.reasonix

+ 141 - 75
tenant/organization/src/main/java/com/jzg/organization/service/impl/SysUserAccountServiceImpl.java

@@ -18,6 +18,7 @@ import com.jzg.organization.mapper.SysAmountAuditingMapper;
 import com.jzg.organization.mapper.SysUserAccountIncomeLogMapper;
 import com.jzg.organization.mapper.SysUserAccountMapper;
 import com.jzg.organization.service.*;
+import org.jetbrains.annotations.NotNull;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.BeanUtils;
@@ -279,84 +280,17 @@ public class SysUserAccountServiceImpl extends ServiceImpl<SysUserAccountMapper,
      */
     @Override
     public List<IncomeAndExpenseVo> getIncomeAndExpense(IncomeAndExpenseParam param){
-
         log.info("查询收支明细记录:param=[{}]", JSONUtil.toJsonStr(param));
         String key = this.populateParam(param);
-        //List<IncomeAndExpenseList> recordsWithOutParam = sysAmountAuditingService.getIncomeAndExpense(new IncomeAndExpenseParam(param.getUserId(),param.getSystemCode()));
         List<IncomeAndExpenseList> allRecords = sysAmountAuditingService.getIncomeAndExpense(param);
-        allRecords = allRecords.stream().peek(action->{
-            if("0".equals(action.getStatus())){
-                action.setRemark("提现审核中");
-            }
-            List<ChangeLogDetail> stepList = new ArrayList<>();
-            if("0".equals(action.getAuditingStatus())){
-                stepList.add(new ChangeLogDetail("提交提现申请",action.getCreateTime(),true, null));
-                stepList.add(new ChangeLogDetail("财务人员审核",null, null,null));
-                stepList.add(new ChangeLogDetail("财务人员打款", null, null, null));
-            }else if(StrUtil.isEmpty(action.getAuditingStatus())){
-                if("1".equals(action.getStatus())){
-                    if("1".equals(action.getIncomeAndExpense())){
-                        stepList.add(new ChangeLogDetail("提交提现申请",action.getCreateTime(),true, null));
-                        stepList.add(new ChangeLogDetail("财务人员审核",action.getPaymentTime(), true,null));
-                        stepList.add(new ChangeLogDetail("财务人员打款", action.getPaymentTime(), true, null));
-                    }
-                    if("0".equals(action.getIncomeAndExpense())){
-                        // 保费收入
-                        stepList.add(new ChangeLogDetail("费用审核通过",action.getCreateTime(),true, null));
-                        stepList.add(new ChangeLogDetail());
-                        stepList.add(new ChangeLogDetail());
-                    }
-                }else if("2".equals(action.getStatus())){
-                    stepList.add(new ChangeLogDetail("提交提现申请",action.getCreateTime(),true, null));
-                    stepList.add(new ChangeLogDetail("财务人员审核",action.getPaymentTime(), true,null));
-                    stepList.add(new ChangeLogDetail("财务审核不通过", action.getRejectTime(), false, null));
-                }
-            }
-            action.setStepList(stepList);
-
-        }).toList();
-        allRecords= new ArrayList<>(allRecords);
+        allRecords= new ArrayList<>(fillProcessDtls(allRecords));
         // 排序
         allRecords.sort((a, b) -> {
             if (a.getCreateTime() == null) return 1;
             if (b.getCreateTime() == null) return -1;
             return b.getCreateTime().compareTo(a.getCreateTime());
         });
-        // 按月份分组统计
-        Map<String, IncomeAndExpenseVo.IncomeAndExpense> monthSummaryMap = new TreeMap<>(Collections.reverseOrder());
-        if(CollUtil.isEmpty(allRecords)){
-            IncomeAndExpenseVo.IncomeAndExpense summary = monthSummaryMap.get(key);
-            summary = new IncomeAndExpenseVo.IncomeAndExpense();
-            summary.setMonth(key);
-            summary.setIncome(BigDecimal.ZERO);
-            summary.setExpense(BigDecimal.ZERO);
-            summary.setBalance(BigDecimal.ZERO);
-            monthSummaryMap.put(key, summary);
-        }
-        for (IncomeAndExpenseList record : allRecords) {
-            if (record.getCreateTime() == null) continue;
-            // 获取或创建月度汇总对象
-            IncomeAndExpenseVo.IncomeAndExpense summary = monthSummaryMap.get(key);
-            if (summary == null) {
-                summary = new IncomeAndExpenseVo.IncomeAndExpense();
-                summary.setMonth(key);
-                summary.setIncome(BigDecimal.ZERO);
-                summary.setExpense(BigDecimal.ZERO);
-                summary.setBalance(BigDecimal.ZERO);
-                monthSummaryMap.put(key, summary);
-            }
-            // 更新收入或支出
-            if ("0".equals(record.getIncomeAndExpense())) {
-                // 收入
-                summary.setIncome(BigDecimalUtil.add(summary.getIncome(),record.getAmount()));
-            } else if("1".equals(record.getIncomeAndExpense()) && !"2".equals(record.getStatus())){
-                // 支出, 并且不是审核驳回的数据
-                summary.setExpense(BigDecimalUtil.add(summary.getExpense(),record.getAmount()));
-            }
-            // 计算余额(收入 - 支出)
-            summary.setBalance(summary.getIncome().subtract(summary.getExpense()));
-        }
-
+        Map<String, IncomeAndExpenseVo.IncomeAndExpense> monthSummaryMap = this.calSummaryData(allRecords, key);
         // 如果指定了月份筛选,只返回该月的数据
         if (param.getMonth() != null && !param.getMonth().isEmpty()) {
             List<IncomeAndExpenseVo> result = new ArrayList<>();
@@ -364,11 +298,20 @@ public class SysUserAccountServiceImpl extends ServiceImpl<SysUserAccountMapper,
             IncomeAndExpenseVo.IncomeAndExpense summary = monthSummaryMap.get(param.getMonth());
             if (summary != null) {
                 vo.setIncomeAndExpense(summary);
-
                 // 筛选当前月份的明细记录
                 List<IncomeAndExpenseVo.IncomeAndExpenseList> monthRecords = allRecords.stream()
                         .filter(record -> param.getMonth().equals(record.getCreateTime().format(DateTimeFormatter.ofPattern("yyyy-MM"))))
-                        .map(action->{
+                        .filter(action->{
+                            if(StrUtil.isNotEmpty(param.getStatus())){
+                                return param.getStatus().equals(action.getStatus());
+                            }
+                            return true;}
+                        ).filter(action->{
+                            if(StrUtil.isNotEmpty(param.getIncomeAndExpense())){
+                                return param.getIncomeAndExpense().equals(action.getIncomeAndExpense());
+                            }
+                            return true;
+                        }).map(action->{
                             IncomeAndExpenseVo.IncomeAndExpenseList a = new IncomeAndExpenseVo.IncomeAndExpenseList();
                             BeanUtils.copyProperties(action,a);
                             return a;
@@ -385,7 +328,6 @@ public class SysUserAccountServiceImpl extends ServiceImpl<SysUserAccountMapper,
         for (Map.Entry<String, IncomeAndExpenseVo.IncomeAndExpense> entry : monthSummaryMap.entrySet()) {
             IncomeAndExpenseVo vo = new IncomeAndExpenseVo();
             vo.setIncomeAndExpense(entry.getValue());
-
             // 筛选当前月份的明细记录
             List<IncomeAndExpenseVo.IncomeAndExpenseList> monthRecords = allRecords.stream()
                     .filter(record -> {
@@ -394,7 +336,17 @@ public class SysUserAccountServiceImpl extends ServiceImpl<SysUserAccountMapper,
                         }
                         return entry.getKey().equals(record.getCreateTime().format(DateTimeFormatter.ofPattern("yyyy-MM")));
                     })
-                    .map(action->{
+                    .filter(action->{
+                        if(StrUtil.isNotEmpty(param.getStatus())){
+                            return param.getStatus().equals(action.getStatus());
+                        }
+                        return true;}
+                    ).filter(action->{
+                        if(StrUtil.isNotEmpty(param.getIncomeAndExpense())){
+                            return param.getIncomeAndExpense().equals(action.getIncomeAndExpense());
+                        }
+                        return true;
+                    }).map(action->{
                         IncomeAndExpenseVo.IncomeAndExpenseList a = new IncomeAndExpenseVo.IncomeAndExpenseList();
                         BeanUtils.copyProperties(action,a);
                         return a;
@@ -406,6 +358,100 @@ public class SysUserAccountServiceImpl extends ServiceImpl<SysUserAccountMapper,
         return result;
     }
 
+    /**
+     * 计算汇总数据
+     *
+     * @author lipf
+     * @date 2026/8/11 14:43
+     */
+    @NotNull
+    private Map<String, IncomeAndExpenseVo.IncomeAndExpense> calSummaryData(List<IncomeAndExpenseList> allRecords, String key) {
+        // 按月份分组统计
+        Map<String, IncomeAndExpenseVo.IncomeAndExpense> monthSummaryMap = new TreeMap<>(Collections.reverseOrder());
+        if(CollUtil.isEmpty(allRecords)){
+            IncomeAndExpenseVo.IncomeAndExpense summary = this.initSummary(key);
+            monthSummaryMap.put(key, summary);
+        }
+        for (IncomeAndExpenseList record : allRecords) {
+            if (record.getCreateTime() == null) continue;
+            // 获取或创建月度汇总对象
+            IncomeAndExpenseVo.IncomeAndExpense summary = monthSummaryMap.get(key);
+            if (summary == null) {
+                summary = this.initSummary(key);
+                monthSummaryMap.put(key, summary);
+            }
+            // 更新收入或支出
+            if ("0".equals(record.getIncomeAndExpense())) {
+                // 收入
+                summary.setIncome(BigDecimalUtil.add(summary.getIncome(),record.getAmount()));
+            } else if("1".equals(record.getIncomeAndExpense()) && !"2".equals(record.getStatus())){
+                // 支出, 并且不是审核驳回的数据
+                summary.setExpense(BigDecimalUtil.add(summary.getExpense(),record.getAmount()));
+            }
+            // 计算余额(收入 - 支出)
+            summary.setBalance(summary.getIncome().subtract(summary.getExpense()));
+        }
+        return monthSummaryMap;
+    }
+
+    /**
+     * 初始化汇总数据
+     *
+     * @param key 月份
+     * @author lipf
+     * @date 2026/8/11 14:41
+     */
+    private  IncomeAndExpenseVo.IncomeAndExpense initSummary(String key) {
+        IncomeAndExpenseVo.IncomeAndExpense summary = new IncomeAndExpenseVo.IncomeAndExpense();
+        summary.setMonth(key);
+        summary.setIncome(BigDecimal.ZERO);
+        summary.setExpense(BigDecimal.ZERO);
+        summary.setBalance(BigDecimal.ZERO);
+        return summary;
+    }
+
+    /**
+     * 填充处理进度
+     *
+     * @param allRecords 要处理的数据
+     * @author lipf
+     * @date 2026/8/11 14:37
+     */
+    @NotNull
+    private static List<IncomeAndExpenseList> fillProcessDtls(List<IncomeAndExpenseList> allRecords) {
+        allRecords = allRecords.stream().peek(action->{
+            if("0".equals(action.getStatus())){
+                action.setRemark("提现审核中");
+            }
+            List<ChangeLogDetail> stepList = new ArrayList<>();
+            if("0".equals(action.getAuditingStatus())){
+                stepList.add(new ChangeLogDetail("提交提现申请",action.getCreateTime(),true, null));
+                stepList.add(new ChangeLogDetail("财务人员审核",null, null,null));
+                stepList.add(new ChangeLogDetail("财务人员打款", null, null, null));
+            }else if(StrUtil.isEmpty(action.getAuditingStatus())){
+                if("1".equals(action.getStatus())){
+                    if("1".equals(action.getIncomeAndExpense())){
+                        stepList.add(new ChangeLogDetail("提交提现申请",action.getCreateTime(),true, null));
+                        stepList.add(new ChangeLogDetail("财务人员审核",action.getPaymentTime(), true,null));
+                        stepList.add(new ChangeLogDetail("财务人员打款", action.getPaymentTime(), true, null));
+                    }
+                    if("0".equals(action.getIncomeAndExpense())){
+                        // 保费收入
+                        stepList.add(new ChangeLogDetail("费用审核通过",action.getCreateTime(),true, null));
+                        stepList.add(new ChangeLogDetail());
+                        stepList.add(new ChangeLogDetail());
+                    }
+                }else if("2".equals(action.getStatus())){
+                    stepList.add(new ChangeLogDetail("提交提现申请",action.getCreateTime(),true, null));
+                    stepList.add(new ChangeLogDetail("财务人员审核",action.getPaymentTime(), true,null));
+                    stepList.add(new ChangeLogDetail("财务审核不通过", action.getRejectTime(), false, null));
+                }
+            }
+            action.setStepList(stepList);
+        }).toList();
+        return allRecords;
+    }
+
     /**
      * 对查询参数进行预处理
      *
@@ -653,7 +699,17 @@ public class SysUserAccountServiceImpl extends ServiceImpl<SysUserAccountMapper,
                 
                 // 筛选当前月份的明细记录
                 List<IncomeAndExpenseVo.IncomeAndExpenseList> monthRecords = allRecords.stream()
-                        .filter(record -> param.getMonth().equals(record.getCreateTime().format(DateTimeFormatter.ofPattern("yyyy-MM"))))
+                        .filter(action->{
+                            if(StrUtil.isNotEmpty(param.getStatus())){
+                                return param.getStatus().equals(action.getStatus());
+                            }
+                            return true;}
+                        ).filter(action->{
+                            if(StrUtil.isNotEmpty(param.getIncomeAndExpense())){
+                                return param.getIncomeAndExpense().equals(action.getIncomeAndExpense());
+                            }
+                            return true;
+                        }).filter(record -> param.getMonth().equals(record.getCreateTime().format(DateTimeFormatter.ofPattern("yyyy-MM"))))
                         .collect(Collectors.toList());
                 vo.setIncomeAndExpenseList(monthRecords);
                 result.add(vo);
@@ -669,7 +725,17 @@ public class SysUserAccountServiceImpl extends ServiceImpl<SysUserAccountMapper,
 
             // 筛选当前月份的明细记录
             List<IncomeAndExpenseVo.IncomeAndExpenseList> monthRecords = allRecords.stream()
-                    .filter(record -> entry.getKey().equals(record.getCreateTime().format(DateTimeFormatter.ofPattern("yyyy-MM"))))
+                    .filter(action->{
+                        if(StrUtil.isNotEmpty(param.getStatus())){
+                            return param.getStatus().equals(action.getStatus());
+                        }
+                        return true;}
+                    ).filter(action->{
+                        if(StrUtil.isNotEmpty(param.getIncomeAndExpense())){
+                            return param.getIncomeAndExpense().equals(action.getIncomeAndExpense());
+                        }
+                        return true;
+                    }).filter(record -> entry.getKey().equals(record.getCreateTime().format(DateTimeFormatter.ofPattern("yyyy-MM"))))
                     .collect(Collectors.toList());
             vo.setIncomeAndExpenseList(monthRecords);
             result.add(vo);

+ 6 - 6
tenant/organization/src/main/resources/mapper/SysAmountAuditingMapper.xml

@@ -264,6 +264,12 @@
         select sum(COALESCE(saa.amount, 0)) as payingAmountSum from sys_amount_auditing saa where saa.auditing_status = 0
     </select>
     <!-- 查询收支明细 2026年7月20日15:47:35 -->
+    <!--            <if test="status != null and status != ''">-->
+    <!--                and a.status= #{status}-->
+    <!--            </if>-->
+    <!--            <if test="incomeAndExpense != null and incomeAndExpense != ''">-->
+    <!--                and a.incomeAndExpense = #{incomeAndExpense}-->
+    <!--            </if>-->
     <select id="getIncomeAndExpense"
             resultType="com.jzg.commons.entity.vo.IncomeAndExpenseList">
         select
@@ -336,12 +342,6 @@
         and saa.auditing_status = 0  ) as a
         <where>
             a.user_id = #{userId}
-            <if test="status != null and status != ''">
-                and a.status= #{status}
-            </if>
-            <if test="incomeAndExpense != null and incomeAndExpense != ''">
-                and a.incomeAndExpense = #{incomeAndExpense}
-            </if>
             <if test="createTimeStart != null and createTimeStart != ''">
                 and a.create_time &gt;= #{createTimeStart}
             </if>