DeptServiceImpl.java 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. package com.ruoyi.project.system.dept.service;
  2. import java.util.ArrayList;
  3. import java.util.HashMap;
  4. import java.util.List;
  5. import java.util.Map;
  6. import org.springframework.beans.factory.annotation.Autowired;
  7. import org.springframework.stereotype.Service;
  8. import com.ruoyi.common.constant.UserConstants;
  9. import com.ruoyi.common.utils.StringUtils;
  10. import com.ruoyi.common.utils.security.ShiroUtils;
  11. import com.ruoyi.project.system.dept.domain.Dept;
  12. import com.ruoyi.project.system.dept.mapper.DeptMapper;
  13. /**
  14. * 部门管理 服务实现
  15. *
  16. * @author ruoyi
  17. */
  18. @Service
  19. public class DeptServiceImpl implements IDeptService
  20. {
  21. @Autowired
  22. private DeptMapper deptMapper;
  23. /**
  24. * 查询部门管理数据
  25. *
  26. * @return 部门信息集合
  27. */
  28. @Override
  29. public List<Dept> selectDeptList(Dept dept)
  30. {
  31. return deptMapper.selectDeptList(dept);
  32. }
  33. /**
  34. * 查询部门所有数据
  35. *
  36. * @return 部门信息集合
  37. */
  38. @Override
  39. public List<Dept> selectDeptAll()
  40. {
  41. return deptMapper.selectDeptAll();
  42. }
  43. /**
  44. * 查询部门管理树
  45. *
  46. * @return 所有部门信息
  47. */
  48. @Override
  49. public List<Map<String, Object>> selectDeptTree()
  50. {
  51. List<Map<String, Object>> trees = new ArrayList<Map<String, Object>>();
  52. List<Dept> deptList = deptMapper.selectDeptAll();
  53. for (Dept dept : deptList)
  54. {
  55. if (UserConstants.DEPT_NORMAL.equals(dept.getStatus()))
  56. {
  57. Map<String, Object> deptMap = new HashMap<String, Object>();
  58. deptMap.put("id", dept.getDeptId());
  59. deptMap.put("pId", dept.getParentId());
  60. deptMap.put("name", dept.getDeptName());
  61. deptMap.put("title", dept.getDeptName());
  62. trees.add(deptMap);
  63. }
  64. }
  65. return trees;
  66. }
  67. /**
  68. * 查询部门人数
  69. *
  70. * @param parentId 部门ID
  71. * @return 结果
  72. */
  73. @Override
  74. public int selectDeptCount(Long parentId)
  75. {
  76. Dept dept = new Dept();
  77. dept.setParentId(parentId);
  78. return deptMapper.selectDeptCount(dept);
  79. }
  80. /**
  81. * 查询部门是否存在用户
  82. *
  83. * @param deptId 部门ID
  84. * @return 结果 true 存在 false 不存在
  85. */
  86. @Override
  87. public boolean checkDeptExistUser(Long deptId)
  88. {
  89. int result = deptMapper.checkDeptExistUser(deptId);
  90. return result > 0 ? true : false;
  91. }
  92. /**
  93. * 删除部门管理信息
  94. *
  95. * @param deptId 部门ID
  96. * @return 结果
  97. */
  98. @Override
  99. public int deleteDeptById(Long deptId)
  100. {
  101. return deptMapper.deleteDeptById(deptId);
  102. }
  103. /**
  104. * 新增保存部门信息
  105. *
  106. * @param dept 部门信息
  107. * @return 结果
  108. */
  109. @Override
  110. public int insertDept(Dept dept)
  111. {
  112. Dept info = deptMapper.selectDeptById(dept.getParentId());
  113. dept.setCreateBy(ShiroUtils.getLoginName());
  114. dept.setAncestors(info.getAncestors() + "," + dept.getParentId());
  115. return deptMapper.insertDept(dept);
  116. }
  117. /**
  118. * 修改保存部门信息
  119. *
  120. * @param dept 部门信息
  121. * @return 结果
  122. */
  123. @Override
  124. public int updateDept(Dept dept)
  125. {
  126. Dept info = deptMapper.selectDeptById(dept.getParentId());
  127. dept.setUpdateBy(ShiroUtils.getLoginName());
  128. dept.setAncestors(info.getAncestors() + "," + dept.getParentId());
  129. return deptMapper.updateDept(dept);
  130. }
  131. /**
  132. * 根据部门ID查询信息
  133. *
  134. * @param deptId 部门ID
  135. * @return 部门信息
  136. */
  137. @Override
  138. public Dept selectDeptById(Long deptId)
  139. {
  140. return deptMapper.selectDeptById(deptId);
  141. }
  142. /**
  143. * 校验部门名称是否唯一
  144. *
  145. * @param dept 部门信息
  146. * @return 结果
  147. */
  148. @Override
  149. public String checkDeptNameUnique(Dept dept)
  150. {
  151. Long deptId = StringUtils.isNull(dept.getDeptId()) ? -1L : dept.getDeptId();
  152. Dept info = deptMapper.checkDeptNameUnique(dept.getDeptName());
  153. if (StringUtils.isNotNull(info) && info.getDeptId().longValue() != deptId.longValue())
  154. {
  155. return UserConstants.DEPT_NAME_NOT_UNIQUE;
  156. }
  157. return UserConstants.DEPT_NAME_UNIQUE;
  158. }
  159. }