SysPostServiceImpl.java 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. package com.ruoyi.system.service.impl;
  2. import java.util.List;
  3. import org.springframework.beans.factory.annotation.Autowired;
  4. import org.springframework.stereotype.Service;
  5. import com.ruoyi.common.constant.UserConstants;
  6. import com.ruoyi.common.exception.ServiceException;
  7. import com.ruoyi.common.utils.StringUtils;
  8. import com.ruoyi.system.domain.SysPost;
  9. import com.ruoyi.system.mapper.SysPostMapper;
  10. import com.ruoyi.system.mapper.SysUserPostMapper;
  11. import com.ruoyi.system.service.ISysPostService;
  12. /**
  13. * 岗位信息 服务层处理
  14. *
  15. * @author ruoyi
  16. */
  17. @Service
  18. public class SysPostServiceImpl implements ISysPostService
  19. {
  20. @Autowired
  21. private SysPostMapper postMapper;
  22. @Autowired
  23. private SysUserPostMapper userPostMapper;
  24. /**
  25. * 查询岗位信息集合
  26. *
  27. * @param post 岗位信息
  28. * @return 岗位信息集合
  29. */
  30. @Override
  31. public List<SysPost> selectPostList(SysPost post)
  32. {
  33. return postMapper.selectPostList(post);
  34. }
  35. /**
  36. * 查询所有岗位
  37. *
  38. * @return 岗位列表
  39. */
  40. @Override
  41. public List<SysPost> selectPostAll()
  42. {
  43. return postMapper.selectPostAll();
  44. }
  45. /**
  46. * 通过岗位ID查询岗位信息
  47. *
  48. * @param postId 岗位ID
  49. * @return 角色对象信息
  50. */
  51. @Override
  52. public SysPost selectPostById(Long postId)
  53. {
  54. return postMapper.selectPostById(postId);
  55. }
  56. /**
  57. * 根据用户ID获取岗位选择框列表
  58. *
  59. * @param userId 用户ID
  60. * @return 选中岗位ID列表
  61. */
  62. @Override
  63. public List<Long> selectPostListByUserId(Long userId)
  64. {
  65. return postMapper.selectPostListByUserId(userId);
  66. }
  67. /**
  68. * 校验岗位名称是否唯一
  69. *
  70. * @param post 岗位信息
  71. * @return 结果
  72. */
  73. @Override
  74. public String checkPostNameUnique(SysPost post)
  75. {
  76. Long postId = StringUtils.isNull(post.getPostId()) ? -1L : post.getPostId();
  77. SysPost info = postMapper.checkPostNameUnique(post.getPostName());
  78. if (StringUtils.isNotNull(info) && info.getPostId().longValue() != postId.longValue())
  79. {
  80. return UserConstants.NOT_UNIQUE;
  81. }
  82. return UserConstants.UNIQUE;
  83. }
  84. /**
  85. * 校验岗位编码是否唯一
  86. *
  87. * @param post 岗位信息
  88. * @return 结果
  89. */
  90. @Override
  91. public String checkPostCodeUnique(SysPost post)
  92. {
  93. Long postId = StringUtils.isNull(post.getPostId()) ? -1L : post.getPostId();
  94. SysPost info = postMapper.checkPostCodeUnique(post.getPostCode());
  95. if (StringUtils.isNotNull(info) && info.getPostId().longValue() != postId.longValue())
  96. {
  97. return UserConstants.NOT_UNIQUE;
  98. }
  99. return UserConstants.UNIQUE;
  100. }
  101. /**
  102. * 通过岗位ID查询岗位使用数量
  103. *
  104. * @param postId 岗位ID
  105. * @return 结果
  106. */
  107. @Override
  108. public int countUserPostById(Long postId)
  109. {
  110. return userPostMapper.countUserPostById(postId);
  111. }
  112. /**
  113. * 删除岗位信息
  114. *
  115. * @param postId 岗位ID
  116. * @return 结果
  117. */
  118. @Override
  119. public int deletePostById(Long postId)
  120. {
  121. return postMapper.deletePostById(postId);
  122. }
  123. /**
  124. * 批量删除岗位信息
  125. *
  126. * @param postIds 需要删除的岗位ID
  127. * @return 结果
  128. * @throws Exception 异常
  129. */
  130. @Override
  131. public int deletePostByIds(Long[] postIds)
  132. {
  133. for (Long postId : postIds)
  134. {
  135. SysPost post = selectPostById(postId);
  136. if (countUserPostById(postId) > 0)
  137. {
  138. throw new ServiceException(String.format("%1$s已分配,不能删除", post.getPostName()));
  139. }
  140. }
  141. return postMapper.deletePostByIds(postIds);
  142. }
  143. /**
  144. * 新增保存岗位信息
  145. *
  146. * @param post 岗位信息
  147. * @return 结果
  148. */
  149. @Override
  150. public int insertPost(SysPost post)
  151. {
  152. return postMapper.insertPost(post);
  153. }
  154. /**
  155. * 修改保存岗位信息
  156. *
  157. * @param post 岗位信息
  158. * @return 结果
  159. */
  160. @Override
  161. public int updatePost(SysPost post)
  162. {
  163. return postMapper.updatePost(post);
  164. }
  165. }