CommonServiceImpl.java 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. package com.ruoyi.demo.service.impl;
  2. import com.ruoyi.demo.entity.AddrCategory;
  3. import com.ruoyi.demo.entity.TypeBy;
  4. import com.ruoyi.demo.entity.vo.AddrCategoryBody;
  5. import com.ruoyi.demo.entity.vo.TypeByBody;
  6. import com.ruoyi.demo.mapper.AddrCategoryDao;
  7. import com.ruoyi.demo.mapper.TypeByDao;
  8. import com.ruoyi.demo.service.CommonService;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.stereotype.Service;
  11. import org.springframework.transaction.annotation.Transactional;
  12. import java.util.ArrayList;
  13. import java.util.List;
  14. import java.util.stream.Collectors;
  15. @Service
  16. @Transactional
  17. public class CommonServiceImpl implements CommonService {
  18. @Autowired
  19. TypeByDao typeByDao;
  20. @Autowired
  21. AddrCategoryDao addrCategoryDao;
  22. @Override
  23. public List<TypeByBody> tag() {
  24. List<TypeBy> typeBIES = typeByDao.selectList(null);
  25. List<TypeBy> collect = typeBIES.stream().filter(typeBy -> {
  26. if (typeBy.getMidCategory() == null || typeBy.getMidCategory().equals(""))
  27. return true;
  28. return false;
  29. }).collect(Collectors.toList());
  30. List<TypeByBody> typeByBodies = new ArrayList<>();
  31. for (TypeBy typeBy : collect) {
  32. TypeByBody typeByBody = new TypeByBody();
  33. typeByBody.setTypeCodeBy(typeBy.getTypeCodeBy());
  34. typeByBody.setTypeNameBy(typeBy.getBigCategory());
  35. typeByBody.setTypeByBodies(findChild(typeBIES, typeByBody.getTypeCodeBy(), 2));
  36. typeByBodies.add(typeByBody);
  37. }
  38. return typeByBodies;
  39. }
  40. public List<TypeByBody> findChild(List<TypeBy> typeBIES, String typeCodeBy, int randType){
  41. String substring = typeCodeBy.substring(0, randType);
  42. if(randType == 2){
  43. List<TypeByBody> list = new ArrayList<>();
  44. for (TypeBy typeBY : typeBIES) {
  45. if(typeBY.getTypeCodeBy().startsWith(substring) && (typeBY.getMidCategory() != null && !typeBY.getMidCategory().equals("")) && (typeBY.getSubCategory() == null || typeBY.getSubCategory().equals(""))){
  46. TypeByBody typeByBody = new TypeByBody();
  47. typeByBody.setTypeCodeBy(typeBY.getTypeCodeBy());
  48. typeByBody.setTypeNameBy(typeBY.getMidCategory());
  49. typeByBody.setTypeByBodies(findChild(typeBIES, typeByBody.getTypeCodeBy(), 4));
  50. list.add(typeByBody);
  51. }
  52. }
  53. return list;
  54. }else if(randType == 4){
  55. List<TypeByBody> list = new ArrayList<>();
  56. for (TypeBy typeBY : typeBIES) {
  57. if(typeBY.getTypeCodeBy().startsWith(substring) && typeBY.getSubCategory() != null && !typeBY.getSubCategory().equals("")){
  58. TypeByBody typeByBody = new TypeByBody();
  59. typeByBody.setTypeCodeBy(typeBY.getTypeCodeBy());
  60. typeByBody.setTypeNameBy(typeBY.getSubCategory());
  61. typeByBody.setTypeByBodies(null);
  62. list.add(typeByBody);
  63. }
  64. }
  65. return list;
  66. }
  67. return null;
  68. }
  69. @Override
  70. public List<AddrCategoryBody> addrCodeMap() {
  71. List<AddrCategory> addrCategories = addrCategoryDao.selectList(null);
  72. List<AddrCategory> collect = addrCategories.stream().filter(addrCategory -> {
  73. if (addrCategory.getCity() == null || addrCategory.getCity().equals(""))
  74. return true;
  75. return false;
  76. }).collect(Collectors.toList());
  77. List<AddrCategoryBody> addrCategoryBodies = new ArrayList<>();
  78. for (AddrCategory addrCategory : collect) {
  79. AddrCategoryBody addrCategoryBody = new AddrCategoryBody();
  80. addrCategoryBody.setAddrCoreName(addrCategory.getProvince());
  81. addrCategoryBody.setAddrCore(addrCategory.getAddrCode());
  82. addrCategoryBody.setAddrCategoryes(findChildAddr(addrCategories, addrCategoryBody.getAddrCore(), 2));
  83. addrCategoryBodies.add(addrCategoryBody);
  84. }
  85. return addrCategoryBodies;
  86. }
  87. public List<AddrCategoryBody> findChildAddr(List<AddrCategory> addrCategories, String addrCore, int randType){
  88. String substring = addrCore.substring(0, randType);
  89. if(randType == 2){
  90. List<AddrCategoryBody> list = new ArrayList<>();
  91. for (AddrCategory addrCategory : addrCategories) {
  92. if(addrCategory.getAddrCode().startsWith(substring) && (addrCategory.getCity() != null && !addrCategory.getCity().equals("")) && (addrCategory.getDistrict() == null || addrCategory.getDistrict().equals(""))){
  93. AddrCategoryBody addrCategoryBody = new AddrCategoryBody();
  94. addrCategoryBody.setAddrCoreName(addrCategory.getCity());
  95. addrCategoryBody.setAddrCore(addrCategory.getAddrCode());
  96. addrCategoryBody.setAddrCategoryes(findChildAddr(addrCategories, addrCategoryBody.getAddrCore(), 4));
  97. list.add(addrCategoryBody);
  98. }
  99. }
  100. return list;
  101. }else if(randType == 4){
  102. List<AddrCategoryBody> list = new ArrayList<>();
  103. for (AddrCategory addrCategory : addrCategories) {
  104. if(addrCategory.getAddrCode().startsWith(substring) && addrCategory.getDistrict() != null && !addrCategory.getDistrict().equals("")){
  105. AddrCategoryBody addrCategoryBody = new AddrCategoryBody();
  106. addrCategoryBody.setAddrCoreName(addrCategory.getDistrict());
  107. addrCategoryBody.setAddrCore(addrCategory.getAddrCode());
  108. addrCategoryBody.setAddrCategoryes(null);
  109. list.add(addrCategoryBody);
  110. }
  111. }
  112. return list;
  113. }
  114. return null;
  115. }
  116. }