| package com.dy.pipIrrBase.clientType; | 
|   | 
|   | 
| 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.pipIrrBase.user.QueryVo; | 
| import com.dy.pipIrrGlobal.pojoBa.BaClientType; | 
| 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="clientType") | 
| @SuppressWarnings("unchecked")//java版本越高,对泛型约束越严,所以配置SuppressWarnings("unchecked") | 
| public class ClientTypeCtrl { | 
|   | 
|     private ClientTypeSv sv ; | 
|   | 
|     @Autowired | 
|     private void setSv(ClientTypeSv 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 = BaClientType.class))} | 
|             ) | 
|     }) | 
|     @GetMapping(path = "all") | 
|     @SsoAop() | 
|     public BaseResponse<QueryResultVo<List<BaClientType>>> all(){ | 
|         try { | 
|             QueryResultVo<List<BaClientType>> res = this.sv.selectAll() ; | 
|             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:QueryResultVo[{}])", | 
|                     content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, | 
|                             schema = @Schema(implementation = BaClientType.class))} | 
|             ) | 
|     }) | 
|     @PostMapping(path = "some", consumes = MediaType.APPLICATION_JSON_VALUE) | 
|     @SsoAop() | 
|     public BaseResponse<QueryResultVo<List<BaClientType>>> some(@RequestBody @Valid QueryVo vo){ | 
|         try { | 
|             QueryResultVo<List<BaClientType>> 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 = BaClientType.class))} | 
|             ) | 
|     }) | 
|     @GetMapping(path = "one", consumes = MediaType.TEXT_PLAIN_VALUE) | 
|     @SsoAop() | 
|     public BaseResponse<BaClientType> 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 BaClientType 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 BaClientType 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不能为空") ; | 
|         } | 
|         Long clientCount = this.sv.selectClientByType(id) ; | 
|         if(clientCount > 0){ | 
|             return BaseResponseUtils.buildFail("删除失败,存在" + clientCount + "个农户归属此类型,该类型不能被删除") ; | 
|         }else{ | 
|             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) ; | 
|             } | 
|         } | 
|     } | 
|   | 
| } |