123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229 |
- package com.gyee.generation.util.rule;//package com.gyee.alarm.rule;
- //
- //import com.gyee.alarm.model.auto.ProBasicEquipment;
- //import com.gyee.alarm.model.auto.ProEconAlarmRule;
- //import com.gyee.alarm.rule.expression.AlarmExpression;
- //import com.gyee.alarm.rule.expression.Analyzer;
- //
- //import com.gyee.alarm.service.initalcache.CacheService;
- //import com.gyee.alarm.util.StringUtils;
- //import lombok.Data;
- //import lombok.extern.slf4j.Slf4j;
- //
- //
- //import java.util.*;
- //import java.util.stream.Collectors;
- //
- //@Slf4j
- //@Data
- //public class AlarmRule {
- //
- // private ProEconAlarmRule proEconAlarmRule;
- //
- // private AlarmExpression alarmExpression;
- //
- // private List<AlarmFunction> funList;
- //
- //
- // public AlarmRule(ProEconAlarmRule ar) {
- // this.proEconAlarmRule = ar;
- // funList = new ArrayList<>();
- // try {
- // alarmExpression = Analyzer.getAlarmExpression(ar.getExpression());
- // alarmExpression.setRuleId(proEconAlarmRule.getId());
- // ArrayList<String> ucs = alarmExpression.getAllUniformCodes();
- // //1-风机 2-风场 5-升压站
- // if ("1".equals(ar.getCategory()) ) {
- // //获取规则所对应的风机
- // List<ProBasicEquipment> lst = new ArrayList<>();
- // cacheService.getWindturbineInfoMap().values().stream()
- // .filter((WindturbineInfo w) -> w.getWindturbine().getModelId().contains(ar.getModelId().trim())&&w.getWindturbine().getWindPowerStationId().equals(ar.getStation())).collect(Collectors.toList()).forEach(n -> lst.add(n.getWindturbine()));
- //
- // // String[] wtArray = ar.getWindturbine().split(",");
- // for (ProBasicEquipment wb : lst) {
- // Map<String, WindturbineInfo> wtMap = cacheService.getWindturbineInfoMap();
- // if (StringUtils.notEmp(wb.getId()) && wtMap.containsKey(wb.getId())) {
- // AlarmFunction alarmFunction = new AlarmFunction(alarmExpression, ThingType.WINDTURBINE, wb.getId());
- // if (funList.contains(alarmFunction)) {
- // log.warn("重复的设备:" + wb.getId());
- // continue;
- // }
- // funList.add(alarmFunction);
- // }
- // }
- // //填充ucWindturbinelist
- // if (ucs.size() > 0) {
- // for (String uc : ucs) {
- // ArrayList<String> wtList = cacheService.getUcWindturbinelist(uc);
- // for (ProBasicEquipment wb : lst) {
- // if (wtList.contains(wb.getId()) == false)
- // wtList.add(wb.getId());
- // }
- // }
- // }
- // }
- //
- //
- // if (("2".equals(ar.getCategory()) || "5".equals(ar.getCategory())) && ar.getStation() != null) {
- // String[] stArray = ar.getStation().split(",");
- // for (String stId : stArray) {
- // Map<String, StationInfo> wtMap = cacheService.getStationInfoMap();
- // if (StringUtil.isNotBlank(stId) && wtMap.containsKey(stId)) {
- // AlarmFunction alarmFunction = new AlarmFunction(alarmExpression, ThingType.STATION, stId);
- // if (funList.contains(alarmFunction)) {
- // log.warn("重复的设备:" + stId);
- // continue;
- // }
- // funList.add(alarmFunction);
- // }
- // }
- //
- // //填充ucStationlist
- // if (ucs.size() > 0) {
- // for (String uc : ucs) {
- // ArrayList<String> stList = cacheService.getUcStationlist(uc);
- // for (String stId : stArray) {
- // if (stList.contains(stId) == false)
- // stList.add(stId);
- // }
- // }
- // }
- // }
- // } catch (Exception ex) {
- // log.error("生成自定义报警规则失败!规则id:" + ar.getId());
- // }
- // }
- //
- // //缓存报警快照,减少数据库查询次数
- // //key: thingId
- // private HashMap<String, AlarmSnap> snapMap;
- //
- // //用于批量更新数据库
- // private List<AlarmSnap> snapChangedList;
- //
- // public void run() {
- // if (funList != null && funList.size() > 0) {
- //
- // if (snapChangedList == null)
- // snapChangedList = new ArrayList<>();
- // else
- // snapChangedList.clear();
- //
- // for (AlarmFunction fun : funList) {
- // try {
- //
- // Object obj = fun.explain();
- // if (obj instanceof Boolean) {
- // boolean writeHistory = true;
- // AlarmSnap snap = getAlertSnap(fun.getThingId());
- // if (true == (boolean) obj) {
- // double interval = 0;
- //// if (snap == null) {
- //// snap = AlertSnapFactory.createAlertsnap(this.proEconAlarmRule, fun.getThingId());
- //// if (snap.getStationName() == null &&
- //// snap.getStationId() != null &&
- //// cacheService.getStationInfoMap().containsKey(snap.getStationId())) {
- ////// StationInfo st = cacheService.getStationInfoMap().get(snap.getStationId());
- //// snap.setStationName(st.getStation().getStationName());
- //// }
- //// } else
- // if (snap.getIsOpened() != 0) {
- // long ts = (new Date()).getTime() - snap.getLastUpdateTime().getTime();
- // //TimeSpan ts = DateTime.Now.Subtract((DateTime)snap.LastUpdateTime);
- // interval = ts / (3600 * 1000);
- // }
- //
- // if (snap.getIsOpened() == 0 || interval > 1) {
- // snap.setIsOpened(1);
- // //snap.DataInfo = CommonMethod.StringCopy(ari.DataInfo, 2000);
- // //snap.setLastUpdatePerson("system");
- // snap.setLastUpdateTime(new Date());
- //// if (snap.getIsConfirmed() != 0 && interval > 8)
- //// snap.setIsConfirmed(0);
- //
- // //sqlService.saveAlertSnap(snap);
- // snapChangedList.add(snap);
- //
- //
- // //AlertSnapRepository.SaveAlertSnap(snap);
- // //写实时库
- //// string key = GetWindTurbineAlertPoint(windTurbine.Id);
- //// logger.InfoFormat("写报警测点,key={0}, value={1}", key, ari.ProEconAlarmRule.EdnaValue);
- //// eDos.SendSinglePoint(key, ari.ProEconAlarmRule.EdnaValue);
- // log.info(String.format("触发报警!%s,规则:%s", fun.getThingId(), proEconAlarmRule.getName()+"--"+proEconAlarmRule.getExpression()));
- // }
- // } else {
- // //解除报警
- // if (snap != null && snap.getIsOpened() != 0) {
- // snap.setIsOpened(0);
- // //snap.DataInfo = CommonMethod.StringCopy(ari.DataInfo, 2000);
- //// snap.setIsConfirmed(0);
- //// snap.setLastClosePerson("system");
- //// snap.setLastCloseTime(new Date());
- // snap.setLastUpdateTime(new Date());
- // //sqlService.saveAlertSnap(snap);
- // snapChangedList.add(snap);
- // log.info(String.format("解除报警!%s,规则:%s",
- // fun.getThingId(), proEconAlarmRule.getId()));
- // }
- // }
- // } else {
- // System.out.print(obj.toString());
- // }
- // } catch (Exception ex) {
- // // ex.printStackTrace();
- // log.error("自定义报警规则执行时出错!"+fun.getThingId()+"--"+this.proEconAlarmRule.getId()+"----"+this.proEconAlarmRule.getName()+"------" + ex.getMessage());
- // }
- // }
- //
- // if (snapChangedList.size() > 0)
- // sqlService.saveAlertSnaps(snapChangedList);
- // }
- // }
- //
- // private AlarmSnap getAlertSnap(String thingId) {
- // if (snapMap == null)
- // snapMap = new HashMap<>();
- // if (snapMap.containsKey(thingId)) {
- // return snapMap.get(thingId);
- // } else {
- // AlarmSnap alertsnap = findAlertSnap(thingId, this.proEconAlarmRule.getEdnaValue());
- // if (alertsnap == null) {
- // alertsnap = AlertSnapFactory.createAlertsnap(this.proEconAlarmRule, thingId);
- // if (alertsnap.getStationName() == null &&
- // alertsnap.getStationId() != null &&
- // cacheService.getStationInfoMap().containsKey(alertsnap.getStationId())) {
- // StationInfo st = cacheService.getStationInfoMap().get(alertsnap.getStationId());
- // alertsnap.setStationName(st.getStation().getStationName());
- // }
- // }
- // if (alertsnap.getId() != null)
- // snapMap.put(thingId, alertsnap);
- // if(StringUtils.isBlank(alertsnap.getCategory3()))
- // {
- // //如果风机报警的category3字段为空,则说明报警没有关联到相关部件,取报警规则中的Relatedparts进行赋值
- // if(StringUtils.isNotBlank(this.proEconAlarmRule.getRelatedParts())){
- // alertsnap.setCategory3(this.proEconAlarmRule.getRelatedParts());
- // }
- // }
- // return alertsnap;
- // }
- // }
- //
- // private AlarmSnap findAlertSnap(String thingId, int alertValue) {
- // try {
- // if ("1".equals(this.proEconAlarmRule.getCategory())) {
- // return sqlService.getAlertSnap(ThingType.WINDTURBINE, thingId, alertValue);
- // }
- //
- // return sqlService.getAlertSnap(ThingType.STATION, thingId, alertValue);
- // } catch (Exception ex) {
- // log.warn(String.format("thingId=%s, alertValue=%d", thingId, alertValue));
- // log.error(ex.getMessage(), ex);
- // return null;
- // }
- //
- // }
- //
- //
- //}
|