diff --git a/sql/common.sql b/sql/common.sql index 1102d3f8..a1a88baa 100644 --- a/sql/common.sql +++ b/sql/common.sql @@ -42,18 +42,16 @@ CREATE TABLE `wvp_common_gb_channel` ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -CREATE TABLE `wvp_common_business_group` +CREATE TABLE `wvp_common_group` ( - `common_business_group_id` bigint unsigned NOT NULL AUTO_INCREMENT, - `common_business_group_device_id` varchar(50) NOT NULL, - `common_business_group_name` varchar(255) NOT NULL, - `common_business_group_parent_id` varchar(50) DEFAULT NULL, - `common_business_group_path` varchar(500) DEFAULT NULL, - `common_business_group_gb_parent_id` varchar(500) DEFAULT NULL, - `common_business_group_create_time` varchar(50) NOT NULL, - `common_business_group_update_time` varchar(50) NOT NULL, - PRIMARY KEY (`common_business_group_id`), - UNIQUE KEY `common_business_group_device_id` (`common_business_group_device_id`) + `common_group_id` bigint unsigned NOT NULL AUTO_INCREMENT, + `common_group_device_id` varchar(50) NOT NULL, + `common_group_name` varchar(255) NOT NULL, + `common_group_parent_id` varchar(50) DEFAULT NULL, + `common_group_create_time` varchar(50) NOT NULL, + `common_group_update_time` varchar(50) NOT NULL, + PRIMARY KEY (`common_group_id`), + UNIQUE KEY `common_group_device_id` (`common_group_device_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; CREATE TABLE `wvp_common_region` @@ -62,7 +60,6 @@ CREATE TABLE `wvp_common_region` `common_region_device_id` varchar(50) NOT NULL, `common_region_name` varchar(255) NOT NULL, `common_region_parent_id` varchar(50) DEFAULT NULL, - `common_region_path` varchar(255) NOT NULL, `common_region_create_time` varchar(50) NOT NULL, `common_region_update_time` varchar(50) NOT NULL, PRIMARY KEY (`common_region_id`), @@ -83,7 +80,7 @@ CREATE TABLE `wvp_common_platform_channel` CREATE TABLE `wvp_common_platform_region` ( - `id` bigint unsigned NOT NULL AUTO_INCREMENT, + `id` bigint unsigned NOT NULL AUTO_INCREMENT, `platform_id` varchar(50) NOT NULL, `region_id` varchar(50) NOT NULL, PRIMARY KEY (`id`), diff --git a/src/main/java/com/genersoft/iot/vmp/conf/CivilCodeFileConf.java b/src/main/java/com/genersoft/iot/vmp/conf/CivilCodeFileConf.java index 20b6eef7..adb6daf3 100644 --- a/src/main/java/com/genersoft/iot/vmp/conf/CivilCodeFileConf.java +++ b/src/main/java/com/genersoft/iot/vmp/conf/CivilCodeFileConf.java @@ -1,6 +1,7 @@ package com.genersoft.iot.vmp.conf; import com.genersoft.iot.vmp.common.CivilCodePo; +import com.genersoft.iot.vmp.service.bean.Region; import org.ehcache.impl.internal.concurrent.ConcurrentHashMap; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -101,4 +102,24 @@ public class CivilCodeFileConf implements CommandLineRunner { } + public Region createRegion(String code) { + if (code.length() > 8) { + return null; + } + if (code.length() == 8) { + String parentCode = code.substring(0, 6); + return Region.getInstance(code, "未知地区_" + code, parentCode); + }else { + CivilCodePo civilCodePo = civilCodeMap.get(code); + if (civilCodePo == null){ + return null; + } + String parentCode = civilCodePo.getParentCode(); + if (parentCode == null) { + return null; + } + return Region.getInstance(code, civilCodePo.getName(), parentCode); + } + } + } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/ChannelIdType.java b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/ChannelIdType.java deleted file mode 100644 index 320bbdd0..00000000 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/ChannelIdType.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.genersoft.iot.vmp.gb28181.bean; - -/** - * 国标类型编码,国标编码中11-13位为类型编码 - * 详见 附 录 D 编码规则 A - * @author lin - */ -public class ChannelIdType { - /** - * 中心信令控制服务器编码 - */ - public final static String CENTRAL_SIGNALING_CONTROL_SERVER = "200"; - - /** - * 业务分组编码 - */ - public final static String BUSINESS_GROUP = "215"; - - /** - * 虚拟组织编码 - */ - public final static String VIRTUAL_ORGANIZATION = "216"; -} diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/Gb28181CodeType.java b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/Gb28181CodeType.java new file mode 100644 index 00000000..aea04321 --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/Gb28181CodeType.java @@ -0,0 +1,43 @@ +package com.genersoft.iot.vmp.gb28181.bean; + +import com.genersoft.iot.vmp.common.enums.DeviceControlType; +import org.dom4j.Element; +import org.springframework.util.ObjectUtils; + +public enum Gb28181CodeType { + + CIVIL_CODE_PROVINCE("CIVIL_CODE_PROVINCE","省级编号"), + CIVIL_CODE_CITY("CIVIL_CODE_CITY","市级编号"), + CIVIL_CODE_COUNTY("CIVIL_CODE_GRASS_ROOTS","区级编号"), + CIVIL_CODE_GRASS_ROOTS("CIVIL_CODE_GRASS_ROOTS","基层接入单位编号"), + BUSINESS_GROUP("BUSINESS_GROUP","业务分组"), + VIRTUAL_ORGANIZATION("VIRTUAL_ORGANIZATION","虚拟组织") + ; + + + private final String val; + + private final String desc; + + Gb28181CodeType(String val, String desc) { + this.val = val; + this.desc = desc; + } + + public String getVal() { + return val; + } + + public String getDesc() { + return desc; + } + + public static DeviceControlType typeOf(Element rootElement) { + for (DeviceControlType item : DeviceControlType.values()) { + if (!ObjectUtils.isEmpty(rootElement.element(item.getVal())) || !ObjectUtils.isEmpty(rootElement.elements(item.getVal()))) { + return item; + } + } + return null; + } +} diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/CatalogResponseMessageHandler.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/CatalogResponseMessageHandler.java index 691e107e..51b81d9e 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/CatalogResponseMessageHandler.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/CatalogResponseMessageHandler.java @@ -141,12 +141,11 @@ public class CatalogResponseMessageHandler extends SIPRequestProcessorParent imp // 数据已经完整接收, 此时可能存在某个设备离线变上线的情况,但是考虑到性能,此处不做处理, // 目前支持设备通道上线通知时和设备上线时向上级通知 boolean resetChannelsResult = deviceChannelService.resetChannels(take.getDevice(), catalogDataCatch.get(take.getDevice().getDeviceId())); + String errorMsg = null; if (!resetChannelsResult) { - String errorMsg = "接收成功,写入失败,共" + sumNum + "条,已接收" + catalogDataCatch.get(take.getDevice().getDeviceId()).size() + "条"; - catalogDataCatch.setChannelSyncEnd(take.getDevice().getDeviceId(), errorMsg); - } else { - catalogDataCatch.setChannelSyncEnd(take.getDevice().getDeviceId(), null); + errorMsg = "接收成功,写入失败,共" + sumNum + "条,已接收" + catalogDataCatch.get(take.getDevice().getDeviceId()).size() + "条"; } + catalogDataCatch.setChannelSyncEnd(take.getDevice().getDeviceId(), errorMsg); } } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/utils/SipUtils.java b/src/main/java/com/genersoft/iot/vmp/gb28181/utils/SipUtils.java index 38b94130..61b6b301 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/utils/SipUtils.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/utils/SipUtils.java @@ -1,6 +1,7 @@ package com.genersoft.iot.vmp.gb28181.utils; import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; +import com.genersoft.iot.vmp.gb28181.bean.Gb28181CodeType; import com.genersoft.iot.vmp.gb28181.bean.Gb28181Sdp; import com.genersoft.iot.vmp.gb28181.bean.RemoteAddressInfo; import com.genersoft.iot.vmp.utils.DateUtil; @@ -263,4 +264,46 @@ public class SipUtils { } return localDateTime.format(DateUtil.formatter); } + + public static Gb28181CodeType getChannelIdType(String channelId) { + int length = channelId.length(); + if (length <= 8) { + // 行政区划 + switch (length){ + case 2: + return Gb28181CodeType.CIVIL_CODE_PROVINCE; + case 4: + return Gb28181CodeType.CIVIL_CODE_CITY; + case 6: + return Gb28181CodeType.CIVIL_CODE_COUNTY; + case 8: + return Gb28181CodeType.CIVIL_CODE_GRASS_ROOTS; + default: + logger.warn("[不规范编号] 编号: {}, 长度: {}, 类型判定失败", channelId, length); + return null; + } + }else { + if (length != 20) { + logger.warn("[不规范编号] 编号: {}, 长度: {}, 尝试类型判定", channelId, length); + } + if (length < 13) { + logger.warn("[不规范编号] 编号: {}, 长度: {}, 无法获取类型编码(11、12、13),类型判定失败", channelId, length); + return null; + } + String codeTypeStr = channelId.substring(10, 13); + if (!NumericUtil.isInteger(codeTypeStr)) { + logger.warn("[不规范编号] 编号: {}, 长度: {}, 类型编码(11、12、13)存在非数字,类型判定失败", channelId, length); + return null; + } + int codeType = Integer.parseInt(codeTypeStr); + switch (codeType){ + case 215: + return Gb28181CodeType.BUSINESS_GROUP; + case 216: + return Gb28181CodeType.VIRTUAL_ORGANIZATION; + default: + return null; + } + } + } } \ No newline at end of file diff --git a/src/main/java/com/genersoft/iot/vmp/service/IBusinessGroupService.java b/src/main/java/com/genersoft/iot/vmp/service/IGroupService.java similarity index 81% rename from src/main/java/com/genersoft/iot/vmp/service/IBusinessGroupService.java rename to src/main/java/com/genersoft/iot/vmp/service/IGroupService.java index 3dd77638..92b2c17b 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/IBusinessGroupService.java +++ b/src/main/java/com/genersoft/iot/vmp/service/IGroupService.java @@ -1,19 +1,19 @@ package com.genersoft.iot.vmp.service; import com.genersoft.iot.vmp.common.CommonGbChannel; -import com.genersoft.iot.vmp.service.bean.BusinessGroup; +import com.genersoft.iot.vmp.service.bean.Group; import java.util.List; /** * 业务分组 */ -public interface IBusinessGroupService { +public interface IGroupService { /** * 查询业务分组 */ - List getNodes(String parentId); + List getNodes(String parentId); /** * 查询业务分组下的通道 @@ -28,7 +28,7 @@ public interface IBusinessGroupService { /** * 添加业务分组 */ - boolean add(BusinessGroup businessGroup); + boolean add(Group businessGroup); /** * 移除业务分组 @@ -43,7 +43,7 @@ public interface IBusinessGroupService { /** * 更新业务分组 */ - boolean update(BusinessGroup businessGroup); + boolean update(Group businessGroup); /** * 设置国标设备到相关的分组中 diff --git a/src/main/java/com/genersoft/iot/vmp/service/IRegionService.java b/src/main/java/com/genersoft/iot/vmp/service/IRegionService.java new file mode 100644 index 00000000..b8f59a38 --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/service/IRegionService.java @@ -0,0 +1,16 @@ +package com.genersoft.iot.vmp.service; + +import com.genersoft.iot.vmp.service.bean.Region; + +import java.util.List; + +public interface IRegionService { + + List getChildren(String parentDeviceId); + + void add(Region region); + + void deleteByDeviceId(String regionDeviceId); + + void updateRegionName(Region region); +} diff --git a/src/main/java/com/genersoft/iot/vmp/service/bean/BusinessGroup.java b/src/main/java/com/genersoft/iot/vmp/service/bean/BusinessGroup.java deleted file mode 100644 index f9723bd8..00000000 --- a/src/main/java/com/genersoft/iot/vmp/service/bean/BusinessGroup.java +++ /dev/null @@ -1,98 +0,0 @@ -package com.genersoft.iot.vmp.service.bean; - -/** - * 业务分组数据 - */ -public class BusinessGroup { - - /** - * 数据库自增ID - */ - private int commonBusinessGroupId; - - /** - * 分组国标编号 - */ - private String commonBusinessGroupDeviceId; - - /** - * 分组名称 - */ - private String commonBusinessGroupName; - - /** - * 分组名称 - */ - private String commonBusinessGroupParentId; - - /** - * 分组树的路径 - */ - private String commonBusinessGroupPath; - - /** - * 创建时间 - */ - private String commonBusinessGroupCreateTime; - - /** - * 更新时间 - */ - private String commonBusinessGroupUpdateTime; - - public int getCommonBusinessGroupId() { - return commonBusinessGroupId; - } - - public void setCommonBusinessGroupId(int commonBusinessGroupId) { - this.commonBusinessGroupId = commonBusinessGroupId; - } - - public String getCommonBusinessGroupDeviceId() { - return commonBusinessGroupDeviceId; - } - - public void setCommonBusinessGroupDeviceId(String commonBusinessGroupDeviceId) { - this.commonBusinessGroupDeviceId = commonBusinessGroupDeviceId; - } - - public String getCommonBusinessGroupName() { - return commonBusinessGroupName; - } - - public void setCommonBusinessGroupName(String commonBusinessGroupName) { - this.commonBusinessGroupName = commonBusinessGroupName; - } - - public String getCommonBusinessGroupPath() { - return commonBusinessGroupPath; - } - - public void setCommonBusinessGroupPath(String commonBusinessGroupPath) { - this.commonBusinessGroupPath = commonBusinessGroupPath; - } - - public String getCommonBusinessGroupParentId() { - return commonBusinessGroupParentId; - } - - public void setCommonBusinessGroupParentId(String commonBusinessGroupParentId) { - this.commonBusinessGroupParentId = commonBusinessGroupParentId; - } - - public String getCommonBusinessGroupCreateTime() { - return commonBusinessGroupCreateTime; - } - - public void setCommonBusinessGroupCreateTime(String commonBusinessGroupCreateTime) { - this.commonBusinessGroupCreateTime = commonBusinessGroupCreateTime; - } - - public String getCommonBusinessGroupUpdateTime() { - return commonBusinessGroupUpdateTime; - } - - public void setCommonBusinessGroupUpdateTime(String commonBusinessGroupUpdateTime) { - this.commonBusinessGroupUpdateTime = commonBusinessGroupUpdateTime; - } -} diff --git a/src/main/java/com/genersoft/iot/vmp/service/bean/Group.java b/src/main/java/com/genersoft/iot/vmp/service/bean/Group.java new file mode 100644 index 00000000..effcb341 --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/service/bean/Group.java @@ -0,0 +1,111 @@ +package com.genersoft.iot.vmp.service.bean; + +import com.genersoft.iot.vmp.utils.DateUtil; + +/** + * 分组数据 + */ +public class Group { + + /** + * 数据库自增ID + */ + private int commonGroupId; + + /** + * 分组国标编号 + */ + private String commonGroupDeviceId; + + /** + * 分组名称 + */ + private String commonGroupName; + + /** + * 分组父ID + */ + private String commonGroupParentId; + + /** + * 分组的顶级节点ID,对应多个虚拟组织的业务分组ID + */ + private String commonGroupTopId; + + /** + * 创建时间 + */ + private String commonGroupCreateTime; + + /** + * 更新时间 + */ + private String commonGroupUpdateTime; + + public static Group getInstance(String commonGroupDeviceId, String commonGroupName, String commonGroupParentId, String commonGroupTopId) { + Group group = new Group(); + group.setCommonGroupDeviceId(commonGroupDeviceId); + group.setCommonGroupName(commonGroupName); + group.setCommonGroupParentId(commonGroupParentId); + group.setCommonGroupTopId(commonGroupTopId); + group.setCommonGroupCreateTime(DateUtil.getNow()); + group.setCommonGroupUpdateTime(DateUtil.getNow()); + return group; + } + + public int getCommonGroupId() { + return commonGroupId; + } + + public void setCommonGroupId(int commonGroupId) { + this.commonGroupId = commonGroupId; + } + + public String getCommonGroupDeviceId() { + return commonGroupDeviceId; + } + + public void setCommonGroupDeviceId(String commonGroupDeviceId) { + this.commonGroupDeviceId = commonGroupDeviceId; + } + + public String getCommonGroupName() { + return commonGroupName; + } + + public void setCommonGroupName(String commonGroupName) { + this.commonGroupName = commonGroupName; + } + + public String getCommonGroupParentId() { + return commonGroupParentId; + } + + public void setCommonGroupParentId(String commonGroupParentId) { + this.commonGroupParentId = commonGroupParentId; + } + + public String getCommonGroupCreateTime() { + return commonGroupCreateTime; + } + + public void setCommonGroupCreateTime(String commonGroupCreateTime) { + this.commonGroupCreateTime = commonGroupCreateTime; + } + + public String getCommonGroupUpdateTime() { + return commonGroupUpdateTime; + } + + public void setCommonGroupUpdateTime(String commonGroupUpdateTime) { + this.commonGroupUpdateTime = commonGroupUpdateTime; + } + + public String getCommonGroupTopId() { + return commonGroupTopId; + } + + public void setCommonGroupTopId(String commonGroupTopId) { + this.commonGroupTopId = commonGroupTopId; + } +} diff --git a/src/main/java/com/genersoft/iot/vmp/service/bean/Region.java b/src/main/java/com/genersoft/iot/vmp/service/bean/Region.java new file mode 100644 index 00000000..84fba264 --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/service/bean/Region.java @@ -0,0 +1,96 @@ +package com.genersoft.iot.vmp.service.bean; + +import com.genersoft.iot.vmp.utils.DateUtil; + +/** + * 区域 + */ +public class Region { + /** + * 数据库自增ID + */ + private int commonRegionId; + + /** + * 区域国标编号 + */ + private String commonRegionDeviceId; + + /** + * 区域名称 + */ + private String commonRegionName; + + /** + * 父区域国标ID + */ + private String commonRegionParentId; + + /** + * 创建时间 + */ + private String commonRegionCreateTime; + + /** + * 更新时间 + */ + private String commonRegionUpdateTime; + + public static Region getInstance(String commonRegionDeviceId, String commonRegionName, String commonRegionParentId) { + Region region = new Region(); + region.setCommonRegionDeviceId(commonRegionDeviceId); + region.setCommonRegionName(commonRegionName); + region.setCommonRegionParentId(commonRegionParentId); + region.setCommonRegionCreateTime(DateUtil.getNow()); + region.setCommonRegionUpdateTime(DateUtil.getNow()); + return region; + } + + public int getCommonRegionId() { + return commonRegionId; + } + + public void setCommonRegionId(int commonRegionId) { + this.commonRegionId = commonRegionId; + } + + public String getCommonRegionDeviceId() { + return commonRegionDeviceId; + } + + public void setCommonRegionDeviceId(String commonRegionDeviceId) { + this.commonRegionDeviceId = commonRegionDeviceId; + } + + public String getCommonRegionName() { + return commonRegionName; + } + + public void setCommonRegionName(String commonRegionName) { + this.commonRegionName = commonRegionName; + } + + public String getCommonRegionParentId() { + return commonRegionParentId; + } + + public void setCommonRegionParentId(String commonRegionParentId) { + this.commonRegionParentId = commonRegionParentId; + } + + public String getCommonRegionCreateTime() { + return commonRegionCreateTime; + } + + public void setCommonRegionCreateTime(String commonRegionCreateTime) { + this.commonRegionCreateTime = commonRegionCreateTime; + } + + public String getCommonRegionUpdateTime() { + return commonRegionUpdateTime; + } + + public void setCommonRegionUpdateTime(String commonRegionUpdateTime) { + this.commonRegionUpdateTime = commonRegionUpdateTime; + } +} diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/CommonGbChannelServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/CommonGbChannelServiceImpl.java index 903e8693..2f0fd926 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/CommonGbChannelServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/CommonGbChannelServiceImpl.java @@ -1,13 +1,22 @@ package com.genersoft.iot.vmp.service.impl; import com.genersoft.iot.vmp.common.CommonGbChannel; +import com.genersoft.iot.vmp.conf.CivilCodeFileConf; import com.genersoft.iot.vmp.gb28181.bean.Device; import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; +import com.genersoft.iot.vmp.gb28181.bean.Gb28181CodeType; +import com.genersoft.iot.vmp.gb28181.utils.SipUtils; +import com.genersoft.iot.vmp.jt1078.proc.request.Re; import com.genersoft.iot.vmp.service.ICommonGbChannelService; +import com.genersoft.iot.vmp.service.bean.Group; import com.genersoft.iot.vmp.service.bean.CommonGbChannelType; +import com.genersoft.iot.vmp.service.bean.Region; import com.genersoft.iot.vmp.storager.dao.CommonGbChannelMapper; import com.genersoft.iot.vmp.storager.dao.DeviceChannelMapper; +import com.genersoft.iot.vmp.storager.dao.GroupMapper; +import com.genersoft.iot.vmp.storager.dao.RegionMapper; import com.genersoft.iot.vmp.utils.DateUtil; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.math.NumberUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -17,8 +26,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.TransactionDefinition; import org.springframework.transaction.TransactionStatus; -import java.util.ArrayList; -import java.util.List; +import java.util.*; @Service public class CommonGbChannelServiceImpl implements ICommonGbChannelService { @@ -32,10 +40,19 @@ public class CommonGbChannelServiceImpl implements ICommonGbChannelService { private DeviceChannelMapper deviceChannelMapper; @Autowired - DataSourceTransactionManager dataSourceTransactionManager; + private GroupMapper groupMapper; @Autowired - TransactionDefinition transactionDefinition; + private RegionMapper regionMapper; + + @Autowired + private DataSourceTransactionManager dataSourceTransactionManager; + + @Autowired + private TransactionDefinition transactionDefinition; + + @Autowired + private CivilCodeFileConf civilCodeFileConf; @Override @@ -77,20 +94,67 @@ public class CommonGbChannelServiceImpl implements ICommonGbChannelService { @Override public boolean syncChannelFromGb28181Device(String gbDeviceId, List syncKeys, Boolean syncGroup, Boolean syncRegion) { - logger.info("同步通用通道]来自国标设备,国标编号: {}", gbDeviceId); + logger.info("[同步通用通道]来自国标设备,国标编号: {}", gbDeviceId); List deviceChannels = deviceChannelMapper.queryAllChannels(gbDeviceId); if (deviceChannels.isEmpty()) { + logger.info("[同步通用通道]来自国标设备,结束, 通道数为0, 国标编号: {}", gbDeviceId); return false; } - List commonGbChannelList = new ArrayList<>(deviceChannels.size()); + List commonGbChannelList = new ArrayList<>(); + // 存储得到的10到13位为215的业务分组数据 + Map businessGroupMap = new HashMap<>(); + // 存储得到的10到13位为216的虚拟组织 数据 + Map virtuallyGroupMap = new HashMap<>(); + // 存储得到的行政区划数据 + Map regionMap = new HashMap<>(); + // 存储得到的所有parentId, 后续检验parentId是否已传输对应的分组/行政区划数据,从而确定是否需要自动创建节点。 + Set parentIdSet = new HashSet<>(); + // 存储得到的所有行政区划, 后续检验civilCode是否已传输对应的行政区划数据,从而确定是否需要自动创建节点。 + Set civilCodeSet = new HashSet<>(); List clearChannels = new ArrayList<>(); - for (DeviceChannel deviceChannel : deviceChannels) { + deviceChannels.stream().forEach(deviceChannel -> { if (deviceChannel.getCommonGbChannelId() > 0) { clearChannels.add(deviceChannel); } - CommonGbChannel commonGbChannel = getCommonChannelFromDeviceChannel(deviceChannel, syncKeys); - commonGbChannelList.add(commonGbChannel); - } + Gb28181CodeType channelIdType = SipUtils.getChannelIdType(deviceChannel.getChannelId()); + if (channelIdType != null) { + if ( + ( + channelIdType == Gb28181CodeType.CIVIL_CODE_PROVINCE + || channelIdType == Gb28181CodeType.CIVIL_CODE_CITY + || channelIdType == Gb28181CodeType.CIVIL_CODE_COUNTY + || channelIdType == Gb28181CodeType.CIVIL_CODE_GRASS_ROOTS + ) + && + !regionMap.containsKey(deviceChannel.getChannelId()) + ) { + // 行政区划条目 + Region region = Region.getInstance(deviceChannel.getChannelId(), deviceChannel.getName(), + civilCodeFileConf.getParentCode(deviceChannel.getChannelId()).getCode()); + regionMap.put(deviceChannel.getChannelId(), region); + } + if (channelIdType == Gb28181CodeType.BUSINESS_GROUP + && !businessGroupMap.containsKey(deviceChannel.getChannelId())) { + Group group = Group.getInstance(deviceChannel.getChannelId(), deviceChannel.getName(), + null, deviceChannel.getChannelId()); + businessGroupMap.put(deviceChannel.getChannelId(), group); + } + if (channelIdType == Gb28181CodeType.VIRTUAL_ORGANIZATION + && !virtuallyGroupMap.containsKey(deviceChannel.getChannelId())) { + Group group = Group.getInstance(deviceChannel.getChannelId(), deviceChannel.getName(), deviceChannel.getParentId(), null); + virtuallyGroupMap.put(deviceChannel.getChannelId(), group); + } + }else { + if (!StringUtils.isEmpty(deviceChannel.getParentId())) { + parentIdSet.add(deviceChannel.getParentId()); + } + if (!StringUtils.isEmpty(deviceChannel.getCivilCode())) { + civilCodeSet.add(deviceChannel.getCivilCode()); + } + CommonGbChannel commonGbChannel = getCommonChannelFromDeviceChannel(deviceChannel, syncKeys); + commonGbChannelList.add(commonGbChannel); + } + }); TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition); int limit = 50; if (!clearChannels.isEmpty()) { @@ -124,16 +188,170 @@ public class CommonGbChannelServiceImpl implements ICommonGbChannelService { int currentResult = commonGbChannelMapper.addAll(commonGbChannelListSub); if (currentResult <= 0) { dataSourceTransactionManager.rollback(transactionStatus); + logger.info("[同步通用通道]来自国标设备,失败, 写入数据库失败, 国标编号: {}", gbDeviceId); return false; } } result = true; } deviceChannelMapper.updateCommonChannelId(gbDeviceId); + + // 为虚拟组织数据补充业务分组ID + if (!virtuallyGroupMap.isEmpty()) { + for (Group virtuallyGroup : virtuallyGroupMap.values()) { + String topGroupId = getTopGroupId(businessGroupMap, virtuallyGroupMap, + virtuallyGroup.getCommonGroupDeviceId(), 0); + if (topGroupId == null) { + virtuallyGroupMap.remove(virtuallyGroup.getCommonGroupDeviceId()); + }else { + virtuallyGroup.setCommonGroupTopId(topGroupId); + } + + } + } + + List errorParentIdList = new ArrayList<>(); + // 检测ParentId字段数据是否不完整 + for (String parentId : parentIdSet) { + Gb28181CodeType channelIdType = SipUtils.getChannelIdType(parentId); + if (channelIdType == null) { + logger.warn("[不规范的ParentId设置]parentId不是虚拟组织编号,无法自动添加分组信息。 " + + "国标编号: {}, parentId: {}", gbDeviceId, parentId ); + continue; + } + if (channelIdType == Gb28181CodeType.CIVIL_CODE_PROVINCE + || channelIdType == Gb28181CodeType.CIVIL_CODE_CITY + || channelIdType == Gb28181CodeType.CIVIL_CODE_COUNTY + || channelIdType == Gb28181CodeType.CIVIL_CODE_GRASS_ROOTS + ){ + logger.warn("[不规范的ParentId设置]错误的将行政区划编号写入ParentId字段中,尝试纠正。 " + + "国标编号: {}, parentId: {}", gbDeviceId, parentId ); + if (!regionMap.containsKey(parentId)) { + Region region = civilCodeFileConf.createRegion(parentId); + regionMap.put(region.getCommonRegionDeviceId(), region); + } + }else if (channelIdType == Gb28181CodeType.BUSINESS_GROUP) { + logger.warn("[不规范的ParentId设置]错误的将通道的ParentId设置为业务分组,应该放在虚拟组织下,尝试纠正。 " + + "国标编号: {}, parentId: {}", gbDeviceId, parentId ); + // 注:纠正的方式为将parentId置空,这样可以在分组列表的<未分组>中找到这些通道,然后进行手动处理, + // 代码在getCommonChannelFromDeviceChannel中体现,这里只是做个日志提示下 + }else if (channelIdType == Gb28181CodeType.VIRTUAL_ORGANIZATION){ + Group virtuallyGroup = virtuallyGroupMap.get(parentId); + if (virtuallyGroup == null) { + // 如果下级同步的通道不包括这个虚拟组织的信息 + errorParentIdList.add(parentId); + }else { + String commonGroupTopId = virtuallyGroup.getCommonGroupTopId(); + // 如果下级同步的通道包括这个虚拟组织的信息, 但是没有对应的业务分组的信息 + if (!businessGroupMap.containsKey(commonGroupTopId)) { + errorParentIdList.add(parentId); + } + } + } + } + // 处理存在错误的parentId + if (!errorParentIdList.isEmpty()) { + if (errorParentIdList.size() <= limit) { + if (commonGbChannelMapper.clearParentIds(errorParentIdList) <= 0) { + dataSourceTransactionManager.rollback(transactionStatus); + logger.info("[同步通用通道]来自国标设备,失败, 处理错误的ParentId失败, 国标编号: {}", gbDeviceId); + return false; + } + } else { + for (int i = 0; i < errorParentIdList.size(); i += limit) { + int toIndex = i + limit; + if (i + limit > errorParentIdList.size()) { + toIndex = errorParentIdList.size(); + } + List errorParentIdListSub = errorParentIdList.subList(i, toIndex); + if (commonGbChannelMapper.clearParentIds(errorParentIdListSub) <= 0) { + dataSourceTransactionManager.rollback(transactionStatus); + logger.info("[同步通用通道]来自国标设备,失败, 处理错误的ParentId失败, 国标编号: {}", gbDeviceId); + return false; + } + } + } + } + // 分组信息写入数据库 + List allGroup = new ArrayList<>(businessGroupMap.values()); + allGroup.addAll(virtuallyGroupMap.values()); + if (allGroup.size() <= limit) { + if (groupMapper.addAll(allGroup) <= 0) { + dataSourceTransactionManager.rollback(transactionStatus); + logger.info("[同步通用通道]来自国标设备,失败,添加分组信息失败, 国标编号: {}", gbDeviceId); + return false; + } + } else { + for (int i = 0; i < allGroup.size(); i += limit) { + int toIndex = i + limit; + if (i + limit > allGroup.size()) { + toIndex = allGroup.size(); + } + List allGroupSub = allGroup.subList(i, toIndex); + if (groupMapper.addAll(allGroupSub) <= 0) { + dataSourceTransactionManager.rollback(transactionStatus); + logger.info("[同步通用通道]来自国标设备,失败,添加分组信息失败, 国标编号: {}", gbDeviceId); + return false; + } + } + } + + // 检测行政区划信息是否完整 + for (String civilCode : civilCodeSet) { + if (!regionMap.containsKey(civilCode)) { + logger.warn("[通道信息中缺少地区信息]补充地区信息 国标编号: {}, civilCode: {}", gbDeviceId, civilCode ); + Region region = civilCodeFileConf.createRegion(civilCode); + regionMap.put(region.getCommonRegionDeviceId(), region); + } + } + // 行政区划信息写入数据库 + List allRegion = new ArrayList<>(regionMap.values()); + if (!allRegion.isEmpty()) { + if (allRegion.size() <= limit) { + if (regionMapper.addAll(allRegion) <= 0) { + dataSourceTransactionManager.rollback(transactionStatus); + logger.info("[同步通用通道]来自国标设备,失败,添加行政区划信息失败, 国标编号: {}", gbDeviceId); + return false; + } + } else { + for (int i = 0; i < allRegion.size(); i += limit) { + int toIndex = i + limit; + if (i + limit > allRegion.size()) { + toIndex = allRegion.size(); + } + List allRegionSub = allRegion.subList(i, toIndex); + if (regionMapper.addAll(allRegionSub) <= 0) { + dataSourceTransactionManager.rollback(transactionStatus); + logger.info("[同步通用通道]来自国标设备,失败,添加行政区划信息失败, 国标编号: {}", gbDeviceId); + return false; + } + } + } + } dataSourceTransactionManager.commit(transactionStatus); return result; } + private String getTopGroupId(Map businessGroupMap, Map virtuallyGroupMap, String commonGroupId, int depth) { + if (depth >= 16) { + return null; + } + Group group = virtuallyGroupMap.get(commonGroupId); + if (group == null) { + return null; + } + Gb28181CodeType channelIdType = SipUtils.getChannelIdType(group.getCommonGroupParentId()); + if (channelIdType == Gb28181CodeType.BUSINESS_GROUP) { + if (businessGroupMap.containsKey(group.getCommonGroupParentId())) { + return group.getCommonGroupParentId(); + }else { + return null; + } + } + depth ++; + return getTopGroupId(businessGroupMap, virtuallyGroupMap, group.getCommonGroupParentId(), depth); + } + @Override public CommonGbChannel getCommonChannelFromDeviceChannel(DeviceChannel deviceChannel, List syncKeys) { if (deviceChannel == null) { @@ -150,11 +368,30 @@ public class CommonGbChannelServiceImpl implements ICommonGbChannelService { commonGbChannel.setCommonGbManufacturer(deviceChannel.getManufacture()); commonGbChannel.setCommonGbModel(deviceChannel.getModel()); commonGbChannel.setCommonGbOwner(deviceChannel.getOwner()); + Gb28181CodeType channelIdType = SipUtils.getChannelIdType(deviceChannel.getCivilCode()); + if (channelIdType == Gb28181CodeType.CIVIL_CODE_PROVINCE + || channelIdType == Gb28181CodeType.CIVIL_CODE_CITY + || channelIdType == Gb28181CodeType.CIVIL_CODE_COUNTY + || channelIdType == Gb28181CodeType.CIVIL_CODE_GRASS_ROOTS + ){ + commonGbChannel.setCommonGbCivilCode(deviceChannel.getCivilCode()); + }else { + logger.warn("[不规范的CivilCode],deviceId: {}, channel: {}, civilCode: {}", + deviceChannel.getDeviceId(), + deviceChannel.getChannelId(), + deviceChannel.getCivilCode()); + } + commonGbChannel.setCommonGbCivilCode(deviceChannel.getCivilCode()); commonGbChannel.setCommonGbBlock(deviceChannel.getBlock()); commonGbChannel.setCommonGbAddress(deviceChannel.getAddress()); - commonGbChannel.setCommonGbParental(deviceChannel.getParental()); - commonGbChannel.setCommonGbParentID(deviceChannel.getParentId()); + commonGbChannel.setCommonGbParental(0); + // 不符合国标的parentId,可以在未分组中找到并重新设置分组信息 + Gb28181CodeType parentIdIdType = SipUtils.getChannelIdType(deviceChannel.getParentId()); + if (parentIdIdType == Gb28181CodeType.VIRTUAL_ORGANIZATION) { + commonGbChannel.setCommonGbParentID(deviceChannel.getParentId()); + } + commonGbChannel.setCommonGbSafetyWay(deviceChannel.getSafetyWay()); commonGbChannel.setCommonGbRegisterWay(deviceChannel.getRegisterWay()); commonGbChannel.setCommonGbCertNum(deviceChannel.getCertNum()); @@ -188,6 +425,19 @@ public class CommonGbChannelServiceImpl implements ICommonGbChannelService { commonGbChannel.setCommonGbOwner(deviceChannel.getOwner()); break; case "commonGbCivilCode": + Gb28181CodeType channelIdType = SipUtils.getChannelIdType(deviceChannel.getCivilCode()); + if (channelIdType == Gb28181CodeType.CIVIL_CODE_PROVINCE + || channelIdType == Gb28181CodeType.CIVIL_CODE_CITY + || channelIdType == Gb28181CodeType.CIVIL_CODE_COUNTY + || channelIdType == Gb28181CodeType.CIVIL_CODE_GRASS_ROOTS + ){ + commonGbChannel.setCommonGbCivilCode(deviceChannel.getCivilCode()); + }else { + logger.warn("[不规范的CivilCode],deviceId: {}, channel: {}, civilCode: {}", + deviceChannel.getDeviceId(), + deviceChannel.getChannelId(), + deviceChannel.getCivilCode()); + } commonGbChannel.setCommonGbCivilCode(deviceChannel.getCivilCode()); break; case "commonGbBlock": diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceChannelServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceChannelServiceImpl.java index a44dc89d..601be2fb 100755 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceChannelServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceChannelServiceImpl.java @@ -285,10 +285,10 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService { } List allChannels = channelMapper.queryAllChannels(device.getDeviceId()); Map allChannelMap = new ConcurrentHashMap<>(); - if (allChannels.size() > 0) { - for (DeviceChannel deviceChannel : allChannels) { + if (!allChannels.isEmpty()) { + allChannels.stream().forEach(deviceChannel -> { allChannelMap.put(deviceChannel.getChannelId(), deviceChannel); - } + }); } // 数据去重 List channels = new ArrayList<>(); @@ -337,7 +337,7 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService { } } } - if (channels.size() > 0) { + if (!channels.isEmpty()) { for (DeviceChannel channel : channels) { if (subContMap.get(channel.getChannelId()) != null){ Integer count = subContMap.get(channel.getChannelId()); @@ -371,33 +371,34 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService { cleanChannelsResult = channelMapper.cleanChannelsNotInList(device.getDeviceId(), channels); } boolean result = cleanChannelsResult < 0; - if (!result && addChannels.size() > 0) { - if (addChannels.size() > limitCount) { - for (int i = 0; i < addChannels.size(); i += limitCount) { - int toIndex = i + limitCount; - if (i + limitCount > addChannels.size()) { - toIndex = addChannels.size(); + if (!result) { + if (!addChannels.isEmpty()) { + if (addChannels.size() > limitCount) { + for (int i = 0; i < addChannels.size(); i += limitCount) { + int toIndex = i + limitCount; + if (i + limitCount > addChannels.size()) { + toIndex = addChannels.size(); + } + result = result || channelMapper.batchAdd(addChannels.subList(i, toIndex)) < 0; } - result = result || channelMapper.batchAdd(addChannels.subList(i, toIndex)) < 0; + }else { + result = channelMapper.batchAdd(addChannels) < 0; + } + } + if (!updateChannels.isEmpty()) { + if (updateChannels.size() > limitCount) { + for (int i = 0; i < updateChannels.size(); i += limitCount) { + int toIndex = i + limitCount; + if (i + limitCount > updateChannels.size()) { + toIndex = updateChannels.size(); + } + result = result || channelMapper.batchUpdate(updateChannels.subList(i, toIndex)) < 0; + } + }else { + result = result || channelMapper.batchUpdate(updateChannels) < 0; } - }else { - result = result || channelMapper.batchAdd(addChannels) < 0; } } - if (!result && updateChannels.size() > 0) { - if (updateChannels.size() > limitCount) { - for (int i = 0; i < updateChannels.size(); i += limitCount) { - int toIndex = i + limitCount; - if (i + limitCount > updateChannels.size()) { - toIndex = updateChannels.size(); - } - result = result || channelMapper.batchUpdate(updateChannels.subList(i, toIndex)) < 0; - } - }else { - result = result || channelMapper.batchUpdate(updateChannels) < 0; - } - } - if (result) { //事务回滚 TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/BusinessGroupServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/GroupServiceImpl.java similarity index 81% rename from src/main/java/com/genersoft/iot/vmp/service/impl/BusinessGroupServiceImpl.java rename to src/main/java/com/genersoft/iot/vmp/service/impl/GroupServiceImpl.java index 755cbedc..6c02cc57 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/BusinessGroupServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/GroupServiceImpl.java @@ -1,9 +1,9 @@ package com.genersoft.iot.vmp.service.impl; import com.genersoft.iot.vmp.common.CommonGbChannel; -import com.genersoft.iot.vmp.service.IBusinessGroupService; -import com.genersoft.iot.vmp.service.bean.BusinessGroup; -import com.genersoft.iot.vmp.storager.dao.BusinessGroupMapper; +import com.genersoft.iot.vmp.service.IGroupService; +import com.genersoft.iot.vmp.service.bean.Group; +import com.genersoft.iot.vmp.storager.dao.GroupMapper; import com.genersoft.iot.vmp.storager.dao.CommonGbChannelMapper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -16,15 +16,15 @@ import org.springframework.transaction.TransactionStatus; import java.util.List; @Service -public class BusinessGroupServiceImpl implements IBusinessGroupService { +public class GroupServiceImpl implements IGroupService { - private final static Logger logger = LoggerFactory.getLogger(BusinessGroupServiceImpl.class); + private final static Logger logger = LoggerFactory.getLogger(GroupServiceImpl.class); @Autowired private CommonGbChannelMapper commonGbChannelDao; @Autowired - private BusinessGroupMapper businessGroupDao; + private GroupMapper businessGroupDao; @Autowired DataSourceTransactionManager dataSourceTransactionManager; @@ -34,13 +34,13 @@ public class BusinessGroupServiceImpl implements IBusinessGroupService { @Override - public List getNodes(String parentId) { + public List getNodes(String parentId) { return businessGroupDao.getNodes(parentId); } @Override public List getChannels(int id) { - BusinessGroup businessGroup = businessGroupDao.query(id); + Group businessGroup = businessGroupDao.query(id); if (businessGroup == null) { return null; } @@ -49,7 +49,7 @@ public class BusinessGroupServiceImpl implements IBusinessGroupService { @Override public List getChannels(String deviceId) { - BusinessGroup businessGroup = businessGroupDao.queryByDeviceId(deviceId); + Group businessGroup = businessGroupDao.queryByDeviceId(deviceId); if (businessGroup == null) { return null; } @@ -57,7 +57,7 @@ public class BusinessGroupServiceImpl implements IBusinessGroupService { } @Override - public boolean add(BusinessGroup businessGroup) { + public boolean add(Group businessGroup) { return businessGroupDao.add(businessGroup) > 0; } @@ -72,11 +72,11 @@ public class BusinessGroupServiceImpl implements IBusinessGroupService { } @Override - public boolean update(BusinessGroup businessGroup) { + public boolean update(Group businessGroup) { if (businessGroup.getCommonBusinessGroupId() == 0) { return false; } - BusinessGroup businessGroupInDb = businessGroupDao.query(businessGroup.getCommonBusinessGroupId()); + Group businessGroupInDb = businessGroupDao.query(businessGroup.getCommonBusinessGroupId()); if (businessGroupInDb == null) { return false; } @@ -103,7 +103,7 @@ public class BusinessGroupServiceImpl implements IBusinessGroupService { if (channels.isEmpty()) { return false; } - BusinessGroup businessGroup = businessGroupDao.query(id); + Group businessGroup = businessGroupDao.query(id); if (businessGroup == null) { return false; } @@ -119,7 +119,7 @@ public class BusinessGroupServiceImpl implements IBusinessGroupService { if (channels.isEmpty()) { return false; } - BusinessGroup businessGroup = businessGroupDao.queryByDeviceId(deviceId); + Group businessGroup = businessGroupDao.queryByDeviceId(deviceId); if (businessGroup == null) { return false; } diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/RegionServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/RegionServiceImpl.java new file mode 100644 index 00000000..f425f0b5 --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/RegionServiceImpl.java @@ -0,0 +1,41 @@ +package com.genersoft.iot.vmp.service.impl; + +import com.genersoft.iot.vmp.service.IRegionService; +import com.genersoft.iot.vmp.service.bean.Region; +import com.genersoft.iot.vmp.storager.dao.RegionMapper; +import com.genersoft.iot.vmp.utils.DateUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * 区域管理类 + */ +@Service +public class RegionServiceImpl implements IRegionService { + + + @Autowired + private RegionMapper regionMapper; + + @Override + public List getChildren(String parentDeviceId) { + return regionMapper.getChildren(parentDeviceId); + } + + @Override + public void add(Region region) { + regionMapper.add(region); + } + + @Override + public void deleteByDeviceId(String regionDeviceId) { + regionMapper.deleteByDeviceId(regionDeviceId); + } + + @Override + public void updateRegionName(Region region) { + regionMapper.updateRegionName(region.getCommonRegionName(), DateUtil.getNow(), region.getCommonRegionDeviceId()); + } +} diff --git a/src/main/java/com/genersoft/iot/vmp/storager/dao/BusinessGroupMapper.java b/src/main/java/com/genersoft/iot/vmp/storager/dao/BusinessGroupMapper.java deleted file mode 100644 index fc7a7bb1..00000000 --- a/src/main/java/com/genersoft/iot/vmp/storager/dao/BusinessGroupMapper.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.genersoft.iot.vmp.storager.dao; - -import com.genersoft.iot.vmp.service.bean.BusinessGroup; -import org.apache.ibatis.annotations.*; -import org.springframework.stereotype.Repository; - -import java.util.List; - -@Mapper -@Repository -public interface BusinessGroupMapper { - - @Select(value = " ") - List getNodes(String parentId); - - @Select(" select * from wvp_common_business_group " + - " WHERE common_business_group_id = #{id} ") - BusinessGroup query(int id); - - @Select(" select * from wvp_common_business_group " + - " WHERE common_business_group_device_id = #{deviceId} ") - BusinessGroup queryByDeviceId(String deviceId); - - @Insert("INSERT INTO wvp_common_business_group (" + - "common_business_group_device_id, " + - "common_business_group_name, " + - "common_business_group_parent_id, " + - "common_business_group_path, " + - "common_business_group_update_time, " + - "common_business_group_create_time ) " + - "VALUES (" + - "#{commonBusinessGroupDeviceId}, " + - "#{commonBusinessGroupName}, " + - "#{commonBusinessGroupParentId}, " + - "#{commonBusinessGroupPath}, " + - "#{commonBusinessGroupUpdateTime}, " + - "#{commonBusinessGroupCreateTime})") - int add(BusinessGroup businessGroup); - - @Delete("delete from wvp_common_business_group where common_business_group_id = #{id}") - int remove(int id); - - - @Delete("delete from wvp_common_business_group where common_business_group_device_id = #{deviceId}") - int removeByDeviceId(String deviceId); - - - @Update(value = {" "}) - int update(BusinessGroup businessGroup); -} diff --git a/src/main/java/com/genersoft/iot/vmp/storager/dao/CommonGbChannelMapper.java b/src/main/java/com/genersoft/iot/vmp/storager/dao/CommonGbChannelMapper.java index 67707777..4cd58260 100644 --- a/src/main/java/com/genersoft/iot/vmp/storager/dao/CommonGbChannelMapper.java +++ b/src/main/java/com/genersoft/iot/vmp/storager/dao/CommonGbChannelMapper.java @@ -301,4 +301,10 @@ public interface CommonGbChannelMapper { " #{item.commonGbChannelId}" + "") void channelsOfflineFromList(List channelList); + + @Update("") + int clearParentIds(List errorParentIdList); } diff --git a/src/main/java/com/genersoft/iot/vmp/storager/dao/GroupMapper.java b/src/main/java/com/genersoft/iot/vmp/storager/dao/GroupMapper.java new file mode 100644 index 00000000..76a4d2eb --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/storager/dao/GroupMapper.java @@ -0,0 +1,83 @@ +package com.genersoft.iot.vmp.storager.dao; + +import com.genersoft.iot.vmp.service.bean.Group; +import org.apache.ibatis.annotations.*; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Mapper +@Repository +public interface GroupMapper { + + @Select(value = " ") + List getNodes(String parentId); + + @Select(" select * from wvp_common_group " + + " WHERE common_group_id = #{id} ") + Group query(int id); + + @Select(" select * from wvp_common_group " + + " WHERE common_group_device_id = #{deviceId} ") + Group queryByDeviceId(String deviceId); + + @Insert("INSERT INTO wvp_common_group (" + + "common_group_device_id, " + + "common_group_name, " + + "common_group_parent_id, " + + "common_group_update_time, " + + "common_group_create_time ) " + + "VALUES (" + + "#{commonGroupDeviceId}, " + + "#{commonGroupName}, " + + "#{commonGroupParentId}, " + + "#{commonGroupUpdateTime}, " + + "#{commonGroupCreateTime})") + int add(Group group); + + @Delete("delete from wvp_common_group where common_group_id = #{id}") + int remove(int id); + + + @Delete("delete from wvp_common_group where common_group_device_id = #{deviceId}") + int removeByDeviceId(String deviceId); + + + @Update(value = {" "}) + int update(Group Group); + + + @Insert(value = "") + int addAll(List allGroup); +} diff --git a/src/main/java/com/genersoft/iot/vmp/storager/dao/RegionMapper.java b/src/main/java/com/genersoft/iot/vmp/storager/dao/RegionMapper.java new file mode 100644 index 00000000..788f93f4 --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/storager/dao/RegionMapper.java @@ -0,0 +1,58 @@ +package com.genersoft.iot.vmp.storager.dao; + +import com.genersoft.iot.vmp.service.bean.Region; +import org.apache.ibatis.annotations.*; + +import java.util.List; + +@Mapper +public interface RegionMapper { + @Select("select * from wvp_common_region where common_region_parent_id = #{parentDeviceId}") + List getChildren(@Param("parentDeviceId") String parentDeviceId); + + @Insert("INSERT INTO wvp_common_region (" + + "common_region_device_id, " + + "common_region_name, " + + "common_region_parent_id, " + + "common_region_path, " + + "common_region_create_time, " + + "common_region_update_time ) " + + "VALUES (" + + "#{commonRegionDeviceId}, " + + "#{commonRegionName}, " + + "#{commonRegionParentId}, " + + "#{commonRegionPath}, " + + "#{commonRegionCreateTime}, " + + "#{commonRegionUpdateTime})") + int add(Region region); + + @Delete("delete from wvp_common_region where common_region_device_id = #{regionDeviceId}") + int deleteByDeviceId(@Param("regionDeviceId") String regionDeviceId); + + @Update(value = {" "}) + int updateRegionName(@Param("name") String name, @Param("updateTime") String updateTime, @Param("regionDeviceId") String regionDeviceId); + + @Insert(value = "") + int addAll(List allRegion); +}