|
@@ -1,23 +1,22 @@
|
|
|
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.JSONObject;
|
|
|
import com.yunfeiyun.agmp.common.constant.ErrorCode;
|
|
import com.yunfeiyun.agmp.common.constant.ErrorCode;
|
|
|
import com.yunfeiyun.agmp.common.exception.BizException;
|
|
import com.yunfeiyun.agmp.common.exception.BizException;
|
|
|
import com.yunfeiyun.agmp.common.utils.DateUtils;
|
|
import com.yunfeiyun.agmp.common.utils.DateUtils;
|
|
|
import com.yunfeiyun.agmp.common.utils.SecurityUtils;
|
|
import com.yunfeiyun.agmp.common.utils.SecurityUtils;
|
|
|
import com.yunfeiyun.agmp.common.utils.StringUtils;
|
|
import com.yunfeiyun.agmp.common.utils.StringUtils;
|
|
|
|
|
+import com.yunfeiyun.agmp.iot.common.constant.devicetype.IotDeviceDictConst;
|
|
|
import com.yunfeiyun.agmp.iot.common.constant.devicetype.IotDeviceDictEnum;
|
|
import com.yunfeiyun.agmp.iot.common.constant.devicetype.IotDeviceDictEnum;
|
|
|
-import com.yunfeiyun.agmp.iot.common.domain.IotWarnconfig;
|
|
|
|
|
-import com.yunfeiyun.agmp.iot.common.domain.IotWarnindicator;
|
|
|
|
|
-import com.yunfeiyun.agmp.iot.common.domain.IotWarnobject;
|
|
|
|
|
|
|
+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.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;
|
|
|
import com.yunfeiyun.agmp.iotm.web.domain.resvo.IotWarnconfigResVo;
|
|
import com.yunfeiyun.agmp.iotm.web.domain.resvo.IotWarnconfigResVo;
|
|
|
-import com.yunfeiyun.agmp.iotm.web.mapper.IotWarnconfigMapper;
|
|
|
|
|
-import com.yunfeiyun.agmp.iotm.web.mapper.IotWarnindicatorMapper;
|
|
|
|
|
-import com.yunfeiyun.agmp.iotm.web.mapper.IotWarnobjectMapper;
|
|
|
|
|
|
|
+import com.yunfeiyun.agmp.iotm.web.mapper.*;
|
|
|
import com.yunfeiyun.agmp.iotm.web.service.IIotWarnconfigService;
|
|
import com.yunfeiyun.agmp.iotm.web.service.IIotWarnconfigService;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
@@ -26,6 +25,8 @@ 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.util.Arrays;
|
|
|
import java.util.Collection;
|
|
import java.util.Collection;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
|
@@ -43,6 +44,11 @@ public class IotWarnconfigServiceImpl implements IIotWarnconfigService {
|
|
|
private IotWarnobjectMapper iotWarnobjectMapper;
|
|
private IotWarnobjectMapper iotWarnobjectMapper;
|
|
|
@Resource
|
|
@Resource
|
|
|
private IotWarnindicatorMapper iotWarnindicatorMapper;
|
|
private IotWarnindicatorMapper iotWarnindicatorMapper;
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private IotDeviceMapper iotDeviceMapper;
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private IotDeviceconfigMapper iotDeviceconfigMapper;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 查询告警配置
|
|
* 查询告警配置
|
|
|
*
|
|
*
|
|
@@ -132,7 +138,7 @@ public class IotWarnconfigServiceImpl implements IIotWarnconfigService {
|
|
|
iotWarnconfigAddReqVo.setWcCreator(SecurityUtils.getUserId());
|
|
iotWarnconfigAddReqVo.setWcCreator(SecurityUtils.getUserId());
|
|
|
|
|
|
|
|
// 获取告警对象
|
|
// 获取告警对象
|
|
|
- List<IotWarnobject> warnobjects = iotWarnconfigAddReqVo.getIotWarnobjects();
|
|
|
|
|
|
|
+ List<IotWarnobject> warnobjects = iotWarnconfigAddReqVo.getIotWarnobjectList();
|
|
|
for(IotWarnobject iotWarnobject : warnobjects){
|
|
for(IotWarnobject iotWarnobject : warnobjects){
|
|
|
iotWarnobject.setWoBid(iotWarnobject.getUUId());
|
|
iotWarnobject.setWoBid(iotWarnobject.getUUId());
|
|
|
iotWarnobject.setWcBid(iotWarnconfigAddReqVo.getWcBid());
|
|
iotWarnobject.setWcBid(iotWarnconfigAddReqVo.getWcBid());
|
|
@@ -141,7 +147,7 @@ public class IotWarnconfigServiceImpl implements IIotWarnconfigService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 获取告警规则
|
|
// 获取告警规则
|
|
|
- List<IotWarnindicator> iotWarnindicatorList = iotWarnconfigAddReqVo.getIotWarnindicator();
|
|
|
|
|
|
|
+ List<IotWarnindicator> iotWarnindicatorList = iotWarnconfigAddReqVo.getIotWarnindicatorList();
|
|
|
for(IotWarnindicator iotWarnindicator : iotWarnindicatorList){
|
|
for(IotWarnindicator iotWarnindicator : iotWarnindicatorList){
|
|
|
iotWarnindicator.setWiBid(iotWarnindicator.getUUId());
|
|
iotWarnindicator.setWiBid(iotWarnindicator.getUUId());
|
|
|
iotWarnindicator.setWcBid(iotWarnconfigAddReqVo.getWcBid());
|
|
iotWarnindicator.setWcBid(iotWarnconfigAddReqVo.getWcBid());
|
|
@@ -171,7 +177,9 @@ public class IotWarnconfigServiceImpl implements IIotWarnconfigService {
|
|
|
// 老数据中存在,新数据中不存在,代表被删除的数据
|
|
// 老数据中存在,新数据中不存在,代表被删除的数据
|
|
|
Collection<IotWarnobject> deleteData = CollectionUtils.subtract(oldWarnObjectList,differ);
|
|
Collection<IotWarnobject> deleteData = CollectionUtils.subtract(oldWarnObjectList,differ);
|
|
|
String[] woBids = deleteData.stream().map(IotWarnobject::getWoBid).toArray(String[]::new);
|
|
String[] woBids = deleteData.stream().map(IotWarnobject::getWoBid).toArray(String[]::new);
|
|
|
- iotWarnobjectMapper.deleteIotWarnobjectByWoBids(woBids, SecurityUtils.getTid());
|
|
|
|
|
|
|
+ if(woBids.length>0){
|
|
|
|
|
+ iotWarnobjectMapper.deleteIotWarnobjectByWoBids(woBids, SecurityUtils.getTid());
|
|
|
|
|
+ }
|
|
|
// 老数据中不存在,新数据中存在,代表新增的数据
|
|
// 老数据中不存在,新数据中存在,代表新增的数据
|
|
|
Collection<IotWarnobject> addData = CollectionUtils.subtract(iotWarnconfigEditReqVo.getIotWarnobjectList(),differ);
|
|
Collection<IotWarnobject> addData = CollectionUtils.subtract(iotWarnconfigEditReqVo.getIotWarnobjectList(),differ);
|
|
|
for(IotWarnobject addWarnObject : addData){
|
|
for(IotWarnobject addWarnObject : addData){
|
|
@@ -206,4 +214,96 @@ public class IotWarnconfigServiceImpl implements IIotWarnconfigService {
|
|
|
iotWarnconfigInfoResVo.setIotWarnobjectList(iotWarnobjectList);
|
|
iotWarnconfigInfoResVo.setIotWarnobjectList(iotWarnobjectList);
|
|
|
return iotWarnconfigInfoResVo;
|
|
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;
|
|
|
|
|
+ }
|
|
|
|
|
+ IotDevice first = iotDeviceList.get(0);
|
|
|
|
|
+ if(IotDeviceDictConst.TYPE_YF_QXZ.equals(first.getDevtypeBid())) {
|
|
|
|
|
+ return getDevConfigByMaxAttr(devBidList,"interval",Integer.class);
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public IotWarnconfig copy(String wcBid) {
|
|
|
|
|
+ // 查询告警规则
|
|
|
|
|
+ IotWarnconfig iotWarnconfig = iotWarnconfigMapper.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);
|
|
|
|
|
+ // 查询告警策略
|
|
|
|
|
+ IotWarnindicator iotWarnindicatorQuery = new IotWarnindicator();
|
|
|
|
|
+ iotWarnindicatorQuery.setTid(SecurityUtils.getTid());
|
|
|
|
|
+ iotWarnindicatorQuery.setWcBid(wcBid);
|
|
|
|
|
+ List<IotWarnindicator> iotWarnindicatorList = iotWarnindicatorMapper.selectIotWarnindicatorList(iotWarnindicatorQuery);
|
|
|
|
|
+ // 重新赋值
|
|
|
|
|
+ iotWarnconfig.setWcBid(iotWarnconfig.getUUId());
|
|
|
|
|
+ iotWarnconfig.setWcCreateddate(DateUtils.dateTimeNow());
|
|
|
|
|
+ iotWarnconfig.setWcCreator(SecurityUtils.getUserId());
|
|
|
|
|
+ iotWarnconfig.setWcModifieddate(null);
|
|
|
|
|
+ iotWarnconfig.setWcModifier(null);
|
|
|
|
|
+ for(IotWarnobject iotWarnobject : iotWarnobjectList){
|
|
|
|
|
+ iotWarnobject.setWcBid(iotWarnconfig.getWcBid());
|
|
|
|
|
+ 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);
|
|
|
|
|
+ }
|
|
|
|
|
+ iotWarnconfigMapper.insertIotWarnconfig(iotWarnconfig);
|
|
|
|
|
+ return iotWarnconfig;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public int editStatus(IotWarnconfig 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){
|
|
|
|
|
+ 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;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if (value != null ){
|
|
|
|
|
+ resultConfig = config;
|
|
|
|
|
+ result = iotDeviceconfig;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|