Commit 1d9db4874f66b2895a1eba59c8f17678d04c7fed
Committed by
Gitee
!654 拼团记录:完善拼团记录后台管理接口
Merge pull request !654 from puhui999/feature/mall_product
Showing
9 changed files
with
325 additions
and
45 deletions
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationRecordController.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.controller.admin.combination; | |
| 2 | + | |
| 3 | +import cn.hutool.core.map.MapUtil; | |
| 4 | +import cn.iocoder.yudao.framework.common.pojo.CommonResult; | |
| 5 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 6 | +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod.CombinationRecordReqPageVO; | |
| 7 | +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod.CombinationRecordRespVO; | |
| 8 | +import cn.iocoder.yudao.module.promotion.convert.combination.CombinationActivityConvert; | |
| 9 | +import cn.iocoder.yudao.module.promotion.service.combination.CombinationRecordService; | |
| 10 | +import com.google.common.cache.CacheLoader; | |
| 11 | +import com.google.common.cache.LoadingCache; | |
| 12 | +import io.swagger.v3.oas.annotations.Operation; | |
| 13 | +import io.swagger.v3.oas.annotations.tags.Tag; | |
| 14 | +import org.springframework.security.access.prepost.PreAuthorize; | |
| 15 | +import org.springframework.validation.annotation.Validated; | |
| 16 | +import org.springframework.web.bind.annotation.GetMapping; | |
| 17 | +import org.springframework.web.bind.annotation.RequestMapping; | |
| 18 | +import org.springframework.web.bind.annotation.RestController; | |
| 19 | + | |
| 20 | +import javax.annotation.Resource; | |
| 21 | +import javax.validation.Valid; | |
| 22 | +import java.time.Duration; | |
| 23 | +import java.util.Map; | |
| 24 | + | |
| 25 | +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | |
| 26 | +import static cn.iocoder.yudao.framework.common.util.cache.CacheUtils.buildAsyncReloadingCache; | |
| 27 | + | |
| 28 | +@Tag(name = "管理后台 - 拼团记录") | |
| 29 | +@RestController | |
| 30 | +@RequestMapping("/promotion/combination-record") | |
| 31 | +@Validated | |
| 32 | +public class CombinationRecordController { | |
| 33 | + | |
| 34 | + @Resource | |
| 35 | + private CombinationRecordService combinationRecordService; | |
| 36 | + /** | |
| 37 | + * {@link Map} 缓存,通过它异步刷新 {@link #getCombinationRecordSummary0()} 所要的拼团记录统计数据 | |
| 38 | + */ | |
| 39 | + private final LoadingCache<String, Map<String, Long>> combinationRecordSummary = buildAsyncReloadingCache(Duration.ofSeconds(60L), | |
| 40 | + new CacheLoader<String, Map<String, Long>>() { | |
| 41 | + | |
| 42 | + @Override | |
| 43 | + public Map<String, Long> load(String key) { | |
| 44 | + return getCombinationRecordSummary0(); | |
| 45 | + } | |
| 46 | + | |
| 47 | + }); | |
| 48 | + | |
| 49 | + @GetMapping("/page") | |
| 50 | + @Operation(summary = "获得拼团记录分页") | |
| 51 | + @PreAuthorize("@ss.hasPermission('promotion:combination-record:query')") | |
| 52 | + public CommonResult<PageResult<CombinationRecordRespVO>> getBargainRecordPage(@Valid CombinationRecordReqPageVO pageVO) { | |
| 53 | + return success(CombinationActivityConvert.INSTANCE.convert( | |
| 54 | + combinationRecordService.getCombinationRecordPage(pageVO))); | |
| 55 | + } | |
| 56 | + | |
| 57 | + @GetMapping("/get-summary") | |
| 58 | + @Operation(summary = "获得拼团记录的概要信息", description = "用于拼团记录页面展示") | |
| 59 | + @PreAuthorize("@ss.hasPermission('promotion:combination-record:query')") | |
| 60 | + public CommonResult<Map<String, Long>> getCombinationRecordSummary() { | |
| 61 | + return success(combinationRecordSummary.getUnchecked("")); // 缓存 | |
| 62 | + } | |
| 63 | + | |
| 64 | + @GetMapping("/get-count") | |
| 65 | + @Operation(summary = "获得拼团记录分页 tab count") | |
| 66 | + @PreAuthorize("@ss.hasPermission('promotion:combination-record:query')") | |
| 67 | + public CommonResult<Map<String, Long>> getCombinationRecordCount() { | |
| 68 | + Map<String, Long> hashMap = MapUtil.newHashMap(7); | |
| 69 | + hashMap.put("all", combinationRecordService.getCombinationRecordsCountByDateType(CombinationRecordReqPageVO.ALL));// 全部 | |
| 70 | + hashMap.put("toDay", combinationRecordService.getCombinationRecordsCountByDateType(CombinationRecordReqPageVO.TO_DAY));// 今天 | |
| 71 | + hashMap.put("yesterday", combinationRecordService.getCombinationRecordsCountByDateType(CombinationRecordReqPageVO.YESTERDAY));// 昨天 | |
| 72 | + hashMap.put("lastSevenDays", combinationRecordService.getCombinationRecordsCountByDateType(CombinationRecordReqPageVO.LAST_SEVEN_DAYS));// 最近七天 | |
| 73 | + hashMap.put("last30Days", combinationRecordService.getCombinationRecordsCountByDateType(CombinationRecordReqPageVO.LAST_30_DAYS));// 最近 30 天 | |
| 74 | + hashMap.put("thisMonth", combinationRecordService.getCombinationRecordsCountByDateType(CombinationRecordReqPageVO.THIS_MONTH));// 本月 | |
| 75 | + hashMap.put("thisYear", combinationRecordService.getCombinationRecordsCountByDateType(CombinationRecordReqPageVO.THIS_YEAR));// 本年 | |
| 76 | + return success(hashMap); | |
| 77 | + } | |
| 78 | + | |
| 79 | + private Map<String, Long> getCombinationRecordSummary0() { | |
| 80 | + Map<String, Long> hashMap = MapUtil.newHashMap(3); | |
| 81 | + hashMap.put("userCount", combinationRecordService.getCombinationRecordsCount());// 获取所有拼团记录 | |
| 82 | + hashMap.put("successCount", combinationRecordService.getCombinationRecordsSuccessCount());// 获取成团记录 | |
| 83 | + hashMap.put("virtualGroupCount", combinationRecordService.getRecordsVirtualGroupCount());// 获取虚拟成团记录 | |
| 84 | + return hashMap; | |
| 85 | + } | |
| 86 | + | |
| 87 | +} | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/recrod/CombinationRecordReqPageVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 4 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 5 | +import lombok.Data; | |
| 6 | +import lombok.EqualsAndHashCode; | |
| 7 | +import lombok.ToString; | |
| 8 | +import org.springframework.format.annotation.DateTimeFormat; | |
| 9 | + | |
| 10 | +import java.time.LocalDateTime; | |
| 11 | + | |
| 12 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | |
| 13 | + | |
| 14 | +@Schema(description = "管理后台 - 拼团记录分页 Request VO") | |
| 15 | +@Data | |
| 16 | +@EqualsAndHashCode(callSuper = true) | |
| 17 | +@ToString(callSuper = true) | |
| 18 | +public class CombinationRecordReqPageVO extends PageParam { | |
| 19 | + | |
| 20 | + public static final Integer ALL = 0; // 全部 | |
| 21 | + public static final Integer TO_DAY = 1; // 今天 | |
| 22 | + public static final Integer YESTERDAY = 2; // 昨天 | |
| 23 | + public static final Integer LAST_SEVEN_DAYS = 3; // 最近七天 | |
| 24 | + public static final Integer LAST_30_DAYS = 4; // 最近 30 天 | |
| 25 | + public static final Integer THIS_MONTH = 5; // 本月 | |
| 26 | + public static final Integer THIS_YEAR = 6; // 本年 | |
| 27 | + | |
| 28 | + @Schema(description = "日期类型", example = "0") | |
| 29 | + private Integer dateType; | |
| 30 | + | |
| 31 | + @Schema(description = "活动状态", example = "0") | |
| 32 | + private Integer status; | |
| 33 | + | |
| 34 | + @Schema(description = "创建时间") | |
| 35 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 36 | + private LocalDateTime[] createTime; | |
| 37 | + | |
| 38 | +} | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/recrod/CombinationRecordRespVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import lombok.Data; | |
| 5 | +import org.springframework.format.annotation.DateTimeFormat; | |
| 6 | + | |
| 7 | +import java.time.LocalDateTime; | |
| 8 | + | |
| 9 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | |
| 10 | + | |
| 11 | +@Schema(description = "管理后台 - 拼团记录 Response VO") | |
| 12 | +@Data | |
| 13 | +public class CombinationRecordRespVO { | |
| 14 | + | |
| 15 | + @Schema(description = "拼团记录编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | |
| 16 | + private Long id; | |
| 17 | + | |
| 18 | + @Schema(description = "拼团活动编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | |
| 19 | + private Long activityId; | |
| 20 | + | |
| 21 | + @Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "花开富贵") | |
| 22 | + private String nickname; | |
| 23 | + | |
| 24 | + @Schema(description = "用户头像", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/1.png") | |
| 25 | + private String avatar; | |
| 26 | + | |
| 27 | + @Schema(description = "团长编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | |
| 28 | + private Long headId; | |
| 29 | + | |
| 30 | + @Schema(description = "过期时间", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 31 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 32 | + private LocalDateTime expireTime; | |
| 33 | + | |
| 34 | + @Schema(description = "可参团人数", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") | |
| 35 | + private Integer userSize; | |
| 36 | + | |
| 37 | + @Schema(description = "已参团人数", requiredMode = Schema.RequiredMode.REQUIRED, example = "5") | |
| 38 | + private Integer userCount; | |
| 39 | + | |
| 40 | + @Schema(description = "拼团状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | |
| 41 | + private Integer status; | |
| 42 | + | |
| 43 | + @Schema(description = "商品名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "我是大黄豆") | |
| 44 | + private String spuName; | |
| 45 | + | |
| 46 | + @Schema(description = "商品图片", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/1.png") | |
| 47 | + private String picUrl; | |
| 48 | + | |
| 49 | + @Schema(description = "是否虚拟成团", requiredMode = Schema.RequiredMode.REQUIRED, example = "false") | |
| 50 | + private Boolean virtualGroup; | |
| 51 | + | |
| 52 | + @Schema(description = "开始时间 (订单付款后开始的时间)", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 53 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 54 | + private LocalDateTime startTime; | |
| 55 | + | |
| 56 | + @Schema(description = "结束时间(成团时间/失败时间)", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 57 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 58 | + private LocalDateTime endTime; | |
| 59 | + | |
| 60 | +} | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationRecordController.java
| ... | ... | @@ -42,7 +42,7 @@ public class AppCombinationRecordController { |
| 42 | 42 | // TODO 芋艿:增加 @Cache 缓存,1 分钟过期 |
| 43 | 43 | public CommonResult<AppCombinationRecordSummaryRespVO> getCombinationRecordSummary() { |
| 44 | 44 | // 获取所有拼团记录 |
| 45 | - Long count = combinationRecordService.getRecordsCount(); | |
| 45 | + Long count = combinationRecordService.getCombinationRecordsCount(); | |
| 46 | 46 | AppCombinationRecordSummaryRespVO summary = new AppCombinationRecordSummaryRespVO(); |
| 47 | 47 | if (count == null || count == 0L) { |
| 48 | 48 | summary.setAvatars(Collections.emptyList()); |
| ... | ... | @@ -53,7 +53,7 @@ public class AppCombinationRecordController { |
| 53 | 53 | summary.setUserCount(count); |
| 54 | 54 | // TODO 只返回最近的 7 个 |
| 55 | 55 | int num = 7; |
| 56 | - summary.setAvatars(convertList(combinationRecordService.getLatestRecordList(num), CombinationRecordDO::getAvatar)); | |
| 56 | + summary.setAvatars(convertList(combinationRecordService.getLatestCombinationRecordList(num), CombinationRecordDO::getAvatar)); | |
| 57 | 57 | return success(summary); |
| 58 | 58 | } |
| 59 | 59 | |
| ... | ... | @@ -69,7 +69,7 @@ public class AppCombinationRecordController { |
| 69 | 69 | @RequestParam("status") Integer status, |
| 70 | 70 | @RequestParam(value = "count", defaultValue = "20") @Max(20) Integer count) { |
| 71 | 71 | return success(CombinationActivityConvert.INSTANCE.convertList3( |
| 72 | - combinationRecordService.getRecordListWithHead(activityId, status, count))); | |
| 72 | + combinationRecordService.getCombinationRecordListWithHead(activityId, status, count))); | |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | @GetMapping("/get-detail") |
| ... | ... | @@ -77,7 +77,7 @@ public class AppCombinationRecordController { |
| 77 | 77 | @Parameter(name = "id", description = "拼团记录编号", required = true, example = "1024") |
| 78 | 78 | public CommonResult<AppCombinationRecordDetailRespVO> getCombinationRecordDetail(@RequestParam("id") Long id) { |
| 79 | 79 | // 1、查询这条记录 |
| 80 | - CombinationRecordDO record = combinationRecordService.getRecordById(id); | |
| 80 | + CombinationRecordDO record = combinationRecordService.getCombinationRecordById(id); | |
| 81 | 81 | if (record == null) { |
| 82 | 82 | return success(null); |
| 83 | 83 | } |
| ... | ... | @@ -88,17 +88,17 @@ public class AppCombinationRecordController { |
| 88 | 88 | if (record.getHeadId() == null) { |
| 89 | 89 | detail.setHeadRecord(CombinationActivityConvert.INSTANCE.convert(record)); |
| 90 | 90 | // 2.1、查找团员拼团记录 |
| 91 | - records = combinationRecordService.getRecordListByHeadId(record.getId()); | |
| 91 | + records = combinationRecordService.getCombinationRecordListByHeadId(record.getId()); | |
| 92 | 92 | } else { |
| 93 | 93 | // 2.2、查找团长拼团记录 |
| 94 | - CombinationRecordDO headRecord = combinationRecordService.getRecordById(record.getHeadId()); | |
| 94 | + CombinationRecordDO headRecord = combinationRecordService.getCombinationRecordById(record.getHeadId()); | |
| 95 | 95 | if (headRecord == null) { |
| 96 | 96 | return success(null); |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | detail.setHeadRecord(CombinationActivityConvert.INSTANCE.convert(headRecord)); |
| 100 | 100 | // 2.3、查找团员拼团记录 |
| 101 | - records = combinationRecordService.getRecordListByHeadId(headRecord.getId()); | |
| 101 | + records = combinationRecordService.getCombinationRecordListByHeadId(headRecord.getId()); | |
| 102 | 102 | |
| 103 | 103 | } |
| 104 | 104 | detail.setMemberRecords(CombinationActivityConvert.INSTANCE.convertList3(records)); | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java
| ... | ... | @@ -13,6 +13,7 @@ import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activit |
| 13 | 13 | import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityUpdateReqVO; |
| 14 | 14 | import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product.CombinationProductBaseVO; |
| 15 | 15 | import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product.CombinationProductRespVO; |
| 16 | +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod.CombinationRecordRespVO; | |
| 16 | 17 | import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.activity.AppCombinationActivityDetailRespVO; |
| 17 | 18 | import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.activity.AppCombinationActivityRespVO; |
| 18 | 19 | import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.record.AppCombinationRecordRespVO; |
| ... | ... | @@ -155,4 +156,6 @@ public interface CombinationActivityConvert { |
| 155 | 156 | |
| 156 | 157 | AppCombinationRecordRespVO convert(CombinationRecordDO record); |
| 157 | 158 | |
| 159 | + PageResult<CombinationRecordRespVO> convert(PageResult<CombinationRecordDO> result); | |
| 160 | + | |
| 158 | 161 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationRecordMapper.java
| ... | ... | @@ -2,13 +2,18 @@ package cn.iocoder.yudao.module.promotion.dal.mysql.combination; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | 4 | import cn.hutool.core.map.MapUtil; |
| 5 | +import cn.hutool.core.util.ObjectUtil; | |
| 6 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 5 | 7 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; |
| 6 | 8 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 7 | 9 | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; |
| 10 | +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod.CombinationRecordReqPageVO; | |
| 8 | 11 | import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationRecordDO; |
| 9 | 12 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| 10 | 13 | import org.apache.ibatis.annotations.Mapper; |
| 11 | 14 | |
| 15 | +import java.time.LocalDateTime; | |
| 16 | +import java.time.LocalTime; | |
| 12 | 17 | import java.util.Collection; |
| 13 | 18 | import java.util.Collections; |
| 14 | 19 | import java.util.List; |
| ... | ... | @@ -27,10 +32,6 @@ public interface CombinationRecordMapper extends BaseMapperX<CombinationRecordDO |
| 27 | 32 | CombinationRecordDO::getOrderId, orderId); |
| 28 | 33 | } |
| 29 | 34 | |
| 30 | - default List<CombinationRecordDO> selectListByUserId(Long userId) { | |
| 31 | - return selectList(CombinationRecordDO::getUserId, userId); | |
| 32 | - } | |
| 33 | - | |
| 34 | 35 | default List<CombinationRecordDO> selectListByUserIdAndStatus(Long userId, Integer status) { |
| 35 | 36 | return selectList(new LambdaQueryWrapperX<CombinationRecordDO>() |
| 36 | 37 | .eq(CombinationRecordDO::getUserId, userId) |
| ... | ... | @@ -115,4 +116,60 @@ public interface CombinationRecordMapper extends BaseMapperX<CombinationRecordDO |
| 115 | 116 | record -> MapUtil.getInt(record, "recordCount" )); |
| 116 | 117 | } |
| 117 | 118 | |
| 119 | + static LocalDateTime[] builderQueryTime(Integer dateType) { | |
| 120 | + LocalDateTime now = LocalDateTime.now(); | |
| 121 | + LocalDateTime[] createTime = null; // 全部时间段 | |
| 122 | + // 今天-一天开始到结束 | |
| 123 | + if (ObjectUtil.equal(dateType, CombinationRecordReqPageVO.TO_DAY)) { | |
| 124 | + createTime = new LocalDateTime[]{now.toLocalDate().atStartOfDay(), now.toLocalDate().atTime(LocalTime.MAX)}; | |
| 125 | + } | |
| 126 | + // 昨天-昨天开始和结束 | |
| 127 | + if (ObjectUtil.equal(dateType, CombinationRecordReqPageVO.YESTERDAY)) { | |
| 128 | + createTime = new LocalDateTime[]{now.minusDays(1).toLocalDate().atStartOfDay(), | |
| 129 | + now.minusDays(1).toLocalDate().atTime(LocalTime.MAX)}; | |
| 130 | + } | |
| 131 | + // 最近七天 | |
| 132 | + if (ObjectUtil.equal(dateType, CombinationRecordReqPageVO.LAST_SEVEN_DAYS)) { | |
| 133 | + createTime = new LocalDateTime[]{now.minusDays(7).toLocalDate().atStartOfDay(), | |
| 134 | + now.toLocalDate().atTime(LocalTime.MAX)}; | |
| 135 | + } | |
| 136 | + // 最近 30 天 | |
| 137 | + if (ObjectUtil.equal(dateType, CombinationRecordReqPageVO.LAST_30_DAYS)) { | |
| 138 | + createTime = new LocalDateTime[]{now.minusDays(30).toLocalDate().atStartOfDay(), | |
| 139 | + now.toLocalDate().atTime(LocalTime.MAX)}; | |
| 140 | + } | |
| 141 | + // 本月 | |
| 142 | + if (ObjectUtil.equal(dateType, CombinationRecordReqPageVO.THIS_MONTH)) { | |
| 143 | + // 获取本月的开始时间 | |
| 144 | + LocalDateTime startTime = now.withDayOfMonth(1).toLocalDate().atStartOfDay(); | |
| 145 | + // 获取下个月的开始时间,然后减去一秒以获取本月的结束时间 | |
| 146 | + LocalDateTime endTime = now.withDayOfMonth(1).plusMonths(1).toLocalDate().atStartOfDay().minusSeconds(1); | |
| 147 | + createTime = new LocalDateTime[]{startTime, endTime}; | |
| 148 | + } | |
| 149 | + // 本年 | |
| 150 | + if (ObjectUtil.equal(dateType, CombinationRecordReqPageVO.THIS_YEAR)) { | |
| 151 | + // 获取本年的开始时间 | |
| 152 | + LocalDateTime startTime = now.withDayOfYear(1).toLocalDate().atStartOfDay(); | |
| 153 | + // 获取下一年的开始时间,然后减去一秒以获取本年的结束时间 | |
| 154 | + LocalDateTime endTime = now.withDayOfYear(1).plusYears(1).toLocalDate().atStartOfDay().minusSeconds(1); | |
| 155 | + createTime = new LocalDateTime[]{startTime, endTime}; | |
| 156 | + } | |
| 157 | + return createTime; | |
| 158 | + } | |
| 159 | + | |
| 160 | + default PageResult<CombinationRecordDO> selectPage(CombinationRecordReqPageVO pageVO) { | |
| 161 | + // 兼容自选时间段 | |
| 162 | + if (pageVO.getDateType() != null) { | |
| 163 | + pageVO.setCreateTime(builderQueryTime(pageVO.getDateType())); | |
| 164 | + } | |
| 165 | + return selectPage(pageVO, new LambdaQueryWrapperX<CombinationRecordDO>() | |
| 166 | + .eqIfPresent(CombinationRecordDO::getStatus, pageVO.getStatus()) | |
| 167 | + .betweenIfPresent(CombinationRecordDO::getCreateTime, pageVO.getCreateTime())); | |
| 168 | + } | |
| 169 | + | |
| 170 | + default Long selectCount(Integer dateType) { | |
| 171 | + return selectCount(new LambdaQueryWrapperX<CombinationRecordDO>() | |
| 172 | + .betweenIfPresent(CombinationRecordDO::getCreateTime, builderQueryTime(dateType))); | |
| 173 | + } | |
| 174 | + | |
| 118 | 175 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordService.java
| 1 | 1 | package cn.iocoder.yudao.module.promotion.service.combination; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.core.KeyValue; |
| 4 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 4 | 5 | import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCreateReqDTO; |
| 5 | 6 | import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationValidateJoinRespDTO; |
| 7 | +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod.CombinationRecordReqPageVO; | |
| 6 | 8 | import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationActivityDO; |
| 7 | 9 | import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationProductDO; |
| 8 | 10 | import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationRecordDO; |
| ... | ... | @@ -13,7 +15,6 @@ import java.util.Collection; |
| 13 | 15 | import java.util.List; |
| 14 | 16 | import java.util.Map; |
| 15 | 17 | |
| 16 | -// todo @PUHUI:方法名,还是带下 Combination 哈 | |
| 17 | 18 | /** |
| 18 | 19 | * 拼团记录 Service 接口 |
| 19 | 20 | * |
| ... | ... | @@ -60,11 +61,11 @@ public interface CombinationRecordService { |
| 60 | 61 | void updateRecordStatusAndStartTimeByUserIdAndOrderId(Integer status, Long userId, Long orderId, LocalDateTime startTime); |
| 61 | 62 | |
| 62 | 63 | /** |
| 63 | - * 获得拼团状态 | |
| 64 | + * 获得拼团记录 | |
| 64 | 65 | * |
| 65 | 66 | * @param userId 用户编号 |
| 66 | 67 | * @param orderId 订单编号 |
| 67 | - * @return 拼团状态 | |
| 68 | + * @return 拼团记录 | |
| 68 | 69 | */ |
| 69 | 70 | CombinationRecordDO getCombinationRecord(Long userId, Long orderId); |
| 70 | 71 | |
| ... | ... | @@ -75,7 +76,7 @@ public interface CombinationRecordService { |
| 75 | 76 | * @param activityId 活动 id |
| 76 | 77 | * @return 拼团记录列表 |
| 77 | 78 | */ |
| 78 | - List<CombinationRecordDO> getRecordListByUserIdAndActivityId(Long userId, Long activityId); | |
| 79 | + List<CombinationRecordDO> getCombinationRecordListByUserIdAndActivityId(Long userId, Long activityId); | |
| 79 | 80 | |
| 80 | 81 | /** |
| 81 | 82 | * 【下单前】校验是否满足拼团活动条件 |
| ... | ... | @@ -95,7 +96,29 @@ public interface CombinationRecordService { |
| 95 | 96 | * |
| 96 | 97 | * @return 记录数 |
| 97 | 98 | */ |
| 98 | - Long getRecordsCount(); | |
| 99 | + Long getCombinationRecordsCount(); | |
| 100 | + | |
| 101 | + /** | |
| 102 | + * 获取成功记录数 | |
| 103 | + * | |
| 104 | + * @return 记录数 | |
| 105 | + */ | |
| 106 | + Long getCombinationRecordsSuccessCount(); | |
| 107 | + | |
| 108 | + /** | |
| 109 | + * 获取虚拟成团记录数 | |
| 110 | + * | |
| 111 | + * @return 记录数 | |
| 112 | + */ | |
| 113 | + Long getRecordsVirtualGroupCount(); | |
| 114 | + | |
| 115 | + /** | |
| 116 | + * 获取指定日期类型的记录数,比如说获取最近七天的拼团记录数 | |
| 117 | + * | |
| 118 | + * @param dateType 日期类型 | |
| 119 | + * @return 记录数 | |
| 120 | + */ | |
| 121 | + Long getCombinationRecordsCountByDateType(Integer dateType); | |
| 99 | 122 | |
| 100 | 123 | /** |
| 101 | 124 | * 获取最近的 count 条拼团记录 |
| ... | ... | @@ -103,7 +126,7 @@ public interface CombinationRecordService { |
| 103 | 126 | * @param count 限制数量 |
| 104 | 127 | * @return 拼团记录列表 |
| 105 | 128 | */ |
| 106 | - List<CombinationRecordDO> getLatestRecordList(int count); | |
| 129 | + List<CombinationRecordDO> getLatestCombinationRecordList(int count); | |
| 107 | 130 | |
| 108 | 131 | /** |
| 109 | 132 | * 获得最近 n 条拼团记录(团长发起的) |
| ... | ... | @@ -113,7 +136,7 @@ public interface CombinationRecordService { |
| 113 | 136 | * @param count 数量 |
| 114 | 137 | * @return 拼团记录列表 |
| 115 | 138 | */ |
| 116 | - List<CombinationRecordDO> getRecordListWithHead(Long activityId, Integer status, Integer count); | |
| 139 | + List<CombinationRecordDO> getCombinationRecordListWithHead(Long activityId, Integer status, Integer count); | |
| 117 | 140 | |
| 118 | 141 | /** |
| 119 | 142 | * 获取指定编号的拼团记录 |
| ... | ... | @@ -121,7 +144,7 @@ public interface CombinationRecordService { |
| 121 | 144 | * @param id 拼团记录编号 |
| 122 | 145 | * @return 拼团记录 |
| 123 | 146 | */ |
| 124 | - CombinationRecordDO getRecordById(Long id); | |
| 147 | + CombinationRecordDO getCombinationRecordById(Long id); | |
| 125 | 148 | |
| 126 | 149 | /** |
| 127 | 150 | * 获取指定团长编号的拼团记录 |
| ... | ... | @@ -129,7 +152,15 @@ public interface CombinationRecordService { |
| 129 | 152 | * @param headId 团长编号 |
| 130 | 153 | * @return 拼团记录列表 |
| 131 | 154 | */ |
| 132 | - List<CombinationRecordDO> getRecordListByHeadId(Long headId); | |
| 155 | + List<CombinationRecordDO> getCombinationRecordListByHeadId(Long headId); | |
| 156 | + | |
| 157 | + /** | |
| 158 | + * 获取拼团记录分页数据 | |
| 159 | + * | |
| 160 | + * @param pageVO 分页请求 | |
| 161 | + * @return 拼团记录分页数据 | |
| 162 | + */ | |
| 163 | + PageResult<CombinationRecordDO> getCombinationRecordPage(CombinationRecordReqPageVO pageVO); | |
| 133 | 164 | |
| 134 | 165 | /** |
| 135 | 166 | * 【拼团活动】获得拼团记录数量 Map | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java
| ... | ... | @@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil; |
| 4 | 4 | import cn.hutool.core.util.ObjectUtil; |
| 5 | 5 | import cn.iocoder.yudao.framework.common.core.KeyValue; |
| 6 | 6 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 7 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 7 | 8 | import cn.iocoder.yudao.module.member.api.user.MemberUserApi; |
| 8 | 9 | import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; |
| 9 | 10 | import cn.iocoder.yudao.module.product.api.sku.ProductSkuApi; |
| ... | ... | @@ -12,6 +13,7 @@ import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi; |
| 12 | 13 | import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; |
| 13 | 14 | import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCreateReqDTO; |
| 14 | 15 | import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationValidateJoinRespDTO; |
| 16 | +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod.CombinationRecordReqPageVO; | |
| 15 | 17 | import cn.iocoder.yudao.module.promotion.convert.combination.CombinationActivityConvert; |
| 16 | 18 | import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationActivityDO; |
| 17 | 19 | import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationProductDO; |
| ... | ... | @@ -137,7 +139,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { |
| 137 | 139 | throw exception(COMBINATION_ACTIVITY_UPDATE_STOCK_FAIL); |
| 138 | 140 | } |
| 139 | 141 | // 3、校验是否有拼团记录 |
| 140 | - List<CombinationRecordDO> recordList = getRecordListByUserIdAndActivityId(userId, activityId); | |
| 142 | + List<CombinationRecordDO> recordList = getCombinationRecordListByUserIdAndActivityId(userId, activityId); | |
| 141 | 143 | if (CollUtil.isEmpty(recordList)) { |
| 142 | 144 | return new KeyValue<>(activity, product); |
| 143 | 145 | } |
| ... | ... | @@ -211,7 +213,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { |
| 211 | 213 | } |
| 212 | 214 | |
| 213 | 215 | @Override |
| 214 | - public List<CombinationRecordDO> getRecordListByUserIdAndActivityId(Long userId, Long activityId) { | |
| 216 | + public List<CombinationRecordDO> getCombinationRecordListByUserIdAndActivityId(Long userId, Long activityId) { | |
| 215 | 217 | return recordMapper.selectListByUserIdAndActivityId(userId, activityId); |
| 216 | 218 | } |
| 217 | 219 | |
| ... | ... | @@ -225,31 +227,51 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { |
| 225 | 227 | } |
| 226 | 228 | |
| 227 | 229 | @Override |
| 228 | - public Long getRecordsCount() { | |
| 230 | + public Long getCombinationRecordsCount() { | |
| 229 | 231 | return recordMapper.selectCount(); |
| 230 | 232 | } |
| 231 | 233 | |
| 232 | 234 | @Override |
| 233 | - public List<CombinationRecordDO> getLatestRecordList(int count) { | |
| 235 | + public Long getCombinationRecordsSuccessCount() { | |
| 236 | + return recordMapper.selectCount(CombinationRecordDO::getStatus, CombinationRecordStatusEnum.SUCCESS.getStatus()); | |
| 237 | + } | |
| 238 | + | |
| 239 | + @Override | |
| 240 | + public Long getRecordsVirtualGroupCount() { | |
| 241 | + return recordMapper.selectCount(CombinationRecordDO::getVirtualGroup, true); | |
| 242 | + } | |
| 243 | + | |
| 244 | + @Override | |
| 245 | + public Long getCombinationRecordsCountByDateType(Integer dateType) { | |
| 246 | + return recordMapper.selectCount(dateType); | |
| 247 | + } | |
| 248 | + | |
| 249 | + @Override | |
| 250 | + public List<CombinationRecordDO> getLatestCombinationRecordList(int count) { | |
| 234 | 251 | return recordMapper.selectLatestList(count); |
| 235 | 252 | } |
| 236 | 253 | |
| 237 | 254 | @Override |
| 238 | - public List<CombinationRecordDO> getRecordListWithHead(Long activityId, Integer status, Integer count) { | |
| 255 | + public List<CombinationRecordDO> getCombinationRecordListWithHead(Long activityId, Integer status, Integer count) { | |
| 239 | 256 | return recordMapper.selectList(activityId, status, count); |
| 240 | 257 | } |
| 241 | 258 | |
| 242 | 259 | @Override |
| 243 | - public CombinationRecordDO getRecordById(Long id) { | |
| 260 | + public CombinationRecordDO getCombinationRecordById(Long id) { | |
| 244 | 261 | return recordMapper.selectById(id); |
| 245 | 262 | } |
| 246 | 263 | |
| 247 | 264 | @Override |
| 248 | - public List<CombinationRecordDO> getRecordListByHeadId(Long headId) { | |
| 265 | + public List<CombinationRecordDO> getCombinationRecordListByHeadId(Long headId) { | |
| 249 | 266 | return recordMapper.selectList(CombinationRecordDO::getHeadId, headId); |
| 250 | 267 | } |
| 251 | 268 | |
| 252 | 269 | @Override |
| 270 | + public PageResult<CombinationRecordDO> getCombinationRecordPage(CombinationRecordReqPageVO pageVO) { | |
| 271 | + return recordMapper.selectPage(pageVO); | |
| 272 | + } | |
| 273 | + | |
| 274 | + @Override | |
| 253 | 275 | public Map<Long, Integer> getCombinationRecordCountMapByActivity(Collection<Long> activityIds, |
| 254 | 276 | @Nullable Integer status, @Nullable Integer headId) { |
| 255 | 277 | return recordMapper.selectCombinationRecordCountMapByActivityIdAndStatusAndHeadId(activityIds, status, headId); | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/test/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImplTest.java
| ... | ... | @@ -111,9 +111,6 @@ public class CombinationActivityServiceImplTest extends BaseDbUnitTest { |
| 111 | 111 | o.setStartTime(null); |
| 112 | 112 | o.setEndTime(null); |
| 113 | 113 | o.setUserSize(null); |
| 114 | - o.setTotalCount(null); | |
| 115 | - o.setSuccessCount(null); | |
| 116 | - o.setOrderUserCount(null); | |
| 117 | 114 | o.setVirtualGroup(null); |
| 118 | 115 | o.setStatus(null); |
| 119 | 116 | o.setLimitDuration(null); |
| ... | ... | @@ -134,12 +131,6 @@ public class CombinationActivityServiceImplTest extends BaseDbUnitTest { |
| 134 | 131 | combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setEndTime(null))); |
| 135 | 132 | // 测试 userSize 不匹配 |
| 136 | 133 | combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setUserSize(null))); |
| 137 | - // 测试 totalNum 不匹配 | |
| 138 | - combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setTotalCount(null))); | |
| 139 | - // 测试 successNum 不匹配 | |
| 140 | - combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setSuccessCount(null))); | |
| 141 | - // 测试 orderUserCount 不匹配 | |
| 142 | - combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setOrderUserCount(null))); | |
| 143 | 134 | // 测试 virtualGroup 不匹配 |
| 144 | 135 | combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setVirtualGroup(null))); |
| 145 | 136 | // 测试 status 不匹配 |
| ... | ... | @@ -173,9 +164,6 @@ public class CombinationActivityServiceImplTest extends BaseDbUnitTest { |
| 173 | 164 | o.setStartTime(null); |
| 174 | 165 | o.setEndTime(null); |
| 175 | 166 | o.setUserSize(null); |
| 176 | - o.setTotalCount(null); | |
| 177 | - o.setSuccessCount(null); | |
| 178 | - o.setOrderUserCount(null); | |
| 179 | 167 | o.setVirtualGroup(null); |
| 180 | 168 | o.setStatus(null); |
| 181 | 169 | o.setLimitDuration(null); |
| ... | ... | @@ -196,12 +184,6 @@ public class CombinationActivityServiceImplTest extends BaseDbUnitTest { |
| 196 | 184 | combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setEndTime(null))); |
| 197 | 185 | // 测试 userSize 不匹配 |
| 198 | 186 | combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setUserSize(null))); |
| 199 | - // 测试 totalNum 不匹配 | |
| 200 | - combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setTotalCount(null))); | |
| 201 | - // 测试 successNum 不匹配 | |
| 202 | - combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setSuccessCount(null))); | |
| 203 | - // 测试 orderUserCount 不匹配 | |
| 204 | - combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setOrderUserCount(null))); | |
| 205 | 187 | // 测试 virtualGroup 不匹配 |
| 206 | 188 | combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setVirtualGroup(null))); |
| 207 | 189 | // 测试 status 不匹配 | ... | ... |