Commit 640ab8c2 by xmh

<feat> sip28181 视频资源接入

1 parent 1139fb92
......@@ -17,7 +17,8 @@ public enum ChannelType {
STREAM_RTSP(0),
/** stream type file */
STREAM_FILE(1),
/** sip28181 */
STREAM_SIP(2),
;
public int value;
......
......@@ -40,6 +40,28 @@ public class ChannelController extends ChannelBaseController {
return channelExample;
}
@RequestMapping(value = "", method = RequestMethod.POST)
@ResponseBody
@Override
public Object add(@RequestBody ChannelVo channelVo) {
Assert.notNull(channelVo.getChannelUnid(), "设备编号不能为空");
Assert.notNull(channelVo.getName(), "设备名称不能为空");
Assert.notNull(channelVo.getIp(), "IP不能为空");
Assert.notNull(channelVo.getPort(), "端口不能为空");
Assert.notNull(channelVo.getStreamType(), "视频流类型不能为空");
Assert.notNull(channelVo.getUsername(), "用户名不能为空");
Assert.notNull(channelVo.getPassword(), "密码不能为空");
Assert.notNull(channelVo.getStreamPath(), "视频流地址不能为空");
Assert.notNull(channelVo.getType(), "类型不能为空");
try {
return channelService.add(channelVo);
} catch (DuplicateKeyException e) {
log.error("", e);
return JsonMessageUtil.getErrorJsonMsg("设备编号或名称重复");
}
}
@Override
@RequestMapping(value = "/{id}", method = RequestMethod.POST)
@ResponseBody
......@@ -121,25 +143,10 @@ public class ChannelController extends ChannelBaseController {
return JsonMessageUtil.getSuccessJsonMsg(result);
}
@RequestMapping(value = "", method = RequestMethod.POST)
@ResponseBody
@Override
public Object add(@RequestBody ChannelVo channelVo) {
Assert.notNull(channelVo.getChannelUnid(), "设备编号不能为空");
Assert.notNull(channelVo.getName(), "设备名称不能为空");
Assert.notNull(channelVo.getIp(), "IP不能为空");
Assert.notNull(channelVo.getPort(), "端口不能为空");
Assert.notNull(channelVo.getStreamType(), "视频流类型不能为空");
Assert.notNull(channelVo.getUsername(), "用户名不能为空");
Assert.notNull(channelVo.getPassword(), "密码不能为空");
Assert.notNull(channelVo.getStreamPath(), "视频流地址不能为空");
Assert.notNull(channelVo.getType(), "类型不能为空");
@GetMapping("/sip28181/pull")
public Object pullFromSip28181() {
channelService.pullFromSip28181();
try {
return channelService.add(channelVo);
} catch (DuplicateKeyException e) {
log.error("", e);
return JsonMessageUtil.getErrorJsonMsg("设备编号或名称重复");
}
return JsonMessageUtil.getSuccessJsonMsg();
}
}
\ No newline at end of file
......@@ -18,4 +18,5 @@ public interface ChannelService extends BaseService<Channel> {
ChannelVo update(long id, ChannelVo vo);
Object pullFromSip28181();
}
\ No newline at end of file
......@@ -10,7 +10,10 @@ import java.util.Map;
public interface DictCodeService extends BaseService<DictCode> {
DictCode getNVS3000Code();
ImmutablePair<Map<Long,DictCodeVo>,List<DictCodeVo>> getTreeCode(List<DictCode> dictCodes);
ImmutablePair<Map<Long, DictCodeVo>, List<DictCodeVo>> getTreeCode(List<DictCode> dictCodes);
DictCode getOrCreateOrgCode(String code);
DictCode saveAndGet(String name, String code, String note, Long cateId, Long parentId);
}
\ No newline at end of file
......@@ -22,6 +22,7 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import org.springframework.web.reactive.function.client.WebClient;
import javax.annotation.Resource;
......@@ -81,6 +82,9 @@ public class ChannelServiceImpl extends BaseServiceImpl<Channel> implements Chan
vo.setId(id);
vo.setUnid(channel.getUnid());
vo.setType(channel.getType());
vo.setCreateTime(channel.getCreateTime());
vo.setStatus(channel.getStatus());
vo.setAddressUnid(channel.getAddressUnid());
updateByPrimaryKey(vo);
// 如果对 streamPath 进行更新,需要同时更新任务信息
......@@ -214,7 +218,7 @@ public class ChannelServiceImpl extends BaseServiceImpl<Channel> implements Chan
*/
@Override
public JSONObject nvs3000(String nvsUrl, String nvsRegex) {
DictCode nvs3000Code = dictcodeService.getNVS3000Code();
DictCode nvs3000Code = dictcodeService.getOrCreateOrgCode("nvs3000");
String addressUnid = nvs3000Code.getUnid();
ChannelExample channelExample = new ChannelExample();
......@@ -276,5 +280,84 @@ public class ChannelServiceImpl extends BaseServiceImpl<Channel> implements Chan
return jsonObject;
}
@Override
public Object pullFromSip28181() {
Assert.notNull(vionConfig.getSip(), "sip28181 配置为空");
Assert.hasText(vionConfig.getSip().getId(), "sip28181 对接id为空");
Assert.hasText(vionConfig.getSip().getUrl(), "sip28181 对接地址为空");
JSONObject response = WebClient.create(vionConfig.getSip().getUrl())
.get()
.uri(uriBuilder -> uriBuilder.path("/api/device/getAllDeviceList").queryParam("userid", vionConfig.getSip().getId()).build())
.retrieve()
.bodyToMono(JSONObject.class)
.block(Duration.ofSeconds(10));
DictCode sip28181 = dictcodeService.getOrCreateOrgCode("sip28181");
if (response != null && response.containsKey("data")) {
JSONArray data = response.getJSONArray("data");
if (data.size() > 0) {
analyseSip28181(data, sip28181, sip28181.getCateId());
}
}
return null;
}
@Transactional(rollbackFor = Exception.class)
protected void analyseSip28181(JSONArray data, DictCode parent, Long cateId) {
for (int i = 0; i < data.size(); i++) {
JSONObject item = data.getJSONObject(i);
JSONArray orzs = item.getJSONArray("orzs");
// orzs 的长度大于零, 说明是组织机构节点,需要添加到字典表中
if (orzs.size() > 0) {
DictCode dictCode = dictcodeService.saveAndGet(item.getString("orzName"), item.getString("orzId"), "sip28181", cateId, parent.getId());
analyseSip28181(orzs, dictCode, cateId);
} else {
// 解析视频资源,devices->channels
JSONArray devices = item.getJSONArray("devices");
if (devices.size() > 0) {
for (int j = 0; j < devices.size(); j++) {
JSONObject deviceJson = devices.getJSONObject(j);
String deviceId = deviceJson.getString("deviceId");
String deviceName = deviceJson.getString("deviceName");
JSONArray channels = deviceJson.getJSONArray("channels");
for (int k = 0; k < channels.size(); k++) {
JSONObject channelJson = channels.getJSONObject(k);
String channelName = channelJson.getString("channelName");
String channelId = channelJson.getString("channelId");
Integer hasPtz = channelJson.getInteger("hasPtz");
saveAndGet(channelName, deviceId, channelId, ChannelType.THIRD_PART.value, ChannelType.STREAM_SIP.value, null, parent.getUnid());
}
}
}
}
}
}
private Channel saveAndGet(String name, String deviceUnid, String channelUnid, Integer type, Integer streamType, String deviceType, String addressUnid) {
ChannelExample channelExample = new ChannelExample();
channelExample.createCriteria().andChannelUnidEqualTo(channelUnid);
List<Channel> channels = selectByExample(channelExample);
if (channels.size() > 0) {
Channel channel = channels.get(0);
if (!channel.getName().equals(name)) {
throw new FanXingException("视频设备通道序列号重复:" + channelUnid);
} else {
return channel;
}
}
Channel channel = new Channel();
channel.setName(name);
channel.setDeviceUnid(deviceUnid);
channel.setChannelUnid(channelUnid);
channel.setType(type);
channel.setStreamType(streamType);
channel.setDeviceType(deviceType);
channel.setAddressUnid(addressUnid);
return insertSelective(channel);
}
}
\ No newline at end of file
......@@ -2,6 +2,7 @@ package com.viontech.fanxing.ops.service.impl;
import com.viontech.fanxing.commons.base.BaseMapper;
import com.viontech.fanxing.commons.base.BaseServiceImpl;
import com.viontech.fanxing.commons.exception.FanXingException;
import com.viontech.fanxing.commons.model.DictCate;
import com.viontech.fanxing.commons.model.DictCode;
import com.viontech.fanxing.commons.model.DictCodeExample;
......@@ -54,29 +55,54 @@ public class DictCodeServiceImpl extends BaseServiceImpl<DictCode> implements Di
}
@Override
public DictCode getNVS3000Code() {
public DictCode getOrCreateOrgCode(String code) {
DictCate videoOrgCate = dictCateService.getVideoOrgCate();
Long cateId = videoOrgCate.getId();
DictCodeExample dictCodeExample = new DictCodeExample();
dictCodeExample.createCriteria().andCateIdEqualTo(cateId);
List<DictCode> dictCodes = selectByExample(dictCodeExample);
DictCode nvs3000Code = null;
DictCode orgCode = null;
for (DictCode dictCode : dictCodes) {
if ("nvs3000".equals(dictCode.getCode())) {
nvs3000Code = dictCode;
if (code.equals(dictCode.getCode())) {
orgCode = dictCode;
break;
}
}
if (nvs3000Code == null) {
nvs3000Code = new DictCode();
nvs3000Code.setCode("nvs3000");
nvs3000Code.setName("nvs3000");
nvs3000Code.setCateId(cateId);
nvs3000Code.setNote("nvs3000");
insertSelective(nvs3000Code);
return getNVS3000Code();
if (orgCode == null) {
orgCode = new DictCode();
orgCode.setCode(code);
orgCode.setName(code);
orgCode.setCateId(cateId);
orgCode.setNote(code);
orgCode.setNote("");
insertSelective(orgCode);
return getOrCreateOrgCode(code);
}
return nvs3000Code;
return orgCode;
}
@Override
public DictCode saveAndGet(String name, String code, String note, Long cateId, Long parentId) {
DictCodeExample dictCodeExample = new DictCodeExample();
dictCodeExample.createCriteria().andCodeEqualTo(code);
List<DictCode> dictCodes = selectByExample(dictCodeExample);
if (dictCodes.size() > 0) {
DictCode item = dictCodes.get(0);
if (!item.getName().equals(name)) {
throw new FanXingException("orzId 重复:" + code);
} else {
return item;
}
}
DictCode dictCode = new DictCode();
dictCode.setName(name);
dictCode.setCode(code);
dictCode.setNote(note);
dictCode.setCateId(cateId);
dictCode.setParentId(parentId);
dictCode = this.insertSelective(dictCode);
return this.selectByPrimaryKey(dictCode.getId());
}
}
\ No newline at end of file
......@@ -63,5 +63,4 @@ vion:
supported-video-formats:
- mp4
- avi
- h264
- nsf
\ No newline at end of file
- h264
\ No newline at end of file
......@@ -33,4 +33,9 @@ server {
rewrite ^/api/video-server/(.*) /$1 break;
proxy_pass http://192.168.9.233:10350/;
}
location /api/sip28181/ {
rewrite ^/api/sip28181/(.*) /$1 break;
proxy_pass http://192.168.9.233:8888/;
}
}
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!