feat(pdd-cookie): 持久化保存Cookie校验状态时间并在失效时发送内部告警通知
This commit is contained in:
@@ -12,7 +12,9 @@ import {
|
||||
savePddStore,
|
||||
deletePddStore,
|
||||
getPddStoreById,
|
||||
updatePddStoreCheckStatus,
|
||||
} from '../../../services/platforms/pdd/pdd-source-config-service.js'
|
||||
import { notifyPddCookieExpired } from '../../../services/notification/domain-notifications.js'
|
||||
import {
|
||||
syncAllPddStores,
|
||||
syncStoreOrders,
|
||||
@@ -120,17 +122,11 @@ router.post(
|
||||
|
||||
let cookie = String(body.cookie || '').trim()
|
||||
let userAgent = body.userAgent
|
||||
const existingStore = body.shopId ? getPddStoreById(body.shopId) : null
|
||||
|
||||
if (!cookie && body.shopId) {
|
||||
const store = getPddStoreById(body.shopId)
|
||||
if (!store) {
|
||||
throw createHttpError(`店铺不存在: ${body.shopId}`, {
|
||||
statusCode: 404,
|
||||
errorCode: 'pdd_store_not_found',
|
||||
})
|
||||
}
|
||||
cookie = store.cookie
|
||||
userAgent = userAgent || store.userAgent
|
||||
if (!cookie && existingStore) {
|
||||
cookie = existingStore.cookie
|
||||
userAgent = userAgent || existingStore.userAgent
|
||||
}
|
||||
|
||||
if (!cookie) {
|
||||
@@ -140,7 +136,29 @@ router.post(
|
||||
})
|
||||
}
|
||||
|
||||
return testPddCookie({ cookie, userAgent })
|
||||
const result = await testPddCookie({ cookie, userAgent })
|
||||
|
||||
// Persist check status and notify if invalid
|
||||
// 持久化测试状态并在失效时触发告警通知
|
||||
if (existingStore) {
|
||||
const now = new Date().toISOString()
|
||||
await updatePddStoreCheckStatus(existingStore.shopId, {
|
||||
cookieValid: result.valid,
|
||||
cookieCheckMessage: result.message,
|
||||
lastCheckedAt: now,
|
||||
totalOrders: result.totalOrders,
|
||||
})
|
||||
|
||||
if (!result.valid) {
|
||||
notifyPddCookieExpired({
|
||||
shopId: existingStore.shopId,
|
||||
shopName: existingStore.shopName,
|
||||
message: result.message,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
},
|
||||
{
|
||||
successMessage: 'Cookie 校验执行完成',
|
||||
|
||||
Reference in New Issue
Block a user