From 1d3a81bc7aac11b3f3d801d2f546e5b106553880 Mon Sep 17 00:00:00 2001 From: zhaoxianglong Date: Thu, 25 Jan 2024 18:59:05 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=B7=AF=E6=B5=8B?= =?UTF-8?q?=E5=B9=BF=E6=92=AD=E8=AE=BE=E5=A4=87=E5=AE=9A=E6=97=B6=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E4=B8=8A=E7=BA=BF=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../business/controller/VideoController.java | 90 ++++++++++++++++--- 1 file changed, 76 insertions(+), 14 deletions(-) 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 f0b08a96..b323fc53 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 @@ -3,8 +3,10 @@ package com.zc.business.controller; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; 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.domain.AjaxResult; +import com.ruoyi.common.core.redis.RedisCache; import com.zc.business.domain.DcDevice; import com.zc.business.service.IDcDeviceService; import com.zc.common.core.httpclient.OkHttp; @@ -22,6 +24,7 @@ import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; import java.io.IOException; import java.util.*; +import java.util.concurrent.TimeUnit; import static com.ruoyi.common.constant.Constants.HTTP; @@ -36,6 +39,10 @@ import static com.ruoyi.common.constant.Constants.HTTP; @RequestMapping("/video") 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 PASSWORD = "jhgskj@2023"; private static String TOKEN; @@ -47,6 +54,8 @@ public class VideoController extends BaseController { public static final Integer ERROR = 500; + @Resource + private RedisCache redisCache; @Resource private IDcDeviceService iDcDeviceService; @@ -55,8 +64,8 @@ public class VideoController extends BaseController { */ @ApiOperation("查询附近相机") @GetMapping(value = "/nearCamListDistance") - public JSONObject nearCamListDistance(@ApiParam(value = "纬度", name = "devLat",required = true)String devLat, - @ApiParam(value = "经度", name = "devLon",required = true)String devLon) throws HttpException, IOException { + public JSONObject nearCamListDistance(@ApiParam(value = "纬度", name = "devLat", required = true) String devLat, + @ApiParam(value = "经度", name = "devLon", required = true) String devLon) throws HttpException, IOException { JSONObject jsonResult = null; @@ -106,21 +115,21 @@ public class VideoController extends BaseController { */ @Scheduled(cron = "0 0/5 * * * ?") public void updateDeviceState() throws HttpException, IOException { - logger.debug("开始执行:同步数据平台设备的设备状态!!"); + 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()); + 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) { + for (Object json : jiHeYunGuanG35) { JSONObject item = JSONObject.parseObject(json.toString()); DcDevice device = new DcDevice(); if (item.get("status").equals("0")) { device.setDeviceState("1"); - }else { + } else { device.setDeviceState("0"); } device.setIotDeviceId(item.get("camId").toString()); @@ -131,6 +140,7 @@ public class VideoController extends BaseController { logger.debug("执行:同步数据平台视频设备的设备状态成功!!"); } + logger.debug("开始执行:同步物联平台设备的设备状态!!"); AjaxResult ajaxResult = synchronizingDeviceStatus(); if (ajaxResult.get("code").equals(200)) { JSONArray data = (JSONArray) ajaxResult.get("data"); @@ -139,28 +149,80 @@ public class VideoController extends BaseController { DcDevice dcDevice = new DcDevice(); JSONObject datum1 = (JSONObject) datum; 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); } 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 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 { OkHttp okHttp = new OkHttp(); Response response // 请求响应 = okHttp - .url(HTTP+"10.0.81.202:8081" + "/api/iot/device/query") // 请求地址 + .url(HTTP + "10.0.81.202:8081" + "/api/iot/device/query") // 请求地址 .get(); // 请求方法 - AjaxResult ajaxResult = JSON.parseObject(response.body().string(), AjaxResult.class); - return ajaxResult; + return JSON.parseObject(response.body().string(), AjaxResult.class); } From 106aa7f35e8db46c8841f95365c1908748aa8a03 Mon Sep 17 00:00:00 2001 From: lau572 <1010031226@qq.com> Date: Thu, 25 Jan 2024 19:37:21 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E6=A1=A9=E5=8F=B7id=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/zc/business/domain/DcStakeMark.java | 4 ++-- .../com/zc/business/service/impl/DcDeviceServiceImpl.java | 2 +- .../zc/business/service/impl/DcStakeMarkServiceImpl.java | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/zc-business/src/main/java/com/zc/business/domain/DcStakeMark.java b/zc-business/src/main/java/com/zc/business/domain/DcStakeMark.java index f69b5840..123c57cd 100644 --- a/zc-business/src/main/java/com/zc/business/domain/DcStakeMark.java +++ b/zc-business/src/main/java/com/zc/business/domain/DcStakeMark.java @@ -13,8 +13,8 @@ public class DcStakeMark { public static final String UP = "1"; public static final String CENTRE = "2"; public static final String DOWN = "3"; - @ApiModelProperty("ID") - private String id; + @ApiModelProperty("桩号") + private String stakeMark; @ApiModelProperty("经度") private String longitude; @ApiModelProperty("纬度") 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 0bc79af1..285cc341 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 @@ -281,7 +281,7 @@ public class DcDeviceServiceImpl extends ServiceImpl i public DcStakeMark exampleQueryTheAssociatedPileNumber(DcDevice dcDevice) { DcStakeMark dcStakeMark = new DcStakeMark(); dcStakeMark.setDirection(dcDevice.getDirection()); - dcStakeMark.setId(dcDevice.getStakeMark()); + dcStakeMark.setStakeMark(dcDevice.getStakeMark()); List dcStakeMarks = dcStakeMarkService.listStakeMark(dcStakeMark); if (dcStakeMarks.size() == 1) { return dcStakeMarks.get(0); diff --git a/zc-business/src/main/java/com/zc/business/service/impl/DcStakeMarkServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/DcStakeMarkServiceImpl.java index ecaec4dd..3dacb227 100644 --- a/zc-business/src/main/java/com/zc/business/service/impl/DcStakeMarkServiceImpl.java +++ b/zc-business/src/main/java/com/zc/business/service/impl/DcStakeMarkServiceImpl.java @@ -29,8 +29,8 @@ public class DcStakeMarkServiceImpl extends ServiceImpl queryWrapper = new LambdaQueryWrapper<>(); // 设备ID - if (StringUtils.hasText(dcStakeMark.getId())) { - queryWrapper.eq(DcStakeMark::getId, dcStakeMark.getId()); + if (StringUtils.hasText(dcStakeMark.getStakeMark())) { + queryWrapper.eq(DcStakeMark::getStakeMark, dcStakeMark.getStakeMark()); } // 经度 @@ -69,7 +69,7 @@ public class DcStakeMarkServiceImpl extends ServiceImpl Date: Fri, 26 Jan 2024 15:09:14 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E4=BA=8B=E4=BB=B6=E5=A4=9A=E5=8F=91?= =?UTF-8?q?=E8=B7=AF=E6=AE=B5=E5=88=86=E6=9E=90=E6=8E=A5=E5=8F=A3=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../business/service/impl/DcTrafficIncidentsServiceImpl.java | 2 +- .../resources/mapper/business/DcTrafficIncidentsMapper.xml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/zc-business/src/main/java/com/zc/business/service/impl/DcTrafficIncidentsServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/DcTrafficIncidentsServiceImpl.java index 9c7c0198..3e7a3a38 100644 --- a/zc-business/src/main/java/com/zc/business/service/impl/DcTrafficIncidentsServiceImpl.java +++ b/zc-business/src/main/java/com/zc/business/service/impl/DcTrafficIncidentsServiceImpl.java @@ -435,7 +435,7 @@ public class DcTrafficIncidentsServiceImpl implements IDcTrafficIncidentsService BigDecimal yearNumRatio = new BigDecimal(map.get("num").toString()).multiply(new BigDecimal("100")).divide(new BigDecimal(map.get("lastYearNum").toString()),2, RoundingMode.HALF_UP); map.put("yearNumRatio",yearNumRatio); } else { - map.put("ratio",0); + map.put("yearNumRatio",0); } //时长同比 diff --git a/zc-business/src/main/resources/mapper/business/DcTrafficIncidentsMapper.xml b/zc-business/src/main/resources/mapper/business/DcTrafficIncidentsMapper.xml index 10315f58..49ac4fcf 100644 --- a/zc-business/src/main/resources/mapper/business/DcTrafficIncidentsMapper.xml +++ b/zc-business/src/main/resources/mapper/business/DcTrafficIncidentsMapper.xml @@ -257,7 +257,7 @@ LEFT JOIN (select t2.section_id, count(*) num from dc_event t1 - left join dc_stake_mark t2 on t1.stake_mark = t2.id and t1.direction = t2.direction + left join dc_stake_mark t2 on t1.stake_mark = t2.stake_mark and t1.direction = t2.direction where t1.event_type = '1' and t1.direction = #{direction} @@ -277,7 +277,7 @@ LEFT JOIN (select t2.section_id, count(*) lastNum from dc_event t1 - left join dc_stake_mark t2 on t1.stake_mark = t2.id and t1.direction = t2.direction + left join dc_stake_mark t2 on t1.stake_mark = t2.stake_mark and t1.direction = t2.direction where t1.event_type = '1' and t1.direction = #{direction} From f04ef293e502f24b7639dacc5dd74ecc68427b1d Mon Sep 17 00:00:00 2001 From: lau572 <1010031226@qq.com> Date: Fri, 26 Jan 2024 18:41:05 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E4=BA=8B=E4=BB=B6=E5=A4=9A=E5=8F=91?= =?UTF-8?q?=E8=B7=AF=E6=AE=B5=E5=88=86=E6=9E=90=E6=8E=A5=E5=8F=A3=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/resources/mapper/business/DcTrafficIncidentsMapper.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zc-business/src/main/resources/mapper/business/DcTrafficIncidentsMapper.xml b/zc-business/src/main/resources/mapper/business/DcTrafficIncidentsMapper.xml index 49ac4fcf..e9337764 100644 --- a/zc-business/src/main/resources/mapper/business/DcTrafficIncidentsMapper.xml +++ b/zc-business/src/main/resources/mapper/business/DcTrafficIncidentsMapper.xml @@ -298,7 +298,7 @@