Commit 9f576514 authored by zhangfeng's avatar zhangfeng

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

parent 7b20bfe6
...@@ -58,4 +58,11 @@ public interface RewardConvert { ...@@ -58,4 +58,11 @@ public interface RewardConvert {
* @return * @return
*/ */
RewardDO convertStatusReqVO(RewardStatusReqVO bean); RewardDO convertStatusReqVO(RewardStatusReqVO bean);
/***
* 礼品延期VO转实体
* @param bean
* @return
*/
RewardDO convertDelayReqVO(RewardDelayReqVO bean);
} }
...@@ -6,6 +6,7 @@ import cn.iocoder.yudao.framework.common.exception.ErrorCode; ...@@ -6,6 +6,7 @@ import cn.iocoder.yudao.framework.common.exception.ErrorCode;
// TODO 待办:请将下面的错误码复制到 yudao-module-reward-api 模块的 ErrorCodeConstants 类中。注意,请给“TODO 补充编号”设置一个错误码编号!!! // TODO 待办:请将下面的错误码复制到 yudao-module-reward-api 模块的 ErrorCodeConstants 类中。注意,请给“TODO 补充编号”设置一个错误码编号!!!
// ========== 礼品 TODO 补充编号 ========== // ========== 礼品 TODO 补充编号 ==========
public interface ErrorCodeConstants { 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> { ...@@ -62,4 +62,15 @@ public interface RewardService extends IService<RewardDO> {
* @return 礼品列表 * @return 礼品列表
*/ */
List<RewardDO> getList(RewardQueryVO query); 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; package cn.iocoder.yudao.module.reward.service.reward;
import java.time.Instant;
import java.util.*; import java.util.*;
import javax.annotation.Resource; 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.framework.mybatis.core.query.LambdaQuery;
import cn.iocoder.yudao.module.reward.enums.ErrorCodeConstants;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import cn.iocoder.yudao.framework.mybatis.core.vo.PageVO; import cn.iocoder.yudao.framework.mybatis.core.vo.PageVO;
...@@ -59,7 +62,7 @@ public class RewardServiceImpl extends AbstractService<RewardMapper, RewardDO> i ...@@ -59,7 +62,7 @@ public class RewardServiceImpl extends AbstractService<RewardMapper, RewardDO> i
private void validateExists(Long id) { private void validateExists(Long id) {
if (rewardMapper.selectById(id) == null) { 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 ...@@ -126,6 +129,42 @@ public class RewardServiceImpl extends AbstractService<RewardMapper, RewardDO> i
return rewardMapper.selectList(query); 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 //生成礼品ID
private String generateRewardCode() { private String generateRewardCode() {
String uuid = UUID.randomUUID().toString().replaceAll("-", ""); 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.*; ...@@ -18,6 +18,7 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid; import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.io.IOException; import java.io.IOException;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
...@@ -63,7 +64,7 @@ public class RewardController { ...@@ -63,7 +64,7 @@ public class RewardController {
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
//@PreAuthorize("@ss.hasPermission('reward::query')") //@PreAuthorize("@ss.hasPermission('reward::query')")
public CommonResult<RewardBackVO> get(@RequestParam("id") Long id) { public CommonResult<RewardBackVO> get(@RequestParam("id") Long id) {
RewardDO rewardDO = rewardService.get(id); RewardDO rewardDO = rewardService.get(id);
return success(RewardConvert.INSTANCE.convert(rewardDO)); return success(RewardConvert.INSTANCE.convert(rewardDO));
} }
...@@ -88,7 +89,20 @@ public class RewardController { ...@@ -88,7 +89,20 @@ public class RewardController {
@ApiOperation("礼品状态变更") @ApiOperation("礼品状态变更")
//@PreAuthorize("@ss.hasPermission('reward::query')") //@PreAuthorize("@ss.hasPermission('reward::query')")
public CommonResult<Boolean> updateStatus(@Valid @RequestBody RewardStatusReqVO statusVO) { 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); return success(true);
} }
...@@ -97,7 +111,7 @@ public class RewardController { ...@@ -97,7 +111,7 @@ public class RewardController {
//@PreAuthorize("@ss.hasPermission('reward::export')") //@PreAuthorize("@ss.hasPermission('reward::export')")
@OperateLog(type = EXPORT) @OperateLog(type = EXPORT)
public void exportExcel(@Valid RewardQueryVO query, public void exportExcel(@Valid RewardQueryVO query,
HttpServletResponse response) throws IOException { HttpServletResponse response) throws IOException {
List<RewardDO> list = rewardService.getList(query); List<RewardDO> list = rewardService.getList(query);
// 导出 Excel // 导出 Excel
List<RewardBackVO> datas = RewardConvert.INSTANCE.convertList(list); List<RewardBackVO> datas = RewardConvert.INSTANCE.convertList(list);
......
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