Commit 3f6f7f404bd51b5e21d507246a927333075a2c5d
1 parent
474eebd8
拼团活动:更改创建拼团记录的校验方式
Showing
1 changed file
with
23 additions
and
23 deletions
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java
| @@ -65,35 +65,35 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { | @@ -65,35 +65,35 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { | ||
| 65 | @Transactional(rollbackFor = Exception.class) | 65 | @Transactional(rollbackFor = Exception.class) |
| 66 | public void updateCombinationRecordStatusByUserIdAndOrderId(Integer status, Long userId, Long orderId) { | 66 | public void updateCombinationRecordStatusByUserIdAndOrderId(Integer status, Long userId, Long orderId) { |
| 67 | // 校验拼团是否存在 | 67 | // 校验拼团是否存在 |
| 68 | - CombinationRecordDO recordDO = validateCombinationRecord(userId, orderId); | 68 | + CombinationRecordDO record = validateCombinationRecord(userId, orderId); |
| 69 | 69 | ||
| 70 | // 更新状态 | 70 | // 更新状态 |
| 71 | - recordDO.setStatus(status); | ||
| 72 | - recordMapper.updateById(recordDO); | 71 | + record.setStatus(status); |
| 72 | + recordMapper.updateById(record); | ||
| 73 | } | 73 | } |
| 74 | 74 | ||
| 75 | @Override | 75 | @Override |
| 76 | @Transactional(rollbackFor = Exception.class) | 76 | @Transactional(rollbackFor = Exception.class) |
| 77 | public void updateRecordStatusAndStartTimeByUserIdAndOrderId(Integer status, Long userId, Long orderId, LocalDateTime startTime) { | 77 | public void updateRecordStatusAndStartTimeByUserIdAndOrderId(Integer status, Long userId, Long orderId, LocalDateTime startTime) { |
| 78 | - CombinationRecordDO recordDO = validateCombinationRecord(userId, orderId); | 78 | + CombinationRecordDO record = validateCombinationRecord(userId, orderId); |
| 79 | // 更新状态 | 79 | // 更新状态 |
| 80 | - recordDO.setStatus(status); | 80 | + record.setStatus(status); |
| 81 | // 更新开始时间 | 81 | // 更新开始时间 |
| 82 | - recordDO.setStartTime(startTime); | ||
| 83 | - recordMapper.updateById(recordDO); | 82 | + record.setStartTime(startTime); |
| 83 | + recordMapper.updateById(record); | ||
| 84 | 84 | ||
| 85 | // 更新拼团参入人数 | 85 | // 更新拼团参入人数 |
| 86 | - List<CombinationRecordDO> recordDOs = recordMapper.selectListByHeadIdAndStatus(recordDO.getHeadId(), status); | ||
| 87 | - if (CollUtil.isNotEmpty(recordDOs)) { | ||
| 88 | - recordDOs.forEach(item -> { | ||
| 89 | - item.setUserCount(recordDOs.size()); | 86 | + List<CombinationRecordDO> records = recordMapper.selectListByHeadIdAndStatus(record.getHeadId(), status); |
| 87 | + if (CollUtil.isNotEmpty(records)) { | ||
| 88 | + records.forEach(item -> { | ||
| 89 | + item.setUserCount(records.size()); | ||
| 90 | // 校验拼团是否满足要求 | 90 | // 校验拼团是否满足要求 |
| 91 | - if (ObjectUtil.equal(recordDOs.size(), recordDO.getUserSize())) { | 91 | + if (ObjectUtil.equal(records.size(), record.getUserSize())) { |
| 92 | item.setStatus(CombinationRecordStatusEnum.SUCCESS.getStatus()); | 92 | item.setStatus(CombinationRecordStatusEnum.SUCCESS.getStatus()); |
| 93 | } | 93 | } |
| 94 | }); | 94 | }); |
| 95 | } | 95 | } |
| 96 | - recordMapper.updateBatch(recordDOs); | 96 | + recordMapper.updateBatch(records); |
| 97 | } | 97 | } |
| 98 | 98 | ||
| 99 | private CombinationRecordDO validateCombinationRecord(Long userId, Long orderId) { | 99 | private CombinationRecordDO validateCombinationRecord(Long userId, Long orderId) { |
| @@ -107,7 +107,8 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { | @@ -107,7 +107,8 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { | ||
| 107 | 107 | ||
| 108 | // TODO @芋艿:在详细预览下; | 108 | // TODO @芋艿:在详细预览下; |
| 109 | @Override | 109 | @Override |
| 110 | - public KeyValue<CombinationActivityDO, CombinationProductDO> validateCombinationRecord(Long activityId, Long userId, Long skuId, Integer count) { | 110 | + public KeyValue<CombinationActivityDO, CombinationProductDO> validateCombinationRecord( |
| 111 | + Long activityId, Long userId, Long skuId, Integer count) { | ||
| 111 | // 1.1 校验拼团活动是否存在 | 112 | // 1.1 校验拼团活动是否存在 |
| 112 | CombinationActivityDO activity = combinationActivityService.validateCombinationActivityExists(activityId); | 113 | CombinationActivityDO activity = combinationActivityService.validateCombinationActivityExists(activityId); |
| 113 | // 1.2 校验活动是否开启 | 114 | // 1.2 校验活动是否开启 |
| @@ -163,38 +164,37 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { | @@ -163,38 +164,37 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { | ||
| 163 | @Override | 164 | @Override |
| 164 | @Transactional(rollbackFor = Exception.class) | 165 | @Transactional(rollbackFor = Exception.class) |
| 165 | public void createCombinationRecord(CombinationRecordCreateReqDTO reqDTO) { | 166 | public void createCombinationRecord(CombinationRecordCreateReqDTO reqDTO) { |
| 166 | - // 1.1、 校验拼团活动 | 167 | + // 1、校验拼团活动 |
| 167 | KeyValue<CombinationActivityDO, CombinationProductDO> keyValue = validateCombinationRecord( | 168 | KeyValue<CombinationActivityDO, CombinationProductDO> keyValue = validateCombinationRecord( |
| 168 | reqDTO.getActivityId(), reqDTO.getUserId(), reqDTO.getSkuId(), reqDTO.getCount()); | 169 | reqDTO.getActivityId(), reqDTO.getUserId(), reqDTO.getSkuId(), reqDTO.getCount()); |
| 169 | CombinationActivityDO activity = keyValue.getKey(); | 170 | CombinationActivityDO activity = keyValue.getKey(); |
| 170 | - | ||
| 171 | - // 2、 校验用户是否参加了其它拼团 | 171 | + // 2、校验用户是否参加了其它拼团 |
| 172 | List<CombinationRecordDO> recordDOList = recordMapper.selectListByUserIdAndStatus(reqDTO.getUserId(), CombinationRecordStatusEnum.IN_PROGRESS.getStatus()); | 172 | List<CombinationRecordDO> recordDOList = recordMapper.selectListByUserIdAndStatus(reqDTO.getUserId(), CombinationRecordStatusEnum.IN_PROGRESS.getStatus()); |
| 173 | if (CollUtil.isNotEmpty(recordDOList)) { | 173 | if (CollUtil.isNotEmpty(recordDOList)) { |
| 174 | throw exception(COMBINATION_RECORD_FAILED_HAVE_JOINED); | 174 | throw exception(COMBINATION_RECORD_FAILED_HAVE_JOINED); |
| 175 | } | 175 | } |
| 176 | - // 3、 校验活动是否开启 | 176 | + // 3、校验活动是否开启 |
| 177 | if (LocalDateTime.now().isAfter(activity.getStartTime())) { | 177 | if (LocalDateTime.now().isAfter(activity.getStartTime())) { |
| 178 | throw exception(COMBINATION_RECORD_FAILED_TIME_NOT_START); | 178 | throw exception(COMBINATION_RECORD_FAILED_TIME_NOT_START); |
| 179 | } | 179 | } |
| 180 | - // 4、 校验当前活动是否过期 | 180 | + // 4、校验当前活动是否过期 |
| 181 | if (LocalDateTime.now().isAfter(activity.getEndTime())) { | 181 | if (LocalDateTime.now().isAfter(activity.getEndTime())) { |
| 182 | throw exception(COMBINATION_RECORD_FAILED_TIME_END); | 182 | throw exception(COMBINATION_RECORD_FAILED_TIME_END); |
| 183 | } | 183 | } |
| 184 | - // 5、 父拼团是否存在,是否已经满了 | 184 | + // 5、父拼团是否存在,是否已经满了 |
| 185 | if (reqDTO.getHeadId() != null) { | 185 | if (reqDTO.getHeadId() != null) { |
| 186 | - // 查询进行中的父拼团 | 186 | + // 5.1、查询进行中的父拼团 |
| 187 | CombinationRecordDO record = recordMapper.selectOneByHeadId(reqDTO.getHeadId(), CombinationRecordStatusEnum.IN_PROGRESS.getStatus()); | 187 | CombinationRecordDO record = recordMapper.selectOneByHeadId(reqDTO.getHeadId(), CombinationRecordStatusEnum.IN_PROGRESS.getStatus()); |
| 188 | if (record == null) { | 188 | if (record == null) { |
| 189 | throw exception(COMBINATION_RECORD_HEAD_NOT_EXISTS); | 189 | throw exception(COMBINATION_RECORD_HEAD_NOT_EXISTS); |
| 190 | } | 190 | } |
| 191 | - // 校验拼团是否满足要求 | 191 | + // 5.2、校验拼团是否满足要求 |
| 192 | if (ObjectUtil.equal(record.getUserCount(), record.getUserSize())) { | 192 | if (ObjectUtil.equal(record.getUserCount(), record.getUserSize())) { |
| 193 | throw exception(COMBINATION_RECORD_USER_FULL); | 193 | throw exception(COMBINATION_RECORD_USER_FULL); |
| 194 | } | 194 | } |
| 195 | } | 195 | } |
| 196 | 196 | ||
| 197 | - // 2. 创建拼团记录 | 197 | + // 6. 创建拼团记录 |
| 198 | MemberUserRespDTO user = memberUserApi.getUser(reqDTO.getUserId()); | 198 | MemberUserRespDTO user = memberUserApi.getUser(reqDTO.getUserId()); |
| 199 | ProductSpuRespDTO spu = productSpuApi.getSpu(reqDTO.getSpuId()); | 199 | ProductSpuRespDTO spu = productSpuApi.getSpu(reqDTO.getSpuId()); |
| 200 | ProductSkuRespDTO sku = productSkuApi.getSku(reqDTO.getSkuId()); | 200 | ProductSkuRespDTO sku = productSkuApi.getSku(reqDTO.getSkuId()); |