mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-22 15:21:53 +08:00
code review:拼团记录流程
This commit is contained in:
parent
6a38da4ad9
commit
99649bfdb8
@ -25,6 +25,7 @@ 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) {
|
||||
// 按照升序排序
|
||||
|
@ -61,6 +61,7 @@ public interface CombinationRecordApi {
|
||||
* @param count 数量
|
||||
* @return 拼团信息
|
||||
*/
|
||||
CombinationValidateJoinRespDTO validateJoinCombination(Long userId, Long activityId, Long headId, Long skuId, Integer count);
|
||||
CombinationValidateJoinRespDTO validateJoinCombination(Long userId, Long activityId, Long headId,
|
||||
Long skuId, Integer count);
|
||||
|
||||
}
|
||||
|
@ -35,12 +35,11 @@ public class CombinationRecordApiImpl implements CombinationRecordApi {
|
||||
|
||||
@Override
|
||||
public boolean isCombinationRecordSuccess(Long userId, Long orderId) {
|
||||
CombinationRecordDO combinationRecord = recordService.getCombinationRecord(userId, orderId);
|
||||
if (combinationRecord == null) {
|
||||
CombinationRecordDO record = recordService.getCombinationRecord(userId, orderId);
|
||||
if (record == null) {
|
||||
throw exception(COMBINATION_RECORD_NOT_EXISTS);
|
||||
}
|
||||
|
||||
return CombinationRecordStatusEnum.isSuccess(combinationRecord.getStatus());
|
||||
return CombinationRecordStatusEnum.isSuccess(record.getStatus());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -33,6 +33,8 @@ public class CombinationRecordController {
|
||||
|
||||
@Resource
|
||||
private CombinationRecordService combinationRecordService;
|
||||
|
||||
// TODO @puhui999:这个缓存不用做哈;主要管理后台,对性能要求不高;不像前段;
|
||||
/**
|
||||
* {@link Map} 缓存,通过它异步刷新 {@link #getCombinationRecordSummary0()} 所要的拼团记录统计数据
|
||||
*/
|
||||
@ -54,6 +56,7 @@ public class CombinationRecordController {
|
||||
combinationRecordService.getCombinationRecordPage(pageVO)));
|
||||
}
|
||||
|
||||
// TODO @puhui999:Map 改成对象,尽量避免 Map 返回结果哈;然后 getCombinationRecordCount、getCombinationRecordsSuccessCount、getRecordsVirtualGroupCount 三个方法,可以合并成一个方法哈,返回这个 vo
|
||||
@GetMapping("/get-summary")
|
||||
@Operation(summary = "获得拼团记录的概要信息", description = "用于拼团记录页面展示")
|
||||
@PreAuthorize("@ss.hasPermission('promotion:combination-record:query')")
|
||||
@ -61,26 +64,11 @@ public class CombinationRecordController {
|
||||
return success(combinationRecordSummary.getUnchecked("")); // 缓存
|
||||
}
|
||||
|
||||
@GetMapping("/get-count")
|
||||
@Operation(summary = "获得拼团记录分页 tab count")
|
||||
@PreAuthorize("@ss.hasPermission('promotion:combination-record:query')")
|
||||
public CommonResult<Map<String, Long>> getCombinationRecordCount() {
|
||||
Map<String, Long> hashMap = MapUtil.newHashMap(7);
|
||||
hashMap.put("all", combinationRecordService.getCombinationRecordsCountByDateType(CombinationRecordReqPageVO.ALL));// 全部
|
||||
hashMap.put("toDay", combinationRecordService.getCombinationRecordsCountByDateType(CombinationRecordReqPageVO.TO_DAY));// 今天
|
||||
hashMap.put("yesterday", combinationRecordService.getCombinationRecordsCountByDateType(CombinationRecordReqPageVO.YESTERDAY));// 昨天
|
||||
hashMap.put("lastSevenDays", combinationRecordService.getCombinationRecordsCountByDateType(CombinationRecordReqPageVO.LAST_SEVEN_DAYS));// 最近七天
|
||||
hashMap.put("last30Days", combinationRecordService.getCombinationRecordsCountByDateType(CombinationRecordReqPageVO.LAST_30_DAYS));// 最近 30 天
|
||||
hashMap.put("thisMonth", combinationRecordService.getCombinationRecordsCountByDateType(CombinationRecordReqPageVO.THIS_MONTH));// 本月
|
||||
hashMap.put("thisYear", combinationRecordService.getCombinationRecordsCountByDateType(CombinationRecordReqPageVO.THIS_YEAR));// 本年
|
||||
return success(hashMap);
|
||||
}
|
||||
|
||||
private Map<String, Long> getCombinationRecordSummary0() {
|
||||
Map<String, Long> hashMap = MapUtil.newHashMap(3);
|
||||
hashMap.put("userCount", combinationRecordService.getCombinationRecordCount());// 获取所有拼团记录
|
||||
hashMap.put("successCount", combinationRecordService.getCombinationRecordsSuccessCount());// 获取成团记录
|
||||
hashMap.put("virtualGroupCount", combinationRecordService.getRecordsVirtualGroupCount());// 获取虚拟成团记录
|
||||
Map<String, Long> hashMap = MapUtil.newHashMap(3); // TODO @puhui999:Maps.newHashMapWithExpectedSize()
|
||||
hashMap.put("userCount", combinationRecordService.getCombinationRecordCount()); // 获取所有拼团记录
|
||||
hashMap.put("successCount", combinationRecordService.getCombinationRecordsSuccessCount()); // 获取成团记录
|
||||
hashMap.put("virtualGroupCount", combinationRecordService.getRecordsVirtualGroupCount()); // 获取虚拟成团记录
|
||||
return hashMap;
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
package cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.validation.InEnum;
|
||||
import cn.iocoder.yudao.module.promotion.enums.bargain.BargainRecordStatusEnum;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@ -17,18 +19,8 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
|
||||
@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")
|
||||
@Schema(description = "活动状态", example = "1")
|
||||
@InEnum(BargainRecordStatusEnum.class)
|
||||
private Integer status;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
|
@ -8,6 +8,7 @@ import java.time.LocalDateTime;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
// TODO @puhui999:可以参考 BargainRecordPageItemRespVO、BargainRecordRespVO 分成两个;一个给记录列表,一个给记录分页
|
||||
@Schema(description = "管理后台 - 拼团记录 Response VO")
|
||||
@Data
|
||||
public class CombinationRecordRespVO {
|
||||
|
@ -108,6 +108,7 @@ public interface CombinationActivityConvert {
|
||||
|
||||
CombinationRecordDO convert(CombinationRecordCreateReqDTO reqDTO);
|
||||
|
||||
// TODO @芋艿:在 convert 优化下;
|
||||
default CombinationRecordDO convert(CombinationRecordCreateReqDTO reqDTO,
|
||||
CombinationActivityDO activity, MemberUserRespDTO user,
|
||||
ProductSpuRespDTO spu, ProductSkuRespDTO sku) {
|
||||
|
@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.promotion.dal.mysql.combination;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
@ -12,8 +11,6 @@ import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationR
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@ -44,12 +41,6 @@ public interface CombinationRecordMapper extends BaseMapperX<CombinationRecordDO
|
||||
.eq(CombinationRecordDO::getStatus, status));
|
||||
}
|
||||
|
||||
default List<CombinationRecordDO> selectListByHeadIdAndStatus(Long headId, Integer status) {
|
||||
return selectList(new LambdaQueryWrapperX<CombinationRecordDO>()
|
||||
.eq(CombinationRecordDO::getHeadId, headId)
|
||||
.eq(CombinationRecordDO::getStatus, status));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询拼团记录
|
||||
*
|
||||
@ -103,60 +94,10 @@ public interface CombinationRecordMapper extends BaseMapperX<CombinationRecordDO
|
||||
record -> MapUtil.getInt(record, "recordCount"));
|
||||
}
|
||||
|
||||
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)));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -104,14 +104,6 @@ public interface CombinationRecordService {
|
||||
*/
|
||||
Long getRecordsVirtualGroupCount();
|
||||
|
||||
/**
|
||||
* 获取指定日期类型的记录数,比如说获取最近七天的拼团记录数
|
||||
*
|
||||
* @param dateType 日期类型
|
||||
* @return 记录数
|
||||
*/
|
||||
Long getCombinationRecordsCountByDateType(Integer dateType);
|
||||
|
||||
/**
|
||||
* 获取最近的 count 条拼团记录
|
||||
*
|
||||
|
@ -262,19 +262,16 @@ public class CombinationRecordServiceImpl implements CombinationRecordService {
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getCombinationRecordsCountByDateType(Integer dateType) {
|
||||
return recordMapper.selectCount(dateType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CombinationRecordDO> getLatestCombinationRecordList(int count) {
|
||||
return recordMapper.selectLatestList(count);
|
||||
|
@ -178,6 +178,7 @@ public interface TradeOrderUpdateService {
|
||||
* @param combinationRecordId 拼团记录编号
|
||||
* @param headId 团长编号
|
||||
*/
|
||||
// TODO 芋艿:再 review 拼团
|
||||
void updateOrderCombinationInfo(Long orderId, Long activityId, Long combinationRecordId, Long headId);
|
||||
|
||||
/**
|
||||
|
@ -43,7 +43,6 @@ public class TradeCombinationHandler implements TradeOrderHandler {
|
||||
if (TradeOrderTypeEnum.isCombination(order.getType())) {
|
||||
return;
|
||||
}
|
||||
|
||||
Assert.isTrue(orderItems.size() == 1, "拼团时,只允许选择一个商品");
|
||||
|
||||
// 获取商品信息
|
||||
|
Loading…
Reference in New Issue
Block a user