1
This commit is contained in:
parent
4db690ea50
commit
57dd323679
@ -237,17 +237,46 @@ export type PendingOrderSyncOrderIdsParams = {
|
||||
id?: number | string;
|
||||
};
|
||||
|
||||
/** syncOrderIds 响应:SN 管理订单(is_sn_mgmt=Y)会被拦截并标记失败,需改用单订单回传 */
|
||||
/** syncOrderIds 响应:异步模式,返回 request_id 供 syncOrderIdsProgress 轮询 */
|
||||
export type PendingOrderSyncOrderIdsResponse = {
|
||||
flag: string;
|
||||
code: number;
|
||||
message: string;
|
||||
request_id: string;
|
||||
warehouse_id: number;
|
||||
data?: {
|
||||
order_ids?: Array<number | string>;
|
||||
[key: string]: unknown;
|
||||
};
|
||||
};
|
||||
|
||||
/** syncOrderIdsProgress 查询参数 */
|
||||
export type PendingOrderSyncOrderIdsProgressParams = {
|
||||
request_id?: string;
|
||||
requestId?: string;
|
||||
};
|
||||
|
||||
/** syncOrderIdsProgress 进度响应 */
|
||||
export type PendingOrderSyncOrderIdsProgressResponse = {
|
||||
flag: string;
|
||||
code: number;
|
||||
message: string;
|
||||
request_id: string;
|
||||
status: 'submitted' | 'running' | 'success' | 'failed' | 'not_found';
|
||||
progress: number;
|
||||
total_count?: number;
|
||||
processed_count?: number;
|
||||
warehouse_id?: number;
|
||||
result?: {
|
||||
success_count?: number;
|
||||
failed_count?: number;
|
||||
dispatch_results?: Record<string, unknown>;
|
||||
[key: string]: unknown;
|
||||
};
|
||||
error?: string;
|
||||
update_time?: number;
|
||||
};
|
||||
|
||||
export function orderPendingOrderList(data: PendingOrderListParams = {}): Promise<any> {
|
||||
return request({
|
||||
url: "/system",
|
||||
@ -402,6 +431,22 @@ export function orderPendingOrderSyncOrderIds(
|
||||
} as any);
|
||||
}
|
||||
|
||||
export function orderPendingOrderSyncOrderIdsProgress(
|
||||
data: PendingOrderSyncOrderIdsProgressParams,
|
||||
): Promise<PendingOrderSyncOrderIdsProgressResponse & { code?: number; message?: string; flag?: string }> {
|
||||
return request({
|
||||
url: "/system",
|
||||
method: "post",
|
||||
params: {
|
||||
method: "order.pendingOrder.syncOrderIdsProgress",
|
||||
v,
|
||||
timestamp: Date.now(),
|
||||
},
|
||||
data,
|
||||
isSystemApi: true,
|
||||
} as any);
|
||||
}
|
||||
|
||||
export function orderPendingOrderUpdateOrderPlatform(
|
||||
data: PendingOrderUpdateOrderPlatformParams,
|
||||
): Promise<any> {
|
||||
@ -674,6 +719,7 @@ export type OrderPendingOrderApi = {
|
||||
allocateStorageProgress: typeof orderPendingOrderAllocateStorageProgress;
|
||||
cancelAllocateStorage: typeof orderPendingOrderCancelAllocateStorage;
|
||||
syncOrderIds: typeof orderPendingOrderSyncOrderIds;
|
||||
syncOrderIdsProgress: typeof orderPendingOrderSyncOrderIdsProgress;
|
||||
updateOrderPlatform: typeof orderPendingOrderUpdateOrderPlatform;
|
||||
updateOrderExpress: typeof orderPendingOrderUpdateOrderExpress;
|
||||
updateAddress: typeof orderPendingOrderUpdateAddress;
|
||||
@ -705,6 +751,7 @@ export const orderPendingOrder: OrderPendingOrderApi = {
|
||||
allocateStorageProgress: orderPendingOrderAllocateStorageProgress,
|
||||
cancelAllocateStorage: orderPendingOrderCancelAllocateStorage,
|
||||
syncOrderIds: orderPendingOrderSyncOrderIds,
|
||||
syncOrderIdsProgress: orderPendingOrderSyncOrderIdsProgress,
|
||||
updateOrderPlatform: orderPendingOrderUpdateOrderPlatform,
|
||||
updateOrderExpress: orderPendingOrderUpdateOrderExpress,
|
||||
updateAddress: orderPendingOrderUpdateAddress,
|
||||
|
||||
@ -275,6 +275,14 @@
|
||||
v-model="syncOrderIdsDialogVisible"
|
||||
:order-count="selectionRows.length"
|
||||
:loading="syncOrderIdsLoading"
|
||||
:request-id="syncOrderIdsRequestId"
|
||||
:task-status="syncOrderIdsTaskStatus"
|
||||
:progress-percent="syncOrderIdsProgressPercent"
|
||||
:total-count="syncOrderIdsTotalCount"
|
||||
:processed-count="syncOrderIdsProcessedCount"
|
||||
:success-count="syncOrderIdsSuccessCount"
|
||||
:failed-count="syncOrderIdsFailedCount"
|
||||
:message="syncOrderIdsMessage"
|
||||
@closed="resetSyncOrderIdsDialog"
|
||||
@submit="submitSyncOrderIds"
|
||||
/>
|
||||
@ -883,6 +891,14 @@ const {
|
||||
manualWaybillForm,
|
||||
syncOrderIdsDialogVisible,
|
||||
syncOrderIdsLoading,
|
||||
syncOrderIdsRequestId,
|
||||
syncOrderIdsTaskStatus,
|
||||
syncOrderIdsProgressPercent,
|
||||
syncOrderIdsTotalCount,
|
||||
syncOrderIdsProcessedCount,
|
||||
syncOrderIdsSuccessCount,
|
||||
syncOrderIdsFailedCount,
|
||||
syncOrderIdsMessage,
|
||||
batchQuickRecheckDialogVisible,
|
||||
batchQuickRecheckSuggestedIds,
|
||||
batchQuickRecheckSelectedRows,
|
||||
|
||||
@ -7,35 +7,114 @@
|
||||
destroy-on-close
|
||||
@closed="emit('closed')"
|
||||
>
|
||||
<el-form label-width="120px" class="storage-allocate-form">
|
||||
<el-form label-width="120px" class="sync-order-ids-form">
|
||||
<el-form-item label="当前勾选订单">
|
||||
<span>{{ orderCount }} 条</span>
|
||||
</el-form-item>
|
||||
<!-- <el-alert
|
||||
type="warning"
|
||||
:closable="false"
|
||||
show-icon
|
||||
title="批量同步说明"
|
||||
description="服务端会按 create_channel 分组派发同步任务。若订单为 SN 管理(is_sn_mgmt=Y),该订单会被拦截并标记失败,不允许走批量回传,需改用单订单回传。"
|
||||
/> -->
|
||||
<template v-if="requestId">
|
||||
<el-form-item label="任务ID">
|
||||
<span>{{ requestId }}</span>
|
||||
</el-form-item>
|
||||
<el-form-item label="任务状态">
|
||||
<span>{{ progressStatusText }}</span>
|
||||
</el-form-item>
|
||||
<el-form-item label="处理进度">
|
||||
<div class="sync-order-ids-progress">
|
||||
<el-progress :percentage="normalizedProgressPercent" :status="progressBarStatus" :stroke-width="16" />
|
||||
<div class="sync-order-ids-progress__meta">
|
||||
<span>总数:{{ totalCount }}</span>
|
||||
<span>已处理:{{ processedCount }}</span>
|
||||
<span>成功:{{ successCount }}</span>
|
||||
<span>失败:{{ failedCount }}</span>
|
||||
</div>
|
||||
<div v-if="message" class="sync-order-ids-progress__message">{{ message }}</div>
|
||||
</div>
|
||||
</el-form-item>
|
||||
</template>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="visible = false">取消</el-button>
|
||||
<el-button type="primary" :loading="loading" @click="emit('submit')">确认同步</el-button>
|
||||
<el-button :disabled="loading && !!requestId" @click="visible = false">取消</el-button>
|
||||
<el-button type="primary" :loading="loading" @click="emit('submit')">
|
||||
{{ requestId ? '处理中' : '确认同步' }}
|
||||
</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
|
||||
const visible = defineModel<boolean>({ default: false })
|
||||
|
||||
defineProps<{
|
||||
const props = defineProps<{
|
||||
orderCount: number
|
||||
loading: boolean
|
||||
requestId?: string
|
||||
taskStatus?: string
|
||||
progressPercent?: number
|
||||
totalCount?: number
|
||||
processedCount?: number
|
||||
successCount?: number
|
||||
failedCount?: number
|
||||
message?: string
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'submit'): void
|
||||
(e: 'closed'): void
|
||||
}>()
|
||||
|
||||
const normalizedProgressPercent = computed(() => {
|
||||
const value = Number(props.progressPercent || 0)
|
||||
if (!Number.isFinite(value)) return 0
|
||||
return Math.max(0, Math.min(100, value))
|
||||
})
|
||||
|
||||
const progressStatusText = computed(() => {
|
||||
const map: Record<string, string> = {
|
||||
submitted: '已受理',
|
||||
running: '进行中',
|
||||
processing: '进行中',
|
||||
pending: '等待处理',
|
||||
success: '已完成',
|
||||
finished: '已完成',
|
||||
fin: '已完成',
|
||||
failed: '失败',
|
||||
error: '失败',
|
||||
exception: '异常',
|
||||
timeout: '超时',
|
||||
not_found: '未找到'
|
||||
}
|
||||
const key = String(props.taskStatus || '').trim().toLowerCase()
|
||||
return map[key] || props.taskStatus || '—'
|
||||
})
|
||||
|
||||
const progressBarStatus = computed(() => {
|
||||
const key = String(props.taskStatus || '').trim().toLowerCase()
|
||||
if (['failed', 'error', 'exception', 'timeout', 'not_found'].includes(key)) return 'exception'
|
||||
if (['success', 'finished', 'fin'].includes(key) || normalizedProgressPercent.value >= 100) return 'success'
|
||||
return undefined
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.sync-order-ids-progress {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.sync-order-ids-progress__meta {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 12px;
|
||||
margin-top: 8px;
|
||||
color: #606266;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.sync-order-ids-progress__message {
|
||||
margin-top: 6px;
|
||||
color: #606266;
|
||||
font-size: 12px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
</style>
|
||||
|
||||
@ -240,6 +240,14 @@
|
||||
v-model="syncOrderIdsDialogVisible"
|
||||
:order-count="selectionRows.length"
|
||||
:loading="syncOrderIdsLoading"
|
||||
:request-id="syncOrderIdsRequestId"
|
||||
:task-status="syncOrderIdsTaskStatus"
|
||||
:progress-percent="syncOrderIdsProgressPercent"
|
||||
:total-count="syncOrderIdsTotalCount"
|
||||
:processed-count="syncOrderIdsProcessedCount"
|
||||
:success-count="syncOrderIdsSuccessCount"
|
||||
:failed-count="syncOrderIdsFailedCount"
|
||||
:message="syncOrderIdsMessage"
|
||||
@closed="resetSyncOrderIdsDialog"
|
||||
@submit="submitSyncOrderIds"
|
||||
/>
|
||||
@ -730,6 +738,14 @@ const {
|
||||
manualWaybillForm,
|
||||
syncOrderIdsDialogVisible,
|
||||
syncOrderIdsLoading,
|
||||
syncOrderIdsRequestId,
|
||||
syncOrderIdsTaskStatus,
|
||||
syncOrderIdsProgressPercent,
|
||||
syncOrderIdsTotalCount,
|
||||
syncOrderIdsProcessedCount,
|
||||
syncOrderIdsSuccessCount,
|
||||
syncOrderIdsFailedCount,
|
||||
syncOrderIdsMessage,
|
||||
batchQuickRecheckDialogVisible,
|
||||
batchQuickRecheckSuggestedIds,
|
||||
batchQuickRecheckSelectedRows,
|
||||
|
||||
@ -536,6 +536,14 @@ export function createPendingToolbarController(params: {
|
||||
|
||||
const syncOrderIdsDialogVisible = ref(false)
|
||||
const syncOrderIdsLoading = ref(false)
|
||||
const syncOrderIdsRequestId = ref('')
|
||||
const syncOrderIdsTaskStatus = ref('')
|
||||
const syncOrderIdsProgressPercent = ref(0)
|
||||
const syncOrderIdsTotalCount = ref(0)
|
||||
const syncOrderIdsProcessedCount = ref(0)
|
||||
const syncOrderIdsSuccessCount = ref(0)
|
||||
const syncOrderIdsFailedCount = ref(0)
|
||||
const syncOrderIdsMessage = ref('')
|
||||
|
||||
const batchQuickRecheckDialogVisible = ref(false)
|
||||
const batchQuickRecheckSuggestedIds = ref<number[]>([])
|
||||
@ -949,6 +957,14 @@ export function createPendingToolbarController(params: {
|
||||
ElMessage.warning('请先勾选需要同步的订单')
|
||||
return
|
||||
}
|
||||
syncOrderIdsRequestId.value = ''
|
||||
syncOrderIdsTaskStatus.value = ''
|
||||
syncOrderIdsProgressPercent.value = 0
|
||||
syncOrderIdsTotalCount.value = 0
|
||||
syncOrderIdsProcessedCount.value = 0
|
||||
syncOrderIdsSuccessCount.value = 0
|
||||
syncOrderIdsFailedCount.value = 0
|
||||
syncOrderIdsMessage.value = ''
|
||||
syncOrderIdsDialogVisible.value = true
|
||||
}
|
||||
|
||||
@ -998,8 +1014,63 @@ export function createPendingToolbarController(params: {
|
||||
ElMessage.error(res?.message || '同步订单ID失败')
|
||||
return
|
||||
}
|
||||
const count = Array.isArray(res?.data?.order_ids) ? res.data.order_ids.length : order_ids.length
|
||||
ElMessage.success((res?.message || '同步请求已受理') + `(${count} 条)`)
|
||||
|
||||
const acceptedPayload = getApiResponsePayload<{ request_id?: string }>(res)
|
||||
const requestId = String(acceptedPayload.request_id || res?.request_id || '').trim()
|
||||
if (!requestId) {
|
||||
// 无 request_id,视为同步完成
|
||||
const count = Array.isArray(res?.data?.order_ids) ? res.data.order_ids.length : order_ids.length
|
||||
ElMessage.success((res?.message || '同步请求已受理') + `(${count} 条)`)
|
||||
syncOrderIdsDialogVisible.value = false
|
||||
params.clearSelection()
|
||||
await params.loadData()
|
||||
return
|
||||
}
|
||||
|
||||
applySyncOrderIdsProgress({
|
||||
request_id: requestId,
|
||||
status: 'submitted',
|
||||
progress: 0,
|
||||
total_count: order_ids.length,
|
||||
processed_count: 0,
|
||||
message: res?.message || '同步任务已受理'
|
||||
}, requestId)
|
||||
|
||||
ElMessage.success((res?.message || '同步任务已受理') + `(任务ID: ${requestId})`)
|
||||
params.clearSelection()
|
||||
|
||||
const pollProgress = async () => {
|
||||
let latestPayload: Record<string, any> = {}
|
||||
for (let attempt = 0; attempt < 120; attempt += 1) {
|
||||
const progressRes = await params.pendingApi.syncOrderIdsProgress({ request_id: requestId })
|
||||
const progressOk = progressRes && (progressRes.code === 1 || progressRes.code === 200 || progressRes.flag === 'success')
|
||||
if (!progressOk) {
|
||||
throw new Error(progressRes?.message || '查询同步进度失败')
|
||||
}
|
||||
latestPayload = getApiResponsePayload(progressRes)
|
||||
applySyncOrderIdsProgress(latestPayload, requestId)
|
||||
const status = normalizeAsyncTaskStatus(latestPayload.status)
|
||||
if (isAsyncTaskSuccessStatus(status)) {
|
||||
return latestPayload
|
||||
}
|
||||
if (isAsyncTaskFailureStatus(status)) {
|
||||
throw new Error(String(latestPayload.error || latestPayload.message || '同步订单失败'))
|
||||
}
|
||||
await sleep(1500)
|
||||
}
|
||||
return latestPayload
|
||||
}
|
||||
|
||||
const progressPayload = await pollProgress()
|
||||
const successCount = Number(
|
||||
progressPayload.success_count
|
||||
?? progressPayload.result?.success_count
|
||||
?? order_ids.length
|
||||
) || order_ids.length
|
||||
const failedCount = Number(progressPayload.failed_count ?? progressPayload.result?.failed_count ?? 0) || 0
|
||||
const parts = [`同步完成 ${successCount} 条`]
|
||||
if (failedCount > 0) parts.push(`失败 ${failedCount} 条`)
|
||||
ElMessage.success(parts.join(','))
|
||||
syncOrderIdsDialogVisible.value = false
|
||||
await params.loadData()
|
||||
} catch {
|
||||
@ -1009,6 +1080,17 @@ export function createPendingToolbarController(params: {
|
||||
}
|
||||
}
|
||||
|
||||
function applySyncOrderIdsProgress(progress: Record<string, any>, fallbackRequestId = '') {
|
||||
syncOrderIdsRequestId.value = String(progress.request_id || fallbackRequestId || syncOrderIdsRequestId.value || '')
|
||||
syncOrderIdsTaskStatus.value = normalizeAsyncTaskStatus(progress.status)
|
||||
syncOrderIdsProgressPercent.value = Number(progress.progress ?? progress.progress_percent ?? syncOrderIdsProgressPercent.value ?? 0) || 0
|
||||
syncOrderIdsTotalCount.value = Number(progress.total_count ?? progress.result?.total_count ?? syncOrderIdsTotalCount.value ?? 0) || 0
|
||||
syncOrderIdsProcessedCount.value = Number(progress.processed_count ?? progress.result?.processed_count ?? syncOrderIdsProcessedCount.value ?? 0) || 0
|
||||
syncOrderIdsSuccessCount.value = Number(progress.success_count ?? progress.result?.success_count ?? syncOrderIdsSuccessCount.value ?? 0) || 0
|
||||
syncOrderIdsFailedCount.value = Number(progress.failed_count ?? progress.result?.failed_count ?? syncOrderIdsFailedCount.value ?? 0) || 0
|
||||
syncOrderIdsMessage.value = String(progress.error || progress.message || '')
|
||||
}
|
||||
|
||||
function openAllocateExpressDialog() {
|
||||
const rows = params.getSelectedRows()
|
||||
if (!rows.length) {
|
||||
@ -1086,7 +1168,16 @@ export function createPendingToolbarController(params: {
|
||||
cloneSourceOrderCode.value = ''
|
||||
}
|
||||
|
||||
function resetSyncOrderIdsDialog() {}
|
||||
function resetSyncOrderIdsDialog() {
|
||||
syncOrderIdsRequestId.value = ''
|
||||
syncOrderIdsTaskStatus.value = ''
|
||||
syncOrderIdsProgressPercent.value = 0
|
||||
syncOrderIdsTotalCount.value = 0
|
||||
syncOrderIdsProcessedCount.value = 0
|
||||
syncOrderIdsSuccessCount.value = 0
|
||||
syncOrderIdsFailedCount.value = 0
|
||||
syncOrderIdsMessage.value = ''
|
||||
}
|
||||
|
||||
function openUpdateAddressDialog() {
|
||||
const ids = params.getSelectedIds()
|
||||
@ -1295,6 +1386,14 @@ export function createPendingToolbarController(params: {
|
||||
manualWaybillForm,
|
||||
syncOrderIdsDialogVisible,
|
||||
syncOrderIdsLoading,
|
||||
syncOrderIdsRequestId,
|
||||
syncOrderIdsTaskStatus,
|
||||
syncOrderIdsProgressPercent,
|
||||
syncOrderIdsTotalCount,
|
||||
syncOrderIdsProcessedCount,
|
||||
syncOrderIdsSuccessCount,
|
||||
syncOrderIdsFailedCount,
|
||||
syncOrderIdsMessage,
|
||||
batchQuickRecheckDialogVisible,
|
||||
batchQuickRecheckSuggestedIds,
|
||||
batchQuickRecheckSelectedRows,
|
||||
|
||||
@ -156,6 +156,14 @@
|
||||
v-model="syncOrderIdsDialogVisible"
|
||||
:order-count="selectionRows.length"
|
||||
:loading="syncOrderIdsLoading"
|
||||
:request-id="syncOrderIdsRequestId"
|
||||
:task-status="syncOrderIdsTaskStatus"
|
||||
:progress-percent="syncOrderIdsProgressPercent"
|
||||
:total-count="syncOrderIdsTotalCount"
|
||||
:processed-count="syncOrderIdsProcessedCount"
|
||||
:success-count="syncOrderIdsSuccessCount"
|
||||
:failed-count="syncOrderIdsFailedCount"
|
||||
:message="syncOrderIdsMessage"
|
||||
@closed="resetSyncOrderIdsDialog"
|
||||
@submit="submitSyncOrderIds"
|
||||
/>
|
||||
@ -381,6 +389,14 @@ const {
|
||||
storageAllocateMessage,
|
||||
syncOrderIdsDialogVisible,
|
||||
syncOrderIdsLoading,
|
||||
syncOrderIdsRequestId,
|
||||
syncOrderIdsTaskStatus,
|
||||
syncOrderIdsProgressPercent,
|
||||
syncOrderIdsTotalCount,
|
||||
syncOrderIdsProcessedCount,
|
||||
syncOrderIdsSuccessCount,
|
||||
syncOrderIdsFailedCount,
|
||||
syncOrderIdsMessage,
|
||||
manualWaybillDialogVisible,
|
||||
manualWaybillLoading,
|
||||
manualWaybillOrderId,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user