Commit 2c0f1121cad30631a9f71ca158eb9821d76d2dae

Authored by puhui999
1 parent 2e559ebe

拼团活动:完善 review 提到的问题

yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApi.java
... ... @@ -29,8 +29,9 @@ public interface CombinationRecordApi {
29 29 * 创建开团记录
30 30 *
31 31 * @param reqDTO 请求 DTO
  32 + * @return 开团记录编号
32 33 */
33   - void createCombinationRecord(@Valid CombinationRecordCreateReqDTO reqDTO);
  34 + Long createCombinationRecord(@Valid CombinationRecordCreateReqDTO reqDTO);
34 35  
35 36 /**
36 37 * 查询拼团记录是否成功
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApiImpl.java
... ... @@ -29,8 +29,8 @@ public class CombinationRecordApiImpl implements CombinationRecordApi {
29 29 }
30 30  
31 31 @Override
32   - public void createCombinationRecord(CombinationRecordCreateReqDTO reqDTO) {
33   - recordService.createCombinationRecord(reqDTO);
  32 + public Long createCombinationRecord(CombinationRecordCreateReqDTO reqDTO) {
  33 + return recordService.createCombinationRecord(reqDTO);
34 34 }
35 35  
36 36 @Override
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordService.java
... ... @@ -49,8 +49,9 @@ public interface CombinationRecordService {
49 49 * 创建拼团记录
50 50 *
51 51 * @param reqDTO 创建信息
  52 + * @return 开团记录编号
52 53 */
53   - void createCombinationRecord(CombinationRecordCreateReqDTO reqDTO);
  54 + Long createCombinationRecord(CombinationRecordCreateReqDTO reqDTO);
54 55  
55 56 /**
56 57 * 获得拼团记录
... ... @@ -87,7 +88,7 @@ public interface CombinationRecordService {
87 88 /**
88 89 * 获取拼团记录数
89 90 *
90   - * @param status 状态-允许为空
  91 + * @param status 状态-允许为空
91 92 * @param virtualGroup 是否虚拟成团-允许为空
92 93 * @return 记录数
93 94 */
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java
... ... @@ -31,7 +31,8 @@ import javax.annotation.Resource;
31 31 import java.util.*;
32 32  
33 33 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
34   -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
  34 +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.findFirst;
  35 +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.getSumValue;
35 36 import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.afterNow;
36 37 import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.beforeNow;
37 38 import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*;
... ... @@ -163,7 +164,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService {
163 164  
164 165 @Override
165 166 @Transactional(rollbackFor = Exception.class)
166   - public void createCombinationRecord(CombinationRecordCreateReqDTO reqDTO) {
  167 + public Long createCombinationRecord(CombinationRecordCreateReqDTO reqDTO) {
167 168 // 1. 校验拼团活动
168 169 KeyValue<CombinationActivityDO, CombinationProductDO> keyValue = validateCombinationRecord(reqDTO.getUserId(),
169 170 reqDTO.getActivityId(), reqDTO.getHeadId(), reqDTO.getSkuId(), reqDTO.getCount());
... ... @@ -173,34 +174,19 @@ public class CombinationRecordServiceImpl implements CombinationRecordService {
173 174 ProductSpuRespDTO spu = productSpuApi.getSpu(reqDTO.getSpuId());
174 175 ProductSkuRespDTO sku = productSkuApi.getSku(reqDTO.getSkuId());
175 176 CombinationRecordDO record = CombinationActivityConvert.INSTANCE.convert(reqDTO, keyValue.getKey(), user, spu, sku);
176   - // TODO @puhui:有 head 的情况下,以 head 结束为准
  177 + // 3. 如果是团长需要设置 headId 为 CombinationRecordDO#HEAD_ID_GROUP
  178 + record.setHeadId(record.getHeadId() == null ? CombinationRecordDO.HEAD_ID_GROUP : record.getHeadId());
177 179 recordMapper.insert(record);
178 180  
179   - // 3. 如果是团长需要设置 headId 为 CombinationRecordDO#HEAD_ID_GROUP
180   - // TODO @puhui999:是不是只要是团长,record 设置了就好啦,不用 update。。。。
181   - if (ObjUtil.equal(CombinationRecordDO.HEAD_ID_GROUP, reqDTO.getHeadId())) {
182   - recordMapper.updateById(new CombinationRecordDO().setId(record.getId()).setHeadId(CombinationRecordDO.HEAD_ID_GROUP));
183   - return;
  181 + if (ObjUtil.equal(CombinationRecordDO.HEAD_ID_GROUP, record.getHeadId())) {
  182 + return record.getId();
184 183 }
185 184  
186   - // TODO 这里要不要弄成异步的;不用异步哈,就是事务好了;
187 185 // 4、更新拼团相关信息到订单
188   - updateOrderCombinationInfo(record.getOrderId(), record.getActivityId(), record.getId(), record.getHeadId());
  186 + tradeOrderApi.updateOrderCombinationInfo(record.getOrderId(), record.getActivityId(), record.getId(), record.getHeadId());
189 187 // 4、更新拼团记录
190 188 updateCombinationRecordWhenCreate(reqDTO.getHeadId(), keyValue.getKey());
191   - }
192   -
193   - // TODO @puhui999:这个更新,放到 trade 那就好了;createCombinationRecord 返回一个 recordId;
194   - /**
195   - * 更新拼团相关信息到订单
196   - *
197   - * @param orderId 订单编号
198   - * @param activityId 拼团活动编号
199   - * @param combinationRecordId 拼团记录编号
200   - * @param headId 团长编号
201   - */
202   - private void updateOrderCombinationInfo(Long orderId, Long activityId, Long combinationRecordId, Long headId) {
203   - tradeOrderApi.updateOrderCombinationInfo(orderId, activityId, combinationRecordId, headId);
  189 + return record.getId();
204 190 }
205 191  
206 192 /**
... ...