mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-22 23:31:52 +08:00
秒杀活动,添加商品,分页查询
This commit is contained in:
parent
7056d89b0c
commit
83ee1c6129
@ -45,4 +45,7 @@ public interface ErrorCodeConstants {
|
||||
// ========== Price 相关 1003007000 ============
|
||||
ErrorCode PRICE_CALCULATE_PAY_PRICE_ILLEGAL = new ErrorCode(1003007000, "支付价格计算异常,原因:价格小于等于 0");
|
||||
|
||||
// ========== 秒杀活动 1003008000 ==========
|
||||
ErrorCode SECKILL_ACTIVITY_NOT_EXISTS = new ErrorCode(1003008000, "秒杀活动不存在");
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,100 @@
|
||||
package cn.iocoder.yudao.module.promotion.controller.admin.seckillactivity;
|
||||
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import io.swagger.annotations.*;
|
||||
|
||||
import javax.validation.constraints.*;
|
||||
import javax.validation.*;
|
||||
import javax.servlet.http.*;
|
||||
import java.util.*;
|
||||
import java.io.IOException;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
|
||||
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
||||
|
||||
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
|
||||
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;
|
||||
|
||||
import cn.iocoder.yudao.module.promotion.controller.admin.seckillactivity.vo.*;
|
||||
import cn.iocoder.yudao.module.promotion.dal.dataobject.seckillactivity.SeckillActivityDO;
|
||||
import cn.iocoder.yudao.module.promotion.convert.seckillactivity.SeckillActivityConvert;
|
||||
import cn.iocoder.yudao.module.promotion.service.seckillactivity.SeckillActivityService;
|
||||
|
||||
@Api(tags = "管理后台 - 秒杀活动")
|
||||
@RestController
|
||||
@RequestMapping("/promotion/seckill-activity")
|
||||
@Validated
|
||||
public class SeckillActivityController {
|
||||
|
||||
@Resource
|
||||
private SeckillActivityService seckillActivityService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@ApiOperation("创建秒杀活动")
|
||||
@PreAuthorize("@ss.hasPermission('promotion:seckill-activity:create')")
|
||||
public CommonResult<Long> createSeckillActivity(@Valid @RequestBody SeckillActivityCreateReqVO createReqVO) {
|
||||
return success(seckillActivityService.createSeckillActivity(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@ApiOperation("更新秒杀活动")
|
||||
@PreAuthorize("@ss.hasPermission('promotion:seckill-activity:update')")
|
||||
public CommonResult<Boolean> updateSeckillActivity(@Valid @RequestBody SeckillActivityUpdateReqVO updateReqVO) {
|
||||
seckillActivityService.updateSeckillActivity(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@ApiOperation("删除秒杀活动")
|
||||
@ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class)
|
||||
@PreAuthorize("@ss.hasPermission('promotion:seckill-activity:delete')")
|
||||
public CommonResult<Boolean> deleteSeckillActivity(@RequestParam("id") Long id) {
|
||||
seckillActivityService.deleteSeckillActivity(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@ApiOperation("获得秒杀活动")
|
||||
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
|
||||
@PreAuthorize("@ss.hasPermission('promotion:seckill-activity:query')")
|
||||
public CommonResult<SeckillActivityRespVO> getSeckillActivity(@RequestParam("id") Long id) {
|
||||
SeckillActivityDO seckillActivity = seckillActivityService.getSeckillActivity(id);
|
||||
return success(SeckillActivityConvert.INSTANCE.convert(seckillActivity));
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("获得秒杀活动列表")
|
||||
@ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
|
||||
@PreAuthorize("@ss.hasPermission('promotion:seckill-activity:query')")
|
||||
public CommonResult<List<SeckillActivityRespVO>> getSeckillActivityList(@RequestParam("ids") Collection<Long> ids) {
|
||||
List<SeckillActivityDO> list = seckillActivityService.getSeckillActivityList(ids);
|
||||
return success(SeckillActivityConvert.INSTANCE.convertList(list));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@ApiOperation("获得秒杀活动分页")
|
||||
@PreAuthorize("@ss.hasPermission('promotion:seckill-activity:query')")
|
||||
public CommonResult<PageResult<SeckillActivityRespVO>> getSeckillActivityPage(@Valid SeckillActivityPageReqVO pageVO) {
|
||||
PageResult<SeckillActivityDO> pageResult = seckillActivityService.getSeckillActivityPage(pageVO);
|
||||
return success(SeckillActivityConvert.INSTANCE.convertPage(pageResult));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@ApiOperation("导出秒杀活动 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('promotion:seckill-activity:export')")
|
||||
@OperateLog(type = EXPORT)
|
||||
public void exportSeckillActivityExcel(@Valid SeckillActivityExportReqVO exportReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
List<SeckillActivityDO> list = seckillActivityService.getSeckillActivityList(exportReqVO);
|
||||
// 导出 Excel
|
||||
List<SeckillActivityExcelVO> datas = SeckillActivityConvert.INSTANCE.convertList02(list);
|
||||
ExcelUtils.write(response, "秒杀活动.xls", "数据", SeckillActivityExcelVO.class, datas);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package cn.iocoder.yudao.module.promotion.controller.admin.seckillactivity.vo;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import java.math.BigDecimal;
|
||||
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 使用
|
||||
* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成
|
||||
*/
|
||||
@Data
|
||||
public class SeckillActivityBaseVO {
|
||||
|
||||
@ApiModelProperty(value = "秒杀活动名称", required = true, example = "晚九点限时秒杀")
|
||||
@NotNull(message = "秒杀活动名称不能为空")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty(value = "活动状态", required = true, example = "进行中")
|
||||
@NotNull(message = "活动状态不能为空")
|
||||
private Integer status;
|
||||
|
||||
@ApiModelProperty(value = "活动开始时间", required = true)
|
||||
@NotNull(message = "活动开始时间不能为空")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private Date startTime;
|
||||
|
||||
@ApiModelProperty(value = "活动结束时间", required = true)
|
||||
@NotNull(message = "活动结束时间不能为空")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private Date endTime;
|
||||
|
||||
@ApiModelProperty(value = "订单实付金额,单位:分", required = true)
|
||||
@NotNull(message = "订单实付金额,单位:分不能为空")
|
||||
private BigDecimal totalPrice;
|
||||
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package cn.iocoder.yudao.module.promotion.controller.admin.seckillactivity.vo;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import io.swagger.annotations.*;
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
@ApiModel("管理后台 - 秒杀活动创建 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class SeckillActivityCreateReqVO extends SeckillActivityBaseVO {
|
||||
|
||||
@ApiModelProperty(value = "备注", example = "限时秒杀活动")
|
||||
private String remark;
|
||||
|
||||
@ApiModelProperty(value = "排序", required = true)
|
||||
@NotNull(message = "排序不能为空")
|
||||
private Integer sort;
|
||||
|
||||
@ApiModelProperty(value = "秒杀时段id", required = true)
|
||||
@NotNull(message = "秒杀时段id不能为空")
|
||||
private Long timeId;
|
||||
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package cn.iocoder.yudao.module.promotion.controller.admin.seckillactivity.vo;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import java.math.BigDecimal;
|
||||
import io.swagger.annotations.*;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
|
||||
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
|
||||
|
||||
|
||||
/**
|
||||
* 秒杀活动 Excel VO
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Data
|
||||
public class SeckillActivityExcelVO {
|
||||
|
||||
@ExcelProperty("秒杀活动名称")
|
||||
private String name;
|
||||
|
||||
@ExcelProperty(value = "活动状态", converter = DictConvert.class)
|
||||
@DictFormat("promotion_activity_status") // TODO 代码优化:建议设置到对应的 XXXDictTypeConstants 枚举类中
|
||||
private Integer status;
|
||||
|
||||
@ExcelProperty("活动开始时间")
|
||||
private Date startTime;
|
||||
|
||||
@ExcelProperty("活动结束时间")
|
||||
private Date endTime;
|
||||
|
||||
@ExcelProperty("付款订单数")
|
||||
private Integer orderCount;
|
||||
|
||||
@ExcelProperty("付款人数")
|
||||
private Integer userCount;
|
||||
|
||||
@ExcelProperty("订单实付金额,单位:分")
|
||||
private BigDecimal totalPrice;
|
||||
|
||||
@ExcelProperty("创建时间")
|
||||
private Date createTime;
|
||||
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package cn.iocoder.yudao.module.promotion.controller.admin.seckillactivity.vo;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import io.swagger.annotations.*;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@ApiModel(value = "管理后台 - 秒杀活动 Excel 导出 Request VO", description = "参数和 SeckillActivityPageReqVO 是一致的")
|
||||
@Data
|
||||
public class SeckillActivityExportReqVO {
|
||||
|
||||
@ApiModelProperty(value = "秒杀活动名称", example = "晚九点限时秒杀")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty(value = "活动状态", example = "进行中")
|
||||
private Integer status;
|
||||
|
||||
@ApiModelProperty(value = "秒杀时段id")
|
||||
private Long timeId;
|
||||
|
||||
@ApiModelProperty(value = "创建时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private Date[] createTime;
|
||||
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package cn.iocoder.yudao.module.promotion.controller.admin.seckillactivity.vo;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import io.swagger.annotations.*;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@ApiModel("管理后台 - 秒杀活动分页 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class SeckillActivityPageReqVO extends PageParam {
|
||||
|
||||
@ApiModelProperty(value = "秒杀活动名称", example = "晚九点限时秒杀")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty(value = "活动状态", example = "进行中")
|
||||
private Integer status;
|
||||
|
||||
@ApiModelProperty(value = "秒杀时段id")
|
||||
private Long timeId;
|
||||
|
||||
@ApiModelProperty(value = "创建时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private Date[] createTime;
|
||||
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package cn.iocoder.yudao.module.promotion.controller.admin.seckillactivity.vo;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import io.swagger.annotations.*;
|
||||
|
||||
@ApiModel("管理后台 - 秒杀活动 Response VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class SeckillActivityRespVO extends SeckillActivityBaseVO {
|
||||
|
||||
@ApiModelProperty(value = "秒杀活动id", required = true, example = "1")
|
||||
private Long id;
|
||||
|
||||
@ApiModelProperty(value = "付款订单数", required = true)
|
||||
private Integer orderCount;
|
||||
|
||||
@ApiModelProperty(value = "付款人数", required = true)
|
||||
private Integer userCount;
|
||||
|
||||
@ApiModelProperty(value = "创建时间", required = true)
|
||||
private Date createTime;
|
||||
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package cn.iocoder.yudao.module.promotion.controller.admin.seckillactivity.vo;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import io.swagger.annotations.*;
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
@ApiModel("管理后台 - 秒杀活动更新 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class SeckillActivityUpdateReqVO extends SeckillActivityBaseVO {
|
||||
|
||||
@ApiModelProperty(value = "秒杀活动编号", required = true, example = "224")
|
||||
@NotNull(message = "秒杀活动编号不能为空")
|
||||
private Long id;
|
||||
|
||||
@ApiModelProperty(value = "备注", example = "限时秒杀活动")
|
||||
private String remark;
|
||||
|
||||
@ApiModelProperty(value = "排序", required = true)
|
||||
@NotNull(message = "排序不能为空")
|
||||
private Integer sort;
|
||||
|
||||
@ApiModelProperty(value = "秒杀时段id", required = true)
|
||||
@NotNull(message = "秒杀时段id不能为空")
|
||||
private Long timeId;
|
||||
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package cn.iocoder.yudao.module.promotion.convert.seckillactivity;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
import cn.iocoder.yudao.module.promotion.controller.admin.seckillactivity.vo.*;
|
||||
import cn.iocoder.yudao.module.promotion.dal.dataobject.seckillactivity.SeckillActivityDO;
|
||||
|
||||
/**
|
||||
* 秒杀活动 Convert
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Mapper
|
||||
public interface SeckillActivityConvert {
|
||||
|
||||
SeckillActivityConvert INSTANCE = Mappers.getMapper(SeckillActivityConvert.class);
|
||||
|
||||
SeckillActivityDO convert(SeckillActivityCreateReqVO bean);
|
||||
|
||||
SeckillActivityDO convert(SeckillActivityUpdateReqVO bean);
|
||||
|
||||
SeckillActivityRespVO convert(SeckillActivityDO bean);
|
||||
|
||||
List<SeckillActivityRespVO> convertList(List<SeckillActivityDO> list);
|
||||
|
||||
PageResult<SeckillActivityRespVO> convertPage(PageResult<SeckillActivityDO> page);
|
||||
|
||||
List<SeckillActivityExcelVO> convertList02(List<SeckillActivityDO> list);
|
||||
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
package cn.iocoder.yudao.module.promotion.dal.dataobject.seckillactivity;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import java.math.BigDecimal;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
|
||||
/**
|
||||
* 秒杀活动 DO
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@TableName("promotion_seckill_activity")
|
||||
@KeySequence("promotion_seckill_activity_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class SeckillActivityDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* 秒杀活动编号
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
/**
|
||||
* 秒杀活动名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 活动状态
|
||||
*
|
||||
* 枚举 {@link TODO promotion_activity_status 对应的类}
|
||||
*/
|
||||
private Integer status;
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
/**
|
||||
* 活动开始时间
|
||||
*/
|
||||
private Date startTime;
|
||||
/**
|
||||
* 活动结束时间
|
||||
*/
|
||||
private Date endTime;
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
private Integer sort;
|
||||
/**
|
||||
* 秒杀时段id
|
||||
*/
|
||||
private Long timeId;
|
||||
/**
|
||||
* 付款订单数
|
||||
*/
|
||||
private Integer orderCount;
|
||||
/**
|
||||
* 付款人数
|
||||
*/
|
||||
private Integer userCount;
|
||||
/**
|
||||
* 订单实付金额,单位:分
|
||||
*/
|
||||
private BigDecimal totalPrice;
|
||||
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package cn.iocoder.yudao.module.promotion.dal.mysql.seckillactivity;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.module.promotion.dal.dataobject.seckillactivity.SeckillActivityDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import cn.iocoder.yudao.module.promotion.controller.admin.seckillactivity.vo.*;
|
||||
|
||||
/**
|
||||
* 秒杀活动 Mapper
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Mapper
|
||||
public interface SeckillActivityMapper extends BaseMapperX<SeckillActivityDO> {
|
||||
|
||||
default PageResult<SeckillActivityDO> selectPage(SeckillActivityPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<SeckillActivityDO>()
|
||||
.likeIfPresent(SeckillActivityDO::getName, reqVO.getName())
|
||||
.eqIfPresent(SeckillActivityDO::getStatus, reqVO.getStatus())
|
||||
.eqIfPresent(SeckillActivityDO::getTimeId, reqVO.getTimeId())
|
||||
.betweenIfPresent(SeckillActivityDO::getCreateTime, reqVO.getCreateTime())
|
||||
.orderByDesc(SeckillActivityDO::getId));
|
||||
}
|
||||
|
||||
default List<SeckillActivityDO> selectList(SeckillActivityExportReqVO reqVO) {
|
||||
return selectList(new LambdaQueryWrapperX<SeckillActivityDO>()
|
||||
.likeIfPresent(SeckillActivityDO::getName, reqVO.getName())
|
||||
.eqIfPresent(SeckillActivityDO::getStatus, reqVO.getStatus())
|
||||
.eqIfPresent(SeckillActivityDO::getTimeId, reqVO.getTimeId())
|
||||
.betweenIfPresent(SeckillActivityDO::getCreateTime, reqVO.getCreateTime())
|
||||
.orderByDesc(SeckillActivityDO::getId));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
package cn.iocoder.yudao.module.promotion.service.seckillactivity;
|
||||
|
||||
import java.util.*;
|
||||
import javax.validation.*;
|
||||
import cn.iocoder.yudao.module.promotion.controller.admin.seckillactivity.vo.*;
|
||||
import cn.iocoder.yudao.module.promotion.dal.dataobject.seckillactivity.SeckillActivityDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
|
||||
/**
|
||||
* 秒杀活动 Service 接口
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
public interface SeckillActivityService {
|
||||
|
||||
/**
|
||||
* 创建秒杀活动
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Long createSeckillActivity(@Valid SeckillActivityCreateReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新秒杀活动
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updateSeckillActivity(@Valid SeckillActivityUpdateReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除秒杀活动
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deleteSeckillActivity(Long id);
|
||||
|
||||
/**
|
||||
* 获得秒杀活动
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 秒杀活动
|
||||
*/
|
||||
SeckillActivityDO getSeckillActivity(Long id);
|
||||
|
||||
/**
|
||||
* 获得秒杀活动列表
|
||||
*
|
||||
* @param ids 编号
|
||||
* @return 秒杀活动列表
|
||||
*/
|
||||
List<SeckillActivityDO> getSeckillActivityList(Collection<Long> ids);
|
||||
|
||||
/**
|
||||
* 获得秒杀活动分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 秒杀活动分页
|
||||
*/
|
||||
PageResult<SeckillActivityDO> getSeckillActivityPage(SeckillActivityPageReqVO pageReqVO);
|
||||
|
||||
/**
|
||||
* 获得秒杀活动列表, 用于 Excel 导出
|
||||
*
|
||||
* @param exportReqVO 查询条件
|
||||
* @return 秒杀活动列表
|
||||
*/
|
||||
List<SeckillActivityDO> getSeckillActivityList(SeckillActivityExportReqVO exportReqVO);
|
||||
|
||||
}
|
@ -0,0 +1,82 @@
|
||||
package cn.iocoder.yudao.module.promotion.service.seckillactivity;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import java.util.*;
|
||||
import cn.iocoder.yudao.module.promotion.controller.admin.seckillactivity.vo.*;
|
||||
import cn.iocoder.yudao.module.promotion.dal.dataobject.seckillactivity.SeckillActivityDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
|
||||
import cn.iocoder.yudao.module.promotion.convert.seckillactivity.SeckillActivityConvert;
|
||||
import cn.iocoder.yudao.module.promotion.dal.mysql.seckillactivity.SeckillActivityMapper;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*;
|
||||
|
||||
/**
|
||||
* 秒杀活动 Service 实现类
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class SeckillActivityServiceImpl implements SeckillActivityService {
|
||||
|
||||
@Resource
|
||||
private SeckillActivityMapper seckillActivityMapper;
|
||||
|
||||
@Override
|
||||
public Long createSeckillActivity(SeckillActivityCreateReqVO createReqVO) {
|
||||
// 插入
|
||||
SeckillActivityDO seckillActivity = SeckillActivityConvert.INSTANCE.convert(createReqVO);
|
||||
seckillActivityMapper.insert(seckillActivity);
|
||||
// 返回
|
||||
return seckillActivity.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSeckillActivity(SeckillActivityUpdateReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
this.validateSeckillActivityExists(updateReqVO.getId());
|
||||
// 更新
|
||||
SeckillActivityDO updateObj = SeckillActivityConvert.INSTANCE.convert(updateReqVO);
|
||||
seckillActivityMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteSeckillActivity(Long id) {
|
||||
// 校验存在
|
||||
this.validateSeckillActivityExists(id);
|
||||
// 删除
|
||||
seckillActivityMapper.deleteById(id);
|
||||
}
|
||||
|
||||
private void validateSeckillActivityExists(Long id) {
|
||||
if (seckillActivityMapper.selectById(id) == null) {
|
||||
throw exception(SECKILL_ACTIVITY_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SeckillActivityDO getSeckillActivity(Long id) {
|
||||
return seckillActivityMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SeckillActivityDO> getSeckillActivityList(Collection<Long> ids) {
|
||||
return seckillActivityMapper.selectBatchIds(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<SeckillActivityDO> getSeckillActivityPage(SeckillActivityPageReqVO pageReqVO) {
|
||||
return seckillActivityMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SeckillActivityDO> getSeckillActivityList(SeckillActivityExportReqVO exportReqVO) {
|
||||
return seckillActivityMapper.selectList(exportReqVO);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
<?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.seckillactivity.SeckillActivityMapper">
|
||||
|
||||
<!--
|
||||
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
|
||||
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
|
||||
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
|
||||
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
||||
-->
|
||||
|
||||
</mapper>
|
@ -0,0 +1,173 @@
|
||||
package cn.iocoder.yudao.module.promotion.service.seckillactivity;
|
||||
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
|
||||
|
||||
import cn.iocoder.yudao.module.promotion.controller.admin.seckillactivity.vo.*;
|
||||
import cn.iocoder.yudao.module.promotion.dal.dataobject.seckillactivity.SeckillActivityDO;
|
||||
import cn.iocoder.yudao.module.promotion.dal.mysql.seckillactivity.SeckillActivityMapper;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import java.util.*;
|
||||
|
||||
import static cn.hutool.core.util.RandomUtil.*;
|
||||
import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*;
|
||||
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*;
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
* {@link SeckillActivityServiceImpl} 的单元测试类
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Import(SeckillActivityServiceImpl.class)
|
||||
public class SeckillActivityServiceImplTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private SeckillActivityServiceImpl seckillActivityService;
|
||||
|
||||
@Resource
|
||||
private SeckillActivityMapper seckillActivityMapper;
|
||||
|
||||
@Test
|
||||
public void testCreateSeckillActivity_success() {
|
||||
// 准备参数
|
||||
SeckillActivityCreateReqVO reqVO = randomPojo(SeckillActivityCreateReqVO.class);
|
||||
|
||||
// 调用
|
||||
Long seckillActivityId = seckillActivityService.createSeckillActivity(reqVO);
|
||||
// 断言
|
||||
assertNotNull(seckillActivityId);
|
||||
// 校验记录的属性是否正确
|
||||
SeckillActivityDO seckillActivity = seckillActivityMapper.selectById(seckillActivityId);
|
||||
assertPojoEquals(reqVO, seckillActivity);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateSeckillActivity_success() {
|
||||
// mock 数据
|
||||
SeckillActivityDO dbSeckillActivity = randomPojo(SeckillActivityDO.class);
|
||||
seckillActivityMapper.insert(dbSeckillActivity);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
SeckillActivityUpdateReqVO reqVO = randomPojo(SeckillActivityUpdateReqVO.class, o -> {
|
||||
o.setId(dbSeckillActivity.getId()); // 设置更新的 ID
|
||||
});
|
||||
|
||||
// 调用
|
||||
seckillActivityService.updateSeckillActivity(reqVO);
|
||||
// 校验是否更新正确
|
||||
SeckillActivityDO seckillActivity = seckillActivityMapper.selectById(reqVO.getId()); // 获取最新的
|
||||
assertPojoEquals(reqVO, seckillActivity);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateSeckillActivity_notExists() {
|
||||
// 准备参数
|
||||
SeckillActivityUpdateReqVO reqVO = randomPojo(SeckillActivityUpdateReqVO.class);
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> seckillActivityService.updateSeckillActivity(reqVO), SECKILL_ACTIVITY_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteSeckillActivity_success() {
|
||||
// mock 数据
|
||||
SeckillActivityDO dbSeckillActivity = randomPojo(SeckillActivityDO.class);
|
||||
seckillActivityMapper.insert(dbSeckillActivity);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
Long id = dbSeckillActivity.getId();
|
||||
|
||||
// 调用
|
||||
seckillActivityService.deleteSeckillActivity(id);
|
||||
// 校验数据不存在了
|
||||
assertNull(seckillActivityMapper.selectById(id));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteSeckillActivity_notExists() {
|
||||
// 准备参数
|
||||
Long id = randomLongId();
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> seckillActivityService.deleteSeckillActivity(id), SECKILL_ACTIVITY_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
|
||||
public void testGetSeckillActivityPage() {
|
||||
// mock 数据
|
||||
SeckillActivityDO dbSeckillActivity = randomPojo(SeckillActivityDO.class, o -> { // 等会查询到
|
||||
o.setName(null);
|
||||
o.setStatus(null);
|
||||
o.setTimeId(null);
|
||||
o.setCreateTime(null);
|
||||
});
|
||||
seckillActivityMapper.insert(dbSeckillActivity);
|
||||
// 测试 name 不匹配
|
||||
seckillActivityMapper.insert(cloneIgnoreId(dbSeckillActivity, o -> o.setName(null)));
|
||||
// 测试 status 不匹配
|
||||
seckillActivityMapper.insert(cloneIgnoreId(dbSeckillActivity, o -> o.setStatus(null)));
|
||||
// 测试 timeId 不匹配
|
||||
seckillActivityMapper.insert(cloneIgnoreId(dbSeckillActivity, o -> o.setTimeId(null)));
|
||||
// 测试 createTime 不匹配
|
||||
seckillActivityMapper.insert(cloneIgnoreId(dbSeckillActivity, o -> o.setCreateTime(null)));
|
||||
// 准备参数
|
||||
SeckillActivityPageReqVO reqVO = new SeckillActivityPageReqVO();
|
||||
reqVO.setName(null);
|
||||
reqVO.setStatus(null);
|
||||
reqVO.setTimeId(null);
|
||||
reqVO.setCreateTime((new Date[]{}));
|
||||
|
||||
// 调用
|
||||
PageResult<SeckillActivityDO> pageResult = seckillActivityService.getSeckillActivityPage(reqVO);
|
||||
// 断言
|
||||
assertEquals(1, pageResult.getTotal());
|
||||
assertEquals(1, pageResult.getList().size());
|
||||
assertPojoEquals(dbSeckillActivity, pageResult.getList().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
|
||||
public void testGetSeckillActivityList() {
|
||||
// mock 数据
|
||||
SeckillActivityDO dbSeckillActivity = randomPojo(SeckillActivityDO.class, o -> { // 等会查询到
|
||||
o.setName(null);
|
||||
o.setStatus(null);
|
||||
o.setTimeId(null);
|
||||
o.setCreateTime(null);
|
||||
});
|
||||
seckillActivityMapper.insert(dbSeckillActivity);
|
||||
// 测试 name 不匹配
|
||||
seckillActivityMapper.insert(cloneIgnoreId(dbSeckillActivity, o -> o.setName(null)));
|
||||
// 测试 status 不匹配
|
||||
seckillActivityMapper.insert(cloneIgnoreId(dbSeckillActivity, o -> o.setStatus(null)));
|
||||
// 测试 timeId 不匹配
|
||||
seckillActivityMapper.insert(cloneIgnoreId(dbSeckillActivity, o -> o.setTimeId(null)));
|
||||
// 测试 createTime 不匹配
|
||||
seckillActivityMapper.insert(cloneIgnoreId(dbSeckillActivity, o -> o.setCreateTime(null)));
|
||||
// 准备参数
|
||||
SeckillActivityExportReqVO reqVO = new SeckillActivityExportReqVO();
|
||||
reqVO.setName(null);
|
||||
reqVO.setStatus(null);
|
||||
reqVO.setTimeId(null);
|
||||
reqVO.setCreateTime((new Date[]{}));
|
||||
|
||||
// 调用
|
||||
List<SeckillActivityDO> list = seckillActivityService.getSeckillActivityList(reqVO);
|
||||
// 断言
|
||||
assertEquals(1, list.size());
|
||||
assertPojoEquals(dbSeckillActivity, list.get(0));
|
||||
}
|
||||
|
||||
}
|
54
yudao-ui-admin/src/api/promotion/seckillActivity.js
Normal file
54
yudao-ui-admin/src/api/promotion/seckillActivity.js
Normal file
@ -0,0 +1,54 @@
|
||||
import request from '@/utils/request'
|
||||
|
||||
// 创建秒杀活动
|
||||
export function createSeckillActivity(data) {
|
||||
return request({
|
||||
url: '/promotion/seckill-activity/create',
|
||||
method: 'post',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
|
||||
// 更新秒杀活动
|
||||
export function updateSeckillActivity(data) {
|
||||
return request({
|
||||
url: '/promotion/seckill-activity/update',
|
||||
method: 'put',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
|
||||
// 删除秒杀活动
|
||||
export function deleteSeckillActivity(id) {
|
||||
return request({
|
||||
url: '/promotion/seckill-activity/delete?id=' + id,
|
||||
method: 'delete'
|
||||
})
|
||||
}
|
||||
|
||||
// 获得秒杀活动
|
||||
export function getSeckillActivity(id) {
|
||||
return request({
|
||||
url: '/promotion/seckill-activity/get?id=' + id,
|
||||
method: 'get'
|
||||
})
|
||||
}
|
||||
|
||||
// 获得秒杀活动分页
|
||||
export function getSeckillActivityPage(query) {
|
||||
return request({
|
||||
url: '/promotion/seckill-activity/page',
|
||||
method: 'get',
|
||||
params: query
|
||||
})
|
||||
}
|
||||
|
||||
// 导出秒杀活动 Excel
|
||||
export function exportSeckillActivityExcel(query) {
|
||||
return request({
|
||||
url: '/promotion/seckill-activity/export-excel',
|
||||
method: 'get',
|
||||
params: query,
|
||||
responseType: 'blob'
|
||||
})
|
||||
}
|
Loading…
Reference in New Issue
Block a user