增加离线在线监测
parent
a60ce2b85d
commit
d06ff3c16c
|
@ -61,6 +61,8 @@ public class VideoResourcesController extends BaseController {
|
|||
pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID()); //操作人
|
||||
pd.put("ISDELETE", "0"); //是否删除
|
||||
videoResourcesService.save(pd);
|
||||
// 新增摄像头信息后更新最新的设备国标编号和通道国标编号
|
||||
videoResourcesService.updateAllNationalCode();
|
||||
map.put("dockData", JSON.toJSONString(pd));
|
||||
map.put("result", errInfo);
|
||||
}else {
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.zcloud.mapper.dsno2.keyProjects;
|
|||
|
||||
import com.zcloud.entity.Page;
|
||||
import com.zcloud.entity.PageData;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -59,5 +60,32 @@ public interface VideoResourcesMapper {
|
|||
List<PageData> listByOutsourced(Page page);
|
||||
|
||||
List<PageData> getPageOutSourceBySidlistPage(Page pd);
|
||||
|
||||
/**
|
||||
* 更新摄像头状态为在线
|
||||
* @param onlineDeviceList
|
||||
*/
|
||||
void updateOnlineStatus(@Param("onlineList") List<String> onlineDeviceList);
|
||||
|
||||
/**
|
||||
* 更新摄像头状态为离线
|
||||
* @param offlineDeviceList
|
||||
*/
|
||||
void updateOfflineStatus(@Param("offlineList") List<String> offlineDeviceList);
|
||||
|
||||
/**
|
||||
* 批量更新所有摄像头状态为离线
|
||||
*/
|
||||
void updateOfflineStatusAll();
|
||||
|
||||
/**
|
||||
* 更新所有设备的设备国标编号
|
||||
*/
|
||||
void updateNationalCode();
|
||||
|
||||
/**
|
||||
* 更新所有设备的通道国标编号
|
||||
*/
|
||||
void updateTHONationalCode();
|
||||
}
|
||||
|
||||
|
|
|
@ -53,5 +53,9 @@ public interface VideoResourcesService {
|
|||
|
||||
|
||||
List<PageData> getPageOutSourceBySid(Page pd);
|
||||
|
||||
void videoDevicesUpdateOnlineStatus();
|
||||
|
||||
void updateAllNationalCode();
|
||||
}
|
||||
|
||||
|
|
|
@ -5,12 +5,17 @@ import com.zcloud.entity.PageData;
|
|||
import com.zcloud.mapper.dsno2.keyProjects.VideoManagerMapper;
|
||||
import com.zcloud.mapper.dsno2.keyProjects.VideoResourcesMapper;
|
||||
import com.zcloud.service.keyProjects.VideoResourcesService;
|
||||
import com.zcloud.util.HeartBreakUtil;
|
||||
import com.zcloud.util.InitPageDataUtil;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 说明:视频管理
|
||||
|
@ -107,5 +112,54 @@ public class VideoResourcesServiceImpl implements VideoResourcesService {
|
|||
return videoResourcesMapper.getPageOutSourceBySidlistPage(pd);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void videoDevicesUpdateOnlineStatus() {
|
||||
try {
|
||||
// 从摄像头接口中获取所有摄像头列表
|
||||
// 获取摄像头列表
|
||||
List<HashMap> channelList = HeartBreakUtil.getList();
|
||||
if (channelList != null && channelList.size() > 0) {
|
||||
Map<String, Boolean> deviceMap = new HashMap<>();
|
||||
// 将设备列表的设备id和是否在线状态封装到map中
|
||||
for (HashMap device : channelList) {
|
||||
// 判断设备状态是否在线,根据STATUS字段
|
||||
Boolean onlineStatus = false;
|
||||
if (StringUtils.equals(device.get("Status").toString(),"ON")) {
|
||||
onlineStatus = true;
|
||||
}
|
||||
// 将设备国标编号和通道国标编号拼在一起放到key里
|
||||
deviceMap.put(device.get("DeviceID").toString() + "-" + device.get("ID").toString(), onlineStatus);
|
||||
}
|
||||
// 将在线和不在线的设备id分开来
|
||||
List<String> onlineDeviceList = new ArrayList<>(); // 在线设备id
|
||||
// 将数据库中的所有设备查询出来
|
||||
List<PageData> videoResourcesList = videoResourcesMapper.listAll(new PageData());
|
||||
for (PageData videoResources : videoResourcesList) {
|
||||
// 将设备列表的设别国标编号和通道国标编号拼在一起
|
||||
String deviceCombId = videoResources.getString("NATIONAL_STANDARD_ID") + "-" + videoResources.getString("THO_NATIONAL_STANDARD_ID");
|
||||
if (deviceMap.containsKey(deviceCombId) && deviceMap.get(deviceCombId)) {
|
||||
onlineDeviceList.add(videoResources.getString("VIDEO_RESOURCES_ID"));
|
||||
}
|
||||
}
|
||||
// 批量更新摄像头在线状态
|
||||
videoResourcesMapper.updateOnlineStatus(onlineDeviceList);
|
||||
videoResourcesMapper.updateOfflineStatus(onlineDeviceList);
|
||||
} else {
|
||||
// 获取摄像头列表为空
|
||||
System.out.println("获取摄像头列表为空");
|
||||
// 批量更新摄像头状态为离线
|
||||
videoResourcesMapper.updateOfflineStatusAll();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateAllNationalCode() {
|
||||
videoResourcesMapper.updateNationalCode();
|
||||
videoResourcesMapper.updateTHONationalCode();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,161 @@
|
|||
package com.zcloud.util;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.zcloud.entity.PageData;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 说明:常用工具
|
||||
* 作者:luoxiaobao
|
||||
* 官网:www.qdkjchina.com
|
||||
*/
|
||||
public class HeartBreakUtil {
|
||||
private static final String host = "https://arqsp.qhdsafety.com:10010";
|
||||
|
||||
// https://arqsp.qhdsafety.com:10010/api/v1/device/list?q=&start=10&limit=10&online=true&sort=ID&order=asc&_=1710834460090
|
||||
// https://arqsp.qhdsafety.com:10010/api/v1/device/list
|
||||
private static String URLToken = "MvEXr3blIlazed1m8AfR22l7ZjLYXuF7WCAKL_wEwN7.oxNzExNTk0MjcyLCJwIjoiNTgwNjEwMGMyZDU2Y2UwMmIzZWYwYTZkZTg5NWQ5ZTliYjYwYTIxMGE4Yjc0NDE5OWE4YTEwZWM4OTYyMmMyOCIsInQiOjE3MTA5ODk0NzIsInUiOiIwYjUxNDkwMzcwIn0eyJlIj.GciOiJIUzI1NiIsInR5cCI6IkpXVCJ9eyJhb";
|
||||
|
||||
public static void main(String[] args) {
|
||||
// getLogin();
|
||||
// getList();
|
||||
}
|
||||
public static void logout (){
|
||||
|
||||
}
|
||||
public static String getLogin (){
|
||||
String sasd = MD5.md5("Zykj@zcloud88888");
|
||||
PageData pd = new PageData();
|
||||
pd.put("username", "admin");
|
||||
pd.put("password", sasd);
|
||||
pd.put("url_token_only", "true");
|
||||
Map returnMap = getGETTest(host + "/api/v1/login" , pd);
|
||||
// 返回结果为空时将返回的token改为空
|
||||
if (Tools.isEmpty(returnMap)) {
|
||||
return null;
|
||||
}
|
||||
String urlToken = returnMap.get("URLToken").toString();
|
||||
System.out.println(returnMap);
|
||||
return urlToken;
|
||||
}
|
||||
public static List<HashMap> getList (){
|
||||
PageData pd = new PageData();
|
||||
pd.put("token", URLToken);
|
||||
Map returnMap = getGETTest(host + "/api/v1/device/channellist" , pd);
|
||||
if (Tools.isEmpty(returnMap)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
// System.out.println(returnMap);
|
||||
// System.out.println(deviceList);
|
||||
// return (List<HashMap>) returnMap.get("DeviceList");
|
||||
return (List<HashMap>) returnMap.get("ChannelList");
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新登录token并获取新的token
|
||||
* @return
|
||||
*/
|
||||
public static boolean updateToken() {
|
||||
String token = getLogin();
|
||||
// 如果返回token为空,则登录获取失败
|
||||
if (Tools.notEmpty(token)) {
|
||||
URLToken = getLogin();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static Map getGETTest (String httpUrl , PageData pd ){
|
||||
HttpURLConnection connection = null;
|
||||
InputStream is = null;
|
||||
BufferedReader br = null;
|
||||
StringBuffer result = new StringBuffer();
|
||||
// ?username=admin&password=234f3424be5a75ad898a1b55f6e34d9e&url_token_only=true
|
||||
StringBuffer nameValue = new StringBuffer();
|
||||
Map<Object, Object> map = (Map)pd;
|
||||
System.out.print("参数:{");
|
||||
for(Map.Entry<Object, Object> entry : map.entrySet()){
|
||||
System.out.print(entry.getKey().toString() + ":" + entry.getValue().toString() + ",");
|
||||
nameValue.append(entry.getKey().toString()+"=" + entry.getValue().toString() + "&");
|
||||
}
|
||||
System.out.println("}");
|
||||
String parameter = "";
|
||||
if(nameValue.length()>0){
|
||||
parameter = "?"+nameValue.toString().substring(0,nameValue.length()-1);
|
||||
}
|
||||
|
||||
System.out.println( "地址:"+httpUrl + parameter);
|
||||
try {
|
||||
//创建连接
|
||||
URL url = new URL(httpUrl + parameter);
|
||||
connection = (HttpURLConnection) url.openConnection();
|
||||
//设置请求方式
|
||||
connection.setRequestMethod("GET");
|
||||
//设置连接超时时间
|
||||
connection.setReadTimeout(15000);
|
||||
//开始连接
|
||||
connection.connect();
|
||||
//获取响应数据
|
||||
if (connection.getResponseCode() == 200) {
|
||||
//获取返回的数据
|
||||
is = connection.getInputStream();
|
||||
if (null != is) {
|
||||
br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
|
||||
String temp = null;
|
||||
while (null != (temp = br.readLine())) {
|
||||
result.append(temp);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (null != br) {
|
||||
try {
|
||||
br.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (null != is) {
|
||||
try {
|
||||
is.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
//关闭远程连接
|
||||
connection.disconnect();
|
||||
}
|
||||
// return result.toString();
|
||||
|
||||
/**
|
||||
* 转换成json,根据合法性返回json或者字符串
|
||||
*/
|
||||
JSONObject jsonObject = null;
|
||||
try{
|
||||
if (Tools.notEmpty(result.toString())) {
|
||||
jsonObject = JSONObject.parseObject(result.toString());
|
||||
Map<String, Object> maps = new HashMap<String, Object>();
|
||||
maps = HttpClientService.parseJSON2Map(jsonObject);
|
||||
return maps;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
package com.zcloud.util;
|
||||
|
||||
import com.zcloud.service.keyProjects.VideoResourcesService;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* 查询摄像头是否在线定时任务
|
||||
* @author limingyu
|
||||
* @date 2024-03-21
|
||||
*/
|
||||
@Component
|
||||
@Order(value = 2)
|
||||
public class VideoHeartBreakScheduled implements ApplicationRunner {
|
||||
|
||||
@Resource
|
||||
private VideoResourcesService videoResourcesService;
|
||||
|
||||
/**
|
||||
* 定时更新摄像头在线状态
|
||||
*/
|
||||
@Scheduled(cron ="0 0/5 * * * ?") //每5分钟执行一次
|
||||
private void videoEquipmentScheduled(){
|
||||
try {
|
||||
System.out.println("============更新摄像头在线状态============");
|
||||
videoResourcesService.videoDevicesUpdateOnlineStatus();
|
||||
System.out.println("============更新摄像头状态成功============");
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 每五天更新一次LiveGBS登录token(token有效期为7天)
|
||||
*/
|
||||
@Scheduled(cron ="0 0 0/5 * * ?") //测试 每5天执行一次
|
||||
private static void getLoginToken() throws Exception{
|
||||
try {
|
||||
System.out.println("===============更新LiveGBS登录token============");
|
||||
boolean result = HeartBreakUtil.updateToken();
|
||||
if (result) {
|
||||
System.out.println("===============更新LiveGBS登录token成功=========");
|
||||
} else {
|
||||
System.out.println("===============更新LiveGBS登录token失败=========");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 系统启动时执行一次
|
||||
* @throws Exception
|
||||
*/
|
||||
@Override
|
||||
public void run(ApplicationArguments args) {
|
||||
try{
|
||||
getLoginToken();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -175,10 +175,12 @@
|
|||
<select id="datalistPage" parameterType="page" resultType="pd">
|
||||
select
|
||||
<include refid="Field"></include>,
|
||||
pv.INDEXCODE
|
||||
pv.INDEXCODE,
|
||||
r.ONLINE_STATUS
|
||||
from
|
||||
<include refid="tableName"></include> f
|
||||
left join bus_platformvideomanagement pv on pv.PLATFORMVIDEOMANAGEMENT_ID = f.PLATFORMVIDEOMANAGEMENT_ID
|
||||
left join bus_video_resources r on r.VIDEO_RESOURCES_ID = f.VIDEO_RESOURCES_ID
|
||||
where f.ISDELETE = '0'
|
||||
<if test="pd.OUTSOURCED_ID != null and pd.OUTSOURCED_ID != ''"><!-- 关键词检索 -->
|
||||
and f.OUTSOURCED_ID=#{pd.OUTSOURCED_ID}
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
<sql id="Field">
|
||||
f.VIDEO_RESOURCES_ID,
|
||||
f.UNITS_ID,
|
||||
f.CORPINFO_ID,
|
||||
f.MODEL,
|
||||
f.UNIT_USE,
|
||||
f.PERSON,
|
||||
|
@ -22,8 +23,10 @@
|
|||
f.VIDEONAME,
|
||||
f.VIDEOURL,
|
||||
f.REMAKE,
|
||||
f.CORPINFO_ID,
|
||||
f.CODE
|
||||
f.CODE,
|
||||
f.ONLINE_STATUS,
|
||||
f.NATIONAL_STANDARD_ID,
|
||||
f.THO_NATIONAL_STANDARD_ID
|
||||
</sql>
|
||||
|
||||
<!-- 字段用于新增 -->
|
||||
|
@ -32,6 +35,7 @@
|
|||
VIDEONAME,
|
||||
VIDEOURL,
|
||||
UNITS_ID,
|
||||
CORPINFO_ID,
|
||||
MODEL,
|
||||
UNIT_USE,
|
||||
PERSON,
|
||||
|
@ -42,26 +46,33 @@
|
|||
CREATTIME,
|
||||
OPERATOR,
|
||||
OPERATTIME,
|
||||
ISDELETE
|
||||
ISDELETE,
|
||||
ONLINE_STATUS,
|
||||
NATIONAL_STANDARD_ID,
|
||||
THO_NATIONAL_STANDARD_ID
|
||||
</sql>
|
||||
|
||||
<!-- 字段值 -->
|
||||
<sql id="FieldValue">
|
||||
#{VIDEO_RESOURCES_ID},
|
||||
#{VIDEONAME},
|
||||
#{VIDEOURL},
|
||||
#{VIDEONAME},
|
||||
#{VIDEOURL},
|
||||
#{UNITS_ID},
|
||||
#{CORPINFO_ID},
|
||||
#{MODEL},
|
||||
#{UNIT_USE},
|
||||
#{PERSON},
|
||||
#{PHONE},
|
||||
#{CODE},
|
||||
#{REMAKE},
|
||||
#{CREATOR},
|
||||
#{CREATTIME},
|
||||
#{OPERATOR},
|
||||
#{OPERATTIME},
|
||||
#{ISDELETE}
|
||||
#{CODE},
|
||||
#{REMAKE},
|
||||
#{CREATOR},
|
||||
#{CREATTIME},
|
||||
#{OPERATOR},
|
||||
#{OPERATTIME},
|
||||
#{ISDELETE},
|
||||
#{ONLINE_STATUS},
|
||||
#{NATIONAL_STANDARD_ID},
|
||||
#{THO_NATIONAL_STANDARD_ID}
|
||||
</sql>
|
||||
|
||||
<!-- 新增-->
|
||||
|
@ -223,4 +234,80 @@
|
|||
#{item}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
<update id="updateOnlineStatus">
|
||||
update
|
||||
<include refid="tableName"></include>
|
||||
set
|
||||
ONLINE_STATUS = 0
|
||||
where
|
||||
VIDEO_RESOURCES_ID IN
|
||||
<foreach collection="onlineList" index="index" open="(" close=")" separator="," item="item">
|
||||
#{item}
|
||||
</foreach>
|
||||
</update>
|
||||
|
||||
<update id="updateOfflineStatus">
|
||||
update
|
||||
<include refid="tableName"></include>
|
||||
set
|
||||
ONLINE_STATUS = 1
|
||||
where
|
||||
VIDEO_RESOURCES_ID NOT IN
|
||||
<foreach collection="offlineList" index="index" open="(" close=")" separator="," item="item">
|
||||
#{item}
|
||||
</foreach>
|
||||
OR NATIONAL_STANDARD_ID IS NULL
|
||||
</update>
|
||||
|
||||
<update id="updateOfflineStatusAll">
|
||||
update
|
||||
<include refid="tableName"></include>
|
||||
set
|
||||
ONLINE_STATUS = 1
|
||||
where
|
||||
ONLINE_STATUS IS NOT NULL
|
||||
</update>
|
||||
|
||||
<update id="updateNationalCode">
|
||||
UPDATE
|
||||
<include refid="tableName"></include> bvr1
|
||||
SET
|
||||
bvr1.NATIONAL_STANDARD_ID =
|
||||
(
|
||||
SELECT
|
||||
temp.NATIONAL_STANDARD_ID
|
||||
FROM
|
||||
(
|
||||
SELECT
|
||||
bvr2.VIDEO_RESOURCES_ID,
|
||||
SUBSTRING_INDEX( SUBSTRING_INDEX( SUBSTRING_INDEX( IF( LOCATE( 'arqsp.qhdsafety.com:10010/play.html', bvr2.VIDEOURL ) > 0, bvr2.VIDEOURL, NULL ), '?', -1 ), '&', 1 ), '=', -1 ) AS NATIONAL_STANDARD_ID
|
||||
FROM
|
||||
bus_video_resources bvr2
|
||||
) temp
|
||||
WHERE
|
||||
temp.VIDEO_RESOURCES_ID = bvr1.VIDEO_RESOURCES_ID
|
||||
)
|
||||
</update>
|
||||
|
||||
<update id="updateTHONationalCode">
|
||||
UPDATE <include refid="tableName"></include> bvr1
|
||||
SET bvr1.THO_NATIONAL_STANDARD_ID = (
|
||||
SELECT
|
||||
temp.NATIONAL_STANDARD_ID
|
||||
FROM
|
||||
(
|
||||
SELECT
|
||||
bvr2.VIDEO_RESOURCES_ID,
|
||||
SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX( IF ( LOCATE( 'arqsp.qhdsafety.com:10010/play.html', bvr2.VIDEOURL ) > 0, bvr2.VIDEOURL, NULL ), '?', - 1 ),'&',2 ),'&',-1),'=',-1)
|
||||
|
||||
AS NATIONAL_STANDARD_ID
|
||||
FROM
|
||||
bus_video_resources bvr2
|
||||
) temp
|
||||
WHERE
|
||||
temp.VIDEO_RESOURCES_ID = bvr1.VIDEO_RESOURCES_ID
|
||||
)
|
||||
</update>
|
||||
|
||||
</mapper>
|
||||
|
|
Loading…
Reference in New Issue