123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- package com.persagy.apm.diagnose.service;
- import com.alibaba.fastjson.JSONObject;
- import com.persagy.apm.diagnose.maintenance.constant.EnumAlarmCategory;
- import com.persagy.apm.diagnose.maintenance.constant.EnumAlarmItem;
- import com.persagy.apm.diagnose.utils.AlarmResultUtil;
- import com.persagy.apm.diagnose.utils.DmpResultUtil;
- import com.persagy.apm.energyalarmstarter.alarmdata.feign.AlarmUrlParam;
- import com.persagy.apm.energyalarmstarter.alarmdata.feign.DmpResult;
- import com.persagy.apm.energyalarmstarter.alarmdata.model.dto.alarmitem.QueryAlarmItemDTO;
- import com.persagy.apm.energyalarmstarter.alarmdata.model.vo.AlarmItem;
- import com.persagy.apm.energyalarmstarter.alarmdata.service.AlarmItemServiceImpl;
- import com.persagy.apm.energyalarmstarter.alarmengine.service.NettyAlarmService;
- import lombok.SneakyThrows;
- import org.assertj.core.util.Lists;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import org.springframework.util.CollectionUtils;
- import java.util.Arrays;
- import java.util.List;
- @Service
- public class NettyAlarmServiceImpl extends NettyAlarmService {
- @Autowired
- private CenterDataService centerDataService;
- @Autowired
- private AlarmItemServiceImpl alarmItemService;
- @Override
- public String getMeterId(String infoCode, String classCode) throws Exception {
- String separator = "_";
- if (!infoCode.contains(separator)) {
- throw new Exception("infoCode格式不正确,应包含'" + separator +
- "',classCode=" + classCode + "; infoCode=" + infoCode);
- }
- String[] tmp = infoCode.split(separator);
- return tmp[0];
- }
- @Override
- public String getFuncId(String infoCode, String classCode) throws Exception {
- String separator = "_";
- if (!infoCode.contains(separator)) {
- throw new Exception("infoCode格式不正确,应包含'" + separator +
- "',classCode=" + classCode + "; infoCode=" + infoCode);
- }
- int indexOf = infoCode.indexOf(separator);
- return infoCode.substring(indexOf + 1);
- }
- @Override
- public String getAlarmName(String projectId, String objId, String category) {
- return null;
- }
- @SneakyThrows
- @Override
- public JSONObject getAlarmSupplement(AlarmUrlParam alarmUrlParam, JSONObject alarmRecord) {
- // "supplement": {
- // "alarm_obj_name": "yy1中文名"
- // }
- String objId = alarmRecord.getString("objId");
- List<JSONObject> objectList = centerDataService.queryObjListByObjId(alarmRecord.getString("projectId"), Arrays.asList(objId));
- JSONObject supplement = new JSONObject();
- if (!CollectionUtils.isEmpty(objectList)) {
- supplement.put("alarm_obj_name", objectList.get(0).get("localName"));
- String itemCode = alarmRecord.getString("itemCode");
- String category = getAlarmCategory(alarmUrlParam, itemCode);
- if (EnumAlarmCategory.EQWB.equals(category)){//报警分类 //维保
- supplement.put("specification",objectList.get(0).getString("specification"));//设备型号
- supplement.put("equip_local_id",objectList.get(0).getString("localId"));//设备本地编码
- supplement.put("equip_local_name",objectList.get(0).getString("localName"));//设备本地名称
- }
- }
- return supplement;
- }
- @Override
- public String getAlarmRemark(AlarmUrlParam data, String objId, String itemCode) {
- //维保
- if (EnumAlarmItem.CondAbnormal.getCode().equals(itemCode)) {// 冷凝器异常
- return "检查冷凝器脏堵情况,并酌情进行清洗。";
- }else if (EnumAlarmItem.EvapAbnormal.getCode().equals(itemCode)){// 蒸发器异常
- return "检查蒸发器脏堵情况,并酌情进行清洗。";
- }else if (EnumAlarmItem.CoolTowerApproachTempAbnormal.getCode().equals(itemCode)){// 冷却塔逼近温度异常
- return "检查冷却水加药装置运行是否正常;检查冷却塔填料破损和脏堵情况,并酌情安排维护或清洗。";
- }
- return null;
- }
- @SneakyThrows
- @Override
- protected String getAlarmCategory(AlarmUrlParam urlParam, String itemCode) {
- QueryAlarmItemDTO queryAlarmItemDTO = new QueryAlarmItemDTO();
- queryAlarmItemDTO.setCode(Lists.newArrayList(itemCode));
- queryAlarmItemDTO.setGroupCode(urlParam.getGroupCode());
- queryAlarmItemDTO.setProjectId(urlParam.getProjectId());
- queryAlarmItemDTO.setUserId(urlParam.getUserId());
- DmpResult<List<AlarmItem>> queryResult = alarmItemService.query(queryAlarmItemDTO);
- List<AlarmItem> data = DmpResultUtil.getData(queryResult);
- if (CollectionUtils.isEmpty(data)) {
- return null;
- }
- return data.get(0).getCategory();
- }
- @SneakyThrows
- @Override
- protected String getObjClassCode(AlarmUrlParam urlParam, String objId) {
- List<JSONObject> objectList = centerDataService.queryObjListByObjId(urlParam.getProjectId(), Arrays.asList(objId));
- if (!CollectionUtils.isEmpty(objectList)) {
- return objectList.get(0).getString("classCode");//设备类型编码
- }
- return null;
- }
- }
|