Commit e59f43408c1f1f93a01cda09fa35229139aa4fbc
1 parent
ddb6fe7e
✨ Pay:增加钱包流水统计接口
Showing
8 changed files
with
107 additions
and
22 deletions
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/AppPayWalletTransactionController.java
| ... | ... | @@ -3,24 +3,30 @@ package cn.iocoder.yudao.module.pay.controller.app.wallet; |
| 3 | 3 | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 5 | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 7 | +import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.transaction.AppPayWalletTransactionSummaryRespVO; | |
| 6 | 8 | import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.transaction.AppPayWalletTransactionPageReqVO; |
| 7 | 9 | import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.transaction.AppPayWalletTransactionRespVO; |
| 8 | -import cn.iocoder.yudao.module.pay.convert.wallet.PayWalletTransactionConvert; | |
| 9 | 10 | import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletTransactionDO; |
| 10 | 11 | import cn.iocoder.yudao.module.pay.service.wallet.PayWalletTransactionService; |
| 11 | 12 | import io.swagger.v3.oas.annotations.Operation; |
| 13 | +import io.swagger.v3.oas.annotations.Parameter; | |
| 12 | 14 | import io.swagger.v3.oas.annotations.tags.Tag; |
| 13 | 15 | import lombok.extern.slf4j.Slf4j; |
| 16 | +import org.springframework.format.annotation.DateTimeFormat; | |
| 14 | 17 | import org.springframework.validation.annotation.Validated; |
| 15 | 18 | import org.springframework.web.bind.annotation.GetMapping; |
| 16 | 19 | import org.springframework.web.bind.annotation.RequestMapping; |
| 20 | +import org.springframework.web.bind.annotation.RequestParam; | |
| 17 | 21 | import org.springframework.web.bind.annotation.RestController; |
| 18 | 22 | |
| 19 | 23 | import jakarta.annotation.Resource; |
| 20 | 24 | import jakarta.validation.Valid; |
| 25 | + | |
| 21 | 26 | import java.time.LocalDateTime; |
| 22 | 27 | |
| 23 | 28 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 29 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | |
| 24 | 30 | import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; |
| 25 | 31 | |
| 26 | 32 | @Tag(name = "用户 APP - 钱包余额明细") |
| ... | ... | @@ -37,16 +43,19 @@ public class AppPayWalletTransactionController { |
| 37 | 43 | @Operation(summary = "获得钱包流水分页") |
| 38 | 44 | public CommonResult<PageResult<AppPayWalletTransactionRespVO>> getWalletTransactionPage( |
| 39 | 45 | @Valid AppPayWalletTransactionPageReqVO pageReqVO) { |
| 40 | - if (true) { | |
| 41 | - PageResult<AppPayWalletTransactionRespVO> result = new PageResult<>(10L); | |
| 42 | - result.getList().add(new AppPayWalletTransactionRespVO().setPrice(1L) | |
| 43 | - .setTitle("测试").setCreateTime(LocalDateTime.now())); | |
| 44 | - result.getList().add(new AppPayWalletTransactionRespVO().setPrice(-1L) | |
| 45 | - .setTitle("测试2").setCreateTime(LocalDateTime.now())); | |
| 46 | - return success(result); | |
| 47 | - } | |
| 48 | - PageResult<PayWalletTransactionDO> result = payWalletTransactionService.getWalletTransactionPage(getLoginUserId(), | |
| 49 | - UserTypeEnum.MEMBER.getValue(), pageReqVO); | |
| 50 | - return success(PayWalletTransactionConvert.INSTANCE.convertPage(result)); | |
| 46 | + PageResult<PayWalletTransactionDO> pageResult = payWalletTransactionService.getWalletTransactionPage( | |
| 47 | + getLoginUserId(), UserTypeEnum.MEMBER.getValue(), pageReqVO); | |
| 48 | + return success(BeanUtils.toBean(pageResult, AppPayWalletTransactionRespVO.class)); | |
| 49 | + } | |
| 50 | + | |
| 51 | + @GetMapping("/get-summary") | |
| 52 | + @Operation(summary = "获得钱包流水统计") | |
| 53 | + @Parameter(name = "times", description = "时间段", required = true) | |
| 54 | + public CommonResult<AppPayWalletTransactionSummaryRespVO> getWalletTransactionSummary( | |
| 55 | + @RequestParam("createTime") @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) LocalDateTime[] createTime) { | |
| 56 | + AppPayWalletTransactionSummaryRespVO summary = payWalletTransactionService.getWalletTransactionSummary( | |
| 57 | + getLoginUserId(), UserTypeEnum.MEMBER.getValue(), createTime); | |
| 58 | + return success(summary); | |
| 51 | 59 | } |
| 60 | + | |
| 52 | 61 | } | ... | ... |
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/vo/transaction/AppPayWalletTransactionPageReqVO.java
| 1 | 1 | package cn.iocoder.yudao.module.pay.controller.app.wallet.vo.transaction; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageParam; |
| 4 | +import cn.iocoder.yudao.framework.common.util.date.DateUtils; | |
| 4 | 5 | import io.swagger.v3.oas.annotations.media.Schema; |
| 5 | 6 | import lombok.Data; |
| 7 | +import org.springframework.format.annotation.DateTimeFormat; | |
| 8 | + | |
| 9 | +import java.time.LocalDateTime; | |
| 6 | 10 | |
| 7 | 11 | @Schema(description = "用户 APP - 钱包流水分页 Request VO") |
| 8 | 12 | @Data |
| ... | ... | @@ -20,4 +24,8 @@ public class AppPayWalletTransactionPageReqVO extends PageParam { |
| 20 | 24 | @Schema(description = "类型", example = "1") |
| 21 | 25 | private Integer type; |
| 22 | 26 | |
| 27 | + @Schema(description = "创建时间") | |
| 28 | + @DateTimeFormat(pattern = DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 29 | + private LocalDateTime[] createTime; | |
| 30 | + | |
| 23 | 31 | } | ... | ... |
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/vo/transaction/AppPayWalletTransactionSummaryRespVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.pay.controller.app.wallet.vo.transaction; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import lombok.Data; | |
| 5 | + | |
| 6 | +@Schema(description = "用户 APP - 钱包流水统计 Request VO") | |
| 7 | +@Data | |
| 8 | +public class AppPayWalletTransactionSummaryRespVO { | |
| 9 | + | |
| 10 | + @Schema(description = "累计支出,单位分", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000") | |
| 11 | + private Integer totalExpense; | |
| 12 | + | |
| 13 | + @Schema(description = "累计收入,单位分", requiredMode = Schema.RequiredMode.REQUIRED, example = "2000") | |
| 14 | + private Integer totalIncome; | |
| 15 | + | |
| 16 | +} | ... | ... |
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/vo/wallet/AppPayWalletRespVO.java
| ... | ... | @@ -7,13 +7,13 @@ import lombok.Data; |
| 7 | 7 | @Data |
| 8 | 8 | public class AppPayWalletRespVO { |
| 9 | 9 | |
| 10 | - @Schema(description = "钱包余额,单位分", requiredMode = Schema.RequiredMode.REQUIRED, example = "100") | |
| 10 | + @Schema(description = "钱包余额,单位分", requiredMode = Schema.RequiredMode.REQUIRED, example = "100") | |
| 11 | 11 | private Integer balance; |
| 12 | 12 | |
| 13 | - @Schema(description = "累计支出, 单位分", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000") | |
| 13 | + @Schema(description = "累计支出,单位分", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000") | |
| 14 | 14 | private Integer totalExpense; |
| 15 | 15 | |
| 16 | - @Schema(description = "累计充值, 单位分", requiredMode = Schema.RequiredMode.REQUIRED, example = "2000") | |
| 16 | + @Schema(description = "累计充值,单位分", requiredMode = Schema.RequiredMode.REQUIRED, example = "2000") | |
| 17 | 17 | private Integer totalRecharge; |
| 18 | 18 | |
| 19 | 19 | } | ... | ... |
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/convert/wallet/PayWalletTransactionConvert.java
| ... | ... | @@ -13,8 +13,6 @@ public interface PayWalletTransactionConvert { |
| 13 | 13 | |
| 14 | 14 | PayWalletTransactionConvert INSTANCE = Mappers.getMapper(PayWalletTransactionConvert.class); |
| 15 | 15 | |
| 16 | - PageResult<AppPayWalletTransactionRespVO> convertPage(PageResult<PayWalletTransactionDO> page); | |
| 17 | - | |
| 18 | 16 | PageResult<PayWalletTransactionRespVO> convertPage2(PageResult<PayWalletTransactionDO> page); |
| 19 | 17 | |
| 20 | 18 | PayWalletTransactionDO convert(WalletTransactionCreateReqBO bean); | ... | ... |
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletTransactionMapper.java
| 1 | 1 | package cn.iocoder.yudao.module.pay.dal.mysql.wallet; |
| 2 | 2 | |
| 3 | 3 | |
| 4 | +import cn.hutool.core.collection.CollUtil; | |
| 5 | +import cn.hutool.core.map.MapUtil; | |
| 4 | 6 | import cn.iocoder.yudao.framework.common.pojo.PageParam; |
| 5 | 7 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | 8 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 7 | 9 | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; |
| 10 | +import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; | |
| 8 | 11 | import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.transaction.AppPayWalletTransactionPageReqVO; |
| 9 | 12 | import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletTransactionDO; |
| 13 | +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | |
| 10 | 14 | import org.apache.ibatis.annotations.Mapper; |
| 11 | 15 | |
| 16 | +import java.time.LocalDateTime; | |
| 17 | +import java.util.List; | |
| 18 | +import java.util.Map; | |
| 12 | 19 | import java.util.Objects; |
| 20 | +import java.util.function.Consumer; | |
| 21 | + | |
| 22 | +import static cn.iocoder.yudao.module.pay.controller.app.wallet.vo.transaction.AppPayWalletTransactionPageReqVO.*; | |
| 13 | 23 | |
| 14 | 24 | @Mapper |
| 15 | 25 | public interface PayWalletTransactionMapper extends BaseMapperX<PayWalletTransactionDO> { |
| 16 | 26 | |
| 17 | 27 | default PageResult<PayWalletTransactionDO> selectPage(Long walletId, Integer type, |
| 18 | - PageParam pageParam) { | |
| 28 | + PageParam pageParam, LocalDateTime[] createTime) { | |
| 19 | 29 | LambdaQueryWrapperX<PayWalletTransactionDO> query = new LambdaQueryWrapperX<PayWalletTransactionDO>() |
| 20 | 30 | .eqIfPresent(PayWalletTransactionDO::getWalletId, walletId); |
| 21 | - if (Objects.equals(type, AppPayWalletTransactionPageReqVO.TYPE_INCOME)) { | |
| 31 | + if (Objects.equals(type, TYPE_INCOME)) { | |
| 22 | 32 | query.gt(PayWalletTransactionDO::getPrice, 0); |
| 23 | - } else if (Objects.equals(type, AppPayWalletTransactionPageReqVO.TYPE_EXPENSE)) { | |
| 33 | + } else if (Objects.equals(type, TYPE_EXPENSE)) { | |
| 24 | 34 | query.lt(PayWalletTransactionDO::getPrice, 0); |
| 25 | 35 | } |
| 36 | + query.betweenIfPresent(PayWalletTransactionDO::getCreateTime, createTime); | |
| 26 | 37 | query.orderByDesc(PayWalletTransactionDO::getId); |
| 27 | 38 | return selectPage(pageParam, query); |
| 28 | 39 | } |
| 29 | 40 | |
| 41 | + default Integer selectPriceSum(Long walletId, Integer type, LocalDateTime[] createTime) { | |
| 42 | + // SQL sum 查询 | |
| 43 | + List<Map<String, Object>> result = selectMaps(new QueryWrapperX<PayWalletTransactionDO>() | |
| 44 | + .select("SUM(price) AS priceSum") | |
| 45 | + .gt(Objects.equals(type, TYPE_INCOME), "price", 0) // 收入 | |
| 46 | + .lt(Objects.equals(type, TYPE_EXPENSE), "price", 0) // 支出 | |
| 47 | + .eq("wallet_id", walletId) | |
| 48 | + .between("create_time", createTime[0], createTime[1])); | |
| 49 | + // 获得 sum 结果 | |
| 50 | + Map<String, Object> first = CollUtil.getFirst(result); | |
| 51 | + return MapUtil.getInt(first, "priceSum", 0); | |
| 52 | + } | |
| 53 | + | |
| 30 | 54 | default PayWalletTransactionDO selectByNo(String no) { |
| 31 | 55 | return selectOne(PayWalletTransactionDO::getNo, no); |
| 32 | 56 | } | ... | ... |
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletTransactionService.java
| ... | ... | @@ -3,12 +3,15 @@ package cn.iocoder.yudao.module.pay.service.wallet; |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | 4 | import cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.transaction.PayWalletTransactionPageReqVO; |
| 5 | 5 | import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.transaction.AppPayWalletTransactionPageReqVO; |
| 6 | +import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.transaction.AppPayWalletTransactionSummaryRespVO; | |
| 6 | 7 | import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletTransactionDO; |
| 7 | 8 | import cn.iocoder.yudao.module.pay.enums.wallet.PayWalletBizTypeEnum; |
| 8 | 9 | import cn.iocoder.yudao.module.pay.service.wallet.bo.WalletTransactionCreateReqBO; |
| 9 | 10 | |
| 10 | 11 | import jakarta.validation.Valid; |
| 11 | 12 | |
| 13 | +import java.time.LocalDateTime; | |
| 14 | + | |
| 12 | 15 | /** |
| 13 | 16 | * 钱包余额流水 Service 接口 |
| 14 | 17 | * |
| ... | ... | @@ -57,4 +60,15 @@ public interface PayWalletTransactionService { |
| 57 | 60 | */ |
| 58 | 61 | PayWalletTransactionDO getWalletTransaction(String bizId, PayWalletBizTypeEnum type); |
| 59 | 62 | |
| 63 | + /** | |
| 64 | + * 获得钱包流水统计 | |
| 65 | + * | |
| 66 | + * @param userId 用户编号 | |
| 67 | + * @param userType 用户类型 | |
| 68 | + * @param createTime 时间段 | |
| 69 | + * @return 钱包流水统计 | |
| 70 | + */ | |
| 71 | + AppPayWalletTransactionSummaryRespVO getWalletTransactionSummary(Long userId, Integer userType, | |
| 72 | + LocalDateTime[] createTime); | |
| 73 | + | |
| 60 | 74 | } | ... | ... |
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletTransactionServiceImpl.java
| ... | ... | @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.pay.service.wallet; |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | 4 | import cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.transaction.PayWalletTransactionPageReqVO; |
| 5 | 5 | import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.transaction.AppPayWalletTransactionPageReqVO; |
| 6 | +import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.transaction.AppPayWalletTransactionSummaryRespVO; | |
| 6 | 7 | import cn.iocoder.yudao.module.pay.convert.wallet.PayWalletTransactionConvert; |
| 7 | 8 | import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletDO; |
| 8 | 9 | import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletTransactionDO; |
| ... | ... | @@ -16,6 +17,11 @@ import org.springframework.validation.annotation.Validated; |
| 16 | 17 | |
| 17 | 18 | import jakarta.annotation.Resource; |
| 18 | 19 | |
| 20 | +import java.time.LocalDateTime; | |
| 21 | + | |
| 22 | +import static cn.iocoder.yudao.module.pay.controller.app.wallet.vo.transaction.AppPayWalletTransactionPageReqVO.TYPE_EXPENSE; | |
| 23 | +import static cn.iocoder.yudao.module.pay.controller.app.wallet.vo.transaction.AppPayWalletTransactionPageReqVO.TYPE_INCOME; | |
| 24 | + | |
| 19 | 25 | /** |
| 20 | 26 | * 钱包流水 Service 实现类 |
| 21 | 27 | * |
| ... | ... | @@ -42,12 +48,12 @@ public class PayWalletTransactionServiceImpl implements PayWalletTransactionServ |
| 42 | 48 | public PageResult<PayWalletTransactionDO> getWalletTransactionPage(Long userId, Integer userType, |
| 43 | 49 | AppPayWalletTransactionPageReqVO pageVO) { |
| 44 | 50 | PayWalletDO wallet = payWalletService.getOrCreateWallet(userId, userType); |
| 45 | - return payWalletTransactionMapper.selectPage(wallet.getId(), pageVO.getType(), pageVO); | |
| 51 | + return payWalletTransactionMapper.selectPage(wallet.getId(), pageVO.getType(), pageVO, pageVO.getCreateTime()); | |
| 46 | 52 | } |
| 47 | 53 | |
| 48 | 54 | @Override |
| 49 | 55 | public PageResult<PayWalletTransactionDO> getWalletTransactionPage(PayWalletTransactionPageReqVO pageVO) { |
| 50 | - return payWalletTransactionMapper.selectPage(pageVO.getWalletId(), null, pageVO); | |
| 56 | + return payWalletTransactionMapper.selectPage(pageVO.getWalletId(), null, pageVO, null); | |
| 51 | 57 | } |
| 52 | 58 | |
| 53 | 59 | @Override |
| ... | ... | @@ -68,4 +74,14 @@ public class PayWalletTransactionServiceImpl implements PayWalletTransactionServ |
| 68 | 74 | return payWalletTransactionMapper.selectByBiz(bizId, type.getType()); |
| 69 | 75 | } |
| 70 | 76 | |
| 77 | + @Override | |
| 78 | + public AppPayWalletTransactionSummaryRespVO getWalletTransactionSummary(Long userId, Integer userType, LocalDateTime[] createTime) { | |
| 79 | + PayWalletDO wallet = payWalletService.getOrCreateWallet(userId, userType); | |
| 80 | + AppPayWalletTransactionSummaryRespVO summary = new AppPayWalletTransactionSummaryRespVO() | |
| 81 | + .setTotalExpense(1).setTotalIncome(100); | |
| 82 | + return new AppPayWalletTransactionSummaryRespVO() | |
| 83 | + .setTotalExpense(payWalletTransactionMapper.selectPriceSum(wallet.getId(), TYPE_EXPENSE, createTime)) | |
| 84 | + .setTotalIncome(payWalletTransactionMapper.selectPriceSum(wallet.getId(), TYPE_INCOME, createTime)); | |
| 85 | + } | |
| 86 | + | |
| 71 | 87 | } | ... | ... |