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 d4e6d2f6..48afce12 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 @@ -28,12 +28,17 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PatchMapping; +import org.springframework.web.bind.annotation.PostMapping; 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.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; import java.util.concurrent.TimeUnit; @@ -118,11 +123,43 @@ public class VideoController extends BaseController { return AjaxResult.error(UniversalEnum.FAILED_TO_OBTAIN_CAMERA_INFORMATION_BASED_ON_THE_ORGANIZATION.getValue()); // 如果获取信息失败或不含有效数据,直接返回 } - JSONArray camDataArray = camApiResponse.getJSONArray("data"); + JSONArray camDataArray = camApiResponse.getJSONArray("data");//总的道路+收费站 + JSONArray camType1Array = new JSONArray();//道路 + JSONArray camTypeNot1Array = new JSONArray();//收费站 + for (int i = 0; i < camDataArray.size(); i++) { + JSONObject camObject = camDataArray.getJSONObject(i); + int camType = camObject.getInteger("camType"); + if (camType == 4||camType == 5) { + camTypeNot1Array.add(camObject); //收费站+收费广场 + } else { + camType1Array.add(camObject); //道路摄像头 + } + } + //循环处理收费站的摄像头 + List dcDevices = iDcDeviceService.selectDeviceTollStationCamera();//收费站全部摄像头 + camTypeNot1Array.forEach(item->{ + JSONObject cameraInfo = (JSONObject) item; + String camId = cameraInfo.getString("camId");//摄像头物联id + String status = cameraInfo.getString("status");// + DcDevice dcDevice = new DcDevice(); + for (DcDevice device:dcDevices){ + if (device.getIotDeviceId().equals(camId)){ + dcDevice.setId(device.getId()); + if ("0".equals(status)){ + dcDevice.setDeviceState("1"); + }else { + dcDevice.setDeviceState("0"); + } + iDcDeviceService.updateTollStationCameraStatus(dcDevice);//同步状态 + }else { + continue; + } + } + }); // 遍历并更新具备匹配IP的摄像头设备物联ID List devicesToUpdate = new ArrayList<>(); - camDataArray.forEach(item -> { + camType1Array.forEach(item -> { JSONObject cameraInfo = (JSONObject) item; // 桩号 String pileNum = cameraInfo.getString("pileNum"); @@ -195,15 +232,36 @@ public class VideoController extends BaseController { * 根据相机中的设备状态,修改数据平台设备的设备状态 */ @Scheduled(cron = "0 0/5 * * * ?") + @PostMapping("/updateDeviceState") public void updateDeviceState() throws HttpException, IOException { logger.debug("开始执行:同步数据平台视频设备设备的设备状态!!"); JSONObject cameraData = synchronizeCameraData(); if (cameraData.get("code").equals(UniversalEnum.TWO_HUNDRED.getNumber())) { - JSONObject data = JSONObject.parseObject(JSONArray.parseArray(cameraData.get("data").toString()).get(UniversalEnum.ZERO.getNumber()).toString()); - JSONObject dataChildren = JSONObject.parseObject(JSONArray.parseArray(data.get("children").toString()).get(UniversalEnum.ZERO.getNumber()).toString()); - JSONObject qiLuGaoSu = JSONObject.parseObject(JSONArray.parseArray(dataChildren.get("children").toString()).get(UniversalEnum.ZERO.getNumber()).toString()); - JSONObject jiHeYunGuan = JSONObject.parseObject(JSONArray.parseArray(qiLuGaoSu.get("children").toString()).get(UniversalEnum.ZERO.getNumber()).toString()); - JSONArray jiHeYunGuanG35 = JSONArray.parseArray(jiHeYunGuan.get("children").toString()); +// JSONObject data = JSONObject.parseObject(JSONArray.parseArray(cameraData.get("data").toString()).get(UniversalEnum.ZERO.getNumber()).toString()); +// JSONObject dataChildren = JSONObject.parseObject(JSONArray.parseArray(data.get("children").toString()).get(UniversalEnum.ZERO.getNumber()).toString()); +// JSONObject qiLuGaoSu = JSONObject.parseObject(JSONArray.parseArray(dataChildren.get("children").toString()).get(UniversalEnum.ZERO.getNumber()).toString()); +// JSONObject jiHeYunGuan = JSONObject.parseObject(JSONArray.parseArray(qiLuGaoSu.get("children").toString()).get(UniversalEnum.ZERO.getNumber()).toString()); +// JSONArray jiHeYunGuanG35 = JSONArray.parseArray(jiHeYunGuan.get("children").toString()); + JSONArray data = cameraData.getJSONArray("data"); + JSONObject children = data.getJSONObject(0); + JSONArray jsonObject = children.getJSONArray("children"); + JSONObject jsonObjectValue = jsonObject.getJSONObject(0);//济菏+德幸 + JSONArray array = jsonObjectValue.getJSONArray("children"); + JSONObject object = array.getJSONObject(0);//收费站 + JSONArray jsonArray = object.getJSONArray("children"); + JSONArray objects = new JSONArray(); + jsonArray.forEach(item->{ + JSONObject cameraInfo = (JSONObject) item; + if (cameraInfo.containsKey("children")) { + JSONArray cameraInfoJSONArray = cameraInfo.getJSONArray("children"); + for (int i = 0; i < cameraInfoJSONArray.size(); i++){ + JSONObject camObject = cameraInfoJSONArray.getJSONObject(i); + objects.add(camObject); + } + } + }); + JSONObject arrayJSONObject = array.getJSONObject(1);//扩建 + JSONArray jiHeYunGuanG35 = arrayJSONObject.getJSONArray("children"); List list = new ArrayList<>(); for (Object json : jiHeYunGuanG35) { JSONObject item = JSONObject.parseObject(json.toString()); @@ -216,7 +274,17 @@ public class VideoController extends BaseController { device.setIotDeviceId(item.get("camId").toString()); list.add(device); } - + for (Object json : objects) { + JSONObject item = JSONObject.parseObject(json.toString()); + DcDevice device = new DcDevice(); + if (item.get("status").equals(UniversalEnum.ZERO.getValue())) { + device.setDeviceState(UniversalEnum.ONE.getValue()); + } else { + device.setDeviceState(UniversalEnum.ZERO.getValue()); + } + device.setIotDeviceId(item.get("camId").toString()); + list.add(device); + } iDcDeviceService.batchUpdate(list); //更新中间库的设备状态 @@ -822,7 +890,6 @@ public class VideoController extends BaseController { return getJsonResult(response,okHttp); } - /** * 判断是否是附近桩号 * @@ -852,5 +919,4 @@ public class VideoController extends BaseController { int meter = Integer.parseInt(parts[UniversalEnum.ONE.getNumber()]); return kilometer * UniversalEnum.THOUSAND.getNumber() + meter; } - } diff --git a/zc-business/src/main/java/com/zc/business/mapper/DcDeviceMapper.java b/zc-business/src/main/java/com/zc/business/mapper/DcDeviceMapper.java index a388851a..9c28ea5f 100644 --- a/zc-business/src/main/java/com/zc/business/mapper/DcDeviceMapper.java +++ b/zc-business/src/main/java/com/zc/business/mapper/DcDeviceMapper.java @@ -35,4 +35,8 @@ public interface DcDeviceMapper extends BaseMapper { int selectDeviceNumber(); public List> selectDeviceOfRoad(); + //收费站摄像头 + List selectDeviceTollStationCamera(); + //同步收费站摄像头状态 + Integer updateTollStationCameraStatus(DcDevice dcDevice); } 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 90e00570..c23145d1 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 @@ -7,6 +7,8 @@ import com.zc.business.domain.DcDevice; import com.zc.business.domain.DcEvent; import com.zc.business.domain.DcStakeMark; import com.zc.common.core.httpclient.exception.HttpException; +import io.swagger.v3.oas.models.security.SecurityScheme; +import sun.reflect.generics.tree.VoidDescriptor; import java.io.IOException; import java.util.HashMap; @@ -120,4 +122,10 @@ public interface IDcDeviceService extends IService { public List> selectDeviceParameterProperties(DcDevice dcDevice); AjaxResult getDeviceByIotDeviceId(String iotDeviceId) throws HttpException, IOException; + + //查询收费站摄像头 + List selectDeviceTollStationCamera(); + //同步收费站摄像头状态 + Integer updateTollStationCameraStatus(DcDevice dcDevice); + } 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 3bc8d0ad..fa16041f 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 @@ -638,9 +638,21 @@ public class DcDeviceServiceImpl extends ServiceImpl i return JSON.parseObject(response.body().string(), AjaxResult.class); } + + public List> selectDeviceOfRoad() { return dcDeviceMapper.selectDeviceOfRoad(); } + //查询收费站摄像头 + @Override + public List selectDeviceTollStationCamera() { + return dcDeviceMapper.selectDeviceTollStationCamera(); + } + + @Override + public Integer updateTollStationCameraStatus(DcDevice dcDevice) { + return dcDeviceMapper.updateTollStationCameraStatus(dcDevice); + } } diff --git a/zc-business/src/main/resources/mapper/business/DcDeviceMapper.xml b/zc-business/src/main/resources/mapper/business/DcDeviceMapper.xml index 1e703994..519d3faf 100644 --- a/zc-business/src/main/resources/mapper/business/DcDeviceMapper.xml +++ b/zc-business/src/main/resources/mapper/business/DcDeviceMapper.xml @@ -72,6 +72,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + - + + + update dc_device set device_state=#{deviceState} where id=#{id} +