| New file | 
|  |  |  | 
|---|
|  |  |  | package com.dy.pipIrrBase.client; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.dy.common.aop.SsoAop; | 
|---|
|  |  |  | 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 io.swagger.v3.oas.annotations.Operation; | 
|---|
|  |  |  | 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 io.swagger.v3.oas.annotations.responses.ApiResponses; | 
|---|
|  |  |  | import io.swagger.v3.oas.annotations.tags.Tag; | 
|---|
|  |  |  | import jakarta.validation.Valid; | 
|---|
|  |  |  | import lombok.extern.slf4j.Slf4j; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.http.MediaType; | 
|---|
|  |  |  | import org.springframework.validation.BindingResult; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Objects; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Slf4j | 
|---|
|  |  |  | @Tag(name = "农户管理", description = "农户增删改查等操作") | 
|---|
|  |  |  | @RestController | 
|---|
|  |  |  | @RequestMapping(path="client") | 
|---|
|  |  |  | @SuppressWarnings("unchecked")//java版本越高,对泛型约束越严,所以配置SuppressWarnings("unchecked") | 
|---|
|  |  |  | public class ClientCtrl { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private ClientSv sv ; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private void setSv(ClientSv sv){ | 
|---|
|  |  |  | this.sv = sv ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 客户端请求得到所有农户数据 | 
|---|
|  |  |  | * @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))} | 
|---|
|  |  |  | ) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @PostMapping(path = "some", consumes = MediaType.APPLICATION_JSON_VALUE) | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<QueryResultVo<List<BaClient>>> some(@RequestBody QueryVo vo){ | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | QueryResultVo<List<BaClient>> res = this.sv.selectSome(vo) ; | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(res); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.error("查询农户异常", e); | 
|---|
|  |  |  | return BaseResponseUtils.buildException(e.getMessage()) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 得到一个农户数据 | 
|---|
|  |  |  | * @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 = BaClient.class))} | 
|---|
|  |  |  | ) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @GetMapping(path = "one", consumes = MediaType.TEXT_PLAIN_VALUE) | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<BaClient> one(Long id){ | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(this.sv.selectById(id)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 保存农户 | 
|---|
|  |  |  | * @param po 保存农户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 = "save", consumes = MediaType.APPLICATION_JSON_VALUE) | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<Boolean> save(@RequestBody @Valid BaClient po, BindingResult bindingResult){ | 
|---|
|  |  |  | if(bindingResult != null && bindingResult.hasErrors()){ | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | po.id = null ; | 
|---|
|  |  |  | int count; | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | 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 po 保存农户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.APPLICATION_JSON_VALUE) | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<Boolean> update(@RequestBody @Valid BaClient po, BindingResult bindingResult){ | 
|---|
|  |  |  | if(bindingResult != null && bindingResult.hasErrors()){ | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(po.id == null){ | 
|---|
|  |  |  | return BaseResponseUtils.buildFail("无数据实体ID") ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 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() | 
|---|
|  |  |  | public BaseResponse<Boolean> delete(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) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|