优化通用通道同步,待完成

结构优化
648540858 2023-11-28 18:56:39 +08:00
parent 5a5108c827
commit e44be505d9
10 changed files with 243 additions and 168 deletions

View File

@ -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;

View File

@ -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;
}

View File

@ -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)) {

View File

@ -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() + "条";

View File

@ -32,7 +32,7 @@ public interface IDeviceChannelService {
* @param deviceId id
* @param channels
*/
int updateChannels(String deviceId, List<DeviceChannel> channels);
int updateChannelsForCatalog(String deviceId, List<DeviceChannel> channels);
/**
*
@ -91,6 +91,6 @@ public interface IDeviceChannelService {
/**
*
*/
boolean updateChannels(Device device, List<DeviceChannel> deviceChannelList);
boolean updateChannelsForCatalog(Device device, List<DeviceChannel> deviceChannelList);
}

View File

@ -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);
}
}

View File

@ -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<DeviceChannel> channels) {
public int updateChannelsForCatalog(String deviceId, List<DeviceChannel> channels) {
List<DeviceChannel> addChannels = new ArrayList<>();
List<DeviceChannel> updateChannels = new ArrayList<>();
HashMap<String, DeviceChannel> channelsInStore = new HashMap<>();
@ -283,31 +286,35 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService {
@Override
@Transactional
public boolean updateChannels(Device device, List<DeviceChannel> deviceChannelList) {
public boolean updateChannelsForCatalog(Device device, List<DeviceChannel> deviceChannelList) {
if (CollectionUtils.isEmpty(deviceChannelList)) {
return false;
}
Map<String, DeviceChannel> allChannelMap = channelMapper.queryAllChannelsForMap(device.getDeviceId());
Map<String, CommonGbChannel> allCommonChannelMap = commonGbChannelMapper.queryAllChannelsForMap();
// 存储数据,方便对数据去重
List<DeviceChannel> channels = new ArrayList<>();
// 存储需要更新的国标通道
List<DeviceChannel> updateChannelsForInfo = new ArrayList<>();
// 存储需要更新的通用通道
List<CommonGbChannel> updateCommonChannelsForInfo = new ArrayList<>();
// 存储需要更新的分组
List<Group> updateGroupForInfo = new ArrayList<>();
// 存储需要更新的行政区划
List<Region> updateRegionForInfo = new ArrayList<>();
// 存储需要需要新增的国标通道
List<DeviceChannel> addChannels = new ArrayList<>();
List<DeviceChannel> addChannelList = new ArrayList<>();
// 存储需要更新的国标通道
List<DeviceChannel> updateChannelList = new ArrayList<>();
// 存储需要需要新增的通用通道
List<CommonGbChannel> addCommonChannels = new ArrayList<>();
List<CommonGbChannel> addCommonChannelList = new ArrayList<>();
// 存储需要更新的通用通道
List<CommonGbChannel> updateCommonChannelList = new ArrayList<>();
// 存储需要需要新增的分组
List<Group> addGroups = new ArrayList<>();
List<Group> addGroupList = new ArrayList<>();
// 存储需要更新的分组
List<Group> updateGroupList = new ArrayList<>();
// 存储需要需要新增的行政区划
List<Region> addRegions = new ArrayList<>();
List<Region> addRegionList = new ArrayList<>();
// 存储需要更新的行政区划
List<Region> updateRegionList = new ArrayList<>();
Map<String, Integer> 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<Group> allGroup = new ArrayList<>(businessGroupMap.values());
allGroup.addAll(virtuallyGroupMap.values());
if (!allGroup.isEmpty()) {
// 这里也采取只插入新数据的方式
List<Group> 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<Region> allRegion = new ArrayList<>(regionMap.values());
if (!allRegion.isEmpty()) {
// 这里也采取只插入新数据的方式
List<Region> regionInDBList = regionMapper.queryInList(allRegion);
List<Region> 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<Region> 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<DeviceChannel> 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<DeviceChannel> 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<Region> 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<Region> allRegionSub = regionList.subList(i, toIndex);
regionMapper.addAll(allRegionSub);
}
}
}
private void updateRegionHandler(List<Region> 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<Region> allRegionSub = regionList.subList(i, toIndex);
regionMapper.updateAllForName(allRegionSub);
}
}
}
private void addGroupHandler(List<Group> 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<Group> 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));
}
}
}
}

View File

@ -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);
}
}

View File

@ -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 = "<script>" +
"<foreach collection='channels' item='item' separator=';'>" +
"UPDATE wvp_common_gb_channel SET " +
"updateTime= #{ item.updateTime} " +
"update_time= #{ item.updateTime} " +
" <if test='item.commonGbDeviceID != null' > ,common_gb_device_id= #{ item.commonGbDeviceID} </if>" +
" <if test='item.commonGbName != null' > ,common_gb_name= #{ item.commonGbName} </if>" +
" <if test='item.commonGbManufacturer != null' > ,common_gb_manufacturer= #{ item.commonGbManufacturer} </if>" +
@ -30,7 +31,7 @@ public interface CommonGbChannelMapper {
" <if test='item.commonGbCivilCode != null' > ,common_gb_civilCode= #{ item.commonGbCivilCode} </if>" +
" <if test='item.commonGbBlock != null' > ,common_gb_block= #{ item.commonGbBlock} </if>" +
" <if test='item.commonGbAddress != null' > ,common_gb_address= #{ item.commonGbAddress} </if>" +
" <if test='item.common_gb_parental != null' > ,common_gb_parental= #{ item.commonGbParental} </if>" +
" <if test='item.commonGbParental != null' > ,common_gb_parental= #{ item.commonGbParental} </if>" +
" <if test='item.commonGbParentID != null' > ,common_gb_parent_id= #{ item.commonGbParentID} </if>" +
" <if test='item.commonGbSafetyWay != null' > ,common_gb_safety_way= #{ item.commonGbSafetyWay} </if>" +
" <if test='item.commonGbRegisterWay != null' > ,common_gb_register_way= #{ item.commonGbRegisterWay} </if>" +
@ -108,8 +109,8 @@ public interface CommonGbChannelMapper {
" <if test='common_gb_download_speed != null' > ,common_gb_download_speed </if>" +
" <if test='common_gb_svc_time_support_mode != null' > ,common_gb_svc_time_support_mode </if>" +
" <if test='type != null' > ,type </if>" +
" <if test='updateTime != null' > ,updateTime </if>" +
" <if test='createTime != null' > ,createTime </if>" +
" <if test='updateTime != null' > ,update_time </if>" +
" <if test='createTime != null' > ,create_time </if>" +
") values (" +
"#{commonGbDeviceID}" +
" <if test='common_gb_name != null' > ,#{commonGbName}</if>" +
@ -156,7 +157,7 @@ public interface CommonGbChannelMapper {
@Update(value = "<script>" +
"UPDATE wvp_common_gb_channel SET " +
"updateTime= #{ updateTime} " +
"update_time= #{ updateTime} " +
" <if test='commonGbDeviceID != null' > ,common_gb_device_id= #{ commonGbDeviceID} </if>" +
" <if test='commonGbName != null' > ,common_gb_name= #{ commonGbName} </if>" +
" <if test='commonGbManufacturer != null' > ,common_gb_manufacturer= #{ commonGbManufacturer} </if>" +
@ -165,7 +166,7 @@ public interface CommonGbChannelMapper {
" <if test='commonGbCivilCode != null' > ,common_gb_civilCode= #{ commonGbCivilCode} </if>" +
" <if test='commonGbBlock != null' > ,common_gb_block= #{ commonGbBlock} </if>" +
" <if test='commonGbAddress != null' > ,common_gb_address= #{ commonGbAddress} </if>" +
" <if test='common_gb_parental != null' > ,common_gb_parental= #{ commonGbParental} </if>" +
" <if test='commonGbParental != null' > ,common_gb_parental= #{ commonGbParental} </if>" +
" <if test='commonGbParentID != null' > ,common_gb_parent_id= #{ commonGbParentID} </if>" +
" <if test='commonGbSafetyWay != null' > ,common_gb_safety_way= #{ commonGbSafetyWay} </if>" +
" <if test='commonGbRegisterWay != null' > ,common_gb_register_way= #{ commonGbRegisterWay} </if>" +
@ -238,8 +239,8 @@ public interface CommonGbChannelMapper {
"common_gb_download_speed, " +
"common_gb_svc_time_support_mode, " +
"type, " +
"updateTime, " +
"createTime " +
"update_time, " +
"create_time " +
") values " +
"<foreach collection='commonGbChannelList' index='index' item='item' separator=','> " +
"( " +
@ -473,10 +474,11 @@ public interface CommonGbChannelMapper {
" common_gb_download_speed, " +
" common_gb_svc_time_support_mode, " +
" type, " +
" updateTime, " +
" createTime )"+
" update_time, " +
" create_time )"+
"values " +
"<foreach collection='commonGbChannels' index='index' item='item' open='(' close=')' separator=','> " +
"<foreach collection='commonGbChannels' index='index' item='item' separator=','> " +
"(" +
"#{item.commonGbDeviceID}, " +
"#{item.commonGbName}, " +
"#{item.commonGbManufacturer}, " +
@ -513,7 +515,7 @@ public interface CommonGbChannelMapper {
"#{item.type}," +
"#{item.updateTime}," +
"#{item.createTime}" +
"</foreach> " +
")</foreach> " +
"</script>")
int batchAdd(@Param("commonGbChannels") List<CommonGbChannel> commonGbChannels);
@ -530,7 +532,7 @@ public interface CommonGbChannelMapper {
" <if test='item.commonGbCivilCode != null' > ,common_gb_civilCode = #{item.commonGbCivilCode} </if>" +
" <if test='item.commonGbBlock != null' > ,common_gb_block = #{item.commonGbBlock} </if>" +
" <if test='item.commonGbAddress != null' > ,common_gb_address = #{item.commonGbAddress} </if>" +
" <if test='item.common_gb_parental != null' > ,common_gb_parental = #{item.commonGbParental} </if>" +
" <if test='item.commonGbParental != null' > ,common_gb_parental = #{item.commonGbParental} </if>" +
" <if test='item.commonGbParentID != null' > ,common_gb_parent_id = #{item.commonGbParentID} </if>" +
" <if test='item.commonGbSafetyWay != null' > ,common_gb_safety_way = #{item.commonGbSafetyWay} </if>" +
" <if test='item.commonGbRegisterWay != null' > ,common_gb_register_way = #{item.commonGbRegisterWay} </if>" +
@ -570,4 +572,9 @@ public interface CommonGbChannelMapper {
"<foreach collection='ids' item='item' open='(' separator=',' close=')' >#{item}</foreach>" +
" </script>"})
int batchDelete(@Param("ids") List<Integer> ids);
@MapKey("commonGbDeviceID")
@Select("select * from wvp_common_gb_channel")
Map<String, CommonGbChannel> queryAllChannelsForMap();
}

View File

@ -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<String, Group> queryNotTopGroupForMap();
@Update({"<script>" +
"<foreach collection='groupList' item='item' separator=';'>" +
" UPDATE" +
" wvp_common_group" +
" SET " +
" common_group_top_id=#{item.commonGroupTopId}, " +
" common_group_parent_id=#{item.commonGroupParentId}, " +
" common_group_name=#{item.commonGroupName}" +
" WHERE common_group_device_id=#{item.commonGroupId}"+
"</foreach>" +
"</script>"})
int updateAll(@Param("groupList") List<Group> groupList);
}