完成秒杀时段,秒杀活动相关todo

pull/2/head
halfninety 2022-12-02 22:33:07 +08:00
parent 0b9ddddd18
commit abbb076859
30 changed files with 160 additions and 191 deletions

View File

@ -2,6 +2,7 @@ package cn.iocoder.yudao.framework.mybatis.core.mapper;
import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.util.MyBatisUtils; import cn.iocoder.yudao.framework.mybatis.core.util.MyBatisUtils;
import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@ -75,9 +76,13 @@ public interface BaseMapperX<T> extends BaseMapper<T> {
return selectList(new LambdaQueryWrapper<T>().in(field, values)); return selectList(new LambdaQueryWrapper<T>().in(field, values));
} }
default List<T> selectList(SFunction<T, ?> leField, SFunction<T, ?> geField, Object value) {
return selectList(new LambdaQueryWrapper<T>().le(leField, value).ge(geField, value));
}
/** /**
* *
* * <p>
* 使 {@link com.baomidou.mybatisplus.extension.service.impl.ServiceImpl#saveBatch(Collection)} * 使 {@link com.baomidou.mybatisplus.extension.service.impl.ServiceImpl#saveBatch(Collection)}
* 使 RoleMenuBatchInsertMapperUserRoleBatchInsertMapper * 使 RoleMenuBatchInsertMapperUserRoleBatchInsertMapper
* *

View File

@ -1,8 +1,8 @@
package cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckillactivity; package cn.iocoder.yudao.module.promotion.controller.admin.seckill;
import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckillactivity.vo.*; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.*;
import cn.iocoder.yudao.module.promotion.convert.seckill.seckillactivity.SeckillActivityConvert; import cn.iocoder.yudao.module.promotion.convert.seckill.seckillactivity.SeckillActivityConvert;
import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity.SeckillActivityDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity.SeckillActivityDO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity.SeckillProductDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity.SeckillProductDO;

View File

@ -1,9 +1,9 @@
package cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckilltime; package cn.iocoder.yudao.module.promotion.controller.admin.seckill;
import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckilltime.vo.SeckillTimeCreateReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.time.SeckillTimeCreateReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckilltime.vo.SeckillTimeRespVO; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.time.SeckillTimeRespVO;
import cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckilltime.vo.SeckillTimeUpdateReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.time.SeckillTimeUpdateReqVO;
import cn.iocoder.yudao.module.promotion.convert.seckill.seckilltime.SeckillTimeConvert; import cn.iocoder.yudao.module.promotion.convert.seckill.seckilltime.SeckillTimeConvert;
import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckilltime.SeckillTimeDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckilltime.SeckillTimeDO;
import cn.iocoder.yudao.module.promotion.service.seckill.seckilltime.SeckillTimeService; import cn.iocoder.yudao.module.promotion.service.seckill.seckilltime.SeckillTimeService;
@ -20,7 +20,6 @@ import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
// TODO @halfninetycontroller 可以都放在 seckill 包下vo 下分成 actvity 和 time
@Api(tags = "管理后台 - 秒杀时段") @Api(tags = "管理后台 - 秒杀时段")
@RestController @RestController
@RequestMapping("/promotion/seckill-time") @RequestMapping("/promotion/seckill-time")
@ -65,20 +64,9 @@ public class SeckillTimeController {
@GetMapping("/list") @GetMapping("/list")
@ApiOperation("获得所有秒杀时段列表") @ApiOperation("获得所有秒杀时段列表")
// @PreAuthorize("@ss.hasPermission('promotion:seckill-time:query')") @PreAuthorize("@ss.hasPermission('promotion:seckill-time:query')")
// TODO @halfninety权限为啥注释掉呀
public CommonResult<List<SeckillTimeRespVO>> getSeckillTimeList() { public CommonResult<List<SeckillTimeRespVO>> getSeckillTimeList() {
List<SeckillTimeDO> list = seckillTimeService.getSeckillTimeList(); List<SeckillTimeDO> list = seckillTimeService.getSeckillTimeList();
return success(SeckillTimeConvert.INSTANCE.convertList(list)); return success(SeckillTimeConvert.INSTANCE.convertList(list));
} }
// TODO @halfninety不用的可以删除掉
// @GetMapping("/page")
// @ApiOperation("获得秒杀时段分页")
// @PreAuthorize("@ss.hasPermission('promotion:seckill-time:query')")
// public CommonResult<PageResult<SeckillTimeRespVO>> getSeckillTimePage(@Valid SeckillTimePageReqVO pageVO) {
// PageResult<SeckillTimeDO> pageResult = seckillTimeService.getSeckillTimePage(pageVO);
// return success(SeckillTimeConvert.INSTANCE.convertPage(pageResult));
// }
} }

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckillactivity.vo; package cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckillactivity.vo; package cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
@ -28,8 +28,8 @@ public class SeckillActivityCreateReqVO extends SeckillActivityBaseVO {
// TODO halfninety直接使用数组接口。timeIds // TODO halfninety直接使用数组接口。timeIds
@ApiModelProperty(value = "秒杀时段id", required = true) @ApiModelProperty(value = "秒杀时段id", required = true)
@NotBlank(message = "参与场次不能为空") @NotEmpty(message = "参与场次不能为空")
private String timeId; private List<Long> timeIds;
/** /**
* *

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckillactivity.vo; package cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import lombok.Data; import lombok.Data;

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckillactivity.vo; package cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity;
import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageParam;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
@ -27,7 +27,7 @@ public class SeckillActivityPageReqVO extends PageParam {
private Integer status; private Integer status;
@ApiModelProperty(value = "秒杀时段id") @ApiModelProperty(value = "秒杀时段id")
private String timeId; private Long timeId;
@ApiModelProperty(value = "创建时间") @ApiModelProperty(value = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckillactivity.vo; package cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
@ -7,6 +7,7 @@ import lombok.EqualsAndHashCode;
import lombok.ToString; import lombok.ToString;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.List;
@ApiModel("管理后台 - 秒杀活动 Response VO") @ApiModel("管理后台 - 秒杀活动 Response VO")
@Data @Data
@ -27,7 +28,7 @@ public class SeckillActivityRespVO extends SeckillActivityBaseVO {
private LocalDateTime createTime; private LocalDateTime createTime;
@ApiModelProperty(value = "秒杀时段id", required = true) @ApiModelProperty(value = "秒杀时段id", required = true)
private String timeId; private List<Long> timeIds;
@ApiModelProperty(value = "排序", required = true) @ApiModelProperty(value = "排序", required = true)
private Integer sort; private Integer sort;

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckillactivity.vo; package cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
@ -29,8 +29,8 @@ public class SeckillActivityUpdateReqVO extends SeckillActivityBaseVO {
private Integer sort; private Integer sort;
@ApiModelProperty(value = "秒杀时段id", required = true) @ApiModelProperty(value = "秒杀时段id", required = true)
@NotNull(message = "秒杀时段id不能为空") @NotEmpty(message = "秒杀时段id不能为空")
private String timeId; private List<Long> timeIds;
/** /**
* *

View File

@ -1,14 +1,11 @@
package cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckilltime.vo; package cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.time;
import lombok.*; import lombok.*;
import java.time.LocalTime; import java.time.LocalTime;
import java.util.*;
import io.swagger.annotations.*; import io.swagger.annotations.*;
import javax.validation.constraints.*; import javax.validation.constraints.*;
import org.springframework.format.annotation.DateTimeFormat;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
/** /**
* Base VO VO 使 * Base VO VO 使

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckilltime.vo; package cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.time;
import lombok.*; import lombok.*;
import io.swagger.annotations.*; import io.swagger.annotations.*;

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckilltime.vo; package cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.time;
import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageParam;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
@ -27,14 +27,4 @@ public class SeckillTimePageReqVO extends PageParam {
@DateTimeFormat(pattern = "HH:mm:ss") @DateTimeFormat(pattern = "HH:mm:ss")
private LocalTime endTime; private LocalTime endTime;
// @ApiModelProperty(value = "创建时间")
// @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
// private Date[] createTime;
} }

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckilltime.vo; package cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.time;
import lombok.*; import lombok.*;
import java.util.*; import java.util.*;

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckilltime.vo; package cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.time;
public class SeckillTimeSimpleRespVO { public class SeckillTimeSimpleRespVO {
} }

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckilltime.vo; package cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.time;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;

View File

@ -2,7 +2,8 @@ package cn.iocoder.yudao.module.promotion.convert.seckill.seckillactivity;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckillactivity.vo.*; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.*;
import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity.SeckillActivityDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity.SeckillActivityDO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity.SeckillProductDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity.SeckillProductDO;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
@ -27,7 +28,7 @@ public interface SeckillActivityConvert {
SeckillActivityDO convert(SeckillActivityCreateReqVO bean); SeckillActivityDO convert(SeckillActivityCreateReqVO bean);
default String map(Long[] value){ default String map(Long[] value) {
return value.toString(); return value.toString();
} }
@ -39,7 +40,7 @@ public interface SeckillActivityConvert {
PageResult<SeckillActivityRespVO> convertPage(PageResult<SeckillActivityDO> page); PageResult<SeckillActivityRespVO> convertPage(PageResult<SeckillActivityDO> page);
@Mappings({@Mapping(target = "products",source = "seckillProducts")}) @Mappings({@Mapping(target = "products", source = "seckillProducts")})
SeckillActivityDetailRespVO convert(SeckillActivityDO seckillActivity, List<SeckillProductDO> seckillProducts); SeckillActivityDetailRespVO convert(SeckillActivityDO seckillActivity, List<SeckillProductDO> seckillProducts);
@ -56,7 +57,6 @@ public interface SeckillActivityConvert {
&& ObjectUtil.equals(productDO.getSeckillPrice(), productVO.getSeckillPrice()) && ObjectUtil.equals(productDO.getSeckillPrice(), productVO.getSeckillPrice())
&& ObjectUtil.equals(productDO.getStock(), productVO.getStock()) && ObjectUtil.equals(productDO.getStock(), productVO.getStock())
&& ObjectUtil.equals(productDO.getLimitBuyCount(), productVO.getLimitBuyCount()); && ObjectUtil.equals(productDO.getLimitBuyCount(), productVO.getLimitBuyCount());
} }
/** /**
@ -74,4 +74,9 @@ public interface SeckillActivityConvert {
&& ObjectUtil.equals(productDO.getLimitBuyCount(), productVO.getLimitBuyCount()); && ObjectUtil.equals(productDO.getLimitBuyCount(), productVO.getLimitBuyCount());
} }
default List<SeckillProductDO> convertList(List<SeckillActivityBaseVO.Product> products, Long seckillActivityId, List<Long> timeIds) {
return CollectionUtils.convertList(products, product -> convert(product)
.setActivityId(seckillActivityId).setTimeIds(timeIds));
}
} }

View File

@ -4,9 +4,9 @@ import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckilltime.vo.SeckillTimeCreateReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.time.SeckillTimeCreateReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckilltime.vo.SeckillTimeRespVO; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.time.SeckillTimeRespVO;
import cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckilltime.vo.SeckillTimeUpdateReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.time.SeckillTimeUpdateReqVO;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers; import org.mapstruct.factory.Mappers;
import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckilltime.SeckillTimeDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckilltime.SeckillTimeDO;

View File

@ -9,11 +9,12 @@ import lombok.*;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.List;
/** /**
* DO * DO
* *
* @author * @author halfninety
*/ */
@TableName("promotion_seckill_activity") @TableName("promotion_seckill_activity")
@KeySequence("promotion_seckill_activity_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 @KeySequence("promotion_seckill_activity_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@ -59,8 +60,7 @@ public class SeckillActivityDO extends BaseDO {
/** /**
* id * id
*/ */
// TODO @halfninety 可以使用 List 存储;看下别的模块怎么做的哈 private List<Long> timeIds;
private String timeId;
/** /**
* *
*/ */
@ -69,10 +69,9 @@ public class SeckillActivityDO extends BaseDO {
* *
*/ */
private Integer userCount; private Integer userCount;
// TODO @halfninety 使用 Long 哈。单位是分
/** /**
* *
*/ */
private BigDecimal totalPrice; private Long totalPrice;
} }

View File

@ -5,16 +5,21 @@ import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable; import java.io.Serializable;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Date; import java.util.Date;
import java.util.List;
import lombok.Data; import lombok.Data;
/** /**
* *
*
* @author halfninety
* @TableName promotion_seckill_product * @TableName promotion_seckill_product
*/ */
@TableName(value ="promotion_seckill_product") @TableName(value = "promotion_seckill_product")
@Data @Data
public class SeckillProductDO extends BaseDO { public class SeckillProductDO extends BaseDO {
/** /**
@ -31,7 +36,7 @@ public class SeckillProductDO extends BaseDO {
/** /**
* id * id
*/ */
private Long timeId; private List<Long> timeIds;
/** /**
* id * id

View File

@ -3,25 +3,23 @@ package cn.iocoder.yudao.module.promotion.dal.mysql.seckill.seckillactivity;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckillactivity.vo.SeckillActivityPageReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityPageReqVO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity.SeckillActivityDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity.SeckillActivityDO;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
/** /**
* Mapper * Mapper
* *
* @author * @author halfninety
*/ */
@Mapper @Mapper
public interface SeckillActivityMapper extends BaseMapperX<SeckillActivityDO> { public interface SeckillActivityMapper extends BaseMapperX<SeckillActivityDO> {
// TODO: 2022/11/28 halfninety 秒杀活动通过场次查询使用like会出现问题查询活动场次编号为1则活动场次编号为 111......的都会被查出来
default PageResult<SeckillActivityDO> selectPage(SeckillActivityPageReqVO reqVO) { default PageResult<SeckillActivityDO> selectPage(SeckillActivityPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<SeckillActivityDO>() return selectPage(reqVO, new LambdaQueryWrapperX<SeckillActivityDO>()
.likeIfPresent(SeckillActivityDO::getName, reqVO.getName()) .likeIfPresent(SeckillActivityDO::getName, reqVO.getName())
.eqIfPresent(SeckillActivityDO::getStatus, reqVO.getStatus()) .eqIfPresent(SeckillActivityDO::getStatus, reqVO.getStatus())
.likeIfPresent(SeckillActivityDO::getTimeId, reqVO.getTimeId())
// .like(StringUtils.hasText(reqVO.getTimeId()),SeckillActivityDO::getTimeId, reqVO.getTimeId() + ",")
.betweenIfPresent(SeckillActivityDO::getCreateTime, reqVO.getCreateTime()) .betweenIfPresent(SeckillActivityDO::getCreateTime, reqVO.getCreateTime())
.apply("FIND_IN_SET(" + reqVO.getTimeId() + ",time_id) > 0")
.orderByDesc(SeckillActivityDO::getId)); .orderByDesc(SeckillActivityDO::getId));
} }

View File

@ -7,15 +7,20 @@ import org.apache.ibatis.annotations.Mapper;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
/**
* Mapper
*
* @author halfninety
*/
@Mapper @Mapper
public interface SeckillProductMapper extends BaseMapperX<SeckillProductDO> { public interface SeckillProductMapper extends BaseMapperX<SeckillProductDO> {
default List<SeckillProductDO> selectListByActivityId(Long id){ default List<SeckillProductDO> selectListByActivityId(Long id) {
return selectList(SeckillProductDO::getActivityId,id); return selectList(SeckillProductDO::getActivityId, id);
} }
default List<SeckillProductDO> selectListBySkuIds(Collection<Long> skuIds){ default List<SeckillProductDO> selectListBySkuIds(Collection<Long> skuIds) {
return selectList(SeckillProductDO::getSkuId,skuIds); return selectList(SeckillProductDO::getSkuId, skuIds);
} }
} }

View File

@ -8,57 +8,44 @@ import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWra
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import java.time.LocalTime; import java.time.LocalTime;
import java.util.Collections; import java.util.Collection;
import java.util.List; import java.util.List;
/** /**
* Mapper * Mapper
* *
* @author * @author halfninety
*/ */
@Mapper @Mapper
public interface SeckillTimeMapper extends BaseMapperX<SeckillTimeDO> { public interface SeckillTimeMapper extends BaseMapperX<SeckillTimeDO> {
// @TODO halfninety){ 之间要有空格哈 default List<SeckillTimeDO> selectListByTime(LocalTime time) {
default List<SeckillTimeDO> selectListWithTime(LocalTime time){ return selectList(SeckillTimeDO::getStartTime,SeckillTimeDO::getEndTime,time);
// TODO @halfninetymapper 层,不做空判断,业务上面自己的保证
if (time == null) {
return Collections.emptyList();
}
// TODO @halfninety在 BaseMapperX 上,可以封装一个 2 个字段的检索哈
return selectList(new LambdaQueryWrapper<SeckillTimeDO>()
.le(SeckillTimeDO::getStartTime,time)
.ge(SeckillTimeDO::getEndTime,time));
} }
// TODO @halfninetyselectListByXXX使用 By 作为查询条件。 default List<SeckillTimeDO> selectListByTime(LocalTime startTime, LocalTime endTime) {
default List<SeckillTimeDO> selectListWithTime(LocalTime startTime, LocalTime endTime){
// TODO @halfninetymapper 层,不做空判断,业务上面自己的保证
if (startTime == null && endTime == null) {
return Collections.emptyList();
}
return selectList(new LambdaQueryWrapper<SeckillTimeDO>() return selectList(new LambdaQueryWrapper<SeckillTimeDO>()
.ge(SeckillTimeDO::getStartTime,startTime) .ge(SeckillTimeDO::getStartTime, startTime)
.le(SeckillTimeDO::getEndTime,endTime)); .le(SeckillTimeDO::getEndTime, endTime));
} }
// TODO @halfninetyupdateActivityCount + 和 -,可以执使用一个方法实现哈。多传递一个参数 // TODO @halfninetyupdateActivityCount + 和 -,可以执使用一个方法实现哈。多传递一个参数
default void sekillActivityCountAdd(List<Long> ids){ default void sekillActivityCountAdd(Collection<Long> ids) {
if (CollUtil.isEmpty(ids)){ if (CollUtil.isEmpty(ids)) {
return; return;
} }
new LambdaUpdateChainWrapper<SeckillTimeDO>(this) new LambdaUpdateChainWrapper<SeckillTimeDO>(this)
.in(SeckillTimeDO::getId,ids) .in(SeckillTimeDO::getId, ids)
.setSql("`seckill_activity_count` = `seckill_activity_count` + 1 ") .setSql("`seckill_activity_count` = `seckill_activity_count` + 1 ")
.update(); .update();
} }
default void sekillActivityCountReduce(List<Long> ids){ default void sekillActivityCountReduce(Collection<Long> ids) {
if (CollUtil.isEmpty(ids)){ if (CollUtil.isEmpty(ids)) {
return; return;
} }
new LambdaUpdateChainWrapper<SeckillTimeDO>(this) new LambdaUpdateChainWrapper<SeckillTimeDO>(this)
.in(SeckillTimeDO::getId,ids) .in(SeckillTimeDO::getId, ids)
.setSql("`seckill_activity_count` = `seckill_activity_count` - 1 ") .setSql("`seckill_activity_count` = `seckill_activity_count` - 1 ")
.update(); .update();
} }

View File

@ -3,9 +3,9 @@ package cn.iocoder.yudao.module.promotion.service.seckill.seckillactivity;
import java.util.*; import java.util.*;
import javax.validation.*; import javax.validation.*;
import cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckillactivity.vo.SeckillActivityCreateReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityCreateReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckillactivity.vo.SeckillActivityPageReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityPageReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckillactivity.vo.SeckillActivityUpdateReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityUpdateReqVO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity.SeckillActivityDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity.SeckillActivityDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity.SeckillProductDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity.SeckillProductDO;
@ -13,7 +13,7 @@ import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity.
/** /**
* Service * Service
* *
* @author * @author halfninety
*/ */
public interface SeckillActivityService { public interface SeckillActivityService {
@ -34,6 +34,7 @@ public interface SeckillActivityService {
/** /**
* *
*
* @param id * @param id
*/ */
void closeSeckillActivity(Long id); void closeSeckillActivity(Long id);
@ -71,6 +72,7 @@ public interface SeckillActivityService {
/** /**
* *
*
* @param id * @param id
* @return * @return
*/ */

View File

@ -4,10 +4,10 @@ import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.framework.common.util.string.StrUtils; import cn.iocoder.yudao.framework.common.util.string.StrUtils;
import cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckillactivity.vo.SeckillActivityBaseVO; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityBaseVO;
import cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckillactivity.vo.SeckillActivityCreateReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityCreateReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckillactivity.vo.SeckillActivityPageReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityPageReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckillactivity.vo.SeckillActivityUpdateReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityUpdateReqVO;
import cn.iocoder.yudao.module.promotion.convert.seckill.seckillactivity.SeckillActivityConvert; import cn.iocoder.yudao.module.promotion.convert.seckill.seckillactivity.SeckillActivityConvert;
import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity.SeckillActivityDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity.SeckillActivityDO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity.SeckillProductDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity.SeckillProductDO;
@ -22,7 +22,6 @@ import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*; import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*;
@ -31,12 +30,13 @@ import static java.util.Arrays.asList;
/** /**
* Service * Service
* *
* @author // TODO @halfninety作者改成你自己哈 * @author halfninety
*/ */
@Service @Service
@Validated @Validated
public class SeckillActivityServiceImpl implements SeckillActivityService { public class SeckillActivityServiceImpl implements SeckillActivityService {
// TODO: 2022/12/2 halfninety 当前修改时忘记秒杀商品中的秒杀时段id的设置了需要全部修改
// TODO: 2022/12/2 halfninety 将活动数量改为原来的商品数量
@Resource @Resource
private SeckillActivityMapper seckillActivityMapper; private SeckillActivityMapper seckillActivityMapper;
@Resource @Resource
@ -47,25 +47,22 @@ public class SeckillActivityServiceImpl implements SeckillActivityService {
@Override @Override
public Long createSeckillActivity(SeckillActivityCreateReqVO createReqVO) { public Long createSeckillActivity(SeckillActivityCreateReqVO createReqVO) {
// TODO @halfninety多余的变量需要删除
List<Integer> statuses = asList(PromotionActivityStatusEnum.WAIT.getStatus(), PromotionActivityStatusEnum.RUN.getStatus());
// 校验商品是否冲突 // 校验商品是否冲突
validateSeckillActivityProductConflicts(null, createReqVO.getProducts()); validateSeckillActivityProductConflicts(null, createReqVO.getProducts());
// TODO halfninety要校验下秒杀时间段存在 // 校验秒杀时段是否存在
seckillTimeService.validateSeckillTimeExists(createReqVO.getTimeIds());
// 插入秒杀活动 // 插入秒杀活动
SeckillActivityDO seckillActivity = SeckillActivityConvert.INSTANCE.convert(createReqVO) SeckillActivityDO seckillActivity = SeckillActivityConvert.INSTANCE.convert(createReqVO)
.setStatus(PromotionUtils.calculateActivityStatus(createReqVO.getStartTime(), createReqVO.getEndTime())); .setStatus(PromotionUtils.calculateActivityStatus(createReqVO.getStartTime(), createReqVO.getEndTime()));
seckillActivityMapper.insert(seckillActivity); seckillActivityMapper.insert(seckillActivity);
// 插入商品 // 插入商品
// TODO @halfninety是不是写成一个 convertList通过 default 来处理下;这样可读性更好哈 List<SeckillProductDO> productDOS = SeckillActivityConvert.INSTANCE
List<SeckillProductDO> productDOS = CollectionUtils.convertList(createReqVO.getProducts(), .convertList(createReqVO.getProducts(),seckillActivity.getId(),seckillActivity.getTimeIds());
product -> SeckillActivityConvert.INSTANCE.convert(product).setActivityId(seckillActivity.getId()));
seckillProductMapper.insertBatch(productDOS); seckillProductMapper.insertBatch(productDOS);
// TODO halfninety最后在更新秒杀时间段的商品数量哈。【我已经改了】一般先做核心的逻辑在做附件的逻辑。
// 更新秒杀时段的秒杀活动数量 // 更新秒杀时段的秒杀活动数量
seckillTimeService.sekillActivityCountAdd(StrUtils.splitToLong(createReqVO.getTimeId(),",")); seckillTimeService.sekillActivityCountAdd(createReqVO.getTimeIds());
return seckillActivity.getId(); return seckillActivity.getId();
} }
@ -80,8 +77,7 @@ public class SeckillActivityServiceImpl implements SeckillActivityService {
validateSeckillActivityProductConflicts(updateReqVO.getId(), updateReqVO.getProducts()); validateSeckillActivityProductConflicts(updateReqVO.getId(), updateReqVO.getProducts());
// 更新秒杀时段的秒杀活动数量 // 更新秒杀时段的秒杀活动数量
// TODO @halfninety可以直接传递 seckillActivity 进去,不用重复查询; updateSeckillTimeActivityCount(seckillActivity, updateReqVO.getTimeIds());
updateSeckillTimeActivityCount(updateReqVO.getId(), updateReqVO.getTimeId());
// 更新活动 // 更新活动
SeckillActivityDO updateObj = SeckillActivityConvert.INSTANCE.convert(updateReqVO) SeckillActivityDO updateObj = SeckillActivityConvert.INSTANCE.convert(updateReqVO)
.setStatus(PromotionUtils.calculateActivityStatus(updateReqVO.getStartTime(), updateReqVO.getEndTime())); .setStatus(PromotionUtils.calculateActivityStatus(updateReqVO.getStartTime(), updateReqVO.getEndTime()));
@ -91,41 +87,39 @@ public class SeckillActivityServiceImpl implements SeckillActivityService {
} }
// TODO @halfninety注释写全哈 // TODO @halfninety注释写全哈
/** /**
* *
* *
* @param id * @param seckillActivity
* @param timeId * @param updateTimeIds id
*/ */
private void updateSeckillTimeActivityCount(Long id, String timeId) { private void updateSeckillTimeActivityCount(SeckillActivityDO seckillActivity, List<Long> updateTimeIds) {
List<Long> updateTimeIds = StrUtils.splitToLong(timeId, ","); // 查询出 timeIds
// 查出自己的 timeIds List<Long> existsTimeIds = seckillActivity.getTimeIds();
SeckillActivityDO seckillActivityDO = seckillActivityMapper.selectById(id);
List<Long> existsTimeIds = StrUtils.splitToLong(seckillActivityDO.getTimeId(), ",");
// 需要减少的时间段 // 需要减少的时间段
// TODO @halfninety可以使用 CollUtil.filterNew() // TODO @halfninety可以使用 CollUtil.filterNew()
List<Long> reduceIds = existsTimeIds.stream() Collection<Long> reduceIds = CollUtil.filterNew(existsTimeIds, existsTimeId -> !updateTimeIds.contains(existsTimeId));
.filter(existsTimeId -> !updateTimeIds.contains(existsTimeId))
.collect(Collectors.toList());
// 需要添加的时间段 // 需要添加的时间段
// TODO @halfninetyIDEA 一般会有告警提示,下面可以 lambada 表达式优化下;通过 command + 回车 updateTimeIds.removeIf(existsTimeIds::contains);
updateTimeIds.removeIf(updateTimeId -> existsTimeIds.contains(updateTimeId));
// 更新减少时间段和增加时间段 // 更新减少时间段和增加时间段
// TODO @halfninety判断非空才操作 if (CollUtil.isNotEmpty(updateTimeIds)) {
seckillTimeService.sekillActivityCountAdd(updateTimeIds); seckillTimeService.sekillActivityCountAdd(updateTimeIds);
}
if (CollUtil.isNotEmpty(reduceIds)) {
seckillTimeService.sekillActivityCountReduce(reduceIds); seckillTimeService.sekillActivityCountReduce(reduceIds);
} }
}
/** /**
* *
*
* 1. sku
* 2. sku
*/ */
private void updateSeckillProduct(SeckillActivityUpdateReqVO updateReqVO) { private void updateSeckillProduct(SeckillActivityUpdateReqVO updateReqVO) {
List<SeckillProductDO> seckillProductDOS = seckillProductMapper.selectListByActivityId(updateReqVO.getId()); List<SeckillProductDO> seckillProductDOS = seckillProductMapper.selectListByActivityId(updateReqVO.getId());
List<SeckillActivityBaseVO.Product> products = updateReqVO.getProducts(); List<SeckillActivityBaseVO.Product> products = updateReqVO.getProducts();
// TODO halfninety下面这段其实可以放到注释哈
// 对后台查出的数据和前台查出的数据进行遍历,
// 1. 对前台数据进行遍历:如果不存在于后台的 sku 中需要新增
// 2. 对后台数据进行遍历:如果不存在于前台的 sku 中需要删除
// 计算需要删除的数据 // 计算需要删除的数据
List<Long> deleteIds = CollectionUtils.convertList(seckillProductDOS, SeckillProductDO::getId, List<Long> deleteIds = CollectionUtils.convertList(seckillProductDOS, SeckillProductDO::getId,
@ -198,7 +192,7 @@ public class SeckillActivityServiceImpl implements SeckillActivityService {
throw exception(SECKILL_ACTIVITY_DELETE_FAIL_STATUS_NOT_CLOSED_OR_END); throw exception(SECKILL_ACTIVITY_DELETE_FAIL_STATUS_NOT_CLOSED_OR_END);
} }
// 更新秒杀时段的秒杀活动数量 // 更新秒杀时段的秒杀活动数量
seckillTimeService.sekillActivityCountReduce(StrUtils.splitToLong(seckillActivity.getTimeId(),",")); seckillTimeService.sekillActivityCountReduce(seckillActivity.getTimeIds());
// 删除 // 删除
seckillActivityMapper.deleteById(id); seckillActivityMapper.deleteById(id);
} }

View File

@ -1,16 +1,17 @@
package cn.iocoder.yudao.module.promotion.service.seckill.seckilltime; package cn.iocoder.yudao.module.promotion.service.seckill.seckilltime;
import cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckilltime.vo.SeckillTimeCreateReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.time.SeckillTimeCreateReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckilltime.vo.SeckillTimeUpdateReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.time.SeckillTimeUpdateReqVO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckilltime.SeckillTimeDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckilltime.SeckillTimeDO;
import javax.validation.Valid; import javax.validation.Valid;
import java.util.Collection;
import java.util.List; import java.util.List;
/** /**
* Service * Service
* *
* @author * @author halfninety
*/ */
public interface SeckillTimeService { public interface SeckillTimeService {
@ -51,12 +52,19 @@ public interface SeckillTimeService {
*/ */
List<SeckillTimeDO> getSeckillTimeList(); List<SeckillTimeDO> getSeckillTimeList();
/**
*
*
* @param timeIds id
*/
void validateSeckillTimeExists(Collection<Long> timeIds);
/** /**
* 1 * 1
* *
* @param ids id * @param ids id
*/ */
void sekillActivityCountAdd(List<Long> ids); void sekillActivityCountAdd(Collection<Long> ids);
/** /**
@ -64,5 +72,5 @@ public interface SeckillTimeService {
* *
* @param ids id * @param ids id
*/ */
void sekillActivityCountReduce(List<Long> ids); void sekillActivityCountReduce(Collection<Long> ids);
} }

View File

@ -1,8 +1,8 @@
package cn.iocoder.yudao.module.promotion.service.seckill.seckilltime; package cn.iocoder.yudao.module.promotion.service.seckill.seckilltime;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckilltime.vo.SeckillTimeCreateReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.time.SeckillTimeCreateReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckilltime.vo.SeckillTimeUpdateReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.time.SeckillTimeUpdateReqVO;
import cn.iocoder.yudao.module.promotion.convert.seckill.seckilltime.SeckillTimeConvert; import cn.iocoder.yudao.module.promotion.convert.seckill.seckilltime.SeckillTimeConvert;
import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckilltime.SeckillTimeDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckilltime.SeckillTimeDO;
import cn.iocoder.yudao.module.promotion.dal.mysql.seckill.seckilltime.SeckillTimeMapper; import cn.iocoder.yudao.module.promotion.dal.mysql.seckill.seckilltime.SeckillTimeMapper;
@ -11,6 +11,7 @@ import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.time.LocalTime; import java.time.LocalTime;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
@ -21,7 +22,7 @@ import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.SECKILL
/** /**
* Service * Service
* *
* @author // TODO @halfninety作者改成你自己哈 * @author halfninety
*/ */
@Service @Service
@Validated @Validated
@ -33,7 +34,7 @@ public class SeckillTimeServiceImpl implements SeckillTimeService {
@Override @Override
public Long createSeckillTime(SeckillTimeCreateReqVO createReqVO) { public Long createSeckillTime(SeckillTimeCreateReqVO createReqVO) {
// 校验时间段是否冲突 // 校验时间段是否冲突
validateSeckillTimeConflict(null,createReqVO.getStartTime(), createReqVO.getEndTime()); validateSeckillTimeConflict(null, createReqVO.getStartTime(), createReqVO.getEndTime());
// 插入 // 插入
SeckillTimeDO seckillTime = SeckillTimeConvert.INSTANCE.convert(createReqVO); SeckillTimeDO seckillTime = SeckillTimeConvert.INSTANCE.convert(createReqVO);
seckillTimeMapper.insert(seckillTime); seckillTimeMapper.insert(seckillTime);
@ -74,10 +75,10 @@ public class SeckillTimeServiceImpl implements SeckillTimeService {
*/ */
private void validateSeckillTimeConflict(Long id, LocalTime startTime, LocalTime endTime) { private void validateSeckillTimeConflict(Long id, LocalTime startTime, LocalTime endTime) {
//查询开始时间,结束时间,是否在别人的时间段内 //查询开始时间,结束时间,是否在别人的时间段内
List<SeckillTimeDO> startTimeList = seckillTimeMapper.selectListWithTime(startTime); List<SeckillTimeDO> startTimeList = seckillTimeMapper.selectListByTime(startTime);
List<SeckillTimeDO> endTimeList = seckillTimeMapper.selectListWithTime(endTime); List<SeckillTimeDO> endTimeList = seckillTimeMapper.selectListByTime(endTime);
//查询自己时间段内是否有时间段 //查询自己时间段内是否有时间段
List<SeckillTimeDO> startEndTimeList = seckillTimeMapper.selectListWithTime(startTime, endTime); List<SeckillTimeDO> startEndTimeList = seckillTimeMapper.selectListByTime(startTime, endTime);
if (id != null) { if (id != null) {
//移除自己 //移除自己
startTimeList.removeIf(seckillTime -> Objects.equals(seckillTime.getId(), id)); startTimeList.removeIf(seckillTime -> Objects.equals(seckillTime.getId(), id));
@ -100,14 +101,24 @@ public class SeckillTimeServiceImpl implements SeckillTimeService {
return seckillTimeMapper.selectList(); return seckillTimeMapper.selectList();
} }
@Override
public void validateSeckillTimeExists(Collection<Long> timeIds) {
if (CollUtil.isEmpty(timeIds)) {
return;
}
if (seckillTimeMapper.selectBatchIds(timeIds).size() != timeIds.size()) {
throw exception(SECKILL_TIME_NOT_EXISTS);
}
}
// TODO @halfninetyupdateActivityCount + 和 -,可以执使用一个方法实现哈。多传递一个参数 // TODO @halfninetyupdateActivityCount + 和 -,可以执使用一个方法实现哈。多传递一个参数
@Override @Override
public void sekillActivityCountAdd(List<Long> ids) { public void sekillActivityCountAdd(Collection<Long> ids) {
seckillTimeMapper.sekillActivityCountAdd(ids); seckillTimeMapper.sekillActivityCountAdd(ids);
} }
@Override @Override
public void sekillActivityCountReduce(List<Long> ids) { public void sekillActivityCountReduce(Collection<Long> ids) {
seckillTimeMapper.sekillActivityCountReduce(ids); seckillTimeMapper.sekillActivityCountReduce(ids);
} }

View File

@ -1,13 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.iocoder.yudao.module.promotion.dal.mysql.seckill.seckillactivity.SeckillActivityMapper">
<!--
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
文档可见https://www.iocoder.cn/MyBatis/x-plugins/
-->
<!-- TODO halfninety不用的话可以删除掉哈。 -->
</mapper>

View File

@ -1,13 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.iocoder.yudao.module.promotion.dal.mysql.seckill.seckilltime.SeckillTimeMapper">
<!--
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
文档可见https://www.iocoder.cn/MyBatis/x-plugins/
-->
<!-- TODO halfninety不用的话可以删除掉哈。 -->
</mapper>

View File

@ -2,9 +2,9 @@ package cn.iocoder.yudao.module.promotion.service.seckillactivity;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
import cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckillactivity.vo.SeckillActivityCreateReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityCreateReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckillactivity.vo.SeckillActivityPageReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityPageReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckillactivity.vo.SeckillActivityUpdateReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityUpdateReqVO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity.SeckillActivityDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity.SeckillActivityDO;
import cn.iocoder.yudao.module.promotion.dal.mysql.seckill.seckillactivity.SeckillActivityMapper; import cn.iocoder.yudao.module.promotion.dal.mysql.seckill.seckillactivity.SeckillActivityMapper;
import cn.iocoder.yudao.module.promotion.service.seckill.seckillactivity.SeckillActivityServiceImpl; import cn.iocoder.yudao.module.promotion.service.seckill.seckillactivity.SeckillActivityServiceImpl;
@ -107,7 +107,7 @@ public class SeckillActivityServiceImplTest extends BaseDbUnitTest {
SeckillActivityDO dbSeckillActivity = randomPojo(SeckillActivityDO.class, o -> { // 等会查询到 SeckillActivityDO dbSeckillActivity = randomPojo(SeckillActivityDO.class, o -> { // 等会查询到
o.setName(null); o.setName(null);
o.setStatus(null); o.setStatus(null);
o.setTimeId(null); o.setTimeIds(null);
o.setCreateTime(null); o.setCreateTime(null);
}); });
seckillActivityMapper.insert(dbSeckillActivity); seckillActivityMapper.insert(dbSeckillActivity);
@ -116,7 +116,7 @@ public class SeckillActivityServiceImplTest extends BaseDbUnitTest {
// 测试 status 不匹配 // 测试 status 不匹配
seckillActivityMapper.insert(cloneIgnoreId(dbSeckillActivity, o -> o.setStatus(null))); seckillActivityMapper.insert(cloneIgnoreId(dbSeckillActivity, o -> o.setStatus(null)));
// 测试 timeId 不匹配 // 测试 timeId 不匹配
seckillActivityMapper.insert(cloneIgnoreId(dbSeckillActivity, o -> o.setTimeId(null))); seckillActivityMapper.insert(cloneIgnoreId(dbSeckillActivity, o -> o.setTimeIds(null)));
// 测试 createTime 不匹配 // 测试 createTime 不匹配
seckillActivityMapper.insert(cloneIgnoreId(dbSeckillActivity, o -> o.setCreateTime(null))); seckillActivityMapper.insert(cloneIgnoreId(dbSeckillActivity, o -> o.setCreateTime(null)));
// 准备参数 // 准备参数
@ -141,7 +141,7 @@ public class SeckillActivityServiceImplTest extends BaseDbUnitTest {
SeckillActivityDO dbSeckillActivity = randomPojo(SeckillActivityDO.class, o -> { // 等会查询到 SeckillActivityDO dbSeckillActivity = randomPojo(SeckillActivityDO.class, o -> { // 等会查询到
o.setName(null); o.setName(null);
o.setStatus(null); o.setStatus(null);
o.setTimeId(null); o.setTimeIds(null);
o.setCreateTime(null); o.setCreateTime(null);
}); });
seckillActivityMapper.insert(dbSeckillActivity); seckillActivityMapper.insert(dbSeckillActivity);
@ -150,7 +150,7 @@ public class SeckillActivityServiceImplTest extends BaseDbUnitTest {
// 测试 status 不匹配 // 测试 status 不匹配
seckillActivityMapper.insert(cloneIgnoreId(dbSeckillActivity, o -> o.setStatus(null))); seckillActivityMapper.insert(cloneIgnoreId(dbSeckillActivity, o -> o.setStatus(null)));
// 测试 timeId 不匹配 // 测试 timeId 不匹配
seckillActivityMapper.insert(cloneIgnoreId(dbSeckillActivity, o -> o.setTimeId(null))); seckillActivityMapper.insert(cloneIgnoreId(dbSeckillActivity, o -> o.setTimeIds(null)));
// 测试 createTime 不匹配 // 测试 createTime 不匹配
seckillActivityMapper.insert(cloneIgnoreId(dbSeckillActivity, o -> o.setCreateTime(null))); seckillActivityMapper.insert(cloneIgnoreId(dbSeckillActivity, o -> o.setCreateTime(null)));
// 准备参数 // 准备参数

View File

@ -1,7 +1,7 @@
package cn.iocoder.yudao.module.promotion.service.seckilltime; package cn.iocoder.yudao.module.promotion.service.seckilltime;
import cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckilltime.vo.SeckillTimeCreateReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.time.SeckillTimeCreateReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckilltime.vo.SeckillTimeUpdateReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.time.SeckillTimeUpdateReqVO;
import cn.iocoder.yudao.module.promotion.service.seckill.seckilltime.SeckillTimeServiceImpl; import cn.iocoder.yudao.module.promotion.service.seckill.seckilltime.SeckillTimeServiceImpl;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;