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 d3cdf7f7..4f522e5d 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 @@ -4,6 +4,8 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; +import com.zc.business.domain.DcDevice; +import com.zc.business.service.IDcDeviceService; import com.zc.common.core.httpclient.OkHttp; import com.zc.common.core.httpclient.exception.HttpException; import com.zc.common.core.httpclient.request.RequestParams; @@ -11,10 +13,12 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import okhttp3.Response; +import org.springframework.scheduling.annotation.Scheduled; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import javax.annotation.Resource; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; @@ -45,6 +49,9 @@ public class VideoController extends BaseController { public static final Integer ERROR = 500; + @Resource + private IDcDeviceService iDcDeviceService; + /** * 查询附近相机 */ @@ -96,6 +103,84 @@ public class VideoController extends BaseController { } + /*** + * 根据相机中的设备状态,修改数据平台设备的设备状态 + */ + @Scheduled(cron = "0 0/5 * * * ?") + public void updateDeviceState() throws HttpException, IOException { + logger.debug("开始执行:同步数据平台设备的设备状态!!"); + JSONObject cameraData = synchronizeCameraData(); + if (cameraData.get("code").equals(200)) { + 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 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()); + JSONArray jiHeYunGuanG35 = JSONArray.parseArray(jiHeYunGuan.get("children").toString()); + List list = new ArrayList<>(); + for (Object json: jiHeYunGuanG35) { + JSONObject item = JSONObject.parseObject(json.toString()); + DcDevice device = new DcDevice(); + if (item.get("status").equals("0")) { + device.setDeviceState("1"); + }else { + device.setDeviceState("0"); + } + device.setIotDeviceId(item.get("camId").toString()); + list.add(device); + } + + iDcDeviceService.batchUpdate(list); + logger.debug("执行:同步数据平台设备的设备状态成功!!"); + + } + + + + } + + /** + * 查询同步相机数据 + */ + public JSONObject synchronizeCameraData() throws HttpException, IOException { + + JSONObject jsonResult = null; + + + OkHttp okHttp = new OkHttp(); + + RequestParams requestParams = new RequestParams(); + + Map header = new HashMap<>(); + + if (VideoController.TOKEN == null) { + getToken(); + } + + header.put("Authorization", TOKEN); + + Response response // 请求响应 + = okHttp + .headers(header) + .url(URL + "/system/dept/camTreeselect") // 请求地址 + .data(requestParams) // 请求参数 + .get(); // 请求方法 + + if (response.body() != null) { + jsonResult = JSONObject.parseObject(response.body().string()); + + if (jsonResult.containsKey("code") && UNAUTHORIZED.equals(jsonResult.getInteger("code"))) { + getToken(); + okHttp.get(); + if (response.body() != null) { + jsonResult = JSONObject.parseObject(response.body().string()); + } + } + } + + return jsonResult; + + } + /** * 根据桩号查询附近相机 */ diff --git a/zc-business/src/main/java/com/zc/business/domain/DcDevice.java b/zc-business/src/main/java/com/zc/business/domain/DcDevice.java index c4db3bf9..818030af 100644 --- a/zc-business/src/main/java/com/zc/business/domain/DcDevice.java +++ b/zc-business/src/main/java/com/zc/business/domain/DcDevice.java @@ -38,6 +38,8 @@ public class DcDevice { private String durableYears; @ApiModelProperty("安装位置") private String installationSite; + @ApiModelProperty("设备状态") + private String deviceState; @ApiModelProperty("使用状态") private Integer useState; @ApiModelProperty("其他配置") diff --git a/zc-business/src/main/java/com/zc/business/service/IDcDeviceService.java b/zc-business/src/main/java/com/zc/business/service/IDcDeviceService.java index 7d355556..7d715f11 100644 --- a/zc-business/src/main/java/com/zc/business/service/IDcDeviceService.java +++ b/zc-business/src/main/java/com/zc/business/service/IDcDeviceService.java @@ -55,6 +55,14 @@ public interface IDcDeviceService extends IService { */ List listDevice(DcDevice dcDevice); + /** + * 批量修改设备 + * + * @param listDevice 参数 + * @return 结果 + */ + boolean batchUpdate(List listDevice); + /** * 根据id查询设备信息 diff --git a/zc-business/src/main/java/com/zc/business/service/impl/DcDeviceServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/DcDeviceServiceImpl.java index 256bfdd4..f3e1aba6 100644 --- a/zc-business/src/main/java/com/zc/business/service/impl/DcDeviceServiceImpl.java +++ b/zc-business/src/main/java/com/zc/business/service/impl/DcDeviceServiceImpl.java @@ -259,6 +259,22 @@ public class DcDeviceServiceImpl extends ServiceImpl i return entityDcDevices; } + /** + * 批量修改设备 + * + * @param listDevice 参数 + * @return 结果 + */ + @Override + public boolean batchUpdate(List listDevice) { + for (DcDevice device : listDevice) { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(DcDevice::getIotDeviceId,device.getIotDeviceId()); + update(device,queryWrapper); + } + return true; + } + /** * 根据id查询设备信息 *