123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- package com.gyee.impala.controller.diagnose;
- import com.alibaba.fastjson.JSONObject;
- import com.gyee.impala.common.feign.RemoteServiceBuilder;
- import com.gyee.impala.common.result.JsonResult;
- import com.gyee.impala.common.result.ResultCode;
- import com.gyee.impala.common.util.DateUtil;
- import com.gyee.impala.model.custom.diagnose.FaultInfo;
- import com.gyee.impala.model.master.Casefaultalg;
- import com.gyee.impala.service.custom.diagnose.AutoCmdService;
- import com.gyee.impala.service.master.CasefaultalgService;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.*;
- import java.util.*;
- import java.util.stream.Collectors;
- /**
- * 离线故障诊断
- */
- @CrossOrigin
- @RestController
- @RequestMapping("/api/diagnosefault")
- public class DiagnoseFaultController {
- @Autowired
- private AutoCmdService autoCmdService;
- @Autowired
- private CasefaultalgService casefaultalgService;
- @Autowired
- private RemoteServiceBuilder remoteServiceBuilder;
- /**
- * 离线列表数据
- * @return
- */
- @GetMapping("/offline")
- public JSONObject offline(@RequestParam(value = "station", required = false) String station,
- @RequestParam(value = "windturbineid", required = false) String wtId,
- @RequestParam(value = "id", required = false) String[] id,
- @RequestParam(value = "faultid", required = false) Long[] faultid,
- @RequestParam(value = "model", required = false) String[] model,
- @RequestParam(value = "faultcode", required = false) String[] faultcode,
- @RequestParam(value = "st", required = false) String st,
- @RequestParam(value = "et", required = false) String et,
- @RequestParam(value = "algcode", required = false) String algcode,
- @RequestParam(value = "confirm", required = false) Optional<Boolean> confirm){
- boolean conf = confirm.isPresent() ? confirm.get() : false;
- if (conf){
- List<Casefaultalg> list = casefaultalgService.getAll(station, wtId, id, faultid, model, faultcode, st, et, algcode, false);
- return JsonResult.successData(ResultCode.SUCCESS, list);
- }else{
- List<Casefaultalg> array = new ArrayList<>();
- List<Casefaultalg> list = casefaultalgService.getAll(station, wtId, id, faultid, model, faultcode, st, et, algcode, false);
- List<FaultInfo> faults = remoteServiceBuilder.sharding().getFaultRecent(et);
- List<FaultInfo> collect = faults.stream()
- .filter(f -> f.getCategory1().equals("FJ") && f.getCategory2().equals("GZ"))
- .filter(a -> StringUtils.isEmpty(station) || a.getStationId().equals(station))
- .filter(a -> StringUtils.isEmpty(wtId) || a.getWindturbineId().equals(wtId))
- .collect(Collectors.toList());
- for (int i = 0; i < collect.size(); i++){
- FaultInfo info = collect.get(i);
- if (list == null || list.size() == 0){
- array.add(format(info));
- }else{
- List<Casefaultalg> ls = list.stream().filter(a -> a.getFaultid().equals(info.getId())).collect(Collectors.toList());
- if (ls.size() == 0)
- array.add(format(info));
- }
- }
- return JsonResult.successData(ResultCode.SUCCESS, array);
- }
- }
- /**
- * 离线诊断
- * @return
- */
- @PostMapping("/offlinediagnose")
- public JSONObject offlineDiagnose(@RequestBody JSONObject json){
- if (json == null)
- return JsonResult.error(ResultCode.PARAM_IS_BLANK);
- String model = json.getString("model");
- List<Casefaultalg> faults = JSONObject.parseArray(json.getJSONArray("faults").toString(), Casefaultalg.class);
- faults.stream().forEach(obj -> {
- FaultInfo info = new FaultInfo();
- info.setStationId(obj.getStationen());
- info.setModelId(obj.getModel());
- info.setId(Long.valueOf(obj.getFaultid()));
- autoCmdService.exec(info);
- });
- return JsonResult.success(ResultCode.SUCCESS);
- }
- /**
- * 诊断准确率统计
- * @return
- */
- @GetMapping("/statistic")
- public JSONObject statistic(String[] station, String st, String et){
- if (StringUtils.isEmpty(st) || StringUtils.isEmpty(et)){
- Calendar cal = Calendar.getInstance();
- int year = cal.get(Calendar.YEAR);
- st = year + "-01-01 00:00:00";
- et = year + "-12-30 23:59:59";
- }
- List<Object> list = new ArrayList<>();
- for (String pt : station){
- List<Casefaultalg> collect = casefaultalgService.getAll(pt, null, null, null, null, null, st, et, null, null);
- int size = collect.stream().filter(a -> a.getConfirm()).collect(Collectors.toList()).size();
- int count = collect.stream().filter(a -> a.getAlgcode().equals(a.getFaultcode())).collect(Collectors.toList()).size();
- Map<String, Object> map = new HashMap<>();
- int accuracy = size > 0 ? count / size : -1;
- map.put("station", station);
- map.put("accuracy", accuracy);
- list.add(map);
- }
- return JsonResult.successData(ResultCode.SUCCESS, list);
- }
- private Casefaultalg format(FaultInfo info){
- Casefaultalg fault = new Casefaultalg();
- fault.setStationcn(info.getStationName());
- fault.setStationen(info.getStationId());
- fault.setTag(0);
- fault.setFaultid(info.getId());
- fault.setWindturbineid(info.getWindturbineId());
- fault.setDiagnosetype(info.getAlertText());
- fault.setStarttime(info.getFaultTime());
- fault.setModel(info.getModelId());
- fault.setCategory("0");
- return fault;
- }
- }
|