package com.gyee.alarm.service; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.gyee.alarm.init.CacheContext; import com.gyee.alarm.mapper.auto.AlarmTsMapper; import com.gyee.alarm.mapper.auto.ProEconAlarmRuleMapper; import com.gyee.alarm.model.auto.ProBasicPowerstation; import com.gyee.alarm.model.auto.ProEconAlarmRule; import com.gyee.alarm.model.auto.ProEconAlarmType; import com.gyee.alarm.model.auto.ProEconCurveFittingMain; import com.gyee.alarm.model.vo.AlarmRuleVo; import com.gyee.alarm.service.auto.IProEconAlarmTypeService; import com.gyee.alarm.util.SnowflakeGenerator; import com.gyee.alarm.util.StringUtil; import com.gyee.alarm.util.StringUtils; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.*; import java.util.stream.Collectors; @Service public class AlarmRuleService { @Resource private ProEconAlarmRuleMapper proEconAlarmRuleMapper; @Resource private RuleUpdateEventService ruleUpdateEventService; private int saveAlertrule(ProEconAlarmRule alarmRule) throws Exception { int result = 0; if (StringUtils.notEmp(alarmRule)) { alarmRule.setCreateTime(new Date()); alarmRule.setId(String.valueOf(SnowflakeGenerator.generateId())); alarmRule.setEnable(true); alarmRule.setUniformCode(""); alarmRule.setRange("0"); result= proEconAlarmRuleMapper.insert(alarmRule); } // if (result > 0) { // int i = eventService.saveEventAlertRule(alarmRule, oldRule2, userData.getUserName()); return result; } public int saveAndUpdateAlertrule(ProEconAlarmRule alarmRule) throws Exception { int result = 0; if (StringUtils.notEmp(alarmRule)) { if (StringUtils.notEmp(alarmRule.getId())) { ProEconAlarmRule oldRule2 = proEconAlarmRuleMapper.selectById(alarmRule.getId()); if (oldRule2 != null) { result = proEconAlarmRuleMapper.updateByAlertruleId(alarmRule); ruleUpdateEventService.saveEventAlertRule(alarmRule,oldRule2); }else { ruleUpdateEventService.saveEventAlertRule(alarmRule,null); result = saveAlertrule(alarmRule); } } else { result = saveAlertrule(alarmRule); ruleUpdateEventService.saveEventAlertRule(alarmRule,null); } } return result; } public int deleteAlertrule(String id) { return proEconAlarmRuleMapper.deleteById(id); } public IPage pageQueryAll(Page page, String name, String station, String modelId, String rank, String category, String enabled, String relatedparts) { if(StringUtils.notEmp(name)) { name="%"+name+"%"; }else { name=null; } if(StringUtils.empty(station)) { station=null; } if(StringUtils.empty(modelId)) { modelId=null; } if(StringUtils.empty(rank)) { rank=null; } if(StringUtils.empty(category)) { category=null; } if(StringUtils.empty(enabled)) { enabled=null; } if(StringUtils.empty(relatedparts)) { relatedparts=null; } IPage alertruleIPage = proEconAlarmRuleMapper.pageQueryAll(page, name, station, modelId, rank, category, enabled, relatedparts); if(!alertruleIPage.getRecords().isEmpty()) { for(ProEconAlarmRule ar:alertruleIPage.getRecords()) { if(CacheContext.wpmap.containsKey(ar.getStationId())) { ProBasicPowerstation wp=CacheContext.wpmap.get(ar.getStationId()); ar.setStationName(wp.getName()); } if(CacheContext.alarmTypeMap.containsKey(ar.getRelatedParts())) { ProEconAlarmType type=CacheContext.alarmTypeMap.get(ar.getRelatedParts()); ar.setRelatedPartsName(type.getName()); } } } return alertruleIPage; } public List queryTree() { List dsList = proEconAlarmRuleMapper.queryTree(); return dsList; } //首页风机部件查询 public Map queryList(String station, String modelId) { Map map2 = new HashMap<>(); map2.put("CLX", 0); map2.put("YP", 0); map2.put("YY", 0); map2.put("BJXT", 0); map2.put("PHXT", 0); map2.put("BPXT", 0); map2.put("CFXT", 0); map2.put("ZZ", 0); map2.put("FDJ", 0); map2.put("QT", 0); List dslist = proEconAlarmRuleMapper.getAllByStationIdAndModelId(station, modelId); map2.put("SUM", dslist.size()); for (ProEconAlarmRule ar : dslist) { int cnt = 0; switch (ar.getRelatedParts()) { case "CLX": cnt = map2.get("CLX").intValue(); map2.put("CLX", ++cnt); break; case "YP": cnt = map2.get("YP").intValue(); map2.put("YP", ++cnt); break; case "YY": cnt = map2.get("YY").intValue(); map2.put("YY", ++cnt); break; case "BJXT": cnt = map2.get("BJXT").intValue(); map2.put("BJXT", ++cnt); break; case "PHXT": cnt = map2.get("PHXT").intValue(); map2.put("PHXT", ++cnt); break; case "BPXT": cnt = map2.get("BPXT").intValue(); map2.put("BPXT", ++cnt); break; case "CFXT": cnt = map2.get("CFXT").intValue(); map2.put("CFXT", ++cnt); break; case "ZZ": cnt = map2.get("ZZ").intValue(); map2.put("ZZ", ++cnt); break; case "FDJ": cnt = map2.get("FDJ").intValue(); map2.put("FDJ", ++cnt); break; default: cnt = map2.get("QT").intValue(); map2.put("QT", ++cnt); break; } } return map2; } public List getUniformCodeByNameAndStation(String name, String station, String modelid) { List rules = proEconAlarmRuleMapper.getUniformCodeByNameAndStation(name, station, modelid); if (rules == null || rules.size() == 0) return null; ProEconAlarmRule rule = rules.get(0); String expression = "(([A][I])|([D][I]))([0-9]+)"; List list = StringUtil.pattern(rule.getExpression(), expression); return list; } public ProEconAlarmRule selectByAlertruleId(String id) { return proEconAlarmRuleMapper.selectById(id); } }