package com.ruoyi.demo.service.impl; import com.ruoyi.demo.entity.AddrCategory; import com.ruoyi.demo.entity.TypeBy; import com.ruoyi.demo.entity.vo.AddrCategoryBody; import com.ruoyi.demo.entity.vo.TypeByBody; import com.ruoyi.demo.mapper.AddrCategoryDao; import com.ruoyi.demo.mapper.TypeByDao; import com.ruoyi.demo.service.CommonService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @Service @Transactional public class CommonServiceImpl implements CommonService { @Autowired TypeByDao typeByDao; @Autowired AddrCategoryDao addrCategoryDao; @Override public List tag() { List typeBIES = typeByDao.selectList(null); List collect = typeBIES.stream().filter(typeBy -> { if (typeBy.getMidCategory() == null || typeBy.getMidCategory().equals("")) return true; return false; }).collect(Collectors.toList()); List typeByBodies = new ArrayList<>(); for (TypeBy typeBy : collect) { TypeByBody typeByBody = new TypeByBody(); typeByBody.setTypeCodeBy(typeBy.getTypeCodeBy()); typeByBody.setTypeNameBy(typeBy.getBigCategory()); typeByBody.setTypeByBodies(findChild(typeBIES, typeByBody.getTypeCodeBy(), 2)); typeByBodies.add(typeByBody); } return typeByBodies; } public List findChild(List typeBIES, String typeCodeBy, int randType){ String substring = typeCodeBy.substring(0, randType); if(randType == 2){ List list = new ArrayList<>(); for (TypeBy typeBY : typeBIES) { if(typeBY.getTypeCodeBy().startsWith(substring) && (typeBY.getMidCategory() != null && !typeBY.getMidCategory().equals("")) && (typeBY.getSubCategory() == null || typeBY.getSubCategory().equals(""))){ TypeByBody typeByBody = new TypeByBody(); typeByBody.setTypeCodeBy(typeBY.getTypeCodeBy()); typeByBody.setTypeNameBy(typeBY.getMidCategory()); typeByBody.setTypeByBodies(findChild(typeBIES, typeByBody.getTypeCodeBy(), 4)); list.add(typeByBody); } } return list; }else if(randType == 4){ List list = new ArrayList<>(); for (TypeBy typeBY : typeBIES) { if(typeBY.getTypeCodeBy().startsWith(substring) && typeBY.getSubCategory() != null && !typeBY.getSubCategory().equals("")){ TypeByBody typeByBody = new TypeByBody(); typeByBody.setTypeCodeBy(typeBY.getTypeCodeBy()); typeByBody.setTypeNameBy(typeBY.getSubCategory()); typeByBody.setTypeByBodies(null); list.add(typeByBody); } } return list; } return null; } @Override public List addrCodeMap() { List addrCategories = addrCategoryDao.selectList(null); List collect = addrCategories.stream().filter(addrCategory -> { if (addrCategory.getCity() == null || addrCategory.getCity().equals("")) return true; return false; }).collect(Collectors.toList()); List addrCategoryBodies = new ArrayList<>(); for (AddrCategory addrCategory : collect) { AddrCategoryBody addrCategoryBody = new AddrCategoryBody(); addrCategoryBody.setAddrCoreName(addrCategory.getProvince()); addrCategoryBody.setAddrCore(addrCategory.getAddrCode()); addrCategoryBody.setAddrCategoryes(findChildAddr(addrCategories, addrCategoryBody.getAddrCore(), 2)); addrCategoryBodies.add(addrCategoryBody); } return addrCategoryBodies; } public List findChildAddr(List addrCategories, String addrCore, int randType){ String substring = addrCore.substring(0, randType); if(randType == 2){ List list = new ArrayList<>(); for (AddrCategory addrCategory : addrCategories) { if(addrCategory.getAddrCode().startsWith(substring) && (addrCategory.getCity() != null && !addrCategory.getCity().equals("")) && (addrCategory.getDistrict() == null || addrCategory.getDistrict().equals(""))){ AddrCategoryBody addrCategoryBody = new AddrCategoryBody(); addrCategoryBody.setAddrCoreName(addrCategory.getCity()); addrCategoryBody.setAddrCore(addrCategory.getAddrCode()); addrCategoryBody.setAddrCategoryes(findChildAddr(addrCategories, addrCategoryBody.getAddrCore(), 4)); list.add(addrCategoryBody); } } return list; }else if(randType == 4){ List list = new ArrayList<>(); for (AddrCategory addrCategory : addrCategories) { if(addrCategory.getAddrCode().startsWith(substring) && addrCategory.getDistrict() != null && !addrCategory.getDistrict().equals("")){ AddrCategoryBody addrCategoryBody = new AddrCategoryBody(); addrCategoryBody.setAddrCoreName(addrCategory.getDistrict()); addrCategoryBody.setAddrCore(addrCategory.getAddrCode()); addrCategoryBody.setAddrCategoryes(null); list.add(addrCategoryBody); } } return list; } return null; } }