package com.newfiber.api.pc.service.impl; import com.newfiber.api.pc.dao.EventsManage.AdministrativeDivisionDao; import com.newfiber.api.pc.dao.EventsManage.DivisionOrgDao; import com.newfiber.api.pc.dao.RiverManage.RiverChiefLogDao; import com.newfiber.api.pc.dao.RiverManage.RiverInfoBasisDao; import com.newfiber.api.pc.model.EventsManage.AdministrativeDivision; import com.newfiber.api.pc.model.River.RiverChiefLog; import com.newfiber.api.pc.model.River.RiverInfoBasis; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.StringUtils; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.stream.Collectors; @Service("riverChiefService") public class RiverChiefService { @Autowired private RiverChiefLogDao riverChiefLogDao; @Autowired private DivisionOrgDao divisionOrgDao; @Autowired private AdministrativeDivisionDao administrativeDivisionDao; @Autowired private RiverInfoBasisDao riverInfoBasisDao; /** * 获得下级河长 No * * @param chiefUserNo * @return */ public List<String> getNextChief(String chiefUserNo) { List<String> result = new ArrayList<>(); RiverInfoBasis riverInfoBasis = riverInfoBasisDao.selectDivisionNoByUserNo(chiefUserNo); if (riverInfoBasis != null && !StringUtils.isEmpty(riverInfoBasis.getDivisionNo())) { //查询下级所有行政区划 List<String> childDivisionNos = divisionOrgDao.getChildDivisionNos(riverInfoBasis.getDivisionNo()); if (!childDivisionNos.isEmpty()) { List<AdministrativeDivision> divisions = administrativeDivisionDao.listByDivisions(childDivisionNos); if (!divisions.isEmpty()) { List<String> list = divisions.stream().map(AdministrativeDivision::getUserNo).collect(Collectors.toList()); //查询下级的巡河人员 Set<String> set = new HashSet<>(list); result = new ArrayList<>(set); } } } return result; } /** * 获得下级河流 No * * @param chiefUserNo * @return */ public List<String> getNextRiver(String chiefUserNo) { List<String> result = new ArrayList<>(); RiverChiefLog riverChiefLog = riverChiefLogDao.selectRiverChiefLogByUserNo(chiefUserNo); if (riverChiefLog != null && !StringUtils.isEmpty(riverChiefLog.getDivisionNo())) { //查询下级所有行政区划 List<String> childDivisionNos = divisionOrgDao.getChildDivisionNos(riverChiefLog.getDivisionNo()); if (!childDivisionNos.isEmpty()) { List<AdministrativeDivision> divisions = administrativeDivisionDao.listByDivisions(childDivisionNos); if (!divisions.isEmpty()) { List<String> list = divisions.stream().map(AdministrativeDivision::getRiverNo).collect(Collectors.toList()); //查询下级的巡河人员 Set<String> set = new HashSet<>(list); result = new ArrayList<>(set); } } } return result; } /** * 传入地区获得下级用户 * * @param divisionNo * @return */ public List<String> getNextUser(String divisionNo) { List<String> result = new ArrayList<>(); if (StringUtils.isEmpty(divisionNo)){ return result; } //查询下级所有行政区划 List<String> childDivisionNos = divisionOrgDao.getChildDivisionNos(divisionNo); if (!childDivisionNos.isEmpty()) { List<AdministrativeDivision> divisions = administrativeDivisionDao.listByDivisions(childDivisionNos); if (!divisions.isEmpty()) { List<String> list = divisions.stream().map(AdministrativeDivision::getUserNo).collect(Collectors.toList()); Set<String> set = new HashSet<>(list); result = new ArrayList<>(set); } } return result; } /** * 获取当前地区下的所有地区 * @param * @return */ public List<String> getNextDivision(String userNo) { List<String> result = new ArrayList<>(); if (StringUtils.isEmpty(userNo)){ return result; } if("Admin".equalsIgnoreCase(userNo)){ result.addAll(divisionOrgDao.getChildDivisionNos("1")); return result; } RiverInfoBasis riverInfoBasis = riverInfoBasisDao.selectDivisionNoByUserNo(userNo); if(riverInfoBasis == null || riverInfoBasis.getDivisionNo() == null){ return result; } result.addAll(divisionOrgDao.getChildDivisionNos(riverInfoBasis.getDivisionNo())); return result; } /** * 查询该河长下的地区 * @param userNo * @return */ public List<String> getUserDivision(String userNo) { List<String> result = new ArrayList<>(); if (StringUtils.isEmpty(userNo)){ return result; } List<RiverInfoBasis> riverInfoBases = riverInfoBasisDao.selectByUserNo(userNo); if(riverInfoBases.isEmpty()){ return result; } //查询下级所有行政区划 List<String> list = riverInfoBases.stream().map(RiverInfoBasis::getDivisionNo).collect(Collectors.toList()); if(!list.isEmpty()){ for (String divisionNo : list) { result.addAll(divisionOrgDao.getChildDivisionNos(divisionNo)); } } return result; } }