From a04a3a27a9e79d3e6d5cb99a41b4134419fc164a Mon Sep 17 00:00:00 2001 From: owen Date: Sat, 30 Sep 2023 23:41:11 +0800 Subject: [PATCH] =?UTF-8?q?Review=E4=BB=A3=E7=A0=81=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dal/mysql/coupon/CouponMapper.java | 20 +++++++++------ .../service/coupon/CouponService.java | 25 +++---------------- .../service/coupon/CouponServiceImpl.java | 11 +++----- .../service/coupon/bo/CouponTakeCountBO.java | 22 ---------------- .../trade/TradeStatisticsController.java | 2 -- 5 files changed, 19 insertions(+), 61 deletions(-) delete mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/bo/CouponTakeCountBO.java diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/coupon/CouponMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/coupon/CouponMapper.java index f5a8ce4e8..e5f1daf6c 100755 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/coupon/CouponMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/coupon/CouponMapper.java @@ -1,6 +1,6 @@ package cn.iocoder.yudao.module.promotion.dal.mysql.coupon; -import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.map.MapUtil; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; @@ -8,7 +8,6 @@ import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.coupon.CouponPageReqVO; import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponDO; import cn.iocoder.yudao.module.promotion.enums.common.PromotionProductScopeEnum; -import cn.iocoder.yudao.module.promotion.service.coupon.bo.CouponTakeCountBO; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.github.yulichang.toolkit.MPJWrappers; import org.apache.ibatis.annotations.Mapper; @@ -16,9 +15,12 @@ import org.apache.ibatis.annotations.Mapper; import java.time.LocalDateTime; import java.util.Collection; import java.util.List; +import java.util.Map; import java.util.function.Function; import java.util.stream.Collectors; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; + /** * 优惠劵 Mapper * @@ -70,14 +72,16 @@ public interface CouponMapper extends BaseMapperX { ); } - // TODO @疯狂:这个是不是搞个 Map 就可以呀? - default List selectCountByUserIdAndTemplateIdIn(Long userId, Collection templateIds) { - return BeanUtil.copyToList(selectMaps(MPJWrappers.lambdaJoin(CouponDO.class) - .select(CouponDO::getTemplateId) - .selectCount(CouponDO::getId, CouponTakeCountBO::getCount) + default Map selectCountByUserIdAndTemplateIdIn(Long userId, Collection templateIds) { + String templateIdAlias = "templateId"; + String countAlias = "count"; + List> list = selectMaps(MPJWrappers.lambdaJoin(CouponDO.class) + .selectAs(CouponDO::getTemplateId, templateIdAlias) + .selectCount(CouponDO::getId, countAlias) .eq(CouponDO::getUserId, userId) .in(CouponDO::getTemplateId, templateIds) - .groupBy(CouponDO::getTemplateId)), CouponTakeCountBO.class); + .groupBy(CouponDO::getTemplateId)); + return convertMap(list, map -> MapUtil.getLong(map, templateIdAlias), map -> MapUtil.getInt(map, countAlias)); } default List selectListByUserIdAndStatusAndUsePriceLeAndProductScope( diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponService.java index 7b7d1e1d9..7cc13e2ce 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponService.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponService.java @@ -1,18 +1,16 @@ package cn.iocoder.yudao.module.promotion.service.coupon; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.map.MapUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.coupon.CouponPageReqVO; import cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.coupon.AppCouponMatchReqVO; import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponTemplateDO; import cn.iocoder.yudao.module.promotion.enums.coupon.CouponTakeTypeEnum; -import cn.iocoder.yudao.module.promotion.service.coupon.bo.CouponTakeCountBO; import java.util.*; -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; - /** * 优惠劵 Service 接口 * @@ -132,11 +130,8 @@ public interface CouponService { * @return 领取优惠券的数量 */ default Integer getTakeCount(Long templateId, Long userId) { - return CollUtil.emptyIfNull(getTakeCountListByTemplateIds(Collections.singleton(templateId), userId)) - .stream() - .findFirst() - .map(CouponTakeCountBO::getCount) - .orElse(0); + Map map = getTakeCountMapByTemplateIds(Collections.singleton(templateId), userId); + return MapUtil.getInt(map, templateId, 0); } /** @@ -146,19 +141,7 @@ public interface CouponService { * @param userId 用户编号 * @return 领取优惠券的数量 */ - default Map getTakeCountMapByTemplateIds(Collection templateIds, Long userId) { - return convertMap(getTakeCountListByTemplateIds(templateIds, userId), - CouponTakeCountBO::getTemplateId, CouponTakeCountBO::getCount); - } - - /** - * 统计会员领取优惠券的数量 - * - * @param templateIds 优惠券模板编号列表 - * @param userId 用户编号 - * @return 领取优惠券的数量 - */ - List getTakeCountListByTemplateIds(Collection templateIds, Long userId); + Map getTakeCountMapByTemplateIds(Collection templateIds, Long userId); /** * 获取用户匹配的优惠券列表 diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponServiceImpl.java index 68f5c53f8..8be928476 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponServiceImpl.java @@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.promotion.service.coupon; import cn.hutool.core.collection.CollStreamUtil; import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.collection.ListUtil; import cn.hutool.core.map.MapUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; @@ -21,7 +20,6 @@ import cn.iocoder.yudao.module.promotion.dal.mysql.coupon.CouponMapper; import cn.iocoder.yudao.module.promotion.enums.coupon.CouponStatusEnum; import cn.iocoder.yudao.module.promotion.enums.coupon.CouponTakeTypeEnum; import cn.iocoder.yudao.module.promotion.enums.coupon.CouponTemplateValidityTypeEnum; -import cn.iocoder.yudao.module.promotion.service.coupon.bo.CouponTakeCountBO; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -29,10 +27,7 @@ import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; import java.time.LocalDateTime; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; import java.util.stream.Collectors; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; @@ -191,9 +186,9 @@ public class CouponServiceImpl implements CouponService { } @Override - public List getTakeCountListByTemplateIds(Collection templateIds, Long userId) { + public Map getTakeCountMapByTemplateIds(Collection templateIds, Long userId) { if (CollUtil.isEmpty(templateIds)) { - return ListUtil.empty(); + return Collections.emptyMap(); } return couponMapper.selectCountByUserIdAndTemplateIdIn(userId, templateIds); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/bo/CouponTakeCountBO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/bo/CouponTakeCountBO.java deleted file mode 100644 index 6e563ffb5..000000000 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/bo/CouponTakeCountBO.java +++ /dev/null @@ -1,22 +0,0 @@ -package cn.iocoder.yudao.module.promotion.service.coupon.bo; - -import lombok.Data; - -/** - * 优惠券领取数量 BO - * - * @author owen - */ -@Data -public class CouponTakeCountBO { - - /** - * 优惠劵模板编号 - */ - private Long templateId; - /** - * 领取数量 - */ - private Integer count; - -} diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/trade/TradeStatisticsController.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/trade/TradeStatisticsController.java index 158e5ac95..aa5b711cb 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/trade/TradeStatisticsController.java +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/trade/TradeStatisticsController.java @@ -32,7 +32,6 @@ public class TradeStatisticsController { @Resource private TradeStatisticsService tradeStatisticsService; - // TODO @疯狂:要不这个就是 /trend/summary 的特例,前端自己查询两次? @GetMapping("/summary") @Operation(summary = "获得交易统计") @PreAuthorize("@ss.hasPermission('statistics:trade:query')") @@ -40,7 +39,6 @@ public class TradeStatisticsController { return success(tradeStatisticsService.getTradeSummaryComparison()); } - // TODO @疯狂:直接 comparison?主要 trend 和 comparison 二选一,一个是数据趋势,一个是数据对比哈; @GetMapping("/trend/summary") @Operation(summary = "获得交易状况统计") @PreAuthorize("@ss.hasPermission('statistics:trade:query')")