!320 秒杀活动相关

Merge pull request !320 from halfninety/feature/1.8.0-uniapp
This commit is contained in:
芋道源码 2022-12-13 02:04:54 +00:00 committed by Gitee
commit f9b4874ee9
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
32 changed files with 241 additions and 285 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 +0,0 @@
package cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckilltime.vo;
public class SeckillTimeSimpleRespVO {
}

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;
@ -7,12 +7,10 @@ import lombok.EqualsAndHashCode;
import lombok.ToString; import lombok.ToString;
import javax.validation.Valid; import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.util.List; import java.util.List;
// TODO halfninety检查下所有的 VO需要保证 example 都写了哈
@ApiModel("管理后台 - 秒杀活动创建 Request VO") @ApiModel("管理后台 - 秒杀活动创建 Request VO")
@Data @Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@ -22,14 +20,13 @@ public class SeckillActivityCreateReqVO extends SeckillActivityBaseVO {
@ApiModelProperty(value = "备注", example = "限时秒杀活动") @ApiModelProperty(value = "备注", example = "限时秒杀活动")
private String remark; private String remark;
@ApiModelProperty(value = "排序", required = true) @ApiModelProperty(value = "排序", required = true, example = "1")
@NotNull(message = "排序不能为空") @NotNull(message = "排序不能为空")
private Integer sort; private Integer sort;
// TODO halfninety直接使用数组接口timeIds @ApiModelProperty(value = "秒杀时段id", required = true, example = "1,3")
@ApiModelProperty(value = "秒杀时段id", required = true) @NotEmpty(message = "参与场次不能为空")
@NotBlank(message = "参与场次不能为空") private List<Long> timeIds;
private String timeId;
/** /**
* 商品列表 * 商品列表

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;
@ -26,8 +26,8 @@ public class SeckillActivityPageReqVO extends PageParam {
@ApiModelProperty(value = "活动状态", example = "进行中") @ApiModelProperty(value = "活动状态", example = "进行中")
private Integer status; private Integer status;
@ApiModelProperty(value = "秒杀时段id") @ApiModelProperty(value = "秒杀时段id", example = "1")
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
@ -17,19 +18,19 @@ public class SeckillActivityRespVO extends SeckillActivityBaseVO {
@ApiModelProperty(value = "秒杀活动id", required = true, example = "1") @ApiModelProperty(value = "秒杀活动id", required = true, example = "1")
private Long id; private Long id;
@ApiModelProperty(value = "付款订单数", required = true) @ApiModelProperty(value = "付款订单数", required = true, example = "1")
private Integer orderCount; private Integer orderCount;
@ApiModelProperty(value = "付款人数", required = true) @ApiModelProperty(value = "付款人数", required = true, example = "1")
private Integer userCount; private Integer userCount;
@ApiModelProperty(value = "创建时间", required = true) @ApiModelProperty(value = "创建时间", required = true)
private LocalDateTime createTime; private LocalDateTime createTime;
@ApiModelProperty(value = "秒杀时段id", required = true) @ApiModelProperty(value = "秒杀时段id", required = true, example = "1,3")
private String timeId; private List<Long> timeIds;
@ApiModelProperty(value = "排序", required = true) @ApiModelProperty(value = "排序", required = true, example = "1")
private Integer sort; private Integer sort;
@ApiModelProperty(value = "备注", example = "限时秒杀活动") @ApiModelProperty(value = "备注", example = "限时秒杀活动")

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;
@ -24,13 +24,13 @@ public class SeckillActivityUpdateReqVO extends SeckillActivityBaseVO {
@ApiModelProperty(value = "备注", example = "限时秒杀活动") @ApiModelProperty(value = "备注", example = "限时秒杀活动")
private String remark; private String remark;
@ApiModelProperty(value = "排序", required = true) @ApiModelProperty(value = "排序", required = true, example = "1")
@NotNull(message = "排序不能为空") @NotNull(message = "排序不能为空")
private Integer sort; private Integer sort;
@ApiModelProperty(value = "秒杀时段id", required = true) @ApiModelProperty(value = "秒杀时段id", required = true, example = "1,3")
@NotNull(message = "秒杀时段id不能为空") @NotEmpty(message = "秒杀时段id不能为空")
private String timeId; private List<Long> timeIds;
/** /**
* 商品列表 * 商品列表

View File

@ -1,14 +1,10 @@
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 io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotNull;
import java.time.LocalTime; import java.time.LocalTime;
import java.util.*;
import io.swagger.annotations.*;
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 使用
@ -17,15 +13,15 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
@Data @Data
public class SeckillTimeBaseVO { public class SeckillTimeBaseVO {
@ApiModelProperty(value = "秒杀时段名称", required = true) @ApiModelProperty(value = "秒杀时段名称", required = true, example = "上午场")
@NotNull(message = "秒杀时段名称不能为空") @NotNull(message = "秒杀时段名称不能为空")
private String name; private String name;
@ApiModelProperty(value = "开始时间点", required = true) @ApiModelProperty(value = "开始时间点", required = true, example = "16:30:40")
@NotNull(message = "开始时间点不能为空") @NotNull(message = "开始时间点不能为空")
private LocalTime startTime; private LocalTime startTime;
@ApiModelProperty(value = "结束时间点", required = true) @ApiModelProperty(value = "结束时间点", required = true, example = "16:30:40")
@NotNull(message = "结束时间点不能为空") @NotNull(message = "结束时间点不能为空")
private LocalTime endTime; private LocalTime endTime;

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;
@ -16,25 +16,15 @@ import java.time.LocalTime;
@ToString(callSuper = true) @ToString(callSuper = true)
public class SeckillTimePageReqVO extends PageParam { public class SeckillTimePageReqVO extends PageParam {
@ApiModelProperty(value = "秒杀时段名称") @ApiModelProperty(value = "秒杀时段名称", example = "上午场")
private String name; private String name;
@ApiModelProperty(value = "开始时间点") @ApiModelProperty(value = "开始时间点", example = "16:30:40")
@DateTimeFormat(pattern = "HH:mm:ss") @DateTimeFormat(pattern = "HH:mm:ss")
private LocalTime startTime; private LocalTime startTime;
@ApiModelProperty(value = "结束时间点") @ApiModelProperty(value = "结束时间点", example = "16:30:40")
@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,8 +1,12 @@
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 io.swagger.annotations.ApiModel;
import java.util.*; import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.*; import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import java.time.LocalDateTime;
@ApiModel("管理后台 - 秒杀时段 Response VO") @ApiModel("管理后台 - 秒杀时段 Response VO")
@Data @Data
@ -10,13 +14,13 @@ import io.swagger.annotations.*;
@ToString(callSuper = true) @ToString(callSuper = true)
public class SeckillTimeRespVO extends SeckillTimeBaseVO { public class SeckillTimeRespVO extends SeckillTimeBaseVO {
@ApiModelProperty(value = "编号", required = true) @ApiModelProperty(value = "编号", required = true, example = "1")
private Long id; private Long id;
@ApiModelProperty(value = "秒杀活动数量", required = true) @ApiModelProperty(value = "秒杀活动数量", required = true, example = "1")
private Integer seckillActivityCount; private Integer seckillActivityCount;
@ApiModelProperty(value = "创建时间", required = true) @ApiModelProperty(value = "创建时间", required = true)
private Date createTime; private LocalDateTime 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 io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
@ -14,7 +14,7 @@ import javax.validation.constraints.NotNull;
@ToString(callSuper = true) @ToString(callSuper = true)
public class SeckillTimeUpdateReqVO extends SeckillTimeBaseVO { public class SeckillTimeUpdateReqVO extends SeckillTimeBaseVO {
@ApiModelProperty(value = "编号", required = true) @ApiModelProperty(value = "编号", required = true, example = "1")
@NotNull(message = "编号不能为空") @NotNull(message = "编号不能为空")
private Long id; private Long id;

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;
@ -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,10 @@ public interface SeckillActivityConvert {
&& ObjectUtil.equals(productDO.getLimitBuyCount(), productVO.getLimitBuyCount()); && ObjectUtil.equals(productDO.getLimitBuyCount(), productVO.getLimitBuyCount());
} }
default List<SeckillProductDO> convertList(List<SeckillActivityBaseVO.Product> products, SeckillActivityDO seckillActivity) {
return CollectionUtils.convertList(products, product -> convert(product)
.setActivityId(seckillActivity.getId()).setTimeIds(seckillActivity.getTimeIds()));
}
} }

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

@ -1,28 +1,29 @@
package cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity; package cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import cn.iocoder.yudao.framework.mybatis.core.type.LongListTypeHandler;
import cn.iocoder.yudao.module.promotion.enums.common.PromotionActivityStatusEnum;
import com.baomidou.mybatisplus.annotation.KeySequence; import com.baomidou.mybatisplus.annotation.KeySequence;
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 cn.iocoder.yudao.module.promotion.enums.common.PromotionActivityStatusEnum; import lombok.Data;
import lombok.*; import lombok.EqualsAndHashCode;
import lombok.ToString;
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(value = "promotion_seckill_activity", autoResultMap = true)
@KeySequence("promotion_seckill_activity_seq") // 用于 OraclePostgreSQLKingbaseDB2H2 数据库的主键自增如果是 MySQL 等数据库可不写 @KeySequence("promotion_seckill_activity_seq") // 用于 OraclePostgreSQLKingbaseDB2H2 数据库的主键自增如果是 MySQL 等数据库可不写
@Data @Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true) @ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class SeckillActivityDO extends BaseDO { public class SeckillActivityDO extends BaseDO {
/** /**
@ -36,7 +37,7 @@ public class SeckillActivityDO extends BaseDO {
private String name; private String name;
/** /**
* 活动状态 * 活动状态
* * <p>
* 枚举 {@link PromotionActivityStatusEnum 对应的类} * 枚举 {@link PromotionActivityStatusEnum 对应的类}
*/ */
private Integer status; private Integer status;
@ -59,8 +60,8 @@ public class SeckillActivityDO extends BaseDO {
/** /**
* 秒杀时段 id * 秒杀时段 id
*/ */
// TODO @halfninety 可以使用 List 存储看下别的模块怎么做的哈 @TableField(typeHandler = LongListTypeHandler.class)
private String timeId; private List<Long> timeIds;
/** /**
* 付款订单数 * 付款订单数
*/ */
@ -69,10 +70,9 @@ public class SeckillActivityDO extends BaseDO {
* 付款人数 * 付款人数
*/ */
private Integer userCount; private Integer userCount;
// TODO @halfninety 使用 Long 单位是分
/** /**
* 订单实付金额单位 * 订单实付金额单位
*/ */
private BigDecimal totalPrice; private Long totalPrice;
} }

View File

@ -1,21 +1,25 @@
package cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity; package cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import com.baomidou.mybatisplus.annotation.IdType; import cn.iocoder.yudao.framework.mybatis.core.type.LongListTypeHandler;
import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import java.util.List;
/** /**
* 秒杀参与商品 * 秒杀参与商品
*
* @author halfninety
* @TableName promotion_seckill_product * @TableName promotion_seckill_product
*/ */
@TableName(value ="promotion_seckill_product") @TableName(value = "promotion_seckill_product", autoResultMap = true)
@KeySequence("promotion_seckill_product_seq") // 用于 OraclePostgreSQLKingbaseDB2H2 数据库的主键自增如果是 MySQL 等数据库可不写
@Data @Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class SeckillProductDO extends BaseDO { public class SeckillProductDO extends BaseDO {
/** /**
* 秒杀参与商品编号 * 秒杀参与商品编号
@ -31,7 +35,8 @@ public class SeckillProductDO extends BaseDO {
/** /**
* 秒杀时段id * 秒杀时段id
*/ */
private Long timeId; @TableField(typeHandler = LongListTypeHandler.class)
private List<Long> timeIds;
/** /**
* 商品id * 商品id

View File

@ -4,7 +4,9 @@ import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import com.baomidou.mybatisplus.annotation.KeySequence; import com.baomidou.mybatisplus.annotation.KeySequence;
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 lombok.*; import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import java.time.LocalTime; import java.time.LocalTime;
@ -18,9 +20,6 @@ import java.time.LocalTime;
@Data @Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true) @ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class SeckillTimeDO extends BaseDO { public class SeckillTimeDO extends BaseDO {
/** /**

View File

@ -1,28 +1,26 @@
package cn.iocoder.yudao.module.promotion.dal.mysql.seckill.seckillactivity; package cn.iocoder.yudao.module.promotion.dal.mysql.seckill.seckillactivity;
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.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(ObjectUtil.isNotNull(reqVO.getTimeId()),"FIND_IN_SET(" + reqVO.getTimeId() + ",time_ids) > 0")
.orderByDesc(SeckillActivityDO::getId)); .orderByDesc(SeckillActivityDO::getId));
} }
} }

View File

@ -1,12 +1,19 @@
package cn.iocoder.yudao.module.promotion.dal.mysql.seckill.seckillactivity; package cn.iocoder.yudao.module.promotion.dal.mysql.seckill.seckillactivity;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity.SeckillProductDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity.SeckillProductDO;
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
import org.apache.ibatis.annotations.Mapper; 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> {
@ -18,4 +25,11 @@ public interface SeckillProductMapper extends BaseMapperX<SeckillProductDO> {
return selectList(SeckillProductDO::getSkuId, skuIds); return selectList(SeckillProductDO::getSkuId, skuIds);
} }
default void updateTimeIdsByActivityId(Long id, List<Long> timeIds) {
new LambdaUpdateChainWrapper<>(this)
.set(SeckillProductDO::getTimeIds, CollUtil.join(timeIds, ","))
.eq(SeckillProductDO::getActivityId, id)
.update();
}
} }

View File

@ -1,6 +1,5 @@
package cn.iocoder.yudao.module.promotion.dal.mysql.seckill.seckilltime; package cn.iocoder.yudao.module.promotion.dal.mysql.seckill.seckilltime;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckilltime.SeckillTimeDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckilltime.SeckillTimeDO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@ -8,59 +7,31 @@ 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 + -可以执使用一个方法实现哈多传递一个参数 default void updateActivityCount(Collection<Long> ids, String type, Integer count) {
default void sekillActivityCountAdd(List<Long> ids){ new LambdaUpdateChainWrapper<>(this)
if (CollUtil.isEmpty(ids)){
return;
}
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` " + type + count)
.update(); .update();
} }
default void sekillActivityCountReduce(List<Long> ids){
if (CollUtil.isEmpty(ids)){
return;
}
new LambdaUpdateChainWrapper<SeckillTimeDO>(this)
.in(SeckillTimeDO::getId,ids)
.setSql("`seckill_activity_count` = `seckill_activity_count` - 1 ")
.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

@ -3,11 +3,10 @@ package cn.iocoder.yudao.module.promotion.service.seckill.seckillactivity;
import cn.hutool.core.collection.CollUtil; 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.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityBaseVO;
import cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckillactivity.vo.SeckillActivityBaseVO; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityCreateReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckillactivity.vo.SeckillActivityCreateReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityPageReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckillactivity.vo.SeckillActivityPageReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityUpdateReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.seckill.seckillactivity.vo.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 +21,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,41 +29,34 @@ 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 {
@Resource @Resource
private SeckillActivityMapper seckillActivityMapper; private SeckillActivityMapper seckillActivityMapper;
@Resource @Resource
private SeckillProductMapper seckillProductMapper; private SeckillProductMapper seckillProductMapper;
@Resource @Resource
private SeckillTimeService seckillTimeService; private SeckillTimeService seckillTimeService;
@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());
// 校验秒杀时段是否存在
seckillTimeService.validateSeckillTimeExists(createReqVO.getTimeIds());
// TODO halfninety要校验下秒杀时间段存在
// 插入秒杀活动 // 插入秒杀活动
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.convertList(createReqVO.getProducts(), seckillActivity);
List<SeckillProductDO> productDOS = CollectionUtils.convertList(createReqVO.getProducts(),
product -> SeckillActivityConvert.INSTANCE.convert(product).setActivityId(seckillActivity.getId()));
seckillProductMapper.insertBatch(productDOS); seckillProductMapper.insertBatch(productDOS);
// TODO halfninety最后在更新秒杀时间段的商品数量哈我已经改了一般先做核心的逻辑在做附件的逻辑
// 更新秒杀时段的秒杀活动数量 // 更新秒杀时段的秒杀活动数量
seckillTimeService.sekillActivityCountAdd(StrUtils.splitToLong(createReqVO.getTimeId(),",")); seckillTimeService.sekillActivityCountIncr(createReqVO.getTimeIds());
return seckillActivity.getId(); return seckillActivity.getId();
} }
@ -79,53 +70,51 @@ public class SeckillActivityServiceImpl implements SeckillActivityService {
// 校验商品是否冲突 // 校验商品是否冲突
validateSeckillActivityProductConflicts(updateReqVO.getId(), updateReqVO.getProducts()); validateSeckillActivityProductConflicts(updateReqVO.getId(), updateReqVO.getProducts());
// 更新秒杀时段的秒杀活动数量
// TODO @halfninety可以直接传递 seckillActivity 进去不用重复查询
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()));
seckillActivityMapper.updateById(updateObj); seckillActivityMapper.updateById(updateObj);
// 更新商品 // 更新商品
updateSeckillProduct(updateReqVO); updateSeckillProduct(updateReqVO);
// 更新秒杀时段的秒杀活动数量
updateSeckillTimeActivityCount(seckillActivity, updateReqVO.getTimeIds());
} }
// 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() Collection<Long> reduceIds = CollUtil.filterNew(existsTimeIds, existsTimeId -> !updateTimeIds.contains(existsTimeId));
List<Long> reduceIds = existsTimeIds.stream()
.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.sekillActivityCountIncr(updateTimeIds);
seckillTimeService.sekillActivityCountReduce(reduceIds); }
if (CollUtil.isNotEmpty(reduceIds)) {
seckillTimeService.sekillActivityCountDecr(reduceIds);
}
} }
/** /**
* 更新秒杀商品 * 更新秒杀商品
* 后台查出的数据和前台查出的数据进行遍历
* 1. 对前台数据进行遍历如果不存在于后台的 sku 中需要新增
* 2. 对后台数据进行遍历如果不存在于前台的 sku 中需要删除
* 3. 最后对当前活动商品全部更新更新秒杀时段id列表
*
* @param updateReqVO 更新的请求VO
*/ */
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,
@ -143,6 +132,9 @@ public class SeckillActivityServiceImpl implements SeckillActivityService {
if (CollUtil.isNotEmpty(newSeckillProductDOs)) { if (CollUtil.isNotEmpty(newSeckillProductDOs)) {
seckillProductMapper.insertBatch(newSeckillProductDOs); seckillProductMapper.insertBatch(newSeckillProductDOs);
} }
//全量更新当前活动商品的秒杀时段id列表timeIds
seckillProductMapper.updateTimeIdsByActivityId(updateReqVO.getId(), updateReqVO.getTimeIds());
} }
/** /**
@ -198,7 +190,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.sekillActivityCountDecr(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 sekillActivityCountIncr(Collection<Long> ids);
/** /**
@ -64,5 +72,5 @@ public interface SeckillTimeService {
* *
* @param ids 秒杀时段id列表 * @param ids 秒杀时段id列表
*/ */
void sekillActivityCountReduce(List<Long> ids); void sekillActivityCountDecr(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
@ -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,15 +101,24 @@ public class SeckillTimeServiceImpl implements SeckillTimeService {
return seckillTimeMapper.selectList(); return seckillTimeMapper.selectList();
} }
// TODO @halfninetyupdateActivityCount + -可以执使用一个方法实现哈多传递一个参数
@Override @Override
public void sekillActivityCountAdd(List<Long> ids) { public void validateSeckillTimeExists(Collection<Long> timeIds) {
seckillTimeMapper.sekillActivityCountAdd(ids); if (CollUtil.isEmpty(timeIds)) {
throw exception(SECKILL_TIME_NOT_EXISTS);
}
if (seckillTimeMapper.selectBatchIds(timeIds).size() != timeIds.size()) {
throw exception(SECKILL_TIME_NOT_EXISTS);
}
} }
@Override @Override
public void sekillActivityCountReduce(List<Long> ids) { public void sekillActivityCountIncr(Collection<Long> ids) {
seckillTimeMapper.sekillActivityCountReduce(ids); seckillTimeMapper.updateActivityCount(ids, "+", 1);
}
@Override
public void sekillActivityCountDecr(Collection<Long> ids) {
seckillTimeMapper.updateActivityCount(ids, "-", 1);
} }
} }

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;

View File

@ -51,10 +51,10 @@
<dict-tag :type="DICT_TYPE.PROMOTION_ACTIVITY_STATUS" :value="scope.row.status" /> <dict-tag :type="DICT_TYPE.PROMOTION_ACTIVITY_STATUS" :value="scope.row.status" />
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="参与场次" prop="timeId" width="250"> <el-table-column label="参与场次" prop="timeIds" width="250">
<template slot-scope="scope"> <template slot-scope="scope">
<span v-for="item in seckillTimeList" :key="item.id" <span v-for="item in seckillTimeList" :key="item.id"
v-if="scope.row.timeId.indexOf(item.id) !== -1"> v-if="scope.row.timeIds.includes(item.id)">
<el-tag style="margin:4px;" size="small">{{ item.name }}</el-tag> <el-tag style="margin:4px;" size="small">{{ item.name }}</el-tag>
</span> </span>
</template> </template>
@ -107,7 +107,7 @@
<el-input type="textarea" v-model="form.remark" placeholder="请输入备注" /> <el-input type="textarea" v-model="form.remark" placeholder="请输入备注" />
</el-form-item> </el-form-item>
<el-form-item label="场次选择"> <el-form-item label="场次选择">
<el-select v-model="form.timeId" placeholder="请选择参与场次" clearable size="small" multiple filterable <el-select v-model="form.timeIds" placeholder="请选择参与场次" clearable size="small" multiple filterable
style="width: 880px"> style="width: 880px">
<el-option v-for="item in seckillTimeList" :key="item.id" :label="item.name" :value="item.id"> <el-option v-for="item in seckillTimeList" :key="item.id" :label="item.name" :value="item.id">
<span style="float: left">{{ item.name + ': { ' }} {{ item.startTime }} -- {{ item.endTime + <span style="float: left">{{ item.name + ': { ' }} {{ item.startTime }} -- {{ item.endTime +
@ -223,7 +223,7 @@ export default {
form: { form: {
skuIds: [], // SKU skuIds: [], // SKU
products: [], // products: [], //
timeId: [], //id timeIds: [], //id
}, },
// SKU // SKU
productSkus: [], productSkus: [],
@ -233,7 +233,7 @@ export default {
status: [{ required: true, message: "活动状态不能为空", trigger: "blur" }], status: [{ required: true, message: "活动状态不能为空", trigger: "blur" }],
startAndEndTime: [{ required: true, message: "活动时间不能为空", trigger: "blur" }], startAndEndTime: [{ required: true, message: "活动时间不能为空", trigger: "blur" }],
sort: [{ required: true, message: "排序不能为空", trigger: "blur" }], sort: [{ required: true, message: "排序不能为空", trigger: "blur" }],
timeId: [{ required: true, message: "秒杀场次不能为空", trigger: "blur" }], timeIds: [{ required: true, message: "秒杀场次不能为空", trigger: "blur" }],
totalPrice: [{ required: true, message: "订单实付金额,单位:分不能为空", trigger: "blur" }], totalPrice: [{ required: true, message: "订单实付金额,单位:分不能为空", trigger: "blur" }],
} }
}; };
@ -247,6 +247,7 @@ export default {
methods: { methods: {
/** 查询列表 */ /** 查询列表 */
getList() { getList() {
// timeId
const timeId = this.$route.params && this.$route.params.timeId; const timeId = this.$route.params && this.$route.params.timeId;
if (timeId) { if (timeId) {
this.queryParams.timeId = timeId this.queryParams.timeId = timeId
@ -254,11 +255,13 @@ export default {
this.loading = true; this.loading = true;
// //
getSeckillActivityPage(this.queryParams).then(response => { getSeckillActivityPage(this.queryParams).then(response => {
console.log(response.data.list, "查询出的值");
this.list = response.data.list; this.list = response.data.list;
this.total = response.data.total; this.total = response.data.total;
this.loading = false; this.loading = false;
}); });
if (timeId) { if (timeId) {
//
this.$route.params.timeId = undefined this.$route.params.timeId = undefined
} }
// SKU // SKU
@ -285,7 +288,7 @@ export default {
startTime: undefined, startTime: undefined,
endTime: undefined, endTime: undefined,
sort: undefined, sort: undefined,
timeId: [], timeIds: [],
totalPrice: undefined, totalPrice: undefined,
skuIds: [], skuIds: [],
products: [], products: [],
@ -317,11 +320,9 @@ export default {
this.reset(); this.reset();
const id = row.id; const id = row.id;
getSeckillActivity(id).then(response => { getSeckillActivity(id).then(response => {
var timeIdList = response.data.timeId.split(',')
this.form = response.data; this.form = response.data;
// //
this.form.startAndEndTime = [response.data.startTime, response.data.endTime]; this.form.startAndEndTime = [response.data.startTime, response.data.endTime];
this.form.timeId = timeIdList.map(item => parseInt(item))
this.form.skuIds = response.data.products.map(item => item.skuId); this.form.skuIds = response.data.products.map(item => item.skuId);
this.form.products.forEach(product => { this.form.products.forEach(product => {
// SKU // SKU
@ -353,7 +354,6 @@ export default {
const data = deepClone(this.form); const data = deepClone(this.form);
data.startTime = this.form.startAndEndTime[0]; data.startTime = this.form.startAndEndTime[0];
data.endTime = this.form.startAndEndTime[1]; data.endTime = this.form.startAndEndTime[1];
data.timeId = data.timeId.toString();
data.products.forEach(product => { data.products.forEach(product => {
product.stock = product.seckillStock; product.stock = product.seckillStock;
product.seckillPrice = product.seckillPrice !== undefined ? product.seckillPrice * 100 : undefined; product.seckillPrice = product.seckillPrice !== undefined ? product.seckillPrice * 100 : undefined;