NettyAlarmServiceImpl.java 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. package com.persagy.apm.diagnose.service;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.persagy.apm.diagnose.maintenance.constant.EnumAlarmCategory;
  4. import com.persagy.apm.diagnose.maintenance.constant.EnumAlarmItem;
  5. import com.persagy.apm.diagnose.utils.AlarmResultUtil;
  6. import com.persagy.apm.diagnose.utils.DmpResultUtil;
  7. import com.persagy.apm.energyalarmstarter.alarmdata.feign.AlarmUrlParam;
  8. import com.persagy.apm.energyalarmstarter.alarmdata.feign.DmpResult;
  9. import com.persagy.apm.energyalarmstarter.alarmdata.model.dto.alarmitem.QueryAlarmItemDTO;
  10. import com.persagy.apm.energyalarmstarter.alarmdata.model.vo.AlarmItem;
  11. import com.persagy.apm.energyalarmstarter.alarmdata.service.AlarmItemServiceImpl;
  12. import com.persagy.apm.energyalarmstarter.alarmengine.service.NettyAlarmService;
  13. import lombok.SneakyThrows;
  14. import org.assertj.core.util.Lists;
  15. import org.springframework.beans.factory.annotation.Autowired;
  16. import org.springframework.stereotype.Service;
  17. import org.springframework.util.CollectionUtils;
  18. import java.util.Arrays;
  19. import java.util.List;
  20. @Service
  21. public class NettyAlarmServiceImpl extends NettyAlarmService {
  22. @Autowired
  23. private CenterDataService centerDataService;
  24. @Autowired
  25. private AlarmItemServiceImpl alarmItemService;
  26. @Override
  27. public String getMeterId(String infoCode, String classCode) throws Exception {
  28. String separator = "_";
  29. if (!infoCode.contains(separator)) {
  30. throw new Exception("infoCode格式不正确,应包含'" + separator +
  31. "',classCode=" + classCode + "; infoCode=" + infoCode);
  32. }
  33. String[] tmp = infoCode.split(separator);
  34. return tmp[0];
  35. }
  36. @Override
  37. public String getFuncId(String infoCode, String classCode) throws Exception {
  38. String separator = "_";
  39. if (!infoCode.contains(separator)) {
  40. throw new Exception("infoCode格式不正确,应包含'" + separator +
  41. "',classCode=" + classCode + "; infoCode=" + infoCode);
  42. }
  43. int indexOf = infoCode.indexOf(separator);
  44. return infoCode.substring(indexOf + 1);
  45. }
  46. @Override
  47. public String getAlarmName(String projectId, String objId, String category) {
  48. return null;
  49. }
  50. @SneakyThrows
  51. @Override
  52. public JSONObject getAlarmSupplement(AlarmUrlParam alarmUrlParam, JSONObject alarmRecord) {
  53. // "supplement": {
  54. // "alarm_obj_name": "yy1中文名"
  55. // }
  56. String objId = alarmRecord.getString("objId");
  57. List<JSONObject> objectList = centerDataService.queryObjListByObjId(alarmRecord.getString("projectId"), Arrays.asList(objId));
  58. JSONObject supplement = new JSONObject();
  59. if (!CollectionUtils.isEmpty(objectList)) {
  60. supplement.put("alarm_obj_name", objectList.get(0).get("localName"));
  61. String itemCode = alarmRecord.getString("itemCode");
  62. String category = getAlarmCategory(alarmUrlParam, itemCode);
  63. if (EnumAlarmCategory.EQWB.equals(category)){//报警分类 //维保
  64. supplement.put("specification",objectList.get(0).getString("specification"));//设备型号
  65. supplement.put("equip_local_id",objectList.get(0).getString("localId"));//设备本地编码
  66. supplement.put("equip_local_name",objectList.get(0).getString("localName"));//设备本地名称
  67. }
  68. }
  69. return supplement;
  70. }
  71. @Override
  72. public String getAlarmRemark(AlarmUrlParam data, String objId, String itemCode) {
  73. //维保
  74. if (EnumAlarmItem.CondAbnormal.getCode().equals(itemCode)) {// 冷凝器异常
  75. return "检查冷凝器脏堵情况,并酌情进行清洗。";
  76. }else if (EnumAlarmItem.EvapAbnormal.getCode().equals(itemCode)){// 蒸发器异常
  77. return "检查蒸发器脏堵情况,并酌情进行清洗。";
  78. }else if (EnumAlarmItem.CoolTowerApproachTempAbnormal.getCode().equals(itemCode)){// 冷却塔逼近温度异常
  79. return "检查冷却水加药装置运行是否正常;检查冷却塔填料破损和脏堵情况,并酌情安排维护或清洗。";
  80. }
  81. return null;
  82. }
  83. @SneakyThrows
  84. @Override
  85. protected String getAlarmCategory(AlarmUrlParam urlParam, String itemCode) {
  86. QueryAlarmItemDTO queryAlarmItemDTO = new QueryAlarmItemDTO();
  87. queryAlarmItemDTO.setCode(Lists.newArrayList(itemCode));
  88. queryAlarmItemDTO.setGroupCode(urlParam.getGroupCode());
  89. queryAlarmItemDTO.setProjectId(urlParam.getProjectId());
  90. queryAlarmItemDTO.setUserId(urlParam.getUserId());
  91. DmpResult<List<AlarmItem>> queryResult = alarmItemService.query(queryAlarmItemDTO);
  92. List<AlarmItem> data = DmpResultUtil.getData(queryResult);
  93. if (CollectionUtils.isEmpty(data)) {
  94. return null;
  95. }
  96. return data.get(0).getCategory();
  97. }
  98. @SneakyThrows
  99. @Override
  100. protected String getObjClassCode(AlarmUrlParam urlParam, String objId) {
  101. List<JSONObject> objectList = centerDataService.queryObjListByObjId(urlParam.getProjectId(), Arrays.asList(objId));
  102. if (!CollectionUtils.isEmpty(objectList)) {
  103. return objectList.get(0).getString("classCode");//设备类型编码
  104. }
  105. return null;
  106. }
  107. }