package com.klp.controller; import java.util.List; import java.util.Arrays; import lombok.RequiredArgsConstructor; import javax.servlet.http.HttpServletResponse; import javax.validation.constraints.*; import cn.dev33.satoken.annotation.SaCheckPermission; import org.springframework.web.bind.annotation.*; import org.springframework.validation.annotation.Validated; import com.klp.common.annotation.RepeatSubmit; import com.klp.common.annotation.Log; import com.klp.common.core.controller.BaseController; import com.klp.common.core.domain.PageQuery; import com.klp.common.core.domain.R; import com.klp.common.core.validate.AddGroup; import com.klp.common.core.validate.EditGroup; import com.klp.common.enums.BusinessType; import com.klp.common.utils.poi.ExcelUtil; import com.klp.domain.vo.WmsCameraManagementVo; import com.klp.domain.bo.WmsCameraManagementBo; import com.klp.service.IWmsCameraManagementService; import com.klp.common.core.page.TableDataInfo; import com.klp.common.config.CameraConfig; /** * 摄像头管理 * * @author Joshi * @date 2025-08-07 */ @Validated @RequiredArgsConstructor @RestController @RequestMapping("/wms/cameraManagement") public class WmsCameraManagementController extends BaseController { private final IWmsCameraManagementService iWmsCameraManagementService; private final CameraConfig cameraConfig; /** * 查询摄像头管理列表 */ @GetMapping("/list") public TableDataInfo list(WmsCameraManagementBo bo, PageQuery pageQuery) { return iWmsCameraManagementService.queryPageList(bo, pageQuery); } /** * 导出摄像头管理列表 */ @Log(title = "摄像头管理", businessType = BusinessType.EXPORT) @PostMapping("/export") public void export(WmsCameraManagementBo bo, HttpServletResponse response) { List list = iWmsCameraManagementService.queryList(bo); ExcelUtil.exportExcel(list, "摄像头管理", WmsCameraManagementVo.class, response); } /** * 获取摄像头管理详细信息 * * @param cameraId 主键 */ @GetMapping("/{cameraId}") public R getInfo(@NotNull(message = "主键不能为空") @PathVariable Long cameraId) { return R.ok(iWmsCameraManagementService.queryById(cameraId)); } /** * 获取摄像头FLV流地址(前端可用flv.js播放) */ @GetMapping("/stream/{cameraId}") public R getCameraStream(@PathVariable Long cameraId) { WmsCameraManagementVo camera = iWmsCameraManagementService.queryById(cameraId); if (camera == null) { return R.fail("摄像头不存在"); } // 组装ZLMediaKit的FLV播放地址 String app = "live"; String stream = camera.getCameraCode(); String flvUrl = cameraConfig.getMediaServerHost() + "/" + app + "/" + stream + ".flv"; camera.setHttpFmp4(flvUrl); // 复用已有字段存flvUrl,前端用httpFmp4字段接收 return R.ok(camera); } /** * 新增摄像头管理 */ @Log(title = "摄像头管理", businessType = BusinessType.INSERT) @RepeatSubmit() @PostMapping() public R add(@Validated(AddGroup.class) @RequestBody WmsCameraManagementBo bo) { return toAjax(iWmsCameraManagementService.insertByBo(bo)); } /** * 修改摄像头管理 */ @Log(title = "摄像头管理", businessType = BusinessType.UPDATE) @RepeatSubmit() @PutMapping() public R edit(@Validated(EditGroup.class) @RequestBody WmsCameraManagementBo bo) { return toAjax(iWmsCameraManagementService.updateByBo(bo)); } /** * 删除摄像头管理 * * @param cameraIds 主键串 */ @Log(title = "摄像头管理", businessType = BusinessType.DELETE) @DeleteMapping("/{cameraIds}") public R remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] cameraIds) { return toAjax(iWmsCameraManagementService.deleteWithValidByIds(Arrays.asList(cameraIds), true)); } }