Bläddra i källkod

删除添加判断条件

leihy 2 år sedan
förälder
incheckning
48db90787f

+ 10 - 0
src/main/groovy/com/jd/brume/controller/CorpController.groovy

@@ -1,5 +1,8 @@
 package com.jd.brume.controller
 
+import com.jd.brume.entity.func.UserFunc
+import com.jd.brume.service.UserService
+
 import javax.annotation.Resource
 import javax.validation.constraints.NotNull
 
@@ -35,6 +38,9 @@ class CorpController {
 	
 	@Resource
 	DictService dictService
+
+	@Resource
+	UserService userService
 	
 	/**
 	 * 分页查询
@@ -73,6 +79,10 @@ class CorpController {
 	 */
 	@DeleteMapping('delete')
 	def deleteCorp(@NotNull Integer deptId) {
+		def count = userService.count(Wrappers.lambdaQuery().eq(UserFunc.deptId(),deptId))
+		if (count > 0){
+			return new Result().msg(100, '单位已被用户使用')
+		}
 		return new Result().ok(corpService.removeById(deptId))
 	}
 	

+ 17 - 1
src/main/groovy/com/jd/brume/controller/MenuButtonController.groovy

@@ -1,5 +1,8 @@
 package com.jd.brume.controller
 
+import com.jd.brume.service.MenuService
+import com.jd.brume.service.RoleMenuService
+
 import javax.annotation.Resource
 import javax.validation.constraints.NotNull
 
@@ -18,7 +21,6 @@ import com.jd.brume.entity.func.MenuButtonFunc
 import com.jd.brume.entity.resultmap.MenuButtonSelect
 import com.jd.brume.service.DictService
 import com.jd.brume.service.MenuButtonService
-import com.jd.brume.util.Constant
 import com.jd.brume.util.Result
 import com.jd.brume.util.ResultEnum
 import com.jd.brume.vo.MenuButtonVo
@@ -41,6 +43,12 @@ class MenuButtonController {
 	
 	@Resource
 	DictService dictService
+
+	@Resource
+	MenuService menuService
+
+	@Resource
+	RoleMenuService roleMenuService
 	
 	/**
 	 * 分页查询
@@ -92,6 +100,14 @@ class MenuButtonController {
 	 */
 	@DeleteMapping('delete')
 	def deleteMenuButton(@NotNull Integer btnId) {
+		def count = roleMenuService.count(Wrappers.lambdaQuery().apply(" FIND_IN_SET({0}, button_ids)", btnId))
+		if (count > 0){
+			return new Result().msg(100, '按钮已被角色使用')
+		}
+		count = menuService.count(Wrappers.lambdaQuery().apply(" FIND_IN_SET({0}, btn_ids)", btnId))
+		if (count > 0){
+			return new Result().msg(100, '按钮已被菜单使用')
+		}
 		return new Result().ok(menuButtonService.removeById(btnId))
 	}
 	

+ 9 - 0
src/main/groovy/com/jd/brume/controller/MenuController.groovy

@@ -2,6 +2,8 @@ package com.jd.brume.controller
 
 import com.jd.brume.entity.UserEntity
 import com.jd.brume.entity.func.CorpFunc
+import com.jd.brume.entity.func.RoleMenuFunc
+import com.jd.brume.service.RoleMenuService
 import com.jd.brume.service.UserService
 import com.jd.brume.util.TokenUtil
 
@@ -58,6 +60,9 @@ class MenuController {
 	@Resource
 	UserService userService
 
+	@Resource
+	RoleMenuService roleMenuService
+
 	/**
 	 * 分页查询
 	 * @param menuVo
@@ -152,6 +157,10 @@ class MenuController {
 	 */
 	@DeleteMapping('delete')
 	def deleteMenu(@NotNull Integer menuId) {
+		def count = roleMenuService.count(Wrappers.lambdaQuery().eq(RoleMenuFunc.menuId(), menuId))
+		if (count > 0){
+			return new Result().msg(100, '菜单已被角色使用')
+		}
 		return new Result().ok(menuService.removeById(menuId))
 	}
 

+ 10 - 0
src/main/groovy/com/jd/brume/controller/RoleController.groovy

@@ -1,5 +1,8 @@
 package com.jd.brume.controller
 
+import com.jd.brume.entity.func.UserFunc
+import com.jd.brume.service.UserService
+
 import javax.annotation.Resource
 import javax.validation.constraints.NotNull
 
@@ -42,6 +45,9 @@ class RoleController {
 	
 	@Resource
 	RoleMenuService roleMenuService
+
+	@Resource
+	UserService userService
 	
 	/**
 	 * 分页查询
@@ -66,6 +72,10 @@ class RoleController {
 	 */
 	@DeleteMapping('delete')
 	def deleteRole(@NotNull Integer roleId) {
+		def count = userService.count(Wrappers.lambdaQuery().eq(UserFunc.roleId(), roleId))
+		if (count > 0){
+			return new Result().msg(100, '角色已被用户使用')
+		}
 		return new Result().ok(roleService.removeById(roleId))
 	}
 	

+ 4 - 0
src/main/groovy/com/jd/brume/entity/func/RoleMenuFunc.java

@@ -16,6 +16,10 @@ public class RoleMenuFunc {
 		SFunction<RoleMenuEntity, Integer> f = RoleMenuEntity::getRoleId;
 		return f;
 	}
+	public static SFunction<RoleMenuEntity, Integer> menuId() {
+		SFunction<RoleMenuEntity, Integer> f = RoleMenuEntity::getMenuId;
+		return f;
+	}
 
 	public static SFunction<RoleMenuEntity, String> buttonIds() {
 		SFunction<RoleMenuEntity, String> f = RoleMenuEntity::getButtonIds;

+ 1 - 1
src/main/resources/static/web/js/button.js

@@ -93,7 +93,7 @@ const initClick = () => {
 			}, (index) => {
 				layui.api.delete(obj.data.btnId, 
 					(json) => {
-						layui.customUtil.refush(json.result, '删除成功', '删除失败')
+						layui.customUtil.refush(json.result, '删除成功', json.msg)
 					}
 				)
 			})

+ 2 - 2
src/main/resources/static/web/js/corp.js

@@ -113,9 +113,9 @@ const initClick = () => {
 			layui.layer.confirm('确认要删除吗?', {
 				btn: ['删除', '取消']
 			}, (index) => {
-				layui.api.delete(obj.data.btnId, 
+				layui.api.delete(obj.data.deptId,
 					(json) => {
-						layui.customUtil.refush(json.result, '删除成功', '删除失败', {
+						layui.customUtil.refush(json.result, '删除成功', json.msg, {
 							queryVal: $('input[name="search"]').val(),
 							type: $('#searchCorpType').val()
 						})

+ 1 - 1
src/main/resources/static/web/js/menu.js

@@ -58,7 +58,7 @@ const initTable = (dicts) => {
 			}, (index) => {
 				layui.api.delete(obj.data.menuId, 
 					(json) => {
-						layui.customUtil.refush(json.result, '删除成功', '删除失败', {
+						layui.customUtil.refush(json.result, '删除成功', json.msg, {
 							queryVal: $('input[name="search"]').val(),
 							parentId: $('#searchParentId').val()
 						})

+ 1 - 1
src/main/resources/static/web/js/role.js

@@ -48,7 +48,7 @@ const initTable = (dicts) => {
 			}, (index) => {
 				layui.api.delete(obj.data.roleId, 
 					(json) => {
-						layui.customUtil.refush(json.result, '删除成功', '删除失败')
+						layui.customUtil.refush(json.result, '删除成功', json.msg)
 					}
 				)
 			})