Просмотр исходного кода

Merge remote-tracking branch 'origin/dev_jzg_lipf_v20260622' into dev_jzg_lipf_v20260622

jiakai 2 месяцев назад
Родитель
Сommit
08adba03e3

+ 6 - 0
commons/src/main/java/com/jzg/commons/entity/dto/IncomeAndExpenseParam.java

@@ -25,4 +25,10 @@ public class IncomeAndExpenseParam {
     @Schema(description = "月份筛选 格式:yyyy-MM,例如:2026-03")
     private String month;
 
+    @Schema(description = "租户代码")
+    private String systemCode;
+
+    @Schema(description = "用户序号")
+    private String userId;
+
 }

+ 41 - 0
commons/src/main/java/com/jzg/commons/entity/vo/IncomeAndExpenseList.java

@@ -0,0 +1,41 @@
+package com.jzg.commons.entity.vo;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+import java.math.BigDecimal;
+import java.time.LocalDateTime;
+
+@Data
+public class IncomeAndExpenseList {
+
+    @Schema(description = "状态 0-收入 1-支出")
+    private String incomeAndExpense;
+
+    @Schema(description = "金额")
+    private BigDecimal amount;
+
+    @Schema(description = "时间")
+    private LocalDateTime createTime;
+
+    @Schema(description = "备注")
+    private String remark;
+
+    @Schema(description = "车牌号")
+    private String licenseNo;
+
+    @Schema(description = "审核状态 0-待审核 1-审核通过 2-审核驳回")
+    private String status;
+
+    @Schema(description = "银行名称")
+    private String bankName;
+
+    @Schema(description = "用户名")
+    private String userName;
+
+    @Schema(description = "银行卡号")
+    private String bankCardNum;
+
+    @Schema(description = "驳回原因")
+    private String rejectReason;
+}

+ 1 - 0
tenant/organization/src/main/java/com/jzg/organization/controller/UserAccountController.java

@@ -98,6 +98,7 @@ public class UserAccountController {
     @PostMapping("/getIncomeAndExpense")
     public HttpResult<List<IncomeAndExpenseVo>> getIncomeAndExpense(@RequestBody IncomeAndExpenseParam param){
         return HttpResult.ok(userAccountService.getIncomeAndExpense(param));
+        //return HttpResult.ok(userAccountService.getIncomeAndExpenseOld(param));
     }
 
     @Operation(summary = "添加用户钱包账户记录")

+ 10 - 0
tenant/organization/src/main/java/com/jzg/organization/mapper/SysAmountAuditingMapper.java

@@ -3,8 +3,10 @@ package com.jzg.organization.mapper;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.jzg.commons.entity.dto.AmountAuditParam;
+import com.jzg.commons.entity.dto.IncomeAndExpenseParam;
 import com.jzg.commons.entity.po.SysAmountAuditing;
 import com.jzg.commons.entity.vo.AmountAuditVo;
+import com.jzg.commons.entity.vo.IncomeAndExpenseList;
 import org.apache.ibatis.annotations.Param;
 
 import java.math.BigDecimal;
@@ -68,6 +70,14 @@ public interface SysAmountAuditingMapper extends BaseMapper<SysAmountAuditing> {
      * @date 2026/7/17 10:24
      */
     BigDecimal queryPayingAmountSum();
+
+    /**
+     * 查询收支明细
+     *
+     * @author lipf
+     * @date 2026/7/20 15:46
+     */
+    List<IncomeAndExpenseList> getIncomeAndExpense(IncomeAndExpenseParam param);
 }
 
 

+ 11 - 1
tenant/organization/src/main/java/com/jzg/organization/service/SysAmountAuditingService.java

@@ -6,8 +6,9 @@ import com.jzg.commons.core.page.HttpResult;
 import com.jzg.commons.entity.dto.*;
 import com.jzg.commons.entity.po.SysAmountAuditing;
 import com.jzg.commons.entity.vo.AmountAuditVo;
-
+import com.jzg.commons.entity.vo.IncomeAndExpenseList;
 import java.math.BigDecimal;
+import java.util.List;
 
 /**
 * @author dongxin
@@ -109,4 +110,13 @@ public interface SysAmountAuditingService extends IService<SysAmountAuditing> {
      * @date 2026/6/17 9:19
      */
     String exportMyPayment(AmountAuditParam param);
+
+    /**
+     * 查询收支明细
+     *
+     * @param param 查询条件 间(月份/时间段), 收支类型(全部/收入/支出) , 状态(全部/待审核/审核通过/审核驳回)
+     * @author lipf
+     * @date 2026/7/20 15:40
+     */
+    List<IncomeAndExpenseList> getIncomeAndExpense(IncomeAndExpenseParam param);
 }

+ 16 - 1
tenant/organization/src/main/java/com/jzg/organization/service/SysUserAccountService.java

@@ -51,9 +51,24 @@ public interface SysUserAccountService extends IService<SysUserAccount> {
      */
     SysUserWalletVo userWallet();
 
-
+    /**
+     * 查询业务员的收支记录
+     *
+     * @param param 时间(月份/时间段), 收支类型(全部/收入/支出) , 状态(全部/待审核/审核通过/审核驳回)
+     * @author lipf
+     * @date 2026/7/20 10:03
+     */
     List<IncomeAndExpenseVo> getIncomeAndExpense(IncomeAndExpenseParam param);
 
 
+    /**
+     * 查询业务员的收支记录 为了查询接口时使用
+     *
+     * @author lipf
+     * @date 2026/7/20 15:01
+     */
+    @Deprecated(since = "2026年7月20日15:02:00")
+    public List<IncomeAndExpenseVo> getIncomeAndExpenseOld(IncomeAndExpenseParam param);
+
 
 }

+ 16 - 0
tenant/organization/src/main/java/com/jzg/organization/service/impl/SysAmountAuditingServiceImpl.java

@@ -18,6 +18,7 @@ import com.jzg.commons.entity.po.SysUserAccount;
 import com.jzg.commons.entity.po.SysUserJzgInfo;
 import com.jzg.commons.entity.po.SysUserJzgInfoBankCard;
 import com.jzg.commons.entity.vo.AmountAuditVo;
+import com.jzg.commons.entity.vo.IncomeAndExpenseList;
 import com.jzg.commons.exception.SystemException;
 import com.jzg.commons.util.AssertionUtils;
 import com.jzg.commons.util.BigDecimalUtil;
@@ -504,6 +505,21 @@ public class SysAmountAuditingServiceImpl extends ServiceImpl<SysAmountAuditingM
                 "业务员收支明细-导出-"+suffix + Instant.now()
         );
     }
+
+    /**
+     * 查询收支明细
+     *
+     * @param param 查询条件 间(月份/时间段), 收支类型(全部/收入/支出) , 状态(全部/待审核/审核通过/审核驳回)
+     * @author lipf
+     * @date 2026/7/20 15:40
+     */
+    @Override
+    public List<IncomeAndExpenseList> getIncomeAndExpense(IncomeAndExpenseParam param) {
+        log.info("查询收支明细queryIncomeANdExpense:param=[{}]", JSONUtil.toJsonStr(param));
+        List<IncomeAndExpenseList>  incomeAndExpenseLists =  baseMapper.getIncomeAndExpense(param);
+        log.info("查询收支明细queryIncomeANdExpense:param=[{}],incomeAndExpenseLists.size()=[{}]",JSONUtil.toJsonStr(param), CollUtil.size(incomeAndExpenseLists));
+        return incomeAndExpenseLists;
+    }
 }
 
 

+ 124 - 5
tenant/organization/src/main/java/com/jzg/organization/service/impl/SysUserAccountServiceImpl.java

@@ -10,10 +10,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.jzg.commons.core.base.BaseController;
 import com.jzg.commons.entity.dto.*;
 import com.jzg.commons.entity.po.*;
-import com.jzg.commons.entity.vo.IncomeAndExpenseVo;
-import com.jzg.commons.entity.vo.SysUserAccountVo;
-import com.jzg.commons.entity.vo.SysUserWalletVo;
-import com.jzg.commons.entity.vo.UserAccountStatisVo;
+import com.jzg.commons.entity.vo.*;
 import com.jzg.commons.util.BigDecimalUtil;
 import com.jzg.organization.client.QuoteClient;
 import com.jzg.organization.mapper.SysAmountAuditingMapper;
@@ -21,6 +18,7 @@ import com.jzg.organization.mapper.SysUserAccountMapper;
 import com.jzg.organization.service.*;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -251,8 +249,129 @@ public class SysUserAccountServiceImpl extends ServiceImpl<SysUserAccountMapper,
         return sysUserWalletVo;
     }
 
+    /**
+     * 查询业务员的收支记录
+     *
+     * @param param 时间(月份/时间段), 收支类型(全部/收入/支出) , 状态(全部/待审核/审核通过/审核驳回)
+     * @author lipf
+     * @date 2026/7/20 10:03
+     */
+    @Override
+    public List<IncomeAndExpenseVo> getIncomeAndExpense(IncomeAndExpenseParam param){
+        log.info("查询收支明细记录:param=[{}]", JSONUtil.toJsonStr(param));
+        // 处理月份筛选参数
+        String createTimeStart = param.getCreateTimeStart();
+        String createTimeEnd = param.getCreateTimeEnd();
+        String userId = baseController.getUserId();
+        param.setUserId(userId);
+        param.setSystemCode(baseController.getSystemCode());
+        if (param.getMonth() != null && !param.getMonth().isEmpty()) {
+            // 如果传入了月份参数,计算该月的开始和结束时间
+            String monthStr = param.getMonth();
+            DateTimeFormatter monthFormatter = DateTimeFormatter.ofPattern("yyyy-MM");
+            YearMonth yearMonth = YearMonth.parse(monthStr, monthFormatter);
+            LocalDateTime monthStart = yearMonth.atDay(1).atStartOfDay();
+            LocalDateTime monthEnd = yearMonth.atEndOfMonth().atTime(23, 59, 59, 999999999);
+
+            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+            createTimeStart = monthStart.format(formatter);
+            createTimeEnd = monthEnd.format(formatter);
+            param.setCreateTimeStart(createTimeStart);
+            param.setCreateTimeEnd(createTimeEnd);
+        }
+
+        List<IncomeAndExpenseList> allRecords = sysAmountAuditingService.getIncomeAndExpense(param);
+        // 排序
+        allRecords.sort((a, b) -> {
+            if (a.getCreateTime() == null) return 1;
+            if (b.getCreateTime() == null) return -1;
+            return b.getCreateTime().compareTo(a.getCreateTime());
+        });
+
+        // 收支状态筛选(在排序后、分组前进行)
+//        if (param.getIncomeAndExpense() != null && !param.getIncomeAndExpense().isEmpty()) {
+//            allRecords = allRecords.stream()
+//                    .filter(record -> param.getIncomeAndExpense().equals(record.getIncomeAndExpense()))
+//                    .collect(Collectors.toList());
+//        }
+
+        // 按月份分组统计
+        Map<String, IncomeAndExpenseVo.IncomeAndExpense> monthSummaryMap = new TreeMap<>(Collections.reverseOrder());
+        for (IncomeAndExpenseList record : allRecords) {
+            if (record.getCreateTime() == null) continue;
+            // 获取月份(格式:yyyy-MM)
+            String month = record.getCreateTime().format(DateTimeFormatter.ofPattern("yyyy-MM"));
+
+            // 获取或创建月度汇总对象
+            IncomeAndExpenseVo.IncomeAndExpense summary = monthSummaryMap.get(month);
+            if (summary == null) {
+                summary = new IncomeAndExpenseVo.IncomeAndExpense();
+                summary.setMonth(month);
+                summary.setIncome(BigDecimal.ZERO);
+                summary.setExpense(BigDecimal.ZERO);
+                summary.setBalance(BigDecimal.ZERO);
+                monthSummaryMap.put(month, summary);
+            }
+
+            // 更新收入或支出
+            if ("0".equals(record.getIncomeAndExpense())) {
+                // 收入
+                summary.setIncome(BigDecimalUtil.add(summary.getIncome(),record.getAmount()));
+            } else {
+                // 支出
+                summary.setExpense(BigDecimalUtil.add(summary.getExpense(),record.getAmount()));
+            }
+
+            // 计算余额(收入 - 支出)
+            summary.setBalance(summary.getIncome().subtract(summary.getExpense()));
+        }
+
+        // 如果指定了月份筛选,只返回该月的数据
+        if (param.getMonth() != null && !param.getMonth().isEmpty()) {
+            List<IncomeAndExpenseVo> result = new ArrayList<>();
+            IncomeAndExpenseVo vo = new IncomeAndExpenseVo();
+            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->{
+                            IncomeAndExpenseVo.IncomeAndExpenseList a = new IncomeAndExpenseVo.IncomeAndExpenseList();
+                            BeanUtils.copyProperties(action,a);
+                            return a;
+                        })
+                        .collect(Collectors.toList());
+                vo.setIncomeAndExpenseList(monthRecords);
+                result.add(vo);
+            }
+            return result;
+        }
+
+        // 构建返回结果
+        List<IncomeAndExpenseVo> result = new ArrayList<>();
+        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 -> entry.getKey().equals(record.getCreateTime().format(DateTimeFormatter.ofPattern("yyyy-MM"))))
+                    .map(action->{
+                        IncomeAndExpenseVo.IncomeAndExpenseList a = new IncomeAndExpenseVo.IncomeAndExpenseList();
+                        BeanUtils.copyProperties(action,a);
+                        return a;
+                    }).collect(Collectors.toList());
+            vo.setIncomeAndExpenseList(monthRecords);
+            result.add(vo);
+        }
+        Collections.reverse(result);
+        return result;
+    }
+
     @Override
-    public List<IncomeAndExpenseVo> getIncomeAndExpense(IncomeAndExpenseParam param) {
+    public List<IncomeAndExpenseVo> getIncomeAndExpenseOld(IncomeAndExpenseParam param) {
         log.info("查询收支明细记录:param=[{}]", JSONUtil.toJsonStr(param));
         // 获取个人中心信息
         String mobile = baseController.getUserName();

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

@@ -263,4 +263,85 @@
     <select id="queryPayingAmountSum" resultType="java.math.BigDecimal">
         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 -->
+    <select id="getIncomeAndExpense"
+            resultType="com.jzg.commons.entity.vo.IncomeAndExpenseList">
+        select
+        a.*
+        from
+        (
+        select
+        suacl.amount,
+        CASE
+        WHEN suacl.amount >= 0 THEN 0
+        -- 正数或0为收入
+        ELSE 1
+        -- 负数为支出
+        END AS incomeAndExpense,
+        '1' as status,
+        suacl.oper_type,
+        CASE
+        suacl.oper_type
+        WHEN 1 THEN '保单费用'
+        WHEN 2 THEN '保单提成'
+        WHEN 3 THEN '提现'
+        WHEN 4 THEN '提现驳回'
+        ELSE suacl.oper_type
+        END as remark,
+        saa.reject_reason,
+        saa.bank_name,
+        saa.bank_num as userName,
+        suacl.bank_card_no_to as bankCardNum,
+        suacl.user_id,
+        suacl.create_by,
+        suacl.create_time,
+        suacl.update_by,
+        suacl.update_time,
+        ioci.license_no
+        from
+        sys_user_account_change_log suacl
+        left join sys_amount_auditing saa on
+        suacl.related_amount_auditing_id = saa.id
+        left join ins_orders_car_info ioci on
+        suacl.related_order_id = ioci.order_no
+        where
+        suacl.system_code = #{systemCode}
+        union ALL
+        select
+        saa.amount,
+        1 as incomeAndExpense,
+        saa.auditing_status as status,
+        null as oper_type,
+        '拒绝付款' as remark,
+        saa.reject_reason,
+        saa.bank_name,
+        saa.bank_num as userName,
+        null as bankCardNum,
+        saa.user_id,
+        saa.create_by,
+        saa.create_time,
+        saa.update_by,
+        saa.update_time,
+        null as license_no
+        from
+        sys_amount_auditing saa
+        where
+        saa.system_code = #{systemCode}
+        and saa.auditing_status in (0, 2)  ) 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>
+            <if test="createTimeEnd != null and createTimeEnd != ''">
+                and a.create_time &lt;= #{createTimeEnd}
+            </if>
+        </where>
+    </select>
 </mapper>