酒店
This commit is contained in:
1 parent
9a4a3f31e9
commit
0548ec93f0
2 files changed
+36
-11
No files matched your search
@@ -156,9 +156,9 @@ export const getHotelZaxSyncCursor = () => {
|
||||
return request.get({ url: '/product/hotel-zax/sync-cursor' })
|
||||
}
|
||||
|
||||
/** full=true:按当前资安心授权范围全量拉(改授权后必须全量,否则增量水位会显示 0) */
|
||||
/** full=true:按当前资安心授权范围异步全量拉(立刻返回;改授权后必须全量;进度看 sync-cursor) */
|
||||
export const syncHotelZax = (full = true) => {
|
||||
return request.post({ url: '/product/hotel-zax/sync', params: { full } })
|
||||
return request.post({ url: '/product/hotel-zax/sync', params: { full }, timeout: 30000 })
|
||||
}
|
||||
|
||||
export const resetHotelZaxCursor = () => {
|
||||
|
||||
@@ -225,10 +225,25 @@ const onChanged = async () => {
|
||||
await getList()
|
||||
}
|
||||
|
||||
const isSyncRunningMsg = (msg?: string) => String(msg || '').startsWith('running,')
|
||||
|
||||
/** 提交后轮询水位,直到 running 结束或超时 */
|
||||
const pollSyncCursorUntilDone = async (maxMs = 30 * 60 * 1000) => {
|
||||
const started = Date.now()
|
||||
while (Date.now() - started < maxMs) {
|
||||
await loadCursor()
|
||||
if (!isSyncRunningMsg(cursor.value?.lastMsg)) {
|
||||
return true
|
||||
}
|
||||
await new Promise((r) => setTimeout(r, 2000))
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
const handleSync = async () => {
|
||||
try {
|
||||
await message.confirm(
|
||||
'将按资安心当前授权范围全量同步到本地(改授权后也请用此按钮)。供应方已上架的会恢复为上架;不在授权内的本地酒店会标为未授权。确认继续?'
|
||||
'将按资安心当前授权范围后台全量同步(改授权后也请用此按钮)。界面立刻返回,进度看「上次结果」;数据量大时可能较久。确认继续?'
|
||||
)
|
||||
} catch {
|
||||
return
|
||||
@@ -236,14 +251,24 @@ const handleSync = async () => {
|
||||
syncing.value = true
|
||||
try {
|
||||
const res = await HotelZaxApi.syncHotelZax(true)
|
||||
const offline = res?.offlineOutOfScope ?? 0
|
||||
const dailyFail = res?.dailyFail ?? 0
|
||||
message.success(
|
||||
`同步完成:写入 ${res?.upsert ?? 0},详情 ${res?.detailOk ?? 0},日历 ${res?.dailyRows ?? 0} 条` +
|
||||
(dailyFail > 0 ? `,日历失败 ${dailyFail} 家` : '') +
|
||||
(offline > 0 ? `,下架授权外 ${offline}` : '')
|
||||
)
|
||||
await onChanged()
|
||||
if (res?.accepted === false || res?.running) {
|
||||
message.warning(res?.message || '已有同步任务在执行,请稍后刷新水位')
|
||||
await loadCursor()
|
||||
return
|
||||
}
|
||||
message.success(res?.message || '已提交后台同步,正在拉取…')
|
||||
const done = await pollSyncCursorUntilDone()
|
||||
await getList()
|
||||
if (!done) {
|
||||
message.warning('同步仍在进行,可稍后刷新页面查看「上次结果」')
|
||||
return
|
||||
}
|
||||
const msg = cursor.value?.lastMsg || ''
|
||||
if (String(msg).startsWith('fail,')) {
|
||||
message.error(`同步失败:${msg}`)
|
||||
} else {
|
||||
message.success(`同步完成:${msg || '请查看水位'}`)
|
||||
}
|
||||
} catch (e: any) {
|
||||
message.error(e?.msg || e?.message || '同步失败')
|
||||
} finally {
|
||||
|
||||
Reference in new issue
Block a user