Commit c71bdd158abd09b1093eb8da66bca9b05237ec9a
1 parent
c8a9d689
拼团活动:完善 review 提到的问题
Showing
16 changed files
with
182 additions
and
86 deletions
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/activity/AppActivityController.java
| @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.promotion.controller.app.activity; | @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.promotion.controller.app.activity; | ||
| 2 | 2 | ||
| 3 | import cn.hutool.core.collection.CollUtil; | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | import cn.hutool.core.map.MapUtil; | 4 | import cn.hutool.core.map.MapUtil; |
| 5 | +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | ||
| 5 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 6 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 6 | import cn.iocoder.yudao.module.promotion.controller.app.activity.vo.AppActivityRespVO; | 7 | import cn.iocoder.yudao.module.promotion.controller.app.activity.vo.AppActivityRespVO; |
| 7 | import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainActivityDO; | 8 | import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainActivityDO; |
| @@ -21,12 +22,10 @@ import org.springframework.web.bind.annotation.RequestParam; | @@ -21,12 +22,10 @@ import org.springframework.web.bind.annotation.RequestParam; | ||
| 21 | import org.springframework.web.bind.annotation.RestController; | 22 | import org.springframework.web.bind.annotation.RestController; |
| 22 | 23 | ||
| 23 | import javax.annotation.Resource; | 24 | import javax.annotation.Resource; |
| 24 | -import java.util.ArrayList; | ||
| 25 | -import java.util.HashMap; | ||
| 26 | -import java.util.List; | ||
| 27 | -import java.util.Map; | 25 | +import java.util.*; |
| 28 | 26 | ||
| 29 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | 27 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 28 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMultiMap; | ||
| 30 | 29 | ||
| 31 | @Tag(name = "用户 APP - 营销活动") // 用于提供跨多个活动的 HTTP 接口 | 30 | @Tag(name = "用户 APP - 营销活动") // 用于提供跨多个活动的 HTTP 接口 |
| 32 | @RestController | 31 | @RestController |
| @@ -42,59 +41,72 @@ public class AppActivityController { | @@ -42,59 +41,72 @@ public class AppActivityController { | ||
| 42 | private BargainActivityService bargainActivityService; | 41 | private BargainActivityService bargainActivityService; |
| 43 | 42 | ||
| 44 | @GetMapping("/list-by-spu-id") | 43 | @GetMapping("/list-by-spu-id") |
| 45 | - @Operation(summary = "获得单个商品,近期参与的每个活动") // 每种活动,只返回一个 | 44 | + @Operation(summary = "获得单个商品,近期参与的每个活动") |
| 46 | @Parameter(name = "spuId", description = "商品编号", required = true) | 45 | @Parameter(name = "spuId", description = "商品编号", required = true) |
| 47 | public CommonResult<List<AppActivityRespVO>> getActivityListBySpuId(@RequestParam("spuId") Long spuId) { | 46 | public CommonResult<List<AppActivityRespVO>> getActivityListBySpuId(@RequestParam("spuId") Long spuId) { |
| 48 | - return success(getAppActivityRespVOList(spuId)); | 47 | + // 每种活动,只返回一个 |
| 48 | + return success(getAppActivityRespVOList(Collections.singletonList(spuId))); | ||
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | @GetMapping("/list-by-spu-ids") | 51 | @GetMapping("/list-by-spu-ids") |
| 52 | - @Operation(summary = "获得多个商品,近期参与的每个活动") // 每种活动,只返回一个;key 为 SPU 编号 | 52 | + @Operation(summary = "获得多个商品,近期参与的每个活动") |
| 53 | @Parameter(name = "spuIds", description = "商品编号数组", required = true) | 53 | @Parameter(name = "spuIds", description = "商品编号数组", required = true) |
| 54 | public CommonResult<Map<Long, List<AppActivityRespVO>>> getActivityListBySpuIds(@RequestParam("spuIds") List<Long> spuIds) { | 54 | public CommonResult<Map<Long, List<AppActivityRespVO>>> getActivityListBySpuIds(@RequestParam("spuIds") List<Long> spuIds) { |
| 55 | if (CollUtil.isEmpty(spuIds)) { | 55 | if (CollUtil.isEmpty(spuIds)) { |
| 56 | return success(MapUtil.empty()); | 56 | return success(MapUtil.empty()); |
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | - // TODO @puhui999:要避免这种 1+n 的查询 | ||
| 60 | - Map<Long, List<AppActivityRespVO>> map = new HashMap<>(spuIds.size()); | ||
| 61 | - spuIds.forEach(spuId -> { | ||
| 62 | - map.put(spuId, getAppActivityRespVOList(spuId)); | ||
| 63 | - }); | ||
| 64 | - return success(map); | 59 | + // 每种活动,只返回一个;key 为 SPU 编号 |
| 60 | + return success(convertMultiMap(getAppActivityRespVOList(spuIds), AppActivityRespVO::getSpuId)); | ||
| 65 | } | 61 | } |
| 66 | 62 | ||
| 67 | - private List<AppActivityRespVO> getAppActivityRespVOList(Long spuId) { | 63 | + private List<AppActivityRespVO> getAppActivityRespVOList(Collection<Long> spuIds) { |
| 64 | + if (CollUtil.isEmpty(spuIds)) { | ||
| 65 | + return new ArrayList<>(); | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | List<AppActivityRespVO> activityList = new ArrayList<>(); | 68 | List<AppActivityRespVO> activityList = new ArrayList<>(); |
| 69 | // 拼团活动 | 69 | // 拼团活动 |
| 70 | - CombinationActivityDO combination = combinationActivityService.getCombinationActivityBySpuId(spuId); | ||
| 71 | - if (combination != null) { | ||
| 72 | - activityList.add(new AppActivityRespVO() | ||
| 73 | - .setId(combination.getId()) | ||
| 74 | - .setType(PromotionTypeEnum.COMBINATION_ACTIVITY.getType()) | ||
| 75 | - .setName(combination.getName()) | ||
| 76 | - .setStartTime(combination.getStartTime()) | ||
| 77 | - .setEndTime(combination.getEndTime())); | 70 | + List<CombinationActivityDO> combinationActivities = combinationActivityService.getCombinationActivityBySpuIdsAndStatus( |
| 71 | + spuIds, CommonStatusEnum.ENABLE.getStatus()); | ||
| 72 | + if (CollUtil.isNotEmpty(combinationActivities)) { | ||
| 73 | + combinationActivities.forEach(item -> { | ||
| 74 | + activityList.add(new AppActivityRespVO() | ||
| 75 | + .setId(item.getId()) | ||
| 76 | + .setType(PromotionTypeEnum.COMBINATION_ACTIVITY.getType()) | ||
| 77 | + .setName(item.getName()) | ||
| 78 | + .setSpuId(item.getSpuId()) | ||
| 79 | + .setStartTime(item.getStartTime()) | ||
| 80 | + .setEndTime(item.getEndTime())); | ||
| 81 | + }); | ||
| 78 | } | 82 | } |
| 79 | // 秒杀活动 | 83 | // 秒杀活动 |
| 80 | - SeckillActivityDO seckill = seckillActivityService.getSeckillActivityBySpuId(spuId); | ||
| 81 | - if (seckill != null) { | ||
| 82 | - activityList.add(new AppActivityRespVO() | ||
| 83 | - .setId(seckill.getId()) | ||
| 84 | - .setType(PromotionTypeEnum.SECKILL_ACTIVITY.getType()) | ||
| 85 | - .setName(seckill.getName()) | ||
| 86 | - .setStartTime(seckill.getStartTime()) | ||
| 87 | - .setEndTime(seckill.getEndTime())); | 84 | + List<SeckillActivityDO> seckillActivities = seckillActivityService.getSeckillActivityBySpuIdsAndStatus( |
| 85 | + spuIds, CommonStatusEnum.ENABLE.getStatus()); | ||
| 86 | + if (CollUtil.isNotEmpty(seckillActivities)) { | ||
| 87 | + seckillActivities.forEach(item -> { | ||
| 88 | + activityList.add(new AppActivityRespVO() | ||
| 89 | + .setId(item.getId()) | ||
| 90 | + .setType(PromotionTypeEnum.SECKILL_ACTIVITY.getType()) | ||
| 91 | + .setName(item.getName()) | ||
| 92 | + .setSpuId(item.getSpuId()) | ||
| 93 | + .setStartTime(item.getStartTime()) | ||
| 94 | + .setEndTime(item.getEndTime())); | ||
| 95 | + }); | ||
| 88 | } | 96 | } |
| 89 | - // 秒杀活动 | ||
| 90 | - BargainActivityDO bargain = bargainActivityService.getBargainActivityBySpuId(spuId); | ||
| 91 | - if (bargain != null) { | ||
| 92 | - activityList.add(new AppActivityRespVO() | ||
| 93 | - .setId(bargain.getId()) | ||
| 94 | - .setType(PromotionTypeEnum.BARGAIN_ACTIVITY.getType()) | ||
| 95 | - .setName(bargain.getName()) | ||
| 96 | - .setStartTime(bargain.getStartTime()) | ||
| 97 | - .setEndTime(bargain.getEndTime())); | 97 | + // 砍价活动 |
| 98 | + List<BargainActivityDO> bargainActivities = bargainActivityService.getBargainActivityBySpuIdsAndStatus( | ||
| 99 | + spuIds, CommonStatusEnum.ENABLE.getStatus()); | ||
| 100 | + if (CollUtil.isNotEmpty(bargainActivities)) { | ||
| 101 | + bargainActivities.forEach(item -> { | ||
| 102 | + activityList.add(new AppActivityRespVO() | ||
| 103 | + .setId(item.getId()) | ||
| 104 | + .setType(PromotionTypeEnum.BARGAIN_ACTIVITY.getType()) | ||
| 105 | + .setName(item.getName()) | ||
| 106 | + .setSpuId(item.getSpuId()) | ||
| 107 | + .setStartTime(item.getStartTime()) | ||
| 108 | + .setEndTime(item.getEndTime())); | ||
| 109 | + }); | ||
| 98 | } | 110 | } |
| 99 | return activityList; | 111 | return activityList; |
| 100 | } | 112 | } |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/activity/vo/AppActivityRespVO.java
| @@ -13,12 +13,14 @@ public class AppActivityRespVO { | @@ -13,12 +13,14 @@ public class AppActivityRespVO { | ||
| 13 | private Long id; | 13 | private Long id; |
| 14 | 14 | ||
| 15 | @Schema(description = "活动类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | 15 | @Schema(description = "活动类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") |
| 16 | - // 对应 PromotionTypeEnum 枚举 | ||
| 17 | - private Integer type; | 16 | + private Integer type; // 对应 PromotionTypeEnum 枚举 |
| 18 | 17 | ||
| 19 | @Schema(description = "活动名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "618 大促") | 18 | @Schema(description = "活动名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "618 大促") |
| 20 | private String name; | 19 | private String name; |
| 21 | 20 | ||
| 21 | + @Schema(description = "spu 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "618") | ||
| 22 | + private Long spuId; | ||
| 23 | + | ||
| 22 | @Schema(description = "活动开始时间", requiredMode = Schema.RequiredMode.REQUIRED) | 24 | @Schema(description = "活动开始时间", requiredMode = Schema.RequiredMode.REQUIRED) |
| 23 | private LocalDateTime startTime; | 25 | private LocalDateTime startTime; |
| 24 | 26 |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainActivityMapper.java
| @@ -8,8 +8,10 @@ import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.activity.Ba | @@ -8,8 +8,10 @@ import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.activity.Ba | ||
| 8 | import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainActivityDO; | 8 | import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainActivityDO; |
| 9 | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; | 9 | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| 10 | import org.apache.ibatis.annotations.Mapper; | 10 | import org.apache.ibatis.annotations.Mapper; |
| 11 | +import org.apache.ibatis.annotations.Select; | ||
| 11 | 12 | ||
| 12 | import java.time.LocalDateTime; | 13 | import java.time.LocalDateTime; |
| 14 | +import java.util.Collection; | ||
| 13 | import java.util.List; | 15 | import java.util.List; |
| 14 | 16 | ||
| 15 | /** | 17 | /** |
| @@ -83,12 +85,23 @@ public interface BargainActivityMapper extends BaseMapperX<BargainActivityDO> { | @@ -83,12 +85,23 @@ public interface BargainActivityMapper extends BaseMapperX<BargainActivityDO> { | ||
| 83 | .last("LIMIT " + count)); | 85 | .last("LIMIT " + count)); |
| 84 | } | 86 | } |
| 85 | 87 | ||
| 86 | - // TODO @puhui999:需要开启状态;另外,是不是可以 limit1,不用 throwEx = false 处理呀?另外,时间要满足噢 | ||
| 87 | - default BargainActivityDO selectOne(Long spuId) { | ||
| 88 | - return selectOne(new LambdaQueryWrapperX<BargainActivityDO>() | ||
| 89 | - .eq(BargainActivityDO::getSpuId, spuId) | ||
| 90 | - .orderByDesc(BargainActivityDO::getCreateTime) | ||
| 91 | - , false); | ||
| 92 | - } | 88 | + /** |
| 89 | + * 获取指定 spu 编号最近参加的活动,每个 spuId 只返回一条记录 | ||
| 90 | + * | ||
| 91 | + * @param spuIds spu 编号 | ||
| 92 | + * @param status 状态 | ||
| 93 | + * @return 砍价活动列表 | ||
| 94 | + */ | ||
| 95 | + @Select("SELECT p1.* " + | ||
| 96 | + "FROM promotion_bargain_activity p1 " + | ||
| 97 | + "INNER JOIN ( " + | ||
| 98 | + " SELECT spu_id, MAX(DISTINCT(create_time)) AS max_create_time " + | ||
| 99 | + " FROM promotion_bargain_activity " + | ||
| 100 | + " WHERE spu_id IN #{spuIds} " + | ||
| 101 | + " GROUP BY spu_id " + | ||
| 102 | + ") p2 " + | ||
| 103 | + "ON p1.spu_id = p2.spu_id AND p1.create_time = p2.max_create_time AND p1.status = #{status} " + | ||
| 104 | + "ORDER BY p1.create_time DESC;") | ||
| 105 | + List<BargainActivityDO> selectListBySpuIds(Collection<Long> spuIds, Integer status); | ||
| 93 | 106 | ||
| 94 | } | 107 | } |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationActivityMapper.java
| @@ -7,7 +7,10 @@ import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | @@ -7,7 +7,10 @@ import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | ||
| 7 | import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityPageReqVO; | 7 | import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityPageReqVO; |
| 8 | import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationActivityDO; | 8 | import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationActivityDO; |
| 9 | import org.apache.ibatis.annotations.Mapper; | 9 | import org.apache.ibatis.annotations.Mapper; |
| 10 | +import org.apache.ibatis.annotations.Param; | ||
| 11 | +import org.apache.ibatis.annotations.Select; | ||
| 10 | 12 | ||
| 13 | +import java.util.Collection; | ||
| 11 | import java.util.List; | 14 | import java.util.List; |
| 12 | 15 | ||
| 13 | /** | 16 | /** |
| @@ -40,12 +43,23 @@ public interface CombinationActivityMapper extends BaseMapperX<CombinationActivi | @@ -40,12 +43,23 @@ public interface CombinationActivityMapper extends BaseMapperX<CombinationActivi | ||
| 40 | .last("LIMIT " + count)); | 43 | .last("LIMIT " + count)); |
| 41 | } | 44 | } |
| 42 | 45 | ||
| 43 | - // TODO @puhui999:需要开启状态;另外,是不是可以 limit1,不用 throwEx = false 处理呀?另外,时间要满足噢 | ||
| 44 | - default CombinationActivityDO selectOne(Long spuId) { | ||
| 45 | - return selectOne(new LambdaQueryWrapperX<CombinationActivityDO>() | ||
| 46 | - .eq(CombinationActivityDO::getSpuId, spuId) | ||
| 47 | - .orderByDesc(CombinationActivityDO::getCreateTime) | ||
| 48 | - , false); | ||
| 49 | - } | 46 | + /** |
| 47 | + * 获取指定 spu 编号最近参加的活动,每个 spuId 只返回一条记录 | ||
| 48 | + * | ||
| 49 | + * @param spuIds spu 编号 | ||
| 50 | + * @param status 状态 | ||
| 51 | + * @return 拼团活动列表 | ||
| 52 | + */ | ||
| 53 | + @Select("SELECT p1.* " + | ||
| 54 | + "FROM promotion_combination_activity p1 " + | ||
| 55 | + "INNER JOIN ( " + | ||
| 56 | + " SELECT spu_id, MAX(DISTINCT(create_time)) AS max_create_time " + | ||
| 57 | + " FROM promotion_combination_activity " + | ||
| 58 | + " WHERE spu_id IN #{spuIds} " + | ||
| 59 | + " GROUP BY spu_id " + | ||
| 60 | + ") p2 " + | ||
| 61 | + "ON p1.spu_id = p2.spu_id AND p1.create_time = p2.max_create_time AND p1.status = #{status} " + | ||
| 62 | + "ORDER BY p1.create_time DESC;") | ||
| 63 | + List<CombinationActivityDO> selectListBySpuIds(@Param("spuIds") Collection<Long> spuIds, @Param("status") Integer status); | ||
| 50 | 64 | ||
| 51 | } | 65 | } |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillActivityMapper.java
| @@ -9,7 +9,9 @@ import cn.iocoder.yudao.module.promotion.controller.app.seckill.vo.activity.AppS | @@ -9,7 +9,9 @@ import cn.iocoder.yudao.module.promotion.controller.app.seckill.vo.activity.AppS | ||
| 9 | import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.SeckillActivityDO; | 9 | import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.SeckillActivityDO; |
| 10 | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; | 10 | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| 11 | import org.apache.ibatis.annotations.Mapper; | 11 | import org.apache.ibatis.annotations.Mapper; |
| 12 | +import org.apache.ibatis.annotations.Select; | ||
| 12 | 13 | ||
| 14 | +import java.util.Collection; | ||
| 13 | import java.util.List; | 15 | import java.util.List; |
| 14 | 16 | ||
| 15 | /** | 17 | /** |
| @@ -56,12 +58,23 @@ public interface SeckillActivityMapper extends BaseMapperX<SeckillActivityDO> { | @@ -56,12 +58,23 @@ public interface SeckillActivityMapper extends BaseMapperX<SeckillActivityDO> { | ||
| 56 | .apply(ObjectUtil.isNotNull(pageReqVO.getConfigId()), "FIND_IN_SET(" + pageReqVO.getConfigId() + ",config_ids) > 0")); | 58 | .apply(ObjectUtil.isNotNull(pageReqVO.getConfigId()), "FIND_IN_SET(" + pageReqVO.getConfigId() + ",config_ids) > 0")); |
| 57 | } | 59 | } |
| 58 | 60 | ||
| 59 | - // TODO @puhui999:需要开启状态;另外,是不是可以 limit1,不用 throwEx = false 处理呀?另外,时间要满足噢; | ||
| 60 | - default SeckillActivityDO selectOne(Long spuId) { | ||
| 61 | - return selectOne(new LambdaQueryWrapperX<SeckillActivityDO>() | ||
| 62 | - .eq(SeckillActivityDO::getSpuId, spuId) | ||
| 63 | - .orderByDesc(SeckillActivityDO::getCreateTime) | ||
| 64 | - , false); | ||
| 65 | - } | 61 | + /** |
| 62 | + * 获取指定 spu 编号最近参加的活动,每个 spuId 只返回一条记录 | ||
| 63 | + * | ||
| 64 | + * @param spuIds spu 编号 | ||
| 65 | + * @param status 状态 | ||
| 66 | + * @return 秒杀活动列表 | ||
| 67 | + */ | ||
| 68 | + @Select("SELECT p1.* " + | ||
| 69 | + "FROM promotion_seckill_activity p1 " + | ||
| 70 | + "INNER JOIN ( " + | ||
| 71 | + " SELECT spu_id, MAX(DISTINCT(create_time)) AS max_create_time " + | ||
| 72 | + " FROM promotion_seckill_activity " + | ||
| 73 | + " WHERE spu_id IN #{spuIds} " + | ||
| 74 | + " GROUP BY spu_id " + | ||
| 75 | + ") p2 " + | ||
| 76 | + "ON p1.spu_id = p2.spu_id AND p1.create_time = p2.max_create_time AND p1.status = #{status} " + | ||
| 77 | + "ORDER BY p1.create_time DESC;") | ||
| 78 | + List<SeckillActivityDO> selectListBySpuIds(Collection<Long> spuIds, Integer status); | ||
| 66 | 79 | ||
| 67 | } | 80 | } |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityService.java
| @@ -8,6 +8,7 @@ import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.activity.Ba | @@ -8,6 +8,7 @@ import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.activity.Ba | ||
| 8 | import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainActivityDO; | 8 | import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainActivityDO; |
| 9 | 9 | ||
| 10 | import javax.validation.Valid; | 10 | import javax.validation.Valid; |
| 11 | +import java.util.Collection; | ||
| 11 | import java.util.List; | 12 | import java.util.List; |
| 12 | import java.util.Set; | 13 | import java.util.Set; |
| 13 | 14 | ||
| @@ -99,11 +100,12 @@ public interface BargainActivityService { | @@ -99,11 +100,12 @@ public interface BargainActivityService { | ||
| 99 | List<BargainActivityDO> getBargainActivityListByCount(Integer count); | 100 | List<BargainActivityDO> getBargainActivityListByCount(Integer count); |
| 100 | 101 | ||
| 101 | /** | 102 | /** |
| 102 | - * 获取指定 spu 编号的活动 | 103 | + * 获取指定 spu 编号最近参加的活动,每个 spuId 只返回一条记录 |
| 103 | * | 104 | * |
| 104 | - * @param spuId spu 编号 | ||
| 105 | - * @return 砍价活动 | 105 | + * @param spuIds spu 编号 |
| 106 | + * @param status 状态 | ||
| 107 | + * @return 砍价活动列表 | ||
| 106 | */ | 108 | */ |
| 107 | - BargainActivityDO getBargainActivityBySpuId(Long spuId); | 109 | + List<BargainActivityDO> getBargainActivityBySpuIdsAndStatus(Collection<Long> spuIds, Integer status); |
| 108 | 110 | ||
| 109 | } | 111 | } |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityServiceImpl.java
| @@ -20,6 +20,7 @@ import org.springframework.validation.annotation.Validated; | @@ -20,6 +20,7 @@ import org.springframework.validation.annotation.Validated; | ||
| 20 | 20 | ||
| 21 | import javax.annotation.Resource; | 21 | import javax.annotation.Resource; |
| 22 | import java.time.LocalDateTime; | 22 | import java.time.LocalDateTime; |
| 23 | +import java.util.Collection; | ||
| 23 | import java.util.List; | 24 | import java.util.List; |
| 24 | import java.util.Set; | 25 | import java.util.Set; |
| 25 | 26 | ||
| @@ -176,8 +177,8 @@ public class BargainActivityServiceImpl implements BargainActivityService { | @@ -176,8 +177,8 @@ public class BargainActivityServiceImpl implements BargainActivityService { | ||
| 176 | } | 177 | } |
| 177 | 178 | ||
| 178 | @Override | 179 | @Override |
| 179 | - public BargainActivityDO getBargainActivityBySpuId(Long spuId) { | ||
| 180 | - return bargainActivityMapper.selectOne(spuId); | 180 | + public List<BargainActivityDO> getBargainActivityBySpuIdsAndStatus(Collection<Long> spuIds, Integer status) { |
| 181 | + return bargainActivityMapper.selectListBySpuIds(spuIds, status); | ||
| 181 | } | 182 | } |
| 182 | 183 | ||
| 183 | } | 184 | } |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java
| @@ -118,11 +118,12 @@ public interface CombinationActivityService { | @@ -118,11 +118,12 @@ public interface CombinationActivityService { | ||
| 118 | CombinationProductDO selectByActivityIdAndSkuId(Long activityId, Long skuId); | 118 | CombinationProductDO selectByActivityIdAndSkuId(Long activityId, Long skuId); |
| 119 | 119 | ||
| 120 | /** | 120 | /** |
| 121 | - * 获取指定 spu 编号的活动 | 121 | + * 获取指定 spu 编号最近参加的活动,每个 spuId 只返回一条记录 |
| 122 | * | 122 | * |
| 123 | - * @param spuId spu 编号 | ||
| 124 | - * @return 拼团活动 | 123 | + * @param spuIds spu 编号 |
| 124 | + * @param status 状态 | ||
| 125 | + * @return 拼团活动列表 | ||
| 125 | */ | 126 | */ |
| 126 | - CombinationActivityDO getCombinationActivityBySpuId(Long spuId); | 127 | + List<CombinationActivityDO> getCombinationActivityBySpuIdsAndStatus(Collection<Long> spuIds, Integer status); |
| 127 | 128 | ||
| 128 | } | 129 | } |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java
| @@ -227,8 +227,8 @@ public class CombinationActivityServiceImpl implements CombinationActivityServic | @@ -227,8 +227,8 @@ public class CombinationActivityServiceImpl implements CombinationActivityServic | ||
| 227 | } | 227 | } |
| 228 | 228 | ||
| 229 | @Override | 229 | @Override |
| 230 | - public CombinationActivityDO getCombinationActivityBySpuId(Long spuId) { | ||
| 231 | - return combinationActivityMapper.selectOne(spuId); | 230 | + public List<CombinationActivityDO> getCombinationActivityBySpuIdsAndStatus(Collection<Long> spuIds, Integer status) { |
| 231 | + return combinationActivityMapper.selectListBySpuIds(spuIds, status); | ||
| 232 | } | 232 | } |
| 233 | 233 | ||
| 234 | } | 234 | } |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityService.java
| @@ -120,11 +120,12 @@ public interface SeckillActivityService { | @@ -120,11 +120,12 @@ public interface SeckillActivityService { | ||
| 120 | SeckillValidateJoinRespDTO validateJoinSeckill(Long activityId, Long skuId, Integer count); | 120 | SeckillValidateJoinRespDTO validateJoinSeckill(Long activityId, Long skuId, Integer count); |
| 121 | 121 | ||
| 122 | /** | 122 | /** |
| 123 | - * 获取指定 spu 编号的活动 | 123 | + * 获取指定 spu 编号最近参加的活动,每个 spuId 只返回一条记录 |
| 124 | * | 124 | * |
| 125 | - * @param spuId spu 编号 | ||
| 126 | - * @return 秒杀活动 | 125 | + * @param spuIds spu 编号 |
| 126 | + * @param status 状态 | ||
| 127 | + * @return 秒杀活动列表 | ||
| 127 | */ | 128 | */ |
| 128 | - SeckillActivityDO getSeckillActivityBySpuId(Long spuId); | 129 | + List<SeckillActivityDO> getSeckillActivityBySpuIdsAndStatus(Collection<Long> spuIds, Integer status); |
| 129 | 130 | ||
| 130 | } | 131 | } |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityServiceImpl.java
| @@ -311,8 +311,8 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { | @@ -311,8 +311,8 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { | ||
| 311 | } | 311 | } |
| 312 | 312 | ||
| 313 | @Override | 313 | @Override |
| 314 | - public SeckillActivityDO getSeckillActivityBySpuId(Long spuId) { | ||
| 315 | - return seckillActivityMapper.selectOne(spuId); | 314 | + public List<SeckillActivityDO> getSeckillActivityBySpuIdsAndStatus(Collection<Long> spuIds, Integer status) { |
| 315 | + return seckillActivityMapper.selectListBySpuIds(spuIds, status); | ||
| 316 | } | 316 | } |
| 317 | 317 | ||
| 318 | } | 318 | } |
yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java
| @@ -33,6 +33,7 @@ public interface ErrorCodeConstants { | @@ -33,6 +33,7 @@ public interface ErrorCodeConstants { | ||
| 33 | ErrorCode ORDER_UPDATE_PRICE_FAIL_PRICE_ERROR = new ErrorCode(1_011_000_028, "支付订单调价失败,原因:调整后支付价格不能小于 0.01 元"); | 33 | ErrorCode ORDER_UPDATE_PRICE_FAIL_PRICE_ERROR = new ErrorCode(1_011_000_028, "支付订单调价失败,原因:调整后支付价格不能小于 0.01 元"); |
| 34 | ErrorCode ORDER_DELETE_FAIL_STATUS_NOT_CANCEL = new ErrorCode(1_011_000_029, "交易订单删除失败,订单不是【已取消】状态"); | 34 | ErrorCode ORDER_DELETE_FAIL_STATUS_NOT_CANCEL = new ErrorCode(1_011_000_029, "交易订单删除失败,订单不是【已取消】状态"); |
| 35 | ErrorCode ORDER_RECEIVE_FAIL_DELIVERY_TYPE_NOT_PICK_UP = new ErrorCode(1_011_000_030, "交易订单自提失败,收货方式不是【用户自提】"); | 35 | ErrorCode ORDER_RECEIVE_FAIL_DELIVERY_TYPE_NOT_PICK_UP = new ErrorCode(1_011_000_030, "交易订单自提失败,收货方式不是【用户自提】"); |
| 36 | + ErrorCode ORDER_UPDATE_ADDRESS_FAIL_STATUS_NOT_DELIVERED = new ErrorCode(1_011_000_031, "交易订单修改收货地址失败,原因:订单已发货"); | ||
| 36 | 37 | ||
| 37 | // ========== After Sale 模块 1-011-000-100 ========== | 38 | // ========== After Sale 模块 1-011-000-100 ========== |
| 38 | ErrorCode AFTER_SALE_NOT_FOUND = new ErrorCode(1_011_000_100, "售后单不存在"); | 39 | ErrorCode AFTER_SALE_NOT_FOUND = new ErrorCode(1_011_000_100, "售后单不存在"); |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/redis/RedisKeyConstants.java
| @@ -15,4 +15,12 @@ public interface RedisKeyConstants { | @@ -15,4 +15,12 @@ public interface RedisKeyConstants { | ||
| 15 | */ | 15 | */ |
| 16 | String TRADE_NO = "trade_no:"; | 16 | String TRADE_NO = "trade_no:"; |
| 17 | 17 | ||
| 18 | + /** | ||
| 19 | + * 交易序号的缓存 | ||
| 20 | + * | ||
| 21 | + * KEY 格式:express_track:{code-logisticsNo-receiverMobile} | ||
| 22 | + * VALUE 数据格式 String, 物流信息集合 | ||
| 23 | + */ | ||
| 24 | + String EXPRESS_TRACK = "express_track"; | ||
| 25 | + | ||
| 18 | } | 26 | } |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderQueryServiceImpl.java
| @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.trade.service.order; | @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.trade.service.order; | ||
| 3 | import cn.hutool.core.collection.CollUtil; | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | import cn.hutool.core.util.ObjectUtil; | 4 | import cn.hutool.core.util.ObjectUtil; |
| 5 | import cn.hutool.core.util.StrUtil; | 5 | import cn.hutool.core.util.StrUtil; |
| 6 | +import cn.hutool.extra.spring.SpringUtil; | ||
| 6 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 7 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 7 | import cn.iocoder.yudao.module.member.api.user.MemberUserApi; | 8 | import cn.iocoder.yudao.module.member.api.user.MemberUserApi; |
| 8 | import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; | 9 | import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; |
| @@ -14,11 +15,13 @@ import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; | @@ -14,11 +15,13 @@ import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; | ||
| 14 | import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO; | 15 | import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO; |
| 15 | import cn.iocoder.yudao.module.trade.dal.mysql.order.TradeOrderItemMapper; | 16 | import cn.iocoder.yudao.module.trade.dal.mysql.order.TradeOrderItemMapper; |
| 16 | import cn.iocoder.yudao.module.trade.dal.mysql.order.TradeOrderMapper; | 17 | import cn.iocoder.yudao.module.trade.dal.mysql.order.TradeOrderMapper; |
| 18 | +import cn.iocoder.yudao.module.trade.dal.redis.RedisKeyConstants; | ||
| 17 | import cn.iocoder.yudao.module.trade.enums.order.TradeOrderStatusEnum; | 19 | import cn.iocoder.yudao.module.trade.enums.order.TradeOrderStatusEnum; |
| 18 | import cn.iocoder.yudao.module.trade.framework.delivery.core.client.ExpressClientFactory; | 20 | import cn.iocoder.yudao.module.trade.framework.delivery.core.client.ExpressClientFactory; |
| 19 | import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressTrackQueryReqDTO; | 21 | import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressTrackQueryReqDTO; |
| 20 | import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressTrackRespDTO; | 22 | import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressTrackRespDTO; |
| 21 | import cn.iocoder.yudao.module.trade.service.delivery.DeliveryExpressService; | 23 | import cn.iocoder.yudao.module.trade.service.delivery.DeliveryExpressService; |
| 24 | +import org.springframework.cache.annotation.Cacheable; | ||
| 22 | import org.springframework.stereotype.Service; | 25 | import org.springframework.stereotype.Service; |
| 23 | 26 | ||
| 24 | import javax.annotation.Resource; | 27 | import javax.annotation.Resource; |
| @@ -143,7 +146,6 @@ public class TradeOrderQueryServiceImpl implements TradeOrderQueryService { | @@ -143,7 +146,6 @@ public class TradeOrderQueryServiceImpl implements TradeOrderQueryService { | ||
| 143 | return tradeOrderItemMapper.selectProductSumByOrderId(convertSet(orders, TradeOrderDO::getId)); | 146 | return tradeOrderItemMapper.selectProductSumByOrderId(convertSet(orders, TradeOrderDO::getId)); |
| 144 | } | 147 | } |
| 145 | 148 | ||
| 146 | - // TODO @puhui999:可以加个 spring 缓存,30 分钟;主要考虑及时性要求不高,但是每次调用需要钱; | ||
| 147 | /** | 149 | /** |
| 148 | * 获得订单的物流轨迹 | 150 | * 获得订单的物流轨迹 |
| 149 | * | 151 | * |
| @@ -160,10 +162,25 @@ public class TradeOrderQueryServiceImpl implements TradeOrderQueryService { | @@ -160,10 +162,25 @@ public class TradeOrderQueryServiceImpl implements TradeOrderQueryService { | ||
| 160 | throw exception(EXPRESS_NOT_EXISTS); | 162 | throw exception(EXPRESS_NOT_EXISTS); |
| 161 | } | 163 | } |
| 162 | 164 | ||
| 165 | + return getSelf().getExpressTrackList(express.getCode(), order.getLogisticsNo(), order.getReceiverMobile()); | ||
| 166 | + } | ||
| 167 | + | ||
| 168 | + /** | ||
| 169 | + * 查询物流轨迹 | ||
| 170 | + * 加个 spring 缓存,30 分钟;主要考虑及时性要求不高,但是每次调用需要钱;TODO @艿艿:这个时间不会搞了。。。交给你了哈哈哈 | ||
| 171 | + * | ||
| 172 | + * @param code 快递公司编码 | ||
| 173 | + * @param logisticsNo 发货快递单号 | ||
| 174 | + * @param receiverMobile 收、寄件人的电话号码 | ||
| 175 | + * @return 物流轨迹 | ||
| 176 | + */ | ||
| 177 | + @Cacheable(cacheNames = RedisKeyConstants.EXPRESS_TRACK, key = "#code + '-' + #logisticsNo + '-' + #receiverMobile", | ||
| 178 | + condition = "#result != null") | ||
| 179 | + public List<ExpressTrackRespDTO> getExpressTrackList(String code, String logisticsNo, String receiverMobile) { | ||
| 163 | // 查询物流轨迹 | 180 | // 查询物流轨迹 |
| 164 | return expressClientFactory.getDefaultExpressClient().getExpressTrackList( | 181 | return expressClientFactory.getDefaultExpressClient().getExpressTrackList( |
| 165 | - new ExpressTrackQueryReqDTO().setExpressCode(express.getCode()).setLogisticsNo(order.getLogisticsNo()) | ||
| 166 | - .setPhone(order.getReceiverMobile())); | 182 | + new ExpressTrackQueryReqDTO().setExpressCode(code).setLogisticsNo(logisticsNo) |
| 183 | + .setPhone(receiverMobile)); | ||
| 167 | } | 184 | } |
| 168 | 185 | ||
| 169 | @Override | 186 | @Override |
| @@ -199,4 +216,13 @@ public class TradeOrderQueryServiceImpl implements TradeOrderQueryService { | @@ -199,4 +216,13 @@ public class TradeOrderQueryServiceImpl implements TradeOrderQueryService { | ||
| 199 | return tradeOrderItemMapper.selectListByOrderId(orderIds); | 216 | return tradeOrderItemMapper.selectListByOrderId(orderIds); |
| 200 | } | 217 | } |
| 201 | 218 | ||
| 219 | + /** | ||
| 220 | + * 获得自身的代理对象,解决 AOP 生效问题 | ||
| 221 | + * | ||
| 222 | + * @return 自己 | ||
| 223 | + */ | ||
| 224 | + private TradeOrderQueryServiceImpl getSelf() { | ||
| 225 | + return SpringUtil.getBean(getClass()); | ||
| 226 | + } | ||
| 227 | + | ||
| 202 | } | 228 | } |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java
| @@ -742,8 +742,10 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { | @@ -742,8 +742,10 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { | ||
| 742 | public void updateOrderAddress(TradeOrderUpdateAddressReqVO reqVO) { | 742 | public void updateOrderAddress(TradeOrderUpdateAddressReqVO reqVO) { |
| 743 | // 校验交易订单 | 743 | // 校验交易订单 |
| 744 | TradeOrderDO order = validateOrderExists(reqVO.getId()); | 744 | TradeOrderDO order = validateOrderExists(reqVO.getId()); |
| 745 | - // TODO @puhui999:是否需要校验订单是否发货 | ||
| 746 | - // TODO 发货后是否支持修改收货地址;回答:发货后,不允许修改; | 745 | + // 发货后,不允许修改; |
| 746 | + if (TradeOrderStatusEnum.isDelivered(order.getStatus())) { | ||
| 747 | + throw exception(ORDER_UPDATE_ADDRESS_FAIL_STATUS_NOT_DELIVERED); | ||
| 748 | + } | ||
| 747 | 749 | ||
| 748 | // 更新 | 750 | // 更新 |
| 749 | tradeOrderMapper.updateById(TradeOrderConvert.INSTANCE.convert(reqVO)); | 751 | tradeOrderMapper.updateById(TradeOrderConvert.INSTANCE.convert(reqVO)); |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceImpl.java
| @@ -176,7 +176,7 @@ public class DeptServiceImpl implements DeptService { | @@ -176,7 +176,7 @@ public class DeptServiceImpl implements DeptService { | ||
| 176 | } | 176 | } |
| 177 | 177 | ||
| 178 | @Override | 178 | @Override |
| 179 | - @DataPermission(enable = false) // 禁用数据权限,避免简历不正确的缓存 | 179 | + @DataPermission(enable = false) // 禁用数据权限,避免建立不正确的缓存 |
| 180 | @Cacheable(cacheNames = RedisKeyConstants.DEPT_CHILDREN_ID_LIST, key = "#id") | 180 | @Cacheable(cacheNames = RedisKeyConstants.DEPT_CHILDREN_ID_LIST, key = "#id") |
| 181 | public Set<Long> getChildDeptIdListFromCache(Long id) { | 181 | public Set<Long> getChildDeptIdListFromCache(Long id) { |
| 182 | List<DeptDO> children = getChildDeptList(id); | 182 | List<DeptDO> children = getChildDeptList(id); |