|
|
@ -1,28 +1,26 @@ |
|
|
|
package com.cloud.kicc.system.controller; |
|
|
|
package com.cloud.kicc.system.controller; |
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
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.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.Dept; |
|
|
|
import com.cloud.kicc.system.api.entity.RoleDept; |
|
|
|
|
|
|
|
import com.cloud.kicc.system.api.entity.User; |
|
|
|
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.DeptService; |
|
|
|
import com.cloud.kicc.system.service.RoleDeptService; |
|
|
|
|
|
|
|
import com.cloud.kicc.system.service.UserService; |
|
|
|
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 lombok.AllArgsConstructor; |
|
|
|
import org.springframework.data.redis.core.RedisTemplate; |
|
|
|
import org.springframework.data.redis.core.RedisTemplate; |
|
|
|
import org.springframework.security.access.prepost.PreAuthorize; |
|
|
|
import org.springframework.security.access.prepost.PreAuthorize; |
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
*<p> |
|
|
|
*<p> |
|
|
|
* 机构信息 |
|
|
|
* 部门信息 |
|
|
|
*</p> |
|
|
|
*</p> |
|
|
|
* |
|
|
|
* |
|
|
|
* @Author: entfrm开发团队-王翔 |
|
|
|
* @Author: entfrm开发团队-王翔 |
|
|
@ -35,13 +33,11 @@ public class DeptController { |
|
|
|
|
|
|
|
|
|
|
|
private final DeptService deptService; |
|
|
|
private final DeptService deptService; |
|
|
|
private final UserService userService; |
|
|
|
private final UserService userService; |
|
|
|
private final RoleDeptService roleDeptService; |
|
|
|
|
|
|
|
private final RedisTemplate redisTemplate; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private QueryWrapper<Dept> getQueryWrapper(Dept dept) { |
|
|
|
private LambdaQueryWrapper<Dept> getQueryWrapper(Dept dept) { |
|
|
|
return new QueryWrapper<Dept>() |
|
|
|
return Wrappers.<Dept>lambdaQuery() |
|
|
|
.like(StrUtil.isNotBlank(dept.getName()), "name", dept.getName()) |
|
|
|
.like(StrUtil.isNotBlank(dept.getName()), Dept::getName, dept.getName()) |
|
|
|
.eq(StrUtil.isNotBlank(dept.getCode()), "code", dept.getCode()); |
|
|
|
.eq(StrUtil.isNotBlank(dept.getStatus()), Dept::getStatus, dept.getStatus()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@GetMapping("/list") |
|
|
|
@GetMapping("/list") |
|
|
@ -84,15 +80,13 @@ public class DeptController { |
|
|
|
@DeleteMapping("/remove/{id:\\w+}") |
|
|
|
@DeleteMapping("/remove/{id:\\w+}") |
|
|
|
@PreAuthorize("@pms.hasPermission('dept_del')") |
|
|
|
@PreAuthorize("@pms.hasPermission('dept_del')") |
|
|
|
public R remove(@PathVariable("id") String id) { |
|
|
|
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("存在下级机构,不允许删除"); |
|
|
|
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("机构存在用户,不允许删除"); |
|
|
|
return R.error("机构存在用户,不允许删除"); |
|
|
|
} |
|
|
|
} |
|
|
|
deptService.removeById(id); |
|
|
|
deptService.removeById(id); |
|
|
|
redisTemplate.delete("deptList"); |
|
|
|
|
|
|
|
redisTemplate.delete("regionList"); |
|
|
|
|
|
|
|
return R.ok(); |
|
|
|
return R.ok(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -104,24 +98,11 @@ public class DeptController { |
|
|
|
return R.ok(); |
|
|
|
return R.ok(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** 加载机构列表树 */ |
|
|
|
* 加载机构列表树 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
@GetMapping("/deptTree") |
|
|
|
@GetMapping("/deptTree") |
|
|
|
public R deptTree() { |
|
|
|
public R deptTree() { |
|
|
|
List<Dept> deptList = deptService.list(new QueryWrapper<Dept>().orderByAsc("sort")); |
|
|
|
List<Dept> deptList = deptService.list(new QueryWrapper<Dept>().orderByAsc("sort")); |
|
|
|
return R.ok(deptService.buildTree(deptList, "0")); |
|
|
|
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)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|