临时提交
parent
8ab88c0f02
commit
a1671c3c3e
|
@ -1,11 +1,14 @@
|
|||
package com.genersoft.iot.vmp.gb28181.bean;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author lin
|
||||
*/
|
||||
@Data
|
||||
public class CatalogData {
|
||||
/**
|
||||
* 命令序列号
|
||||
|
@ -13,6 +16,8 @@ public class CatalogData {
|
|||
private int sn;
|
||||
private int total;
|
||||
private List<DeviceChannel> channelList;
|
||||
private List<Region> regionListList;
|
||||
private List<Group> groupListListList;
|
||||
private Instant lastTime;
|
||||
private Device device;
|
||||
private String errorMsg;
|
||||
|
@ -21,61 +26,4 @@ public class CatalogData {
|
|||
ready, runIng, end
|
||||
}
|
||||
private CatalogDataStatus status;
|
||||
|
||||
|
||||
public int getSn() {
|
||||
return sn;
|
||||
}
|
||||
|
||||
public void setSn(int sn) {
|
||||
this.sn = sn;
|
||||
}
|
||||
|
||||
public int getTotal() {
|
||||
return total;
|
||||
}
|
||||
|
||||
public void setTotal(int total) {
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
public List<DeviceChannel> getChannelList() {
|
||||
return channelList;
|
||||
}
|
||||
|
||||
public void setChannelList(List<DeviceChannel> channelList) {
|
||||
this.channelList = channelList;
|
||||
}
|
||||
|
||||
public Instant getLastTime() {
|
||||
return lastTime;
|
||||
}
|
||||
|
||||
public void setLastTime(Instant lastTime) {
|
||||
this.lastTime = lastTime;
|
||||
}
|
||||
|
||||
public Device getDevice() {
|
||||
return device;
|
||||
}
|
||||
|
||||
public void setDevice(Device device) {
|
||||
this.device = device;
|
||||
}
|
||||
|
||||
public String getErrorMsg() {
|
||||
return errorMsg;
|
||||
}
|
||||
|
||||
public void setErrorMsg(String errorMsg) {
|
||||
this.errorMsg = errorMsg;
|
||||
}
|
||||
|
||||
public CatalogDataStatus getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(CatalogDataStatus status) {
|
||||
this.status = status;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.genersoft.iot.vmp.gb28181.bean;
|
||||
|
||||
import com.genersoft.iot.vmp.utils.DateUtil;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
@ -58,6 +59,25 @@ public class Group implements Comparable<Group>{
|
|||
@Schema(description = "平台ID")
|
||||
private Integer platformId;
|
||||
|
||||
public static Group getInstance(DeviceChannel channel) {
|
||||
GbCode gbCode = GbCode.decode(channel.getDeviceId());
|
||||
if (gbCode == null || (!gbCode.getTypeCode().equals("215") && !gbCode.getTypeCode().equals("216"))) {
|
||||
return null;
|
||||
}
|
||||
Group group = new Group();
|
||||
group.setName(channel.getName());
|
||||
group.setDeviceId(channel.getDeviceId());
|
||||
group.setCreateTime(DateUtil.getNow());
|
||||
group.setUpdateTime(DateUtil.getNow());
|
||||
if (gbCode.getTypeCode().equals("215")) {
|
||||
group.setBusinessGroup(channel.getDeviceId());
|
||||
}else if (gbCode.getTypeCode().equals("216")) {
|
||||
group.setBusinessGroup(channel.getBusinessGroupId());
|
||||
group.setParentDeviceId(channel.getParentId());
|
||||
}
|
||||
return group;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(@NotNull Group region) {
|
||||
return Integer.compare(Integer.parseInt(this.deviceId), Integer.parseInt(region.getDeviceId()));
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.genersoft.iot.vmp.gb28181.bean;
|
||||
|
||||
import com.genersoft.iot.vmp.common.CivilCodePo;
|
||||
import com.genersoft.iot.vmp.utils.CivilCodeUtil;
|
||||
import com.genersoft.iot.vmp.utils.DateUtil;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
@ -70,6 +71,19 @@ public class Region implements Comparable<Region>{
|
|||
return region;
|
||||
}
|
||||
|
||||
public static Region getInstance(DeviceChannel channel) {
|
||||
Region region = new Region();
|
||||
region.setName(channel.getName());
|
||||
region.setDeviceId(channel.getDeviceId());
|
||||
CivilCodePo parentCode = CivilCodeUtil.INSTANCE.getParentCode(channel.getDeviceId());
|
||||
if (parentCode != null) {
|
||||
region.setParentDeviceId(parentCode.getCode());
|
||||
}
|
||||
region.setCreateTime(DateUtil.getNow());
|
||||
region.setUpdateTime(DateUtil.getNow());
|
||||
return region;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(@NotNull Region region) {
|
||||
return Integer.compare(Integer.parseInt(this.deviceId), Integer.parseInt(region.getDeviceId()));
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.genersoft.iot.vmp.gb28181.dao;
|
|||
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Group;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.GroupTree;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Region;
|
||||
import org.apache.ibatis.annotations.*;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -152,4 +153,11 @@ public interface GroupMapper {
|
|||
" SET parent_device_id=#{group.deviceId}, business_group = #{group.businessGroup}" +
|
||||
" WHERE parent_device_id = #{oldDeviceId}")
|
||||
int updateChild(@Param("oldDeviceId") String oldDeviceId, Group group);
|
||||
|
||||
@Select(" <script>" +
|
||||
" SELECT * from wvp_common_group " +
|
||||
" where device_id in " +
|
||||
" <foreach collection='groupList' item='item' open='(' separator=',' close=')' > #{item.deviceId}</foreach>" +
|
||||
" </script>")
|
||||
List<Region> queryInGroupList(List<Group> groupList);
|
||||
}
|
||||
|
|
|
@ -89,4 +89,11 @@ public interface RegionMapper {
|
|||
" <foreach collection='allChildren' item='item' open='(' separator=',' close=')' > #{item.id}</foreach>" +
|
||||
" </script>")
|
||||
void batchDelete(List<Region> allChildren);
|
||||
|
||||
@Select(" <script>" +
|
||||
" SELECT * from wvp_common_region " +
|
||||
" where device_id in " +
|
||||
" <foreach collection='regionList' item='item' open='(' separator=',' close=')' > #{item.deviceId}</foreach>" +
|
||||
" </script>")
|
||||
List<Region> queryInRegionList(List<Region> regionList);
|
||||
}
|
||||
|
|
|
@ -19,4 +19,6 @@ public interface IGroupService {
|
|||
void syncFromChannel();
|
||||
|
||||
boolean delete(int id);
|
||||
|
||||
boolean batchAdd(List<Group> groupList);
|
||||
}
|
||||
|
|
|
@ -37,4 +37,6 @@ public interface IRegionService {
|
|||
void syncFromChannel();
|
||||
|
||||
boolean delete(int id);
|
||||
|
||||
boolean batchAdd(List<Region> regionList);
|
||||
}
|
||||
|
|
|
@ -16,7 +16,9 @@ import org.springframework.util.Assert;
|
|||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 区域管理类
|
||||
|
@ -234,4 +236,24 @@ public class GroupServiceImpl implements IGroupService {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean batchAdd(List<Group> groupList) {
|
||||
if (groupList== null || groupList.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
Map<String, Group> groupMapForVerification = new HashMap<>();
|
||||
for (Group group : groupList) {
|
||||
groupMapForVerification.put(group.getDeviceId(), group);
|
||||
}
|
||||
// 查询数据库中已经存在的.
|
||||
List<Region> regionListInDb = groupManager.queryInGroupList(groupList);
|
||||
if (!regionListInDb.isEmpty()) {
|
||||
for (Region region : regionListInDb) {
|
||||
groupMapForVerification.remove(region.getDeviceId());
|
||||
}
|
||||
}
|
||||
groupManager.batchAdd(new ArrayList<>(groupMapForVerification.values()));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,8 @@ import com.genersoft.iot.vmp.utils.DateUtil;
|
|||
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.DuplicateKeyException;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -29,6 +31,7 @@ import java.util.*;
|
|||
public class RegionServiceImpl implements IRegionService {
|
||||
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(RegionServiceImpl.class);
|
||||
@Autowired
|
||||
private RegionMapper regionMapper;
|
||||
|
||||
|
@ -177,4 +180,24 @@ public class RegionServiceImpl implements IRegionService {
|
|||
public boolean delete(int id) {
|
||||
return regionMapper.delete(id) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean batchAdd(List<Region> regionList) {
|
||||
if (regionList== null || regionList.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
Map<String, Region> regionMapForVerification = new HashMap<>();
|
||||
for (Region region : regionList) {
|
||||
regionMapForVerification.put(region.getDeviceId(), region);
|
||||
}
|
||||
// 查询数据库中已经存在的.
|
||||
List<Region> regionListInDb = regionMapper.queryInRegionList(regionList);
|
||||
if (!regionListInDb.isEmpty()) {
|
||||
for (Region region : regionListInDb) {
|
||||
regionMapForVerification.remove(region.getDeviceId());
|
||||
}
|
||||
}
|
||||
regionMapper.batchAdd(new ArrayList<>(regionMapForVerification.values()));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
package com.genersoft.iot.vmp.gb28181.session;
|
||||
|
||||
import com.genersoft.iot.vmp.gb28181.bean.CatalogData;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Device;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.SyncStatus;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.*;
|
||||
import com.genersoft.iot.vmp.gb28181.service.IDeviceChannelService;
|
||||
import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -39,7 +36,8 @@ public class CatalogDataCatch {
|
|||
}
|
||||
}
|
||||
|
||||
public void put(String deviceId, int sn, int total, Device device, List<DeviceChannel> deviceChannelList) {
|
||||
public void put(String deviceId, int sn, int total, Device device, List<DeviceChannel> deviceChannelList,
|
||||
List<Region> regionList, List<Group> groupList) {
|
||||
CatalogData catalogData = data.get(deviceId);
|
||||
if (catalogData == null) {
|
||||
catalogData = new CatalogData();
|
||||
|
@ -47,6 +45,8 @@ public class CatalogDataCatch {
|
|||
catalogData.setTotal(total);
|
||||
catalogData.setDevice(device);
|
||||
catalogData.setChannelList(deviceChannelList);
|
||||
catalogData.setRegionListList(regionList);
|
||||
catalogData.setGroupListListList(groupList);
|
||||
catalogData.setStatus(CatalogData.CatalogDataStatus.runIng);
|
||||
catalogData.setLastTime(Instant.now());
|
||||
data.put(deviceId, catalogData);
|
||||
|
@ -59,11 +59,13 @@ public class CatalogDataCatch {
|
|||
catalogData.setDevice(device);
|
||||
catalogData.setStatus(CatalogData.CatalogDataStatus.runIng);
|
||||
catalogData.getChannelList().addAll(deviceChannelList);
|
||||
catalogData.getRegionListList().addAll(regionList);
|
||||
catalogData.getGroupListListList().addAll(groupList);
|
||||
catalogData.setLastTime(Instant.now());
|
||||
}
|
||||
}
|
||||
|
||||
public List<DeviceChannel> get(String deviceId) {
|
||||
public List<DeviceChannel> getDeviceChannelList(String deviceId) {
|
||||
CatalogData catalogData = data.get(deviceId);
|
||||
if (catalogData == null) {
|
||||
return null;
|
||||
|
@ -71,6 +73,22 @@ public class CatalogDataCatch {
|
|||
return catalogData.getChannelList();
|
||||
}
|
||||
|
||||
public List<Region> getRegionList(String deviceId) {
|
||||
CatalogData catalogData = data.get(deviceId);
|
||||
if (catalogData == null) {
|
||||
return null;
|
||||
}
|
||||
return catalogData.getRegionListList();
|
||||
}
|
||||
|
||||
public List<Group> getGroupList(String deviceId) {
|
||||
CatalogData catalogData = data.get(deviceId);
|
||||
if (catalogData == null) {
|
||||
return null;
|
||||
}
|
||||
return catalogData.getGroupListListList();
|
||||
}
|
||||
|
||||
public int getTotal(String deviceId) {
|
||||
CatalogData catalogData = data.get(deviceId);
|
||||
if (catalogData == null) {
|
||||
|
|
|
@ -2,12 +2,13 @@ package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.respon
|
|||
|
||||
import com.genersoft.iot.vmp.conf.SipConfig;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.*;
|
||||
import com.genersoft.iot.vmp.gb28181.service.IGroupService;
|
||||
import com.genersoft.iot.vmp.gb28181.service.IRegionService;
|
||||
import com.genersoft.iot.vmp.gb28181.session.CatalogDataCatch;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessageHandler;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.ResponseMessageHandler;
|
||||
import com.genersoft.iot.vmp.gb28181.service.IDeviceChannelService;
|
||||
import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
|
||||
import gov.nist.javax.sip.message.SIPRequest;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dom4j.DocumentException;
|
||||
|
@ -17,6 +18,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.sip.InvalidArgumentException;
|
||||
import javax.sip.RequestEvent;
|
||||
|
@ -44,10 +46,13 @@ public class CatalogResponseMessageHandler extends SIPRequestProcessorParent imp
|
|||
private final ConcurrentLinkedQueue<HandlerCatchData> taskQueue = new ConcurrentLinkedQueue<>();
|
||||
|
||||
@Autowired
|
||||
private IVideoManagerStorage storager;
|
||||
private IDeviceChannelService deviceChannelService;
|
||||
|
||||
@Autowired
|
||||
private IDeviceChannelService deviceChannelService;
|
||||
private IRegionService regionService;
|
||||
|
||||
@Autowired
|
||||
private IGroupService groupService;
|
||||
|
||||
@Autowired
|
||||
private CatalogDataCatch catalogDataCatch;
|
||||
|
@ -66,6 +71,7 @@ public class CatalogResponseMessageHandler extends SIPRequestProcessorParent imp
|
|||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void handForDevice(RequestEvent evt, Device device, Element element) {
|
||||
taskQueue.offer(new HandlerCatchData(evt, device, element));
|
||||
// 回复200 OK
|
||||
|
@ -106,6 +112,8 @@ public class CatalogResponseMessageHandler extends SIPRequestProcessorParent imp
|
|||
Iterator<Element> deviceListIterator = deviceListElement.elementIterator();
|
||||
if (deviceListIterator != null) {
|
||||
List<DeviceChannel> channelList = new ArrayList<>();
|
||||
List<Region> regionList = new ArrayList<>();
|
||||
List<Group> groupList = new ArrayList<>();
|
||||
// 遍历DeviceList
|
||||
while (deviceListIterator.hasNext()) {
|
||||
Element itemDevice = deviceListIterator.next();
|
||||
|
@ -114,7 +122,7 @@ public class CatalogResponseMessageHandler extends SIPRequestProcessorParent imp
|
|||
continue;
|
||||
}
|
||||
DeviceChannel channel = DeviceChannel.decode(itemDevice);
|
||||
if (channel == null || channel.getDeviceId() == null) {
|
||||
if (channel.getDeviceId() == null) {
|
||||
log.info("[收到目录订阅]:但是解析失败 {}", new String(evt.getRequest().getRawContent()));
|
||||
continue;
|
||||
}
|
||||
|
@ -122,17 +130,30 @@ public class CatalogResponseMessageHandler extends SIPRequestProcessorParent imp
|
|||
if (channel.getParentId() != null && channel.getParentId().equals(sipConfig.getId())) {
|
||||
channel.setParentId(null);
|
||||
}
|
||||
// 解析通道类型
|
||||
if (channel.getDeviceId().length() <= 8) {
|
||||
// 行政区划
|
||||
Region region = Region.getInstance(channel);
|
||||
regionList.add(region);
|
||||
}else if (channel.getDeviceId().length() == 20){
|
||||
// 业务分组/虚拟组织
|
||||
Group group = Group.getInstance(channel);
|
||||
if (group != null) {
|
||||
groupList.add(group);
|
||||
}
|
||||
}
|
||||
channelList.add(channel);
|
||||
}
|
||||
int sn = Integer.parseInt(snElement.getText());
|
||||
catalogDataCatch.put(take.getDevice().getDeviceId(), sn, sumNum, take.getDevice(), channelList);
|
||||
log.info("[收到通道]设备: {} -> {}个,{}/{}", take.getDevice().getDeviceId(), channelList.size(), catalogDataCatch.get(take.getDevice().getDeviceId()) == null ? 0 : catalogDataCatch.get(take.getDevice().getDeviceId()).size(), sumNum);
|
||||
if (catalogDataCatch.get(take.getDevice().getDeviceId()).size() == sumNum) {
|
||||
catalogDataCatch.put(take.getDevice().getDeviceId(), sn, sumNum, take.getDevice(),
|
||||
channelList, regionList, groupList);
|
||||
log.info("[收到通道]设备: {} -> {}个,{}/{}", take.getDevice().getDeviceId(), channelList.size(), catalogDataCatch.getDeviceChannelList(take.getDevice().getDeviceId()) == null ? 0 : catalogDataCatch.getDeviceChannelList(take.getDevice().getDeviceId()).size(), sumNum);
|
||||
if (catalogDataCatch.getDeviceChannelList(take.getDevice().getDeviceId()).size() == sumNum) {
|
||||
// 数据已经完整接收, 此时可能存在某个设备离线变上线的情况,但是考虑到性能,此处不做处理,
|
||||
// 目前支持设备通道上线通知时和设备上线时向上级通知
|
||||
boolean resetChannelsResult = deviceChannelService.resetChannels(device.getId(), catalogDataCatch.get(take.getDevice().getDeviceId()));
|
||||
boolean resetChannelsResult = saveData(device);
|
||||
if (!resetChannelsResult) {
|
||||
String errorMsg = "接收成功,写入失败,共" + sumNum + "条,已接收" + catalogDataCatch.get(take.getDevice().getDeviceId()).size() + "条";
|
||||
String errorMsg = "接收成功,写入失败,共" + sumNum + "条,已接收" + catalogDataCatch.getDeviceChannelList(take.getDevice().getDeviceId()).size() + "条";
|
||||
catalogDataCatch.setChannelSyncEnd(take.getDevice().getDeviceId(), errorMsg);
|
||||
} else {
|
||||
catalogDataCatch.setChannelSyncEnd(take.getDevice().getDeviceId(), null);
|
||||
|
@ -152,13 +173,26 @@ public class CatalogResponseMessageHandler extends SIPRequestProcessorParent imp
|
|||
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public boolean saveData(Device device) {
|
||||
|
||||
boolean result = deviceChannelService.resetChannels(device.getId(), catalogDataCatch.getDeviceChannelList(device.getDeviceId()));
|
||||
if (!catalogDataCatch.getRegionList(device.getDeviceId()).isEmpty()) {
|
||||
result &= regionService.batchAdd(catalogDataCatch.getRegionList(device.getDeviceId()));
|
||||
}
|
||||
if (!catalogDataCatch.getGroupList(device.getDeviceId()).isEmpty()) {
|
||||
result &= groupService.batchAdd(catalogDataCatch.getGroupList(device.getDeviceId()));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handForPlatform(RequestEvent evt, ParentPlatform parentPlatform, Element rootElement) {
|
||||
|
||||
}
|
||||
|
||||
public SyncStatus getChannelSyncProgress(String deviceId) {
|
||||
if (catalogDataCatch.get(deviceId) == null) {
|
||||
if (catalogDataCatch.getDeviceChannelList(deviceId) == null) {
|
||||
return null;
|
||||
} else {
|
||||
return catalogDataCatch.getSyncStatus(deviceId);
|
||||
|
@ -166,7 +200,7 @@ public class CatalogResponseMessageHandler extends SIPRequestProcessorParent imp
|
|||
}
|
||||
|
||||
public boolean isSyncRunning(String deviceId) {
|
||||
if (catalogDataCatch.get(deviceId) == null) {
|
||||
if (catalogDataCatch.getDeviceChannelList(deviceId) == null) {
|
||||
return false;
|
||||
} else {
|
||||
return catalogDataCatch.isSyncRunning(deviceId);
|
||||
|
|
Loading…
Reference in New Issue