修复删除部门BUG以及部门ID编号自增过大问题

This commit is contained in:
kenhy
2020-05-19 01:12:40 +08:00
parent 4f8da2c2ee
commit 8cee2af209
4 changed files with 15 additions and 12 deletions

View File

@ -7,11 +7,8 @@
* 一经发现盗用、分享等行为,将追究法律责任,后果自负
*/
package co.yixiang.modules.system.domain;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
@ -29,7 +26,7 @@ import java.io.Serializable;
public class Dept implements Serializable {
/** ID */
@TableId
@TableId(value = "id",type= IdType.AUTO)
private Long id;

View File

@ -30,6 +30,7 @@ import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@ -109,16 +110,21 @@ public class DeptController {
@PreAuthorize("@el.check('admin','dept:del')")
public ResponseEntity<Object> delete(@RequestBody Set<Long> ids){
//if(StrUtil.isNotEmpty("22")) throw new BadRequestException("演示环境禁止操作");
Set<DeptDto> deptDtos = new HashSet<>();
List<Long> deptIds = new ArrayList<>();
for (Long id : ids) {
List<Dept> deptList = deptService.findByPid(id);
deptDtos.add(generator.convert(deptService.getOne(new QueryWrapper<Dept>().eq("id",id)),DeptDto.class));
Dept dept = deptService.getOne(new QueryWrapper<Dept>().eq("id",id));
if(null!=dept){
deptIds.add(dept.getId());
}
if(CollectionUtil.isNotEmpty(deptList)){
deptDtos = deptService.getDeleteDepts(deptList, deptDtos);
for(Dept d:deptList){
deptIds.add(d.getId());
}
}
}
try {
deptService.removeByIds(deptDtos);
deptService.removeByIds(deptIds);
}catch (Throwable e){
ThrowableUtil.throwForeignKeyException(e, "所选部门中存在岗位或者角色关联,请取消关联后再试");
}

View File

@ -67,7 +67,7 @@ public interface DeptService extends BaseService<Dept>{
* @param deptDtos /
* @return /
*/
Set<DeptDto> getDeleteDepts(List<Dept> deptList, Set<DeptDto> deptDtos);
/*Set<DeptDto> getDeleteDepts(List<Dept> deptList, Set<DeptDto> deptDtos);*/
/**
* 根据角色ID查询

View File

@ -161,7 +161,7 @@ public class DeptServiceImpl extends BaseServiceImpl<DeptMapper, Dept> implement
* @param deptDtos /
* @return /
*/
@Override
/* @Override
public Set<DeptDto> getDeleteDepts(List<Dept> deptList, Set<DeptDto> deptDtos) {
for (Dept dept : deptList) {
@ -172,7 +172,7 @@ public class DeptServiceImpl extends BaseServiceImpl<DeptMapper, Dept> implement
}
}
return deptDtos;
}
}*/
/**
* 根据角色ID查询