feat:充值、消费、退款记录

This commit is contained in:
dzc committed 2025-01-07 18:21:59 +08:00
1 parent f911239fb5
commit 449740d0cf
7 files changed
+107 -13

No files matched your search

@@ -13,6 +13,7 @@ public enum WalletBizEnum {
BATCH("2", "批量更新余额"),
RECHARGE("3", "充值"),
PAYMENT("4", "支付"),
REFUND("5", "退款"),
;
private final String code;
@@ -4,6 +4,8 @@ import com.bsd.pjcloud.wallet.api.entity.WalletTransactionEntity;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.util.List;
@Data
public class WalletTransactionDto extends WalletTransactionEntity {
@@ -24,4 +26,10 @@ public class WalletTransactionDto extends WalletTransactionEntity {
*/
private Long userId;
private List<Long> userIds;
private Long walletTypeId;
private List<String> bizTypes;
}
@@ -1,8 +1,38 @@
package com.bsd.pjcloud.wallet.api.vo;
import com.bsd.pjcloud.admin.api.vo.base.BaseDeptInterface;
import com.bsd.pjcloud.admin.api.vo.base.BaseUserInterface;
import com.bsd.pjcloud.wallet.api.entity.WalletTransactionEntity;
import lombok.Data;
@Data
public class WalletTransactionVo extends WalletTransactionEntity {
public class WalletTransactionVo extends WalletTransactionEntity implements BaseUserInterface, BaseDeptInterface {
/**
* 用户相关
*/
private Long userId;
private String username;
private String userMobile;
private String userAvatar;
/**
* 部门相关
*/
private Long deptId;
private String deptName;
/**
* 钱包类型相关
*/
private String walletTypeName;
private String walletTypeUniqueCode;
}
@@ -11,6 +11,7 @@ import com.bsd.pjcloud.common.log.annotation.SysLog;
import com.bsd.pjcloud.common.security.annotation.Inner;
import com.bsd.pjcloud.common.security.service.PjcloudUser;
import com.bsd.pjcloud.common.security.util.SecurityUtils;
import com.bsd.pjcloud.wallet.api.constant.WalletBizEnum;
import com.bsd.pjcloud.wallet.api.dto.WalletBalanceTransactionDto;
import com.bsd.pjcloud.wallet.api.dto.WalletTransactionDto;
import com.bsd.pjcloud.wallet.api.entity.WalletTransactionEntity;
@@ -77,12 +78,25 @@ public class WalletTransactionController {
return R.ok(walletTransactionService.updateWalletBalance(dto));
}
@Operation(summary = "分页查询", description = "分页查询")
@GetMapping("/page")
@PreAuthorize("@pms.hasPermission('wallet_walletTransaction_view')")
public R getWalletTransactionPage(@ParameterObject Page page, @ParameterObject WalletTransactionEntity dto) {
LambdaQueryWrapper<WalletTransactionEntity> wrapper = new LambdaQueryWrapper<WalletTransactionEntity>();
return R.ok(walletTransactionService.page(page, wrapper));
@Operation(summary = "后台充值分页", description = "后台充值分页")
@GetMapping("/page-cz")
public R pageCz(@ParameterObject Page page, @ParameterObject WalletTransactionDto dto) {
dto.setBizTypes(List.of(WalletBizEnum.RECHARGE.getCode()));
return R.ok(walletTransactionService.pageJoin(page, dto));
}
@Operation(summary = "后台消费分页", description = "后台消费分页")
@GetMapping("/page-xf")
public R pageXf(@ParameterObject Page page, @ParameterObject WalletTransactionDto dto) {
dto.setBizTypes(List.of(WalletBizEnum.PAYMENT.getCode()));
return R.ok(walletTransactionService.pageJoin(page, dto));
}
@Operation(summary = "后台退款分页", description = "后台退款分页")
@GetMapping("/page-tk")
public R pageTk(@ParameterObject Page page, @ParameterObject WalletTransactionDto dto) {
dto.setBizTypes(List.of(WalletBizEnum.REFUND.getCode()));
return R.ok(walletTransactionService.pageJoin(page, dto));
}
@Operation(summary = "分页查询复杂查询", description = "分页查询复杂查询")
@@ -8,6 +8,7 @@ import com.bsd.pjcloud.common.data.datascope.PjcloudBaseMapper;
import com.bsd.pjcloud.wallet.api.dto.WalletTransactionDto;
import com.bsd.pjcloud.wallet.api.entity.WalletManageEntity;
import com.bsd.pjcloud.wallet.api.entity.WalletTransactionEntity;
import com.bsd.pjcloud.wallet.api.entity.WalletTypeEntity;
import com.bsd.pjcloud.wallet.api.vo.WalletManageVo;
import com.bsd.pjcloud.wallet.api.vo.WalletTransactionVo;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
@@ -18,10 +19,20 @@ import java.util.Objects;
@Mapper
public interface WalletTransactionMapper extends PjcloudBaseMapper<WalletTransactionEntity> {
default IPage<WalletTransactionVo> pageJoin(Page page, WalletTransactionDto dto) {
default Page<WalletTransactionVo> pageJoin(Page page, WalletTransactionDto dto) {
MPJLambdaWrapper<WalletTransactionEntity> wrapper = new MPJLambdaWrapper<WalletTransactionEntity>()
.eqIfExists(WalletTransactionEntity::getWalletId, dto.getWalletId());
.selectAll(WalletTransactionEntity.class)
.selectAs(WalletManageEntity::getUserId, WalletTransactionVo::getUserId)
.selectAs(WalletManageEntity::getDeptId, WalletTransactionVo::getDeptId)
.selectAs(WalletTypeEntity::getName, WalletTransactionVo::getWalletTypeName)
.selectAs(WalletTypeEntity::getUniqueCode, WalletTransactionVo::getWalletTypeUniqueCode)
.leftJoin(WalletManageEntity.class, WalletManageEntity::getId, WalletTransactionEntity::getWalletId)
.leftJoin(WalletTypeEntity.class, WalletTypeEntity::getId, WalletManageEntity::getWalletTypeId)
.eqIfExists(WalletTransactionEntity::getWalletId, dto.getWalletId())
.eqIfExists(WalletTransactionEntity::getBizType, dto.getBizType())
.eqIfExists(WalletManageEntity::getWalletTypeId, dto.getWalletTypeId())
.in(ObjectUtil.isNotEmpty(dto.getBizTypes()), WalletTransactionEntity::getBizType, dto.getBizTypes())
.in(ObjectUtil.isNotEmpty(dto.getUserIds()), WalletManageEntity::getUserId, dto.getUserIds());
if (ObjectUtil.equals(dto.getType(), WalletTransactionDto.TYPE_INCOME)) {
wrapper.gt(WalletTransactionEntity::getPrice, 0);
} else if (Objects.equals(dto.getType(), WalletTransactionDto.TYPE_EXPENSE)) {
@@ -47,5 +47,5 @@ public interface WalletTransactionService extends IService<WalletTransactionEnti
* @param dto
* @return
*/
IPage<WalletTransactionVo> pageJoin(Page page, WalletTransactionDto dto);
Page<WalletTransactionVo> pageJoin(Page page, WalletTransactionDto dto);
}
@@ -6,12 +6,20 @@ import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bsd.pjcloud.admin.api.entity.SysDept;
import com.bsd.pjcloud.admin.api.entity.SysUser;
import com.bsd.pjcloud.admin.api.feign.RemoteDeptService;
import com.bsd.pjcloud.admin.api.feign.RemoteUserService;
import com.bsd.pjcloud.admin.api.utils.DataUtil;
import com.bsd.pjcloud.common.core.constant.CacheConstants;
import com.bsd.pjcloud.common.core.exception.CheckedException;
import com.bsd.pjcloud.common.core.util.CollectionUtils;
import com.bsd.pjcloud.common.core.util.R;
import com.bsd.pjcloud.wallet.api.constant.WalletBizEnum;
import com.bsd.pjcloud.wallet.api.dto.WalletTransactionDto;
import com.bsd.pjcloud.wallet.api.entity.WalletManageEntity;
import com.bsd.pjcloud.wallet.api.entity.WalletTransactionEntity;
import com.bsd.pjcloud.wallet.api.vo.WalletManageVo;
import com.bsd.pjcloud.wallet.api.vo.WalletTransactionVo;
import com.bsd.pjcloud.wallet.mapper.WalletManageMapper;
import com.bsd.pjcloud.wallet.mapper.WalletTransactionMapper;
@@ -25,6 +33,10 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* 会员钱包流水表
*
@@ -43,6 +55,9 @@ public class WalletTransactionServiceImpl extends ServiceImpl<WalletTransactionM
private final WalletManageMapper walletManageMapper;
private final RemoteUserService userService;
private final RemoteDeptService deptService;
@Override
public boolean save(WalletTransactionEntity entity) {
@@ -127,7 +142,22 @@ public class WalletTransactionServiceImpl extends ServiceImpl<WalletTransactionM
}
@Override
public IPage<WalletTransactionVo> pageJoin(Page page, WalletTransactionDto dto) {
return baseMapper.pageJoin(page, dto);
public Page<WalletTransactionVo> pageJoin(Page page, WalletTransactionDto dto) {
Page<WalletTransactionVo> list = baseMapper.pageJoin(page, dto);
if (ObjectUtil.isNotEmpty(list.getRecords())) {
// 用户
List<Long> userIds = list.getRecords().stream().map(WalletTransactionVo::getUserId).distinct().toList();
R<List<SysUser>> userList = userService.getUserById(new ArrayList<>(userIds));
if (ObjectUtil.isNotEmpty(userList.getData())) {
DataUtil.convertUserList(list.getRecords(), CollectionUtils.convertMap(userList.getData(), SysUser::getUserId));
}
// 部门
List<Long> deptIds = list.getRecords().stream().map(WalletTransactionVo::getDeptId).distinct().toList();
R<Map<Long, SysDept>> deptList = deptService.getDeptByDeptIds(deptIds);
if (ObjectUtil.isNotEmpty(deptList.getData())) {
DataUtil.convertDeptList(list.getRecords(), deptList.getData());
}
}
return list;
}
}