| | |
| | | package com.dy.pipIrrBase.district; |
| | | |
| | | 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.beans.factory.annotation.Autowired; |
| | | import org.springframework.http.MediaType; |
| | | import org.springframework.validation.BindingResult; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | 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, DistrictLevel.Group) ; |
| | | 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() |
| | | public BaseResponse<List<BaDistrict>> all(){ |
| | | List<BaDistrict> list = this.sv.selectAllByLevel(DistrictLevel.City.code) ; |
| | | return BaseResponseUtils.buildSuccess(list); |
| | |
| | | schema = @Schema(implementation = BaDistrict.class))} |
| | | ) |
| | | }) |
| | | @GetMapping(path = "one") |
| | | public BaseResponse<BaDistrict> one(@Parameter(description = "实体id", required = true) Long id){ |
| | | @GetMapping(path = "one", consumes = MediaType.TEXT_PLAIN_VALUE) |
| | | @SsoAop() |
| | | public BaseResponse<BaDistrict> one(Long id){ |
| | | return BaseResponseUtils.buildSuccess(this.sv.selectById(id)); |
| | | } |
| | | |
| | |
| | | schema = @Schema(implementation = Boolean.class))} |
| | | ) |
| | | }) |
| | | @PostMapping(path = "save", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) |
| | | @SsoAop("-1")//@SsoAop(power = "-1") |
| | | public BaseResponse<Boolean> save(@Parameter(description = "form表单数据", required = true) @Valid DistrictVo vo, @Parameter(hidden = true) BindingResult bindingResult){ |
| | | @PostMapping(path = "save", consumes = MediaType.APPLICATION_JSON_VALUE) |
| | | @SsoAop() |
| | | public BaseResponse<Boolean> save(@RequestBody @Valid DistrictVo vo, BindingResult bindingResult){ |
| | | if(bindingResult != null && bindingResult.hasErrors()){ |
| | | return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); |
| | | } |
| | | BaDistrict po = DistrictVoMapper.INSTANCT.convert(vo); |
| | | int count; |
| | | try { |
| | | BaDistrict supperPo = this.sv.selectById(po.supperId) ; |
| | | if(supperPo == null){ |
| | | return BaseResponseUtils.buildFail("出错,未得到上级行政区") ; |
| | | }else{ |
| | | po.level = DistrictLevel.get((byte)(supperPo.level.code + 1)) ; |
| | | } |
| | | po.deleted = Deleted.NO ; |
| | | count = this.sv.save(po); |
| | | } catch (Exception e) { |
| | | log.error("保存行政区异常", e); |
| | |
| | | schema = @Schema(implementation = Boolean.class))} |
| | | ) |
| | | }) |
| | | @PostMapping(path = "update", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) |
| | | @SsoAop("-1")//@SsoAop(power = "-1") |
| | | public BaseResponse<Boolean> update(@Parameter(description = "form表单数据", required = true) @Valid DistrictVo vo, @Parameter(hidden = true) BindingResult bindingResult){ |
| | | @PostMapping(path = "update", consumes = MediaType.APPLICATION_JSON_VALUE) |
| | | @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); |
| | | } |
| | | } |