fix 新增区域管理报错
This commit is contained in:
-62
@@ -49,37 +49,6 @@ public class LawsAreaServiceImpl extends ServiceImpl<LawsAreaMapper, LawsArea> i
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void add(LawsArea lawsArea) {
|
public void add(LawsArea lawsArea) {
|
||||||
Integer inputSort = lawsArea.getSort();
|
|
||||||
//查询展示顺序相同的
|
|
||||||
QueryWrapper<LawsArea> queryWrapper= new QueryWrapper<>();
|
|
||||||
queryWrapper.orderByAsc("sort");
|
|
||||||
queryWrapper.eq("sort", inputSort);
|
|
||||||
Integer orderNumCount = lawsAreaMapper.selectCount(queryWrapper);
|
|
||||||
if(orderNumCount > 0) {//有重复展示顺序的,后面的号全+1
|
|
||||||
//设置排序
|
|
||||||
QueryWrapper<LawsArea> orderNumQueryWrapper = new QueryWrapper<>();
|
|
||||||
orderNumQueryWrapper.ge("sort", inputSort)
|
|
||||||
.orderByAsc("sort");
|
|
||||||
List<LawsArea> geSortList = list(orderNumQueryWrapper);
|
|
||||||
|
|
||||||
//判断相邻的序号,去掉不邻的
|
|
||||||
for(int i = 0 ; i <= geSortList.size() ; i++) {
|
|
||||||
if (geSortList.size()==1){
|
|
||||||
break;
|
|
||||||
}else if (geSortList.get(i + 1).getSort() - geSortList.get(i).getSort() > 1) {
|
|
||||||
int deleteStart = geSortList.get(i+1).getSort();
|
|
||||||
geSortList = geSortList.stream().filter(e->e.getSort() < deleteStart).collect(Collectors.toList());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
geSortList.stream().forEach(e -> e.setSort(e.getSort() + 1));
|
|
||||||
saveOrUpdateBatch(geSortList);
|
|
||||||
}
|
|
||||||
|
|
||||||
Date now = new Date();
|
|
||||||
lawsArea.setCreateTime(now);
|
|
||||||
lawsArea.setUpdateTime(now);
|
|
||||||
save(lawsArea);
|
save(lawsArea);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@@ -105,37 +74,6 @@ public class LawsAreaServiceImpl extends ServiceImpl<LawsAreaMapper, LawsArea> i
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void editById(LawsArea lawsArea) {
|
public void editById(LawsArea lawsArea) {
|
||||||
Integer inputSort = lawsArea.getSort();
|
|
||||||
//查询展示顺序相同的
|
|
||||||
QueryWrapper<LawsArea> queryWrapper= new QueryWrapper<>();
|
|
||||||
queryWrapper.orderByAsc("sort");
|
|
||||||
Integer orderNumData = list(queryWrapper).stream().filter(e->e.getId().equals(lawsArea.getId()))
|
|
||||||
.map(e -> e.getSort()).collect(Collectors.toList()).get(0);
|
|
||||||
queryWrapper.eq("sort", inputSort);
|
|
||||||
Integer orderNumCount = lawsAreaMapper.selectCount(queryWrapper);
|
|
||||||
if(orderNumCount > 0 && !orderNumData.equals(inputSort)) {//有重复展示顺序的,后面的号全+1
|
|
||||||
//设置排序
|
|
||||||
QueryWrapper<LawsArea> orderNumQueryWrapper = new QueryWrapper<>();
|
|
||||||
orderNumQueryWrapper.ge("sort", inputSort)
|
|
||||||
.orderByAsc("sort");
|
|
||||||
List<LawsArea> geSortList = list(orderNumQueryWrapper);
|
|
||||||
|
|
||||||
//判断相邻的序号,去掉不邻的
|
|
||||||
for(int i = 0 ; i <= geSortList.size() ; i++) {
|
|
||||||
if (geSortList.size()==1){
|
|
||||||
break;
|
|
||||||
}else if (geSortList.get(i + 1).getSort() - geSortList.get(i).getSort() > 1) {
|
|
||||||
int deleteStart = geSortList.get(i+1).getSort();
|
|
||||||
geSortList = geSortList.stream().filter(e->e.getSort() < deleteStart).collect(Collectors.toList());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
geSortList.stream().forEach(e -> e.setSort(e.getSort() + 1));
|
|
||||||
saveOrUpdateBatch(geSortList);
|
|
||||||
}
|
|
||||||
Date now = new Date();
|
|
||||||
lawsArea.setUpdateTime(now);
|
|
||||||
saveOrUpdate(lawsArea);
|
saveOrUpdate(lawsArea);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user