Commit a04a3a27a9e79d3e6d5cb99a41b4134419fc164a
1 parent
7d68bdc7
Review代码修改
Showing
5 changed files
with
19 additions
and
61 deletions
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/coupon/CouponMapper.java
| 1 | 1 | package cn.iocoder.yudao.module.promotion.dal.mysql.coupon; |
| 2 | 2 | |
| 3 | -import cn.hutool.core.bean.BeanUtil; | |
| 3 | +import cn.hutool.core.map.MapUtil; | |
| 4 | 4 | import cn.hutool.core.util.StrUtil; |
| 5 | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | 6 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| ... | ... | @@ -8,7 +8,6 @@ import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; |
| 8 | 8 | import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.coupon.CouponPageReqVO; |
| 9 | 9 | import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponDO; |
| 10 | 10 | import cn.iocoder.yudao.module.promotion.enums.common.PromotionProductScopeEnum; |
| 11 | -import cn.iocoder.yudao.module.promotion.service.coupon.bo.CouponTakeCountBO; | |
| 12 | 11 | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| 13 | 12 | import com.github.yulichang.toolkit.MPJWrappers; |
| 14 | 13 | import org.apache.ibatis.annotations.Mapper; |
| ... | ... | @@ -16,9 +15,12 @@ import org.apache.ibatis.annotations.Mapper; |
| 16 | 15 | import java.time.LocalDateTime; |
| 17 | 16 | import java.util.Collection; |
| 18 | 17 | import java.util.List; |
| 18 | +import java.util.Map; | |
| 19 | 19 | import java.util.function.Function; |
| 20 | 20 | import java.util.stream.Collectors; |
| 21 | 21 | |
| 22 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; | |
| 23 | + | |
| 22 | 24 | /** |
| 23 | 25 | * 优惠劵 Mapper |
| 24 | 26 | * |
| ... | ... | @@ -70,14 +72,16 @@ public interface CouponMapper extends BaseMapperX<CouponDO> { |
| 70 | 72 | ); |
| 71 | 73 | } |
| 72 | 74 | |
| 73 | - // TODO @疯狂:这个是不是搞个 Map 就可以呀? | |
| 74 | - default List<CouponTakeCountBO> selectCountByUserIdAndTemplateIdIn(Long userId, Collection<Long> templateIds) { | |
| 75 | - return BeanUtil.copyToList(selectMaps(MPJWrappers.lambdaJoin(CouponDO.class) | |
| 76 | - .select(CouponDO::getTemplateId) | |
| 77 | - .selectCount(CouponDO::getId, CouponTakeCountBO::getCount) | |
| 75 | + default Map<Long, Integer> selectCountByUserIdAndTemplateIdIn(Long userId, Collection<Long> templateIds) { | |
| 76 | + String templateIdAlias = "templateId"; | |
| 77 | + String countAlias = "count"; | |
| 78 | + List<Map<String, Object>> list = selectMaps(MPJWrappers.lambdaJoin(CouponDO.class) | |
| 79 | + .selectAs(CouponDO::getTemplateId, templateIdAlias) | |
| 80 | + .selectCount(CouponDO::getId, countAlias) | |
| 78 | 81 | .eq(CouponDO::getUserId, userId) |
| 79 | 82 | .in(CouponDO::getTemplateId, templateIds) |
| 80 | - .groupBy(CouponDO::getTemplateId)), CouponTakeCountBO.class); | |
| 83 | + .groupBy(CouponDO::getTemplateId)); | |
| 84 | + return convertMap(list, map -> MapUtil.getLong(map, templateIdAlias), map -> MapUtil.getInt(map, countAlias)); | |
| 81 | 85 | } |
| 82 | 86 | |
| 83 | 87 | default List<CouponDO> selectListByUserIdAndStatusAndUsePriceLeAndProductScope( | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponService.java
| 1 | 1 | package cn.iocoder.yudao.module.promotion.service.coupon; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | +import cn.hutool.core.map.MapUtil; | |
| 4 | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | 6 | import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.coupon.CouponPageReqVO; |
| 6 | 7 | import cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.coupon.AppCouponMatchReqVO; |
| 7 | 8 | import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponDO; |
| 8 | 9 | import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponTemplateDO; |
| 9 | 10 | import cn.iocoder.yudao.module.promotion.enums.coupon.CouponTakeTypeEnum; |
| 10 | -import cn.iocoder.yudao.module.promotion.service.coupon.bo.CouponTakeCountBO; | |
| 11 | 11 | |
| 12 | 12 | import java.util.*; |
| 13 | 13 | |
| 14 | -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; | |
| 15 | - | |
| 16 | 14 | /** |
| 17 | 15 | * 优惠劵 Service 接口 |
| 18 | 16 | * |
| ... | ... | @@ -132,23 +130,8 @@ public interface CouponService { |
| 132 | 130 | * @return 领取优惠券的数量 |
| 133 | 131 | */ |
| 134 | 132 | default Integer getTakeCount(Long templateId, Long userId) { |
| 135 | - return CollUtil.emptyIfNull(getTakeCountListByTemplateIds(Collections.singleton(templateId), userId)) | |
| 136 | - .stream() | |
| 137 | - .findFirst() | |
| 138 | - .map(CouponTakeCountBO::getCount) | |
| 139 | - .orElse(0); | |
| 140 | - } | |
| 141 | - | |
| 142 | - /** | |
| 143 | - * 统计会员领取优惠券的数量 | |
| 144 | - * | |
| 145 | - * @param templateIds 优惠券模板编号列表 | |
| 146 | - * @param userId 用户编号 | |
| 147 | - * @return 领取优惠券的数量 | |
| 148 | - */ | |
| 149 | - default Map<Long, Integer> getTakeCountMapByTemplateIds(Collection<Long> templateIds, Long userId) { | |
| 150 | - return convertMap(getTakeCountListByTemplateIds(templateIds, userId), | |
| 151 | - CouponTakeCountBO::getTemplateId, CouponTakeCountBO::getCount); | |
| 133 | + Map<Long, Integer> map = getTakeCountMapByTemplateIds(Collections.singleton(templateId), userId); | |
| 134 | + return MapUtil.getInt(map, templateId, 0); | |
| 152 | 135 | } |
| 153 | 136 | |
| 154 | 137 | /** |
| ... | ... | @@ -158,7 +141,7 @@ public interface CouponService { |
| 158 | 141 | * @param userId 用户编号 |
| 159 | 142 | * @return 领取优惠券的数量 |
| 160 | 143 | */ |
| 161 | - List<CouponTakeCountBO> getTakeCountListByTemplateIds(Collection<Long> templateIds, Long userId); | |
| 144 | + Map<Long, Integer> getTakeCountMapByTemplateIds(Collection<Long> templateIds, Long userId); | |
| 162 | 145 | |
| 163 | 146 | /** |
| 164 | 147 | * 获取用户匹配的优惠券列表 | ... | ... |
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; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.collection.CollStreamUtil; |
| 4 | 4 | import cn.hutool.core.collection.CollUtil; |
| 5 | -import cn.hutool.core.collection.ListUtil; | |
| 6 | 5 | import cn.hutool.core.map.MapUtil; |
| 7 | 6 | import cn.hutool.core.util.ObjectUtil; |
| 8 | 7 | import cn.hutool.core.util.StrUtil; |
| ... | ... | @@ -21,7 +20,6 @@ import cn.iocoder.yudao.module.promotion.dal.mysql.coupon.CouponMapper; |
| 21 | 20 | import cn.iocoder.yudao.module.promotion.enums.coupon.CouponStatusEnum; |
| 22 | 21 | import cn.iocoder.yudao.module.promotion.enums.coupon.CouponTakeTypeEnum; |
| 23 | 22 | import cn.iocoder.yudao.module.promotion.enums.coupon.CouponTemplateValidityTypeEnum; |
| 24 | -import cn.iocoder.yudao.module.promotion.service.coupon.bo.CouponTakeCountBO; | |
| 25 | 23 | import lombok.extern.slf4j.Slf4j; |
| 26 | 24 | import org.springframework.stereotype.Service; |
| 27 | 25 | import org.springframework.transaction.annotation.Transactional; |
| ... | ... | @@ -29,10 +27,7 @@ import org.springframework.validation.annotation.Validated; |
| 29 | 27 | |
| 30 | 28 | import javax.annotation.Resource; |
| 31 | 29 | import java.time.LocalDateTime; |
| 32 | -import java.util.Collection; | |
| 33 | -import java.util.List; | |
| 34 | -import java.util.Map; | |
| 35 | -import java.util.Set; | |
| 30 | +import java.util.*; | |
| 36 | 31 | import java.util.stream.Collectors; |
| 37 | 32 | |
| 38 | 33 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| ... | ... | @@ -191,9 +186,9 @@ public class CouponServiceImpl implements CouponService { |
| 191 | 186 | } |
| 192 | 187 | |
| 193 | 188 | @Override |
| 194 | - public List<CouponTakeCountBO> getTakeCountListByTemplateIds(Collection<Long> templateIds, Long userId) { | |
| 189 | + public Map<Long, Integer> getTakeCountMapByTemplateIds(Collection<Long> templateIds, Long userId) { | |
| 195 | 190 | if (CollUtil.isEmpty(templateIds)) { |
| 196 | - return ListUtil.empty(); | |
| 191 | + return Collections.emptyMap(); | |
| 197 | 192 | } |
| 198 | 193 | return couponMapper.selectCountByUserIdAndTemplateIdIn(userId, templateIds); |
| 199 | 194 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/bo/CouponTakeCountBO.java deleted
| 1 | -package cn.iocoder.yudao.module.promotion.service.coupon.bo; | |
| 2 | - | |
| 3 | -import lombok.Data; | |
| 4 | - | |
| 5 | -/** | |
| 6 | - * 优惠券领取数量 BO | |
| 7 | - * | |
| 8 | - * @author owen | |
| 9 | - */ | |
| 10 | -@Data | |
| 11 | -public class CouponTakeCountBO { | |
| 12 | - | |
| 13 | - /** | |
| 14 | - * 优惠劵模板编号 | |
| 15 | - */ | |
| 16 | - private Long templateId; | |
| 17 | - /** | |
| 18 | - * 领取数量 | |
| 19 | - */ | |
| 20 | - private Integer count; | |
| 21 | - | |
| 22 | -} |
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 { |
| 32 | 32 | @Resource |
| 33 | 33 | private TradeStatisticsService tradeStatisticsService; |
| 34 | 34 | |
| 35 | - // TODO @疯狂:要不这个就是 /trend/summary 的特例,前端自己查询两次? | |
| 36 | 35 | @GetMapping("/summary") |
| 37 | 36 | @Operation(summary = "获得交易统计") |
| 38 | 37 | @PreAuthorize("@ss.hasPermission('statistics:trade:query')") |
| ... | ... | @@ -40,7 +39,6 @@ public class TradeStatisticsController { |
| 40 | 39 | return success(tradeStatisticsService.getTradeSummaryComparison()); |
| 41 | 40 | } |
| 42 | 41 | |
| 43 | - // TODO @疯狂:直接 comparison?主要 trend 和 comparison 二选一,一个是数据趋势,一个是数据对比哈; | |
| 44 | 42 | @GetMapping("/trend/summary") |
| 45 | 43 | @Operation(summary = "获得交易状况统计") |
| 46 | 44 | @PreAuthorize("@ss.hasPermission('statistics:trade:query')") | ... | ... |