|
|
@@ -1,17 +1,35 @@
|
|
|
package com.yunfeiyun.agmp.iotm.web.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson2.JSONArray;
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
+import com.yunfeiyun.agmp.common.constant.ErrorCode;
|
|
|
+import com.yunfeiyun.agmp.common.exception.BizException;
|
|
|
+import com.yunfeiyun.agmp.common.utils.StringUtils;
|
|
|
+import com.yunfeiyun.agmp.iot.common.constant.devicetype.IotDeviceDictConst;
|
|
|
+import com.yunfeiyun.agmp.iot.common.domain.IotDevice;
|
|
|
+import com.yunfeiyun.agmp.iot.common.domain.IotDevicelasteddata;
|
|
|
+import com.yunfeiyun.agmp.iot.common.domain.IotWarndataitem;
|
|
|
import com.yunfeiyun.agmp.iot.common.domain.IotWarnindicator;
|
|
|
+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.mapper.IotWarndataitemMapper;
|
|
|
import com.yunfeiyun.agmp.iotm.web.mapper.IotWarnindicatorMapper;
|
|
|
import com.yunfeiyun.agmp.iotm.web.service.IIotWarnindicatorService;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 告警指标,存储所有与告警相关的指标信息Service业务层处理
|
|
|
- *
|
|
|
+ *
|
|
|
* @author 杨晓辉
|
|
|
* @date 2025-03-07
|
|
|
*/
|
|
|
@@ -19,70 +37,155 @@ import java.util.List;
|
|
|
public class IotWarnindicatorServiceImpl implements IIotWarnindicatorService {
|
|
|
@Autowired
|
|
|
private IotWarnindicatorMapper iotWarnindicatorMapper;
|
|
|
+ @Resource
|
|
|
+ private IotWarndataitemMapper iotWarndataitemMapper;
|
|
|
+ @Resource
|
|
|
+ private IotDeviceCommonService iotDeviceCommonService;
|
|
|
|
|
|
/**
|
|
|
* 查询告警指标,存储所有与告警相关的指标信息
|
|
|
- *
|
|
|
+ *
|
|
|
* @param wiBid 告警指标,存储所有与告警相关的指标信息主键
|
|
|
* @return 告警指标,存储所有与告警相关的指标信息
|
|
|
*/
|
|
|
@Override
|
|
|
- public IotWarnindicator selectIotWarnindicatorByWiBid(String wiBid, String tid){
|
|
|
+ public IotWarnindicator selectIotWarnindicatorByWiBid(String wiBid, String tid) {
|
|
|
return iotWarnindicatorMapper.selectIotWarnindicatorByWiBid(wiBid, tid);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查询告警指标,存储所有与告警相关的指标信息列表
|
|
|
- *
|
|
|
+ *
|
|
|
* @param iotWarnindicator 告警指标,存储所有与告警相关的指标信息
|
|
|
* @return 告警指标,存储所有与告警相关的指标信息
|
|
|
*/
|
|
|
@Override
|
|
|
- public List<IotWarnindicator> selectIotWarnindicatorList(IotWarnindicator iotWarnindicator){
|
|
|
+ public List<IotWarnindicator> selectIotWarnindicatorList(IotWarnindicator iotWarnindicator) {
|
|
|
return iotWarnindicatorMapper.selectIotWarnindicatorList(iotWarnindicator);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 新增告警指标,存储所有与告警相关的指标信息
|
|
|
- *
|
|
|
+ *
|
|
|
* @param iotWarnindicator 告警指标,存储所有与告警相关的指标信息
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public int insertIotWarnindicator(IotWarnindicator iotWarnindicator){
|
|
|
+ public int insertIotWarnindicator(IotWarnindicator iotWarnindicator) {
|
|
|
return iotWarnindicatorMapper.insertIotWarnindicator(iotWarnindicator);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 修改告警指标,存储所有与告警相关的指标信息
|
|
|
- *
|
|
|
+ *
|
|
|
* @param iotWarnindicator 告警指标,存储所有与告警相关的指标信息
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public int updateIotWarnindicator(IotWarnindicator iotWarnindicator){
|
|
|
+ public int updateIotWarnindicator(IotWarnindicator iotWarnindicator) {
|
|
|
return iotWarnindicatorMapper.updateIotWarnindicator(iotWarnindicator);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 批量删除告警指标,存储所有与告警相关的指标信息
|
|
|
- *
|
|
|
+ *
|
|
|
* @param wiBids 需要删除的告警指标,存储所有与告警相关的指标信息主键
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public int deleteIotWarnindicatorByWiBids(String[] wiBids, String tid){
|
|
|
+ public int deleteIotWarnindicatorByWiBids(String[] wiBids, String tid) {
|
|
|
return iotWarnindicatorMapper.deleteIotWarnindicatorByWiBids(wiBids, tid);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 删除告警指标,存储所有与告警相关的指标信息信息
|
|
|
- *
|
|
|
+ *
|
|
|
* @param wiBid 告警指标,存储所有与告警相关的指标信息主键
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public int deleteIotWarnindicatorByWiBid(String wiBid, String tid){
|
|
|
+ public int deleteIotWarnindicatorByWiBid(String wiBid, String tid) {
|
|
|
return iotWarnindicatorMapper.deleteIotWarnindicatorByWiBid(wiBid, tid);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<IotWarnindicator> query(IotDevice iotDevice) {
|
|
|
+ if (StringUtils.isEmpty(iotDevice.getDevtypeBid())) {
|
|
|
+ throw new BizException(ErrorCode.INVALID_PARAMETER.getCode(), "设备类型不能为空");
|
|
|
+ }
|
|
|
+ List<IotWarnindicator> result = new ArrayList<>();
|
|
|
+ // 暂时只支持针对设备的告警要素查询
|
|
|
+ if (StringUtils.isNotEmpty(iotDevice.getDevBid())) {
|
|
|
+ result = warnindicatorDevQuery(iotDevice);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ private List<IotWarnindicator> warnindicatorDevQuery(IotDevice iotDevice){
|
|
|
+ // 查询当前设备是否存在预设要素
|
|
|
+ Map<String,IotWarndataitem> warndataitemMap = queryDefaultFactorMap(iotDevice);
|
|
|
+ List<IotWarnindicator> result = new ArrayList<>();
|
|
|
+ if (isFactorDevice(iotDevice.getDevtypeBid())) {
|
|
|
+ IotDeviceDataListReqVo iotDeviceDataListReqVo = new IotDeviceDataListReqVo();
|
|
|
+ BeanUtils.copyProperties(iotDevice,iotDeviceDataListReqVo);
|
|
|
+ IotDeviceBaseFunReqVo iotDeviceBaseFunReqVo = new IotDeviceBaseFunReqVo();
|
|
|
+ iotDeviceBaseFunReqVo.setDevBid(iotDevice.getDevBid());
|
|
|
+ iotDeviceBaseFunReqVo.setMethodName("warnDataLatest");
|
|
|
+ iotDeviceBaseFunReqVo.setParam(iotDeviceDataListReqVo);
|
|
|
+ IotDevicelasteddata iotDevicelasteddata = iotDeviceCommonService.func(iotDeviceBaseFunReqVo);
|
|
|
+ JSONArray jsonArray = JSONArray.parseArray(iotDevicelasteddata.getDevldContent());
|
|
|
+ if (!jsonArray.isEmpty() && !warndataitemMap.isEmpty()) {
|
|
|
+ // 如果设备存在预设要素。则需要过滤非预设要素
|
|
|
+ for (int i = 0; i < jsonArray.size(); i++) {
|
|
|
+ JSONObject dataItem = jsonArray.getJSONObject(i);
|
|
|
+ IotWarndataitem iotWarndataitem = warndataitemMap.get(dataItem.getString("factorCode"));
|
|
|
+ if (null != iotWarndataitem) {
|
|
|
+ IotWarnindicator iotWarnindicator = new IotWarnindicator();
|
|
|
+ iotWarnindicator.setWiAddress(dataItem.getString("address"));
|
|
|
+ iotWarnindicator.setWiCode(dataItem.getString("factorCode"));
|
|
|
+ iotWarnindicator.setWiName(dataItem.getString("factorName"));
|
|
|
+ iotWarnindicator.setWiUnit(dataItem.getString("factorUnit"));
|
|
|
+ iotWarnindicator.setWdBid(iotWarndataitem.getWdBid());
|
|
|
+ result.add(iotWarnindicator);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 如果设备不存在预设要素。则直接返回设备上报的数据
|
|
|
+ for (int i = 0; i < jsonArray.size(); i++) {
|
|
|
+ JSONObject dataItem = jsonArray.getJSONObject(i);
|
|
|
+ IotWarnindicator iotWarnindicator = new IotWarnindicator();
|
|
|
+ iotWarnindicator.setWiAddress(dataItem.getString("address"));
|
|
|
+ iotWarnindicator.setWiCode(dataItem.getString("factorCode"));
|
|
|
+ iotWarnindicator.setWiName(dataItem.getString("factorName"));
|
|
|
+ iotWarnindicator.setWiUnit(dataItem.getString("factorUnit"));
|
|
|
+ result.add(iotWarnindicator);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<String,IotWarndataitem> queryDefaultFactorMap(IotDevice iotDevice){
|
|
|
+ // 查询设备是否存在预设要素
|
|
|
+ IotWarndataitem iotWarndataitemQuery = new IotWarndataitem();
|
|
|
+ iotWarndataitemQuery.setWdType("0");
|
|
|
+ iotWarndataitemQuery.setWdObjid(iotDevice.getDevBid());
|
|
|
+ List<IotWarndataitem> iotWarndataitemList = iotWarndataitemMapper.selectIotWarndataitemList(iotWarndataitemQuery);
|
|
|
+ if (iotWarndataitemList.isEmpty()) {
|
|
|
+ // 查询设备类型是否存在预设要素
|
|
|
+ iotWarndataitemQuery.setWdType("1");
|
|
|
+ iotWarndataitemQuery.setWdObjid(iotDevice.getDevtypeBid());
|
|
|
+ iotWarndataitemList = iotWarndataitemMapper.selectIotWarndataitemList(iotWarndataitemQuery);
|
|
|
+ }
|
|
|
+ return iotWarndataitemList.stream().collect(Collectors.toMap(IotWarndataitem::getWdCode, item -> item));
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean isFactorDevice(String devTypeBid) {
|
|
|
+ if(IotDeviceDictConst.TYPE_YF_QXZ.equals(devTypeBid)){
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ if(IotDeviceDictConst.TYPE_YF_SQZ.equals(devTypeBid)){
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|