|
@@ -1,17 +1,22 @@
|
|
package com.jiayue.insu.inclientqn.service;
|
|
package com.jiayue.insu.inclientqn.service;
|
|
|
|
|
|
-import cn.hutool.core.collection.CollectionUtil;
|
|
|
|
import cn.hutool.core.date.DateTime;
|
|
import cn.hutool.core.date.DateTime;
|
|
import cn.hutool.core.date.DateUtil;
|
|
import cn.hutool.core.date.DateUtil;
|
|
import cn.hutool.http.HttpRequest;
|
|
import cn.hutool.http.HttpRequest;
|
|
import cn.hutool.json.JSONObject;
|
|
import cn.hutool.json.JSONObject;
|
|
import cn.hutool.json.JSONUtil;
|
|
import cn.hutool.json.JSONUtil;
|
|
-//import com.jiayue.insu.inclientqn.ElectricFieldTypeEnum;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.jiayue.insu.inclientqn.constant.ConnectConstant;
|
|
import com.jiayue.insu.inclientqn.constant.ConnectConstant;
|
|
import com.jiayue.insu.inclientqn.constant.DataTypeConstant;
|
|
import com.jiayue.insu.inclientqn.constant.DataTypeConstant;
|
|
import com.jiayue.insu.inclientqn.constant.StatusConstant;
|
|
import com.jiayue.insu.inclientqn.constant.StatusConstant;
|
|
import com.jiayue.insu.inclientqn.entity.CorrforeSt;
|
|
import com.jiayue.insu.inclientqn.entity.CorrforeSt;
|
|
|
|
+import com.jiayue.insu.inclientqn.entity.InsuLog;
|
|
import com.jiayue.insu.inclientqn.entity.TokenInfo;
|
|
import com.jiayue.insu.inclientqn.entity.TokenInfo;
|
|
|
|
+import com.jiayue.insu.inclientqn.inenum.ElectricFieldTypeEnum;
|
|
|
|
+import com.jiayue.insu.inclientqn.inenum.LogStatusEnum;
|
|
|
|
+import com.jiayue.insu.inclientqn.inenum.LogTypeEnum;
|
|
|
|
+import com.jiayue.insu.inclientqn.mapper.CorrforeStMapper;
|
|
|
|
+import com.jiayue.insu.inclientqn.mapper.InsuLogMapper;
|
|
import com.jiayue.insu.inclientqn.model.RequestVo;
|
|
import com.jiayue.insu.inclientqn.model.RequestVo;
|
|
import com.jiayue.insu.inclientqn.model.ResponseVo;
|
|
import com.jiayue.insu.inclientqn.model.ResponseVo;
|
|
import com.jiayue.insu.inclientqn.model.TokenVo;
|
|
import com.jiayue.insu.inclientqn.model.TokenVo;
|
|
@@ -24,8 +29,6 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
import java.sql.Timestamp;
|
|
import java.sql.Timestamp;
|
|
-import java.time.LocalDateTime;
|
|
|
|
-import java.time.format.DateTimeFormatter;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
@@ -42,39 +45,37 @@ import java.util.stream.Collectors;
|
|
@Service
|
|
@Service
|
|
@Slf4j
|
|
@Slf4j
|
|
@RequiredArgsConstructor
|
|
@RequiredArgsConstructor
|
|
-public class ForecastPowerTermCorrectService {
|
|
|
|
|
|
+public class ForecastPowerTermCorrectService extends ServiceImpl<CorrforeStMapper, CorrforeSt> {
|
|
@Autowired
|
|
@Autowired
|
|
InTokenService inTokenService;
|
|
InTokenService inTokenService;
|
|
@Autowired
|
|
@Autowired
|
|
TokenInfoService tokenInfoService;
|
|
TokenInfoService tokenInfoService;
|
|
|
|
+ @Autowired
|
|
|
|
+ InsuLogService insuLogServicel;
|
|
|
|
|
|
@Value("${stationCode}")
|
|
@Value("${stationCode}")
|
|
private String stationCode;
|
|
private String stationCode;
|
|
|
|
|
|
public String[] pullCorrectData() {
|
|
public String[] pullCorrectData() {
|
|
- String[] status = new String[2];
|
|
|
|
// 获取清能一体化token
|
|
// 获取清能一体化token
|
|
TokenVo tokenVo = inTokenService.getToken();
|
|
TokenVo tokenVo = inTokenService.getToken();
|
|
|
|
|
|
if (tokenVo != null) {
|
|
if (tokenVo != null) {
|
|
- long startTimeT = DateUtil.beginOfDay(new Date()).getTime();
|
|
|
|
- long endTimeT = DateUtil.offsetDay(new Date(startTimeT), 1).getTime() - 1;
|
|
|
|
- //请求当日预测数据
|
|
|
|
- String todayforeStatus = corrforeData(tokenVo, DataTypeConstant.CORRFORE_TYPE, startTimeT, endTimeT, 97);
|
|
|
|
- status[0] = todayforeStatus;
|
|
|
|
-// long startTimeC = DateUtil.beginOfDay(DateUtil.tomorrow()).getTime();
|
|
|
|
-// long endTimeC = DateUtil.offsetDay(new Date(startTimeC), 9).getTime();
|
|
|
|
-// //请求未来9天预测数据
|
|
|
|
-// String corrforeStatus = corrforeData(tokenVo, DataTypeConstant.CORRFORE_TYPE, startTimeC, endTimeC, 865);
|
|
|
|
-// status[1] = corrforeStatus;
|
|
|
|
|
|
+ // 请求当日预测数据
|
|
|
|
+ downLoadCorrforeData(tokenVo, DataTypeConstant.CORRFORE_TYPE);
|
|
} else {
|
|
} else {
|
|
log.error(stationCode + " ========== 一体化:下载短期修正数据失败 无token ==========");
|
|
log.error(stationCode + " ========== 一体化:下载短期修正数据失败 无token ==========");
|
|
}
|
|
}
|
|
- return status;
|
|
|
|
|
|
+ return null;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
- public String corrforeData(TokenVo tokenVo, String type, long startTime, long endTime, int count) {
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 下载修正预测数据
|
|
|
|
+ * @param tokenVo
|
|
|
|
+ * @param type
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public String downLoadCorrforeData(TokenVo tokenVo, String type) {
|
|
String response = "";
|
|
String response = "";
|
|
String status = "";
|
|
String status = "";
|
|
boolean result = false;
|
|
boolean result = false;
|
|
@@ -114,13 +115,18 @@ public class ForecastPowerTermCorrectService {
|
|
log.info("请求短期修正数据返回内容:{}", response);
|
|
log.info("请求短期修正数据返回内容:{}", response);
|
|
|
|
|
|
String dataContent = responseVo.getData();
|
|
String dataContent = responseVo.getData();
|
|
- if (!dataContent.contains("NULL") && !dataContent.contains("null")) {
|
|
|
|
|
|
+// if (!dataContent.contains("NULL") && !dataContent.contains("null")) {
|
|
try {
|
|
try {
|
|
-// if (ElectricFieldTypeEnum.E1.toString().equals(tokenInfo.getStationType())) {
|
|
|
|
-// list = correctPhotovoltaicData(responseVo.getData());
|
|
|
|
-// } else {
|
|
|
|
-//// list = correctWindData(responseVo.getData());
|
|
|
|
-// }
|
|
|
|
|
|
+ // 入库
|
|
|
|
+ if (ElectricFieldTypeEnum.E1.toString().equals(tokenInfo.getStationType())) {
|
|
|
|
+ list = correctPhotovoltaicData(responseVo.getData());
|
|
|
|
+ } else {
|
|
|
|
+// list = correctWindData(responseVo.getData());
|
|
|
|
+ }
|
|
|
|
+ if (!list.isEmpty()){
|
|
|
|
+ super.saveBatch(list);
|
|
|
|
+ packingLog(LogStatusEnum.E1.toString(), LogTypeEnum.E1.toString(),null);
|
|
|
|
+ }
|
|
|
|
|
|
/**************检测解析数据完整性*******************/
|
|
/**************检测解析数据完整性*******************/
|
|
// if (list.size() < count) {
|
|
// if (list.size() < count) {
|
|
@@ -155,48 +161,51 @@ public class ForecastPowerTermCorrectService {
|
|
/**************检测解析数据完整性*******************/
|
|
/**************检测解析数据完整性*******************/
|
|
|
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
- status = StatusConstant.Correct_STATUS_DATA_FAIL;
|
|
|
|
|
|
+ log.error("解析修正数据失败",e);
|
|
|
|
+ packingLog(LogStatusEnum.E2.toString(), LogTypeEnum.E1.toString(),"解析修正数据失败");
|
|
// log.info("========== 一体化: {} 解析期修正数据失败 {} ==========", el.getStationCode(), type);
|
|
// log.info("========== 一体化: {} 解析期修正数据失败 {} ==========", el.getStationCode(), type);
|
|
}
|
|
}
|
|
- } else {
|
|
|
|
- status = StatusConstant.Correct_STATUS_DATA_FAIL;
|
|
|
|
-// log.info("========== 一体化: {} 解析期修正数据为完成 含NULL {} ==========", el.getStationCode(), type);
|
|
|
|
- }
|
|
|
|
|
|
+// } else {
|
|
|
|
+// log.info("========== 下载修正数据含NULL ==========");
|
|
|
|
+// packingLog(LogStatusEnum.E2.toString(), LogTypeEnum.E1.toString(),"修正数据含NULL");
|
|
|
|
+// }
|
|
if (result) {
|
|
if (result) {
|
|
// log.info("========== 一体化: {} 下载短期修正数据成功 {} ==========", el.getStationCode(), type);
|
|
// log.info("========== 一体化: {} 下载短期修正数据成功 {} ==========", el.getStationCode(), type);
|
|
// aioForecastPowerShortTermService.saveAll(aList);
|
|
// aioForecastPowerShortTermService.saveAll(aList);
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- log.error("========== 一体化: {} 下载短期修正数据失败 接收retCode响应码非成功标识T200 {} ==========", stationCode, type);
|
|
|
|
- log.error("========== 一体化: {} {} 下载短期修正数据失败 接收retCode响应码非成功标识T200 标识为{} ==========", stationCode, type, status);
|
|
|
|
- log.error("========== 一体化: {} {} 下载短期修正数据失败 接收retCode响应码非成功标识T200 失败原因为{} ==========", stationCode, type, responseVo.getRetMsg());
|
|
|
|
|
|
+// log.error("========== 一体化: {} 下载短期修正数据失败 接收retCode响应码非成功标识T200 {} ==========", stationCode, type);
|
|
|
|
+// log.error("========== 一体化: {} {} 下载短期修正数据失败 接收retCode响应码非成功标识T200 标识为{} ==========", stationCode, type, status);
|
|
|
|
+// log.error("========== 一体化: {} {} 下载短期修正数据失败 接收retCode响应码非成功标识T200 失败原因为{} ==========", stationCode, type, responseVo.getRetMsg());
|
|
if (status.equals(StatusConstant.TOKEN_EXPIRE)) {
|
|
if (status.equals(StatusConstant.TOKEN_EXPIRE)) {
|
|
- log.error("========== 一体化: {} 下载短期修正数据失败 token过期 已重新请求token ==========", stationCode);
|
|
|
|
|
|
+ log.info("========== token过期 ==========");
|
|
|
|
+ packingLog(LogStatusEnum.E2.toString(), LogTypeEnum.E1.toString(),"token过期");
|
|
}
|
|
}
|
|
if (status.equals(StatusConstant.TOKEN_INVALID)) {
|
|
if (status.equals(StatusConstant.TOKEN_INVALID)) {
|
|
- log.error("========== 一体化: {} 上下载短期修正数据失败 token失效 已重新请求token ==========", stationCode);
|
|
|
|
|
|
+ log.info("========== token失效 ==========");
|
|
|
|
+ packingLog(LogStatusEnum.E2.toString(), LogTypeEnum.E1.toString(),"token失效");
|
|
}
|
|
}
|
|
if (status.equals(StatusConstant.AUTOGRAPH_FAIL)) {
|
|
if (status.equals(StatusConstant.AUTOGRAPH_FAIL)) {
|
|
- log.error("========== 一体化: {} 下载短期修正数据失败 签名失败 已重新请求token ==========", stationCode);
|
|
|
|
|
|
+ log.info("========== 签名失败 ==========");
|
|
|
|
+ packingLog(LogStatusEnum.E2.toString(), LogTypeEnum.E1.toString(),"签名失败");
|
|
}
|
|
}
|
|
if (responseVo.getRetCode().equals(StatusConstant.LOGIN_NOT)) {
|
|
if (responseVo.getRetCode().equals(StatusConstant.LOGIN_NOT)) {
|
|
- log.error("========== 一体化: {} 下载短期修正数据失败 用户未登录 已重新请求token ==========", stationCode);
|
|
|
|
|
|
+ log.info("========== 用户未登录 ==========");
|
|
|
|
+ packingLog(LogStatusEnum.E2.toString(), LogTypeEnum.E1.toString(),"用户未登录");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- status = StatusConstant.RESPONSE_ERROR1;
|
|
|
|
- log.error("========== 一体化:下载短期修正数据失败 接收响应字符串非json格式 " + response + " ==========");
|
|
|
|
|
|
+ log.info("========== 接收响应字符串非json格式 ==========");
|
|
|
|
+ packingLog(LogStatusEnum.E2.toString(), LogTypeEnum.E1.toString(),"接收响应字符串非json格式");
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- status = StatusConstant.RESPONSE_ERROR2;
|
|
|
|
- log.error("========== 一体化:下载短期修正数据失败 返回响应内容为空 ==========");
|
|
|
|
|
|
+ log.info("========== 响应内容为空 ==========");
|
|
|
|
+ packingLog(LogStatusEnum.E2.toString(), LogTypeEnum.E1.toString(),"响应内容为空");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
- status = StatusConstant.RESPONSE_ERROR3;
|
|
|
|
- log.error("========== 一体化:下载短期修正数据失败 连接断开或请求超时 ==========");
|
|
|
|
- e.printStackTrace();
|
|
|
|
-
|
|
|
|
|
|
+ log.error("========== 连接断开或请求超时 ==========",e);
|
|
|
|
+ packingLog(LogStatusEnum.E2.toString(), LogTypeEnum.E1.toString(),"连接断开或请求超时");
|
|
}
|
|
}
|
|
return status;
|
|
return status;
|
|
}
|
|
}
|
|
@@ -211,7 +220,6 @@ public class ForecastPowerTermCorrectService {
|
|
*/
|
|
*/
|
|
public List<CorrforeSt> correctPhotovoltaicData(String data) throws Exception {
|
|
public List<CorrforeSt> correctPhotovoltaicData(String data) throws Exception {
|
|
String[] content = data.split("\n");
|
|
String[] content = data.split("\n");
|
|
-// String dateStr = content[0].split("'")[1];
|
|
|
|
List<CorrforeSt> list = new ArrayList<>();
|
|
List<CorrforeSt> list = new ArrayList<>();
|
|
Date genDate = new Date();
|
|
Date genDate = new Date();
|
|
for (int i = 3; i < content.length - 1; i++) {
|
|
for (int i = 3; i < content.length - 1; i++) {
|
|
@@ -312,4 +320,12 @@ public class ForecastPowerTermCorrectService {
|
|
return bigDecimal;
|
|
return bigDecimal;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public void packingLog(String status,String logType,String failCause){
|
|
|
|
+ InsuLog insuLog = new InsuLog();
|
|
|
|
+ insuLog.setGenTime(new Timestamp(new Date().getTime()));
|
|
|
|
+ insuLog.setStatus(status);
|
|
|
|
+ insuLog.setType(logType);
|
|
|
|
+ insuLog.setFailCause(failCause);
|
|
|
|
+ insuLogServicel.save(insuLog);
|
|
|
|
+ }
|
|
}
|
|
}
|