AlarmRuleService.java 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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.init.CacheContext;
  6. import com.gyee.alarm.mapper.auto.AlarmTsMapper;
  7. import com.gyee.alarm.mapper.auto.ProEconAlarmRuleMapper;
  8. import com.gyee.alarm.model.auto.ProBasicPowerstation;
  9. import com.gyee.alarm.model.auto.ProEconAlarmRule;
  10. import com.gyee.alarm.model.auto.ProEconAlarmType;
  11. import com.gyee.alarm.model.auto.ProEconCurveFittingMain;
  12. import com.gyee.alarm.model.vo.AlarmRuleVo;
  13. import com.gyee.alarm.service.auto.IProEconAlarmTypeService;
  14. import com.gyee.alarm.util.SnowflakeGenerator;
  15. import com.gyee.alarm.util.StringUtil;
  16. import com.gyee.alarm.util.StringUtils;
  17. import org.springframework.stereotype.Service;
  18. import javax.annotation.Resource;
  19. import java.util.*;
  20. import java.util.stream.Collectors;
  21. @Service
  22. public class AlarmRuleService {
  23. @Resource
  24. private ProEconAlarmRuleMapper proEconAlarmRuleMapper;
  25. @Resource
  26. private RuleUpdateEventService ruleUpdateEventService;
  27. private int saveAlertrule(ProEconAlarmRule alarmRule) throws Exception {
  28. int result = 0;
  29. if (StringUtils.notEmp(alarmRule)) {
  30. alarmRule.setCreateTime(new Date());
  31. alarmRule.setId(String.valueOf(SnowflakeGenerator.generateId()));
  32. alarmRule.setEnable(true);
  33. alarmRule.setUniformCode("");
  34. alarmRule.setRange("0");
  35. result= proEconAlarmRuleMapper.insert(alarmRule);
  36. }
  37. // if (result > 0) {
  38. // int i = eventService.saveEventAlertRule(alarmRule, oldRule2, userData.getUserName());
  39. return result;
  40. }
  41. public int saveAndUpdateAlertrule(ProEconAlarmRule alarmRule) throws Exception {
  42. int result = 0;
  43. if (StringUtils.notEmp(alarmRule)) {
  44. if (StringUtils.notEmp(alarmRule.getId())) {
  45. ProEconAlarmRule oldRule2 = proEconAlarmRuleMapper.selectById(alarmRule.getId());
  46. if (oldRule2 != null) {
  47. result = proEconAlarmRuleMapper.updateByAlertruleId(alarmRule);
  48. ruleUpdateEventService.saveEventAlertRule(alarmRule,oldRule2);
  49. }else
  50. {
  51. ruleUpdateEventService.saveEventAlertRule(alarmRule,null);
  52. result = saveAlertrule(alarmRule);
  53. }
  54. }
  55. else
  56. {
  57. result = saveAlertrule(alarmRule);
  58. ruleUpdateEventService.saveEventAlertRule(alarmRule,null);
  59. }
  60. }
  61. return result;
  62. }
  63. public int deleteAlertrule(String id) {
  64. return proEconAlarmRuleMapper.deleteById(id);
  65. }
  66. public IPage<ProEconAlarmRule> pageQueryAll(Page page, String name, String station, String modelId, String rank, String category, String enabled, String relatedparts) {
  67. if(StringUtils.notEmp(name))
  68. {
  69. name="%"+name+"%";
  70. }else
  71. {
  72. name=null;
  73. }
  74. if(StringUtils.empty(station))
  75. {
  76. station=null;
  77. }
  78. if(StringUtils.empty(modelId))
  79. {
  80. modelId=null;
  81. }
  82. if(StringUtils.empty(rank))
  83. {
  84. rank=null;
  85. }
  86. if(StringUtils.empty(category))
  87. {
  88. category=null;
  89. }
  90. if(StringUtils.empty(enabled))
  91. {
  92. enabled=null;
  93. }
  94. if(StringUtils.empty(relatedparts))
  95. {
  96. relatedparts=null;
  97. }
  98. IPage<ProEconAlarmRule> alertruleIPage = proEconAlarmRuleMapper.pageQueryAll(page, name, station, modelId, rank, category, enabled, relatedparts);
  99. if(!alertruleIPage.getRecords().isEmpty())
  100. {
  101. for(ProEconAlarmRule ar:alertruleIPage.getRecords())
  102. {
  103. if(CacheContext.wpmap.containsKey(ar.getStationId()))
  104. {
  105. ProBasicPowerstation wp=CacheContext.wpmap.get(ar.getStationId());
  106. ar.setStationName(wp.getName());
  107. }
  108. if(CacheContext.alarmTypeMap.containsKey(ar.getRelatedParts()))
  109. {
  110. ProEconAlarmType type=CacheContext.alarmTypeMap.get(ar.getRelatedParts());
  111. ar.setRelatedPartsName(type.getName());
  112. }
  113. }
  114. }
  115. return alertruleIPage;
  116. }
  117. public List<AlarmRuleVo> queryTree() {
  118. List<AlarmRuleVo> dsList = proEconAlarmRuleMapper.queryTree();
  119. return dsList;
  120. }
  121. //首页风机部件查询
  122. public Map<String, Integer> queryList(String station, String modelId) {
  123. Map<String, Integer> map2 = new HashMap<>();
  124. map2.put("CLX", 0);
  125. map2.put("YP", 0);
  126. map2.put("YY", 0);
  127. map2.put("BJXT", 0);
  128. map2.put("PHXT", 0);
  129. map2.put("BPXT", 0);
  130. map2.put("CFXT", 0);
  131. map2.put("ZZ", 0);
  132. map2.put("FDJ", 0);
  133. map2.put("QT", 0);
  134. List<ProEconAlarmRule> dslist = proEconAlarmRuleMapper.getAllByStationIdAndModelId(station, modelId);
  135. map2.put("SUM", dslist.size());
  136. for (ProEconAlarmRule ar : dslist) {
  137. int cnt = 0;
  138. switch (ar.getRelatedParts()) {
  139. case "CLX":
  140. cnt = map2.get("CLX").intValue();
  141. map2.put("CLX", ++cnt);
  142. break;
  143. case "YP":
  144. cnt = map2.get("YP").intValue();
  145. map2.put("YP", ++cnt);
  146. break;
  147. case "YY":
  148. cnt = map2.get("YY").intValue();
  149. map2.put("YY", ++cnt);
  150. break;
  151. case "BJXT":
  152. cnt = map2.get("BJXT").intValue();
  153. map2.put("BJXT", ++cnt);
  154. break;
  155. case "PHXT":
  156. cnt = map2.get("PHXT").intValue();
  157. map2.put("PHXT", ++cnt);
  158. break;
  159. case "BPXT":
  160. cnt = map2.get("BPXT").intValue();
  161. map2.put("BPXT", ++cnt);
  162. break;
  163. case "CFXT":
  164. cnt = map2.get("CFXT").intValue();
  165. map2.put("CFXT", ++cnt);
  166. break;
  167. case "ZZ":
  168. cnt = map2.get("ZZ").intValue();
  169. map2.put("ZZ", ++cnt);
  170. break;
  171. case "FDJ":
  172. cnt = map2.get("FDJ").intValue();
  173. map2.put("FDJ", ++cnt);
  174. break;
  175. default:
  176. cnt = map2.get("QT").intValue();
  177. map2.put("QT", ++cnt);
  178. break;
  179. }
  180. }
  181. return map2;
  182. }
  183. public List<String> getUniformCodeByNameAndStation(String name, String station, String modelid) {
  184. List<ProEconAlarmRule> rules = proEconAlarmRuleMapper.getUniformCodeByNameAndStation(name, station, modelid);
  185. if (rules == null || rules.size() == 0)
  186. return null;
  187. ProEconAlarmRule rule = rules.get(0);
  188. String expression = "(([A][I])|([D][I]))([0-9]+)";
  189. List<String> list = StringUtil.pattern(rule.getExpression(), expression);
  190. return list;
  191. }
  192. public ProEconAlarmRule selectByAlertruleId(String id) {
  193. return proEconAlarmRuleMapper.selectById(id);
  194. }
  195. }