Showing
8 changed files
with
410 additions
and
0 deletions
| @@ -128,6 +128,12 @@ | @@ -128,6 +128,12 @@ | ||
| 128 | <artifactId>janino</artifactId> | 128 | <artifactId>janino</artifactId> |
| 129 | </dependency> | 129 | </dependency> |
| 130 | 130 | ||
| 131 | + <dependency> | ||
| 132 | + <groupId>cn.hutool</groupId> | ||
| 133 | + <artifactId>hutool-all</artifactId> | ||
| 134 | + <version>5.8.32</version> | ||
| 135 | + </dependency> | ||
| 136 | + | ||
| 131 | </dependencies> | 137 | </dependencies> |
| 132 | 138 | ||
| 133 | <build> | 139 | <build> |
| 1 | +package com.wondertek.controller; | ||
| 2 | + | ||
| 3 | +import com.wondertek.dto.DelayParam; | ||
| 4 | +import com.wondertek.service.RoomOperationSerivice; | ||
| 5 | +import com.wondertek.util.ResultBean; | ||
| 6 | +import jakarta.annotation.Resource; | ||
| 7 | +import lombok.extern.slf4j.Slf4j; | ||
| 8 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
| 9 | +import org.springframework.web.bind.annotation.RestController; | ||
| 10 | + | ||
| 11 | +/** | ||
| 12 | + * @Description: 审片间控制 | ||
| 13 | + * @Author W5669 | ||
| 14 | + * @Create 2025/7/22 | ||
| 15 | + * @Version 1.0 | ||
| 16 | + */ | ||
| 17 | +@Slf4j | ||
| 18 | +@RestController | ||
| 19 | +@RequestMapping("/monitor/room") | ||
| 20 | +public class RoomOperationController { | ||
| 21 | + @Resource | ||
| 22 | + private RoomOperationSerivice roomOperationSerivice; | ||
| 23 | + | ||
| 24 | + @RequestMapping("/setDelayTime") | ||
| 25 | + public ResultBean setDelayTime(DelayParam delayParam) { | ||
| 26 | + | ||
| 27 | + return roomOperationSerivice.setDelayTime(delayParam); | ||
| 28 | + | ||
| 29 | + } | ||
| 30 | +} |
| 1 | +package com.wondertek.dto; | ||
| 2 | + | ||
| 3 | +import lombok.Data; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * @Description: 延迟设置参数 | ||
| 7 | + * @Author W5669 | ||
| 8 | + * @Create 2025/7/22 | ||
| 9 | + * @Version 1.0 | ||
| 10 | + */ | ||
| 11 | +@Data | ||
| 12 | +public class DelayParam { | ||
| 13 | + private Long roomId; | ||
| 14 | + private Integer delayFirst; | ||
| 15 | + private Integer delaySecond; | ||
| 16 | + private Integer delayPlay; | ||
| 17 | +} |
| 1 | +package com.wondertek.service; | ||
| 2 | + | ||
| 3 | +import com.wondertek.dto.DelayParam; | ||
| 4 | +import com.wondertek.util.ResultBean; | ||
| 5 | + | ||
| 6 | +/** | ||
| 7 | + * @Description: | ||
| 8 | + * @Author W5669 | ||
| 9 | + * @Create 2025/7/22 | ||
| 10 | + * @Version 1.0 | ||
| 11 | + */ | ||
| 12 | +public interface RoomOperationSerivice { | ||
| 13 | + /** | ||
| 14 | + * 设置延迟时间 | ||
| 15 | + * @param delayParam | ||
| 16 | + * @return | ||
| 17 | + */ | ||
| 18 | + ResultBean setDelayTime(DelayParam delayParam); | ||
| 19 | +} |
| 1 | +package com.wondertek.service.impl; | ||
| 2 | + | ||
| 3 | +import cn.hutool.http.HttpRequest; | ||
| 4 | +import cn.hutool.http.HttpResponse; | ||
| 5 | +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | ||
| 6 | +import com.fasterxml.jackson.core.type.TypeReference; | ||
| 7 | +import com.wondertek.dto.DelayParam; | ||
| 8 | +import com.wondertek.entity.LiveMonitorRoom; | ||
| 9 | +import com.wondertek.entity.StreamTask; | ||
| 10 | +import com.wondertek.mapper.LiveMonitorRoomMapper; | ||
| 11 | +import com.wondertek.mapper.StreamTaskMapper; | ||
| 12 | +import com.wondertek.service.RoomOperationSerivice; | ||
| 13 | +import com.wondertek.util.JSONUtils; | ||
| 14 | +import com.wondertek.util.ResponseData; | ||
| 15 | +import com.wondertek.util.ResultBean; | ||
| 16 | +import jakarta.annotation.Resource; | ||
| 17 | +import lombok.extern.slf4j.Slf4j; | ||
| 18 | +import org.springframework.beans.factory.annotation.Value; | ||
| 19 | +import org.springframework.stereotype.Service; | ||
| 20 | + | ||
| 21 | +import java.util.HashMap; | ||
| 22 | +import java.util.List; | ||
| 23 | +import java.util.Map; | ||
| 24 | + | ||
| 25 | +/** | ||
| 26 | + * @Description: | ||
| 27 | + * @Author W5669 | ||
| 28 | + * @Create 2025/7/22 | ||
| 29 | + * @Version 1.0 | ||
| 30 | + */ | ||
| 31 | +@Service | ||
| 32 | +@Slf4j | ||
| 33 | +public class RoomOperationServiceImpl implements RoomOperationSerivice { | ||
| 34 | + @Resource | ||
| 35 | + private LiveMonitorRoomMapper liveMonitorRoomMapper; | ||
| 36 | + @Resource | ||
| 37 | + private StreamTaskMapper streamTaskMapper; | ||
| 38 | + @Value("${transcode.delayTimeUrl}") | ||
| 39 | + private String delayTimeUrl; | ||
| 40 | + | ||
| 41 | + @Override | ||
| 42 | + public ResultBean setDelayTime(DelayParam delayParam) { | ||
| 43 | + log.info("-->【云审片平台】审片间延时设置,delayParam:{}",delayParam); | ||
| 44 | + LiveMonitorRoom liveMonitorRoom = liveMonitorRoomMapper.selectById(delayParam.getRoomId()); | ||
| 45 | + LambdaQueryWrapper<StreamTask> wrapper = new LambdaQueryWrapper<>(); | ||
| 46 | + wrapper.eq(StreamTask::getRoomId,delayParam.getRoomId()); | ||
| 47 | + List<StreamTask> streamTasks = streamTaskMapper.selectList(wrapper); | ||
| 48 | + //1.依次取出延时1、延时2、播出任务,设置转码平台相应的延时时间 | ||
| 49 | + streamTasks.forEach(streamTask -> { | ||
| 50 | + if (streamTask.getPlayType().equals("delay1")){ | ||
| 51 | + delayTask(streamTask.getTaskId(),delayParam.getDelayFirst()); | ||
| 52 | + //更新任务 | ||
| 53 | + streamTask.setDelayTime(delayParam.getDelayFirst()); | ||
| 54 | + streamTaskMapper.updateById(streamTask); | ||
| 55 | + } | ||
| 56 | + }); | ||
| 57 | + | ||
| 58 | + //2.更新多画 | ||
| 59 | + | ||
| 60 | + return ResultBean.ok("设置成功"); | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + public void delayTask(String taskId,int delayTime){ | ||
| 64 | + Map<String, Object> paramsMap = new HashMap<>(); | ||
| 65 | + paramsMap.put("taskId", taskId); | ||
| 66 | + paramsMap.put("delayTime", delayTime); | ||
| 67 | + HttpResponse execute = null; | ||
| 68 | + try { | ||
| 69 | + execute = HttpRequest.post(delayTimeUrl) | ||
| 70 | + .header("Content-Type", "application/json") | ||
| 71 | + .body(JSONUtils.obj2json(paramsMap)).timeout(30000).execute(); | ||
| 72 | + if (execute.isOk()) { | ||
| 73 | + log.info("-->请求转码系统延时接口,url:{},paramsMap:{}",delayTimeUrl,paramsMap); | ||
| 74 | + String body = execute.body(); | ||
| 75 | + ResponseData response = JSONUtils.jsonToObject(body, new TypeReference<ResponseData>() { | ||
| 76 | + }); | ||
| 77 | + if (response.getResultCode().equals("0")) { | ||
| 78 | + log.info("请求转码系统延时接口成功"); | ||
| 79 | + }else { | ||
| 80 | + log.info("请求转码系统延时接口响应失败,response:{}",response); | ||
| 81 | + } | ||
| 82 | + } else { | ||
| 83 | + log.error("请求转码系统延时接口失败,url:{},body:{}", delayTimeUrl, execute.body()); | ||
| 84 | + } | ||
| 85 | + } catch (Exception e) { | ||
| 86 | + log.error("请求转码系统延时接口失败,url:{}", delayTimeUrl, e); | ||
| 87 | + } | ||
| 88 | + } | ||
| 89 | +} |
| 1 | +package com.wondertek.util; | ||
| 2 | + | ||
| 3 | +import com.fasterxml.jackson.core.JsonProcessingException; | ||
| 4 | +import com.fasterxml.jackson.core.type.TypeReference; | ||
| 5 | +import com.fasterxml.jackson.databind.DeserializationFeature; | ||
| 6 | +import com.fasterxml.jackson.databind.JsonNode; | ||
| 7 | +import com.fasterxml.jackson.databind.ObjectMapper; | ||
| 8 | +import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; | ||
| 9 | +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; | ||
| 10 | +import com.fasterxml.jackson.module.paramnames.ParameterNamesModule; | ||
| 11 | +import lombok.extern.slf4j.Slf4j; | ||
| 12 | + | ||
| 13 | +import java.util.List; | ||
| 14 | + | ||
| 15 | +@Slf4j | ||
| 16 | +public class JSONUtils { | ||
| 17 | + | ||
| 18 | + private static final ObjectMapper objectMapper = new ObjectMapper().registerModule(new ParameterNamesModule()) | ||
| 19 | + .registerModule(new Jdk8Module()) | ||
| 20 | + // 使jackson识别被@JsonFormat标识的字段 | ||
| 21 | + .registerModule(new JavaTimeModule()) | ||
| 22 | + // 设置jackson反序列化时遇到类中不存在的字段时不抛出异常 | ||
| 23 | + .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); | ||
| 24 | + | ||
| 25 | + private JSONUtils() { | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | + public static ObjectMapper getInstance() { | ||
| 29 | + return objectMapper; | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + /** | ||
| 33 | + * javaBean,list,array convert to json string | ||
| 34 | + */ | ||
| 35 | + public static String obj2json(Object obj) { | ||
| 36 | + try { | ||
| 37 | + return objectMapper.writeValueAsString(obj); | ||
| 38 | + } catch (JsonProcessingException e) { | ||
| 39 | + log.error("获取异常信息:{}", e.getMessage()); | ||
| 40 | + } | ||
| 41 | + return null; | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + public static JsonNode parseJsonNode(String jsonChar) { | ||
| 45 | + return jsonToObject(jsonChar, JsonNode.class); | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + public static <T> T obj2T(Object obj, Class<T> t) { | ||
| 49 | + return objectMapper.convertValue(obj, new TypeReference<T>() { | ||
| 50 | + }); | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + public static <T> T jsonToObject(String jsonChar, TypeReference<T> t) { | ||
| 54 | + try { | ||
| 55 | + return objectMapper.readValue(jsonChar, t); | ||
| 56 | + } catch (Exception e) { | ||
| 57 | + log.error("json字符串反序列化失败,json字符串:{},类型:{}", jsonChar, t.getType().getTypeName()); | ||
| 58 | + } | ||
| 59 | + return null; | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + public static <T> List<T> jsonToList(String jsonChar, Class<T> t) { | ||
| 63 | + return jsonToObject(jsonChar, new TypeReference<List<T>>() { | ||
| 64 | + }); | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + public static <T> T jsonToObject(String jsonChar, Class<T> t) { | ||
| 68 | + try { | ||
| 69 | + return objectMapper.readValue(jsonChar, t); | ||
| 70 | + } catch (Exception e) { | ||
| 71 | + log.error("json字符串反序列化失败,json字符串:{},类型:{}", jsonChar, t.getName()); | ||
| 72 | + } | ||
| 73 | + return null; | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + /** | ||
| 77 | + * 获取节点指定字段的值 | ||
| 78 | + * <p><b>Title:</b> getString</p> | ||
| 79 | + * <p><b>Description:</b> </p> | ||
| 80 | + * | ||
| 81 | + * @author Zewei.Zhou | ||
| 82 | + * @param jsonNode 节点 | ||
| 83 | + * @param fieldName 字段名称 | ||
| 84 | + * @return | ||
| 85 | + */ | ||
| 86 | + public static String getString(JsonNode jsonNode, String fieldName) { | ||
| 87 | + if (jsonNode == null) { | ||
| 88 | + return null; | ||
| 89 | + } | ||
| 90 | + JsonNode node = jsonNode.get(fieldName); | ||
| 91 | + | ||
| 92 | + return (node == null || node.isNull()) ? null : node.asText(); | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + /** | ||
| 96 | + * 获取节点指定字段的值 | ||
| 97 | + * <p><b>Title:</b> nodeToString</p> | ||
| 98 | + * <p><b>Description:</b> </p> | ||
| 99 | + * | ||
| 100 | + * @author Zewei.Zhou | ||
| 101 | + * @param jsonNode 节点 | ||
| 102 | + * @param fieldName 字段名称 | ||
| 103 | + * @return | ||
| 104 | + */ | ||
| 105 | + public static String nodeToString(JsonNode jsonNode, String fieldName) { | ||
| 106 | + if (jsonNode == null) { | ||
| 107 | + return null; | ||
| 108 | + } | ||
| 109 | + JsonNode node = jsonNode.get(fieldName); | ||
| 110 | + | ||
| 111 | + return (node == null || node.isNull()) ? null : node.toString(); | ||
| 112 | + } | ||
| 113 | + | ||
| 114 | + /** | ||
| 115 | + * 获取节点指定字段的int值,默认为0 | ||
| 116 | + * <p><b>Title:</b> getInt</p> | ||
| 117 | + * <p><b>Description:</b> </p> | ||
| 118 | + * | ||
| 119 | + * @author Zewei.Zhou | ||
| 120 | + * @param jsonNode 节点 | ||
| 121 | + * @param fieldName 字段名称 | ||
| 122 | + * @return | ||
| 123 | + */ | ||
| 124 | + public static int getInt(JsonNode jsonNode, String fieldName) { | ||
| 125 | + if (jsonNode == null) { | ||
| 126 | + return 0; | ||
| 127 | + } | ||
| 128 | + JsonNode node = jsonNode.get(fieldName); | ||
| 129 | + return node == null || !node.canConvertToInt() ? 0 : node.asInt(); | ||
| 130 | + } | ||
| 131 | + | ||
| 132 | + /** | ||
| 133 | + * 获取节点指定字段的值 | ||
| 134 | + * <p><b>Title:</b> getInteger</p> | ||
| 135 | + * <p><b>Description:</b> </p> | ||
| 136 | + * | ||
| 137 | + * @author Zewei.Zhou | ||
| 138 | + * @param jsonNode 节点 | ||
| 139 | + * @param fieldName 字段名称 | ||
| 140 | + * @return | ||
| 141 | + */ | ||
| 142 | + public static Integer getInteger(JsonNode jsonNode, String fieldName) { | ||
| 143 | + if (jsonNode == null) { | ||
| 144 | + return null; | ||
| 145 | + } | ||
| 146 | + JsonNode node = jsonNode.get(fieldName); | ||
| 147 | + return node == null || !node.canConvertToInt() ? null : node.asInt(); | ||
| 148 | + } | ||
| 149 | + | ||
| 150 | + /** | ||
| 151 | + * 获取节点指定字段的值 | ||
| 152 | + * <p><b>Title:</b> getLong</p> | ||
| 153 | + * <p><b>Description:</b> </p> | ||
| 154 | + * | ||
| 155 | + * @author Zewei.Zhou | ||
| 156 | + * @param jsonNode 节点 | ||
| 157 | + * @param fieldName 字段名称 | ||
| 158 | + * @return | ||
| 159 | + */ | ||
| 160 | + public static Long getLong(JsonNode jsonNode, String fieldName) { | ||
| 161 | + if (jsonNode == null) { | ||
| 162 | + return null; | ||
| 163 | + } | ||
| 164 | + JsonNode node = jsonNode.get(fieldName); | ||
| 165 | + return node == null || !node.canConvertToLong() ? null : node.asLong(); | ||
| 166 | + } | ||
| 167 | +} |
| 1 | +package com.wondertek.util; | ||
| 2 | + | ||
| 3 | +import com.fasterxml.jackson.annotation.JsonInclude; | ||
| 4 | +import com.wondertek.enums.GlobalCodeEnum; | ||
| 5 | +import lombok.Data; | ||
| 6 | +import lombok.ToString; | ||
| 7 | + | ||
| 8 | +@Data | ||
| 9 | +@ToString | ||
| 10 | +@JsonInclude(JsonInclude.Include.NON_NULL) | ||
| 11 | +public class ResponseData<T> { | ||
| 12 | + | ||
| 13 | + /** | ||
| 14 | + * 返回代码 | ||
| 15 | + */ | ||
| 16 | + private String resultCode; | ||
| 17 | + /** | ||
| 18 | + * 返回信息 | ||
| 19 | + */ | ||
| 20 | + private String returnMessage; | ||
| 21 | + /** | ||
| 22 | + * 返回结果 | ||
| 23 | + */ | ||
| 24 | + private T data; | ||
| 25 | + | ||
| 26 | + public <K> ResponseData() { | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + public ResponseData(String code, String msg) { | ||
| 30 | + this.resultCode = code; | ||
| 31 | + this.returnMessage = msg; | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | + public ResponseData(String code, String msg, T result) { | ||
| 35 | + this.resultCode = code; | ||
| 36 | + this.returnMessage = msg; | ||
| 37 | + this.data = result; | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + public static <T> ResponseData<T> ok() { | ||
| 41 | + return new ResponseData<>(GlobalCodeEnum.SUCCESS.getCode(), GlobalCodeEnum.SUCCESS.getMsg()); | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + public static <T> ResponseData<T> ok(String msg) { | ||
| 45 | + return new ResponseData<T>(GlobalCodeEnum.SUCCESS.getCode(), msg); | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + public static <T> ResponseData<T> ok(T result) { | ||
| 49 | + return new ResponseData<T>(GlobalCodeEnum.SUCCESS.getCode(), GlobalCodeEnum.SUCCESS.getMsg(), result); | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + public Boolean isSuccess() { | ||
| 53 | + return GlobalCodeEnum.SUCCESS.getCode().equals(this.resultCode); | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + public static <T> ResponseData<T> error() { | ||
| 57 | + return new ResponseData<T>(GlobalCodeEnum.FAILURE.getCode(), GlobalCodeEnum.FAILURE.getMsg()); | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + public static <T> ResponseData<T> error(String msg) { | ||
| 61 | + return new ResponseData<T>(GlobalCodeEnum.FAILURE.getCode(), msg); | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + public static <T> ResponseData<T> error(String code, String msg) { | ||
| 65 | + return new ResponseData<T>(code, msg); | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + public static <K> ResponseData<K> error(String code, String msg, K k) { | ||
| 69 | + return new ResponseData<K>(code, msg, k); | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + public void setCodeAndMsg(GlobalCodeEnum globalCodeEnum) { | ||
| 73 | + setCodeAndMsg(globalCodeEnum.getCode(), globalCodeEnum.getMsg()); | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + public void setCodeAndMsg(String code, String msg) { | ||
| 77 | + this.resultCode = code; | ||
| 78 | + this.returnMessage = msg; | ||
| 79 | + } | ||
| 80 | +} |
| @@ -59,6 +59,8 @@ mybatis-plus: | @@ -59,6 +59,8 @@ mybatis-plus: | ||
| 59 | logic-not-delete-value: 1 | 59 | logic-not-delete-value: 1 |
| 60 | logic-delete-value: 0 | 60 | logic-delete-value: 0 |
| 61 | 61 | ||
| 62 | +transcode: | ||
| 63 | + delayTimeUrl: http://192.168.1.41:8080/transcode/delayTime # 延迟接口 | ||
| 62 | 64 | ||
| 63 | crp: | 65 | crp: |
| 64 | log: | 66 | log: |
-
Please register or login to post a comment