HealthJudgeService.java 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138
  1. package com.gyee.healthmodel.service;
  2. import com.gyee.common.contant.ContantXk;
  3. import com.gyee.common.model.PointData;
  4. import com.gyee.healthmodel.init.CacheContext;
  5. import com.gyee.healthmodel.model.auto.*;
  6. import com.gyee.healthmodel.model.vo.StatusDetailValue;
  7. import com.gyee.healthmodel.service.auto.*;
  8. import com.gyee.healthmodel.util.*;
  9. import com.gyee.healthmodel.vo.healthsystem.DataVo;
  10. import com.gyee.healthmodel.vo.healthsystem.HealthExpression;
  11. import com.gyee.healthmodel.vo.healthsystem.ResultVo;
  12. import org.slf4j.Logger;
  13. import org.slf4j.LoggerFactory;
  14. import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
  15. import org.springframework.stereotype.Service;
  16. import javax.annotation.Resource;
  17. import java.math.BigDecimal;
  18. import java.math.RoundingMode;
  19. import java.util.*;
  20. import java.util.Map.Entry;
  21. import java.util.concurrent.CountDownLatch;
  22. @Service
  23. public class HealthJudgeService {
  24. private static Logger logger = LoggerFactory.getLogger(HealthJudgeService.class);
  25. @Resource
  26. private IProEconHealthSystemService proEconHealthSystemService;
  27. @Resource
  28. private IProEconHealthSystemSubService proEconHealthSystemSubService;
  29. @Resource
  30. private ThreadPoolTaskExecutor threadPoolTaskExecutor;
  31. @Resource
  32. private IProEconStateJudgmentDayService proEconStateJudgmentDayService;
  33. @Resource
  34. private IProEconStateJudgmentRealService proEconStateJudgmentRealService;
  35. @Resource
  36. private HealthInitialService healthInitialService;
  37. @Resource
  38. private HealthFactoryService healthFactoryService;
  39. @Resource
  40. private AlarmcountsService alarmcountsService;
  41. @Resource
  42. private AlarmsnapsService alarmsnapsService;
  43. @Resource
  44. private Alertrule2sService alertrule2sService;
  45. @Resource
  46. private IProEconWindturbineWarnCountService proEconWindturbineWarnCountService;
  47. @Resource
  48. private IProEconPartWarnCountService proEconPartWarnCountService;
  49. @Resource
  50. private IProEconPartWarnCountSubService proEconPartWarnCountSubService;
  51. @Resource
  52. private AlertrulefailuresubsService alertrulefailuresubsService;
  53. @Resource
  54. private IProEconEarlyWarningMainService proEconEarlyWarningMainService;
  55. private final double judgescore = 80;
  56. @Resource
  57. private IProBasicEquipmentPointService proBasicEquipmentPointsService;
  58. @Resource
  59. private IProEconCurveFittingSubService proEconCurveFittingSubService;
  60. @Resource
  61. private IProEconEquipmentInfoDayTopService proEconEquipmentInfoDayTopService;
  62. IRealTimeDataBaseUtil realApiUtil = RealTimeDataBaseFactory.createRealTimeDataBase();
  63. public void changeHealthModelValue() throws Exception {
  64. healthInitialService.healthChangeInitial();// 初始化函数算法模型数据
  65. List<String> codels = new ArrayList<String>();
  66. codels.add(ContantXk.JKZT002);
  67. codels.add(ContantXk.JKZT003);
  68. codels.add(ContantXk.JKZT004);
  69. codels.add(ContantXk.JKZT005);
  70. List<ProEconStateJudgmentReal> pols = new ArrayList<>();
  71. for (ProBasicEquipment wt : CacheContext.wtls) {
  72. if (wt.getWindpowerstationId().contains("FDC")) {
  73. ProEconStateJudgmentReal po = new ProEconStateJudgmentReal();
  74. po.setId(com.gyee.common.model.StringUtils.getUUID());
  75. po.setWpId(wt.getWindpowerstationId());
  76. po.setWtId(wt.getId());
  77. StringBuilder statejudgment = new StringBuilder();
  78. double fjzt = 0;
  79. double score = 100;
  80. ProBasicEquipmentPoint ai = proBasicEquipmentPointsService.getEquipmentPoint(wt.getId(), ContantXk.MXZT);
  81. PointData point = realApiUtil.getRealData(ai);
  82. if (StringUtils.notEmp(point)) {
  83. if (point.getPointValueInDouble() == StatusDetailValue.GZ.getCode()) {
  84. fjzt = StatusDetailValue.GZ.getCode();
  85. }
  86. if (point.getPointValueInDouble() == StatusDetailValue.JX.getCode()) {
  87. fjzt = StatusDetailValue.JX.getCode();
  88. }
  89. }
  90. // String[] points = new String[codels.size()];
  91. List<String> points = new ArrayList<>();
  92. for (int i = 0; i < codels.size(); i++) {
  93. if (CacheContext.wtpAimap.containsKey(wt.getId())) {
  94. Map<String, ProBasicEquipmentPoint> wtmap = CacheContext.wtpAimap.get(wt.getId());
  95. // 判断是否包含该统一编码
  96. if (wtmap.containsKey(codels.get(i))) {
  97. ProBasicEquipmentPoint temp = wtmap.get(codels.get(i));
  98. points.add(temp.getNemCode());
  99. }
  100. }
  101. }
  102. ProBasicEquipmentPoint fjjkzf = proBasicEquipmentPointsService.getEquipmentPoint(wt.getId(), ContantXk.JKZT100);
  103. List<PointData> ssvalues = realApiUtil.getRealData(points);
  104. PointData fjjkzfpoint = new PointData();
  105. fjjkzfpoint.setEdnaId(fjjkzf.getNemCode());
  106. fjjkzfpoint.setPointTime(new BigDecimal(new Date().getTime()).divide(new BigDecimal(1000), 0, RoundingMode.HALF_EVEN).longValue());
  107. double clxzt = 0.0;
  108. double fdjzt = 0.0;
  109. double bjzt = 0.0;
  110. double zkzt = 0.0;
  111. if (ssvalues.size() == 4) {
  112. clxzt = ssvalues.get(0).getPointValueInDouble();
  113. fdjzt = ssvalues.get(1).getPointValueInDouble();
  114. bjzt = ssvalues.get(2).getPointValueInDouble();
  115. zkzt = ssvalues.get(3).getPointValueInDouble();
  116. }
  117. // 出现故障状态,直接降到10分 差
  118. if (fjzt ==StatusDetailValue.GZ.getCode() || fjzt ==StatusDetailValue.JX.getCode()) {
  119. score = 9.0;
  120. statejudgment.append("1-");
  121. } else {
  122. statejudgment.append("0-");
  123. }
  124. if(clxzt==4 || fdjzt==4 || bjzt==4 || zkzt==4)
  125. {
  126. score = score=setScoreValue(score);
  127. statejudgment.append("1-");
  128. }else if(clxzt==3 || fdjzt==3 || bjzt==3 || zkzt==3)
  129. {
  130. score = score=setScoreValue(score);
  131. statejudgment.append("1-");
  132. }else {
  133. statejudgment.append("0-");
  134. }
  135. // Map<String, Double> xnmap = proEconEquipmentInfoDayTopService.findXnfx(Calendar.getInstance().getTime());
  136. Map<String, Double> xnmap=HealthInitialService.djpgchagemap;
  137. if (xnmap.containsKey(wt.getId())) {
  138. double djpgscore = xnmap.get(wt.getId());
  139. if (djpgscore < 60) {
  140. score=setScoreValue(score);
  141. statejudgment.append("1-");
  142. }else {
  143. statejudgment.append("0-");
  144. }
  145. } else {
  146. statejudgment.append("0-");
  147. }
  148. // Map<String, List<ProEconCurveFittingSub>> cfmap = null;
  149. // Calendar c = Calendar.getInstance();
  150. // c.add(Calendar.DAY_OF_MONTH, -1);
  151. //
  152. //
  153. //// cfmap = proEconCurveFittingSubService.findCurvefittingmapByDate(c.getTime(), wt.getId(), 3.0, 5.0);
  154. //
  155. // double qxpc1 = proEconCurveFittingSubService.getNuberValue(cfmap, wt);
  156. // double xfqrqc = Math.abs(qxpc1);
  157. Map<String, Double> xfpdmap=HealthInitialService.xfpdchagemap;
  158. if(xfpdmap.containsKey(wt.getId()))
  159. {
  160. double xfqrqc =xfpdmap.get(wt.getId());
  161. //小风曲线偏差
  162. if (xfqrqc > 5) {
  163. score=setScoreValue(score);
  164. statejudgment.append("1-");
  165. } else {
  166. statejudgment.append("0-");
  167. }
  168. }else {
  169. statejudgment.append("0-");
  170. }
  171. // cfmap = proEconCurveFittingSubService.findCurvefittingmapByDate(c.getTime(), wt.getId(), 5.0, 11.0);
  172. // double qxpc2 = proEconCurveFittingSubService.getNuberValue(cfmap, wt);
  173. // double zcclqc = Math.abs(qxpc2);
  174. Map<String, Double> clpdmap=HealthInitialService.clpdchagemap;
  175. if(clpdmap.containsKey(wt.getId()))
  176. {
  177. double zcclqc =clpdmap.get(wt.getId());
  178. //正常出力曲线偏差
  179. if (zcclqc > 5) {
  180. score=setScoreValue(score);
  181. statejudgment.append("1-");
  182. } else {
  183. statejudgment.append("0-");
  184. }
  185. }else {
  186. statejudgment.append("0-");
  187. }
  188. //
  189. // cfmap = proEconCurveFittingSubService.findCurvefittingmapByDate(c.getTime(), wt.getId(), 11.0, 25.0);
  190. // double qxpc3 = proEconCurveFittingSubService.getNuberValue(cfmap, wt);
  191. // double dfqrqc = Math.abs(qxpc3);
  192. Map<String, Double> dfpdmap=HealthInitialService.dfpdchagemap;
  193. if(dfpdmap.containsKey(wt.getId()))
  194. {
  195. double dfqrqc =dfpdmap.get(wt.getId());
  196. //大风曲线偏差
  197. if (dfqrqc > 5) {
  198. score=setScoreValue(score);
  199. statejudgment.append("1-");
  200. } else {
  201. statejudgment.append("0-");
  202. }
  203. }else {
  204. statejudgment.append("0-");
  205. }
  206. po.setStateJudgment(String.valueOf(statejudgment.substring(0, statejudgment.length() - 1)));
  207. pols.add(po);
  208. fjjkzfpoint.setPointValueInDouble(score);
  209. realApiUtil.updatePoint(fjjkzfpoint);
  210. }
  211. }
  212. proEconStateJudgmentRealService.deleteProEconStateJudgmentReal();
  213. if (!pols.isEmpty()) {
  214. proEconStateJudgmentRealService.saveOrUpdateBatch(pols);
  215. // for (ProEconStateJudgmentReal po : pols) {
  216. // proEconStateJudgmentRealService.insertStatejudgmentrecord(po);
  217. // }
  218. }
  219. System.out.println("结束健康模型分数计算!");
  220. }
  221. private double setScoreValue(double score) {
  222. if (score >= 90) {
  223. score = score - 12.0;
  224. } else if (score < 90 && score >= 60) {
  225. score = score -9;
  226. } else if (score < 60 && score >= 30) {
  227. score = score -6;
  228. } else if (score < 30 && score >= 10) {
  229. score = score -3;
  230. } else {
  231. score = 9.0;
  232. }
  233. return score;
  234. }
  235. public void healthJudge() throws Exception {
  236. ScriptJava sj = new ScriptJava();
  237. healthInitialService.healthInitial();// 初始化函数算法模型数据
  238. Map<String, Integer> maps = new HashMap<>();
  239. Map<String, List<ProEconHealthSystemSub>> hsmap = new HashMap<>();
  240. Map<String, HcEnum> hcmap = new HashMap<>();
  241. Map<String, Object> parmarsmap = new HashMap<>();
  242. for (HcEnum e : HcEnum.values()) {
  243. hcmap.put(e.getName(), e);
  244. }
  245. List<ProEconHealthSystem> hsls = proEconHealthSystemService.queryHealthSystem();
  246. Map<String, List<ProEconHealthSystemSub>> map = proEconHealthSystemSubService.queryHealthSystemSubMap();
  247. if (!hsls.isEmpty()) {
  248. for (ProEconHealthSystem hs : hsls) {
  249. if (map.containsKey(hs.getId())) {
  250. List<ProEconHealthSystemSub> subls = map.get(hs.getId());
  251. if (!subls.isEmpty()) {
  252. StringBuilder sb = new StringBuilder();
  253. sb.append(hs.getWpId()).append("_").append(hs.getModelId());
  254. if (!hsmap.containsKey(String.valueOf(sb))) {
  255. hsmap.put(String.valueOf(sb), subls);
  256. }
  257. }
  258. }
  259. }
  260. }
  261. proEconStateJudgmentDayService.deleteProEconStateJudgmentDay();
  262. List<ProEconStateJudgmentDay> polist = new ArrayList<>();
  263. for (ProBasicEquipment wt : CacheContext.wtls) {
  264. if (wt.getWindpowerstationId().contains("FDC")) {
  265. StringBuilder sb = new StringBuilder();
  266. sb.append(wt.getWindpowerstationId()).append("_").append(wt.getModelId());
  267. if (hsmap.containsKey(String.valueOf(sb))) {
  268. List<ProEconHealthSystemSub> subls = hsmap.get(String.valueOf(sb));
  269. if (!subls.isEmpty()) {
  270. List<String> descls = new ArrayList<>();
  271. List<String> formulals = new ArrayList<>();
  272. double score = 100;
  273. for (ProEconHealthSystemSub sub : subls) {
  274. if (StringUtils.notEmp(sub.getFormula())) {
  275. HealthExpression healthExpression = HealthAnalyzer.getHealthExpression(sub.getFormula());
  276. ArrayList<String> ucs = healthExpression.getAllUniformCodes();
  277. judgeParams(hcmap, parmarsmap, wt, ucs);
  278. }
  279. Object obj = sj.getCalValue(sub.getFormula(), parmarsmap);
  280. if (obj instanceof Boolean) {
  281. boolean value = Boolean.valueOf(String.valueOf(obj));
  282. if (value) {
  283. descls.add(sub.getName());
  284. formulals.add(sub.getFormula());
  285. double tempscore = null != sub.getFormulaScore() ? sub.getFormulaScore() : 0.0;
  286. score = score - tempscore;
  287. }
  288. }
  289. }
  290. ProEconStateJudgmentDay po = new ProEconStateJudgmentDay();
  291. po.setWpId(wt.getWindpowerstationId());
  292. po.setWtId(wt.getId());
  293. Calendar c = Calendar.getInstance();
  294. c.set(Calendar.HOUR_OF_DAY, 0);
  295. c.set(Calendar.MINUTE, 0);
  296. c.set(Calendar.SECOND, 0);
  297. po.setRecordDate(c.getTime());
  298. StringBuilder sb2 = new StringBuilder();
  299. if (!descls.isEmpty()) {
  300. for (String str : descls) {
  301. sb2.append(str).append(",");
  302. }
  303. String st = String.valueOf(sb2);
  304. po.setStateJudgment(st.substring(0, st.length() - 1));
  305. }
  306. StringBuilder sb3 = new StringBuilder();
  307. if (!formulals.isEmpty()) {
  308. for (String str : formulals) {
  309. sb3.append(str).append(",");
  310. }
  311. String st = String.valueOf(sb3);
  312. po.setFormulas(st.substring(0, st.length() - 1));
  313. }
  314. sb3 = new StringBuilder();
  315. if (!descls.isEmpty()) {
  316. for (String str : descls) {
  317. sb3.append(str).append(",");
  318. }
  319. String st = String.valueOf(sb3);
  320. po.setFormulasText(st.substring(0, st.length() - 1));
  321. }
  322. po.setScore(score);
  323. polist.add(po);
  324. //proEconStateJudgmentDayService.insertStatejudgmentrecord(po);
  325. logger.debug("完成风机" + po.getWtId() + "_规则" + po.getStateJudgment() + "_分数" + po.getScore());
  326. }
  327. }
  328. }
  329. }
  330. if (polist != null && polist.size() > 0) {
  331. Collections.sort(polist, new Comparator<ProEconStateJudgmentDay>() {
  332. @Override
  333. public int compare(ProEconStateJudgmentDay o1, ProEconStateJudgmentDay o2) {
  334. // 从小到大
  335. return o1.getScore().compareTo(o2.getScore());
  336. }
  337. });
  338. for (int i = 0; i < polist.size(); i++) {
  339. ProEconStateJudgmentDay po = polist.get(i);
  340. Boolean isHave = false;
  341. // Boolean isHave = wobugeqsService
  342. // .isQueryThreeDayWobugeqs(po.getWtId());
  343. List<String> parts = relevancePartTopThree(CacheContext.wtmap.get(po.getWtId()));
  344. int size = parts.size();
  345. if (size > 0) {
  346. if (size == 3) {
  347. if (parts.get(0) != null) {
  348. po.setTop1(parts.get(0));
  349. } else {
  350. po.setTop1(null);
  351. }
  352. if (parts.get(1) != null) {
  353. po.setTop2(parts.get(1));
  354. } else {
  355. po.setTop2(null);
  356. }
  357. if (parts.get(2) != null) {
  358. po.setTop3(parts.get(2));
  359. } else {
  360. po.setTop3(null);
  361. }
  362. } else if (size == 2) {
  363. if (parts.get(0) != null) {
  364. po.setTop1(parts.get(0));
  365. } else {
  366. po.setTop1(null);
  367. }
  368. if (parts.get(1) != null) {
  369. po.setTop2(parts.get(1));
  370. } else {
  371. po.setTop2(null);
  372. }
  373. po.setTop3(null);
  374. } else if (size == 1) {
  375. if (parts.get(0) != null) {
  376. po.setTop1(parts.get(0));
  377. } else {
  378. po.setTop1(null);
  379. }
  380. po.setTop2(null);
  381. po.setTop3(null);
  382. }
  383. }
  384. if (isHave == true) {
  385. po.setJudgmentDescribe("此风机近期有故障记录,故不在推荐范围之内!");
  386. } else if (po.getScore() <= judgescore) {
  387. if (maps.containsKey(po.getWpId())) {
  388. int temp = maps.get(po.getWpId()) + 1;
  389. if (temp > 2) {
  390. po.setJudgmentDescribe("设备健康情况不良,但推荐等级偏低,还需继续观察!");
  391. } else {
  392. po.setJudgmentDescribe("健康报告达到推荐级别,推荐检修!");
  393. }
  394. maps.put(po.getWpId(), temp);
  395. } else {
  396. po.setJudgmentDescribe("健康报告达到推荐级别,推荐检修!");
  397. maps.put(po.getWpId(), 1);
  398. }
  399. //po.setJudgmentDescribe("健康报告达到推荐级别,推荐检修!");
  400. } else {
  401. po.setJudgmentDescribe("健康指标未达到推荐级别,不予推荐!");
  402. }
  403. // proEconStateJudgmentDayService.save(po);
  404. }
  405. proEconStateJudgmentDayService.saveOrUpdateBatch(polist);
  406. }
  407. }
  408. /**
  409. * 关联部件前三名新
  410. *
  411. * @param wt
  412. * @return
  413. */
  414. private List<String> relevancePartTopThree(ProBasicEquipment wt) {
  415. Calendar c = Calendar.getInstance();
  416. c.set(Calendar.HOUR_OF_DAY, 0);
  417. c.set(Calendar.MINUTE, 0);
  418. c.set(Calendar.SECOND, 0);
  419. c.add(Calendar.DAY_OF_MONTH, -1);
  420. Date date = c.getTime();
  421. c.add(Calendar.DAY_OF_MONTH, -1);
  422. Date endDate = c.getTime();
  423. c.add(Calendar.DAY_OF_MONTH, -15);
  424. Date beginDate = c.getTime();
  425. Map<String, ResultVo> map = new HashMap<String, ResultVo>();
  426. List<String> resultList = new ArrayList<String>();
  427. List<Alertrule2> voList = findArsubs(wt.getWindpowerstationId(), wt.getModelId());
  428. for (Alertrule2 arv : voList) {
  429. Long snapid = findAlarmsnap(wt, arv.getEdnavalue());
  430. String cc = findAlarmcount(snapid, beginDate, endDate);
  431. String[] temp = cc.split(",");
  432. Double countsum = Double.parseDouble(temp[0]);
  433. Double benchmark = countsum / 3;
  434. Double yestodayCount = findyearstodayAlarmcount(snapid, date, date);
  435. Double deviation = 0.0;
  436. if (benchmark != 0) {
  437. deviation = (double) (Math.abs((yestodayCount - benchmark)) / benchmark);
  438. } else if (yestodayCount > 0) {
  439. deviation = 1.0;
  440. }
  441. ResultVo vo = new ResultVo();
  442. vo.setBenchmark(benchmark);
  443. vo.setDeviation(deviation);
  444. vo.setYestodayCount(yestodayCount);
  445. map.put(arv.getName(), vo);
  446. }
  447. // 这里将map.entrySet()转换成list
  448. List<Entry<String, ResultVo>> list = new ArrayList<Entry<String, ResultVo>>((Collection<? extends Entry<String, ResultVo>>) map.entrySet());
  449. // 然后通过比较器来实现排序
  450. Collections.sort(list, new Comparator<Entry<String, ResultVo>>() {
  451. @Override
  452. public int compare(Entry<String, ResultVo> o1, Entry<String, ResultVo> o2) {
  453. return (o2.getValue().getDeviation()).compareTo(o1.getValue().getDeviation());
  454. }
  455. });
  456. for (int i = 0; i < list.size(); i++) {
  457. // boolean isContent = isContent(list.get(i).getValue());
  458. // if (isContent) {
  459. if (resultList.size() < 3) {
  460. resultList.add(list.get(i).getKey());
  461. } else {
  462. break;
  463. }
  464. // } else {
  465. // continue;
  466. // }
  467. }
  468. return resultList;
  469. }
  470. /***
  471. * 是否满足自定义偏差规则
  472. *
  473. */
  474. @SuppressWarnings("unused")
  475. private Boolean isContent(ResultVo vo) {
  476. boolean result = false;
  477. Double yestodayCount = vo.getYestodayCount();// 实际
  478. Double benchmark = vo.getBenchmark();// 基准
  479. int bresult = new Double(benchmark).intValue();
  480. int bit = ("" + bresult).length();
  481. if (bit == 1) {
  482. switch (bresult) {
  483. case 0:
  484. result = yestodayCount >= 1.0 ? true : false;
  485. break;
  486. case 1:
  487. result = yestodayCount >= 2.0 ? true : false;
  488. break;
  489. case 2:
  490. result = yestodayCount >= 3.0 ? true : false;
  491. break;
  492. case 3:
  493. result = yestodayCount >= 5.0 ? true : false;
  494. break;
  495. case 4:
  496. result = yestodayCount >= 6.0 ? true : false;
  497. break;
  498. case 5:
  499. result = yestodayCount >= 7.5 ? true : false;
  500. break;
  501. case 6:
  502. result = yestodayCount >= 9.0 ? true : false;
  503. break;
  504. case 7:
  505. result = yestodayCount >= 10.5 ? true : false;
  506. break;
  507. case 8:
  508. result = yestodayCount >= 12.0 ? true : false;
  509. break;
  510. case 9:
  511. result = yestodayCount >= 13.5 ? true : false;
  512. break;
  513. default:
  514. break;
  515. }
  516. } else if (bit == 2) {
  517. Integer firstDigit = getFirstDigit(bresult);
  518. if (firstDigit == 1) {
  519. result = yestodayCount >= bresult * 1.1 ? true : false;
  520. } else if (firstDigit == 2) {
  521. result = yestodayCount >= bresult * 1.05 ? true : false;
  522. } else if (firstDigit == 3 || firstDigit == 4) {
  523. result = yestodayCount >= bresult * 1.03 ? true : false;
  524. } else if (firstDigit == 5 || firstDigit == 6 || firstDigit == 7 || firstDigit == 8 || firstDigit == 9) {
  525. result = yestodayCount >= bresult * 1.03 ? true : false;
  526. } else {
  527. result = false;
  528. }
  529. } else {
  530. Integer firstDigit = getFirstDigit(bresult);
  531. if (firstDigit == 1) {
  532. result = yestodayCount >= bresult * 1.01 ? true : false;
  533. } else if (firstDigit == 2) {
  534. result = yestodayCount >= bresult * 1.005 ? true : false;
  535. } else if (firstDigit == 3 || firstDigit == 4) {
  536. result = yestodayCount >= bresult * 1.003 ? true : false;
  537. } else if (firstDigit == 5 || firstDigit == 6 || firstDigit == 7 || firstDigit == 8 || firstDigit == 9) {
  538. result = yestodayCount >= bresult * 1.003 ? true : false;
  539. } else {
  540. result = false;
  541. }
  542. }
  543. return result;
  544. }
  545. /**
  546. * 获取数字的最高位数字
  547. *
  548. * @return
  549. */
  550. private int getFirstDigit(int number) {
  551. number = Math.abs(number);
  552. if (number < 10) {
  553. return number;
  554. }
  555. return getFirstDigit((number - (number % 10)) / 10);
  556. }
  557. /**
  558. * 查询指定时间区间内的规则报警次数
  559. *
  560. * @param snapid
  561. * @param beginDate
  562. * @param endDate
  563. * @return
  564. */
  565. private String findAlarmcount(Long snapid, Date beginDate, Date endDate) {
  566. if (snapid != 0) {
  567. String result = alarmcountsService.findAlarmcount(snapid, beginDate, endDate);
  568. return result;
  569. }
  570. return "0.0,0.0";
  571. }
  572. private Double findyearstodayAlarmcount(Long snapid, Date beginDate, Date endDate) {
  573. if (snapid != 0) {
  574. Double result = alarmcountsService.findyearstodayAlarmcount(snapid, beginDate, endDate);
  575. return result;
  576. }
  577. return 0.0;
  578. }
  579. /**
  580. * 查询风机单个规则在alermsnap表里id snapid:此id可以关联到alarmcount表查询次数
  581. *
  582. * @param wt
  583. * @param ednavalue
  584. * @return
  585. */
  586. private Long findAlarmsnap(ProBasicEquipment wt, Long ednavalue) {
  587. if (StringUtils.notEmp(wt) && StringUtils.notEmp(ednavalue)) {
  588. Long result = alarmsnapsService.getAlarmsnapid(wt.getId(), ednavalue);
  589. return result;
  590. }
  591. return 0l;
  592. }
  593. /**
  594. * 查询单个风场型号的特征规则
  595. *
  596. * @param modelid
  597. * @param staionid
  598. * @return
  599. */
  600. private List<Alertrule2> findArsubs(String staionid, String modelid) {
  601. if (StringUtils.notEmp(modelid) && StringUtils.notEmp(staionid)) {
  602. List<Alertrule2> voList = alertrule2sService.findAlertRuleList(staionid, modelid);
  603. return voList;
  604. }
  605. return new ArrayList<>();
  606. }
  607. @SuppressWarnings("unused")
  608. private void saveData(List<ProEconStateJudgmentDay> jkfxorder) {
  609. for (ProEconStateJudgmentDay vo : jkfxorder) {
  610. proEconStateJudgmentDayService.insertProEconStateJudgmentDay(vo);
  611. }
  612. }
  613. private List<ProEconStateJudgmentDay> containList(List<ProEconStateJudgmentDay> list, List<ProEconStateJudgmentDay> zlist) {
  614. for (ProEconStateJudgmentDay statejudgmentrecordVo : list) {
  615. zlist.add(statejudgmentrecordVo);
  616. }
  617. return zlist;
  618. }
  619. private List<ProEconStateJudgmentDay> removeDuplicate(List<ProEconStateJudgmentDay> list) {
  620. for (int i = 0; i < list.size() - 1; i++) {
  621. for (int j = list.size() - 1; j > i; j--) {
  622. 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())) {
  623. list.remove(j);
  624. }
  625. }
  626. }
  627. return list;
  628. }
  629. private void judgeParams(Map<String, HcEnum> hcmap, Map<String, Object> parmarsmap, ProBasicEquipment wt, ArrayList<String> ucs) throws Exception {
  630. Calendar c = Calendar.getInstance();
  631. c.set(Calendar.HOUR_OF_DAY, 0);
  632. c.set(Calendar.MINUTE, 0);
  633. c.set(Calendar.SECOND, 0);
  634. if (!ucs.isEmpty()) {
  635. for (String str : ucs) {
  636. if (hcmap.containsKey(str)) {
  637. HcEnum hc = hcmap.get(str);
  638. Object obj = healthFactoryService.judegeHealth(hc, wt, c);
  639. if (obj instanceof Boolean) {
  640. parmarsmap.put(str, Boolean.valueOf(String.valueOf(obj)));
  641. } else if (obj instanceof Double) {
  642. parmarsmap.put(str, Double.valueOf(String.valueOf(obj)));
  643. } else if (obj instanceof Integer) {
  644. parmarsmap.put(str, Integer.valueOf(String.valueOf(obj)));
  645. }
  646. }
  647. }
  648. }
  649. }
  650. private List<ProEconWindturbineWarnCount> queryWindturbinebjCountByLineAndAlertrule(Alertrule2 ar, String lnid) {
  651. if (StringUtils.notEmp(ar) && StringUtils.notEmp(lnid)) {
  652. List<ProEconWindturbineWarnCount> list = proEconWindturbineWarnCountService.queryWindturbinebjCountByLineAndAlertrule(ar.getId(), lnid);
  653. return list;
  654. }
  655. return new ArrayList<>();
  656. }
  657. private Boolean isExceedingStandard(ProEconWindturbineWarnCount wb) {
  658. if (wb.getTotal() == 0 || wb.getTotal() <= wb.getAverageQuantity()) {
  659. return false;
  660. }
  661. if (("" + wb.getAverageQuantity()).length() == 1) {
  662. if (wb.getAverageQuantity() == 0 && wb.getTotal() >= 8) {
  663. return true;
  664. } else if (wb.getAverageQuantity() == 1 && wb.getTotal() >= 20) {
  665. return true;
  666. } else if (wb.getAverageQuantity() == 2 && wb.getTotal() >= 30) {
  667. return true;
  668. } else if (wb.getAverageQuantity() == 3 && wb.getTotal() >= 30) {
  669. return true;
  670. } else if (wb.getAverageQuantity() == 4 && wb.getTotal() >= 30) {
  671. return true;
  672. } else if (wb.getAverageQuantity() == 5 && wb.getTotal() >= 30) {
  673. return true;
  674. } else if (wb.getAverageQuantity() == 6 && wb.getTotal() >= 30) {
  675. return true;
  676. } else if (wb.getAverageQuantity() == 7 && wb.getTotal() >= 30) {
  677. return true;
  678. } else if (wb.getAverageQuantity() == 8 && wb.getTotal() >= 30) {
  679. return true;
  680. } else if (wb.getAverageQuantity() == 9 && wb.getTotal() >= 30) {
  681. return true;
  682. } else {
  683. return false;
  684. }
  685. } else if (("" + wb.getAverageQuantity()).length() == 2) {
  686. if (getFirstDigit(wb.getAverageQuantity().intValue()) == 1 && wb.getTotal() >= (wb.getAverageQuantity() * 3)) {
  687. return true;
  688. } else if (getFirstDigit(wb.getAverageQuantity().intValue()) == 2 && wb.getTotal() >= (wb.getAverageQuantity() * 2)) {
  689. return true;
  690. } else if (getFirstDigit(wb.getAverageQuantity().intValue()) == 3 && wb.getTotal() >= (wb.getAverageQuantity() * 1.5)) {
  691. return true;
  692. } else if (getFirstDigit(wb.getAverageQuantity().intValue()) == 4 && wb.getTotal() >= (wb.getAverageQuantity() * 1.4)) {
  693. return true;
  694. } else if (getFirstDigit(wb.getAverageQuantity().intValue()) == 5 && wb.getTotal() >= (wb.getAverageQuantity() * 1.3)) {
  695. return true;
  696. } else if (getFirstDigit(wb.getAverageQuantity().intValue()) == 6 && wb.getTotal() >= (wb.getAverageQuantity() * 1.3)) {
  697. return true;
  698. } else if (getFirstDigit(wb.getAverageQuantity().intValue()) == 7 && wb.getTotal() >= (wb.getAverageQuantity() * 1.3)) {
  699. return true;
  700. } else if (getFirstDigit(wb.getAverageQuantity().intValue()) == 8 && wb.getTotal() >= (wb.getAverageQuantity() * 1.3)) {
  701. return true;
  702. } else if (getFirstDigit(wb.getAverageQuantity().intValue()) == 9 && wb.getTotal() >= (wb.getAverageQuantity() * 1.3)) {
  703. return true;
  704. } else {
  705. return false;
  706. }
  707. } else if (("" + wb.getAverageQuantity()).length() == 3) {
  708. if (getFirstDigit(wb.getAverageQuantity().intValue()) == 1 && wb.getTotal() >= (wb.getAverageQuantity() * 2)) {
  709. return true;
  710. } else if (getFirstDigit(wb.getAverageQuantity().intValue()) == 2 && wb.getTotal() >= (wb.getAverageQuantity() * 1.5)) {
  711. return true;
  712. } else if (getFirstDigit(wb.getAverageQuantity().intValue()) == 3 && wb.getTotal() >= (wb.getAverageQuantity() * 1.4)) {
  713. return true;
  714. } else if (getFirstDigit(wb.getAverageQuantity().intValue()) == 4 && wb.getTotal() >= (wb.getAverageQuantity() * 1.3)) {
  715. return true;
  716. } else if (getFirstDigit(wb.getAverageQuantity().intValue()) == 5 && wb.getTotal() >= (wb.getAverageQuantity() * 1.3)) {
  717. return true;
  718. } else if (getFirstDigit(wb.getAverageQuantity().intValue()) == 6 && wb.getTotal() >= (wb.getAverageQuantity() * 1.3)) {
  719. return true;
  720. } else if (getFirstDigit(wb.getAverageQuantity().intValue()) == 7 && wb.getTotal() >= (wb.getAverageQuantity() * 1.3)) {
  721. return true;
  722. } else if (getFirstDigit(wb.getAverageQuantity().intValue()) == 8 && wb.getTotal() >= (wb.getAverageQuantity() * 1.3)) {
  723. return true;
  724. } else if (getFirstDigit(wb.getAverageQuantity().intValue()) == 9 && wb.getTotal() >= (wb.getAverageQuantity() * 1.3)) {
  725. return true;
  726. } else {
  727. return false;
  728. }
  729. } else {
  730. if (getFirstDigit(wb.getAverageQuantity().intValue()) == 1 && wb.getTotal() >= (wb.getAverageQuantity() * 1.9)) {
  731. return true;
  732. } else if (getFirstDigit(wb.getAverageQuantity().intValue()) == 2 && wb.getTotal() >= (wb.getAverageQuantity() * 1.5)) {
  733. return true;
  734. } else if (getFirstDigit(wb.getAverageQuantity().intValue()) == 3 && wb.getTotal() >= (wb.getAverageQuantity() * 1.4)) {
  735. return true;
  736. } else if (getFirstDigit(wb.getAverageQuantity().intValue()) == 4 && wb.getTotal() >= (wb.getAverageQuantity() * 1.3)) {
  737. return true;
  738. } else if (getFirstDigit(wb.getAverageQuantity().intValue()) == 5 && wb.getTotal() >= (wb.getAverageQuantity() * 1.2)) {
  739. return true;
  740. } else if (getFirstDigit(wb.getAverageQuantity().intValue()) == 6 && wb.getTotal() >= (wb.getAverageQuantity() * 1.2)) {
  741. return true;
  742. } else if (getFirstDigit(wb.getAverageQuantity().intValue()) == 7 && wb.getTotal() >= (wb.getAverageQuantity() * 1.2)) {
  743. return true;
  744. } else if (getFirstDigit(wb.getAverageQuantity().intValue()) == 8 && wb.getTotal() >= (wb.getAverageQuantity() * 1.2)) {
  745. return true;
  746. } else if (getFirstDigit(wb.getAverageQuantity().intValue()) == 9 && wb.getTotal() >= (wb.getAverageQuantity() * 1.2)) {
  747. return true;
  748. } else {
  749. return false;
  750. }
  751. }
  752. }
  753. private List<String> queryWindturbinebjCountLine(Alertrule2 ar) {
  754. if (StringUtils.notEmp(ar)) {
  755. List<String> lnids = proEconWindturbineWarnCountService.queryWindturbinebjCountLine(ar.getId());
  756. return lnids;
  757. }
  758. return new ArrayList<>();
  759. }
  760. public void savePartbjcount() {
  761. Calendar c = Calendar.getInstance();
  762. c.set(Calendar.HOUR_OF_DAY, 0);
  763. c.set(Calendar.MINUTE, 0);
  764. c.set(Calendar.SECOND, 0);
  765. c.add(Calendar.DAY_OF_MONTH, -1);
  766. Date date = c.getTime();
  767. proEconPartWarnCountService.deletePartbjcount(date);
  768. List<Alertrule2> ars = CacheContext.alarmrulels;
  769. for (Alertrule2 ar : ars) {
  770. List<String> lnids = queryWindturbinebjCountLine(ar);
  771. for (String lnid : lnids) {
  772. int count = 0;
  773. String part = null;
  774. List<ProEconWindturbineWarnCount> wclist = queryWindturbinebjCountByLineAndAlertrule(ar, lnid);
  775. for (ProEconWindturbineWarnCount wc : wclist) {
  776. boolean temp = isExceedingStandard(wc);
  777. part = wc.getPart();
  778. if (temp == true) {
  779. count++;
  780. }
  781. }
  782. if (count >= (wclist.size() * 0.9)) {
  783. String uuid = UUID.randomUUID().toString().replaceAll("-", "");
  784. ProEconPartWarnCount po = new ProEconPartWarnCount();
  785. po.setId(uuid);
  786. po.setLnId(lnid);
  787. po.setAlertruleId(ar.getId());
  788. po.setPart(part);
  789. po.setRecordDate(DateUtils.truncate(date));
  790. proEconPartWarnCountService.insertPartbjcount(po);
  791. for (ProEconWindturbineWarnCount wbc : wclist) {
  792. if (isExceedingStandard(wbc) == true) {
  793. String id = UUID.randomUUID().toString().replaceAll("-", "");
  794. ProEconPartWarnCountSub posub = new ProEconPartWarnCountSub();
  795. posub.setId(id);
  796. posub.setWtId(wbc.getWtId());
  797. posub.setTotal(wbc.getTotal());
  798. posub.setAverageQuantity(wbc.getAverageQuantity());
  799. posub.setPid(uuid);
  800. proEconPartWarnCountSubService.insertPartbjcountsub(posub);
  801. }
  802. }
  803. }
  804. }
  805. }
  806. }
  807. /**
  808. * 保存
  809. *
  810. * @return
  811. */
  812. public void saveWindturbineBjCount() {
  813. Calendar c = Calendar.getInstance();
  814. c.set(Calendar.HOUR_OF_DAY, 0);
  815. c.set(Calendar.MINUTE, 0);
  816. c.set(Calendar.SECOND, 0);
  817. c.add(Calendar.DAY_OF_MONTH, -2);
  818. Date endDate = c.getTime();
  819. c.add(Calendar.DAY_OF_MONTH, -6);
  820. Date beginDate = c.getTime();
  821. c.add(Calendar.DAY_OF_MONTH, 7);
  822. Date date = c.getTime();
  823. List<ProEconWindturbineWarnCount> melist = new ArrayList<ProEconWindturbineWarnCount>();
  824. proEconWindturbineWarnCountService.deleteWindturbinebjcount(date);
  825. for (ProBasicLine line : CacheContext.lines) {
  826. List<ProBasicEquipment> wtls = CacheContext.wtlinemap.get(line.getId());
  827. List<DataVo> arlist = findAlertRuleList(line);
  828. if (arlist != null && arlist.size() > 0) {
  829. for (DataVo ar : arlist) {
  830. for (ProBasicEquipment w : wtls) {
  831. // if (wobugeqsService
  832. // .isQueryThreeDayWobugeqs(w.getId()) == false) {
  833. Long snapid = getAlarmsnapid(w.getId(), ar.getEdnavalue());
  834. String cc = findAlarmcount(snapid, beginDate, endDate);
  835. String[] s = cc.split(",");
  836. Double avg = 0.0;
  837. if (Double.parseDouble(s[1]) != 0) {
  838. avg = (Double.parseDouble(s[0]) / Double.parseDouble(s[1]));
  839. }
  840. Double sjcount = findyearstodayAlarmcount(snapid, date, date);
  841. String uuid = UUID.randomUUID().toString().replaceAll("-", "");
  842. String part = getPartByAlertruleid(ar.getId());
  843. ProEconWindturbineWarnCount wbc = new ProEconWindturbineWarnCount();
  844. wbc.setId(uuid);
  845. wbc.setWtId(w.getId());
  846. wbc.setLnId(w.getLineId());
  847. wbc.setWpId(w.getWindpowerstationId());
  848. wbc.setAlertruleId(ar.getId());
  849. wbc.setAlertruleName(ar.getName());
  850. wbc.setPart(part);
  851. wbc.setTotal(sjcount.intValue());
  852. wbc.setAverageQuantity(avg);
  853. wbc.setRecordDate(date);
  854. melist.add(wbc);
  855. // }
  856. }
  857. }
  858. }
  859. }
  860. insertWindturbineBjCount(melist);
  861. }
  862. /**
  863. * 向WindturbineBjCount表插入数据
  864. *
  865. * @param melist
  866. */
  867. private void insertWindturbineBjCount(List<ProEconWindturbineWarnCount> melist) {
  868. for (ProEconWindturbineWarnCount wb : melist) {
  869. proEconWindturbineWarnCountService.insertWindturbineBjCount(wb);
  870. }
  871. }
  872. /**
  873. * 根据alertrule2id查询所属分组
  874. *
  875. * @param id
  876. * @return
  877. */
  878. private String getPartByAlertruleid(String id) {
  879. if (StringUtils.notEmp(id)) {
  880. List<String> list = alertrulefailuresubsService.getPartByAlertruleid(id);
  881. if (!list.isEmpty()) {
  882. return list.get(0);
  883. }
  884. }
  885. return "";
  886. }
  887. private Long getAlarmsnapid(String wtid, Long ednavalue) {
  888. if (StringUtils.notEmp(wtid) && StringUtils.notEmp(ednavalue)) {
  889. Long snapid = alarmsnapsService.getAlarmsnapid(wtid, ednavalue);
  890. return snapid;
  891. }
  892. return 0l;
  893. }
  894. private List<DataVo> findAlertRuleList(ProBasicLine line) {
  895. List<ProBasicEquipment> wt1 = CacheContext.wtlinemap.get(line.getId());
  896. ProBasicEquipment wt = wt1.get(0);
  897. List<DataVo> dos = new ArrayList<>();
  898. if (StringUtils.notEmp(line)) {
  899. List<Alertrule2> ls = alertrule2sService.findAlertRuleList(wt.getWindpowerstationId(), wt.getModelId());
  900. if (!ls.isEmpty()) {
  901. for (Alertrule2 ar : ls) {
  902. DataVo vo = new DataVo();
  903. vo.setId(ar.getId());
  904. vo.setEdnavalue(ar.getEdnavalue());
  905. vo.setName(ar.getName());
  906. dos.add(vo);
  907. }
  908. }
  909. }
  910. return dos;
  911. }
  912. public void test1() {
  913. final CountDownLatch countDownLatch = new CountDownLatch(6);
  914. for (int i = 0; i < 3; i++) {
  915. threadPoolTaskExecutor.execute(new Runnable() {
  916. // 解决多线程操作同一集合
  917. @Override
  918. public void run() {
  919. // logger.debug("启动:" + wt.getId() + "---" + ar.getId()
  920. // + "--特征分析子线程--");
  921. //synchronized (this) {
  922. try {
  923. for (int j = 0; j < 2; j++) {
  924. System.out.println("======" + j);
  925. // if(i==funList.size()-1)
  926. // {
  927. // if (obj instanceof Boolean) {
  928. // if (true == (boolean) obj) {
  929. // // atomic.getAndIncrement();
  930. // time++;
  931. // break;
  932. // }
  933. // }
  934. // }
  935. Thread.sleep(10000);
  936. // logger.debug("剩余线程数:"+countDownLatch.getTotal());
  937. // logger.debug("完成:" + wt.getId() + "---" +
  938. // ar.getId() + "--特征分析子线程--");
  939. //
  940. }
  941. } catch (Exception e) {
  942. e.printStackTrace();
  943. } finally {
  944. countDownLatch.countDown();// 工人完成工作,计数器减一
  945. }
  946. }
  947. });
  948. }
  949. // threadPoolTaskExecutor.shutdown();
  950. try {
  951. countDownLatch.await();
  952. } catch (Exception e) {
  953. e.printStackTrace();
  954. }
  955. // logger.debug("特征提取完成!");
  956. }
  957. }