分销:Review代码修改

This commit is contained in:
owen
2023-09-24 20:28:44 +08:00
parent 421bb7d154
commit e9fd377772
20 changed files with 131 additions and 102 deletions

View File

@ -0,0 +1,11 @@
package cn.iocoder.yudao.module.trade.enums;
/**
* Trade 字典类型的枚举类
*
* @author owen
*/
public interface DictTypeConstants {
String BROKERAGE_WITHDRAW_STATUS = "brokerage_withdraw_status"; // 佣金提现状态
}

View File

@ -22,9 +22,6 @@ public enum BrokerageWithdrawStatusEnum implements IntArrayValuable {
WITHDRAW_FAIL(21, "提现失败"),
;
// TODO @疯狂:字典现在枚举在每个模块的 DictTypeConstants 里哈;可以创建一个出来;主要是想,治理每个模块到底有多少个枚举;
public static final String DICT_TYPE = "BROKERAGE_WITHDRAW_STATUS";
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(BrokerageWithdrawStatusEnum::getStatus).toArray();
/**

View File

@ -67,8 +67,8 @@ public class AppBrokerageUserController {
@Operation(summary = "绑定推广员")
@PreAuthenticated
public CommonResult<Boolean> bindBrokerageUser(@Valid @RequestBody AppBrokerageUserBindReqVO reqVO) {
// TODO @疯狂:是不是 isNewUser 不用传递哈,交给 service 自己计算出来?
return success(brokerageUserService.bindBrokerageUser(getLoginUserId(), reqVO.getBindUserId(), false));
MemberUserRespDTO user = memberUserApi.getUser(getLoginUserId());
return success(brokerageUserService.bindBrokerageUser(user.getId(), reqVO.getBindUserId(), user.getCreateTime()));
}
@GetMapping("/get-summary")

View File

@ -9,7 +9,6 @@ import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.withdraw.AppBro
import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.withdraw.AppBrokerageWithdrawRespVO;
import cn.iocoder.yudao.module.trade.convert.brokerage.BrokerageWithdrawConvert;
import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageWithdrawDO;
import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageWithdrawStatusEnum;
import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageWithdrawService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
@ -19,7 +18,6 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Map;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.getLoginUserId;
@ -44,10 +42,7 @@ public class AppBrokerageWithdrawController {
// 分页查询
PageResult<BrokerageWithdrawDO> pageResult = brokerageWithdrawService.getBrokerageWithdrawPage(
BrokerageWithdrawConvert.INSTANCE.convert(pageReqVO, getLoginUserId()));
// 拼接信息
// TODO @疯狂:后端可以直接用 DictFrameworkUtils.getDictDataLabel() 去渲染哈;这样就不用 getDictDataLabelMap 方法了;
Map<String, String> statusNameMap = dictDataApi.getDictDataLabelMap(BrokerageWithdrawStatusEnum.DICT_TYPE);
return success(BrokerageWithdrawConvert.INSTANCE.convertPage02(pageResult, statusNameMap));
return success(BrokerageWithdrawConvert.INSTANCE.convertPage03(pageResult));
}
@PostMapping("/create")

View File

@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.trade.controller.app.config;
import cn.hutool.core.util.ObjUtil;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.trade.controller.app.config.vo.AppTradeConfigRespVO;
import cn.iocoder.yudao.module.trade.convert.config.TradeConfigConvert;
import cn.iocoder.yudao.module.trade.dal.dataobject.config.TradeConfigDO;
import cn.iocoder.yudao.module.trade.service.config.TradeConfigService;
import io.swagger.v3.oas.annotations.Operation;
@ -33,13 +34,7 @@ public class AppTradeConfigController {
@Operation(summary = "获得交易配置")
public CommonResult<AppTradeConfigRespVO> getTradeConfig() {
TradeConfigDO tradeConfig = ObjUtil.defaultIfNull(tradeConfigService.getTradeConfig(), new TradeConfigDO());
// TODO @疯狂:是不是直接 convert 就好啦;
AppTradeConfigRespVO respVO = new AppTradeConfigRespVO()
.setBrokeragePosterUrls(tradeConfig.getBrokeragePostUrls())
.setBrokerageFrozenDays(tradeConfig.getBrokerageFrozenDays())
.setBrokerageWithdrawMinPrice(tradeConfig.getBrokerageWithdrawMinPrice())
.setBrokerageWithdrawType(tradeConfig.getBrokerageWithdrawType());
return success(respVO);
return success(TradeConfigConvert.INSTANCE.convert02(tradeConfig));
}
}

View File

@ -4,6 +4,7 @@ import cn.hutool.core.math.Money;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.number.MoneyUtils;
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.record.BrokerageRecordPageReqVO;
import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.record.BrokerageRecordRespVO;
@ -51,7 +52,7 @@ public interface BrokerageRecordConvert {
.setBizType(bizType.getType()).setBizId(bizId)
.setPrice(brokeragePrice).setTotalPrice(user.getBrokeragePrice())
.setTitle(title)
.setDescription(StrUtil.format(bizType.getDescription(), new Money(0, Math.abs(brokeragePrice))))
.setDescription(StrUtil.format(bizType.getDescription(), MoneyUtils.fenToYuanStr(Math.abs(brokeragePrice))))
.setStatus(status).setFrozenDays(brokerageFrozenDays).setUnfreezeTime(unfreezeTime)
.setSourceUserLevel(sourceUserLevel).setSourceUserId(sourceUserId);
}

View File

@ -1,7 +1,7 @@
package cn.iocoder.yudao.module.trade.convert.brokerage;
import cn.hutool.core.map.MapUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.dict.core.util.DictFrameworkUtils;
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.withdraw.BrokerageWithdrawPageReqVO;
import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.withdraw.BrokerageWithdrawRespVO;
@ -9,6 +9,7 @@ import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.withdraw.AppBro
import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.withdraw.AppBrokerageWithdrawPageReqVO;
import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.withdraw.AppBrokerageWithdrawRespVO;
import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageWithdrawDO;
import cn.iocoder.yudao.module.trade.enums.DictTypeConstants;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
@ -44,10 +45,10 @@ public interface BrokerageWithdrawConvert {
PageResult<AppBrokerageWithdrawRespVO> convertPage02(PageResult<BrokerageWithdrawDO> pageResult);
default PageResult<AppBrokerageWithdrawRespVO> convertPage02(PageResult<BrokerageWithdrawDO> pageResult, Map<String, String> statusNameMap) {
default PageResult<AppBrokerageWithdrawRespVO> convertPage03(PageResult<BrokerageWithdrawDO> pageResult) {
PageResult<AppBrokerageWithdrawRespVO> result = convertPage02(pageResult);
for (AppBrokerageWithdrawRespVO vo : result.getList()) {
vo.setStatusName(MapUtil.getStr(statusNameMap, String.valueOf(vo.getStatus()), ""));
vo.setStatusName(DictFrameworkUtils.getDictDataLabel(DictTypeConstants.BROKERAGE_WITHDRAW_STATUS, vo.getStatus()));
}
return result;
}

View File

@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.trade.convert.config;
import cn.iocoder.yudao.module.trade.controller.admin.config.vo.TradeConfigRespVO;
import cn.iocoder.yudao.module.trade.controller.admin.config.vo.TradeConfigSaveReqVO;
import cn.iocoder.yudao.module.trade.controller.app.config.vo.AppTradeConfigRespVO;
import cn.iocoder.yudao.module.trade.dal.dataobject.config.TradeConfigDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
@ -20,4 +21,5 @@ public interface TradeConfigConvert {
TradeConfigRespVO convert(TradeConfigDO bean);
AppTradeConfigRespVO convert02(TradeConfigDO tradeConfig);
}

View File

@ -1,7 +1,6 @@
package cn.iocoder.yudao.module.trade.service.brokerage;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.math.Money;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.BooleanUtil;
import cn.hutool.core.util.ObjectUtil;
@ -240,7 +239,6 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService {
return new PageResult<>(pageResult.getRecords(), pageResult.getTotal());
}
// TODO @疯狂:这个求出来,应该是不准的?例如说超过 100+ 名后?
@Override
public Integer getUserRankByPrice(Long userId, LocalDateTime[] times) {
AppBrokerageUserRankPageReqVO pageParam = new AppBrokerageUserRankPageReqVO().setTimes(times);
@ -261,15 +259,14 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService {
int balance = Optional.of(user)
.map(BrokerageUserDO::getBrokeragePrice).orElse(0);
if (balance + brokeragePrice < 0) {
// TODO @疯狂:要不 MoneyUtils 那,统一搞个 format 金额的方法?然后把分到元的字符串,统一收口掉;
throw exception(BROKERAGE_WITHDRAW_USER_BALANCE_NOT_ENOUGH, new Money(0, balance));
throw exception(BROKERAGE_WITHDRAW_USER_BALANCE_NOT_ENOUGH, MoneyUtils.fenToYuanStr(balance));
}
// 2. 更新佣金余额
boolean success = brokerageUserService.updateUserPrice(userId, brokeragePrice);
if (!success) {
// 失败时,则抛出异常。只会出现扣减佣金时,余额不足的情况
throw exception(BROKERAGE_WITHDRAW_USER_BALANCE_NOT_ENOUGH, new Money(0, balance));
throw exception(BROKERAGE_WITHDRAW_USER_BALANCE_NOT_ENOUGH, MoneyUtils.fenToYuanStr(balance));
}
// 3. 新增记录

View File

@ -187,7 +187,7 @@ public class BrokerageUserServiceImpl implements BrokerageUserService {
/**
* 补全绑定用户的字段
*
* @param bindUserId 绑定的用户编号
* @param bindUserId 绑定的用户编号
* @param brokerageUser update 对象
* @return 补全后的 update 对象
*/
@ -261,12 +261,15 @@ public class BrokerageUserServiceImpl implements BrokerageUserService {
}
// 下级不能绑定自己的上级
// TODO @疯狂:这里是不是查询不到的时候,应该有个 break 结束循环哈
for (int i = 0; i <= Short.MAX_VALUE; i++) {
if (Objects.equals(bindUser.getBindUserId(), user.getId())) {
throw exception(BROKERAGE_BIND_LOOP);
}
bindUser = getBrokerageUser(bindUser.getBindUserId());
// 找到根节点,结束循环
if (bindUser == null || bindUser.getBindUserId() == null) {
break;
}
}
}
@ -274,8 +277,8 @@ public class BrokerageUserServiceImpl implements BrokerageUserService {
* 根据绑定用户编号,获得绑定用户编号列表
*
* @param bindUserId 绑定用户编号
* @param level 绑定用户的层级。
* 如果 level 为空,则查询 1+2 两个层级
* @param level 绑定用户的层级。
* 如果 level 为空,则查询 1+2 两个层级
* @return 绑定用户编号列表
*/
private List<Long> buildBindUserIdsByLevel(Long bindUserId, Integer level) {

View File

@ -93,7 +93,7 @@ public class BrokerageWithdrawServiceImpl implements BrokerageWithdrawService {
// 4. 通知用户
Map<String, Object> templateParams = MapUtil.<String, Object>builder()
.put("createTime", LocalDateTimeUtil.formatNormal(withdraw.getCreateTime()))
.put("price", new Money(0, withdraw.getPrice()).toString())
.put("price", MoneyUtils.fenToYuanStr(withdraw.getPrice()))
.put("reason", withdraw.getAuditReason())
.build();
NotifySendSingleToUserReqDTO reqDTO = new NotifySendSingleToUserReqDTO()
@ -170,7 +170,7 @@ public class BrokerageWithdrawServiceImpl implements BrokerageWithdrawService {
TradeConfigDO validateWithdrawPrice(Integer withdrawPrice) {
TradeConfigDO tradeConfig = tradeConfigService.getTradeConfig();
if (tradeConfig.getBrokerageWithdrawMinPrice() != null && withdrawPrice < tradeConfig.getBrokerageWithdrawMinPrice()) {
throw exception(BROKERAGE_WITHDRAW_MIN_PRICE, new Money(0, tradeConfig.getBrokerageWithdrawMinPrice()));
throw exception(BROKERAGE_WITHDRAW_MIN_PRICE, MoneyUtils.fenToYuanStr(tradeConfig.getBrokerageWithdrawMinPrice()));
}
return tradeConfig;
}