【代码代码】PAY:移除对 member 的依赖

This commit is contained in:
YunaiV 2024-07-21 11:13:11 +08:00
parent fe3f144cff
commit e052ddab2f
9 changed files with 20 additions and 65 deletions

View File

@ -222,7 +222,6 @@ public class TradeOrderQueryServiceImpl implements TradeOrderQueryService {
.setPhone(receiverMobile)); .setPhone(receiverMobile));
} }
// =================== Order Item =================== // =================== Order Item ===================
@Override @Override

View File

@ -23,11 +23,6 @@
<artifactId>yudao-module-pay-api</artifactId> <artifactId>yudao-module-pay-api</artifactId>
<version>${revision}</version> <version>${revision}</version>
</dependency> </dependency>
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-module-member-api</artifactId>
<version>${revision}</version>
</dependency>
<!-- 业务组件 --> <!-- 业务组件 -->
<dependency> <dependency>

View File

@ -1,11 +1,7 @@
package cn.iocoder.yudao.module.pay.controller.admin.wallet; package cn.iocoder.yudao.module.pay.controller.admin.wallet;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.member.api.user.MemberUserApi;
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
import cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.wallet.PayWalletPageReqVO; import cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.wallet.PayWalletPageReqVO;
import cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.wallet.PayWalletRespVO; import cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.wallet.PayWalletRespVO;
import cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.wallet.PayWalletUserReqVO; import cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.wallet.PayWalletUserReqVO;
@ -14,6 +10,8 @@ import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletDO;
import cn.iocoder.yudao.module.pay.service.wallet.PayWalletService; import cn.iocoder.yudao.module.pay.service.wallet.PayWalletService;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
@ -21,14 +19,8 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import java.util.List;
import java.util.Map;
import static cn.iocoder.yudao.framework.common.enums.UserTypeEnum.MEMBER; import static cn.iocoder.yudao.framework.common.enums.UserTypeEnum.MEMBER;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
@Tag(name = "管理后台 - 用户钱包") @Tag(name = "管理后台 - 用户钱包")
@RestController @RestController
@ -39,38 +31,21 @@ public class PayWalletController {
@Resource @Resource
private PayWalletService payWalletService; private PayWalletService payWalletService;
@Resource
private MemberUserApi memberUserApi;
@GetMapping("/get") @GetMapping("/get")
@PreAuthorize("@ss.hasPermission('pay:wallet:query')") @PreAuthorize("@ss.hasPermission('pay:wallet:query')")
@Operation(summary = "获得用户钱包明细") @Operation(summary = "获得用户钱包明细")
public CommonResult<PayWalletRespVO> getWallet(PayWalletUserReqVO reqVO) { public CommonResult<PayWalletRespVO> getWallet(PayWalletUserReqVO reqVO) {
PayWalletDO wallet = payWalletService.getOrCreateWallet(reqVO.getUserId(), MEMBER.getValue()); PayWalletDO wallet = payWalletService.getOrCreateWallet(reqVO.getUserId(), MEMBER.getValue());
// TODO jason如果为空返回给前端只要 null 就可以了 return success(PayWalletConvert.INSTANCE.convert02(wallet));
MemberUserRespDTO memberUser = memberUserApi.getUser(reqVO.getUserId());
String nickname = memberUser == null ? "" : memberUser.getNickname();
String avatar = memberUser == null ? "" : memberUser.getAvatar();
return success(PayWalletConvert.INSTANCE.convert02(nickname, avatar, wallet));
} }
@GetMapping("/page") @GetMapping("/page")
@Operation(summary = "获得会员钱包分页") @Operation(summary = "获得会员钱包分页")
@PreAuthorize("@ss.hasPermission('pay:wallet:query')") @PreAuthorize("@ss.hasPermission('pay:wallet:query')")
public CommonResult<PageResult<PayWalletRespVO>> getWalletPage(@Valid PayWalletPageReqVO pageVO) { public CommonResult<PageResult<PayWalletRespVO>> getWalletPage(@Valid PayWalletPageReqVO pageVO) {
if (StrUtil.isNotEmpty(pageVO.getNickname())) { PageResult<PayWalletDO> pageResult = payWalletService.getWalletPage(pageVO);
List<MemberUserRespDTO> users = memberUserApi.getUserListByNickname(pageVO.getNickname()); return success(PayWalletConvert.INSTANCE.convertPage(pageResult));
pageVO.setUserIds(convertSet(users, MemberUserRespDTO::getId));
}
// TODO @jason管理员也可以先查询下
// 暂时支持查询 userType 会员类型管理员类型还不知道使用场景
PageResult<PayWalletDO> pageResult = payWalletService.getWalletPage(MEMBER.getValue(),pageVO);
if (CollectionUtil.isEmpty(pageResult.getList())) {
return success(new PageResult<>(pageResult.getTotal()));
}
List<MemberUserRespDTO> users = memberUserApi.getUserList(convertList(pageResult.getList(), PayWalletDO::getUserId));
Map<Long, MemberUserRespDTO> userMap = convertMap(users, MemberUserRespDTO::getId);
return success(PayWalletConvert.INSTANCE.convertPage(pageResult, userMap));
} }
} }

View File

@ -1,6 +1,8 @@
package cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.wallet; package cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.wallet;
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.validation.InEnum;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
@ -8,7 +10,6 @@ import lombok.ToString;
import org.springframework.format.annotation.DateTimeFormat; import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Collection;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@ -18,11 +19,12 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
@ToString(callSuper = true) @ToString(callSuper = true)
public class PayWalletPageReqVO extends PageParam { public class PayWalletPageReqVO extends PageParam {
@Schema(description = "用户昵称", example = "李四") @Schema(description = "用户编号", example = "1024")
private String nickname; private Long userId;
@Schema(description = "用户编号", example = "[1,2]") @Schema(description = "用户类型", example = "1")
private Collection<Long> userIds; @InEnum(value = UserTypeEnum.class)
private Integer userType;
@Schema(description = "创建时间") @Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)

View File

@ -19,9 +19,4 @@ public class PayWalletRespVO extends PayWalletBaseVO {
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
private LocalDateTime createTime; private LocalDateTime createTime;
@Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "王**")
private String nickname;
@Schema(description = "用户头像", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/xxx.jpg")
private String avatar;
} }

View File

@ -1,16 +1,12 @@
package cn.iocoder.yudao.module.pay.convert.wallet; package cn.iocoder.yudao.module.pay.convert.wallet;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
import cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.wallet.PayWalletRespVO; import cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.wallet.PayWalletRespVO;
import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.wallet.AppPayWalletRespVO; import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.wallet.AppPayWalletRespVO;
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletDO; import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletDO;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers; import org.mapstruct.factory.Mappers;
import java.util.Map;
@Mapper @Mapper
public interface PayWalletConvert { public interface PayWalletConvert {
@ -18,15 +14,8 @@ public interface PayWalletConvert {
AppPayWalletRespVO convert(PayWalletDO bean); AppPayWalletRespVO convert(PayWalletDO bean);
PayWalletRespVO convert02(String nickname,String avatar, PayWalletDO bean); PayWalletRespVO convert02(PayWalletDO bean);
PageResult<PayWalletRespVO> convertPage(PageResult<PayWalletDO> page); PageResult<PayWalletRespVO> convertPage(PageResult<PayWalletDO> page);
default PageResult<PayWalletRespVO> convertPage(PageResult<PayWalletDO> page, Map<Long, MemberUserRespDTO> userMap) {
PageResult<PayWalletRespVO> pageResult = convertPage(page);
pageResult.getList().forEach(wallet -> MapUtils.findAndThen(userMap, wallet.getUserId(),
user -> wallet.setNickname(user.getNickname()).setAvatar(user.getAvatar())));
return pageResult;
}
} }

View File

@ -17,10 +17,10 @@ public interface PayWalletMapper extends BaseMapperX<PayWalletDO> {
PayWalletDO::getUserType, userType); PayWalletDO::getUserType, userType);
} }
default PageResult<PayWalletDO> selectPage(Integer userType, PayWalletPageReqVO reqVO) { default PageResult<PayWalletDO> selectPage(PayWalletPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<PayWalletDO>() return selectPage(reqVO, new LambdaQueryWrapperX<PayWalletDO>()
.inIfPresent(PayWalletDO::getUserId, reqVO.getUserIds()) .eqIfPresent(PayWalletDO::getUserId, reqVO.getUserId())
.eqIfPresent(PayWalletDO::getUserType, userType) .eqIfPresent(PayWalletDO::getUserType, reqVO.getUserType())
.betweenIfPresent(PayWalletDO::getCreateTime, reqVO.getCreateTime()) .betweenIfPresent(PayWalletDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(PayWalletDO::getId)); .orderByDesc(PayWalletDO::getId));
} }
@ -31,7 +31,7 @@ public interface PayWalletMapper extends BaseMapperX<PayWalletDO> {
* @param id 钱包 id * @param id 钱包 id
* @param price 消费金额 * @param price 消费金额
*/ */
default int updateWhenConsumptionRefund(Long id, Integer price){ default int updateWhenConsumptionRefund(Long id, Integer price) {
LambdaUpdateWrapper<PayWalletDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<PayWalletDO>() LambdaUpdateWrapper<PayWalletDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<PayWalletDO>()
.setSql(" balance = balance + " + price .setSql(" balance = balance + " + price
+ ", total_expense = total_expense - " + price) + ", total_expense = total_expense - " + price)

View File

@ -36,7 +36,7 @@ public interface PayWalletService {
* @param pageReqVO 分页查询 * @param pageReqVO 分页查询
* @return 会员钱包分页 * @return 会员钱包分页
*/ */
PageResult<PayWalletDO> getWalletPage(Integer userType, PayWalletPageReqVO pageReqVO); PageResult<PayWalletDO> getWalletPage(PayWalletPageReqVO pageReqVO);
/** /**
* 钱包订单支付 * 钱包订单支付

View File

@ -65,8 +65,8 @@ public class PayWalletServiceImpl implements PayWalletService {
} }
@Override @Override
public PageResult<PayWalletDO> getWalletPage(Integer userType,PayWalletPageReqVO pageReqVO) { public PageResult<PayWalletDO> getWalletPage(PayWalletPageReqVO pageReqVO) {
return walletMapper.selectPage(userType, pageReqVO); return walletMapper.selectPage(pageReqVO);
} }
@Override @Override