|
@@ -2,6 +2,7 @@ package com.energy.manage.service.service.vibration.impl;
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
|
|
+import cn.hutool.core.io.FileUtil;
|
|
|
import cn.hutool.core.text.StrFormatter;
|
|
import cn.hutool.core.text.StrFormatter;
|
|
|
import cn.hutool.core.text.csv.CsvUtil;
|
|
import cn.hutool.core.text.csv.CsvUtil;
|
|
|
import cn.hutool.core.text.csv.CsvWriter;
|
|
import cn.hutool.core.text.csv.CsvWriter;
|
|
@@ -9,13 +10,13 @@ import cn.hutool.core.util.CharsetUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
|
|
+import com.energy.manage.common.constant.redis.ManagerRedisKeyConstant;
|
|
|
import com.energy.manage.common.reponse.HttpResult;
|
|
import com.energy.manage.common.reponse.HttpResult;
|
|
|
import com.energy.manage.service.client.skf.AuthClient;
|
|
import com.energy.manage.service.client.skf.AuthClient;
|
|
|
import com.energy.manage.service.client.skf.DynamicMeasurementsClient;
|
|
import com.energy.manage.service.client.skf.DynamicMeasurementsClient;
|
|
|
import com.energy.manage.service.constant.client.skf.SkfClientConstants;
|
|
import com.energy.manage.service.constant.client.skf.SkfClientConstants;
|
|
|
-import com.energy.manage.service.domain.client.skf.AutoTokenVO;
|
|
|
|
|
-import com.energy.manage.service.domain.client.skf.DynamicMeasurementsVo;
|
|
|
|
|
-import com.energy.manage.service.domain.client.skf.HierarchyListVo;
|
|
|
|
|
|
|
+import com.energy.manage.service.domain.client.skf.*;
|
|
|
|
|
+import com.energy.manage.service.service.cache.CacheService;
|
|
|
import com.energy.manage.service.service.vibration.VibrationService;
|
|
import com.energy.manage.service.service.vibration.VibrationService;
|
|
|
import com.energy.manage.service.util.HttpGetClient;
|
|
import com.energy.manage.service.util.HttpGetClient;
|
|
|
import com.google.common.collect.Lists;
|
|
import com.google.common.collect.Lists;
|
|
@@ -23,20 +24,20 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
+import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
import java.io.File;
|
|
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.Month;
|
|
import java.time.Month;
|
|
|
import java.time.ZoneId;
|
|
import java.time.ZoneId;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.time.format.TextStyle;
|
|
import java.time.format.TextStyle;
|
|
|
-import java.util.HashMap;
|
|
|
|
|
-import java.util.List;
|
|
|
|
|
-import java.util.Locale;
|
|
|
|
|
-import java.util.Map;
|
|
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
@Slf4j
|
|
@Slf4j
|
|
|
@Service
|
|
@Service
|
|
@@ -48,15 +49,22 @@ public class VibrationServiceImpl implements VibrationService {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private DynamicMeasurementsClient dynamicMeasurementsClient;
|
|
private DynamicMeasurementsClient dynamicMeasurementsClient;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private CacheService cacheService;
|
|
|
|
|
+
|
|
|
// 定义时间格式
|
|
// 定义时间格式
|
|
|
private final String dateTimeFormatter = "yyyy-MM-dd";
|
|
private final String dateTimeFormatter = "yyyy-MM-dd";
|
|
|
|
|
|
|
|
private final String dateFormatter = "MM-dd";
|
|
private final String dateFormatter = "MM-dd";
|
|
|
|
|
|
|
|
- private String dynamicMeasurementsUrl = "http://192.168.50.242:13050/v1/points/{}/dynamicMeasurements";
|
|
|
|
|
|
|
+ @Value("${skf.data.url}")
|
|
|
|
|
+ private String dynamicMeasurementsUrl;
|
|
|
|
|
|
|
|
private ZoneId shanghaiZone = ZoneId.of("Asia/Shanghai");
|
|
private ZoneId shanghaiZone = ZoneId.of("Asia/Shanghai");
|
|
|
|
|
|
|
|
|
|
+ // redis 过期时间
|
|
|
|
|
+ private final Long expire = 172800L;
|
|
|
|
|
+
|
|
|
private String yesterdayTime = LocalDate.now().minusDays(1).format(DateTimeFormatter.ofPattern(dateFormatter));
|
|
private String yesterdayTime = LocalDate.now().minusDays(1).format(DateTimeFormatter.ofPattern(dateFormatter));
|
|
|
|
|
|
|
|
@Value("${skf.data.path}")
|
|
@Value("${skf.data.path}")
|
|
@@ -65,6 +73,11 @@ public class VibrationServiceImpl implements VibrationService {
|
|
|
@Value("${skf.data.condition}")
|
|
@Value("${skf.data.condition}")
|
|
|
private String condition;
|
|
private String condition;
|
|
|
|
|
|
|
|
|
|
+ private List<String> abcd = Lists.newArrayList();
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 通过skf接口获取树结构(带部件)
|
|
|
|
|
+ */
|
|
|
@Override
|
|
@Override
|
|
|
public void extractSkfPointData() {
|
|
public void extractSkfPointData() {
|
|
|
|
|
|
|
@@ -111,7 +124,7 @@ public class VibrationServiceImpl implements VibrationService {
|
|
|
+ engineHierarchyListVo.getName() + "/" + getCurrentYearByTimeZone(this.shanghaiZone) + "/"
|
|
+ engineHierarchyListVo.getName() + "/" + getCurrentYearByTimeZone(this.shanghaiZone) + "/"
|
|
|
+ yesterdayTime;
|
|
+ yesterdayTime;
|
|
|
|
|
|
|
|
- String fileNamePrefix = fieldHierarchyListVo.getName() + "#" + engineHierarchyListVo.getName() + "#" + pointHierarchyListVo.getName();
|
|
|
|
|
|
|
+ String fileNamePrefix = fieldHierarchyListVo.getName() + "@" + engineHierarchyListVo.getName() + "@" + pointHierarchyListVo.getName();
|
|
|
|
|
|
|
|
// 获取具体数据并生成csv
|
|
// 获取具体数据并生成csv
|
|
|
dynamicMeasurementsConvertData(dynamicMeasurementsList, dataPath, fileNamePrefix);
|
|
dynamicMeasurementsConvertData(dynamicMeasurementsList, dataPath, fileNamePrefix);
|
|
@@ -123,9 +136,11 @@ public class VibrationServiceImpl implements VibrationService {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 通过skf接口获取树结构(不带部件,直接到测点)
|
|
|
|
|
+ */
|
|
|
@Override
|
|
@Override
|
|
|
- public void extracTwindGeneratorSkfPointData() {
|
|
|
|
|
|
|
+ public void extracTwindGeneratorSkfPointData(String yesterdayDate) {
|
|
|
// 获取组织结构
|
|
// 获取组织结构
|
|
|
List<HierarchyListVo> hierarchyListVoList = getHierarchyLists();
|
|
List<HierarchyListVo> hierarchyListVoList = getHierarchyLists();
|
|
|
log.info("获取SKF数据组织结构树 >>> " + JSON.toJSONString(hierarchyListVoList));
|
|
log.info("获取SKF数据组织结构树 >>> " + JSON.toJSONString(hierarchyListVoList));
|
|
@@ -139,47 +154,95 @@ public class VibrationServiceImpl implements VibrationService {
|
|
|
if (CollectionUtils.isEmpty(fieldHierarchyListVo.getChildren())) {
|
|
if (CollectionUtils.isEmpty(fieldHierarchyListVo.getChildren())) {
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
- // 是否包含当前风场
|
|
|
|
|
-// if (fieldHierarchyListVo.getName().contains(this.condition)) {
|
|
|
|
|
- //风机,特殊情况需要单独处理(风机到部件到具体测点有可能少一层部件)需要根据不同风场进行单独处理,风机直接获取测点id,跳过部件
|
|
|
|
|
- engine:
|
|
|
|
|
- for (HierarchyListVo engineHierarchyListVo : fieldHierarchyListVo.getChildren()) {
|
|
|
|
|
- if (CollectionUtils.isEmpty(engineHierarchyListVo.getChildren())) {
|
|
|
|
|
|
|
+ //风机,特殊情况需要单独处理(风机到部件到具体测点有可能少一层部件)需要根据不同风场进行单独处理,风机直接获取测点id,跳过部件
|
|
|
|
|
+ engine:
|
|
|
|
|
+ for (HierarchyListVo engineHierarchyListVo : fieldHierarchyListVo.getChildren()) {
|
|
|
|
|
+ if (CollectionUtils.isEmpty(engineHierarchyListVo.getChildren())) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ // 具体测点
|
|
|
|
|
+ for (HierarchyListVo pointHierarchyListVo : engineHierarchyListVo.getChildren()) {
|
|
|
|
|
+ //获取测点id值,调用skf接口获取振动测点值
|
|
|
|
|
+ log.info("测点路径:>>> " + companyHierarchyListVo.getName() + " -> " + fieldHierarchyListVo.getName() +
|
|
|
|
|
+ " -> " + engineHierarchyListVo.getName() + " -> " + pointHierarchyListVo.getName());
|
|
|
|
|
+ // 测点id
|
|
|
|
|
+ Integer pointId = pointHierarchyListVo.getId();
|
|
|
|
|
+ log.info("测点id >>> " + pointId);
|
|
|
|
|
+
|
|
|
|
|
+ List<DynamicMeasurementsVo> dynamicMeasurementsList = getDynamicMeasurementsList(pointId);
|
|
|
|
|
+ if (CollectionUtil.isEmpty(dynamicMeasurementsList)) {
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
- // 具体测点
|
|
|
|
|
- for (HierarchyListVo pointHierarchyListVo : engineHierarchyListVo.getChildren()) {
|
|
|
|
|
- //获取测点id值,调用skf接口获取振动测点值
|
|
|
|
|
- log.info("测点路径:>>> " + companyHierarchyListVo.getName() + " -> " + fieldHierarchyListVo.getName() +
|
|
|
|
|
- " -> " + engineHierarchyListVo.getName() + " -> " + pointHierarchyListVo.getName());
|
|
|
|
|
- // 测点id
|
|
|
|
|
- Integer pointId = pointHierarchyListVo.getId();
|
|
|
|
|
- log.info("测点id >>> " + pointId);
|
|
|
|
|
|
|
+ // 拼接服务器地址
|
|
|
|
|
+ String dataPath = skfDataPath + "/" + companyHierarchyListVo.getName() + "/" + fieldHierarchyListVo.getName() + "/"
|
|
|
|
|
+ + engineHierarchyListVo.getName() + "/" + getCurrentYearByTimeZone(this.shanghaiZone) + "/"
|
|
|
|
|
+ + yesterdayTime;
|
|
|
|
|
|
|
|
- List<DynamicMeasurementsVo> dynamicMeasurementsList = getDynamicMeasurementsList(pointId);
|
|
|
|
|
- if (CollectionUtil.isEmpty(dynamicMeasurementsList)) {
|
|
|
|
|
- continue;
|
|
|
|
|
- }
|
|
|
|
|
- // 拼接服务器地址
|
|
|
|
|
- String dataPath = skfDataPath + companyHierarchyListVo.getName() + "/" + fieldHierarchyListVo.getName() + "/"
|
|
|
|
|
- + engineHierarchyListVo.getName() + "/" + getCurrentYearByTimeZone(this.shanghaiZone) + "/"
|
|
|
|
|
- + yesterdayTime;
|
|
|
|
|
|
|
+ String fileNamePrefix = fieldHierarchyListVo.getName() + "@" + engineHierarchyListVo.getName() + "@" + pointId + "@" + pointHierarchyListVo.getName();
|
|
|
|
|
|
|
|
- String fileNamePrefix = fieldHierarchyListVo.getName() + "#" + engineHierarchyListVo.getName() + "#" + pointHierarchyListVo.getName();
|
|
|
|
|
|
|
+ // 获取具体数据并生成csv
|
|
|
|
|
+ dynamicMeasurementsConvertData(dynamicMeasurementsList, dataPath, fileNamePrefix);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- // 获取具体数据并生成csv
|
|
|
|
|
- dynamicMeasurementsConvertData(dynamicMeasurementsList, dataPath, fileNamePrefix);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ StringBuffer keyBuffer = new StringBuffer(ManagerRedisKeyConstant.SKF_SHAKE_KEY);
|
|
|
|
|
+ keyBuffer.append(ManagerRedisKeyConstant.PLACEHOLDER);
|
|
|
|
|
+ keyBuffer.append(yesterdayDate);
|
|
|
|
|
+ cacheService.add(keyBuffer.toString(), "1");
|
|
|
|
|
|
|
|
-// }
|
|
|
|
|
|
|
+ log.info(" >>> skf接口处理完毕 <<<");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void extracTwindGeneratorSkfMachinePart(String yesterdayDate) {
|
|
|
|
|
|
|
|
|
|
+ log.info(" ========== 生成故障频率开始 ========== ");
|
|
|
|
|
+ List<MachineVO> machineList = getMachine();
|
|
|
|
|
+ log.info(" skf机器号 =====> " + machineList);
|
|
|
|
|
+
|
|
|
|
|
+ if (CollectionUtil.isEmpty(machineList)) {
|
|
|
|
|
+ log.info("=====>没有skf机器号<=====");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ for (MachineVO machineVO : machineList) {
|
|
|
|
|
+ // 获取skf故障频率
|
|
|
|
|
+ MachinePartVO machinePart = getMachinePart(machineVO.getId());
|
|
|
|
|
+ String machinePartJson = JSON.toJSONString(machinePart);
|
|
|
|
|
+ log.info("机器号" + machineVO.getId() + ":故障频律 ====> " + machinePartJson);
|
|
|
|
|
+
|
|
|
|
|
+ if (StringUtils.isEmpty(machineVO.getPath())) {
|
|
|
|
|
+ log.error(" 机器号对应风场路径为空 ");
|
|
|
|
|
+ continue;
|
|
|
}
|
|
}
|
|
|
- log.info(" >>> skf接口处理完毕 <<<");
|
|
|
|
|
|
|
+ // 使用split方法,注意\\是转义字符
|
|
|
|
|
+ List<String> pathlist = Arrays.stream(machineVO.getPath().split("\\\\")).collect(Collectors.toList());
|
|
|
|
|
+ // 打印结果
|
|
|
|
|
+ System.out.println("分隔结果: " + pathlist);
|
|
|
|
|
+
|
|
|
|
|
+ StringBuffer skfPath = new StringBuffer();
|
|
|
|
|
+ for (String path : pathlist) {
|
|
|
|
|
+ skfPath.append(path).append("/");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //机器id@关联测点id@output.json
|
|
|
|
|
+ String fileName = machineVO.getName() + "@" + machinePart.getSpeedPointId() + "@output.json";
|
|
|
|
|
+
|
|
|
|
|
+ // 拼接服务器地址
|
|
|
|
|
+ StringBuffer dataPath = new StringBuffer(skfDataPath).append("/").
|
|
|
|
|
+ append(skfPath).
|
|
|
|
|
+ append(getCurrentYearByTimeZone(this.shanghaiZone)).append("/").
|
|
|
|
|
+ append(yesterdayTime).append("/").append(fileName);
|
|
|
|
|
+
|
|
|
|
|
+ FileUtil.writeString(machinePartJson, new File(dataPath.toString()), StandardCharsets.UTF_8);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ log.info(" ========== 生成故障频率结束 ========== ");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 通过测点id获取测点数据并生成csv文件
|
|
* 通过测点id获取测点数据并生成csv文件
|
|
|
*
|
|
*
|
|
@@ -222,7 +285,7 @@ public class VibrationServiceImpl implements VibrationService {
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 将测点数据转换抽取
|
|
|
|
|
|
|
+ * 将测点数据转换抽取文件
|
|
|
*
|
|
*
|
|
|
* @param dynamicMeasurementsList
|
|
* @param dynamicMeasurementsList
|
|
|
* @return
|
|
* @return
|
|
@@ -238,7 +301,11 @@ public class VibrationServiceImpl implements VibrationService {
|
|
|
if (CollectionUtils.isEmpty(doubleList)) {
|
|
if (CollectionUtils.isEmpty(doubleList)) {
|
|
|
break dynamic;
|
|
break dynamic;
|
|
|
}
|
|
}
|
|
|
- String fileName = fileNamePrefix + "@" + dynamicMeasurementsVo.getSpeed() + "@" + utctolocal(dynamicMeasurementsVo.getReadingTimeUTC()) + "_cms.csv";
|
|
|
|
|
|
|
+ // 风场名称@风机名称@测点id@测点名称@转速@采样频率@震动类型时间_cms.csv
|
|
|
|
|
+ String fileName = fileNamePrefix + "@" + dynamicMeasurementsVo.getSpeed() + "@" + dynamicMeasurementsVo.getSampleRate() + "@" + dynamicMeasurementsVo.getEUType() + "@" + utctolocal(dynamicMeasurementsVo.getReadingTimeUTC()) + "_cms.csv";
|
|
|
|
|
+
|
|
|
|
|
+ // abcd.add("震动类型:" + dynamicMeasurementsVo.getEUType() + " 类型值: " + dynamicMeasurementsVo.getEu());
|
|
|
|
|
+
|
|
|
//生成csv文件
|
|
//生成csv文件
|
|
|
createCsvFile(doubleList, dataPath, fileName);
|
|
createCsvFile(doubleList, dataPath, fileName);
|
|
|
log.info("抽取skf数据并生成csv文件 >>>> " + fileName);
|
|
log.info("抽取skf数据并生成csv文件 >>>> " + fileName);
|
|
@@ -306,6 +373,40 @@ public class VibrationServiceImpl implements VibrationService {
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
|
+ * 获取skf机器信息
|
|
|
|
|
+ *
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ private List<MachineVO> getMachine() {
|
|
|
|
|
+
|
|
|
|
|
+ String skfToken = getSkfAutoToken();
|
|
|
|
|
+ if (StringUtils.isEmpty(skfToken)) {
|
|
|
|
|
+ log.info(" >>>>>> 获取skftoken失败 <<<<<< ");
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ List<MachineVO> list = dynamicMeasurementsClient.getMachine(skfToken);
|
|
|
|
|
+ return CollectionUtils.isEmpty(list) ? null : list;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取skf故障频率
|
|
|
|
|
+ *
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ private MachinePartVO getMachinePart(int machineId) {
|
|
|
|
|
+
|
|
|
|
|
+ String skfToken = getSkfAutoToken();
|
|
|
|
|
+ if (StringUtils.isEmpty(skfToken)) {
|
|
|
|
|
+ log.info(" >>>>>> 获取skftoken失败 <<<<<< ");
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ MachinePartVO machinePart = dynamicMeasurementsClient.getMachinePart(skfToken, machineId);
|
|
|
|
|
+ return machinePart;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
* 获取token
|
|
* 获取token
|
|
|
*
|
|
*
|
|
|
* @return
|
|
* @return
|