| package com.dy.pipIrrProject.video; | 
|   | 
| 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.pojoVi.ViCamera; | 
| import com.dy.pipIrrGlobal.voVi.VoCamera; | 
| 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.RequiredArgsConstructor; | 
| 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.ArrayList; | 
| import java.util.List; | 
| import java.util.Objects; | 
|   | 
| /** | 
|  * @Author: liurunyu | 
|  * @Date: 2025/6/9 9:01 | 
|  * @Description | 
|  */ | 
| @Slf4j | 
| @Tag(name = "视频站管理", description = "视频站管理") | 
| @RestController | 
| @RequestMapping(path = "camera") | 
| @RequiredArgsConstructor | 
| public class CameraCtrl { | 
|     private CameraSv sv; | 
|   | 
|     @Autowired | 
|     private void setSv(CameraSv sv){ | 
|         this.sv = sv ; | 
|     } | 
|   | 
|     /** | 
|      * 客户端请求得到所有摄像机类型 | 
|      * @return 所有摄像机类型 | 
|      */ | 
|     @Operation(summary = "获得全部摄像机类型", description = "返回全部摄像机类型") | 
|     @ApiResponses(value = { | 
|             @ApiResponse( | 
|                     responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, | 
|                     description = "返回全部摄像机类型数据(BaseResponse.content:TypesVo[{}])", | 
|                     content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, | 
|                             schema = @Schema(implementation = TypesVo.class))} | 
|             ) | 
|     }) | 
|     @GetMapping(path = "types") | 
|     @SsoAop() | 
|     public BaseResponse<QueryResultVo<List<TypesVo>>> types() { | 
|         try { | 
|             List<TypesVo> list = new ArrayList<>() ; | 
|             if(CameraTypesConfig.types != null && CameraTypesConfig.types.size() > 0){ | 
|                 for (String type : CameraTypesConfig.types) { | 
|                     String[] typeGrp = type.split(","); | 
|                     if(typeGrp.length == 2){ | 
|                         TypesVo vo = new TypesVo() ; | 
|                         vo.type = Integer.parseInt(typeGrp[0].trim()) ; | 
|                         vo.name = typeGrp[1].trim() ; | 
|                         list.add(vo) ; | 
|                     } | 
|                 } | 
|             } | 
|             QueryResultVo<List<TypesVo>> res = new QueryResultVo() ; | 
|             res.obj = list ; | 
|             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 = VoCamera.class))} | 
|             ) | 
|     }) | 
|     @GetMapping(path = "some") | 
|     @SsoAop() | 
|     public BaseResponse<QueryResultVo<List<VoCamera>>> some(CameraQo vo){ | 
|         try { | 
|             QueryResultVo<List<VoCamera>> res = this.sv.some(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 = ViCamera.class))} | 
|             ) | 
|     }) | 
|     @GetMapping(path = "one") | 
|     @SsoAop() | 
|     public BaseResponse<ViCamera> one(Long id){ | 
|         return BaseResponseUtils.buildSuccess(this.sv.selectById(id)); | 
|     } | 
|   | 
|     /** | 
|      * 保存摄像机 | 
|      * @param dto 保存摄像机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 CameraDto dto, BindingResult bindingResult){ | 
|         if(bindingResult != null && bindingResult.hasErrors()){ | 
|             return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
|         } | 
|         ViCamera po = dto.toNewPo() ; | 
|         po.deleted = 0 ; | 
|         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 dto 保存摄像机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 CameraDto dto, BindingResult bindingResult){ | 
|         if(bindingResult != null && bindingResult.hasErrors()){ | 
|             return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
|         } | 
|         ViCamera po = dto.toPo() ; | 
|         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") | 
|     @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) ; | 
|         } | 
|     } | 
|   | 
|   | 
| } |