diff --git a/sql/common.sql b/sql/common.sql index 06d50ca5..deb1a247 100644 --- a/sql/common.sql +++ b/sql/common.sql @@ -35,8 +35,8 @@ CREATE TABLE `wvp_common_gb_channel` `common_gb_download_speed` varchar(255) DEFAULT NULL, `common_gb_svc_time_support_mode` integer, `type` varchar(255) NOT NULL, - `updateTime` varchar(50) NOT NULL, - `createTime` varchar(50) NOT NULL, + `update_time` varchar(50) NOT NULL, + `create_time` varchar(50) NOT NULL, PRIMARY KEY (`common_gb_id`), UNIQUE KEY `common_gb_device_id` (`common_gb_device_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; diff --git a/src/main/java/com/genersoft/iot/vmp/common/BatchLimit.java b/src/main/java/com/genersoft/iot/vmp/common/BatchLimit.java index 8cd7227a..a5d19399 100644 --- a/src/main/java/com/genersoft/iot/vmp/common/BatchLimit.java +++ b/src/main/java/com/genersoft/iot/vmp/common/BatchLimit.java @@ -1,5 +1,5 @@ package com.genersoft.iot.vmp.common; public class BatchLimit { - public static final int count = 50; + public static final int count = 2; } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/session/CatalogDataCatch.java b/src/main/java/com/genersoft/iot/vmp/gb28181/session/CatalogDataCatch.java index df20fe2d..3ed8c954 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/session/CatalogDataCatch.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/session/CatalogDataCatch.java @@ -112,7 +112,7 @@ public class CatalogDataCatch { if ( catalogData.getLastTime().isBefore(instantBefore5S)) { // 超过五秒收不到消息任务超时, 只更新这一部分数据, 收到数据与声明的总数一致,则重置通道数据,数据不全则只对收到的数据做更新操作 if (catalogData.getStatus().equals(CatalogData.CatalogDataStatus.runIng)) { - deviceChannelService.updateChannels(catalogData.getDevice(), catalogData.getChannelList()); + deviceChannelService.updateChannelsForCatalog(catalogData.getDevice(), catalogData.getChannelList()); String errorMsg = "更新成功,共" + catalogData.getTotal() + "条,已更新" + catalogData.getChannelList().size() + "条"; catalogData.setErrorMsg(errorMsg); }else if (catalogData.getStatus().equals(CatalogData.CatalogDataStatus.ready)) { 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 2f83f568..bf91a716 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 @@ -140,7 +140,7 @@ public class CatalogResponseMessageHandler extends SIPRequestProcessorParent imp if (catalogDataCatch.get(take.getDevice().getDeviceId()).size() == sumNum) { // 数据已经完整接收, 此时可能存在某个设备离线变上线的情况,但是考虑到性能,此处不做处理, // 目前支持设备通道上线通知时和设备上线时向上级通知 - boolean resetChannelsResult = deviceChannelService.updateChannels(take.getDevice(), catalogDataCatch.get(take.getDevice().getDeviceId())); + boolean resetChannelsResult = deviceChannelService.updateChannelsForCatalog(take.getDevice(), catalogDataCatch.get(take.getDevice().getDeviceId())); String errorMsg = null; if (!resetChannelsResult) { errorMsg = "接收成功,写入失败,共" + sumNum + "条,已接收" + catalogDataCatch.get(take.getDevice().getDeviceId()).size() + "条"; diff --git a/src/main/java/com/genersoft/iot/vmp/service/IDeviceChannelService.java b/src/main/java/com/genersoft/iot/vmp/service/IDeviceChannelService.java index ad0b6ae3..7b125303 100755 --- a/src/main/java/com/genersoft/iot/vmp/service/IDeviceChannelService.java +++ b/src/main/java/com/genersoft/iot/vmp/service/IDeviceChannelService.java @@ -32,7 +32,7 @@ public interface IDeviceChannelService { * @param deviceId 设备id * @param channels 多个通道 */ - int updateChannels(String deviceId, List channels); + int updateChannelsForCatalog(String deviceId, List channels); /** * 获取统计信息 @@ -91,6 +91,6 @@ public interface IDeviceChannelService { /** * 重置通道 */ - boolean updateChannels(Device device, List deviceChannelList); + boolean updateChannelsForCatalog(Device device, List deviceChannelList); } 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 f213f836..82b4ffb2 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 @@ -723,14 +723,10 @@ public class CommonGbChannelServiceImpl implements ICommonGbChannelService { if (i + BatchLimit.count > commonGbChannels.size()) { toIndex = commonGbChannels.size(); } - if (commonGbChannelMapper.batchAdd(commonGbChannels.subList(i, toIndex)) < 0) { - throw new RuntimeException("batch add commonGbChannel fail"); - } + commonGbChannelMapper.batchAdd(commonGbChannels.subList(i, toIndex)); } }else { - if (commonGbChannelMapper.batchAdd(commonGbChannels) < 0) { - throw new RuntimeException("batch add commonGbChannel fail"); - } + commonGbChannelMapper.batchAdd(commonGbChannels); } } 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 61a33fba..aec31f06 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 @@ -47,6 +47,9 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService { @Autowired private DeviceChannelMapper channelMapper; + @Autowired + private CommonGbChannelMapper commonGbChannelMapper; + @Autowired private DeviceMapper deviceMapper; @@ -122,7 +125,7 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService { } @Override - public int updateChannels(String deviceId, List channels) { + public int updateChannelsForCatalog(String deviceId, List channels) { List addChannels = new ArrayList<>(); List updateChannels = new ArrayList<>(); HashMap channelsInStore = new HashMap<>(); @@ -283,31 +286,35 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService { @Override @Transactional - public boolean updateChannels(Device device, List deviceChannelList) { + public boolean updateChannelsForCatalog(Device device, List deviceChannelList) { if (CollectionUtils.isEmpty(deviceChannelList)) { return false; } Map allChannelMap = channelMapper.queryAllChannelsForMap(device.getDeviceId()); + Map allCommonChannelMap = commonGbChannelMapper.queryAllChannelsForMap(); // 存储数据,方便对数据去重 List channels = new ArrayList<>(); - // 存储需要更新的国标通道 - List updateChannelsForInfo = new ArrayList<>(); - // 存储需要更新的通用通道 - List updateCommonChannelsForInfo = new ArrayList<>(); - // 存储需要更新的分组 - List updateGroupForInfo = new ArrayList<>(); - // 存储需要更新的行政区划 - List updateRegionForInfo = new ArrayList<>(); // 存储需要需要新增的国标通道 - List addChannels = new ArrayList<>(); + List addChannelList = new ArrayList<>(); + // 存储需要更新的国标通道 + List updateChannelList = new ArrayList<>(); + // 存储需要需要新增的通用通道 - List addCommonChannels = new ArrayList<>(); + List addCommonChannelList = new ArrayList<>(); + // 存储需要更新的通用通道 + List updateCommonChannelList = new ArrayList<>(); + // 存储需要需要新增的分组 - List addGroups = new ArrayList<>(); + List addGroupList = new ArrayList<>(); + // 存储需要更新的分组 + List updateGroupList = new ArrayList<>(); + // 存储需要需要新增的行政区划 - List addRegions = new ArrayList<>(); + List addRegionList = new ArrayList<>(); + // 存储需要更新的行政区划 + List updateRegionList = new ArrayList<>(); Map subContMap = new HashMap<>(); @@ -339,18 +346,19 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService { deviceChannel.setCommonGbChannelId(channelInDb.getCommonGbChannelId()); deviceChannel.setUpdateTime(DateUtil.getNow()); // 同步时发现状态变化 - updateChannelsForInfo.add(deviceChannel); - if (channelIdType == null) { - updateCommonChannelsForInfo.add(CommonGbChannel.getInstance(null, deviceChannel)); - } + updateChannelList.add(deviceChannel); // 将需要更新的移除,剩下的都是需要删除的了 allChannelMap.remove(deviceChannel.getChannelId()); }else { deviceChannel.setCreateTime(DateUtil.getNow()); deviceChannel.setUpdateTime(DateUtil.getNow()); - addChannels.add(deviceChannel); - if (channelIdType == null) { - addCommonChannels.add(CommonGbChannel.getInstance(null, deviceChannel)); + addChannelList.add(deviceChannel); + } + if (channelIdType == null) { + if (allCommonChannelMap.containsKey(deviceChannel.getChannelId())) { + updateCommonChannelList.add(CommonGbChannel.getInstance(null, deviceChannel)); + }else { + addCommonChannelList.add(CommonGbChannel.getInstance(null, deviceChannel)); } } @@ -368,14 +376,14 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService { // 行政区划条目 region = Region.getInstance(deviceChannel.getChannelId(), deviceChannel.getName(), civilCode); - addRegions.add(region); + addRegionList.add(region); }else { // 区域存在记录并检查是否需要更新 region = regionMap.get(deviceChannel.getChannelId()); if (region.getCommonRegionName().equals(deviceChannel.getName())) { // 对于行政区划,父节点是不会变化的,所以只需要判断名称变化,执行更新就可以 region.setCommonRegionName(deviceChannel.getName()); - updateRegionForInfo.add(region); + updateRegionList.add(region); } } regionMap.put(region.getCommonRegionDeviceId(), region); @@ -385,14 +393,14 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService { if (!businessGroupMap.containsKey(deviceChannel.getChannelId())) { group = Group.getInstance(deviceChannel.getChannelId(), deviceChannel.getName(), null, deviceChannel.getChannelId()); - businessGroupMap.put(deviceChannel.getChannelId(), group); + addGroupList.add(group); }else { // 对于业务分组,因为它本身即使顶级节点,所以不能父节点变化,所以只需要考虑名称变化的情况 group = businessGroupMap.get(deviceChannel.getChannelId()); if (!group.getCommonGroupName().equals(deviceChannel.getName())) { group.setCommonGroupName(deviceChannel.getName()); } - updateGroupForInfo.add(group); + updateGroupList.add(group); } businessGroupMap.put(group.getCommonGroupDeviceId(), group); @@ -400,7 +408,7 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService { Group group; if (!virtuallyGroupMap.containsKey(deviceChannel.getChannelId())) { group = Group.getInstance(deviceChannel.getChannelId(), deviceChannel.getName(), deviceChannel.getParentId(), deviceChannel.getBusinessGroupId()); - virtuallyGroupMap.put(deviceChannel.getChannelId(), group); + addGroupList.add(group); }else { // 对于虚拟组织的变化,需要考虑三点, 名称, 顶级父节点(所属业务分组)或者 父节点 group = virtuallyGroupMap.get(deviceChannel.getChannelId()); @@ -411,16 +419,11 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService { group.setCommonGroupName(deviceChannel.getName()); group.setCommonGroupTopId(deviceChannel.getBusinessGroupId()); group.setCommonGroupParentId(deviceChannel.getParentId()); - updateGroupForInfo.add(group); + updateGroupList.add(group); } } virtuallyGroupMap.put(group.getCommonGroupDeviceId(), group); } - }else { - if (!StringUtils.isEmpty(deviceChannel.getCivilCode())) { - civilCodeSet.add(deviceChannel.getCivilCode()); - } - addCommonChannels.add(CommonGbChannel.getInstance(null, deviceChannel)); } channels.add(deviceChannel); @@ -452,21 +455,34 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService { }else { // 检查业务分组与虚拟组织 if (!virtuallyGroupMap.isEmpty()) { - for (String key : virtuallyGroupMap.keySet()) { - Group virtuallyGroup = virtuallyGroupMap.get(key); - if (virtuallyGroup.getCommonGroupTopId() == null - || !businessGroupMap.containsKey(virtuallyGroup.getCommonGroupTopId()) - ) { - virtuallyGroupMap.remove(key); + for (int i = 0; i < addGroupList.size(); i++) { + Group group = addGroupList.get(i); + if (ObjectUtils.isEmpty(group.getCommonGroupTopId())) { + if (businessGroupMap.containsKey(group.getCommonGroupParentId())) { + group.setCommonGroupTopId(group.getCommonGroupParentId()); + }else { + addGroupList.remove(i); + i--; + continue; + } + }else { + if (!businessGroupMap.containsKey(group.getCommonGroupTopId())) { + addGroupList.remove(i); + i--; + continue; + } + } + + if (!ObjectUtils.isEmpty(group.getCommonGroupParentId()) + && !virtuallyGroupMap.containsKey(group.getCommonGroupParentId())) { + addGroupList.remove(i); + i--; continue; } - if (virtuallyGroup.getCommonGroupParentId() != null && !virtuallyGroupMap.containsKey(virtuallyGroup.getCommonGroupParentId())) { - virtuallyGroup.setCommonGroupParentId(null); + if (!businessGroupMap.containsKey(group.getCommonGroupTopId())) { + group.setCommonGroupTopId(null); } } - if (virtuallyGroupMap.isEmpty()) { - businessGroupMap.clear(); - } } } // 对于只发送了行政区划编号,没有发送行政区划的情况进行兼容,自动为通道创建一个行政区划。 @@ -474,10 +490,13 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService { if (!regionMap.containsKey(civilCode)) { logger.warn("[通道信息中缺少地区信息]补充地区信息 civilCode: {}", civilCode ); if (civilCode.length() == 8) { - Region region = civilCodeFileConf.createRegion(civilCode.substring(0, 6)); - if (region != null) { - Region.getInstance(civilCode, region.getCommonRegionName() + "的基层组织", region.getCommonRegionDeviceId()); + Region parentRegion = civilCodeFileConf.createRegion(civilCode.substring(0, 6)); + if (parentRegion != null) { + Region region = Region.getInstance(civilCode, + parentRegion.getCommonRegionName() + "的基层组织", + parentRegion.getCommonRegionDeviceId()); regionMap.put(region.getCommonRegionDeviceId(), region); + addRegionList.add(region); }else { logger.warn("[获取地区信息]失败 civilCode: {}", civilCode ); } @@ -485,18 +504,16 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService { Region region = civilCodeFileConf.createRegion(civilCode); if (region != null) { regionMap.put(region.getCommonRegionDeviceId(), region); + addRegionList.add(region); }else { logger.warn("[获取地区信息]失败 civilCode: {}", civilCode ); } } - - - } } // 对待写入的数据做处理 - if (!addCommonChannels.isEmpty()) { - addCommonChannels.stream().forEach(commonGbChannel -> { + if (!addCommonChannelList.isEmpty()) { + addCommonChannelList.stream().forEach(commonGbChannel -> { if (commonGbChannel.getCommonGbParentID() != null && !virtuallyGroupMap.containsKey(commonGbChannel.getCommonGbParentID())) { commonGbChannel.setCommonGbParentID(null); @@ -540,108 +557,62 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService { commonGbChannelService.batchDelete(allCommonChannelsForDelete); } // addChannels 与 addCommonChannels 数量一致,这里使用同一个循环处理 - if (!addChannels.isEmpty()) { + if (!addChannelList.isEmpty()) { // 对于新增的部分需要先添加通用通道,拿到ID后再添加国标通道 - commonGbChannelService.batchAdd(addCommonChannels); - for (int j = 0; j < addCommonChannels.size(); j++) { - addChannels.get(j).setCommonGbChannelId(addCommonChannels.get(j).getCommonGbId()); - } - if (addChannels.size() > BatchLimit.count) { - for (int i = 0; i < addChannels.size(); i += BatchLimit.count) { - int toIndex = i + BatchLimit.count; - if (i + BatchLimit.count > addChannels.size()) { - toIndex = addChannels.size(); - } - channelMapper.batchAdd(addChannels.subList(i, toIndex)); - } - }else { - channelMapper.batchAdd(addChannels); + commonGbChannelService.batchAdd(addCommonChannelList); + for (int j = 0; j < addCommonChannelList.size(); j++) { + addChannelList.get(j).setCommonGbChannelId(addCommonChannelList.get(j).getCommonGbId()); } + addChannelHandler(addChannelList); + } - if (!updateChannelsForInfo.isEmpty()) { - if (updateChannelsForInfo.size() > BatchLimit.count) { - for (int i = 0; i < updateChannelsForInfo.size(); i += BatchLimit.count) { - int toIndex = i + BatchLimit.count; - if (i + BatchLimit.count > updateChannelsForInfo.size()) { - toIndex = updateChannelsForInfo.size(); - } - channelMapper.batchUpdate(updateChannelsForInfo.subList(i, toIndex)); - } - }else { - channelMapper.batchUpdate(updateChannelsForInfo); - } - commonGbChannelService.batchUpdate(updateCommonChannelsForInfo); + if (!updateChannelList.isEmpty()) { + commonGbChannelService.batchUpdate(updateCommonChannelList); + updateChannelHandler(updateChannelList); } // 写入分组数据 - List allGroup = new ArrayList<>(businessGroupMap.values()); - allGroup.addAll(virtuallyGroupMap.values()); - if (!allGroup.isEmpty()) { - // 这里也采取只插入新数据的方式 - List groupInDBList = groupMapper.queryInList(allGroup); - if (!groupInDBList.isEmpty()) { - groupInDBList.stream().forEach(groupInDB -> { - for (int i = 0; i < allGroup.size(); i++) { - if (groupInDB.getCommonGroupDeviceId().equalsIgnoreCase(allGroup.get(i).getCommonGroupDeviceId())) { - allGroup.remove(i); - break; - } - } - }); - } - if (!allGroup.isEmpty()) { - if (allGroup.size() <= BatchLimit.count) { - groupMapper.addAll(allGroup); - } else { - for (int i = 0; i < allGroup.size(); i += BatchLimit.count) { - int toIndex = i + BatchLimit.count; - if (i + BatchLimit.count > allGroup.size()) { - toIndex = allGroup.size(); - } - groupMapper.addAll(allGroup.subList(i, toIndex)); - } - } - } + if (!addGroupList.isEmpty()) { + addGroupHandler(addGroupList); + } + if (!updateGroupList.isEmpty()) { + updateGroupHandler(updateGroupList); } - // 写入地区 - List allRegion = new ArrayList<>(regionMap.values()); - if (!allRegion.isEmpty()) { - // 这里也采取只插入新数据的方式 - List regionInDBList = regionMapper.queryInList(allRegion); - List regionInForUpdate = new ArrayList<>(); - if (!regionInDBList.isEmpty()) { - regionInDBList.stream().forEach(regionInDB -> { - for (int i = 0; i < allRegion.size(); i++) { - if (regionInDB.getCommonRegionDeviceId().equalsIgnoreCase(allRegion.get(i).getCommonRegionDeviceId())) { - if (!regionInDB.getCommonRegionName().equals(allRegion.get(i).getCommonRegionName())) { - regionInForUpdate.add(allRegion.get(i)); - } - allRegion.remove(i); - break; + // 写入地区 + if (!addRegionList.isEmpty()) { + // 如果下级未发送完整的区域树,则通过自动探查补全 + addRegionList.stream().forEach((region -> { + if (!regionMap.containsKey(region.getCommonRegionParentId()) + && !ObjectUtils.isEmpty(region.getCommonRegionParentId()) + && region.getCommonRegionParentId().length() > 2) { + Region parentRegion = civilCodeFileConf.createRegion(region.getCommonRegionParentId()); + addRegionList.add(parentRegion); + String parentDeviceId = parentRegion.getCommonRegionParentId(); + if (parentDeviceId.length() == 6) { + CivilCodePo parentCode = civilCodeFileConf.getParentCode(region.getCommonRegionDeviceId()); + if (parentCode == null) { + return; + } + parentDeviceId = parentCode.getParentCode(); + if (regionMap.containsKey(region.getCommonRegionDeviceId())) { + addRegionList.add(Region.getInstance(parentCode.getCode(), + parentCode.getCode(), parentCode.getParentCode())); } } - }); - } - if (!allRegion.isEmpty()) { - if (allRegion.size() <= BatchLimit.count) { - if (regionMapper.addAll(allRegion) <= 0) { - regionMapper.addAll(allRegion); - } - } else { - for (int i = 0; i < allRegion.size(); i += BatchLimit.count) { - int toIndex = i + BatchLimit.count; - if (i + BatchLimit.count > allRegion.size()) { - toIndex = allRegion.size(); + if (parentDeviceId.length() == 4) { + CivilCodePo parentCode = civilCodeFileConf.getParentCode(region.getCommonRegionDeviceId()); + if (parentCode == null) { + return; } - List allRegionSub = allRegion.subList(i, toIndex); - regionMapper.addAll(allRegionSub); + addRegionList.add(Region.getInstance(parentCode.getCode(), + parentCode.getCode(), parentCode.getParentCode())); } } - } - // 对于名称变化的地区进行修改 - if (!regionInForUpdate.isEmpty()) { - regionMapper.updateAllForName(regionInForUpdate); - } + })); + addRegionHandler(addRegionList); + } + if (!updateRegionList.isEmpty()) { + updateRegionHandler(updateRegionList); } return true; }catch (Exception e) { @@ -657,4 +628,92 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService { || channelIdType == Gb28181CodeType.CIVIL_CODE_COUNTY || channelIdType == Gb28181CodeType.CIVIL_CODE_GRASS_ROOTS; } + + private void addChannelHandler(List addChannels) { + if (addChannels.size() > BatchLimit.count) { + for (int i = 0; i < addChannels.size(); i += BatchLimit.count) { + int toIndex = i + BatchLimit.count; + if (i + BatchLimit.count > addChannels.size()) { + toIndex = addChannels.size(); + } + channelMapper.batchAdd(addChannels.subList(i, toIndex)); + } + }else { + channelMapper.batchAdd(addChannels); + } + } + + private void updateChannelHandler(List updateChannels) { + if (updateChannels.size() > BatchLimit.count) { + for (int i = 0; i < updateChannels.size(); i += BatchLimit.count) { + int toIndex = i + BatchLimit.count; + if (i + BatchLimit.count > updateChannels.size()) { + toIndex = updateChannels.size(); + } + channelMapper.batchUpdate(updateChannels.subList(i, toIndex)); + } + }else { + channelMapper.batchUpdate(updateChannels); + } + } + + private void addRegionHandler(List regionList) { + if (regionList.size() <= BatchLimit.count) { + if (regionMapper.addAll(regionList) <= 0) { + regionMapper.addAll(regionList); + } + } else { + for (int i = 0; i < regionList.size(); i += BatchLimit.count) { + int toIndex = i + BatchLimit.count; + if (i + BatchLimit.count > regionList.size()) { + toIndex = regionList.size(); + } + List allRegionSub = regionList.subList(i, toIndex); + regionMapper.addAll(allRegionSub); + } + } + } + + private void updateRegionHandler(List regionList) { + if (regionList.size() <= BatchLimit.count) { + regionMapper.updateAllForName(regionList); + } else { + for (int i = 0; i < regionList.size(); i += BatchLimit.count) { + int toIndex = i + BatchLimit.count; + if (i + BatchLimit.count > regionList.size()) { + toIndex = regionList.size(); + } + List allRegionSub = regionList.subList(i, toIndex); + regionMapper.updateAllForName(allRegionSub); + } + } + } + + private void addGroupHandler(List groupList) { + if (groupList.size() <= BatchLimit.count) { + groupMapper.addAll(groupList); + } else { + for (int i = 0; i < groupList.size(); i += BatchLimit.count) { + int toIndex = i + BatchLimit.count; + if (i + BatchLimit.count > groupList.size()) { + toIndex = groupList.size(); + } + groupMapper.addAll(groupList.subList(i, toIndex)); + } + } + } + + private void updateGroupHandler(List groupList) { + if (groupList.size() <= BatchLimit.count) { + groupMapper.updateAll(groupList); + } else { + for (int i = 0; i < groupList.size(); i += BatchLimit.count) { + int toIndex = i + BatchLimit.count; + if (i + BatchLimit.count > groupList.size()) { + toIndex = groupList.size(); + } + groupMapper.updateAll(groupList.subList(i, toIndex)); + } + } + } } diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java index 0d99eccd..697d5c7d 100755 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java @@ -390,7 +390,7 @@ public class DeviceServiceImpl implements IDeviceService { for (DeviceChannel deviceChannel : deviceChannels) { deviceChannelsForStore.add(deviceChannelService.updateGps(deviceChannel, device)); } - deviceChannelService.updateChannels(device.getDeviceId(), deviceChannelsForStore); + deviceChannelService.updateChannelsForCatalog(device.getDeviceId(), deviceChannelsForStore); } } 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 21682605..441bc882 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 @@ -10,6 +10,7 @@ import org.apache.ibatis.annotations.*; import org.springframework.stereotype.Repository; import java.util.List; +import java.util.Map; @Mapper @Repository @@ -21,7 +22,7 @@ public interface CommonGbChannelMapper { @Update(value = "") int batchAdd(@Param("commonGbChannels") List commonGbChannels); @@ -530,7 +532,7 @@ public interface CommonGbChannelMapper { " ,common_gb_civilCode = #{item.commonGbCivilCode} " + " ,common_gb_block = #{item.commonGbBlock} " + " ,common_gb_address = #{item.commonGbAddress} " + - " ,common_gb_parental = #{item.commonGbParental} " + + " ,common_gb_parental = #{item.commonGbParental} " + " ,common_gb_parent_id = #{item.commonGbParentID} " + " ,common_gb_safety_way = #{item.commonGbSafetyWay} " + " ,common_gb_register_way = #{item.commonGbRegisterWay} " + @@ -570,4 +572,9 @@ public interface CommonGbChannelMapper { "#{item}" + " "}) int batchDelete(@Param("ids") List ids); + + @MapKey("commonGbDeviceID") + @Select("select * from wvp_common_gb_channel") + Map queryAllChannelsForMap(); + } 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 index 13038b6e..62473245 100644 --- a/src/main/java/com/genersoft/iot/vmp/storager/dao/GroupMapper.java +++ b/src/main/java/com/genersoft/iot/vmp/storager/dao/GroupMapper.java @@ -150,4 +150,17 @@ public interface GroupMapper { @MapKey("commonGroupDeviceId") @Select("select * from wvp_common_group where common_group_device_id != common_group_top_id") Map queryNotTopGroupForMap(); + + @Update({""}) + int updateAll(@Param("groupList") List groupList); }