Commit 9bb083b3 authored by zhangfeng's avatar zhangfeng

积分规则接口校验

parent 45bceac6
......@@ -110,9 +110,9 @@ public class ScoreRuleController {
return success(true);
}
@GetMapping("/getWarehouseTreeRegionList")
@GetMapping("/warehouse-tree-region-list")
@ApiOperation("获得目的国、目的城市、目的仓列表")
public CommonResult<List<WarehouseTreeRegionVO>> WarehouseTreeRegionList() {
public CommonResult<List<WarehouseTreeRegionVO>> warehouseTreeRegionList() {
List<WarehouseTreeRegionVO> listIn = warehouseService.getWarehouseTreeRegionList(1);
List<WarehouseTreeRegionVO> listOut = warehouseService.getWarehouseTreeRegionList(2);
List<WarehouseTreeRegionVO> list = ListUtils.sum(listIn, listOut);
......
......@@ -47,7 +47,7 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
if (scoreRule.getStatus() != ScoreRuleStatusEnum.DISABLED.getValue() && scoreRule.getStatus() != ScoreRuleStatusEnum.ENABLED.getValue()){
throw exception(SCORE_RULE_FIELD_ERROR);
}
verifyCommon(scoreRule);
verifyCommon(createReqVO);
Integer scoreRuleType = scoreRule.getType();
verifyAndSetExtraDO(createReqVO, scoreRuleType, scoreRule);
scoreRuleMapper.insert(scoreRule);
......@@ -55,29 +55,48 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
return scoreRule.getId();
}
private void verifyCommon(ScoreRuleDO scoreRule) {
private void verifyCommon(ScoreRuleBaseVO scoreRuleIn) {
//校验公共入参
if (scoreRule.getGetScoreOnce() <= 0) {
if (scoreRuleIn.getGetScoreOnce() <= 0) {
throw exception(SCORE_RULE_FIELD_ERROR);
}
if (scoreRule.getMaxScoreTotal() <= 0) {
if (scoreRuleIn.getMaxScoreTotal() <= 0) {
throw exception(SCORE_RULE_FIELD_ERROR);
}
if (scoreRule.getStartTime().after((scoreRule.getEndTime())) || scoreRule.getEndTime().before(Date.from(Instant.now()))) {
if (scoreRuleIn.getStartTime().after((scoreRuleIn.getEndTime())) || scoreRuleIn.getEndTime().before(Date.from(Instant.now()))) {
throw exception(SCORE_RULE_FIELD_ERROR);
}
if (scoreRule.getScorePeriod() <= 0) {
if (scoreRuleIn.getScorePeriod() <= 0) {
throw exception(SCORE_RULE_FIELD_ERROR);
}
//如果是启用,校验同一个规则下,有效期内有没有重复的规则设置,分享不校验
if (scoreRule.getStatus() == ScoreRuleStatusEnum.ENABLED.getValue() && scoreRule.getType() != ScoreRuleTypeEnum.SHARE.getValue()) {
//如果是启用,校验同一个规则下,有效期内有没有重复的规则设置,分享不校验。海运空运分开算
if (scoreRuleIn.getStatus() == ScoreRuleStatusEnum.ENABLED.getValue() && scoreRuleIn.getType() != ScoreRuleTypeEnum.SHARE.getValue()) {
LambdaQuery<ScoreRuleDO> scoreRuleDOLambdaQuery = new LambdaQuery<>();
scoreRuleDOLambdaQuery.eq(ScoreRuleDO::getStatus, ScoreRuleStatusEnum.ENABLED.getValue())
.eq(ScoreRuleDO::getType, scoreRule.getType())
.eq(ScoreRuleDO::getStatus, ScoreRuleStatusEnum.ENABLED.getValue());
Long count = scoreRuleMapper.selectCount(scoreRuleDOLambdaQuery);
if (count > 0) {
throw exception(SCORE_RULE_FIELD_ERROR);
.eq(ScoreRuleDO::getType, scoreRuleIn.getType());
if (scoreRuleIn.getType() == ScoreRuleTypeEnum.ORDER_V.getValue()) {
ScoreRuleOrderVExtraVO extraOrderV = scoreRuleIn.getExtraOrderV();
if (extraOrderV == null) {
throw exception(SCORE_RULE_FIELD_ERROR);
}
Integer transportType = extraOrderV.getTransportType();
if (transportType != TransportType.OCEAN_LCL.getValue() && transportType != TransportType.SPECIAL_LINE_AIR_FREIGHT.getValue()) {
throw exception(SCORE_RULE_FIELD_ERROR);
}
List<ScoreRuleDO> scoreRuleDOS = scoreRuleMapper.selectList(scoreRuleDOLambdaQuery);
if (scoreRuleDOS != null && !scoreRuleDOS.isEmpty()) {
for (ScoreRuleDO scoreRuleDO : scoreRuleDOS) {
ScoreRuleOrderVExtraVO bean = JSONUtil.toBean(scoreRuleDO.getExtra(), ScoreRuleOrderVExtraVO.class);
if (Objects.equals(bean.getTransportType(), transportType)) {
throw exception(SCORE_RULE_FIELD_ERROR);
}
}
}
} else {
Long count = scoreRuleMapper.selectCount(scoreRuleDOLambdaQuery);
if (count > 0) {
throw exception(SCORE_RULE_FIELD_ERROR);
}
}
}
}
......@@ -93,7 +112,7 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
throw exception(SCORE_RULE_UPDATE_ERROR);
}
ScoreRuleDO scoreRule = ScoreRuleConvert.INSTANCE.convert(updateReqVO);
verifyCommon(scoreRule);
verifyCommon(updateReqVO);
verifyAndSetExtraDO(updateReqVO, updateReqVO.getType(), scoreRule);
// 更新
scoreRuleMapper.updateById(scoreRule);
......@@ -115,7 +134,7 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
if (extraOrderV.getFirstOrder() != YesOrNoTypeEnum.YES.ordinal() && extraOrderV.getFirstOrder() != YesOrNoTypeEnum.NO.ordinal()) {
throw exception(SCORE_RULE_FIELD_ERROR);
}
if (extraOrderV.getTransportType() != TransportType.OCEAN_LCL.getValue() && extraOrderV.getFirstOrder() != TransportType.SPECIAL_LINE_AIR_FREIGHT.getValue()) {
if (extraOrderV.getTransportType() != TransportType.OCEAN_LCL.getValue() && extraOrderV.getTransportType() != TransportType.SPECIAL_LINE_AIR_FREIGHT.getValue()) {
throw exception(SCORE_RULE_FIELD_ERROR);
}
if (StringUtils.isAnyBlank(extraOrderV.getTargetCountry(), extraOrderV.getTargetCity(), extraOrderV.getReceiveAddr(), extraOrderV.getOrderEntry())) {
......@@ -208,15 +227,13 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
@Override
public List<ScoreRuleBackVO> getScoreRuleList(Collection<Long> ids) {
List<ScoreRuleDO> scoreRuleDOS = scoreRuleMapper.selectBatchIds(ids);
List<ScoreRuleBackVO> scoreRuleBackVOS = ScoreRuleConvert.INSTANCE.convertList(scoreRuleDOS);
return scoreRuleBackVOS;
return ScoreRuleConvert.INSTANCE.convertList(scoreRuleDOS);
}
@Override
public PageResult<ScoreRuleBackVO> getScoreRulePage(ScoreRuleQueryVO query, PageVO page) {
PageResult<ScoreRuleDO> pageResult = scoreRuleMapper.selectPage(page, query);
PageResult<ScoreRuleBackVO> scoreRuleBackVOPageResult = ScoreRuleConvert.INSTANCE.convertPage(pageResult);
return scoreRuleBackVOPageResult;
return ScoreRuleConvert.INSTANCE.convertPage(pageResult);
}
/**
......
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