| | |
| | | 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.ResultCodeMsg; |
| | |
| | | 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; |
| | |
| | | }) |
| | | @GetMapping(path = "allLevel") |
| | | public BaseResponse<List<DistrictLevel>> allDistrictLevels(){ |
| | | List<DistrictLevel> list = Arrays.asList(DistrictLevel.City, DistrictLevel.County, DistrictLevel.Town, DistrictLevel.Village, DistrictLevel.Group) ; |
| | | List<DistrictLevel> list = Arrays.asList(DistrictLevel.City, DistrictLevel.County, DistrictLevel.Town, DistrictLevel.Village) ; |
| | | return BaseResponseUtils.buildSuccess(list); |
| | | } |
| | | |
| | | /** |
| | | * 客户端请求得到所有行政区数据 |
| | | * @return 所有行政区数据 |
| | | */ |
| | | @Operation(summary = "获得所有行政区", description = "返回所有行政区数据") |
| | | @ApiResponses(value = { |
| | | @ApiResponse( |
| | | responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, |
| | | description = "返回所有行政区数据(BaseResponse.content:[{}])", |
| | | content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, |
| | | schema = @Schema(implementation = BaDistrict.class))} |
| | | ) |
| | | }) |
| | | @GetMapping(path = "all") |
| | | @SsoAop("-1") |
| | | public BaseResponse<List<BaDistrict>> all(){ |
| | | List<BaDistrict> list = this.sv.selectAllByLevel(DistrictLevel.City.code) ; |
| | | return BaseResponseUtils.buildSuccess(list); |
| | | } |
| | | |
| | | /** |
| | | * 得到一个行政区数据 |
| | | * @return 一个行政区数据 |
| | | */ |
| | | @Operation(summary = "一个行政区", description = "得到一个行政区数据") |
| | | @ApiResponses(value = { |
| | | @ApiResponse( |
| | | responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, |
| | | description = "返回一个行政区数据(BaseResponse.content:{})", |
| | | content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, |
| | | schema = @Schema(implementation = BaDistrict.class))} |
| | | ) |
| | | }) |
| | | @GetMapping(path = "one") |
| | | @SsoAop("-1") |
| | | public BaseResponse<BaDistrict> one(@Parameter(description = "实体id", required = true) Long id){ |
| | | return BaseResponseUtils.buildSuccess(this.sv.selectById(id)); |
| | | } |
| | | |
| | | /** |
| | | * 保存行政区 |
| | |
| | | @ApiResponses(value = { |
| | | @ApiResponse( |
| | | responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, |
| | | description = "保存行政区返回:true:成功,false:失败(数据基类的content)", |
| | | description = "操作结果:true:成功,false:失败(BaseResponse.content)", |
| | | content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, |
| | | schema = @Schema(implementation = Boolean.class))} |
| | | ) |
| | |
| | | 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); |
| | | return BaseResponseUtils.buildException(e.getMessage()) ; |
| | | } |
| | | if(count <= 0){ |
| | | return BaseResponseUtils.buildFail("数据库存储失败") ; |
| | | }else{ |
| | | return BaseResponseUtils.buildSuccess(true) ; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 编辑修改行政区 |
| | | * @param vo 保存行政区form表单对象 |
| | | * @return 是否成功 |
| | | */ |
| | | @Operation(summary = "编辑修改行政区", description = "提交行政区数据(form表单),进行修改") |
| | | @ApiResponses(value = { |
| | | @ApiResponse( |
| | | responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, |
| | | description = "操作结果:true:成功,false:失败(BaseResponse.content)", |
| | | content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, |
| | | 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){ |
| | | if(bindingResult != null && bindingResult.hasErrors()){ |
| | | return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); |
| | | } |
| | | BaDistrict po = DistrictVoMapper.INSTANCT.convert(vo); |
| | | int count; |
| | | try { |
| | | count = this.sv.update(po); |
| | | } catch (Exception e) { |
| | | log.error("保存行政区异常", e); |
| | | return BaseResponseUtils.buildException(e.getMessage()) ; |
| | | } |
| | | if(count <= 0){ |
| | | return BaseResponseUtils.buildFail("数据库存储失败") ; |
| | | }else{ |
| | | return BaseResponseUtils.buildSuccess(true) ; |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 删除行政区 |
| | | * @param id 行政区ID |
| | | * @return 是否成功 |
| | | */ |
| | | @Operation(summary = "删除行政区", description = "提交行政区ID,进行逻辑删除") |
| | | @ApiResponses(value = { |
| | | @ApiResponse( |
| | | responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, |
| | | description = "操作结果:true:成功,false:失败(BaseResponse.content)", |
| | | content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, |
| | | schema = @Schema(implementation = Boolean.class))} |
| | | ) |
| | | }) |
| | | @GetMapping(path = "delete", consumes = MediaType.TEXT_PLAIN_VALUE) |
| | | @SsoAop("-1")//@SsoAop(power = "-1") |
| | | public BaseResponse<Boolean> delete(@Parameter(description = "实体id", required = true) Long id){ |
| | | if(id == null){ |
| | | return BaseResponseUtils.buildFail("id不能为空") ; |
| | | } |
| | | int count; |
| | | try { |
| | | count = this.sv.delete(id); |
| | | } catch (Exception e) { |
| | | log.error("保存行政区异常", e); |
| | | return BaseResponseUtils.buildException(e.getMessage()) ; |
| | | } |
| | | if(count <= 0){ |
| | | return BaseResponseUtils.buildFail("数据库存储失败") ; |
| | | }else{ |
| | | return BaseResponseUtils.buildSuccess(true) ; |
| | | } |