|
@@ -0,0 +1,690 @@
|
|
|
+//package com.jiayue.insu.inclientqn.service.client;
|
|
|
+//
|
|
|
+//import cn.hutool.core.date.DateTime;
|
|
|
+//import cn.hutool.core.date.DateUtil;
|
|
|
+//import cn.hutool.core.date.LocalDateTimeUtil;
|
|
|
+//import cn.hutool.core.util.StrUtil;
|
|
|
+//import cn.hutool.http.HttpRequest;
|
|
|
+//import cn.hutool.json.JSONObject;
|
|
|
+//import cn.hutool.json.JSONUtil;
|
|
|
+//import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+//import com.jiayue.insu.inclientqn.constant.CommonStant;
|
|
|
+//import com.jiayue.insu.inclientqn.entity.*;
|
|
|
+//import com.jiayue.insu.inclientqn.inenum.QNHLEnum;
|
|
|
+//import com.jiayue.insu.inclientqn.inenum.StatusEnum;
|
|
|
+//import com.jiayue.insu.inclientqn.mapper.CorrforeStMapper;
|
|
|
+//import com.jiayue.insu.inclientqn.model.RequestVo;
|
|
|
+//import com.jiayue.insu.inclientqn.model.ResponseVo;
|
|
|
+//import com.jiayue.insu.inclientqn.permisson.com.ComPermisson;
|
|
|
+//import com.jiayue.insu.inclientqn.service.*;
|
|
|
+//import com.jiayue.insu.inclientqn.util.RequestUtils;
|
|
|
+//import com.jiayue.insu.inclientqn.util.SystermUtils;
|
|
|
+//import com.jiayue.insu.minio.util.MinioUtilService;
|
|
|
+//import lombok.RequiredArgsConstructor;
|
|
|
+//import lombok.extern.slf4j.Slf4j;
|
|
|
+//import org.apache.velocity.Template;
|
|
|
+//import org.apache.velocity.VelocityContext;
|
|
|
+//import org.apache.velocity.app.VelocityEngine;
|
|
|
+//import org.springframework.beans.factory.annotation.Value;
|
|
|
+//import org.springframework.stereotype.Service;
|
|
|
+//
|
|
|
+//import java.io.File;
|
|
|
+//import java.io.FileOutputStream;
|
|
|
+//import java.io.IOException;
|
|
|
+//import java.io.StringWriter;
|
|
|
+//import java.math.BigDecimal;
|
|
|
+//import java.time.LocalDateTime;
|
|
|
+//import java.util.*;
|
|
|
+//import java.util.regex.Matcher;
|
|
|
+//import java.util.regex.Pattern;
|
|
|
+//
|
|
|
+///**
|
|
|
+// * @description:
|
|
|
+// * @author: yuanhao
|
|
|
+// * @createDate: 2021/9/27
|
|
|
+// * @version: 1.0
|
|
|
+// */
|
|
|
+//@Service
|
|
|
+//@Slf4j
|
|
|
+//@RequiredArgsConstructor
|
|
|
+//public class SHCorrforeService extends ServiceImpl<CorrforeStMapper, CorrforeSt> {
|
|
|
+//
|
|
|
+// private final RecordService recordService;
|
|
|
+// private final StationService stationService;
|
|
|
+// private final CorrforeStService corrforeStService;
|
|
|
+// private final VelocityEngine velocityEngine;
|
|
|
+// private final ComPermisson comPermisson;
|
|
|
+// private final MinioUtilService minioUtilService;
|
|
|
+// private final CorrectUltraShortTermService correctUltraShortTermService;
|
|
|
+// private final RepairPlanService repairPlanService;
|
|
|
+//
|
|
|
+// @Value("${minio.bucketname}")
|
|
|
+// private String bucketName;
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 下载超短期数据
|
|
|
+// *
|
|
|
+// * @param signTime
|
|
|
+// */
|
|
|
+// public void downLoadUltraShortTerm(long signTime) {
|
|
|
+// // 获取全部场站
|
|
|
+// List<Station> stationList = stationService.findAll();
|
|
|
+// Record record;
|
|
|
+// LocalDateTime localDateTime = LocalDateTimeUtil.of(signTime);
|
|
|
+//
|
|
|
+// // 如果场站大于2个,则为多场站情况
|
|
|
+// if (stationList != null && stationList.size() > 1) {
|
|
|
+// for (Station station : stationList) {
|
|
|
+// record = recordService.findTimeAndTypeAndContentAndStateAndStationCode(localDateTime.plusMinutes(15L), CommonStant.RECORD_TYPE_CORRECT_DATA, QNHLEnum.DATA_CORRULTRSHOR_TYPE.getCode(), StatusEnum.SUCCESS.getSign(),station.getStationCode());
|
|
|
+// if (record != null) {
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// this.getUltraShortTermAndGenFile(station, signTime);
|
|
|
+// }
|
|
|
+// // 如果只有一个场站
|
|
|
+// } else if (stationList != null && stationList.size() == 1) {
|
|
|
+// record = recordService.findTimeAndTypeAndContentAndState(localDateTime.plusMinutes(15L), CommonStant.RECORD_TYPE_CORRECT_DATA, QNHLEnum.DATA_CORRULTRSHOR_TYPE.getCode(), StatusEnum.SUCCESS.getSign());
|
|
|
+// if (record != null) {
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// this.getUltraShortTermAndGenFile(stationList.get(0), signTime);
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 获取超短期修正数据并生成文件
|
|
|
+// * @param station
|
|
|
+// * @param signTime
|
|
|
+// */
|
|
|
+// public void getUltraShortTermAndGenFile(Station station, long signTime){
|
|
|
+// //标记为要生成超短期的时刻
|
|
|
+// LocalDateTime signLDT = LocalDateTimeUtil.of(signTime).plusMinutes(15L);
|
|
|
+// // 初始化日志
|
|
|
+// Record record = new Record();
|
|
|
+// record.setType(CommonStant.RECORD_TYPE_CORRECT_DATA);
|
|
|
+// record.setContent(QNHLEnum.DATA_CORRULTRSHOR_TYPE.getCode());
|
|
|
+// record.setCreateTime(LocalDateTime.now());
|
|
|
+// record.setStationCode(station.getStationCode());
|
|
|
+// //标记为要生成超短期的时刻
|
|
|
+// record.setTime(signLDT);
|
|
|
+// // 组装请求参数
|
|
|
+// RequestVo requestVo = RequestVo.CORRECT_US(station.getSignCode(), null, signTime);
|
|
|
+// JSONObject json = JSONUtil.parseObj(requestVo, true);
|
|
|
+// String body = json.toString();
|
|
|
+// // 发送请求
|
|
|
+// String response = RequestUtils.post(station.getDownloadurl(), body, station.getComKey());
|
|
|
+// // 返回结果校验成功
|
|
|
+// if (RequestUtils.checkResponse(response, record)) {
|
|
|
+// ResponseVo responseVo = JSONUtil.toBean(response, ResponseVo.class);
|
|
|
+// String code = responseVo.getRetCode();
|
|
|
+// // 如果请求成功
|
|
|
+// if (code.equals(QNHLEnum.REQUEST_SUCCESS.getCode())) {
|
|
|
+// // 获取请求结果
|
|
|
+// JSONObject jsonObject = JSONUtil.parseObj(responseVo.getData());
|
|
|
+// // 如果生成修正超短期文件成功
|
|
|
+// if (genUs(station, jsonObject)) {
|
|
|
+// // 将修正后的超短期数据入库
|
|
|
+// correctUltraShortTerm(jsonObject.get("data").toString(), signLDT);
|
|
|
+// // 设置日志操作状态
|
|
|
+// record.setState(StatusEnum.SUCCESS.getSign());
|
|
|
+// record.setStateContent(responseVo.getRetMsg());
|
|
|
+// // 如果生成超短期修正文件失败
|
|
|
+// } else {
|
|
|
+// // 设置日志操作状态
|
|
|
+// record.setState(StatusEnum.GEN_FILE_FAIL.getSign());
|
|
|
+// record.setStateContent(StatusEnum.GEN_FILE_FAIL.getMsg());
|
|
|
+// }
|
|
|
+// // 如果请求失败
|
|
|
+// } else {
|
|
|
+// // 设置日志操作状态
|
|
|
+// record.setState(code);
|
|
|
+// record.setStateContent(responseVo.getRetMsg());
|
|
|
+// }
|
|
|
+// }
|
|
|
+// // 保存操作日志
|
|
|
+// recordService.save(record);
|
|
|
+// }
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 下载检修计划
|
|
|
+// *
|
|
|
+// * @param signTime
|
|
|
+// */
|
|
|
+// public void downLoadRepairPlan(long signTime,Station station) {
|
|
|
+// // 获取当日开始时间
|
|
|
+// LocalDateTime localDateTime = LocalDateTimeUtil.beginOfDay(LocalDateTime.now());
|
|
|
+// //初始化操作日志
|
|
|
+// Record record = new Record();
|
|
|
+// record.setType(CommonStant.RECORD_TYPE_CORRECT_DATA);
|
|
|
+// record.setContent(QNHLEnum.DATA_REPAPLAN_TYPE.getCode());
|
|
|
+// record.setCreateTime(LocalDateTime.now());
|
|
|
+// record.setTime(localDateTime);
|
|
|
+// //组装请求参数
|
|
|
+// RequestVo requestVo = RequestVo.CORRECT_RP(null, signTime);
|
|
|
+// JSONObject json = JSONUtil.parseObj(requestVo, true);
|
|
|
+// String body = json.toString();
|
|
|
+// // 发送请求,下载检修计划
|
|
|
+// String response = RequestUtils.post(station.getDownloadurl(), body, station.getComKey());
|
|
|
+// // 如果返回结果正常
|
|
|
+// if (RequestUtils.checkResponse(response, record)) {
|
|
|
+// // 获取返回信息
|
|
|
+// ResponseVo responseVo = JSONUtil.toBean(response, ResponseVo.class);
|
|
|
+// String code = responseVo.getRetCode();
|
|
|
+// // 如果调用接口成功
|
|
|
+// if (code.equals(QNHLEnum.REQUEST_SUCCESS.getCode())) {
|
|
|
+// // 如果生成检修计划文件成功
|
|
|
+// if (genRp(station, responseVo.getData())) {
|
|
|
+// // 保存检修计划数据
|
|
|
+// repairPlan(responseVo.getData(), localDateTime);
|
|
|
+// // 设置操作结果
|
|
|
+// record.setState(StatusEnum.SUCCESS.getSign());
|
|
|
+// record.setStateContent(responseVo.getRetMsg());
|
|
|
+// } else {
|
|
|
+// // 设置操作结果
|
|
|
+// record.setState(StatusEnum.GEN_FILE_FAIL.getSign());
|
|
|
+// record.setStateContent(StatusEnum.GEN_FILE_FAIL.getMsg());
|
|
|
+// }
|
|
|
+// //调用接口失败
|
|
|
+// } else {
|
|
|
+// // 设置操作结果
|
|
|
+// record.setState(code);
|
|
|
+// record.setStateContent(responseVo.getRetMsg());
|
|
|
+// }
|
|
|
+// }
|
|
|
+// // 保存操作记录
|
|
|
+// recordService.save(record);
|
|
|
+// }
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 下载修正文件,从嘉越云上
|
|
|
+// *
|
|
|
+// * @param station
|
|
|
+// * @return
|
|
|
+// */
|
|
|
+// public boolean downLoadCorrforeFile(Station station) {
|
|
|
+//
|
|
|
+// Record record = new Record();
|
|
|
+// record.setType(CommonStant.RECORD_TYPE_PULL_CORRECT_JY);
|
|
|
+// LocalDateTime localDateTime = LocalDateTimeUtil.beginOfDay(LocalDateTime.now());
|
|
|
+// record.setTime(localDateTime);
|
|
|
+// record.setCreateTime(LocalDateTime.now());
|
|
|
+// boolean isUpload = false;
|
|
|
+//
|
|
|
+// try {
|
|
|
+// List<String> names = minioUtilService.listObjects(bucketName, station.getStationCode(), true);
|
|
|
+// boolean isFile = false;
|
|
|
+// String downfileName = "";
|
|
|
+// String fileName = station.getStationCode() + "/DQ_" + DateUtil.format(DateUtil.beginOfDay(new Date()), "yyyyMMdd");
|
|
|
+// for (String name : names) {
|
|
|
+// if (name.contains(fileName)) {
|
|
|
+// isFile = true;
|
|
|
+// downfileName = name;
|
|
|
+// break;
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// if (isFile) {
|
|
|
+// minioUtilService.downloadObject(bucketName, downfileName, station.getLocalFilePath() + File.separatorChar + downfileName.split("/")[1]);
|
|
|
+// record.setState(StatusEnum.SUCCESS.getSign());
|
|
|
+// } else {
|
|
|
+// record.setState(StatusEnum.FILE_NULL.getSign());
|
|
|
+// }
|
|
|
+//
|
|
|
+// } catch (Exception e) {
|
|
|
+// e.printStackTrace();
|
|
|
+// record.setState(StatusEnum.DOWNLOAD_FILE_ERROR.getSign());
|
|
|
+// record.setStateContent(StatusEnum.DOWNLOAD_FILE_ERROR.getMsg());
|
|
|
+// }
|
|
|
+//
|
|
|
+// recordService.save(record);
|
|
|
+// return isUpload;
|
|
|
+// }
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 下载修正短期预测数据,从一体化上
|
|
|
+// *
|
|
|
+// * @param station
|
|
|
+// * @return
|
|
|
+// */
|
|
|
+// public boolean downLoadCorrforeData(Station station) {
|
|
|
+// // 初始化操作记录
|
|
|
+// Record record = new Record();
|
|
|
+// record.setType(CommonStant.RECORD_TYPE_PULL_CORRECT);
|
|
|
+// LocalDateTime localDateTime = LocalDateTimeUtil.beginOfDay(LocalDateTime.now());
|
|
|
+// record.setTime(localDateTime);
|
|
|
+// record.setCreateTime(LocalDateTime.now());
|
|
|
+// // 获取token
|
|
|
+// String token = station.getComKey();
|
|
|
+// // 获取下载路径
|
|
|
+// String dataPullUrl = station.getDownloadurl();
|
|
|
+//
|
|
|
+// boolean result = false;
|
|
|
+// boolean isUpload = false;
|
|
|
+// String response;
|
|
|
+// RequestVo requestVo;
|
|
|
+// List<CorrforeSt> list = new ArrayList<>();
|
|
|
+// // 如果token为空或者token失效,从新获取token
|
|
|
+// LocalDateTime tokenTime = station.getKeyTime();
|
|
|
+// if (StrUtil.isEmpty(token) || LocalDateTime.now().isAfter(tokenTime)) {
|
|
|
+// if (comPermisson.generateKey(station)) {
|
|
|
+// station = stationService.findThis();
|
|
|
+// token = station.getComKey();
|
|
|
+// tokenTime = station.getKeyTime();
|
|
|
+// }
|
|
|
+// }
|
|
|
+// // 如果token为不为空并且者token未失效
|
|
|
+// if (StrUtil.isNotEmpty(token) && LocalDateTime.now().isBefore(tokenTime)) {
|
|
|
+// try {
|
|
|
+// //实装请求参数
|
|
|
+// DateTime dateTime = DateUtil.parse(DateUtil.today());
|
|
|
+// requestVo = RequestVo.builder()
|
|
|
+// .transferType(QNHLEnum.TRANSFER_TYPE_CORRECT.getCode())
|
|
|
+// .date(dateTime.toString("yyyyMMdd"))
|
|
|
+// .dataType(QNHLEnum.DATA_CORRFORE_TYPE.getCode())
|
|
|
+// .build();
|
|
|
+// // 将求情转为jsonString
|
|
|
+// JSONObject json = JSONUtil.parseObj(requestVo, true);
|
|
|
+// String body = json.toString();
|
|
|
+// // 发送请求
|
|
|
+// HttpRequest httpRequest = HttpRequest.post(dataPullUrl)
|
|
|
+// .header("Content-Type", "application/json")
|
|
|
+// .header("Authorization", token);
|
|
|
+// httpRequest.setGlobalTimeout(20000);
|
|
|
+// response = httpRequest
|
|
|
+// .body(body)
|
|
|
+// .execute().body();
|
|
|
+//
|
|
|
+// // 如果结果不为空
|
|
|
+// if (StrUtil.isNotEmpty(response)) {
|
|
|
+// boolean isJson = JSONUtil.isJsonObj(response);
|
|
|
+// // 如果返回结果是json类型
|
|
|
+// if (isJson) {
|
|
|
+// ResponseVo responseVo = JSONUtil.toBean(response, ResponseVo.class);
|
|
|
+// String code = responseVo.getRetCode();
|
|
|
+// // 如果调用结果成功
|
|
|
+// if (code.equals(QNHLEnum.REQUEST_SUCCESS.getCode())) {
|
|
|
+// log.info(station.getStationCode() + " 请求短期修正数据返回内容:{}", response);
|
|
|
+// try {
|
|
|
+// // 如果是光伏
|
|
|
+// if (CommonStant.ET_PHOTOVOLTAIC.equals(station.getType())) {
|
|
|
+// //解析光伏数据
|
|
|
+// list = correctPhotovoltaicData(responseVo.getData());
|
|
|
+// // 如果是风电
|
|
|
+// } else {
|
|
|
+// //解析风电数据
|
|
|
+// list = correctWindData(responseVo.getData());
|
|
|
+// }
|
|
|
+// /**************检测解析数据完整性*******************/
|
|
|
+// BigDecimal one = new BigDecimal("1");
|
|
|
+// BigDecimal checkCount = new BigDecimal(station.getDays().toString()).add(one).multiply(new BigDecimal("96")).add(one);
|
|
|
+// // 如果修正后短期数据不为0
|
|
|
+// if (list.size() > 0) {
|
|
|
+// if (list.size() < checkCount.intValue()) {
|
|
|
+// log.warn("========== 请求短期修正数据缺数: {}", list.size());
|
|
|
+// }
|
|
|
+// corrforeStService.updateBetweenForecastTime(list.get(0).getTimeFormat(), list.get(list.size() - 1).getTimeFormat(), list);
|
|
|
+// // 生成短期修正后文件
|
|
|
+// if(genFile(station, list)){
|
|
|
+// result = true;
|
|
|
+// }
|
|
|
+// // 如果短期数据为空
|
|
|
+// } else {
|
|
|
+// record.setState(StatusEnum.CONNECT_RESPONSE_CONTENT_NULL.getCode());
|
|
|
+// record.setStateContent(StatusEnum.CONNECT_RESPONSE_CONTENT_NULL.getMsg());
|
|
|
+// }
|
|
|
+// /**************检测解析数据完整性*******************/
|
|
|
+// } catch (Exception e) {
|
|
|
+// e.printStackTrace();
|
|
|
+// record.setState(StatusEnum.CONNECT_RESPONSE_FORMAT_ERROR.getSign());
|
|
|
+// record.setStateContent("解析短期或生成文件失败");
|
|
|
+// log.error("========== 解析短期或生成文件失败 ");
|
|
|
+// }
|
|
|
+//
|
|
|
+// if (result) {
|
|
|
+// log.info("========== 拉取短期修正数据成功! ==========");
|
|
|
+// record.setState(StatusEnum.SUCCESS.getSign());
|
|
|
+// record.setStateContent(String.valueOf(list.size()));
|
|
|
+// }
|
|
|
+//
|
|
|
+// } else {
|
|
|
+// record.setState(StatusEnum.RESPONSE_FAIL.getSign());
|
|
|
+// record.setStateContent(StatusEnum.RESPONSE_FAIL.getMsg());
|
|
|
+// log.error("========== 拉取短期修正数据失败 响应码异常 " + station.getStationCode() + " :请求短期修正数据返回内容:"+ response);
|
|
|
+// }
|
|
|
+// } else {
|
|
|
+// record.setState(StatusEnum.CONNECT_RESPONSE_FORMAT_ERROR.getSign());
|
|
|
+// record.setStateContent(StatusEnum.CONNECT_RESPONSE_FORMAT_ERROR.getMsg());
|
|
|
+// log.error("========== 拉取短期修正数据失败 接收响应字符串非json格式 ");
|
|
|
+// }
|
|
|
+// } else {
|
|
|
+// record.setState(StatusEnum.CONNECT_RESPONSE_CONTENT_NULL.getSign());
|
|
|
+// record.setStateContent(StatusEnum.CONNECT_RESPONSE_CONTENT_NULL.getMsg());
|
|
|
+// log.error("========== 拉取短期修正数据失败 返回响应内容为空 ==========");
|
|
|
+// }
|
|
|
+//
|
|
|
+// } catch (Exception e) {
|
|
|
+// record.setState(StatusEnum.CONNECT_ERROR.getSign());
|
|
|
+// record.setStateContent(StatusEnum.CONNECT_ERROR.getMsg());
|
|
|
+// log.error("========== 请求短期修正数据失败 连接断开或请求超时 ==========");
|
|
|
+// e.printStackTrace();
|
|
|
+//
|
|
|
+// }
|
|
|
+// }
|
|
|
+// recordService.save(record);
|
|
|
+// return isUpload;
|
|
|
+// }
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 光伏数据解析
|
|
|
+// *
|
|
|
+// * @param data 待解析数据
|
|
|
+// * @return
|
|
|
+// * @throws Exception
|
|
|
+// */
|
|
|
+// public List<CorrforeSt> correctPhotovoltaicData(String data) throws Exception {
|
|
|
+// List<CorrforeSt> list = new ArrayList<>();
|
|
|
+// String[] content = data.split("\n");
|
|
|
+//
|
|
|
+// for (int i = 3; i < content.length - 1; i++) {
|
|
|
+// CorrforeSt corrforeSt = new CorrforeSt();
|
|
|
+// String column = content[i];
|
|
|
+// String[] datas = column.split(CommonStant.SPACE1_CONSTANT);
|
|
|
+// corrforeSt.setForecastTime(DateUtil.parse(datas[2], "yyyyMMddHHmmss").getTime());
|
|
|
+// corrforeSt.setTimeFormat(DateUtil.parse(datas[2], "yyyyMMddHHmmss").toTimestamp().toLocalDateTime());
|
|
|
+// corrforeSt.setFpValue(isNumberOrNull(datas[3]));
|
|
|
+// corrforeSt.setGlobalR(isNumberOrNull(datas[4]));
|
|
|
+// corrforeSt.setDirectR(isNumberOrNull(datas[5]));
|
|
|
+// corrforeSt.setDiffuseR(isNumberOrNull(datas[6]));
|
|
|
+// corrforeSt.setT(isNumberOrNull(datas[7]));
|
|
|
+// corrforeSt.setRh(isNumberOrNull(datas[8]));
|
|
|
+// corrforeSt.setP(isNumberOrNull(datas[9]));
|
|
|
+// corrforeSt.setWs(isNumberOrNull(datas[10]));
|
|
|
+// corrforeSt.setWd(isNumberOrNull(datas[11]));
|
|
|
+// corrforeSt.setCorrectTime(LocalDateTime.now());
|
|
|
+// Collections.sort(list, Comparator.comparing(CorrforeSt::getForecastTime));
|
|
|
+// list.add(corrforeSt);
|
|
|
+// }
|
|
|
+// return list;
|
|
|
+// }
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 风电数据解析
|
|
|
+// *
|
|
|
+// * @param data 待解析数据
|
|
|
+// * @return 解析数据
|
|
|
+// * @throws Exception
|
|
|
+// */
|
|
|
+// public List<CorrforeSt> correctWindData(String data) throws Exception {
|
|
|
+// List<CorrforeSt> list = new ArrayList<>();
|
|
|
+// String[] content = data.split("\n");
|
|
|
+//
|
|
|
+// for (int i = 3; i < content.length - 1; i++) {
|
|
|
+// CorrforeSt corrforeSt = new CorrforeSt();
|
|
|
+// String column = content[i];
|
|
|
+// String[] datas = column.split(CommonStant.SPACE1_CONSTANT);
|
|
|
+// corrforeSt.setForecastTime(DateUtil.parse(datas[2], "yyyyMMddHHmmss").getTime());
|
|
|
+// corrforeSt.setTimeFormat(DateUtil.parse(datas[2], "yyyyMMddHHmmss").toTimestamp().toLocalDateTime());
|
|
|
+// corrforeSt.setFpValue(isNumberOrNull(datas[3]));
|
|
|
+// corrforeSt.setWs(isNumberOrNull(datas[4]));
|
|
|
+// corrforeSt.setWd(isNumberOrNull(datas[5]));
|
|
|
+// corrforeSt.setT(isNumberOrNull(datas[6]));
|
|
|
+// corrforeSt.setRh(isNumberOrNull(datas[7]));
|
|
|
+// corrforeSt.setP(isNumberOrNull(datas[8]));
|
|
|
+// corrforeSt.setCorrectTime(LocalDateTime.now());
|
|
|
+// Collections.sort(list, Comparator.comparing(CorrforeSt::getForecastTime));
|
|
|
+// list.add(corrforeSt);
|
|
|
+// }
|
|
|
+// return list;
|
|
|
+// }
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 将修正后的超短期数据入库
|
|
|
+// *
|
|
|
+// * @param content
|
|
|
+// * @param signTime
|
|
|
+// * @return
|
|
|
+// */
|
|
|
+// public boolean correctUltraShortTerm(String content, LocalDateTime signTime) {
|
|
|
+// boolean result = true;
|
|
|
+// try {
|
|
|
+// List<CorrectUltraShortTerm> list = new ArrayList<>();
|
|
|
+// String[] contents = content.split("\n");
|
|
|
+// for (int i = 3; i < contents.length - 1; i++) {
|
|
|
+// CorrectUltraShortTerm cus = new CorrectUltraShortTerm();
|
|
|
+// String column = contents[i];
|
|
|
+// String[] datas = column.split("\\s+");
|
|
|
+// cus.setSignTime(signTime);
|
|
|
+// cus.setPassTime(LocalDateTime.now());
|
|
|
+// cus.setRequestTime(LocalDateTime.now());
|
|
|
+// cus.setForecastTime(DateUtil.parse(datas[2], "yyyyMMddHHmmss").toTimestamp().toLocalDateTime());
|
|
|
+// cus.setRatio(new BigDecimal(datas[3]));
|
|
|
+// list.add(cus);
|
|
|
+// }
|
|
|
+// correctUltraShortTermService.saveBatch(list);
|
|
|
+// } catch (Exception e) {
|
|
|
+// e.printStackTrace();
|
|
|
+// result = false;
|
|
|
+// }
|
|
|
+// return result;
|
|
|
+// }
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 批量保存检修计划
|
|
|
+// *
|
|
|
+// * @param content
|
|
|
+// * @param signTime
|
|
|
+// * @return
|
|
|
+// */
|
|
|
+// public boolean repairPlan(String content, LocalDateTime signTime) {
|
|
|
+// boolean result = true;
|
|
|
+// try {
|
|
|
+// List<RepairPlan> list = new ArrayList<>();
|
|
|
+// String[] contents = content.split("\n");
|
|
|
+// for (int i = 3; i < contents.length - 1; i++) {
|
|
|
+// RepairPlan rp = new RepairPlan();
|
|
|
+// String column = contents[i];
|
|
|
+// String[] datas = column.split("\\s+");
|
|
|
+// rp.setSignTime(signTime);
|
|
|
+// rp.setRequestTime(LocalDateTime.now());
|
|
|
+// rp.setPassTime(LocalDateTime.now());
|
|
|
+// rp.setStartTime(DateUtil.parse(datas[2], "yyyyMMddHHmmss").toTimestamp().toLocalDateTime());
|
|
|
+// rp.setEndTime(DateUtil.parse(datas[3], "yyyyMMddHHmmss").toTimestamp().toLocalDateTime());
|
|
|
+// rp.setCap(new BigDecimal(datas[4]));
|
|
|
+// list.add(rp);
|
|
|
+// }
|
|
|
+// repairPlanService.saveBatch(list);
|
|
|
+// } catch (Exception e) {
|
|
|
+// e.printStackTrace();
|
|
|
+// result = false;
|
|
|
+// }
|
|
|
+// return result;
|
|
|
+// }
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 判断是否是NULL 和是否是数值
|
|
|
+// *
|
|
|
+// * @param data
|
|
|
+// * @return
|
|
|
+// */
|
|
|
+// public BigDecimal isNumberOrNull(String data) {
|
|
|
+// BigDecimal bigDecimal = new BigDecimal("-99");
|
|
|
+// if (!data.contains("null") && !data.contains("NULL")) {
|
|
|
+// Pattern pattern = Pattern.compile("-[0-9]+(.[0-9]+)?|[0-9]+(.[0-9]+)?");
|
|
|
+// Matcher isNum = pattern.matcher(data);
|
|
|
+// try {
|
|
|
+// if (isNum.matches()) {
|
|
|
+// bigDecimal = new BigDecimal(data).setScale(2, BigDecimal.ROUND_DOWN);
|
|
|
+// }
|
|
|
+// } catch (Exception e) {
|
|
|
+// e.printStackTrace();
|
|
|
+// }
|
|
|
+// }
|
|
|
+// return bigDecimal;
|
|
|
+// }
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 生成修正后的短期文件
|
|
|
+// *
|
|
|
+// * @param station
|
|
|
+// * @param list
|
|
|
+// * @return
|
|
|
+// */
|
|
|
+// public boolean genFile(Station station, List<CorrforeSt> list) {
|
|
|
+// boolean result = true;
|
|
|
+// // 初始化模板
|
|
|
+// String vmsPath = SystermUtils.getResourceBasePath() + "/vms/DQ.vm";
|
|
|
+// File file ;
|
|
|
+// Template template = this.velocityEngine.getTemplate(vmsPath);
|
|
|
+// // 如果模板不为空
|
|
|
+// if (template != null) {
|
|
|
+// VelocityContext velocityContext;
|
|
|
+// StringWriter writer;
|
|
|
+// // 将修正后的短期数据按照预测时间排序
|
|
|
+// list.sort(Comparator.comparing(CorrforeSt::getForecastTime));
|
|
|
+// // 根据修正后的数据,拼接需要的数据
|
|
|
+// List<Map<String, Object>> vList = new ArrayList<>();
|
|
|
+// for (CorrforeSt a : list) {
|
|
|
+// Map<String, Object> map = new HashMap<>();
|
|
|
+// map.put("id", a.getId());
|
|
|
+// map.put("stationName", station.getName());
|
|
|
+// map.put("forecastTime", DateUtil.format(new Date(a.getForecastTime()), "yyyy-MM-dd HH:mm:ss"));
|
|
|
+// map.put("fpValue", a.getFpValue() == null ? "-99" : a.getFpValue());
|
|
|
+// vList.add(map);
|
|
|
+// }
|
|
|
+// // 格式化模板数据
|
|
|
+// writer = new StringWriter();
|
|
|
+// velocityContext = new VelocityContext();
|
|
|
+// velocityContext.put("stationName", station.getName());
|
|
|
+// velocityContext.put("date", DateUtil.format(new Date(), "yyyy-MM-dd"));
|
|
|
+// velocityContext.put("vList", vList);
|
|
|
+// template.merge(velocityContext, writer);
|
|
|
+// // 获取文件路径
|
|
|
+// File fileUrl = new File(station.getLocalFilePath());
|
|
|
+// if (!fileUrl.exists()) {// 判断目录是否存在
|
|
|
+// fileUrl.mkdirs();
|
|
|
+// }
|
|
|
+// // 获取文件名
|
|
|
+// String fileName = "DQ_" + DateUtil.format(DateUtil.beginOfDay(new Date()), "yyyyMMddHHmmss") + "0.txt";
|
|
|
+// file = new File(station.getLocalFilePath() + File.separatorChar + fileName);
|
|
|
+// // 写入文件
|
|
|
+// result = writeFile(file, station, writer, fileName);
|
|
|
+// }
|
|
|
+// return result;
|
|
|
+// }
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 生成修正后的超短期文件
|
|
|
+// *
|
|
|
+// * @param station
|
|
|
+// * @param jsonObject
|
|
|
+// * @return
|
|
|
+// */
|
|
|
+// public boolean genUs(Station station, JSONObject jsonObject) {
|
|
|
+// boolean result = true;
|
|
|
+// // 获取模板
|
|
|
+// String vmsPath = SystermUtils.getResourceBasePath() + "/vms/US.vm";
|
|
|
+// Template template = this.velocityEngine.getTemplate(vmsPath);
|
|
|
+// // 如果
|
|
|
+// if (template != null) {
|
|
|
+// // 获取文件名
|
|
|
+// String fileName = jsonObject.get("fileName").toString();
|
|
|
+// String[] s = fileName.split("_");
|
|
|
+// String fn = "CDQ_" + s[1] + s[2] + "00.txt";
|
|
|
+// File file = new File(station.getLocalFilePath() + File.separatorChar + fn);
|
|
|
+// // 创建文件并写入
|
|
|
+// result = mergeTemplateAndwriteFile(file, station, fileName, template, jsonObject.get("data").toString());
|
|
|
+// }
|
|
|
+// return result;
|
|
|
+// }
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 生成检修计划文件
|
|
|
+// *
|
|
|
+// * @param station
|
|
|
+// * @param content
|
|
|
+// * @return
|
|
|
+// */
|
|
|
+// public boolean genRp(Station station, String content) {
|
|
|
+// boolean result = true;
|
|
|
+// // 初始化模板
|
|
|
+// String vmsPath = SystermUtils.getResourceBasePath() + "/vms/RP.vm";
|
|
|
+// File file;
|
|
|
+// Template template = this.velocityEngine.getTemplate(vmsPath);
|
|
|
+// // 如果模板不为空
|
|
|
+// if (template != null) {
|
|
|
+// // 获取文件名
|
|
|
+// String fileName = "JX_" + LocalDateTimeUtil.format(LocalDateTimeUtil.beginOfDay(LocalDateTime.now()), "yyyyMMddHHmmss") + ".txt";
|
|
|
+// file = new File(station.getLocalFilePath() + File.separatorChar + fileName);
|
|
|
+// // 创建文件并写入
|
|
|
+// result = mergeTemplateAndwriteFile(file, station, fileName, template, content);
|
|
|
+// }
|
|
|
+// return result;
|
|
|
+// }
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 写入文件
|
|
|
+// *
|
|
|
+// * @param file
|
|
|
+// * @param station
|
|
|
+// * @return
|
|
|
+// */
|
|
|
+// private boolean mergeTemplateAndwriteFile(File file, Station station, String fileName, Template template, String content) {
|
|
|
+// // 创建模板
|
|
|
+// VelocityContext velocityContext = new VelocityContext();
|
|
|
+// StringWriter writer = new StringWriter();
|
|
|
+// // 放入内容
|
|
|
+// velocityContext.put("content", content);
|
|
|
+// // 写入数据
|
|
|
+// template.merge(velocityContext, writer);
|
|
|
+// return writeFile(file, station, writer, fileName);
|
|
|
+// }
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 写入文件
|
|
|
+// * @param file
|
|
|
+// * @param station
|
|
|
+// * @param writer
|
|
|
+// * @param fileName
|
|
|
+// * @return
|
|
|
+// */
|
|
|
+// private boolean writeFile(File file, Station station, StringWriter writer, String fileName) {
|
|
|
+// boolean result = true;
|
|
|
+// // 获取文件路径
|
|
|
+// File fileUrl = new File(station.getLocalFilePath());
|
|
|
+// // 判断目录是否存在
|
|
|
+// if (!fileUrl.exists()) {
|
|
|
+// fileUrl.mkdirs();
|
|
|
+// }
|
|
|
+// // 创建流
|
|
|
+// FileOutputStream os = null;
|
|
|
+// try {
|
|
|
+// boolean res = file.createNewFile();
|
|
|
+// // 如果创建成功
|
|
|
+// if (res) {
|
|
|
+// os = new FileOutputStream(file);
|
|
|
+// // 采用UTF-8字符集
|
|
|
+// os.write(writer.toString().getBytes("UTF-8"));
|
|
|
+// os.flush();
|
|
|
+// // 创建文件失败
|
|
|
+// } else {
|
|
|
+// result = false;
|
|
|
+// log.warn(station.getStationCode() + "文件名:" + fileName + " 生成失败");
|
|
|
+// }
|
|
|
+// } catch (IOException e) {
|
|
|
+// e.printStackTrace();
|
|
|
+// result = false;
|
|
|
+// log.warn(station.getStationCode() + " 创建" + "文件名:" + fileName + "失败");
|
|
|
+// } finally {
|
|
|
+// // 如果流不为空,关闭流
|
|
|
+// if (os != null) {
|
|
|
+// try {
|
|
|
+// os.close();
|
|
|
+// } catch (IOException e) {
|
|
|
+// log.error("文件生成关闭流失败", e);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// log.info("执行生成文件完毕:" + station.getLocalFilePath() + File.separatorChar + fileName);
|
|
|
+// return result;
|
|
|
+// }
|
|
|
+// }
|
|
|
+//}
|