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

Merge pull request !656 from puhui999/feature/mall_product
This commit is contained in:
芋道源码 2023-10-08 12:06:35 +00:00 committed by Gitee
commit 781ec1028f
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
30 changed files with 345 additions and 214 deletions

View File

@ -25,15 +25,6 @@ public class CollectionUtils {
return Arrays.stream(collections).anyMatch(CollectionUtil::isEmpty);
}
// TODO @puhui999 list.sort(); 可以替代呀
public static <T, U extends Comparable<? super U>> List<T> sortedAsc(
Collection<T> from, Function<? super T, ? extends U> keyExtractor) {
// 按照升序排序
return from.stream()
.sorted(Comparator.comparing(keyExtractor))
.collect(Collectors.toList());
}
public static <T> boolean anyMatch(Collection<T> from, Predicate<T> predicate) {
return from.stream().anyMatch(predicate);
}

View File

@ -29,8 +29,9 @@ public interface CombinationRecordApi {
* 创建开团记录
*
* @param reqDTO 请求 DTO
* @return 开团记录编号
*/
void createCombinationRecord(@Valid CombinationRecordCreateReqDTO reqDTO);
Long createCombinationRecord(@Valid CombinationRecordCreateReqDTO reqDTO);
/**
* 查询拼团记录是否成功

View File

@ -46,7 +46,6 @@ public class CombinationRecordCreateReqDTO {
/**
* 团长编号
*/
@NotNull(message = "团长编号不能为空")
private Long headId;
/**
* 拼团商品单价

View File

@ -29,8 +29,8 @@ public class CombinationRecordApiImpl implements CombinationRecordApi {
}
@Override
public void createCombinationRecord(CombinationRecordCreateReqDTO reqDTO) {
recordService.createCombinationRecord(reqDTO);
public Long createCombinationRecord(CombinationRecordCreateReqDTO reqDTO) {
return recordService.createCombinationRecord(reqDTO);
}
@Override

View File

@ -1,16 +1,19 @@
package cn.iocoder.yudao.module.promotion.controller.admin.combination;
import cn.hutool.core.map.MapUtil;
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.CombinationRecordReqPageVO;
import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod.CombinationRecordRespVO;
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.CombinationRecordDO;
import cn.iocoder.yudao.module.promotion.enums.combination.CombinationRecordStatusEnum;
import cn.iocoder.yudao.module.promotion.service.combination.CombinationActivityService;
import cn.iocoder.yudao.module.promotion.service.combination.CombinationRecordService;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.context.annotation.Lazy;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
@ -19,11 +22,10 @@ import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.time.Duration;
import java.util.Map;
import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.cache.CacheUtils.buildAsyncReloadingCache;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
@Tag(name = "管理后台 - 拼团记录")
@RestController
@ -32,44 +34,31 @@ import static cn.iocoder.yudao.framework.common.util.cache.CacheUtils.buildAsync
public class CombinationRecordController {
@Resource
private CombinationActivityService combinationActivityService;
@Resource
@Lazy
private CombinationRecordService combinationRecordService;
// TODO @puhui999:这个缓存不用做哈主要管理后台对性能要求不高不像前段
/**
* {@link Map} 缓存通过它异步刷新 {@link #getCombinationRecordSummary0()} 所要的拼团记录统计数据
*/
private final LoadingCache<String, Map<String, Long>> combinationRecordSummary = buildAsyncReloadingCache(Duration.ofSeconds(60L),
new CacheLoader<String, Map<String, Long>>() {
@Override
public Map<String, Long> load(String key) {
return getCombinationRecordSummary0();
}
});
@GetMapping("/page")
@Operation(summary = "获得拼团记录分页")
@PreAuthorize("@ss.hasPermission('promotion:combination-record:query')")
public CommonResult<PageResult<CombinationRecordRespVO>> getBargainRecordPage(@Valid CombinationRecordReqPageVO pageVO) {
return success(CombinationActivityConvert.INSTANCE.convert(
combinationRecordService.getCombinationRecordPage(pageVO)));
public CommonResult<PageResult<CombinationRecordPageItemRespVO>> getBargainRecordPage(@Valid CombinationRecordReqPageVO pageVO) {
PageResult<CombinationRecordDO> recordPage = combinationRecordService.getCombinationRecordPage(pageVO);
List<CombinationActivityDO> activities = combinationActivityService.getCombinationActivityListByIds(
convertSet(recordPage.getList(), CombinationRecordDO::getActivityId));
return success(CombinationActivityConvert.INSTANCE.convert(recordPage, activities));
}
// TODO @puhui999Map 改成对象尽量避免 Map 返回结果哈然后 getCombinationRecordCountgetCombinationRecordsSuccessCountgetRecordsVirtualGroupCount 三个方法可以合并成一个方法哈返回这个 vo
@GetMapping("/get-summary")
@Operation(summary = "获得拼团记录的概要信息", description = "用于拼团记录页面展示")
@PreAuthorize("@ss.hasPermission('promotion:combination-record:query')")
public CommonResult<Map<String, Long>> getCombinationRecordSummary() {
return success(combinationRecordSummary.getUnchecked("")); // 缓存
}
private Map<String, Long> getCombinationRecordSummary0() {
Map<String, Long> hashMap = MapUtil.newHashMap(3); // TODO @puhui999Maps.newHashMapWithExpectedSize()
hashMap.put("userCount", combinationRecordService.getCombinationRecordCount()); // 获取所有拼团记录
hashMap.put("successCount", combinationRecordService.getCombinationRecordsSuccessCount()); // 获取成团记录
hashMap.put("virtualGroupCount", combinationRecordService.getRecordsVirtualGroupCount()); // 获取虚拟成团记录
return hashMap;
public CommonResult<CombinationRecordSummaryVO> getCombinationRecordSummary() {
CombinationRecordSummaryVO summaryVO = new CombinationRecordSummaryVO();
summaryVO.setUserCount(combinationRecordService.getCombinationRecordCount(null, null)); // 获取所有拼团记录
summaryVO.setSuccessCount(combinationRecordService.getCombinationRecordCount(
CombinationRecordStatusEnum.SUCCESS.getStatus(), null));// 获取成团记录
summaryVO.setVirtualGroupCount(combinationRecordService.getCombinationRecordCount(null, Boolean.TRUE));// 获取虚拟成团记录
return success(summaryVO);
}
}

View File

@ -4,14 +4,19 @@ import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
// TODO @puhui999可以参考 BargainRecordPageItemRespVOBargainRecordRespVO 分成两个一个给记录列表一个给记录分页
@Schema(description = "管理后台 - 拼团记录 Response VO")
/**
* 拼团记录 Base VO提供给添加修改详细的子 VO 使用
* 如果子 VO 存在差异的字段请不要添加到这里影响 Swagger 文档生成
*
* @author HUIHUI
*/
@Data
public class CombinationRecordRespVO {
public class CombinationRecordBaseVO {
@Schema(description = "拼团记录编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Long id;
@ -19,15 +24,37 @@ public class CombinationRecordRespVO {
@Schema(description = "拼团活动编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Long activityId;
@Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "花开富贵")
private String nickname;
@Schema(description = "用户头像", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/1.png")
private String avatar;
@Schema(description = "团长编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Long headId;
// ========== 用户相关 ==========
@Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "9430")
@NotNull(message = "用户编号不能为空")
private Long userId;
@Schema(description = "用户昵称", example = "老芋艿")
private String nickname;
@Schema(description = "用户头像", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/xxx.jpg")
private String avatar;
// ========== 商品相关 ==========
@Schema(description = "商品 SPU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "23622")
@NotNull(message = "商品 SPU 编号不能为空")
private Long spuId;
@Schema(description = "商品 SKU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "29950")
@NotNull(message = "商品 SKU 编号不能为空")
private Long skuId;
@Schema(description = "商品名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "我是大黄豆")
private String spuName;
@Schema(description = "商品图片", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/1.png")
private String picUrl;
@Schema(description = "过期时间", requiredMode = Schema.RequiredMode.REQUIRED)
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime expireTime;
@ -41,12 +68,6 @@ public class CombinationRecordRespVO {
@Schema(description = "拼团状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Integer status;
@Schema(description = "商品名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "我是大黄豆")
private String spuName;
@Schema(description = "商品图片", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/1.png")
private String picUrl;
@Schema(description = "是否虚拟成团", requiredMode = Schema.RequiredMode.REQUIRED, example = "false")
private Boolean virtualGroup;

View File

@ -0,0 +1,19 @@
package cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod;
import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityRespVO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
@Schema(description = "管理后台 - 拼团记录的分页项 Response VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class CombinationRecordPageItemRespVO extends CombinationRecordBaseVO {
// ========== 活动相关 ==========
private CombinationActivityRespVO activity;
}

View File

@ -0,0 +1,19 @@
package cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Schema(description = "管理后台 - 拼团记录信息统计 Response VO")
@Data
public class CombinationRecordSummaryVO {
@Schema(description = "所有拼团记录", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Long userCount;
@Schema(description = "成团记录", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Long successCount;
@Schema(description = "虚拟成团记录", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Long virtualGroupCount;
}

View File

@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.promotion.controller.app.activity;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.map.MapUtil;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.promotion.controller.app.activity.vo.AppActivityRespVO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainActivityDO;
@ -21,12 +22,10 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMultiMap;
@Tag(name = "用户 APP - 营销活动") // 用于提供跨多个活动的 HTTP 接口
@RestController
@ -42,59 +41,72 @@ public class AppActivityController {
private BargainActivityService bargainActivityService;
@GetMapping("/list-by-spu-id")
@Operation(summary = "获得单个商品,近期参与的每个活动") // 每种活动只返回一个
@Operation(summary = "获得单个商品,近期参与的每个活动")
@Parameter(name = "spuId", description = "商品编号", required = true)
public CommonResult<List<AppActivityRespVO>> getActivityListBySpuId(@RequestParam("spuId") Long spuId) {
return success(getAppActivityRespVOList(spuId));
// 每种活动只返回一个
return success(getAppActivityRespVOList(Collections.singletonList(spuId)));
}
@GetMapping("/list-by-spu-ids")
@Operation(summary = "获得多个商品,近期参与的每个活动") // 每种活动只返回一个key SPU 编号
@Operation(summary = "获得多个商品,近期参与的每个活动")
@Parameter(name = "spuIds", description = "商品编号数组", required = true)
public CommonResult<Map<Long, List<AppActivityRespVO>>> getActivityListBySpuIds(@RequestParam("spuIds") List<Long> spuIds) {
if (CollUtil.isEmpty(spuIds)) {
return success(MapUtil.empty());
}
// TODO @puhui999要避免这种 1+n 的查询
Map<Long, List<AppActivityRespVO>> map = new HashMap<>(spuIds.size());
spuIds.forEach(spuId -> {
map.put(spuId, getAppActivityRespVOList(spuId));
});
return success(map);
// 每种活动只返回一个key SPU 编号
return success(convertMultiMap(getAppActivityRespVOList(spuIds), AppActivityRespVO::getSpuId));
}
private List<AppActivityRespVO> getAppActivityRespVOList(Long spuId) {
private List<AppActivityRespVO> getAppActivityRespVOList(Collection<Long> spuIds) {
if (CollUtil.isEmpty(spuIds)) {
return new ArrayList<>();
}
List<AppActivityRespVO> activityList = new ArrayList<>();
// 拼团活动
CombinationActivityDO combination = combinationActivityService.getCombinationActivityBySpuId(spuId);
if (combination != null) {
activityList.add(new AppActivityRespVO()
.setId(combination.getId())
.setType(PromotionTypeEnum.COMBINATION_ACTIVITY.getType())
.setName(combination.getName())
.setStartTime(combination.getStartTime())
.setEndTime(combination.getEndTime()));
List<CombinationActivityDO> combinationActivities = combinationActivityService.getCombinationActivityBySpuIdsAndStatus(
spuIds, CommonStatusEnum.ENABLE.getStatus());
if (CollUtil.isNotEmpty(combinationActivities)) {
combinationActivities.forEach(item -> {
activityList.add(new AppActivityRespVO()
.setId(item.getId())
.setType(PromotionTypeEnum.COMBINATION_ACTIVITY.getType())
.setName(item.getName())
.setSpuId(item.getSpuId())
.setStartTime(item.getStartTime())
.setEndTime(item.getEndTime()));
});
}
// 秒杀活动
SeckillActivityDO seckill = seckillActivityService.getSeckillActivityBySpuId(spuId);
if (seckill != null) {
activityList.add(new AppActivityRespVO()
.setId(seckill.getId())
.setType(PromotionTypeEnum.SECKILL_ACTIVITY.getType())
.setName(seckill.getName())
.setStartTime(seckill.getStartTime())
.setEndTime(seckill.getEndTime()));
List<SeckillActivityDO> seckillActivities = seckillActivityService.getSeckillActivityBySpuIdsAndStatus(
spuIds, CommonStatusEnum.ENABLE.getStatus());
if (CollUtil.isNotEmpty(seckillActivities)) {
seckillActivities.forEach(item -> {
activityList.add(new AppActivityRespVO()
.setId(item.getId())
.setType(PromotionTypeEnum.SECKILL_ACTIVITY.getType())
.setName(item.getName())
.setSpuId(item.getSpuId())
.setStartTime(item.getStartTime())
.setEndTime(item.getEndTime()));
});
}
// 秒杀活动
BargainActivityDO bargain = bargainActivityService.getBargainActivityBySpuId(spuId);
if (bargain != null) {
activityList.add(new AppActivityRespVO()
.setId(bargain.getId())
.setType(PromotionTypeEnum.BARGAIN_ACTIVITY.getType())
.setName(bargain.getName())
.setStartTime(bargain.getStartTime())
.setEndTime(bargain.getEndTime()));
// 砍价活动
List<BargainActivityDO> bargainActivities = bargainActivityService.getBargainActivityBySpuIdsAndStatus(
spuIds, CommonStatusEnum.ENABLE.getStatus());
if (CollUtil.isNotEmpty(bargainActivities)) {
bargainActivities.forEach(item -> {
activityList.add(new AppActivityRespVO()
.setId(item.getId())
.setType(PromotionTypeEnum.BARGAIN_ACTIVITY.getType())
.setName(item.getName())
.setSpuId(item.getSpuId())
.setStartTime(item.getStartTime())
.setEndTime(item.getEndTime()));
});
}
return activityList;
}

View File

@ -13,12 +13,14 @@ public class AppActivityRespVO {
private Long id;
@Schema(description = "活动类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
// 对应 PromotionTypeEnum 枚举
private Integer type;
private Integer type; // 对应 PromotionTypeEnum 枚举
@Schema(description = "活动名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "618 大促")
private String name;
@Schema(description = "spu 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "618")
private Long spuId;
@Schema(description = "活动开始时间", requiredMode = Schema.RequiredMode.REQUIRED)
private LocalDateTime startTime;

View File

@ -47,7 +47,7 @@ public class AppCombinationRecordController {
public CommonResult<AppCombinationRecordSummaryRespVO> getCombinationRecordSummary() {
AppCombinationRecordSummaryRespVO summary = new AppCombinationRecordSummaryRespVO();
// 1. 获得拼团记录数量
Long count = combinationRecordService.getCombinationRecordCount();
Long count = combinationRecordService.getCombinationRecordCount(null, null);
if (count == 0) {
summary.setAvatars(Collections.emptyList());
summary.setUserCount(count);

View File

@ -14,7 +14,7 @@ import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activit
import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityUpdateReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product.CombinationProductBaseVO;
import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product.CombinationProductRespVO;
import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod.CombinationRecordRespVO;
import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod.CombinationRecordPageItemRespVO;
import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.activity.AppCombinationActivityDetailRespVO;
import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.activity.AppCombinationActivityRespVO;
import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.record.AppCombinationRecordDetailRespVO;
@ -79,6 +79,7 @@ public interface CombinationActivityConvert {
});
return pageResult;
}
PageResult<CombinationActivityPageItemRespVO> convertPage(PageResult<CombinationActivityDO> page);
List<CombinationProductRespVO> convertList2(List<CombinationProductDO> productDOs);
@ -113,9 +114,8 @@ public interface CombinationActivityConvert {
CombinationActivityDO activity, MemberUserRespDTO user,
ProductSpuRespDTO spu, ProductSkuRespDTO sku) {
return convert(reqDTO)
.setHeadId(reqDTO.getHeadId()) // 显示性再设置一下
.setCount(reqDTO.getCount())
.setVirtualGroup(false)
.setVirtualGroup(false) // 默认 false 拼团过期都还没有成功则按照 CombinationActivityDO#virtualGroup 来如果为 true 则执行虚拟成团的逻辑
.setStatus(CombinationRecordStatusEnum.IN_PROGRESS.getStatus()) // 创建后默认状态为进行中
.setStartTime(LocalDateTime.now())
.setExpireTime(activity.getStartTime().plusHours(activity.getLimitDuration()))
@ -176,7 +176,20 @@ public interface CombinationActivityConvert {
AppCombinationRecordRespVO convert(CombinationRecordDO record);
PageResult<CombinationRecordRespVO> convert(PageResult<CombinationRecordDO> result);
PageResult<CombinationRecordPageItemRespVO> convert(PageResult<CombinationRecordDO> result);
default PageResult<CombinationRecordPageItemRespVO> convert(PageResult<CombinationRecordDO> recordPage, List<CombinationActivityDO> activities) {
PageResult<CombinationRecordPageItemRespVO> result = convert(recordPage);
Map<Long, CombinationActivityDO> activityMap = convertMap(activities, CombinationActivityDO::getId);
result.setList(CollectionUtils.convertList(result.getList(), item -> {
findAndThen(activityMap, item.getActivityId(), activity -> {
item.setActivity(convert(activity));
});
return item;
}));
return result;
}
default AppCombinationRecordDetailRespVO convert(Long userId, CombinationRecordDO headRecord, List<CombinationRecordDO> memberRecords) {
AppCombinationRecordDetailRespVO respVO = new AppCombinationRecordDetailRespVO()

View File

@ -77,7 +77,6 @@ public class CombinationRecordDO extends BaseDO {
*/
private Long userId;
// TODO @puhui999要不去掉这 2 个字段通过读取解决如果去掉相关接口都要处理下哈
/**
* 用户昵称
*/

View File

@ -8,8 +8,10 @@ import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.activity.Ba
import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainActivityDO;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import java.time.LocalDateTime;
import java.util.Collection;
import java.util.List;
/**
@ -83,12 +85,23 @@ public interface BargainActivityMapper extends BaseMapperX<BargainActivityDO> {
.last("LIMIT " + count));
}
// TODO @puhui999需要开启状态另外是不是可以 limit1不用 throwEx = false 处理呀另外时间要满足噢
default BargainActivityDO selectOne(Long spuId) {
return selectOne(new LambdaQueryWrapperX<BargainActivityDO>()
.eq(BargainActivityDO::getSpuId, spuId)
.orderByDesc(BargainActivityDO::getCreateTime)
, false);
}
/**
* 获取指定 spu 编号最近参加的活动每个 spuId 只返回一条记录
*
* @param spuIds spu 编号
* @param status 状态
* @return 砍价活动列表
*/
@Select("SELECT p1.* " +
"FROM promotion_bargain_activity p1 " +
"INNER JOIN ( " +
" SELECT spu_id, MAX(DISTINCT(create_time)) AS max_create_time " +
" FROM promotion_bargain_activity " +
" WHERE spu_id IN #{spuIds} " +
" GROUP BY spu_id " +
") p2 " +
"ON p1.spu_id = p2.spu_id AND p1.create_time = p2.max_create_time AND p1.status = #{status} " +
"ORDER BY p1.create_time DESC;")
List<BargainActivityDO> selectListBySpuIds(Collection<Long> spuIds, Integer status);
}

View File

@ -7,7 +7,10 @@ import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityPageReqVO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationActivityDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.Collection;
import java.util.List;
/**
@ -40,12 +43,23 @@ public interface CombinationActivityMapper extends BaseMapperX<CombinationActivi
.last("LIMIT " + count));
}
// TODO @puhui999需要开启状态另外是不是可以 limit1不用 throwEx = false 处理呀另外时间要满足噢
default CombinationActivityDO selectOne(Long spuId) {
return selectOne(new LambdaQueryWrapperX<CombinationActivityDO>()
.eq(CombinationActivityDO::getSpuId, spuId)
.orderByDesc(CombinationActivityDO::getCreateTime)
, false);
}
/**
* 获取指定 spu 编号最近参加的活动每个 spuId 只返回一条记录
*
* @param spuIds spu 编号
* @param status 状态
* @return 拼团活动列表
*/
@Select("SELECT p1.* " +
"FROM promotion_combination_activity p1 " +
"INNER JOIN ( " +
" SELECT spu_id, MAX(DISTINCT(create_time)) AS max_create_time " +
" FROM promotion_combination_activity " +
" WHERE spu_id IN #{spuIds} " +
" GROUP BY spu_id " +
") p2 " +
"ON p1.spu_id = p2.spu_id AND p1.create_time = p2.max_create_time AND p1.status = #{status} " +
"ORDER BY p1.create_time DESC;")
List<CombinationActivityDO> selectListBySpuIds(@Param("spuIds") Collection<Long> spuIds, @Param("status") Integer status);
}

View File

@ -100,4 +100,12 @@ public interface CombinationRecordMapper extends BaseMapperX<CombinationRecordDO
.betweenIfPresent(CombinationRecordDO::getCreateTime, pageVO.getCreateTime()));
}
default Long selectRecordCount(Integer status, Boolean virtualGroup) {
return selectCount(new LambdaQueryWrapperX<CombinationRecordDO>()
.eq(status != null || virtualGroup != null,
CombinationRecordDO::getHeadId, CombinationRecordDO.HEAD_ID_GROUP) // 统计团信息则指定团长
.eqIfPresent(CombinationRecordDO::getStatus, status)
.eqIfPresent(CombinationRecordDO::getVirtualGroup, virtualGroup));
}
}

View File

@ -9,7 +9,9 @@ import cn.iocoder.yudao.module.promotion.controller.app.seckill.vo.activity.AppS
import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.SeckillActivityDO;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import java.util.Collection;
import java.util.List;
/**
@ -56,12 +58,23 @@ public interface SeckillActivityMapper extends BaseMapperX<SeckillActivityDO> {
.apply(ObjectUtil.isNotNull(pageReqVO.getConfigId()), "FIND_IN_SET(" + pageReqVO.getConfigId() + ",config_ids) > 0"));
}
// TODO @puhui999需要开启状态另外是不是可以 limit1不用 throwEx = false 处理呀另外时间要满足噢
default SeckillActivityDO selectOne(Long spuId) {
return selectOne(new LambdaQueryWrapperX<SeckillActivityDO>()
.eq(SeckillActivityDO::getSpuId, spuId)
.orderByDesc(SeckillActivityDO::getCreateTime)
, false);
}
/**
* 获取指定 spu 编号最近参加的活动每个 spuId 只返回一条记录
*
* @param spuIds spu 编号
* @param status 状态
* @return 秒杀活动列表
*/
@Select("SELECT p1.* " +
"FROM promotion_seckill_activity p1 " +
"INNER JOIN ( " +
" SELECT spu_id, MAX(DISTINCT(create_time)) AS max_create_time " +
" FROM promotion_seckill_activity " +
" WHERE spu_id IN #{spuIds} " +
" GROUP BY spu_id " +
") p2 " +
"ON p1.spu_id = p2.spu_id AND p1.create_time = p2.max_create_time AND p1.status = #{status} " +
"ORDER BY p1.create_time DESC;")
List<SeckillActivityDO> selectListBySpuIds(Collection<Long> spuIds, Integer status);
}

View File

@ -8,6 +8,7 @@ import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.activity.Ba
import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainActivityDO;
import javax.validation.Valid;
import java.util.Collection;
import java.util.List;
import java.util.Set;
@ -99,11 +100,12 @@ public interface BargainActivityService {
List<BargainActivityDO> getBargainActivityListByCount(Integer count);
/**
* 获取指定 spu 编号的活动
* 获取指定 spu 编号最近参加的活动每个 spuId 只返回一条记录
*
* @param spuId spu 编号
* @return 砍价活动
* @param spuIds spu 编号
* @param status 状态
* @return 砍价活动列表
*/
BargainActivityDO getBargainActivityBySpuId(Long spuId);
List<BargainActivityDO> getBargainActivityBySpuIdsAndStatus(Collection<Long> spuIds, Integer status);
}

View File

@ -20,6 +20,7 @@ import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.Collection;
import java.util.List;
import java.util.Set;
@ -176,8 +177,8 @@ public class BargainActivityServiceImpl implements BargainActivityService {
}
@Override
public BargainActivityDO getBargainActivityBySpuId(Long spuId) {
return bargainActivityMapper.selectOne(spuId);
public List<BargainActivityDO> getBargainActivityBySpuIdsAndStatus(Collection<Long> spuIds, Integer status) {
return bargainActivityMapper.selectListBySpuIds(spuIds, status);
}
}

View File

@ -84,6 +84,14 @@ public interface CombinationActivityService {
*/
List<CombinationProductDO> getCombinationProductListByActivityIds(Collection<Long> activityIds);
/**
* 获得拼团活动列表
*
* @param ids 拼团活动 ids
* @return 拼团活动的列表
*/
List<CombinationActivityDO> getCombinationActivityListByIds(Collection<Long> ids);
/**
* 获取正在进行的活动分页数据
*
@ -110,11 +118,12 @@ public interface CombinationActivityService {
CombinationProductDO selectByActivityIdAndSkuId(Long activityId, Long skuId);
/**
* 获取指定 spu 编号的活动
* 获取指定 spu 编号最近参加的活动每个 spuId 只返回一条记录
*
* @param spuId spu 编号
* @return 拼团活动
* @param spuIds spu 编号
* @param status 状态
* @return 拼团活动列表
*/
CombinationActivityDO getCombinationActivityBySpuId(Long spuId);
List<CombinationActivityDO> getCombinationActivityBySpuIdsAndStatus(Collection<Long> spuIds, Integer status);
}

View File

@ -204,6 +204,11 @@ public class CombinationActivityServiceImpl implements CombinationActivityServic
return combinationProductMapper.selectListByActivityIds(activityIds);
}
@Override
public List<CombinationActivityDO> getCombinationActivityListByIds(Collection<Long> ids) {
return combinationActivityMapper.selectList(CombinationActivityDO::getId, ids);
}
@Override
public List<CombinationActivityDO> getCombinationActivityListByCount(Integer count) {
return combinationActivityMapper.selectListByStatus(CommonStatusEnum.ENABLE.getStatus(), count);
@ -222,8 +227,8 @@ public class CombinationActivityServiceImpl implements CombinationActivityServic
}
@Override
public CombinationActivityDO getCombinationActivityBySpuId(Long spuId) {
return combinationActivityMapper.selectOne(spuId);
public List<CombinationActivityDO> getCombinationActivityBySpuIdsAndStatus(Collection<Long> spuIds, Integer status) {
return combinationActivityMapper.selectListBySpuIds(spuIds, status);
}
}

View File

@ -49,8 +49,9 @@ public interface CombinationRecordService {
* 创建拼团记录
*
* @param reqDTO 创建信息
* @return 开团记录编号
*/
void createCombinationRecord(CombinationRecordCreateReqDTO reqDTO);
Long createCombinationRecord(CombinationRecordCreateReqDTO reqDTO);
/**
* 获得拼团记录
@ -85,25 +86,13 @@ public interface CombinationRecordService {
CombinationValidateJoinRespDTO validateJoinCombination(Long userId, Long activityId, Long headId, Long skuId, Integer count);
/**
* 获取所有拼团记录数
* 获取拼团记录数
*
* @param status 状态-允许为空
* @param virtualGroup 是否虚拟成团-允许为空
* @return 记录数
*/
Long getCombinationRecordCount();
/**
* 获取成功记录数
*
* @return 记录数
*/
Long getCombinationRecordsSuccessCount();
/**
* 获取虚拟成团记录数
*
* @return 记录数
*/
Long getRecordsVirtualGroupCount();
Long getCombinationRecordCount(@Nullable Integer status, @Nullable Boolean virtualGroup);
/**
* 获取最近的 count 条拼团记录

View File

@ -31,7 +31,8 @@ import javax.annotation.Resource;
import java.util.*;
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.findFirst;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.getSumValue;
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.*;
@ -95,7 +96,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService {
if (ObjUtil.equal(activity.getStatus(), CommonStatusEnum.DISABLE.getStatus())) {
throw exception(COMBINATION_ACTIVITY_STATUS_DISABLE);
}
// 1.2 校验活动开始时间
// 1.2. 校验活动开始时间
if (afterNow(activity.getStartTime())) {
throw exception(COMBINATION_RECORD_FAILED_TIME_NOT_START);
}
@ -163,7 +164,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService {
@Override
@Transactional(rollbackFor = Exception.class)
public void createCombinationRecord(CombinationRecordCreateReqDTO reqDTO) {
public Long createCombinationRecord(CombinationRecordCreateReqDTO reqDTO) {
// 1. 校验拼团活动
KeyValue<CombinationActivityDO, CombinationProductDO> keyValue = validateCombinationRecord(reqDTO.getUserId(),
reqDTO.getActivityId(), reqDTO.getHeadId(), reqDTO.getSkuId(), reqDTO.getCount());
@ -173,34 +174,19 @@ public class CombinationRecordServiceImpl implements CombinationRecordService {
ProductSpuRespDTO spu = productSpuApi.getSpu(reqDTO.getSpuId());
ProductSkuRespDTO sku = productSkuApi.getSku(reqDTO.getSkuId());
CombinationRecordDO record = CombinationActivityConvert.INSTANCE.convert(reqDTO, keyValue.getKey(), user, spu, sku);
// TODO @puhui head 的情况下 head 结束为准
// 3. 如果是团长需要设置 headId CombinationRecordDO#HEAD_ID_GROUP
record.setHeadId(record.getHeadId() == null ? CombinationRecordDO.HEAD_ID_GROUP : record.getHeadId());
recordMapper.insert(record);
// 3. 如果是团长需要设置 headId CombinationRecordDO#HEAD_ID_GROUP
// TODO @puhui999是不是只要是团长record 设置了就好啦不用 update
if (ObjUtil.equal(CombinationRecordDO.HEAD_ID_GROUP, reqDTO.getHeadId())) {
recordMapper.updateById(new CombinationRecordDO().setId(record.getId()).setHeadId(CombinationRecordDO.HEAD_ID_GROUP));
return;
if (ObjUtil.equal(CombinationRecordDO.HEAD_ID_GROUP, record.getHeadId())) {
return record.getId();
}
// TODO 这里要不要弄成异步的不用异步哈就是事务好了
// 4更新拼团相关信息到订单
updateOrderCombinationInfo(record.getOrderId(), record.getActivityId(), record.getId(), record.getHeadId());
tradeOrderApi.updateOrderCombinationInfo(record.getOrderId(), record.getActivityId(), record.getId(), record.getHeadId());
// 4更新拼团记录
updateCombinationRecordWhenCreate(reqDTO.getHeadId(), keyValue.getKey());
}
// TODO @puhui999这个更新放到 trade 那就好了createCombinationRecord 返回一个 recordId
/**
* 更新拼团相关信息到订单
*
* @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);
return record.getId();
}
/**
@ -252,20 +238,8 @@ public class CombinationRecordServiceImpl implements CombinationRecordService {
}
@Override
public Long getCombinationRecordCount() {
return recordMapper.selectCount();
}
@Override
public Long getCombinationRecordsSuccessCount() {
// TODO @puhui999这个应该要多查询 headId
return recordMapper.selectCount(CombinationRecordDO::getStatus, CombinationRecordStatusEnum.SUCCESS.getStatus());
}
@Override
public Long getRecordsVirtualGroupCount() {
// TODO @puhui999这个应该要多查询 headId然后recordMapper 要明确的查询哈不要直接使用 mapper 来拼接查询条件
return recordMapper.selectCount(CombinationRecordDO::getVirtualGroup, true);
public Long getCombinationRecordCount(@Nullable Integer status, @Nullable Boolean virtualGroup) {
return recordMapper.selectRecordCount(status, virtualGroup);
}
@Override
@ -321,9 +295,9 @@ public class CombinationRecordServiceImpl implements CombinationRecordService {
return;
}
// 按照创建时间升序排序
List<CombinationRecordDO> recordsSort = sortedAsc(list, CombinationRecordDO::getCreateTime);
CombinationRecordDO newHead = recordsSort.get(0); // 新团长继位
recordsSort.forEach(item -> {
list.sort(Comparator.comparing(CombinationRecordDO::getCreateTime)); // 影响原 list
CombinationRecordDO newHead = list.get(0); // 新团长继位
list.forEach(item -> {
CombinationRecordDO recordDO = new CombinationRecordDO();
recordDO.setId(item.getId());
if (ObjUtil.equal(item.getId(), newHead.getId())) { // 新团长
@ -331,7 +305,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService {
} else {
recordDO.setHeadId(newHead.getId());
}
recordDO.setUserCount(recordsSort.size());
recordDO.setUserCount(list.size());
updateRecords.add(recordDO);
});
} else { // 情况二团员

View File

@ -120,11 +120,12 @@ public interface SeckillActivityService {
SeckillValidateJoinRespDTO validateJoinSeckill(Long activityId, Long skuId, Integer count);
/**
* 获取指定 spu 编号的活动
* 获取指定 spu 编号最近参加的活动每个 spuId 只返回一条记录
*
* @param spuId spu 编号
* @return 秒杀活动
* @param spuIds spu 编号
* @param status 状态
* @return 秒杀活动列表
*/
SeckillActivityDO getSeckillActivityBySpuId(Long spuId);
List<SeckillActivityDO> getSeckillActivityBySpuIdsAndStatus(Collection<Long> spuIds, Integer status);
}

View File

@ -311,8 +311,8 @@ public class SeckillActivityServiceImpl implements SeckillActivityService {
}
@Override
public SeckillActivityDO getSeckillActivityBySpuId(Long spuId) {
return seckillActivityMapper.selectOne(spuId);
public List<SeckillActivityDO> getSeckillActivityBySpuIdsAndStatus(Collection<Long> spuIds, Integer status) {
return seckillActivityMapper.selectListBySpuIds(spuIds, status);
}
}

View File

@ -33,6 +33,7 @@ public interface ErrorCodeConstants {
ErrorCode ORDER_UPDATE_PRICE_FAIL_PRICE_ERROR = new ErrorCode(1_011_000_028, "支付订单调价失败,原因:调整后支付价格不能小于 0.01 元");
ErrorCode ORDER_DELETE_FAIL_STATUS_NOT_CANCEL = new ErrorCode(1_011_000_029, "交易订单删除失败,订单不是【已取消】状态");
ErrorCode ORDER_RECEIVE_FAIL_DELIVERY_TYPE_NOT_PICK_UP = new ErrorCode(1_011_000_030, "交易订单自提失败,收货方式不是【用户自提】");
ErrorCode ORDER_UPDATE_ADDRESS_FAIL_STATUS_NOT_DELIVERED = new ErrorCode(1_011_000_031, "交易订单修改收货地址失败,原因:订单已发货");
// ========== After Sale 模块 1-011-000-100 ==========
ErrorCode AFTER_SALE_NOT_FOUND = new ErrorCode(1_011_000_100, "售后单不存在");

View File

@ -15,4 +15,12 @@ public interface RedisKeyConstants {
*/
String TRADE_NO = "trade_no:";
/**
* 交易序号的缓存
*
* KEY 格式express_track:{code-logisticsNo-receiverMobile}
* VALUE 数据格式 String, 物流信息集合
*/
String EXPRESS_TRACK = "express_track";
}

View File

@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.trade.service.order;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.spring.SpringUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.member.api.user.MemberUserApi;
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
@ -14,11 +15,13 @@ import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO;
import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO;
import cn.iocoder.yudao.module.trade.dal.mysql.order.TradeOrderItemMapper;
import cn.iocoder.yudao.module.trade.dal.mysql.order.TradeOrderMapper;
import cn.iocoder.yudao.module.trade.dal.redis.RedisKeyConstants;
import cn.iocoder.yudao.module.trade.enums.order.TradeOrderStatusEnum;
import cn.iocoder.yudao.module.trade.framework.delivery.core.client.ExpressClientFactory;
import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressTrackQueryReqDTO;
import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressTrackRespDTO;
import cn.iocoder.yudao.module.trade.service.delivery.DeliveryExpressService;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@ -143,7 +146,6 @@ public class TradeOrderQueryServiceImpl implements TradeOrderQueryService {
return tradeOrderItemMapper.selectProductSumByOrderId(convertSet(orders, TradeOrderDO::getId));
}
// TODO @puhui999可以加个 spring 缓存30 分钟主要考虑及时性要求不高但是每次调用需要钱
/**
* 获得订单的物流轨迹
*
@ -160,10 +162,25 @@ public class TradeOrderQueryServiceImpl implements TradeOrderQueryService {
throw exception(EXPRESS_NOT_EXISTS);
}
return getSelf().getExpressTrackList(express.getCode(), order.getLogisticsNo(), order.getReceiverMobile());
}
/**
* 查询物流轨迹
* 加个 spring 缓存30 分钟主要考虑及时性要求不高但是每次调用需要钱TODO @艿艿这个时间不会搞了交给你了哈哈哈
*
* @param code 快递公司编码
* @param logisticsNo 发货快递单号
* @param receiverMobile 寄件人的电话号码
* @return 物流轨迹
*/
@Cacheable(cacheNames = RedisKeyConstants.EXPRESS_TRACK, key = "#code + '-' + #logisticsNo + '-' + #receiverMobile",
condition = "#result != null")
public List<ExpressTrackRespDTO> getExpressTrackList(String code, String logisticsNo, String receiverMobile) {
// 查询物流轨迹
return expressClientFactory.getDefaultExpressClient().getExpressTrackList(
new ExpressTrackQueryReqDTO().setExpressCode(express.getCode()).setLogisticsNo(order.getLogisticsNo())
.setPhone(order.getReceiverMobile()));
new ExpressTrackQueryReqDTO().setExpressCode(code).setLogisticsNo(logisticsNo)
.setPhone(receiverMobile));
}
@Override
@ -199,4 +216,13 @@ public class TradeOrderQueryServiceImpl implements TradeOrderQueryService {
return tradeOrderItemMapper.selectListByOrderId(orderIds);
}
/**
* 获得自身的代理对象解决 AOP 生效问题
*
* @return 自己
*/
private TradeOrderQueryServiceImpl getSelf() {
return SpringUtil.getBean(getClass());
}
}

View File

@ -742,8 +742,10 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
public void updateOrderAddress(TradeOrderUpdateAddressReqVO reqVO) {
// 校验交易订单
TradeOrderDO order = validateOrderExists(reqVO.getId());
// TODO @puhui999是否需要校验订单是否发货
// TODO 发货后是否支持修改收货地址回答发货后不允许修改
// 发货后不允许修改
if (TradeOrderStatusEnum.isDelivered(order.getStatus())) {
throw exception(ORDER_UPDATE_ADDRESS_FAIL_STATUS_NOT_DELIVERED);
}
// 更新
tradeOrderMapper.updateById(TradeOrderConvert.INSTANCE.convert(reqVO));

View File

@ -176,7 +176,7 @@ public class DeptServiceImpl implements DeptService {
}
@Override
@DataPermission(enable = false) // 禁用数据权限避免简历不正确的缓存
@DataPermission(enable = false) // 禁用数据权限避免建立不正确的缓存
@Cacheable(cacheNames = RedisKeyConstants.DEPT_CHILDREN_ID_LIST, key = "#id")
public Set<Long> getChildDeptIdListFromCache(Long id) {
List<DeptDO> children = getChildDeptList(id);