public void test11(){
List<String> dbStr = new ArrayList<>();
dbStr.add("aaa");
// dbStr.add("cccc");
dbStr.add("dddd");
List<String> dbStr1 = new ArrayList<>();
dbStr.add("aaa");
dbStr.add("dddd");
dbStr.add("ffff");
for (String srt:dbStr) {
if(!dbStr1.contains(srt)){
dbStr.remove(srt);
}
}
for (String ss:dbStr1) {
if(id!=null){
service.update(id);
}else{
service.add(id);
}
}
}
CostTypes fatherType=new CostTypes();
fatherType.setId(costSubTypeVO.getSid());
fatherType.setTypeName(costSubTypeVO.getStypeName());
costTypeService.updateById(fatherType);
CostTypes fatherIdType=new CostTypes();
fatherIdType.setFatherId(costSubTypeVO.getSid());
List<CostTypes> oldSubTypeList=costTypeService.selectList(new EntityWrapper<>(fatherIdType));
List<String> newSubTypeNames=new ArrayList<>();
for (CostTypes newSubType: costSubTypeVO.getSubTypes()) {
newSubTypeNames.add(newSubType.getTypeName());
}
for (CostTypes costType : costSubTypeVO.getSubTypes()) {
if (costType.getId()!=null){
for (CostTypes oldSubType: oldSubTypeList) {
if (newSubTypeNames.contains(oldSubType.getTypeName())){
}
}
costTypeService.updateById(costType);
}
else {
CostTypes newType=new CostTypes();
newType.setTypeName(costType.getTypeName());
newType.setFatherId(costSubTypeVO.getSid());
costTypeService.insert(newType);
}
}
/**
* 修改一级
*/
CostTypes fatherType = new CostTypes();
fatherType.setId(costSubTypeVO.getSid());
fatherType.setTypeName(costSubTypeVO.getStypeName());
costTypeService.updateById(fatherType);
/**
* 获取数据库中一级下的二级list
*/
CostTypes fatherIdType = new CostTypes();
fatherIdType.setFatherId(costSubTypeVO.getSid());
List<CostTypes> dbList = costTypeService.selectList(new EntityWrapper<>(fatherIdType));
/**
* 将前端传过来的二级list的name单独取出
*/
List<String> newStrList = new ArrayList<>();
for (CostTypes newTypes : costSubTypeVO.getSubTypes()) {
newStrList.add(newTypes.getTypeName());
}
/**
* 先处理数据库的list 若数据库里的对象name不存在于新的list中,删除
*/
for (CostTypes dbTypes : dbList) {
if (!newStrList.contains(dbTypes.getTypeName())) {
costTypeService.deleteById(dbTypes.getId());
}
}
/**
* 再处理前端的 若id不为空 则修改
* id为空 则新增
*/
for (CostTypes newList : costSubTypeVO.getSubTypes()) {
if (newList.getId() != null) {
costTypeService.updateById(newList);
} else {
CostTypes newType = new CostTypes();
newType.setTypeName(newList.getTypeName());
newType.setFatherId(costSubTypeVO.getSid());
costTypeService.insert(newType);
}
}