package cn.com.goldenwater.dcproj.service.impl.base; import cn.com.goldenwater.core.service.AbstractCrudService; import cn.com.goldenwater.dcproj.dao.AttAdBaseDao; import cn.com.goldenwater.dcproj.dto.AdUpDto; import cn.com.goldenwater.dcproj.model.AttAdBase; import cn.com.goldenwater.dcproj.param.AttAdBaseParam; import cn.com.goldenwater.dcproj.service.AttAdBaseService; import cn.com.goldenwater.dcproj.service.OlBisInspOrgService; import cn.com.goldenwater.dcproj.utils.Constant; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; /** * @author lune * @date 2019-2-18 */ @Service @Transactional(rollbackFor = Exception.class) public class AttAdBaseServiceImpl extends AbstractCrudService implements AttAdBaseService { @Autowired private AttAdBaseDao attAdBaseDao; @Autowired private OlBisInspOrgService olBisInspOrgService; public AttAdBaseServiceImpl(AttAdBaseDao attAdBaseDao) { super(attAdBaseDao); this.attAdBaseDao = attAdBaseDao; } @Override public List getProvincialAdList() { //查询所有省级行政区划 AttAdBaseParam attAdBaseParam = new AttAdBaseParam(); attAdBaseParam.setAdCode("__0000000000"); List list = attAdBaseDao.findList(attAdBaseParam); list.remove(0); return list; } @Override public List getAdData(String adCode) { return this.attAdBaseDao.getAdData(adCode); } @Override public AdUpDto getAdUp(String adCode) { AdUpDto adUpBean = null; List list = new ArrayList(); int j = 0; AdUpDto adUpBean1 = attAdBaseDao.fingAdUp(adCode); for (int i = 0; i < 8; i++) { adUpBean = attAdBaseDao.fingAdUp(adCode); if (adUpBean == null) { break; } else { j++; } if (adUpBean.getAdFcode() == "000000000000" || adUpBean.getAdFcode() == null || "000000000000".equals(adUpBean.getAdFcode())) { if (j > 1) { break; } break; } else { AdUpDto ab1 = attAdBaseDao.fingAdUp(adUpBean.getAdFcode()); list.add(ab1); adCode = ab1.getAdCode(); } } adUpBean1.setAdUpDtoList(list); return adUpBean1; } @Override public AttAdBase getByAdcode(String adCode) { return attAdBaseDao.getByAdcode(adCode); } @Override public Boolean whetherTheCityOrCounty(String orgId) { AttAdBase byAdcode = this.getByAdcode(olBisInspOrgService.getRlProvince(orgId)); return StringUtils.equalsAny(byAdcode.getAdGrad(), Constant.STRING_THREE, Constant.STRING_FORE); } @Override public List getAllChildByCode(String code) { return attAdBaseDao.getAllChildByCode(code); } @Override public List getTreeByUser(String adCode ,String code) { List list = attAdBaseDao.getAllChildren(adCode); if(CollectionUtils.isEmpty(list)){ return new ArrayList(); } List rootAdList = new ArrayList<>(); for(AdUpDto adBase : list){ if(code.equals(adBase.getAdCode())){ rootAdList.add(adBase); } } List adTreeList = new ArrayList<>(); for (AdUpDto rootAd : rootAdList) { AdUpDto adBase = buildUserTree(list, rootAd); adTreeList.add(adBase); } return adTreeList; } public AdUpDto buildUserTree(List AdDataList, AdUpDto adBase) { List childrenList = new ArrayList<>(); for (AdUpDto adUpDto : AdDataList) { // 当前数据的 parentId 等于 父节点的 id,则该数据是当前父级节点的子级。 if (adUpDto.getAdFcode().equals(adBase.getAdCode())) { // 递归调用 childrenList.add(buildUserTree(AdDataList, adUpDto)); } } adBase.setAdUpDtoList(childrenList); return adBase; } }