✨ Pay:增加钱包流水统计接口
This commit is contained in:
parent
ddb6fe7ec8
commit
e59f43408c
@ -3,24 +3,30 @@ package cn.iocoder.yudao.module.pay.controller.app.wallet;
|
||||
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.transaction.AppPayWalletTransactionSummaryRespVO;
|
||||
import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.transaction.AppPayWalletTransactionPageReqVO;
|
||||
import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.transaction.AppPayWalletTransactionRespVO;
|
||||
import cn.iocoder.yudao.module.pay.convert.wallet.PayWalletTransactionConvert;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletTransactionDO;
|
||||
import cn.iocoder.yudao.module.pay.service.wallet.PayWalletTransactionService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
||||
|
||||
@Tag(name = "用户 APP - 钱包余额明细")
|
||||
@ -37,16 +43,19 @@ public class AppPayWalletTransactionController {
|
||||
@Operation(summary = "获得钱包流水分页")
|
||||
public CommonResult<PageResult<AppPayWalletTransactionRespVO>> getWalletTransactionPage(
|
||||
@Valid AppPayWalletTransactionPageReqVO pageReqVO) {
|
||||
if (true) {
|
||||
PageResult<AppPayWalletTransactionRespVO> result = new PageResult<>(10L);
|
||||
result.getList().add(new AppPayWalletTransactionRespVO().setPrice(1L)
|
||||
.setTitle("测试").setCreateTime(LocalDateTime.now()));
|
||||
result.getList().add(new AppPayWalletTransactionRespVO().setPrice(-1L)
|
||||
.setTitle("测试2").setCreateTime(LocalDateTime.now()));
|
||||
return success(result);
|
||||
}
|
||||
PageResult<PayWalletTransactionDO> result = payWalletTransactionService.getWalletTransactionPage(getLoginUserId(),
|
||||
UserTypeEnum.MEMBER.getValue(), pageReqVO);
|
||||
return success(PayWalletTransactionConvert.INSTANCE.convertPage(result));
|
||||
PageResult<PayWalletTransactionDO> pageResult = payWalletTransactionService.getWalletTransactionPage(
|
||||
getLoginUserId(), UserTypeEnum.MEMBER.getValue(), pageReqVO);
|
||||
return success(BeanUtils.toBean(pageResult, AppPayWalletTransactionRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/get-summary")
|
||||
@Operation(summary = "获得钱包流水统计")
|
||||
@Parameter(name = "times", description = "时间段", required = true)
|
||||
public CommonResult<AppPayWalletTransactionSummaryRespVO> getWalletTransactionSummary(
|
||||
@RequestParam("createTime") @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) LocalDateTime[] createTime) {
|
||||
AppPayWalletTransactionSummaryRespVO summary = payWalletTransactionService.getWalletTransactionSummary(
|
||||
getLoginUserId(), UserTypeEnum.MEMBER.getValue(), createTime);
|
||||
return success(summary);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,8 +1,12 @@
|
||||
package cn.iocoder.yudao.module.pay.controller.app.wallet.vo.transaction;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.util.date.DateUtils;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Schema(description = "用户 APP - 钱包流水分页 Request VO")
|
||||
@Data
|
||||
@ -20,4 +24,8 @@ public class AppPayWalletTransactionPageReqVO extends PageParam {
|
||||
@Schema(description = "类型", example = "1")
|
||||
private Integer type;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
@DateTimeFormat(pattern = DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime[] createTime;
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,16 @@
|
||||
package cn.iocoder.yudao.module.pay.controller.app.wallet.vo.transaction;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
@Schema(description = "用户 APP - 钱包流水统计 Request VO")
|
||||
@Data
|
||||
public class AppPayWalletTransactionSummaryRespVO {
|
||||
|
||||
@Schema(description = "累计支出,单位分", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000")
|
||||
private Integer totalExpense;
|
||||
|
||||
@Schema(description = "累计收入,单位分", requiredMode = Schema.RequiredMode.REQUIRED, example = "2000")
|
||||
private Integer totalIncome;
|
||||
|
||||
}
|
@ -7,13 +7,13 @@ import lombok.Data;
|
||||
@Data
|
||||
public class AppPayWalletRespVO {
|
||||
|
||||
@Schema(description = "钱包余额,单位分", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
|
||||
@Schema(description = "钱包余额,单位分", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
|
||||
private Integer balance;
|
||||
|
||||
@Schema(description = "累计支出, 单位分", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000")
|
||||
@Schema(description = "累计支出,单位分", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000")
|
||||
private Integer totalExpense;
|
||||
|
||||
@Schema(description = "累计充值, 单位分", requiredMode = Schema.RequiredMode.REQUIRED, example = "2000")
|
||||
@Schema(description = "累计充值,单位分", requiredMode = Schema.RequiredMode.REQUIRED, example = "2000")
|
||||
private Integer totalRecharge;
|
||||
|
||||
}
|
||||
|
@ -13,8 +13,6 @@ public interface PayWalletTransactionConvert {
|
||||
|
||||
PayWalletTransactionConvert INSTANCE = Mappers.getMapper(PayWalletTransactionConvert.class);
|
||||
|
||||
PageResult<AppPayWalletTransactionRespVO> convertPage(PageResult<PayWalletTransactionDO> page);
|
||||
|
||||
PageResult<PayWalletTransactionRespVO> convertPage2(PageResult<PayWalletTransactionDO> page);
|
||||
|
||||
PayWalletTransactionDO convert(WalletTransactionCreateReqBO bean);
|
||||
|
@ -1,32 +1,56 @@
|
||||
package cn.iocoder.yudao.module.pay.dal.mysql.wallet;
|
||||
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX;
|
||||
import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.transaction.AppPayWalletTransactionPageReqVO;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletTransactionDO;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static cn.iocoder.yudao.module.pay.controller.app.wallet.vo.transaction.AppPayWalletTransactionPageReqVO.*;
|
||||
|
||||
@Mapper
|
||||
public interface PayWalletTransactionMapper extends BaseMapperX<PayWalletTransactionDO> {
|
||||
|
||||
default PageResult<PayWalletTransactionDO> selectPage(Long walletId, Integer type,
|
||||
PageParam pageParam) {
|
||||
PageParam pageParam, LocalDateTime[] createTime) {
|
||||
LambdaQueryWrapperX<PayWalletTransactionDO> query = new LambdaQueryWrapperX<PayWalletTransactionDO>()
|
||||
.eqIfPresent(PayWalletTransactionDO::getWalletId, walletId);
|
||||
if (Objects.equals(type, AppPayWalletTransactionPageReqVO.TYPE_INCOME)) {
|
||||
if (Objects.equals(type, TYPE_INCOME)) {
|
||||
query.gt(PayWalletTransactionDO::getPrice, 0);
|
||||
} else if (Objects.equals(type, AppPayWalletTransactionPageReqVO.TYPE_EXPENSE)) {
|
||||
} else if (Objects.equals(type, TYPE_EXPENSE)) {
|
||||
query.lt(PayWalletTransactionDO::getPrice, 0);
|
||||
}
|
||||
query.betweenIfPresent(PayWalletTransactionDO::getCreateTime, createTime);
|
||||
query.orderByDesc(PayWalletTransactionDO::getId);
|
||||
return selectPage(pageParam, query);
|
||||
}
|
||||
|
||||
default Integer selectPriceSum(Long walletId, Integer type, LocalDateTime[] createTime) {
|
||||
// SQL sum 查询
|
||||
List<Map<String, Object>> result = selectMaps(new QueryWrapperX<PayWalletTransactionDO>()
|
||||
.select("SUM(price) AS priceSum")
|
||||
.gt(Objects.equals(type, TYPE_INCOME), "price", 0) // 收入
|
||||
.lt(Objects.equals(type, TYPE_EXPENSE), "price", 0) // 支出
|
||||
.eq("wallet_id", walletId)
|
||||
.between("create_time", createTime[0], createTime[1]));
|
||||
// 获得 sum 结果
|
||||
Map<String, Object> first = CollUtil.getFirst(result);
|
||||
return MapUtil.getInt(first, "priceSum", 0);
|
||||
}
|
||||
|
||||
default PayWalletTransactionDO selectByNo(String no) {
|
||||
return selectOne(PayWalletTransactionDO::getNo, no);
|
||||
}
|
||||
|
@ -3,12 +3,15 @@ package cn.iocoder.yudao.module.pay.service.wallet;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.transaction.PayWalletTransactionPageReqVO;
|
||||
import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.transaction.AppPayWalletTransactionPageReqVO;
|
||||
import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.transaction.AppPayWalletTransactionSummaryRespVO;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletTransactionDO;
|
||||
import cn.iocoder.yudao.module.pay.enums.wallet.PayWalletBizTypeEnum;
|
||||
import cn.iocoder.yudao.module.pay.service.wallet.bo.WalletTransactionCreateReqBO;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 钱包余额流水 Service 接口
|
||||
*
|
||||
@ -57,4 +60,15 @@ public interface PayWalletTransactionService {
|
||||
*/
|
||||
PayWalletTransactionDO getWalletTransaction(String bizId, PayWalletBizTypeEnum type);
|
||||
|
||||
/**
|
||||
* 获得钱包流水统计
|
||||
*
|
||||
* @param userId 用户编号
|
||||
* @param userType 用户类型
|
||||
* @param createTime 时间段
|
||||
* @return 钱包流水统计
|
||||
*/
|
||||
AppPayWalletTransactionSummaryRespVO getWalletTransactionSummary(Long userId, Integer userType,
|
||||
LocalDateTime[] createTime);
|
||||
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.pay.service.wallet;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.transaction.PayWalletTransactionPageReqVO;
|
||||
import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.transaction.AppPayWalletTransactionPageReqVO;
|
||||
import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.transaction.AppPayWalletTransactionSummaryRespVO;
|
||||
import cn.iocoder.yudao.module.pay.convert.wallet.PayWalletTransactionConvert;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletDO;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletTransactionDO;
|
||||
@ -16,6 +17,11 @@ import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static cn.iocoder.yudao.module.pay.controller.app.wallet.vo.transaction.AppPayWalletTransactionPageReqVO.TYPE_EXPENSE;
|
||||
import static cn.iocoder.yudao.module.pay.controller.app.wallet.vo.transaction.AppPayWalletTransactionPageReqVO.TYPE_INCOME;
|
||||
|
||||
/**
|
||||
* 钱包流水 Service 实现类
|
||||
*
|
||||
@ -42,12 +48,12 @@ public class PayWalletTransactionServiceImpl implements PayWalletTransactionServ
|
||||
public PageResult<PayWalletTransactionDO> getWalletTransactionPage(Long userId, Integer userType,
|
||||
AppPayWalletTransactionPageReqVO pageVO) {
|
||||
PayWalletDO wallet = payWalletService.getOrCreateWallet(userId, userType);
|
||||
return payWalletTransactionMapper.selectPage(wallet.getId(), pageVO.getType(), pageVO);
|
||||
return payWalletTransactionMapper.selectPage(wallet.getId(), pageVO.getType(), pageVO, pageVO.getCreateTime());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<PayWalletTransactionDO> getWalletTransactionPage(PayWalletTransactionPageReqVO pageVO) {
|
||||
return payWalletTransactionMapper.selectPage(pageVO.getWalletId(), null, pageVO);
|
||||
return payWalletTransactionMapper.selectPage(pageVO.getWalletId(), null, pageVO, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -68,4 +74,14 @@ public class PayWalletTransactionServiceImpl implements PayWalletTransactionServ
|
||||
return payWalletTransactionMapper.selectByBiz(bizId, type.getType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public AppPayWalletTransactionSummaryRespVO getWalletTransactionSummary(Long userId, Integer userType, LocalDateTime[] createTime) {
|
||||
PayWalletDO wallet = payWalletService.getOrCreateWallet(userId, userType);
|
||||
AppPayWalletTransactionSummaryRespVO summary = new AppPayWalletTransactionSummaryRespVO()
|
||||
.setTotalExpense(1).setTotalIncome(100);
|
||||
return new AppPayWalletTransactionSummaryRespVO()
|
||||
.setTotalExpense(payWalletTransactionMapper.selectPriceSum(wallet.getId(), TYPE_EXPENSE, createTime))
|
||||
.setTotalIncome(payWalletTransactionMapper.selectPriceSum(wallet.getId(), TYPE_INCOME, createTime));
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user