Commit 99e50784 authored by zhangfeng's avatar zhangfeng

礼品创建修改

parent bde97df0
...@@ -28,5 +28,6 @@ public interface ErrorCodeConstants { ...@@ -28,5 +28,6 @@ public interface ErrorCodeConstants {
ErrorCode REWARD_REDEEM_VERIFY_BACK_STATUS = new ErrorCode(1001011022, "reward.redeem.verify.back.status"); ErrorCode REWARD_REDEEM_VERIFY_BACK_STATUS = new ErrorCode(1001011022, "reward.redeem.verify.back.status");
ErrorCode REDEEM_IMPORT_MAX_COUNT = new ErrorCode(1001011023, "redeem.import.max.count"); ErrorCode REDEEM_IMPORT_MAX_COUNT = new ErrorCode(1001011023, "redeem.import.max.count");
ErrorCode REDEEM_CANCEL_STATUS_ERROR = new ErrorCode(1001011024, "redeem.cancel.status.error"); ErrorCode REDEEM_CANCEL_STATUS_ERROR = new ErrorCode(1001011024, "redeem.cancel.status.error");
ErrorCode REWARD_NODE_AND_POINTS_LIST_ERROR = new ErrorCode(1001011025, "reward.node.and.points.list.error");
} }
...@@ -41,7 +41,7 @@ public class RewardController { ...@@ -41,7 +41,7 @@ public class RewardController {
@ApiOperation("创建礼品") @ApiOperation("创建礼品")
@Idempotent(timeout = 3) @Idempotent(timeout = 3)
@PreAuthorize("@ss.hasPermission('ecw:giftManagement:add')") @PreAuthorize("@ss.hasPermission('ecw:giftManagement:add')")
public CommonResult<Long> create(@Valid @RequestBody RewardCreateReqVO createReqVO) { public CommonResult<List<Long>> create(@Valid @RequestBody RewardCreateReqVO createReqVO) {
return success(rewardService.create(createReqVO)); return success(rewardService.create(createReqVO));
} }
......
...@@ -24,7 +24,7 @@ public interface RewardService extends IService<RewardDO> { ...@@ -24,7 +24,7 @@ public interface RewardService extends IService<RewardDO> {
* @param createReqVO 创建信息 * @param createReqVO 创建信息
* @return 编号 * @return 编号
*/ */
Long create(@Valid RewardCreateReqVO createReqVO); List<Long> create(@Valid RewardCreateReqVO createReqVO);
/** /**
* 更新礼品 * 更新礼品
......
...@@ -24,10 +24,7 @@ import org.springframework.validation.annotation.Validated; ...@@ -24,10 +24,7 @@ import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.time.Instant; import java.time.Instant;
import java.util.Collection; import java.util.*;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors; 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;
...@@ -50,7 +47,34 @@ public class RewardServiceImpl extends AbstractService<RewardMapper, RewardDO> i ...@@ -50,7 +47,34 @@ public class RewardServiceImpl extends AbstractService<RewardMapper, RewardDO> i
private MemberUserApi memberUserApi; private MemberUserApi memberUserApi;
@Override @Override
public Long create(RewardCreateReqVO createReqVO) { public List<Long> create(RewardCreateReqVO createReqVO) {
verifyCreateVO(createReqVO);
// 插入
RewardDO rewardDO = RewardConvert.INSTANCE.convert(createReqVO);
// 剩余数量若没传给默认值0
if (rewardDO.getQuantityRemain() == null) {
rewardDO.setQuantityRemain(0);
}
ArrayList<Long> ids = new ArrayList<>();
for (RewardCreateReqVO.NodeAndPoints nodeId : createReqVO.getNodeIds()) {
rewardDO.setNodeId(nodeId.getNodeId());
rewardDO.setPointsRequire(nodeId.getPoints());
rewardDO.setCode(generateRewardCode());
//如果插入失败,重新生成code再次插入
try {
rewardMapper.insert(rewardDO);
} catch (Exception e) {
rewardDO.setCode(generateRewardCode());
rewardMapper.insert(rewardDO);
}
ids.add(rewardDO.getId());
rewardDO.setId(null);
}
// 返回
return ids;
}
private void verifyCreateVO(RewardCreateReqVO createReqVO) {
//活动开始时间不能比活动结束时间晚,活动结束时间不能比当前时间早 //活动开始时间不能比活动结束时间晚,活动结束时间不能比当前时间早
if (ObjectUtils.allNotNull(createReqVO.getStartTime(), createReqVO.getEndTime())) { if (ObjectUtils.allNotNull(createReqVO.getStartTime(), createReqVO.getEndTime())) {
if (createReqVO.getStartTime().after((createReqVO.getEndTime())) || createReqVO.getEndTime().before(Date.from(Instant.now()))) { if (createReqVO.getStartTime().after((createReqVO.getEndTime())) || createReqVO.getEndTime().before(Date.from(Instant.now()))) {
...@@ -64,22 +88,20 @@ public class RewardServiceImpl extends AbstractService<RewardMapper, RewardDO> i ...@@ -64,22 +88,20 @@ public class RewardServiceImpl extends AbstractService<RewardMapper, RewardDO> i
if (createReqVO.getStatus() != RewardStatusEnum.ENABLED.getValue() && createReqVO.getStatus() != RewardStatusEnum.DISABLED.getValue()) { if (createReqVO.getStatus() != RewardStatusEnum.ENABLED.getValue() && createReqVO.getStatus() != RewardStatusEnum.DISABLED.getValue()) {
throw exception(REWARD_STATUS_NOT_ALLOW_CREATE); throw exception(REWARD_STATUS_NOT_ALLOW_CREATE);
} }
// 插入 // 校验节点和所需积分
RewardDO rewardDO = RewardConvert.INSTANCE.convert(createReqVO); List<RewardCreateReqVO.NodeAndPoints> nodeIds = createReqVO.getNodeIds();
rewardDO.setCode(generateRewardCode()); if (CollectionUtil.isEmpty(nodeIds)) {
// 剩余数量若没传给默认值0 throw exception(REWARD_NODE_AND_POINTS_LIST_ERROR);
if (rewardDO.getQuantityRemain() == null) { } else {
rewardDO.setQuantityRemain(0); for (RewardCreateReqVO.NodeAndPoints nodeId : nodeIds) {
} if (nodeId.getPoints() == null || nodeId.getNodeId() == null) {
//如果插入失败,重新生成code再次插入 throw exception(REWARD_NODE_AND_POINTS_LIST_ERROR);
try { }
rewardMapper.insert(rewardDO); if (nodeId.getPoints() <= 0 || nodeId.getNodeId() <= 0) {
} catch (Exception e) { throw exception(REWARD_NODE_AND_POINTS_LIST_ERROR);
rewardDO.setCode(generateRewardCode()); }
rewardMapper.insert(rewardDO); }
} }
// 返回
return rewardDO.getId();
} }
@Override @Override
......
...@@ -40,14 +40,18 @@ public class RewardCreateReqVO { ...@@ -40,14 +40,18 @@ public class RewardCreateReqVO {
@ApiModelProperty(value = "法文礼品图片") @ApiModelProperty(value = "法文礼品图片")
private String imgFr; private String imgFr;
@ApiModelProperty(value = "兑换所需积分", required = true) //@ApiModelProperty(value = "兑换所需积分", required = true)
@NotNull(message = "兑换所需积分不能为空") //@NotNull(message = "兑换所需积分不能为空")
@Min(value = 0) //@Min(value = 0)
private Integer pointsRequire; //private Integer pointsRequire;
//@ApiModelProperty(value = "兑换网点", required = true)
//@NotNull(message = "兑换网点不能为空")
//private Integer nodeId;
@ApiModelProperty(value = "兑换网点", required = true) @ApiModelProperty(value = "兑换网点和积分列表", required = true)
@NotNull(message = "兑换网点不能为空") @NotNull(message = "兑换网点列表不能为空")
private Integer nodeId; private List<NodeAndPoints> nodeIds;
@ApiModelProperty(value = "剩余数量", required = true) @ApiModelProperty(value = "剩余数量", required = true)
@NotNull(message = "剩余数量不能为空") @NotNull(message = "剩余数量不能为空")
...@@ -86,4 +90,12 @@ public class RewardCreateReqVO { ...@@ -86,4 +90,12 @@ public class RewardCreateReqVO {
@ApiModelProperty(value = "礼品状态(1已启用,2未启用,3已关闭,4已过期)", required = true) @ApiModelProperty(value = "礼品状态(1已启用,2未启用,3已关闭,4已过期)", required = true)
@NotNull(message = "礼品状态不能为空") @NotNull(message = "礼品状态不能为空")
private Integer status; private Integer status;
@Data
public static class NodeAndPoints {
@ApiModelProperty(value = "兑换网点")
private Integer nodeId;
@ApiModelProperty(value = "兑换网点对应积分")
private Integer points;
}
} }
...@@ -1024,6 +1024,7 @@ reward.score.not.enough = user score not enough:{} ...@@ -1024,6 +1024,7 @@ reward.score.not.enough = user score not enough:{}
reward.count.not.enough = reward count not enough reward.count.not.enough = reward count not enough
reward.redeem.count.not.allow = bulk redemption is limited to a maximum of 10 pieces at a time reward.redeem.count.not.allow = bulk redemption is limited to a maximum of 10 pieces at a time
reward.redeem.allow.count.error = the number of redemptions allowed by the individual has been exceeded:{} reward.redeem.allow.count.error = the number of redemptions allowed by the individual has been exceeded:{}
reward.node.and.points.list.error = reward node and points create error
redeem.import.max.count = allow maximum number of imports is {} redeem.import.max.count = allow maximum number of imports is {}
dict.unknown.error = Not in dict {0}: {1} dict.unknown.error = Not in dict {0}: {1}
......
...@@ -1022,6 +1022,7 @@ reward.score.not.enough = \u79EF\u5206\u4E0D\u8DB3\uFF1A{} ...@@ -1022,6 +1022,7 @@ reward.score.not.enough = \u79EF\u5206\u4E0D\u8DB3\uFF1A{}
reward.count.not.enough = \u793C\u54C1\u6570\u91CF\u4E0D\u8DB3 reward.count.not.enough = \u793C\u54C1\u6570\u91CF\u4E0D\u8DB3
reward.redeem.count.not.allow = \u6279\u91CF\u5151\u6362\u6BCF\u6B21\u6700\u591A\u5341\u6761 reward.redeem.count.not.allow = \u6279\u91CF\u5151\u6362\u6BCF\u6B21\u6700\u591A\u5341\u6761
reward.redeem.allow.count.error = \u5DF2\u8D85\u51FA\u4E2A\u4EBA\u5141\u8BB8\u5151\u6362\u6B21\u6570\uFF1A{} reward.redeem.allow.count.error = \u5DF2\u8D85\u51FA\u4E2A\u4EBA\u5141\u8BB8\u5151\u6362\u6B21\u6570\uFF1A{}
reward.node.and.points.list.error = \u521B\u5EFA\u793C\u54C1\u7F51\u70B9\u6216\u6240\u9700\u79EF\u5206\u9519\u8BEF
get.lock.failed = \u670D\u52A1\u7E41\u5FD9\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5 get.lock.failed = \u670D\u52A1\u7E41\u5FD9\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5
reward.redeem.not.exist = \u793C\u54C1\u5151\u6362\u8BB0\u5F55\u4E0D\u5B58\u5728 reward.redeem.not.exist = \u793C\u54C1\u5151\u6362\u8BB0\u5F55\u4E0D\u5B58\u5728
......
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