87 lines
3.1 KiB
TypeScript
87 lines
3.1 KiB
TypeScript
import { ndmClient } from '@/apis/client';
|
|
import type { PageParams, NdmNvrPageQuery, PageResult, NdmNvrResultVO, NdmNvrUpdateVO, ClientChannel, NdmRecordCheck } from '@/apis/models';
|
|
import dayjs from 'dayjs';
|
|
|
|
export const postNdmNvrPage = async (stationCode: string, pageQuery: PageParams<NdmNvrPageQuery>, signal?: AbortSignal) => {
|
|
const prefix = stationCode ? `/${stationCode}` : '';
|
|
const resp = await ndmClient.post<PageResult<NdmNvrResultVO>>(`${prefix}/api/ndm/ndmNvr/page`, pageQuery, { signal });
|
|
const [err, ndmNvr] = resp;
|
|
if (err || !ndmNvr) {
|
|
throw err;
|
|
}
|
|
return ndmNvr;
|
|
};
|
|
|
|
export const getNdmNvrDetail = async (stationCode: string, id: string) => {
|
|
const prefix = stationCode ? `/${stationCode}` : '';
|
|
const resp = await ndmClient.get<NdmNvrResultVO>(`${prefix}/api/ndm/ndmNvr/detail`, { params: { id } });
|
|
const [err, ndmNvr] = resp;
|
|
if (err || !ndmNvr) {
|
|
throw err;
|
|
}
|
|
return ndmNvr;
|
|
};
|
|
|
|
export const putNdmNvr = async (stationCode: string, updateVO: NdmNvrUpdateVO) => {
|
|
const prefix = stationCode ? `/${stationCode}` : '';
|
|
const resp = await ndmClient.put<NdmNvrResultVO>(`${prefix}/api/ndm/ndmNvr`, updateVO);
|
|
const [err, ndmNvr] = resp;
|
|
if (err || !ndmNvr) {
|
|
throw err;
|
|
}
|
|
return await getNdmNvrDetail(stationCode, ndmNvr.id ?? '');
|
|
};
|
|
|
|
export const getChannelList = async (stationCode: string, ndmNvr: NdmNvrResultVO) => {
|
|
const prefix = stationCode ? `/${stationCode}` : '';
|
|
const resp = await ndmClient.post<ClientChannel[]>(`${prefix}/api/ndm/ndmRecordCheck/getChannelList`, {
|
|
code: ndmNvr.gbCode,
|
|
time: '',
|
|
});
|
|
const [err, channelList] = resp;
|
|
if (err || !channelList) {
|
|
throw err;
|
|
}
|
|
return channelList;
|
|
};
|
|
|
|
export const getRecordCheckByParentId = async (stationCode: string, ndmNvr: NdmNvrResultVO, lastDays: number, gbCodeList: string[] = []) => {
|
|
const prefix = stationCode ? `/${stationCode}` : '';
|
|
const endDateTime = dayjs();
|
|
const startDateTime = endDateTime.subtract(lastDays, 'day');
|
|
const resp = await ndmClient.post<NdmRecordCheck[]>(`${prefix}/api/ndm/ndmRecordCheck/getRecordCheckByParentId`, {
|
|
start: startDateTime.format('YYYY-MM-DD'),
|
|
end: endDateTime.format('YYYY-MM-DD'),
|
|
parentId: ndmNvr.gbCode,
|
|
gbCodeList,
|
|
});
|
|
const [err, recordCheckList] = resp;
|
|
if (err || !recordCheckList) {
|
|
throw err;
|
|
}
|
|
return recordCheckList;
|
|
};
|
|
|
|
export const reloadRecordCheckByGbId = async (stationCode: string, channel: ClientChannel, dayOffset: number) => {
|
|
const prefix = stationCode ? `/${stationCode}` : '';
|
|
const resp = await ndmClient.post<boolean>(`${prefix}/api/ndm/ndmRecordCheck/reloadRecordCheckByGbId`, {
|
|
...channel,
|
|
dayOffset,
|
|
});
|
|
const [err, result] = resp;
|
|
if (err || !result) {
|
|
throw err;
|
|
}
|
|
return result;
|
|
};
|
|
|
|
export const reloadAllRecordCheck = async (stationCode: string, dayOffset: number) => {
|
|
const prefix = stationCode ? `/${stationCode}` : '';
|
|
const resp = await ndmClient.post<boolean>(`${prefix}/api/ndm/ndmRecordCheck/reloadAllRecordCheck`, dayOffset);
|
|
const [err, result] = resp;
|
|
if (err || !result) {
|
|
throw err;
|
|
}
|
|
return result;
|
|
};
|