MainService.java
6.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
package com.viontech.integration.jiaoguansuo.service;
import cn.hutool.core.date.DateUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import com.viontech.fanxing.commons.constant.ChannelType;
import com.viontech.fanxing.commons.model.Channel;
import com.viontech.fanxing.commons.model.Task;
import com.viontech.fanxing.commons.vo.TaskVo;
import com.viontech.integration.jiaoguansuo.entity.Code;
import com.viontech.integration.jiaoguansuo.entity.VideoEntity;
import com.viontech.integration.jiaoguansuo.feign.OpsClient;
import com.viontech.integration.jiaoguansuo.feign.TaskClient;
import com.viontech.keliu.util.JsonMessageUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.time.Duration;
import java.util.Date;
import java.util.List;
/**
* .
*
* @author 谢明辉
* @date 2022/2/21
*/
@Service
@Slf4j
public class MainService {
@Resource
private TaskClient taskClient;
@Resource
private OpsClient opsClient;
@Value("${vion.storage-config-id}")
private Long storageConfigId;
@Resource
private XingheDeviceService xingheDeviceService;
public List<Channel> getChannels(Channel channel) {
JsonMessageUtil.JsonMessage<List<Channel>> channels = opsClient.getChannels(channel);
if (channels.isSuccess()) {
return channels.getData();
} else {
throw new RuntimeException(channels.getMsg());
}
}
public Channel addChannel(VideoEntity addVideo) {
Channel channel = new Channel();
channel.setChannelUnid(addVideo.getSxjbh());
channel.setDeviceUnid(addVideo.getDwxh());
JsonMessageUtil.JsonMessage<List<Channel>> channels = opsClient.getChannels(channel);
if (channels.isSuccess() && channels.getData().size() > 0) {
return channels.getData().get(0);
}
channel.setName(addVideo.getSxjbh());
channel.setStreamType(ChannelType.STREAM_RTSP.value);
channel.setStreamPath(addVideo.getJkdz());
channel.setIp("0.0.0.0");
channel.setPort(0);
channel.setUsername("username");
channel.setPassword("password");
channel.setType(ChannelType.MANUALLY.value);
JsonMessageUtil.JsonMessage<Channel> add = opsClient.add(channel);
if (add.isSuccess()) {
//星河平台同步新增设备
xingheDeviceService.addDevice(addVideo);
return add.getData();
} else {
throw new RuntimeException(add.getMsg());
}
}
public Task addTask(VideoEntity videoEntity, Channel channel, Code code) {
TaskVo taskVo = new TaskVo();
taskVo.setResourceNeed(1F);
taskVo.setStoreConfigId(storageConfigId);
taskVo.setName(videoEntity.getSxjbh());
taskVo.setAlgType(String.valueOf(0));
taskVo.setDeviceUnid(channel.getDeviceUnid());
taskVo.setChannelUnid(channel.getChannelUnid());
taskVo.setStreamPath(channel.getStreamPath());
taskVo.setStreamType(channel.getStreamType());
taskVo.setAlgEnabled("[\"" + code.paramName + "\"]");
// 视频检测运行配置
Integer jcfx = videoEntity.getJcfx();
if (jcfx == 1) {
long l = Duration.ofMinutes(videoEntity.getJcsj()).toMillis();
if (l == 0) {
taskVo.setRuntimeType(4);
taskVo.setRuntimeConf("{\"type\":4}");
} else {
taskVo.setRuntimeType(1);
JSONObject config = new JSONObject();
config.set("start", DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
config.set("end", DateUtil.format(new Date(System.currentTimeMillis() + l + 1000), "yyyy-MM-dd HH:mm:ss"));
JSONObject jsonObject = new JSONObject();
jsonObject.set("type", 1);
jsonObject.set("config", config);
taskVo.setRuntimeConf(jsonObject.toString());
}
} else {
String[] split = videoEntity.getJcsd().split("#");
if (split.length == 0) {
taskVo.setRuntimeType(4);
taskVo.setRuntimeConf("{\"type\":4}");
} else {
taskVo.setRuntimeType(0);
JSONArray configs = new JSONArray();
for (String dd : split) {
String[] ddd = dd.split("-");
JSONObject config = new JSONObject();
config.set("start", ddd[0] + ":00");
config.set("end", ddd[1] + ":00");
configs.add(config);
}
JSONObject jsonObject = new JSONObject();
jsonObject.set("type", 0);
jsonObject.set("config", configs);
taskVo.setRuntimeConf(jsonObject.toString());
}
}
JsonMessageUtil.JsonMessage<TaskVo> res = taskClient.addTask(taskVo);
if (res.isSuccess()) {
return res.getData();
} else {
throw new RuntimeException(res.getMsg());
}
}
public void removeChannel(Long id) {
JsonMessageUtil.JsonMessage remove = opsClient.remove(id);
log.info("删除视频资源结果:{}", remove.getMsg());
}
public void startTask(Long id) {
JsonMessageUtil.JsonMessage<TaskVo> task = taskClient.startTask(id);
}
public void removeTask(Long id) {
JsonMessageUtil.JsonMessage jsonMessage = taskClient.removeTask(id);
log.info("删除任务结果:{}", jsonMessage.getMsg());
}
public List<Task> getTask(Task task) {
JsonMessageUtil.JsonMessage<List<Task>> res = taskClient.getTask(task);
if (res.isSuccess()) {
return res.getData();
}
throw new RuntimeException(res.getMsg());
}
public void updateTask(Long id, Task task) {
JsonMessageUtil.JsonMessage<TaskVo> update = taskClient.update(id, task);
if (!update.isSuccess()) {
throw new RuntimeException(update.getMsg());
}
}
}