添加从国标通道同步的方法

结构优化
648540858 2023-08-30 15:05:52 +08:00
parent 43fe078723
commit a730fc904b
3 changed files with 147 additions and 96 deletions

View File

@ -1,6 +1,7 @@
package com.genersoft.iot.vmp.service; package com.genersoft.iot.vmp.service;
import com.genersoft.iot.vmp.common.CommonGbChannel; import com.genersoft.iot.vmp.common.CommonGbChannel;
import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
import java.util.List; import java.util.List;
@ -10,6 +11,8 @@ public interface ICommonGbChannelService {
int add(CommonGbChannel channel); int add(CommonGbChannel channel);
int addFromGbChannel(DeviceChannel channel);
int delete(String channelId); int delete(String channelId);
int update(CommonGbChannel channel); int update(CommonGbChannel channel);

View File

@ -6,6 +6,8 @@ import com.genersoft.iot.vmp.service.ICommonGbChannelService;
import com.genersoft.iot.vmp.storager.dao.CommonGbChannelMapper; import com.genersoft.iot.vmp.storager.dao.CommonGbChannelMapper;
import com.genersoft.iot.vmp.storager.dao.DeviceChannelMapper; import com.genersoft.iot.vmp.storager.dao.DeviceChannelMapper;
import org.apache.commons.lang3.math.NumberUtils; import org.apache.commons.lang3.math.NumberUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.datasource.DataSourceTransactionManager; import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -18,6 +20,8 @@ import java.util.List;
@Service @Service
public class CommonGbChannelServiceImpl implements ICommonGbChannelService { public class CommonGbChannelServiceImpl implements ICommonGbChannelService {
private final static Logger logger = LoggerFactory.getLogger(CommonGbChannelServiceImpl.class);
@Autowired @Autowired
private CommonGbChannelMapper commonGbChannelMapper; private CommonGbChannelMapper commonGbChannelMapper;
@ -41,6 +45,18 @@ public class CommonGbChannelServiceImpl implements ICommonGbChannelService {
return commonGbChannelMapper.add(channel); return commonGbChannelMapper.add(channel);
} }
@Override
public int addFromGbChannel(DeviceChannel channel) {
CommonGbChannel commonGbChannel = commonGbChannelMapper.queryByDeviceID(channel.getChannelId());
logger.info("[添加通用通道]来自国标通道,国标编号: {}, 同步所有字段", channel.getChannelId());
if (commonGbChannel != null) {
logger.info("[添加通用通道]来自国标通道,失败,已存在。国标编号: {}", channel.getChannelId());
return 0;
}
CommonGbChannel commonChannelFromDeviceChannel = getCommonChannelFromDeviceChannel(channel, null);
return commonGbChannelMapper.add(commonChannelFromDeviceChannel);
}
@Override @Override
public int delete(String channelId) { public int delete(String channelId) {
return commonGbChannelMapper.deleteByDeviceID(channelId); return commonGbChannelMapper.deleteByDeviceID(channelId);
@ -58,6 +74,7 @@ public class CommonGbChannelServiceImpl implements ICommonGbChannelService {
@Override @Override
public boolean SyncChannelFromGb28181Device(String gbDeviceId, List<String> syncKeys) { public boolean SyncChannelFromGb28181Device(String gbDeviceId, List<String> syncKeys) {
logger.info("同步通用通道]来自国标设备,国标编号: {}", gbDeviceId);
List<DeviceChannel> deviceChannels = deviceChannelMapper.queryAllChannels(gbDeviceId); List<DeviceChannel> deviceChannels = deviceChannelMapper.queryAllChannels(gbDeviceId);
if (deviceChannels.isEmpty()) { if (deviceChannels.isEmpty()) {
return false; return false;
@ -92,107 +109,138 @@ public class CommonGbChannelServiceImpl implements ICommonGbChannelService {
} }
private CommonGbChannel getCommonChannelFromDeviceChannel(DeviceChannel deviceChannel, List<String> syncKeys) { private CommonGbChannel getCommonChannelFromDeviceChannel(DeviceChannel deviceChannel, List<String> syncKeys) {
if (deviceChannel == null || syncKeys == null || syncKeys.isEmpty()) { if (deviceChannel == null) {
return null; return null;
} }
CommonGbChannel commonGbChannel = new CommonGbChannel(); CommonGbChannel commonGbChannel = new CommonGbChannel();
commonGbChannel.setCommonGbDeviceID(deviceChannel.getChannelId()); commonGbChannel.setCommonGbDeviceID(deviceChannel.getChannelId());
for (String key : syncKeys) { if (syncKeys == null || syncKeys.isEmpty()) {
switch (key) { commonGbChannel.setCommonGbName(deviceChannel.getName());
case "commonGbName": commonGbChannel.setCommonGbManufacturer(deviceChannel.getManufacture());
commonGbChannel.setCommonGbName(deviceChannel.getName()); commonGbChannel.setCommonGbModel(deviceChannel.getModel());
break; commonGbChannel.setCommonGbOwner(deviceChannel.getOwner());
case "commonGbManufacturer": commonGbChannel.setCommonGbCivilCode(deviceChannel.getCivilCode());
commonGbChannel.setCommonGbManufacturer(deviceChannel.getManufacture()); commonGbChannel.setCommonGbBlock(deviceChannel.getBlock());
break; commonGbChannel.setCommonGbAddress(deviceChannel.getAddress());
case "commonGbModel": commonGbChannel.setCommonGbParental(deviceChannel.getParental());
commonGbChannel.setCommonGbModel(deviceChannel.getModel()); commonGbChannel.setCommonGbParentID(deviceChannel.getParentId());
break; commonGbChannel.setCommonGbSafetyWay(deviceChannel.getSafetyWay());
case "commonGbOwner": commonGbChannel.setCommonGbRegisterWay(deviceChannel.getRegisterWay());
commonGbChannel.setCommonGbOwner(deviceChannel.getOwner()); commonGbChannel.setCommonGbCertNum(deviceChannel.getCertNum());
break; commonGbChannel.setCommonGbCertifiable(deviceChannel.getCertifiable());
case "commonGbCivilCode": commonGbChannel.setCommonGbErrCode(deviceChannel.getErrCode());
commonGbChannel.setCommonGbCivilCode(deviceChannel.getCivilCode()); commonGbChannel.setCommonGbEndTime(deviceChannel.getEndTime());
break; if (NumberUtils.isParsable(deviceChannel.getSecrecy())) {
case "commonGbBlock": commonGbChannel.setCommonGbSecrecy(Integer.parseInt(deviceChannel.getSecrecy()));
commonGbChannel.setCommonGbBlock(deviceChannel.getBlock()); }
break; commonGbChannel.setCommonGbIPAddress(deviceChannel.getIpAddress());
case "commonGbAddress": commonGbChannel.setCommonGbPort(deviceChannel.getPort());
commonGbChannel.setCommonGbAddress(deviceChannel.getAddress()); commonGbChannel.setCommonGbPassword(deviceChannel.getPassword());
break; commonGbChannel.setCommonGbStatus(deviceChannel.isStatus());
case "commonGbParental": commonGbChannel.setCommonGbLongitude(deviceChannel.getLongitude());
commonGbChannel.setCommonGbParental(deviceChannel.getParental()); commonGbChannel.setCommonGbLatitude(deviceChannel.getLatitude());
break; commonGbChannel.setCommonGbPtzType(deviceChannel.getPTZType());
case "commonGbParentID": commonGbChannel.setCommonGbPositionType(deviceChannel.getCommonGbPositionType());
commonGbChannel.setCommonGbParentID(deviceChannel.getParentId()); commonGbChannel.setCommonGbBusinessGroupID(deviceChannel.getBusinessGroupId());
break; } else {
case "commonGbSafetyWay": for (String key : syncKeys) {
commonGbChannel.setCommonGbSafetyWay(deviceChannel.getSafetyWay()); switch (key) {
break; case "commonGbName":
case "commonGbRegisterWay": commonGbChannel.setCommonGbName(deviceChannel.getName());
commonGbChannel.setCommonGbRegisterWay(deviceChannel.getRegisterWay()); break;
break; case "commonGbManufacturer":
case "commonGbCertNum": commonGbChannel.setCommonGbManufacturer(deviceChannel.getManufacture());
commonGbChannel.setCommonGbCertNum(deviceChannel.getCertNum()); break;
break; case "commonGbModel":
case "commonGbCertifiable": commonGbChannel.setCommonGbModel(deviceChannel.getModel());
commonGbChannel.setCommonGbCertifiable(deviceChannel.getCertifiable()); break;
break; case "commonGbOwner":
case "commonGbErrCode": commonGbChannel.setCommonGbOwner(deviceChannel.getOwner());
commonGbChannel.setCommonGbErrCode(deviceChannel.getErrCode()); break;
break; case "commonGbCivilCode":
case "commonGbEndTime": commonGbChannel.setCommonGbCivilCode(deviceChannel.getCivilCode());
commonGbChannel.setCommonGbEndTime(deviceChannel.getEndTime()); break;
break; case "commonGbBlock":
case "commonGbSecrecy": commonGbChannel.setCommonGbBlock(deviceChannel.getBlock());
if (NumberUtils.isParsable(deviceChannel.getSecrecy())) { break;
commonGbChannel.setCommonGbSecrecy(Integer.parseInt(deviceChannel.getSecrecy())); case "commonGbAddress":
} commonGbChannel.setCommonGbAddress(deviceChannel.getAddress());
break; break;
case "commonGbIPAddress": case "commonGbParental":
commonGbChannel.setCommonGbIPAddress(deviceChannel.getIpAddress()); commonGbChannel.setCommonGbParental(deviceChannel.getParental());
break; break;
case "commonGbPort": case "commonGbParentID":
commonGbChannel.setCommonGbPort(deviceChannel.getPort()); commonGbChannel.setCommonGbParentID(deviceChannel.getParentId());
break; break;
case "commonGbPassword": case "commonGbSafetyWay":
commonGbChannel.setCommonGbPassword(deviceChannel.getPassword()); commonGbChannel.setCommonGbSafetyWay(deviceChannel.getSafetyWay());
break; break;
case "commonGbStatus": case "commonGbRegisterWay":
commonGbChannel.setCommonGbStatus(deviceChannel.isStatus()); commonGbChannel.setCommonGbRegisterWay(deviceChannel.getRegisterWay());
break; break;
case "commonGbLongitude": case "commonGbCertNum":
commonGbChannel.setCommonGbLongitude(deviceChannel.getLongitude()); commonGbChannel.setCommonGbCertNum(deviceChannel.getCertNum());
break; break;
case "commonGbLatitude": case "commonGbCertifiable":
commonGbChannel.setCommonGbLatitude(deviceChannel.getLatitude()); commonGbChannel.setCommonGbCertifiable(deviceChannel.getCertifiable());
break; break;
case "commonGbPtzType": case "commonGbErrCode":
commonGbChannel.setCommonGbPtzType(deviceChannel.getPTZType()); commonGbChannel.setCommonGbErrCode(deviceChannel.getErrCode());
break; break;
case "commonGbPositionType": case "commonGbEndTime":
commonGbChannel.setCommonGbPositionType(deviceChannel.getCommonGbPositionType()); commonGbChannel.setCommonGbEndTime(deviceChannel.getEndTime());
break; break;
case "commonGbRoomType": case "commonGbSecrecy":
break; if (NumberUtils.isParsable(deviceChannel.getSecrecy())) {
case "commonGbUseType": commonGbChannel.setCommonGbSecrecy(Integer.parseInt(deviceChannel.getSecrecy()));
break; }
case "commonGbSupplyLightType": break;
break; case "commonGbIPAddress":
case "commonGbDirectionType": commonGbChannel.setCommonGbIPAddress(deviceChannel.getIpAddress());
break; break;
case "commonGbResolution": case "commonGbPort":
break; commonGbChannel.setCommonGbPort(deviceChannel.getPort());
case "commonGbBusinessGroupID": break;
commonGbChannel.setCommonGbBusinessGroupID(deviceChannel.getBusinessGroupId()); case "commonGbPassword":
break; commonGbChannel.setCommonGbPassword(deviceChannel.getPassword());
case "commonGbDownloadSpeed": break;
break; case "commonGbStatus":
case "commonGbSVCTimeSupportMode": commonGbChannel.setCommonGbStatus(deviceChannel.isStatus());
break; break;
case "commonGbLongitude":
commonGbChannel.setCommonGbLongitude(deviceChannel.getLongitude());
break;
case "commonGbLatitude":
commonGbChannel.setCommonGbLatitude(deviceChannel.getLatitude());
break;
case "commonGbPtzType":
commonGbChannel.setCommonGbPtzType(deviceChannel.getPTZType());
break;
case "commonGbPositionType":
commonGbChannel.setCommonGbPositionType(deviceChannel.getCommonGbPositionType());
break;
case "commonGbRoomType":
break;
case "commonGbUseType":
break;
case "commonGbSupplyLightType":
break;
case "commonGbDirectionType":
break;
case "commonGbResolution":
break;
case "commonGbBusinessGroupID":
commonGbChannel.setCommonGbBusinessGroupID(deviceChannel.getBusinessGroupId());
break;
case "commonGbDownloadSpeed":
break;
case "commonGbSVCTimeSupportMode":
break;
}
} }
} }
return commonGbChannel; return commonGbChannel;
} }
} }

View File

@ -10,13 +10,13 @@ import java.util.List;
@Repository @Repository
public interface BusinessGroupMapper { public interface BusinessGroupMapper {
@Select(value = {" <script>" + @Select(value = " <script>" +
" select * from wvp_common_business_group " + " select * from wvp_common_business_group " +
" WHERE 1=1 " + " WHERE 1=1 " +
" <if test='parentId != null' > AND common_business_group_parent_id = #{parentId}</if>" + " <if test='parentId != null' > AND common_business_group_parent_id = #{parentId}</if>" +
" <if test='parentId == null' > AND common_business_group_parent_id is null </if>" + " <if test='parentId == null' > AND common_business_group_parent_id is null </if>" +
" order by common_business_group_id ASC " + " order by common_business_group_id ASC " +
" </script>"}) " </script>")
List<BusinessGroup> getNodes(String parentId); List<BusinessGroup> getNodes(String parentId);
@Select(" select * from wvp_common_business_group " + @Select(" select * from wvp_common_business_group " +