From ce77d510bb7cc5a375960fa3615de9d7f89f779e Mon Sep 17 00:00:00 2001 From: puhui999 Date: Fri, 6 Oct 2023 20:27:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8B=BC=E5=9B=A2=E8=AE=B0=E5=BD=95=EF=BC=9A?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=8B=BC=E5=9B=A2=E8=AE=B0=E5=BD=95=E5=90=8E?= =?UTF-8?q?=E5=8F=B0=E7=AE=A1=E7=90=86=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CombinationRecordController.java | 87 +++++++++++++++++++ .../vo/recrod/CombinationRecordReqPageVO.java | 38 ++++++++ .../vo/recrod/CombinationRecordRespVO.java | 60 +++++++++++++ .../CombinationActivityConvert.java | 3 + .../combination/CombinationRecordMapper.java | 61 +++++++++++++ .../combination/CombinationRecordService.java | 32 +++++++ .../CombinationRecordServiceImpl.java | 22 +++++ 7 files changed, 303 insertions(+) create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationRecordController.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/recrod/CombinationRecordReqPageVO.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/recrod/CombinationRecordRespVO.java diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationRecordController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationRecordController.java new file mode 100644 index 000000000..de24a7631 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationRecordController.java @@ -0,0 +1,87 @@ +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.CombinationRecordReqPageVO; +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod.CombinationRecordRespVO; +import cn.iocoder.yudao.module.promotion.convert.combination.CombinationActivityConvert; +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.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; +import javax.validation.Valid; +import java.time.Duration; +import java.util.Map; + +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; +import static cn.iocoder.yudao.framework.common.util.cache.CacheUtils.buildAsyncReloadingCache; + +@Tag(name = "管理后台 - 拼团记录") +@RestController +@RequestMapping("/promotion/combination-record") +@Validated +public class CombinationRecordController { + + @Resource + private CombinationRecordService combinationRecordService; + /** + * {@link Map} 缓存,通过它异步刷新 {@link #getCombinationRecordSummary0()} 所要的拼团记录统计数据 + */ + private final LoadingCache> combinationRecordSummary = buildAsyncReloadingCache(Duration.ofSeconds(60L), + new CacheLoader>() { + + @Override + public Map load(String key) { + return getCombinationRecordSummary0(); + } + + }); + + @GetMapping("/page") + @Operation(summary = "获得拼团记录分页") + @PreAuthorize("@ss.hasPermission('promotion:combination-record:query')") + public CommonResult> getBargainRecordPage(@Valid CombinationRecordReqPageVO pageVO) { + return success(CombinationActivityConvert.INSTANCE.convert( + combinationRecordService.getBargainRecordPage(pageVO))); + } + + @GetMapping("/get-summary") + @Operation(summary = "获得拼团记录的概要信息", description = "用于拼团记录页面展示") + @PreAuthorize("@ss.hasPermission('promotion:combination-record:query')") + public CommonResult> getCombinationRecordSummary() { + return success(combinationRecordSummary.getUnchecked("")); // 缓存 + } + + @GetMapping("/get-count") + @Operation(summary = "获得拼团记录分页 tab count") + @PreAuthorize("@ss.hasPermission('promotion:combination-record:query')") + public CommonResult> getSpuCount() { + Map hashMap = MapUtil.newHashMap(7); + hashMap.put("all", combinationRecordService.getRecordsCountByDateType(CombinationRecordReqPageVO.ALL));// 全部 + hashMap.put("toDay", combinationRecordService.getRecordsCountByDateType(CombinationRecordReqPageVO.TO_DAY));// 今天 + hashMap.put("yesterday", combinationRecordService.getRecordsCountByDateType(CombinationRecordReqPageVO.YESTERDAY));// 昨天 + hashMap.put("lastSevenDays", combinationRecordService.getRecordsCountByDateType(CombinationRecordReqPageVO.LAST_SEVEN_DAYS));// 最近七天 + hashMap.put("last30Days", combinationRecordService.getRecordsCountByDateType(CombinationRecordReqPageVO.LAST_30_DAYS));// 最近 30 天 + hashMap.put("thisMonth", combinationRecordService.getRecordsCountByDateType(CombinationRecordReqPageVO.THIS_MONTH));// 本月 + hashMap.put("thisYear", combinationRecordService.getRecordsCountByDateType(CombinationRecordReqPageVO.THIS_YEAR));// 本年 + return success(hashMap); + } + + private Map getCombinationRecordSummary0() { + Map hashMap = MapUtil.newHashMap(3); + hashMap.put("userCount", combinationRecordService.getRecordsCount());// 获取所有拼团记录 + hashMap.put("successCount", combinationRecordService.getRecordsSuccessCount());// 获取成团记录 + hashMap.put("virtualGroupCount", combinationRecordService.getRecordsVirtualGroupCount());// 获取虚拟成团记录 + return hashMap; + } + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/recrod/CombinationRecordReqPageVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/recrod/CombinationRecordReqPageVO.java new file mode 100644 index 000000000..bf99dcb7c --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/recrod/CombinationRecordReqPageVO.java @@ -0,0 +1,38 @@ +package cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod; + +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; +import org.springframework.format.annotation.DateTimeFormat; + +import java.time.LocalDateTime; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +@Schema(description = "管理后台 - 拼团记录分页 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class CombinationRecordReqPageVO extends PageParam { + + public static final Integer ALL = 0; // 全部 + public static final Integer TO_DAY = 1; // 今天 + public static final Integer YESTERDAY = 2; // 昨天 + public static final Integer LAST_SEVEN_DAYS = 3; // 最近七天 + public static final Integer LAST_30_DAYS = 4; // 最近 30 天 + public static final Integer THIS_MONTH = 5; // 本月 + public static final Integer THIS_YEAR = 6; // 本年 + + @Schema(description = "日期类型", example = "0") + private Integer dateType; + + @Schema(description = "活动状态", example = "0") + private Integer status; + + @Schema(description = "创建时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime[] createTime; + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/recrod/CombinationRecordRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/recrod/CombinationRecordRespVO.java new file mode 100644 index 000000000..ab1a98607 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/recrod/CombinationRecordRespVO.java @@ -0,0 +1,60 @@ +package cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + +import java.time.LocalDateTime; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +@Schema(description = "管理后台 - 拼团记录 Response VO") +@Data +public class CombinationRecordRespVO { + + @Schema(description = "拼团记录编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + private Long id; + + @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) + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime expireTime; + + @Schema(description = "可参团人数", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") + private Integer userSize; + + @Schema(description = "已参团人数", requiredMode = Schema.RequiredMode.REQUIRED, example = "5") + private Integer userCount; + + @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; + + @Schema(description = "开始时间 (订单付款后开始的时间)", requiredMode = Schema.RequiredMode.REQUIRED) + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime startTime; + + @Schema(description = "结束时间(成团时间/失败时间)", requiredMode = Schema.RequiredMode.REQUIRED) + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime endTime; + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java index ebbb252a3..5419f53a4 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java @@ -12,6 +12,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.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.AppCombinationRecordRespVO; @@ -146,4 +147,6 @@ public interface CombinationActivityConvert { AppCombinationRecordRespVO convert(CombinationRecordDO record); + PageResult convert(PageResult result); + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationRecordMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationRecordMapper.java index 91117ad83..a9998852d 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationRecordMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationRecordMapper.java @@ -1,10 +1,15 @@ package cn.iocoder.yudao.module.promotion.dal.mysql.combination; +import cn.hutool.core.util.ObjectUtil; +import cn.iocoder.yudao.framework.common.pojo.PageResult; 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.CombinationRecordReqPageVO; import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationRecordDO; import org.apache.ibatis.annotations.Mapper; +import java.time.LocalDateTime; +import java.time.LocalTime; import java.util.List; /** @@ -90,4 +95,60 @@ public interface CombinationRecordMapper extends BaseMapperX selectPage(CombinationRecordReqPageVO pageVO) { + // 兼容自选时间段 + if (pageVO.getDateType() != null) { + pageVO.setCreateTime(builderQueryTime(pageVO.getDateType())); + } + return selectPage(pageVO, new LambdaQueryWrapperX() + .eqIfPresent(CombinationRecordDO::getStatus, pageVO.getStatus()) + .betweenIfPresent(CombinationRecordDO::getCreateTime, pageVO.getCreateTime())); + } + + default Long selectCount(Integer dateType) { + return selectCount(new LambdaQueryWrapperX() + .betweenIfPresent(CombinationRecordDO::getCreateTime, builderQueryTime(dateType))); + } + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordService.java index aeac753ad..e965764df 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordService.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordService.java @@ -1,8 +1,10 @@ package cn.iocoder.yudao.module.promotion.service.combination; 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.CombinationRecordReqPageVO; 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; @@ -93,6 +95,28 @@ public interface CombinationRecordService { */ Long getRecordsCount(); + /** + * 获取成功记录数 + * + * @return 记录数 + */ + Long getRecordsSuccessCount(); + + /** + * 获取虚拟成团记录数 + * + * @return 记录数 + */ + Long getRecordsVirtualGroupCount(); + + /** + * 获取指定日期类型的记录数,比如说获取最近七天的拼团记录数 + * + * @param dateType 日期类型 + * @return 记录数 + */ + Long getRecordsCountByDateType(Integer dateType); + /** * 获取最近的 count 条拼团记录 * @@ -127,4 +151,12 @@ public interface CombinationRecordService { */ List getRecordListByHeadId(Long headId); + /** + * 获取拼团记录分页数据 + * + * @param pageVO 分页请求 + * @return 拼团记录分页数据 + */ + PageResult getBargainRecordPage(CombinationRecordReqPageVO pageVO); + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java index aa87fb880..83d1dc018 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java +++ b/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; import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.core.KeyValue; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; +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; import cn.iocoder.yudao.module.product.api.sku.ProductSkuApi; @@ -12,6 +13,7 @@ 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.CombinationRecordReqPageVO; 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; @@ -225,6 +227,21 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { return recordMapper.selectCount(); } + @Override + public Long getRecordsSuccessCount() { + return recordMapper.selectCount(CombinationRecordDO::getStatus, CombinationRecordStatusEnum.SUCCESS.getStatus()); + } + + @Override + public Long getRecordsVirtualGroupCount() { + return recordMapper.selectCount(CombinationRecordDO::getVirtualGroup, true); + } + + @Override + public Long getRecordsCountByDateType(Integer dateType) { + return recordMapper.selectCount(dateType); + } + @Override public List getLatestRecordList(int count) { return recordMapper.selectLatestList(count); @@ -245,4 +262,9 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { return recordMapper.selectList(CombinationRecordDO::getHeadId, headId); } + @Override + public PageResult getBargainRecordPage(CombinationRecordReqPageVO pageVO) { + return recordMapper.selectPage(pageVO); + } + }