This commit is contained in:
XinYi Song 2022-02-12 10:22:44 +08:00
parent 9db8142a1a
commit 29a7eb579c
7 changed files with 148 additions and 46 deletions

14
pom.xml
View File

@ -41,6 +41,13 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
<!--排除logback依赖-->
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
@ -185,6 +192,13 @@
<artifactId>spring-boot-starter-websocket</artifactId>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/redis.clients/jedis -->
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>3.7.0</version>
</dependency>
</dependencies>
<build>

View File

@ -13,7 +13,7 @@ import com.xkrs.util.RequestUtil;
*/
public class GetVideoTool {
public static String getVideo() throws JsonProcessingException {
public static String getVideo(String alarmCode) throws JsonProcessingException {
String token = GetTokenTool.getToken();
String url = "https://111.26.161.203:443/admin/API/SS/Record/GetAlarmRecords?token=" + token;
JSONObject jsonObject = new JSONObject();
@ -23,7 +23,7 @@ public class GetVideoTool {
jsonObject.put("project","PSDK");
jsonObject.put("method","SS.Record.GetAlarmRecords");
JSONObject jsonObject1 = new JSONObject();
jsonObject1.put("alarmCode","{8348AB45-93EF-E14B-BD85-F8FCB737C655}");
jsonObject1.put("alarmCode",alarmCode);
jsonObject1.put("optional","/admin/API/SS/Record/GetAlarmRecords");
jsonObject.put("data",jsonObject1);
String s = RequestUtil.doPostJson(url, jsonObject.toString());

View File

@ -2,16 +2,19 @@ package com.xkrs.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.xkrs.common.encapsulation.PromptMessageEnum;
import com.xkrs.common.tools.GetTokenTool;
import com.xkrs.common.tools.GetVideoTool;
import com.xkrs.common.tools.JackSonTool;
import com.xkrs.dao.EquipmentDao;
import com.xkrs.model.entity.Equipment;
import com.xkrs.util.DateTimeUtil;
import com.xkrs.util.RequestUtil;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
@ -25,6 +28,8 @@ public class EquipmentController {
@Resource
private EquipmentDao equipmentDao;
Locale locale = LocaleContextHolder.getLocale();
@GetMapping("/getEquipment")
public String getEquipment(){
Locale locale = LocaleContextHolder.getLocale();
@ -91,4 +96,39 @@ public class EquipmentController {
}
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "设备入库成功!", locale);
}
/**
* 查询实时视频信息
* @return
*/
@GetMapping("/findVideoPath")
public String findVideoPath(){
List<Map<String, String>> videoPath = equipmentDao.findVideoPath();
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, videoPath, locale);
}
/**
* 获取录像的url
* @RequestParam("alarmCodes") String alarmCodes
* @param
* @return
* @throws JsonProcessingException
*/
@PostMapping("/findVideo")
public String findVideo(@RequestBody Map map) throws JsonProcessingException {
String alarmCodes = (String) map.get("alarmCodes");
String video = GetVideoTool.getVideo(alarmCodes);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,video,locale);
}
/**
* 获取设备信息
* @return
*/
@GetMapping("/findEquipment")
public String findEquipment(){
List<Map<String, String>> equipment = equipmentDao.findEquipment();
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,equipment,locale);
}
}

View File

@ -4,18 +4,25 @@ import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.xkrs.common.encapsulation.PromptMessageEnum;
import com.xkrs.common.tools.GetTokenTool;
import com.xkrs.common.tools.JackSonTool;
import com.xkrs.dao.EquipmentDao;
import com.xkrs.model.entity.Equipment;
import com.xkrs.util.Md5Util;
import com.xkrs.util.RequestUtil;
import com.xkrs.util.WeatherUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.transaction.Transactional;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import static com.xkrs.common.encapsulation.OutputEncapsulation.outputEncapsulationObject;
/**
* @Author: XinYi Song
* @Date: 2022/2/8 14:32
@ -23,43 +30,18 @@ import java.util.Map;
@RestController
public class TestController {
@GetMapping("/getTT")
public Map getTT(){
String url1 = "https://111.26.161.203:443/admin/API/accounts/authorize";
String json1 = "{\n" +
" \"userName\": system,\n" +
" \"ipAddress\": \"\",\n" +
" \"clientType\": \"WINPC\"\n" +
"}";
// 第一次鉴权
String doPostJson = RequestUtil.doPostJson(url1, json1);
Map map = JackSonTool.json2map(doPostJson);
String randomKey = (String) map.get("randomKey");
Locale locale = LocaleContextHolder.getLocale();
String admin123 = Md5Util.stringToMd5("admin123");
String stringToMd5 = Md5Util.stringToMd5("system" + admin123);
String toMd5 = Md5Util.stringToMd5(stringToMd5);
String md5 = Md5Util.stringToMd5("system:" + "DSS:" + toMd5);
String signature = Md5Util.stringToMd5(md5 + ":" + randomKey);
@Resource
private EquipmentDao equipmentDao;
String url2 = "https://111.26.161.203:443/admin/API/accounts/authorize";
JSONObject jsonObject = new JSONObject();
jsonObject.put("userName","system");
jsonObject.put("randomKey",randomKey);
jsonObject.put("mac","");
jsonObject.put("encryptType","MD5");
jsonObject.put("ipAddress","");
jsonObject.put("signature",signature);
jsonObject.put("clientType","WINPC");
// 第二次鉴权
String postJson = RequestUtil.doPostJson(url2, jsonObject.toString());
Map map1 = JackSonTool.json2map(postJson);
String token = (String) map1.get("token");
return map1;
}
@PostMapping("/getVideo")
/**
* 获取录像的url
* @param
* @return
* @throws JsonProcessingException
*//*
@GetMapping("/getVideos")
public String getVideo(@RequestParam("alarmCode") String alarmCode) throws JsonProcessingException {
String token = GetTokenTool.getToken();
String url = "https://111.26.161.203:443/admin/API/SS/Record/GetAlarmRecords?token=" + token;
@ -100,8 +82,9 @@ public class TestController {
JsonNode jsonNode1 = objectMapper1.readTree(s1);
JsonNode data1 = jsonNode1.get("data");
String url1 = data1.get("url").asText();
return url1;
}
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,url1,locale);
}*/
/**
* 获取天气信息的接口
@ -117,4 +100,16 @@ public class TestController {
return jsonNode1;
}
@PostMapping("/updateVideoPath")
@Transactional(rollbackOn = Exception.class)
public String updateVideoPath(){
List<Equipment> allInformation = equipmentDao.findAllInformation();
for(Equipment equipment : allInformation){
String equipmentCode = equipment.getEquipmentCode();
String url = "http://111.26.161.203:7086/live/cameraid/"+equipmentCode+"%240/substream/1.m3u8";
equipmentDao.updateVideo(equipmentCode,url);
}
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"成功!",locale);
}
}

View File

@ -2,10 +2,47 @@ package com.xkrs.dao;
import com.xkrs.model.entity.Equipment;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import java.util.List;
import java.util.Map;
/**
* @Author: XinYi Song
* @Date: 2022/2/8 9:26
*/
public interface EquipmentDao extends JpaRepository<Equipment,Long> {
/**
* 根据设备编码修改实时视频路径
* @param code
* @param videoPath
*/
@Modifying(clearAutomatically=true)
@Query(value = "update equipment set live_video = ?2 where equipment_code = ?1",nativeQuery = true)
void updateVideo(String code,String videoPath);
/**
* 查询全部设备信息
* @return
*/
@Query(value = "select * from equipment",nativeQuery = true)
List<Equipment> findAllInformation();
/**
* 查询实时视频
* @return
*/
@Query(value = "select equipment_code equipmentcode,live_video livevideo from equipment",nativeQuery = true)
List<Map<String,String>> findVideoPath();
/**
* 获取设备的信息
* @return
*/
@Query(value = "select equipment_code equipmentcode,equipment_name equipmentname,equipment_type equipmenttype," +
"equipment_status equipmentstatus,equipment_longitude equipmentlongitude," +
"equipment_latitude equipmentlatitude,installation_time installationtime from equipment",nativeQuery = true)
List<Map<String,String>> findEquipment();
}

View File

@ -59,10 +59,15 @@ public class Equipment {
@Column(length = 65, columnDefinition = "varchar(65)")
private String installationTime;
/**
* 实时视频
*/
private String liveVideo;
public Equipment() {
}
public Equipment(Integer id, String equipmentCode, String equipmentName, String equipmentType, String equipmentStatus, String equipmentLongitude, String equipmentLatitude, String installationTime) {
public Equipment(Integer id, String equipmentCode, String equipmentName, String equipmentType, String equipmentStatus, String equipmentLongitude, String equipmentLatitude, String installationTime, String liveVideo) {
this.id = id;
this.equipmentCode = equipmentCode;
this.equipmentName = equipmentName;
@ -71,6 +76,7 @@ public class Equipment {
this.equipmentLongitude = equipmentLongitude;
this.equipmentLatitude = equipmentLatitude;
this.installationTime = installationTime;
this.liveVideo = liveVideo;
}
public Integer getId() {
@ -137,6 +143,14 @@ public class Equipment {
this.installationTime = installationTime;
}
public String getLiveVideo() {
return liveVideo;
}
public void setLiveVideo(String liveVideo) {
this.liveVideo = liveVideo;
}
@Override
public String toString() {
return "Equipment{" +
@ -148,6 +162,7 @@ public class Equipment {
", equipmentLongitude='" + equipmentLongitude + '\'' +
", equipmentLatitude='" + equipmentLatitude + '\'' +
", installationTime='" + installationTime + '\'' +
", liveVideo='" + liveVideo + '\'' +
'}';
}
}

View File

@ -44,6 +44,7 @@ spring.redis.lettuce.pool.max-idle = 100
spring.redis.lettuce.pool.min-idle = 1
spring.redis.lettuce.shutdown-timeout = 0
# MQ的配置
spring.activemq.broker-url=tcp://111.26.161.203:61616
spring.activemq.packages.trust-all=true
spring.activemq.user=admin