DeptServiceImpl.java 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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.Repository;
  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. @Repository("deptService")
  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 saveDept(Dept dept)
  111. {
  112. if (StringUtils.isNotNull(dept.getDeptId()))
  113. {
  114. dept.setUpdateBy(ShiroUtils.getLoginName());
  115. return deptMapper.updateDept(dept);
  116. }
  117. else
  118. {
  119. dept.setCreateBy(ShiroUtils.getLoginName());
  120. return deptMapper.insertDept(dept);
  121. }
  122. }
  123. /**
  124. * 根据部门ID查询信息
  125. *
  126. * @param deptId 部门ID
  127. * @return 部门信息
  128. */
  129. @Override
  130. public Dept selectDeptById(Long deptId)
  131. {
  132. return deptMapper.selectDeptById(deptId);
  133. }
  134. /**
  135. * 校验部门名称是否唯一
  136. *
  137. * @param dept 部门信息
  138. * @return 结果
  139. */
  140. @Override
  141. public String checkDeptNameUnique(Dept dept)
  142. {
  143. if (dept.getDeptId() == null)
  144. {
  145. dept.setDeptId(-1L);
  146. }
  147. Long deptId = dept.getDeptId();
  148. Dept info = deptMapper.checkDeptNameUnique(dept.getDeptName());
  149. if (StringUtils.isNotNull(info) && StringUtils.isNotNull(info.getDeptId())
  150. && info.getDeptId().longValue() != deptId.longValue())
  151. {
  152. return UserConstants.DEPT_NAME_NOT_UNIQUE;
  153. }
  154. return UserConstants.DEPT_NAME_UNIQUE;
  155. }
  156. }