车型添加时如果套餐未选择,则不验证
This commit is contained in:
@ -108,31 +108,33 @@ public class ZcCarModelController extends BaseController
|
|||||||
{
|
{
|
||||||
return error("新增失败,该车型已存在");
|
return error("新增失败,该车型已存在");
|
||||||
}
|
}
|
||||||
String[] stringArray = rentCarRuleIds.stream()
|
if(rentCarRuleIds.size() > 0){
|
||||||
.map(String::valueOf)
|
String[] stringArray = rentCarRuleIds.stream()
|
||||||
.toArray(String[]::new);
|
.map(String::valueOf)
|
||||||
List<ZcRentCarRule> carRuleList = zcRentCarRuleService.selectZcRentCarRuleByIds(stringArray);
|
.toArray(String[]::new);
|
||||||
|
List<ZcRentCarRule> carRuleList = zcRentCarRuleService.selectZcRentCarRuleByIds(stringArray);
|
||||||
|
|
||||||
// 按类型分组
|
// 按类型分组
|
||||||
Map<String, List<ZcRentCarRule>> typeGroups = carRuleList.stream()
|
Map<String, List<ZcRentCarRule>> typeGroups = carRuleList.stream()
|
||||||
.collect(Collectors.groupingBy(ZcRentCarRule::getRentalType));
|
.collect(Collectors.groupingBy(ZcRentCarRule::getRentalType));
|
||||||
|
|
||||||
// 检查类型1、2、4的重复
|
// 检查类型1、2、4的重复
|
||||||
boolean hasDuplicateCommon = typeGroups.entrySet().stream()
|
boolean hasDuplicateCommon = typeGroups.entrySet().stream()
|
||||||
.filter(entry -> !"3".equals(entry.getKey())) // 排除类型3
|
.filter(entry -> !"3".equals(entry.getKey())) // 排除类型3
|
||||||
.anyMatch(entry -> entry.getValue().size() > 1);
|
.anyMatch(entry -> entry.getValue().size() > 1);
|
||||||
|
|
||||||
if (hasDuplicateCommon) {
|
if (hasDuplicateCommon) {
|
||||||
return error("新增失败,同一车型不允许设置相同类型套餐。");
|
return error("新增失败,同一车型不允许设置相同类型套餐。");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 专门检查类型3的租赁天数重复
|
// 专门检查类型3的租赁天数重复
|
||||||
List<ZcRentCarRule> type3Rules = typeGroups.get("3");
|
List<ZcRentCarRule> type3Rules = typeGroups.get("3");
|
||||||
if (type3Rules != null) {
|
if (type3Rules != null) {
|
||||||
Set<Long> rentalDaysSet = new HashSet<>();
|
Set<Long> rentalDaysSet = new HashSet<>();
|
||||||
for (ZcRentCarRule rule : type3Rules) {
|
for (ZcRentCarRule rule : type3Rules) {
|
||||||
if (!rentalDaysSet.add(rule.getRentalDays())) {
|
if (!rentalDaysSet.add(rule.getRentalDays())) {
|
||||||
return error("新增失败,同一车型不允许设置相同租赁天数的按天租套餐.");
|
return error("新增失败,同一车型不允许设置相同租赁天数的按天租套餐.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -173,31 +175,33 @@ public class ZcCarModelController extends BaseController
|
|||||||
{
|
{
|
||||||
return error("修改失败,该车型已存在");
|
return error("修改失败,该车型已存在");
|
||||||
}
|
}
|
||||||
String[] stringArray = rentCarRuleIds.stream()
|
if(rentCarRuleIds.size() > 0) {
|
||||||
.map(String::valueOf)
|
String[] stringArray = rentCarRuleIds.stream()
|
||||||
.toArray(String[]::new);
|
.map(String::valueOf)
|
||||||
List<ZcRentCarRule> carRuleList = zcRentCarRuleService.selectZcRentCarRuleByIds(stringArray);
|
.toArray(String[]::new);
|
||||||
|
List<ZcRentCarRule> carRuleList = zcRentCarRuleService.selectZcRentCarRuleByIds(stringArray);
|
||||||
|
|
||||||
// 按类型分组
|
// 按类型分组
|
||||||
Map<String, List<ZcRentCarRule>> typeGroups = carRuleList.stream()
|
Map<String, List<ZcRentCarRule>> typeGroups = carRuleList.stream()
|
||||||
.collect(Collectors.groupingBy(ZcRentCarRule::getRentalType));
|
.collect(Collectors.groupingBy(ZcRentCarRule::getRentalType));
|
||||||
|
|
||||||
// 检查类型1、2、4的重复
|
// 检查类型1、2、4的重复
|
||||||
boolean hasDuplicateCommon = typeGroups.entrySet().stream()
|
boolean hasDuplicateCommon = typeGroups.entrySet().stream()
|
||||||
.filter(entry -> !"3".equals(entry.getKey())) // 排除类型3
|
.filter(entry -> !"3".equals(entry.getKey())) // 排除类型3
|
||||||
.anyMatch(entry -> entry.getValue().size() > 1);
|
.anyMatch(entry -> entry.getValue().size() > 1);
|
||||||
|
|
||||||
if (hasDuplicateCommon) {
|
if (hasDuplicateCommon) {
|
||||||
return error("新增失败,同一车型不允许设置相同类型套餐。");
|
return error("新增失败,同一车型不允许设置相同类型套餐。");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 专门检查类型3的租赁天数重复
|
// 专门检查类型3的租赁天数重复
|
||||||
List<ZcRentCarRule> type3Rules = typeGroups.get("3");
|
List<ZcRentCarRule> type3Rules = typeGroups.get("3");
|
||||||
if (type3Rules != null) {
|
if (type3Rules != null) {
|
||||||
Set<Long> rentalDaysSet = new HashSet<>();
|
Set<Long> rentalDaysSet = new HashSet<>();
|
||||||
for (ZcRentCarRule rule : type3Rules) {
|
for (ZcRentCarRule rule : type3Rules) {
|
||||||
if (!rentalDaysSet.add(rule.getRentalDays())) {
|
if (!rentalDaysSet.add(rule.getRentalDays())) {
|
||||||
return error("新增失败,同一车型不允许设置相同租赁天数的按天租套餐.");
|
return error("新增失败,同一车型不允许设置相同租赁天数的按天租套餐.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user