Commit 453f69931fcd33d1144f2658c69f8eb8bd4c6ebc
1 parent
64b842ed
code review:营销文章
Showing
7 changed files
with
22 additions
and
23 deletions
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/activity/AppActivityController.java
| @@ -46,7 +46,7 @@ public class AppActivityController { | @@ -46,7 +46,7 @@ public class AppActivityController { | ||
| 46 | @Parameter(name = "spuId", description = "商品编号", required = true) | 46 | @Parameter(name = "spuId", description = "商品编号", required = true) |
| 47 | public CommonResult<List<AppActivityRespVO>> getActivityListBySpuId(@RequestParam("spuId") Long spuId) { | 47 | public CommonResult<List<AppActivityRespVO>> getActivityListBySpuId(@RequestParam("spuId") Long spuId) { |
| 48 | // 每种活动,只返回一个 | 48 | // 每种活动,只返回一个 |
| 49 | - return success(getAppActivityRespVOList(Collections.singletonList(spuId))); | 49 | + return success(getAppActivityList(Collections.singletonList(spuId))); |
| 50 | } | 50 | } |
| 51 | 51 | ||
| 52 | @GetMapping("/list-by-spu-ids") | 52 | @GetMapping("/list-by-spu-ids") |
| @@ -57,16 +57,17 @@ public class AppActivityController { | @@ -57,16 +57,17 @@ public class AppActivityController { | ||
| 57 | return success(MapUtil.empty()); | 57 | return success(MapUtil.empty()); |
| 58 | } | 58 | } |
| 59 | // 每种活动,只返回一个;key 为 SPU 编号 | 59 | // 每种活动,只返回一个;key 为 SPU 编号 |
| 60 | - return success(convertMultiMap(getAppActivityRespVOList(spuIds), AppActivityRespVO::getSpuId)); | 60 | + return success(convertMultiMap(getAppActivityList(spuIds), AppActivityRespVO::getSpuId)); |
| 61 | } | 61 | } |
| 62 | 62 | ||
| 63 | - private List<AppActivityRespVO> getAppActivityRespVOList(Collection<Long> spuIds) { | 63 | + private List<AppActivityRespVO> getAppActivityList(Collection<Long> spuIds) { |
| 64 | if (CollUtil.isEmpty(spuIds)) { | 64 | if (CollUtil.isEmpty(spuIds)) { |
| 65 | return new ArrayList<>(); | 65 | return new ArrayList<>(); |
| 66 | } | 66 | } |
| 67 | LocalDateTime now = LocalDateTime.now(); | 67 | LocalDateTime now = LocalDateTime.now(); |
| 68 | List<AppActivityRespVO> activityList = new ArrayList<>(); | 68 | List<AppActivityRespVO> activityList = new ArrayList<>(); |
| 69 | - // 拼团活动-获取开启的且开始的且没有结束的活动 | 69 | + |
| 70 | + // 1. 拼团活动 - 获取开启的且开始的且没有结束的活动 | ||
| 70 | List<CombinationActivityDO> combinationActivities = combinationActivityService.getCombinationActivityBySpuIdsAndStatusAndDateTimeLt( | 71 | List<CombinationActivityDO> combinationActivities = combinationActivityService.getCombinationActivityBySpuIdsAndStatusAndDateTimeLt( |
| 71 | spuIds, CommonStatusEnum.ENABLE.getStatus(), now); | 72 | spuIds, CommonStatusEnum.ENABLE.getStatus(), now); |
| 72 | if (CollUtil.isNotEmpty(combinationActivities)) { | 73 | if (CollUtil.isNotEmpty(combinationActivities)) { |
| @@ -76,7 +77,8 @@ public class AppActivityController { | @@ -76,7 +77,8 @@ public class AppActivityController { | ||
| 76 | .setSpuId(item.getSpuId()).setStartTime(item.getStartTime()).setEndTime(item.getEndTime())); | 77 | .setSpuId(item.getSpuId()).setStartTime(item.getStartTime()).setEndTime(item.getEndTime())); |
| 77 | }); | 78 | }); |
| 78 | } | 79 | } |
| 79 | - // 秒杀活动-获取开启的且开始的且没有结束的活动 | 80 | + |
| 81 | + // 2. 秒杀活动 - 获取开启的且开始的且没有结束的活动 | ||
| 80 | List<SeckillActivityDO> seckillActivities = seckillActivityService.getSeckillActivityBySpuIdsAndStatusAndDateTimeLt( | 82 | List<SeckillActivityDO> seckillActivities = seckillActivityService.getSeckillActivityBySpuIdsAndStatusAndDateTimeLt( |
| 81 | spuIds, CommonStatusEnum.ENABLE.getStatus(), now); | 83 | spuIds, CommonStatusEnum.ENABLE.getStatus(), now); |
| 82 | if (CollUtil.isNotEmpty(seckillActivities)) { | 84 | if (CollUtil.isNotEmpty(seckillActivities)) { |
| @@ -86,7 +88,8 @@ public class AppActivityController { | @@ -86,7 +88,8 @@ public class AppActivityController { | ||
| 86 | .setSpuId(item.getSpuId()).setStartTime(item.getStartTime()).setEndTime(item.getEndTime())); | 88 | .setSpuId(item.getSpuId()).setStartTime(item.getStartTime()).setEndTime(item.getEndTime())); |
| 87 | }); | 89 | }); |
| 88 | } | 90 | } |
| 89 | - // 砍价活动-获取开启的且开始的且没有结束的活动 | 91 | + |
| 92 | + // 3. 砍价活动 - 获取开启的且开始的且没有结束的活动 | ||
| 90 | List<BargainActivityDO> bargainActivities = bargainActivityService.getBargainActivityBySpuIdsAndStatusAndDateTimeLt( | 93 | List<BargainActivityDO> bargainActivities = bargainActivityService.getBargainActivityBySpuIdsAndStatusAndDateTimeLt( |
| 91 | spuIds, CommonStatusEnum.ENABLE.getStatus(), now); | 94 | spuIds, CommonStatusEnum.ENABLE.getStatus(), now); |
| 92 | if (CollUtil.isNotEmpty(bargainActivities)) { | 95 | if (CollUtil.isNotEmpty(bargainActivities)) { |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/article/AppArticleCategoryController.java
| @@ -32,7 +32,7 @@ public class AppArticleCategoryController { | @@ -32,7 +32,7 @@ public class AppArticleCategoryController { | ||
| 32 | public CommonResult<List<AppArticleCategoryRespVO>> getArticleCategoryList() { | 32 | public CommonResult<List<AppArticleCategoryRespVO>> getArticleCategoryList() { |
| 33 | List<ArticleCategoryDO> categoryList = articleCategoryService.getArticleCategoryListByStatus( | 33 | List<ArticleCategoryDO> categoryList = articleCategoryService.getArticleCategoryListByStatus( |
| 34 | CommonStatusEnum.ENABLE.getStatus()); | 34 | CommonStatusEnum.ENABLE.getStatus()); |
| 35 | - categoryList.sort(Comparator.comparing(ArticleCategoryDO::getSort).reversed()); // 按 sort 降序排列 | 35 | + categoryList.sort(Comparator.comparing(ArticleCategoryDO::getSort)); // 按 sort 降序排列 |
| 36 | return success(ArticleCategoryConvert.INSTANCE.convertList04(categoryList)); | 36 | return success(ArticleCategoryConvert.INSTANCE.convertList04(categoryList)); |
| 37 | } | 37 | } |
| 38 | 38 |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/article/AppArticleController.java
| @@ -56,10 +56,12 @@ public class AppArticleController { | @@ -56,10 +56,12 @@ public class AppArticleController { | ||
| 56 | return success(ArticleConvert.INSTANCE.convert01(articleService.getArticle(id))); | 56 | return success(ArticleConvert.INSTANCE.convert01(articleService.getArticle(id))); |
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | + // TODO @puhui999:add-browse-count 噢;前端 uniapp 也要接下;就是打开文章的时候,调用下这个接口; | ||
| 59 | @PutMapping("/add-browseCount") | 60 | @PutMapping("/add-browseCount") |
| 60 | @Operation(summary = "增加文章浏览量") | 61 | @Operation(summary = "增加文章浏览量") |
| 61 | @Parameter(name = "id", description = "文章编号", example = "1024") | 62 | @Parameter(name = "id", description = "文章编号", example = "1024") |
| 62 | public CommonResult<Boolean> addBrowseCount(@RequestParam("id") Long id) { | 63 | public CommonResult<Boolean> addBrowseCount(@RequestParam("id") Long id) { |
| 64 | + // TODO @puhui999:addArticleBrowseCount | ||
| 63 | articleService.addBrowseCount(id); | 65 | articleService.addBrowseCount(id); |
| 64 | return success(true); | 66 | return success(true); |
| 65 | } | 67 | } |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java
| @@ -204,9 +204,6 @@ public interface CombinationActivityConvert { | @@ -204,9 +204,6 @@ public interface CombinationActivityConvert { | ||
| 204 | return respVO; | 204 | return respVO; |
| 205 | } | 205 | } |
| 206 | 206 | ||
| 207 | - @Mapping(target = "id", ignore = true) | ||
| 208 | - CombinationRecordDO convert5(CombinationRecordDO headRecord); | ||
| 209 | - | ||
| 210 | /** | 207 | /** |
| 211 | * 转换生成虚拟成团虚拟记录 | 208 | * 转换生成虚拟成团虚拟记录 |
| 212 | * | 209 | * |
| @@ -214,21 +211,19 @@ public interface CombinationActivityConvert { | @@ -214,21 +211,19 @@ public interface CombinationActivityConvert { | ||
| 214 | * @return 虚拟记录列表 | 211 | * @return 虚拟记录列表 |
| 215 | */ | 212 | */ |
| 216 | default List<CombinationRecordDO> convertVirtualRecordList(CombinationRecordDO headRecord) { | 213 | default List<CombinationRecordDO> convertVirtualRecordList(CombinationRecordDO headRecord) { |
| 217 | - List<CombinationRecordDO> createRecords = new ArrayList<>(); | ||
| 218 | - // 计算需要创建的虚拟成团记录数量 | ||
| 219 | int count = headRecord.getUserSize() - headRecord.getUserCount(); | 214 | int count = headRecord.getUserSize() - headRecord.getUserCount(); |
| 215 | + List<CombinationRecordDO> createRecords = new ArrayList<>(count); | ||
| 220 | for (int i = 0; i < count; i++) { | 216 | for (int i = 0; i < count; i++) { |
| 221 | // 基础信息和团长保持一致 | 217 | // 基础信息和团长保持一致 |
| 222 | CombinationRecordDO newRecord = convert5(headRecord); | 218 | CombinationRecordDO newRecord = convert5(headRecord); |
| 223 | // 虚拟信息 | 219 | // 虚拟信息 |
| 224 | - newRecord.setCount(0); | ||
| 225 | - newRecord.setUserId(0L); | ||
| 226 | - newRecord.setNickname(""); | ||
| 227 | - newRecord.setAvatar(""); | ||
| 228 | - newRecord.setOrderId(0L); | 220 | + newRecord.setCount(0) // 会单独更新下,在后续的 Service 逻辑里 |
| 221 | + .setUserId(0L).setNickname("").setAvatar("").setOrderId(0L); | ||
| 229 | createRecords.add(newRecord); | 222 | createRecords.add(newRecord); |
| 230 | } | 223 | } |
| 231 | return createRecords; | 224 | return createRecords; |
| 232 | } | 225 | } |
| 226 | + @Mapping(target = "id", ignore = true) | ||
| 227 | + CombinationRecordDO convert5(CombinationRecordDO headRecord); | ||
| 233 | 228 | ||
| 234 | } | 229 | } |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainActivityMapper.java
| @@ -102,6 +102,7 @@ public interface BargainActivityMapper extends BaseMapperX<BargainActivityDO> { | @@ -102,6 +102,7 @@ public interface BargainActivityMapper extends BaseMapperX<BargainActivityDO> { | ||
| 102 | .groupBy("spu_id")); | 102 | .groupBy("spu_id")); |
| 103 | } | 103 | } |
| 104 | 104 | ||
| 105 | + // TODO @puhui999:是不是只要 endTime 小于就可以啦; | ||
| 105 | /** | 106 | /** |
| 106 | * 获取指定活动编号的活动列表且 | 107 | * 获取指定活动编号的活动列表且 |
| 107 | * 开始时间和结束时间小于给定时间 dateTime 的活动列表 | 108 | * 开始时间和结束时间小于给定时间 dateTime 的活动列表 |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/article/ArticleServiceImpl.java
| @@ -10,7 +10,6 @@ import cn.iocoder.yudao.module.promotion.dal.dataobject.article.ArticleCategoryD | @@ -10,7 +10,6 @@ import cn.iocoder.yudao.module.promotion.dal.dataobject.article.ArticleCategoryD | ||
| 10 | import cn.iocoder.yudao.module.promotion.dal.dataobject.article.ArticleDO; | 10 | import cn.iocoder.yudao.module.promotion.dal.dataobject.article.ArticleDO; |
| 11 | import cn.iocoder.yudao.module.promotion.dal.mysql.article.ArticleMapper; | 11 | import cn.iocoder.yudao.module.promotion.dal.mysql.article.ArticleMapper; |
| 12 | import org.springframework.stereotype.Service; | 12 | import org.springframework.stereotype.Service; |
| 13 | -import org.springframework.transaction.annotation.Transactional; | ||
| 14 | import org.springframework.validation.annotation.Validated; | 13 | import org.springframework.validation.annotation.Validated; |
| 15 | 14 | ||
| 16 | import javax.annotation.Resource; | 15 | import javax.annotation.Resource; |
| @@ -112,12 +111,10 @@ public class ArticleServiceImpl implements ArticleService { | @@ -112,12 +111,10 @@ public class ArticleServiceImpl implements ArticleService { | ||
| 112 | } | 111 | } |
| 113 | 112 | ||
| 114 | @Override | 113 | @Override |
| 115 | - @Transactional(rollbackFor = Exception.class) | ||
| 116 | public void addBrowseCount(Long id) { | 114 | public void addBrowseCount(Long id) { |
| 117 | // 校验文章是否存在 | 115 | // 校验文章是否存在 |
| 118 | validateArticleExists(id); | 116 | validateArticleExists(id); |
| 119 | - | ||
| 120 | - // 增加浏览次数 TODO 先简单做,用户规模不大,只 +1 | 117 | + // 增加浏览次数 |
| 121 | articleMapper.updateBrowseCount(id); | 118 | articleMapper.updateBrowseCount(id); |
| 122 | } | 119 | } |
| 123 | 120 |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java
| @@ -369,6 +369,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { | @@ -369,6 +369,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { | ||
| 369 | keyValue.setValue(keyValue.getValue() + 1); | 369 | keyValue.setValue(keyValue.getValue() + 1); |
| 370 | } | 370 | } |
| 371 | } catch (Exception ignored) { // 处理异常继续循环 | 371 | } catch (Exception ignored) { // 处理异常继续循环 |
| 372 | + // TODO @puhui999:拼团过期 or 虚拟成团 可以改成 expireCombinationRecord;因为找方法更容易一些; | ||
| 372 | log.error("[拼团过期 or 虚拟成团][record({}) 处理异常,请进行处理!record 数据是:{}]", | 373 | log.error("[拼团过期 or 虚拟成团][record({}) 处理异常,请进行处理!record 数据是:{}]", |
| 373 | record.getId(), JsonUtils.toJsonString(record)); | 374 | record.getId(), JsonUtils.toJsonString(record)); |
| 374 | } | 375 | } |
| @@ -383,10 +384,10 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { | @@ -383,10 +384,10 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { | ||
| 383 | */ | 384 | */ |
| 384 | @Transactional(rollbackFor = Exception.class) | 385 | @Transactional(rollbackFor = Exception.class) |
| 385 | public void handleExpireRecord(CombinationRecordDO headRecord) { | 386 | public void handleExpireRecord(CombinationRecordDO headRecord) { |
| 386 | - // 1.更新拼团记录 | 387 | + // 1. 更新拼团记录 |
| 387 | List<CombinationRecordDO> headAndRecords = updateBatchCombinationRecords(headRecord, | 388 | List<CombinationRecordDO> headAndRecords = updateBatchCombinationRecords(headRecord, |
| 388 | CombinationRecordStatusEnum.FAILED); | 389 | CombinationRecordStatusEnum.FAILED); |
| 389 | - // 2.订单取消 | 390 | + // 2. 订单取消 |
| 390 | headAndRecords.forEach(item -> tradeOrderApi.cancelPaidOrder(item.getUserId(), item.getOrderId())); | 391 | headAndRecords.forEach(item -> tradeOrderApi.cancelPaidOrder(item.getUserId(), item.getOrderId())); |
| 391 | } | 392 | } |
| 392 | 393 |