From 25a80d5bb5769b03d164660c17e39cc302d14e65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=9D=BE?= <8605635+zhang3064194730@user.noreply.gitee.com> Date: Tue, 25 Mar 2025 00:37:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=9A=E5=91=98=E4=BD=99=E9=A2=9D=E6=98=8E?= =?UTF-8?q?=E7=BB=86=E8=8E=B7=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/admin/ShopUserController.java | 25 +++++++++++++-- .../account/service/ShopUserFlowService.java | 6 +++- .../account/mapper/ShopUserFlowMapper.java | 2 +- .../service/impl/ShopUserFlowServiceImpl.java | 32 +++++++++++++++++-- .../resources/mapper/ShopUserFlowMapper.xml | 7 ++++ 5 files changed, 66 insertions(+), 6 deletions(-) diff --git a/cash-api/account-server/src/main/java/com/czg/controller/admin/ShopUserController.java b/cash-api/account-server/src/main/java/com/czg/controller/admin/ShopUserController.java index 09ec4571..d054453e 100644 --- a/cash-api/account-server/src/main/java/com/czg/controller/admin/ShopUserController.java +++ b/cash-api/account-server/src/main/java/com/czg/controller/admin/ShopUserController.java @@ -16,9 +16,12 @@ import com.czg.utils.PageUtil; import com.mybatisflex.core.paginate.Page; import com.mybatisflex.core.query.QueryWrapper; import jakarta.annotation.Resource; +import jakarta.servlet.http.HttpServletResponse; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import java.io.IOException; + /** * 店铺用户管理 * @@ -49,6 +52,8 @@ public class ShopUserController { /** * 获取店铺用户充值记录 * @param userId 用户id + * @param startTime 开始时间 + * @param endTime 结束时间 * @param bizCode 充值类型 类型: * cashIn 现金充值, * wechatIn 微信小程序充值, @@ -64,8 +69,24 @@ public class ShopUserController { @SaAdminCheckPermission(value = "shopUser:flow", name = "店铺用户充值记录") @GetMapping("/flow") @SaStaffCheckPermission("yun_xu_guan_li_hui_yuan_xin_xi") - public CzgResult> flow(Integer userId, String bizCode) { - return CzgResult.success(shopUserFlowService.pageInfo(StpKit.USER.getShopId(), userId, bizCode)); + public CzgResult> flow(Integer userId, String bizCode, String startTime, String endTime) { + return CzgResult.success(shopUserFlowService.pageInfo(StpKit.USER.getShopId(), userId, bizCode, startTime, endTime)); + } + + /** + * 余额明细记录导出 + * @param userId 用户id + * @param bizCode 代码 + * @param startTime 开始时间 + * @param endTime 结束时间 + * @param response 响应 + * @throws IOException 异常 + */ + @SaAdminCheckPermission(value = "shopUser:flow:downLoad", name = "店铺用户充值记录导出") + @GetMapping("/flow/download") + @SaStaffCheckPermission("yun_xu_guan_li_hui_yuan_xin_xi") + public void flowDownload(Integer userId, String bizCode, String startTime, String endTime, HttpServletResponse response) throws IOException { + shopUserFlowService.flowDownload(StpKit.USER.getShopId(), userId, bizCode, startTime, endTime, response); } /** diff --git a/cash-common/cash-common-service/src/main/java/com/czg/account/service/ShopUserFlowService.java b/cash-common/cash-common-service/src/main/java/com/czg/account/service/ShopUserFlowService.java index 1ec5939f..a2918b1c 100644 --- a/cash-common/cash-common-service/src/main/java/com/czg/account/service/ShopUserFlowService.java +++ b/cash-common/cash-common-service/src/main/java/com/czg/account/service/ShopUserFlowService.java @@ -4,7 +4,9 @@ import com.czg.account.entity.ShopUserFlow; import com.czg.account.vo.ShopUserFlowVO; import com.mybatisflex.core.paginate.Page; import com.mybatisflex.core.service.IService; +import jakarta.servlet.http.HttpServletResponse; +import java.io.IOException; import java.math.BigDecimal; /** @@ -17,5 +19,7 @@ public interface ShopUserFlowService extends IService { void updateRefund(Long id, BigDecimal refundAmount); - Page pageInfo(Long shopId, Integer userId, String bizCode); + Page pageInfo(Long shopId, Integer userId, String bizCode, String startTime, String endTime); + + void flowDownload(Long shopId, Integer userId, String bizCode, String startTime, String endTime, HttpServletResponse response) throws IOException; } diff --git a/cash-service/account-service/src/main/java/com/czg/service/account/mapper/ShopUserFlowMapper.java b/cash-service/account-service/src/main/java/com/czg/service/account/mapper/ShopUserFlowMapper.java index 5e00a556..34a6eb71 100644 --- a/cash-service/account-service/src/main/java/com/czg/service/account/mapper/ShopUserFlowMapper.java +++ b/cash-service/account-service/src/main/java/com/czg/service/account/mapper/ShopUserFlowMapper.java @@ -15,5 +15,5 @@ import java.util.List; */ public interface ShopUserFlowMapper extends BaseMapper { - List pageInfo(@Param("shopId") Long shopId, @Param("userId") Integer userId, @Param("bizCode") String bizCode); + List pageInfo(@Param("shopId") Long shopId, @Param("userId") Integer userId, @Param("bizCode") String bizCode, @Param("startTime") String startTime, @Param("endTime") String endTime); } diff --git a/cash-service/account-service/src/main/java/com/czg/service/account/service/impl/ShopUserFlowServiceImpl.java b/cash-service/account-service/src/main/java/com/czg/service/account/service/impl/ShopUserFlowServiceImpl.java index 2f5bfc7c..a504f4c1 100644 --- a/cash-service/account-service/src/main/java/com/czg/service/account/service/impl/ShopUserFlowServiceImpl.java +++ b/cash-service/account-service/src/main/java/com/czg/service/account/service/impl/ShopUserFlowServiceImpl.java @@ -1,8 +1,11 @@ package com.czg.service.account.service.impl; +import cn.hutool.poi.excel.ExcelUtil; +import cn.hutool.poi.excel.ExcelWriter; import com.czg.account.entity.ShopUserFlow; import com.czg.account.service.ShopUserFlowService; import com.czg.account.vo.ShopUserFlowVO; +import com.czg.account.vo.SysUserDetailVO; import com.czg.service.account.mapper.ShopUserFlowMapper; import com.czg.utils.PageUtil; import com.github.pagehelper.PageHelper; @@ -10,9 +13,13 @@ import com.github.pagehelper.PageInfo; import com.mybatisflex.core.paginate.Page; import com.mybatisflex.core.update.UpdateChain; import com.mybatisflex.spring.service.impl.ServiceImpl; +import jakarta.servlet.http.HttpServletResponse; import org.apache.dubbo.config.annotation.DubboService; +import java.io.IOException; import java.math.BigDecimal; +import java.net.URLEncoder; +import java.util.List; /** * 用户余额流水 服务层实现。 @@ -32,8 +39,29 @@ public class ShopUserFlowServiceImpl extends ServiceImpl pageInfo(Long shopId, Integer userId, String bizCode) { + public Page pageInfo(Long shopId, Integer userId, String bizCode, String startTime, String endTime) { PageHelper.startPage(PageUtil.buildPageHelp()); - return PageUtil.convert(new PageInfo<>(mapper.pageInfo(shopId, userId, bizCode))); + return PageUtil.convert(new PageInfo<>(mapper.pageInfo(shopId, userId, bizCode, startTime, endTime))); + } + + @Override + public void flowDownload(Long shopId, Integer userId, String bizCode, String startTime, String endTime, HttpServletResponse response) throws IOException { + PageHelper.startPage(PageUtil.buildPageHelp()); + List shopUserFlowVOS = mapper.pageInfo(shopId, userId, bizCode, startTime, endTime); + + // 1. 创建 ExcelWriter + // true 表示使用 XLSX 格式 + ExcelWriter writer = ExcelUtil.getWriter(true); + + // 2. 写入数据 + writer.write(shopUserFlowVOS, true); + + // 3. 设置响应头,返回 Excel + response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8"); + response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("余额明细.xlsx", "UTF-8")); + + // 4. 写入到响应流 + writer.flush(response.getOutputStream(), true); + writer.close(); } } diff --git a/cash-service/account-service/src/main/resources/mapper/ShopUserFlowMapper.xml b/cash-service/account-service/src/main/resources/mapper/ShopUserFlowMapper.xml index 6c169c7c..bd18f7d8 100644 --- a/cash-service/account-service/src/main/resources/mapper/ShopUserFlowMapper.xml +++ b/cash-service/account-service/src/main/resources/mapper/ShopUserFlowMapper.xml @@ -15,6 +15,13 @@ and a.user_id=#{userId} + + and a.create_time >= #{startTime} + + + + and a.create_time <= #{endTime} + order by a.create_time desc