Commit b7ea7a20 authored by zhangfeng's avatar zhangfeng

积分规则接口校验

parent ed0ae6b3
package cn.iocoder.yudao.module.member.enums;
public enum TransportType {
OCEAN_LCL(1, "海运拼柜"),
SPECIAL_LINE_AIR_FREIGHT(3, "专线空运");
private final int value;
private final String name;
TransportType(int value, String name) {
this.value = value;
this.name = name;
}
public int getValue() {
return value;
}
public String getName() {
return name;
}
}
...@@ -54,19 +54,17 @@ public class ScoreRuleController { ...@@ -54,19 +54,17 @@ public class ScoreRuleController {
@PostMapping("/delete") @PostMapping("/delete")
@ApiOperation("删除积分规则") @ApiOperation("删除积分规则")
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
@PreAuthorize("@ss.hasPermission('member:score-rule:delete')") @PreAuthorize("@ss.hasPermission('member:score-rule:delete')")
public CommonResult<Boolean> deleteScoreRule(@NotNull @RequestBody Long id) { public CommonResult<Boolean> deleteScoreRule(@Valid @RequestBody IdReqVo idReqVo) {
scoreRuleService.deleteScoreRule(id); scoreRuleService.deleteScoreRule(idReqVo.getId());
return success(true); return success(true);
} }
@PostMapping("/get") @PostMapping("/get")
@ApiOperation("获得积分规则详情") @ApiOperation("获得积分规则详情")
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
@PreAuthorize("@ss.hasPermission('member:score-rule:query')") @PreAuthorize("@ss.hasPermission('member:score-rule:query')")
public CommonResult<ScoreRuleBackDetailVO> getScoreRule(@NotNull @RequestBody Long id) { public CommonResult<ScoreRuleBackDetailVO> getScoreRule(@Valid @RequestBody IdReqVo idReqVo) {
ScoreRuleBackDetailVO scoreRuleBackDetailVO = scoreRuleService.getScoreRule(id); ScoreRuleBackDetailVO scoreRuleBackDetailVO = scoreRuleService.getScoreRule(idReqVo.getId());
return success(scoreRuleBackDetailVO); return success(scoreRuleBackDetailVO);
} }
...@@ -74,7 +72,7 @@ public class ScoreRuleController { ...@@ -74,7 +72,7 @@ public class ScoreRuleController {
@ApiOperation("获得积分规则列表") @ApiOperation("获得积分规则列表")
@ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class) @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
@PreAuthorize("@ss.hasPermission('member:score-rule:query')") @PreAuthorize("@ss.hasPermission('member:score-rule:query')")
public CommonResult<List<ScoreRuleBackVO>> getScoreRuleList(@NotNull @RequestBody Collection<Long> ids) { public CommonResult<List<ScoreRuleBackVO>> getScoreRuleList(@NotNull @RequestParam Collection<Long> ids) {
List<ScoreRuleBackVO> list = scoreRuleService.getScoreRuleList(ids); List<ScoreRuleBackVO> list = scoreRuleService.getScoreRuleList(ids);
return success(list); return success(list);
} }
...@@ -96,8 +94,8 @@ public class ScoreRuleController { ...@@ -96,8 +94,8 @@ public class ScoreRuleController {
@PostMapping("/copy") @PostMapping("/copy")
@ApiOperation("复制规则") @ApiOperation("复制规则")
@PreAuthorize("@ss.hasPermission('member:score-rule:create')") @PreAuthorize("@ss.hasPermission('member:score-rule:create')")
public CommonResult<Long> copyScoreRule(@NotNull @RequestBody Long id) { public CommonResult<Long> copyScoreRule(@Valid @RequestBody IdReqVo idReqVo) {
return success(scoreRuleService.copyScoreRule(id)); return success(scoreRuleService.copyScoreRule(idReqVo.getId()));
} }
@PostMapping("/delay") @PostMapping("/delay")
@ApiOperation("延期规则") @ApiOperation("延期规则")
......
...@@ -71,7 +71,7 @@ public class ScoreRuleDO extends BaseDO { ...@@ -71,7 +71,7 @@ public class ScoreRuleDO extends BaseDO {
/** /**
* 积分有效期 * 积分有效期
*/ */
private Integer socrePeriod; private Integer scorePeriod;
/** /**
* 排序值 * 排序值
*/ */
......
...@@ -31,7 +31,7 @@ public interface ScoreRuleMapper extends AbstractMapper<ScoreRuleDO> { ...@@ -31,7 +31,7 @@ public interface ScoreRuleMapper extends AbstractMapper<ScoreRuleDO> {
.eqIfPresent(ScoreRuleDO::getMaxScoreTotal, vo.getMaxScoreTotal()) .eqIfPresent(ScoreRuleDO::getMaxScoreTotal, vo.getMaxScoreTotal())
.betweenIfPresent(ScoreRuleDO::getStartTime, vo.getBeginStartTime(), vo.getEndStartTime()) .betweenIfPresent(ScoreRuleDO::getStartTime, vo.getBeginStartTime(), vo.getEndStartTime())
.betweenIfPresent(ScoreRuleDO::getEndTime, vo.getBeginEndTime(), vo.getEndEndTime()) .betweenIfPresent(ScoreRuleDO::getEndTime, vo.getBeginEndTime(), vo.getEndEndTime())
.eqIfPresent(ScoreRuleDO::getSocrePeriod, vo.getSocrePeriod()) .eqIfPresent(ScoreRuleDO::getScorePeriod, vo.getSocrePeriod())
.eqIfPresent(ScoreRuleDO::getOrderNum, vo.getOrderNum()) .eqIfPresent(ScoreRuleDO::getOrderNum, vo.getOrderNum())
.eqIfPresent(ScoreRuleDO::getPushActivity, vo.getPushActivity()) .eqIfPresent(ScoreRuleDO::getPushActivity, vo.getPushActivity())
.eqIfPresent(ScoreRuleDO::getShowPlatform, vo.getShowPlatform()) .eqIfPresent(ScoreRuleDO::getShowPlatform, vo.getShowPlatform())
...@@ -60,7 +60,7 @@ public interface ScoreRuleMapper extends AbstractMapper<ScoreRuleDO> { ...@@ -60,7 +60,7 @@ public interface ScoreRuleMapper extends AbstractMapper<ScoreRuleDO> {
.eqIfPresent(ScoreRuleDO::getMaxScoreTotal, vo.getMaxScoreTotal()) .eqIfPresent(ScoreRuleDO::getMaxScoreTotal, vo.getMaxScoreTotal())
.betweenIfPresent(ScoreRuleDO::getStartTime, vo.getBeginStartTime(), vo.getEndStartTime()) .betweenIfPresent(ScoreRuleDO::getStartTime, vo.getBeginStartTime(), vo.getEndStartTime())
.betweenIfPresent(ScoreRuleDO::getEndTime, vo.getBeginEndTime(), vo.getEndEndTime()) .betweenIfPresent(ScoreRuleDO::getEndTime, vo.getBeginEndTime(), vo.getEndEndTime())
.eqIfPresent(ScoreRuleDO::getSocrePeriod, vo.getSocrePeriod()) .eqIfPresent(ScoreRuleDO::getScorePeriod, vo.getSocrePeriod())
.eqIfPresent(ScoreRuleDO::getOrderNum, vo.getOrderNum()) .eqIfPresent(ScoreRuleDO::getOrderNum, vo.getOrderNum())
.eqIfPresent(ScoreRuleDO::getPushActivity, vo.getPushActivity()) .eqIfPresent(ScoreRuleDO::getPushActivity, vo.getPushActivity())
.eqIfPresent(ScoreRuleDO::getShowPlatform, vo.getShowPlatform()) .eqIfPresent(ScoreRuleDO::getShowPlatform, vo.getShowPlatform())
......
...@@ -13,6 +13,7 @@ import cn.iocoder.yudao.module.member.dal.dataobject.scoreRule.ScoreRuleDO; ...@@ -13,6 +13,7 @@ import cn.iocoder.yudao.module.member.dal.dataobject.scoreRule.ScoreRuleDO;
import cn.iocoder.yudao.module.member.dal.mysql.scoreRule.ScoreRuleMapper; import cn.iocoder.yudao.module.member.dal.mysql.scoreRule.ScoreRuleMapper;
import cn.iocoder.yudao.module.member.enums.ScoreRuleStatusEnum; import cn.iocoder.yudao.module.member.enums.ScoreRuleStatusEnum;
import cn.iocoder.yudao.module.member.enums.ScoreRuleTypeEnum; import cn.iocoder.yudao.module.member.enums.ScoreRuleTypeEnum;
import cn.iocoder.yudao.module.member.enums.TransportType;
import cn.iocoder.yudao.module.member.enums.YesOrNoTypeEnum; import cn.iocoder.yudao.module.member.enums.YesOrNoTypeEnum;
import cn.iocoder.yudao.module.member.vo.scoreRule.*; import cn.iocoder.yudao.module.member.vo.scoreRule.*;
import cn.iocoder.yudao.module.member.vo.scoreRule.extra.ScoreRuleOrderVExtraVO; import cn.iocoder.yudao.module.member.vo.scoreRule.extra.ScoreRuleOrderVExtraVO;
...@@ -43,6 +44,9 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score ...@@ -43,6 +44,9 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
@Override @Override
public Long createScoreRule(ScoreRuleCreateReqVO createReqVO) { public Long createScoreRule(ScoreRuleCreateReqVO createReqVO) {
ScoreRuleDO scoreRule = ScoreRuleConvert.INSTANCE.convert(createReqVO); ScoreRuleDO scoreRule = ScoreRuleConvert.INSTANCE.convert(createReqVO);
if (scoreRule.getStatus() != ScoreRuleStatusEnum.DISABLED.getValue() && scoreRule.getStatus() != ScoreRuleStatusEnum.ENABLED.getValue()){
throw exception(SCORE_RULE_FIELD_ERROR);
}
verifyCommon(scoreRule); verifyCommon(scoreRule);
Integer scoreRuleType = scoreRule.getType(); Integer scoreRuleType = scoreRule.getType();
verifyAndSetExtraDO(createReqVO, scoreRuleType, scoreRule); verifyAndSetExtraDO(createReqVO, scoreRuleType, scoreRule);
...@@ -62,7 +66,7 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score ...@@ -62,7 +66,7 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
if (scoreRule.getStartTime().after((scoreRule.getEndTime())) || scoreRule.getEndTime().before(Date.from(Instant.now()))) { if (scoreRule.getStartTime().after((scoreRule.getEndTime())) || scoreRule.getEndTime().before(Date.from(Instant.now()))) {
throw exception(SCORE_RULE_FIELD_ERROR); throw exception(SCORE_RULE_FIELD_ERROR);
} }
if (scoreRule.getSocrePeriod() <= 0) { if (scoreRule.getScorePeriod() <= 0) {
throw exception(SCORE_RULE_FIELD_ERROR); throw exception(SCORE_RULE_FIELD_ERROR);
} }
//如果是启用,校验同一个规则下,有效期内有没有重复的规则设置,分享不校验 //如果是启用,校验同一个规则下,有效期内有没有重复的规则设置,分享不校验
...@@ -72,7 +76,7 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score ...@@ -72,7 +76,7 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
.eq(ScoreRuleDO::getType, scoreRule.getType()) .eq(ScoreRuleDO::getType, scoreRule.getType())
.eq(ScoreRuleDO::getStatus, ScoreRuleStatusEnum.ENABLED.getValue()); .eq(ScoreRuleDO::getStatus, ScoreRuleStatusEnum.ENABLED.getValue());
Long count = scoreRuleMapper.selectCount(scoreRuleDOLambdaQuery); Long count = scoreRuleMapper.selectCount(scoreRuleDOLambdaQuery);
if (count > 1) { if (count > 0) {
throw exception(SCORE_RULE_FIELD_ERROR); throw exception(SCORE_RULE_FIELD_ERROR);
} }
} }
...@@ -85,7 +89,7 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score ...@@ -85,7 +89,7 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
if (scoreRuleDO == null) { if (scoreRuleDO == null) {
throw exception(SCORE_RULE_NOT_EXISTS); throw exception(SCORE_RULE_NOT_EXISTS);
} }
if (scoreRuleDO.getStatus() == ScoreRuleStatusEnum.ENABLED.getValue()) { if (scoreRuleDO.getStatus() != ScoreRuleStatusEnum.DISABLED.getValue()) {
throw exception(SCORE_RULE_UPDATE_ERROR); throw exception(SCORE_RULE_UPDATE_ERROR);
} }
ScoreRuleDO scoreRule = ScoreRuleConvert.INSTANCE.convert(updateReqVO); ScoreRuleDO scoreRule = ScoreRuleConvert.INSTANCE.convert(updateReqVO);
...@@ -111,6 +115,9 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score ...@@ -111,6 +115,9 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
if (extraOrderV.getFirstOrder() != YesOrNoTypeEnum.YES.ordinal() && extraOrderV.getFirstOrder() != YesOrNoTypeEnum.NO.ordinal()) { if (extraOrderV.getFirstOrder() != YesOrNoTypeEnum.YES.ordinal() && extraOrderV.getFirstOrder() != YesOrNoTypeEnum.NO.ordinal()) {
throw exception(SCORE_RULE_FIELD_ERROR); throw exception(SCORE_RULE_FIELD_ERROR);
} }
if (extraOrderV.getTransportType() != TransportType.OCEAN_LCL.getValue() && extraOrderV.getFirstOrder() != TransportType.SPECIAL_LINE_AIR_FREIGHT.getValue()) {
throw exception(SCORE_RULE_FIELD_ERROR);
}
if (StringUtils.isAnyBlank(extraOrderV.getTargetCountry(), extraOrderV.getTargetCity(), extraOrderV.getReceiveAddr(), extraOrderV.getOrderEntry())) { if (StringUtils.isAnyBlank(extraOrderV.getTargetCountry(), extraOrderV.getTargetCity(), extraOrderV.getReceiveAddr(), extraOrderV.getOrderEntry())) {
throw exception(SCORE_RULE_FIELD_ERROR); throw exception(SCORE_RULE_FIELD_ERROR);
} }
...@@ -172,7 +179,7 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score ...@@ -172,7 +179,7 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
if (scoreRuleDO == null) { if (scoreRuleDO == null) {
throw exception(SCORE_RULE_NOT_EXISTS); throw exception(SCORE_RULE_NOT_EXISTS);
} }
if (scoreRuleDO.getStatus() == ScoreRuleStatusEnum.ENABLED.getValue()) { if (scoreRuleDO.getStatus() != ScoreRuleStatusEnum.DISABLED.getValue()) {
throw exception(SCORE_RULE_DELETE_ERROR); throw exception(SCORE_RULE_DELETE_ERROR);
} }
// 删除 // 删除
...@@ -255,11 +262,13 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score ...@@ -255,11 +262,13 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
.eq(ScoreRuleDO::getType, scoreRuleDO.getType()) .eq(ScoreRuleDO::getType, scoreRuleDO.getType())
.eq(ScoreRuleDO::getStatus, ScoreRuleStatusEnum.ENABLED.getValue()); .eq(ScoreRuleDO::getStatus, ScoreRuleStatusEnum.ENABLED.getValue());
Long count = scoreRuleMapper.selectCount(scoreRuleDOLambdaQuery); Long count = scoreRuleMapper.selectCount(scoreRuleDOLambdaQuery);
if (count > 1) { if (count > 0) {
throw exception(SCORE_RULE_FIELD_ERROR); throw exception(SCORE_RULE_FIELD_ERROR);
} }
} }
upScoreRuleDO.setStatus(scoreRuleStatusReqVO.getStatus()); upScoreRuleDO.setStatus(scoreRuleStatusReqVO.getStatus());
} else {
throw exception(SCORE_RULE_UPDATE_ERROR);
} }
scoreRuleMapper.updateById(upScoreRuleDO); scoreRuleMapper.updateById(upScoreRuleDO);
} }
...@@ -290,7 +299,7 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score ...@@ -290,7 +299,7 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
} }
Instant now = Instant.now(); Instant now = Instant.now();
//结束时间不能小于当前时间 //结束时间不能小于当前时间
if (!delayReqVO.getEndTime().toInstant().isAfter(now)) { if (!delayReqVO.getEndTime().toInstant().isAfter(now) || !delayReqVO.getEndTime().toInstant().isAfter(scoreRuleDO.getStartTime().toInstant())) {
throw exception(SCORE_RULE_UPDATE_ERROR); throw exception(SCORE_RULE_UPDATE_ERROR);
} }
ScoreRuleDO upScoreRuleDO = new ScoreRuleDO(); ScoreRuleDO upScoreRuleDO = new ScoreRuleDO();
......
package cn.iocoder.yudao.module.member.vo.scoreRule;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotNull;
@Data
@ApiModel("管理后台 - 积分规则id请求 VO")
public class IdReqVo {
@ApiModelProperty(value = "主键", required = true)
@NotNull(message = "主键不能为空")
private Long id;
}
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