DeptController.java 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. package com.ruoyi.web.controller.system;
  2. import java.util.List;
  3. import java.util.Map;
  4. import org.apache.shiro.authz.annotation.RequiresPermissions;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.stereotype.Controller;
  7. import org.springframework.ui.ModelMap;
  8. import org.springframework.web.bind.annotation.GetMapping;
  9. import org.springframework.web.bind.annotation.PathVariable;
  10. import org.springframework.web.bind.annotation.PostMapping;
  11. import org.springframework.web.bind.annotation.RequestMapping;
  12. import org.springframework.web.bind.annotation.ResponseBody;
  13. import com.ruoyi.common.utils.StringUtils;
  14. import com.ruoyi.common.annotation.Log;
  15. import com.ruoyi.common.base.AjaxResult;
  16. import com.ruoyi.common.enums.BusinessType;
  17. import com.ruoyi.framework.util.ShiroUtils;
  18. import com.ruoyi.system.domain.SysDept;
  19. import com.ruoyi.system.domain.SysRole;
  20. import com.ruoyi.system.service.ISysDeptService;
  21. import com.ruoyi.web.core.base.BaseController;
  22. /**
  23. * 部门信息
  24. *
  25. * @author ruoyi
  26. */
  27. @Controller
  28. @RequestMapping("/system/dept")
  29. public class DeptController extends BaseController
  30. {
  31. private String prefix = "system/dept";
  32. @Autowired
  33. private ISysDeptService deptService;
  34. @RequiresPermissions("system:dept:view")
  35. @GetMapping()
  36. public String dept()
  37. {
  38. return prefix + "/dept";
  39. }
  40. @RequiresPermissions("system:dept:list")
  41. @GetMapping("/list")
  42. @ResponseBody
  43. public List<SysDept> list(SysDept dept)
  44. {
  45. List<SysDept> deptList = deptService.selectDeptList(dept);
  46. return deptList;
  47. }
  48. /**
  49. * 新增部门
  50. */
  51. @GetMapping("/add/{parentId}")
  52. public String add(@PathVariable("parentId") Long parentId, ModelMap mmap)
  53. {
  54. mmap.put("dept", deptService.selectDeptById(parentId));
  55. return prefix + "/add";
  56. }
  57. /**
  58. * 新增保存部门
  59. */
  60. @Log(title = "部门管理", businessType = BusinessType.INSERT)
  61. @RequiresPermissions("system:dept:add")
  62. @PostMapping("/add")
  63. @ResponseBody
  64. public AjaxResult addSave(SysDept dept)
  65. {
  66. dept.setCreateBy(ShiroUtils.getLoginName());
  67. return toAjax(deptService.insertDept(dept));
  68. }
  69. /**
  70. * 修改
  71. */
  72. @GetMapping("/edit/{deptId}")
  73. public String edit(@PathVariable("deptId") Long deptId, ModelMap mmap)
  74. {
  75. SysDept dept = deptService.selectDeptById(deptId);
  76. if (StringUtils.isNotNull(dept) && 100L == deptId)
  77. {
  78. dept.setParentName("无");
  79. }
  80. mmap.put("dept", dept);
  81. return prefix + "/edit";
  82. }
  83. /**
  84. * 保存
  85. */
  86. @Log(title = "部门管理", businessType = BusinessType.UPDATE)
  87. @RequiresPermissions("system:dept:edit")
  88. @PostMapping("/edit")
  89. @ResponseBody
  90. public AjaxResult editSave(SysDept dept)
  91. {
  92. dept.setUpdateBy(ShiroUtils.getLoginName());
  93. return toAjax(deptService.updateDept(dept));
  94. }
  95. /**
  96. * 删除
  97. */
  98. @Log(title = "部门管理", businessType = BusinessType.DELETE)
  99. @RequiresPermissions("system:dept:remove")
  100. @PostMapping("/remove/{deptId}")
  101. @ResponseBody
  102. public AjaxResult remove(@PathVariable("deptId") Long deptId)
  103. {
  104. if (deptService.selectDeptCount(deptId) > 0)
  105. {
  106. return error(1, "存在下级部门,不允许删除");
  107. }
  108. if (deptService.checkDeptExistUser(deptId))
  109. {
  110. return error(1, "部门存在用户,不允许删除");
  111. }
  112. return toAjax(deptService.deleteDeptById(deptId));
  113. }
  114. /**
  115. * 校验部门名称
  116. */
  117. @PostMapping("/checkDeptNameUnique")
  118. @ResponseBody
  119. public String checkDeptNameUnique(SysDept dept)
  120. {
  121. return deptService.checkDeptNameUnique(dept);
  122. }
  123. /**
  124. * 选择部门树
  125. */
  126. @GetMapping("/selectDeptTree/{deptId}")
  127. public String selectDeptTree(@PathVariable("deptId") Long deptId, ModelMap mmap)
  128. {
  129. mmap.put("dept", deptService.selectDeptById(deptId));
  130. return prefix + "/tree";
  131. }
  132. /**
  133. * 加载部门列表树
  134. */
  135. @GetMapping("/treeData")
  136. @ResponseBody
  137. public List<Map<String, Object>> treeData()
  138. {
  139. List<Map<String, Object>> tree = deptService.selectDeptTree();
  140. return tree;
  141. }
  142. /**
  143. * 加载角色部门(数据权限)列表树
  144. */
  145. @GetMapping("/roleDeptTreeData")
  146. @ResponseBody
  147. public List<Map<String, Object>> deptTreeData(SysRole role)
  148. {
  149. List<Map<String, Object>> tree = deptService.roleDeptTreeData(role);
  150. return tree;
  151. }
  152. }