标准法规清单-国家/地区清单中的 每个国家或者地区只能建立一次清单,需做限制
当前的是修改的限制
This commit is contained in:
+14
-2
@@ -26,6 +26,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -150,8 +151,19 @@ public class SarLawsDetailedListController extends BaseController<SarLawsDetaile
|
||||
@PutMapping("/updateList")
|
||||
public ResponseMessage updateList(@RequestBody DetailedUpDto detailedUpDto) {
|
||||
String src = sarLawsDetailedListService.updateList(detailedUpDto);
|
||||
return Result.success("200",src,true);
|
||||
System.out.println("src是什么呢?"+src);
|
||||
if (Objects.equals(src, "国家/地区清单修改失败") || Objects.equals(src, "车型类别清单修改失败")){
|
||||
src = "该清单已存在,修改失败";
|
||||
return Result.error("200",src,false);
|
||||
}else if (Objects.equals(src, "国家/地区清单修改成功") || Objects.equals(src, "车型类别清单修改成功")){
|
||||
src = "修改成功";
|
||||
return Result.success("200",src,true);
|
||||
}else {
|
||||
src = "修改成功";
|
||||
return Result.success("200",src,true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+151
-6
@@ -314,7 +314,7 @@ public class SarLawsDetailedListServiceImpl extends ServiceImpl<SarLawsDetailedL
|
||||
for (String s : split) {
|
||||
for (Map<String, String> map1 : arr) {
|
||||
if (map1.get("value").equals(s)) {
|
||||
s = map1.get("label");
|
||||
s = map1.get("value");
|
||||
builder.append(s + ",");
|
||||
break;
|
||||
}
|
||||
@@ -325,7 +325,7 @@ public class SarLawsDetailedListServiceImpl extends ServiceImpl<SarLawsDetailedL
|
||||
} else {
|
||||
for (Map<String, String> map1 : arr) {
|
||||
if (map1.get("value").equals(list1.getCountryArea())) {
|
||||
list1.setCountryArea(map1.get("label"));
|
||||
list1.setCountryArea(map1.get("value"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -340,14 +340,159 @@ public class SarLawsDetailedListServiceImpl extends ServiceImpl<SarLawsDetailedL
|
||||
|
||||
@Override
|
||||
public String updateList(DetailedUpDto detailedUpDto) {
|
||||
|
||||
QueryWrapper<SarLawsDetailedList> wrapper = new QueryWrapper<>();
|
||||
wrapper.select("DISTINCT country_area,car_type");
|
||||
List<SarLawsDetailedList> sarLawsDetailedLists = sarLawsDetailedListDao.selectList(wrapper);
|
||||
|
||||
//list是数据库里根据id查出来的数据;detailedUpDto是页面传回来的数据
|
||||
SarLawsDetailedList list = sarLawsDetailedListDao.selectById(detailedUpDto.getId());
|
||||
System.out.println("数据库里存的当前数据"+list.getCountryArea());
|
||||
System.out.println("页面现在的数据"+detailedUpDto.getCountryArea());
|
||||
|
||||
//国家/地区清单 多选是否可以添加的标识,true表示可以添加,false表示不许添加
|
||||
boolean multiEditFlag = true;
|
||||
//国家/地区清单 单选是否可以添加的标识,true表示可以添加,false表示不许添加
|
||||
boolean singleEditFlag = true;
|
||||
//车型类别是否可以添加的标识,true表示可以添加,false表示不许添加
|
||||
boolean carEditFlag = true;
|
||||
|
||||
if (detailedUpDto.getCountryArea() == null && detailedUpDto.getCarType() == null) {
|
||||
//下面放修改的具体方法
|
||||
//国家或地区
|
||||
//如果页面的国家地区为空,就把数据库里的国家地区字段也设为空
|
||||
updateListMethod(detailedUpDto);
|
||||
return "其他清单添加成功";
|
||||
}
|
||||
//如果是车辆修改
|
||||
else if (detailedUpDto.getCarType() != null) {
|
||||
//就判断页面的值和数据库里的值是否相等
|
||||
for (int i = 0; i < sarLawsDetailedLists.size(); i++) {
|
||||
//判断数据库里的数据的车型类别字段是否为空
|
||||
if (null == sarLawsDetailedLists.get(i) || null == sarLawsDetailedLists.get(i).getCarType()){
|
||||
System.out.println("数据库里第" + (i + 1) + "条的车型类别字段长度为空,不重复,目前可以添加");
|
||||
}
|
||||
else if (Objects.equals(detailedUpDto.getCarType(), list.getCarType())){
|
||||
System.out.println("页面的数据和数据库里存的当前数据相同,说明没有做更改,允许提交");
|
||||
}
|
||||
//相等就不许添加
|
||||
else if (!Objects.equals(detailedUpDto.getCarType(), list.getCarType()) && Objects.equals(detailedUpDto.getCarType(), sarLawsDetailedLists.get(i).getCarType())) {
|
||||
System.out.println("数据库里第" + (i + 1) + "条的车型类别字段和页面一样,重复,不许添加");
|
||||
carEditFlag = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
//如果是国家修改
|
||||
else if (detailedUpDto.getCountryArea() != null) {
|
||||
for (int i = 0; i < sarLawsDetailedLists.size(); i++) {
|
||||
//就先判断数据库里的数据的国家/地区字段是否为空
|
||||
if (null == sarLawsDetailedLists.get(i) || null == sarLawsDetailedLists.get(i).getCountryArea()) {
|
||||
System.out.println("数据库里第" + (i + 1) + "条的国家地区字段长度为空,不重复,目前可以添加");
|
||||
}
|
||||
else if (Objects.equals(detailedUpDto.getCountryArea(), list.getCountryArea())){
|
||||
System.out.println("页面的数据和数据库里存的当前数据相同,说明没有做更改,允许提交");
|
||||
}
|
||||
//再判断页面字段长度是否与数据库里的长度一样,如果长度不一样,允许新增
|
||||
else if (detailedUpDto.getCountryArea().length() != sarLawsDetailedLists.get(i).getCountryArea().length()) {
|
||||
System.out.println("数据库里第" + (i + 1) + "条的国家地区字段长度和页面的国家地区字段长度不一样,不重复,目前可以添加");
|
||||
}
|
||||
//如果不为空且长度一样
|
||||
else {
|
||||
//判断页面的国家地区是单选还是多选(判断能不能拆)
|
||||
if (detailedUpDto.getCountryArea().contains(",")) {
|
||||
System.out.println("页面是多选");
|
||||
//如果数据库里的国家地区字段存在",",说明是多选,如果不存在说明是单选
|
||||
if (sarLawsDetailedLists.get(i).getCountryArea().contains(",")) {
|
||||
System.out.println("数据库是多选,如果页面字段拆分之后都包含于数据库字段拆分之后,则说明重复,目前不许添加");
|
||||
System.out.println("页面字段为" + detailedUpDto.getCountryArea());
|
||||
//页面字段以“,”为分隔符拆分后的结果
|
||||
String[] frontCountryArea = detailedUpDto.getCountryArea().split(",");
|
||||
//数据库字段以“,”为分隔符拆分后的结果
|
||||
String[] databaseCountryArea = sarLawsDetailedLists.get(i).getCountryArea().split(",");
|
||||
|
||||
//如果页面字段拆分之后都包含于数据库字段拆分之后,则说明重复,不许添加
|
||||
for (int j = 0; j < frontCountryArea.length; j++) {
|
||||
//如果数据库包含了页面字段的所有值,说明这俩完全相同,重复,不许添加
|
||||
List<String> databaseCountryAreaList = Arrays.asList(databaseCountryArea);
|
||||
if (!Objects.equals(detailedUpDto.getCountryArea(), list.getCountryArea()) && databaseCountryAreaList.contains(frontCountryArea[j])) {
|
||||
System.out.println("数据库" + databaseCountryAreaList);
|
||||
System.out.println("页面" + frontCountryArea[j]);
|
||||
System.out.println("数据库里的字段包含页面里的字段,可能重复,目前不许修改");
|
||||
multiEditFlag = false;
|
||||
} else {
|
||||
System.out.println("数据库" + databaseCountryAreaList);
|
||||
System.out.println("页面" + frontCountryArea[j]);
|
||||
System.out.println("数据库里的字段和页面字段虽然长度相同,但是里面有不一样的元素,可以修改");
|
||||
multiEditFlag = true;
|
||||
}
|
||||
}
|
||||
if (multiEditFlag == true) {
|
||||
System.out.println("长度相同,只要有一个不重复,就可以添加");
|
||||
} else {
|
||||
System.out.println("长度相同,整个循环下来都重复,说明两个字段重复,不许添加");
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
System.out.println("页面是单选");
|
||||
|
||||
//如果数据库里的国家地区字段存在",",说明是多选,如果不存在说明是单选
|
||||
if (sarLawsDetailedLists.get(i).getCountryArea().contains(",")) {
|
||||
System.out.println("数据库是多选,肯定不重复,目前可以添加");
|
||||
} else {
|
||||
System.out.println("数据库是单选,如果数据库里的字段和页面的字段相等,重复,不许添加");
|
||||
//如果数据库里的字段和页面的字段相等,重复,不许添加
|
||||
if (!Objects.equals(detailedUpDto.getCountryArea(), list.getCountryArea()) && Objects.equals(sarLawsDetailedLists.get(i).getCountryArea(), detailedUpDto.getCountryArea())) {
|
||||
System.out.println("数据库里的字段和页面的字段相等,重复,不许添加");
|
||||
singleEditFlag = false;
|
||||
break;
|
||||
} else {
|
||||
System.out.println("数据库里的字段和页面的字段不相等,不重复,允许添加");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//如果整个循环下来都没有重复,则可以添加,不然就说明有重复,不能添加
|
||||
if (carEditFlag == true && multiEditFlag == true && singleEditFlag == true) {
|
||||
//下面放添加的具体方法
|
||||
//国家或地区
|
||||
//如果页面的国家地区为空,就把数据库里的国家地区字段也设为空
|
||||
updateListMethod(detailedUpDto);
|
||||
return "车型类别清单修改成功";
|
||||
//添加方法结束
|
||||
} else if (carEditFlag == false){
|
||||
//0表示添加成功,1表示添加失败
|
||||
return "车型类别清单修改失败";
|
||||
}
|
||||
|
||||
//如果循环完整个数据库,都没有重复使当前数据无法添加,则添加
|
||||
if (multiEditFlag == true && singleEditFlag == true && carEditFlag == true) {
|
||||
//下面放添加的具体方法
|
||||
//国家或地区
|
||||
//如果页面的国家地区为空,就把数据库里的国家地区字段也设为空
|
||||
updateListMethod(detailedUpDto);
|
||||
//0表示添加成功,1表示添加失败
|
||||
return "国家/地区清单修改成功";
|
||||
//添加方法结束
|
||||
} else {
|
||||
//0表示添加成功,1表示添加失败
|
||||
return "国家/地区清单修改失败";
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void updateListMethod(DetailedUpDto detailedUpDto) {
|
||||
//list是数据库里根据id查出来的数据;detailedUpDto是页面传回来的数据
|
||||
SarLawsDetailedList list = sarLawsDetailedListDao.selectById(detailedUpDto.getId());
|
||||
|
||||
//国家或地区
|
||||
//如果页面的国家地区为空,就把数据库里的国家地区字段也设为空
|
||||
if (StringUtils.isBlank(detailedUpDto.getCountryArea())) list.setCountryArea(null);
|
||||
else if ("null".equals(detailedUpDto.getCountryArea())) ;
|
||||
//把数据库里的国家地区字段设为页面的国家地区
|
||||
//把数据库里的国家地区字段设为页面的国家地区
|
||||
else list.setCountryArea(detailedUpDto.getCountryArea());
|
||||
//车型类别
|
||||
if (StringUtils.isBlank(detailedUpDto.getCarType())) list.setCarType(null);
|
||||
@@ -429,9 +574,9 @@ public class SarLawsDetailedListServiceImpl extends ServiceImpl<SarLawsDetailedL
|
||||
}
|
||||
service.updateDetailedLaws(detailedUpDto.getId(), timeDto);
|
||||
}
|
||||
return "修改成功";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public SarLawsDetailedList selSarLawDetailById(String id) {
|
||||
return baseMapper.selectById(id);
|
||||
|
||||
Reference in New Issue
Block a user