Commit 99649bfdb82390405bda27df60faeeaeed52cbd8

Authored by YunaiV
1 parent 6a38da4a

code review:拼团记录流程

Showing 12 changed files with 22 additions and 109 deletions
yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/collection/CollectionUtils.java
... ... @@ -25,6 +25,7 @@ public class CollectionUtils {
25 25 return Arrays.stream(collections).anyMatch(CollectionUtil::isEmpty);
26 26 }
27 27  
  28 + // TODO @puhui999: list.sort(); 可以替代呀;
28 29 public static <T, U extends Comparable<? super U>> List<T> sortedAsc(
29 30 Collection<T> from, Function<? super T, ? extends U> keyExtractor) {
30 31 // 按照升序排序
... ...
yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApi.java
... ... @@ -61,6 +61,7 @@ public interface CombinationRecordApi {
61 61 * @param count 数量
62 62 * @return 拼团信息
63 63 */
64   - CombinationValidateJoinRespDTO validateJoinCombination(Long userId, Long activityId, Long headId, Long skuId, Integer count);
  64 + CombinationValidateJoinRespDTO validateJoinCombination(Long userId, Long activityId, Long headId,
  65 + Long skuId, Integer count);
65 66  
66 67 }
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApiImpl.java
... ... @@ -35,12 +35,11 @@ public class CombinationRecordApiImpl implements CombinationRecordApi {
35 35  
36 36 @Override
37 37 public boolean isCombinationRecordSuccess(Long userId, Long orderId) {
38   - CombinationRecordDO combinationRecord = recordService.getCombinationRecord(userId, orderId);
39   - if (combinationRecord == null) {
  38 + CombinationRecordDO record = recordService.getCombinationRecord(userId, orderId);
  39 + if (record == null) {
40 40 throw exception(COMBINATION_RECORD_NOT_EXISTS);
41 41 }
42   -
43   - return CombinationRecordStatusEnum.isSuccess(combinationRecord.getStatus());
  42 + return CombinationRecordStatusEnum.isSuccess(record.getStatus());
44 43 }
45 44  
46 45 @Override
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationRecordController.java
... ... @@ -33,6 +33,8 @@ public class CombinationRecordController {
33 33  
34 34 @Resource
35 35 private CombinationRecordService combinationRecordService;
  36 +
  37 + // TODO @puhui999:这个缓存不用做哈;主要管理后台,对性能要求不高;不像前段;
36 38 /**
37 39 * {@link Map} 缓存,通过它异步刷新 {@link #getCombinationRecordSummary0()} 所要的拼团记录统计数据
38 40 */
... ... @@ -54,6 +56,7 @@ public class CombinationRecordController {
54 56 combinationRecordService.getCombinationRecordPage(pageVO)));
55 57 }
56 58  
  59 + // TODO @puhui999:Map 改成对象,尽量避免 Map 返回结果哈;然后 getCombinationRecordCount、getCombinationRecordsSuccessCount、getRecordsVirtualGroupCount 三个方法,可以合并成一个方法哈,返回这个 vo
57 60 @GetMapping("/get-summary")
58 61 @Operation(summary = "获得拼团记录的概要信息", description = "用于拼团记录页面展示")
59 62 @PreAuthorize("@ss.hasPermission('promotion:combination-record:query')")
... ... @@ -61,26 +64,11 @@ public class CombinationRecordController {
61 64 return success(combinationRecordSummary.getUnchecked("")); // 缓存
62 65 }
63 66  
64   - @GetMapping("/get-count")
65   - @Operation(summary = "获得拼团记录分页 tab count")
66   - @PreAuthorize("@ss.hasPermission('promotion:combination-record:query')")
67   - public CommonResult<Map<String, Long>> getCombinationRecordCount() {
68   - Map<String, Long> hashMap = MapUtil.newHashMap(7);
69   - hashMap.put("all", combinationRecordService.getCombinationRecordsCountByDateType(CombinationRecordReqPageVO.ALL));// 全部
70   - hashMap.put("toDay", combinationRecordService.getCombinationRecordsCountByDateType(CombinationRecordReqPageVO.TO_DAY));// 今天
71   - hashMap.put("yesterday", combinationRecordService.getCombinationRecordsCountByDateType(CombinationRecordReqPageVO.YESTERDAY));// 昨天
72   - hashMap.put("lastSevenDays", combinationRecordService.getCombinationRecordsCountByDateType(CombinationRecordReqPageVO.LAST_SEVEN_DAYS));// 最近七天
73   - hashMap.put("last30Days", combinationRecordService.getCombinationRecordsCountByDateType(CombinationRecordReqPageVO.LAST_30_DAYS));// 最近 30 天
74   - hashMap.put("thisMonth", combinationRecordService.getCombinationRecordsCountByDateType(CombinationRecordReqPageVO.THIS_MONTH));// 本月
75   - hashMap.put("thisYear", combinationRecordService.getCombinationRecordsCountByDateType(CombinationRecordReqPageVO.THIS_YEAR));// 本年
76   - return success(hashMap);
77   - }
78   -
79 67 private Map<String, Long> getCombinationRecordSummary0() {
80   - Map<String, Long> hashMap = MapUtil.newHashMap(3);
81   - hashMap.put("userCount", combinationRecordService.getCombinationRecordCount());// 获取所有拼团记录
82   - hashMap.put("successCount", combinationRecordService.getCombinationRecordsSuccessCount());// 获取成团记录
83   - hashMap.put("virtualGroupCount", combinationRecordService.getRecordsVirtualGroupCount());// 获取虚拟成团记录
  68 + Map<String, Long> hashMap = MapUtil.newHashMap(3); // TODO @puhui999:Maps.newHashMapWithExpectedSize()
  69 + hashMap.put("userCount", combinationRecordService.getCombinationRecordCount()); // 获取所有拼团记录
  70 + hashMap.put("successCount", combinationRecordService.getCombinationRecordsSuccessCount()); // 获取成团记录
  71 + hashMap.put("virtualGroupCount", combinationRecordService.getRecordsVirtualGroupCount()); // 获取虚拟成团记录
84 72 return hashMap;
85 73 }
86 74  
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/recrod/CombinationRecordReqPageVO.java
1 1 package cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod;
2 2  
3 3 import cn.iocoder.yudao.framework.common.pojo.PageParam;
  4 +import cn.iocoder.yudao.framework.common.validation.InEnum;
  5 +import cn.iocoder.yudao.module.promotion.enums.bargain.BargainRecordStatusEnum;
4 6 import io.swagger.v3.oas.annotations.media.Schema;
5 7 import lombok.Data;
6 8 import lombok.EqualsAndHashCode;
... ... @@ -17,18 +19,8 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
17 19 @ToString(callSuper = true)
18 20 public class CombinationRecordReqPageVO extends PageParam {
19 21  
20   - public static final Integer ALL = 0; // 全部
21   - public static final Integer TO_DAY = 1; // 今天
22   - public static final Integer YESTERDAY = 2; // 昨天
23   - public static final Integer LAST_SEVEN_DAYS = 3; // 最近七天
24   - public static final Integer LAST_30_DAYS = 4; // 最近 30 天
25   - public static final Integer THIS_MONTH = 5; // 本月
26   - public static final Integer THIS_YEAR = 6; // 本年
27   -
28   - @Schema(description = "日期类型", example = "0")
29   - private Integer dateType;
30   -
31   - @Schema(description = "活动状态", example = "0")
  22 + @Schema(description = "活动状态", example = "1")
  23 + @InEnum(BargainRecordStatusEnum.class)
32 24 private Integer status;
33 25  
34 26 @Schema(description = "创建时间")
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/recrod/CombinationRecordRespVO.java
... ... @@ -8,6 +8,7 @@ import java.time.LocalDateTime;
8 8  
9 9 import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
10 10  
  11 +// TODO @puhui999:可以参考 BargainRecordPageItemRespVO、BargainRecordRespVO 分成两个;一个给记录列表,一个给记录分页
11 12 @Schema(description = "管理后台 - 拼团记录 Response VO")
12 13 @Data
13 14 public class CombinationRecordRespVO {
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java
... ... @@ -108,6 +108,7 @@ public interface CombinationActivityConvert {
108 108  
109 109 CombinationRecordDO convert(CombinationRecordCreateReqDTO reqDTO);
110 110  
  111 + // TODO @芋艿:在 convert 优化下;
111 112 default CombinationRecordDO convert(CombinationRecordCreateReqDTO reqDTO,
112 113 CombinationActivityDO activity, MemberUserRespDTO user,
113 114 ProductSpuRespDTO spu, ProductSkuRespDTO sku) {
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationRecordMapper.java
... ... @@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.promotion.dal.mysql.combination;
2 2  
3 3 import cn.hutool.core.collection.CollUtil;
4 4 import cn.hutool.core.map.MapUtil;
5   -import cn.hutool.core.util.ObjectUtil;
6 5 import cn.iocoder.yudao.framework.common.pojo.PageResult;
7 6 import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
8 7 import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
... ... @@ -12,8 +11,6 @@ import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationR
12 11 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
13 12 import org.apache.ibatis.annotations.Mapper;
14 13  
15   -import java.time.LocalDateTime;
16   -import java.time.LocalTime;
17 14 import java.util.Collection;
18 15 import java.util.Collections;
19 16 import java.util.List;
... ... @@ -44,12 +41,6 @@ public interface CombinationRecordMapper extends BaseMapperX&lt;CombinationRecordDO
44 41 .eq(CombinationRecordDO::getStatus, status));
45 42 }
46 43  
47   - default List<CombinationRecordDO> selectListByHeadIdAndStatus(Long headId, Integer status) {
48   - return selectList(new LambdaQueryWrapperX<CombinationRecordDO>()
49   - .eq(CombinationRecordDO::getHeadId, headId)
50   - .eq(CombinationRecordDO::getStatus, status));
51   - }
52   -
53 44 /**
54 45 * 查询拼团记录
55 46 *
... ... @@ -103,60 +94,10 @@ public interface CombinationRecordMapper extends BaseMapperX&lt;CombinationRecordDO
103 94 record -> MapUtil.getInt(record, "recordCount"));
104 95 }
105 96  
106   - static LocalDateTime[] builderQueryTime(Integer dateType) {
107   - LocalDateTime now = LocalDateTime.now();
108   - LocalDateTime[] createTime = null; // 全部时间段
109   - // 今天-一天开始到结束
110   - if (ObjectUtil.equal(dateType, CombinationRecordReqPageVO.TO_DAY)) {
111   - createTime = new LocalDateTime[]{now.toLocalDate().atStartOfDay(), now.toLocalDate().atTime(LocalTime.MAX)};
112   - }
113   - // 昨天-昨天开始和结束
114   - if (ObjectUtil.equal(dateType, CombinationRecordReqPageVO.YESTERDAY)) {
115   - createTime = new LocalDateTime[]{now.minusDays(1).toLocalDate().atStartOfDay(),
116   - now.minusDays(1).toLocalDate().atTime(LocalTime.MAX)};
117   - }
118   - // 最近七天
119   - if (ObjectUtil.equal(dateType, CombinationRecordReqPageVO.LAST_SEVEN_DAYS)) {
120   - createTime = new LocalDateTime[]{now.minusDays(7).toLocalDate().atStartOfDay(),
121   - now.toLocalDate().atTime(LocalTime.MAX)};
122   - }
123   - // 最近 30 天
124   - if (ObjectUtil.equal(dateType, CombinationRecordReqPageVO.LAST_30_DAYS)) {
125   - createTime = new LocalDateTime[]{now.minusDays(30).toLocalDate().atStartOfDay(),
126   - now.toLocalDate().atTime(LocalTime.MAX)};
127   - }
128   - // 本月
129   - if (ObjectUtil.equal(dateType, CombinationRecordReqPageVO.THIS_MONTH)) {
130   - // 获取本月的开始时间
131   - LocalDateTime startTime = now.withDayOfMonth(1).toLocalDate().atStartOfDay();
132   - // 获取下个月的开始时间,然后减去一秒以获取本月的结束时间
133   - LocalDateTime endTime = now.withDayOfMonth(1).plusMonths(1).toLocalDate().atStartOfDay().minusSeconds(1);
134   - createTime = new LocalDateTime[]{startTime, endTime};
135   - }
136   - // 本年
137   - if (ObjectUtil.equal(dateType, CombinationRecordReqPageVO.THIS_YEAR)) {
138   - // 获取本年的开始时间
139   - LocalDateTime startTime = now.withDayOfYear(1).toLocalDate().atStartOfDay();
140   - // 获取下一年的开始时间,然后减去一秒以获取本年的结束时间
141   - LocalDateTime endTime = now.withDayOfYear(1).plusYears(1).toLocalDate().atStartOfDay().minusSeconds(1);
142   - createTime = new LocalDateTime[]{startTime, endTime};
143   - }
144   - return createTime;
145   - }
146   -
147 97 default PageResult<CombinationRecordDO> selectPage(CombinationRecordReqPageVO pageVO) {
148   - // 兼容自选时间段
149   - if (pageVO.getDateType() != null) {
150   - pageVO.setCreateTime(builderQueryTime(pageVO.getDateType()));
151   - }
152 98 return selectPage(pageVO, new LambdaQueryWrapperX<CombinationRecordDO>()
153 99 .eqIfPresent(CombinationRecordDO::getStatus, pageVO.getStatus())
154 100 .betweenIfPresent(CombinationRecordDO::getCreateTime, pageVO.getCreateTime()));
155 101 }
156 102  
157   - default Long selectCount(Integer dateType) {
158   - return selectCount(new LambdaQueryWrapperX<CombinationRecordDO>()
159   - .betweenIfPresent(CombinationRecordDO::getCreateTime, builderQueryTime(dateType)));
160   - }
161   -
162 103 }
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordService.java
... ... @@ -105,14 +105,6 @@ public interface CombinationRecordService {
105 105 Long getRecordsVirtualGroupCount();
106 106  
107 107 /**
108   - * 获取指定日期类型的记录数,比如说获取最近七天的拼团记录数
109   - *
110   - * @param dateType 日期类型
111   - * @return 记录数
112   - */
113   - Long getCombinationRecordsCountByDateType(Integer dateType);
114   -
115   - /**
116 108 * 获取最近的 count 条拼团记录
117 109 *
118 110 * @param count 限制数量
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java
... ... @@ -262,20 +262,17 @@ public class CombinationRecordServiceImpl implements CombinationRecordService {
262 262  
263 263 @Override
264 264 public Long getCombinationRecordsSuccessCount() {
  265 + // TODO @puhui999:这个应该要多查询 headId
265 266 return recordMapper.selectCount(CombinationRecordDO::getStatus, CombinationRecordStatusEnum.SUCCESS.getStatus());
266 267 }
267 268  
268 269 @Override
269 270 public Long getRecordsVirtualGroupCount() {
  271 + // TODO @puhui999:这个应该要多查询 headId;然后,recordMapper 要明确的查询哈,不要直接使用 mapper 来拼接查询条件
270 272 return recordMapper.selectCount(CombinationRecordDO::getVirtualGroup, true);
271 273 }
272 274  
273 275 @Override
274   - public Long getCombinationRecordsCountByDateType(Integer dateType) {
275   - return recordMapper.selectCount(dateType);
276   - }
277   -
278   - @Override
279 276 public List<CombinationRecordDO> getLatestCombinationRecordList(int count) {
280 277 return recordMapper.selectLatestList(count);
281 278 }
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateService.java
... ... @@ -178,6 +178,7 @@ public interface TradeOrderUpdateService {
178 178 * @param combinationRecordId 拼团记录编号
179 179 * @param headId 团长编号
180 180 */
  181 + // TODO 芋艿:再 review 拼团
181 182 void updateOrderCombinationInfo(Long orderId, Long activityId, Long combinationRecordId, Long headId);
182 183  
183 184 /**
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationHandler.java
... ... @@ -43,7 +43,6 @@ public class TradeCombinationHandler implements TradeOrderHandler {
43 43 if (TradeOrderTypeEnum.isCombination(order.getType())) {
44 44 return;
45 45 }
46   -
47 46 Assert.isTrue(orderItems.size() == 1, "拼团时,只允许选择一个商品");
48 47  
49 48 // 获取商品信息
... ...