From 4a5027ab99b10da151abc92b75544490fe828cdf Mon Sep 17 00:00:00 2001
From: wany <13995595726@qq.com>
Date: Mon, 29 Jul 2024 13:23:23 +0800
Subject: [PATCH] =?UTF-8?q?=E8=A7=86=E9=A2=91=E7=82=B9=E5=B8=A6=E5=9C=A8?=
=?UTF-8?q?=E7=BA=BF=E7=8A=B6=E6=80=81=E5=88=97=E8=A1=A8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pom.xml | 6 +-
.../xyt/controller/AttCctvBaseController.java | 29 ++++++++
.../project/xyt/entity/vo/CameraOnlineVo.java | 22 ++++++
.../project/xyt/entity/vo/CctvControlVo.java | 45 ++++++++++++
.../gunshi/project/xyt/model/AttCctvBase.java | 5 ++
.../xyt/service/AttCctvBaseService.java | 24 ++++++-
.../xyt/service/GateValveRealService.java | 2 +-
.../project/xyt/service/IscService.java | 72 +++++++++++++++++++
8 files changed, 202 insertions(+), 3 deletions(-)
create mode 100644 src/main/java/com/gunshi/project/xyt/entity/vo/CameraOnlineVo.java
create mode 100644 src/main/java/com/gunshi/project/xyt/entity/vo/CctvControlVo.java
create mode 100644 src/main/java/com/gunshi/project/xyt/service/IscService.java
diff --git a/pom.xml b/pom.xml
index 819599a..f5c1d8b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -90,7 +90,11 @@
-
+
+ com.hikvision.ga
+ artemis-http-client
+ 1.1.3
+
diff --git a/src/main/java/com/gunshi/project/xyt/controller/AttCctvBaseController.java b/src/main/java/com/gunshi/project/xyt/controller/AttCctvBaseController.java
index d50b8a8..ceac669 100644
--- a/src/main/java/com/gunshi/project/xyt/controller/AttCctvBaseController.java
+++ b/src/main/java/com/gunshi/project/xyt/controller/AttCctvBaseController.java
@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.gunshi.core.result.R;
import com.gunshi.project.xyt.entity.so.AttCctvBasePage;
+import com.gunshi.project.xyt.entity.vo.CctvControlVo;
import com.gunshi.project.xyt.model.AttCctvBase;
import com.gunshi.project.xyt.service.AttCctvBaseService;
import com.gunshi.project.xyt.util.OkHttpUtil;
@@ -103,4 +104,32 @@ public class AttCctvBaseController {
return R.ok(ret);
}
+ @Operation(summary = "云台控制")
+ @PostMapping("/control")
+ public R control(@RequestBody CctvControlVo vo) {
+ String indexCode = vo.getIndexCode();
+ Integer action = vo.getAction();
+ Integer speed = vo.getSpeed();
+ String command = vo.getCommand();
+ String api = "http://223.75.53.141:81/isc/controlling?cameraIndexCode="+indexCode+"&action="+action+"&speed="+speed+"&command="+command+"&token=111";
+ OkHttpClient client = OkHttpUtil.build();
+ String ret = null;
+ try {
+ Response resp = client.newCall(new Request.Builder().url(api).build()).execute();
+ String respStr = resp.body().string();
+ ObjectMapper om = new ObjectMapper();
+ Map map = om.readValue(respStr, Map.class);
+ ret = map.get("data").toString();
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ return R.ok(ret);
+ }
+
+ @Operation(summary = "视频点列表(带在线状态)")
+ @GetMapping("/listWithStatus")
+ public R> listWithStatus() {
+ return R.ok(service.listWithStatus());
+ }
+
}
\ No newline at end of file
diff --git a/src/main/java/com/gunshi/project/xyt/entity/vo/CameraOnlineVo.java b/src/main/java/com/gunshi/project/xyt/entity/vo/CameraOnlineVo.java
new file mode 100644
index 0000000..403af6c
--- /dev/null
+++ b/src/main/java/com/gunshi/project/xyt/entity/vo/CameraOnlineVo.java
@@ -0,0 +1,22 @@
+package com.gunshi.project.xyt.entity.vo;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+/**
+ * Description:
+ * Created by wanyan on 2024/7/26
+ *
+ * @author wanyan
+ * @version 1.0
+ */
+@Data
+public class CameraOnlineVo {
+
+ @Schema(description="摄像头code")
+ private String indexCode;
+
+ @Schema(description="在线状态,0离线,1在线")
+ private Integer online;
+
+}
diff --git a/src/main/java/com/gunshi/project/xyt/entity/vo/CctvControlVo.java b/src/main/java/com/gunshi/project/xyt/entity/vo/CctvControlVo.java
new file mode 100644
index 0000000..0d78727
--- /dev/null
+++ b/src/main/java/com/gunshi/project/xyt/entity/vo/CctvControlVo.java
@@ -0,0 +1,45 @@
+package com.gunshi.project.xyt.entity.vo;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+/**
+ * Description:
+ * Created by wanyan on 2024/7/26
+ *
+ * @author wanyan
+ * @version 1.0
+ */
+@Data
+public class CctvControlVo {
+
+ @Schema(description="摄像头code")
+ private String indexCode;
+
+ @Schema(description="动作(0开始 1停止)")
+ private Integer action;
+
+ @Schema(description="云台速度")
+ private Integer speed;
+
+ @Schema(description="命令(LEFT 左转\n" +
+ "RIGHT右转\n" +
+ "UP 上转\n" +
+ "DOWN 下转\n" +
+ "ZOOM_IN 焦距变大\n" +
+ "ZOOM_OUT 焦距变小\n" +
+ "LEFT_UP 左上\n" +
+ "LEFT_DOWN 左下\n" +
+ "RIGHT_UP 右上\n" +
+ "RIGHT_DOWN 右下\n" +
+ "FOCUS_NEAR 焦点前移\n" +
+ "FOCUS_FAR 焦点后移\n" +
+ "IRIS_ENLARGE 光圈扩大\n" +
+ "IRIS_REDUCE 光圈缩小\n" +
+ "WIPER_SWITCH 接通雨刷开关\n" +
+ "START_RECORD_TRACK 开始记录运行轨迹\n" +
+ "STOP_RECORD_TRACK 停止记录运行轨迹\n" +
+ "START_TRACK 开始运行轨迹\n" +
+ "STOP_TRACK 停止运行轨迹;)")
+ private String command;
+}
diff --git a/src/main/java/com/gunshi/project/xyt/model/AttCctvBase.java b/src/main/java/com/gunshi/project/xyt/model/AttCctvBase.java
index 37b4aa6..47772d3 100644
--- a/src/main/java/com/gunshi/project/xyt/model/AttCctvBase.java
+++ b/src/main/java/com/gunshi/project/xyt/model/AttCctvBase.java
@@ -122,4 +122,9 @@ public class AttCctvBase implements Serializable {
@JsonFormat(pattern = DateFormatString.YYYY_MM_DD_HH_MM_SS, timezone = "GMT+8")
private Date createTime;
+
+ @TableField(exist = false)
+ @Schema(description="在线状态,0离线,1在线")
+ private Integer online;
+
}
\ No newline at end of file
diff --git a/src/main/java/com/gunshi/project/xyt/service/AttCctvBaseService.java b/src/main/java/com/gunshi/project/xyt/service/AttCctvBaseService.java
index 440efed..1db6b86 100644
--- a/src/main/java/com/gunshi/project/xyt/service/AttCctvBaseService.java
+++ b/src/main/java/com/gunshi/project/xyt/service/AttCctvBaseService.java
@@ -1,13 +1,19 @@
package com.gunshi.project.xyt.service;
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.gunshi.project.xyt.entity.vo.CameraOnlineVo;
import com.gunshi.project.xyt.mapper.AttCctvBaseMapper;
import com.gunshi.project.xyt.model.AttCctvBase;
+import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
-import java.util.Date;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
/**
* 描述: 视频基本信息表
@@ -20,6 +26,22 @@ import java.util.Date;
public class AttCctvBaseService extends ServiceImpl
{
+ @Resource
+ private IscService iscService;
+
+ public List listWithStatus() {
+ List list = this.list();
+ if(CollectionUtils.isEmpty(list)){
+ return new ArrayList<>();
+ }
+ List indexCodes = list.stream().map(AttCctvBase::getIndexCode).collect(Collectors.toList());
+ List cameraOnlineVos = iscService.getCameraOnlineStatus(indexCodes);
+ Map map = cameraOnlineVos.stream().collect(Collectors.toMap(CameraOnlineVo::getIndexCode, CameraOnlineVo::getOnline));
+ for (AttCctvBase base : list){
+ base.setOnline(map.get(base.getIndexCode()));
+ }
+ return list;
+ }
}
diff --git a/src/main/java/com/gunshi/project/xyt/service/GateValveRealService.java b/src/main/java/com/gunshi/project/xyt/service/GateValveRealService.java
index fd718d7..2be5661 100644
--- a/src/main/java/com/gunshi/project/xyt/service/GateValveRealService.java
+++ b/src/main/java/com/gunshi/project/xyt/service/GateValveRealService.java
@@ -117,7 +117,7 @@ public class GateValveRealService extends ServiceImpl list = reservoirWaterService.list();
diff --git a/src/main/java/com/gunshi/project/xyt/service/IscService.java b/src/main/java/com/gunshi/project/xyt/service/IscService.java
new file mode 100644
index 0000000..dd35257
--- /dev/null
+++ b/src/main/java/com/gunshi/project/xyt/service/IscService.java
@@ -0,0 +1,72 @@
+package com.gunshi.project.xyt.service;
+
+import cn.hutool.json.JSONArray;
+import cn.hutool.json.JSONObject;
+import cn.hutool.json.JSONUtil;
+import com.gunshi.project.xyt.entity.vo.CameraOnlineVo;
+import com.hikvision.artemis.sdk.ArtemisHttpUtil;
+import com.hikvision.artemis.sdk.config.ArtemisConfig;
+import org.springframework.stereotype.Service;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Description:
+ * Created by wanyan on 2024/7/26
+ *
+ * @author wanyan
+ * @version 1.0
+ */
+@Service
+public class IscService {
+
+ public List getCameraOnlineStatus(List indexCodes) {
+
+ /**
+ * STEP1:设置平台参数,根据实际情况,设置host appkey appsecret 三个参数.
+ */
+
+ ArtemisConfig.host="223.76.234.232:1443";
+ ArtemisConfig.appKey="22410244";
+ ArtemisConfig.appSecret="6WYT5OVPyCHJJmaaAZr9";
+
+ /**
+ * STEP2:设置OpenAPI接口的上下文
+ */
+ final String ARTEMIS_PATH = "/artemis";
+
+ /**
+ * STEP3:设置接口的URI地址
+ */
+ final String previewURLsApi = ARTEMIS_PATH + "/api/nms/v1/online/camera/get";
+ Map path = new HashMap(2) {
+ {
+ put("https://", previewURLsApi);//根据现场环境部署确认是http还是https
+ }
+ };
+
+ /**
+ * STEP4:设置参数提交方式
+ */
+ String contentType = "application/json";
+
+ /**
+ * STEP5:组装请求参数
+ */
+ JSONObject jsonBody = new JSONObject();
+ jsonBody.put("indexCodes", indexCodes);
+ jsonBody.put("pageNo", 1);
+ jsonBody.put("pageSize", 1000);
+ String body = jsonBody.toString();
+ /**
+ * STEP6:调用接口
+ */
+ String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType , null);// post请求application/json类型参数
+ JSONObject obj = JSONUtil.parseObj(result);
+ JSONObject jsonObject = obj.getJSONObject("data");
+ JSONArray list = jsonObject.getJSONArray("list");
+ return list.toList(CameraOnlineVo.class);
+ }
+}