临时提交

pull/1642/head
panlinlin 2024-07-07 07:28:54 +08:00
parent 52aa4e6e85
commit 052bbf16c3
3 changed files with 74 additions and 6 deletions

View File

@ -4,6 +4,8 @@ import com.genersoft.iot.vmp.gb28181.bean.CommonGBChannel;
import org.apache.ibatis.annotations.*; import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.List;
@Mapper @Mapper
@Repository @Repository
public interface CommonGBChannelMapper { public interface CommonGBChannelMapper {
@ -294,4 +296,8 @@ public interface CommonGBChannelMapper {
int update(CommonGBChannel commonGBChannel); int update(CommonGBChannel commonGBChannel);
int updateStatus(@Param("gbId") int gbId, @Param("status") int status); int updateStatus(@Param("gbId") int gbId, @Param("status") int status);
int updateStatusForList(List<CommonGBChannel> commonGBChannels, @Param("status") int status);
List<CommonGBChannel> queryInListByStatus(List<CommonGBChannel> commonGBChannelList, @Param("status") int status);
} }

View File

@ -24,6 +24,8 @@ public interface IGbChannelService {
void closeSend(CommonGBChannel commonGBChannel); void closeSend(CommonGBChannel commonGBChannel);
void closeSend(List<CommonGBChannel> commonGBChannelList);
void batchAdd(List<CommonGBChannel> commonGBChannels); void batchAdd(List<CommonGBChannel> commonGBChannels);
void updateStatus(List<CommonGBChannel> channelList); void updateStatus(List<CommonGBChannel> channelList);

View File

@ -44,6 +44,8 @@ public class GbChannelServiceImpl implements IGbChannelService {
}catch (Exception e) { }catch (Exception e) {
log.warn("[通道移除通知] 发送失败,{}", channel.getGbDeviceId(), e); log.warn("[通道移除通知] 发送失败,{}", channel.getGbDeviceId(), e);
} }
// 结束发送
closeSend(channel);
} }
return 1; return 1;
} }
@ -91,10 +93,34 @@ public class GbChannelServiceImpl implements IGbChannelService {
log.warn("[多个通道离线] 通道数量为0更新失败"); log.warn("[多个通道离线] 通道数量为0更新失败");
return 0; return 0;
} }
int result = 0; List<CommonGBChannel> onlineChannelList = commonGBChannelMapper.queryInListByStatus(commonGBChannelList, 1);
for (CommonGBChannel channel : commonGBChannelList) { if (onlineChannelList.isEmpty()) {
result += offline(channel); log.warn("[多个通道离线] 更新失败, 参数内通道已经离线");
return 0;
} }
int limitCount = 1000;
int result = 0;
if (onlineChannelList.size() > limitCount) {
for (int i = 0; i < onlineChannelList.size(); i += limitCount) {
int toIndex = i + limitCount;
if (i + limitCount > onlineChannelList.size()) {
toIndex = onlineChannelList.size();
}
result += commonGBChannelMapper.updateStatusForList(onlineChannelList.subList(i, toIndex), 0);
}
}else {
result += commonGBChannelMapper.updateStatusForList(onlineChannelList, 0);
}
if (result > 0) {
try {
// 发送catalog
eventPublisher.catalogEventPublish(null, onlineChannelList, CatalogEvent.OFF);
}catch (Exception e) {
log.warn("[多个通道离线] 发送失败,数量:{}", onlineChannelList.size(), e);
}
}
// 结束国标级联的发送
closeSend(onlineChannelList);
return result; return result;
} }
@ -123,10 +149,34 @@ public class GbChannelServiceImpl implements IGbChannelService {
log.warn("[多个通道上线] 通道数量为0更新失败"); log.warn("[多个通道上线] 通道数量为0更新失败");
return 0; return 0;
} }
int result = 0; List<CommonGBChannel> offlineChannelList = commonGBChannelMapper.queryInListByStatus(commonGBChannelList, 0);
for (CommonGBChannel channel : commonGBChannelList) { if (offlineChannelList.isEmpty()) {
result += online(channel); log.warn("[多个通道上线] 更新失败, 参数内通道已经上线线");
return 0;
} }
// 批量更新
int limitCount = 1000;
int result = 0;
if (offlineChannelList.size() > limitCount) {
for (int i = 0; i < offlineChannelList.size(); i += limitCount) {
int toIndex = i + limitCount;
if (i + limitCount > offlineChannelList.size()) {
toIndex = offlineChannelList.size();
}
result += commonGBChannelMapper.updateStatusForList(offlineChannelList.subList(i, toIndex), 1);
}
}else {
result += commonGBChannelMapper.updateStatusForList(offlineChannelList, 1);
}
if (result > 0) {
try {
// 发送catalog
eventPublisher.catalogEventPublish(null, offlineChannelList, CatalogEvent.ON);
}catch (Exception e) {
log.warn("[多个通道上线] 发送失败,数量:{}", offlineChannelList.size(), e);
}
}
return result; return result;
} }
@ -135,6 +185,16 @@ public class GbChannelServiceImpl implements IGbChannelService {
} }
@Override
@Transactional
public void closeSend(List<CommonGBChannel> commonGBChannelList) {
if (!commonGBChannelList.isEmpty()) {
for (CommonGBChannel commonGBChannel : commonGBChannelList) {
closeSend(commonGBChannel);
}
}
}
@Override @Override
public void batchAdd(List<CommonGBChannel> commonGBChannels) { public void batchAdd(List<CommonGBChannel> commonGBChannels) {