| 
						
						
							
								
							
						
						
					 | 
					@ -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; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
					@ -106,7 +115,7 @@ 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()); | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					@ -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"); | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					@ -143,13 +153,66 @@ public class VideoController extends BaseController { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                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 { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					@ -159,8 +222,7 @@ public class VideoController extends BaseController { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                = 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; | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					    } | 
					 | 
					 | 
					    } | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
					
  |