|  |  | 
 |  |  | package com.dy.pipIrrBase.district; | 
 |  |  |  | 
 |  |  | import com.alibaba.fastjson2.JSON; | 
 |  |  | import com.alibaba.fastjson2.JSONArray; | 
 |  |  | import com.alibaba.fastjson2.JSONObject; | 
 |  |  | import com.dy.common.aop.SsoAop; | 
 |  |  | import com.dy.common.mybatis.envm.Deleted; | 
 |  |  | import com.dy.common.webUtil.BaseResponse; | 
 |  |  | 
 |  |  |         } | 
 |  |  |         return BaseResponseUtils.buildSuccess(map_Districts); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 获取三级行政区划 | 
 |  |  |      * @return 县镇村三级行政区划 | 
 |  |  |      */ | 
 |  |  |     @GetMapping(path = "/three") | 
 |  |  |     @SsoAop() | 
 |  |  |     public BaseResponse<QueryResultVo<List<Map<String, Object>>>> getThreeDistrict() { | 
 |  |  |         JSONArray array_counties = new JSONArray(); | 
 |  |  |         JSONArray array_towns = new JSONArray(); | 
 |  |  |         JSONArray array_villages = new JSONArray(); | 
 |  |  |  | 
 |  |  |         List<Map<String, Object>> list_counties = Optional.ofNullable(sv.getDistrictgsByLevel(2)).orElse(new ArrayList<>()); | 
 |  |  |         if(list_counties.size() > 0) { | 
 |  |  |             array_counties = JSONArray.parseArray(JSON.toJSONString(list_counties)); | 
 |  |  |             // 遍历每一个县,将县下的镇村加到县的子集 | 
 |  |  |             for(int i = 0; i < array_counties.size(); i++) { | 
 |  |  |                 JSONObject job_county = array_counties.getJSONObject(i); | 
 |  |  |                     Long countyId = job_county.getLong("id"); | 
 |  |  |                     List<Map<String, Object>> list_towns = Optional.ofNullable(sv.getDistrictsBySupperId(countyId)).orElse(new ArrayList<>()); | 
 |  |  |                     if(list_towns.size() > 0) { | 
 |  |  |                         array_towns = JSONArray.parseArray(JSON.toJSONString(list_towns)); | 
 |  |  |                         // 遍历每一个镇,将镇下村列表加到镇的子集 | 
 |  |  |                         for(int j = 0; j < array_towns.size(); j++) { | 
 |  |  |                             JSONObject job_town = array_towns.getJSONObject(j); | 
 |  |  |                             Long townId = job_town.getLong("id"); | 
 |  |  |                             List<Map<String, Object>> list_villages = Optional.ofNullable(sv.getDistrictsBySupperId(townId)).orElse(new ArrayList<>()); | 
 |  |  |                             if(list_villages.size() > 0) { | 
 |  |  |                                 array_villages = JSONArray.parseArray(JSON.toJSONString(list_villages)); | 
 |  |  |                                 job_town.put("children", array_villages); | 
 |  |  |                             } | 
 |  |  |                         } | 
 |  |  |                         //System.out.println("----" + array_towns); | 
 |  |  |                     } | 
 |  |  |                     // 镇村组装完毕,将镇村加到县下 | 
 |  |  |                     job_county.put("children", array_towns); | 
 |  |  |             } | 
 |  |  |             // 县组装完毕 | 
 |  |  |             //String a = array_counties.toJSONString(); | 
 |  |  |             //System.out.println(a); | 
 |  |  |             return BaseResponseUtils.buildSuccess(array_counties); | 
 |  |  |         }else { | 
 |  |  |             return BaseResponseUtils.buildFail("县级行政区划不存在"); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |         //return BaseResponseUtils.buildSuccess(); | 
 |  |  |     } | 
 |  |  | } |