From 1af77ab5f7c11a4b3d59c1989b51b9fca29679ce Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: 星期二, 18 十月 2022 22:18:49 +0800 Subject: [PATCH] Merge pull request #645 from IKangXu/wvp-28181-2.0 --- src/main/java/com/genersoft/iot/vmp/vmanager/streamProxy/StreamProxyController.java | 123 +++++++++++++++++++---------------------- 1 files changed, 57 insertions(+), 66 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/streamProxy/StreamProxyController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/streamProxy/StreamProxyController.java index f099631..95537c4 100644 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/streamProxy/StreamProxyController.java +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/streamProxy/StreamProxyController.java @@ -1,23 +1,26 @@ package com.genersoft.iot.vmp.vmanager.streamProxy; import com.alibaba.fastjson.JSONObject; -import com.genersoft.iot.vmp.media.zlm.dto.IMediaServerItem; +import com.genersoft.iot.vmp.common.StreamInfo; +import com.genersoft.iot.vmp.conf.exception.ControllerException; import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem; import com.genersoft.iot.vmp.service.IMediaServerService; +import com.genersoft.iot.vmp.service.IMediaService; import com.genersoft.iot.vmp.storager.IRedisCatchStorage; import com.genersoft.iot.vmp.service.IStreamProxyService; +import com.genersoft.iot.vmp.vmanager.bean.ErrorCode; import com.genersoft.iot.vmp.vmanager.bean.WVPResult; import com.github.pagehelper.PageInfo; -import io.netty.util.internal.StringUtil; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiImplicitParam; -import io.swagger.annotations.ApiImplicitParams; -import io.swagger.annotations.ApiOperation; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Parameters; +import io.swagger.v3.oas.annotations.tags.Tag; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; +import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.*; @@ -25,7 +28,7 @@ /** * 鎷夋祦浠g悊鎺ュ彛 */ -@Api(tags = "鎷夋祦浠g悊") +@Tag(name = "鎷夋祦浠g悊", description = "") @Controller @CrossOrigin @RequestMapping(value = "/api/proxy") @@ -34,23 +37,17 @@ private final static Logger logger = LoggerFactory.getLogger(StreamProxyController.class); @Autowired - private IRedisCatchStorage redisCatchStorage; - - - @Autowired private IMediaServerService mediaServerService; @Autowired private IStreamProxyService streamProxyService; - @ApiOperation("鍒嗛〉鏌ヨ娴佷唬鐞�") - @ApiImplicitParams({ - @ApiImplicitParam(name="page", value = "褰撳墠椤�", required = true, dataTypeClass = Integer.class), - @ApiImplicitParam(name="count", value = "姣忛〉鏌ヨ鏁伴噺", required = true, dataTypeClass = Integer.class), - @ApiImplicitParam(name="query", value = "鏌ヨ鍐呭", dataTypeClass = String.class), - @ApiImplicitParam(name="online", value = "鏄惁鍦ㄧ嚎", dataTypeClass = Boolean.class), - }) + @Operation(summary = "鍒嗛〉鏌ヨ娴佷唬鐞�") + @Parameter(name = "page", description = "褰撳墠椤�") + @Parameter(name = "count", description = "姣忛〉鏌ヨ鏁伴噺") + @Parameter(name = "query", description = "鏌ヨ鍐呭") + @Parameter(name = "online", description = "鏄惁鍦ㄧ嚎") @GetMapping(value = "/list") @ResponseBody public PageInfo<StreamProxyItem> list(@RequestParam(required = false)Integer page, @@ -61,84 +58,78 @@ return streamProxyService.getAll(page, count); } - @ApiOperation("淇濆瓨浠g悊") - @ApiImplicitParams({ - @ApiImplicitParam(name = "param", value = "浠g悊鍙傛暟", dataTypeClass = StreamProxyItem.class), + @Operation(summary = "淇濆瓨浠g悊", parameters = { + @Parameter(name = "param", description = "浠g悊鍙傛暟", required = true), }) @PostMapping(value = "/save") @ResponseBody - public WVPResult save(@RequestBody StreamProxyItem param){ + public StreamInfo save(@RequestBody StreamProxyItem param){ logger.info("娣诲姞浠g悊锛� " + JSONObject.toJSONString(param)); - if (StringUtils.isEmpty(param.getMediaServerId())) param.setMediaServerId("auto"); - String msg = streamProxyService.save(param); - WVPResult<Object> result = new WVPResult<>(); - result.setCode(0); - result.setMsg(msg); - return result; + if (ObjectUtils.isEmpty(param.getMediaServerId())) { + param.setMediaServerId("auto"); + } + if (ObjectUtils.isEmpty(param.getType())) { + param.setType("default"); + } + if (ObjectUtils.isEmpty(param.getGbId())) { + param.setGbId(null); + } + return streamProxyService.save(param); } - @ApiOperation("鑾峰彇ffmpeg.cmd妯℃澘") @GetMapping(value = "/ffmpeg_cmd/list") - @ApiImplicitParams({ - @ApiImplicitParam(name = "mediaServerId", value = "娴佸獟浣揑D", dataTypeClass = String.class), - }) @ResponseBody - public WVPResult getFFmpegCMDs(@RequestParam String mediaServerId){ + @Operation(summary = "鑾峰彇ffmpeg.cmd妯℃澘") + @Parameter(name = "mediaServerId", description = "娴佸獟浣揑D", required = true) + public JSONObject getFFmpegCMDs(@RequestParam String mediaServerId){ logger.debug("鑾峰彇鑺傜偣[ {} ]ffmpeg.cmd妯℃澘", mediaServerId ); - IMediaServerItem mediaServerItem = mediaServerService.getOne(mediaServerId); - JSONObject data = streamProxyService.getFFmpegCMDs(mediaServerItem); - WVPResult<JSONObject> result = new WVPResult<>(); - result.setCode(0); - result.setMsg("success"); - result.setData(data); - return result; + MediaServerItem mediaServerItem = mediaServerService.getOne(mediaServerId); + if (mediaServerItem == null) { + throw new ControllerException(ErrorCode.ERROR100.getCode(), "娴佸獟浣擄細 " + mediaServerId + "鏈壘鍒�"); + } + return streamProxyService.getFFmpegCMDs(mediaServerItem); } - @ApiOperation("绉婚櫎浠g悊") - @ApiImplicitParams({ - @ApiImplicitParam(name = "app", value = "搴旂敤鍚�", required = true, dataTypeClass = String.class), - @ApiImplicitParam(name = "stream", value = "娴両D", required = true, dataTypeClass = String.class), - }) @DeleteMapping(value = "/del") @ResponseBody - public WVPResult del(@RequestParam String app, @RequestParam String stream){ + @Operation(summary = "绉婚櫎浠g悊") + @Parameter(name = "app", description = "搴旂敤鍚�", required = true) + @Parameter(name = "stream", description = "娴乮d", required = true) + public void del(@RequestParam String app, @RequestParam String stream){ logger.info("绉婚櫎浠g悊锛� " + app + "/" + stream); - WVPResult<Object> result = new WVPResult<>(); if (app == null || stream == null) { - result.setCode(400); - result.setMsg(app == null ?"app涓嶈兘涓簄ull":"stream涓嶈兘涓簄ull"); + throw new ControllerException(ErrorCode.ERROR400.getCode(), app == null ?"app涓嶈兘涓簄ull":"stream涓嶈兘涓簄ull"); }else { streamProxyService.del(app, stream); - result.setCode(0); - result.setMsg("success"); } - return result; } - @ApiOperation("鍚敤浠g悊") - @ApiImplicitParams({ - @ApiImplicitParam(name = "app", value = "搴旂敤鍚�", dataTypeClass = String.class), - @ApiImplicitParam(name = "stream", value = "娴両D", dataTypeClass = String.class), - }) @GetMapping(value = "/start") @ResponseBody - public Object start(String app, String stream){ + @Operation(summary = "鍚敤浠g悊") + @Parameter(name = "app", description = "搴旂敤鍚�", required = true) + @Parameter(name = "stream", description = "娴乮d", required = true) + public void start(String app, String stream){ logger.info("鍚敤浠g悊锛� " + app + "/" + stream); boolean result = streamProxyService.start(app, stream); - return result?"success":"fail"; + if (!result) { + logger.info("鍚敤浠g悊澶辫触锛� " + app + "/" + stream); + throw new ControllerException(ErrorCode.ERROR100); + } } - @ApiOperation("鍋滅敤浠g悊") - @ApiImplicitParams({ - @ApiImplicitParam(name = "app", value = "搴旂敤鍚�", dataTypeClass = String.class), - @ApiImplicitParam(name = "stream", value = "娴両D", dataTypeClass = String.class), - }) @GetMapping(value = "/stop") @ResponseBody - public Object stop(String app, String stream){ + @Operation(summary = "鍋滅敤浠g悊") + @Parameter(name = "app", description = "搴旂敤鍚�", required = true) + @Parameter(name = "stream", description = "娴乮d", required = true) + public void stop(String app, String stream){ logger.info("鍋滅敤浠g悊锛� " + app + "/" + stream); boolean result = streamProxyService.stop(app, stream); - return result?"success":"fail"; + if (!result) { + logger.info("鍋滅敤浠g悊澶辫触锛� " + app + "/" + stream); + throw new ControllerException(ErrorCode.ERROR100); + } } } -- Gitblit v1.8.0