statistics.ts 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import axiosInstance from '../../utils/axios';
  2. export interface StatisticsQuery {
  3. startTime?: Date | string;
  4. endTime?: Date | string;
  5. type?: string;
  6. [key: string]: any;
  7. }
  8. /** 按物资柜的开关/异常等统计(行数据) */
  9. export type CabinetStatRow = {
  10. cabinetName?: string;
  11. openCount?: number;
  12. misplaceCount?: number;
  13. openTimeoutCount?: number;
  14. [key: string]: any;
  15. };
  16. /** 按物资类型的借还/均摊时长等 */
  17. export type MaterialsLoanStatRow = {
  18. materialsTypeName?: string;
  19. allCount?: number;
  20. returnCount?: number;
  21. timeoutCount?: number;
  22. averageTime?: number;
  23. [key: string]: any;
  24. };
  25. /** 特殊状态物资、更换统计等(按类型) */
  26. export type MaterialsTypeCountRow = {
  27. materialsTypeName?: string;
  28. willExpireCount?: number;
  29. expiredCount?: number;
  30. badCount?: number;
  31. allCount?: number;
  32. expireCount?: number;
  33. [key: string]: any;
  34. };
  35. /** 每日借还 */
  36. export type DayLoanStatRow = {
  37. day?: string;
  38. date?: string;
  39. allCount?: number;
  40. returnCount?: number;
  41. timeoutCount?: number;
  42. [key: string]: any;
  43. };
  44. export const materialStatisticsApi = {
  45. getMaterialInventory: (type: string) =>
  46. axiosInstance.get('/iscs/statistics-api/getMaterialInventory', { params: { type } }),
  47. getInventorySum: () => axiosInstance.get('/iscs/statistics-api/getInventorySum'),
  48. exportMaterialInventory: () =>
  49. axiosInstance.post('/iscs/statistics-api/exportMaterialInventory', undefined, {
  50. responseType: 'blob',
  51. }),
  52. exportBaseData: (params: Record<string, any>) =>
  53. axiosInstance.post('/iscs/statistics-api/exportBaseData', params, { responseType: 'blob' }),
  54. exportClaimAndReturn: (params: Record<string, any>) =>
  55. axiosInstance.post('/iscs/statistics-api/exportClaimAndReturn', params, { responseType: 'blob' }),
  56. getCabinetStatistics: (params: StatisticsQuery) =>
  57. axiosInstance.get<CabinetStatRow[] | unknown>('/iscs/statistics-api/getCabinetStatistics', { params }),
  58. getMaterialsLoanStatistics: (params: StatisticsQuery) =>
  59. axiosInstance.get<MaterialsLoanStatRow[] | unknown>('/iscs/statistics-api/getMaterialsLoanStatistics', {
  60. params,
  61. }),
  62. getMaterialsStatusStatistics: (params: StatisticsQuery) =>
  63. axiosInstance.get<MaterialsTypeCountRow[] | unknown>('/iscs/statistics-api/getMaterialsStatusStatistics', {
  64. params,
  65. }),
  66. getMaterialsChangeStatistics: (params: StatisticsQuery) =>
  67. axiosInstance.get<MaterialsTypeCountRow[] | unknown>('/iscs/statistics-api/getMaterialsChangeStatistics', {
  68. params,
  69. }),
  70. getDayLoanStatistics: (params: StatisticsQuery) =>
  71. axiosInstance.get<DayLoanStatRow[] | unknown>('/iscs/statistics-api/getDayLoanStatistics', { params }),
  72. getHomePage: (params: StatisticsQuery) =>
  73. axiosInstance.get('/iscs/statistics-api/getHomePage', { params }),
  74. };
  75. export function toStatArray<T>(res: T[] | { list?: T[]; records?: T[] } | null | undefined): T[] {
  76. if (res == null) return [];
  77. if (Array.isArray(res)) return res;
  78. if (Array.isArray((res as { list?: T[] }).list)) return (res as { list: T[] }).list;
  79. if (Array.isArray((res as { records?: T[] }).records)) return (res as { records: T[] }).records;
  80. return [];
  81. }