SysDeptController.java 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /**
  2. * Copyright (c) 2016-2019 人人开源 All rights reserved.
  3. * <p>
  4. * https://www.renren.io
  5. * <p>
  6. * 版权所有,侵权必究!
  7. */
  8. package io.renren.modules.sys.controller;
  9. import io.renren.common.utils.Constant;
  10. import io.renren.common.utils.R;
  11. import io.renren.modules.sys.entity.SysDeptEntity;
  12. import io.renren.modules.sys.service.SysDeptService;
  13. import org.apache.shiro.authz.annotation.RequiresPermissions;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.web.bind.annotation.PathVariable;
  16. import org.springframework.web.bind.annotation.RequestBody;
  17. import org.springframework.web.bind.annotation.RequestMapping;
  18. import org.springframework.web.bind.annotation.RestController;
  19. import java.util.HashMap;
  20. import java.util.List;
  21. /**
  22. * 部门管理
  23. *
  24. * @author Mark 735032128@qq.com
  25. */
  26. @RestController
  27. @RequestMapping("/sys/dept")
  28. public class SysDeptController extends AbstractController {
  29. @Autowired
  30. private SysDeptService sysDeptService;
  31. /**
  32. * 列表
  33. */
  34. @RequestMapping("/list")
  35. @RequiresPermissions("sys:dept:list")
  36. public List<SysDeptEntity> list() {
  37. List<SysDeptEntity> deptList = sysDeptService.queryList(new HashMap<String, Object>());
  38. return deptList;
  39. }
  40. /**
  41. * 选择部门(添加、修改菜单)
  42. */
  43. @RequestMapping("/select")
  44. @RequiresPermissions("sys:dept:select")
  45. public R select() {
  46. List<SysDeptEntity> deptList = sysDeptService.queryList(new HashMap<String, Object>());
  47. //添加一级部门
  48. if (getUserId() == Constant.SUPER_ADMIN) {
  49. SysDeptEntity root = new SysDeptEntity();
  50. root.setDeptId(0L);
  51. root.setName("一级部门");
  52. root.setParentId(-1L);
  53. root.setOpen(true);
  54. deptList.add(root);
  55. }
  56. return R.ok().put("deptList", deptList);
  57. }
  58. /**
  59. * 上级部门Id(管理员则为0)
  60. */
  61. @RequestMapping("/info")
  62. @RequiresPermissions("sys:dept:list")
  63. public R info() {
  64. long deptId = 0;
  65. if (getUserId() != Constant.SUPER_ADMIN) {
  66. List<SysDeptEntity> deptList = sysDeptService.queryList(new HashMap<String, Object>());
  67. Long parentId = null;
  68. for (SysDeptEntity sysDeptEntity : deptList) {
  69. if (parentId == null) {
  70. parentId = sysDeptEntity.getParentId();
  71. continue;
  72. }
  73. if (parentId > sysDeptEntity.getParentId().longValue()) {
  74. parentId = sysDeptEntity.getParentId();
  75. }
  76. }
  77. deptId = parentId;
  78. }
  79. return R.ok().put("deptId", deptId);
  80. }
  81. /**
  82. * 信息
  83. */
  84. @RequestMapping("/info/{deptId}")
  85. @RequiresPermissions("sys:dept:info")
  86. public R info(@PathVariable("deptId") Long deptId) {
  87. SysDeptEntity dept = sysDeptService.getById(deptId);
  88. return R.ok().put("dept", dept);
  89. }
  90. /**
  91. * 保存
  92. */
  93. @RequestMapping("/save")
  94. @RequiresPermissions("sys:dept:save")
  95. public R save(@RequestBody SysDeptEntity dept) {
  96. sysDeptService.save(dept);
  97. return R.ok();
  98. }
  99. /**
  100. * 修改
  101. */
  102. @RequestMapping("/update")
  103. @RequiresPermissions("sys:dept:update")
  104. public R update(@RequestBody SysDeptEntity dept) {
  105. sysDeptService.updateById(dept);
  106. return R.ok();
  107. }
  108. /**
  109. * 删除
  110. */
  111. @RequestMapping("/delete/{deptId}")
  112. @RequiresPermissions("sys:dept:delete")
  113. public R delete(@PathVariable("deptId") long deptId) {
  114. //判断是否有子部门
  115. List<Long> deptList = sysDeptService.queryDetpIdList(deptId);
  116. if (deptList.size() > 0) {
  117. return R.error("请先删除子部门");
  118. }
  119. sysDeptService.removeById(deptId);
  120. return R.ok();
  121. }
  122. }