diff --git a/zc-business/src/main/java/com/zc/business/controller/VideoController.java b/zc-business/src/main/java/com/zc/business/controller/VideoController.java index 4f522e5d..f0b08a96 100644 --- a/zc-business/src/main/java/com/zc/business/controller/VideoController.java +++ b/zc-business/src/main/java/com/zc/business/controller/VideoController.java @@ -1,5 +1,6 @@ package com.zc.business.controller; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.ruoyi.common.core.controller.BaseController; @@ -20,10 +21,7 @@ import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import static com.ruoyi.common.constant.Constants.HTTP; @@ -130,6 +128,21 @@ public class VideoController extends BaseController { } iDcDeviceService.batchUpdate(list); + logger.debug("执行:同步数据平台视频设备的设备状态成功!!"); + + } + AjaxResult ajaxResult = synchronizingDeviceStatus(); + if (ajaxResult.get("code").equals(200)) { + JSONArray data = (JSONArray) ajaxResult.get("data"); + ArrayList dcDevices = new ArrayList<>(); + for (Object datum : data) { + DcDevice dcDevice = new DcDevice(); + JSONObject datum1 = (JSONObject) datum; + dcDevice.setIotDeviceId(datum1.getString("id")); + dcDevice.setDeviceState(Objects.equals(datum1.getString("deviceState"), "online") ?"1":"0"); + dcDevices.add(dcDevice); + } + iDcDeviceService.batchUpdate(dcDevices); logger.debug("执行:同步数据平台设备的设备状态成功!!"); } @@ -138,6 +151,19 @@ public class VideoController extends BaseController { } + private AjaxResult synchronizingDeviceStatus() throws HttpException, IOException { + + OkHttp okHttp = new OkHttp(); + + Response response // 请求响应 + = okHttp + .url(HTTP+"10.0.81.202:8081" + "/api/iot/device/query") // 请求地址 + .get(); // 请求方法 + AjaxResult ajaxResult = JSON.parseObject(response.body().string(), AjaxResult.class); + return ajaxResult; + } + + /** * 查询同步相机数据 */ diff --git a/zc-business/src/main/resources/mapper/business/DcDeviceMapper.xml b/zc-business/src/main/resources/mapper/business/DcDeviceMapper.xml index f855bdc0..3e71d46c 100644 --- a/zc-business/src/main/resources/mapper/business/DcDeviceMapper.xml +++ b/zc-business/src/main/resources/mapper/business/DcDeviceMapper.xml @@ -20,6 +20,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + @@ -49,6 +50,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" durable_years, installation_site, use_state, + device_state, other_config, remark, create_time, @@ -59,7 +61,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"