|
@@ -1,11 +1,10 @@
|
|
package cn.iocoder.yudao.module.promotion.service.combination;
|
|
package cn.iocoder.yudao.module.promotion.service.combination;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.collection.CollUtil;
|
|
-import cn.hutool.core.util.ObjectUtil;
|
|
|
|
|
|
+import cn.hutool.core.util.ObjUtil;
|
|
import cn.iocoder.yudao.framework.common.core.KeyValue;
|
|
import cn.iocoder.yudao.framework.common.core.KeyValue;
|
|
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
|
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
-import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils;
|
|
|
|
import cn.iocoder.yudao.module.member.api.user.MemberUserApi;
|
|
import cn.iocoder.yudao.module.member.api.user.MemberUserApi;
|
|
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
|
|
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
|
|
import cn.iocoder.yudao.module.product.api.sku.ProductSkuApi;
|
|
import cn.iocoder.yudao.module.product.api.sku.ProductSkuApi;
|
|
@@ -22,7 +21,6 @@ import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationR
|
|
import cn.iocoder.yudao.module.promotion.dal.mysql.combination.CombinationRecordMapper;
|
|
import cn.iocoder.yudao.module.promotion.dal.mysql.combination.CombinationRecordMapper;
|
|
import cn.iocoder.yudao.module.promotion.enums.combination.CombinationRecordStatusEnum;
|
|
import cn.iocoder.yudao.module.promotion.enums.combination.CombinationRecordStatusEnum;
|
|
import cn.iocoder.yudao.module.trade.api.order.TradeOrderApi;
|
|
import cn.iocoder.yudao.module.trade.api.order.TradeOrderApi;
|
|
-import cn.iocoder.yudao.module.trade.enums.order.TradeOrderStatusEnum;
|
|
|
|
import org.springframework.context.annotation.Lazy;
|
|
import org.springframework.context.annotation.Lazy;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -30,13 +28,12 @@ import org.springframework.validation.annotation.Validated;
|
|
|
|
|
|
import javax.annotation.Nullable;
|
|
import javax.annotation.Nullable;
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
-import java.time.LocalDateTime;
|
|
|
|
-import java.util.Collection;
|
|
|
|
-import java.util.List;
|
|
|
|
-import java.util.Map;
|
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
|
|
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
|
|
|
|
+import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.afterNow;
|
|
|
|
+import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.beforeNow;
|
|
import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*;
|
|
import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*;
|
|
|
|
|
|
// TODO 芋艿:等拼团记录做完,完整 review 下
|
|
// TODO 芋艿:等拼团记录做完,完整 review 下
|
|
@@ -79,31 +76,6 @@ public class CombinationRecordServiceImpl implements CombinationRecordService {
|
|
recordMapper.updateById(record);
|
|
recordMapper.updateById(record);
|
|
}
|
|
}
|
|
|
|
|
|
- // TODO @芋艿:在详细预览下;
|
|
|
|
- @Override
|
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
|
- public void updateRecordStatusAndStartTimeByUserIdAndOrderId(Integer status, Long userId, Long orderId, LocalDateTime startTime) {
|
|
|
|
- CombinationRecordDO record = validateCombinationRecord(userId, orderId);
|
|
|
|
- // 更新状态
|
|
|
|
- record.setStatus(status);
|
|
|
|
- // 更新开始时间
|
|
|
|
- record.setStartTime(startTime);
|
|
|
|
- recordMapper.updateById(record);
|
|
|
|
-
|
|
|
|
- // 更新拼团参入人数
|
|
|
|
- List<CombinationRecordDO> records = recordMapper.selectListByHeadIdAndStatus(record.getHeadId(), status);
|
|
|
|
- if (CollUtil.isNotEmpty(records)) {
|
|
|
|
- records.forEach(item -> {
|
|
|
|
- item.setUserCount(records.size());
|
|
|
|
- // 校验拼团是否满足要求
|
|
|
|
- if (ObjectUtil.equal(records.size(), record.getUserSize())) {
|
|
|
|
- item.setStatus(CombinationRecordStatusEnum.SUCCESS.getStatus());
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- recordMapper.updateBatch(records);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
private CombinationRecordDO validateCombinationRecord(Long userId, Long orderId) {
|
|
private CombinationRecordDO validateCombinationRecord(Long userId, Long orderId) {
|
|
// 校验拼团是否存在
|
|
// 校验拼团是否存在
|
|
CombinationRecordDO recordDO = recordMapper.selectByUserIdAndOrderId(userId, orderId);
|
|
CombinationRecordDO recordDO = recordMapper.selectByUserIdAndOrderId(userId, orderId);
|
|
@@ -116,54 +88,76 @@ public class CombinationRecordServiceImpl implements CombinationRecordService {
|
|
// TODO @芋艿:在详细预览下;
|
|
// TODO @芋艿:在详细预览下;
|
|
@Override
|
|
@Override
|
|
public KeyValue<CombinationActivityDO, CombinationProductDO> validateCombinationRecord(
|
|
public KeyValue<CombinationActivityDO, CombinationProductDO> validateCombinationRecord(
|
|
- Long activityId, Long userId, Long skuId, Integer count) {
|
|
|
|
- // 1.1 校验拼团活动是否存在
|
|
|
|
|
|
+ Long userId, Long activityId, Long headId, Long skuId, Integer count) {
|
|
|
|
+ // 1 校验拼团活动是否存在
|
|
CombinationActivityDO activity = combinationActivityService.validateCombinationActivityExists(activityId);
|
|
CombinationActivityDO activity = combinationActivityService.validateCombinationActivityExists(activityId);
|
|
- // 1.2 校验活动是否开启
|
|
|
|
- if (ObjectUtil.equal(activity.getStatus(), CommonStatusEnum.DISABLE.getStatus())) {
|
|
|
|
|
|
+ // 1.1 校验活动是否开启
|
|
|
|
+ if (ObjUtil.equal(activity.getStatus(), CommonStatusEnum.DISABLE.getStatus())) {
|
|
throw exception(COMBINATION_ACTIVITY_STATUS_DISABLE);
|
|
throw exception(COMBINATION_ACTIVITY_STATUS_DISABLE);
|
|
}
|
|
}
|
|
- // 2 校验是否超出单次限购数量
|
|
|
|
|
|
+ // 1.2、校验活动开始时间
|
|
|
|
+ if (afterNow(activity.getStartTime())) {
|
|
|
|
+ throw exception(COMBINATION_RECORD_FAILED_TIME_NOT_START);
|
|
|
|
+ }
|
|
|
|
+ // 1.3 校验是否超出单次限购数量
|
|
if (count > activity.getSingleLimitCount()) {
|
|
if (count > activity.getSingleLimitCount()) {
|
|
throw exception(COMBINATION_RECORD_FAILED_SINGLE_LIMIT_COUNT_EXCEED);
|
|
throw exception(COMBINATION_RECORD_FAILED_SINGLE_LIMIT_COUNT_EXCEED);
|
|
}
|
|
}
|
|
- // 2.1、校验活动商品是否存在
|
|
|
|
|
|
+
|
|
|
|
+ // 2、父拼团是否存在,是否已经满了
|
|
|
|
+ if (headId != null) {
|
|
|
|
+ // 2.1、查询进行中的父拼团
|
|
|
|
+ CombinationRecordDO record = recordMapper.selectOneByHeadId(headId, CombinationRecordStatusEnum.IN_PROGRESS.getStatus());
|
|
|
|
+ if (record == null) {
|
|
|
|
+ throw exception(COMBINATION_RECORD_HEAD_NOT_EXISTS);
|
|
|
|
+ }
|
|
|
|
+ // 2.2、校验拼团是否满足要求
|
|
|
|
+ if (ObjUtil.equal(record.getUserCount(), record.getUserSize())) {
|
|
|
|
+ throw exception(COMBINATION_RECORD_USER_FULL);
|
|
|
|
+ }
|
|
|
|
+ // 2.3、校验拼团是否过期(有父拼团的时候只校验父拼团的过期时间)
|
|
|
|
+ if (beforeNow(record.getExpireTime())) {
|
|
|
|
+ throw exception(COMBINATION_RECORD_FAILED_TIME_END);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ // 3、校验当前活动是否结束(自己是父拼团的时候才校验活动是否结束)
|
|
|
|
+ if (beforeNow(activity.getEndTime())) {
|
|
|
|
+ throw exception(COMBINATION_RECORD_FAILED_TIME_END);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 4、校验活动商品是否存在
|
|
CombinationProductDO product = combinationActivityService.selectByActivityIdAndSkuId(activityId, skuId);
|
|
CombinationProductDO product = combinationActivityService.selectByActivityIdAndSkuId(activityId, skuId);
|
|
if (product == null) {
|
|
if (product == null) {
|
|
throw exception(COMBINATION_JOIN_ACTIVITY_PRODUCT_NOT_EXISTS);
|
|
throw exception(COMBINATION_JOIN_ACTIVITY_PRODUCT_NOT_EXISTS);
|
|
}
|
|
}
|
|
- // 2.2、校验 sku 是否存在
|
|
|
|
|
|
+
|
|
|
|
+ // 5、校验 sku 是否存在
|
|
ProductSkuRespDTO sku = productSkuApi.getSku(skuId);
|
|
ProductSkuRespDTO sku = productSkuApi.getSku(skuId);
|
|
if (sku == null) {
|
|
if (sku == null) {
|
|
throw exception(COMBINATION_JOIN_ACTIVITY_PRODUCT_NOT_EXISTS);
|
|
throw exception(COMBINATION_JOIN_ACTIVITY_PRODUCT_NOT_EXISTS);
|
|
}
|
|
}
|
|
- // 2.3、 校验库存是否充足
|
|
|
|
|
|
+ // 5.1、校验库存是否充足
|
|
if (count > sku.getStock()) {
|
|
if (count > sku.getStock()) {
|
|
throw exception(COMBINATION_ACTIVITY_UPDATE_STOCK_FAIL);
|
|
throw exception(COMBINATION_ACTIVITY_UPDATE_STOCK_FAIL);
|
|
}
|
|
}
|
|
- // 3、校验是否有拼团记录
|
|
|
|
|
|
+
|
|
|
|
+ // 6、校验是否有拼团记录
|
|
List<CombinationRecordDO> recordList = getCombinationRecordListByUserIdAndActivityId(userId, activityId);
|
|
List<CombinationRecordDO> recordList = getCombinationRecordListByUserIdAndActivityId(userId, activityId);
|
|
if (CollUtil.isEmpty(recordList)) {
|
|
if (CollUtil.isEmpty(recordList)) {
|
|
return new KeyValue<>(activity, product);
|
|
return new KeyValue<>(activity, product);
|
|
}
|
|
}
|
|
- // 4、校验是否超出总限购数量
|
|
|
|
|
|
+ // 6.1、校验用户是否有该活动正在进行的拼团
|
|
|
|
+ List<CombinationRecordDO> filtered = filterList(recordList, record -> CombinationRecordStatusEnum.isInProgress(record.getStatus()));
|
|
|
|
+ if (CollUtil.isNotEmpty(filtered)) {
|
|
|
|
+ throw exception(COMBINATION_RECORD_FAILED_HAVE_JOINED);
|
|
|
|
+ }
|
|
|
|
+ // 6.2、校验是否超出总限购数量
|
|
Integer sumValue = getSumValue(convertList(recordList, CombinationRecordDO::getCount,
|
|
Integer sumValue = getSumValue(convertList(recordList, CombinationRecordDO::getCount,
|
|
- item -> ObjectUtil.equals(item.getStatus(), CombinationRecordStatusEnum.SUCCESS.getStatus())), i -> i, Integer::sum);
|
|
|
|
|
|
+ item -> CombinationRecordStatusEnum.isSuccess(item.getStatus())), i -> i, Integer::sum);
|
|
if ((sumValue + count) > activity.getTotalLimitCount()) {
|
|
if ((sumValue + count) > activity.getTotalLimitCount()) {
|
|
throw exception(COMBINATION_RECORD_FAILED_TOTAL_LIMIT_COUNT_EXCEED);
|
|
throw exception(COMBINATION_RECORD_FAILED_TOTAL_LIMIT_COUNT_EXCEED);
|
|
}
|
|
}
|
|
- // 5、校验拼团记录是否存在未支付的订单(如果存在未支付的订单则不允许发起新的拼团)
|
|
|
|
- CombinationRecordDO record = findFirst(recordList, item -> ObjectUtil.equals(item.getStatus(), null));
|
|
|
|
- if (record == null) {
|
|
|
|
- return new KeyValue<>(activity, product);
|
|
|
|
- }
|
|
|
|
- // 5.1、查询关联的订单是否已经支付
|
|
|
|
- // 当前 activityId 已经有未支付的订单,不允许在发起新的;要么支付,要么去掉先;
|
|
|
|
- // TODO 芋艿:看看是不是可以删除掉;
|
|
|
|
- Integer orderStatus = tradeOrderApi.getOrderStatus(record.getOrderId());
|
|
|
|
- if (ObjectUtil.equal(orderStatus, TradeOrderStatusEnum.UNPAID.getStatus())) {
|
|
|
|
- throw exception(COMBINATION_RECORD_FAILED_ORDER_STATUS_UNPAID);
|
|
|
|
- }
|
|
|
|
|
|
|
|
return new KeyValue<>(activity, product);
|
|
return new KeyValue<>(activity, product);
|
|
}
|
|
}
|
|
@@ -173,47 +167,78 @@ public class CombinationRecordServiceImpl implements CombinationRecordService {
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
public void createCombinationRecord(CombinationRecordCreateReqDTO reqDTO) {
|
|
public void createCombinationRecord(CombinationRecordCreateReqDTO reqDTO) {
|
|
// 1、校验拼团活动
|
|
// 1、校验拼团活动
|
|
- KeyValue<CombinationActivityDO, CombinationProductDO> keyValue = validateCombinationRecord(
|
|
|
|
- reqDTO.getActivityId(), reqDTO.getUserId(), reqDTO.getSkuId(), reqDTO.getCount());
|
|
|
|
- CombinationActivityDO activity = keyValue.getKey();
|
|
|
|
- // 2、校验用户是否参加了其它拼团
|
|
|
|
- List<CombinationRecordDO> recordDOList = recordMapper.selectListByUserIdAndStatus(reqDTO.getUserId(), CombinationRecordStatusEnum.IN_PROGRESS.getStatus());
|
|
|
|
- if (CollUtil.isNotEmpty(recordDOList)) {
|
|
|
|
- throw exception(COMBINATION_RECORD_FAILED_HAVE_JOINED);
|
|
|
|
- }
|
|
|
|
- // 3、校验活动是否开启
|
|
|
|
- if (!LocalDateTimeUtils.beforeNow(activity.getStartTime())) {
|
|
|
|
- throw exception(COMBINATION_RECORD_FAILED_TIME_NOT_START);
|
|
|
|
- }
|
|
|
|
- // 4、校验当前活动是否过期
|
|
|
|
- if (LocalDateTime.now().isAfter(activity.getEndTime())) {
|
|
|
|
- throw exception(COMBINATION_RECORD_FAILED_TIME_END);
|
|
|
|
- }
|
|
|
|
- // 5、父拼团是否存在,是否已经满了
|
|
|
|
- if (reqDTO.getHeadId() != null) {
|
|
|
|
- // 5.1、查询进行中的父拼团
|
|
|
|
- CombinationRecordDO record = recordMapper.selectOneByHeadId(reqDTO.getHeadId(), CombinationRecordStatusEnum.IN_PROGRESS.getStatus());
|
|
|
|
- if (record == null) {
|
|
|
|
- throw exception(COMBINATION_RECORD_HEAD_NOT_EXISTS);
|
|
|
|
- }
|
|
|
|
- // 5.2、校验拼团是否满足要求
|
|
|
|
- if (ObjectUtil.equal(record.getUserCount(), record.getUserSize())) {
|
|
|
|
- throw exception(COMBINATION_RECORD_USER_FULL);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ KeyValue<CombinationActivityDO, CombinationProductDO> keyValue = validateCombinationRecord(reqDTO.getUserId(),
|
|
|
|
+ reqDTO.getActivityId(), reqDTO.getHeadId(), reqDTO.getSkuId(), reqDTO.getCount());
|
|
|
|
|
|
- // 6. 创建拼团记录
|
|
|
|
|
|
+ // 2. 组合数据创建拼团记录
|
|
MemberUserRespDTO user = memberUserApi.getUser(reqDTO.getUserId());
|
|
MemberUserRespDTO user = memberUserApi.getUser(reqDTO.getUserId());
|
|
ProductSpuRespDTO spu = productSpuApi.getSpu(reqDTO.getSpuId());
|
|
ProductSpuRespDTO spu = productSpuApi.getSpu(reqDTO.getSpuId());
|
|
ProductSkuRespDTO sku = productSkuApi.getSku(reqDTO.getSkuId());
|
|
ProductSkuRespDTO sku = productSkuApi.getSku(reqDTO.getSkuId());
|
|
- // TODO @puhui999:status 未设置;headId 未设置
|
|
|
|
- recordMapper.insert(CombinationActivityConvert.INSTANCE.convert(reqDTO, activity, user, spu, sku));
|
|
|
|
|
|
+ CombinationRecordDO recordDO = CombinationActivityConvert.INSTANCE.convert(reqDTO, keyValue.getKey(), user, spu, sku);
|
|
|
|
+ recordMapper.insert(recordDO);
|
|
|
|
+
|
|
|
|
+ // 3、如果是团长需要设置 headId 为 CombinationRecordDO#HEAD_ID_GROUP
|
|
|
|
+ if (ObjUtil.equal(CombinationRecordDO.HEAD_ID_GROUP, reqDTO.getHeadId())) {
|
|
|
|
+ recordMapper.updateById(new CombinationRecordDO().setId(recordDO.getId()).setHeadId(CombinationRecordDO.HEAD_ID_GROUP));
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // TODO 这里要不要弄成异步的
|
|
|
|
+ // 4、更新拼团相关信息到订单
|
|
|
|
+ updateOrderCombinationInfo(recordDO.getOrderId(), recordDO.getActivityId(), recordDO.getId(), recordDO.getHeadId());
|
|
|
|
+ // 4、更新拼团记录
|
|
|
|
+ updateCombinationRecords(keyValue.getKey(), reqDTO.getHeadId());
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 更新拼团相关信息到订单
|
|
|
|
+ *
|
|
|
|
+ * @param orderId 订单编号
|
|
|
|
+ * @param activityId 拼团活动编号
|
|
|
|
+ * @param combinationRecordId 拼团记录编号
|
|
|
|
+ * @param headId 团长编号
|
|
|
|
+ */
|
|
|
|
+ private void updateOrderCombinationInfo(Long orderId, Long activityId, Long combinationRecordId, Long headId) {
|
|
|
|
+ tradeOrderApi.updateOrderCombinationInfo(orderId, activityId, combinationRecordId, headId);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 更新拼团记录
|
|
|
|
+ *
|
|
|
|
+ * @param activity 活动
|
|
|
|
+ * @param headId 团长编号
|
|
|
|
+ */
|
|
|
|
+ private void updateCombinationRecords(CombinationActivityDO activity, Long headId) {
|
|
|
|
+ // 团长
|
|
|
|
+ CombinationRecordDO recordHead = recordMapper.selectById(headId);
|
|
|
|
+ // 团员
|
|
|
|
+ List<CombinationRecordDO> records = getCombinationRecordListByHeadId(headId);
|
|
|
|
+ // 需要更新的记录
|
|
|
|
+ List<CombinationRecordDO> updateRecords = new ArrayList<>();
|
|
|
|
+
|
|
|
|
+ if (CollUtil.isEmpty(records)) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ records.add(recordHead); // 加入团长,团长也需要更新
|
|
|
|
+ boolean isEqual = ObjUtil.equal(records.size(), activity.getUserSize());
|
|
|
|
+ records.forEach(item -> {
|
|
|
|
+ CombinationRecordDO recordDO = new CombinationRecordDO();
|
|
|
|
+ recordDO.setId(item.getId());
|
|
|
|
+ recordDO.setUserCount(records.size());
|
|
|
|
+ // 校验拼团是否满足要求
|
|
|
|
+ if (isEqual) {
|
|
|
|
+ recordDO.setStatus(CombinationRecordStatusEnum.SUCCESS.getStatus());
|
|
|
|
+ }
|
|
|
|
+ updateRecords.add(recordDO);
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ recordMapper.updateBatch(updateRecords);
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public CombinationRecordDO getCombinationRecord(Long userId, Long orderId) {
|
|
public CombinationRecordDO getCombinationRecord(Long userId, Long orderId) {
|
|
- // TODO puhui999:这里直接获得,不适合调用校验的接口;
|
|
|
|
- return validateCombinationRecord(userId, orderId);
|
|
|
|
|
|
+ return recordMapper.selectByUserIdAndOrderId(userId, orderId);
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -222,8 +247,8 @@ public class CombinationRecordServiceImpl implements CombinationRecordService {
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public CombinationValidateJoinRespDTO validateJoinCombination(Long activityId, Long userId, Long skuId, Integer count) {
|
|
|
|
- KeyValue<CombinationActivityDO, CombinationProductDO> keyValue = validateCombinationRecord(activityId, userId, skuId, count);
|
|
|
|
|
|
+ public CombinationValidateJoinRespDTO validateJoinCombination(Long userId, Long activityId, Long headId, Long skuId, Integer count) {
|
|
|
|
+ KeyValue<CombinationActivityDO, CombinationProductDO> keyValue = validateCombinationRecord(userId, activityId, headId, skuId, count);
|
|
return new CombinationValidateJoinRespDTO()
|
|
return new CombinationValidateJoinRespDTO()
|
|
.setActivityId(keyValue.getKey().getId())
|
|
.setActivityId(keyValue.getKey().getId())
|
|
.setName(keyValue.getKey().getName())
|
|
.setName(keyValue.getKey().getName())
|
|
@@ -282,4 +307,59 @@ public class CombinationRecordServiceImpl implements CombinationRecordService {
|
|
return recordMapper.selectCombinationRecordCountMapByActivityIdAndStatusAndHeadId(activityIds, status, headId);
|
|
return recordMapper.selectCombinationRecordCountMapByActivityIdAndStatusAndHeadId(activityIds, status, headId);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public CombinationRecordDO getCombinationRecordByIdAndUser(Long userId, Long id) {
|
|
|
|
+ return recordMapper.selectOne(CombinationRecordDO::getUserId, userId, CombinationRecordDO::getId, id);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
+ public void cancelCombinationRecord(Long userId, Long id, Long headId) {
|
|
|
|
+ // 删除记录
|
|
|
|
+ recordMapper.deleteById(id);
|
|
|
|
+
|
|
|
|
+ // 需要更新的记录
|
|
|
|
+ List<CombinationRecordDO> updateRecords = new ArrayList<>();
|
|
|
|
+ // 如果它是团长,则顺序(下单时间)继承
|
|
|
|
+ if (Objects.equals(headId, CombinationRecordDO.HEAD_ID_GROUP)) { // 情况一:团长
|
|
|
|
+ // 团员
|
|
|
|
+ List<CombinationRecordDO> list = getCombinationRecordListByHeadId(id);
|
|
|
|
+ if (CollUtil.isEmpty(list)) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ // 按照创建时间升序排序
|
|
|
|
+ List<CombinationRecordDO> recordsSort = sortedAsc(list, CombinationRecordDO::getCreateTime);
|
|
|
|
+ CombinationRecordDO newHead = recordsSort.get(0); // 新团长继位
|
|
|
|
+ recordsSort.forEach(item -> {
|
|
|
|
+ CombinationRecordDO recordDO = new CombinationRecordDO();
|
|
|
|
+ recordDO.setId(item.getId());
|
|
|
|
+ if (ObjUtil.equal(item.getId(), newHead.getId())) { // 新团长
|
|
|
|
+ recordDO.setHeadId(CombinationRecordDO.HEAD_ID_GROUP);
|
|
|
|
+ } else {
|
|
|
|
+ recordDO.setHeadId(newHead.getId());
|
|
|
|
+ }
|
|
|
|
+ recordDO.setUserCount(recordsSort.size());
|
|
|
|
+ updateRecords.add(recordDO);
|
|
|
|
+ });
|
|
|
|
+ } else { // 情况二:团员
|
|
|
|
+ // 团长
|
|
|
|
+ CombinationRecordDO recordHead = recordMapper.selectById(headId);
|
|
|
|
+ // 团员
|
|
|
|
+ List<CombinationRecordDO> records = getCombinationRecordListByHeadId(headId);
|
|
|
|
+ if (CollUtil.isEmpty(records)) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ records.add(recordHead); // 加入团长,团长数据也需要更新
|
|
|
|
+ records.forEach(item -> {
|
|
|
|
+ CombinationRecordDO recordDO = new CombinationRecordDO();
|
|
|
|
+ recordDO.setId(item.getId());
|
|
|
|
+ recordDO.setUserCount(records.size());
|
|
|
|
+ updateRecords.add(recordDO);
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 更新拼团记录
|
|
|
|
+ recordMapper.updateBatch(updateRecords);
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|