From 94ad66d32b80224dc61649e71231aa2bc8b912b9 Mon Sep 17 00:00:00 2001 From: mohammad sedighi Date: Wed, 22 Jul 2026 00:31:10 +0330 Subject: [PATCH] =?UTF-8?q?all=20customer=20from=20pargar=20fixing=20?= =?UTF-8?q?=DB=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/PargarCustomerSync.vue | 2 +- .../components/TahesabCustomerSync.vue | 2 +- src/store/customerImportStore.ts | 28 +++++++++++++------ 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/pages/menuPages/accounting/components/PargarCustomerSync.vue b/src/pages/menuPages/accounting/components/PargarCustomerSync.vue index 0311d8e..70c6e17 100644 --- a/src/pages/menuPages/accounting/components/PargarCustomerSync.vue +++ b/src/pages/menuPages/accounting/components/PargarCustomerSync.vue @@ -529,7 +529,7 @@ async function importAll() { importStore.expand() return } - await importStore.start(pending) + await importStore.start(pending, 'pargar') } // با پیشرفت عملیات سراسری، ردیف‌های وارد شده را همین‌جا هم تیک بزن diff --git a/src/pages/menuPages/accounting/components/TahesabCustomerSync.vue b/src/pages/menuPages/accounting/components/TahesabCustomerSync.vue index 88b35a1..6e39d88 100644 --- a/src/pages/menuPages/accounting/components/TahesabCustomerSync.vue +++ b/src/pages/menuPages/accounting/components/TahesabCustomerSync.vue @@ -526,7 +526,7 @@ async function importAll() { importStore.expand() return } - await importStore.start(pending) + await importStore.start(pending, 'tahesab') } // با پیشرفت عملیات سراسری، ردیف‌های وارد شده را همین‌جا هم تیک بزن diff --git a/src/store/customerImportStore.ts b/src/store/customerImportStore.ts index 5490463..502d6b6 100644 --- a/src/store/customerImportStore.ts +++ b/src/store/customerImportStore.ts @@ -1,6 +1,7 @@ import { ref, computed } from 'vue' import { defineStore } from 'pinia' import { importFromTahesab, type TahesabOnlyCustomer } from '@/api/tahesab' +import { importFromPargar, type PargarOnlyCustomer } from '@/api/pargar' export interface ImportError { code: number @@ -9,23 +10,27 @@ export interface ImportError { } export type ImportStatus = 'idle' | 'running' | 'done' | 'canceled' +export type ImportProvider = 'tahesab' | 'pargar' /** نتیجهٔ نهایی برای نمایش آیکن/متن مناسب */ export type ImportOutcome = 'running' | 'success' | 'error' | 'partial' | 'canceled' +type ImportCustomer = TahesabOnlyCustomer | PargarOnlyCustomer + /** تعداد مشتری در هر درخواست (برای جلوگیری از محدودیت نرخ سرور) */ const CHUNK_SIZE = 50 const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms)) /** - * فروشگاه سراسری برای فرایند «وارد کردن همه» مشتریان ته‌حساب. + * فروشگاه سراسری برای فرایند «وارد کردن همه» مشتریان حسابداری. * چون به‌صورت singleton است، با جابه‌جایی بین صفحات از بین نمی‌رود و * عملیات در پس‌زمینه ادامه پیدا می‌کند. */ export const useCustomerImportStore = defineStore('customerImport', () => { const status = ref('idle') - const queue = ref([]) + const provider = ref('tahesab') + const queue = ref([]) const total = ref(0) const processed = ref(0) const success = ref(0) @@ -56,6 +61,7 @@ export const useCustomerImportStore = defineStore('customerImport', () => { function reset() { status.value = 'idle' + provider.value = 'tahesab' queue.value = [] total.value = 0 processed.value = 0 @@ -86,10 +92,14 @@ export const useCustomerImportStore = defineStore('customerImport', () => { reset() } - async function start(customers: TahesabOnlyCustomer[]) { + async function start( + customers: ImportCustomer[], + importProvider: ImportProvider = 'tahesab', + ) { if (status.value === 'running') return if (!customers.length) return + provider.value = importProvider queue.value = customers.slice() total.value = customers.length processed.value = 0 @@ -105,10 +115,12 @@ export const useCustomerImportStore = defineStore('customerImport', () => { await runLoop() } - // ارسال یک دسته با تلاش مجدد در صورت خطا (مثلاً محدودیت نرخ موقتی) - async function importChunkWithRetry(chunk: TahesabOnlyCustomer[], attempt = 0): Promise { + async function importChunkWithRetry(chunk: ImportCustomer[], attempt = 0): Promise { try { - return await importFromTahesab(chunk) + if (provider.value === 'pargar') { + return await importFromPargar(chunk as PargarOnlyCustomer[]) + } + return await importFromTahesab(chunk as TahesabOnlyCustomer[]) } catch (e) { if (attempt < 2 && !cancelRequested) { await sleep(1500 * (attempt + 1)) @@ -140,23 +152,21 @@ export const useCustomerImportStore = defineStore('customerImport', () => { } } } catch (e) { - // کل دسته ناموفق شد (مثلاً محدودیت نرخ یا قطع ارتباط) for (const c of chunk) { failed.value++ errors.value.push({ code: c.code, name: c.name, error: 'خطا در ارتباط با سرور' }) } } processed.value += chunk.length - // مکث کوتاه بین دسته‌ها برای جلوگیری از محدودیت نرخ سرور if (processed.value < queue.value.length) await sleep(250) } status.value = 'done' - // پس از تکمیل محو نمی‌شود؛ تا زمانی که کاربر گزارش را ببندد باقی می‌ماند } return { status, + provider, queue, total, processed,