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

175 lines
4.3 KiB
JavaScript
Raw Normal View History

2025-05-19 14:26:18 +08:00
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 }) => data)
.catch(() => null),
5000
);
export const HDRealPromise = new CachePromise(
() => httpget(apiurl.real.rz, { layers: 'sh,sw' })
.then(({ data }) => data)
.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
);
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 }) => data)
.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)
);
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
);