AlarmRuleService.java 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. package com.gyee.alarm.service;
  2. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  3. import com.baomidou.mybatisplus.core.metadata.IPage;
  4. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  5. import com.gyee.alarm.mapper.auto.AlarmTsMapper;
  6. import com.gyee.alarm.mapper.auto.ProEconAlarmRuleMapper;
  7. import com.gyee.alarm.model.auto.ProEconAlarmRule;
  8. import com.gyee.alarm.model.auto.ProEconAlarmType;
  9. import com.gyee.alarm.model.auto.ProEconCurveFittingMain;
  10. import com.gyee.alarm.model.vo.AlarmRuleVo;
  11. import com.gyee.alarm.service.auto.IProEconAlarmTypeService;
  12. import com.gyee.alarm.util.SnowflakeGenerator;
  13. import com.gyee.alarm.util.StringUtil;
  14. import com.gyee.alarm.util.StringUtils;
  15. import org.springframework.stereotype.Service;
  16. import javax.annotation.Resource;
  17. import java.util.*;
  18. import java.util.stream.Collectors;
  19. @Service
  20. public class AlarmRuleService {
  21. @Resource
  22. private ProEconAlarmRuleMapper proEconAlarmRuleMapper;
  23. @Resource
  24. private IProEconAlarmTypeService proEconAlarmTypeService;
  25. private int saveAlertrule(ProEconAlarmRule alarmRule) throws Exception {
  26. int result = 0;
  27. if (StringUtils.notEmp(alarmRule)) {
  28. alarmRule.setCreateTime(new Date());
  29. alarmRule.setId(String.valueOf(SnowflakeGenerator.generateId()));
  30. result= proEconAlarmRuleMapper.insert(alarmRule);
  31. }
  32. // if (result > 0) {
  33. // int i = eventService.saveEventAlertRule(alarmRule, oldRule2, userData.getUserName());
  34. return result;
  35. }
  36. public int saveAndUpdateAlertrule(ProEconAlarmRule alarmRule) throws Exception {
  37. int result = 0;
  38. if (StringUtils.notEmp(alarmRule)) {
  39. if (StringUtils.notEmp(alarmRule.getId())) {
  40. ProEconAlarmRule oldRule2 = proEconAlarmRuleMapper.selectById(alarmRule.getId());
  41. if (oldRule2 != null) {
  42. result = proEconAlarmRuleMapper.updateByAlertruleId(alarmRule);
  43. }else
  44. {
  45. result = saveAlertrule(alarmRule);
  46. }
  47. }
  48. else
  49. {
  50. result = saveAlertrule(alarmRule);
  51. }
  52. }
  53. return result;
  54. }
  55. public int deleteAlertrule(ProEconAlarmRule alarmRule) {
  56. return proEconAlarmRuleMapper.deleteById(alarmRule.getId());
  57. }
  58. public IPage<ProEconAlarmRule> pageQueryAll(Page page, String name, String station, String modelId, String rank, String category, String enabled, String relatedparts) {
  59. IPage<ProEconAlarmRule> AlertruleIPage = proEconAlarmRuleMapper.pageQueryAll(page, name, station, modelId, rank, category, enabled, relatedparts);
  60. return AlertruleIPage;
  61. }
  62. public List<AlarmRuleVo> queryTree() {
  63. List<AlarmRuleVo> dsList = proEconAlarmRuleMapper.queryTree();
  64. return dsList;
  65. }
  66. //首页风机部件查询
  67. public Map<String, Integer> queryList(String station, String modelId) {
  68. Map<String, Integer> map2 = new HashMap<>();
  69. map2.put("CLX", 0);
  70. map2.put("YP", 0);
  71. map2.put("YY", 0);
  72. map2.put("BJXT", 0);
  73. map2.put("PHXT", 0);
  74. map2.put("BPXT", 0);
  75. map2.put("CFXT", 0);
  76. map2.put("ZZ", 0);
  77. map2.put("FDJ", 0);
  78. map2.put("QT", 0);
  79. List<ProEconAlarmRule> dslist = proEconAlarmRuleMapper.getAllByStationIdAndModelId(station, modelId);
  80. map2.put("SUM", dslist.size());
  81. for (ProEconAlarmRule ar : dslist) {
  82. int cnt = 0;
  83. switch (ar.getRelatedParts()) {
  84. case "CLX":
  85. cnt = map2.get("CLX").intValue();
  86. map2.put("CLX", ++cnt);
  87. break;
  88. case "YP":
  89. cnt = map2.get("YP").intValue();
  90. map2.put("YP", ++cnt);
  91. break;
  92. case "YY":
  93. cnt = map2.get("YY").intValue();
  94. map2.put("YY", ++cnt);
  95. break;
  96. case "BJXT":
  97. cnt = map2.get("BJXT").intValue();
  98. map2.put("BJXT", ++cnt);
  99. break;
  100. case "PHXT":
  101. cnt = map2.get("PHXT").intValue();
  102. map2.put("PHXT", ++cnt);
  103. break;
  104. case "BPXT":
  105. cnt = map2.get("BPXT").intValue();
  106. map2.put("BPXT", ++cnt);
  107. break;
  108. case "CFXT":
  109. cnt = map2.get("CFXT").intValue();
  110. map2.put("CFXT", ++cnt);
  111. break;
  112. case "ZZ":
  113. cnt = map2.get("ZZ").intValue();
  114. map2.put("ZZ", ++cnt);
  115. break;
  116. case "FDJ":
  117. cnt = map2.get("FDJ").intValue();
  118. map2.put("FDJ", ++cnt);
  119. break;
  120. default:
  121. cnt = map2.get("QT").intValue();
  122. map2.put("QT", ++cnt);
  123. break;
  124. }
  125. }
  126. return map2;
  127. }
  128. public List<String> getUniformCodeByNameAndStation(String name, String station, String modelid) {
  129. List<ProEconAlarmRule> rules = proEconAlarmRuleMapper.getUniformCodeByNameAndStation(name, station, modelid);
  130. if (rules == null || rules.size() == 0)
  131. return null;
  132. ProEconAlarmRule rule = rules.get(0);
  133. String expression = "(([A][I])|([D][I]))([0-9]+)";
  134. List<String> list = StringUtil.pattern(rule.getExpression(), expression);
  135. return list;
  136. }
  137. public ProEconAlarmRule selectByAlertruleId(String id) {
  138. return proEconAlarmRuleMapper.selectById(id);
  139. }
  140. }