优化快手接单匹配
This commit is contained in:
@@ -201,6 +201,31 @@ export async function listKuaishouIndustryVouchersByOid(
|
||||
return result.rows
|
||||
}
|
||||
|
||||
export type KuaishouIndustryVoucherWorkOrderSyncSource = {
|
||||
oid: string
|
||||
raw_payload_json: string | Record<string, unknown>
|
||||
}
|
||||
|
||||
export async function listKuaishouIndustryVoucherWorkOrderSyncSources(
|
||||
limit = 100,
|
||||
): Promise<KuaishouIndustryVoucherWorkOrderSyncSource[]> {
|
||||
const result = await query<KuaishouIndustryVoucherWorkOrderSyncSource>(
|
||||
`
|
||||
SELECT oid, raw_payload_json
|
||||
FROM (
|
||||
SELECT DISTINCT ON (oid) oid, raw_payload_json, updated_at, id
|
||||
FROM kuaishou_industry_vouchers
|
||||
WHERE raw_payload_json ? 'body'
|
||||
ORDER BY oid, updated_at DESC, id DESC
|
||||
) AS latest_source
|
||||
ORDER BY updated_at DESC, id DESC
|
||||
LIMIT $1
|
||||
`,
|
||||
[normalizePositiveLimit(limit, 100)],
|
||||
)
|
||||
return result.rows
|
||||
}
|
||||
|
||||
export async function listKuaishouIndustryVouchersForSendCallbackRetry(
|
||||
limit = 100,
|
||||
maxAttempts = 8,
|
||||
|
||||
@@ -209,3 +209,19 @@ export async function getOrderItemById(orderItemId: number | string): Promise<Or
|
||||
])
|
||||
return result.rows[0] || null
|
||||
}
|
||||
|
||||
export async function updateOrderItemSourceSnapshot(
|
||||
orderItemId: number | string,
|
||||
input: { skuName: string; itemSnapshotJson: string; updatedAt: string },
|
||||
): Promise<OrderItemRow | null> {
|
||||
const result = await query<{ id: number }>(
|
||||
`
|
||||
UPDATE order_items
|
||||
SET sku_name = $1, item_snapshot_json = $2::jsonb, updated_at = $3
|
||||
WHERE id = $4
|
||||
RETURNING id
|
||||
`,
|
||||
[input.skuName, input.itemSnapshotJson, input.updatedAt, Number(orderItemId)],
|
||||
)
|
||||
return result.rows[0] ? getOrderItemById(orderItemId) : null
|
||||
}
|
||||
|
||||
@@ -153,6 +153,7 @@ export type WorkProductRuleRow = {
|
||||
timeout_minutes: number
|
||||
timeout_policy: string
|
||||
requirement_json: string | Record<string, unknown>
|
||||
match_json: string | Record<string, unknown>
|
||||
sort_order: number
|
||||
created_at: string
|
||||
updated_at: string
|
||||
|
||||
@@ -711,6 +711,7 @@ export async function upsertWorkProductRule(input: {
|
||||
timeoutMinutes?: number
|
||||
timeoutPolicy?: string
|
||||
requirementJson: string
|
||||
matchJson?: string
|
||||
sortOrder: number
|
||||
now: string
|
||||
}): Promise<WorkProductRuleRow | null> {
|
||||
@@ -723,7 +724,7 @@ export async function upsertWorkProductRule(input: {
|
||||
required_deposit_amount, deposit_threshold_amount,
|
||||
sharing_enabled, sharing_total_quantity, sharing_unit_reward,
|
||||
timeout_minutes, timeout_policy,
|
||||
requirement_json,
|
||||
requirement_json, match_json,
|
||||
sort_order, created_at, updated_at
|
||||
) VALUES (
|
||||
$1, $2, $3, $4, $5, $6,
|
||||
@@ -732,8 +733,8 @@ export async function upsertWorkProductRule(input: {
|
||||
$13, $14,
|
||||
$15, $16, $17,
|
||||
$18, $19,
|
||||
$20::jsonb,
|
||||
$21, $22, $23
|
||||
$20::jsonb, $21::jsonb,
|
||||
$22, $23, $24
|
||||
)
|
||||
ON CONFLICT (rule_key) DO UPDATE
|
||||
SET
|
||||
@@ -756,6 +757,7 @@ export async function upsertWorkProductRule(input: {
|
||||
timeout_minutes = EXCLUDED.timeout_minutes,
|
||||
timeout_policy = EXCLUDED.timeout_policy,
|
||||
requirement_json = EXCLUDED.requirement_json,
|
||||
match_json = EXCLUDED.match_json,
|
||||
sort_order = EXCLUDED.sort_order,
|
||||
updated_at = EXCLUDED.updated_at
|
||||
RETURNING *
|
||||
@@ -781,6 +783,7 @@ export async function upsertWorkProductRule(input: {
|
||||
toPositiveInteger(input.timeoutMinutes, 0),
|
||||
String(input.timeoutPolicy || 'reopen').trim(),
|
||||
input.requirementJson,
|
||||
input.matchJson || '{}',
|
||||
input.sortOrder,
|
||||
input.now,
|
||||
input.now,
|
||||
|
||||
Reference in New Issue
Block a user