Commit 2d44b3a245a29fa0e666cc8bfa60c6e2eebef2ec
Committed by
Gitee
!979 MEMBER: 根据【代码评审】完善微信小程序码。 修复获得个人分销统计 NPE 异常
Merge pull request !979 from puhui999/develop
Showing
3 changed files
with
40 additions
and
29 deletions
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java
| 1 | 1 | package cn.iocoder.yudao.module.trade.controller.app.brokerage; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.date.LocalDateTimeUtil; |
| 4 | +import cn.hutool.core.util.ObjUtil; | |
| 4 | 5 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 5 | 6 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | 7 | import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; |
| ... | ... | @@ -10,6 +11,8 @@ import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.*; |
| 10 | 11 | import cn.iocoder.yudao.module.trade.convert.brokerage.BrokerageRecordConvert; |
| 11 | 12 | import cn.iocoder.yudao.module.trade.convert.brokerage.BrokerageUserConvert; |
| 12 | 13 | import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageUserDO; |
| 14 | +import cn.iocoder.yudao.module.trade.dal.dataobject.config.TradeConfigDO; | |
| 15 | +import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageEnabledConditionEnum; | |
| 13 | 16 | import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum; |
| 14 | 17 | import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordStatusEnum; |
| 15 | 18 | import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageWithdrawStatusEnum; |
| ... | ... | @@ -17,16 +20,17 @@ import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageRecordService; |
| 17 | 20 | import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageUserService; |
| 18 | 21 | import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageWithdrawService; |
| 19 | 22 | import cn.iocoder.yudao.module.trade.service.brokerage.bo.BrokerageWithdrawSummaryRespBO; |
| 23 | +import cn.iocoder.yudao.module.trade.service.config.TradeConfigService; | |
| 20 | 24 | import io.swagger.v3.oas.annotations.Operation; |
| 21 | 25 | import io.swagger.v3.oas.annotations.Parameter; |
| 22 | 26 | import io.swagger.v3.oas.annotations.tags.Tag; |
| 27 | +import jakarta.annotation.Resource; | |
| 28 | +import jakarta.validation.Valid; | |
| 23 | 29 | import lombok.extern.slf4j.Slf4j; |
| 24 | 30 | import org.springframework.format.annotation.DateTimeFormat; |
| 25 | 31 | import org.springframework.validation.annotation.Validated; |
| 26 | 32 | import org.springframework.web.bind.annotation.*; |
| 27 | 33 | |
| 28 | -import jakarta.annotation.Resource; | |
| 29 | -import jakarta.validation.Valid; | |
| 30 | 34 | import java.time.LocalDateTime; |
| 31 | 35 | import java.util.Collections; |
| 32 | 36 | import java.util.Map; |
| ... | ... | @@ -50,7 +54,8 @@ public class AppBrokerageUserController { |
| 50 | 54 | private BrokerageRecordService brokerageRecordService; |
| 51 | 55 | @Resource |
| 52 | 56 | private BrokerageWithdrawService brokerageWithdrawService; |
| 53 | - | |
| 57 | + @Resource | |
| 58 | + private TradeConfigService tradeConfigService; | |
| 54 | 59 | @Resource |
| 55 | 60 | private MemberUserApi memberUserApi; |
| 56 | 61 | |
| ... | ... | @@ -59,9 +64,13 @@ public class AppBrokerageUserController { |
| 59 | 64 | @PreAuthenticated |
| 60 | 65 | public CommonResult<AppBrokerageUserRespVO> getBrokerageUser() { |
| 61 | 66 | Optional<BrokerageUserDO> user = Optional.ofNullable(brokerageUserService.getBrokerageUser(getLoginUserId())); |
| 67 | + // 获得交易中心配置 | |
| 68 | + TradeConfigDO tradeConfig = tradeConfigService.getTradeConfig(); | |
| 69 | + // 如果是人人分佣 BrokerageUserDO 为 null 时,也有分销资格 | |
| 70 | + boolean brokerageEnabled = ObjUtil.equal(BrokerageEnabledConditionEnum.ALL.getCondition(), tradeConfig.getBrokerageEnabledCondition()); | |
| 62 | 71 | // 返回数据 |
| 63 | 72 | AppBrokerageUserRespVO respVO = new AppBrokerageUserRespVO() |
| 64 | - .setBrokerageEnabled(user.map(BrokerageUserDO::getBrokerageEnabled).orElse(false)) | |
| 73 | + .setBrokerageEnabled(user.map(BrokerageUserDO::getBrokerageEnabled).orElse(brokerageEnabled)) | |
| 65 | 74 | .setBrokeragePrice(user.map(BrokerageUserDO::getBrokeragePrice).orElse(0)) |
| 66 | 75 | .setFrozenPrice(user.map(BrokerageUserDO::getFrozenPrice).orElse(0)); |
| 67 | 76 | return success(respVO); |
| ... | ... | @@ -79,21 +88,22 @@ public class AppBrokerageUserController { |
| 79 | 88 | @PreAuthenticated |
| 80 | 89 | public CommonResult<AppBrokerageUserMySummaryRespVO> getBrokerageUserSummary() { |
| 81 | 90 | // 查询当前登录用户信息 |
| 82 | - BrokerageUserDO brokerageUser = brokerageUserService.getBrokerageUser(getLoginUserId()); | |
| 91 | + Long userId = getLoginUserId(); | |
| 92 | + BrokerageUserDO brokerageUser = brokerageUserService.getBrokerageUser(userId); | |
| 83 | 93 | // 统计用户昨日的佣金 |
| 84 | 94 | LocalDateTime yesterday = LocalDateTime.now().minusDays(1); |
| 85 | 95 | LocalDateTime beginTime = LocalDateTimeUtil.beginOfDay(yesterday); |
| 86 | 96 | LocalDateTime endTime = LocalDateTimeUtil.endOfDay(yesterday); |
| 87 | - Integer yesterdayPrice = brokerageRecordService.getSummaryPriceByUserId(brokerageUser.getId(), | |
| 97 | + Integer yesterdayPrice = brokerageRecordService.getSummaryPriceByUserId(userId, | |
| 88 | 98 | BrokerageRecordBizTypeEnum.ORDER, BrokerageRecordStatusEnum.SETTLEMENT, beginTime, endTime); |
| 89 | 99 | // 统计用户提现的佣金 |
| 90 | - Integer withdrawPrice = brokerageWithdrawService.getWithdrawSummaryListByUserId(Collections.singleton(brokerageUser.getId()), | |
| 100 | + Integer withdrawPrice = brokerageWithdrawService.getWithdrawSummaryListByUserId(Collections.singleton(userId), | |
| 91 | 101 | BrokerageWithdrawStatusEnum.AUDIT_SUCCESS).stream() |
| 92 | 102 | .findFirst().map(BrokerageWithdrawSummaryRespBO::getPrice).orElse(0); |
| 93 | 103 | // 统计分销用户数量(一级) |
| 94 | - Long firstBrokerageUserCount = brokerageUserService.getBrokerageUserCountByBindUserId(brokerageUser.getId(), 1); | |
| 104 | + Long firstBrokerageUserCount = brokerageUserService.getBrokerageUserCountByBindUserId(userId, 1); | |
| 95 | 105 | // 统计分销用户数量(二级) |
| 96 | - Long secondBrokerageUserCount = brokerageUserService.getBrokerageUserCountByBindUserId(brokerageUser.getId(), 2); | |
| 106 | + Long secondBrokerageUserCount = brokerageUserService.getBrokerageUserCountByBindUserId(userId, 2); | |
| 97 | 107 | |
| 98 | 108 | // 拼接返回 |
| 99 | 109 | return success(BrokerageUserConvert.INSTANCE.convert(yesterdayPrice, withdrawPrice, firstBrokerageUserCount, secondBrokerageUserCount, brokerageUser)); | ... | ... |
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/social/AppSocialUserController.java
| 1 | 1 | package cn.iocoder.yudao.module.member.controller.app.social; |
| 2 | 2 | |
| 3 | +import cn.hutool.core.codec.Base64; | |
| 4 | +import cn.hutool.core.util.ObjUtil; | |
| 3 | 5 | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; |
| 4 | 6 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 5 | 7 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| ... | ... | @@ -22,8 +24,6 @@ import jakarta.validation.Valid; |
| 22 | 24 | import org.springframework.validation.annotation.Validated; |
| 23 | 25 | import org.springframework.web.bind.annotation.*; |
| 24 | 26 | |
| 25 | -import java.util.Base64; | |
| 26 | - | |
| 27 | 27 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 28 | 28 | import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; |
| 29 | 29 | |
| ... | ... | @@ -33,6 +33,13 @@ import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUti |
| 33 | 33 | @Validated |
| 34 | 34 | public class AppSocialUserController { |
| 35 | 35 | |
| 36 | + public static final String ENV_VERSION = "release"; // 小程序版本。正式版为 "release",体验版为 "trial",开发版为 "develop" | |
| 37 | + private static final String SCENE = ""; // 页面路径不能携带参数(参数请放在scene字段里) | |
| 38 | + private static final Integer WIDTH = 430; // 二维码宽度 | |
| 39 | + private static final Boolean AUTO_COLOR = true; // 默认true 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调 | |
| 40 | + private static final Boolean CHECK_PATH = true; // 默认true 检查 page 是否存在 | |
| 41 | + private static final Boolean HYALINE = true; // 是否需要透明底色, hyaline 为true时,生成透明底色的小程序码 | |
| 42 | + | |
| 36 | 43 | @Resource |
| 37 | 44 | private SocialUserApi socialUserApi; |
| 38 | 45 | @Resource |
| ... | ... | @@ -69,10 +76,13 @@ public class AppSocialUserController { |
| 69 | 76 | @PostMapping("/wxa-qrcode") |
| 70 | 77 | @Operation(summary = "获得微信小程序码(base64 image)") |
| 71 | 78 | public CommonResult<String> getWxQrcode(@RequestBody @Valid AppSocialWxQrcodeReqVO reqVO) { |
| 72 | - byte[] wxQrcode = socialClientApi.getWxaQrcode(BeanUtils.toBean(reqVO, SocialWxQrcodeReqDTO.class) | |
| 73 | - .setEnvVersion(AppSocialWxQrcodeReqVO.ENV_VERSION)); | |
| 74 | - // TODO @puhui999:1)是不是 base64 返回,不拼接哈 data:image/png;base64;2)cn.hutool.core.codec.Base64.encode() | |
| 75 | - return success("data:image/png;base64," + Base64.getEncoder().encodeToString(wxQrcode)); | |
| 79 | + byte[] wxQrcode = socialClientApi.getWxaQrcode(new SocialWxQrcodeReqDTO().setPath(reqVO.getPath()) | |
| 80 | + .setEnvVersion(ENV_VERSION).setWidth(ObjUtil.defaultIfNull(reqVO.getWidth(), WIDTH)) | |
| 81 | + .setScene(ObjUtil.defaultIfNull(reqVO.getScene(), SCENE)) | |
| 82 | + .setAutoColor(ObjUtil.defaultIfNull(reqVO.getAutoColor(), AUTO_COLOR)) | |
| 83 | + .setHyaline(ObjUtil.defaultIfNull(reqVO.getHyaline(), HYALINE)) | |
| 84 | + .setCheckPath(ObjUtil.defaultIfNull(reqVO.getCheckPath(), CHECK_PATH))); | |
| 85 | + return success(Base64.encode(wxQrcode)); | |
| 76 | 86 | } |
| 77 | 87 | |
| 78 | 88 | } | ... | ... |
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/social/vo/AppSocialWxQrcodeReqVO.java
| ... | ... | @@ -9,20 +9,11 @@ import lombok.Data; |
| 9 | 9 | @Data |
| 10 | 10 | public class AppSocialWxQrcodeReqVO { |
| 11 | 11 | |
| 12 | - // TODO @puhui999: 没有默认值 getQrcodeService().createWxaCodeUnlimitBytes() 转类型会报错 🤣 | |
| 13 | - // TODO @puhui999:懂了哈;default 最好在 controller 搞;对于 VO 来说,不给默认值; | |
| 14 | - public static String ENV_VERSION = "release"; // 小程序版本。正式版为 "release",体验版为 "trial",开发版为 "develop" | |
| 15 | - private static String SCENE = ""; // 页面路径不能携带参数(参数请放在scene字段里) | |
| 16 | - private static Integer WIDTH = 430; // 二维码宽度 | |
| 17 | - private static Boolean AUTO_COLOR = true; // 默认true 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调 | |
| 18 | - private static Boolean CHECK_PATH = true; // 默认true 检查 page 是否存在 | |
| 19 | - private static Boolean HYALINE = true; // 是否需要透明底色, is_hyaline 为true时,生成透明底色的小程序码 | |
| 20 | - | |
| 21 | 12 | /** |
| 22 | 13 | * 页面路径不能携带参数(参数请放在scene字段里) |
| 23 | 14 | */ |
| 24 | 15 | @Schema(description = "场景值", requiredMode = Schema.RequiredMode.REQUIRED, example = "1001") |
| 25 | - private String scene = SCENE; | |
| 16 | + private String scene; | |
| 26 | 17 | |
| 27 | 18 | /** |
| 28 | 19 | * 默认是主页,页面 page,例如 pages/index/index,根路径前不要填加 /,不能携带参数(参数请放在scene字段里), |
| ... | ... | @@ -33,15 +24,15 @@ public class AppSocialWxQrcodeReqVO { |
| 33 | 24 | private String path; |
| 34 | 25 | |
| 35 | 26 | @Schema(description = "二维码宽度", requiredMode = Schema.RequiredMode.REQUIRED, example = "430") |
| 36 | - private Integer width = WIDTH; | |
| 27 | + private Integer width; | |
| 37 | 28 | |
| 38 | 29 | @Schema(description = "是/否自动配置线条颜色", requiredMode = Schema.RequiredMode.REQUIRED, example = "true") |
| 39 | - private Boolean autoColor = AUTO_COLOR; | |
| 30 | + private Boolean autoColor; | |
| 40 | 31 | |
| 41 | 32 | @Schema(description = "是/否检查 page 是否存在", requiredMode = Schema.RequiredMode.REQUIRED, example = "true") |
| 42 | - private Boolean checkPath = CHECK_PATH; | |
| 33 | + private Boolean checkPath; | |
| 43 | 34 | |
| 44 | 35 | @Schema(description = "是/否需要透明底色", requiredMode = Schema.RequiredMode.REQUIRED, example = "true") |
| 45 | - private Boolean hyaline = HYALINE; | |
| 36 | + private Boolean hyaline; | |
| 46 | 37 | |
| 47 | 38 | } | ... | ... |