|
@ -3,8 +3,10 @@ package com.zc.business.controller; |
|
|
import com.alibaba.fastjson.JSON; |
|
|
import com.alibaba.fastjson.JSON; |
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
import com.ruoyi.common.core.controller.BaseController; |
|
|
import com.ruoyi.common.core.controller.BaseController; |
|
|
import com.ruoyi.common.core.domain.AjaxResult; |
|
|
import com.ruoyi.common.core.domain.AjaxResult; |
|
|
|
|
|
import com.ruoyi.common.core.redis.RedisCache; |
|
|
import com.zc.business.domain.DcDevice; |
|
|
import com.zc.business.domain.DcDevice; |
|
|
import com.zc.business.service.IDcDeviceService; |
|
|
import com.zc.business.service.IDcDeviceService; |
|
|
import com.zc.common.core.httpclient.OkHttp; |
|
|
import com.zc.common.core.httpclient.OkHttp; |
|
@ -22,6 +24,7 @@ import org.springframework.web.bind.annotation.RestController; |
|
|
import javax.annotation.Resource; |
|
|
import javax.annotation.Resource; |
|
|
import java.io.IOException; |
|
|
import java.io.IOException; |
|
|
import java.util.*; |
|
|
import java.util.*; |
|
|
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
|
|
|
|
|
import static com.ruoyi.common.constant.Constants.HTTP; |
|
|
import static com.ruoyi.common.constant.Constants.HTTP; |
|
|
|
|
|
|
|
@ -36,6 +39,10 @@ import static com.ruoyi.common.constant.Constants.HTTP; |
|
|
@RequestMapping("/video") |
|
|
@RequestMapping("/video") |
|
|
public class VideoController extends BaseController { |
|
|
public class VideoController extends BaseController { |
|
|
|
|
|
|
|
|
|
|
|
private static final String ID = "admin"; |
|
|
|
|
|
private static final String SECRET = "21232f297a57a5a743894a0e4a801fc3"; |
|
|
|
|
|
private static final String CALLBACKURL = "http://10.0.81.209/broadcast/logIn"; |
|
|
|
|
|
private final static String TOKENKEY = "tokenRoadTestBroadcastPlatform"; |
|
|
private static final String USERNAME = "jhgskj"; |
|
|
private static final String USERNAME = "jhgskj"; |
|
|
private static final String PASSWORD = "jhgskj@2023"; |
|
|
private static final String PASSWORD = "jhgskj@2023"; |
|
|
private static String TOKEN; |
|
|
private static String TOKEN; |
|
@ -47,6 +54,8 @@ public class VideoController extends BaseController { |
|
|
|
|
|
|
|
|
public static final Integer ERROR = 500; |
|
|
public static final Integer ERROR = 500; |
|
|
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
|
private RedisCache redisCache; |
|
|
@Resource |
|
|
@Resource |
|
|
private IDcDeviceService iDcDeviceService; |
|
|
private IDcDeviceService iDcDeviceService; |
|
|
|
|
|
|
|
@ -55,8 +64,8 @@ public class VideoController extends BaseController { |
|
|
*/ |
|
|
*/ |
|
|
@ApiOperation("查询附近相机") |
|
|
@ApiOperation("查询附近相机") |
|
|
@GetMapping(value = "/nearCamListDistance") |
|
|
@GetMapping(value = "/nearCamListDistance") |
|
|
public JSONObject nearCamListDistance(@ApiParam(value = "纬度", name = "devLat",required = true)String devLat, |
|
|
public JSONObject nearCamListDistance(@ApiParam(value = "纬度", name = "devLat", required = true) String devLat, |
|
|
@ApiParam(value = "经度", name = "devLon",required = true)String devLon) throws HttpException, IOException { |
|
|
@ApiParam(value = "经度", name = "devLon", required = true) String devLon) throws HttpException, IOException { |
|
|
|
|
|
|
|
|
JSONObject jsonResult = null; |
|
|
JSONObject jsonResult = null; |
|
|
|
|
|
|
|
@ -106,21 +115,21 @@ public class VideoController extends BaseController { |
|
|
*/ |
|
|
*/ |
|
|
@Scheduled(cron = "0 0/5 * * * ?") |
|
|
@Scheduled(cron = "0 0/5 * * * ?") |
|
|
public void updateDeviceState() throws HttpException, IOException { |
|
|
public void updateDeviceState() throws HttpException, IOException { |
|
|
logger.debug("开始执行:同步数据平台设备的设备状态!!"); |
|
|
logger.debug("开始执行:同步数据平台视频设备设备的设备状态!!"); |
|
|
JSONObject cameraData = synchronizeCameraData(); |
|
|
JSONObject cameraData = synchronizeCameraData(); |
|
|
if (cameraData.get("code").equals(200)) { |
|
|
if (cameraData.get("code").equals(200)) { |
|
|
JSONObject data =JSONObject.parseObject(JSONArray.parseArray(cameraData.get("data").toString()).get(0).toString()); |
|
|
JSONObject data = JSONObject.parseObject(JSONArray.parseArray(cameraData.get("data").toString()).get(0).toString()); |
|
|
JSONObject dataChildren =JSONObject.parseObject(JSONArray.parseArray(data.get("children").toString()).get(0).toString()); |
|
|
JSONObject dataChildren = JSONObject.parseObject(JSONArray.parseArray(data.get("children").toString()).get(0).toString()); |
|
|
JSONObject qiLuGaoSu =JSONObject.parseObject(JSONArray.parseArray(dataChildren.get("children").toString()).get(0).toString()); |
|
|
JSONObject qiLuGaoSu = JSONObject.parseObject(JSONArray.parseArray(dataChildren.get("children").toString()).get(0).toString()); |
|
|
JSONObject jiHeYunGuan =JSONObject.parseObject(JSONArray.parseArray(qiLuGaoSu.get("children").toString()).get(0).toString()); |
|
|
JSONObject jiHeYunGuan = JSONObject.parseObject(JSONArray.parseArray(qiLuGaoSu.get("children").toString()).get(0).toString()); |
|
|
JSONArray jiHeYunGuanG35 = JSONArray.parseArray(jiHeYunGuan.get("children").toString()); |
|
|
JSONArray jiHeYunGuanG35 = JSONArray.parseArray(jiHeYunGuan.get("children").toString()); |
|
|
List<DcDevice> list = new ArrayList<>(); |
|
|
List<DcDevice> list = new ArrayList<>(); |
|
|
for (Object json: jiHeYunGuanG35) { |
|
|
for (Object json : jiHeYunGuanG35) { |
|
|
JSONObject item = JSONObject.parseObject(json.toString()); |
|
|
JSONObject item = JSONObject.parseObject(json.toString()); |
|
|
DcDevice device = new DcDevice(); |
|
|
DcDevice device = new DcDevice(); |
|
|
if (item.get("status").equals("0")) { |
|
|
if (item.get("status").equals("0")) { |
|
|
device.setDeviceState("1"); |
|
|
device.setDeviceState("1"); |
|
|
}else { |
|
|
} else { |
|
|
device.setDeviceState("0"); |
|
|
device.setDeviceState("0"); |
|
|
} |
|
|
} |
|
|
device.setIotDeviceId(item.get("camId").toString()); |
|
|
device.setIotDeviceId(item.get("camId").toString()); |
|
@ -131,6 +140,7 @@ public class VideoController extends BaseController { |
|
|
logger.debug("执行:同步数据平台视频设备的设备状态成功!!"); |
|
|
logger.debug("执行:同步数据平台视频设备的设备状态成功!!"); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
logger.debug("开始执行:同步物联平台设备的设备状态!!"); |
|
|
AjaxResult ajaxResult = synchronizingDeviceStatus(); |
|
|
AjaxResult ajaxResult = synchronizingDeviceStatus(); |
|
|
if (ajaxResult.get("code").equals(200)) { |
|
|
if (ajaxResult.get("code").equals(200)) { |
|
|
JSONArray data = (JSONArray) ajaxResult.get("data"); |
|
|
JSONArray data = (JSONArray) ajaxResult.get("data"); |
|
@ -139,28 +149,80 @@ public class VideoController extends BaseController { |
|
|
DcDevice dcDevice = new DcDevice(); |
|
|
DcDevice dcDevice = new DcDevice(); |
|
|
JSONObject datum1 = (JSONObject) datum; |
|
|
JSONObject datum1 = (JSONObject) datum; |
|
|
dcDevice.setIotDeviceId(datum1.getString("id")); |
|
|
dcDevice.setIotDeviceId(datum1.getString("id")); |
|
|
dcDevice.setDeviceState(Objects.equals(datum1.getString("deviceState"), "online") ?"1":"0"); |
|
|
dcDevice.setDeviceState(Objects.equals(datum1.getString("deviceState"), "online") ? "1" : "0"); |
|
|
dcDevices.add(dcDevice); |
|
|
dcDevices.add(dcDevice); |
|
|
} |
|
|
} |
|
|
iDcDeviceService.batchUpdate(dcDevices); |
|
|
iDcDeviceService.batchUpdate(dcDevices); |
|
|
logger.debug("执行:同步数据平台设备的设备状态成功!!"); |
|
|
logger.debug("执行:同步物联平台设备的设备状态成功!!"); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
logger.debug("开始执行:同步广播设备的设备状态!!"); |
|
|
|
|
|
AjaxResult ajaxResultBroadcast = synchronizingBroadcastDeviceStatus(); |
|
|
|
|
|
if (Objects.equals(String.valueOf(ajaxResultBroadcast.get("retCode")), "0")) { |
|
|
|
|
|
JSONArray data = (JSONArray) ajaxResultBroadcast.get("termList"); |
|
|
|
|
|
for (Object datum : data) { |
|
|
|
|
|
DcDevice dcDevice = new DcDevice(); |
|
|
|
|
|
JSONObject datum1 = (JSONObject) datum; |
|
|
|
|
|
dcDevice.setIotDeviceId(datum1.getString("termDN")); |
|
|
|
|
|
dcDevice.setDeviceState(Objects.equals(datum1.getString("regState"), "online") ? "1" : "0"); |
|
|
|
|
|
LambdaQueryWrapper<DcDevice> queryWrapper = new LambdaQueryWrapper<>(); |
|
|
|
|
|
queryWrapper.eq(DcDevice::getIotDeviceId, dcDevice.getIotDeviceId()); |
|
|
|
|
|
iDcDeviceService.update(dcDevice, queryWrapper); |
|
|
|
|
|
} |
|
|
|
|
|
logger.debug("执行:同步广播设备的设备状态成功!!"); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private AjaxResult synchronizingBroadcastDeviceStatus() throws HttpException, IOException { |
|
|
|
|
|
OkHttp okHttp = new OkHttp(); |
|
|
|
|
|
RequestParams requestParams = new RequestParams(); |
|
|
|
|
|
String tokenRoadTestBroadcastPlatform = redisCache.getCacheObject(TOKENKEY); |
|
|
|
|
|
if (tokenRoadTestBroadcastPlatform == null) { |
|
|
|
|
|
tokenRoadTestBroadcastPlatform = getBroadcastToken(); |
|
|
|
|
|
} |
|
|
|
|
|
requestParams.put("zoneId", "*6001"); |
|
|
|
|
|
requestParams.put("termDN", ""); |
|
|
|
|
|
Response response // 请求响应
|
|
|
|
|
|
= okHttp |
|
|
|
|
|
.headers(new HashMap<>()) |
|
|
|
|
|
.data(requestParams) // 请求参数
|
|
|
|
|
|
.url("http://10.0.81.106/api/REST-API/queryTerm.do?accessToken=" + tokenRoadTestBroadcastPlatform) // 请求地址
|
|
|
|
|
|
.post(); // 请求方法
|
|
|
|
|
|
return JSON.parseObject(response.body().string(), AjaxResult.class); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public String getBroadcastToken() throws HttpException, IOException { |
|
|
|
|
|
OkHttp okHttp = new OkHttp(); |
|
|
|
|
|
RequestParams requestParams = new RequestParams(); |
|
|
|
|
|
requestParams.put("id", ID); |
|
|
|
|
|
requestParams.put("secret", SECRET); |
|
|
|
|
|
requestParams.put("callbackUrl", CALLBACKURL); |
|
|
|
|
|
Response response // 请求响应
|
|
|
|
|
|
= okHttp |
|
|
|
|
|
.headers(new HashMap<>()) |
|
|
|
|
|
.url("http://10.0.81.106/api/REST-API/login.do") // 请求地址
|
|
|
|
|
|
.data(requestParams) // 请求参数
|
|
|
|
|
|
.post(); // 请求方法
|
|
|
|
|
|
if (response.body() != null) { |
|
|
|
|
|
String accessToken = JSONObject.parseObject(response.body().string()).getString("accessToken"); |
|
|
|
|
|
redisCache.setCacheObject(TOKENKEY, accessToken, 100, TimeUnit.MINUTES); |
|
|
|
|
|
return accessToken; |
|
|
|
|
|
} |
|
|
|
|
|
return null; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private AjaxResult synchronizingDeviceStatus() throws HttpException, IOException { |
|
|
private AjaxResult synchronizingDeviceStatus() throws HttpException, IOException { |
|
|
|
|
|
|
|
|
OkHttp okHttp = new OkHttp(); |
|
|
OkHttp okHttp = new OkHttp(); |
|
|
|
|
|
|
|
|
Response response // 请求响应
|
|
|
Response response // 请求响应
|
|
|
= okHttp |
|
|
= okHttp |
|
|
.url(HTTP+"10.0.81.202:8081" + "/api/iot/device/query") // 请求地址
|
|
|
.url(HTTP + "10.0.81.202:8081" + "/api/iot/device/query") // 请求地址
|
|
|
.get(); // 请求方法
|
|
|
.get(); // 请求方法
|
|
|
AjaxResult ajaxResult = JSON.parseObject(response.body().string(), AjaxResult.class); |
|
|
return JSON.parseObject(response.body().string(), AjaxResult.class); |
|
|
return ajaxResult; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|