SysDeptServiceImpl.java 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package com.kmall.admin.service.impl;
  2. import com.kmall.admin.dao.SysDeptDao;
  3. import com.kmall.admin.entity.SysDeptEntity;
  4. import com.kmall.admin.service.SysDeptService;
  5. import com.qiniu.util.StringUtils;
  6. import org.springframework.beans.factory.annotation.Autowired;
  7. import org.springframework.stereotype.Service;
  8. import java.util.ArrayList;
  9. import java.util.List;
  10. import java.util.Map;
  11. @Service("sysDeptService")
  12. public class SysDeptServiceImpl implements SysDeptService {
  13. @Autowired
  14. private SysDeptDao sysDeptDao;
  15. @Override
  16. public SysDeptEntity queryObject(Long deptId) {
  17. return sysDeptDao.queryObject(deptId);
  18. }
  19. @Override
  20. public List<SysDeptEntity> queryList(Map<String, Object> map) {
  21. return sysDeptDao.queryList(map);
  22. }
  23. @Override
  24. public void save(SysDeptEntity sysDept) {
  25. sysDeptDao.save(sysDept);
  26. }
  27. @Override
  28. public void update(SysDeptEntity sysDept) {
  29. sysDeptDao.update(sysDept);
  30. }
  31. @Override
  32. public void delete(Long deptId) {
  33. sysDeptDao.delete(deptId);
  34. }
  35. @Override
  36. public List<Long> queryDetpIdList(Long parentId) {
  37. return sysDeptDao.queryDetpIdList(parentId);
  38. }
  39. @Override
  40. public String getSubDeptIdList(Long deptId) {
  41. //部门及子部门ID列表
  42. List<Long> deptIdList = new ArrayList<>();
  43. //获取子部门ID
  44. List<Long> subIdList = queryDetpIdList(deptId);
  45. getDeptTreeList(subIdList, deptIdList);
  46. //添加本部门
  47. deptIdList.add(deptId);
  48. String deptFilter = StringUtils.join(deptIdList, ",");
  49. return deptFilter;
  50. }
  51. /**
  52. * 递归
  53. */
  54. public void getDeptTreeList(List<Long> subIdList, List<Long> deptIdList) {
  55. for (Long deptId : subIdList) {
  56. List<Long> list = queryDetpIdList(deptId);
  57. if (list.size() > 0) {
  58. getDeptTreeList(list, deptIdList);
  59. }
  60. deptIdList.add(deptId);
  61. }
  62. }
  63. }