Commit 5e90b8f3d7f583818d14981a62c921ec99412ff7
1 parent
628891b0
1
Showing
1 changed file
with
46 additions
and
7 deletions
美国版/Food Labeling Management Platform/src/services/teamMemberService.ts
| 1 | -import { createApiClient } from "../lib/apiClient"; | |
| 1 | +import { ApiError, createApiClient } from "../lib/apiClient"; | |
| 2 | 2 | import { authorizedGetBlobDownload, authorizedPostMultipartJson } from "../lib/batchFileHttp"; |
| 3 | 3 | import type { |
| 4 | 4 | PagedResultDto, |
| ... | ... | @@ -308,14 +308,53 @@ export async function importTeamMembersBatch(file: File, signal?: AbortSignal): |
| 308 | 308 | }); |
| 309 | 309 | } |
| 310 | 310 | |
| 311 | +function bulkItemToUpdateInput(item: TeamMemberBulkUpdateItemVo): TeamMemberUpdateInput { | |
| 312 | + const phoneStr = item.phone == null ? null : String(item.phone).trim() || null; | |
| 313 | + const input: TeamMemberUpdateInput = { | |
| 314 | + fullName: item.fullName, | |
| 315 | + userName: item.userName, | |
| 316 | + email: item.email ?? null, | |
| 317 | + phone: phoneStr, | |
| 318 | + roleId: item.roleId, | |
| 319 | + locationIds: item.locationIds ?? [], | |
| 320 | + state: item.state, | |
| 321 | + }; | |
| 322 | + if (item.password && String(item.password).trim()) { | |
| 323 | + input.password = item.password; | |
| 324 | + } | |
| 325 | + return input; | |
| 326 | +} | |
| 327 | + | |
| 328 | +// 部分环境 bulk 路径与 `PUT /team-member/{id}` 冲突;不改后端时改为逐条 PUT。 | |
| 311 | 329 | export async function updateTeamMembersBulk( |
| 312 | 330 | body: { items: TeamMemberBulkUpdateItemVo[] }, |
| 313 | 331 | ): Promise<TeamMemberBulkUpdateResultDto> { |
| 314 | - // ABP 约定控制器:`Update*Async` 多为 PUT,POST 会 405 | |
| 315 | - return api.requestJson<TeamMemberBulkUpdateResultDto>({ | |
| 316 | - path: `${PATH}/update-team-members-bulk`, | |
| 317 | - method: "PUT", | |
| 318 | - body, | |
| 319 | - }); | |
| 332 | + const ZERO = "00000000-0000-0000-0000-000000000000"; | |
| 333 | + const errors: NonNullable<TeamMemberBulkUpdateResultDto["errors"]> = []; | |
| 334 | + let successCount = 0; | |
| 335 | + let failCount = 0; | |
| 336 | + | |
| 337 | + for (let i = 0; i < body.items.length; i += 1) { | |
| 338 | + const item = body.items[i]; | |
| 339 | + const rowNumber = i + 1; | |
| 340 | + const id = (item.id ?? "").trim(); | |
| 341 | + if (!id || id.toLowerCase() === ZERO) continue; | |
| 342 | + | |
| 343 | + try { | |
| 344 | + await updateTeamMember(id, bulkItemToUpdateInput(item)); | |
| 345 | + successCount += 1; | |
| 346 | + } catch (e) { | |
| 347 | + failCount += 1; | |
| 348 | + const message = | |
| 349 | + e instanceof ApiError ? e.message : e instanceof Error ? e.message : "Update failed."; | |
| 350 | + errors.push({ rowNumber, id, message }); | |
| 351 | + } | |
| 352 | + } | |
| 353 | + | |
| 354 | + return { | |
| 355 | + successCount, | |
| 356 | + failCount, | |
| 357 | + errors: errors.length ? errors : undefined, | |
| 358 | + }; | |
| 320 | 359 | } |
| 321 | 360 | ... | ... |