|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 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.pipIrrBase.role.RoleSv; | 
|---|
|  |  |  | import com.dy.pipIrrBase.user.QueryVo; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.pojoBa.BaClientType; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.pojoBa.BaClientType; | 
|---|
|  |  |  | 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.List; | 
|---|
|  |  |  | import java.util.Objects; | 
|---|
|  |  |  | 
|---|
|  |  |  | ) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @GetMapping(path = "all") | 
|---|
|  |  |  | @SsoAop("-1") | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<QueryResultVo<List<BaClientType>>> all(){ | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | QueryResultVo<List<BaClientType>> res = this.sv.selectAll() ; | 
|---|
|  |  |  | 
|---|
|  |  |  | schema = @Schema(implementation = BaClientType.class))} | 
|---|
|  |  |  | ) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @PostMapping(path = "some", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) | 
|---|
|  |  |  | @SsoAop("-1") | 
|---|
|  |  |  | public BaseResponse<QueryResultVo<List<BaClientType>>> some(@Parameter(description = "查询form表单数据", required = true) @Valid QueryVo vo){ | 
|---|
|  |  |  | @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); | 
|---|
|  |  |  | 
|---|
|  |  |  | schema = @Schema(implementation = BaClientType.class))} | 
|---|
|  |  |  | ) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @GetMapping(path = "one") | 
|---|
|  |  |  | @SsoAop("-1") | 
|---|
|  |  |  | public BaseResponse<BaClientType> one(@Parameter(description = "实体id", required = true) Long id){ | 
|---|
|  |  |  | @GetMapping(path = "one", consumes = MediaType.TEXT_PLAIN_VALUE) | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<BaClientType> 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 BaClientType po, @Parameter(hidden = true) BindingResult bindingResult){ | 
|---|
|  |  |  | @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()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | 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 BaClientType po, @Parameter(hidden = true) BindingResult bindingResult){ | 
|---|
|  |  |  | @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()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | ) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @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不能为空") ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 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("数据库存储失败") ; | 
|---|
|  |  |  | Long clientCount = this.sv.selectClientByType(id) ; | 
|---|
|  |  |  | if(clientCount > 0){ | 
|---|
|  |  |  | return BaseResponseUtils.buildFail("删除失败,存在" + clientCount + "个农户归属此类型,该类型不能被删除") ; | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(true) ; | 
|---|
|  |  |  | 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) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|