AlarmCtService.java 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. package com.gyee.alarm.service;
  2. import com.gyee.alarm.init.CacheContext;
  3. import com.gyee.alarm.model.auto.*;
  4. import com.gyee.alarm.model.vo.*;
  5. import com.gyee.alarm.service.auto.IAlarmTsService;
  6. import com.gyee.alarm.service.auto.IProEconAlarmInfoService;
  7. import com.gyee.alarm.util.DateUtils;
  8. import com.gyee.alarm.util.StringUtils;
  9. import org.springframework.stereotype.Service;
  10. import org.springframework.web.context.request.RequestContextHolder;
  11. import org.springframework.web.context.request.ServletRequestAttributes;
  12. import javax.annotation.Resource;
  13. import javax.servlet.http.HttpServletRequest;
  14. import javax.websocket.EncodeException;
  15. import java.io.IOException;
  16. import java.sql.SQLException;
  17. import java.util.*;
  18. import java.util.concurrent.ConcurrentHashMap;
  19. @Service
  20. public class AlarmCtService {
  21. @Resource
  22. private IAlarmTsService alarmTsService;
  23. @Resource
  24. private IProEconAlarmInfoService proEconAlarmInfoService;
  25. @Resource
  26. private TokenService tokenService;
  27. public List<AlarmVo> initalAlarmVo() {
  28. List<AlarmVo> alarmVoList = new ArrayList<>();
  29. Map<String, List<ProEconAlarmRule>> alarmRulesMap = CacheContext.alarmRulesMap;
  30. //风机自定义报警
  31. wtCustomAlarm(alarmVoList, alarmRulesMap);
  32. //逆变器自定义报警
  33. lnCustomAlarm(alarmVoList, alarmRulesMap);
  34. // //场站自定义报警
  35. // wpCustomAlarm(alarmVoList, alarmRulesMap);
  36. //升压站自定义报警
  37. btCustomAlarm(alarmVoList, alarmRulesMap);
  38. return alarmVoList;
  39. }
  40. private void wtCustomAlarm(List<AlarmVo> alarmVoList, Map<String, List<ProEconAlarmRule>> alarmRulesMap) {
  41. Map<String, List<ProEconAlarmRule>> armap = new HashMap<>();
  42. if (alarmRulesMap.containsKey(DeviceTypeValue.WT.getCode())) {
  43. List<ProEconAlarmRule> arls = alarmRulesMap.get(DeviceTypeValue.WT.getCode());
  44. if (!arls.isEmpty()) {
  45. for (ProEconAlarmRule ar : arls) {
  46. StringBuilder sb = new StringBuilder();
  47. sb.append(ar.getStationId() + ar.getModelId());
  48. if (armap.containsKey(String.valueOf(sb))) {
  49. List<ProEconAlarmRule> ls = armap.get(String.valueOf(sb));
  50. ls.add(ar);
  51. } else {
  52. List<ProEconAlarmRule> ls = new ArrayList<>();
  53. ls.add(ar);
  54. armap.put(String.valueOf(sb), ls);
  55. }
  56. }
  57. }
  58. }
  59. for (ProBasicEquipment wt : CacheContext.wtls) {
  60. StringBuilder sb = new StringBuilder();
  61. sb.append(wt.getWindpowerstationId() + wt.getModelId());
  62. if (armap.containsKey(String.valueOf(sb))) {
  63. List<ProEconAlarmRule> alarmls = armap.get(String.valueOf(sb));
  64. if (!alarmls.isEmpty()) {
  65. for (ProEconAlarmRule alarm : alarmls) {
  66. AlarmVo vo = new AlarmVo();
  67. StringBuilder tbName = new StringBuilder();
  68. tbName.append(wt.getId()).append("_").append(alarm.getId());
  69. vo.setTbName(String.valueOf(tbName));
  70. vo.setAlarmid(alarm.getId());
  71. vo.setTagid(alarm.getExpression());
  72. vo.setAlarmtype(AlarmTypeValue.CT.getCode());
  73. vo.setCharacteristic(alarm.getName());
  74. vo.setComponents(alarm.getRelatedParts());
  75. vo.setDescription(alarm.getDescription());
  76. vo.setDeviceid(wt.getId());
  77. vo.setDevicename(wt.getName());
  78. vo.setDevicetype(DeviceTypeValue.WT.getCode());
  79. vo.setEnabled(alarm.getEnable());
  80. vo.setLineid(wt.getLineId());
  81. if (CacheContext.lnmap.containsKey(wt.getLineId())) {
  82. ProBasicLine ln = CacheContext.lnmap.get(wt.getLineId());
  83. vo.setLinename(ln.getName());
  84. }
  85. vo.setModelId(wt.getModelId());
  86. vo.setProjectid(wt.getProjectId());
  87. if (CacheContext.pjmap.containsKey(wt.getProjectId())) {
  88. ProBasicProject pj = CacheContext.pjmap.get(wt.getProjectId());
  89. vo.setProjectname(pj.getName());
  90. }
  91. vo.setRank(alarm.getRank());
  92. vo.setResettable(false);
  93. vo.setStationid(wt.getWindpowerstationId());
  94. if (CacheContext.wpmap.containsKey(wt.getWindpowerstationId())) {
  95. ProBasicPowerstation wp = CacheContext.wpmap.get(wt.getWindpowerstationId());
  96. vo.setStationname(wp.getName());
  97. }
  98. vo.setSubcomponents("");
  99. vo.setSuffix("");
  100. vo.setTriggertype(1);
  101. vo.setUniformcode("");
  102. vo.setSuperTableName(AlarmSuperTalbeType.CT.getCode());
  103. vo.setVal(0);
  104. vo.setCharacteristic("自定义");
  105. vo.setFaultCause(alarm.getDescription());
  106. vo.setResolvent(alarm.getExpression());
  107. alarmVoList.add(vo);
  108. }
  109. }
  110. }
  111. }
  112. }
  113. private void lnCustomAlarm(List<AlarmVo> alarmVoList, Map<String, List<ProEconAlarmRule>> alarmRulesMap) {
  114. Map<String, List<ProEconAlarmRule>> armap = new HashMap<>();
  115. if (alarmRulesMap.containsKey(DeviceTypeValue.IN.getCode())) {
  116. List<ProEconAlarmRule> arls = alarmRulesMap.get(DeviceTypeValue.IN.getCode());
  117. if (!arls.isEmpty()) {
  118. for (ProEconAlarmRule ar : arls) {
  119. StringBuilder sb = new StringBuilder();
  120. sb.append(ar.getStationId() + ar.getModelId());
  121. if (armap.containsKey(String.valueOf(sb))) {
  122. List<ProEconAlarmRule> ls = armap.get(String.valueOf(sb));
  123. ls.add(ar);
  124. } else {
  125. List<ProEconAlarmRule> ls = new ArrayList<>();
  126. ls.add(ar);
  127. armap.put(String.valueOf(sb), ls);
  128. }
  129. }
  130. }
  131. }
  132. //
  133. // HttpServletRequest request = ((ServletRequestAttributes) (RequestContextHolder.currentRequestAttributes())).getRequest();
  134. // List<ProBasicEquipment> wtls = tokenService.getWtls(request);
  135. for (ProBasicEquipment wt : CacheContext.wtls) {
  136. StringBuilder sb = new StringBuilder();
  137. sb.append(wt.getWindpowerstationId() + wt.getModelId());
  138. if (armap.containsKey(String.valueOf(sb))) {
  139. List<ProEconAlarmRule> alarmls = armap.get(String.valueOf(sb));
  140. if (!alarmls.isEmpty()) {
  141. for (ProEconAlarmRule alarm : alarmls) {
  142. AlarmVo vo = new AlarmVo();
  143. StringBuilder tbName = new StringBuilder();
  144. tbName.append(wt.getId()).append("_").append(alarm.getId());
  145. vo.setTbName(String.valueOf(tbName));
  146. vo.setAlarmid(alarm.getId());
  147. vo.setTagid(alarm.getExpression());
  148. vo.setAlarmtype(AlarmTypeValue.CT.getCode());
  149. vo.setCharacteristic(alarm.getName());
  150. vo.setComponents(alarm.getRelatedParts());
  151. vo.setDescription(alarm.getDescription());
  152. vo.setDeviceid(wt.getId());
  153. vo.setDevicename(wt.getName());
  154. vo.setDevicetype(DeviceTypeValue.IN.getCode());
  155. vo.setEnabled(alarm.getEnable());
  156. vo.setLineid(wt.getLineId());
  157. if (CacheContext.lnmap.containsKey(wt.getLineId())) {
  158. ProBasicLine ln = CacheContext.lnmap.get(wt.getLineId());
  159. vo.setLinename(ln.getName());
  160. }
  161. vo.setModelId(wt.getModelId());
  162. vo.setProjectid(wt.getProjectId());
  163. if (CacheContext.pjmap.containsKey(wt.getProjectId())) {
  164. ProBasicProject pj = CacheContext.pjmap.get(wt.getProjectId());
  165. vo.setProjectname(pj.getName());
  166. }
  167. vo.setRank(alarm.getRank());
  168. vo.setResettable(false);
  169. vo.setStationid(wt.getWindpowerstationId());
  170. if (CacheContext.wpmap.containsKey(wt.getWindpowerstationId())) {
  171. ProBasicPowerstation wp = CacheContext.wpmap.get(wt.getWindpowerstationId());
  172. vo.setStationname(wp.getName());
  173. }
  174. vo.setSubcomponents("");
  175. vo.setSuffix("");
  176. vo.setTriggertype(1);
  177. vo.setUniformcode("");
  178. vo.setSuperTableName(AlarmSuperTalbeType.CT.getCode());
  179. vo.setVal(0);
  180. vo.setCharacteristic("自定义");
  181. vo.setFaultCause(alarm.getDescription());
  182. vo.setResolvent(alarm.getExpression());
  183. alarmVoList.add(vo);
  184. }
  185. }
  186. }
  187. }
  188. }
  189. private void wpCustomAlarm(List<AlarmVo> alarmVoList, Map<String, List<ProEconAlarmRule>> alarmRulesMap) {
  190. List<ProEconAlarmRule> alarmls = new ArrayList<>();
  191. if (alarmRulesMap.containsKey(DeviceTypeValue.WP.getCode())) {
  192. alarmls = alarmRulesMap.get(DeviceTypeValue.WP.getCode());
  193. }
  194. // HttpServletRequest request = ((ServletRequestAttributes) (RequestContextHolder.currentRequestAttributes())).getRequest();
  195. // List<ProBasicPowerstation> wpls = tokenService.getWpls(request);
  196. for (ProBasicPowerstation wp : CacheContext.wpls) {
  197. if (!alarmls.isEmpty()) {
  198. for (ProEconAlarmRule alarm : alarmls) {
  199. AlarmVo vo = new AlarmVo();
  200. StringBuilder tbName = new StringBuilder();
  201. tbName.append(wp.getId()).append("_").append(alarm.getId());
  202. vo.setTbName(String.valueOf(tbName));
  203. vo.setAlarmid(alarm.getId());
  204. vo.setTagid(alarm.getExpression());
  205. vo.setAlarmtype(AlarmTypeValue.CT.getCode());
  206. vo.setCharacteristic(alarm.getName());
  207. vo.setComponents(alarm.getRelatedParts());
  208. vo.setDescription(alarm.getDescription());
  209. vo.setDeviceid("");
  210. vo.setDevicename("");
  211. vo.setDevicetype(DeviceTypeValue.WP.getCode());
  212. vo.setEnabled(alarm.getEnable());
  213. vo.setLineid("");
  214. vo.setLinename("");
  215. vo.setModelId("");
  216. vo.setProjectid("");
  217. vo.setProjectname("");
  218. vo.setRank(alarm.getRank());
  219. vo.setResettable(false);
  220. vo.setStationid(wp.getId());
  221. vo.setStationname(wp.getName());
  222. vo.setSubcomponents("");
  223. vo.setSuffix("");
  224. vo.setTriggertype(1);
  225. vo.setUniformcode("");
  226. vo.setSuperTableName(AlarmSuperTalbeType.CT.getCode());
  227. vo.setVal(0);
  228. alarmVoList.add(vo);
  229. }
  230. }
  231. }
  232. }
  233. private void btCustomAlarm(List<AlarmVo> alarmVoList, Map<String, List<ProEconAlarmRule>> alarmRulesMap) {
  234. Map<String,List<ProEconAlarmRule>> alarmMap=new HashMap<>();
  235. if (alarmRulesMap.containsKey(DeviceTypeValue.BT.getCode())) {
  236. List<ProEconAlarmRule> alarmls = alarmRulesMap.get(DeviceTypeValue.BT.getCode());
  237. if(!alarmls.isEmpty())
  238. {
  239. for(ProEconAlarmRule alarm:alarmls)
  240. {
  241. if (StringUtils.notEmp(alarm) && StringUtils.notEmp(alarm.getElectricalId()))
  242. {
  243. String [] ids=alarm.getElectricalId().split(",");
  244. if(ids.length>0)
  245. {
  246. for(int i=0;i<ids.length;i++)
  247. {
  248. if(alarmMap.containsKey(ids[i]))
  249. {
  250. List<ProEconAlarmRule> arls=alarmMap.get(ids[i]);
  251. arls.add(alarm);
  252. }else
  253. {
  254. List<ProEconAlarmRule> arls=new ArrayList<>();
  255. arls.add(alarm);
  256. alarmMap.put(ids[i],arls);
  257. }
  258. }
  259. }
  260. }
  261. }
  262. }
  263. }
  264. // HttpServletRequest request = ((ServletRequestAttributes) (RequestContextHolder.currentRequestAttributes())).getRequest();
  265. // List<ProBasicSubStation> subwpls = tokenService.getSubwpls(request);
  266. for (ProBasicSubStation wp : CacheContext.subwpls) {
  267. if (!alarmMap.isEmpty() && alarmMap.containsKey(wp.getId())) {
  268. List<ProEconAlarmRule> alarmls = alarmMap.get(wp.getId());
  269. for (ProEconAlarmRule alarm : alarmls) {
  270. AlarmVo vo = new AlarmVo();
  271. StringBuilder tbName = new StringBuilder();
  272. tbName.append(wp.getId()).append("_").append(alarm.getId());
  273. vo.setTbName(String.valueOf(tbName));
  274. vo.setAlarmid(alarm.getId());
  275. vo.setTagid(alarm.getExpression());
  276. vo.setAlarmtype(AlarmTypeValue.CT.getCode());
  277. vo.setCharacteristic(alarm.getName());
  278. vo.setComponents(alarm.getRelatedParts());
  279. vo.setDescription(alarm.getDescription());
  280. vo.setDeviceid("");
  281. vo.setDevicename("");
  282. vo.setDevicetype(DeviceTypeValue.BT.getCode());
  283. vo.setEnabled(alarm.getEnable());
  284. vo.setLineid("");
  285. vo.setLinename("");
  286. vo.setModelId("");
  287. vo.setProjectid("");
  288. vo.setProjectname("");
  289. vo.setRank(alarm.getRank());
  290. vo.setResettable(false);
  291. vo.setStationid(wp.getId());
  292. vo.setStationname(wp.getName());
  293. vo.setSubcomponents("");
  294. vo.setSuffix("");
  295. vo.setTriggertype(1);
  296. vo.setUniformcode("");
  297. vo.setSuperTableName(AlarmSuperTalbeType.CT.getCode());
  298. vo.setVal(0);
  299. vo.setOval(0);
  300. vo.setCharacteristic("自定义");
  301. vo.setFaultCause(alarm.getDescription());
  302. vo.setResolvent(alarm.getExpression());
  303. alarmVoList.add(vo);
  304. }
  305. }
  306. }
  307. }
  308. }