You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
General-AI-Platform-Web/mock/businessState.ts

153 lines
4.3 KiB
TypeScript

/*
* @Author: donghao donghao@supervision.ltd
* @Date: 2024-05-08 14:21:42
* @LastEditors: donghao donghao@supervision.ltd
* @LastEditTime: 2024-05-10 15:17:08
* @FilePath: \general-ai-platform-web\mock\businessState.ts
* @Description: 服务器、设备状态
*/
import {
deviceListData,
deviceStateLogListData,
serverListData,
serverStateLogListData,
} from './pools/businessStateData';
import { successMockApiProps } from './typing';
import { fetchCurrPageByList } from './utils/apiMock';
export default {
// 服务器列表
'GET /api/business/serverState/list': async (req: Request, res: Response) => {
// get 使用 query 读取参数
const { pageNo, pageSize, status } = req.query;
let finalData = serverListData;
let { onlineCount, outlineCount } = serverListData.data;
if (status && ['1', '2'].includes(status)) {
onlineCount = 0;
outlineCount = 0;
let newArr = [];
serverListData.data.data.forEach((item) => {
if (status === item.state) {
newArr.push(item);
}
if (item.state === '1') {
onlineCount++;
} else {
outlineCount++;
}
});
finalData = {
...serverListData,
data: {
...serverListData.data,
onlineCount,
outlineCount,
data: newArr,
},
};
}
const resData: successMockApiProps = {
...fetchCurrPageByList({
...finalData,
data: { ...finalData.data, pageNo, pageSize: pageSize || 10 },
}),
};
res.json(resData);
},
// 服务器日志分页列表
'GET /api/business/serverState/logList': async (req: Request, res: Response) => {
// get 使用 query 读取参数
const { pageNo, pageSize } = req.query;
const resData: successMockApiProps = {
...fetchCurrPageByList({
...serverStateLogListData,
data: { ...serverStateLogListData.data, pageNo, pageSize: pageSize || 10 },
}),
};
res.json(resData);
},
// 设备列表
'GET /api/business/deviceState/list': async (req: Request, res: Response) => {
// get 使用 query 读取参数
const { pageNo, pageSize, status } = req.query;
let finalData = deviceListData;
let { onlineCount, outlineCount, processCount, errorCount } = deviceListData.data;
if (status && ['1', '2', '3', '4'].includes(status)) {
onlineCount = 0;
outlineCount = 0;
processCount = 0;
errorCount = 0;
let newArr = [];
deviceListData.data.data.forEach((item) => {
if (status === item.state) {
newArr.push(item);
}
switch (item.state) {
case '1':
onlineCount++;
break;
case '2':
outlineCount++;
break;
case '3':
processCount++;
break;
default:
errorCount++;
break;
}
});
finalData = {
...deviceListData,
data: {
...deviceListData.data,
onlineCount,
outlineCount,
processCount,
errorCount,
data: newArr,
},
};
}
const resData: successMockApiProps = {
...fetchCurrPageByList({
...finalData,
data: { ...finalData.data, pageNo, pageSize: pageSize || 10 },
}),
};
res.json(resData);
},
// 服务器日志分页列表
'GET /api/business/deviceState/logList': async (req: Request, res: Response) => {
// get 使用 query 读取参数
const { pageNo, pageSize } = req.query;
const resData: successMockApiProps = {
...fetchCurrPageByList({
...deviceStateLogListData,
data: { ...deviceStateLogListData.data, pageNo, pageSize: pageSize || 10 },
}),
};
res.json(resData);
},
// 未启用
// 企业详情
// 'GET /api/business/serverState/detail': async (req: Request, res: Response) => {
// // get 使用 query 读取参数
// const { id } = req.query;
// let finalData = {};
// serverListData.data.data.forEach((item) => {
// if (Number(item.id) === Number(id)) {
// finalData = item;
// // break;
// }
// });
// const resData: successMockApiProps = fetchMockSuccessFullByOther({
// data: finalData,
// });
// res.json(resData);
// },
};