|
@@ -31,6 +31,7 @@ import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.DigestUtils;
|
|
|
+
|
|
|
import java.io.*;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.time.LocalDateTime;
|
|
@@ -89,16 +90,8 @@ public class ApiServiceImpl implements ApiService {
|
|
|
String requestUserPass = userInfo.getStr(CommonStant.REQUEST_USER_PASS);
|
|
|
// 获取用户列表
|
|
|
Map<String, String> userMap = redisTemplate.opsForHash().entries(CommonStant.REDIS_USERS);
|
|
|
- // 如果用户列表为空,返回失败
|
|
|
- if (userMap == null) {
|
|
|
- return JsonResultUtil.failure();
|
|
|
- }
|
|
|
// 根据用户名获取密码
|
|
|
String password = userMap.get(requestUserName);
|
|
|
- // 如果密码为空
|
|
|
- if (password == null) {
|
|
|
- return JsonResultUtil.failure();
|
|
|
- }
|
|
|
// 加密后的密码
|
|
|
String passwordMD5t = DigestUtils.md5DigestAsHex(password.getBytes()).toUpperCase();
|
|
|
// 如果密码匹配成功
|
|
@@ -114,6 +107,7 @@ public class ApiServiceImpl implements ApiService {
|
|
|
if (timeout > 360) {
|
|
|
result = JsonResultUtil.success();
|
|
|
result.set("token", token);
|
|
|
+ log.info("用户:" + requestUserName + "获取token,剩余有效期" + timeout + "秒");
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
@@ -130,11 +124,12 @@ public class ApiServiceImpl implements ApiService {
|
|
|
result.set(CommonStant.TOKEN, token);
|
|
|
// 成功生成token后,将toke存入redis 有效期24小时
|
|
|
redisTemplate.opsForValue().set(key, token, 24, TimeUnit.HOURS);
|
|
|
+ log.info("用户:" + requestUserName + "获取token,剩余有效期86400秒");
|
|
|
// 返回结果
|
|
|
return result;
|
|
|
} else {
|
|
|
- log.info("用户不存在或密码错误");
|
|
|
- return JsonResultUtil.failure();
|
|
|
+ log.info("密码错误");
|
|
|
+ return JsonResultUtil.failure("密码错误");
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -146,14 +141,68 @@ public class ApiServiceImpl implements ApiService {
|
|
|
*/
|
|
|
@Override
|
|
|
public JSONObject getShortWpfData(JSONObject requestJson) {
|
|
|
- JSONObject result;
|
|
|
- String stationCode = requestJson.getStr("wfId");
|
|
|
- // 根据场站编号查询场站信息
|
|
|
- Station station = stationService.findByStationCode(stationCode);
|
|
|
- // 从minIo获取文件
|
|
|
- File file = downLoadFileFromMinIo(station, "dq", requestJson.getStr("beginDate"), requestJson.getStr("endDate"));
|
|
|
- //解析短期文件
|
|
|
- result = fileAnalysis(file, station, "dq", requestJson.getStr("beginDate"), requestJson.getStr("endDate"));
|
|
|
+ JSONObject result = new JSONObject();
|
|
|
+ JSONArray stationCodeArr = requestJson.getJSONArray("wfId");
|
|
|
+ JSONArray dataArr = new JSONArray();
|
|
|
+ boolean getStatus = false;
|
|
|
+ //
|
|
|
+ for (int i = 0; i < stationCodeArr.size(); i++) {
|
|
|
+ // 根据场站编号查询场站信息
|
|
|
+ Station station = stationService.findByStationCode(stationCodeArr.get(i).toString());
|
|
|
+ JSONObject errMsg = new JSONObject();
|
|
|
+ // 从minIo获取文件
|
|
|
+ File file = downLoadFileFromMinIo(station, "dq", requestJson.getStr("beginDate"), requestJson.getStr("endDate"), errMsg);
|
|
|
+ // 解析短期文件
|
|
|
+ JSONObject fileResult = fileAnalysis(file, station, "dq", requestJson.getStr("beginDate"), requestJson.getStr("beginDate"));
|
|
|
+ // 如果解析文件成功,则放入data集合中
|
|
|
+ if (JsonResultUtil.Type.success.value().equals(fileResult.get(JsonResultUtil.CODE_TAG))) {
|
|
|
+ result = fileResult;
|
|
|
+ dataArr.addAll(fileResult.getJSONArray("data"));
|
|
|
+ getStatus = true;
|
|
|
+ } else {
|
|
|
+ dataArr.add(stationCodeArr.get(i).toString() + ":" + errMsg.getStr("msg"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 如果全部文件都未下载,返回失败原因
|
|
|
+ if (!getStatus) {
|
|
|
+ return JsonResultUtil.failure(dataArr);
|
|
|
+ }
|
|
|
+
|
|
|
+ result.set("data", dataArr);
|
|
|
+ // 如果解析完的短期文件列表为空
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public JSONObject getNwpData(JSONObject requestJson) {
|
|
|
+ JSONObject result = new JSONObject();
|
|
|
+ JSONArray stationCodeArr = requestJson.getJSONArray("wfId");
|
|
|
+ JSONArray dataArr = new JSONArray();
|
|
|
+ boolean getStatus = false;
|
|
|
+ //
|
|
|
+ for (int i = 0; i < stationCodeArr.size(); i++) {
|
|
|
+ // 根据场站编号查询场站信息
|
|
|
+ Station station = stationService.findByStationCode(stationCodeArr.get(i).toString());
|
|
|
+ JSONObject errMsg = new JSONObject();
|
|
|
+ // 从minIo获取文件
|
|
|
+ File file = downLoadFileFromMinIo(station, "nwp", requestJson.getStr("beginDate"), requestJson.getStr("endDate"), errMsg);
|
|
|
+ // 解析短期文件
|
|
|
+ JSONObject fileResult = fileAnalysis(file, station, "nwp", requestJson.getStr("beginDate"), requestJson.getStr("beginDate"));
|
|
|
+ // 如果解析文件成功,则放入data集合中
|
|
|
+ if (JsonResultUtil.Type.success.value().equals(fileResult.get(JsonResultUtil.CODE_TAG))) {
|
|
|
+ getStatus = true;
|
|
|
+ result = fileResult;
|
|
|
+ dataArr.addAll(fileResult.getJSONArray("data"));
|
|
|
+ } else {
|
|
|
+ dataArr.add(stationCodeArr.get(i).toString() + ":" + errMsg.getStr("msg"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 如果全部文件都未下载,返回失败原因
|
|
|
+ if (!getStatus) {
|
|
|
+ return JsonResultUtil.failure(dataArr);
|
|
|
+ }
|
|
|
+ // 将data放入列表
|
|
|
+ result.set("data", dataArr);
|
|
|
// 如果解析完的短期文件列表为空
|
|
|
return result;
|
|
|
}
|
|
@@ -175,13 +224,13 @@ public class ApiServiceImpl implements ApiService {
|
|
|
// 明日修正后数据Arr
|
|
|
JSONArray datas = values.getJSONArray("datas");
|
|
|
// 将json数据转化为ListMap
|
|
|
- List<Map<String, Object>> dqListMap = getDqListMap(station,datas, station.getName());
|
|
|
+ List<Map<String, Object>> dqListMap = getDqListMap(station, datas, station.getName());
|
|
|
// 短期文件模板
|
|
|
String vmsPath = SystermUtils.getResourceBasePath() + "/vms/DQ.vm";
|
|
|
// 生成dq文件
|
|
|
- JSONObject result = genFile(station, dqListMap, vmsPath);
|
|
|
- if(JsonResultUtil.Type.failure.value().equals(result.get(JsonResultUtil.CODE_TAG))){
|
|
|
- Record record = new Record(CommonStant.RECORD_TYPE_PUSH_CORRECT_TO_MIN_IO,"CSGS",requestJson.getStr("wfId"),null,LocalDateTime.now(),LocalDateTime.now(),JsonResultUtil.Type.failure.msg(),JsonResultUtil.Type.failure.value());
|
|
|
+ JSONObject result = genFile(station, dqListMap, vmsPath, "_CORR", "DQ");
|
|
|
+ if (JsonResultUtil.Type.failure.value().equals(result.get(JsonResultUtil.CODE_TAG))) {
|
|
|
+ Record record = new Record(CommonStant.RECORD_TYPE_PUSH_CORRECT_TO_MIN_IO, "CSGS", requestJson.getStr("wfId"), null, LocalDateTime.now(), LocalDateTime.now(), JsonResultUtil.Type.failure.msg(), JsonResultUtil.Type.failure.value());
|
|
|
recordService.save(record);
|
|
|
}
|
|
|
return JsonResultUtil.success();
|
|
@@ -199,8 +248,9 @@ public class ApiServiceImpl implements ApiService {
|
|
|
String stationCode = requestJson.getStr("wfId");
|
|
|
// 根据场站编号查询场站信息
|
|
|
Station station = stationService.findByStationCode(stationCode);
|
|
|
+ JSONObject errMsg = new JSONObject();
|
|
|
// 从minIo下载文件
|
|
|
- File file = downLoadFileFromMinIo(station, "cdq", requestJson.getStr("beginDate"), requestJson.getStr("endDate"));
|
|
|
+ File file = downLoadFileFromMinIo(station, "cdq", requestJson.getStr("beginDate"), requestJson.getStr("endDate"), errMsg);
|
|
|
//解析短期文件
|
|
|
result = fileAnalysis(file, station, "cdq", requestJson.getStr("beginDate"), requestJson.getStr("endDate"));
|
|
|
return result;
|
|
@@ -223,11 +273,11 @@ public class ApiServiceImpl implements ApiService {
|
|
|
// 所有日期的数据Arr
|
|
|
JSONArray datas = values.getJSONArray("datas");
|
|
|
// 将json数据转化为ListMap
|
|
|
- List<Map<String, Object>> dqListMap = getDqListMap(station,datas, station.getName());
|
|
|
+ List<Map<String, Object>> dqListMap = getDqListMap(station, datas, station.getName());
|
|
|
// 短期文件模板
|
|
|
- String vmsPath = SystermUtils.getResourceBasePath() + "/vms/DQ.vm";
|
|
|
- // 生成dq文件
|
|
|
- genFile(station, dqListMap, vmsPath);
|
|
|
+ String vmsPath = SystermUtils.getResourceBasePath() + "/vms/CDQ.vm";
|
|
|
+ // 生成cdq文件
|
|
|
+ genFile(station, dqListMap, vmsPath, "_CORR", "CDQ");
|
|
|
return JsonResultUtil.success();
|
|
|
}
|
|
|
|
|
@@ -241,9 +291,9 @@ public class ApiServiceImpl implements ApiService {
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONObject fileAnalysis(File dqFile, Station station, String type, String startDate, String endDate) {
|
|
|
- if (dqFile == null){
|
|
|
- log.info("从minIo下载的文件为空");
|
|
|
- return JsonResultUtil.failure();
|
|
|
+ if (dqFile == null) {
|
|
|
+ log.info("请求的文件不存在");
|
|
|
+ return JsonResultUtil.failure("请求的文件不存在");
|
|
|
}
|
|
|
JSONArray resultArr = new JSONArray();
|
|
|
boolean jx = true;
|
|
@@ -281,7 +331,7 @@ public class ApiServiceImpl implements ApiService {
|
|
|
//当条的日期
|
|
|
String thisDate = string_arr[2].split(" ")[0];
|
|
|
// 如果是短期
|
|
|
- if("dq".equals(type)){
|
|
|
+ if ("dq".equals(type)) {
|
|
|
// 如果 当条日期<开始时间 || 当条日期>结束时间 跳过当次循环
|
|
|
if (thisDate.compareTo(startDate) < 0 || thisDate.compareTo(endDate) > 0) {
|
|
|
continue;
|
|
@@ -320,10 +370,7 @@ public class ApiServiceImpl implements ApiService {
|
|
|
valuesArr.add(dayInfoJson);
|
|
|
|
|
|
// 将短期预测数据放入powerJson中
|
|
|
- JSONObject powerJson = new JSONObject();
|
|
|
- powerJson.set("values", valuesArr);
|
|
|
- powerJson.set("type", "power");
|
|
|
- powerJson.set("wfId", station.getStationCode());
|
|
|
+ JSONObject powerJson = putPowerJson(station.getStationCode(), "power", valuesArr);
|
|
|
//返回短期数据JSONArray
|
|
|
resultArr.add(powerJson);
|
|
|
// 如果是超短期
|
|
@@ -359,17 +406,61 @@ public class ApiServiceImpl implements ApiService {
|
|
|
dayInfoJson.set("datas", datas);
|
|
|
valuesArr.add(dayInfoJson);
|
|
|
// 将短期预测数据放入powerJson中
|
|
|
- JSONObject powerJson = new JSONObject();
|
|
|
- powerJson.set("type", "power");
|
|
|
- powerJson.set("values", valuesArr);
|
|
|
- powerJson.set("wfId", station.getStationCode());
|
|
|
+ JSONObject powerJson = putPowerJson(station.getStationCode(), "power", valuesArr);
|
|
|
+ //返回短期数据JSONArray
|
|
|
+ resultArr.add(powerJson);
|
|
|
+ }else if("nwp".equals(type)){
|
|
|
+ while ((stringLine = dqBufferedReader.readLine()) != null) {
|
|
|
+ String[] string_arr = stringLine.split("\t");
|
|
|
+ if (string_arr[0].startsWith("#")) {
|
|
|
+ if (StrUtil.isNotEmpty(string_arr[2])) {
|
|
|
+ // 每一条数据的json,放入预测数据和预测时间
|
|
|
+ oneJson = new JSONObject();
|
|
|
+ oneJson.set("farmId", string_arr[1]);
|
|
|
+ oneJson.set("scDate",string_arr[2]);
|
|
|
+ oneJson.set("scTime", string_arr[3]);
|
|
|
+ oneJson.set("preDate", string_arr[4]);
|
|
|
+ oneJson.set("preTime", string_arr[5]);
|
|
|
+ oneJson.set("t", new BigDecimal(string_arr[6]).subtract(new BigDecimal("273.15")));
|
|
|
+ oneJson.set("rh", new BigDecimal(string_arr[7]));
|
|
|
+ oneJson.set("pressure", new BigDecimal(string_arr[8]));
|
|
|
+ oneJson.set("swr", new BigDecimal(string_arr[9]));
|
|
|
+ oneJson.set("lwr", new BigDecimal(string_arr[10]));
|
|
|
+ oneJson.set("senf", new BigDecimal(string_arr[11]));
|
|
|
+ oneJson.set("ws10", new BigDecimal(string_arr[12]));
|
|
|
+ oneJson.set("ws30", new BigDecimal(string_arr[13]));
|
|
|
+ oneJson.set("ws50", new BigDecimal(string_arr[14]));
|
|
|
+ oneJson.set("ws70", new BigDecimal(string_arr[15]));
|
|
|
+ oneJson.set("ws80", new BigDecimal(string_arr[16]));
|
|
|
+ oneJson.set("ws90", new BigDecimal(string_arr[17]));
|
|
|
+ oneJson.set("ws100", new BigDecimal(string_arr[18]));
|
|
|
+ oneJson.set("ws170", new BigDecimal(string_arr[19]));
|
|
|
+ oneJson.set("wd10",new BigDecimal( string_arr[20]));
|
|
|
+ oneJson.set("wd30", new BigDecimal(string_arr[21]));
|
|
|
+ oneJson.set("wd50", new BigDecimal(string_arr[22]));
|
|
|
+ oneJson.set("wd70", new BigDecimal(string_arr[23]));
|
|
|
+ oneJson.set("wd80", new BigDecimal(string_arr[24]));
|
|
|
+ oneJson.set("wd90", new BigDecimal(string_arr[25]));
|
|
|
+ oneJson.set("wd100", new BigDecimal(string_arr[26]));
|
|
|
+ oneJson.set("wd170", new BigDecimal(string_arr[27]));
|
|
|
+ // 将一每条数据放入datas(一天的json)中
|
|
|
+ datas.add(oneJson);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 将最后一日数据放入valuesArr
|
|
|
+ dayInfoJson.set("datas", datas);
|
|
|
+ valuesArr.add(dayInfoJson);
|
|
|
+ // 将短期预测数据放入powerJson中
|
|
|
+ JSONObject powerJson = putPowerJson(station.getStationCode(), "nwp", valuesArr);
|
|
|
//返回短期数据JSONArray
|
|
|
resultArr.add(powerJson);
|
|
|
+
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
jx = false;
|
|
|
log.error(station.getStationCode() + " 解析当天DQ文件错误:", e);
|
|
|
- return JsonResultUtil.failure();
|
|
|
+ return JsonResultUtil.failure(" 解析当天DQ文件错误:");
|
|
|
} finally {
|
|
|
close(dqBufferedReader, dqRead);
|
|
|
}
|
|
@@ -378,7 +469,7 @@ public class ApiServiceImpl implements ApiService {
|
|
|
if (jx) {
|
|
|
return JsonResultUtil.success(resultArr);
|
|
|
} else {
|
|
|
- return JsonResultUtil.failure();
|
|
|
+ return JsonResultUtil.failure("解析失败");
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -407,31 +498,30 @@ public class ApiServiceImpl implements ApiService {
|
|
|
* @param dqDate
|
|
|
* @param stationName
|
|
|
* @param station
|
|
|
- *
|
|
|
* @return
|
|
|
*/
|
|
|
- public List<Map<String, Object>> getDqListMap(Station station ,JSONArray dqDate, String stationName) {
|
|
|
+ public List<Map<String, Object>> getDqListMap(Station station, JSONArray dqDate, String stationName) {
|
|
|
List<Map<String, Object>> result = new ArrayList<>();
|
|
|
- BigDecimal rowData = BigDecimal.ZERO;
|
|
|
// 获取当前时间
|
|
|
String dateNow = DateUtil.format(new Date(), "yyyy-MM-dd");
|
|
|
+ JSONObject errMsg = new JSONObject();
|
|
|
// 下载当天文件
|
|
|
- File file = downLoadFileFromMinIo(station, "dq", dateNow,dateNow);
|
|
|
+ File file = downLoadFileFromMinIo(station, "dq", dateNow, dateNow, errMsg);
|
|
|
//解析短期文件,并获取当天数据
|
|
|
JSONObject todayData = fileAnalysis(file, station, "dq", dateNow, dateNow);
|
|
|
- if(JsonResultUtil.Type.success.value().equals(todayData.get(JsonResultUtil.CODE_TAG))){
|
|
|
- addListData(result,todayData,stationName,"minIo");
|
|
|
+ if (JsonResultUtil.Type.success.value().equals(todayData.get(JsonResultUtil.CODE_TAG))) {
|
|
|
+ addListData(result, todayData, stationName, "minIo");
|
|
|
}
|
|
|
// 将修正后的明天的数据放入
|
|
|
- addListData(result,JsonResultUtil.success(dqDate),stationName,"other");
|
|
|
+ addListData(result, JsonResultUtil.success(dqDate), stationName, "other");
|
|
|
// 获取后天日期
|
|
|
LocalDateTime dayAfterTomorrowDateTime = LocalDateTime.now().plus(2, ChronoUnit.DAYS);
|
|
|
String dayAfterTomorrowStr = dayAfterTomorrowDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
//解析短期文件,并获取后天之后的数据
|
|
|
JSONObject otherData = fileAnalysis(file, station, "dq", dayAfterTomorrowStr, "2123-01-01");
|
|
|
// 放入后天之后的数据
|
|
|
- if(JsonResultUtil.Type.success.value().equals(otherData.get(JsonResultUtil.CODE_TAG))){
|
|
|
- addListData(result,otherData,stationName,"minIo");
|
|
|
+ if (JsonResultUtil.Type.success.value().equals(otherData.get(JsonResultUtil.CODE_TAG))) {
|
|
|
+ addListData(result, otherData, stationName, "minIo");
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
@@ -439,15 +529,18 @@ public class ApiServiceImpl implements ApiService {
|
|
|
/**
|
|
|
* 生成文件
|
|
|
*
|
|
|
- * @param station
|
|
|
- * @param listDate
|
|
|
+ * @param station 场站信息
|
|
|
+ * @param listDate 数据列表
|
|
|
+ * @param vmsPath 模板路径
|
|
|
+ * @param dateType 数据类型(CORR:修正)
|
|
|
+ * @param fileType 文件类型(DQ/CDQ)
|
|
|
* @return
|
|
|
*/
|
|
|
- public JSONObject genFile(Station station, List<Map<String, Object>> listDate, String vmsPath) {
|
|
|
+ public JSONObject genFile(Station station, List<Map<String, Object>> listDate, String vmsPath, String dateType, String fileType) {
|
|
|
Template template = this.velocityEngine.getTemplate(vmsPath);
|
|
|
if (template == null) {
|
|
|
log.info("模板为空");
|
|
|
- return JsonResultUtil.failure();
|
|
|
+ return JsonResultUtil.failure("生成模板为空");
|
|
|
}
|
|
|
// 初始化模板
|
|
|
VelocityContext velocityContext = new VelocityContext();
|
|
@@ -467,7 +560,8 @@ public class ApiServiceImpl implements ApiService {
|
|
|
fileUrl.mkdirs();
|
|
|
}
|
|
|
// 文件名
|
|
|
- String fileName = "DQ_" + DateUtil.format(new Date(), "yyyyMMddHHmmss") + "0.RB";
|
|
|
+ String fileName = fileType + "_" + DateUtil.format(new Date(), "yyyyMMddHHmmss") + "0" + dateType + ".RB";
|
|
|
+
|
|
|
// 根据文件路径和文件名,初始化文件
|
|
|
File file = new File(fUrl + File.separatorChar + fileName);
|
|
|
// 文件输出入流
|
|
@@ -482,12 +576,12 @@ public class ApiServiceImpl implements ApiService {
|
|
|
os.write(writer.toString().getBytes("UTF-8"));
|
|
|
os.flush();
|
|
|
} else {
|
|
|
- log.warn(station.getStationCode() + " 生成DQ文件失败");
|
|
|
+ log.warn(station.getStationCode() + " 生成" + fileType + "文件失败");
|
|
|
}
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
- log.warn(station.getStationCode() + " 创建DQ文件失败");
|
|
|
- return JsonResultUtil.failure();
|
|
|
+ log.warn(station.getStationCode() + " 创建" + fileType + "文件失败");
|
|
|
+ return JsonResultUtil.failure(" 创建" + fileType + "文件失败");
|
|
|
} finally {
|
|
|
if (os != null) {
|
|
|
try {
|
|
@@ -501,16 +595,16 @@ public class ApiServiceImpl implements ApiService {
|
|
|
// 将生成的文件放入MinIo
|
|
|
JSONObject pushMinIoResult = pushFileToMinIo(file, station.getStationCode());
|
|
|
if (JsonResultUtil.Type.failure.value().equals(pushMinIoResult.get(JsonResultUtil.CODE_TAG))) {
|
|
|
- return JsonResultUtil.failure();
|
|
|
+ return JsonResultUtil.failure(pushMinIoResult.get(JsonResultUtil.DETAIL_TAG));
|
|
|
}
|
|
|
-
|
|
|
+ // 获取推送到minIo的文件名
|
|
|
String minIoFileUrl = pushMinIoResult.getStr(JsonResultUtil.DATA_TAG);
|
|
|
- String [] minIoFileUrlArr = minIoFileUrl.split(";");
|
|
|
- if(minIoFileUrlArr.length>1){
|
|
|
- for(String url : minIoFileUrlArr ){
|
|
|
+ String[] minIoFileUrlArr = minIoFileUrl.split(";");
|
|
|
+ if (minIoFileUrlArr.length > 1) {
|
|
|
+ for (String url : minIoFileUrlArr) {
|
|
|
postFileCreateInfoToCloud(station.getStationCode(), file.getName(), url);
|
|
|
}
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
// 如果文件放成功,回传文件生成信息到云端
|
|
|
postFileCreateInfoToCloud(station.getStationCode(), file.getName(), pushMinIoResult.getStr(JsonResultUtil.DATA_TAG));
|
|
|
}
|
|
@@ -526,32 +620,33 @@ public class ApiServiceImpl implements ApiService {
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONObject pushFileToMinIo(File file, String stationCode) {
|
|
|
- boolean flag = false;
|
|
|
// 存放完文件后返回的文件路径
|
|
|
- String minIoFileUrl = "";
|
|
|
+ String minIoFileUrl;
|
|
|
try {
|
|
|
// 查看桶名称是否存在
|
|
|
- flag = minioUtilService.bucketExists(bucketName);
|
|
|
+ boolean flag = minioUtilService.bucketExists(bucketName);
|
|
|
if (!flag) {
|
|
|
- return JsonResultUtil.failure();
|
|
|
+ return JsonResultUtil.failure("MinIo桶不存在");
|
|
|
}
|
|
|
// 向minIo中放入文件
|
|
|
InputStream in = new FileInputStream(file);
|
|
|
String fileName = "/" + stationCode + "/" + file.getName();
|
|
|
minIoFileUrl = minioUtilService.putObject(bucketName, fileName, in);
|
|
|
// 如果是AB机,向B中也放入文件
|
|
|
- if(stationCode.indexOf("-A")>0){
|
|
|
- String fileNameB = "/" + stationCode.replace("-A","-B") + "/" + file.getName();
|
|
|
- minIoFileUrl = minIoFileUrl + ";"+minioUtilService.putObject(bucketName, fileNameB, in);
|
|
|
+ if (stationCode.indexOf("-A") > 0) {
|
|
|
+ String fileNameB = "/" + stationCode.replace("-A", "-B") + "/" + file.getName();
|
|
|
+ minIoFileUrl = minIoFileUrl + ";" + minioUtilService.putObject(bucketName, fileNameB, in);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
- return JsonResultUtil.failure();
|
|
|
+ return JsonResultUtil.failure("推送MinIo失败");
|
|
|
}
|
|
|
return JsonResultUtil.success(minIoFileUrl);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 请求V3云平台返回上传minIo文件信息
|
|
|
+ *
|
|
|
* @param stationCode
|
|
|
* @param fileName
|
|
|
* @param fileDownloadUrl
|
|
@@ -583,88 +678,102 @@ public class ApiServiceImpl implements ApiService {
|
|
|
* @param type
|
|
|
* @return
|
|
|
*/
|
|
|
- public File downLoadFileFromMinIo(Station station, String type, String startTime, String endTime) {
|
|
|
+ public File downLoadFileFromMinIo(Station station, String type, String startTime, String endTime, JSONObject errMsg) {
|
|
|
// 如果场站信息为空
|
|
|
if (station == null) {
|
|
|
log.info("场站信息为空");
|
|
|
+ errMsg.set("msg", "场站信息为空");
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
if (startTime == null || "".equals(startTime)) {
|
|
|
- log.info("超短期文件获取失败,开始时间为空");
|
|
|
+ log.info("文件获取失败,开始时间为空");
|
|
|
+ errMsg.set("msg", "文件获取失败,开始时间为空");
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 校验日期格式
|
|
|
+ if (startTime.indexOf("-") == -1) {
|
|
|
+ log.info("文件获取失败,开始时间格式不正确,正确格式为yyyy-MM-dd");
|
|
|
+ errMsg.set("msg", "文件获取失败,开始时间格式不正确,正确格式为yyyy-MM-dd");
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
Record record = new Record();
|
|
|
log.info("下载minIo原始RB文件 --> {}" + station.getStationCode());
|
|
|
try {
|
|
|
- HttpRequest httpRequest = HttpRequest.get(url + station.getStationCode());
|
|
|
+ // 从云上获取minIo中指定日期的文件信息 格式https://117.78.19.70:9010/client/getFileLogsForAio/J00260/2023-08-11
|
|
|
+ String getUrl = url + station.getStationCode() + "/" + startTime;
|
|
|
+ HttpRequest httpRequest = HttpRequest.get(getUrl);
|
|
|
httpRequest.setGlobalTimeout(20000);
|
|
|
String body = httpRequest.execute().body();
|
|
|
JSONObject json = JSONUtil.parseObj(body);
|
|
|
- String code = json.get("code").toString();
|
|
|
String data = json.get("data").toString();
|
|
|
+ String code = json.get("code").toString();
|
|
|
if (!code.equals("0") || data.length() <= 0) {
|
|
|
record.setState(StatusEnum.RESPONSE_FAIL.getCode());
|
|
|
log.error("下载minIo原始RB文件 --> {} 失败,失败原因:{}", station.getStationCode(), StatusEnum.RESPONSE_FAIL.getMsg());
|
|
|
+ errMsg.set("msg", "下载原始文件失败");
|
|
|
return null;
|
|
|
}
|
|
|
- // 获取文件文件内容
|
|
|
+ // 获取文件信息列表
|
|
|
JSONArray array = JSONUtil.parseArray(data);
|
|
|
// 文件列表
|
|
|
List<FileCreateLog> list = array.toList(FileCreateLog.class);
|
|
|
- // 获取当前时间
|
|
|
- String dateNow = DateUtil.format(new Date(), "yyyyMMdd");
|
|
|
// 如果文件列表为空,则未获取到文件
|
|
|
if (CollectionUtil.isEmpty(list)) {
|
|
|
record.setState(StatusEnum.FILE_NULL.getCode());
|
|
|
- log.error("下载minIo原始RB文件 --> {} 失败,失败原因:{}", station.getStationCode(), StatusEnum.FILE_NULL.getMsg());
|
|
|
+ log.info("下载minIo原始RB文件 --> {} 失败,失败原因:{}", station.getStationCode(), StatusEnum.FILE_NULL.getMsg());
|
|
|
+ errMsg.set("msg", "下载原始文件失败");
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
// 保存文件路径
|
|
|
String fileSaveUrl = fileDir + File.separatorChar + "init" + File.separatorChar + station.getStationCode();
|
|
|
- log.info(fileSaveUrl);
|
|
|
+ log.info("文件保存路径" + fileSaveUrl);
|
|
|
File dir = new File(fileSaveUrl);
|
|
|
if (!dir.exists()) {// 判断目录是否存在
|
|
|
dir.mkdirs();
|
|
|
log.info("创建目录:" + fileSaveUrl);
|
|
|
}
|
|
|
- // 筛选当日短期文件
|
|
|
- List<FileCreateLog> listNow = new ArrayList<>();
|
|
|
+ // 筛选指定日期短期文件
|
|
|
+ List<FileCreateLog> listFile = new ArrayList<>();
|
|
|
String nowUrl = "";
|
|
|
String downloadFileName = "";
|
|
|
// 如果是短期
|
|
|
if ("dq".equals(type)) {
|
|
|
- listNow = list.stream().filter(f -> f.getFileName().contains("DQ_" + dateNow.replace("-", ""))).collect(Collectors.toList());
|
|
|
+ listFile = list.stream().filter(f -> f.getFileName().contains("DQ_" + startTime.replace("-", ""))).collect(Collectors.toList());
|
|
|
// 如果文件为空,
|
|
|
- if (CollectionUtil.isEmpty(listNow)) {
|
|
|
+ if (CollectionUtil.isEmpty(listFile)) {
|
|
|
record.setState(StatusEnum.FILE_NULL.getCode());
|
|
|
- log.error("下载minIo原始RB文件 --> {} 失败,失败原因:{}", station.getStationCode()+" DQ文件", StatusEnum.FILE_NULL.getMsg());
|
|
|
+ log.error("下载minIo原始RB文件 --> {} 失败,失败原因:{}", station.getStationCode() + " DQ文件", StatusEnum.FILE_NULL.getMsg());
|
|
|
+ errMsg.set("msg", "下载原始文件失败");
|
|
|
return null;
|
|
|
}
|
|
|
// 将短期文件倒序,获取最新的文件
|
|
|
- listNow.sort(Comparator.comparing(FileCreateLog::getFileName).reversed());
|
|
|
+ listFile.sort(Comparator.comparing(FileCreateLog::getFileName).reversed());
|
|
|
// 拼接下载文件url=fileUrl(下载文件请求地址)+从minIo获取的最新一条的文件id
|
|
|
- nowUrl = fileurl + listNow.get(0).getId();
|
|
|
- downloadFileName = listNow.get(0).getFileName();
|
|
|
+ nowUrl = fileurl + listFile.get(0).getId();
|
|
|
+ downloadFileName = listFile.get(0).getFileName();
|
|
|
// 如果是超短期
|
|
|
} else if ("cdq".equals(type)) {
|
|
|
// 格式化开始时间 将时间2019-10-10 01:15 转为=》201910100115
|
|
|
String formatStartTime = startTime.replace("-", "").replace(" ", "").replace(":", "");
|
|
|
// 根据CDQ_201910100115 筛选超短期文件
|
|
|
- listNow = list.stream().filter(f -> f.getFileName().contains("CDQ_" + formatStartTime)).collect(Collectors.toList());
|
|
|
- // 如果文件为空,
|
|
|
- if (CollectionUtil.isEmpty(listNow)) {
|
|
|
- record.setState(StatusEnum.FILE_NULL.getCode());
|
|
|
- log.error("下载minIo原始RB文件 --> {} 失败,失败原因:{}", station.getStationCode(), StatusEnum.FILE_NULL.getMsg());
|
|
|
- return null;
|
|
|
- }
|
|
|
+ listFile = list.stream().filter(f -> f.getFileName().contains("CDQ_" + formatStartTime)).collect(Collectors.toList());
|
|
|
+ } else if("nwp".equals(type)){
|
|
|
+ listFile = list.stream().filter(f -> f.getFileName().contains("NWP_" + startTime.replace("-", ""))).collect(Collectors.toList());
|
|
|
+ // 将短期文件倒序,获取最新的文件
|
|
|
+ listFile.sort(Comparator.comparing(FileCreateLog::getFileName).reversed());
|
|
|
+ // 拼接下载文件url=fileUrl(下载文件请求地址)+从minIo获取的最新一条的文件id
|
|
|
+ nowUrl = fileurl + listFile.get(0).getId();
|
|
|
+ downloadFileName = listFile.get(0).getFileName();
|
|
|
}
|
|
|
// 如果文件为空,
|
|
|
- if (CollectionUtil.isEmpty(listNow)) {
|
|
|
- record.setState(StatusEnum.FILE_NULL.getCode());
|
|
|
+ if (CollectionUtil.isEmpty(listFile)) {
|
|
|
log.error("下载minIo原始RB文件 --> {} 失败,失败原因:{}", station.getStationCode(), StatusEnum.FILE_NULL.getMsg());
|
|
|
+ record.setState(StatusEnum.FILE_NULL.getCode());
|
|
|
+ errMsg.set("msg", "下载原始文件失败");
|
|
|
return null;
|
|
|
}
|
|
|
|
|
@@ -673,28 +782,33 @@ public class ApiServiceImpl implements ApiService {
|
|
|
File nowFile = HttpUtil.downloadFileFromUrl(nowUrl, fileSaveUrl + File.separatorChar + downloadFileName);
|
|
|
if (nowFile == null) {
|
|
|
record.setState(StatusEnum.DOWNLOAD_FILE_ERROR.getCode());
|
|
|
- log.error("下载minIo原始RB文件 --> {} 失败,失败原因:{}", station.getStationCode(), StatusEnum.DOWNLOAD_FILE_ERROR.getMsg());
|
|
|
+ log.error("下载minIo原始RB文件 --> {} 失败,失败原因:{}", station.getStationCode(), StatusEnum.FILE_NULL.getMsg());
|
|
|
+ errMsg.set("msg", "下载原始文件失败");
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
// 回传dq和nwp文件状态
|
|
|
- this.postBackMinIoState(station.getStationCode(),nowFile.getName(),"down","是");
|
|
|
+ this.postBackMinIoState(station.getStationCode(), nowFile.getName(), "down", "是");
|
|
|
// 返回文件
|
|
|
return nowFile;
|
|
|
} catch (Exception e) {
|
|
|
record.setState(StatusEnum.DOWNLOAD_FILE_FAIL.getCode());
|
|
|
log.error("下载minIo原始RB文件 --> {} 失败,失败原因:{}", station.getStationCode(), StatusEnum.DOWNLOAD_FILE_FAIL.getMsg());
|
|
|
e.printStackTrace();
|
|
|
+ errMsg.set("msg", "下载原始文件失败");
|
|
|
return null;
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
record.setState(StatusEnum.RESPONSE_FAIL.getCode());
|
|
|
log.error("下载minIo原始RB文件 --> {} 失败,失败原因:{}", station.getStationCode(), StatusEnum.RESPONSE_FAIL.getMsg());
|
|
|
e.printStackTrace();
|
|
|
+ errMsg.set("msg", "下载原始文件失败");
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 向list中添加数据
|
|
|
*
|
|
|
* @param list
|
|
|
* @param data
|
|
@@ -702,37 +816,38 @@ public class ApiServiceImpl implements ApiService {
|
|
|
* @param type
|
|
|
* @return
|
|
|
*/
|
|
|
- public List<Map<String, Object>> addListData(List<Map<String, Object>> list,JSONObject data,String stationName,String type){
|
|
|
- if(JsonResultUtil.Type.success.value().equals(data.get(JsonResultUtil.CODE_TAG))) {
|
|
|
- JSONArray dataArr = new JSONArray();
|
|
|
- if("minIo".equals(type)){
|
|
|
+ public List<Map<String, Object>> addListData(List<Map<String, Object>> list, JSONObject data, String stationName, String type) {
|
|
|
+ if (JsonResultUtil.Type.success.value().equals(data.get(JsonResultUtil.CODE_TAG))) {
|
|
|
+ JSONArray dataArr;
|
|
|
+ if ("minIo".equals(type)) {
|
|
|
dataArr = data.getJSONArray("data").getJSONObject(0).getJSONArray("values");
|
|
|
- for(Object one :dataArr){
|
|
|
+ for (Object one : dataArr) {
|
|
|
JSONArray oneDaysData = JSONUtil.parseObj(one).getJSONArray("datas");
|
|
|
- addOneDay(list,oneDaysData,stationName);
|
|
|
+ addOneDay(list, oneDaysData, stationName);
|
|
|
}
|
|
|
- }else if("other".equals(type)){
|
|
|
+ } else if ("other".equals(type)) {
|
|
|
dataArr = data.getJSONArray("data");
|
|
|
- addOneDay(list,dataArr,stationName);
|
|
|
+ addOneDay(list, dataArr, stationName);
|
|
|
}
|
|
|
}
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 添加1天的数据
|
|
|
*
|
|
|
* @param list
|
|
|
* @param dataArr
|
|
|
* @param stationName
|
|
|
* @return
|
|
|
*/
|
|
|
- public List<Map<String, Object>> addOneDay(List<Map<String, Object>> list,JSONArray dataArr,String stationName){
|
|
|
- for(Object one :dataArr){
|
|
|
+ public List<Map<String, Object>> addOneDay(List<Map<String, Object>> list, JSONArray dataArr, String stationName) {
|
|
|
+ for (Object one : dataArr) {
|
|
|
JSONObject oneJson = JSONUtil.parseObj(one);
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
map.put("stationName", stationName);
|
|
|
- map.put("fpValue", oneJson.getStr("data") == null ? "-99" : new BigDecimal(oneJson.getStr("data")).divide(new BigDecimal("1000"),2,BigDecimal.ROUND_HALF_UP));
|
|
|
- map.put("forecastTime", oneJson.getStr("time").length()==16? oneJson.getStr("time")+ CommonStant.CHARACTER_TIME_ZERO:oneJson.getStr("time"));
|
|
|
+ map.put("fpValue", oneJson.getStr("data") == null ? "-99" : new BigDecimal(oneJson.getStr("data")).divide(new BigDecimal("1000"), 2, BigDecimal.ROUND_HALF_UP));
|
|
|
+ map.put("forecastTime", oneJson.getStr("time").length() == 16 ? oneJson.getStr("time") + CommonStant.CHARACTER_TIME_ZERO : oneJson.getStr("time"));
|
|
|
list.add(map);
|
|
|
}
|
|
|
return list;
|
|
@@ -740,20 +855,37 @@ public class ApiServiceImpl implements ApiService {
|
|
|
|
|
|
/**
|
|
|
* 从minIo下载文件后,回传状态
|
|
|
+ *
|
|
|
* @param stationCode
|
|
|
* @param fileName
|
|
|
* @param type
|
|
|
* @param status
|
|
|
*/
|
|
|
@Override
|
|
|
- public void postBackMinIoState(String stationCode ,String fileName,String type,String status){
|
|
|
+ public void postBackMinIoState(String stationCode, String fileName, String type, String status) {
|
|
|
Map urlParams = new HashMap(4);
|
|
|
- urlParams.put("stationCode",stationCode);
|
|
|
- urlParams.put("forecastFileName",fileName);
|
|
|
- urlParams.put("type",type);
|
|
|
- urlParams.put("status",status);
|
|
|
- log.debug("回传文件状态给新平台,请求参数",JSONUtil.toJsonStr(urlParams));
|
|
|
- String repose = HttpUtil.post(postBackUrl,urlParams,10000);
|
|
|
+ urlParams.put("stationCode", stationCode);
|
|
|
+ urlParams.put("forecastFileName", fileName);
|
|
|
+ urlParams.put("type", type);
|
|
|
+ urlParams.put("status", status);
|
|
|
+ log.debug("回传文件状态给新平台,请求参数", JSONUtil.toJsonStr(urlParams));
|
|
|
+ String repose = HttpUtil.post(postBackUrl, urlParams, 10000);
|
|
|
log.info("回传文件状态给新平台,请求相应 {}", repose);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设置短期数据
|
|
|
+ *
|
|
|
+ * @param stationCode
|
|
|
+ * @param type
|
|
|
+ * @param valuesArr
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public JSONObject putPowerJson(String stationCode, String type, JSONArray valuesArr) {
|
|
|
+ JSONObject result = new JSONObject();
|
|
|
+ result.set("wfId", stationCode);
|
|
|
+ result.set("type", type);
|
|
|
+ result.set("values", valuesArr);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
}
|