tsg-web/src/models/_/shqxjs.js

275 lines
8.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import { config } from '../../config';
import CachePromise from '../../utils/cachepromise';
import { httpget } from '../../utils/request';
import apiurl from '../../service/apiurl';
import moment from 'moment';
export const WeatherSet24h = new CachePromise(
async () => {
const latest = await ShqxYjhisLatest.get();
if (!latest) {
return null;
}
return httpget(apiurl.yjhis.weather, {
filename: latest.rainFile,
x1: 108.615000,//config.extent[0],
y1: 29.315000,//config.extent[1],
x2: 109.345000,//config.extent[2],
y2: 30.055000,//config.extent[3],
//layers: '00.24, 00.01, 01.01, 02.01, 03.01,04.01,05.01,06.01,07.01,08.01,09.01,10.01,11.01,12.01,13.01,14.01,15.01,16.01,17.01,18.01,19.01,20.01,21.01,22.01,23.01,24.01'
layers:'00.24'
}).then(({ data }) => data)
.catch(() => null)
},
1000 * 60
);
//天气预报-网格雨量
export const WeatherSetTm24h = async (paramsTm) => {
const latest = await ShqxYjhisGet(paramsTm)
if (!latest) {
return null;
}
return httpget(apiurl.yjhis.weather, {
filename: latest.rainFile,
x1: 108.615000,//config.extent[0],
y1: 29.315000,//config.extent[1],
x2: 109.345000,//config.extent[2],
y2: 30.055000,//config.extent[3],
layers: '00.24, 00.01, 01.01, 02.01, 03.01,04.01,05.01,06.01,07.01,08.01,09.01,10.01,11.01,12.01,13.01,14.01,15.01,16.01,17.01,18.01,19.01,20.01,21.01,22.01,23.01,24.01'
// layers:'00.24'
}).then(({ data }) => data)
.catch(() => null)
}
//天气预报-网格雨量24
export const WeatherSetTm24h2 = async (paramsTm) => {
const latest = await ShqxYjhisGet(paramsTm)
if (!latest) {
return null;
}
return httpget(apiurl.yjhis.weather, {
filename: latest.rainFile,
x1: 108.62318959955861,//108.615000,//config.extent[0],
y1: 29.328651167767397,//29.315000,//config.extent[1],
x2: 109.33730092768361,//109.345000,//config.extent[2],
y2: 30.04791233720099,//30.055000,//config.extent[3],
// layers: '00.24, 00.01, 01.01, 02.01, 03.01,04.01,05.01,06.01,07.01,08.01,09.01,10.01,11.01,12.01,13.01,14.01,15.01,16.01,17.01,18.01,19.01,20.01,21.01,22.01,23.01,24.01'
layers:'00.24'
}).then(({ data }) => data)
.catch(() => null)
}
//天气预报-网格雨量2h
export const WeatherSetTm2h = async (paramsTm) => {
const latest = await ShqxYjhis2hGet(paramsTm)
if (!latest) {
return null;
}
return httpget(apiurl.yjhis.radar, {
filename: latest.rainFile,
x1: 108.62318959955861,//108.615000,//config.extent[0],
y1: 29.328651167767397,//29.315000,//config.extent[1],
x2: 109.33730092768361,//109.345000,//config.extent[2],
y2: 30.04791233720099,//30.055000,//config.extent[3],
// layers: '00.24, 00.01, 01.01, 02.01, 03.01,04.01,05.01,06.01,07.01,08.01,09.01,10.01,11.01,12.01,13.01,14.01,15.01,16.01,17.01,18.01,19.01,20.01,21.01,22.01,23.01,24.01'
// layers:'00.24'
}).then(({ data }) => data)
.catch(() => null)
}
/**
* 时间轴,当前时间右侧的气象预报数据
* */
export const WeatherSetRightQx = new CachePromise(
async () => {
/**
*取当前系统时间
① 如果当前系统时间是0815之前的时间取前一天2000的数据
② 如果当前系统时间是0815之后的且是2000之前的取当天的0800
③ 如果当前系统时间是0815之后的且是2000之后的取当天的2000
这个grb/get接口报错或没返回值等就提示“没有对应的预报数据”
* */
let paramsTm = "";
let defalut1 = moment().format("YYYY-MM-DD 08:15");
let defalut2 = moment().format("YYYY-MM-DD 20:00");
let currentHM = moment().format("YYYY-MM-DD HH:mm");
if(moment(currentHM).isBefore(defalut1)){
paramsTm = moment().add(-1, 'day').format("YYYYMMDD20");
}else{
if(moment(currentHM).isBefore(defalut2)){
paramsTm = moment().format("YYYYMMDD08");
}else{
paramsTm = moment().format("YYYYMMDD20");
}
}
//console.log("paramsTm 63++++",paramsTm);
const latest = await ShqxYjhisGet(paramsTm);
if (!latest) {
return null;
}
//let lastH = latest.tm.substring(12,13);
let lastH = latest.tm.substring(11,13);
let currentH = moment().format("H");
let currentM = moment().format("m");
let currentTime = "";
if(currentM>15){
currentTime = currentH;
}else{
currentTime = Number(currentH) - 1;
}
//console.log("currentTime 58++++",currentTime);
//console.log("lastH 58++++",lastH);
//偏移量
let pylNum = Number(currentTime) - Number(lastH);
//console.log("pylNum 61++++",pylNum);
let layers = ' ';
for (let i = pylNum; i <= 24; i++) {
layers += (i>=10?String(i):"0"+String(i))+".01, ";
}
//console.log("layers 67++++",layers);
return httpget(apiurl.yjhis.weather, {
filename: latest.rainFile,//"Z_NWGD_C_BCWH_20230213170706_P_RFFC_SPCC-ER01_202302132000_02401.GRB2",//latest.rainFile,
x1: 108.62318959955861,//108.615000,//config.extent[0],
y1: 29.328651167767397,//29.315000,//config.extent[1],
x2: 109.33730092768361,//109.345000,//config.extent[2],
y2: 30.04791233720099,//30.055000,//config.extent[3],
layers: layers
}).then(({ data }) => {
return [...data]
})
.catch(() => null)
},
1000 * 60
);
//按时间获取天气预报24h
export const WeatherSetRightQx2 =async (myTm) => {
const paramsTm = myTm
//console.log("paramsTm 63++++",paramsTm);
const latest = await ShqxYjhisGet(paramsTm);
if (!latest) {
return null;
}
//let lastH = latest.tm.substring(12,13);
let lastH = latest.tm.substring(11,13);
let currentH = moment().format("H");
let currentM = moment().format("m");
let currentTime = "";
if(currentM>15){
currentTime = currentH;
}else{
currentTime = Number(currentH) - 1;
}
//console.log("currentTime 58++++",currentTime);
//console.log("lastH 58++++",lastH);
//偏移量
let pylNum = 0//Number(currentTime) - Number(lastH);
//console.log("pylNum 61++++",pylNum);
let layers = ' ';
for (let i = pylNum; i <= 24; i++) {
layers += (i>=10?String(i):"0"+String(i))+".01, ";
}
//console.log("layers 67++++",layers);
return httpget(apiurl.yjhis.weather, {
filename: latest.rainFile,//"Z_NWGD_C_BCWH_20230213170706_P_RFFC_SPCC-ER01_202302132000_02401.GRB2",//latest.rainFile,
x1: 108.62318959955861,//108.615000,//config.extent[0],
y1: 29.328651167767397,//29.315000,//config.extent[1],
x2: 109.33730092768361,//109.345000,//config.extent[2],
y2: 30.04791233720099,//30.055000,//config.extent[3],
layers: layers
}).then(({ data }) => {
return [...data]
})
.catch(() => null)
}
export const WeatherRadar = new CachePromise(
async () => {
const latest = await ShqxRadarhisLatest.get();
if (!latest) {
return null;
}
return httpget(apiurl.radarhis.weather, {
filename: latest.rainFile,
x1: config.extent[0],
y1: config.extent[1],
x2: config.extent[2],
y2: config.extent[3],
}).then(({ data }) => data)
.catch(() => null)
},
1000 * 60
);
export const WeatherRadar2 = async(tm) => {
const latest = await httpget('http://223.75.53.124:8005/radar/get', { tm })
if (!latest.data) {
return null;
}
return httpget('http://223.75.53.124:8005/res/radarlayer', {
filename: latest.data.rainFile,
}).then(({ data }) => data)
.catch(() => null)
}
export const ShqxYjhisLatest = new CachePromise(
() => httpget(`http://223.75.53.124:8005/grb/latest`, { adcd: localStorage.getItem('ADCD6') })
.then(({ data }) => {
data.intv = 24 * 60;
return data;
})
.catch(() => null),
5000
);
export const ShqxYjhisGet = (tm) => httpget(`http://223.75.53.124:8005/grb/get`, { tm })
.then(({ data }) => {
data.intv = 24 * 60;
return data;
}).catch(() => null)
export const ShqxYjhis2hGet = (tm) => httpget(`http://223.75.53.124:8005/radar/get`, { tm })
.then(({ data }) => {
data.intv = 24 * 60;
return data;
}).catch(() => null)
export const ShqxRadarhisLatest = new CachePromise(
() => httpget(apiurl.radarhis.latest, { adcd: localStorage.getItem('ADCD6') })
.then(({ data }) => {
data.intv = 2 * 60;
return data;
})
.catch(() => null),
5000
);
export const YjList =
(params) => httpget(apiurl.yjhis.find, {...params})
.then(({ data }) => data)
.catch(() => null);
//风险预警详情
export const fxyjDetails =
(params) => httpget(apiurl.yjhis.stat, {...params})
.then((data) => data)
.catch(() => null);