|
|
@@ -1,26 +1,35 @@
|
|
|
|
|
|
package com.dskj.znzn.transData.web.waveData.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.dskj.znzn.transData.common.base.PageR;
|
|
|
import com.dskj.znzn.transData.common.exception.BusinessException;
|
|
|
+import com.dskj.znzn.transData.web.waveData.entity.WaveConf;
|
|
|
import com.dskj.znzn.transData.web.waveData.entity.WaveData;
|
|
|
-import com.dskj.znzn.transData.web.waveData.indata.GetMesureDataInData;
|
|
|
-import com.dskj.znzn.transData.web.waveData.indata.GetMesureWithSFDataInData;
|
|
|
+import com.dskj.znzn.transData.web.waveData.indata.*;
|
|
|
import com.dskj.znzn.transData.web.waveData.mapper.WaveDataMapper;
|
|
|
+import com.dskj.znzn.transData.web.waveData.outdata.GetByFunctionTypeSummaryInnerDataOutData;
|
|
|
+import com.dskj.znzn.transData.web.waveData.outdata.GetByFunctionTypeSummaryOutData;
|
|
|
import com.dskj.znzn.transData.web.waveData.outdata.ItemOutData;
|
|
|
+import com.dskj.znzn.transData.web.waveData.service.IWaveConfService;
|
|
|
import com.dskj.znzn.transData.web.waveData.service.IWaveDataService;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
@RequiredArgsConstructor(onConstructor = @__({@Autowired}))
|
|
|
public class WaveDataServiceImpl extends ServiceImpl<WaveDataMapper, WaveData> implements IWaveDataService {
|
|
|
private final WaveDataMapper waveDataMapper;
|
|
|
+ private final IWaveConfService waveConfService;
|
|
|
|
|
|
public List<WaveData> getMesureData(GetMesureDataInData inData) {
|
|
|
if (inData.getWindCode().contains(" ")) {
|
|
|
@@ -51,8 +60,63 @@ public class WaveDataServiceImpl extends ServiceImpl<WaveDataMapper, WaveData> i
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<Integer> getSamplingFrequencyByParams(GetSamplingFrequencyByParamsInData inData) {
|
|
|
+ String winFarmCode = inData.getWindFarmCode();
|
|
|
+ if (winFarmCode.contains(" ")) {
|
|
|
+ throw new BusinessException("风场参数异常");
|
|
|
+ } else {
|
|
|
+ winFarmCode = winFarmCode + "_wave";
|
|
|
+ inData.setWindFarmCode(winFarmCode);
|
|
|
+ return waveDataMapper.getSamplingFrequencyByParams(inData);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public PageR<WaveData> getByFunctionTypeInData(GetByFunctionTypeInData inData) {
|
|
|
+ if (inData.getWindCode().contains(" ")) {
|
|
|
+ throw new BusinessException("风场参数异常");
|
|
|
+ } else {
|
|
|
+
|
|
|
+ Page<WaveData> queryPage = Page.of(inData.getPageNo(), inData.getPageSize());
|
|
|
+ inData.setWindCode(inData.getWindCode() + "_wave");
|
|
|
+ Page<WaveData> pageData = this.waveDataMapper.getByFunctionTypeInData(queryPage, inData);
|
|
|
+ return PageR.page(pageData);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
- public List<String> getAllSamplingFrequency(String windCode) {
|
|
|
+ public List<GetByFunctionTypeSummaryOutData> getByFunctionTypeInDataSummary(GetByFunctionTypeInData inData) {
|
|
|
+ if (inData.getWindCode().contains(" ")) {
|
|
|
+ throw new BusinessException("风场参数异常");
|
|
|
+ } else {
|
|
|
+ inData.setWindCode(inData.getWindCode() + "_wave");
|
|
|
+ Map<String, List<WaveData>> nameGrooup = waveDataMapper.getByFunctionTypeInDataSummary(inData).stream()
|
|
|
+ .collect(Collectors.groupingBy(data -> data.getDetectionPointCn()));
|
|
|
+ List<GetByFunctionTypeSummaryOutData> datas = new ArrayList<>();
|
|
|
+ for (Map.Entry<String, List<WaveData>> entry : nameGrooup.entrySet()) {
|
|
|
+ GetByFunctionTypeSummaryOutData outData = new GetByFunctionTypeSummaryOutData();
|
|
|
+ outData.setPointNameCn(entry.getKey());
|
|
|
+// List<GetByFunctionTypeSummaryInnerDataOutData> innerDatas = new ArrayList<>();
|
|
|
+// for (WaveData value : entry.getValue()) {
|
|
|
+// GetByFunctionTypeSummaryInnerDataOutData innerDataOutData = new GetByFunctionTypeSummaryInnerDataOutData();
|
|
|
+// innerDataOutData.setTimeStamp(value.getTimeStamp());
|
|
|
+// innerDataOutData.setStatus(value.getStatus());
|
|
|
+// innerDataOutData.setId(value.getId());
|
|
|
+// innerDatas.add(innerDataOutData);
|
|
|
+// }
|
|
|
+// innerDatas.sort(Comparator.comparing(GetByFunctionTypeSummaryInnerDataOutData::getTimeStamp));
|
|
|
+ outData.setInnerDatas(entry.getValue());
|
|
|
+ datas.add(outData);
|
|
|
+ }
|
|
|
+
|
|
|
+ return datas;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<Integer> getAllSamplingFrequency(String windCode) {
|
|
|
|
|
|
if (windCode.contains(" ")) {
|
|
|
throw new BusinessException("风场参数异常");
|
|
|
@@ -73,7 +137,7 @@ public class WaveDataServiceImpl extends ServiceImpl<WaveDataMapper, WaveData> i
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<String> getWindTurbineNumberSamplingFrequency(String windCode, String windTurbineNumber) {
|
|
|
+ public List<Integer> getWindTurbineNumberSamplingFrequency(String windCode, String windTurbineNumber) {
|
|
|
if (windCode.contains(" ")) {
|
|
|
throw new BusinessException("风场参数异常");
|
|
|
} else {
|
|
|
@@ -81,4 +145,118 @@ public class WaveDataServiceImpl extends ServiceImpl<WaveDataMapper, WaveData> i
|
|
|
return waveDataMapper.getWindTurbineNumberSamplingFrequency(windCode, windTurbineNumber);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<ItemOutData> getAllWindFarmAndFirstData(GetAllWindFarmAndFirstInData inData) {
|
|
|
+
|
|
|
+ LambdaQueryWrapper<WaveConf> waveConfLambdaQueryWrapper = Wrappers.lambdaQuery(WaveConf.class);
|
|
|
+ waveConfLambdaQueryWrapper.eq(WaveConf::getStatus, 1);
|
|
|
+ if (StringUtils.isNotBlank(inData.getWindFarmName())) {
|
|
|
+ waveConfLambdaQueryWrapper.eq(WaveConf::getWindName, inData.getWindFarmName());
|
|
|
+ }
|
|
|
+ waveConfLambdaQueryWrapper.orderByDesc(WaveConf::getId);
|
|
|
+
|
|
|
+ List<WaveConf> waveConfs = waveConfService.list(waveConfLambdaQueryWrapper);
|
|
|
+ boolean first = true;
|
|
|
+ List<ItemOutData> list = new ArrayList<>();
|
|
|
+ for (WaveConf conf : waveConfs) {
|
|
|
+ ItemOutData outData = new ItemOutData();
|
|
|
+ outData.setItemKey(conf.getWindCode());
|
|
|
+ outData.setItemValue(conf.getWindName());
|
|
|
+ if (first) {
|
|
|
+ first = false;
|
|
|
+ outData.setHasNext(true);
|
|
|
+ List<Map<String, String>> maps = waveDataMapper.getTableTreeData(conf.getWindCode() + "_wave", inData.getBeginTime(), inData.getEndTime());
|
|
|
+ outData.setNextData(buildItemOutData(maps));
|
|
|
+ }
|
|
|
+
|
|
|
+ list.add(outData);
|
|
|
+ }
|
|
|
+
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<ItemOutData> getWindFarmData(GetAllWindFarmAndFirstInData inData) {
|
|
|
+ if (StringUtils.isBlank(inData.getWindFarmCode()) || inData.getWindFarmCode().contains(" ")) {
|
|
|
+ throw new BusinessException("风场参数异常");
|
|
|
+ }
|
|
|
+ List<Map<String, String>> maps = waveDataMapper.getTableTreeData(inData.getWindFarmCode() + "_wave", inData.getBeginTime(), inData.getEndTime());
|
|
|
+ if (null == maps || maps.isEmpty()) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+
|
|
|
+ return buildItemOutData(maps);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 核心方法:按新的key/value规则构建层级化的ItemOutData列表
|
|
|
+ */
|
|
|
+ private List<ItemOutData> buildItemOutData(List<Map<String, String>> maps) {
|
|
|
+ List<ItemOutData> rootList = new ArrayList<>();
|
|
|
+
|
|
|
+ // 第一步:按风机编号(wind_turbine_number)分组(保证风机节点唯一)
|
|
|
+ Map<String, List<Map<String, String>>> turbineGroup = maps.stream()
|
|
|
+ .collect(Collectors.groupingBy(map -> map.get("wind_turbine_number")));
|
|
|
+
|
|
|
+ // 遍历每个风机分组,构建第一层(风机)
|
|
|
+ for (Map.Entry<String, List<Map<String, String>>> turbineEntry : turbineGroup.entrySet()) {
|
|
|
+ String turbineNumber = turbineEntry.getKey(); // itemKey = 风机编号
|
|
|
+ List<Map<String, String>> turbineDataList = turbineEntry.getValue();
|
|
|
+ // 取风机名称(同一风机编号下名称一致,取第一个即可)
|
|
|
+ String turbineName = turbineDataList.get(0).get("wind_turbine_name");
|
|
|
+
|
|
|
+ // 构建风机层级ItemOutData:key=风机编号,value=风机名称,hasNext=true
|
|
|
+ ItemOutData turbineItem = new ItemOutData(turbineNumber, turbineName, true);
|
|
|
+
|
|
|
+ // 第二步:在当前风机下,按测点英文名称(detection_point_en)分组
|
|
|
+ Map<String, List<Map<String, String>>> pointGroup = turbineDataList.stream()
|
|
|
+ .collect(Collectors.groupingBy(map -> map.get("detection_point_en")));
|
|
|
+
|
|
|
+ // 遍历每个测点分组,构建第二层(测点)
|
|
|
+ for (Map.Entry<String, List<Map<String, String>>> pointEntry : pointGroup.entrySet()) {
|
|
|
+ String pointEn = pointEntry.getKey(); // itemKey = 测点英文名称
|
|
|
+ List<Map<String, String>> pointDataList = pointEntry.getValue();
|
|
|
+ // 取测点中文名称(同一英文标识下中文名称一致,取第一个即可)
|
|
|
+ String pointCn = pointDataList.get(0).get("detection_point_cn");
|
|
|
+
|
|
|
+ // 构建测点层级ItemOutData:key=测点英文,value=测点中文,hasNext=true
|
|
|
+ ItemOutData pointItem = new ItemOutData(pointEn, pointCn, true);
|
|
|
+
|
|
|
+ // 第三步:遍历当前测点下的所有数据,构建第三层(时间)
|
|
|
+ // 时间层:key=id,value=time_stamp(每个id对应一条时间记录,无需去重)
|
|
|
+ for (Map<String, String> timeMap : pointDataList) {
|
|
|
+ String id = String.valueOf(timeMap.get("id")); // itemKey = id
|
|
|
+ String timeStamp = String.valueOf(timeMap.get("time_stamp")).replace("T", " "); // itemValue = 时间戳
|
|
|
+ String hz = String.valueOf(timeMap.get("sampling_frequency"));
|
|
|
+ String rotational_speed = String.valueOf(timeMap.get("rotational_speed"));
|
|
|
+ String type = String.valueOf(timeMap.get("type"));
|
|
|
+ String brand = timeMap.get("brand");
|
|
|
+ String brandType = timeMap.get("brand_type");
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("Hz", hz);
|
|
|
+ jsonObject.put("RPM", rotational_speed);
|
|
|
+ jsonObject.put("type", type);
|
|
|
+// jsonObject.put("type_detail", "-1:不存在 0:角度 1:速度 2:加速度 3:位移 4:包络,默认 -1");
|
|
|
+ jsonObject.put("brand", brand);
|
|
|
+ jsonObject.put("brandType", brandType);
|
|
|
+
|
|
|
+ // 构建时间层级ItemOutData:key=id,value=时间戳,hasNext=false
|
|
|
+ ItemOutData timeItem = new ItemOutData(id, timeStamp, false, jsonObject);
|
|
|
+ pointItem.getNextData().add(timeItem);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // 将测点Item添加到风机Item的nextData中
|
|
|
+ turbineItem.getNextData().add(pointItem);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 将风机Item添加到顶层列表
|
|
|
+ rootList.add(turbineItem);
|
|
|
+ }
|
|
|
+
|
|
|
+ return rootList;
|
|
|
+ }
|
|
|
+
|
|
|
}
|