mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-22 15:21:53 +08:00
拼团活动: 完善 review 提到的问题
This commit is contained in:
parent
2e207019b3
commit
a4613f0af9
@ -1,7 +1,7 @@
|
||||
package cn.iocoder.yudao.module.promotion.api.combination;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.core.KeyValue;
|
||||
import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCreateReqDTO;
|
||||
import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCreateRespDTO;
|
||||
import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationValidateJoinRespDTO;
|
||||
|
||||
import javax.validation.Valid;
|
||||
@ -28,9 +28,9 @@ public interface CombinationRecordApi {
|
||||
* 创建开团记录
|
||||
*
|
||||
* @param reqDTO 请求 DTO
|
||||
* @return key 开团记录编号、value 团长编号
|
||||
* @return 团信息
|
||||
*/
|
||||
KeyValue<Long, Long> createCombinationRecord(@Valid CombinationRecordCreateReqDTO reqDTO);
|
||||
CombinationRecordCreateRespDTO createCombinationRecord(@Valid CombinationRecordCreateReqDTO reqDTO);
|
||||
|
||||
/**
|
||||
* 查询拼团记录是否成功
|
||||
|
@ -0,0 +1,32 @@
|
||||
package cn.iocoder.yudao.module.promotion.api.combination.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 拼团记录的创建 Response DTO
|
||||
*
|
||||
* @author HUIHUI
|
||||
*/
|
||||
@Data
|
||||
public class CombinationRecordCreateRespDTO {
|
||||
|
||||
/**
|
||||
* 拼团活动编号
|
||||
*
|
||||
* 关联 CombinationActivityDO 的 id 字段
|
||||
*/
|
||||
private Long combinationActivityId;
|
||||
/**
|
||||
* 拼团团长编号
|
||||
*
|
||||
* 关联 CombinationRecordDO 的 headId 字段
|
||||
*/
|
||||
private Long combinationHeadId;
|
||||
/**
|
||||
* 拼团记录编号
|
||||
*
|
||||
* 关联 CombinationRecordDO 的 id 字段
|
||||
*/
|
||||
private Long combinationRecordId;
|
||||
|
||||
}
|
@ -1,8 +1,9 @@
|
||||
package cn.iocoder.yudao.module.promotion.api.combination;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.core.KeyValue;
|
||||
import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCreateReqDTO;
|
||||
import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCreateRespDTO;
|
||||
import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationValidateJoinRespDTO;
|
||||
import cn.iocoder.yudao.module.promotion.convert.combination.CombinationActivityConvert;
|
||||
import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationRecordDO;
|
||||
import cn.iocoder.yudao.module.promotion.enums.combination.CombinationRecordStatusEnum;
|
||||
import cn.iocoder.yudao.module.promotion.service.combination.CombinationRecordService;
|
||||
@ -29,10 +30,9 @@ public class CombinationRecordApiImpl implements CombinationRecordApi {
|
||||
recordService.validateCombinationRecord(userId, activityId, headId, skuId, count);
|
||||
}
|
||||
|
||||
// TODO @puhui999:搞个创建的 RespDTO 哈;
|
||||
@Override
|
||||
public KeyValue<Long, Long> createCombinationRecord(CombinationRecordCreateReqDTO reqDTO) {
|
||||
return recordService.createCombinationRecord(reqDTO);
|
||||
public CombinationRecordCreateRespDTO createCombinationRecord(CombinationRecordCreateReqDTO reqDTO) {
|
||||
return CombinationActivityConvert.INSTANCE.convert4(recordService.createCombinationRecord(reqDTO));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -3,11 +3,11 @@ package cn.iocoder.yudao.module.promotion.controller.admin.combination;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod.CombinationRecordPageItemRespVO;
|
||||
import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod.CombinationRecordReqPage2VO;
|
||||
import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod.CombinationRecordReqPageVO;
|
||||
import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod.CombinationRecordSummaryVO;
|
||||
import cn.iocoder.yudao.module.promotion.convert.combination.CombinationActivityConvert;
|
||||
import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationActivityDO;
|
||||
import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationProductDO;
|
||||
import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationRecordDO;
|
||||
import cn.iocoder.yudao.module.promotion.enums.combination.CombinationRecordStatusEnum;
|
||||
import cn.iocoder.yudao.module.promotion.service.combination.CombinationActivityService;
|
||||
@ -40,7 +40,6 @@ public class CombinationRecordController {
|
||||
@Lazy
|
||||
private CombinationRecordService combinationRecordService;
|
||||
|
||||
// TODO @puhui999:getBargainRecordPage 和 getBargainRecordPage 是不是可以合并;然后 CombinationRecordReqPageVO 加一个 headId;
|
||||
// 然后如果 headId 非空,并且第一页,单独多查询一条 head ;放到第 0 个位置;相当于说,第一页特殊一点;
|
||||
|
||||
@GetMapping("/page")
|
||||
@ -48,21 +47,12 @@ public class CombinationRecordController {
|
||||
@PreAuthorize("@ss.hasPermission('promotion:combination-record:query')")
|
||||
public CommonResult<PageResult<CombinationRecordPageItemRespVO>> getBargainRecordPage(@Valid CombinationRecordReqPageVO pageVO) {
|
||||
PageResult<CombinationRecordDO> recordPage = combinationRecordService.getCombinationRecordPage(pageVO);
|
||||
// 拼接数据
|
||||
List<CombinationActivityDO> activities = combinationActivityService.getCombinationActivityListByIds(
|
||||
convertSet(recordPage.getList(), CombinationRecordDO::getActivityId));
|
||||
// TODO @puhui999:商品没读取
|
||||
return success(CombinationActivityConvert.INSTANCE.convert(recordPage, activities));
|
||||
}
|
||||
|
||||
@GetMapping("/page-by-headId")
|
||||
@Operation(summary = "获得拼团记录分页")
|
||||
@PreAuthorize("@ss.hasPermission('promotion:combination-record:query')")
|
||||
public CommonResult<PageResult<CombinationRecordPageItemRespVO>> getBargainRecordPage(@Valid CombinationRecordReqPage2VO pageVO) {
|
||||
// 包含团长和团员的分页记录
|
||||
PageResult<CombinationRecordDO> recordPage = combinationRecordService.getCombinationRecordPage2(pageVO);
|
||||
List<CombinationActivityDO> activities = combinationActivityService.getCombinationActivityListByIds(
|
||||
List<CombinationProductDO> products = combinationActivityService.getCombinationProductListByActivityIds(
|
||||
convertSet(recordPage.getList(), CombinationRecordDO::getActivityId));
|
||||
return success(CombinationActivityConvert.INSTANCE.convert(recordPage, activities));
|
||||
return success(CombinationActivityConvert.INSTANCE.convert(recordPage, activities, products));
|
||||
}
|
||||
|
||||
@GetMapping("/get-summary")
|
||||
@ -70,7 +60,7 @@ public class CombinationRecordController {
|
||||
@PreAuthorize("@ss.hasPermission('promotion:combination-record:query')")
|
||||
public CommonResult<CombinationRecordSummaryVO> getCombinationRecordSummary() {
|
||||
CombinationRecordSummaryVO summaryVO = new CombinationRecordSummaryVO();
|
||||
summaryVO.setUserCount(combinationRecordService.getCombinationRecordCount(null, null, null)); // 获取拼团用户参与数量
|
||||
summaryVO.setUserCount(combinationRecordService.getCombinationUserCount()); // 获取拼团用户参与数量
|
||||
summaryVO.setSuccessCount(combinationRecordService.getCombinationRecordCount( // 获取成团记录
|
||||
CombinationRecordStatusEnum.SUCCESS.getStatus(), null, CombinationRecordDO.HEAD_ID_GROUP));
|
||||
summaryVO.setVirtualGroupCount(combinationRecordService.getCombinationRecordCount(// 获取虚拟成团记录
|
||||
|
@ -23,6 +23,9 @@ public class CombinationRecordReqPageVO extends PageParam {
|
||||
@InEnum(BargainRecordStatusEnum.class)
|
||||
private Integer status;
|
||||
|
||||
@Schema(description = "团长编号", example = "1024")
|
||||
private Long headId;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime[] createTime;
|
||||
|
@ -47,7 +47,7 @@ public class AppCombinationRecordController {
|
||||
public CommonResult<AppCombinationRecordSummaryRespVO> getCombinationRecordSummary() {
|
||||
AppCombinationRecordSummaryRespVO summary = new AppCombinationRecordSummaryRespVO();
|
||||
// 1. 获得拼团参与用户数量
|
||||
Long count = combinationRecordService.getCombinationRecordCount(null, null, null);
|
||||
Long count = combinationRecordService.getCombinationUserCount();
|
||||
if (count == 0) {
|
||||
summary.setAvatars(Collections.emptyList());
|
||||
summary.setUserCount(count);
|
||||
|
@ -8,6 +8,7 @@ import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
|
||||
import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO;
|
||||
import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO;
|
||||
import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCreateReqDTO;
|
||||
import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCreateRespDTO;
|
||||
import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityCreateReqVO;
|
||||
import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityPageItemRespVO;
|
||||
import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityRespVO;
|
||||
@ -109,6 +110,11 @@ public interface CombinationActivityConvert {
|
||||
|
||||
CombinationRecordDO convert(CombinationRecordCreateReqDTO reqDTO);
|
||||
|
||||
default CombinationRecordCreateRespDTO convert4(CombinationRecordDO combinationRecord) {
|
||||
return new CombinationRecordCreateRespDTO().setCombinationActivityId(combinationRecord.getActivityId())
|
||||
.setCombinationRecordId(combinationRecord.getId()).setCombinationHeadId(combinationRecord.getHeadId());
|
||||
}
|
||||
|
||||
default CombinationRecordDO convert(CombinationRecordCreateReqDTO reqDTO,
|
||||
CombinationActivityDO activity, MemberUserRespDTO user,
|
||||
ProductSpuRespDTO spu, ProductSkuRespDTO sku) {
|
||||
@ -172,12 +178,14 @@ public interface CombinationActivityConvert {
|
||||
|
||||
PageResult<CombinationRecordPageItemRespVO> convert(PageResult<CombinationRecordDO> result);
|
||||
|
||||
default PageResult<CombinationRecordPageItemRespVO> convert(PageResult<CombinationRecordDO> recordPage, List<CombinationActivityDO> activities) {
|
||||
default PageResult<CombinationRecordPageItemRespVO> convert(PageResult<CombinationRecordDO> recordPage, List<CombinationActivityDO> activities, List<CombinationProductDO> products) {
|
||||
PageResult<CombinationRecordPageItemRespVO> result = convert(recordPage);
|
||||
// 拼接关联属性
|
||||
Map<Long, CombinationActivityDO> activityMap = convertMap(activities, CombinationActivityDO::getId);
|
||||
Map<Long, List<CombinationProductDO>> productsMap = convertMultiMap(products, CombinationProductDO::getActivityId);
|
||||
result.setList(CollectionUtils.convertList(result.getList(), item -> {
|
||||
findAndThen(activityMap, item.getActivityId(), activity -> {
|
||||
item.setActivity(convert(activity));
|
||||
item.setActivity(convert(activity).setProducts(convertList2(productsMap.get(item.getActivityId()))));
|
||||
});
|
||||
return item;
|
||||
}));
|
||||
|
@ -86,7 +86,7 @@ public interface BargainActivityMapper extends BaseMapperX<BargainActivityDO> {
|
||||
.last("LIMIT " + count));
|
||||
}
|
||||
|
||||
// TODO @puhui999:是不是返回 BargainActivityDO 更干净哈?
|
||||
// TODO @puhui999:是不是返回 BargainActivityDO 更干净哈?分组后返回 DO 的话需要联表查询
|
||||
/**
|
||||
* 查询出指定 spuId 的 spu 参加的活动最接近现在的一条记录。多个的话,一个 spuId 对应一个最近的活动编号
|
||||
*
|
||||
|
@ -6,7 +6,6 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod.CombinationRecordReqPage2VO;
|
||||
import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod.CombinationRecordReqPageVO;
|
||||
import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationRecordDO;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
@ -97,21 +96,19 @@ public interface CombinationRecordMapper extends BaseMapperX<CombinationRecordDO
|
||||
}
|
||||
|
||||
default PageResult<CombinationRecordDO> selectPage(CombinationRecordReqPageVO pageVO) {
|
||||
return selectPage(pageVO, new LambdaQueryWrapperX<CombinationRecordDO>()
|
||||
LambdaQueryWrapperX<CombinationRecordDO> queryWrapper = new LambdaQueryWrapperX<CombinationRecordDO>()
|
||||
.eqIfPresent(CombinationRecordDO::getStatus, pageVO.getStatus())
|
||||
.betweenIfPresent(CombinationRecordDO::getCreateTime, pageVO.getCreateTime()));
|
||||
}
|
||||
|
||||
default PageResult<CombinationRecordDO> selectPage(CombinationRecordReqPage2VO pageVO) {
|
||||
return selectPage(pageVO, new LambdaQueryWrapperX<CombinationRecordDO>()
|
||||
.eq(CombinationRecordDO::getId, pageVO.getHeadId())
|
||||
.or()
|
||||
.eq(CombinationRecordDO::getHeadId, pageVO.getHeadId()));
|
||||
.betweenIfPresent(CombinationRecordDO::getCreateTime, pageVO.getCreateTime());
|
||||
if (pageVO.getHeadId() != null) {
|
||||
queryWrapper.eq(CombinationRecordDO::getId, pageVO.getHeadId())
|
||||
.or()
|
||||
.eq(CombinationRecordDO::getHeadId, pageVO.getHeadId());
|
||||
}
|
||||
return selectPage(pageVO, queryWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询指定条件的记录数
|
||||
* 如果参数都为 null 时则查询用户拼团记录(DISTINCT 去重),也就是说查询会员表中的用户有多少人参与过拼团活动每个人只统计一次
|
||||
*
|
||||
* @param status 状态,可为 null
|
||||
* @param virtualGroup 是否虚拟成团,可为 null
|
||||
@ -119,12 +116,20 @@ public interface CombinationRecordMapper extends BaseMapperX<CombinationRecordDO
|
||||
* @return 记录数
|
||||
*/
|
||||
default Long selectCountByHeadAndStatusAndVirtualGroup(Integer status, Boolean virtualGroup, Long headId) {
|
||||
return selectCount(new LambdaQueryWrapperX<CombinationRecordDO>()
|
||||
.eqIfPresent(CombinationRecordDO::getStatus, status)
|
||||
.eqIfPresent(CombinationRecordDO::getVirtualGroup, virtualGroup)
|
||||
.eqIfPresent(CombinationRecordDO::getHeadId, headId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询用户拼团记录(DISTINCT 去重),也就是说查询会员表中的用户有多少人参与过拼团活动每个人只统计一次
|
||||
*
|
||||
* @return 参加过拼团的用户数
|
||||
*/
|
||||
default Long selectUserDistinctCount() {
|
||||
return selectCount(new QueryWrapper<CombinationRecordDO>()
|
||||
// TODO @puhui999:这种偏逻辑性的,不要给 mapper 哈;可以考虑拆成 2 个 mapper,上层也是 2 个 service;
|
||||
.select(status == null && virtualGroup == null && headId == null, "DISTINCT (user_id)")
|
||||
.eq(status != null, "status", status)
|
||||
.eq(virtualGroup != null, "virtual_group", virtualGroup)
|
||||
.eq(headId != null, "head_id", headId)
|
||||
.select("DISTINCT (user_id)")
|
||||
.groupBy("user_id"));
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,6 @@ import cn.iocoder.yudao.framework.common.core.KeyValue;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCreateReqDTO;
|
||||
import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationValidateJoinRespDTO;
|
||||
import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod.CombinationRecordReqPage2VO;
|
||||
import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod.CombinationRecordReqPageVO;
|
||||
import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationActivityDO;
|
||||
import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationProductDO;
|
||||
@ -50,9 +49,9 @@ public interface CombinationRecordService {
|
||||
* 创建拼团记录
|
||||
*
|
||||
* @param reqDTO 创建信息
|
||||
* @return key 开团记录编号 value 团长编号
|
||||
* @return 团信息
|
||||
*/
|
||||
KeyValue<Long, Long> createCombinationRecord(CombinationRecordCreateReqDTO reqDTO);
|
||||
CombinationRecordDO createCombinationRecord(CombinationRecordCreateReqDTO reqDTO);
|
||||
|
||||
/**
|
||||
* 获得拼团记录
|
||||
@ -94,7 +93,14 @@ public interface CombinationRecordService {
|
||||
* @param headId 团长编号,允许空。目的 headId 设置为 {@link CombinationRecordDO#HEAD_ID_GROUP} 时,可以设置
|
||||
* @return 记录数
|
||||
*/
|
||||
Long getCombinationRecordCount(@Nullable Integer status, @Nullable Boolean virtualGroup, @Nullable Long headId);
|
||||
Long getCombinationRecordCount(@Nullable Integer status, @Nullable Boolean virtualGroup, Long headId);
|
||||
|
||||
/**
|
||||
* 查询用户拼团记录(DISTINCT 去重),也就是说查询会员表中的用户有多少人参与过拼团活动每个人只统计一次
|
||||
*
|
||||
* @return 参加过拼团的用户数
|
||||
*/
|
||||
Long getCombinationUserCount();
|
||||
|
||||
/**
|
||||
* 获取最近的 count 条拼团记录
|
||||
@ -138,14 +144,6 @@ public interface CombinationRecordService {
|
||||
*/
|
||||
PageResult<CombinationRecordDO> getCombinationRecordPage(CombinationRecordReqPageVO pageVO);
|
||||
|
||||
/**
|
||||
* 获取拼团记录分页数据(通过团长查询)
|
||||
*
|
||||
* @param pageVO 分页请求
|
||||
* @return 拼团记录分页数据(包括团长的)
|
||||
*/
|
||||
PageResult<CombinationRecordDO> getCombinationRecordPage2(CombinationRecordReqPage2VO pageVO);
|
||||
|
||||
/**
|
||||
* 【拼团活动】获得拼团记录数量 Map
|
||||
*
|
||||
|
@ -14,7 +14,6 @@ import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi;
|
||||
import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO;
|
||||
import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCreateReqDTO;
|
||||
import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationValidateJoinRespDTO;
|
||||
import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod.CombinationRecordReqPage2VO;
|
||||
import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod.CombinationRecordReqPageVO;
|
||||
import cn.iocoder.yudao.module.promotion.convert.combination.CombinationActivityConvert;
|
||||
import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationActivityDO;
|
||||
@ -23,7 +22,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.enums.combination.CombinationRecordStatusEnum;
|
||||
import cn.iocoder.yudao.module.trade.api.order.TradeOrderApi;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
@ -72,9 +70,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService {
|
||||
CombinationRecordDO record = validateCombinationRecord(userId, orderId);
|
||||
|
||||
// 更新状态
|
||||
// TODO @puhui999:不要整个更新,new 一个出来;why?例如说,两个线程都去更新,这样存在相互覆盖的问题
|
||||
record.setStatus(status);
|
||||
combinationRecordMapper.updateById(record);
|
||||
combinationRecordMapper.updateById(new CombinationRecordDO().setId(record.getId()).setStatus(status));
|
||||
}
|
||||
|
||||
private CombinationRecordDO validateCombinationRecord(Long userId, Long orderId) {
|
||||
@ -164,7 +160,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService {
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public KeyValue<Long, Long> createCombinationRecord(CombinationRecordCreateReqDTO reqDTO) {
|
||||
public CombinationRecordDO createCombinationRecord(CombinationRecordCreateReqDTO reqDTO) {
|
||||
// 1. 校验拼团活动
|
||||
KeyValue<CombinationActivityDO, CombinationProductDO> keyValue = validateCombinationRecord(reqDTO.getUserId(),
|
||||
reqDTO.getActivityId(), reqDTO.getHeadId(), reqDTO.getSkuId(), reqDTO.getCount());
|
||||
@ -191,7 +187,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService {
|
||||
if (ObjUtil.notEqual(CombinationRecordDO.HEAD_ID_GROUP, record.getHeadId())) {
|
||||
updateCombinationRecordWhenCreate(reqDTO.getHeadId(), keyValue.getKey());
|
||||
}
|
||||
return new KeyValue<>(record.getId(), record.getHeadId());
|
||||
return record;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -249,6 +245,11 @@ public class CombinationRecordServiceImpl implements CombinationRecordService {
|
||||
return combinationRecordMapper.selectCountByHeadAndStatusAndVirtualGroup(status, virtualGroup, headId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getCombinationUserCount() {
|
||||
return combinationRecordMapper.selectUserDistinctCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CombinationRecordDO> getLatestCombinationRecordList(int count) {
|
||||
return combinationRecordMapper.selectLatestList(count);
|
||||
@ -275,11 +276,6 @@ public class CombinationRecordServiceImpl implements CombinationRecordService {
|
||||
return combinationRecordMapper.selectPage(pageVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<CombinationRecordDO> getCombinationRecordPage2(CombinationRecordReqPage2VO pageVO) {
|
||||
return combinationRecordMapper.selectPage(pageVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Long, Integer> getCombinationRecordCountMapByActivity(Collection<Long> activityIds,
|
||||
@Nullable Integer status, @Nullable Long headId) {
|
||||
@ -343,32 +339,28 @@ public class CombinationRecordServiceImpl implements CombinationRecordService {
|
||||
|
||||
@Override
|
||||
public KeyValue<Integer, Integer> expireCombinationRecord() {
|
||||
// TODO @puhui999:数字一般是 1. 2. 这种格式哈
|
||||
// 1。获取所有正在进行中的过期的父拼团
|
||||
// 1.获取所有正在进行中的过期的父拼团
|
||||
List<CombinationRecordDO> headExpireRecords = combinationRecordMapper.selectListByHeadIdAndStatusAndExpireTimeLt(
|
||||
CombinationRecordDO.HEAD_ID_GROUP, CombinationRecordStatusEnum.IN_PROGRESS.getStatus(), LocalDateTime.now());
|
||||
if (CollUtil.isEmpty(headExpireRecords)) {
|
||||
return new KeyValue<>(0, 0);
|
||||
}
|
||||
|
||||
// 2. 获取拼团活动
|
||||
// TODO @puhui999:在自己模块里,变量可以简略点;例如说 activityList
|
||||
List<CombinationActivityDO> combinationActivities = combinationActivityService.getCombinationActivityListByIds(
|
||||
// 2.获取拼团活动
|
||||
List<CombinationActivityDO> activities = combinationActivityService.getCombinationActivityListByIds(
|
||||
convertSet(headExpireRecords, CombinationRecordDO::getActivityId));
|
||||
Map<Long, CombinationActivityDO> activityMap = convertMap(combinationActivities, CombinationActivityDO::getId);
|
||||
Map<Long, CombinationActivityDO> activityMap = convertMap(activities, CombinationActivityDO::getId);
|
||||
|
||||
// TODO @puhui999:job 一般不建议异步跑;因为可能下次跑,结果上次还没跑完;
|
||||
// TODO 这里,我们可以每个 record 处理下;然后按照是否需要虚拟拼团,各搞一个方法逻辑 + 事务;这样,保证 job 里面尽量不要大事务,而是 n 个独立小事务的处理。
|
||||
// 3. 校验是否虚拟成团
|
||||
// 3.校验是否虚拟成团
|
||||
List<CombinationRecordDO> virtualGroupHeadRecords = new ArrayList<>(); // 虚拟成团
|
||||
for (Iterator<CombinationRecordDO> iterator = headExpireRecords.iterator(); iterator.hasNext(); ) {
|
||||
CombinationRecordDO record = iterator.next();
|
||||
// 3.1 不匹配,则直接跳过
|
||||
// 3.1.不匹配,则直接跳过
|
||||
CombinationActivityDO activity = activityMap.get(record.getActivityId());
|
||||
if (activity == null || !activity.getVirtualGroup()) { // 取不到活动的或者不是虚拟拼团的
|
||||
continue;
|
||||
}
|
||||
// 3.2 匹配,则移除,添加到虚拟成团中,并结束寻找
|
||||
// 3.2.匹配,则移除,添加到虚拟成团中,并结束寻找
|
||||
virtualGroupHeadRecords.add(record);
|
||||
iterator.remove();
|
||||
break;
|
||||
@ -381,8 +373,13 @@ public class CombinationRecordServiceImpl implements CombinationRecordService {
|
||||
return new KeyValue<>(headExpireRecords.size(), virtualGroupHeadRecords.size());
|
||||
}
|
||||
|
||||
@Async
|
||||
protected void handleExpireRecord(List<CombinationRecordDO> headExpireRecords) {
|
||||
/**
|
||||
* 处理过期拼团
|
||||
*
|
||||
* @param headExpireRecords 过期拼团团长记录列表
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void handleExpireRecord(List<CombinationRecordDO> headExpireRecords) {
|
||||
if (CollUtil.isEmpty(headExpireRecords)) {
|
||||
return;
|
||||
}
|
||||
@ -400,8 +397,13 @@ public class CombinationRecordServiceImpl implements CombinationRecordService {
|
||||
});
|
||||
}
|
||||
|
||||
@Async
|
||||
protected void handleVirtualGroupRecord(List<CombinationRecordDO> virtualGroupHeadRecords) {
|
||||
/**
|
||||
* 处理虚拟拼团
|
||||
*
|
||||
* @param virtualGroupHeadRecords 虚拟成团团长记录列表
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void handleVirtualGroupRecord(List<CombinationRecordDO> virtualGroupHeadRecords) {
|
||||
if (CollUtil.isEmpty(virtualGroupHeadRecords)) {
|
||||
return;
|
||||
}
|
||||
|
@ -93,16 +93,19 @@ public interface TradeOrderMapper extends BaseMapperX<TradeOrderDO> {
|
||||
return selectOne(TradeOrderDO::getPickUpVerifyCode, pickUpVerifyCode);
|
||||
}
|
||||
|
||||
// TODO @hui999:是不是只针对 combinationActivityId 的查询呀?
|
||||
/**
|
||||
* 只针对 combinationActivityId 的查询
|
||||
*
|
||||
* @param userId 用户编号
|
||||
* @param activityId 拼团活动编号
|
||||
* @param status 订单状态
|
||||
* @return 交易订单
|
||||
*/
|
||||
default TradeOrderDO selectByUserIdAndActivityIdAndStatus(Long userId, Long activityId, Integer status) {
|
||||
return selectOne(new LambdaQueryWrapperX<TradeOrderDO>()
|
||||
.and(q -> q.eq(TradeOrderDO::getUserId, userId)
|
||||
.eq(TradeOrderDO::getStatus, status))
|
||||
.and(q -> q.eq(TradeOrderDO::getCombinationActivityId, activityId)
|
||||
.or()
|
||||
.eq(TradeOrderDO::getSeckillActivityId, activityId)
|
||||
.or()
|
||||
.eq(TradeOrderDO::getBargainActivityId, activityId))
|
||||
.eq(TradeOrderDO::getUserId, userId)
|
||||
.eq(TradeOrderDO::getStatus, status)
|
||||
.eq(TradeOrderDO::getCombinationActivityId, activityId)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
package cn.iocoder.yudao.module.trade.service.order.handler;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.iocoder.yudao.framework.common.core.KeyValue;
|
||||
import cn.iocoder.yudao.module.promotion.api.combination.CombinationRecordApi;
|
||||
import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCreateRespDTO;
|
||||
import cn.iocoder.yudao.module.trade.convert.order.TradeOrderConvert;
|
||||
import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO;
|
||||
import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO;
|
||||
@ -49,7 +49,6 @@ public class TradeCombinationOrderHandler implements TradeOrderHandler {
|
||||
order.getCombinationHeadId(), item.getSkuId(), item.getCount());
|
||||
|
||||
// 2. 校验该用户是否存在未支付的拼团活动订单,避免一个拼团可以下多个单子了
|
||||
// TODO @puhui999:只校验未支付的拼团订单噢
|
||||
TradeOrderDO activityOrder = orderQueryService.getActivityOrderByUserIdAndActivityIdAndStatus(
|
||||
order.getUserId(), order.getCombinationActivityId(), TradeOrderStatusEnum.UNPAID.getStatus());
|
||||
if (activityOrder != null) {
|
||||
@ -67,13 +66,14 @@ public class TradeCombinationOrderHandler implements TradeOrderHandler {
|
||||
|
||||
// 2. 创建拼团记录
|
||||
TradeOrderItemDO item = orderItems.get(0);
|
||||
KeyValue<Long, Long> recordIdAndHeadId = combinationRecordApi.createCombinationRecord(
|
||||
CombinationRecordCreateRespDTO combinationRecord = combinationRecordApi.createCombinationRecord(
|
||||
TradeOrderConvert.INSTANCE.convert(order, item));
|
||||
|
||||
// 3. 更新拼团相关信息到订单
|
||||
// TODO 芋艿,只需要更新 record
|
||||
// TODO 芋艿,只需要更新 record。 如果创建订单时自己是团长的情况下 combinationHeadId 是为 null 的,
|
||||
// 设置团长编号这个操作时在订单是否后创建拼团记录时才设置的,所以支付完创建拼团记录后需要设置一下记录编号和团长编号
|
||||
orderUpdateService.updateOrderCombinationInfo(order.getId(), order.getCombinationActivityId(),
|
||||
recordIdAndHeadId.getKey(), recordIdAndHeadId.getValue());
|
||||
combinationRecord.getCombinationRecordId(), combinationRecord.getCombinationHeadId());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user