Commit 9f576514 authored by zhangfeng's avatar zhangfeng

feature-reward:接口基础功能完成

parent 7b20bfe6
......@@ -58,4 +58,11 @@ public interface RewardConvert {
* @return
*/
RewardDO convertStatusReqVO(RewardStatusReqVO bean);
/***
* 礼品延期VO转实体
* @param bean
* @return
*/
RewardDO convertDelayReqVO(RewardDelayReqVO bean);
}
......@@ -6,6 +6,7 @@ import cn.iocoder.yudao.framework.common.exception.ErrorCode;
// TODO 待办:请将下面的错误码复制到 yudao-module-reward-api 模块的 ErrorCodeConstants 类中。注意,请给“TODO 补充编号”设置一个错误码编号!!!
// ========== 礼品 TODO 补充编号 ==========
public interface ErrorCodeConstants {
ErrorCode _NOT_EXISTS = new ErrorCode(1009011000, "礼品不存在");
ErrorCode REWARD_NOT_EXISTS = new ErrorCode(1010011001, "礼品不存在");
ErrorCode REWARD_ENDTIME_ERROR = new ErrorCode(1001011002, "礼品结束时间不能早于当前时间");
}
......@@ -62,4 +62,15 @@ public interface RewardService extends IService<RewardDO> {
* @return 礼品列表
*/
List<RewardDO> getList(RewardQueryVO query);
/**
* 复制礼品
* @param id 编号
* @return 新的礼品id
*/
Long copyReward(Long id);
void delayReward(RewardDelayReqVO delayVO);
void updateStatus(RewardStatusReqVO statusVO);
}
package cn.iocoder.yudao.module.reward.service.reward;
import java.time.Instant;
import java.util.*;
import javax.annotation.Resource;
import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQuery;
import cn.iocoder.yudao.module.reward.enums.ErrorCodeConstants;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import cn.iocoder.yudao.framework.mybatis.core.vo.PageVO;
......@@ -59,7 +62,7 @@ public class RewardServiceImpl extends AbstractService<RewardMapper, RewardDO> i
private void validateExists(Long id) {
if (rewardMapper.selectById(id) == null) {
throw exception(_NOT_EXISTS);
throw exception(REWARD_NOT_EXISTS);
}
}
......@@ -126,6 +129,42 @@ public class RewardServiceImpl extends AbstractService<RewardMapper, RewardDO> i
return rewardMapper.selectList(query);
}
@Override
public Long copyReward(Long id) {
RewardDO reward = rewardMapper.selectById(id);
if (reward == null) {
throw exception(REWARD_NOT_EXISTS);
}
//重新生成礼品ID
reward.setCode(generateRewardCode());
//设置为未启用
reward.setStatus(2);
reward.setId(null);
reward.setCreateTime(null);
reward.setUpdateTime(null);
reward.setDeleted(null);
rewardMapper.insert(reward);
return reward.getId();
}
@Override
public void delayReward(RewardDelayReqVO delayVO) {
this.validateExists(delayVO.getId());
Instant now = Instant.now();
//结束时间不能小于当前时间
if (!delayVO.getEndTime().toInstant().isAfter(now)) {
throw ServiceExceptionUtil.exception(ErrorCodeConstants.REWARD_ENDTIME_ERROR);
}
rewardMapper.updateById(RewardConvert.INSTANCE.convertDelayReqVO(delayVO));
}
@Override
public void updateStatus(RewardStatusReqVO statusVO) {
this.validateExists(statusVO.getId());
rewardMapper.updateById(RewardConvert.INSTANCE.convertStatusReqVO(statusVO));
}
//生成礼品ID
private String generateRewardCode() {
String uuid = UUID.randomUUID().toString().replaceAll("-", "");
......
package cn.iocoder.yudao.module.reward.vo.reward;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import javax.validation.constraints.NotNull;
import java.util.Date;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Data
@ApiModel("管理后台 - 礼品延期 VO")
public class RewardDelayReqVO {
@ApiModelProperty(value = "", required = true)
@NotNull(message = "不能为空")
private Long id;
@ApiModelProperty(value = "活动结束时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
@NotNull(message = "结束时间不能为空")
private Date endTime;
}
......@@ -18,6 +18,7 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.io.IOException;
import java.util.Collection;
import java.util.List;
......@@ -88,7 +89,20 @@ public class RewardController {
@ApiOperation("礼品状态变更")
//@PreAuthorize("@ss.hasPermission('reward::query')")
public CommonResult<Boolean> updateStatus(@Valid @RequestBody RewardStatusReqVO statusVO) {
rewardService.updateById(RewardConvert.INSTANCE.convertStatusReqVO(statusVO));
rewardService.updateStatus(statusVO);
return success(true);
}
@PostMapping("/copy/{id}")
@ApiOperation("复制礼品")
public CommonResult<Long> copyReward(@NotNull @PathVariable Long id) {
return success(rewardService.copyReward(id));
}
@PostMapping("/delay")
@ApiOperation("礼品延期")
public CommonResult<Boolean> delayReward(@Valid @RequestBody RewardDelayReqVO delayVO) {
rewardService.delayReward(delayVO);
return success(true);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment