package com.newfiber.api.pc.controller.River; import cn.hutool.core.collection.CollUtil; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.plugins.Page; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.newfiber.api.config.FileVisitProperty; import com.newfiber.api.core.annotation.SysLog; import com.newfiber.api.core.bean.ReqBodyObj; import com.newfiber.api.core.bean.RespBodyObj; import com.newfiber.api.core.utils.UUIDPK; import com.newfiber.api.pc.dao.EventsManage.AdministrativeDivisionDao; import com.newfiber.api.pc.dao.EventsManage.DivisionOrgDao; import com.newfiber.api.pc.dao.RiverManage.*; import com.newfiber.api.pc.model.EventsManage.AdministrativeDivision; import com.newfiber.api.pc.model.EventsManage.AdministrativeDivisionQuery; import com.newfiber.api.pc.model.EventsManage.Tree; import com.newfiber.api.pc.model.River.*; import com.newfiber.api.pc.model.Users; import com.newfiber.api.pc.service.RestTemplateService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.ResponseBody; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import java.io.Serializable; import java.math.BigDecimal; import java.text.DecimalFormat; import java.text.NumberFormat; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; /** * @author wmj * @version 创建时间:2017/11/25 * @description 河道基础信息控制器 */ @Controller @CrossOrigin public class RiverController { @Autowired private RiverInfoBasisDao riverInfoBasisDao; @Autowired private RiverChiefLogDao riverChiefLogDao; @Autowired private AdministrativeDivisionDao administrativeDivisionDao; @Autowired private DivisionOrgDao divisionOrgDao; @Autowired private RiverChiefDao riverChiefDao; @Autowired private RiverPicsDao riverPicsDao; @Autowired private RiverPatrolDao riverPatrolDao; @Autowired private RiverChiefInformationDao riverChiefInformationDao; @Resource private RestTemplateService restTemplateService; @Autowired private FileVisitProperty fileVisitProperty; /** * 查询河道基本信息列表 * @return */ @PostMapping(value = "river/selectRiverInfoBasisList", produces = "application/json;charset=utf-8") @ResponseBody @SysLog(value="查询河道基本信息列表",actionType="4") public RespBodyObj<Page<RiverInfoBasis>> selectRiverInfoBasisList(@RequestBody ReqBodyObj<RiverInfoBasis> params){ RiverInfoBasis ri = params.getData(); Page<RiverInfoBasis> result = new Page<>(); try{ Integer pageNo = null; Integer pageSize = null; if(params.getSize() != 0){ pageNo = (params.getCurrent()-1)*params.getSize(); pageSize = params.getSize(); } List<RiverInfoBasis> riverInfoBasisList = riverInfoBasisDao.selectRiverInfoBasisList(pageNo,pageSize,ri.getRiverNo(),ri.getRiverGrade(),ri.getRiverName()); if(riverInfoBasisList != null && riverInfoBasisList.size() > 0){ for(RiverInfoBasis riverInfoBasis : riverInfoBasisList){ String riverPicsNo = riverInfoBasis.getRiverPicsNo(); List<RiverPics> riverPicsList = riverPicsDao.selectRiverPicsList(riverPicsNo); if(!riverPicsList.isEmpty()){ List<Image> images = new ArrayList<>(); for (RiverPics riverPics : riverPicsList) { Image image = new Image(); image.setPath(riverPics.getRiverPicsAddress()); image.setRealPath(fileVisitProperty.getWebFile()+riverPics.getRiverPicsAddress()); } riverInfoBasis.setImagesList(images); } String riverNo1 = riverInfoBasis.getRiverNo(); //根据河道编号查询是否已经配置河长 List<RiverInfoBasis> riverInfoBasisList1 = riverInfoBasisDao.selectRiverInformationIsNull(riverNo1); if(riverInfoBasisList1 != null && riverInfoBasisList1.size() > 0){ riverInfoBasis.setIsNull("1"); }else{ riverInfoBasis.setIsNull("0"); } // TODO 跳过水质相关功能 // RiverInfoBasis riverInfoBasis1 = riverInfoBasisDao.selectRiverInfoWaterLevel(riverNo1); // if(riverInfoBasis1 != null){ // riverInfoBasis.setStandardLevel(riverInfoBasis1.getStandardLevel()); // String s = riverInfoBasis1.getStandardLevelZn(); // s = s.substring(0,s.length()- 1); // riverInfoBasis.setStandardLevelZn(s); // String dataNo = riverInfoBasis1.getDataNo(); // String siteNo = riverInfoBasis1.getSiteNo(); // //根据dataNo和siteNo查询实时数据 // List<WaterQuality> waterList = riverInfoBasisDao.selectWaterQualityMessage(siteNo,dataNo); // riverInfoBasis.setWaterList(waterList); // //根据站点编号查询历史数据 // List<WaterQuality> waterQualityList = riverInfoBasisDao.selectWaterQualityMessageHistory(siteNo); // riverInfoBasis.setWaterQualityList(waterQualityList); // } String s = "["; String pointXY = riverInfoBasis.getPointXY(); pointXY = pointXY.substring(1,pointXY.length()-1); String xy[] = pointXY.split(";"); List<Object> list = new ArrayList<Object>(); for(int i =0 ; i <xy.length ; i++){ list.add(xy[i]); if(i < xy.length - 1){ s = s + xy[i] + ","; }else{ s = s + xy[i]; } } s = s+ "]"; riverInfoBasis.setObjectList(list); riverInfoBasis.setPointXY(s); } } int count = riverInfoBasisDao.countRiverInfoBasisList(ri.getRiverNo(),ri.getRiverGrade(),ri.getRiverName()); result.setRecords(riverInfoBasisList); result.setTotal(count); return RespBodyObj.ok(result); }catch(Exception e){ e.printStackTrace(); return RespBodyObj.error("查询异常"); } } /** * 根据河道编号查询河道坐标 * @return */ @PostMapping(value = "river/selectRiverInfoBasisPoint", produces = "application/json;charset=utf-8") @ResponseBody @SysLog(value="根据河道编号查询河道坐标",actionType="4") public RespBodyObj<Map<String, Object>> selectRiverInfoBasisPoint(@RequestBody ReqBodyObj<RiverInfoBasis> params){ Map<String, Object> map = new HashMap<>(); RiverInfoBasis riverInfoBasis = riverInfoBasisDao.selectRiverInfoBasisPoint(params.getData().getRiverNo()); DecimalFormat df = new DecimalFormat("######0.0000"); if(riverInfoBasis != null){ String pointXY = riverInfoBasis.getPointXY(); if(pointXY != null && pointXY.equals("") != true){ String xy[] = pointXY.split(";"); List<Object> list = new ArrayList<Object>(); for(int i =0 ; i <xy.length ; i++){ if(i/2==0){ list.add(xy[i].substring(1, xy[i].length())); }else{ list.add(xy[i].substring(1,xy[i].length()-1)); } } map.put("point",list); } } return RespBodyObj.ok(map); } /** * 查询我的河道基本信息 * @return */ @PostMapping(value = "river/selectRiverInfoBasisByDivisionNo", produces = "application/json;charset=utf-8") @ResponseBody @SysLog(value="查询我的河道基本信息",actionType="4") public RespBodyObj<Page<RiverInfoBasis>> selectRiverInfoBasisByDivisionNo(@RequestBody ReqBodyObj<RiverInfoBasis> params){ RiverInfoBasis ri = params.getData(); Page<RiverInfoBasis> result = new Page<>(); try{ PageHelper.startPage(params.getCurrent(), params.getSize()); List<RiverInfoBasis> riverInfoBasisList = riverInfoBasisDao.selectRiverInfoBasisByDivisionNoo(ri.getDivisionNo(),ri.getRiverNo()); if(riverInfoBasisList != null && riverInfoBasisList.size() > 0){ for(RiverInfoBasis riverInfoBasis : riverInfoBasisList){ String riverPicsNo = riverInfoBasis.getRiverPicsNo(); if(!StringUtils.isEmpty(riverPicsNo)){ List<RiverPics> riverPicsList = riverPicsDao.selectRiverPicsList(riverPicsNo); if(!riverPicsList.isEmpty()){ List<Image> images = new ArrayList<>(); riverPicsList.stream().forEach(e->{ Image image = new Image(); image.setPath(e.getRiverPicsAddress()); image.setRealPath(fileVisitProperty.getWebFile()+e.getRiverPicsAddress()); images.add(image); }); riverInfoBasis.setImagesList(images); } }else{ riverInfoBasis.setImagesList(new ArrayList<Image>()); } String riverNo1 = riverInfoBasis.getRiverNo(); //查询该河道是否已经配置过河长用户 List<RiverChief> riverChiefList = riverChiefDao.selectRiverChiefByRiverNo(riverNo1); if(riverChiefList != null && riverChiefList.size() > 0){ riverInfoBasis.setIsNull("1"); }else{ riverInfoBasis.setIsNull("0"); } //TODO 跳过水质相关功能 // RiverInfoBasis riverInfoBasis1 = riverInfoBasisDao.selectRiverInfoWaterLevel(riverNo1); // if(riverInfoBasis1 != null){ // riverInfoBasis.setStandardLevel(riverInfoBasis1.getStandardLevel()); // String s = riverInfoBasis1.getStandardLevelZn(); // s = s.substring(0,s.length()- 1); // riverInfoBasis.setStandardLevelZn(s); // } } } PageInfo<RiverInfoBasis> info = new PageInfo<>(riverInfoBasisList); result.setTotal(info.getTotal()); result.setRecords(riverInfoBasisList); return RespBodyObj.ok(result); }catch(Exception e){ e.printStackTrace(); return RespBodyObj.error("查询异常"); } } /** * 新增河道基本信息 * @return */ @PostMapping(value = "river/addRiverInfoBasis", produces = "application/json;charset=utf-8") @ResponseBody @SysLog(value="新增河道基本信息",actionType="1") public RespBodyObj addRiverInfoBasis(@RequestBody ReqBodyObj<RiverInfoBasis> params,HttpServletRequest request){ RiverInfoBasis ri = params.getData(); String riverNo = UUIDPK.UUIDGenerator.getUUID(); String createUserNo = ri.getCreateUserNo(); try{ if (createUserNo == null || createUserNo == "") { createUserNo = request.getHeader("userNo"); } String riverGradeZn = ""; int riverGrade = 0; BigDecimal riverLength=new BigDecimal(ri.getRiverLength()); riverLength=riverLength.setScale(2, BigDecimal.ROUND_HALF_UP); String[] pointX = request.getParameterValues("pointX"); String[] pointY = request.getParameterValues("pointY"); String pointXY= ri.getPointXY(); RiverInfoBasis riverInfoBasis = riverInfoBasisDao.selectRiverParentRiverNoo(ri.getDivisionNo()); if(riverInfoBasis != null){ String parentDivisionNo = riverInfoBasis.getParentDivisionNo(); List<RiverInfoBasis> riverInfoBasisList = riverInfoBasisDao.selectRiverParentRiverNo(parentDivisionNo); if(riverInfoBasisList != null && riverInfoBasisList.size() > 0){ riverGrade = riverInfoBasisList.get(0).getRiverGrade()+1; if(riverGrade > 5){ riverGrade = 5; } if(riverGrade==1){ riverGradeZn = "省级河道"; }else if(riverGrade==2){ riverGradeZn = "市级河道"; }else if(riverGrade==3){ riverGradeZn = "县级河道"; }else if(riverGrade==4){ riverGradeZn = "镇级河道"; }else if(riverGrade==5){ riverGradeZn = "村级河道"; } } } String riverPicsNo = UUIDPK.UUIDGenerator.getUUID(); int a = riverInfoBasisDao.addRiverInfoBasis(ri.getRiverName(),riverGrade,riverGradeZn,ri.getParentRiverNo(),riverLength,ri.getRiverStartAddress(),ri.getRiverEndAddress(),ri.getFlowThroughRegion(), createUserNo,riverNo,ri.getDivisionNo(),ri.getRiverInformation(),riverPicsNo,pointXY); List<Image> riverPicsList = params.getData().getImagesList(); for(Image pic: riverPicsList){ riverPicsDao.addRiverPics(riverPicsNo,pic.getPath(),pic.getPath(),createUserNo); } if(a>0){ return RespBodyObj.ok("新增成功"); }else{ return RespBodyObj.error("新增失败"); } }catch(Exception e){ e.printStackTrace(); return RespBodyObj.error("新增失败"); } } /** * 修改河道基本信息 * @return */ @PostMapping(value = "river/updateRiverInfoBasis", produces = "application/json;charset=utf-8") @ResponseBody @SysLog(value="修改河道基本信息",actionType="3") public RespBodyObj updateRiverInfoBasis(@RequestBody ReqBodyObj<RiverInfoBasis> params, HttpServletRequest request){ RiverInfoBasis ri = params.getData(); String createUserNo = ri.getCreateUserNo(); try{ if (createUserNo == null || createUserNo == "") { createUserNo = request.getHeader("userNo"); } int riverGrade = params.getData().getRiverGrade(); String riverGradeZn = ""; if(riverGrade == 3){ riverGradeZn = "市级河道"; }else if(riverGrade == 4){ riverGradeZn = "镇级河道"; }else if(riverGrade == 5){ riverGradeZn = "村级河道"; } BigDecimal riverLength=new BigDecimal(ri.getRiverLength()); riverLength=riverLength.setScale(2, BigDecimal.ROUND_HALF_UP); String pointXY= ""; if(!StringUtils.isEmpty(ri.getPointXY())){ pointXY= ri.getPointXY(); } String riverPicsNo = UUIDPK.UUIDGenerator.getUUID(); int a = riverInfoBasisDao.updateRiverInfoBasis(ri.getRiverName(),riverGrade,riverGradeZn,ri.getParentRiverNo(),riverLength,ri.getRiverStartAddress(),ri.getRiverEndAddress(),ri.getFlowThroughRegion(), ri.getRiverNo(),ri.getDivisionNo(),ri.getRiverInformation(),riverPicsNo,pointXY); List<Image> pics = params.getData().getImagesList(); if(!pics.isEmpty()){ for(Image pic:pics){ riverPicsDao.addRiverPics(riverPicsNo,pic.getPath(),pic.getPath(),createUserNo); } } if(a>0){ return RespBodyObj.ok("修改成功"); }else{ return RespBodyObj.error("修改失败"); } }catch(Exception e){ e.printStackTrace(); return RespBodyObj.error("修改失败"); } } /** * 删除河道基本信息 * @return */ @PostMapping(value = "river/deleteRiverInfoBasis", produces = "application/json;charset=utf-8") @ResponseBody @SysLog(value="删除河道基本信息",actionType="2") public RespBodyObj deleteRiverInfoBasis(@RequestBody ReqBodyObj<RiverInfoBasis> params){ RiverInfoBasis riverInfoBasis = params.getData(); try{ int a = riverInfoBasisDao.deleteRiverInfoBasis(riverInfoBasis.getList()); if(a>0){ return RespBodyObj.ok("删除成功"); }else{ return RespBodyObj.error("删除失败"); } }catch(Exception e){ e.printStackTrace(); return RespBodyObj.error("删除失败"); } } /** * 统计分析--河道信息--河道等级分布(无权限) * @return */ @PostMapping(value = "river/selectRiverInfoBasisTotal", produces = "application/json;charset=utf-8") @ResponseBody @SysLog(value="统计分析--河道信息--河道等级分布(无权限)",actionType="4") public RespBodyObj<JSONObject> selectRiverInfoBasisTotal(){ JSONObject json = new JSONObject(); try{ int cityCount = riverInfoBasisDao.selectRiverInfoBasisTotal(3); json.put("cityRiver",cityCount); int townCount = riverInfoBasisDao.selectRiverInfoBasisTotal(4); json.put("townRiver",townCount); int villageCount = riverInfoBasisDao.selectRiverInfoBasisTotal(5); json.put("villageRiver",villageCount); int count = cityCount + townCount + villageCount; //创建一个数值格式化对象 NumberFormat numberFormat = NumberFormat.getInstance(); //设置精确到小数点后2位 numberFormat.setMaximumFractionDigits(2); String city = numberFormat.format((float) cityCount / (float) count * 100) + "%"; String town = numberFormat.format((float) townCount / (float) count * 100) + "%"; String village = numberFormat.format((float) villageCount / (float) count * 100) + "%"; json.put("city",city); json.put("town",town); json.put("village",village); return RespBodyObj.ok(json); }catch(Exception e){ e.printStackTrace(); return RespBodyObj.error("查询失败"); } } /** * 统计分析--河道信息--河道及河长分布 * 根据当前登录用户查询下级的所有河道以及河长 * @param request * @return */ @PostMapping(value = "river/countNextRiverChiefTotal", produces = "application/json;charset=utf-8") @ResponseBody @SysLog(value="根据当前登录用户查询下级的所有河道以及河长",actionType="4") public RespBodyObj<List<Object>> countNextRiverChiefTotal(@RequestBody ReqBodyObj<RiverChiefLog> params,HttpServletRequest request){ JSONObject json = new JSONObject(); List<Object> list1 = new ArrayList<Object>(); try{ //查询当前登录用户 String chiefUserNo = params.getData().getChiefUserNo(); if (chiefUserNo == null || chiefUserNo.equals("") == true) { chiefUserNo = request.getHeader("userNo"); } //查询当前登录用户的行政区划编号 RiverChiefLog riverChiefLog = riverChiefLogDao.selectRiverChiefLogByUserNo(chiefUserNo); if(riverChiefLog != null){ String divisionNo = riverChiefLog.getDivisionNo(); if(divisionNo != null && divisionNo.equals("") != true){ //根据divisionNo查询出parentDivisionNo AdministrativeDivision administrativeDivision = administrativeDivisionDao.selectParentDivisionNo(divisionNo); if(administrativeDivision != null){ String divisionName = administrativeDivision.getDivisionName(); String parentDivisionNo = administrativeDivision.getParentDivisionNo(); //查询下级所有行政区划 List<AdministrativeDivision> administrativeDivisionList = administrativeDivisionDao.selectParentDivisionNoList(divisionNo); if(administrativeDivisionList != null && administrativeDivisionList.size() > 0){ for(AdministrativeDivision administrativeDivisions : administrativeDivisionList){ List<String> list = new ArrayList<String>(); List<String> listUser = new ArrayList<String>(); Map<String,Object> map = new HashMap<String,Object>(); String divisionNames = administrativeDivisions.getDivisionName(); String divisionNos = administrativeDivisions.getDivisionNo(); //查询本级在内的人员 List<RiverPatrol> listPatrol = riverPatrolDao.selectPatrolUserTotal(divisionNos); if(listPatrol != null && listPatrol.size()>0){ for(RiverPatrol riverPatrol : listPatrol){ String userNo = riverPatrol.getRiverChiefNo(); listUser.add(userNo); } } //查询下级的巡河人员 list = getUserNo(divisionNos); if(listUser != null && listUser.size() > 0 && list != null){ for(int i =0;i<listUser.size();i++){ list.add(listUser.get(i)); } } if(!CollectionUtils.isEmpty(list)){ //对list去处重复 for (int i = 0; i < list.size() - 1; i++) { for (int j = list.size() - 1; j > i; j--) { if (list.get(j).equals(list.get(i))) { list.remove(j); } } } } //查询该区域的河道总数 int a = 0; int river = 0; if(list != null && list.size() > 0){ a = list.size(); }else{ list = null; } river = riverChiefLogDao.countRiverNew(divisionNos); map.put("riverChiefUser",a); map.put("riverCount",river); map.put("divisionName",divisionNames); list1.add(map); } } } } }else if("Admin".equalsIgnoreCase(chiefUserNo)){ //根据divisionNo查询出parentDivisionNo String divisionName = "信阳市"; String parentDivisionNo = "0"; //查询下级所有行政区划 List<AdministrativeDivision> administrativeDivisionList = administrativeDivisionDao.selectOne(); if(administrativeDivisionList != null && administrativeDivisionList.size() > 0){ for(AdministrativeDivision administrativeDivisions : administrativeDivisionList){ List<String> list = new ArrayList<String>(); List<String> listUser = new ArrayList<String>(); Map<String,Object> map = new HashMap<String,Object>(); String divisionNames = administrativeDivisions.getDivisionName(); String divisionNos = administrativeDivisions.getDivisionNo(); //查询本级在内的人员 List<RiverPatrol> listPatrol = riverPatrolDao.selectPatrolUserTotal(divisionNos); if(listPatrol != null && listPatrol.size()>0){ for(RiverPatrol riverPatrol : listPatrol){ String userNo = riverPatrol.getRiverChiefNo(); listUser.add(userNo); } } //查询下级的巡河人员 list = getUserNo(divisionNos); if(listUser != null && listUser.size() > 0 && list != null){ for(int i =0;i<listUser.size();i++){ list.add(listUser.get(i)); } } if(!CollectionUtils.isEmpty(list)){ //对list去处重复 for (int i = 0; i < list.size() - 1; i++) { for (int j = list.size() - 1; j > i; j--) { if (list.get(j).equals(list.get(i))) { list.remove(j); } } } } //查询该区域的河道总数 int a = 0; int river = 0; if(list != null && list.size() > 0){ a = list.size(); }else{ list = null; } river = riverChiefLogDao.countRiverNew(divisionNos); map.put("riverChiefUser",a); map.put("riverCount",river); map.put("divisionName",divisionNames); list1.add(map); } } } return RespBodyObj.ok(list1); }catch(Exception e){ e.printStackTrace(); return RespBodyObj.error("查询失败"); } } /** * 递归查询 * @param divisionNo * @return */ public List<String> getUserNo(String divisionNo) { List<AdministrativeDivision> administrativeDivisionList = administrativeDivisionDao.selectuserNoListByDivisionNo(divisionNo); List<String> list = null; if(!CollectionUtils.isEmpty(administrativeDivisionList)){ list = administrativeDivisionList.stream() .map(AdministrativeDivision::getUserNo) .collect(Collectors.toList()); } return list; } /** * 递归查询 * @param divisionNo * @return */ public List<Object> getRiverList(String divisionNo){ int countRiverChief = 0; int countSize = 0; List<Object> list = new ArrayList<Object>(); //查询下级所有河道 List<AdministrativeDivision> administrativeDivisionList = administrativeDivisionDao.selectParentDivisionNoListByRiver(divisionNo); if(administrativeDivisionList != null && administrativeDivisionList.size() > 0){ countSize += administrativeDivisionList.size(); for(AdministrativeDivision administrativeDivision : administrativeDivisionList){ String divisionNos = administrativeDivision.getDivisionNo(); //根据divisionNo查询下面的所有河长 countRiverChief += riverInfoBasisDao.countRiverChiefTotalByDivisionNo(divisionNos); List<Object> list1 = getRiverList(divisionNos); countSize += (int)list1.get(1); countRiverChief += (int)list1.get(0); } } list.add(countRiverChief); list.add(countSize); return list; } /** * 根据用户编号查询用户所属的区域 * @param request * @return */ @PostMapping(value = "river/getDivisionTreeByUserNos",produces = "application/json;charset=UTF-8") @ResponseBody @SysLog(value="根据用户编号查询用户所属的区域",actionType="4") public RespBodyObj<List<AdminnistrativeTree>> getDiviosionTreeByUserNos(HttpServletRequest request){ String userNo = request.getHeader("userNo"); //查询出系统管理员 List<Users> managers = restTemplateService.getSystemManager(); for (Users uu : managers){ if (uu.getLoginname().equals(userNo)){ userNo=null; } } List<AdminnistrativeTree> list1 = new ArrayList<>(); if (userNo==null){ List<AdministrativeDivision> administrativeDivisions = administrativeDivisionDao.listAll(); List<AdminnistrativeTree> result = getAdminnistrativeTrees(administrativeDivisions); list1 = buildTree(result); }else { List<AdministrativeDivision> divisionList = divisionOrgDao.getDivisionNoByUserNo(userNo); if (divisionList == null || divisionList.size() == 0) { List<AdministrativeDivision> administrativeDivisions = administrativeDivisionDao.listAll(); List<AdminnistrativeTree> result = getAdminnistrativeTrees(administrativeDivisions); list1 = buildTree(result); }else{ List<String> collect = divisionList.stream().map(AdministrativeDivision::getDivisionNo).collect(Collectors.toList()); List<AdministrativeDivision> result = new ArrayList<>(); List<AdministrativeDivision> root = administrativeDivisionDao.queryListByDivisionNos(collect); if(!root.isEmpty()){ result.addAll(root); } List<AdministrativeDivision> child = administrativeDivisionDao.listParent(collect); List<AdministrativeDivision> child2 = new ArrayList<>(); if(!child.isEmpty()){ List<String> collect2 = divisionList.stream().map(AdministrativeDivision::getDivisionNo).collect(Collectors.toList()); child2 = administrativeDivisionDao.listParent(collect2); result.addAll(child); } List<AdministrativeDivision> child3 = new ArrayList<>(); if(!child2.isEmpty()){ child3 = administrativeDivisionDao.listParent(child2.stream().map(AdministrativeDivision::getDivisionNo).collect(Collectors.toList())); result.addAll(child3); } List<AdministrativeDivision> child4 = new ArrayList<>(); if(!child3.isEmpty()){ child4 = administrativeDivisionDao.listParent(child3.stream().map(AdministrativeDivision::getDivisionNo).collect(Collectors.toList())); result.addAll(child4); } //Set<AdministrativeDivision> set = new HashSet<>(result); List<AdminnistrativeTree> result1 = getAdminnistrativeTrees(result); list1 = buildTree(result1); } } return RespBodyObj.ok(list1); } private List<AdminnistrativeTree> getAdminnistrativeTrees(List<AdministrativeDivision> administrativeDivisions) { List<AdminnistrativeTree> result = new ArrayList<>(); for (AdministrativeDivision division : administrativeDivisions) { AdminnistrativeTree tree = new AdminnistrativeTree(); tree.setId(division.getDivisionNo()); tree.setText(division.getDivisionName()); tree.setParentId(division.getParentDivisionNo()); result.add(tree); } return result; } /** * 递归程序 * @param divisionList * @return */ public List<Map<String,Object>> addChildren(List<AdministrativeDivision> divisionList){ List<Map<String,Object>> list = new ArrayList<>(); if (divisionList.size()>0){ for (AdministrativeDivision ad : divisionList){ Map<String,Object> map = new HashMap<>(); String id = ad.getDivisionNo(); String text = ad.getDivisionName(); map.put("id",id); map.put("text",text); AdministrativeDivisionQuery query = new AdministrativeDivisionQuery(); query.createCriteria().andParentDivisionNoEqualTo(id); List<AdministrativeDivision> childList = administrativeDivisionDao.selectByExample(query); if (childList.size()>0){ List<Map<String,Object>> newList = this.addChildren(childList); map.put("children",newList); } list.add(map); } } return list; } /** * 查询时用到的下拉框 * @param request * @return */ @PostMapping(value = "river/countRiverLevelGradeTotal", produces = "application/json;charset=utf-8") @ResponseBody @SysLog(value="查询时用到的下拉框",actionType="4") public RespBodyObj<List<Object>> countRiverGradeTotal(HttpServletRequest request){ JSONObject json = new JSONObject(); try{ String chiefUserNo = request.getHeader("userNo"); RiverChief riverChief = riverChiefDao.selectGradeByUserNo(chiefUserNo); List<Object> list = new ArrayList<Object>(); if(riverChief != null){ Integer chiefGrade = riverChief.getChiefGrade(); if(chiefGrade == 3){ for (int i=0;i<4;i++){ Map<Object,Object> map = new HashMap<Object,Object>(); if(i == 0){ map.put("riverGrade",i+3); map.put("riverGradeZn","县级河道"); list.add(map); }else if(i == 1){ map.put("riverGrade",i+3); map.put("riverGradeZn","镇级河道"); list.add(map); }else if(i == 2){ map.put("riverGrade",i+3); map.put("riverGradeZn","村级河道"); list.add(map); }else if(i == 3){ map.put("riverGrade",0); map.put("riverGradeZn","---全部---"); list.add(map); } } }else if(chiefGrade == 4){ for (int i=0;i<3;i++){ Map<Object,Object> map = new HashMap<Object,Object>(); if(i == 0){ map.put("riverGrade",i+4); map.put("riverGradeZn","镇级河道"); list.add(map); }else if(i == 1){ map.put("riverGrade",i+4); map.put("riverGradeZn","村级河道"); list.add(map); }else if(i == 2){ map.put("riverGrade",0); map.put("riverGradeZn","---全部---"); list.add(map); } } }else if(chiefGrade == 5){ Map<Object,Object> map = new HashMap<Object,Object>(); map.put("riverGrade",5); map.put("riverGradeZn","村级河道"); list.add(map); }else{ Map<Object,Object> map = new HashMap<Object,Object>(); map.put("查询出错",0); list.add(map); } }else{ Map<Object,Object> map = new HashMap<Object,Object>(); map.put("查询出错",0); list.add(map); } return RespBodyObj.ok(list); }catch(Exception e){ e.printStackTrace(); return RespBodyObj.error("查询失败"); } } /** * 按照行政区划编号查询河道名称以及河道编号 * @return */ @PostMapping(value = "river/selectParentNameNo", produces = "application/json;charset=utf-8") @ResponseBody @SysLog(value="按照行政区划编号查询河道名称以及河道编号",actionType="4") public RespBodyObj<List<Object>> selectParentNameNo(@RequestBody ReqBodyObj<AdministrativeDivision> params){ JSONObject json = new JSONObject(); List<Object> list = new ArrayList<Object>(); try{ //根据当前行政区划查询上级行政区划的河道编号 AdministrativeDivision administrativeDivision = administrativeDivisionDao.selectParentDivisionNo(params.getData().getDivisionNo()); if(administrativeDivision != null){ String parentDivisionNo = administrativeDivision.getParentDivisionNo(); if(parentDivisionNo != null){ List<RiverInfoBasis> riverInfoBasisList = riverInfoBasisDao.selectRiverParentRiverNo(parentDivisionNo); if(riverInfoBasisList != null && riverInfoBasisList.size() > 0){ for(RiverInfoBasis riverInfoBasis : riverInfoBasisList){ Map<Object,Object> map = new HashMap<Object,Object>(); String riverName = riverInfoBasis.getRiverName(); String riverNo = riverInfoBasis.getRiverNo(); map.put("riverName",riverName); map.put("parentRiverNo",riverNo); list.add(map); } } } } return RespBodyObj.ok(list); }catch(Exception e){ e.printStackTrace(); return RespBodyObj.error("查询失败"); } } /** * 按照用户编号查询河道名称以及河道编号 * @return */ @PostMapping(value = "river/selectParentNameNoByUserNo", produces = "application/json;charset=utf-8") @ResponseBody @SysLog(value="按照用户编号查询河道名称以及河道编号",actionType="4") public RespBodyObj<List<Object>> selectParentNameNoByUserNo(@RequestBody ReqBodyObj<AdministrativeDivision> params){ JSONObject json = new JSONObject(); List<Object> list = new ArrayList<Object>(); try{ //根据当前行政区划查询上级行政区划的河道编号 AdministrativeDivision administrativeDivision = administrativeDivisionDao.selectParentDivisionNo(params.getData().getDivisionNo()); if(administrativeDivision != null){ String parentDivisionNo = administrativeDivision.getParentDivisionNo(); if(parentDivisionNo != null){ List<RiverInfoBasis> riverInfoBasisList = riverInfoBasisDao.selectRiverParentRiverNo(parentDivisionNo); if(riverInfoBasisList != null && riverInfoBasisList.size() > 0){ for(RiverInfoBasis riverInfoBasis : riverInfoBasisList){ Map<Object,Object> map = new HashMap<Object,Object>(); String riverName = riverInfoBasis.getRiverName(); String riverNo = riverInfoBasis.getRiverNo(); map.put("riverName",riverName); map.put("parentRiverNo",riverNo); list.add(map); } } } } return RespBodyObj.ok(list); }catch(Exception e){ e.printStackTrace(); return RespBodyObj.error("查询失败"); } } /** * 业务管理--河道信息--根据河道等级查询未分配的河长(从河长简介表查询) * @return */ @PostMapping(value = "river/selectUserNoUserNameByRiverGrade", produces = "application/json;charset=utf-8") @ResponseBody @SysLog(value="业务管理--河道信息--根据河道等级查询未分配的河长(从河长简介表查询)",actionType="4") public RespBodyObj<List<Object>> selectUserNoUserNameByRiverGrade(@RequestBody ReqBodyObj<RiverChiefInformation> params){ JSONObject json = new JSONObject(); List<Object> list = new ArrayList<Object>(); try{ List<RiverChiefInformation> riverChiefInformationList = riverChiefInformationDao.selectUserNoUserNameByRiverGrade(params.getData().getRiverGrade()); if(riverChiefInformationList != null && riverChiefInformationList.size() > 0){ for(RiverChiefInformation riverChiefInformation : riverChiefInformationList){ Map<String,String> map = new HashMap<String,String>(); String chiefUserNo = riverChiefInformation.getChiefUserNo(); String chiefUserName = riverChiefInformation.getChiefUserName(); map.put("chiefUserNo",chiefUserNo); map.put("chiefUserName",chiefUserName); list.add(map); } }else{ return RespBodyObj.error("暂无河长可分配"); } return RespBodyObj.ok(list); }catch(Exception e){ e.printStackTrace(); return RespBodyObj.error("查询失败"); } } /** * 根据站点编号和因子名称查询水质历史数据 * @return */ @PostMapping(value = "river/selectWaterQualityMessageHistoryByFieldName", produces = "application/json;charset=utf-8") @ResponseBody @SysLog(value="根据站点编号和因子名称查询水质历史数据",actionType="4") public RespBodyObj<List<WaterQuality>> selectWaterQualityMessageHistoryByFieldName(@RequestBody ReqBodyObj<WaterQuality> params){ try{ List<WaterQuality> waterQualityList = riverInfoBasisDao.selectWaterQualityMessageHistoryByFieldName(params.getData().getSiteNo(),params.getData().getFieldName()); return RespBodyObj.ok(waterQualityList); }catch(Exception e){ e.printStackTrace(); return RespBodyObj.error("查询失败"); } } /** * 查询河流树形 * @return */ @PostMapping("river/selectRiverTree") @ResponseBody public RespBodyObj selectRiverTree(){ List<Tree> Tree = new ArrayList<>(); //一级河流的编号为0 Tree = getRiverTree("0"); return RespBodyObj.ok(Tree); } /** * 根据父级河道编号查询子级 * @param parentRiverNo * @return */ public List<Tree> getRiverTree(String parentRiverNo){ List<Tree> tree = new ArrayList<>(); List<RiverInfoBasis> riverList = riverInfoBasisDao.selectByParentNo(parentRiverNo); if (riverList != null){ for (RiverInfoBasis river : riverList) { Tree tree1 = new Tree(); String id = river.getRiverNo(); tree1.setId(river.getRiverNo()); tree1.setText(river.getRiverName()); List<Tree> children = getRiverTree(id); if (children != null){ tree1.setChildren(children); } tree.add(tree1); } } return tree; } public static List<AdminnistrativeTree> buildTree(List<AdminnistrativeTree> treeList) { if (CollUtil.isEmpty(treeList)) { return new ArrayList<>(); } //记录自己是自己的父节点的id集合 List<Serializable> selfIdEqSelfParent = new ArrayList<>(); // 为每一个节点找到子节点集合 for (AdminnistrativeTree parent : treeList) { for (AdminnistrativeTree children : treeList) { if (parent != children) { //parent != children 这个来判断自己的孩子不允许是自己,因为有时候,根节点的parent会被设置成为自己 if (parent.getId().equals(children.getParentId())) { parent.initChildren(); parent.getChildren().add(children); } } else if (parent.getId().equals(parent.getParentId())) { selfIdEqSelfParent.add(parent.getId()); } } } // 找出根节点集合 List<AdminnistrativeTree> trees = new ArrayList<>(); List<? extends Serializable> allIds = treeList.stream().map(node -> node.getId()).collect(Collectors.toList()); for (AdminnistrativeTree baseNode : treeList) { if (!allIds.contains(baseNode.getParentId()) || selfIdEqSelfParent.contains(baseNode.getParentId())) { trees.add(baseNode); } } return trees; } }