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 | 46 | @Parameter(name = "spuId", description = "商品编号", required = true) |
| 47 | 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 | 52 | @GetMapping("/list-by-spu-ids") |
| ... | ... | @@ -57,16 +57,17 @@ public class AppActivityController { |
| 57 | 57 | return success(MapUtil.empty()); |
| 58 | 58 | } |
| 59 | 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 | 64 | if (CollUtil.isEmpty(spuIds)) { |
| 65 | 65 | return new ArrayList<>(); |
| 66 | 66 | } |
| 67 | 67 | LocalDateTime now = LocalDateTime.now(); |
| 68 | 68 | List<AppActivityRespVO> activityList = new ArrayList<>(); |
| 69 | - // 拼团活动-获取开启的且开始的且没有结束的活动 | |
| 69 | + | |
| 70 | + // 1. 拼团活动 - 获取开启的且开始的且没有结束的活动 | |
| 70 | 71 | List<CombinationActivityDO> combinationActivities = combinationActivityService.getCombinationActivityBySpuIdsAndStatusAndDateTimeLt( |
| 71 | 72 | spuIds, CommonStatusEnum.ENABLE.getStatus(), now); |
| 72 | 73 | if (CollUtil.isNotEmpty(combinationActivities)) { |
| ... | ... | @@ -76,7 +77,8 @@ public class AppActivityController { |
| 76 | 77 | .setSpuId(item.getSpuId()).setStartTime(item.getStartTime()).setEndTime(item.getEndTime())); |
| 77 | 78 | }); |
| 78 | 79 | } |
| 79 | - // 秒杀活动-获取开启的且开始的且没有结束的活动 | |
| 80 | + | |
| 81 | + // 2. 秒杀活动 - 获取开启的且开始的且没有结束的活动 | |
| 80 | 82 | List<SeckillActivityDO> seckillActivities = seckillActivityService.getSeckillActivityBySpuIdsAndStatusAndDateTimeLt( |
| 81 | 83 | spuIds, CommonStatusEnum.ENABLE.getStatus(), now); |
| 82 | 84 | if (CollUtil.isNotEmpty(seckillActivities)) { |
| ... | ... | @@ -86,7 +88,8 @@ public class AppActivityController { |
| 86 | 88 | .setSpuId(item.getSpuId()).setStartTime(item.getStartTime()).setEndTime(item.getEndTime())); |
| 87 | 89 | }); |
| 88 | 90 | } |
| 89 | - // 砍价活动-获取开启的且开始的且没有结束的活动 | |
| 91 | + | |
| 92 | + // 3. 砍价活动 - 获取开启的且开始的且没有结束的活动 | |
| 90 | 93 | List<BargainActivityDO> bargainActivities = bargainActivityService.getBargainActivityBySpuIdsAndStatusAndDateTimeLt( |
| 91 | 94 | spuIds, CommonStatusEnum.ENABLE.getStatus(), now); |
| 92 | 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 | 32 | public CommonResult<List<AppArticleCategoryRespVO>> getArticleCategoryList() { |
| 33 | 33 | List<ArticleCategoryDO> categoryList = articleCategoryService.getArticleCategoryListByStatus( |
| 34 | 34 | CommonStatusEnum.ENABLE.getStatus()); |
| 35 | - categoryList.sort(Comparator.comparing(ArticleCategoryDO::getSort).reversed()); // 按 sort 降序排列 | |
| 35 | + categoryList.sort(Comparator.comparing(ArticleCategoryDO::getSort)); // 按 sort 降序排列 | |
| 36 | 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 | 56 | return success(ArticleConvert.INSTANCE.convert01(articleService.getArticle(id))); |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | + // TODO @puhui999:add-browse-count 噢;前端 uniapp 也要接下;就是打开文章的时候,调用下这个接口; | |
| 59 | 60 | @PutMapping("/add-browseCount") |
| 60 | 61 | @Operation(summary = "增加文章浏览量") |
| 61 | 62 | @Parameter(name = "id", description = "文章编号", example = "1024") |
| 62 | 63 | public CommonResult<Boolean> addBrowseCount(@RequestParam("id") Long id) { |
| 64 | + // TODO @puhui999:addArticleBrowseCount | |
| 63 | 65 | articleService.addBrowseCount(id); |
| 64 | 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 | 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 | 211 | * @return 虚拟记录列表 |
| 215 | 212 | */ |
| 216 | 213 | default List<CombinationRecordDO> convertVirtualRecordList(CombinationRecordDO headRecord) { |
| 217 | - List<CombinationRecordDO> createRecords = new ArrayList<>(); | |
| 218 | - // 计算需要创建的虚拟成团记录数量 | |
| 219 | 214 | int count = headRecord.getUserSize() - headRecord.getUserCount(); |
| 215 | + List<CombinationRecordDO> createRecords = new ArrayList<>(count); | |
| 220 | 216 | for (int i = 0; i < count; i++) { |
| 221 | 217 | // 基础信息和团长保持一致 |
| 222 | 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 | 222 | createRecords.add(newRecord); |
| 230 | 223 | } |
| 231 | 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
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 | 10 | import cn.iocoder.yudao.module.promotion.dal.dataobject.article.ArticleDO; |
| 11 | 11 | import cn.iocoder.yudao.module.promotion.dal.mysql.article.ArticleMapper; |
| 12 | 12 | import org.springframework.stereotype.Service; |
| 13 | -import org.springframework.transaction.annotation.Transactional; | |
| 14 | 13 | import org.springframework.validation.annotation.Validated; |
| 15 | 14 | |
| 16 | 15 | import javax.annotation.Resource; |
| ... | ... | @@ -112,12 +111,10 @@ public class ArticleServiceImpl implements ArticleService { |
| 112 | 111 | } |
| 113 | 112 | |
| 114 | 113 | @Override |
| 115 | - @Transactional(rollbackFor = Exception.class) | |
| 116 | 114 | public void addBrowseCount(Long id) { |
| 117 | 115 | // 校验文章是否存在 |
| 118 | 116 | validateArticleExists(id); |
| 119 | - | |
| 120 | - // 增加浏览次数 TODO 先简单做,用户规模不大,只 +1 | |
| 117 | + // 增加浏览次数 | |
| 121 | 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 | 369 | keyValue.setValue(keyValue.getValue() + 1); |
| 370 | 370 | } |
| 371 | 371 | } catch (Exception ignored) { // 处理异常继续循环 |
| 372 | + // TODO @puhui999:拼团过期 or 虚拟成团 可以改成 expireCombinationRecord;因为找方法更容易一些; | |
| 372 | 373 | log.error("[拼团过期 or 虚拟成团][record({}) 处理异常,请进行处理!record 数据是:{}]", |
| 373 | 374 | record.getId(), JsonUtils.toJsonString(record)); |
| 374 | 375 | } |
| ... | ... | @@ -383,10 +384,10 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { |
| 383 | 384 | */ |
| 384 | 385 | @Transactional(rollbackFor = Exception.class) |
| 385 | 386 | public void handleExpireRecord(CombinationRecordDO headRecord) { |
| 386 | - // 1.更新拼团记录 | |
| 387 | + // 1. 更新拼团记录 | |
| 387 | 388 | List<CombinationRecordDO> headAndRecords = updateBatchCombinationRecords(headRecord, |
| 388 | 389 | CombinationRecordStatusEnum.FAILED); |
| 389 | - // 2.订单取消 | |
| 390 | + // 2. 订单取消 | |
| 390 | 391 | headAndRecords.forEach(item -> tradeOrderApi.cancelPaidOrder(item.getUserId(), item.getOrderId())); |
| 391 | 392 | } |
| 392 | 393 | ... | ... |