yeg
2026-08-26 9f48020dfd3e29d1c0049a3da9df3203c40bc264
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import type { TestTypeRecord, TestTypeStatus } from '@/stores/testTypes'
import { request, type ApiResponse } from './request'
 
export interface TestTypeListParams {
  pageNum: number
  pageSize: number
  testTypeId?: number
  testTypeName?: string
  beginCreateTime?: string
  endCreateTime?: string
  status?: string
}
 
interface TestTypeDto {
  testTypeId: number
  testTypeName: string | null
  status: string | null
  createBy: string | null
  createTime: string | null
  remark: string | null
}
 
interface TestTypeListResponse extends ApiResponse {
  total: number
  rows: TestTypeDto[]
}
 
interface TestTypeDetailResponse extends ApiResponse {
  data: TestTypeDto
}
 
export interface TestTypeListResult {
  total: number
  rows: TestTypeRecord[]
}
 
export interface TestTypePayload {
  testTypeName: string
  remark: string
}
 
const statusMap: Record<string, TestTypeStatus> = { '0': '启用', '1': '禁用' }
 
function mapTestType(item: TestTypeDto): TestTypeRecord {
  return {
    id: item.testTypeId,
    name: item.testTypeName || '-',
    createdAt: item.createTime || '',
    creator: item.createBy || '-',
    remark: item.remark || '',
    status: statusMap[item.status || ''] || '禁用',
  }
}
 
export async function getTestTypeList(params: TestTypeListParams): Promise<TestTypeListResult> {
  const searchParams = new URLSearchParams()
  Object.entries(params).forEach(([key, value]) => {
    if (value !== undefined && value !== '') searchParams.set(key, String(value))
  })
 
  const result = await request<TestTypeListResponse>(`/system/testType/list?${searchParams.toString()}`)
  return {
    total: Number(result.total) || 0,
    rows: (result.rows || []).map(mapTestType),
  }
}
 
export async function getTestType(testTypeId: number): Promise<TestTypeRecord> {
  const result = await request<TestTypeDetailResponse>(`/system/testType/${testTypeId}`)
  return mapTestType(result.data)
}
 
export function createTestType(payload: TestTypePayload): Promise<ApiResponse> {
  return request<ApiResponse>('/system/testType', {
    method: 'POST',
    body: JSON.stringify(payload),
  })
}
 
export function updateTestType(testTypeId: number, payload: TestTypePayload): Promise<ApiResponse> {
  return request<ApiResponse>('/system/testType', {
    method: 'PUT',
    body: JSON.stringify({ testTypeId, ...payload }),
  })
}
 
export async function changeTestTypeStatus(testTypeId: number, status: TestTypeStatus): Promise<void> {
  await request<ApiResponse>('/system/testType/changeStatus', {
    method: 'PUT',
    body: JSON.stringify({
      testTypeId,
      status: status === '启用' ? '0' : '1',
    }),
  })
}
 
export async function deleteTestTypes(testTypeIds: number | number[]): Promise<void> {
  const ids = Array.isArray(testTypeIds) ? testTypeIds : [testTypeIds]
  await request<ApiResponse>(`/system/testType/${ids.join(',')}`, {
    method: 'DELETE',
  })
}