|
@@ -26,7 +26,6 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import net.jodah.expiringmap.ExpirationPolicy;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
-import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
|
import org.springframework.util.DigestUtils;
|
|
|
import javax.annotation.Resource;
|
|
|
import java.math.BigDecimal;
|
|
@@ -34,7 +33,6 @@ import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
-import java.time.temporal.ChronoUnit;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
@@ -67,7 +65,7 @@ public class InApiServiceImpl implements InApiService {
|
|
|
*/
|
|
|
@Override
|
|
|
public JSONObject getToken(JSONObject userInfo) {
|
|
|
- CacheUtil.cacheMap.entrySet().forEach(entry ->log.info("==========user:" + entry.getKey() + "token" + entry.getValue()+"=========="));
|
|
|
+ CacheUtil.cacheMap.entrySet().forEach(entry -> log.info("==========user:" + entry.getKey() + "token" + entry.getValue() + "=========="));
|
|
|
JSONObject result;
|
|
|
//获取用户名密码
|
|
|
String requestUserName = userInfo.getStr(CommonStant.REQUEST_USER_NAME);
|
|
@@ -78,7 +76,7 @@ public class InApiServiceImpl implements InApiService {
|
|
|
SysParameter systemParameter = systemParameterMapper.selectOne(wrapper);
|
|
|
if (systemParameter == null || systemParameter.getSysValue() == null || "".equals(systemParameter.getSysValue()) || systemParameter.getSysValue().split(CommonStant.CHARACTER_COLON).length != 2) {
|
|
|
log.error("系统参数TOKEN_USER不正常");
|
|
|
- return JsonResultUtil.failure();
|
|
|
+ return JsonResultUtil.failureDesc("系统参数TOKEN_USER不正常");
|
|
|
}
|
|
|
String tokenUser = systemParameter.getSysValue();
|
|
|
// 根据用户名获取密码
|
|
@@ -89,7 +87,7 @@ public class InApiServiceImpl implements InApiService {
|
|
|
// 如果用户名或密码不匹配
|
|
|
if (!requestUserName.equals(userName) || !requestUserPass.equals(passwordMD5t)) {
|
|
|
log.error("账户密码不匹配");
|
|
|
- return JsonResultUtil.failure();
|
|
|
+ return JsonResultUtil.failureDesc("账户密码不匹配");
|
|
|
}
|
|
|
// 根据用户名去缓存中获取token,如果token已存在,则返回token,如果token不存在,则创建新token并返回
|
|
|
// 根据用户名获取token
|
|
@@ -110,7 +108,7 @@ public class InApiServiceImpl implements InApiService {
|
|
|
result.set(CommonStant.TOKEN, token);
|
|
|
// 将生成的token放入缓存中
|
|
|
CacheUtil.cacheMap.put(userName, token, ExpirationPolicy.CREATED, 1440, TimeUnit.MINUTES);
|
|
|
- CacheUtil.cacheMap.entrySet().forEach(entry ->log.info("==========user:" + entry.getKey() + "token" + entry.getValue()+"=========="));
|
|
|
+ CacheUtil.cacheMap.entrySet().forEach(entry -> log.info("==========user:" + entry.getKey() + "token" + entry.getValue() + "=========="));
|
|
|
} else {
|
|
|
// 将缓存中查到的token返回
|
|
|
result = JsonResultUtil.success();
|
|
@@ -130,11 +128,22 @@ public class InApiServiceImpl implements InApiService {
|
|
|
public JSONObject getShortWpfData(JSONObject requestJson) {
|
|
|
// 获取场站id
|
|
|
String stationCode = requestJson.getStr("wfId");
|
|
|
- // 获取明日短期预测数据
|
|
|
- List<ForecastPowerShortTerm> shortList = getShortArr();
|
|
|
- //解析短期文件
|
|
|
- JSONObject result = fileAnalysis(stationCode, shortList, null, "dq", requestJson.getStr("beginDate"), requestJson.getStr("endDate"));
|
|
|
- return result;
|
|
|
+ String startTime = requestJson.getStr("beginDate");
|
|
|
+ String endTime = requestJson.getStr("endDate");
|
|
|
+ SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ try {
|
|
|
+ long startTimeL = sdfDate.parse(startTime).getTime();
|
|
|
+ long oneDay = 24*60*60*1000-1000;
|
|
|
+ long endTimeL = sdfDate.parse(endTime).getTime() + oneDay;
|
|
|
+ // 获取明日短期预测数据
|
|
|
+ List<ForecastPowerShortTerm> shortList = getShortArr(startTimeL, endTimeL);
|
|
|
+ //解析短期文件
|
|
|
+ JSONObject result = fileAnalysis(stationCode, shortList, null, "dq", requestJson.getStr("beginDate"), requestJson.getStr("endDate"));
|
|
|
+ return result;
|
|
|
+ } catch (ParseException e) {
|
|
|
+ log.error(String.valueOf(e));
|
|
|
+ return JsonResultUtil.failure("获取超短期数据失败");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -149,7 +158,7 @@ public class InApiServiceImpl implements InApiService {
|
|
|
// 功率json
|
|
|
JSONObject values = JSONUtil.parseObj(requestJson.getJSONArray("values").get(0));
|
|
|
if (values == null || values.getJSONArray("datas").size() == 0) {
|
|
|
- return JsonResultUtil.failure();
|
|
|
+ return JsonResultUtil.failureDesc("修正短期数据为空");
|
|
|
}
|
|
|
// 明日修正后数据Arr
|
|
|
JSONArray datas = values.getJSONArray("datas");
|
|
@@ -157,7 +166,7 @@ public class InApiServiceImpl implements InApiService {
|
|
|
List<ForecastPowerShortTerm> dqList = getDqListMap(datas);
|
|
|
if (dqList == null || dqList.size() == 0 || dqList.size() > 96) {
|
|
|
log.error("修正数据大于96条");
|
|
|
- return JsonResultUtil.failure();
|
|
|
+ return JsonResultUtil.failureDesc("修正数据大于96条");
|
|
|
}
|
|
|
// 更新
|
|
|
updateShortTerm(dqList);
|
|
@@ -193,7 +202,7 @@ public class InApiServiceImpl implements InApiService {
|
|
|
// 所有日期的数据Arr
|
|
|
JSONArray datas = values.getJSONArray("datas");
|
|
|
if (datas.size() == 0) {
|
|
|
- return JsonResultUtil.failure();
|
|
|
+ return JsonResultUtil.failureDesc("修正超短期数据为空");
|
|
|
}
|
|
|
// 将json数据转化为ListMap
|
|
|
List<ForecastPowerUltraShortTerm> cdqListMap = getCdqListMap(datas);
|
|
@@ -236,6 +245,10 @@ public class InApiServiceImpl implements InApiService {
|
|
|
SimpleDateFormat sdfDateTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
// 如果是短期
|
|
|
if ("dq".equals(type)) {
|
|
|
+ if (shortList == null || shortList.size() == 0) {
|
|
|
+ log.error("短期实时数据为空");
|
|
|
+ return JsonResultUtil.failureDesc("短期实时数据为空");
|
|
|
+ }
|
|
|
for (int i = 0; i < shortList.size(); i++) {
|
|
|
ForecastPowerShortTerm shortTerm = shortList.get(i);
|
|
|
//当条的日期
|
|
@@ -274,8 +287,9 @@ public class InApiServiceImpl implements InApiService {
|
|
|
//返回短期数据JSONArray
|
|
|
resultArr.add(powerJson);
|
|
|
} else if ("cdq".equals(type)) {
|
|
|
- if(ultraShortList==null || ultraShortList.size()==0){
|
|
|
- return JsonResultUtil.failure();
|
|
|
+ if (ultraShortList == null || ultraShortList.size() == 0) {
|
|
|
+ log.error("超短期实时数据为空");
|
|
|
+ return JsonResultUtil.failureDesc("超短期实时数据为空");
|
|
|
}
|
|
|
cdqFileStartTime = sdfDateTime.format(ultraShortList.get(0).getForecastTime());
|
|
|
datas = new JSONArray();
|
|
@@ -302,8 +316,8 @@ public class InApiServiceImpl implements InApiService {
|
|
|
resultArr.add(powerJson);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
- log.error(stationCode + " 解析当天DQ文件错误:", e);
|
|
|
- return JsonResultUtil.failure();
|
|
|
+ log.error(stationCode + " 解析当天DQ数据错误:", e);
|
|
|
+ return JsonResultUtil.failureDesc("解析当天DQ数据错误");
|
|
|
}
|
|
|
//如果解析成功
|
|
|
return JsonResultUtil.success(resultArr);
|
|
@@ -331,7 +345,7 @@ public class InApiServiceImpl implements InApiService {
|
|
|
forecastPowerShortTerm.setPredictionModelEnum(PredictionModelEnum.E11);
|
|
|
forecastPowerShortTerm.setForecastTime(sdf.parse(oneJson.getStr("time")).getTime());
|
|
|
forecastPowerShortTerm.setGenDate(now);
|
|
|
- forecastPowerShortTerm.setFpValue(new BigDecimal(oneJson.getStr("data")).divide(new BigDecimal("1000"),2,BigDecimal.ROUND_HALF_UP));
|
|
|
+ forecastPowerShortTerm.setFpValue(new BigDecimal(oneJson.getStr("data")).divide(new BigDecimal("1000"), 2, BigDecimal.ROUND_HALF_UP));
|
|
|
shortTermList.add(forecastPowerShortTerm);
|
|
|
}
|
|
|
} catch (ParseException e) {
|
|
@@ -357,7 +371,7 @@ public class InApiServiceImpl implements InApiService {
|
|
|
// 初始化短期数据实体
|
|
|
forecastPowerUltraShortTerm.setGenDate(now);
|
|
|
forecastPowerUltraShortTerm.setForecastTime(sdf.parse(oneJson.getStr("time")).getTime());
|
|
|
- forecastPowerUltraShortTerm.setFpValue(new BigDecimal(oneJson.getStr("data")).divide(new BigDecimal("1000"),2,BigDecimal.ROUND_HALF_UP));
|
|
|
+ forecastPowerUltraShortTerm.setFpValue(new BigDecimal(oneJson.getStr("data")).divide(new BigDecimal("1000"), 2, BigDecimal.ROUND_HALF_UP));
|
|
|
forecastPowerUltraShortTerm.setPredictionModelEnum(PredictionModelEnum.E11);
|
|
|
ultraShortTermList.add(forecastPowerUltraShortTerm);
|
|
|
}
|
|
@@ -372,14 +386,12 @@ public class InApiServiceImpl implements InApiService {
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
- public List<ForecastPowerShortTerm> getShortArr() {
|
|
|
+ public List<ForecastPowerShortTerm> getShortArr(long startTime, long endTime) {
|
|
|
// 获取短期预测数据
|
|
|
LambdaQueryWrapper<ForecastPowerShortTerm> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
- // 获取明天0点到23:59:59的预测数据
|
|
|
- long startTime = DateUtil.beginOfDay(DateUtil.tomorrow()).getTime();
|
|
|
- long endTime = DateUtil.endOfDay(DateUtil.tomorrow()).getTime();
|
|
|
- lambdaQueryWrapper.between(ForecastPowerShortTerm::getForecastTime, startTime,endTime);
|
|
|
+ lambdaQueryWrapper.between(ForecastPowerShortTerm::getForecastTime, startTime, endTime);
|
|
|
List<ForecastPowerShortTerm> shortList = forecastPowerShortTermMapper.selectList(lambdaQueryWrapper);
|
|
|
+ shortList.sort(Comparator.comparing(ForecastPowerShortTerm::getForecastTime));
|
|
|
return shortList;
|
|
|
}
|
|
|
|
|
@@ -398,13 +410,14 @@ public class InApiServiceImpl implements InApiService {
|
|
|
long endDateL = 0;
|
|
|
try {
|
|
|
beginDateL = sdf.parse(beginDate).getTime();
|
|
|
- endDateL = sdf.parse(endDate).getTime()-1;
|
|
|
+ endDateL = sdf.parse(endDate).getTime();
|
|
|
} catch (ParseException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
// 获取明天日期
|
|
|
lambdaQueryWrapper.between(ForecastPowerUltraShortTerm::getForecastTime, beginDateL, endDateL);
|
|
|
List<ForecastPowerUltraShortTerm> ultraShortList = forecastPowerUltraShortTermMapper.selectList(lambdaQueryWrapper);
|
|
|
+ ultraShortList.sort(Comparator.comparing(ForecastPowerUltraShortTerm::getForecastTime));
|
|
|
return ultraShortList;
|
|
|
}
|
|
|
|
|
@@ -420,7 +433,8 @@ public class InApiServiceImpl implements InApiService {
|
|
|
long endTime = DateUtil.endOfDay(DateUtil.tomorrow()).getTime();
|
|
|
// 根据开始时间和结束时间作为删除的查询条件
|
|
|
LambdaQueryWrapper<ForecastPowerShortTerm> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
- lambdaQueryWrapper.between(ForecastPowerShortTerm::getForecastTime, startTime,endTime);
|
|
|
+ lambdaQueryWrapper.between(ForecastPowerShortTerm::getForecastTime, startTime, endTime);
|
|
|
+ shortTermList.sort(Comparator.comparing(ForecastPowerShortTerm::getForecastTime));
|
|
|
// 删除明天的预测数据
|
|
|
forecastPowerShortTermMapper.delete(lambdaQueryWrapper);
|
|
|
// 保存明天的预测数据
|
|
@@ -438,10 +452,11 @@ public class InApiServiceImpl implements InApiService {
|
|
|
LambdaQueryWrapper<ForecastPowerUltraShortTerm> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
long startTimeL = ultraShortTermList.stream().mapToLong(ForecastPowerUltraShortTerm::getForecastTime).min().getAsLong();
|
|
|
long endTimeL = ultraShortTermList.stream().mapToLong(ForecastPowerUltraShortTerm::getForecastTime).max().getAsLong();
|
|
|
- if(ultraShortTermList.size()>16){
|
|
|
+ if (ultraShortTermList.size() > 16) {
|
|
|
log.info("====================超短期个数大于16====================");
|
|
|
- return JsonResultUtil.failure();
|
|
|
+ return JsonResultUtil.failureDesc("超短期个数大于16");
|
|
|
}
|
|
|
+ ultraShortTermList.sort(Comparator.comparing(ForecastPowerUltraShortTerm::getForecastTime));
|
|
|
lambdaQueryWrapper.between(ForecastPowerUltraShortTerm::getForecastTime, startTimeL, endTimeL);
|
|
|
forecastPowerUltraShortTermMapper.delete(lambdaQueryWrapper);
|
|
|
forecastPowerUltraShortTermService.saveBatch(ultraShortTermList);
|