ActivityController
代码语言:javascript复制@PreAuthorize("hasPermission('tienchin:activity:create')")
@Log(title = "活动管理", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@Validated @RequestBody ActivityVO activityVO) {
return AjaxResult.success(iActivityService.addActivity(activityVO) > 0 ? "添加成功" : "添加失败");
}
IActivityService
代码语言:javascript复制/**
* 添加活动
*
* @param activityVO 活动信息
* @return 结果
*/
int addActivity(ActivityVO activityVO);
ActivityServiceImpl
代码语言:javascript复制@Override
public int addActivity(ActivityVO activityVO) {
Activity activity = new Activity();
BeanUtils.copyProperties(activityVO, activity);
activity.setCreateTime(LocalDateTime.now());
activity.setCreateBy(SecurityUtils.getUsername());
return save(activity) ? 1 : 0;
}
ValidationMessages.properties
代码语言:javascript复制# 活动管理
activity.name.notBlank=活动名称不能为空
activity.name.size=活动名称最大长度为20个字符
activity.channelId.notnull=渠道ID不能为空
activity.info.notBlank=活动简介不能为空
activity.info.size=活动简介最多为255个字符
activity.type.notnull=活动类型不能为空
activity.status.max=活动状态最大值为1
activity.status.min=活动状态最小值为0
activity.discount.max=折扣最大值为1
activity.discount.min=折扣最小值为0
activity.voucher.min=代金券最小值为0
activity.beginTime.notnull=活动开始时间不能为空
activity.endTime.notnull=活动结束时间不能为空
ActivityVO
代码语言:javascript复制/**
* 活动名称
*/
@NotBlank(message = "{activity.name.notBlank}")
@Size(max = 20, message = "{activity.name.size}")
private String activityName;
/**
* 渠道ID
*/
@NotNull(message = "{activity.channelId.notnull}")
private Integer channelId;
/**
* 渠道名称
*/
private String channelName;
/**
* 活动简介
*/
@NotBlank(message = "{activity.info.notBlank}")
@Size(max = 255, message = "{activity.info.size}")
private String activityInfo;
/**
* 活动类型,1.折扣券、2.代金券
*/
@NotNull(message = "{activity.type.notnull}")
private Integer activityType;
/**
* 活动状态,0.表示禁用、1.表示正常
*/
@Max(value = 1, message = "{activity.status.max}")
@Min(value = 0, message = "{activity.status.min}")
private Integer activityStatus;
/**
* 折扣券
*/
@Max(value = 10, message = "{activity.discount.max}")
@Min(value = 0, message = "{activity.discount.min}")
private Double discount;
/**
* 代金券
*/
@Min(value = 0, message = "{activity.voucher.min}")
private Double voucher;
/**
* 活动开始时间
*/
@NotNull(message = "{activity.beginTime.notnull}")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai")
private LocalDateTime beginTime;
/**
* 活动结束时间
*/
@NotNull(message = "{activity.endTime.notnull}")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai")
private LocalDateTime endTime;
BaseEntity
给基础实体类时间字段添加时区属性。
代码语言:javascript复制/**
* 创建时间
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai")
private Date createTime;
/**
* 更新时间
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai")
private Date updateTime;