Commit 77525aef authored by zhangfeng's avatar zhangfeng

礼品领取方式校验

parent 26afa7ad
......@@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.reward.service.reward;
import cn.hutool.core.collection.CollectionUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.dict.core.dto.DictDataRespDTO;
import cn.iocoder.yudao.framework.dict.core.util.DictFrameworkUtils;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQuery;
import cn.iocoder.yudao.framework.mybatis.core.service.AbstractService;
......@@ -16,6 +17,7 @@ import cn.iocoder.yudao.module.reward.convert.reward.RewardConvert;
import cn.iocoder.yudao.module.reward.dal.dataobject.reward.RewardDO;
import cn.iocoder.yudao.module.reward.dal.mysql.reward.RewardMapper;
import cn.iocoder.yudao.module.reward.enums.QuantitativeRelationSymbolEnum;
import cn.iocoder.yudao.module.reward.enums.RewardPickMethedEnum;
import cn.iocoder.yudao.module.reward.enums.RewardStatusEnum;
import cn.iocoder.yudao.module.reward.vo.reward.*;
import org.apache.commons.lang3.ObjectUtils;
......@@ -78,7 +80,12 @@ public class RewardServiceImpl extends AbstractService<RewardMapper, RewardDO> i
}
private void verifyCreateVO(RewardCreateReqVO createReqVO) {
//活动开始时间不能比活动结束时间晚,活动结束时间不能比当前时间早
// 校验领取方式
List<String> pickMethodList = Arrays.asList(createReqVO.getPickMethod().split(","));
if (!pickMethodList.contains(String.valueOf(RewardPickMethedEnum.SELF_PICKUP.getValue())) && !pickMethodList.contains(String.valueOf(RewardPickMethedEnum.SEND_HOME_FREE.getValue())) && !pickMethodList.contains(String.valueOf(RewardPickMethedEnum.SEND_HOME_PAY.getValue()))) {
throw exception(REWARD_PICK_METHOD_NOT_ALLOW);
}
// 活动开始时间不能比活动结束时间晚,活动结束时间不能比当前时间早
if (ObjectUtils.allNotNull(createReqVO.getStartTime(), createReqVO.getEndTime())) {
if (createReqVO.getStartTime().after((createReqVO.getEndTime())) || createReqVO.getEndTime().before(Date.from(Instant.now()))) {
throw exception(REWARD_START_OR_END_TIME_NOT_ALLOW);
......@@ -117,6 +124,11 @@ public class RewardServiceImpl extends AbstractService<RewardMapper, RewardDO> i
RewardDO updateObj = new RewardDO();
//未启用可编辑所有内容
if (rewardDO.getStatus() == RewardStatusEnum.DISABLED.getValue()) {
// 校验领取方式
List<String> pickMethodList = Arrays.asList(updateReqVO.getPickMethod().split(","));
if (StringUtils.isNotBlank(updateReqVO.getPickMethod()) && !pickMethodList.contains(String.valueOf(RewardPickMethedEnum.SELF_PICKUP.getValue())) && !pickMethodList.contains(String.valueOf(RewardPickMethedEnum.SEND_HOME_FREE.getValue())) && !pickMethodList.contains(String.valueOf(RewardPickMethedEnum.SEND_HOME_PAY.getValue()))) {
throw exception(REWARD_PICK_METHOD_NOT_ALLOW);
}
if (ObjectUtils.allNotNull(updateReqVO.getStartTime(), updateReqVO.getEndTime())) {
if (updateReqVO.getStartTime().after((updateReqVO.getEndTime())) || updateReqVO.getEndTime().before(Date.from(Instant.now()))) {
throw exception(REWARD_START_OR_END_TIME_NOT_ALLOW);
......@@ -125,11 +137,11 @@ public class RewardServiceImpl extends AbstractService<RewardMapper, RewardDO> i
} else {
throw exception(REWARD_START_OR_END_TIME_NOT_ALLOW);
}
List<RewardCreateReqVO.NodeAndPoints> nodeIds = updateReqVO.getNodeIds();
List<RewardUpdateReqVO.NodeAndPoints> nodeIds = updateReqVO.getNodeIds();
if (CollectionUtil.isEmpty(nodeIds)) {
throw exception(REWARD_NODE_AND_POINTS_LIST_ERROR);
}
RewardCreateReqVO.NodeAndPoints nodeAndPoints = nodeIds.get(0);
RewardUpdateReqVO.NodeAndPoints nodeAndPoints = nodeIds.get(0);
updateObj = RewardConvert.INSTANCE.convert(updateReqVO);
updateObj.setPointsRequire(nodeAndPoints.getPoints());
updateObj.setNodeId(nodeAndPoints.getNodeId());
......@@ -360,11 +372,15 @@ public class RewardServiceImpl extends AbstractService<RewardMapper, RewardDO> i
}
private void setPickMethod(AppRewardBackVO appRewardBackVO) {
for (String pickMethod : appRewardBackVO.getPickMethod().split(",")) {
String[] splitPickMethod = appRewardBackVO.getPickMethod().split(",");
for (String pickMethod : splitPickMethod) {
AppRewardBackVO.PickMethod pickMethodDict = new AppRewardBackVO.PickMethod();
pickMethodDict.setValue(pickMethod);
pickMethodDict.setLabelZh(DictFrameworkUtils.getDictDataFromCache("way_of_receiving", pickMethod).getLabel());
pickMethodDict.setLabelEn(DictFrameworkUtils.getDictDataFromCache("way_of_receiving", pickMethod).getLabelEn());
DictDataRespDTO wayOfReceiving = DictFrameworkUtils.getDictDataFromCache("way_of_receiving", pickMethod);
if (wayOfReceiving != null) {
pickMethodDict.setLabelZh(wayOfReceiving.getLabel());
pickMethodDict.setLabelEn(wayOfReceiving.getLabelEn());
}
appRewardBackVO.getPickMethodList().add(pickMethodDict);
}
}
......
......@@ -52,7 +52,7 @@ public class RewardUpdateReqVO {
@ApiModelProperty(value = "兑换网点和积分列表", required = true)
@NotNull(message = "兑换网点列表不能为空")
private List<RewardCreateReqVO.NodeAndPoints> nodeIds;
private List<RewardUpdateReqVO.NodeAndPoints> nodeIds;
@ApiModelProperty(value = "剩余数量")
@Min(value = 0)
......
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