SysDeptController.java 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. package com.xunmei.system.controller;
  2. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  3. import com.xunmei.common.core.domain.R;
  4. import com.xunmei.common.core.utils.StringUtils;
  5. import com.xunmei.common.core.web.controller.BaseController;
  6. import com.xunmei.common.core.web.domain.AjaxResult;
  7. import com.xunmei.common.core.web.page.TableDataInfo;
  8. import com.xunmei.common.log.annotation.Log;
  9. import com.xunmei.common.log.enums.BusinessType;
  10. import com.xunmei.common.security.annotation.RequiresPermissions;
  11. import com.xunmei.common.security.utils.SecurityUtils;
  12. import com.xunmei.system.api.domain.SysDept;
  13. import com.xunmei.system.api.domain.SysOrg;
  14. import com.xunmei.system.api.domain.SysUser;
  15. import com.xunmei.system.service.ISysDeptService;
  16. import com.xunmei.system.service.ISysOrgService;
  17. import com.xunmei.system.service.ISysUserService;
  18. import org.apache.commons.lang3.ArrayUtils;
  19. import org.springframework.beans.factory.annotation.Autowired;
  20. import org.springframework.validation.annotation.Validated;
  21. import org.springframework.web.bind.annotation.*;
  22. import java.util.Date;
  23. import java.util.List;
  24. /**
  25. * 部门信息
  26. *
  27. * @author xunmei
  28. */
  29. @RestController
  30. @RequestMapping("/dept")
  31. public class SysDeptController extends BaseController {
  32. @Autowired
  33. private ISysDeptService deptService;
  34. @Autowired
  35. private ISysOrgService orgService;
  36. @Autowired
  37. private ISysUserService userService;
  38. /**
  39. * 获取部门列表
  40. */
  41. @RequiresPermissions("system:dept:list")
  42. @GetMapping("/list")
  43. public TableDataInfo list(SysOrg dept) {
  44. return orgService.selectPage(dept);
  45. }
  46. /**
  47. * 查询部门列表(排除节点)
  48. */
  49. @RequiresPermissions("system:dept:list")
  50. @GetMapping("/list/exclude/{deptId}")
  51. public AjaxResult excludeChild(@PathVariable(value = "deptId", required = false) Long deptId) {
  52. List<SysOrg> depts = orgService.list();
  53. depts.removeIf(d -> d.getId().intValue() == deptId || ArrayUtils.contains(StringUtils.split(d.getPath(), "-"), deptId + ""));
  54. return success(depts);
  55. }
  56. /**
  57. * 根据部门编号获取详细信息
  58. */
  59. @RequiresPermissions("system:dept:query")
  60. @GetMapping(value = "/{deptId}")
  61. public AjaxResult getInfo(@PathVariable Long deptId) {
  62. // deptService.checkDeptDataScope(deptId);
  63. return success(orgService.getById(deptId));
  64. }
  65. /**
  66. * 新增部门
  67. */
  68. @RequiresPermissions("system:dept:add")
  69. @Log(title = "部门管理", businessType = BusinessType.INSERT)
  70. @PostMapping
  71. public AjaxResult add(@Validated @RequestBody SysOrg dept) {
  72. if (orgService.list(new QueryWrapper<SysOrg>().eq("name", dept.getName())).size() > 0) {
  73. return error("新增部门'" + dept.getName() + "'失败,部门名称已存在");
  74. }
  75. dept.setCreateBy(SecurityUtils.getUsername());
  76. dept.setCreateTime(new Date());
  77. return toAjax(orgService.save(dept));
  78. }
  79. /**
  80. * 修改部门
  81. */
  82. @RequiresPermissions("system:dept:edit")
  83. @Log(title = "部门管理", businessType = BusinessType.UPDATE)
  84. @PutMapping
  85. public AjaxResult edit(@Validated @RequestBody SysOrg dept) {
  86. Long deptId = dept.getId();
  87. // deptService.checkDeptDataScope(deptId);
  88. if (orgService.list(new QueryWrapper<SysOrg>().eq("name", dept.getName()).eq("deleted", 0L)).size() > 1) {
  89. return error("修改部门'" + dept.getName() + "'失败,部门名称已存在");
  90. } else if (dept.getParentId().equals(deptId)) {
  91. return error("修改部门'" + dept.getName() + "'失败,上级部门不能是自己");
  92. }
  93. // else if (StringUtils.equals(UserConstants.DEPT_DISABLE, dept.getIsLock()) && deptService.selectNormalChildrenDeptById(deptId) > 0)
  94. // {
  95. // return error("该部门包含未停用的子部门!");
  96. // }
  97. dept.setUpdateBy(SecurityUtils.getUsername());
  98. dept.setUpdateTime(new Date());
  99. return toAjax(orgService.updateById(dept));
  100. }
  101. /**
  102. * 删除部门
  103. */
  104. @RequiresPermissions("system:dept:remove")
  105. @Log(title = "部门管理", businessType = BusinessType.DELETE)
  106. @DeleteMapping("/{deptId}")
  107. public AjaxResult remove(@PathVariable Long deptId) {
  108. if (orgService.list(new QueryWrapper<SysOrg>().eq("parent_id", deptId).eq("deleted", 0L)).size() > 0) {
  109. return warn("存在下级部门,不允许删除");
  110. }
  111. if (userService.list(new QueryWrapper<SysUser>().eq("org_id", deptId).eq("deleted", 0L)).size() > 0) {
  112. return warn("部门存在用户,不允许删除");
  113. }
  114. // deptService.checkDeptDataScope(deptId);
  115. return toAjax(orgService.removeById(deptId));
  116. }
  117. /**
  118. * 获取部门树列表(机构)
  119. */
  120. @GetMapping("/deptTree")
  121. public AjaxResult deptTree(SysOrg dept) {
  122. return success(deptService.selectDeptTreeList(dept));
  123. }
  124. /**
  125. * @param dept
  126. * @return 获取部门树(真部门)
  127. */
  128. @GetMapping("/sysDeptTree")
  129. public AjaxResult sysDeptTree(SysDept dept) {
  130. return success(deptService.selectDeptTreeList(dept));
  131. }
  132. @GetMapping("/selectCheckSubOrgIdList")
  133. public R<List<Long>> selectCheckSubOrgIdList(Long orgId) {
  134. return R.ok(orgService.selectCheckSubOrgIdList(orgId));
  135. }
  136. @GetMapping("/selectSysOrgById")
  137. public R<SysOrg> selectSysOrgById(Long id) {
  138. return R.ok(orgService.getById(id));
  139. }
  140. @GetMapping("/listByIds")
  141. public R<List<SysOrg>> listByIds(List<Long> ids) {
  142. return R.ok(orgService.listByIds(ids));
  143. }
  144. @GetMapping("/findListByOrgType")
  145. public R<List<Long>> findListByOrgType(Integer execOrgType) {
  146. return R.ok(orgService.findListByOrgType(execOrgType));
  147. }
  148. }