Files
klp-oa/klp-wms/src/main/java/com/klp/controller/WmsCameraManagementController.java
JR dde51169f0 feat(wms): 添加摄像头流媒体功能
- 在 application.yml 中添加 camera 配置项,用于指定媒体服务器地址
- 新增 CameraConfig 类,用于获取媒体服务器主机地址
- 在 WmsCameraManagementController 中添加 getCameraStream 方法,用于获取摄像头 FLV 流地址
2025-08-07 17:49:28 +08:00

120 lines
4.1 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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<WmsCameraManagementVo> 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<WmsCameraManagementVo> list = iWmsCameraManagementService.queryList(bo);
ExcelUtil.exportExcel(list, "摄像头管理", WmsCameraManagementVo.class, response);
}
/**
* 获取摄像头管理详细信息
*
* @param cameraId 主键
*/
@GetMapping("/{cameraId}")
public R<WmsCameraManagementVo> getInfo(@NotNull(message = "主键不能为空")
@PathVariable Long cameraId) {
return R.ok(iWmsCameraManagementService.queryById(cameraId));
}
/**
* 获取摄像头FLV流地址前端可用flv.js播放
*/
@GetMapping("/stream/{cameraId}")
public R<WmsCameraManagementVo> 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<Void> add(@Validated(AddGroup.class) @RequestBody WmsCameraManagementBo bo) {
return toAjax(iWmsCameraManagementService.insertByBo(bo));
}
/**
* 修改摄像头管理
*/
@Log(title = "摄像头管理", businessType = BusinessType.UPDATE)
@RepeatSubmit()
@PutMapping()
public R<Void> edit(@Validated(EditGroup.class) @RequestBody WmsCameraManagementBo bo) {
return toAjax(iWmsCameraManagementService.updateByBo(bo));
}
/**
* 删除摄像头管理
*
* @param cameraIds 主键串
*/
@Log(title = "摄像头管理", businessType = BusinessType.DELETE)
@DeleteMapping("/{cameraIds}")
public R<Void> remove(@NotEmpty(message = "主键不能为空")
@PathVariable Long[] cameraIds) {
return toAjax(iWmsCameraManagementService.deleteWithValidByIds(Arrays.asList(cameraIds), true));
}
}