|
@@ -50,124 +50,150 @@ import java.util.regex.Pattern;
|
|
|
@RequiredArgsConstructor
|
|
|
public class CorrforeService 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- public void downLoadUltraShortTerm(long signTime){
|
|
|
-
|
|
|
- Station station = stationService.findThis();
|
|
|
+ /**
|
|
|
+ * 获取超短期修正数据并生成文件
|
|
|
+ * @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);
|
|
|
-
|
|
|
+ // 如果生成修正超短期文件成功
|
|
|
+ if (genUs(station, jsonObject)) {
|
|
|
+ // 将修正后的超短期数据入库
|
|
|
+ correctUltraShortTerm(jsonObject.get("data").toString(), signLDT);
|
|
|
+ // 设置日志操作状态
|
|
|
record.setState(StatusEnum.SUCCESS.getSign());
|
|
|
record.setStateContent(responseVo.getRetMsg());
|
|
|
- }else{
|
|
|
+ // 如果生成超短期修正文件失败
|
|
|
+ } 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);
|
|
|
-
|
|
|
}
|
|
|
|
|
|
- public void downLoadRepairPlan(long signTime){
|
|
|
-
|
|
|
- Station station = stationService.findThis();
|
|
|
-
|
|
|
+ /**
|
|
|
+ * 下载检修计划
|
|
|
+ *
|
|
|
+ * @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);
|
|
|
-
|
|
|
+ // 如果生成检修计划文件成功
|
|
|
+ if (genRp(station, responseVo.getData())) {
|
|
|
+ // 保存检修计划数据
|
|
|
+ repairPlan(responseVo.getData(), localDateTime);
|
|
|
+ // 设置操作结果
|
|
|
record.setState(StatusEnum.SUCCESS.getSign());
|
|
|
record.setStateContent(responseVo.getRetMsg());
|
|
|
- }else{
|
|
|
+ } 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);
|
|
|
-
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -183,7 +209,6 @@ public class CorrforeService extends ServiceImpl<CorrforeStMapper, CorrforeSt> {
|
|
|
LocalDateTime localDateTime = LocalDateTimeUtil.beginOfDay(LocalDateTime.now());
|
|
|
record.setTime(localDateTime);
|
|
|
record.setCreateTime(LocalDateTime.now());
|
|
|
-
|
|
|
boolean isUpload = false;
|
|
|
|
|
|
try {
|
|
@@ -202,7 +227,7 @@ public class CorrforeService extends ServiceImpl<CorrforeStMapper, CorrforeSt> {
|
|
|
if (isFile) {
|
|
|
minioUtilService.downloadObject(bucketName, downfileName, station.getLocalFilePath() + File.separatorChar + downfileName.split("/")[1]);
|
|
|
record.setState(StatusEnum.SUCCESS.getSign());
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
record.setState(StatusEnum.FILE_NULL.getSign());
|
|
|
}
|
|
|
|
|
@@ -212,38 +237,35 @@ public class CorrforeService extends ServiceImpl<CorrforeStMapper, CorrforeSt> {
|
|
|
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();
|
|
|
- LocalDateTime tokenTime = station.getKeyTime();
|
|
|
-
|
|
|
+ // 获取下载路径
|
|
|
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();
|
|
@@ -251,20 +273,20 @@ public class CorrforeService extends ServiceImpl<CorrforeStMapper, CorrforeSt> {
|
|
|
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);
|
|
@@ -273,45 +295,45 @@ public class CorrforeService extends ServiceImpl<CorrforeStMapper, CorrforeSt> {
|
|
|
.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);
|
|
|
- genFile(station, list);
|
|
|
- result = true;
|
|
|
-
|
|
|
-
|
|
|
+ // 生成短期修正后文件
|
|
|
+ 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());
|
|
@@ -319,12 +341,10 @@ public class CorrforeService extends ServiceImpl<CorrforeStMapper, CorrforeSt> {
|
|
|
log.error("========== 解析短期或生成文件失败 ");
|
|
|
}
|
|
|
|
|
|
-
|
|
|
if (result) {
|
|
|
log.info("========== 拉取短期修正数据成功! ==========");
|
|
|
record.setState(StatusEnum.SUCCESS.getSign());
|
|
|
record.setStateContent(String.valueOf(list.size()));
|
|
|
-
|
|
|
}
|
|
|
|
|
|
} else {
|
|
@@ -355,7 +375,6 @@ public class CorrforeService extends ServiceImpl<CorrforeStMapper, CorrforeSt> {
|
|
|
return isUpload;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 光伏数据解析
|
|
|
*
|
|
@@ -365,44 +384,28 @@ public class CorrforeService extends ServiceImpl<CorrforeStMapper, CorrforeSt> {
|
|
|
*/
|
|
|
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;
|
|
|
-
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -413,113 +416,91 @@ public class CorrforeService extends ServiceImpl<CorrforeStMapper, CorrforeSt> {
|
|
|
* @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;
|
|
|
-
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- public boolean correctUltraShortTerm(String content,LocalDateTime signTime){
|
|
|
+ /**
|
|
|
+ * 将修正后的超短期数据入库
|
|
|
+ *
|
|
|
+ * @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++) {
|
|
|
+ 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.setRequestTime(LocalDateTime.now());
|
|
|
cus.setPassTime(LocalDateTime.now());
|
|
|
- cus.setForecastTime( DateUtil.parse(datas[2], "yyyyMMddHHmmss").toTimestamp().toLocalDateTime());
|
|
|
+ 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){
|
|
|
+ } catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
result = false;
|
|
|
}
|
|
|
-
|
|
|
return result;
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
|
|
|
- public boolean repairPlan(String content,LocalDateTime signTime){
|
|
|
+ /**
|
|
|
+ * 批量保存检修计划
|
|
|
+ *
|
|
|
+ * @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++) {
|
|
|
+ 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.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){
|
|
|
+ } catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
result = false;
|
|
|
}
|
|
|
-
|
|
|
return result;
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
/**
|
|
|
* 判断是否是NULL 和是否是数值
|
|
|
*
|
|
@@ -529,7 +510,6 @@ public class CorrforeService extends ServiceImpl<CorrforeStMapper, CorrforeSt> {
|
|
|
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 {
|
|
@@ -539,30 +519,31 @@ public class CorrforeService extends ServiceImpl<CorrforeStMapper, CorrforeSt> {
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
return bigDecimal;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
- * 生成文件
|
|
|
+ * 生成修正后的短期文件
|
|
|
*
|
|
|
+ * @param station
|
|
|
+ * @param list
|
|
|
* @return
|
|
|
*/
|
|
|
- public File genFile(Station station, List<CorrforeSt> list) {
|
|
|
-
|
|
|
+ public boolean genFile(Station station, List<CorrforeSt> list) {
|
|
|
+ boolean result = true;
|
|
|
+ // 初始化模板
|
|
|
String vmsPath = SystermUtils.getResourceBasePath() + "/vms/DQ.vm";
|
|
|
- File file = null;
|
|
|
+ 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());
|
|
@@ -570,179 +551,141 @@ public class CorrforeService extends ServiceImpl<CorrforeStMapper, CorrforeSt> {
|
|
|
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);
|
|
|
-
|
|
|
- writer = new StringWriter();
|
|
|
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.RB";
|
|
|
-
|
|
|
file = new File(station.getLocalFilePath() + File.separatorChar + fileName);
|
|
|
-
|
|
|
-
|
|
|
- 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 {
|
|
|
- log.warn(station.getStationCode() + " 生成修正DQ文件失败");
|
|
|
- }
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- log.warn(station.getStationCode() + " 创建修正DQ失败");
|
|
|
- } finally {
|
|
|
- if (os != null) {
|
|
|
- try {
|
|
|
- os.close();
|
|
|
- } catch (IOException e) {
|
|
|
- log.error("文件生成关闭流失败", e);
|
|
|
- }
|
|
|
- }
|
|
|
- log.info("执行生成文件完毕:"+station.getLocalFilePath() + File.separatorChar + fileName);
|
|
|
- }
|
|
|
-
|
|
|
+ // 写入文件
|
|
|
+ result = writeFile(file, station, writer, fileName);
|
|
|
}
|
|
|
-
|
|
|
- return file;
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- public boolean genUs(Station station, JSONObject jsonObject){
|
|
|
+ /**
|
|
|
+ * 生成修正后的超短期文件
|
|
|
+ *
|
|
|
+ * @param station
|
|
|
+ * @param jsonObject
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public boolean genUs(Station station, JSONObject jsonObject) {
|
|
|
boolean result = true;
|
|
|
-
|
|
|
+ // 获取模板
|
|
|
String vmsPath = SystermUtils.getResourceBasePath() + "/vms/US.vm";
|
|
|
- File file = null;
|
|
|
Template template = this.velocityEngine.getTemplate(vmsPath);
|
|
|
+ // 如果
|
|
|
if (template != null) {
|
|
|
- VelocityContext velocityContext= new VelocityContext();
|
|
|
- StringWriter writer;
|
|
|
-
|
|
|
-
|
|
|
- velocityContext.put("content", jsonObject.get("data").toString());
|
|
|
-
|
|
|
- writer = new StringWriter();
|
|
|
- template.merge(velocityContext, writer);
|
|
|
-
|
|
|
-
|
|
|
- File fileUrl = new File(station.getLocalFilePath());
|
|
|
- if (!fileUrl.exists()) {// 判断目录是否存在
|
|
|
- fileUrl.mkdirs();
|
|
|
- }
|
|
|
-
|
|
|
- String fileName = jsonObject.get("fileName").toString() ;
|
|
|
+ // 获取文件名
|
|
|
+ String fileName = jsonObject.get("fileName").toString();
|
|
|
String[] s = fileName.split("_");
|
|
|
- String fn = "CDQ_"+s[1]+s[2]+"00.RB";
|
|
|
- file = new File(station.getLocalFilePath() + File.separatorChar + fn);
|
|
|
-
|
|
|
-
|
|
|
- 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() + " 生成修正超短期系数文件失败");
|
|
|
- }
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- result = false;
|
|
|
- log.warn(station.getStationCode() + " 创建修正超短期系数文件失败");
|
|
|
- } finally {
|
|
|
- if (os != null) {
|
|
|
- try {
|
|
|
- os.close();
|
|
|
- } catch (IOException e) {
|
|
|
- log.error("文件生成关闭流失败", e);
|
|
|
- }
|
|
|
- }
|
|
|
- log.info("执行生成文件完毕:"+station.getLocalFilePath() + File.separatorChar + fileName);
|
|
|
- }
|
|
|
-
|
|
|
+ String fn = "CDQ_" + s[1] + s[2] + "00.RB";
|
|
|
+ File file = new File(station.getLocalFilePath() + File.separatorChar + fn);
|
|
|
+ // 创建文件并写入
|
|
|
+ result = mergeTemplateAndwriteFile(file, station, fileName, template, jsonObject.get("data").toString());
|
|
|
}
|
|
|
-
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- public boolean genRp(Station station, String content){
|
|
|
+ /**
|
|
|
+ * 生成检修计划文件
|
|
|
+ *
|
|
|
+ * @param station
|
|
|
+ * @param content
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public boolean genRp(Station station, String content) {
|
|
|
boolean result = true;
|
|
|
-
|
|
|
+ // 初始化模板
|
|
|
String vmsPath = SystermUtils.getResourceBasePath() + "/vms/RP.vm";
|
|
|
- File file = null;
|
|
|
+ File file;
|
|
|
Template template = this.velocityEngine.getTemplate(vmsPath);
|
|
|
+ // 如果模板不为空
|
|
|
if (template != null) {
|
|
|
- VelocityContext velocityContext= new VelocityContext();
|
|
|
- StringWriter writer;
|
|
|
-
|
|
|
-
|
|
|
- velocityContext.put("content", content);
|
|
|
-
|
|
|
- writer = new StringWriter();
|
|
|
- template.merge(velocityContext, writer);
|
|
|
-
|
|
|
-
|
|
|
- File fileUrl = new File(station.getLocalFilePath());
|
|
|
- if (!fileUrl.exists()) {// 判断目录是否存在
|
|
|
- fileUrl.mkdirs();
|
|
|
- }
|
|
|
-
|
|
|
- String fileName = "JX_"+LocalDateTimeUtil.format(LocalDateTimeUtil.beginOfDay(LocalDateTime.now()),"yyyyMMddHHmmss")+".RB" ;
|
|
|
-
|
|
|
+ // 获取文件名
|
|
|
+ String fileName = "JX_" + LocalDateTimeUtil.format(LocalDateTimeUtil.beginOfDay(LocalDateTime.now()), "yyyyMMddHHmmss") + ".RB";
|
|
|
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);
|
|
|
+ }
|
|
|
|
|
|
- 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() + " 生成修正超短期系数文件失败");
|
|
|
- }
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
+ /**
|
|
|
+ * 写入文件
|
|
|
+ * @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() + " 创建修正超短期系数文件失败");
|
|
|
- } finally {
|
|
|
- if (os != null) {
|
|
|
- try {
|
|
|
- os.close();
|
|
|
- } catch (IOException e) {
|
|
|
- log.error("文件生成关闭流失败", e);
|
|
|
- }
|
|
|
+ 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);
|
|
|
}
|
|
|
-
|
|
|
+ log.info("执行生成文件完毕:" + station.getLocalFilePath() + File.separatorChar + fileName);
|
|
|
+ return result;
|
|
|
}
|
|
|
-
|
|
|
- return result;
|
|
|
}
|
|
|
}
|