Просмотр исходного кода

部门管理和岗位管理 删除是添加校验 是否存在人员,存在不删除

xieyn 1 год назад
Родитель
Сommit
8042cf86f6

+ 23 - 9
jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/controller/SysDepartController.java

@@ -17,9 +17,11 @@ import org.jeecg.common.system.vo.LoginUser;
 import org.jeecg.common.util.oConvertUtils;
 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.model.DepartIdModel;
 import org.jeecg.modules.system.model.SysDepartTreeModel;
 import org.jeecg.modules.system.service.ISysDepartService;
+import org.jeecg.modules.system.service.ISysUserDepartService;
 import org.jeecg.modules.system.service.ISysUserService;
 import org.jeecg.modules.system.util.FindsDepartsChildrenUtil;
 import org.jeecgframework.poi.excel.ExcelImportUtil;
@@ -47,7 +49,7 @@ import lombok.extern.slf4j.Slf4j;
  * <p>
  * 部门表 前端控制器
  * <p>
- * 
+ *
  * @Author: Steve @Since: 2019-01-22
  */
 @RestController
@@ -61,6 +63,9 @@ public class SysDepartController {
 	@Autowired
 	private ISysUserService sysUserService;
 
+	@Autowired
+	private ISysUserDepartService sysUserDepartService;
+
 	/**
 	 * 查询数据 查出我的部门,并以树结构数据格式响应给前端
 	 *
@@ -108,7 +113,7 @@ public class SysDepartController {
 
 	/**
 	 * 查询数据 查出所有部门,并以树结构数据格式响应给前端
-	 * 
+	 *
 	 * @return
 	 */
 	@RequestMapping(value = "/queryTreeList", method = RequestMethod.GET)
@@ -151,7 +156,7 @@ public class SysDepartController {
 
 	/**
 	 * 添加新数据 添加用户新建的部门对象数据,并保存到数据库
-	 * 
+	 *
 	 * @param sysDepart
 	 * @return
 	 */
@@ -176,7 +181,7 @@ public class SysDepartController {
 
 	/**
 	 * 编辑数据 编辑部门的部分数据,并保存到数据库
-	 * 
+	 *
 	 * @param sysDepart
 	 * @return
 	 */
@@ -201,7 +206,7 @@ public class SysDepartController {
 		}
 		return result;
 	}
-	
+
 	 /**
      *   通过id删除
     * @param id
@@ -230,7 +235,7 @@ public class SysDepartController {
 
 	/**
 	 * 批量删除 根据前端请求的多个ID,对数据库执行删除相关部门数据的操作
-	 * 
+	 *
 	 * @param ids
 	 * @return
 	 */
@@ -242,6 +247,15 @@ public class SysDepartController {
 		if (ids == null || "".equals(ids.trim())) {
 			result.error500("参数不识别!");
 		} else {
+			String[] idss = ids.split(",");
+			for(String id: idss){
+				QueryWrapper<SysUser>  queryWrapper = new QueryWrapper();
+				queryWrapper.eq("depart_ids",id);
+				List<SysUser> list = sysUserService.list(queryWrapper);
+				if(list.size()>0){
+					return result.error500("选择的部门下存在人员,无法删除");
+				}
+			}
 			this.sysDepartService.deleteBatchWithChildren(Arrays.asList(ids.split(",")));
 			result.success("删除成功!");
 		}
@@ -250,7 +264,7 @@ public class SysDepartController {
 
 	/**
 	 * 查询数据 添加或编辑页面对该方法发起请求,以树结构形式加载所有部门的名称,方便用户的操作
-	 * 
+	 *
 	 * @return
 	 */
 	@RequestMapping(value = "/queryIdTree", method = RequestMethod.GET)
@@ -284,12 +298,12 @@ public class SysDepartController {
 		}
 		return result;
 	}
-	 
+
 	/**
 	 * <p>
 	 * 部门搜索功能方法,根据关键字模糊搜索相关部门
 	 * </p>
-	 * 
+	 *
 	 * @param keyWord
 	 * @return
 	 */

+ 30 - 1
jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/controller/SysPositionController.java

@@ -16,6 +16,7 @@ import org.jeecg.modules.oa.entity.CdLinks;
 import org.jeecg.modules.system.entity.SysPosition;
 import org.jeecg.modules.system.entity.SysUser;
 import org.jeecg.modules.system.service.ISysPositionService;
+import org.jeecg.modules.system.service.ISysUserService;
 import org.jeecgframework.poi.excel.ExcelImportUtil;
 import org.jeecgframework.poi.excel.def.NormalExcelConstants;
 import org.jeecgframework.poi.excel.entity.ExportParams;
@@ -51,6 +52,9 @@ public class SysPositionController {
     @Autowired
     private ISysPositionService sysPositionService;
 
+    @Autowired
+    private ISysUserService sysUserService;
+
     /**
      * 分页列表查询
      *
@@ -140,6 +144,10 @@ public class SysPositionController {
     @ApiOperation(value = "职务表-通过id删除", notes = "职务表-通过id删除")
     @DeleteMapping(value = "/delete")
     public Result<?> delete(@RequestParam(name = "id", required = true) String id) {
+        List<SysUser> list = getSysUsers(id);
+        if(list.size()>0){
+            return Result.error("删除失败!,改岗位存在用户,无法删除");
+        }
         try {
             sysPositionService.removeById(id);
         } catch (Exception e) {
@@ -148,6 +156,20 @@ public class SysPositionController {
         }
         return Result.ok("删除成功!");
     }
+    /**
+     * 查询删除的岗位的用户
+     *
+     * @param id
+     * @return
+     */
+    private List<SysUser> getSysUsers(String id) {
+        SysPosition sysPosition = sysPositionService.getById(id);
+        String code = sysPosition.getCode();
+        QueryWrapper<SysUser> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("post",code);
+        List<SysUser> list = sysUserService.list(queryWrapper);
+        return list;
+    }
 
     /**
      * 批量删除
@@ -163,7 +185,14 @@ public class SysPositionController {
         if (ids == null || "".equals(ids.trim())) {
             result.error500("参数不识别!");
         } else {
-            this.sysPositionService.removeByIds(Arrays.asList(ids.split(",")));
+            String[] idss = ids.split(",");
+            for (String id : idss){
+                List<SysUser> list = getSysUsers(id);
+                if(list.size()>0){
+                    return result.error500("删除失败!,选择的岗位中存在用户,无法删除");
+                }
+            }
+            this.sysPositionService.removeByIds(Arrays.asList(idss));
             result.success("删除成功!");
         }
         return result;