1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138 |
- package com.gyee.healthmodel.service;
- import com.gyee.common.contant.ContantXk;
- import com.gyee.common.model.PointData;
- import com.gyee.healthmodel.init.CacheContext;
- import com.gyee.healthmodel.model.auto.*;
- import com.gyee.healthmodel.model.vo.StatusDetailValue;
- import com.gyee.healthmodel.service.auto.*;
- import com.gyee.healthmodel.util.*;
- import com.gyee.healthmodel.vo.healthsystem.DataVo;
- import com.gyee.healthmodel.vo.healthsystem.HealthExpression;
- import com.gyee.healthmodel.vo.healthsystem.ResultVo;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
- import org.springframework.stereotype.Service;
- import javax.annotation.Resource;
- import java.math.BigDecimal;
- import java.math.RoundingMode;
- import java.util.*;
- import java.util.Map.Entry;
- import java.util.concurrent.CountDownLatch;
- @Service
- public class HealthJudgeService {
- private static Logger logger = LoggerFactory.getLogger(HealthJudgeService.class);
- @Resource
- private IProEconHealthSystemService proEconHealthSystemService;
- @Resource
- private IProEconHealthSystemSubService proEconHealthSystemSubService;
- @Resource
- private ThreadPoolTaskExecutor threadPoolTaskExecutor;
- @Resource
- private IProEconStateJudgmentDayService proEconStateJudgmentDayService;
- @Resource
- private IProEconStateJudgmentRealService proEconStateJudgmentRealService;
- @Resource
- private HealthInitialService healthInitialService;
- @Resource
- private HealthFactoryService healthFactoryService;
- @Resource
- private AlarmcountsService alarmcountsService;
- @Resource
- private AlarmsnapsService alarmsnapsService;
- @Resource
- private Alertrule2sService alertrule2sService;
- @Resource
- private IProEconWindturbineWarnCountService proEconWindturbineWarnCountService;
- @Resource
- private IProEconPartWarnCountService proEconPartWarnCountService;
- @Resource
- private IProEconPartWarnCountSubService proEconPartWarnCountSubService;
- @Resource
- private AlertrulefailuresubsService alertrulefailuresubsService;
- @Resource
- private IProEconEarlyWarningMainService proEconEarlyWarningMainService;
- private final double judgescore = 80;
- @Resource
- private IProBasicEquipmentPointService proBasicEquipmentPointsService;
- @Resource
- private IProEconCurveFittingSubService proEconCurveFittingSubService;
- @Resource
- private IProEconEquipmentInfoDayTopService proEconEquipmentInfoDayTopService;
- IRealTimeDataBaseUtil realApiUtil = RealTimeDataBaseFactory.createRealTimeDataBase();
- public void changeHealthModelValue() throws Exception {
- healthInitialService.healthChangeInitial();// 初始化函数算法模型数据
- List<String> codels = new ArrayList<String>();
- codels.add(ContantXk.JKZT002);
- codels.add(ContantXk.JKZT003);
- codels.add(ContantXk.JKZT004);
- codels.add(ContantXk.JKZT005);
- List<ProEconStateJudgmentReal> pols = new ArrayList<>();
- for (ProBasicEquipment wt : CacheContext.wtls) {
- if (wt.getWindpowerstationId().contains("FDC")) {
- ProEconStateJudgmentReal po = new ProEconStateJudgmentReal();
- po.setId(com.gyee.common.model.StringUtils.getUUID());
- po.setWpId(wt.getWindpowerstationId());
- po.setWtId(wt.getId());
- StringBuilder statejudgment = new StringBuilder();
- double fjzt = 0;
- double score = 100;
- ProBasicEquipmentPoint ai = proBasicEquipmentPointsService.getEquipmentPoint(wt.getId(), ContantXk.MXZT);
- PointData point = realApiUtil.getRealData(ai);
- if (StringUtils.notEmp(point)) {
- if (point.getPointValueInDouble() == StatusDetailValue.GZ.getCode()) {
- fjzt = StatusDetailValue.GZ.getCode();
- }
- if (point.getPointValueInDouble() == StatusDetailValue.JX.getCode()) {
- fjzt = StatusDetailValue.JX.getCode();
- }
- }
- // String[] points = new String[codels.size()];
- List<String> points = new ArrayList<>();
- for (int i = 0; i < codels.size(); i++) {
- if (CacheContext.wtpAimap.containsKey(wt.getId())) {
- Map<String, ProBasicEquipmentPoint> wtmap = CacheContext.wtpAimap.get(wt.getId());
- // 判断是否包含该统一编码
- if (wtmap.containsKey(codels.get(i))) {
- ProBasicEquipmentPoint temp = wtmap.get(codels.get(i));
- points.add(temp.getNemCode());
- }
- }
- }
- ProBasicEquipmentPoint fjjkzf = proBasicEquipmentPointsService.getEquipmentPoint(wt.getId(), ContantXk.JKZT100);
- List<PointData> ssvalues = realApiUtil.getRealData(points);
- PointData fjjkzfpoint = new PointData();
- fjjkzfpoint.setEdnaId(fjjkzf.getNemCode());
- fjjkzfpoint.setPointTime(new BigDecimal(new Date().getTime()).divide(new BigDecimal(1000), 0, RoundingMode.HALF_EVEN).longValue());
- double clxzt = 0.0;
- double fdjzt = 0.0;
- double bjzt = 0.0;
- double zkzt = 0.0;
- if (ssvalues.size() == 4) {
- clxzt = ssvalues.get(0).getPointValueInDouble();
- fdjzt = ssvalues.get(1).getPointValueInDouble();
- bjzt = ssvalues.get(2).getPointValueInDouble();
- zkzt = ssvalues.get(3).getPointValueInDouble();
- }
- // 出现故障状态,直接降到10分 差
- if (fjzt ==StatusDetailValue.GZ.getCode() || fjzt ==StatusDetailValue.JX.getCode()) {
- score = 9.0;
- statejudgment.append("1-");
- } else {
- statejudgment.append("0-");
- }
- if(clxzt==4 || fdjzt==4 || bjzt==4 || zkzt==4)
- {
- score = score=setScoreValue(score);
- statejudgment.append("1-");
- }else if(clxzt==3 || fdjzt==3 || bjzt==3 || zkzt==3)
- {
- score = score=setScoreValue(score);
- statejudgment.append("1-");
- }else {
- statejudgment.append("0-");
- }
- // Map<String, Double> xnmap = proEconEquipmentInfoDayTopService.findXnfx(Calendar.getInstance().getTime());
- Map<String, Double> xnmap=HealthInitialService.djpgchagemap;
- if (xnmap.containsKey(wt.getId())) {
- double djpgscore = xnmap.get(wt.getId());
- if (djpgscore < 60) {
- score=setScoreValue(score);
- statejudgment.append("1-");
- }else {
- statejudgment.append("0-");
- }
- } else {
- statejudgment.append("0-");
- }
- // Map<String, List<ProEconCurveFittingSub>> cfmap = null;
- // Calendar c = Calendar.getInstance();
- // c.add(Calendar.DAY_OF_MONTH, -1);
- //
- //
- //// cfmap = proEconCurveFittingSubService.findCurvefittingmapByDate(c.getTime(), wt.getId(), 3.0, 5.0);
- //
- // double qxpc1 = proEconCurveFittingSubService.getNuberValue(cfmap, wt);
- // double xfqrqc = Math.abs(qxpc1);
- Map<String, Double> xfpdmap=HealthInitialService.xfpdchagemap;
- if(xfpdmap.containsKey(wt.getId()))
- {
- double xfqrqc =xfpdmap.get(wt.getId());
- //小风曲线偏差
- if (xfqrqc > 5) {
- score=setScoreValue(score);
- statejudgment.append("1-");
- } else {
- statejudgment.append("0-");
- }
- }else {
- statejudgment.append("0-");
- }
- // cfmap = proEconCurveFittingSubService.findCurvefittingmapByDate(c.getTime(), wt.getId(), 5.0, 11.0);
- // double qxpc2 = proEconCurveFittingSubService.getNuberValue(cfmap, wt);
- // double zcclqc = Math.abs(qxpc2);
- Map<String, Double> clpdmap=HealthInitialService.clpdchagemap;
- if(clpdmap.containsKey(wt.getId()))
- {
- double zcclqc =clpdmap.get(wt.getId());
- //正常出力曲线偏差
- if (zcclqc > 5) {
- score=setScoreValue(score);
- statejudgment.append("1-");
- } else {
- statejudgment.append("0-");
- }
- }else {
- statejudgment.append("0-");
- }
- //
- // cfmap = proEconCurveFittingSubService.findCurvefittingmapByDate(c.getTime(), wt.getId(), 11.0, 25.0);
- // double qxpc3 = proEconCurveFittingSubService.getNuberValue(cfmap, wt);
- // double dfqrqc = Math.abs(qxpc3);
- Map<String, Double> dfpdmap=HealthInitialService.dfpdchagemap;
- if(dfpdmap.containsKey(wt.getId()))
- {
- double dfqrqc =dfpdmap.get(wt.getId());
- //大风曲线偏差
- if (dfqrqc > 5) {
- score=setScoreValue(score);
- statejudgment.append("1-");
- } else {
- statejudgment.append("0-");
- }
- }else {
- statejudgment.append("0-");
- }
- po.setStateJudgment(String.valueOf(statejudgment.substring(0, statejudgment.length() - 1)));
- pols.add(po);
- fjjkzfpoint.setPointValueInDouble(score);
- realApiUtil.updatePoint(fjjkzfpoint);
- }
- }
- proEconStateJudgmentRealService.deleteProEconStateJudgmentReal();
- if (!pols.isEmpty()) {
- proEconStateJudgmentRealService.saveOrUpdateBatch(pols);
- // for (ProEconStateJudgmentReal po : pols) {
- // proEconStateJudgmentRealService.insertStatejudgmentrecord(po);
- // }
- }
- System.out.println("结束健康模型分数计算!");
- }
- private double setScoreValue(double score) {
- if (score >= 90) {
- score = score - 12.0;
- } else if (score < 90 && score >= 60) {
- score = score -9;
- } else if (score < 60 && score >= 30) {
- score = score -6;
- } else if (score < 30 && score >= 10) {
- score = score -3;
- } else {
- score = 9.0;
- }
- return score;
- }
- public void healthJudge() throws Exception {
- ScriptJava sj = new ScriptJava();
- healthInitialService.healthInitial();// 初始化函数算法模型数据
- Map<String, Integer> maps = new HashMap<>();
- Map<String, List<ProEconHealthSystemSub>> hsmap = new HashMap<>();
- Map<String, HcEnum> hcmap = new HashMap<>();
- Map<String, Object> parmarsmap = new HashMap<>();
- for (HcEnum e : HcEnum.values()) {
- hcmap.put(e.getName(), e);
- }
- List<ProEconHealthSystem> hsls = proEconHealthSystemService.queryHealthSystem();
- Map<String, List<ProEconHealthSystemSub>> map = proEconHealthSystemSubService.queryHealthSystemSubMap();
- if (!hsls.isEmpty()) {
- for (ProEconHealthSystem hs : hsls) {
- if (map.containsKey(hs.getId())) {
- List<ProEconHealthSystemSub> subls = map.get(hs.getId());
- if (!subls.isEmpty()) {
- StringBuilder sb = new StringBuilder();
- sb.append(hs.getWpId()).append("_").append(hs.getModelId());
- if (!hsmap.containsKey(String.valueOf(sb))) {
- hsmap.put(String.valueOf(sb), subls);
- }
- }
- }
- }
- }
- proEconStateJudgmentDayService.deleteProEconStateJudgmentDay();
- List<ProEconStateJudgmentDay> polist = new ArrayList<>();
- for (ProBasicEquipment wt : CacheContext.wtls) {
- if (wt.getWindpowerstationId().contains("FDC")) {
- StringBuilder sb = new StringBuilder();
- sb.append(wt.getWindpowerstationId()).append("_").append(wt.getModelId());
- if (hsmap.containsKey(String.valueOf(sb))) {
- List<ProEconHealthSystemSub> subls = hsmap.get(String.valueOf(sb));
- if (!subls.isEmpty()) {
- List<String> descls = new ArrayList<>();
- List<String> formulals = new ArrayList<>();
- double score = 100;
- for (ProEconHealthSystemSub sub : subls) {
- if (StringUtils.notEmp(sub.getFormula())) {
- HealthExpression healthExpression = HealthAnalyzer.getHealthExpression(sub.getFormula());
- ArrayList<String> ucs = healthExpression.getAllUniformCodes();
- judgeParams(hcmap, parmarsmap, wt, ucs);
- }
- Object obj = sj.getCalValue(sub.getFormula(), parmarsmap);
- if (obj instanceof Boolean) {
- boolean value = Boolean.valueOf(String.valueOf(obj));
- if (value) {
- descls.add(sub.getName());
- formulals.add(sub.getFormula());
- double tempscore = null != sub.getFormulaScore() ? sub.getFormulaScore() : 0.0;
- score = score - tempscore;
- }
- }
- }
- ProEconStateJudgmentDay po = new ProEconStateJudgmentDay();
- po.setWpId(wt.getWindpowerstationId());
- po.setWtId(wt.getId());
- Calendar c = Calendar.getInstance();
- c.set(Calendar.HOUR_OF_DAY, 0);
- c.set(Calendar.MINUTE, 0);
- c.set(Calendar.SECOND, 0);
- po.setRecordDate(c.getTime());
- StringBuilder sb2 = new StringBuilder();
- if (!descls.isEmpty()) {
- for (String str : descls) {
- sb2.append(str).append(",");
- }
- String st = String.valueOf(sb2);
- po.setStateJudgment(st.substring(0, st.length() - 1));
- }
- StringBuilder sb3 = new StringBuilder();
- if (!formulals.isEmpty()) {
- for (String str : formulals) {
- sb3.append(str).append(",");
- }
- String st = String.valueOf(sb3);
- po.setFormulas(st.substring(0, st.length() - 1));
- }
- sb3 = new StringBuilder();
- if (!descls.isEmpty()) {
- for (String str : descls) {
- sb3.append(str).append(",");
- }
- String st = String.valueOf(sb3);
- po.setFormulasText(st.substring(0, st.length() - 1));
- }
- po.setScore(score);
- polist.add(po);
- //proEconStateJudgmentDayService.insertStatejudgmentrecord(po);
- logger.debug("完成风机" + po.getWtId() + "_规则" + po.getStateJudgment() + "_分数" + po.getScore());
- }
- }
- }
- }
- if (polist != null && polist.size() > 0) {
- Collections.sort(polist, new Comparator<ProEconStateJudgmentDay>() {
- @Override
- public int compare(ProEconStateJudgmentDay o1, ProEconStateJudgmentDay o2) {
- // 从小到大
- return o1.getScore().compareTo(o2.getScore());
- }
- });
- for (int i = 0; i < polist.size(); i++) {
- ProEconStateJudgmentDay po = polist.get(i);
- Boolean isHave = false;
- // Boolean isHave = wobugeqsService
- // .isQueryThreeDayWobugeqs(po.getWtId());
- List<String> parts = relevancePartTopThree(CacheContext.wtmap.get(po.getWtId()));
- int size = parts.size();
- if (size > 0) {
- if (size == 3) {
- if (parts.get(0) != null) {
- po.setTop1(parts.get(0));
- } else {
- po.setTop1(null);
- }
- if (parts.get(1) != null) {
- po.setTop2(parts.get(1));
- } else {
- po.setTop2(null);
- }
- if (parts.get(2) != null) {
- po.setTop3(parts.get(2));
- } else {
- po.setTop3(null);
- }
- } else if (size == 2) {
- if (parts.get(0) != null) {
- po.setTop1(parts.get(0));
- } else {
- po.setTop1(null);
- }
- if (parts.get(1) != null) {
- po.setTop2(parts.get(1));
- } else {
- po.setTop2(null);
- }
- po.setTop3(null);
- } else if (size == 1) {
- if (parts.get(0) != null) {
- po.setTop1(parts.get(0));
- } else {
- po.setTop1(null);
- }
- po.setTop2(null);
- po.setTop3(null);
- }
- }
- if (isHave == true) {
- po.setJudgmentDescribe("此风机近期有故障记录,故不在推荐范围之内!");
- } else if (po.getScore() <= judgescore) {
- if (maps.containsKey(po.getWpId())) {
- int temp = maps.get(po.getWpId()) + 1;
- if (temp > 2) {
- po.setJudgmentDescribe("设备健康情况不良,但推荐等级偏低,还需继续观察!");
- } else {
- po.setJudgmentDescribe("健康报告达到推荐级别,推荐检修!");
- }
- maps.put(po.getWpId(), temp);
- } else {
- po.setJudgmentDescribe("健康报告达到推荐级别,推荐检修!");
- maps.put(po.getWpId(), 1);
- }
- //po.setJudgmentDescribe("健康报告达到推荐级别,推荐检修!");
- } else {
- po.setJudgmentDescribe("健康指标未达到推荐级别,不予推荐!");
- }
- // proEconStateJudgmentDayService.save(po);
- }
- proEconStateJudgmentDayService.saveOrUpdateBatch(polist);
- }
- }
- /**
- * 关联部件前三名新
- *
- * @param wt
- * @return
- */
- private List<String> relevancePartTopThree(ProBasicEquipment wt) {
- Calendar c = Calendar.getInstance();
- c.set(Calendar.HOUR_OF_DAY, 0);
- c.set(Calendar.MINUTE, 0);
- c.set(Calendar.SECOND, 0);
- c.add(Calendar.DAY_OF_MONTH, -1);
- Date date = c.getTime();
- c.add(Calendar.DAY_OF_MONTH, -1);
- Date endDate = c.getTime();
- c.add(Calendar.DAY_OF_MONTH, -15);
- Date beginDate = c.getTime();
- Map<String, ResultVo> map = new HashMap<String, ResultVo>();
- List<String> resultList = new ArrayList<String>();
- List<Alertrule2> voList = findArsubs(wt.getWindpowerstationId(), wt.getModelId());
- for (Alertrule2 arv : voList) {
- Long snapid = findAlarmsnap(wt, arv.getEdnavalue());
- String cc = findAlarmcount(snapid, beginDate, endDate);
- String[] temp = cc.split(",");
- Double countsum = Double.parseDouble(temp[0]);
- Double benchmark = countsum / 3;
- Double yestodayCount = findyearstodayAlarmcount(snapid, date, date);
- Double deviation = 0.0;
- if (benchmark != 0) {
- deviation = (double) (Math.abs((yestodayCount - benchmark)) / benchmark);
- } else if (yestodayCount > 0) {
- deviation = 1.0;
- }
- ResultVo vo = new ResultVo();
- vo.setBenchmark(benchmark);
- vo.setDeviation(deviation);
- vo.setYestodayCount(yestodayCount);
- map.put(arv.getName(), vo);
- }
- // 这里将map.entrySet()转换成list
- List<Entry<String, ResultVo>> list = new ArrayList<Entry<String, ResultVo>>((Collection<? extends Entry<String, ResultVo>>) map.entrySet());
- // 然后通过比较器来实现排序
- Collections.sort(list, new Comparator<Entry<String, ResultVo>>() {
- @Override
- public int compare(Entry<String, ResultVo> o1, Entry<String, ResultVo> o2) {
- return (o2.getValue().getDeviation()).compareTo(o1.getValue().getDeviation());
- }
- });
- for (int i = 0; i < list.size(); i++) {
- // boolean isContent = isContent(list.get(i).getValue());
- // if (isContent) {
- if (resultList.size() < 3) {
- resultList.add(list.get(i).getKey());
- } else {
- break;
- }
- // } else {
- // continue;
- // }
- }
- return resultList;
- }
- /***
- * 是否满足自定义偏差规则
- *
- */
- @SuppressWarnings("unused")
- private Boolean isContent(ResultVo vo) {
- boolean result = false;
- Double yestodayCount = vo.getYestodayCount();// 实际
- Double benchmark = vo.getBenchmark();// 基准
- int bresult = new Double(benchmark).intValue();
- int bit = ("" + bresult).length();
- if (bit == 1) {
- switch (bresult) {
- case 0:
- result = yestodayCount >= 1.0 ? true : false;
- break;
- case 1:
- result = yestodayCount >= 2.0 ? true : false;
- break;
- case 2:
- result = yestodayCount >= 3.0 ? true : false;
- break;
- case 3:
- result = yestodayCount >= 5.0 ? true : false;
- break;
- case 4:
- result = yestodayCount >= 6.0 ? true : false;
- break;
- case 5:
- result = yestodayCount >= 7.5 ? true : false;
- break;
- case 6:
- result = yestodayCount >= 9.0 ? true : false;
- break;
- case 7:
- result = yestodayCount >= 10.5 ? true : false;
- break;
- case 8:
- result = yestodayCount >= 12.0 ? true : false;
- break;
- case 9:
- result = yestodayCount >= 13.5 ? true : false;
- break;
- default:
- break;
- }
- } else if (bit == 2) {
- Integer firstDigit = getFirstDigit(bresult);
- if (firstDigit == 1) {
- result = yestodayCount >= bresult * 1.1 ? true : false;
- } else if (firstDigit == 2) {
- result = yestodayCount >= bresult * 1.05 ? true : false;
- } else if (firstDigit == 3 || firstDigit == 4) {
- result = yestodayCount >= bresult * 1.03 ? true : false;
- } else if (firstDigit == 5 || firstDigit == 6 || firstDigit == 7 || firstDigit == 8 || firstDigit == 9) {
- result = yestodayCount >= bresult * 1.03 ? true : false;
- } else {
- result = false;
- }
- } else {
- Integer firstDigit = getFirstDigit(bresult);
- if (firstDigit == 1) {
- result = yestodayCount >= bresult * 1.01 ? true : false;
- } else if (firstDigit == 2) {
- result = yestodayCount >= bresult * 1.005 ? true : false;
- } else if (firstDigit == 3 || firstDigit == 4) {
- result = yestodayCount >= bresult * 1.003 ? true : false;
- } else if (firstDigit == 5 || firstDigit == 6 || firstDigit == 7 || firstDigit == 8 || firstDigit == 9) {
- result = yestodayCount >= bresult * 1.003 ? true : false;
- } else {
- result = false;
- }
- }
- return result;
- }
- /**
- * 获取数字的最高位数字
- *
- * @return
- */
- private int getFirstDigit(int number) {
- number = Math.abs(number);
- if (number < 10) {
- return number;
- }
- return getFirstDigit((number - (number % 10)) / 10);
- }
- /**
- * 查询指定时间区间内的规则报警次数
- *
- * @param snapid
- * @param beginDate
- * @param endDate
- * @return
- */
- private String findAlarmcount(Long snapid, Date beginDate, Date endDate) {
- if (snapid != 0) {
- String result = alarmcountsService.findAlarmcount(snapid, beginDate, endDate);
- return result;
- }
- return "0.0,0.0";
- }
- private Double findyearstodayAlarmcount(Long snapid, Date beginDate, Date endDate) {
- if (snapid != 0) {
- Double result = alarmcountsService.findyearstodayAlarmcount(snapid, beginDate, endDate);
- return result;
- }
- return 0.0;
- }
- /**
- * 查询风机单个规则在alermsnap表里id snapid:此id可以关联到alarmcount表查询次数
- *
- * @param wt
- * @param ednavalue
- * @return
- */
- private Long findAlarmsnap(ProBasicEquipment wt, Long ednavalue) {
- if (StringUtils.notEmp(wt) && StringUtils.notEmp(ednavalue)) {
- Long result = alarmsnapsService.getAlarmsnapid(wt.getId(), ednavalue);
- return result;
- }
- return 0l;
- }
- /**
- * 查询单个风场型号的特征规则
- *
- * @param modelid
- * @param staionid
- * @return
- */
- private List<Alertrule2> findArsubs(String staionid, String modelid) {
- if (StringUtils.notEmp(modelid) && StringUtils.notEmp(staionid)) {
- List<Alertrule2> voList = alertrule2sService.findAlertRuleList(staionid, modelid);
- return voList;
- }
- return new ArrayList<>();
- }
- @SuppressWarnings("unused")
- private void saveData(List<ProEconStateJudgmentDay> jkfxorder) {
- for (ProEconStateJudgmentDay vo : jkfxorder) {
- proEconStateJudgmentDayService.insertProEconStateJudgmentDay(vo);
- }
- }
- private List<ProEconStateJudgmentDay> containList(List<ProEconStateJudgmentDay> list, List<ProEconStateJudgmentDay> zlist) {
- for (ProEconStateJudgmentDay statejudgmentrecordVo : list) {
- zlist.add(statejudgmentrecordVo);
- }
- return zlist;
- }
- private List<ProEconStateJudgmentDay> removeDuplicate(List<ProEconStateJudgmentDay> list) {
- for (int i = 0; i < list.size() - 1; i++) {
- for (int j = list.size() - 1; j > i; j--) {
- if (list.get(i).getFormulas().equals(list.get(j).getFormulas()) && list.get(i).getWtId().equals(list.get(j).getWtId()) && list.get(i).getRecordDate().equals(list.get(j).getRecordDate())) {
- list.remove(j);
- }
- }
- }
- return list;
- }
- private void judgeParams(Map<String, HcEnum> hcmap, Map<String, Object> parmarsmap, ProBasicEquipment wt, ArrayList<String> ucs) throws Exception {
- Calendar c = Calendar.getInstance();
- c.set(Calendar.HOUR_OF_DAY, 0);
- c.set(Calendar.MINUTE, 0);
- c.set(Calendar.SECOND, 0);
- if (!ucs.isEmpty()) {
- for (String str : ucs) {
- if (hcmap.containsKey(str)) {
- HcEnum hc = hcmap.get(str);
- Object obj = healthFactoryService.judegeHealth(hc, wt, c);
- if (obj instanceof Boolean) {
- parmarsmap.put(str, Boolean.valueOf(String.valueOf(obj)));
- } else if (obj instanceof Double) {
- parmarsmap.put(str, Double.valueOf(String.valueOf(obj)));
- } else if (obj instanceof Integer) {
- parmarsmap.put(str, Integer.valueOf(String.valueOf(obj)));
- }
- }
- }
- }
- }
- private List<ProEconWindturbineWarnCount> queryWindturbinebjCountByLineAndAlertrule(Alertrule2 ar, String lnid) {
- if (StringUtils.notEmp(ar) && StringUtils.notEmp(lnid)) {
- List<ProEconWindturbineWarnCount> list = proEconWindturbineWarnCountService.queryWindturbinebjCountByLineAndAlertrule(ar.getId(), lnid);
- return list;
- }
- return new ArrayList<>();
- }
- private Boolean isExceedingStandard(ProEconWindturbineWarnCount wb) {
- if (wb.getTotal() == 0 || wb.getTotal() <= wb.getAverageQuantity()) {
- return false;
- }
- if (("" + wb.getAverageQuantity()).length() == 1) {
- if (wb.getAverageQuantity() == 0 && wb.getTotal() >= 8) {
- return true;
- } else if (wb.getAverageQuantity() == 1 && wb.getTotal() >= 20) {
- return true;
- } else if (wb.getAverageQuantity() == 2 && wb.getTotal() >= 30) {
- return true;
- } else if (wb.getAverageQuantity() == 3 && wb.getTotal() >= 30) {
- return true;
- } else if (wb.getAverageQuantity() == 4 && wb.getTotal() >= 30) {
- return true;
- } else if (wb.getAverageQuantity() == 5 && wb.getTotal() >= 30) {
- return true;
- } else if (wb.getAverageQuantity() == 6 && wb.getTotal() >= 30) {
- return true;
- } else if (wb.getAverageQuantity() == 7 && wb.getTotal() >= 30) {
- return true;
- } else if (wb.getAverageQuantity() == 8 && wb.getTotal() >= 30) {
- return true;
- } else if (wb.getAverageQuantity() == 9 && wb.getTotal() >= 30) {
- return true;
- } else {
- return false;
- }
- } else if (("" + wb.getAverageQuantity()).length() == 2) {
- if (getFirstDigit(wb.getAverageQuantity().intValue()) == 1 && wb.getTotal() >= (wb.getAverageQuantity() * 3)) {
- return true;
- } else if (getFirstDigit(wb.getAverageQuantity().intValue()) == 2 && wb.getTotal() >= (wb.getAverageQuantity() * 2)) {
- return true;
- } else if (getFirstDigit(wb.getAverageQuantity().intValue()) == 3 && wb.getTotal() >= (wb.getAverageQuantity() * 1.5)) {
- return true;
- } else if (getFirstDigit(wb.getAverageQuantity().intValue()) == 4 && wb.getTotal() >= (wb.getAverageQuantity() * 1.4)) {
- return true;
- } else if (getFirstDigit(wb.getAverageQuantity().intValue()) == 5 && wb.getTotal() >= (wb.getAverageQuantity() * 1.3)) {
- return true;
- } else if (getFirstDigit(wb.getAverageQuantity().intValue()) == 6 && wb.getTotal() >= (wb.getAverageQuantity() * 1.3)) {
- return true;
- } else if (getFirstDigit(wb.getAverageQuantity().intValue()) == 7 && wb.getTotal() >= (wb.getAverageQuantity() * 1.3)) {
- return true;
- } else if (getFirstDigit(wb.getAverageQuantity().intValue()) == 8 && wb.getTotal() >= (wb.getAverageQuantity() * 1.3)) {
- return true;
- } else if (getFirstDigit(wb.getAverageQuantity().intValue()) == 9 && wb.getTotal() >= (wb.getAverageQuantity() * 1.3)) {
- return true;
- } else {
- return false;
- }
- } else if (("" + wb.getAverageQuantity()).length() == 3) {
- if (getFirstDigit(wb.getAverageQuantity().intValue()) == 1 && wb.getTotal() >= (wb.getAverageQuantity() * 2)) {
- return true;
- } else if (getFirstDigit(wb.getAverageQuantity().intValue()) == 2 && wb.getTotal() >= (wb.getAverageQuantity() * 1.5)) {
- return true;
- } else if (getFirstDigit(wb.getAverageQuantity().intValue()) == 3 && wb.getTotal() >= (wb.getAverageQuantity() * 1.4)) {
- return true;
- } else if (getFirstDigit(wb.getAverageQuantity().intValue()) == 4 && wb.getTotal() >= (wb.getAverageQuantity() * 1.3)) {
- return true;
- } else if (getFirstDigit(wb.getAverageQuantity().intValue()) == 5 && wb.getTotal() >= (wb.getAverageQuantity() * 1.3)) {
- return true;
- } else if (getFirstDigit(wb.getAverageQuantity().intValue()) == 6 && wb.getTotal() >= (wb.getAverageQuantity() * 1.3)) {
- return true;
- } else if (getFirstDigit(wb.getAverageQuantity().intValue()) == 7 && wb.getTotal() >= (wb.getAverageQuantity() * 1.3)) {
- return true;
- } else if (getFirstDigit(wb.getAverageQuantity().intValue()) == 8 && wb.getTotal() >= (wb.getAverageQuantity() * 1.3)) {
- return true;
- } else if (getFirstDigit(wb.getAverageQuantity().intValue()) == 9 && wb.getTotal() >= (wb.getAverageQuantity() * 1.3)) {
- return true;
- } else {
- return false;
- }
- } else {
- if (getFirstDigit(wb.getAverageQuantity().intValue()) == 1 && wb.getTotal() >= (wb.getAverageQuantity() * 1.9)) {
- return true;
- } else if (getFirstDigit(wb.getAverageQuantity().intValue()) == 2 && wb.getTotal() >= (wb.getAverageQuantity() * 1.5)) {
- return true;
- } else if (getFirstDigit(wb.getAverageQuantity().intValue()) == 3 && wb.getTotal() >= (wb.getAverageQuantity() * 1.4)) {
- return true;
- } else if (getFirstDigit(wb.getAverageQuantity().intValue()) == 4 && wb.getTotal() >= (wb.getAverageQuantity() * 1.3)) {
- return true;
- } else if (getFirstDigit(wb.getAverageQuantity().intValue()) == 5 && wb.getTotal() >= (wb.getAverageQuantity() * 1.2)) {
- return true;
- } else if (getFirstDigit(wb.getAverageQuantity().intValue()) == 6 && wb.getTotal() >= (wb.getAverageQuantity() * 1.2)) {
- return true;
- } else if (getFirstDigit(wb.getAverageQuantity().intValue()) == 7 && wb.getTotal() >= (wb.getAverageQuantity() * 1.2)) {
- return true;
- } else if (getFirstDigit(wb.getAverageQuantity().intValue()) == 8 && wb.getTotal() >= (wb.getAverageQuantity() * 1.2)) {
- return true;
- } else if (getFirstDigit(wb.getAverageQuantity().intValue()) == 9 && wb.getTotal() >= (wb.getAverageQuantity() * 1.2)) {
- return true;
- } else {
- return false;
- }
- }
- }
- private List<String> queryWindturbinebjCountLine(Alertrule2 ar) {
- if (StringUtils.notEmp(ar)) {
- List<String> lnids = proEconWindturbineWarnCountService.queryWindturbinebjCountLine(ar.getId());
- return lnids;
- }
- return new ArrayList<>();
- }
- public void savePartbjcount() {
- Calendar c = Calendar.getInstance();
- c.set(Calendar.HOUR_OF_DAY, 0);
- c.set(Calendar.MINUTE, 0);
- c.set(Calendar.SECOND, 0);
- c.add(Calendar.DAY_OF_MONTH, -1);
- Date date = c.getTime();
- proEconPartWarnCountService.deletePartbjcount(date);
- List<Alertrule2> ars = CacheContext.alarmrulels;
- for (Alertrule2 ar : ars) {
- List<String> lnids = queryWindturbinebjCountLine(ar);
- for (String lnid : lnids) {
- int count = 0;
- String part = null;
- List<ProEconWindturbineWarnCount> wclist = queryWindturbinebjCountByLineAndAlertrule(ar, lnid);
- for (ProEconWindturbineWarnCount wc : wclist) {
- boolean temp = isExceedingStandard(wc);
- part = wc.getPart();
- if (temp == true) {
- count++;
- }
- }
- if (count >= (wclist.size() * 0.9)) {
- String uuid = UUID.randomUUID().toString().replaceAll("-", "");
- ProEconPartWarnCount po = new ProEconPartWarnCount();
- po.setId(uuid);
- po.setLnId(lnid);
- po.setAlertruleId(ar.getId());
- po.setPart(part);
- po.setRecordDate(DateUtils.truncate(date));
- proEconPartWarnCountService.insertPartbjcount(po);
- for (ProEconWindturbineWarnCount wbc : wclist) {
- if (isExceedingStandard(wbc) == true) {
- String id = UUID.randomUUID().toString().replaceAll("-", "");
- ProEconPartWarnCountSub posub = new ProEconPartWarnCountSub();
- posub.setId(id);
- posub.setWtId(wbc.getWtId());
- posub.setTotal(wbc.getTotal());
- posub.setAverageQuantity(wbc.getAverageQuantity());
- posub.setPid(uuid);
- proEconPartWarnCountSubService.insertPartbjcountsub(posub);
- }
- }
- }
- }
- }
- }
- /**
- * 保存
- *
- * @return
- */
- public void saveWindturbineBjCount() {
- Calendar c = Calendar.getInstance();
- c.set(Calendar.HOUR_OF_DAY, 0);
- c.set(Calendar.MINUTE, 0);
- c.set(Calendar.SECOND, 0);
- c.add(Calendar.DAY_OF_MONTH, -2);
- Date endDate = c.getTime();
- c.add(Calendar.DAY_OF_MONTH, -6);
- Date beginDate = c.getTime();
- c.add(Calendar.DAY_OF_MONTH, 7);
- Date date = c.getTime();
- List<ProEconWindturbineWarnCount> melist = new ArrayList<ProEconWindturbineWarnCount>();
- proEconWindturbineWarnCountService.deleteWindturbinebjcount(date);
- for (ProBasicLine line : CacheContext.lines) {
- List<ProBasicEquipment> wtls = CacheContext.wtlinemap.get(line.getId());
- List<DataVo> arlist = findAlertRuleList(line);
- if (arlist != null && arlist.size() > 0) {
- for (DataVo ar : arlist) {
- for (ProBasicEquipment w : wtls) {
- // if (wobugeqsService
- // .isQueryThreeDayWobugeqs(w.getId()) == false) {
- Long snapid = getAlarmsnapid(w.getId(), ar.getEdnavalue());
- String cc = findAlarmcount(snapid, beginDate, endDate);
- String[] s = cc.split(",");
- Double avg = 0.0;
- if (Double.parseDouble(s[1]) != 0) {
- avg = (Double.parseDouble(s[0]) / Double.parseDouble(s[1]));
- }
- Double sjcount = findyearstodayAlarmcount(snapid, date, date);
- String uuid = UUID.randomUUID().toString().replaceAll("-", "");
- String part = getPartByAlertruleid(ar.getId());
- ProEconWindturbineWarnCount wbc = new ProEconWindturbineWarnCount();
- wbc.setId(uuid);
- wbc.setWtId(w.getId());
- wbc.setLnId(w.getLineId());
- wbc.setWpId(w.getWindpowerstationId());
- wbc.setAlertruleId(ar.getId());
- wbc.setAlertruleName(ar.getName());
- wbc.setPart(part);
- wbc.setTotal(sjcount.intValue());
- wbc.setAverageQuantity(avg);
- wbc.setRecordDate(date);
- melist.add(wbc);
- // }
- }
- }
- }
- }
- insertWindturbineBjCount(melist);
- }
- /**
- * 向WindturbineBjCount表插入数据
- *
- * @param melist
- */
- private void insertWindturbineBjCount(List<ProEconWindturbineWarnCount> melist) {
- for (ProEconWindturbineWarnCount wb : melist) {
- proEconWindturbineWarnCountService.insertWindturbineBjCount(wb);
- }
- }
- /**
- * 根据alertrule2id查询所属分组
- *
- * @param id
- * @return
- */
- private String getPartByAlertruleid(String id) {
- if (StringUtils.notEmp(id)) {
- List<String> list = alertrulefailuresubsService.getPartByAlertruleid(id);
- if (!list.isEmpty()) {
- return list.get(0);
- }
- }
- return "";
- }
- private Long getAlarmsnapid(String wtid, Long ednavalue) {
- if (StringUtils.notEmp(wtid) && StringUtils.notEmp(ednavalue)) {
- Long snapid = alarmsnapsService.getAlarmsnapid(wtid, ednavalue);
- return snapid;
- }
- return 0l;
- }
- private List<DataVo> findAlertRuleList(ProBasicLine line) {
- List<ProBasicEquipment> wt1 = CacheContext.wtlinemap.get(line.getId());
- ProBasicEquipment wt = wt1.get(0);
- List<DataVo> dos = new ArrayList<>();
- if (StringUtils.notEmp(line)) {
- List<Alertrule2> ls = alertrule2sService.findAlertRuleList(wt.getWindpowerstationId(), wt.getModelId());
- if (!ls.isEmpty()) {
- for (Alertrule2 ar : ls) {
- DataVo vo = new DataVo();
- vo.setId(ar.getId());
- vo.setEdnavalue(ar.getEdnavalue());
- vo.setName(ar.getName());
- dos.add(vo);
- }
- }
- }
- return dos;
- }
- public void test1() {
- final CountDownLatch countDownLatch = new CountDownLatch(6);
- for (int i = 0; i < 3; i++) {
- threadPoolTaskExecutor.execute(new Runnable() {
- // 解决多线程操作同一集合
- @Override
- public void run() {
- // logger.debug("启动:" + wt.getId() + "---" + ar.getId()
- // + "--特征分析子线程--");
- //synchronized (this) {
- try {
- for (int j = 0; j < 2; j++) {
- System.out.println("======" + j);
- // if(i==funList.size()-1)
- // {
- // if (obj instanceof Boolean) {
- // if (true == (boolean) obj) {
- // // atomic.getAndIncrement();
- // time++;
- // break;
- // }
- // }
- // }
- Thread.sleep(10000);
- // logger.debug("剩余线程数:"+countDownLatch.getTotal());
- // logger.debug("完成:" + wt.getId() + "---" +
- // ar.getId() + "--特征分析子线程--");
- //
- }
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- countDownLatch.countDown();// 工人完成工作,计数器减一
- }
- }
- });
- }
- // threadPoolTaskExecutor.shutdown();
- try {
- countDownLatch.await();
- } catch (Exception e) {
- e.printStackTrace();
- }
- // logger.debug("特征提取完成!");
- }
- }
|