1、安防告警时抓拍监控

This commit is contained in:
wyw 2024-08-15 16:05:08 +08:00
parent 58b20a4b8d
commit 6de0dd6a2b
6 changed files with 145 additions and 6 deletions

View File

@ -6,6 +6,7 @@ fastbee:
demoEnabled: true # 实例演示开关
# 文件路径以uploadPath结尾 示例( Windows配置 D:/uploadPathLinux配置 /uploadPath
profile: /home/soft/hzwmiot/uploadPath
# profile: D:/uploadPath
addressEnabled: true # 获取ip地址开关
captchaType: math # 验证码类型 math 数组计算 char 字符验证

View File

@ -110,9 +110,12 @@ public class UploadedPhotosController extends BaseController
// 处理时间戳
long timestamp = Long.parseLong(time + "000");
Date date = new Date(timestamp);
//抓拍监控并返回路径
String monitorPath = uploadedPhotosService.captureMonitorPhoto(sn);
//推送告警短信通知
uploadedPhotosService.sendAlarmMessage(sn, doorState, shakeState);
UploadedPhotos uploadedPhotos = new UploadedPhotos(
null, fileName, imei, sn, latitude, longitude, temperature, doorState, shakeState, date
null, fileName, monitorPath,imei, sn, latitude, longitude, temperature, doorState, shakeState, date
);
return toAjax(uploadedPhotosService.insertUploadedPhotos(uploadedPhotos));
} catch (IOException e) {

View File

@ -59,4 +59,19 @@ public interface IUploadedPhotosService
* @return 结果
*/
public int deleteUploadedPhotosById(Long id);
/**
* 抓拍监控照片
* @param sn
* @return
*/
String captureMonitorPhoto(String sn);
/**
* 发送短信通知
* @param sn
* @param doorState
* @param shakeState
*/
void sendAlarmMessage(String sn, String doorState, String shakeState);
}

View File

@ -1,13 +1,28 @@
package com.fastbee.iot.anfang.service.impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.json.JSONObject;
import com.fastbee.common.config.RuoYiConfig;
import com.fastbee.common.utils.DevParamsUtils;
import com.fastbee.common.utils.file.FileUploadUtils;
import com.fastbee.iot.anfang.service.IUploadedPhotosService;
import com.fastbee.iot.domain.Device;
import com.fastbee.iot.haikang.HaikangYingshiApi;
import com.fastbee.iot.mapper.UploadedPhotosMapper;
import com.fastbee.iot.model.anfang.UploadedPhotos;
import com.fastbee.iot.service.IDeviceService;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Handler;
/**
* 存储上传的照片信息Service业务层处理
@ -20,7 +35,8 @@ public class UploadedPhotosServiceImpl implements IUploadedPhotosService
{
@Resource
private UploadedPhotosMapper uploadedPhotosMapper;
@Autowired
private IDeviceService deviceService;
/**
* 查询存储上传的照片信息
*
@ -92,4 +108,101 @@ public class UploadedPhotosServiceImpl implements IUploadedPhotosService
{
return uploadedPhotosMapper.deleteUploadedPhotosById(id);
}
@Override
public String captureMonitorPhoto(String sn) {
Device device = deviceService.selectDeviceBySerialNumber(sn);
if (device == null) {
return "";
}
Map<String, Object> devParams = DevParamsUtils.getDevParams(device.getDevParams());
if(!devParams.containsKey("jiankongIds")){
return "";
}
String jiankongIds = devParams.get("jiankongIds").toString();
Device jiankongDevice = deviceService.selectDeviceByDeviceId(Long.parseLong(jiankongIds));
if(jiankongDevice == null){
return "";
}
Map devData = DevParamsUtils.getDevParams(jiankongDevice.getDevParams());
if (devData.get("appKey") == null) {
return "";
}
if (devData.get("appSecret") == null) {
return "";
}
if (devData.get("channelNo") == null) {
return "";
}
Map<String, Object> map = new HashMap<>();//存放参数
map.put("appKey", devData.get("appKey"));
map.put("appSecret", devData.get("appSecret"));
cn.hutool.json.JSONObject token = HaikangYingshiApi.getToken(map);
if (token != null && token.get("code").equals("200")) {
Map<String, Object> params = new HashMap<>();
token = (cn.hutool.json.JSONObject) token.get("data");
params.put("accessToken", token.get("accessToken"));
params.put("deviceSerial", jiankongDevice.getSerialNumber());
params.put("channelNo", devData.get("channelNo"));
cn.hutool.json.JSONObject token1 = HaikangYingshiApi.capture(params);
if (token1 != null && token1.get("code").equals("200")) {
String dirs = DateUtil.thisYear() + "/" + (DateUtil.thisMonth() + 1) + "/" + DateUtil.thisDayOfMonth();
File dirfile = new File(RuoYiConfig.getUploadPath() + "/" + dirs);
if (!dirfile.exists()) {
// 目录不存在创建目录
boolean created = dirfile.mkdirs();
if (created) {
} else {
}
} else {
}
Map data = (JSONObject) token1.get("data");
Map<String, Object> reMap = new HashMap<>();
reMap.put("picUrl", data.get("picUrl"));
if (data.get("picUrl") != null) {
try {
String picUrl = data.get("picUrl").toString();
URL url = new URL(picUrl);
HttpURLConnection httpConnection = (HttpURLConnection) url.openConnection();
int responseCode = httpConnection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
InputStream inputStream = httpConnection.getInputStream();
byte[] buffer = new byte[4096];
int bytesRead = -1;
String[] split1 = picUrl.split("\\.");
String filename =
DateUtil.date().toDateStr() + "-" + DateUtil.thisHour(true)
+ DateUtil.thisMinute() +
"-anfangmonitor-" + device.getDeviceId() + "."
+ split1[split1.length - 1].split("\\?")[0];
String pathUrl = RuoYiConfig.getUploadPath() + "/" + dirs + "/" + filename;
OutputStream outputStream = new FileOutputStream(pathUrl);
while ((bytesRead = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, bytesRead);
}
outputStream.close();
inputStream.close();
String httpimg = FileUploadUtils.getPathFileName(RuoYiConfig.getUploadPath(), dirs +
"/" + filename);
return httpimg;
} else {
System.out.println("读取http图片失败!");
return "";
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
return "";
} else {
return "";
}
}
return "";
}
@Override
public void sendAlarmMessage(String sn, String doorState, String shakeState) {
}
}

View File

@ -28,7 +28,9 @@ public class UploadedPhotos extends BaseEntity
/** 照片存储路径 */
@Excel(name = "照片存储路径")
private String photoPath;
/** 监控抓拍 */
@Excel(name = "监控抓拍")
private String monitorPath;
/** 设备IMEI号 */
@Excel(name = "设备IMEI号")
private String imei;

View File

@ -7,6 +7,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<resultMap type="com.fastbee.iot.model.anfang.UploadedPhotos" id="UploadedPhotosResult">
<result property="id" column="id" />
<result property="photoPath" column="photo_path" />
<result property="monitorPath" column="monitor_path" />
<result property="imei" column="imei" />
<result property="sn" column="sn" />
<result property="lat" column="lat" />
@ -18,10 +19,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap>
<sql id="selectUploadedPhotosVo">
select id, photo_path, imei, sn, lat, lng, temp, door_state, shake_state, upload_time from uploaded_photos
select id, photo_path,monitor_path, imei, sn, lat, lng, temp, door_state, shake_state, upload_time from uploaded_photos
</sql>
<select id="selectUploadedPhotosList" parameterType="com.fastbee.iot.model.anfang.UploadedPhotos" resultMap="UploadedPhotosResult">
<select id="selectUploadedPhotosList" parameterType="com.fastbee.iot.model.anfang.UploadedPhotos"
resultMap="UploadedPhotosResult">
<include refid="selectUploadedPhotosVo"/>
<where>
<if test="photoPath != null and photoPath != ''"> and photo_path = #{photoPath}</if>
@ -46,6 +48,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
insert into uploaded_photos
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="photoPath != null and photoPath != ''">photo_path,</if>
<if test="monitorPath != null and monitorPath != ''">monitor_path,</if>
<if test="imei != null and imei != ''">imei,</if>
<if test="sn != null">sn,</if>
<if test="lat != null">lat,</if>
@ -57,6 +60,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="photoPath != null and photoPath != ''">#{photoPath},</if>
<if test="monitorPath != null and monitorPath != ''">#{monitorPath},</if>
<if test="imei != null and imei != ''">#{imei},</if>
<if test="sn != null">#{sn},</if>
<if test="lat != null">#{lat},</if>
@ -72,6 +76,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
update uploaded_photos
<trim prefix="SET" suffixOverrides=",">
<if test="photoPath != null and photoPath != ''">photo_path = #{photoPath},</if>
<if test="monitorPath != null and monitorPath != ''">monitor_path = #{monitorPath},</if>
<if test="imei != null and imei != ''">imei = #{imei},</if>
<if test="sn != null">sn = #{sn},</if>
<if test="lat != null">lat = #{lat},</if>