|  |  |  | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  | import com.dy.common.webUtil.BaseResponseUtils; | 
|---|
|  |  |  | import com.dy.common.webUtil.QueryResultVo; | 
|---|
|  |  |  | import com.dy.common.webUtil.ResultCodeMsg; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.pojoBa.BaClient; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.pojoBa.BaDistrict; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.util.DistrictLevel; | 
|---|
|  |  |  | import io.swagger.v3.oas.annotations.Operation; | 
|---|
|  |  |  | import io.swagger.v3.oas.annotations.Parameter; | 
|---|
|  |  |  | import io.swagger.v3.oas.annotations.media.Content; | 
|---|
|  |  |  | import io.swagger.v3.oas.annotations.media.Schema; | 
|---|
|  |  |  | import io.swagger.v3.oas.annotations.responses.ApiResponse; | 
|---|
|  |  |  | 
|---|
|  |  |  | import org.springframework.validation.BindingResult; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.Arrays; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Objects; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Slf4j | 
|---|
|  |  |  | @Tag(name = "行政区划管理", description = "行政区划增删改查等操作") | 
|---|
|  |  |  | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @GetMapping(path = "allLevel") | 
|---|
|  |  |  | public BaseResponse<List<DistrictLevel>> allDistrictLevels(){ | 
|---|
|  |  |  | List<DistrictLevel> list = Arrays.asList(DistrictLevel.City, DistrictLevel.County, DistrictLevel.Town, DistrictLevel.Village) ; | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(list); | 
|---|
|  |  |  | //List<DistrictLevel> list = Arrays.asList(DistrictLevel.City, DistrictLevel.County, DistrictLevel.Town, DistrictLevel.Village) ; | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(DistrictLevel.LevelList); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  | ) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @GetMapping(path = "all") | 
|---|
|  |  |  | @SsoAop("-1") | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<List<BaDistrict>> all(){ | 
|---|
|  |  |  | List<BaDistrict> list = this.sv.selectAllByLevel(DistrictLevel.City.code) ; | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(list); | 
|---|
|  |  |  | 
|---|
|  |  |  | ) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @GetMapping(path = "one", consumes = MediaType.TEXT_PLAIN_VALUE) | 
|---|
|  |  |  | @SsoAop("-1") | 
|---|
|  |  |  | public BaseResponse<BaDistrict> one(@Parameter(description = "实体id", required = true) Long id){ | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<BaDistrict> one(Long id){ | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(this.sv.selectById(id)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | ) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @PostMapping(path = "save", consumes = MediaType.APPLICATION_JSON_VALUE) | 
|---|
|  |  |  | @SsoAop("-1")//@SsoAop(power = "-1") | 
|---|
|  |  |  | public BaseResponse<Boolean> save(@RequestBody @Parameter(description = "form表单json数据", required = true) @Valid DistrictVo vo, @Parameter(hidden = true) BindingResult bindingResult){ | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<Boolean> save(@RequestBody @Valid DistrictVo vo, BindingResult bindingResult){ | 
|---|
|  |  |  | if(bindingResult != null && bindingResult.hasErrors()){ | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | ) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @PostMapping(path = "update", consumes = MediaType.APPLICATION_JSON_VALUE) | 
|---|
|  |  |  | @SsoAop("-1")//@SsoAop(power = "-1") | 
|---|
|  |  |  | public BaseResponse<Boolean> update(@RequestBody @Parameter(description = "form表单json数据", required = true) @Valid DistrictVo vo, @Parameter(hidden = true) BindingResult bindingResult){ | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<Boolean> update(@RequestBody @Valid DistrictVo vo, BindingResult bindingResult){ | 
|---|
|  |  |  | if(bindingResult != null && bindingResult.hasErrors()){ | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | ) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @GetMapping(path = "delete", consumes = MediaType.TEXT_PLAIN_VALUE) | 
|---|
|  |  |  | @SsoAop("-1")//@SsoAop(power = "-1") | 
|---|
|  |  |  | public BaseResponse<Boolean> delete(@Parameter(description = "实体id", required = true) Long id){ | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<Boolean> delete(Long id){ | 
|---|
|  |  |  | if(id == null){ | 
|---|
|  |  |  | return BaseResponseUtils.buildFail("id不能为空") ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(true) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 根据级别获取行政区划列表 | 
|---|
|  |  |  | * @param id | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Operation(summary = "获得行政区划列表", description = "返回行政区划列表") | 
|---|
|  |  |  | @ApiResponses(value = { | 
|---|
|  |  |  | @ApiResponse( | 
|---|
|  |  |  | responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, | 
|---|
|  |  |  | description = "返回一页农户数据(BaseResponse.content:QueryResultVo[{}])", | 
|---|
|  |  |  | content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, | 
|---|
|  |  |  | schema = @Schema(implementation = BaClient.class))} | 
|---|
|  |  |  | ) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @GetMapping(path = "/level/{id}") | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<QueryResultVo<List<Map<String, Object>>>> getDistrictgsByLevel(@PathVariable("id") Integer id){ | 
|---|
|  |  |  | if(id == null || id <= 0){ | 
|---|
|  |  |  | return BaseResponseUtils.buildFail("id不能为空") ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Map<String, Object>> map_Districts = Optional.ofNullable(sv.getDistrictgsByLevel(id)).orElse(new ArrayList<>()); | 
|---|
|  |  |  | if(map_Districts == null || map_Districts.size() == 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail("您输入的层级有误") ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(map_Districts); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 根据父ID获取行政区划列表 | 
|---|
|  |  |  | * @param supperId | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Operation(summary = "获得行政区划列表", description = "返回行政区划列表") | 
|---|
|  |  |  | @ApiResponses(value = { | 
|---|
|  |  |  | @ApiResponse( | 
|---|
|  |  |  | responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, | 
|---|
|  |  |  | description = "返回一页农户数据(BaseResponse.content:QueryResultVo[{}])", | 
|---|
|  |  |  | content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, | 
|---|
|  |  |  | schema = @Schema(implementation = BaClient.class))} | 
|---|
|  |  |  | ) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @GetMapping(path = "/supperid/{supperId}") | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<QueryResultVo<List<Map<String, Object>>>> getDistrictsBySupperId(@PathVariable("supperId") Long supperId){ | 
|---|
|  |  |  | if(supperId == null || supperId <= 0){ | 
|---|
|  |  |  | return BaseResponseUtils.buildFail("父ID不能为空") ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Map<String, Object>> map_Districts = Optional.ofNullable(sv.getDistrictsBySupperId(supperId)).orElse(new ArrayList<>()); | 
|---|
|  |  |  | if(map_Districts == null || map_Districts.size() == 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail("您输入的父级ID有误") ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 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(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|