mcfxkh-Web/src/models/_/real.js

231 lines
6.0 KiB
JavaScript

import config from '../../config';
import CachePromise from '../../utils/cachepromise';
import { httpget } from '../../utils/request';
import apiurl from '../apiurl';
import appconsts from '../appconsts';
export const TestDrpRealPromise = new CachePromise(
() => httpget('./data/drp.json')
.then(({ data }) => data)
.catch(() => null),
5000
);
export const DrpRealPromise = new CachePromise(
// () => httpget(apiurl.real.drp, { layers: 'sh,sw,sk,qx' })
// .then(({ data }) => {
// debugger
// return data
// })
// .catch(() => null),
// 5000
() => fetch(`${process.env.PUBLIC_URL}/data3/drpReal.json`)
.then((response) => response.json())
.then(data=>{
return data.filter(o=>o.state===1)
})
.catch(() => null),
5000
);
export const HDRealPromise = new CachePromise(
// () => httpget(apiurl.real.rz, { layers: 'sh,sw' })
// .then(({ data }) => data)
// .catch(() => null),
// 5000
() => fetch(`${process.env.PUBLIC_URL}/data3/hdReal.json`)
.then((response) => response.json())
.catch(() => null),
5000
);
export const HDGet = async (stcd) => {
const list = await HDRealPromise.get();
return list.find(o => o.stcd === stcd);
}
export const SkRealPromise = new CachePromise(
// () => httpget(apiurl.real.sk, { layers: 'sk' })
// .then(({ data }) => data || [])
// .then(data => data.map(o => ({ ...o, aRz: parseFloat((o.rz - o.fsltdz).toFixed(2)) })))
// .catch(() => null),
// 5000
() => fetch(`${process.env.PUBLIC_URL}/data3/skReal.json`)
.then((response) => response.json())
// .then(data=>data.map(o=>{
// return {...o,layer:'RealSkLayer',layerPop:'RealSkPop'}
// }))
.then(data => {
return data.map(o => ({ ...o, aRz: parseFloat((o.rz - o.fsltdz).toFixed(2)) }))
})
// .then(data=>{
// const list = data.map((item)=>{
// const obj = {...item}
// const num = item.lgtd.toString()||'0.000';
// const num2 = Number(num.slice(num.length-1,num.length))
// obj.h1 = item.h1+num2
// obj.h3 = item.h3+num2*1.2
// obj.h6 = item.h6+num2*1.5
// obj.h12 = item.h12+num2*1.6
// obj.h24 = item.h24+num2*1.8
// obj.h48 = item.h48+num2*1.9
// if(obj.w<=0.5){
// // c.push(obj)
// }
// return obj
// })
// return list
// })
// .then(data=>data.filter(o=>o.rzState===1))
.catch(() => null),
5000
);
export async function skRealGet(stcd) {
const { data } = await httpget(apiurl.real.skget, { stcd }) || {};
return data;
}
export async function drpRealGet({ type, stcd }) {
if (!type || !stcd) {
return null;
}
const { data } = await httpget(apiurl.real.drpget, { stcd, type }) || {};
return data;
}
export async function skPicGet(stcd) {
const { data } = await httpget(apiurl.real.skPicGet, { stcd }) || {};
return data;
}
export const OverallPromise = new CachePromise(
// () => httpget(apiurl.ex.bx)
// .then(({ data }) => {
// return data
// })
// .catch(() => null),
// 5000
() => fetch(`${process.env.PUBLIC_URL}/data3/overall.json`)
.then((response) => response.json())
.catch(() => null),
5000
);
export async function bxstr() {
const { data } = await httpget(apiurl.ex.bx, { mode: 'text' }) || {};
return data || '';
}
export async function yuwaiReal() {
const { data } = await httpget(`${apiurl.pubapi}/stmgr/getRelShSt?type=sh&adcd=${config.ADCD12}`) || {};
if (!data) {
return null;
}
if (!data.length) {
return [];
}
const sts = data.map(o => o.stcd).join(',');
const { data: drpList } = await httpget(`${apiurl.pubapi}/stmgr/pprealsts?type=sh&adcd=${config.ADCD12}&stcds=${sts}`) || {};
if (drpList?.length > 0) {
const drpMap = drpList.reduce((total, cur) => { total[cur.stcd] = cur; return total; }, {});
for (const st of data) {
const drpInfo = drpMap[st.stcd];
if (drpInfo) {
st.type = 'sh';
st.hasDrp = true;
st.drpTm = drpInfo.tm;
st.state = drpInfo.state;
st.today = drpInfo.today;
st.h1 = drpInfo.h1;
st.h3 = drpInfo.h3;
st.h6 = drpInfo.h6;
st.h12 = drpInfo.h12;
st.h24 = drpInfo.h24;
st.h48 = drpInfo.h48;
st.drpInfo = drpInfo;
}
}
}
const { data: rzList } = await httpget(`${apiurl.pubapi}/stmgr/zzrealsts?type=sh&adcd=${config.ADCD12}&stcds=${sts}`) || {};
if (rzList?.length > 0) {
const drpMap = rzList.reduce((total, cur) => { total[cur.stcd] = cur; return total; }, {});
for (const st of data) {
const rzInfo = drpMap[st.stcd];
if (rzInfo) {
st.type = 'sh';
st.hasRz = true;
st.rzTm = rzInfo.tm;
st.rzState = rzInfo.state;
st.rz = rzInfo.z;
st.q = rzInfo.q;
st.trend = rzInfo.trend;
st.rzInfo = rzInfo;
}
}
}
console.log(data)
return data;
}
export const YuwaiPromise = new CachePromise(yuwaiReal, 60 * 1000);
export const PicStPromise = new CachePromise(
() => httpget(apiurl.picst.list)
.then(({ data }) => data)
.catch(() => null)
// () => fetch(`${process.env.PUBLIC_URL}/data/overall.json`)
// .then((response) => response.json())
// .catch(() => null),
);
export const TestPicStPromise = new CachePromise(
() => httpget('./data/picst.json')
.then(({ data }) => data)
.catch(() => null)
);
export const getRealPic = async ({ adcd, stcd }) => {
const { obj } = await httpget(`${apiurl.pubapi_old}/shquery/tx/last`, {
adcd: adcd ? adcd.substr(0, 6) + '000000' : appconsts.ADCD12,
stcd,
debug: 0
}) || {};
if (!obj || !obj[0]) {
return null;
}
return obj[0];
}
//==================================================================
export const SkPicPromise = new CachePromise(
() => httpget(apiurl.xqjs.sktp)
.then(({ data }) => data)
.catch(() => null),
5000
);
export const RzRealPromise = new CachePromise(
() => httpget(apiurl.real.shrz)
.then(({ data }) => data)
.catch(() => null),
5000
);