|
@@ -1,20 +1,33 @@
|
|
|
package com.gyee.impala.service.impl.master;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.gyee.impala.common.config.datasource.KuduDataSourceConfig;
|
|
|
+import com.gyee.impala.common.result.JsonResult;
|
|
|
+import com.gyee.impala.common.result.ResultCode;
|
|
|
+import com.gyee.impala.common.util.DateUtil;
|
|
|
import com.gyee.impala.common.util.SnowFlakeUtil;
|
|
|
import com.gyee.impala.mapper.master.WindspeedforecastshorttermMapper;
|
|
|
-import com.gyee.impala.model.master.Casewarningcustom;
|
|
|
+import com.gyee.impala.mapper.master.WindspeedforecastspshorttermMapper;
|
|
|
+import com.gyee.impala.model.master.WindspeedforecastContrast;
|
|
|
import com.gyee.impala.model.master.Windspeedforecastshortterm;
|
|
|
+import com.gyee.impala.model.master.Windspeedforecastspshortterm;
|
|
|
import com.gyee.impala.service.master.IWindspeedforecastshorttermService;
|
|
|
import org.apache.kudu.client.*;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.cache.annotation.Cacheable;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.function.Function;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -28,6 +41,9 @@ import java.util.List;
|
|
|
public class WindspeedforecastshorttermServiceImpl extends ServiceImpl<WindspeedforecastshorttermMapper, Windspeedforecastshortterm> implements IWindspeedforecastshorttermService {
|
|
|
@Autowired
|
|
|
private KuduDataSourceConfig kuduConfig;
|
|
|
+ @Resource
|
|
|
+ private WindspeedforecastspshorttermMapper windspeedforecastspshorttermMapper;
|
|
|
+
|
|
|
/**
|
|
|
* 由于mybatis-plus存储的中文乱码
|
|
|
* 采用原生写法
|
|
@@ -80,4 +96,80 @@ public class WindspeedforecastshorttermServiceImpl extends ServiceImpl<Windspeed
|
|
|
Page<Windspeedforecastshortterm> windspeedforecastshorttermPage = baseMapper.selectPage(page, wrapper);
|
|
|
return windspeedforecastshorttermPage;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Cacheable("windspeedforecastcontrast")
|
|
|
+ public JSONObject getContrast(String stationid, String starttime, String endtime, int timescale) {
|
|
|
+ if(stationid.isEmpty()||starttime.isEmpty()||endtime.isEmpty()){
|
|
|
+ return JsonResult.error(ResultCode.PARAM_IS_BLANK);
|
|
|
+ }
|
|
|
+ Date dateStart = DateUtil.str2DateTime(starttime);
|
|
|
+ Date dateEnd = DateUtil.str2DateTime(endtime);
|
|
|
+ Date dateStartQntq = DateUtil.str2QntqDateTime(starttime);
|
|
|
+ Date dateEndQntq = DateUtil.str2QntqDateTime(endtime);
|
|
|
+
|
|
|
+ //list1短期 list2超短期 list3去年同期短期 list4去年同期超短期
|
|
|
+ List<Windspeedforecastshortterm> list1 = getShortterm(stationid,dateStart,dateEnd);
|
|
|
+ List<Windspeedforecastspshortterm> list2 = getSpShortterm(stationid,dateStart,dateEnd,timescale);
|
|
|
+ List<Windspeedforecastshortterm> list3 = getShortterm(stationid,dateStartQntq,dateEndQntq);
|
|
|
+ List<Windspeedforecastspshortterm> list4 = getSpShortterm(stationid,dateStartQntq,dateEndQntq,timescale);
|
|
|
+ List<WindspeedforecastContrast> windspeedforecastContrasts = new ArrayList<>();
|
|
|
+ list1.forEach(l->{
|
|
|
+ WindspeedforecastContrast wsfcc = new WindspeedforecastContrast();
|
|
|
+ wsfcc.setCalctime(l.getCalctime());
|
|
|
+ wsfcc.setActualpower(l.getActualpower());
|
|
|
+ wsfcc.setActualwindspeed(l.getActualwindspeed());
|
|
|
+ wsfcc.setForecastpower(l.getForecastpower());
|
|
|
+ wsfcc.setForecastwindspeed(l.getForecastwindspeed());
|
|
|
+ windspeedforecastContrasts.add(wsfcc);
|
|
|
+ });
|
|
|
+ Map<Date, WindspeedforecastContrast> contrastMap = windspeedforecastContrasts.stream().collect(Collectors.toMap(WindspeedforecastContrast::getCalctime, Function.identity()));
|
|
|
+ /*Map<Date, WindspeedforecastContrast> contrastMap = new HashMap<>();
|
|
|
+ for (WindspeedforecastContrast wsfcc : windspeedforecastContrasts) {
|
|
|
+ contrastMap.put(wsfcc.getCalctime(), wsfcc);
|
|
|
+ }*/
|
|
|
+ list2.forEach(l-> {
|
|
|
+ WindspeedforecastContrast wsfcc = contrastMap.get(l.getCalctime());
|
|
|
+ wsfcc.setForecastpowersp(l.getForecastpower());
|
|
|
+ wsfcc.setForecastwindspeedsp(l.getForecastwindspeed());
|
|
|
+ });
|
|
|
+ //给年份加一年,然后匹配
|
|
|
+ list3.forEach(l-> {
|
|
|
+ WindspeedforecastContrast wsfcc = contrastMap.get(DateUtil.dateTimeAddYear(l.getCalctime()));
|
|
|
+ wsfcc.setActualpowertq(l.getActualpower());
|
|
|
+ wsfcc.setForecastpowertq(l.getForecastpower());
|
|
|
+ wsfcc.setActualwindspeedtq(l.getActualwindspeed());
|
|
|
+ wsfcc.setForecastwindspeedtq(l.getForecastwindspeed());
|
|
|
+ });
|
|
|
+ list4.forEach(l-> {
|
|
|
+ WindspeedforecastContrast wsfcc = contrastMap.get(DateUtil.dateTimeAddYear(l.getCalctime()));
|
|
|
+ wsfcc.setForecastpowersptq(l.getForecastpower());
|
|
|
+ wsfcc.setForecastwindspeedsptq(l.getForecastwindspeed());
|
|
|
+ });
|
|
|
+
|
|
|
+ return JsonResult.successData(ResultCode.SUCCESS,windspeedforecastContrasts);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 短期功率
|
|
|
+ */
|
|
|
+ private List<Windspeedforecastshortterm> getShortterm(String stationid, Date dateStart, Date dateEnd) {
|
|
|
+ QueryWrapper<Windspeedforecastshortterm> wrapper = new QueryWrapper<>();
|
|
|
+ wrapper.eq("stationid", stationid)
|
|
|
+ .eq("algorithmmodel","风电_极限学习机_功率_中国大陆")
|
|
|
+ .between("calctime", dateStart, dateEnd);
|
|
|
+ return baseMapper.selectList(wrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 超短期功率
|
|
|
+ */
|
|
|
+ private List<Windspeedforecastspshortterm> getSpShortterm(String stationid, Date dateStart, Date dateEnd,int timescale) {
|
|
|
+ QueryWrapper<Windspeedforecastspshortterm> wrapper = new QueryWrapper<>();
|
|
|
+ wrapper.eq("stationid", stationid)
|
|
|
+ .between("calctime", dateStart, dateEnd)
|
|
|
+ .eq("forecasttime", timescale);
|
|
|
+ return windspeedforecastspshorttermMapper.selectList(wrapper);
|
|
|
+ }
|
|
|
+
|
|
|
}
|