yeg
2026-08-27 8bc9027e4614944c6d5ee4fa2d50d01ebb87f3e1
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
import { request, type ApiResponse } from './request'
import type { BatteryGroupPayload, GroupStatus } from './batteryGroupPayload'
 
export type { GroupStatus } from './batteryGroupPayload'
 
export interface BatteryGroupListParams {
  pageNum: number
  pageSize: number
  groupId?: number
  groupName?: string
  model?: string
  status?: string
  createBy?: string
  beginCreateTime?: string
  endCreateTime?: string
}
 
interface BatteryGroupBatteryDto {
  batteryNo: string | null
}
 
interface BatteryGroupTemplateFieldDto {
  templateId: number | null
  batteryGroupFieldId: number | null
  fieldName: string | null
  fieldType: string | null
}
 
interface BatteryGroupDto {
  groupId: number
  groupName: string | null
  model: string | null
  purpose: string | null
  status: string | null
  createBy: string | null
  createTime: string | null
  batteryCount: number | null
  remark?: string | null
  z?: string | null
  h?: string | null
  f?: string | null
  a?: string | null
  b?: string | null
  batteries?: BatteryGroupBatteryDto[] | null
  templateFields?: BatteryGroupTemplateFieldDto[] | null
}
 
interface BatteryGroupListResponse extends ApiResponse {
  total: number
  rows: BatteryGroupDto[]
}
 
export interface BatteryGroupListItem {
  id: number
  name: string
  model: string
  purpose: string
  batteryCount: number
  createdAt: string
  status: GroupStatus
  creator: string
}
 
export interface BatteryGroupListResult {
  total: number
  rows: BatteryGroupListItem[]
}
 
interface BatteryGroupCreatorResponse extends ApiResponse {
  data: BatteryGroupCreatorDto[]
}
 
interface BatteryGroupDetailResponse extends ApiResponse {
  data: BatteryGroupDto
}
 
interface BatteryGroupCreatorDto {
  userName: string | null
  nickName: string | null
}
 
export interface BatteryGroupCreatorOption {
  label: string
  value: string
}
 
export interface BatteryGroupTemplateField {
  templateId: number
  batteryGroupFieldId: number
  fieldName: string
  fieldType: string
}
 
export interface BatteryGroupDetail {
  id: number
  name: string
  model: string
  purpose: string
  remark: string
  status: GroupStatus
  creator: string
  specs: Record<'z' | 'h' | 'f' | 'a' | 'b', string>
  batteries: string[]
  templateFields: BatteryGroupTemplateField[]
}
 
function mapBatteryGroup(item: BatteryGroupDto): BatteryGroupListItem {
  return {
    id: item.groupId,
    name: item.groupName || '-',
    model: item.model || '-',
    purpose: item.purpose || '-',
    batteryCount: Number(item.batteryCount) || 0,
    createdAt: item.createTime || '-',
    status: item.status === '1' ? '禁用' : '启用',
    creator: item.createBy || '-',
  }
}
 
export async function getBatteryGroupList(params: BatteryGroupListParams): Promise<BatteryGroupListResult> {
  const searchParams = new URLSearchParams()
  Object.entries(params).forEach(([key, value]) => {
    if (value === undefined || value === '') return
    searchParams.set(key, String(value))
  })
 
  const result = await request<BatteryGroupListResponse>(`/system/batteryGroup/list?${searchParams.toString()}`)
  return {
    total: Number(result.total) || 0,
    rows: (result.rows || []).map(mapBatteryGroup),
  }
}
 
export async function getBatteryGroupCreatorOptions(): Promise<BatteryGroupCreatorOption[]> {
  const result = await request<BatteryGroupCreatorResponse>('/system/batteryGroup/creatorOptions')
  return (result.data || [])
    .map(item => {
      const value = item.userName?.trim() || ''
      const name = item.nickName?.trim() || value
      return { label: name === value ? name : `${name}(${value})`, value }
    })
    .filter(item => item.value)
}
 
export async function getBatteryGroupDetail(groupId: number): Promise<BatteryGroupDetail> {
  const result = await request<BatteryGroupDetailResponse>(`/system/batteryGroup/${groupId}`)
  const item = result.data
  return {
    id: item.groupId,
    name: item.groupName || '',
    model: item.model || '',
    purpose: item.purpose || '',
    remark: item.remark || '',
    status: item.status === '1' ? '禁用' : '启用',
    creator: item.createBy || '',
    specs: { z: item.z || '', h: item.h || '', f: item.f || '', a: item.a || '', b: item.b || '' },
    batteries: (item.batteries || []).map(battery => battery.batteryNo?.trim() || '').filter(Boolean),
    templateFields: (item.templateFields || [])
      .filter(field => field.templateId != null && field.batteryGroupFieldId != null)
      .map(field => ({
        templateId: Number(field.templateId),
        batteryGroupFieldId: Number(field.batteryGroupFieldId),
        fieldName: field.fieldName || '',
        fieldType: field.fieldType || '文本',
      })),
  }
}
 
export function createBatteryGroup(payload: BatteryGroupPayload): Promise<ApiResponse> {
  return request<ApiResponse>('/system/batteryGroup', {
    method: 'POST',
    body: JSON.stringify(payload),
  })
}
 
export function updateBatteryGroup(groupId: number, payload: BatteryGroupPayload): Promise<ApiResponse> {
  return request<ApiResponse>('/system/batteryGroup', {
    method: 'PUT',
    body: JSON.stringify({ groupId, ...payload }),
  })
}