|
|
@@ -12,6 +12,7 @@ import org.jeecg.common.api.vo.Result;
|
|
|
import org.jeecg.common.config.TenantContext;
|
|
|
import org.jeecg.common.constant.CacheConstant;
|
|
|
import org.jeecg.common.constant.CommonConstant;
|
|
|
+import org.jeecg.common.exception.JeecgBootException;
|
|
|
import org.jeecg.common.system.util.JwtUtil;
|
|
|
import org.jeecg.common.system.vo.LoginUser;
|
|
|
import org.jeecg.common.util.ImportExcelUtil;
|
|
|
@@ -22,7 +23,9 @@ import org.jeecg.modules.system.app.entity.AppSite;
|
|
|
import org.jeecg.modules.system.app.mapper.AppSiteMapper;
|
|
|
import org.jeecg.modules.system.entity.SysDepart;
|
|
|
import org.jeecg.modules.system.entity.SysUser;
|
|
|
+import org.jeecg.modules.system.entity.SysUserDepart;
|
|
|
import org.jeecg.modules.system.mapper.SysDepartMapper;
|
|
|
+import org.jeecg.modules.system.mapper.SysUserDepartMapper;
|
|
|
import org.jeecg.modules.system.model.DepartIdModel;
|
|
|
import org.jeecg.modules.system.model.SysDepartTreeModel;
|
|
|
import org.jeecg.modules.system.service.ISysDepartService;
|
|
|
@@ -75,6 +78,8 @@ public class SysDepartController {
|
|
|
private SysDepartMapper sysDepartMapper;
|
|
|
@Resource
|
|
|
private AppSiteMapper appSiteMapper;
|
|
|
+ @Resource
|
|
|
+ private SysUserDepartMapper sysUserDepartMapper;
|
|
|
/**
|
|
|
* 查询数据 查出我的部门,并以树结构数据格式响应给前端
|
|
|
*
|
|
|
@@ -248,9 +253,16 @@ public class SysDepartController {
|
|
|
|
|
|
Result<SysDepart> result = new Result<SysDepart>();
|
|
|
SysDepart sysDepart = sysDepartService.getById(id);
|
|
|
- if(!sysDepartMapper.selectList(Wrappers.<SysDepart>lambdaQuery().eq(SysDepart::getParentId, id)).isEmpty()){
|
|
|
- result.error500("请先删除子部门");
|
|
|
- }
|
|
|
+ List<SysDepart> sysDeparts = sysDepartMapper.selectList(Wrappers.<SysDepart>lambdaQuery().eq(SysDepart::getParentId, id));
|
|
|
+ if(sysDeparts.isEmpty()){
|
|
|
+ throw new JeecgBootException("请先删除子部门");
|
|
|
+ }else {
|
|
|
+ sysDeparts.forEach(depart -> {
|
|
|
+ if(!sysUserDepartMapper.selectList(Wrappers.<SysUserDepart>lambdaQuery().eq(SysUserDepart::getId, depart.getId())).isEmpty()){
|
|
|
+ throw new JeecgBootException("当前部门或下级部门存在用户!");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
if(sysDepart==null) {
|
|
|
result.error500("未找到对应实体");
|
|
|
}else {
|
|
|
@@ -275,12 +287,27 @@ public class SysDepartController {
|
|
|
@RequestMapping(value = "/deleteBatch", method = RequestMethod.DELETE)
|
|
|
@CacheEvict(value= {CacheConstant.SYS_DEPARTS_CACHE,CacheConstant.SYS_DEPART_IDS_CACHE}, allEntries=true)
|
|
|
public Result<SysDepart> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
|
|
|
-
|
|
|
- Result<SysDepart> result = new Result<SysDepart>();
|
|
|
+ List<String> strings = List.of(ids.split(","));
|
|
|
+ Result<SysDepart> result = new Result<SysDepart>();
|
|
|
if (ids == null || "".equals(ids.trim())) {
|
|
|
result.error500("参数不识别!");
|
|
|
} else {
|
|
|
+
|
|
|
this.sysDepartService.deleteBatchWithChildren(Arrays.asList(ids.split(",")));
|
|
|
+ strings.forEach(sysDepart -> {
|
|
|
+ List<SysDepart> sysDeparts = sysDepartMapper.selectList(Wrappers.<SysDepart>lambdaQuery().eq(SysDepart::getParentId, sysDepart));
|
|
|
+ if(sysDeparts.isEmpty()){
|
|
|
+ throw new JeecgBootException("请先删除子部门");
|
|
|
+ }else {
|
|
|
+ sysDeparts.forEach(depart -> {
|
|
|
+ if(!sysUserDepartMapper.selectList(Wrappers.<SysUserDepart>lambdaQuery().eq(SysUserDepart::getId, depart.getId())).isEmpty()){
|
|
|
+ throw new JeecgBootException("当前部门或下级部门存在用户!");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ appSiteMapper.delete(Wrappers.<AppSite>lambdaQuery()
|
|
|
+ .eq(AppSite::getOrgCode, sysDepartMapper.getDepartById(sysDepart).getOrgCode()));
|
|
|
+ });
|
|
|
result.success("删除成功!");
|
|
|
}
|
|
|
return result;
|