|
@@ -4,13 +4,9 @@ package com.sooka.sponest.monitor.dahua.controller;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
|
|
import com.ruoyi.common.core.domain.R;
|
|
|
-import com.ruoyi.common.core.web.domain.AjaxResult;
|
|
|
import com.ruoyi.common.log.annotation.Log;
|
|
|
import com.ruoyi.common.log.enums.BusinessType;
|
|
|
import com.sooka.sponest.monitor.camera.mapper.CentermonitorTCameraMapper;
|
|
|
-import com.sooka.sponest.monitor.dahua.domain.CentermonitorTMonitoringEquipmentPositionDO;
|
|
|
-import com.sooka.sponest.monitor.dahua.mapper.CentermonitorTMonitoringEquipmentPositionMapper;
|
|
|
-import com.sooka.sponest.monitor.dahua.service.DahuaService;
|
|
|
import com.sooka.sponest.monitor.dahua.utils.HttpEnum;
|
|
|
import com.sooka.sponest.monitor.dahua.utils.HttpTestUtils;
|
|
|
import io.swagger.annotations.Api;
|
|
@@ -19,25 +15,24 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
-import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.util.Arrays;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
import static org.springframework.web.bind.annotation.RequestMethod.GET;
|
|
|
|
|
|
|
|
|
/**
|
|
|
- * 对接大华根据组织获取执法记录仪、单兵设备在线状态
|
|
|
+ * 对接大华根据组织获取反拉和低点位在线状态定时任务
|
|
|
*/
|
|
|
|
|
|
@Slf4j
|
|
|
@Component
|
|
|
-@Api(tags = "对接大华根据组织获取执法记录仪、单兵设备在线状态定时任务")
|
|
|
+@Api(tags = "对接大华根据组织获取反拉和低点位在线状态定时任务")
|
|
|
@RestController
|
|
|
@RequestMapping("/equipmentStatus/quartz")
|
|
|
public class EquipmentStatusTaskController {
|
|
@@ -52,111 +47,113 @@ public class EquipmentStatusTaskController {
|
|
|
private String userName;
|
|
|
@Value("${sooka.dahua_interface_server.userPwd}")
|
|
|
private String userPwd;
|
|
|
-// private String loginIp = "10.53.0.35";
|
|
|
+ // private String loginIp = "10.53.0.35";
|
|
|
// private String loginPort = "7901";
|
|
|
// private String userName = "system";
|
|
|
// private String userPwd = "Admin123";
|
|
|
//按组织获取设备详细信息
|
|
|
public static final String ACTION = "/videoService/devicesManager/devicesInfo";
|
|
|
- @Resource
|
|
|
- DahuaService dahuaService;
|
|
|
- @Resource
|
|
|
- CentermonitorTMonitoringEquipmentPositionMapper centermonitorTMonitoringEquipmentPositionMapper;
|
|
|
+ public static final String ROOT_ORG_CODE = "12438460063615168,15012101012011000001";
|
|
|
+
|
|
|
|
|
|
// @Scheduled(cron = "0/5 * * * * ?")
|
|
|
- @Log(title = "对接大华根据组织获取执法记录仪、单兵设备在线状态定时任务", businessType = BusinessType.OTHER)
|
|
|
- @ApiOperation(value = "对接大华根据组织获取执法记录仪、单兵设备在线状态定时任务", notes = "对接大华根据组织获取执法记录仪、单兵设备在线状态定时任务")
|
|
|
+ @Log(title = "对接大华根据组织获取反拉和低点位在线状态定时任务", businessType = BusinessType.OTHER)
|
|
|
+ @ApiOperation(value = "对接大华根据组织获取反拉和低点位在线状态定时任务", notes = "对接大华根据组织获取反拉和低点位在线状态定时任务")
|
|
|
@RequestMapping(value = "/getLongPollingPositionMsg", method = GET)
|
|
|
public void getLongPollingPositionMsg() throws Exception {
|
|
|
- log.info("开始执行获取记录仪在离线数据定时任务");
|
|
|
+ log.info("开始执行获反拉和低点位在离线数据定时任务");
|
|
|
R<?> result = HttpTestUtils.getToken(loginIp, Integer.parseInt(loginPort), userName, userPwd);
|
|
|
if (result.getCode() != 200) {
|
|
|
log.info("获取token失败,请检查配置信息:", JSONObject.parseObject(result.getMsg()));
|
|
|
}
|
|
|
String token = result.getData().toString();
|
|
|
- getMessage(loginIp, Integer.parseInt(loginPort), token);
|
|
|
+ getDeviceAllOrg(loginIp, Integer.parseInt(loginPort), token);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 根据组织code编码获取执法仪详情数据
|
|
|
+ * 根据组织code编码调用获取反拉和低点位详情数据
|
|
|
*
|
|
|
* @param ip
|
|
|
* @param port
|
|
|
* @param token
|
|
|
*/
|
|
|
- private void getMessage(String ip, int port, String token) {
|
|
|
+ private void getMessage(String ip, int port, String token, List<Map<String, Object>> arrayList) {
|
|
|
Map<String, String> content = new HashMap<>();
|
|
|
- content.put("orgCode", "11248668755298496");
|
|
|
- getDevicesInfo(ip, port, token, content);
|
|
|
-
|
|
|
+ int count = 0;
|
|
|
+ for (Map<String, Object> map : arrayList) {
|
|
|
+ content.put("orgCode", map.get("orgCode").toString());
|
|
|
+// log.info("当前组织机构编码为:{}", map.get("orgCode").toString());
|
|
|
+ count++;
|
|
|
+ log.info("当前循环次数为:{}", count);
|
|
|
+ getDevicesInfo(ip, port, token, content);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取反拉和低点位详情数据
|
|
|
+ *
|
|
|
+ * @param ip
|
|
|
+ * @param port
|
|
|
+ * @param token
|
|
|
+ * @param content
|
|
|
+ */
|
|
|
private void getDevicesInfo(String ip, int port, String token, Map<String, String> content) {
|
|
|
String response = HttpTestUtils.httpRequest(HttpEnum.POST, ip, port, ACTION, token, new Gson().toJson(content));
|
|
|
JSONObject jsonObject = JSONObject.parseObject(response);
|
|
|
+// log.info("根据组织code编码获取反拉和低点位jsonObject:{}", jsonObject);
|
|
|
if (jsonObject.get("devices") == null) {
|
|
|
- log.info("根据组织code编码获取执法仪response:{}", response);
|
|
|
- return;
|
|
|
+ log.info("根据组织code编码获取反拉和低点位设备详情为空:{}", jsonObject.get("devices"));
|
|
|
}
|
|
|
Map<String, Object> rsp = new Gson().fromJson(response, Map.class);
|
|
|
List<Map<String, Object>> arr = (List<Map<String, Object>>) rsp.get("devices");
|
|
|
- log.info("获取记录仪在离线数据 size = {}", arr.size());
|
|
|
+// log.info("获取反拉和低点位在离线数据 size = {}", arr.size());
|
|
|
updateDeviceState(arr);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 更新执法仪在离线状态
|
|
|
+ * 获取反拉和低点一级及以下的orgCode
|
|
|
+ *
|
|
|
+ * @param ip
|
|
|
+ * @param port
|
|
|
+ * @param token
|
|
|
+ */
|
|
|
+ private void getDeviceAllOrg(String ip, int port, String token) {
|
|
|
+ String response = HttpTestUtils.httpRequest(HttpEnum.GET, ip, port, "/videoService/devicesManager/deviceAllOrg?orgCodes=" + ROOT_ORG_CODE, token, null);
|
|
|
+ Map<String, Object> rsp = new Gson().fromJson(response, Map.class);
|
|
|
+ List<Map<String, Object>> arr = (List<Map<String, Object>>) rsp.get("results");
|
|
|
+// log.info("获取用户所属的组织树数据size:{}", arr.size());
|
|
|
+ getMessage(loginIp, Integer.parseInt(loginPort), token, arr);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新反拉和低点位在离线状态
|
|
|
*
|
|
|
* @param arr
|
|
|
*/
|
|
|
private void updateDeviceState(List<Map<String, Object>> arr) {
|
|
|
- log.info("根据组织code编码获取执法仪详情数据:{}", arr.size());
|
|
|
+// log.info("根据组织code编码获取反拉和低点位详情数据:{}", arr);
|
|
|
+ List<Map<String, Object>> channels;
|
|
|
+ String workingStatus;
|
|
|
if (CollectionUtils.isNotEmpty(arr)) {
|
|
|
- List<Map<String, Object>> list = (List<Map<String, Object>>) arr.get(0).get("units");
|
|
|
- for (Map<String, Object> map : list) {
|
|
|
- if (map.get("unitType").toString().equals("1")) {
|
|
|
- arr = (List<Map<String, Object>>) map.get("channels");
|
|
|
- //更新摄像头类型为录像机在离线状态
|
|
|
- List<String> channelCodeAllList = arr.stream().map(item -> item.get("channelCode"))
|
|
|
- .filter(channelCode -> channelCode != null)
|
|
|
- .map(Object::toString)
|
|
|
- .collect(Collectors.toList());
|
|
|
- //先把摄像头类型为录像机的状态全部改成离线
|
|
|
- if (CollectionUtils.isNotEmpty(channelCodeAllList)) {
|
|
|
- centermonitorTCameraMapper.updateBatchVideoRecorderOfflineState(channelCodeAllList);
|
|
|
+ for (Map<String, Object> map : arr) {
|
|
|
+ workingStatus = map.get("status").toString();
|
|
|
+// log.info("当前设备名称为:{},状态是:{}", map.get("name").toString(), workingStatus);
|
|
|
+ List<Map<String, Object>> list = (List<Map<String, Object>>) map.get("units");
|
|
|
+ for (Map<String, Object> var : list) {
|
|
|
+ if (var.get("unitType").toString().equals("1")) {
|
|
|
+ channels = (List<Map<String, Object>>) var.get("channels");
|
|
|
+ //更新反拉和低点位在离线状态
|
|
|
+ if (CollectionUtils.isNotEmpty(channels)) {
|
|
|
+ for (Map<String, Object> item : channels) {
|
|
|
+// log.info("更新当前设备名称为:{},通道编码为:{},状态为:{}", map.get("name").toString(), item.get("channelCode").toString(), workingStatus.equals("0") ? "1" : "0");
|
|
|
+ centermonitorTCameraMapper.updateBatchVideoRecorderState(workingStatus.equals("0") ? "1" : "0", item.get("channelCode").toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- //再修改摄像头类型为录像机的在线状态
|
|
|
- List<String> channelCodeList = arr.stream()
|
|
|
- .filter(item -> "1".equals(item.get("status")))
|
|
|
- .map(item -> item.get("channelCode"))
|
|
|
- .filter(channelCode -> channelCode != null)
|
|
|
- .map(Object::toString)
|
|
|
- .collect(Collectors.toList());
|
|
|
- if (CollectionUtils.isNotEmpty(channelCodeList)) {
|
|
|
- centermonitorTCameraMapper.updateBatchVideoRecorderOnlineState(channelCodeList);
|
|
|
- }
|
|
|
- break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 获取记录仪位置数据
|
|
|
- */
|
|
|
- @PostMapping("putDahuaRecorderLocation")
|
|
|
- @ResponseBody
|
|
|
- public AjaxResult insertLocationListToday(@RequestBody CentermonitorTMonitoringEquipmentPositionDO centermonitorTMonitoringEquipmentPositionDO) {
|
|
|
- try {
|
|
|
- dahuaService.insertEquipmentPosition(centermonitorTMonitoringEquipmentPositionDO);
|
|
|
- //更新执法记录仪经纬度
|
|
|
- log.info("获取记录仪位置数据:{}", centermonitorTMonitoringEquipmentPositionDO);
|
|
|
- centermonitorTMonitoringEquipmentPositionMapper.updateLongitudeAndLatitudeByCameraCode(centermonitorTMonitoringEquipmentPositionDO.getGpsX(), centermonitorTMonitoringEquipmentPositionDO.getGpsY(), centermonitorTMonitoringEquipmentPositionDO.getChannelCode());
|
|
|
- return AjaxResult.success();
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- return AjaxResult.error(500, "内部服务器错误");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
}
|