|
|
@@ -1,8 +1,10 @@
|
|
|
package com.yunfeiyun.agmp.iotm.web.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson2.JSON;
|
|
|
+import com.alibaba.fastjson2.JSONArray;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
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.exception.BizException;
|
|
|
import com.yunfeiyun.agmp.common.framework.manager.RedisCacheManager;
|
|
|
@@ -14,13 +16,23 @@ import com.yunfeiyun.agmp.iot.common.constant.devicetype.IotDeviceDictEnum;
|
|
|
import com.yunfeiyun.agmp.iot.common.domain.*;
|
|
|
import com.yunfeiyun.agmp.iot.common.enums.warn.IotWarnTouchTypeEnum;
|
|
|
import com.yunfeiyun.agmp.iot.common.enums.warn.IotWarnlevelEnum;
|
|
|
+import com.yunfeiyun.agmp.iot.common.util.dev.DevTypeUtil;
|
|
|
+import com.yunfeiyun.agmp.iot.common.util.dev.QxElementTypeUtil;
|
|
|
+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.IotWarnconfigEditReqVo;
|
|
|
import com.yunfeiyun.agmp.iotm.web.domain.resvo.IotWarnconfigInfoResVo;
|
|
|
import com.yunfeiyun.agmp.iotm.web.domain.resvo.IotWarnconfigResVo;
|
|
|
-import com.yunfeiyun.agmp.iotm.web.mapper.*;
|
|
|
+import com.yunfeiyun.agmp.iotm.web.mapper.IotDeviceMapper;
|
|
|
+import com.yunfeiyun.agmp.iotm.web.mapper.IotDeviceconfigMapper;
|
|
|
+import com.yunfeiyun.agmp.iotm.web.mapper.IotWarnconfigMapper;
|
|
|
+import com.yunfeiyun.agmp.iotm.web.mapper.IotWarnobjectMapper;
|
|
|
import com.yunfeiyun.agmp.iotm.web.service.IIotWarnconfigService;
|
|
|
+import com.yunfeiyun.agmp.iotm.web.service.IIotWarncountService;
|
|
|
import com.yunfeiyun.agmp.iotm.web.service.IIotWarnindicatorService;
|
|
|
+import com.yunfeiyun.agmp.iotm.web.service.IIotWarnobjectService;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
@@ -28,13 +40,13 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.math.BigDecimal;
|
|
|
+import java.time.LocalDateTime;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 告警配置Service业务层处理
|
|
|
- *
|
|
|
+ *
|
|
|
* @author 杨晓辉
|
|
|
* @date 2025-03-07
|
|
|
*/
|
|
|
@@ -45,70 +57,79 @@ public class IotWarnconfigServiceImpl implements IIotWarnconfigService {
|
|
|
@Resource
|
|
|
private IotWarnobjectMapper iotWarnobjectMapper;
|
|
|
@Resource
|
|
|
- private IotWarnindicatorMapper iotWarnindicatorMapper;
|
|
|
- @Resource
|
|
|
private IotDeviceMapper iotDeviceMapper;
|
|
|
@Resource
|
|
|
private IotDeviceconfigMapper iotDeviceconfigMapper;
|
|
|
@Resource
|
|
|
private RedisCacheManager redisCacheManager;
|
|
|
- @Resource
|
|
|
- private IotWarncountMapper iotWarncountMapper;
|
|
|
+
|
|
|
@Resource
|
|
|
private IIotWarnindicatorService iotWarnindicatorService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private IotDeviceCommonService iotDeviceCommonService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IIotWarnobjectService iotWarnobjectService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IIotWarncountService iIotWarncountService;
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 查询告警配置
|
|
|
- *
|
|
|
+ *
|
|
|
* @param wcBid 告警配置主键
|
|
|
* @return 告警配置
|
|
|
*/
|
|
|
@Override
|
|
|
- public IotWarnconfig selectIotWarnconfigByWcBid(String wcBid, String tid){
|
|
|
+ public IotWarnconfig selectIotWarnconfigByWcBid(String wcBid, String tid) {
|
|
|
|
|
|
return iotWarnconfigMapper.selectIotWarnconfigByWcBid(wcBid, tid);
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 查询告警配置列表
|
|
|
- *
|
|
|
+ *
|
|
|
* @param iotWarnconfig 告警配置
|
|
|
* @return 告警配置
|
|
|
*/
|
|
|
@Override
|
|
|
- public List<IotWarnconfig> selectIotWarnconfigList(IotWarnconfig iotWarnconfig){
|
|
|
+ public List<IotWarnconfig> selectIotWarnconfigList(IotWarnconfig iotWarnconfig) {
|
|
|
return iotWarnconfigMapper.selectIotWarnconfigList(iotWarnconfig);
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 查询告警配置列表
|
|
|
- * */
|
|
|
+ */
|
|
|
@Override
|
|
|
public List<IotWarnconfigResVo> selectIotWarnconfigResVoList(IotWarnconfig iotWarnconfig) {
|
|
|
List<IotWarnconfigResVo> iotWarnconfigResVoList = iotWarnconfigMapper.selectIotWarnconfigResVoList(iotWarnconfig);
|
|
|
List<String> wcBids = new ArrayList<>();
|
|
|
- Map<String,IotWarnconfigResVo> map = new HashMap<>();
|
|
|
- for(IotWarnconfigResVo iotWarnconfigResVo : iotWarnconfigResVoList){
|
|
|
+ Map<String, IotWarnconfigResVo> map = new HashMap<>();
|
|
|
+ for (IotWarnconfigResVo iotWarnconfigResVo : iotWarnconfigResVoList) {
|
|
|
iotWarnconfigResVo.setDevtypeName(IotDeviceDictEnum.getNameByCode(iotWarnconfigResVo.getDevtypeBid()));
|
|
|
iotWarnconfigResVo.setWcTouchtypeName(IotWarnTouchTypeEnum.findByCode(iotWarnconfigResVo.getWcTouchtype()).getContent());
|
|
|
iotWarnconfigResVo.setWcLevelName(IotWarnlevelEnum.findByCode(iotWarnconfigResVo.getWcLevel()).getContent());
|
|
|
iotWarnconfigResVo.setIotDeviceList(new ArrayList<>());
|
|
|
iotWarnconfigResVo.setSysUserList(new ArrayList<>());
|
|
|
wcBids.add(iotWarnconfigResVo.getWcBid());
|
|
|
- map.put(iotWarnconfigResVo.getWcBid(),iotWarnconfigResVo);
|
|
|
+ map.put(iotWarnconfigResVo.getWcBid(), iotWarnconfigResVo);
|
|
|
}
|
|
|
- if(!wcBids.isEmpty()){
|
|
|
+ if (!wcBids.isEmpty()) {
|
|
|
// 填充设备信息
|
|
|
- List<IotWarnobject> iotWarnobjectList = iotWarnobjectMapper.selectIotWarnobjectListByWcBids(wcBids,SecurityUtils.getTid());
|
|
|
- Map<String,List<IotWarnobject>> iotWarnobjectMap = iotWarnobjectList.stream().collect(Collectors.groupingBy(IotWarnobject::getDevBid));
|
|
|
- if(!iotWarnobjectMap.isEmpty()){
|
|
|
- List<IotDevice> iotDeviceList = iotDeviceMapper.selectIotDeviceByDevBids(new ArrayList<>(iotWarnobjectMap.keySet()),SecurityUtils.getTid());
|
|
|
- for(IotDevice iotDevice : iotDeviceList){
|
|
|
+ List<IotWarnobject> iotWarnobjectList = iotWarnobjectMapper.selectIotWarnobjectListByWcBids(wcBids, SecurityUtils.getTid());
|
|
|
+ Map<String, List<IotWarnobject>> iotWarnobjectMap = iotWarnobjectList.stream().collect(Collectors.groupingBy(IotWarnobject::getDevBid));
|
|
|
+ if (!iotWarnobjectMap.isEmpty()) {
|
|
|
+ List<IotDevice> iotDeviceList = iotDeviceMapper.selectIotDeviceByDevBids(new ArrayList<>(iotWarnobjectMap.keySet()), SecurityUtils.getTid());
|
|
|
+ for (IotDevice iotDevice : iotDeviceList) {
|
|
|
List<IotWarnobject> devWarnObjectList = iotWarnobjectMap.get(iotDevice.getDevBid());
|
|
|
- if(null == devWarnObjectList){
|
|
|
+ if (null == devWarnObjectList) {
|
|
|
continue;
|
|
|
}
|
|
|
- for(IotWarnobject iotWarnobject : devWarnObjectList){
|
|
|
+ for (IotWarnobject iotWarnobject : devWarnObjectList) {
|
|
|
IotWarnconfigResVo iotWarnconfigResVo = map.get(iotWarnobject.getWcBid());
|
|
|
- if(null != iotWarnconfigResVo){
|
|
|
+ if (null != iotWarnconfigResVo) {
|
|
|
iotWarnconfigResVo.getIotDeviceList().add(iotDevice);
|
|
|
}
|
|
|
}
|
|
|
@@ -124,47 +145,100 @@ public class IotWarnconfigServiceImpl implements IIotWarnconfigService {
|
|
|
|
|
|
/**
|
|
|
* 新增告警配置
|
|
|
- *
|
|
|
+ *
|
|
|
* @param iotWarnconfig 告警配置
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public int insertIotWarnconfig(IotWarnconfig iotWarnconfig){
|
|
|
+ public int insertIotWarnconfig(IotWarnconfig iotWarnconfig) {
|
|
|
return iotWarnconfigMapper.insertIotWarnconfig(iotWarnconfig);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 修改告警配置
|
|
|
- *
|
|
|
+ *
|
|
|
* @param iotWarnconfig 告警配置
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public int updateIotWarnconfig(IotWarnconfig iotWarnconfig){
|
|
|
+ public int updateIotWarnconfig(IotWarnconfig iotWarnconfig) {
|
|
|
return iotWarnconfigMapper.updateIotWarnconfig(iotWarnconfig);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 批量删除告警配置
|
|
|
- *
|
|
|
+ *
|
|
|
* @param wcBids 需要删除的告警配置主键
|
|
|
* @return 结果
|
|
|
*/
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
- public int deleteIotWarnconfigWcBids(String[] wcBids, String tid){
|
|
|
- return iotWarnconfigMapper.deleteIotWarnconfigWcBids(wcBids, tid);
|
|
|
+ public int deleteIotWarnconfigWcBids(String[] wcBids, String tid) {
|
|
|
+ int status = iotWarnconfigMapper.deleteIotWarnconfigWcBids(wcBids, tid);
|
|
|
+ iIotWarncountService.deleteIotWarncountByWcBids(wcBids, tid);
|
|
|
+ iotWarnindicatorService.deleteIotWarnindicatorByWcBids(wcBids, tid);
|
|
|
+ iotWarnobjectService.deleteIotWarnobjectByWcBids(wcBids, tid);
|
|
|
+ return status;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 删除告警配置信息
|
|
|
- *
|
|
|
+ *
|
|
|
* @param wcBid 告警配置主键
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public int deleteIotWarnconfigByWcBid(String wcBid, String tid){
|
|
|
+ public int deleteIotWarnconfigByWcBid(String wcBid, String tid) {
|
|
|
return iotWarnconfigMapper.deleteIotWarnconfigByWcBid(wcBid, tid);
|
|
|
}
|
|
|
+
|
|
|
+ private void addWarnindicator(String wcBid, List<IotWarnindicator> iotWarnindicatorList) {
|
|
|
+ String createDate = DateUtils.dateTimeNow();
|
|
|
+ String wiCreator = SecurityUtils.getUserId();
|
|
|
+ String tid = SecurityUtils.getTid();
|
|
|
+ List<IotWarnindicator> insertList = new ArrayList<>();
|
|
|
+
|
|
|
+ for (IotWarnindicator item : iotWarnindicatorList) {
|
|
|
+ String wiBid = item.getUUId();
|
|
|
+
|
|
|
+ item.setWiBid(wiBid);
|
|
|
+ item.setWcBid(wcBid);
|
|
|
+ item.setTid(tid);
|
|
|
+ item.setWiCreator(wiCreator);
|
|
|
+ item.setWiCreateddate(createDate);
|
|
|
+ insertList.add(item);
|
|
|
+
|
|
|
+ List<IotWarnindicator> childrenList = item.getChildrenList();
|
|
|
+ if (childrenList != null && !childrenList.isEmpty()) {
|
|
|
+ Set<String> wiCodeSet = new HashSet<>();
|
|
|
+ for (IotWarnindicator iotWarnindicator : childrenList) {
|
|
|
+ String wiCode = iotWarnindicator.getWiCode();
|
|
|
+ if (StringUtils.isEmpty(wiCode)) {
|
|
|
+ throw new BizException(ErrorCode.INVALID_PARAMETER.getCode(), "告警要素不能为空");
|
|
|
+ }
|
|
|
+ if (wiCodeSet.contains(wiCode)) {
|
|
|
+ throw new BizException(ErrorCode.INVALID_PARAMETER.getCode(), "告警要素不能重复");
|
|
|
+ }
|
|
|
+
|
|
|
+ iotWarnindicator.setWiBid(iotWarnindicator.getUUId());
|
|
|
+ iotWarnindicator.setWcBid(wcBid);
|
|
|
+ iotWarnindicator.setTid(tid);
|
|
|
+ iotWarnindicator.setWiCreator(wiCreator);
|
|
|
+ iotWarnindicator.setWiCreateddate(createDate);
|
|
|
+ iotWarnindicator.setWiOptiontype("0");
|
|
|
+ iotWarnindicator.setWiStatus("0");
|
|
|
+ iotWarnindicator.setWiParentbid(wiBid);
|
|
|
+
|
|
|
+ insertList.add(iotWarnindicator);
|
|
|
+ wiCodeSet.add(wiCode);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!insertList.isEmpty()) {
|
|
|
+ iotWarnindicatorService.insertIotWarnindicatorBatch(insertList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
public int add(IotWarnconfigAddReqVo iotWarnconfigAddReqVo) {
|
|
|
@@ -176,7 +250,7 @@ public class IotWarnconfigServiceImpl implements IIotWarnconfigService {
|
|
|
|
|
|
// 获取告警对象
|
|
|
List<IotWarnobject> warnobjects = iotWarnconfigAddReqVo.getIotWarnobjectList();
|
|
|
- for(IotWarnobject iotWarnobject : warnobjects){
|
|
|
+ for (IotWarnobject iotWarnobject : warnobjects) {
|
|
|
iotWarnobject.setWoBid(iotWarnobject.getUUId());
|
|
|
iotWarnobject.setWcBid(iotWarnconfigAddReqVo.getWcBid());
|
|
|
iotWarnobject.setTid(SecurityUtils.getTid());
|
|
|
@@ -185,22 +259,17 @@ public class IotWarnconfigServiceImpl implements IIotWarnconfigService {
|
|
|
|
|
|
// 获取告警规则
|
|
|
List<IotWarnindicator> iotWarnindicatorList = iotWarnconfigAddReqVo.getIotWarnindicatorList();
|
|
|
- for(IotWarnindicator iotWarnindicator : iotWarnindicatorList){
|
|
|
- iotWarnindicator.setWiBid(iotWarnindicator.getUUId());
|
|
|
- iotWarnindicator.setWcBid(iotWarnconfigAddReqVo.getWcBid());
|
|
|
- iotWarnindicator.setTid(SecurityUtils.getTid());
|
|
|
- iotWarnindicator.setWiCreator(SecurityUtils.getTid());
|
|
|
- iotWarnindicator.setWiCreateddate(DateUtils.dateTimeNow());
|
|
|
- iotWarnindicatorMapper.insertIotWarnindicator(iotWarnindicator);
|
|
|
- }
|
|
|
+
|
|
|
+ addWarnindicator(iotWarnconfigAddReqVo.getWcBid(), iotWarnindicatorList);
|
|
|
return iotWarnconfigMapper.insertIotWarnconfig(iotWarnconfigAddReqVo);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
public int edit(IotWarnconfigEditReqVo iotWarnconfigEditReqVo) {
|
|
|
- if(StringUtils.isEmpty(iotWarnconfigEditReqVo.getWcBid())){
|
|
|
- throw new BizException(ErrorCode.INVALID_PARAMETER.getCode(),"告警规则标识不能为空");
|
|
|
+ if (StringUtils.isEmpty(iotWarnconfigEditReqVo.getWcBid())) {
|
|
|
+ throw new BizException(ErrorCode.INVALID_PARAMETER.getCode(), "告警规则标识不能为空");
|
|
|
}
|
|
|
// 告警对象全量编辑
|
|
|
// 获取告警对象
|
|
|
@@ -208,126 +277,188 @@ public class IotWarnconfigServiceImpl implements IIotWarnconfigService {
|
|
|
iotWarnobjectQuery.setTid(SecurityUtils.getTid());
|
|
|
iotWarnobjectQuery.setWcBid(iotWarnconfigEditReqVo.getWcBid());
|
|
|
// 获取配置的旧的告警对象
|
|
|
- List<IotWarnobject> oldWarnObjectList = iotWarnobjectMapper.selectIotWarnobjectList(iotWarnobjectQuery);
|
|
|
+ List<IotWarnobject> oldWarnObjectList = iotWarnobjectService.selectIotWarnobjectList(iotWarnobjectQuery);
|
|
|
// 对比两个集合,获取不同的内容
|
|
|
- Collection<IotWarnobject> differ = CollectionUtils.disjunction(oldWarnObjectList,iotWarnconfigEditReqVo.getIotWarnobjectList());
|
|
|
+ Collection<IotWarnobject> differ = CollectionUtils.disjunction(oldWarnObjectList, iotWarnconfigEditReqVo.getIotWarnobjectList());
|
|
|
// 老数据中存在,新数据中不存在,代表被删除的数据,即旧数据与differ的交集
|
|
|
- Collection<IotWarnobject> deleteData = CollectionUtils.intersection(oldWarnObjectList,differ);
|
|
|
- for(IotWarnobject iotWarnobject :deleteData){
|
|
|
- iotWarnobjectMapper.deleteIotWarnobjectByWoBid(iotWarnobject.getWoBid(), SecurityUtils.getTid());
|
|
|
- iotWarncountMapper.deleteIotWarncountByDevBidAndWcBid(iotWarnobject.getDevBid(),iotWarnobject.getWcBid(),SecurityUtils.getTid());
|
|
|
+ Collection<IotWarnobject> deleteData = CollectionUtils.intersection(oldWarnObjectList, differ);
|
|
|
+ for (IotWarnobject iotWarnobject : deleteData) {
|
|
|
+ iotWarnobjectService.deleteIotWarnobjectByWoBid(iotWarnobject.getWoBid(), SecurityUtils.getTid());
|
|
|
+ iIotWarncountService.deleteIotWarncountByDevBidAndWcBid(iotWarnobject.getDevBid(), iotWarnobject.getWcBid(), SecurityUtils.getTid());
|
|
|
// 清除告警对象的缓存
|
|
|
redisCacheManager.deleteObject(RedisCacheKey.IOT_WARN_RE_COUNTS, iotWarnconfigEditReqVo.getWcBid() + ":" + iotWarnobject.getDevBid());
|
|
|
}
|
|
|
// 老数据中不存在,新数据中存在,代表新增的数据,即入参与differ的交集
|
|
|
- Collection<IotWarnobject> addData = CollectionUtils.intersection(iotWarnconfigEditReqVo.getIotWarnobjectList(),differ);
|
|
|
- for(IotWarnobject addWarnObject : addData){
|
|
|
+ Collection<IotWarnobject> addData = CollectionUtils.intersection(iotWarnconfigEditReqVo.getIotWarnobjectList(), differ);
|
|
|
+ for (IotWarnobject addWarnObject : addData) {
|
|
|
addWarnObject.setTid(SecurityUtils.getTid());
|
|
|
addWarnObject.setWcBid(iotWarnconfigEditReqVo.getWcBid());
|
|
|
addWarnObject.setWoBid(addWarnObject.getUUId());
|
|
|
iotWarnobjectMapper.insertIotWarnobject(addWarnObject);
|
|
|
}
|
|
|
+
|
|
|
// 考虑编辑设备的情况下,对应的规则可能出现调整的情况,
|
|
|
- iotWarnindicatorMapper.deleteIotWarnindicatorByWcBid(iotWarnconfigEditReqVo.getWcBid(),SecurityUtils.getTid());
|
|
|
- for(IotWarnindicator iotWarnindicator : iotWarnconfigEditReqVo.getIotWarnindicatorList()){
|
|
|
- iotWarnindicator.setWiBid(iotWarnindicator.getUUId());
|
|
|
- iotWarnindicator.setWcBid(iotWarnconfigEditReqVo.getWcBid());
|
|
|
- iotWarnindicator.setTid(SecurityUtils.getTid());
|
|
|
- iotWarnindicator.setWiCreator(SecurityUtils.getTid());
|
|
|
- iotWarnindicator.setWiCreateddate(DateUtils.dateTimeNow());
|
|
|
- iotWarnindicatorMapper.insertIotWarnindicator(iotWarnindicator);
|
|
|
- }
|
|
|
+ iotWarnindicatorService.deleteIotWarnindicatorByWcBid(iotWarnconfigEditReqVo.getWcBid(), SecurityUtils.getTid());
|
|
|
+
|
|
|
+ List<IotWarnindicator> iotWarnindicatorList = iotWarnconfigEditReqVo.getIotWarnindicatorList();
|
|
|
+ addWarnindicator(iotWarnconfigEditReqVo.getWcBid(), iotWarnindicatorList);
|
|
|
return iotWarnconfigMapper.updateIotWarnconfig(iotWarnconfigEditReqVo);
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public IotWarnconfigInfoResVo info(String wcBid, String tid) {
|
|
|
- IotWarnconfig iotWarnconfig = iotWarnconfigMapper.selectIotWarnconfigByWcBid(wcBid,SecurityUtils.getTid());
|
|
|
- if(null == iotWarnconfig){
|
|
|
- return null;
|
|
|
- }
|
|
|
- IotWarnobject iotWarnobjectQuery = new IotWarnobject();
|
|
|
- iotWarnobjectQuery.setWcBid(wcBid);
|
|
|
- iotWarnobjectQuery.setTid(SecurityUtils.getTid());
|
|
|
- List<IotWarnobject> iotWarnobjectList = iotWarnobjectMapper.selectIotWarnobjectList(iotWarnobjectQuery);
|
|
|
+ private void setInfoByQxz(IotWarnconfig iotWarnconfig, List<IotWarnobject> iotWarnobjectList, List<IotWarnindicator> resultIotWarnIndicatorList) {
|
|
|
+ String wcBid = iotWarnconfig.getWcBid();
|
|
|
+ String tid = SecurityUtils.getTid();
|
|
|
+
|
|
|
IotWarnindicator iotWarnindicatorQuery = new IotWarnindicator();
|
|
|
iotWarnindicatorQuery.setWcBid(wcBid);
|
|
|
- iotWarnindicatorQuery.setTid(SecurityUtils.getTid());
|
|
|
+ iotWarnindicatorQuery.setTid(tid);
|
|
|
// 获取已经配置的设备要素
|
|
|
- List<IotWarnindicator> iotWarnindicatorList = iotWarnindicatorMapper.selectIotWarnindicatorList(iotWarnindicatorQuery);
|
|
|
+ List<IotWarnindicator> iotWarnindicatorList = iotWarnindicatorService.selectIotWarnindicatorList(iotWarnindicatorQuery);
|
|
|
Set<String> wiCodeSet = new HashSet<>();
|
|
|
- if(iotWarnobjectList.size() ==1){
|
|
|
+ if (iotWarnobjectList.size() == 1) {
|
|
|
IotDevice deviceQuery = new IotDevice();
|
|
|
deviceQuery.setDevBid(iotWarnobjectList.get(0).getDevBid());
|
|
|
deviceQuery.setDevtypeBid(iotWarnconfig.getDevtypeBid());
|
|
|
- List<IotWarnindicator> devNowWarnIndicator = iotWarnindicatorService.warnindicatorDevQuery(deviceQuery);
|
|
|
+ List<IotWarnindicator> devNowWarnIndicator = iotWarnindicatorService.warnindicatorDevQueryByQxSq(deviceQuery);
|
|
|
wiCodeSet.addAll(devNowWarnIndicator.stream().map(IotWarnindicator::getWiCode).collect(Collectors.toList()));
|
|
|
}
|
|
|
- List<IotWarnindicator> resultIotWarnIndicatorList = new ArrayList<>();
|
|
|
- for(IotWarnindicator iotWarnindicator : iotWarnindicatorList){
|
|
|
- if(wiCodeSet.contains(iotWarnindicator.getWiCode())){
|
|
|
+
|
|
|
+ for (IotWarnindicator iotWarnindicator : iotWarnindicatorList) {
|
|
|
+ String wiCode = iotWarnindicator.getWiCode();
|
|
|
+ if (wiCodeSet.contains(wiCode)) {
|
|
|
+ String typeName = QxElementTypeUtil.getTypeName(wiCode);
|
|
|
+ iotWarnindicator.setTypeName(typeName);
|
|
|
resultIotWarnIndicatorList.add(iotWarnindicator);
|
|
|
}
|
|
|
}
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setInfoByCbd(IotWarnconfig iotWarnconfig, List<IotWarnobject> iotWarnobjectList, List<IotWarnindicator> resultIotWarnIndicatorList) {
|
|
|
+ String wcBid = iotWarnconfig.getWcBid();
|
|
|
+ String tid = SecurityUtils.getTid();
|
|
|
+
|
|
|
+ IotWarnindicator iotWarnindicatorQuery = new IotWarnindicator();
|
|
|
+ iotWarnindicatorQuery.setWcBid(wcBid);
|
|
|
+ iotWarnindicatorQuery.setTid(tid);
|
|
|
+ // 获取已经配置的设备要素
|
|
|
+ List<IotWarnindicator> iotWarnindicatorList = iotWarnindicatorService.selectIotWarnindicatorList(iotWarnindicatorQuery);
|
|
|
+ Map<String, IotWarnindicator> iotWarnindicatorMap = new LinkedHashMap<>();
|
|
|
+ for (IotWarnindicator iotWarnindicator : iotWarnindicatorList) {
|
|
|
+ String wiBid = iotWarnindicator.getWiBid();
|
|
|
+ String wiParentbid = iotWarnindicator.getWiParentbid();
|
|
|
+ if (iotWarnindicatorMap.containsKey(wiParentbid)) {
|
|
|
+ List<IotWarnindicator> childrenList = iotWarnindicatorMap.get(wiParentbid).getChildrenList();
|
|
|
+ if (childrenList == null) {
|
|
|
+ childrenList = new ArrayList<>();
|
|
|
+ }
|
|
|
+ childrenList.add(iotWarnindicator);
|
|
|
+ iotWarnindicatorMap.get(wiParentbid).setChildrenList(childrenList);
|
|
|
+ } else {
|
|
|
+ iotWarnindicatorMap.put(wiBid, iotWarnindicator);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ resultIotWarnIndicatorList.addAll(iotWarnindicatorMap.values());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public IotWarnconfigInfoResVo info(String wcBid) {
|
|
|
+ String tid = SecurityUtils.getTid();
|
|
|
+ IotWarnconfig iotWarnconfig = selectIotWarnconfigByWcBid(wcBid, tid);
|
|
|
+ if (null == iotWarnconfig) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ IotWarnobject iotWarnobjectQuery = new IotWarnobject();
|
|
|
+ iotWarnobjectQuery.setWcBid(wcBid);
|
|
|
+ iotWarnobjectQuery.setTid(tid);
|
|
|
+ List<IotWarnobject> iotWarnobjectList = iotWarnobjectService.selectIotWarnobjectList(iotWarnobjectQuery);
|
|
|
+
|
|
|
+ List<IotWarnindicator> resultIotWarnIndicatorList = new ArrayList<>();
|
|
|
+
|
|
|
IotWarnconfigInfoResVo iotWarnconfigInfoResVo = new IotWarnconfigInfoResVo();
|
|
|
- BeanUtils.copyProperties(iotWarnconfig,iotWarnconfigInfoResVo);
|
|
|
+ BeanUtils.copyProperties(iotWarnconfig, iotWarnconfigInfoResVo);
|
|
|
+ iotWarnconfigInfoResVo.setIotWarnindicatorList(resultIotWarnIndicatorList);
|
|
|
+ iotWarnconfigInfoResVo.setIotWarnobjectList(iotWarnobjectList);
|
|
|
+
|
|
|
+ String devtypeBid = iotWarnconfig.getDevtypeBid();
|
|
|
+ if (!StringUtils.isEmpty(devtypeBid)) {
|
|
|
+ if (DevTypeUtil.isQxSq(devtypeBid)) {
|
|
|
+ setInfoByQxz(iotWarnconfig, iotWarnobjectList, resultIotWarnIndicatorList);
|
|
|
+ } else if (DevTypeUtil.isYfCbd(devtypeBid)) {
|
|
|
+ setInfoByCbd(iotWarnconfig, iotWarnobjectList, resultIotWarnIndicatorList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ BeanUtils.copyProperties(iotWarnconfig, iotWarnconfigInfoResVo);
|
|
|
iotWarnconfigInfoResVo.setIotWarnindicatorList(resultIotWarnIndicatorList);
|
|
|
iotWarnconfigInfoResVo.setIotWarnobjectList(iotWarnobjectList);
|
|
|
return iotWarnconfigInfoResVo;
|
|
|
}
|
|
|
|
|
|
@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
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public IotWarnconfig copy(String wcBid) {
|
|
|
// 查询告警规则
|
|
|
- IotWarnconfig iotWarnconfig = iotWarnconfigMapper.selectIotWarnconfigByWcBid(wcBid,SecurityUtils.getTid());
|
|
|
- if(null == iotWarnconfig){
|
|
|
- throw new BizException(ErrorCode.INVALID_PARAMETER.getCode(),"告警规则不存在");
|
|
|
+ IotWarnconfig iotWarnconfig = selectIotWarnconfigByWcBid(wcBid, SecurityUtils.getTid());
|
|
|
+ if (null == iotWarnconfig) {
|
|
|
+ throw new BizException(ErrorCode.INVALID_PARAMETER.getCode(), "告警规则不存在");
|
|
|
}
|
|
|
+
|
|
|
// 查询告警对象
|
|
|
IotWarnobject iotWarnobjectQuery = new IotWarnobject();
|
|
|
iotWarnobjectQuery.setTid(SecurityUtils.getTid());
|
|
|
iotWarnobjectQuery.setWcBid(wcBid);
|
|
|
- List<IotWarnobject> iotWarnobjectList = iotWarnobjectMapper.selectIotWarnobjectList(iotWarnobjectQuery);
|
|
|
+ List<IotWarnobject> iotWarnobjectList = iotWarnobjectService.selectIotWarnobjectList(iotWarnobjectQuery);
|
|
|
+
|
|
|
// 查询告警策略
|
|
|
- IotWarnindicator iotWarnindicatorQuery = new IotWarnindicator();
|
|
|
- iotWarnindicatorQuery.setTid(SecurityUtils.getTid());
|
|
|
- iotWarnindicatorQuery.setWcBid(wcBid);
|
|
|
- List<IotWarnindicator> iotWarnindicatorList = iotWarnindicatorMapper.selectIotWarnindicatorList(iotWarnindicatorQuery);
|
|
|
- // 重新赋值
|
|
|
- iotWarnconfig.setWcBid(iotWarnconfig.getUUId());
|
|
|
+ String devtypeBid = iotWarnconfig.getDevtypeBid();
|
|
|
+ List<IotWarnindicator> iotWarnindicatorList = new ArrayList<>();
|
|
|
+ if (DevTypeUtil.isQxSq(devtypeBid)) {
|
|
|
+ setInfoByQxz(iotWarnconfig, iotWarnobjectList, iotWarnindicatorList);
|
|
|
+ } else if (DevTypeUtil.isYfCbd(devtypeBid)) {
|
|
|
+ setInfoByCbd(iotWarnconfig, iotWarnobjectList, iotWarnindicatorList);
|
|
|
+ }
|
|
|
+
|
|
|
+ String newWcBid = iotWarnconfig.getUUId();
|
|
|
+
|
|
|
+ iotWarnconfig.setWcBid(newWcBid);
|
|
|
iotWarnconfig.setWcCreateddate(DateUtils.dateTimeNow());
|
|
|
iotWarnconfig.setWcCreator(SecurityUtils.getUserId());
|
|
|
iotWarnconfig.setWcModifieddate(null);
|
|
|
iotWarnconfig.setWcModifier(null);
|
|
|
- for(IotWarnobject iotWarnobject : iotWarnobjectList){
|
|
|
- iotWarnobject.setWcBid(iotWarnconfig.getWcBid());
|
|
|
+ for (IotWarnobject iotWarnobject : iotWarnobjectList) {
|
|
|
+ iotWarnobject.setWcBid(newWcBid);
|
|
|
iotWarnobject.setWoBid(iotWarnobject.getUUId());
|
|
|
iotWarnobjectMapper.insertIotWarnobject(iotWarnobject);
|
|
|
}
|
|
|
- for(IotWarnindicator iotWarnindicator : iotWarnindicatorList){
|
|
|
- iotWarnindicator.setWcBid(iotWarnconfig.getWcBid());
|
|
|
- iotWarnindicator.setWdBid(iotWarnindicator.getUUId());
|
|
|
- iotWarnindicator.setWiCreateddate(DateUtils.dateTimeNow());
|
|
|
- iotWarnindicator.setWiCreator(SecurityUtils.getUserId());
|
|
|
- iotWarnindicator.setWiModifieddate(null);
|
|
|
- iotWarnindicator.setWiModifier(null);
|
|
|
- iotWarnindicatorMapper.insertIotWarnindicator(iotWarnindicator);
|
|
|
- }
|
|
|
+
|
|
|
+ // 重新赋值
|
|
|
+ addWarnindicator(newWcBid, iotWarnindicatorList);
|
|
|
+
|
|
|
iotWarnconfigMapper.insertIotWarnconfig(iotWarnconfig);
|
|
|
return iotWarnconfig;
|
|
|
}
|
|
|
@@ -337,35 +468,78 @@ public class IotWarnconfigServiceImpl implements IIotWarnconfigService {
|
|
|
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;
|
|
|
+ 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) {
|
|
|
}
|
|
|
- IotDeviceconfig result = null;
|
|
|
- JSONObject resultConfig = new JSONObject();
|
|
|
- for(IotDeviceconfig iotDeviceconfig : iotDeviceconfigs){
|
|
|
+ return interval;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Integer getReportIntervalByConfig(String devBid) {
|
|
|
+ Integer interval = null;
|
|
|
+ String[] keys = {
|
|
|
+ "interval", "datt", "dat_f"
|
|
|
+ };
|
|
|
+ IotDeviceconfig iotDeviceconfig = iotDeviceconfigMapper.selectIotDeviceConfigByDevBid(devBid);
|
|
|
+ if (iotDeviceconfig != null) {
|
|
|
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 (DevTypeUtil.isQxSq(devtypeBid)) {
|
|
|
+ interval = getQxZReportInterval(dataList);
|
|
|
+ }
|
|
|
+ return interval;
|
|
|
}
|
|
|
|
|
|
}
|