|
@@ -3,16 +3,26 @@ package com.gyee.sampleimpala.service.impl.kudu;
|
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.gyee.sampleimpala.common.base.ExcludeQueryWrapper;
|
|
|
+import com.gyee.sampleimpala.common.constant.Constants;
|
|
|
import com.gyee.sampleimpala.common.exception.CustomException;
|
|
|
+import com.gyee.sampleimpala.common.feign.RemoteServiceBuilder;
|
|
|
import com.gyee.sampleimpala.common.result.ResultCode;
|
|
|
+import com.gyee.sampleimpala.common.util.DateUtil;
|
|
|
import com.gyee.sampleimpala.common.util.SnowFlakeGenerator;
|
|
|
+import com.gyee.sampleimpala.common.util.StationMapperUtil;
|
|
|
import com.gyee.sampleimpala.mapper.kudu.CaseperformanceMapper;
|
|
|
+import com.gyee.sampleimpala.model.custom.TsPointData;
|
|
|
import com.gyee.sampleimpala.model.kudu.Caseperformance;
|
|
|
+import com.gyee.sampleimpala.model.kudu.Windturbinepoint;
|
|
|
import com.gyee.sampleimpala.service.kudu.CaseperformanceService;
|
|
|
+import com.gyee.sampleimpala.service.kudu.WindturbinepointService;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.velocity.runtime.directive.Foreach;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -25,16 +35,28 @@ import java.util.List;
|
|
|
@Service
|
|
|
public class CaseperformanceServiceImpl extends ServiceImpl<CaseperformanceMapper, Caseperformance> implements CaseperformanceService {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private RemoteServiceBuilder remoteService;
|
|
|
+ @Autowired
|
|
|
+ private WindturbinepointService windturbinepointService;
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
- public List<Caseperformance> getPerformanceList(String station, String[] model, Integer tag, String st, String et) {
|
|
|
+ public List<Caseperformance> getPerformanceList(String station, String[] model, Integer tag, String interval, String st, String et) {
|
|
|
ExcludeQueryWrapper<Caseperformance> wrapper = new ExcludeQueryWrapper<>();
|
|
|
+
|
|
|
+ //前端传的*-*类型,需要保持一致
|
|
|
+ String[] temp = !StringUtils.isEmpty(interval) ? interval.split("-") : new String[]{"0", "0.5"};
|
|
|
+
|
|
|
wrapper.eq("stationen", station)
|
|
|
.in("model", model)
|
|
|
.eq("tag", tag)
|
|
|
+ .ge("intervals", Double.valueOf(temp[0]))
|
|
|
+ .le("intervals", Double.valueOf(temp[1]))
|
|
|
.ge("starttime", st)
|
|
|
.le("endtime", et);
|
|
|
|
|
|
- List<Caseperformance> list = new ArrayList<>();
|
|
|
+ List<Caseperformance> list = null;
|
|
|
try {
|
|
|
list = baseMapper.selectList(wrapper);
|
|
|
} catch (Exception e) {
|
|
@@ -95,10 +117,240 @@ public class CaseperformanceServiceImpl extends ServiceImpl<CaseperformanceMappe
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Caseperformance getPerformanceByid(Integer id) {
|
|
|
+ public Caseperformance getPerformanceByid(String id) {
|
|
|
Caseperformance cp = baseMapper.selectById(id);
|
|
|
return cp;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public Map<String, List> getCurveScatter(String id, int interval) {
|
|
|
+ Map<String, List> maps = new HashMap<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ String[] codes = new String[]{Constants.POINT_SPEED, Constants.POINT_POWER};
|
|
|
+ Caseperformance cp = getPerformanceByid(id);
|
|
|
+
|
|
|
+ //查询测点名
|
|
|
+ List<Windturbinepoint> winds = windturbinepointService.getListByStationAndWtIdAndUniformCode(cp.getStationen(), cp.getWindturbineid(), codes);
|
|
|
+
|
|
|
+ //golden适配器取数据
|
|
|
+ List<TsPointData> speedList = remoteService.ShardingService().getHistorySnap(winds.get(0).getPoint(), DateUtil.covertDateTimestamp(cp.getStarttime()),
|
|
|
+ DateUtil.covertDateTimestamp(cp.getEndtime()), interval);
|
|
|
+ List<TsPointData> powerList = remoteService.ShardingService().getHistorySnap(winds.get(1).getPoint(), DateUtil.covertDateTimestamp(cp.getStarttime()),
|
|
|
+ DateUtil.covertDateTimestamp(cp.getEndtime()), interval);
|
|
|
+
|
|
|
+ if (speedList == null || powerList == null)
|
|
|
+ return maps;
|
|
|
+
|
|
|
+ //计算数组最小的
|
|
|
+ int len = speedList.size() <= powerList.size() ? speedList.size() : powerList.size();
|
|
|
+ //散点图
|
|
|
+ List listS = new ArrayList<>();
|
|
|
+
|
|
|
+ for (int i = 0; i < len; i++) {
|
|
|
+ //计算散点图
|
|
|
+ List ls = new ArrayList();
|
|
|
+ ls.add(speedList.get(i).getDoubleValue());
|
|
|
+ ls.add(powerList.get(i).getDoubleValue());
|
|
|
+ listS.add(ls);
|
|
|
+ }
|
|
|
+
|
|
|
+ maps.put(cp.getWindturbineid(), listS);
|
|
|
+
|
|
|
+ return maps;
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage());
|
|
|
+ throw new CustomException(ResultCode.ERROR_DATA);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String, List> getCurveScatter(String[] ids, int interval, Integer type) {
|
|
|
+ Map<String, List> maps = new HashMap<>();
|
|
|
+ List<Map<String, List>> list = new ArrayList<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ for (String id : ids) {
|
|
|
+ list.add(getCurveScatter(id, interval));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (list.size() <= 0)
|
|
|
+ return maps;
|
|
|
+
|
|
|
+ switch (type) {
|
|
|
+ //单台
|
|
|
+ case 0:
|
|
|
+ maps = list.get(0);
|
|
|
+ break;
|
|
|
+ //多台
|
|
|
+ case 1:
|
|
|
+ for (Map<String, List> ls : list) {
|
|
|
+ Set<String> keys = ls.keySet();
|
|
|
+ for (String key : keys)
|
|
|
+ maps.put(key, ls.get(key));
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ //多台拟合
|
|
|
+ case 2:
|
|
|
+ case 3:
|
|
|
+ List<List> merge = new ArrayList<>();
|
|
|
+ for (Map<String, List> ls : list) {
|
|
|
+ Set<String> keys = ls.keySet();
|
|
|
+ for (String key : keys) {
|
|
|
+ List<Object> lp = ls.get(key);
|
|
|
+ for (int i = 0; i < lp.size(); i++)
|
|
|
+ merge.add((List) lp.get(i));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ maps.put("NH", merge);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ return maps;
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage());
|
|
|
+ throw new CustomException(ResultCode.ERROR_DATA);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String, List> getLines(String[] ids, int interval, Integer type) {
|
|
|
+ Map<String, List> maps = new HashMap<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ if (ids == null || ids.length == 0)
|
|
|
+ return maps;
|
|
|
+
|
|
|
+// for (String id : ids){
|
|
|
+// list.add(getLine(id, interval));
|
|
|
+// }
|
|
|
+
|
|
|
+ return getLine(ids[0], interval);
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage());
|
|
|
+ throw new CustomException(ResultCode.ERROR_DATA);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List getPerformanceList(String station, String interval, Integer tag, String st, String et) {
|
|
|
+ List list = new ArrayList();
|
|
|
+ ExcludeQueryWrapper<Caseperformance> wrapper = new ExcludeQueryWrapper<>();
|
|
|
+
|
|
|
+ //前端传的*-*类型,需要保持一致
|
|
|
+ String[] temp = !StringUtils.isEmpty(interval) ? interval.split("-") : new String[]{"0", "0.5"};
|
|
|
+
|
|
|
+ try{
|
|
|
+ wrapper.eq("stationen", station)
|
|
|
+ .eq("tag", tag)
|
|
|
+ .ge("intervals", Double.valueOf(temp[0]))
|
|
|
+ .le("intervals", Double.valueOf(temp[1]))
|
|
|
+ .ge("starttime", st)
|
|
|
+ .le("endtime", et)
|
|
|
+ .groupBy("id","windturbineid", "starttime", "endtime")
|
|
|
+ .select("id", "windturbineid", "starttime", "endtime")
|
|
|
+ .orderByAsc("windturbineid");
|
|
|
+
|
|
|
+ List<Caseperformance> cases = baseMapper.selectList(wrapper);
|
|
|
+
|
|
|
+ // 根据风机编号分组
|
|
|
+ Map<String, List<Caseperformance>> singleMap = cases.stream()
|
|
|
+ .sorted(Comparator.comparing(Caseperformance::getWindturbineid))
|
|
|
+ .collect(Collectors.groupingBy(Caseperformance::getWindturbineid));
|
|
|
+
|
|
|
+ String wtId = StationMapperUtil.stationCN(station);
|
|
|
+ int i = 0; //前端树状展示,需要id
|
|
|
+ for (Map.Entry<String, List<Caseperformance>> entry : singleMap.entrySet()){
|
|
|
+ Map<String, Object> map = new LinkedHashMap<>();
|
|
|
+ String key = entry.getKey();
|
|
|
+ String windId = wtId + key.substring(key.lastIndexOf("_") + 1) + "号风机";
|
|
|
+
|
|
|
+ List<Caseperformance> value = entry.getValue();
|
|
|
+ List childList = new ArrayList();
|
|
|
+ for (Caseperformance performance : value){
|
|
|
+ Map<String, Object> childMap = new LinkedHashMap<>();
|
|
|
+ childMap.put("id", performance.getId());
|
|
|
+ childMap.put("wtId", key);
|
|
|
+ childMap.put("windturbineId", performance.getStarttime() + "性能下降");
|
|
|
+ childMap.put("st", performance.getStarttime());
|
|
|
+ childMap.put("et", performance.getEndtime());
|
|
|
+ childList.add(childMap);
|
|
|
+ }
|
|
|
+ map.put("id", i);
|
|
|
+ map.put("windturbineId", windId);
|
|
|
+ map.put("children", childList);
|
|
|
+
|
|
|
+ list.add(map);
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+
|
|
|
+ return list;
|
|
|
+
|
|
|
+ }catch (Exception e) {
|
|
|
+ log.error(e.getMessage());
|
|
|
+ throw new CustomException(ResultCode.ERROR_DATA);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询单台风机风速功率
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @param interval
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Map<String, List> getLine(String id, int interval) {
|
|
|
+ Map<String, List> maps = new HashMap<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ if (StringUtils.isEmpty(id))
|
|
|
+ return maps;
|
|
|
+
|
|
|
+ String[] codes = new String[]{Constants.POINT_SPEED, Constants.POINT_POWER, Constants.POINT_POWER_LLGL};
|
|
|
+ //单台风机
|
|
|
+ Caseperformance cp = getPerformanceByid(id);
|
|
|
+ //查询测点名
|
|
|
+ List<Windturbinepoint> winds = windturbinepointService.getListByStationAndWtIdAndUniformCode(cp.getStationen(), cp.getWindturbineid(), codes);
|
|
|
+ //golden适配器取数据
|
|
|
+ List<TsPointData> speedList = remoteService.ShardingService().getHistorySnap(winds.get(0).getPoint(), DateUtil.covertDateTimestamp(cp.getStarttime()),
|
|
|
+ DateUtil.covertDateTimestamp(cp.getEndtime()), interval);
|
|
|
+ List<TsPointData> powerList = remoteService.ShardingService().getHistorySnap(winds.get(1).getPoint(), DateUtil.covertDateTimestamp(cp.getStarttime()),
|
|
|
+ DateUtil.covertDateTimestamp(cp.getEndtime()), interval);
|
|
|
+ List<TsPointData> llglList = remoteService.ShardingService().getHistorySnap(winds.get(2).getPoint(), DateUtil.covertDateTimestamp(cp.getStarttime()),
|
|
|
+ DateUtil.covertDateTimestamp(cp.getEndtime()), interval);
|
|
|
+
|
|
|
+ if (speedList == null || powerList == null || llglList == null)
|
|
|
+ return maps;
|
|
|
+
|
|
|
+ //计算数组最小的
|
|
|
+ int len = speedList.size() <= powerList.size() ? speedList.size() : powerList.size();
|
|
|
+ List listPower = new ArrayList();
|
|
|
+ List listSpeed = new ArrayList();
|
|
|
+ List listLLGL = new ArrayList();
|
|
|
+ //返回给前端的点数
|
|
|
+ int temp = 10;
|
|
|
+ int snap = len / temp;
|
|
|
+ for (int i = 0; i < temp; i++) {
|
|
|
+ listPower.add(powerList.get(snap * i));
|
|
|
+ listSpeed.add(speedList.get(snap * i));
|
|
|
+ listLLGL.add(llglList.get(snap * i));
|
|
|
+ }
|
|
|
+
|
|
|
+ maps.put("power", listPower);
|
|
|
+ maps.put("llglpower", listLLGL);
|
|
|
+ maps.put("speed", listSpeed);
|
|
|
+
|
|
|
+ return maps;
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage());
|
|
|
+ throw new CustomException(ResultCode.ERROR_DATA);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
}
|