|
|
|
@ -1,685 +0,0 @@
|
|
|
|
|
//package org.dromara.service;
|
|
|
|
|
//
|
|
|
|
|
//import com.alibaba.fastjson.JSON;
|
|
|
|
|
//import com.alibaba.fastjson.JSONArray;
|
|
|
|
|
//import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
//import com.aliyun.auth.credentials.Credential;
|
|
|
|
|
//import com.aliyun.auth.credentials.provider.StaticCredentialProvider;
|
|
|
|
|
//import com.aliyun.sdk.service.dysmsapi20170525.AsyncClient;
|
|
|
|
|
//import com.aliyun.sdk.service.dysmsapi20170525.models.SendSmsRequest;
|
|
|
|
|
//import com.aliyun.sdk.service.dysmsapi20170525.models.SendSmsResponse;
|
|
|
|
|
//import com.ruoyi.common.core.constant.HwDictConstants;
|
|
|
|
|
//import com.ruoyi.common.core.constant.SecurityConstants;
|
|
|
|
|
//import com.ruoyi.common.core.constant.TdEngineConstants;
|
|
|
|
|
//import com.ruoyi.common.core.domain.R;
|
|
|
|
|
//import com.ruoyi.common.core.enums.ResultEnums;
|
|
|
|
|
//import com.ruoyi.common.core.utils.RegexUtils;
|
|
|
|
|
//import com.ruoyi.common.core.utils.StringUtils;
|
|
|
|
|
//import com.ruoyi.dataprocess.amap.LocationVo;
|
|
|
|
|
//import com.ruoyi.dataprocess.amap.PositionUtils;
|
|
|
|
|
//import com.ruoyi.dataprocess.amap.PositionVo;
|
|
|
|
|
//import com.ruoyi.dataprocess.common.ImageUtils;
|
|
|
|
|
//import com.ruoyi.dataprocess.domain.*;
|
|
|
|
|
//import com.ruoyi.dataprocess.mapper.*;
|
|
|
|
|
//import com.ruoyi.dataprocess.service.CommanHandleService;
|
|
|
|
|
//import com.ruoyi.dataprocess.service.IDataProcessService;
|
|
|
|
|
//import com.ruoyi.tdengine.api.RemoteTdEngineService;
|
|
|
|
|
//import com.ruoyi.tdengine.api.domain.TdField;
|
|
|
|
|
//import com.ruoyi.tdengine.api.domain.TdHistorySelectDto;
|
|
|
|
|
//import com.ruoyi.tdengine.api.domain.TdReturnDataVo;
|
|
|
|
|
//import com.ruoyi.tdengine.api.domain.TdTableVo;
|
|
|
|
|
//import darabonba.core.client.ClientOverrideConfiguration;
|
|
|
|
|
//import org.apache.commons.codec.binary.Base64;
|
|
|
|
|
//import org.apache.poi.openxml4j.exceptions.InvalidOperationException;
|
|
|
|
|
//import org.slf4j.Logger;
|
|
|
|
|
//import org.slf4j.LoggerFactory;
|
|
|
|
|
//import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
//import org.springframework.stereotype.Service;
|
|
|
|
|
//
|
|
|
|
|
//import javax.annotation.Resource;
|
|
|
|
|
//import javax.script.ScriptEngine;
|
|
|
|
|
//import javax.script.ScriptEngineManager;
|
|
|
|
|
//import java.io.IOException;
|
|
|
|
|
//import java.math.BigDecimal;
|
|
|
|
|
//import java.text.SimpleDateFormat;
|
|
|
|
|
//import java.util.*;
|
|
|
|
|
//import java.util.concurrent.CompletableFuture;
|
|
|
|
|
//import java.util.concurrent.ExecutionException;
|
|
|
|
|
//import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
|
|
//import java.util.stream.Collectors;
|
|
|
|
|
//
|
|
|
|
|
///**
|
|
|
|
|
// * @Description: 数据处理业务类
|
|
|
|
|
// * @ClassName: DataProcessServiceImpl
|
|
|
|
|
// * @Author : xins
|
|
|
|
|
// * @Date :2023-09-04 8:58
|
|
|
|
|
// * @Version :1.0
|
|
|
|
|
// */
|
|
|
|
|
//@Service
|
|
|
|
|
//public class DataProcessServiceImpl extends CommanHandleService implements IDataProcessService {
|
|
|
|
|
//
|
|
|
|
|
// private static final Logger logger = LoggerFactory.getLogger(DataProcessServiceImpl.class);
|
|
|
|
|
//
|
|
|
|
|
// private final String AccessKeyId = "LTAI5tPoTQHh8HHst2toxtGa";
|
|
|
|
|
// private final String AccessKeySecret = "K8OIuSNgsSnpGMJ2PdqIJFYyUqL38m";
|
|
|
|
|
//
|
|
|
|
|
// @Resource
|
|
|
|
|
// private RemoteTdEngineService remoteTdEngineService;
|
|
|
|
|
//
|
|
|
|
|
// @Autowired
|
|
|
|
|
// private HwDeviceMapper hwDeviceMapper;
|
|
|
|
|
//
|
|
|
|
|
// @Autowired
|
|
|
|
|
// private HwElectronicFenceMapper hwElectronicFenceMapper;
|
|
|
|
|
//
|
|
|
|
|
// @Autowired
|
|
|
|
|
// private HwFenceAreaMapper hwFenceAreaMapper;
|
|
|
|
|
//
|
|
|
|
|
// @Autowired
|
|
|
|
|
// private HwAlarmInfoMapper hwAlarmInfoMapper;
|
|
|
|
|
//
|
|
|
|
|
// @Autowired
|
|
|
|
|
// private HwAlarmRuleMapper hwAlarmRuleMapper;
|
|
|
|
|
//
|
|
|
|
|
// /**
|
|
|
|
|
// * @param: jsonData
|
|
|
|
|
// * @param: imagePath ruoyifile的上传地址
|
|
|
|
|
// * @param: imagePatterns
|
|
|
|
|
// * @param: imageDomain ruoyifile的domain
|
|
|
|
|
// * @param: imagePrefix ruoyifile的prefix
|
|
|
|
|
// * @param: topic 发布主题,用来获取网关设备devicecode
|
|
|
|
|
// * @description
|
|
|
|
|
// * @author xins
|
|
|
|
|
// * @date 2023-08-31 16:16
|
|
|
|
|
// */
|
|
|
|
|
// @Override
|
|
|
|
|
// public int processBusinessData(String jsonData, String imagePath,
|
|
|
|
|
// String imagePatterns, String imageDomain, String imagePrefix, String topic) {
|
|
|
|
|
// JSONObject json = JSON.parseObject(jsonData);
|
|
|
|
|
// Long ts = json.getLong(TdEngineConstants.PAYLOAD_TS);
|
|
|
|
|
// String tsStr = String.valueOf(ts);
|
|
|
|
|
// if (tsStr.length() == 10) {
|
|
|
|
|
// ts = ts * 1000;
|
|
|
|
|
// }
|
|
|
|
|
// JSONArray paramArr = json.getJSONArray(TdEngineConstants.PAYLOAD_PARAM);
|
|
|
|
|
//// System.out.println(this.hwDeviceMapper);
|
|
|
|
|
//// System.out.println(this.remoteTdEngineService);
|
|
|
|
|
// String deviceCode = "";
|
|
|
|
|
// for (int i = 0; i < paramArr.size(); i++) {
|
|
|
|
|
// try {
|
|
|
|
|
// JSONObject paramJson = paramArr.getJSONObject(i);
|
|
|
|
|
// String dataType = paramJson.getString(TdEngineConstants.PAYLOAD_DATATYPE);
|
|
|
|
|
// JSONObject dataValueJson = paramJson.getJSONObject(TdEngineConstants.PAYLOAD_DATAVALUE);
|
|
|
|
|
// deviceCode = dataValueJson.getString(TdEngineConstants.PAYLOAD_DEVICE_CODE).toLowerCase();
|
|
|
|
|
// //deviceCode = getUidByParam(json);
|
|
|
|
|
// HwDevice hwDevice = hwDeviceMapper.selectHwDeviceByDeviceCode(deviceCode);
|
|
|
|
|
// if (hwDevice == null) {
|
|
|
|
|
// logger.error("此设备【deviceCode:{}】不存在", deviceCode);
|
|
|
|
|
// continue;
|
|
|
|
|
// }
|
|
|
|
|
// if (hwDevice.getDeviceStatus().equals(HwDictConstants.DEVICE_STATUS_DELETE)) {
|
|
|
|
|
// logger.error("此设备【deviceCode:{}】已删除", deviceCode);
|
|
|
|
|
// continue;
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// Long sceneId = hwDevice.getSceneId();
|
|
|
|
|
// Long deviceId = hwDevice.getDeviceId();
|
|
|
|
|
// Long monitorUnitId = hwDevice.getMonitorUnitId();
|
|
|
|
|
// Long tenantId = hwDevice.getTenantId();
|
|
|
|
|
// String databaseName = TdEngineConstants.getDatabaseName();
|
|
|
|
|
// String tableName = TdEngineConstants.DEFAULT_TABLE_NAME_PREFIX + deviceId;
|
|
|
|
|
//
|
|
|
|
|
// dataValueJson.remove(TdEngineConstants.PAYLOAD_DEVICE_CODE);
|
|
|
|
|
// TdTableVo tdTableVo = new TdTableVo();
|
|
|
|
|
// List<TdField> schemaFields = new ArrayList<>();
|
|
|
|
|
// List<TdField> alarmSchemaFields = new ArrayList<>();
|
|
|
|
|
//
|
|
|
|
|
// //添加timestamp字段,默认字段名称是ts,协议上传的key是timestamp
|
|
|
|
|
// TdField firstTdField = new TdField();
|
|
|
|
|
// firstTdField.setFieldName(TdEngineConstants.DEFAULT_FIRST_FIELD_NAME);
|
|
|
|
|
// long currentTimeMillis = System.currentTimeMillis();
|
|
|
|
|
// firstTdField.setFieldValue(currentTimeMillis);
|
|
|
|
|
//// firstTdField.setFieldValue(ts);
|
|
|
|
|
// schemaFields.add(firstTdField);
|
|
|
|
|
//
|
|
|
|
|
// Object longitude = null;
|
|
|
|
|
// Object latitude = null;
|
|
|
|
|
//
|
|
|
|
|
// for (Map.Entry<String, Object> entry : dataValueJson.entrySet()) {
|
|
|
|
|
// String originalKey = entry.getKey();//原来的key
|
|
|
|
|
// Object value = entry.getValue();
|
|
|
|
|
//
|
|
|
|
|
// /**
|
|
|
|
|
// * 先对key进行转换,例如对于key是value的需要转换成value1;
|
|
|
|
|
// */
|
|
|
|
|
// String key = TdEngineConstants.TDENGINE_KEY_TRANSFER_MAP.get(originalKey) == null ? originalKey
|
|
|
|
|
// : TdEngineConstants.TDENGINE_KEY_TRANSFER_MAP.get(originalKey);
|
|
|
|
|
//
|
|
|
|
|
// if (key.equalsIgnoreCase(TdEngineConstants.PAYLOAD_DEVICE_DATA_TYPE_TYPE)) {
|
|
|
|
|
// continue;
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// if (value instanceof String) {
|
|
|
|
|
// String valueStr = (String) value;
|
|
|
|
|
// if (StringUtils.isNotBlank(valueStr)) {
|
|
|
|
|
// /**
|
|
|
|
|
// * 先判读是否是图片,并获取图片名称, 获取到证明是图片
|
|
|
|
|
// */
|
|
|
|
|
// String[] imagePatternArr = imagePatterns.split(",");
|
|
|
|
|
// String extension = ImageUtils.getImageType(valueStr, imagePatternArr);
|
|
|
|
|
// if (StringUtils.isNotBlank(extension) && valueStr.length() > 300) {
|
|
|
|
|
// //保存图片,并返回图片详细地址进行赋值保存
|
|
|
|
|
// value = getImageFileName(imagePath, imageDomain, imagePrefix, valueStr, deviceId, extension);
|
|
|
|
|
// if (value == null) continue;
|
|
|
|
|
// } else if (dataType.equalsIgnoreCase(TdEngineConstants.PAYLOAD_DEVICE_DATA_TYPE_IMAGE)) {
|
|
|
|
|
// if (ImageUtils.checkIsBase64(valueStr) && valueStr.length() > 300) {//判断没有加前缀的情况
|
|
|
|
|
// String type = dataValueJson.getString(TdEngineConstants.PAYLOAD_DEVICE_DATA_TYPE_TYPE);
|
|
|
|
|
// if (type == null) {
|
|
|
|
|
// type = dataValueJson.getString(TdEngineConstants.PAYLOAD_DEVICE_DATA_TYPE_TYPE_FIRSET_UPPER);
|
|
|
|
|
// }
|
|
|
|
|
// extension = "jpg";
|
|
|
|
|
// if (type != null) {
|
|
|
|
|
// extension = StringUtils.isNotBlank(ImageUtils.getImageType(type, imagePatternArr))
|
|
|
|
|
// ? ImageUtils.getImageType(type, imagePatternArr) : extension;
|
|
|
|
|
// }
|
|
|
|
|
// value = getImageFileName(imagePath, imageDomain, imagePrefix, valueStr, deviceId, extension);
|
|
|
|
|
// if (value == null) continue;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// TdField tdField = new TdField();
|
|
|
|
|
// tdField.setFieldName(key);
|
|
|
|
|
// tdField.setFieldValue(value);
|
|
|
|
|
// schemaFields.add(tdField);
|
|
|
|
|
// }
|
|
|
|
|
// } else {
|
|
|
|
|
// TdField tdField = new TdField();
|
|
|
|
|
// tdField.setFieldName(key);
|
|
|
|
|
// tdField.setFieldValue(value);
|
|
|
|
|
// schemaFields.add(tdField);
|
|
|
|
|
//
|
|
|
|
|
// //经纬度判断
|
|
|
|
|
// if (key.equalsIgnoreCase(HwDictConstants.DEFAULT_FUNCTION_LONGITUDE_IDENTIFIER)) {
|
|
|
|
|
// longitude = value;
|
|
|
|
|
// } else if (key.equalsIgnoreCase(HwDictConstants.DEFAULT_FUNCTION_LATITUDE_IDENTIFIER)) {
|
|
|
|
|
// latitude = value;
|
|
|
|
|
// } else {
|
|
|
|
|
// TdField alarmTdField = new TdField();
|
|
|
|
|
// alarmTdField.setFieldName(originalKey);
|
|
|
|
|
// alarmTdField.setFieldValue(value);
|
|
|
|
|
// alarmSchemaFields.add(alarmTdField);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// tdTableVo.setDatabaseName(databaseName);
|
|
|
|
|
// tdTableVo.setTableName(tableName);
|
|
|
|
|
// tdTableVo.setSchemaFields(schemaFields);
|
|
|
|
|
//
|
|
|
|
|
// final R<?> insertResult = this.remoteTdEngineService.insertTable(tdTableVo , SecurityConstants.INNER);
|
|
|
|
|
// if (insertResult.getCode() == ResultEnums.SUCCESS.getCode()) {
|
|
|
|
|
// logger.info("Insert data result: {}", insertResult.getCode());
|
|
|
|
|
// } else {
|
|
|
|
|
// logger.error("Insert data Exception: {},data:{}", insertResult.getMsg(), jsonData);
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// //校验电子围栏
|
|
|
|
|
// if (longitude != null && latitude != null) {
|
|
|
|
|
// checkElectronicFence(deviceId, tenantId, monitorUnitId, sceneId, longitude, latitude, ts);
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// //校验设备报警信息
|
|
|
|
|
// checkAlarm(deviceId, alarmSchemaFields, tenantId, sceneId, monitorUnitId, topic, deviceCode);
|
|
|
|
|
//
|
|
|
|
|
// } catch (Exception e) {
|
|
|
|
|
// e.printStackTrace();
|
|
|
|
|
// logger.error("deviceCode:{},errorMsg:{},data:{}", deviceCode, e.getMessage(), jsonData);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// return paramArr.size();
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// /**
|
|
|
|
|
// * 获取设备UID
|
|
|
|
|
// * @param jsonStr
|
|
|
|
|
// * @return
|
|
|
|
|
// */
|
|
|
|
|
// private String getUidByParam(JSONObject jsonStr){
|
|
|
|
|
//
|
|
|
|
|
// JSONObject jsonObject = new JSONObject(jsonStr);
|
|
|
|
|
//
|
|
|
|
|
// JSONArray paramArray = jsonObject.getJSONArray("param");
|
|
|
|
|
//
|
|
|
|
|
// JSONObject firstParamObject = paramArray.getJSONObject(0);
|
|
|
|
|
//
|
|
|
|
|
// JSONObject datavalueObject = firstParamObject.getJSONObject("datavalue");
|
|
|
|
|
//
|
|
|
|
|
// String uid = datavalueObject.getString("uid");
|
|
|
|
|
//
|
|
|
|
|
// return uid;
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// private static String getImageFileName(String imagePath, String imageDomain, String imagePrefix, String valueStr, Long deviceId, String extension) {
|
|
|
|
|
// try {
|
|
|
|
|
// String imageFileName = ImageUtils.convertBase64ToImage(imagePath,
|
|
|
|
|
// valueStr, "device" + deviceId, extension);
|
|
|
|
|
// return imageDomain + imagePrefix + imageFileName;
|
|
|
|
|
//
|
|
|
|
|
// } catch (IOException e) {
|
|
|
|
|
// logger.error("转换图片错误:" + e.getMessage(), e);
|
|
|
|
|
// }
|
|
|
|
|
// return null;
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// /**
|
|
|
|
|
// * @param: deviceId
|
|
|
|
|
// * @param: monitorUnitId
|
|
|
|
|
// * @param: sceneId
|
|
|
|
|
// * @param: longitude
|
|
|
|
|
// * @param: latitude
|
|
|
|
|
// * @param: ts
|
|
|
|
|
// * @description 校验此设备电子围栏
|
|
|
|
|
// * @author xins
|
|
|
|
|
// * @date 2023-09-04 14:04
|
|
|
|
|
// */
|
|
|
|
|
// private void checkElectronicFence(Long deviceId, Long tenantId, Long monitorUnitId, Long sceneId, Object longitude, Object latitude, Long ts) {
|
|
|
|
|
// //根据设备ID、监控单元ID和场景ID获取所有的电子围栏配置。(目前先只支持场景)
|
|
|
|
|
//// List<HwElectronicFence> hwElectronicFences = hwElectronicFenceMapper.selectElectronicFencesByDeviceId(deviceId);
|
|
|
|
|
//// hwElectronicFences = hwElectronicFenceMapper.selectElectronicFencesByMonitorUnitId(monitorUnitId);
|
|
|
|
|
// List<HwElectronicFence> hwElectronicFences = hwElectronicFenceMapper.selectElectronicFencesBySceneId(sceneId);
|
|
|
|
|
//
|
|
|
|
|
// if (StringUtils.isNotEmpty(hwElectronicFences)) {
|
|
|
|
|
// for (HwElectronicFence hwElectronicFence : hwElectronicFences) {
|
|
|
|
|
// HwFenceArea queryFenceArea = new HwFenceArea();
|
|
|
|
|
// queryFenceArea.setElectronicFenceId(hwElectronicFence.getElectronicFenceId());
|
|
|
|
|
// //获取电子围栏下配置的区域列表
|
|
|
|
|
// List<HwFenceArea> fenceAreas = hwFenceAreaMapper.selectHwFenceAreaList(queryFenceArea);
|
|
|
|
|
// String effectiveTimeFlag = hwElectronicFence.getEffectiveTimeFlag();
|
|
|
|
|
// String triggerStatus = hwElectronicFence.getTriggerStatus();
|
|
|
|
|
// if (fenceAreas != null && !fenceAreas.isEmpty()) {
|
|
|
|
|
// fenceAreas.forEach(fenceArea -> {
|
|
|
|
|
// boolean isAlarmed = false;//是否报警
|
|
|
|
|
// if (effectiveTimeFlag.equals(HwDictConstants.EFFECTIVE_TIME_FLAG_LONG)) {
|
|
|
|
|
// String areaShapeFlag = fenceArea.getAreaShapeFlag();
|
|
|
|
|
// String areaRange = fenceArea.getAreaRange();
|
|
|
|
|
// //多边形处理
|
|
|
|
|
// if (areaShapeFlag.equals(HwDictConstants.AREA_SHAPE_FLAG_POLYGN)) {
|
|
|
|
|
// LocationVo polygonVo = new LocationVo();
|
|
|
|
|
// polygonVo.setMarkerType(LocationVo.MARKER_TYPE_POLYGON);
|
|
|
|
|
// List<List<PositionVo>> polygonList = new ArrayList<>();
|
|
|
|
|
// List<PositionVo> postionList = new ArrayList<>();
|
|
|
|
|
// String[] areaRangeArr = areaRange.split("_");//多个点,每个点的经纬度信息(经度_纬度)
|
|
|
|
|
// for (String areaRange1 : areaRangeArr) {
|
|
|
|
|
// String[] areaRange1Arr = areaRange1.split(",");
|
|
|
|
|
// String longitudeStr = areaRange1Arr[0];
|
|
|
|
|
// String latitudeStr = areaRange1Arr[1];
|
|
|
|
|
// postionList.add(new PositionVo(new BigDecimal(longitudeStr), new BigDecimal(latitudeStr)));
|
|
|
|
|
// polygonList.add(postionList);
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// polygonVo.setPolygonList(polygonList);
|
|
|
|
|
//
|
|
|
|
|
// /**
|
|
|
|
|
// * 传入的longitude和latitude是object类型,本身有可能是BigDecimal,Double,Long和Integer,先转成String再转成Double
|
|
|
|
|
// */
|
|
|
|
|
// boolean isWithin = PositionUtils.checkAddressInLocation(polygonVo, Double.valueOf(String.valueOf(longitude)), Double.valueOf(String.valueOf(latitude)));
|
|
|
|
|
// if (triggerStatus.equals(HwDictConstants.ELECTRONIC_FENCE_TRIGGER_STATUS_EXIT) && !isWithin) {//如果电子围栏配置是出界,而此设备出界则报警
|
|
|
|
|
// isAlarmed = true;
|
|
|
|
|
// } else if (triggerStatus.equals(HwDictConstants.ELECTRONIC_FENCE_TRIGGER_STATUS_ENTRY) && isWithin) {//如果电子围栏配置是入界,而此设备入界则报警
|
|
|
|
|
// isAlarmed = true;
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// } else if (areaShapeFlag.equals(HwDictConstants.AREA_SHAPE_FLAG_CIRCULA)) {//圆形处理
|
|
|
|
|
// String[] areaRangeArr = areaRange.split(",");
|
|
|
|
|
// String longitudeStr = areaRangeArr[0];
|
|
|
|
|
// String latitudeStr = areaRangeArr[1];
|
|
|
|
|
// String radiusStr = areaRangeArr[2];
|
|
|
|
|
// LocationVo circulrVo = new LocationVo();
|
|
|
|
|
// circulrVo.setRadius(Double.valueOf(radiusStr));
|
|
|
|
|
// circulrVo.setLongitude(Double.valueOf(longitudeStr));
|
|
|
|
|
// circulrVo.setLatitude(Double.valueOf(latitudeStr));
|
|
|
|
|
// circulrVo.setMarkerType(LocationVo.MARKER_TYPE_CIRCULAR);
|
|
|
|
|
// boolean isWithin = PositionUtils.checkAddressInLocation(circulrVo, Double.valueOf(String.valueOf(longitude)), Double.valueOf(String.valueOf(latitude)));
|
|
|
|
|
// if (triggerStatus.equals(HwDictConstants.ELECTRONIC_FENCE_TRIGGER_STATUS_EXIT) && !isWithin) {//如果电子围栏配置是出界,而此设备出界则报警
|
|
|
|
|
// isAlarmed = true;
|
|
|
|
|
// } else if (triggerStatus.equals(HwDictConstants.ELECTRONIC_FENCE_TRIGGER_STATUS_ENTRY) && isWithin) {//如果电子围栏配置是入界,而此设备入界则报警
|
|
|
|
|
// isAlarmed = true;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// if (isAlarmed) {
|
|
|
|
|
// HwAlarmInfo hwAralmInfo = new HwAlarmInfo();
|
|
|
|
|
// hwAralmInfo.setAlarmInfoType(HwDictConstants.ALARM_INFO_TYPE_ELECTRONIC_FENCE);
|
|
|
|
|
// hwAralmInfo.setAlarmReleatedId(hwElectronicFence.getElectronicFenceId());
|
|
|
|
|
// hwAralmInfo.setDeviceId(deviceId);
|
|
|
|
|
// hwAralmInfo.setMonitorUnitId(monitorUnitId);
|
|
|
|
|
// hwAralmInfo.setTenantId(tenantId);
|
|
|
|
|
// hwAralmInfo.setSceneId(sceneId);
|
|
|
|
|
// hwAralmInfo.setFunctionValue(longitude + "_" + latitude);
|
|
|
|
|
// hwAralmInfo.setTriggerStatus(triggerStatus);
|
|
|
|
|
// hwAralmInfo.setAlarmTime(new Date(ts));
|
|
|
|
|
// hwAralmInfo.setCreateTime(new Date());
|
|
|
|
|
// hwAralmInfo.setFenceAreaId(fenceArea.getFenceAreaId());
|
|
|
|
|
// hwAlarmInfoMapper.insertHwAlarmInfo(hwAralmInfo);
|
|
|
|
|
// }
|
|
|
|
|
// });
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// /**
|
|
|
|
|
// * @param: deviceId
|
|
|
|
|
// * @param: alarmFields
|
|
|
|
|
// * @description 校验报警
|
|
|
|
|
// * @author xins
|
|
|
|
|
// * @date 2023-11-07 10:15
|
|
|
|
|
// */
|
|
|
|
|
// private void checkAlarm(Long deviceId, List<TdField> alarmFields,
|
|
|
|
|
// Long tenantId, Long sceneId, Long monitorUnitId, String topic, String subDeviceCode) {
|
|
|
|
|
//
|
|
|
|
|
// try {
|
|
|
|
|
// HwAlarmRule queryAlarmRule = new HwAlarmRule();
|
|
|
|
|
// queryAlarmRule.setRuleDeviceId(deviceId);
|
|
|
|
|
// queryAlarmRule.setRuleType(HwDictConstants.ALARM_RULE_RULE_TYPE_DEVICE);
|
|
|
|
|
// queryAlarmRule.setAlarmRuleStatus(HwDictConstants.ALARM_RULE_STATUS_ENABLE);
|
|
|
|
|
// List<HwAlarmRule> alarmRules = hwAlarmRuleMapper.selectHwAlarmRulesWithLink(queryAlarmRule);
|
|
|
|
|
//
|
|
|
|
|
// ScriptEngineManager manager = new ScriptEngineManager();
|
|
|
|
|
// ScriptEngine engine = manager.getEngineByName("js");
|
|
|
|
|
//
|
|
|
|
|
// if (alarmRules != null) {
|
|
|
|
|
// Date currentDate = new Date();
|
|
|
|
|
// for (HwAlarmRule alarmRule : alarmRules) {
|
|
|
|
|
// String triggerExpression = alarmRule.getTriggerExpression()
|
|
|
|
|
// .replaceAll("and", "&&")
|
|
|
|
|
// .replaceAll("or", "||");
|
|
|
|
|
// AtomicBoolean isAlarmed = new AtomicBoolean(false);
|
|
|
|
|
// List<HwAlarmDetail> alarmDetails = new ArrayList<HwAlarmDetail>();
|
|
|
|
|
//
|
|
|
|
|
// for (TdField alarmField : alarmFields) {
|
|
|
|
|
// String fieldName = alarmField.getFieldName();
|
|
|
|
|
// Object filedValue = alarmField.getFieldValue();
|
|
|
|
|
// if (triggerExpression.contains("{" + fieldName + "}")) {
|
|
|
|
|
// isAlarmed.set(true);
|
|
|
|
|
//
|
|
|
|
|
// /**
|
|
|
|
|
// * Add By 获取五分钟内的数据 WenJY 2024-07-03 14:13:21
|
|
|
|
|
// */
|
|
|
|
|
// if(alarmRule.getTriggerTimeFrame() != null && alarmRule.getTriggerTimeFrame() > 0){
|
|
|
|
|
// double difValue = FilterDeviceValue(deviceId, fieldName, alarmRule.getTriggerTimeFrame());
|
|
|
|
|
//// if(difValue > 0){
|
|
|
|
|
//// filedValue = difValue;
|
|
|
|
|
//// }
|
|
|
|
|
// filedValue = difValue;
|
|
|
|
|
// }
|
|
|
|
|
// /** End **/
|
|
|
|
|
//
|
|
|
|
|
// triggerExpression = triggerExpression.replaceAll("\\{" + fieldName + "\\}", String.valueOf(filedValue));
|
|
|
|
|
// HwAlarmDetail alarmDetail = new HwAlarmDetail();
|
|
|
|
|
// alarmDetail.setDeviceId(deviceId);
|
|
|
|
|
// alarmDetail.setFunctionIdentifier(fieldName);
|
|
|
|
|
// alarmDetail.setFunctionValue(String.valueOf(filedValue));
|
|
|
|
|
// alarmDetail.setMonitorTime(currentDate);
|
|
|
|
|
// alarmDetails.add(alarmDetail);
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// if (isAlarmed.get() && !triggerExpression.contains("{")
|
|
|
|
|
// && RegexUtils.findSymbolInText(triggerExpression).size() > 0
|
|
|
|
|
// && RegexUtils.findNumberInText(triggerExpression).size() > 0) {
|
|
|
|
|
//
|
|
|
|
|
// Boolean triggerExpressionBool = (Boolean) engine.eval(triggerExpression);
|
|
|
|
|
// if (triggerExpressionBool) {
|
|
|
|
|
// HwAlarmInfo alarmInfo = new HwAlarmInfo();
|
|
|
|
|
// alarmInfo.setAlarmInfoType(HwDictConstants.ALARM_INFO_TYPE_DEVICE);
|
|
|
|
|
// alarmInfo.setAlarmReleatedId(alarmRule.getAlarmRuleId());
|
|
|
|
|
// alarmInfo.setDeviceId(deviceId);
|
|
|
|
|
// alarmInfo.setMonitorUnitId(monitorUnitId);
|
|
|
|
|
// alarmInfo.setTenantId(tenantId);
|
|
|
|
|
// alarmInfo.setSceneId(sceneId);
|
|
|
|
|
// alarmInfo.setAlarmLevelId(alarmRule.getAlarmLevelId());
|
|
|
|
|
// alarmInfo.setAlarmTypeId(alarmRule.getAlarmTypeId());
|
|
|
|
|
// alarmInfo.setHwAlarmDetailList(alarmDetails);
|
|
|
|
|
// alarmInfo.setHandleStatus(HwDictConstants.ALARM_HANDLE_STATUS_NO);
|
|
|
|
|
// alarmInfo.setCreateTime(currentDate);
|
|
|
|
|
// alarmInfo.setAlarmTime(currentDate);
|
|
|
|
|
// hwAlarmInfoMapper.insertHwAlarmInfo(alarmInfo);
|
|
|
|
|
// this.insertHwAlarmDetail(alarmInfo);
|
|
|
|
|
// this.handleAlarmLink(alarmRule, topic, subDeviceCode);
|
|
|
|
|
// /**
|
|
|
|
|
// * Add By WenJY 下发报警信息
|
|
|
|
|
// */
|
|
|
|
|
// if(StringUtils.isNotEmpty(alarmRule.getPhoneNumbers())){
|
|
|
|
|
// SendAlarmInfoBySms(deviceId,alarmRule);
|
|
|
|
|
// }else {
|
|
|
|
|
// logger.warn("设备:{};报警信息发送失败,联系方式为空",deviceId);
|
|
|
|
|
// }
|
|
|
|
|
// break;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }catch (Exception e){
|
|
|
|
|
// logger.error("设备:{};报警逻辑处理异常:{}",deviceId,e.getMessage());
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// /**
|
|
|
|
|
// * 过滤指定时间段内的数据,返回最大最小的差值,过滤0
|
|
|
|
|
// * @param deviceId
|
|
|
|
|
// * @param fieldName
|
|
|
|
|
// * @param triggerTimeFrame
|
|
|
|
|
// * @return 差值
|
|
|
|
|
// */
|
|
|
|
|
// private double FilterDeviceValue(Long deviceId,String fieldName,long triggerTimeFrame){
|
|
|
|
|
// double differenceValue = 0.00;
|
|
|
|
|
// String databaseName = TdEngineConstants.getDatabaseName();
|
|
|
|
|
// String tableName = TdEngineConstants.DEFAULT_TABLE_NAME_PREFIX + deviceId;
|
|
|
|
|
// long currentTimeMillis = System.currentTimeMillis();
|
|
|
|
|
// long fiveMinutesInMillis = triggerTimeFrame * 60 * 1000;
|
|
|
|
|
// long beforeTimeMillis = currentTimeMillis - fiveMinutesInMillis;
|
|
|
|
|
//
|
|
|
|
|
// TdHistorySelectDto tdHistorySelectDto = new TdHistorySelectDto();
|
|
|
|
|
// tdHistorySelectDto.setDatabaseName(databaseName);
|
|
|
|
|
// tdHistorySelectDto.setTableName(tableName);
|
|
|
|
|
// tdHistorySelectDto.setStartTime(beforeTimeMillis);
|
|
|
|
|
// tdHistorySelectDto.setEndTime(currentTimeMillis);
|
|
|
|
|
// tdHistorySelectDto.setFirstFieldName("ts");
|
|
|
|
|
// R<?> result = this.remoteTdEngineService.getHistoryData(tdHistorySelectDto , SecurityConstants.INNER);
|
|
|
|
|
//
|
|
|
|
|
// if (result.getCode() == ResultEnums.SUCCESS.getCode()) {
|
|
|
|
|
// logger.info("Get history data result: {}", result.getCode());
|
|
|
|
|
//
|
|
|
|
|
// TdReturnDataVo data = (TdReturnDataVo) result.getData();
|
|
|
|
|
//
|
|
|
|
|
// List<Map<String, Object>> dataList = data.getDataList();
|
|
|
|
|
// List<Double> value = dataList.stream().map(map -> (Double)map.get("value1")).distinct().filter(x -> x > 0).collect(Collectors.toList());
|
|
|
|
|
//
|
|
|
|
|
// System.out.println(triggerTimeFrame +"分钟内数据:"+JSONArray.toJSON(value) );
|
|
|
|
|
//
|
|
|
|
|
// OptionalDouble maxOptional = value.stream().mapToDouble(Double::doubleValue).max();
|
|
|
|
|
// OptionalDouble minOptional = value.stream().mapToDouble(Double::doubleValue).min();
|
|
|
|
|
//
|
|
|
|
|
// if (maxOptional.isPresent() && minOptional.isPresent()) {
|
|
|
|
|
// double maxValue = maxOptional.getAsDouble();
|
|
|
|
|
// double minValue = minOptional.getAsDouble();
|
|
|
|
|
// differenceValue = maxValue - minValue;
|
|
|
|
|
// System.out.println("Difference between max and min values: " + differenceValue);
|
|
|
|
|
// } else {
|
|
|
|
|
// System.out.println("No values found to calculate difference.");
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// } else {
|
|
|
|
|
// logger.error("Get history data Exception: {}", result.getMsg());
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// return differenceValue;
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// /**
|
|
|
|
|
// * 新增报警详情信息信息
|
|
|
|
|
// *
|
|
|
|
|
// * @param hwAlarmInfo 报警信息对象
|
|
|
|
|
// */
|
|
|
|
|
// private void insertHwAlarmDetail(HwAlarmInfo hwAlarmInfo) {
|
|
|
|
|
// List<HwAlarmDetail> hwAlarmDetailList = hwAlarmInfo.getHwAlarmDetailList();
|
|
|
|
|
// Long alarmInfoId = hwAlarmInfo.getAlarmInfoId();
|
|
|
|
|
// if (StringUtils.isNotNull(hwAlarmDetailList)) {
|
|
|
|
|
// List<HwAlarmDetail> list = new ArrayList<HwAlarmDetail>();
|
|
|
|
|
// for (HwAlarmDetail hwAlarmDetail : hwAlarmDetailList) {
|
|
|
|
|
// hwAlarmDetail.setAlarmInfoId(alarmInfoId);
|
|
|
|
|
// list.add(hwAlarmDetail);
|
|
|
|
|
// }
|
|
|
|
|
// if (list.size() > 0) {
|
|
|
|
|
// hwAlarmInfoMapper.batchHwAlarmDetail(list);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// /**
|
|
|
|
|
// * @param: alarmRule
|
|
|
|
|
// * @param: topic
|
|
|
|
|
// * @param: subDeviceCode
|
|
|
|
|
// * @description 处理报警规则联动设备
|
|
|
|
|
// * @author xins
|
|
|
|
|
// * @date 2023-11-07 16:39
|
|
|
|
|
// */
|
|
|
|
|
// private void handleAlarmLink(HwAlarmRule alarmRule, String topic, String subDeviceCode) {
|
|
|
|
|
// String controlCommandTopic = topic.replace(HwDictConstants.TOPIC_TYPE_DATA_POSTFIX, HwDictConstants.TOPIC_TYPE_COMMAND_POSTFIX);
|
|
|
|
|
// if (alarmRule.getLinkFlag().equals(HwDictConstants.ALARM_RULE_LINK_FLAG_YES)) {
|
|
|
|
|
// List<HwAlarmRuleLink> alarmRuleLinks = alarmRule.getHwAlarmRuleLinkList();
|
|
|
|
|
// alarmRuleLinks.forEach(alarmRuleLink -> {
|
|
|
|
|
// this.publishControlCommand(controlCommandTopic, subDeviceCode, alarmRuleLink.getLinkDeviceFunctionIdentifier());
|
|
|
|
|
// });
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// @Override
|
|
|
|
|
// public void testBase64(String jsonData, String imagePath, String imagePatterns, String imageDomain, String imagePrefix) {
|
|
|
|
|
// JSONObject json = JSON.parseObject(jsonData);
|
|
|
|
|
// Object value = json.get("base64");
|
|
|
|
|
// if (value instanceof String) {
|
|
|
|
|
//
|
|
|
|
|
// String valueStr = (String) value;
|
|
|
|
|
// System.out.println(Base64.isBase64(valueStr));
|
|
|
|
|
// if (StringUtils.isNotBlank(valueStr)) {
|
|
|
|
|
// /**
|
|
|
|
|
// * 先判读是否是图片,并获取图片名称, 获取到证明是图片
|
|
|
|
|
// */
|
|
|
|
|
// String[] imagePatternArr = imagePatterns.split(",");
|
|
|
|
|
// String extension = ImageUtils.getImageType(valueStr, imagePatternArr);
|
|
|
|
|
// if (StringUtils.isNotBlank(extension)) {
|
|
|
|
|
// //保存图片,并返回图片详细地址进行赋值保存
|
|
|
|
|
// Long deviceId = 100L;
|
|
|
|
|
// String imageFileName = null;
|
|
|
|
|
// try {
|
|
|
|
|
// imageFileName = ImageUtils.convertBase64ToImage(imagePath,
|
|
|
|
|
// valueStr, "device" + deviceId, extension);
|
|
|
|
|
// if (StringUtils.isNotBlank(imageFileName)) {
|
|
|
|
|
// String url = imageDomain + imagePrefix + imageFileName;
|
|
|
|
|
// System.out.println(url);
|
|
|
|
|
// }
|
|
|
|
|
// } catch (IOException e) {
|
|
|
|
|
// throw new RuntimeException(e);
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// /**
|
|
|
|
|
// * 发送报警短信
|
|
|
|
|
// * @param deviceId
|
|
|
|
|
// * @param alarmRule
|
|
|
|
|
// */
|
|
|
|
|
// private void SendAlarmInfoBySms(Long deviceId,HwAlarmRule alarmRule){
|
|
|
|
|
// try {
|
|
|
|
|
// HwDevice hwDevice = hwDeviceMapper.GetDeviceById(deviceId);
|
|
|
|
|
// if(hwDevice != null){
|
|
|
|
|
// AlarmMsgTemplateParam alarmMsgTemplateParam = new AlarmMsgTemplateParam();
|
|
|
|
|
// alarmMsgTemplateParam.setWarning(alarmRule.getAlarmRuleName());
|
|
|
|
|
// alarmMsgTemplateParam.setParentname(hwDevice.getMonitorUnitName());
|
|
|
|
|
// alarmMsgTemplateParam.setSensorID(deviceId.toString());
|
|
|
|
|
// AliSmsHandle(alarmRule.getPhoneNumbers(),alarmMsgTemplateParam);
|
|
|
|
|
// }
|
|
|
|
|
// } catch (ExecutionException | InterruptedException e) {
|
|
|
|
|
// throw new InvalidOperationException(String.format("报警信息发送异常:%e",e.getMessage()));
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// /**
|
|
|
|
|
// * 报警短信推送
|
|
|
|
|
// * @param phoneNumbers
|
|
|
|
|
// * @param alarmMsgTemplateParam
|
|
|
|
|
// * @throws ExecutionException
|
|
|
|
|
// * @throws InterruptedException
|
|
|
|
|
// */
|
|
|
|
|
// private void AliSmsHandle(String phoneNumbers,AlarmMsgTemplateParam alarmMsgTemplateParam ) throws ExecutionException, InterruptedException {
|
|
|
|
|
// StaticCredentialProvider provider = StaticCredentialProvider.create(Credential.builder()
|
|
|
|
|
// .accessKeyId(AccessKeyId)
|
|
|
|
|
// .accessKeySecret(AccessKeySecret)
|
|
|
|
|
// .build());
|
|
|
|
|
//
|
|
|
|
|
// AsyncClient client = AsyncClient.builder()
|
|
|
|
|
// .region("cn-shenzhen") // Region ID
|
|
|
|
|
// .credentialsProvider(provider)
|
|
|
|
|
// .overrideConfiguration(
|
|
|
|
|
// ClientOverrideConfiguration.create()
|
|
|
|
|
// .setEndpointOverride("dysmsapi.aliyuncs.com")
|
|
|
|
|
// )
|
|
|
|
|
// .build();
|
|
|
|
|
//
|
|
|
|
|
// String jsonString = com.alibaba.fastjson2.JSONArray.toJSONString(alarmMsgTemplateParam);
|
|
|
|
|
//
|
|
|
|
|
// SendSmsRequest sendSmsRequest = SendSmsRequest.builder()
|
|
|
|
|
// .phoneNumbers(phoneNumbers)
|
|
|
|
|
// .signName("深圳市金瑞铭科技")
|
|
|
|
|
// .templateCode("SMS_468740027")
|
|
|
|
|
// .templateParam(jsonString)
|
|
|
|
|
// .build();
|
|
|
|
|
// logger.info("向:{};发送报警信息:{}",phoneNumbers,jsonString);
|
|
|
|
|
// CompletableFuture<SendSmsResponse> response = client.sendSms(sendSmsRequest);
|
|
|
|
|
// SendSmsResponse resp = response.get();
|
|
|
|
|
//
|
|
|
|
|
// client.close();
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// public static void main(String[] args) {
|
|
|
|
|
// System.out.println(System.currentTimeMillis());
|
|
|
|
|
// SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
|
|
|
|
|
// Date date = new Date();
|
|
|
|
|
// System.out.println(format.format(date));
|
|
|
|
|
// Object jsonData = "{\n" +
|
|
|
|
|
// "\n" +
|
|
|
|
|
// " \"timestamp\": 1689814424,\"type\": \"CMD_REPORTDATA\",\n" +
|
|
|
|
|
// " \"param\": [\n{\n" +
|
|
|
|
|
// " \"datatype\": \"cttemperature\",\n" +
|
|
|
|
|
// "\"datavalue\": {\n" +
|
|
|
|
|
// " \"uid\": \"0009340109040126\", \"alias\": \"\",\n" +
|
|
|
|
|
// " \"value\": 25.6,\n" +
|
|
|
|
|
// " \"voltage\": 3.76,\n" +
|
|
|
|
|
// " \"rssi\": -80\n" +
|
|
|
|
|
// " } },\n" +
|
|
|
|
|
// " {\"datatype\": \"cttemperature\",\n" +
|
|
|
|
|
// " \"datavalue\": {\n" +
|
|
|
|
|
// " \"uid1\": \"00093440109040924\",\n" +
|
|
|
|
|
// " \"alias\": \"\",\n" +
|
|
|
|
|
// " \"value\": 25.6,\n" +
|
|
|
|
|
// " \"voltage\": 3.64,\n" +
|
|
|
|
|
// " \"rssi\": -87\n" +
|
|
|
|
|
// " }\n" +
|
|
|
|
|
// " }]}";
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
//}
|