@ -1,28 +1,26 @@
@@ -1,28 +1,26 @@
package com.cloud.kicc.system.controller ;
import cn.hutool.core.util.StrUtil ;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper ;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper ;
import com.baomidou.mybatisplus.core.toolkit.Wrappers ;
import com.cloud.kicc.common.core.api.R ;
import com.cloud.kicc.common.core.constant.AppConstants ;
import com.cloud.kicc.common.log.annotation.SysLog ;
import com.cloud.kicc.system.api.entity.Dept ;
import com.cloud.kicc.system.api.entity.RoleDept ;
import com.cloud.kicc.system.api.entity.User ;
import com.cloud.kicc.system.api.vo.ResultVo ;
import com.cloud.kicc.system.service.DeptService ;
import com.cloud.kicc.system.service.RoleDeptService ;
import com.cloud.kicc.system.service.UserService ;
import com.cloud.kicc.common.core.api.R ;
import com.cloud.kicc.common.core.constant.AppConstants ;
import com.cloud.kicc.common.log.annotation.SysLog ;
import lombok.AllArgsConstructor ;
import org.springframework.data.redis.core.RedisTemplate ;
import org.springframework.security.access.prepost.PreAuthorize ;
import org.springframework.web.bind.annotation.* ;
import java.util.List ;
import java.util.stream.Collectors ;
/ * *
* < p >
* 机构 信息
* 部门 信息
* < / p >
*
* @Author : entfrm开发团队 - 王翔
@ -35,13 +33,11 @@ public class DeptController {
@@ -35,13 +33,11 @@ public class DeptController {
private final DeptService deptService ;
private final UserService userService ;
private final RoleDeptService roleDeptService ;
private final RedisTemplate redisTemplate ;
private QueryWrapper < Dept > getQueryWrapper ( Dept dept ) {
return new QueryWrapper < Dept > ( )
. like ( StrUtil . isNotBlank ( dept . getName ( ) ) , "name" , dept . getName ( ) )
. eq ( StrUtil . isNotBlank ( dept . getCode ( ) ) , "code" , dept . getCode ( ) ) ;
private LambdaQueryWrapper < Dept > getQueryWrapper ( Dept dept ) {
return Wrappers . < Dept > lambdaQuery ( )
. like ( StrUtil . isNotBlank ( dept . getName ( ) ) , Dept : : getName , dept . getName ( ) )
. eq ( StrUtil . isNotBlank ( dept . getStatus ( ) ) , Dept : : getStatus , dept . getStatus ( ) ) ;
}
@GetMapping ( "/list" )
@ -84,15 +80,13 @@ public class DeptController {
@@ -84,15 +80,13 @@ public class DeptController {
@DeleteMapping ( "/remove/{id:\\w+}" )
@PreAuthorize ( "@pms.hasPermission('dept_del')" )
public R remove ( @PathVariable ( "id" ) String id ) {
if ( deptService . getOne ( new QueryWrapper < Dept > ( ) . eq ( "parent_id" , id ) ) ! = null ) {
if ( deptService . getOne ( Wrappers . < Dept > lambdaQuery ( ) . eq ( Dept : : getParentId , id ) ) ! = null ) {
return R . error ( "存在下级机构,不允许删除" ) ;
}
if ( userService . getOne ( new QueryWrapper < User > ( ) . eq ( "dept_id" , id ) ) ! = null ) {
if ( userService . getOne ( Wrappers . < User > lambdaQuery ( ) . eq ( User : : getDeptId , id ) ) ! = null ) {
return R . error ( "机构存在用户,不允许删除" ) ;
}
deptService . removeById ( id ) ;
redisTemplate . delete ( "deptList" ) ;
redisTemplate . delete ( "regionList" ) ;
return R . ok ( ) ;
}
@ -104,24 +98,11 @@ public class DeptController {
@@ -104,24 +98,11 @@ public class DeptController {
return R . ok ( ) ;
}
/ * *
* 加载机构列表树
* /
/** 加载机构列表树 */
@GetMapping ( "/deptTree" )
public R deptTree ( ) {
List < Dept > deptList = deptService . list ( new QueryWrapper < Dept > ( ) . orderByAsc ( "sort" ) ) ;
return R . ok ( deptService . buildTree ( deptList , "0" ) ) ;
}
/ * *
* 加载角色机构 ( 数据权限 ) 列表树
* /
@GetMapping ( "/roleDeptTree/{roleId:\\w+}" )
public R roleDeptTree ( @PathVariable String roleId ) {
List < Dept > deptList = deptService . list ( new QueryWrapper < Dept > ( ) . orderByAsc ( "sort" ) ) ;
List < String > depts = roleDeptService . list ( new QueryWrapper < RoleDept > ( ) . eq ( "role_id" , roleId ) )
. stream ( ) . map ( roleMenu - > roleMenu . getDeptId ( ) ) . collect ( Collectors . toList ( ) ) ;
return R . ok ( new ResultVo ( ) . setResult ( deptService . buildTree ( deptList , "0" ) ) . setExtend ( depts ) ) ;
}
}