mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-22 23:31:52 +08:00
fix:seckill:调整相关类属性和表字段对齐
This commit is contained in:
parent
16f2a5b91a
commit
1871a01944
@ -16,6 +16,13 @@ import java.util.List;
|
||||
@ToString(callSuper = true)
|
||||
public class SeckillActivityCreateReqVO extends SeckillActivityBaseVO {
|
||||
|
||||
/**
|
||||
* 秒杀活动商品
|
||||
*/
|
||||
@Schema(description = "秒杀活动商品", example = "1")
|
||||
@NotNull(message = "秒杀活动商品不能为空")
|
||||
private Long spuId;
|
||||
|
||||
@Schema(description = "备注", example = "限时秒杀活动")
|
||||
private String remark;
|
||||
|
||||
@ -25,7 +32,7 @@ public class SeckillActivityCreateReqVO extends SeckillActivityBaseVO {
|
||||
|
||||
@Schema(description = "秒杀时段id", requiredMode = Schema.RequiredMode.REQUIRED, example = "1,3")
|
||||
@NotEmpty(message = "参与场次不能为空")
|
||||
private List<Long> timeIds;
|
||||
private List<Long> configIds;
|
||||
|
||||
/**
|
||||
* 商品列表
|
||||
|
@ -26,7 +26,7 @@ public class SeckillActivityPageReqVO extends PageParam {
|
||||
private Integer status;
|
||||
|
||||
@Schema(description = "秒杀时段id", example = "1")
|
||||
private Long timeId;
|
||||
private Long configId;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
|
@ -17,7 +17,7 @@ public class SeckillActivityRespVO extends SeckillActivityBaseVO {
|
||||
@Schema(description = "秒杀活动id", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "付款订单数", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
@Schema(description = "新增订单数", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
private Integer orderCount;
|
||||
|
||||
@Schema(description = "付款人数", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
@ -27,7 +27,7 @@ public class SeckillActivityRespVO extends SeckillActivityBaseVO {
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@Schema(description = "秒杀时段id", requiredMode = Schema.RequiredMode.REQUIRED, example = "1,3")
|
||||
private List<Long> timeIds;
|
||||
private List<Long> configIds;
|
||||
|
||||
@Schema(description = "排序", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
private Integer sort;
|
||||
|
@ -29,7 +29,7 @@ public class SeckillActivityUpdateReqVO extends SeckillActivityBaseVO {
|
||||
|
||||
@Schema(description = "秒杀时段id", requiredMode = Schema.RequiredMode.REQUIRED, example = "1,3")
|
||||
@NotEmpty(message = "秒杀时段id不能为空")
|
||||
private List<Long> timeIds;
|
||||
private List<Long> configIds;
|
||||
|
||||
/**
|
||||
* 商品列表
|
||||
|
@ -2,12 +2,8 @@ package cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.config;
|
||||
|
||||
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.LocalTime;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_HOUR_MINUTE_SECOND;
|
||||
|
||||
/**
|
||||
* 秒杀时段 Base VO,提供给添加、修改、详细的子 VO 使用
|
||||
@ -24,13 +20,11 @@ public class SeckillConfigBaseVO {
|
||||
|
||||
@Schema(description = "开始时间点", requiredMode = Schema.RequiredMode.REQUIRED, example = "09:00:00")
|
||||
@NotNull(message = "开始时间点不能为空")
|
||||
@DateTimeFormat(pattern = FORMAT_HOUR_MINUTE_SECOND)
|
||||
private LocalTime startTime;
|
||||
private String startTime;
|
||||
|
||||
@Schema(description = "结束时间点", requiredMode = Schema.RequiredMode.REQUIRED, example = "16:00:00")
|
||||
@NotNull(message = "结束时间点不能为空")
|
||||
@DateTimeFormat(pattern = FORMAT_HOUR_MINUTE_SECOND)
|
||||
private LocalTime endTime;
|
||||
private String endTime;
|
||||
|
||||
@Schema(description = "秒杀主图", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn")
|
||||
@NotNull(message = "秒杀主图不能为空")
|
||||
|
@ -5,9 +5,6 @@ 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.LocalTime;
|
||||
|
||||
/**
|
||||
* 管理后台 - 秒杀时段分页 Request VO
|
||||
@ -26,12 +23,4 @@ public class SeckillConfigPageReqVO extends PageParam {
|
||||
@Schema(description = "状态", example = "0")
|
||||
private Integer status;
|
||||
|
||||
@Schema(description = "开始时间点", example = "16:30:40")
|
||||
@DateTimeFormat(pattern = "HH:mm:ss")
|
||||
private LocalTime[] startTime;
|
||||
|
||||
@Schema(description = "结束时间点", example = "16:30:40")
|
||||
@DateTimeFormat(pattern = "HH:mm:ss")
|
||||
private LocalTime[] endTime;
|
||||
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ public interface SeckillActivityConvert {
|
||||
return ObjectUtil.equals(productDO.getSpuId(), productVO.getSpuId())
|
||||
&& ObjectUtil.equals(productDO.getSkuId(), productVO.getSkuId())
|
||||
&& ObjectUtil.equals(productDO.getSeckillPrice(), productVO.getSeckillPrice())
|
||||
&& ObjectUtil.equals(productDO.getStock(), productVO.getStock())
|
||||
&& ObjectUtil.equals(productDO.getQuota(), productVO.getQuota())
|
||||
&& ObjectUtil.equals(productDO.getLimitCount(), productVO.getLimitCount());
|
||||
}
|
||||
|
||||
@ -70,14 +70,14 @@ public interface SeckillActivityConvert {
|
||||
return ObjectUtil.equals(productDO.getSpuId(), productVO.getSpuId())
|
||||
&& ObjectUtil.equals(productDO.getSkuId(), productVO.getSkuId())
|
||||
&& ObjectUtil.equals(productDO.getSeckillPrice(), productVO.getSeckillPrice())
|
||||
&& ObjectUtil.equals(productDO.getStock(), productVO.getStock())
|
||||
&& ObjectUtil.equals(productDO.getQuota(), productVO.getQuota())
|
||||
&& ObjectUtil.equals(productDO.getLimitCount(), productVO.getLimitCount());
|
||||
|
||||
}
|
||||
|
||||
default List<SeckillProductDO> convertList(List<SeckillActivityBaseVO.Product> products, SeckillActivityDO seckillActivity) {
|
||||
return CollectionUtils.convertList(products, product -> convert(product)
|
||||
.setActivityId(seckillActivity.getId()).setTimeIds(seckillActivity.getTimeIds()));
|
||||
.setActivityId(seckillActivity.getId()).setConfigIds(seckillActivity.getConfigIds()));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.config.Seck
|
||||
import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.config.SeckillConfigUpdateReqVO;
|
||||
import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillconfig.SeckillConfigDO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
@ -25,7 +24,6 @@ public interface SeckillConfigConvert {
|
||||
|
||||
SeckillConfigDO convert(SeckillConfigUpdateReqVO bean);
|
||||
|
||||
@Mapping(target = "s")
|
||||
SeckillConfigRespVO convert(SeckillConfigDO bean);
|
||||
|
||||
List<SeckillConfigRespVO> convertList(List<SeckillConfigDO> list);
|
||||
|
@ -31,13 +31,17 @@ public class SeckillActivityDO extends BaseDO {
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
/**
|
||||
* 秒杀活动商品
|
||||
*/
|
||||
private Long spuId;
|
||||
/**
|
||||
* 秒杀活动名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 活动状态
|
||||
*
|
||||
* <p>
|
||||
* 枚举 {@link PromotionActivityStatusEnum 对应的类}
|
||||
*/
|
||||
private Integer status;
|
||||
@ -61,9 +65,9 @@ public class SeckillActivityDO extends BaseDO {
|
||||
* 秒杀时段 id
|
||||
*/
|
||||
@TableField(typeHandler = LongListTypeHandler.class)
|
||||
private List<Long> timeIds;
|
||||
private List<Long> configIds;
|
||||
/**
|
||||
* 付款订单数
|
||||
* 新增订单数
|
||||
*/
|
||||
private Integer orderCount;
|
||||
/**
|
||||
|
@ -21,6 +21,7 @@ import java.util.List;
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class SeckillProductDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* 秒杀参与商品编号
|
||||
*/
|
||||
@ -36,7 +37,7 @@ public class SeckillProductDO extends BaseDO {
|
||||
* 秒杀时段id
|
||||
*/
|
||||
@TableField(typeHandler = LongListTypeHandler.class)
|
||||
private List<Long> timeIds;
|
||||
private List<Long> configIds;
|
||||
|
||||
/**
|
||||
* 商品id
|
||||
@ -53,9 +54,8 @@ public class SeckillProductDO extends BaseDO {
|
||||
*/
|
||||
private Integer seckillPrice;
|
||||
|
||||
// TODO @芋艿:改成 quota 限量库存;每次购买时,需要减小;
|
||||
/**
|
||||
* 秒杀库存
|
||||
* 秒杀库存 限量库存;每次购买时,需要减小;
|
||||
*/
|
||||
private Integer quota;
|
||||
|
||||
|
@ -9,8 +9,6 @@ import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.time.LocalTime;
|
||||
|
||||
/**
|
||||
* 秒杀时段 DO
|
||||
*
|
||||
@ -35,11 +33,11 @@ public class SeckillConfigDO extends BaseDO {
|
||||
/**
|
||||
* 开始时间点
|
||||
*/
|
||||
private LocalTime startTime;
|
||||
private String startTime;
|
||||
/**
|
||||
* 结束时间点
|
||||
*/
|
||||
private LocalTime endTime;
|
||||
private String endTime;
|
||||
/**
|
||||
* 秒杀主图
|
||||
*/
|
||||
|
@ -20,7 +20,7 @@ public interface SeckillActivityMapper extends BaseMapperX<SeckillActivityDO> {
|
||||
.likeIfPresent(SeckillActivityDO::getName, reqVO.getName())
|
||||
.eqIfPresent(SeckillActivityDO::getStatus, reqVO.getStatus())
|
||||
.betweenIfPresent(SeckillActivityDO::getCreateTime, reqVO.getCreateTime())
|
||||
.apply(ObjectUtil.isNotNull(reqVO.getTimeId()),"FIND_IN_SET(" + reqVO.getTimeId() + ",time_ids) > 0")
|
||||
.apply(ObjectUtil.isNotNull(reqVO.getConfigId()), "FIND_IN_SET(" + reqVO.getConfigId() + ",time_ids) > 0")
|
||||
.orderByDesc(SeckillActivityDO::getId));
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ public interface SeckillProductMapper extends BaseMapperX<SeckillProductDO> {
|
||||
|
||||
default void updateTimeIdsByActivityId(Long id, List<Long> timeIds) {
|
||||
new LambdaUpdateChainWrapper<>(this)
|
||||
.set(SeckillProductDO::getTimeIds, CollUtil.join(timeIds, ","))
|
||||
.set(SeckillProductDO::getConfigIds, CollUtil.join(timeIds, ","))
|
||||
.eq(SeckillProductDO::getActivityId, id)
|
||||
.update();
|
||||
}
|
||||
|
@ -36,8 +36,6 @@ public interface SeckillConfigMapper extends BaseMapperX<SeckillConfigDO> {
|
||||
default PageResult<SeckillConfigDO> selectPage(SeckillConfigPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<SeckillConfigDO>()
|
||||
.likeIfPresent(SeckillConfigDO::getName, reqVO.getName())
|
||||
.betweenIfPresent(SeckillConfigDO::getStartTime, reqVO.getStartTime())
|
||||
.betweenIfPresent(SeckillConfigDO::getEndTime, reqVO.getEndTime())
|
||||
.eqIfPresent(SeckillConfigDO::getStatus, reqVO.getStatus())
|
||||
.orderByDesc(SeckillConfigDO::getId));
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ public class SeckillActivityServiceImpl implements SeckillActivityService {
|
||||
// 校验商品是否冲突
|
||||
validateSeckillActivityProductConflicts(null, createReqVO.getProducts());
|
||||
// 校验秒杀时段是否存在
|
||||
seckillConfigService.validateSeckillConfigExists(createReqVO.getTimeIds());
|
||||
seckillConfigService.validateSeckillConfigExists(createReqVO.getConfigIds());
|
||||
|
||||
// 插入秒杀活动
|
||||
SeckillActivityDO seckillActivity = SeckillActivityConvert.INSTANCE.convert(createReqVO)
|
||||
@ -57,7 +57,7 @@ public class SeckillActivityServiceImpl implements SeckillActivityService {
|
||||
List<SeckillProductDO> productDOs = SeckillActivityConvert.INSTANCE.convertList(createReqVO.getProducts(), seckillActivity);
|
||||
seckillProductMapper.insertBatch(productDOs);
|
||||
// 更新秒杀时段的秒杀活动数量
|
||||
seckillConfigService.seckillActivityCountIncr(createReqVO.getTimeIds());
|
||||
seckillConfigService.seckillActivityCountIncr(createReqVO.getConfigIds());
|
||||
return seckillActivity.getId();
|
||||
}
|
||||
|
||||
@ -78,7 +78,7 @@ public class SeckillActivityServiceImpl implements SeckillActivityService {
|
||||
// 更新商品
|
||||
updateSeckillProduct(updateReqVO);
|
||||
// 更新秒杀时段的秒杀活动数量
|
||||
updateSeckillConfigActivityCount(seckillActivity, updateReqVO.getTimeIds());
|
||||
updateSeckillConfigActivityCount(seckillActivity, updateReqVO.getConfigIds());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -89,7 +89,7 @@ public class SeckillActivityServiceImpl implements SeckillActivityService {
|
||||
*/
|
||||
private void updateSeckillConfigActivityCount(SeckillActivityDO seckillActivity, List<Long> updateTimeIds) {
|
||||
// 查询出 timeIds
|
||||
List<Long> existsTimeIds = seckillActivity.getTimeIds();
|
||||
List<Long> existsTimeIds = seckillActivity.getConfigIds();
|
||||
// 需要减少的时间段
|
||||
Collection<Long> reduceIds = CollUtil.filterNew(existsTimeIds, existsTimeId -> !updateTimeIds.contains(existsTimeId));
|
||||
// 需要添加的时间段
|
||||
@ -134,7 +134,7 @@ public class SeckillActivityServiceImpl implements SeckillActivityService {
|
||||
}
|
||||
|
||||
//全量更新当前活动商品的秒杀时段id列表(timeIds)
|
||||
seckillProductMapper.updateTimeIdsByActivityId(updateReqVO.getId(), updateReqVO.getTimeIds());
|
||||
seckillProductMapper.updateTimeIdsByActivityId(updateReqVO.getId(), updateReqVO.getConfigIds());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -190,7 +190,7 @@ public class SeckillActivityServiceImpl implements SeckillActivityService {
|
||||
throw exception(SECKILL_ACTIVITY_DELETE_FAIL_STATUS_NOT_CLOSED_OR_END);
|
||||
}
|
||||
// 更新秒杀时段的秒杀活动数量
|
||||
seckillConfigService.seckillActivityCountDecr(seckillActivity.getTimeIds());
|
||||
seckillConfigService.seckillActivityCountDecr(seckillActivity.getConfigIds());
|
||||
// 删除
|
||||
seckillActivityMapper.deleteById(id);
|
||||
}
|
||||
|
@ -36,7 +36,8 @@ public class SeckillConfigServiceImpl implements SeckillConfigService {
|
||||
@Override
|
||||
public Long createSeckillConfig(SeckillConfigCreateReqVO createReqVO) {
|
||||
// 校验时间段是否冲突
|
||||
validateSeckillConfigConflict(null, createReqVO.getStartTime(), createReqVO.getEndTime());
|
||||
//validateSeckillConfigConflict(null, createReqVO.getStartTime(), createReqVO.getEndTime());
|
||||
|
||||
// 插入
|
||||
SeckillConfigDO seckillConfig = SeckillConfigConvert.INSTANCE.convert(createReqVO);
|
||||
seckillConfigMapper.insert(seckillConfig);
|
||||
@ -49,7 +50,8 @@ public class SeckillConfigServiceImpl implements SeckillConfigService {
|
||||
// 校验存在
|
||||
this.validateSeckillConfigExists(updateReqVO.getId());
|
||||
// 校验时间段是否冲突
|
||||
validateSeckillConfigConflict(updateReqVO.getId(), updateReqVO.getStartTime(), updateReqVO.getEndTime());
|
||||
//validateSeckillConfigConflict(updateReqVO.getId(), updateReqVO.getStartTime(), updateReqVO.getEndTime());
|
||||
|
||||
// 更新
|
||||
SeckillConfigDO updateObj = SeckillConfigConvert.INSTANCE.convert(updateReqVO);
|
||||
seckillConfigMapper.updateById(updateObj);
|
||||
@ -77,6 +79,7 @@ public class SeckillConfigServiceImpl implements SeckillConfigService {
|
||||
*/
|
||||
private void validateSeckillConfigConflict(Long id, LocalTime startTime, LocalTime endTime) {
|
||||
//查询开始时间,结束时间,是否在别人的时间段内
|
||||
// TODO 为什么要检查这个时间段是否冲突 比如早上 09:00:00 - 10:00:00 我再添加一个 09:00:00 - 09:30:00 不可以这样吗?
|
||||
List<SeckillConfigDO> startTimeList = seckillConfigMapper.selectListByTime(startTime);
|
||||
List<SeckillConfigDO> endTimeList = seckillConfigMapper.selectListByTime(endTime);
|
||||
//查询自己时间段内是否有时间段
|
||||
|
@ -108,7 +108,7 @@ public class SeckillActivityServiceImplTest extends BaseDbUnitTest {
|
||||
SeckillActivityDO dbSeckillActivity = randomPojo(SeckillActivityDO.class, o -> { // 等会查询到
|
||||
o.setName(null);
|
||||
o.setStatus(null);
|
||||
o.setTimeIds(null);
|
||||
o.setConfigIds(null);
|
||||
o.setCreateTime(null);
|
||||
});
|
||||
seckillActivityMapper.insert(dbSeckillActivity);
|
||||
@ -117,15 +117,15 @@ public class SeckillActivityServiceImplTest extends BaseDbUnitTest {
|
||||
// 测试 status 不匹配
|
||||
seckillActivityMapper.insert(cloneIgnoreId(dbSeckillActivity, o -> o.setStatus(null)));
|
||||
// 测试 timeId 不匹配
|
||||
seckillActivityMapper.insert(cloneIgnoreId(dbSeckillActivity, o -> o.setTimeIds(null)));
|
||||
seckillActivityMapper.insert(cloneIgnoreId(dbSeckillActivity, o -> o.setConfigIds(null)));
|
||||
// 测试 createTime 不匹配
|
||||
seckillActivityMapper.insert(cloneIgnoreId(dbSeckillActivity, o -> o.setCreateTime(null)));
|
||||
// 准备参数
|
||||
SeckillActivityPageReqVO reqVO = new SeckillActivityPageReqVO();
|
||||
reqVO.setName(null);
|
||||
reqVO.setStatus(null);
|
||||
reqVO.setTimeId(null);
|
||||
reqVO.setCreateTime((new LocalDateTime[]{}));
|
||||
reqVO.setStatus(null);
|
||||
reqVO.setConfigId(null);
|
||||
reqVO.setCreateTime((new LocalDateTime[]{}));
|
||||
|
||||
// 调用
|
||||
PageResult<SeckillActivityDO> pageResult = seckillActivityService.getSeckillActivityPage(reqVO);
|
||||
@ -142,7 +142,7 @@ public class SeckillActivityServiceImplTest extends BaseDbUnitTest {
|
||||
SeckillActivityDO dbSeckillActivity = randomPojo(SeckillActivityDO.class, o -> { // 等会查询到
|
||||
o.setName(null);
|
||||
o.setStatus(null);
|
||||
o.setTimeIds(null);
|
||||
o.setConfigIds(null);
|
||||
o.setCreateTime(null);
|
||||
});
|
||||
seckillActivityMapper.insert(dbSeckillActivity);
|
||||
@ -151,7 +151,7 @@ public class SeckillActivityServiceImplTest extends BaseDbUnitTest {
|
||||
// 测试 status 不匹配
|
||||
seckillActivityMapper.insert(cloneIgnoreId(dbSeckillActivity, o -> o.setStatus(null)));
|
||||
// 测试 timeId 不匹配
|
||||
seckillActivityMapper.insert(cloneIgnoreId(dbSeckillActivity, o -> o.setTimeIds(null)));
|
||||
seckillActivityMapper.insert(cloneIgnoreId(dbSeckillActivity, o -> o.setConfigIds(null)));
|
||||
// 测试 createTime 不匹配
|
||||
seckillActivityMapper.insert(cloneIgnoreId(dbSeckillActivity, o -> o.setCreateTime(null)));
|
||||
// 准备参数
|
||||
|
Loading…
Reference in New Issue
Block a user