SysDeptController.java 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. package com.kmall.admin.controller;
  2. import com.kmall.admin.entity.SysDeptEntity;
  3. import com.kmall.admin.service.SysDeptService;
  4. import com.kmall.admin.fromcomm.controller.AbstractController;
  5. import com.kmall.common.utils.Constant;
  6. import com.kmall.common.utils.R;
  7. import org.apache.shiro.authz.annotation.RequiresPermissions;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.web.bind.annotation.PathVariable;
  10. import org.springframework.web.bind.annotation.RequestBody;
  11. import org.springframework.web.bind.annotation.RequestMapping;
  12. import org.springframework.web.bind.annotation.RestController;
  13. import java.util.HashMap;
  14. import java.util.List;
  15. import java.util.Map;
  16. /**
  17. * 部门管理
  18. *
  19. * @author liepngjun
  20. * @email
  21. * @date 2017-09-17 23:58:47
  22. */
  23. @RestController
  24. @RequestMapping("/sys/dept")
  25. public class SysDeptController extends AbstractController {
  26. @Autowired
  27. private SysDeptService sysDeptService;
  28. /**
  29. * 列表
  30. */
  31. @RequestMapping("/list")
  32. @RequiresPermissions("sys:dept:list")
  33. public R list() {
  34. Map<String, Object> map = new HashMap<>();
  35. //如果不是超级管理员,则只能查询本部门及子部门数据
  36. if (getUserId() != Constant.SUPER_ADMIN) {
  37. map.put("deptFilter", sysDeptService.getSubDeptIdList(getDeptId()));
  38. }
  39. List<SysDeptEntity> deptList = sysDeptService.queryList(map);
  40. return R.ok().put("list", deptList);
  41. }
  42. /**
  43. * 选择部门(添加、修改菜单)
  44. */
  45. @RequestMapping("/select")
  46. @RequiresPermissions("sys:dept:select")
  47. public R select() {
  48. Map<String, Object> map = new HashMap<>();
  49. //如果不是超级管理员,则只能查询本部门及子部门数据
  50. if (getUserId() != Constant.SUPER_ADMIN) {
  51. map.put("deptFilter", sysDeptService.getSubDeptIdList(getDeptId()));
  52. }
  53. List<SysDeptEntity> deptList = sysDeptService.queryList(map);
  54. //添加一级部门
  55. if (getUserId() == Constant.SUPER_ADMIN) {
  56. SysDeptEntity root = new SysDeptEntity();
  57. root.setDeptId(0L);
  58. root.setName("一级部门");
  59. root.setParentId(-1L);
  60. root.setOpen(true);
  61. deptList.add(root);
  62. }
  63. return R.ok().put("deptList", deptList);
  64. }
  65. /**
  66. * 上级部门Id(管理员则为0)
  67. */
  68. @RequestMapping("/info")
  69. @RequiresPermissions("sys:dept:list")
  70. public R info() {
  71. long deptId = 0;
  72. if (getUserId() != Constant.SUPER_ADMIN) {
  73. SysDeptEntity dept = sysDeptService.queryObject(getDeptId());
  74. deptId = dept.getParentId();
  75. }
  76. return R.ok().put("deptId", deptId);
  77. }
  78. /**
  79. * 信息
  80. */
  81. @RequestMapping("/info/{deptId}")
  82. @RequiresPermissions("sys:dept:info")
  83. public R info(@PathVariable("deptId") Long deptId) {
  84. SysDeptEntity dept = sysDeptService.queryObject(deptId);
  85. return R.ok().put("dept", dept);
  86. }
  87. /**
  88. * 保存
  89. */
  90. @RequestMapping("/save")
  91. @RequiresPermissions("sys:dept:save")
  92. public R save(@RequestBody SysDeptEntity dept) {
  93. sysDeptService.save(dept);
  94. return R.ok();
  95. }
  96. /**
  97. * 修改
  98. */
  99. @RequestMapping("/update")
  100. @RequiresPermissions("sys:dept:update")
  101. public R update(@RequestBody SysDeptEntity dept) {
  102. sysDeptService.update(dept);
  103. return R.ok();
  104. }
  105. /**
  106. * 删除
  107. */
  108. @RequestMapping("/delete")
  109. @RequiresPermissions("sys:dept:delete")
  110. public R delete(long deptId) {
  111. //判断是否有子部门
  112. List<Long> deptList = sysDeptService.queryDetpIdList(deptId);
  113. if (deptList.size() > 0) {
  114. return R.error("请先删除子部门");
  115. }
  116. sysDeptService.delete(deptId);
  117. return R.ok();
  118. }
  119. }