|
@@ -0,0 +1,646 @@
|
|
|
+package com.jiayue.ipfcst.service;
|
|
|
+
|
|
|
+import com.jiayue.ipfcst.common.core.exception.BusinessException;
|
|
|
+import com.jiayue.ipfcst.common.core.util.CommonUtil;
|
|
|
+import com.jiayue.ipfcst.common.core.util.DateMomentUtil;
|
|
|
+import com.jiayue.ipfcst.common.data.entity.ElectricField;
|
|
|
+import com.jiayue.ipfcst.common.data.entity.Nwp;
|
|
|
+import com.jiayue.ipfcst.common.data.entity.NwpOne;
|
|
|
+import com.jiayue.ipfcst.common.data.entity.SysParameter;
|
|
|
+import com.jiayue.ipfcst.common.data.repository.NwpOneRepository;
|
|
|
+import com.jiayue.ipfcst.common.data.repository.NwpRepository;
|
|
|
+import com.jiayue.ipfcst.common.data.repository.SysParameterRepository;
|
|
|
+import com.jiayue.ipfcst.common.data.service.BaseService;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang.time.DateFormatUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.domain.Page;
|
|
|
+import org.springframework.data.domain.PageRequest;
|
|
|
+import org.springframework.data.domain.Pageable;
|
|
|
+import org.springframework.data.domain.Sort;
|
|
|
+import org.springframework.data.jpa.domain.Specification;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Propagation;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import javax.persistence.criteria.Predicate;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * NWP实时业务层
|
|
|
+ *
|
|
|
+ * @author yh
|
|
|
+ * @version 1.0
|
|
|
+ * @since 2019/8/5 16:02
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@Slf4j
|
|
|
+public class NwpOneService extends BaseService {
|
|
|
+
|
|
|
+ private final NwpOneRepository nwpOneRepository;
|
|
|
+
|
|
|
+ private final SysParameterRepository sysParameterRepository;
|
|
|
+ @Autowired
|
|
|
+ public NwpOneService( NwpOneRepository nwpOneRepository, SysParameterRepository sysParameterRepository){
|
|
|
+ this.nwpOneRepository = nwpOneRepository;
|
|
|
+ this.sysParameterRepository = sysParameterRepository;
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 按时间查询实时NWP yh
|
|
|
+ * @param startTime 开始时间
|
|
|
+ * @param endTime 结束时间
|
|
|
+ * @return 结果集
|
|
|
+ */
|
|
|
+ @Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
|
|
|
+ public Map<String,Object> findByForecastTimeBetween(Long startTime, Long endTime) throws BusinessException {
|
|
|
+ Map<String,Object> map = new HashMap<>();
|
|
|
+ List<NwpOne> list = new ArrayList<>();
|
|
|
+ List<NwpOne> checkList = new ArrayList<>();
|
|
|
+ Map<String,Object> datas = new LinkedHashMap<>();
|
|
|
+ list = nwpOneRepository.findByPreTimeBetween(startTime, endTime);
|
|
|
+ list.sort(Comparator.comparing(NwpOne::getPreTime));
|
|
|
+
|
|
|
+ long startTimeLong = startTime;
|
|
|
+ long endTimeLong = endTime;
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ long timeStep = 900000L;
|
|
|
+ if(startTimeLong%timeStep !=0){
|
|
|
+ startTimeLong = startTimeLong -(startTimeLong%timeStep);
|
|
|
+ }
|
|
|
+ List<String> times = new ArrayList<>();
|
|
|
+
|
|
|
+ for(long i = startTimeLong;i<endTimeLong;i=i+timeStep){
|
|
|
+ long finalI = i;
|
|
|
+ List<NwpOne> p = list.stream().filter(t -> t.getPreTime() == finalI).collect(Collectors.toList());
|
|
|
+ if (p != null && p.size() > 0) {
|
|
|
+ checkList.add(p.get(0));
|
|
|
+ }else{
|
|
|
+ checkList.add(new NwpOne());
|
|
|
+ }
|
|
|
+ String timeFormat = sdf.format(new Date(i));
|
|
|
+ times.add(timeFormat);
|
|
|
+ }
|
|
|
+ this.defaultReplace(checkList);
|
|
|
+ ElectricField electricField = this.getElectricField();
|
|
|
+ List<BigDecimal> ws10Collect = new ArrayList<>();
|
|
|
+ List<BigDecimal> ws30Collect= new ArrayList<>();
|
|
|
+ List<BigDecimal> ws50Collect= new ArrayList<>();
|
|
|
+ List<BigDecimal> ws70Collect= new ArrayList<>();
|
|
|
+ List<BigDecimal> ws80Collect= new ArrayList<>();
|
|
|
+ List<BigDecimal> ws90Collect= new ArrayList<>();
|
|
|
+ List<BigDecimal> ws100Collect= new ArrayList<>();
|
|
|
+ List<BigDecimal> ws170Collect= new ArrayList<>();
|
|
|
+ List<BigDecimal> swrCollect= new ArrayList<>();
|
|
|
+ List<BigDecimal> diffuseRadiationCollect= new ArrayList<>();
|
|
|
+ List<BigDecimal> directRadiationCollect= new ArrayList<>();
|
|
|
+ Map<String,String> map1 = new HashMap<>();
|
|
|
+ if(electricField.getElectricFieldTypeEnum().getCode() == 1){
|
|
|
+ swrCollect = checkList.stream().map(NwpOne::getSwr).collect(Collectors.toList());
|
|
|
+ diffuseRadiationCollect = checkList.stream().map(NwpOne::getDiffuseRadiation).collect(Collectors.toList());
|
|
|
+ directRadiationCollect = checkList.stream().map(NwpOne::getDirectRadiation).collect(Collectors.toList());
|
|
|
+ datas.put("swr",swrCollect);
|
|
|
+ datas.put("diffuseRadiation",diffuseRadiationCollect);
|
|
|
+ datas.put("directRadiation",directRadiationCollect);
|
|
|
+
|
|
|
+ }else{
|
|
|
+ ws10Collect = checkList.stream().map(NwpOne::getWs10).collect(Collectors.toList());
|
|
|
+ ws30Collect = checkList.stream().map(NwpOne::getWs30).collect(Collectors.toList());
|
|
|
+ ws50Collect = checkList.stream().map(NwpOne::getWs50).collect(Collectors.toList());
|
|
|
+ ws70Collect = checkList.stream().map(NwpOne::getWs70).collect(Collectors.toList());
|
|
|
+ ws80Collect = checkList.stream().map(NwpOne::getWs80).collect(Collectors.toList());
|
|
|
+ ws90Collect = checkList.stream().map(NwpOne::getWs90).collect(Collectors.toList());
|
|
|
+ ws100Collect = checkList.stream().map(NwpOne::getWs100).collect(Collectors.toList());
|
|
|
+ ws170Collect = checkList.stream().map(NwpOne::getWs170).collect(Collectors.toList());
|
|
|
+ datas.put("ws10",ws10Collect);
|
|
|
+ datas.put("ws30",ws30Collect);
|
|
|
+ datas.put("ws50",ws50Collect);
|
|
|
+ datas.put("ws70",ws70Collect);
|
|
|
+ datas.put("ws80",ws80Collect);
|
|
|
+ datas.put("ws90",ws90Collect);
|
|
|
+ datas.put("ws100",ws100Collect);
|
|
|
+ datas.put("ws170",ws170Collect);
|
|
|
+ try {
|
|
|
+ SysParameter sysParameter = sysParameterRepository.findBySysKeyEquals("NWP_CHANGE_WIND");
|
|
|
+ if (sysParameter != null) {
|
|
|
+ String nwpChangeWind = sysParameter.getSysValue();
|
|
|
+ String[] windChangeName = nwpChangeWind.split(",");
|
|
|
+ if (windChangeName.length == 16) {
|
|
|
+ map1.put("ws10",windChangeName[0]+"米风速");
|
|
|
+ map1.put("ws30",windChangeName[1]+"米风速");
|
|
|
+ map1.put("ws50",windChangeName[2]+"米风速");
|
|
|
+ map1.put("ws70",windChangeName[3]+"米风速");
|
|
|
+ map1.put("ws80",windChangeName[4]+"米风速");
|
|
|
+ map1.put("ws90",windChangeName[5]+"米风速");
|
|
|
+ map1.put("ws100",windChangeName[6]+"米风速");
|
|
|
+ map1.put("ws170",windChangeName[7]+"米风速");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (RuntimeException e) {
|
|
|
+ String errorInfo = "NWP风速风向别名参数获取失败" + CommonUtil.printStackTraceToString(e);
|
|
|
+ log.error(errorInfo, e);
|
|
|
+ }
|
|
|
+ if (map1.isEmpty()){
|
|
|
+ map1.put("ws10","10米风速");
|
|
|
+ map1.put("ws30","30米风速");
|
|
|
+ map1.put("ws50","50米风速");
|
|
|
+ map1.put("ws70","70米风速");
|
|
|
+ map1.put("ws80","80米风速");
|
|
|
+ map1.put("ws90","90米风速");
|
|
|
+ map1.put("ws100","100米风速");
|
|
|
+ map1.put("ws170","170米风速");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ map.put("cName",map1);
|
|
|
+ map.put("times",times);
|
|
|
+ map.put("datas",datas);
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据时间 分页查询 NWP数据 yh
|
|
|
+ *
|
|
|
+ * @param startTime 开始时间
|
|
|
+ * @param endTime 结束时间
|
|
|
+ * @param page 页码
|
|
|
+ * @param size 条数
|
|
|
+ * @param sortOrder 排序
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
|
|
|
+ public Map<String, Object> findByTimeBetweenAndNoForPaging(Long startTime, Long endTime,
|
|
|
+ Integer page, Integer size,
|
|
|
+ String sortOrder) {
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ Sort sort = Sort.by(Sort.Direction.DESC, "preTime");
|
|
|
+ if (sortOrder.contains("asc")) {
|
|
|
+ sort = Sort.by(Sort.Direction.ASC, "preTime");
|
|
|
+ }
|
|
|
+ Specification<NwpOne> specification = this.specificationFindByTimeAndNo(startTime, endTime);
|
|
|
+ Pageable pageable = PageRequest.of(page - 1, size, sort);
|
|
|
+ Page nwps = nwpOneRepository.findAll(specification,pageable);
|
|
|
+ List<NwpOne> datas = new ArrayList<>();
|
|
|
+ datas = nwps.getContent();
|
|
|
+ this.defaultReplace(datas);
|
|
|
+ map.put("content", datas);
|
|
|
+ map.put("count", nwps.getTotalElements());
|
|
|
+ Map<String,String> map1 = new HashMap<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ SysParameter sysParameter = sysParameterRepository.findBySysKeyEquals("NWP_CHANGE_WIND");
|
|
|
+ if (sysParameter != null) {
|
|
|
+ String nwpChangeWind = sysParameter.getSysValue();
|
|
|
+ String[] windChangeName = nwpChangeWind.split(",");
|
|
|
+ if (windChangeName.length == 16) {
|
|
|
+ map1.put("preTime","预测时间");
|
|
|
+ map1.put("scTime","生成时间");
|
|
|
+ map1.put("pressure","气压(KPa)");
|
|
|
+ map1.put("t","温度(℃)");
|
|
|
+ map1.put("rh","湿度(%)");
|
|
|
+ map1.put("swr","总辐射(W/㎡)");
|
|
|
+ map1.put("directRadiation","直辐射(W/㎡)");
|
|
|
+ map1.put("diffuseRadiation","散辐射(W/㎡)");
|
|
|
+ map1.put("senf","热感通量(W/㎡)");
|
|
|
+ map1.put("ws10",windChangeName[0]+"米风速(m/s)");
|
|
|
+ map1.put("ws30",windChangeName[1]+"米风速(m/s)");
|
|
|
+ map1.put("ws50",windChangeName[2]+"米风速(m/s)");
|
|
|
+ map1.put("ws70",windChangeName[3]+"米风速(m/s)");
|
|
|
+ map1.put("ws80",windChangeName[4]+"米风速(m/s)");
|
|
|
+ map1.put("ws90",windChangeName[5]+"米风速(m/s)");
|
|
|
+ map1.put("ws100",windChangeName[6]+"米风速(m/s)");
|
|
|
+ map1.put("ws170",windChangeName[7]+"米风速(m/s)");
|
|
|
+ map1.put("wd10",windChangeName[8]+"米风向(°)");
|
|
|
+ map1.put("wd30",windChangeName[9]+"米风向(°)");
|
|
|
+ map1.put("wd50",windChangeName[10]+"米风向(°)");
|
|
|
+ map1.put("wd70",windChangeName[11]+"米风向(°)");
|
|
|
+ map1.put("wd80",windChangeName[12]+"米风向(°)");
|
|
|
+ map1.put("wd90",windChangeName[13]+"米风向(°)");
|
|
|
+ map1.put("wd100",windChangeName[14]+"米风向(°)");
|
|
|
+ map1.put("wd170",windChangeName[15]+"米风向(°)");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (RuntimeException e) {
|
|
|
+ String errorInfo = "NWP风速风向别名参数获取失败" + CommonUtil.printStackTraceToString(e);
|
|
|
+ log.error(errorInfo, e);
|
|
|
+ }
|
|
|
+ if (map1.isEmpty()){
|
|
|
+ map1.put("preTime","预测时间");
|
|
|
+ map1.put("scTime","生成时间");
|
|
|
+ map1.put("pressure","气压(KPa)");
|
|
|
+ map1.put("t","温度(℃)");
|
|
|
+ map1.put("rh","湿度(%)");
|
|
|
+ map1.put("swr","总辐射(W/㎡)");
|
|
|
+ map1.put("directRadiation","直辐射(W/㎡)");
|
|
|
+ map1.put("diffuseRadiation","散辐射(W/㎡)");
|
|
|
+ map1.put("senf","热感通量(W/㎡)");
|
|
|
+ map1.put("ws10","10米风速(m/s)");
|
|
|
+ map1.put("ws30","30米风速(m/s)");
|
|
|
+ map1.put("ws50","50米风速(m/s)");
|
|
|
+ map1.put("ws70","70米风速(m/s)");
|
|
|
+ map1.put("ws80","80米风速(m/s)");
|
|
|
+ map1.put("ws90","90米风速(m/s)");
|
|
|
+ map1.put("ws100","100米风速(m/s)");
|
|
|
+ map1.put("ws170","170米风速(m/s)");
|
|
|
+ map1.put("wd10","10米风向(m/s)");
|
|
|
+ map1.put("wd30","30米风向(m/s)");
|
|
|
+ map1.put("wd50","50米风向(m/s)");
|
|
|
+ map1.put("wd70","70米风向(m/s)");
|
|
|
+ map1.put("wd80","80米风向(m/s)");
|
|
|
+ map1.put("wd90","90米风向(m/s)");
|
|
|
+ map1.put("wd100","100米风向(m/s)");
|
|
|
+ map1.put("wd170","170米风向(m/s)");
|
|
|
+ }
|
|
|
+ map.put("cName",map1);
|
|
|
+ //################ 统计 ##################
|
|
|
+ int days = DateMomentUtil.getDaysBetweenTwoDate(startTime,endTime+1000);
|
|
|
+ List<NwpOne> dataList = new ArrayList<>();
|
|
|
+ for (int i = 0 ; i < days; i++){
|
|
|
+ NwpOne nwp = new NwpOne();
|
|
|
+ List<NwpOne> nwpOneList = nwpOneRepository.findByPreTimeBetween(startTime + ((long) i * 60 * 60 * 24 * 1000),startTime + ((long) (i+1) * 60 * 60 * 24 * 1000 - 1000));
|
|
|
+ BigDecimal t = new BigDecimal(0);
|
|
|
+ BigDecimal rh = new BigDecimal(0);
|
|
|
+ BigDecimal pressure = new BigDecimal(0);
|
|
|
+ BigDecimal swr = new BigDecimal(0);
|
|
|
+ BigDecimal lwr = new BigDecimal(0);
|
|
|
+ BigDecimal directRadiation = new BigDecimal(0);
|
|
|
+ BigDecimal diffuseRadiation = new BigDecimal(0);
|
|
|
+ BigDecimal senf = new BigDecimal(0);
|
|
|
+ BigDecimal ws10 = new BigDecimal(0);
|
|
|
+ BigDecimal ws30 = new BigDecimal(0);
|
|
|
+ BigDecimal ws50 = new BigDecimal(0);
|
|
|
+ BigDecimal ws70 = new BigDecimal(0);
|
|
|
+ BigDecimal ws80 = new BigDecimal(0);
|
|
|
+ BigDecimal ws90 = new BigDecimal(0);
|
|
|
+ BigDecimal ws100 = new BigDecimal(0);
|
|
|
+ BigDecimal ws170 = new BigDecimal(0);
|
|
|
+ BigDecimal wd10 = new BigDecimal(0);
|
|
|
+ BigDecimal wd30 = new BigDecimal(0);
|
|
|
+ BigDecimal wd50 = new BigDecimal(0);
|
|
|
+ BigDecimal wd70 = new BigDecimal(0);
|
|
|
+ BigDecimal wd80 = new BigDecimal(0);
|
|
|
+ BigDecimal wd90 = new BigDecimal(0);
|
|
|
+ BigDecimal wd100 = new BigDecimal(0);
|
|
|
+ BigDecimal wd170 = new BigDecimal(0);
|
|
|
+ for(int j = 0; j < nwpOneList.size(); j++ ){
|
|
|
+ t = t.add(nwpOneList.get(j).getT() == null ? BigDecimal.valueOf(0) : nwpOneList.get(j).getT());
|
|
|
+ rh = rh.add(nwpOneList.get(j).getRh() == null ? BigDecimal.valueOf(0) : nwpOneList.get(j).getRh());
|
|
|
+ pressure = pressure.add(nwpOneList.get(j).getPressure() == null ? BigDecimal.valueOf(0) : nwpOneList.get(j).getPressure());
|
|
|
+ swr = swr.add(nwpOneList.get(j).getSwr() == null ? BigDecimal.valueOf(0) : nwpOneList.get(j).getSwr());
|
|
|
+ lwr = lwr.add(nwpOneList.get(j).getLwr() == null ? BigDecimal.valueOf(0) : nwpOneList.get(j).getLwr());
|
|
|
+ directRadiation = directRadiation.add(nwpOneList.get(j).getDirectRadiation() == null ? BigDecimal.valueOf(0) : nwpOneList.get(j).getDirectRadiation());
|
|
|
+ diffuseRadiation = diffuseRadiation.add(nwpOneList.get(j).getDiffuseRadiation() == null ? BigDecimal.valueOf(0) : nwpOneList.get(j).getDiffuseRadiation());
|
|
|
+ senf = senf.add(nwpOneList.get(j).getSenf() == null ? BigDecimal.valueOf(0) : nwpOneList.get(j).getSenf());
|
|
|
+ ws10 = ws10.add(nwpOneList.get(j).getWs10() == null ? BigDecimal.valueOf(0) : nwpOneList.get(j).getWs10());
|
|
|
+ ws30 = ws30.add(nwpOneList.get(j).getWs30() == null ? BigDecimal.valueOf(0) : nwpOneList.get(j).getWs30());
|
|
|
+ ws50 = ws50.add(nwpOneList.get(j).getWs50() == null ? BigDecimal.valueOf(0) : nwpOneList.get(j).getWs50());
|
|
|
+ ws70 = ws70.add(nwpOneList.get(j).getWs70() == null ? BigDecimal.valueOf(0) : nwpOneList.get(j).getWs70());
|
|
|
+ ws80 = ws80.add(nwpOneList.get(j).getWs80() == null ? BigDecimal.valueOf(0) : nwpOneList.get(j).getWs80());
|
|
|
+ ws90 = ws90.add(nwpOneList.get(j).getWs90() == null ? BigDecimal.valueOf(0) : nwpOneList.get(j).getWs90());
|
|
|
+ ws100 = ws100.add(nwpOneList.get(j).getWs100() == null ? BigDecimal.valueOf(0) : nwpOneList.get(j).getWs100());
|
|
|
+ ws170 = ws170.add(nwpOneList.get(j).getWs170() == null ? BigDecimal.valueOf(0) : nwpOneList.get(j).getWs170());
|
|
|
+ wd10 = wd10.add(nwpOneList.get(j).getWd10() == null ? BigDecimal.valueOf(0) : nwpOneList.get(j).getWd10());
|
|
|
+ wd30 = wd30.add(nwpOneList.get(j).getWd30() == null ? BigDecimal.valueOf(0) : nwpOneList.get(j).getWd30());
|
|
|
+ wd50 = wd50.add(nwpOneList.get(j).getWd50() == null ? BigDecimal.valueOf(0) : nwpOneList.get(j).getWd50());
|
|
|
+ wd70 = wd70.add(nwpOneList.get(j).getWd70() == null ? BigDecimal.valueOf(0) : nwpOneList.get(j).getWd70());
|
|
|
+ wd80 = wd80.add(nwpOneList.get(j).getWd80() == null ? BigDecimal.valueOf(0) : nwpOneList.get(j).getWd80());
|
|
|
+ wd90 = wd90.add(nwpOneList.get(j).getWd90() == null ? BigDecimal.valueOf(0) : nwpOneList.get(j).getWd90());
|
|
|
+ wd100 = wd100.add(nwpOneList.get(j).getWd100() == null ? BigDecimal.valueOf(0) : nwpOneList.get(j).getWd100());
|
|
|
+ wd170 = wd170.add(nwpOneList.get(j).getWd170() == null ? BigDecimal.valueOf(0) : nwpOneList.get(j).getWd170());
|
|
|
+ }
|
|
|
+ if(nwpOneList.size() > 0){
|
|
|
+ nwp.setScTime(nwpOneList.get(0).getScTime());
|
|
|
+ nwp.setScDate(nwpOneList.get(0).getScDate());
|
|
|
+ nwp.setPreTime(nwpOneList.get(0).getPreTime());
|
|
|
+ nwp.setPreDate(nwpOneList.get(0).getPreDate());
|
|
|
+ nwp.setFarmId(nwpOneList.get(0).getFarmId());
|
|
|
+ nwp.setT(t.divide(BigDecimal.valueOf(nwpOneList.size()),2, BigDecimal.ROUND_HALF_UP).doubleValue() < 0d ? new BigDecimal(0) : t.divide(BigDecimal.valueOf(nwpOneList.size()),2, BigDecimal.ROUND_HALF_UP));
|
|
|
+ nwp.setRh(rh.divide(BigDecimal.valueOf(nwpOneList.size()),2, BigDecimal.ROUND_HALF_UP).doubleValue() < 0d ? new BigDecimal(0) : rh.divide(BigDecimal.valueOf(nwpOneList.size()),2, BigDecimal.ROUND_HALF_UP));
|
|
|
+ nwp.setPressure(pressure.divide(BigDecimal.valueOf(nwpOneList.size()),2, BigDecimal.ROUND_HALF_UP).doubleValue() < 0d ? new BigDecimal(0) : pressure.divide(BigDecimal.valueOf(nwpOneList.size()),2, BigDecimal.ROUND_HALF_UP));
|
|
|
+ nwp.setSwr(swr.divide(BigDecimal.valueOf(nwpOneList.size()),2, BigDecimal.ROUND_HALF_UP).doubleValue() < 0d ? new BigDecimal(0) : swr.divide(BigDecimal.valueOf(nwpOneList.size()),2, BigDecimal.ROUND_HALF_UP));
|
|
|
+ nwp.setLwr(lwr.divide(BigDecimal.valueOf(nwpOneList.size()),2, BigDecimal.ROUND_HALF_UP).doubleValue() < 0d ? new BigDecimal(0) : lwr.divide(BigDecimal.valueOf(nwpOneList.size()),2, BigDecimal.ROUND_HALF_UP));
|
|
|
+ nwp.setDirectRadiation(directRadiation.divide(BigDecimal.valueOf(nwpOneList.size()),2, BigDecimal.ROUND_HALF_UP).doubleValue() < 0d ? new BigDecimal(0) : directRadiation.divide(BigDecimal.valueOf(nwpOneList.size()),2, BigDecimal.ROUND_HALF_UP));
|
|
|
+ nwp.setDiffuseRadiation(diffuseRadiation.divide(BigDecimal.valueOf(nwpOneList.size()),2, BigDecimal.ROUND_HALF_UP).doubleValue() < 0d ? new BigDecimal(0) : diffuseRadiation.divide(BigDecimal.valueOf(nwpOneList.size()),2, BigDecimal.ROUND_HALF_UP));
|
|
|
+ nwp.setSenf(senf.divide(BigDecimal.valueOf(nwpOneList.size()),2, BigDecimal.ROUND_HALF_UP).doubleValue() < 0d ? new BigDecimal(0) : senf.divide(BigDecimal.valueOf(nwpOneList.size()),2, BigDecimal.ROUND_HALF_UP));
|
|
|
+ nwp.setWs10(ws10.divide(BigDecimal.valueOf(nwpOneList.size()),2, BigDecimal.ROUND_HALF_UP).doubleValue() < 0d ? new BigDecimal(0) : ws10.divide(BigDecimal.valueOf(nwpOneList.size()),2, BigDecimal.ROUND_HALF_UP));
|
|
|
+ nwp.setWs30(ws30.divide(BigDecimal.valueOf(nwpOneList.size()),2, BigDecimal.ROUND_HALF_UP).doubleValue() < 0d ? new BigDecimal(0) : ws30.divide(BigDecimal.valueOf(nwpOneList.size()),2, BigDecimal.ROUND_HALF_UP));
|
|
|
+ nwp.setWs50(ws50.divide(BigDecimal.valueOf(nwpOneList.size()),2, BigDecimal.ROUND_HALF_UP).doubleValue() < 0d ? new BigDecimal(0) : ws50.divide(BigDecimal.valueOf(nwpOneList.size()),2, BigDecimal.ROUND_HALF_UP));
|
|
|
+ nwp.setWs70(ws70.divide(BigDecimal.valueOf(nwpOneList.size()),2, BigDecimal.ROUND_HALF_UP).doubleValue() < 0d ? new BigDecimal(0) : ws70.divide(BigDecimal.valueOf(nwpOneList.size()),2, BigDecimal.ROUND_HALF_UP));
|
|
|
+ nwp.setWs80(ws80.divide(BigDecimal.valueOf(nwpOneList.size()),2, BigDecimal.ROUND_HALF_UP).doubleValue() < 0d ? new BigDecimal(0) : ws80.divide(BigDecimal.valueOf(nwpOneList.size()),2, BigDecimal.ROUND_HALF_UP));
|
|
|
+ nwp.setWs90(ws90.divide(BigDecimal.valueOf(nwpOneList.size()),2, BigDecimal.ROUND_HALF_UP).doubleValue() < 0d ? new BigDecimal(0) : ws90.divide(BigDecimal.valueOf(nwpOneList.size()),2, BigDecimal.ROUND_HALF_UP));
|
|
|
+ nwp.setWs100(ws100.divide(BigDecimal.valueOf(nwpOneList.size()),2, BigDecimal.ROUND_HALF_UP).doubleValue() < 0d ? new BigDecimal(0) : ws100.divide(BigDecimal.valueOf(nwpOneList.size()),2, BigDecimal.ROUND_HALF_UP));
|
|
|
+ nwp.setWs170(ws170.divide(BigDecimal.valueOf(nwpOneList.size()),2, BigDecimal.ROUND_HALF_UP).doubleValue() < 0d ? new BigDecimal(0) : ws170.divide(BigDecimal.valueOf(nwpOneList.size()),2, BigDecimal.ROUND_HALF_UP));
|
|
|
+ nwp.setWd10(wd10.divide(BigDecimal.valueOf(nwpOneList.size()),2, BigDecimal.ROUND_HALF_UP).doubleValue() < 0d ? new BigDecimal(0) : wd10.divide(BigDecimal.valueOf(nwpOneList.size()),2, BigDecimal.ROUND_HALF_UP));
|
|
|
+ nwp.setWd30(wd30.divide(BigDecimal.valueOf(nwpOneList.size()),2, BigDecimal.ROUND_HALF_UP).doubleValue() < 0d ? new BigDecimal(0) : wd30.divide(BigDecimal.valueOf(nwpOneList.size()),2, BigDecimal.ROUND_HALF_UP));
|
|
|
+ nwp.setWd50(wd50.divide(BigDecimal.valueOf(nwpOneList.size()),2, BigDecimal.ROUND_HALF_UP).doubleValue() < 0d ? new BigDecimal(0) : wd50.divide(BigDecimal.valueOf(nwpOneList.size()),2, BigDecimal.ROUND_HALF_UP));
|
|
|
+ nwp.setWd70(wd70.divide(BigDecimal.valueOf(nwpOneList.size()),2, BigDecimal.ROUND_HALF_UP).doubleValue() < 0d ? new BigDecimal(0) : wd70.divide(BigDecimal.valueOf(nwpOneList.size()),2, BigDecimal.ROUND_HALF_UP));
|
|
|
+ nwp.setWd80(wd80.divide(BigDecimal.valueOf(nwpOneList.size()),2, BigDecimal.ROUND_HALF_UP).doubleValue() < 0d ? new BigDecimal(0) : wd80.divide(BigDecimal.valueOf(nwpOneList.size()),2, BigDecimal.ROUND_HALF_UP));
|
|
|
+ nwp.setWd90(wd90.divide(BigDecimal.valueOf(nwpOneList.size()),2, BigDecimal.ROUND_HALF_UP).doubleValue() < 0d ? new BigDecimal(0) : wd90.divide(BigDecimal.valueOf(nwpOneList.size()),2, BigDecimal.ROUND_HALF_UP));
|
|
|
+ nwp.setWd100(wd100.divide(BigDecimal.valueOf(nwpOneList.size()),2, BigDecimal.ROUND_HALF_UP).doubleValue() < 0d ? new BigDecimal(0) : wd100.divide(BigDecimal.valueOf(nwpOneList.size()),2, BigDecimal.ROUND_HALF_UP));
|
|
|
+ nwp.setWd170(wd170.divide(BigDecimal.valueOf(nwpOneList.size()),2, BigDecimal.ROUND_HALF_UP).doubleValue() < 0d ? new BigDecimal(0) : wd170.divide(BigDecimal.valueOf(nwpOneList.size()),2, BigDecimal.ROUND_HALF_UP));
|
|
|
+ dataList.add(nwp);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ map.put("statistics", dataList);
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据时间和编号 分页查询条件 yh
|
|
|
+ *
|
|
|
+ * @param startTime 开始时间
|
|
|
+ * @param endTime 结束时间
|
|
|
+ * @return 过滤条件
|
|
|
+ */
|
|
|
+ Specification<NwpOne> specificationFindByTimeAndNo(final Long startTime, final Long endTime) {
|
|
|
+ return (Specification<NwpOne>) (root, criteriaQuery, cb) -> {
|
|
|
+ List<Predicate> predicates = new ArrayList<>();
|
|
|
+ if (startTime!=null) {
|
|
|
+ //大于或等于传入时间
|
|
|
+ predicates.add(cb.greaterThanOrEqualTo(root.get("preTime").as(Long.class), startTime));
|
|
|
+ }
|
|
|
+ if (endTime!=null) {
|
|
|
+ //小于传入时间
|
|
|
+ predicates.add(cb.lessThan(root.get("preTime").as(Long.class), endTime));
|
|
|
+ }
|
|
|
+
|
|
|
+ //添加排序的功能
|
|
|
+ return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
+
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 对集合进行 -99替换null操作,主要用于图标展示空值
|
|
|
+ *
|
|
|
+ * @param datas 需要替换集合
|
|
|
+ */
|
|
|
+ public void defaultReplace(List<NwpOne> datas){
|
|
|
+ BigDecimal nullBig = new BigDecimal(-99);
|
|
|
+ for(NwpOne i :datas){
|
|
|
+
|
|
|
+
|
|
|
+ if(i.getT().compareTo(nullBig)==0){
|
|
|
+ i.setT(null);
|
|
|
+ }
|
|
|
+ if(i.getRh().compareTo(nullBig)==0){
|
|
|
+ i.setRh(null);
|
|
|
+ }
|
|
|
+ if(i.getPressure().compareTo(nullBig)==0){
|
|
|
+ i.setPressure(null);
|
|
|
+ }
|
|
|
+ if(i.getSwr().compareTo(nullBig)==0){
|
|
|
+ i.setSwr(null);
|
|
|
+ }
|
|
|
+ if(i.getDirectRadiation().compareTo(nullBig)==0){
|
|
|
+ i.setDirectRadiation(null);
|
|
|
+ }
|
|
|
+ if(i.getDiffuseRadiation().compareTo(nullBig)==0){
|
|
|
+ i.setDiffuseRadiation(null);
|
|
|
+ }
|
|
|
+ if(i.getSenf().compareTo(nullBig)==0){
|
|
|
+ i.setSenf(null);
|
|
|
+ }
|
|
|
+ if(i.getWs10().compareTo(nullBig)==0){
|
|
|
+ i.setWs10(null);
|
|
|
+ }
|
|
|
+ if(i.getWs30().compareTo(nullBig)==0){
|
|
|
+ i.setWs30(null);
|
|
|
+ }
|
|
|
+ if(i.getWs50().compareTo(nullBig)==0){
|
|
|
+ i.setWs50(null);
|
|
|
+ }
|
|
|
+ if(i.getWs70().compareTo(nullBig)==0){
|
|
|
+ i.setWs70(null);
|
|
|
+ }
|
|
|
+ if(i.getWs80().compareTo(nullBig)==0){
|
|
|
+ i.setWs80(null);
|
|
|
+ }
|
|
|
+ if(i.getWs90().compareTo(nullBig)==0){
|
|
|
+ i.setWs90(null);
|
|
|
+ }
|
|
|
+ if(i.getWs100().compareTo(nullBig)==0){
|
|
|
+ i.setWs100(null);
|
|
|
+ }
|
|
|
+ if(i.getWs170().compareTo(nullBig)==0){
|
|
|
+ i.setWs170(null);
|
|
|
+ }
|
|
|
+ if(i.getWd10().compareTo(nullBig)==0){
|
|
|
+ i.setWd10(null);
|
|
|
+ }
|
|
|
+ if(i.getWd30().compareTo(nullBig)==0){
|
|
|
+ i.setWd30(null);
|
|
|
+ }
|
|
|
+ if(i.getWd50().compareTo(nullBig)==0){
|
|
|
+ i.setWd50(null);
|
|
|
+ }
|
|
|
+ if(i.getWd70().compareTo(nullBig)==0){
|
|
|
+ i.setWd70(null);
|
|
|
+ }
|
|
|
+ if(i.getWd80().compareTo(nullBig)==0){
|
|
|
+ i.setWd80(null);
|
|
|
+ }
|
|
|
+ if(i.getWd90().compareTo(nullBig)==0){
|
|
|
+ i.setWd90(null);
|
|
|
+ }
|
|
|
+ if(i.getWd100().compareTo(nullBig)==0){
|
|
|
+ i.setWd100(null);
|
|
|
+ }
|
|
|
+ if(i.getWd170().compareTo(nullBig)==0){
|
|
|
+ i.setWd170(null);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * (统计查询:nwp风速统计(吉林22))
|
|
|
+ * @param startTime 开始时间
|
|
|
+ * @param endTime 结束时间
|
|
|
+ * @param statistics 统计类型
|
|
|
+ * @param wsHeight 层高
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<Map<String, Object>> getWsStatistics( Long startTime,
|
|
|
+ Long endTime,
|
|
|
+ String statistics,
|
|
|
+ Integer wsHeight) {
|
|
|
+ List<Map<String, Object>> resultList = new ArrayList<>();
|
|
|
+
|
|
|
+ List<NwpOne> nList = nwpOneRepository.findByPreTimeBetween(startTime, endTime);
|
|
|
+
|
|
|
+ List<Map<String, Float>> beforeFormatting = new ArrayList<>();
|
|
|
+ Map<String, List<Float>> afterFormatting = new HashMap<>();
|
|
|
+ String dateformat = "yyyyMMdd";
|
|
|
+
|
|
|
+ if (statistics.equals("month")) {
|
|
|
+ dateformat = "yyyyMM";
|
|
|
+ }
|
|
|
+
|
|
|
+ if (statistics.equals("year")) {
|
|
|
+ dateformat = "yyyy";
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (wsHeight == 10) {
|
|
|
+ for (NwpOne n : nList) {
|
|
|
+ Map<String, Float> map1 = new HashMap();
|
|
|
+ map1.put(DateFormatUtils.format(n.getPreTime(), dateformat), n.getWs10().floatValue());
|
|
|
+ beforeFormatting.add(map1);
|
|
|
+ }
|
|
|
+ afterFormatting = beforeFormatting.stream().flatMap(m -> m.entrySet().stream()).collect(Collectors.groupingBy(Map.Entry::getKey, Collectors.mapping(Map.Entry::getValue, Collectors.toList())));
|
|
|
+
|
|
|
+ }
|
|
|
+ if (wsHeight == 30) {
|
|
|
+ for (NwpOne n : nList) {
|
|
|
+ Map<String, Float> map1 = new HashMap();
|
|
|
+ map1.put(DateFormatUtils.format(n.getPreTime(), dateformat), n.getWs30().floatValue());
|
|
|
+ beforeFormatting.add(map1);
|
|
|
+ }
|
|
|
+ afterFormatting = beforeFormatting.stream().flatMap(m -> m.entrySet().stream()).collect(Collectors.groupingBy(Map.Entry::getKey, Collectors.mapping(Map.Entry::getValue, Collectors.toList())));
|
|
|
+
|
|
|
+ }
|
|
|
+ if (wsHeight == 50) {
|
|
|
+ for (NwpOne n : nList) {
|
|
|
+ Map<String, Float> map1 = new HashMap();
|
|
|
+ map1.put(DateFormatUtils.format(n.getPreTime(), dateformat), n.getWs50().floatValue());
|
|
|
+ beforeFormatting.add(map1);
|
|
|
+ }
|
|
|
+ afterFormatting = beforeFormatting.stream().flatMap(m -> m.entrySet().stream()).collect(Collectors.groupingBy(Map.Entry::getKey, Collectors.mapping(Map.Entry::getValue, Collectors.toList())));
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if (wsHeight == 70) {
|
|
|
+ for (NwpOne n : nList) {
|
|
|
+ Map<String, Float> map1 = new HashMap();
|
|
|
+ map1.put(DateFormatUtils.format(n.getPreTime(), dateformat), n.getWs70().floatValue());
|
|
|
+ beforeFormatting.add(map1);
|
|
|
+ }
|
|
|
+ afterFormatting = beforeFormatting.stream().flatMap(m -> m.entrySet().stream()).collect(Collectors.groupingBy(Map.Entry::getKey, Collectors.mapping(Map.Entry::getValue, Collectors.toList())));
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if (wsHeight == 80) {
|
|
|
+ for (NwpOne n : nList) {
|
|
|
+ Map<String, Float> map1 = new HashMap();
|
|
|
+ map1.put(DateFormatUtils.format(n.getPreTime(), dateformat), n.getWs80().floatValue());
|
|
|
+ beforeFormatting.add(map1);
|
|
|
+ }
|
|
|
+ afterFormatting = beforeFormatting.stream().flatMap(m -> m.entrySet().stream()).collect(Collectors.groupingBy(Map.Entry::getKey, Collectors.mapping(Map.Entry::getValue, Collectors.toList())));
|
|
|
+
|
|
|
+ }
|
|
|
+ if (wsHeight == 90) {
|
|
|
+ for (NwpOne n : nList) {
|
|
|
+ Map<String, Float> map1 = new HashMap();
|
|
|
+ map1.put(DateFormatUtils.format(n.getPreTime(), dateformat), n.getWs90().floatValue());
|
|
|
+ beforeFormatting.add(map1);
|
|
|
+ }
|
|
|
+ afterFormatting = beforeFormatting.stream().flatMap(m -> m.entrySet().stream()).collect(Collectors.groupingBy(Map.Entry::getKey, Collectors.mapping(Map.Entry::getValue, Collectors.toList())));
|
|
|
+
|
|
|
+ }
|
|
|
+ if (wsHeight == 100) {
|
|
|
+ for (NwpOne n : nList) {
|
|
|
+ Map<String, Float> map1 = new HashMap();
|
|
|
+ map1.put(DateFormatUtils.format(n.getPreTime(), dateformat), n.getWs100().floatValue());
|
|
|
+ beforeFormatting.add(map1);
|
|
|
+ }
|
|
|
+ afterFormatting = beforeFormatting.stream().flatMap(m -> m.entrySet().stream()).collect(Collectors.groupingBy(Map.Entry::getKey, Collectors.mapping(Map.Entry::getValue, Collectors.toList())));
|
|
|
+
|
|
|
+ }
|
|
|
+ if (wsHeight == 170) {
|
|
|
+ for (NwpOne n : nList) {
|
|
|
+ Map<String, Float> map1 = new HashMap();
|
|
|
+ map1.put(DateFormatUtils.format(n.getPreTime(), dateformat), n.getWs170().floatValue());
|
|
|
+ beforeFormatting.add(map1);
|
|
|
+ }
|
|
|
+ afterFormatting = beforeFormatting.stream().flatMap(m -> m.entrySet().stream()).collect(Collectors.groupingBy(Map.Entry::getKey, Collectors.mapping(Map.Entry::getValue, Collectors.toList())));
|
|
|
+
|
|
|
+ }
|
|
|
+ Map<String, List<Float>> resultMap = new TreeMap<>((str1, str2) -> str1.compareTo(str2));
|
|
|
+ resultMap.putAll(afterFormatting);
|
|
|
+
|
|
|
+ for (String key : resultMap.keySet()) {
|
|
|
+ List<Float> n = afterFormatting.get(key);
|
|
|
+ Float maxValue = Collections.max(n);
|
|
|
+ Float minValue = Collections.min(n);
|
|
|
+ Float init = 0f;
|
|
|
+ BigDecimal sum = new BigDecimal(init);
|
|
|
+ for (int i = 0;i<n.size();i++){
|
|
|
+ BigDecimal value = new BigDecimal(n.get(i));
|
|
|
+ sum = sum.add(value);
|
|
|
+ }
|
|
|
+ BigDecimal size = new BigDecimal(n.size());
|
|
|
+ BigDecimal avgValue = sum.divide(size,4,BigDecimal.ROUND_HALF_UP);
|
|
|
+ BigDecimal topWs = new BigDecimal(maxValue).multiply(new BigDecimal(0.05)).add(new BigDecimal(maxValue)).setScale(4,BigDecimal.ROUND_HALF_UP);
|
|
|
+ Map<String,Object> map2 = new HashMap<>();
|
|
|
+ map2.put("time",key);
|
|
|
+ map2.put("wsHight",wsHeight);
|
|
|
+ map2.put("maxWs",maxValue);
|
|
|
+ map2.put("topWs",topWs.floatValue());
|
|
|
+ map2.put("minWs",minValue);
|
|
|
+ map2.put("avgWs",avgValue);
|
|
|
+ resultList.add(map2);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return resultList;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 用于实时对比查询
|
|
|
+ * 实时nwp数据
|
|
|
+ *
|
|
|
+ */
|
|
|
+ public List<NwpOne> findByPreTimeBetween(Long startTime, Long endTime, Long timeStep){
|
|
|
+ List<NwpOne> list = new ArrayList<>();
|
|
|
+ List<NwpOne> resultList = new ArrayList<>();
|
|
|
+
|
|
|
+ list = nwpOneRepository.findByPreTimeBetween(startTime,endTime);
|
|
|
+
|
|
|
+ if(startTime%timeStep !=0){
|
|
|
+ startTime = endTime -(startTime%timeStep);
|
|
|
+ }
|
|
|
+ for(long i = startTime;i<endTime;i=i+timeStep) {
|
|
|
+ long finalI =i;
|
|
|
+ List<NwpOne> w = list.stream().filter(t -> t.getPreTime() == finalI).collect(Collectors.toList());
|
|
|
+ if(w.size()>0){
|
|
|
+ resultList.add(w.get(0));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return resultList;
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<NwpOne> findByTimeBetween(Long startTime,Long endTime){
|
|
|
+ List<NwpOne> nwpOneList = nwpOneRepository.findByPreTimeBetween(startTime,endTime);
|
|
|
+
|
|
|
+ Collections.sort(nwpOneList,Comparator.comparing(NwpOne::getPreTime));
|
|
|
+
|
|
|
+ return nwpOneList;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public int getNwpDay(){
|
|
|
+ int nwpDays = 3;
|
|
|
+ String days = super.getSysParameter("FILE_NWP_DAYS", "3");
|
|
|
+ try {
|
|
|
+ nwpDays = Integer.parseInt(days);
|
|
|
+ }catch (Exception e){
|
|
|
+ log.error("参数转换数据类型失败");
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return nwpDays;
|
|
|
+ }
|
|
|
+}
|