DeptController.java 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. package com.ruoyi.project.system.dept.controller;
  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.framework.aspectj.lang.annotation.Log;
  15. import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
  16. import com.ruoyi.framework.web.controller.BaseController;
  17. import com.ruoyi.framework.web.domain.AjaxResult;
  18. import com.ruoyi.project.system.dept.domain.Dept;
  19. import com.ruoyi.project.system.dept.service.IDeptService;
  20. /**
  21. * 部门信息
  22. *
  23. * @author ruoyi
  24. */
  25. @Controller
  26. @RequestMapping("/system/dept")
  27. public class DeptController extends BaseController
  28. {
  29. private String prefix = "system/dept";
  30. @Autowired
  31. private IDeptService deptService;
  32. @RequiresPermissions("system:dept:view")
  33. @GetMapping()
  34. public String dept()
  35. {
  36. return prefix + "/dept";
  37. }
  38. @RequiresPermissions("system:dept:list")
  39. @GetMapping("/list")
  40. @ResponseBody
  41. public List<Dept> list(Dept dept)
  42. {
  43. List<Dept> deptList = deptService.selectDeptList(dept);
  44. return deptList;
  45. }
  46. /**
  47. * 新增部门
  48. */
  49. @GetMapping("/add/{parentId}")
  50. public String add(@PathVariable("parentId") Long parentId, ModelMap mmap)
  51. {
  52. mmap.put("dept", deptService.selectDeptById(parentId));
  53. return prefix + "/add";
  54. }
  55. /**
  56. * 新增保存部门
  57. */
  58. @Log(title = "部门管理", businessType = BusinessType.INSERT)
  59. @RequiresPermissions("system:dept:add")
  60. @PostMapping("/add")
  61. @ResponseBody
  62. public AjaxResult addSave(Dept dept)
  63. {
  64. return toAjax(deptService.insertDept(dept));
  65. }
  66. /**
  67. * 修改
  68. */
  69. @GetMapping("/edit/{deptId}")
  70. public String edit(@PathVariable("deptId") Long deptId, ModelMap mmap)
  71. {
  72. mmap.put("dept", deptService.selectDeptById(deptId));
  73. return prefix + "/edit";
  74. }
  75. /**
  76. * 保存
  77. */
  78. @Log(title = "部门管理", businessType = BusinessType.UPDATE)
  79. @RequiresPermissions("system:dept:edit")
  80. @PostMapping("/edit")
  81. @ResponseBody
  82. public AjaxResult editSave(Dept dept)
  83. {
  84. return toAjax(deptService.updateDept(dept));
  85. }
  86. /**
  87. * 删除
  88. */
  89. @Log(title = "部门管理", businessType = BusinessType.DELETE)
  90. @RequiresPermissions("system:dept:remove")
  91. @PostMapping("/remove/{deptId}")
  92. @ResponseBody
  93. public AjaxResult remove(@PathVariable("deptId") Long deptId)
  94. {
  95. if (deptService.selectDeptCount(deptId) > 0)
  96. {
  97. return error(1, "存在下级部门,不允许删除");
  98. }
  99. if (deptService.checkDeptExistUser(deptId))
  100. {
  101. return error(1, "部门存在用户,不允许删除");
  102. }
  103. return toAjax(deptService.deleteDeptById(deptId));
  104. }
  105. /**
  106. * 校验部门名称
  107. */
  108. @PostMapping("/checkDeptNameUnique")
  109. @ResponseBody
  110. public String checkDeptNameUnique(Dept dept)
  111. {
  112. String uniqueFlag = "0";
  113. if (StringUtils.isNotNull(dept))
  114. {
  115. uniqueFlag = deptService.checkDeptNameUnique(dept);
  116. }
  117. return uniqueFlag;
  118. }
  119. /**
  120. * 选择部门树
  121. */
  122. @GetMapping("/selectDeptTree/{deptId}")
  123. public String selectDeptTree(@PathVariable("deptId") Long deptId, ModelMap mmap)
  124. {
  125. mmap.put("dept", deptService.selectDeptById(deptId));
  126. return prefix + "/tree";
  127. }
  128. /**
  129. * 加载部门列表树
  130. */
  131. @GetMapping("/treeData")
  132. @ResponseBody
  133. public List<Map<String, Object>> treeData()
  134. {
  135. List<Map<String, Object>> tree = deptService.selectDeptTree();
  136. return tree;
  137. }
  138. }