123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- 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<TypeByBody> tag() {
- List<TypeBy> typeBIES = typeByDao.selectList(null);
- List<TypeBy> collect = typeBIES.stream().filter(typeBy -> {
- if (typeBy.getMidCategory() == null || typeBy.getMidCategory().equals(""))
- return true;
- return false;
- }).collect(Collectors.toList());
- List<TypeByBody> 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<TypeByBody> findChild(List<TypeBy> typeBIES, String typeCodeBy, int randType){
- String substring = typeCodeBy.substring(0, randType);
- if(randType == 2){
- List<TypeByBody> 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<TypeByBody> 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<AddrCategoryBody> addrCodeMap() {
- List<AddrCategory> addrCategories = addrCategoryDao.selectList(null);
- List<AddrCategory> collect = addrCategories.stream().filter(addrCategory -> {
- if (addrCategory.getCity() == null || addrCategory.getCity().equals(""))
- return true;
- return false;
- }).collect(Collectors.toList());
- List<AddrCategoryBody> 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<AddrCategoryBody> findChildAddr(List<AddrCategory> addrCategories, String addrCore, int randType){
- String substring = addrCore.substring(0, randType);
- if(randType == 2){
- List<AddrCategoryBody> 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<AddrCategoryBody> 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;
- }
- }
|