|
@@ -1,8 +1,10 @@
|
|
|
package com.yunfeiyun.agmp.iotm.web.service.impl;
|
|
package com.yunfeiyun.agmp.iotm.web.service.impl;
|
|
|
|
|
|
|
|
import com.alibaba.fastjson2.JSON;
|
|
import com.alibaba.fastjson2.JSON;
|
|
|
|
|
+import com.alibaba.fastjson2.JSONArray;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
import com.yunfeiyun.agmp.common.constant.ErrorCode;
|
|
import com.yunfeiyun.agmp.common.constant.ErrorCode;
|
|
|
|
|
+import com.yunfeiyun.agmp.common.core.page.TableDataInfo;
|
|
|
import com.yunfeiyun.agmp.common.enums.RedisCacheKey;
|
|
import com.yunfeiyun.agmp.common.enums.RedisCacheKey;
|
|
|
import com.yunfeiyun.agmp.common.exception.BizException;
|
|
import com.yunfeiyun.agmp.common.exception.BizException;
|
|
|
import com.yunfeiyun.agmp.common.framework.manager.RedisCacheManager;
|
|
import com.yunfeiyun.agmp.common.framework.manager.RedisCacheManager;
|
|
@@ -14,6 +16,10 @@ import com.yunfeiyun.agmp.iot.common.constant.devicetype.IotDeviceDictEnum;
|
|
|
import com.yunfeiyun.agmp.iot.common.domain.*;
|
|
import com.yunfeiyun.agmp.iot.common.domain.*;
|
|
|
import com.yunfeiyun.agmp.iot.common.enums.warn.IotWarnTouchTypeEnum;
|
|
import com.yunfeiyun.agmp.iot.common.enums.warn.IotWarnTouchTypeEnum;
|
|
|
import com.yunfeiyun.agmp.iot.common.enums.warn.IotWarnlevelEnum;
|
|
import com.yunfeiyun.agmp.iot.common.enums.warn.IotWarnlevelEnum;
|
|
|
|
|
+import com.yunfeiyun.agmp.iot.common.util.dev.QxzTypeUtil;
|
|
|
|
|
+import com.yunfeiyun.agmp.iotm.device.common.domin.IotDeviceBaseFunReqVo;
|
|
|
|
|
+import com.yunfeiyun.agmp.iotm.device.common.domin.IotDeviceDataListReqVo;
|
|
|
|
|
+import com.yunfeiyun.agmp.iotm.device.common.service.IotDeviceCommonService;
|
|
|
import com.yunfeiyun.agmp.iotm.web.domain.reqvo.IotWarnconfigAddReqVo;
|
|
import com.yunfeiyun.agmp.iotm.web.domain.reqvo.IotWarnconfigAddReqVo;
|
|
|
import com.yunfeiyun.agmp.iotm.web.domain.reqvo.IotWarnconfigEditReqVo;
|
|
import com.yunfeiyun.agmp.iotm.web.domain.reqvo.IotWarnconfigEditReqVo;
|
|
|
import com.yunfeiyun.agmp.iotm.web.domain.resvo.IotWarnconfigInfoResVo;
|
|
import com.yunfeiyun.agmp.iotm.web.domain.resvo.IotWarnconfigInfoResVo;
|
|
@@ -28,7 +34,7 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
-import java.math.BigDecimal;
|
|
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
@@ -57,6 +63,9 @@ public class IotWarnconfigServiceImpl implements IIotWarnconfigService {
|
|
|
@Resource
|
|
@Resource
|
|
|
private IIotWarnindicatorService iotWarnindicatorService;
|
|
private IIotWarnindicatorService iotWarnindicatorService;
|
|
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private IotDeviceCommonService iotDeviceCommonService;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 查询告警配置
|
|
* 查询告警配置
|
|
|
*
|
|
*
|
|
@@ -277,17 +286,26 @@ public class IotWarnconfigServiceImpl implements IIotWarnconfigService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public IotDeviceconfig devConfigInfo(String[] devBids) {
|
|
|
|
|
- List<String> devBidList = Arrays.asList(devBids);
|
|
|
|
|
- List<IotDevice> iotDeviceList = iotDeviceMapper.selectIotDeviceByDevBids(devBidList,SecurityUtils.getTid());
|
|
|
|
|
- if(iotDeviceList.isEmpty()){
|
|
|
|
|
- return null;
|
|
|
|
|
|
|
+ public JSONObject devInterval(String devBid) {
|
|
|
|
|
+ Integer interval = null;
|
|
|
|
|
+ Set<String> devtypeSet = new HashSet<>();
|
|
|
|
|
+ devtypeSet.add(IotDeviceDictConst.TYPE_DAHUA_YUNRUI_DEVICE);
|
|
|
|
|
+ devtypeSet.add(IotDeviceDictConst.TYPE_EZVIZ_JKSB);
|
|
|
|
|
+
|
|
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
|
|
+ jsonObject.put("interval", interval);
|
|
|
|
|
+
|
|
|
|
|
+ IotDevice iotDevice = iotDeviceMapper.selectIotDeviceByDevBid(devBid);
|
|
|
|
|
+ if(iotDevice == null || devtypeSet.contains(iotDevice.getDevtypeBid())){
|
|
|
|
|
+ return jsonObject;
|
|
|
}
|
|
}
|
|
|
- IotDevice first = iotDeviceList.get(0);
|
|
|
|
|
- if(IotDeviceDictConst.TYPE_YF_QXZ.equals(first.getDevtypeBid())) {
|
|
|
|
|
- return getDevConfigByMaxAttr(devBidList,"interval",Integer.class);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ interval = getReportIntervalByConfig(devBid);
|
|
|
|
|
+ if(interval == null){
|
|
|
|
|
+ interval = getReportIntervalByData(iotDevice);
|
|
|
}
|
|
}
|
|
|
- return null;
|
|
|
|
|
|
|
+ jsonObject.put("interval",interval);
|
|
|
|
|
+ return jsonObject;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -337,35 +355,75 @@ public class IotWarnconfigServiceImpl implements IIotWarnconfigService {
|
|
|
return iotWarnconfigMapper.updateIotWarnconfig(updateObject);
|
|
return iotWarnconfigMapper.updateIotWarnconfig(updateObject);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 根据最大值获取配置
|
|
|
|
|
- private IotDeviceconfig getDevConfigByMaxAttr(List<String> devBidList,String attr,Class attrType){
|
|
|
|
|
- List<IotDeviceconfig> iotDeviceconfigs = iotDeviceconfigMapper.selectIotDeviceConfigByDevBidList(devBidList);
|
|
|
|
|
- if(iotDeviceconfigs.isEmpty()){
|
|
|
|
|
- return null;
|
|
|
|
|
- }
|
|
|
|
|
- IotDeviceconfig result = null;
|
|
|
|
|
- JSONObject resultConfig = new JSONObject();
|
|
|
|
|
- for(IotDeviceconfig iotDeviceconfig : iotDeviceconfigs){
|
|
|
|
|
|
|
+ private Integer getQxZReportInterval(JSONArray dataList) {
|
|
|
|
|
+ Integer interval = null;
|
|
|
|
|
+ try{
|
|
|
|
|
+ JSONArray oneArray = dataList.getJSONArray(0);
|
|
|
|
|
+ JSONArray twoArray = dataList.getJSONArray(1);
|
|
|
|
|
+
|
|
|
|
|
+ String oneTime = oneArray.getJSONObject(0).getString("time");
|
|
|
|
|
+ String twoTime = twoArray.getJSONObject(0).getString("time");
|
|
|
|
|
+
|
|
|
|
|
+ Date oneDate = DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS, oneTime);
|
|
|
|
|
+ Date twoDate = DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS, twoTime);
|
|
|
|
|
+ interval = (int) (oneDate.getTime() - twoDate.getTime()) / 1000 / 60;
|
|
|
|
|
+ }catch (Exception e){}
|
|
|
|
|
+ return interval;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private Integer getReportIntervalByConfig(String devBid){
|
|
|
|
|
+ Integer interval = null;
|
|
|
|
|
+ String[] keys = {"interval"};
|
|
|
|
|
+ IotDeviceconfig iotDeviceconfig = iotDeviceconfigMapper.selectIotDeviceConfigByDevBid(devBid);
|
|
|
|
|
+ if (iotDeviceconfig != null) {
|
|
|
String configContext = iotDeviceconfig.getDevcfgContext();
|
|
String configContext = iotDeviceconfig.getDevcfgContext();
|
|
|
- if(JSON.isValidObject(configContext)){
|
|
|
|
|
- JSONObject config = JSONObject.parseObject(configContext);
|
|
|
|
|
- Object value = config.get(attr);
|
|
|
|
|
- Object resultConfigValue = resultConfig.get(attr);
|
|
|
|
|
- if(null != resultConfigValue&&null != value){
|
|
|
|
|
- // 数字类型的比较
|
|
|
|
|
- if(attrType.equals(Integer.class)){
|
|
|
|
|
- if(new BigDecimal(String.valueOf(value)).compareTo(new BigDecimal(String.valueOf(resultConfigValue))) >= 1){
|
|
|
|
|
- resultConfig = config;
|
|
|
|
|
- result = iotDeviceconfig;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (JSON.isValidObject(configContext)) {
|
|
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(configContext);
|
|
|
|
|
+ for(String key : keys){
|
|
|
|
|
+ if(jsonObject.containsKey(key)){
|
|
|
|
|
+ interval = jsonObject.getInteger(key);
|
|
|
|
|
+ break;
|
|
|
}
|
|
}
|
|
|
- } else if (value != null ){
|
|
|
|
|
- resultConfig = config;
|
|
|
|
|
- result = iotDeviceconfig;
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- return result;
|
|
|
|
|
|
|
+ return interval;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private Integer getReportIntervalByData(IotDevice iotDevice){
|
|
|
|
|
+ Integer interval = null;
|
|
|
|
|
+ // 获取今天23:59:59
|
|
|
|
|
+ LocalDateTime todayEnd = LocalDateTime.now().withHour(23).withMinute(59).withSecond(59);
|
|
|
|
|
+ Date todayEndDate = DateUtils.toDate(todayEnd);
|
|
|
|
|
+
|
|
|
|
|
+ // 获取30天前的0:00:00
|
|
|
|
|
+ LocalDateTime thirtyDaysAgo = LocalDateTime.now().withHour(0).withMinute(0).withSecond(0);
|
|
|
|
|
+ Date thirtyDaysAgoDate = DateUtils.toDate(thirtyDaysAgo);
|
|
|
|
|
+
|
|
|
|
|
+ String startTime = DateUtils.formatDate(thirtyDaysAgoDate, DateUtils.YYYY_MM_DD_HH_MM_SS);
|
|
|
|
|
+ String endTime = DateUtils.formatDate(todayEndDate, DateUtils.YYYY_MM_DD_HH_MM_SS);
|
|
|
|
|
+
|
|
|
|
|
+ IotDeviceDataListReqVo reqVo = new IotDeviceDataListReqVo();
|
|
|
|
|
+ reqVo.setDevBid(iotDevice.getDevBid());
|
|
|
|
|
+ reqVo.setStartTime(startTime);
|
|
|
|
|
+ reqVo.setEndTime(endTime);
|
|
|
|
|
+
|
|
|
|
|
+ IotDeviceBaseFunReqVo iotDeviceBaseFunReqVo = new IotDeviceBaseFunReqVo();
|
|
|
|
|
+ iotDeviceBaseFunReqVo.setDevBid(reqVo.getDevBid());
|
|
|
|
|
+ iotDeviceBaseFunReqVo.setMethodName("dataList");
|
|
|
|
|
+ iotDeviceBaseFunReqVo.setParam(reqVo);
|
|
|
|
|
+
|
|
|
|
|
+ TableDataInfo tableDataInfo = iotDeviceCommonService.func(iotDeviceBaseFunReqVo);
|
|
|
|
|
+ List result = tableDataInfo.getData();
|
|
|
|
|
+ if(result == null || result.size() < 2){
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ JSONArray dataList = JSONArray.from(result);
|
|
|
|
|
+ String devtypeBid = iotDevice.getDevtypeBid();
|
|
|
|
|
+ if(QxzTypeUtil.isYfCommQxz(devtypeBid)){
|
|
|
|
|
+ interval = getQxZReportInterval(dataList);
|
|
|
|
|
+ }
|
|
|
|
|
+ return interval;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|