拼团记录:添加拼团记录后台管理接口

This commit is contained in:
puhui999 2023-10-06 20:27:22 +08:00
parent 3d51c67f1a
commit ce77d510bb
7 changed files with 303 additions and 0 deletions

View File

@ -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<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.getBargainRecordPage(pageVO)));
}
@GetMapping("/get-summary")
@Operation(summary = "获得拼团记录的概要信息", description = "用于拼团记录页面展示")
@PreAuthorize("@ss.hasPermission('promotion:combination-record:query')")
public CommonResult<Map<String, Long>> getCombinationRecordSummary() {
return success(combinationRecordSummary.getUnchecked("")); // 缓存
}
@GetMapping("/get-count")
@Operation(summary = "获得拼团记录分页 tab count")
@PreAuthorize("@ss.hasPermission('promotion:combination-record:query')")
public CommonResult<Map<String, Long>> getSpuCount() {
Map<String, Long> 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<String, Long> getCombinationRecordSummary0() {
Map<String, Long> hashMap = MapUtil.newHashMap(3);
hashMap.put("userCount", combinationRecordService.getRecordsCount());// 获取所有拼团记录
hashMap.put("successCount", combinationRecordService.getRecordsSuccessCount());// 获取成团记录
hashMap.put("virtualGroupCount", combinationRecordService.getRecordsVirtualGroupCount());// 获取虚拟成团记录
return hashMap;
}
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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<CombinationRecordRespVO> convert(PageResult<CombinationRecordDO> result);
}

View File

@ -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<CombinationRecordDO
.last("LIMIT " + count));
}
static LocalDateTime[] builderQueryTime(Integer dateType) {
LocalDateTime now = LocalDateTime.now();
LocalDateTime[] createTime = null; // 全部时间段
// 今天-一天开始到结束
if (ObjectUtil.equal(dateType, CombinationRecordReqPageVO.TO_DAY)) {
createTime = new LocalDateTime[]{now.toLocalDate().atStartOfDay(), now.toLocalDate().atTime(LocalTime.MAX)};
}
// 昨天-昨天开始和结束
if (ObjectUtil.equal(dateType, CombinationRecordReqPageVO.YESTERDAY)) {
createTime = new LocalDateTime[]{now.minusDays(1).toLocalDate().atStartOfDay(),
now.minusDays(1).toLocalDate().atTime(LocalTime.MAX)};
}
// 最近七天
if (ObjectUtil.equal(dateType, CombinationRecordReqPageVO.LAST_SEVEN_DAYS)) {
createTime = new LocalDateTime[]{now.minusDays(7).toLocalDate().atStartOfDay(),
now.toLocalDate().atTime(LocalTime.MAX)};
}
// 最近 30
if (ObjectUtil.equal(dateType, CombinationRecordReqPageVO.LAST_30_DAYS)) {
createTime = new LocalDateTime[]{now.minusDays(30).toLocalDate().atStartOfDay(),
now.toLocalDate().atTime(LocalTime.MAX)};
}
// 本月
if (ObjectUtil.equal(dateType, CombinationRecordReqPageVO.THIS_MONTH)) {
// 获取本月的开始时间
LocalDateTime startTime = now.withDayOfMonth(1).toLocalDate().atStartOfDay();
// 获取下个月的开始时间然后减去一秒以获取本月的结束时间
LocalDateTime endTime = now.withDayOfMonth(1).plusMonths(1).toLocalDate().atStartOfDay().minusSeconds(1);
createTime = new LocalDateTime[]{startTime, endTime};
}
// 本年
if (ObjectUtil.equal(dateType, CombinationRecordReqPageVO.THIS_YEAR)) {
// 获取本年的开始时间
LocalDateTime startTime = now.withDayOfYear(1).toLocalDate().atStartOfDay();
// 获取下一年的开始时间然后减去一秒以获取本年的结束时间
LocalDateTime endTime = now.withDayOfYear(1).plusYears(1).toLocalDate().atStartOfDay().minusSeconds(1);
createTime = new LocalDateTime[]{startTime, endTime};
}
return createTime;
}
default PageResult<CombinationRecordDO> selectPage(CombinationRecordReqPageVO pageVO) {
// 兼容自选时间段
if (pageVO.getDateType() != null) {
pageVO.setCreateTime(builderQueryTime(pageVO.getDateType()));
}
return selectPage(pageVO, new LambdaQueryWrapperX<CombinationRecordDO>()
.eqIfPresent(CombinationRecordDO::getStatus, pageVO.getStatus())
.betweenIfPresent(CombinationRecordDO::getCreateTime, pageVO.getCreateTime()));
}
default Long selectCount(Integer dateType) {
return selectCount(new LambdaQueryWrapperX<CombinationRecordDO>()
.betweenIfPresent(CombinationRecordDO::getCreateTime, builderQueryTime(dateType)));
}
}

View File

@ -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<CombinationRecordDO> getRecordListByHeadId(Long headId);
/**
* 获取拼团记录分页数据
*
* @param pageVO 分页请求
* @return 拼团记录分页数据
*/
PageResult<CombinationRecordDO> getBargainRecordPage(CombinationRecordReqPageVO pageVO);
}

View File

@ -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<CombinationRecordDO> 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<CombinationRecordDO> getBargainRecordPage(CombinationRecordReqPageVO pageVO) {
return recordMapper.selectPage(pageVO);
}
}