diff --git a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/number/MoneyUtils.java b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/number/MoneyUtils.java index e2fd3fa6e..cac8438e0 100644 --- a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/number/MoneyUtils.java +++ b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/number/MoneyUtils.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.framework.common.util.number; +import cn.hutool.core.math.Money; import cn.hutool.core.util.NumberUtil; import java.math.BigDecimal; @@ -16,7 +17,7 @@ public class MoneyUtils { * 计算百分比金额,四舍五入 * * @param price 金额 - * @param rate 百分比,例如说 56.77% 则传入 56.77 + * @param rate 百分比,例如说 56.77% 则传入 56.77 * @return 百分比金额 */ public static Integer calculateRatePrice(Integer price, Double rate) { @@ -27,24 +28,43 @@ public class MoneyUtils { * 计算百分比金额,向下传入 * * @param price 金额 - * @param rate 百分比,例如说 56.77% 则传入 56.77 + * @param rate 百分比,例如说 56.77% 则传入 56.77 * @return 百分比金额 */ public static Integer calculateRatePriceFloor(Integer price, Double rate) { return calculateRatePrice(price, rate, 0, RoundingMode.FLOOR).intValue(); } - /** - * 计算百分比金额 - * - * @param price 金额 - * @param rate 百分比,例如说 56.77% 则传入 56.77 - * @param scale 保留小数位数 - * @param roundingMode 舍入模式 - */ - public static BigDecimal calculateRatePrice(Number price, Number rate, int scale, RoundingMode roundingMode) { - return NumberUtil.toBigDecimal(price).multiply(NumberUtil.toBigDecimal(rate)) // 乘以 - .divide(BigDecimal.valueOf(100), scale, roundingMode); // 除以 100 - } + /** + * 计算百分比金额 + * + * @param price 金额 + * @param rate 百分比,例如说 56.77% 则传入 56.77 + * @param scale 保留小数位数 + * @param roundingMode 舍入模式 + */ + public static BigDecimal calculateRatePrice(Number price, Number rate, int scale, RoundingMode roundingMode) { + return NumberUtil.toBigDecimal(price).multiply(NumberUtil.toBigDecimal(rate)) // 乘以 + .divide(BigDecimal.valueOf(100), scale, roundingMode); // 除以 100 + } + /** + * 分转元 + * + * @param fen 分 + * @return 元 + */ + public static BigDecimal fenToYuan(int fen) { + return new Money(0, fen).getAmount(); + } + + /** + * 分转元(字符串) + * + * @param fen 分 + * @return 元 + */ + public static String fenToYuanStr(int fen) { + return new Money(0, fen).toString(); + } } diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/DictTypeConstants.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/DictTypeConstants.java new file mode 100644 index 000000000..4ff3c95f2 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/DictTypeConstants.java @@ -0,0 +1,11 @@ +package cn.iocoder.yudao.module.trade.enums; + +/** + * Trade 字典类型的枚举类 + * + * @author owen + */ +public interface DictTypeConstants { + + String BROKERAGE_WITHDRAW_STATUS = "brokerage_withdraw_status"; // 佣金提现状态 +} diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageWithdrawStatusEnum.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageWithdrawStatusEnum.java index 59dfbfbc8..a80aad02a 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageWithdrawStatusEnum.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageWithdrawStatusEnum.java @@ -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(); /** diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java index c7db41647..5471e0b54 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java @@ -67,8 +67,8 @@ public class AppBrokerageUserController { @Operation(summary = "绑定推广员") @PreAuthenticated public CommonResult 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") diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageWithdrawController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageWithdrawController.java index 77bae4be9..8ca12b79b 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageWithdrawController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageWithdrawController.java @@ -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 pageResult = brokerageWithdrawService.getBrokerageWithdrawPage( BrokerageWithdrawConvert.INSTANCE.convert(pageReqVO, getLoginUserId())); - // 拼接信息 - // TODO @疯狂:后端可以直接用 DictFrameworkUtils.getDictDataLabel() 去渲染哈;这样就不用 getDictDataLabelMap 方法了; - Map statusNameMap = dictDataApi.getDictDataLabelMap(BrokerageWithdrawStatusEnum.DICT_TYPE); - return success(BrokerageWithdrawConvert.INSTANCE.convertPage02(pageResult, statusNameMap)); + return success(BrokerageWithdrawConvert.INSTANCE.convertPage03(pageResult)); } @PostMapping("/create") diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/config/AppTradeConfigController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/config/AppTradeConfigController.java index 47c21ed57..6b7660a1c 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/config/AppTradeConfigController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/config/AppTradeConfigController.java @@ -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 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)); } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageRecordConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageRecordConvert.java index 175db060c..e6c0e4f8c 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageRecordConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageRecordConvert.java @@ -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); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageWithdrawConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageWithdrawConvert.java index 82932bbe5..69441ab07 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageWithdrawConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageWithdrawConvert.java @@ -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 convertPage02(PageResult pageResult); - default PageResult convertPage02(PageResult pageResult, Map statusNameMap) { + default PageResult convertPage03(PageResult pageResult) { PageResult 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; } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/config/TradeConfigConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/config/TradeConfigConvert.java index 031f1198a..57da020c2 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/config/TradeConfigConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/config/TradeConfigConvert.java @@ -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); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordServiceImpl.java index 88114731d..1080dbfc1 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordServiceImpl.java @@ -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. 新增记录 diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserServiceImpl.java index 658e99326..182e457b5 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserServiceImpl.java @@ -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 buildBindUserIdsByLevel(Long bindUserId, Integer level) { diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawServiceImpl.java index 82334955c..783b0685a 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawServiceImpl.java @@ -93,7 +93,7 @@ public class BrokerageWithdrawServiceImpl implements BrokerageWithdrawService { // 4. 通知用户 Map templateParams = MapUtil.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; } diff --git a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/user/dto/MemberUserRespDTO.java b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/user/dto/MemberUserRespDTO.java index c426fbbf1..85dad84d7 100644 --- a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/user/dto/MemberUserRespDTO.java +++ b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/user/dto/MemberUserRespDTO.java @@ -3,6 +3,8 @@ package cn.iocoder.yudao.module.member.api.user.dto; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import lombok.Data; +import java.time.LocalDateTime; + /** * 用户信息 Response DTO * @@ -33,6 +35,10 @@ public class MemberUserRespDTO { * 手机 */ private String mobile; + /** + * 创建时间 + */ + private LocalDateTime createTime; // ========== 其它信息 ========== diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/dict/DictDataApi.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/dict/DictDataApi.java index 34c33c568..107184564 100644 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/dict/DictDataApi.java +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/dict/DictDataApi.java @@ -3,8 +3,6 @@ package cn.iocoder.yudao.module.system.api.dict; import cn.iocoder.yudao.module.system.api.dict.dto.DictDataRespDTO; import java.util.Collection; -import java.util.List; -import java.util.Map; /** * 字典数据 API 接口 @@ -19,40 +17,23 @@ public interface DictDataApi { * 2. 字典数据被禁用 * * @param dictType 字典类型 - * @param values 字典数据值的数组 + * @param values 字典数据值的数组 */ void validateDictDataList(String dictType, Collection values); /** * 获得指定的字典数据,从缓存中 * - * @param type 字典类型 + * @param type 字典类型 * @param value 字典数据值 * @return 字典数据 */ DictDataRespDTO getDictData(String type, String value); - /** - * 获得指定类型的字典数据,从缓存中 - * - * @param type 字典类型 - * @return 字典数据 - */ - List getDictDataList(String type); - - /** - * 获得指定类型的字典数据 标签字典,从缓存中 - * key:value, value: label - * - * @param type 字典类型 - * @return 字典数据 - */ - Map getDictDataLabelMap(String type); - /** * 解析获得指定的字典数据,从缓存中 * - * @param type 字典类型 + * @param type 字典类型 * @param label 字典数据标签 * @return 字典数据 */ diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/dict/DictDataApiImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/dict/DictDataApiImpl.java index d50ac0299..e88771fa7 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/dict/DictDataApiImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/dict/DictDataApiImpl.java @@ -1,7 +1,6 @@ package cn.iocoder.yudao.module.system.api.dict; import cn.iocoder.yudao.module.system.api.dict.dto.DictDataRespDTO; -import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.DictDataExportReqVO; import cn.iocoder.yudao.module.system.convert.dict.DictDataConvert; import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictDataDO; import cn.iocoder.yudao.module.system.service.dict.DictDataService; @@ -9,10 +8,6 @@ import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.Collection; -import java.util.List; -import java.util.Map; - -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; /** * 字典数据 API 实现类 @@ -36,19 +31,6 @@ public class DictDataApiImpl implements DictDataApi { return DictDataConvert.INSTANCE.convert02(dictData); } - @Override - public List getDictDataList(String type) { - // TODO @疯狂:不用 DictDataExportReqVO 哈;可以考虑直接加个允许传递 type 传递的 - List list = dictDataService.getDictDataList(new DictDataExportReqVO().setDictType(type)); - return DictDataConvert.INSTANCE.convertList04(list); - } - - @Override - public Map getDictDataLabelMap(String type) { - List list = dictDataService.getDictDataList(new DictDataExportReqVO().setDictType(type)); - return convertMap(list, DictDataDO::getValue, DictDataDO::getLabel); - } - @Override public DictDataRespDTO parseDictData(String dictType, String label) { DictDataDO dictData = dictDataService.parseDictData(dictType, label); diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/AppDictDataController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/AppDictDataController.java index 95ae7e187..2332875b8 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/AppDictDataController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/AppDictDataController.java @@ -1,17 +1,17 @@ package cn.iocoder.yudao.module.system.controller.app.dict; import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.DictDataExportReqVO; import cn.iocoder.yudao.module.system.controller.app.dict.vo.AppDictDataRespVO; import cn.iocoder.yudao.module.system.convert.dict.DictDataConvert; import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictDataDO; import cn.iocoder.yudao.module.system.service.dict.DictDataService; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; @@ -28,11 +28,11 @@ public class AppDictDataController { @Resource private DictDataService dictDataService; - // TODO @疯狂:暂时不用 path 参数哈;主要考虑一些中间件支持的一般,例如说链路追踪之类的;还是作为一个参数噶; - @GetMapping("/type/{dictType}") + @GetMapping("/type") @Operation(summary = "根据字典类型查询字典数据信息") - public CommonResult> getDictDataList(@PathVariable String dictType) { - List list = dictDataService.getDictDataList(new DictDataExportReqVO().setDictType(dictType)); + @Parameter(name = "type", description = "字典类型", required = true, example = "common_status") + public CommonResult> getDictDataListByType(@RequestParam String type) { + List list = dictDataService.getEnabledDictDataListByType(type); return success(DictDataConvert.INSTANCE.convertList03(list)); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/vo/AppDictDataRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/vo/AppDictDataRespVO.java index 307fa9821..b7dfaf230 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/vo/AppDictDataRespVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/vo/AppDictDataRespVO.java @@ -1,22 +1,41 @@ package cn.iocoder.yudao.module.system.controller.app.dict.vo; -import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.DictDataBaseVO; import io.swagger.v3.oas.annotations.media.Schema; import lombok.AllArgsConstructor; import lombok.Data; -import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; + @Schema(description = "用户 App - 字典数据信息 Response VO") @Data @NoArgsConstructor @AllArgsConstructor -@EqualsAndHashCode(callSuper = true) -public class AppDictDataRespVO extends DictDataBaseVO { - - // TODO @疯狂:app 的接口,不集成 admin 接口的 vo 哈;看看是不是只返回必要的字段,类似 remark、sort 不好返回的哈; +public class AppDictDataRespVO { @Schema(description = "字典数据编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") private Long id; + @Schema(description = "字典标签", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道") + @NotBlank(message = "字典标签不能为空") + @Size(max = 100, message = "字典标签长度不能超过100个字符") + private String label; + + @Schema(description = "字典值", requiredMode = Schema.RequiredMode.REQUIRED, example = "iocoder") + @NotBlank(message = "字典键值不能为空") + @Size(max = 100, message = "字典键值长度不能超过100个字符") + private String value; + + @Schema(description = "字典类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "sys_common_sex") + @NotBlank(message = "字典类型不能为空") + @Size(max = 100, message = "字典类型长度不能超过100个字符") + private String dictType; + + @Schema(description = "颜色类型,default、primary、success、info、warning、danger", example = "default") + private String colorType; + @Schema(description = "css 样式", example = "btn-visible") + private String cssClass; + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dict/DictDataMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dict/DictDataMapper.java index 244825093..85da83a5d 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dict/DictDataMapper.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dict/DictDataMapper.java @@ -48,4 +48,8 @@ public interface DictDataMapper extends BaseMapperX { .eqIfPresent(DictDataDO::getStatus, reqVO.getStatus())); } + default List selectListByTypeAndStatus(String dictType, Integer status) { + return selectList(new LambdaQueryWrapper() + .eq(DictDataDO::getDictType, dictType).eq(DictDataDO::getStatus, status)); + } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictDataService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictDataService.java index d2eb8c519..3fc6a4071 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictDataService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictDataService.java @@ -62,6 +62,14 @@ public interface DictDataService { */ List getDictDataList(DictDataExportReqVO reqVO); + /** + * 获得字典数据列表 + * + * @param dictType 字典类型 + * @return 字典数据列表 + */ + List getEnabledDictDataListByType(String dictType); + /** * 获得字典数据详情 * @@ -84,7 +92,7 @@ public interface DictDataService { * 2. 字典数据被禁用 * * @param dictType 字典类型 - * @param values 字典数据值的数组 + * @param values 字典数据值的数组 */ void validateDictDataList(String dictType, Collection values); @@ -92,7 +100,7 @@ public interface DictDataService { * 获得指定的字典数据 * * @param dictType 字典类型 - * @param value 字典数据值 + * @param value 字典数据值 * @return 字典数据 */ DictDataDO getDictData(String dictType, String value); @@ -101,7 +109,7 @@ public interface DictDataService { * 解析获得指定的字典数据,从缓存中 * * @param dictType 字典类型 - * @param label 字典数据标签 + * @param label 字典数据标签 * @return 字典数据 */ DictDataDO parseDictData(String dictType, String label); diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictDataServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictDataServiceImpl.java index 7cca762f4..8a49719fb 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictDataServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictDataServiceImpl.java @@ -66,6 +66,13 @@ public class DictDataServiceImpl implements DictDataService { return list; } + @Override + public List getEnabledDictDataListByType(String dictType) { + List list = dictDataMapper.selectListByTypeAndStatus(dictType, CommonStatusEnum.ENABLE.getStatus()); + list.sort(COMPARATOR_TYPE_AND_SORT); + return list; + } + @Override public DictDataDO getDictData(Long id) { return dictDataMapper.selectById(id);