feat: 迁移 Admin Repository 到 MySQL 8 (#79)

This commit is contained in:
chengma
2026-08-10 02:21:31 +08:00
parent 05793e48b3
commit 13cfced80d
29 changed files with 390 additions and 240 deletions
+23 -20
View File
@@ -29,10 +29,10 @@ func SaveSybSession(q Execer, username, cookiesJSON, expiresAt string) error {
_, err := q.Exec(`
INSERT INTO syb_session (username, cookies, expires_at, updated_at)
VALUES (?, ?, ?, ?)
ON CONFLICT(username) DO UPDATE SET
cookies = excluded.cookies,
expires_at = excluded.expires_at,
updated_at = excluded.updated_at`,
ON DUPLICATE KEY UPDATE
cookies = VALUES(cookies),
expires_at = VALUES(expires_at),
updated_at = VALUES(updated_at)`,
username, cookiesJSON, expiresAt, now)
if err != nil {
return fmt.Errorf("保存顺运宝会话缓存失败: %w", err)
@@ -103,9 +103,9 @@ func SetSybLastSyncedAt(q Execer, at string) error {
_, err := q.Exec(`
INSERT INTO syb_sync_state (id, last_synced_at, updated_at)
VALUES (1, ?, ?)
ON CONFLICT(id) DO UPDATE SET
last_synced_at = excluded.last_synced_at,
updated_at = excluded.updated_at`,
ON DUPLICATE KEY UPDATE
last_synced_at = VALUES(last_synced_at),
updated_at = VALUES(updated_at)`,
at, now)
if err != nil {
return fmt.Errorf("更新顺运宝同步进度失败: %w", err)
@@ -254,16 +254,16 @@ func UpsertSybOrder(q Execer, o model.SybOrder) (created bool, err error) {
(syb_id, order_no, title, product_spec, shopee_goods_id, shopee_sku_id,
quantity, price_twd_cent, image_url, syb_data, created_at, updated_at)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
ON CONFLICT(syb_id) DO UPDATE SET
order_no = excluded.order_no,
title = excluded.title,
product_spec = excluded.product_spec,
shopee_goods_id = excluded.shopee_goods_id,
quantity = excluded.quantity,
price_twd_cent = excluded.price_twd_cent,
image_url = excluded.image_url,
syb_data = excluded.syb_data,
updated_at = excluded.updated_at`,
ON DUPLICATE KEY UPDATE
order_no = VALUES(order_no),
title = VALUES(title),
product_spec = VALUES(product_spec),
shopee_goods_id = VALUES(shopee_goods_id),
quantity = VALUES(quantity),
price_twd_cent = VALUES(price_twd_cent),
image_url = VALUES(image_url),
syb_data = VALUES(syb_data),
updated_at = VALUES(updated_at)`,
// 注意:shopee_sku_id 只出现在 INSERT 的列清单里(新建行时写 o.ShopeeSKUID,
// 同步永远传空字符串),完全不出现在 DO UPDATE SET 里——已存在的行
// 这一列不受本语句影响,见上面的函数注释。
@@ -297,7 +297,7 @@ func sybOrderFilterClause(filter SybOrderFilter) (string, []any) {
var args []any
if kw := filter.Keyword; kw != "" {
like := "%" + escapeLike(kw) + "%"
clauses = append(clauses, `(so.order_no LIKE ? ESCAPE '\' OR so.title LIKE ? ESCAPE '\')`)
clauses = append(clauses, `(so.order_no LIKE ? ESCAPE '!' OR so.title LIKE ? ESCAPE '!')`)
args = append(args, like, like)
}
switch filter.Stage {
@@ -386,8 +386,11 @@ func ListSybOrderContexts(q Execer, filter SybOrderFilter, limit, offset int) ([
AND t.syb_id = so.syb_id
AND t.status IN ('pending', 'assigned', 'claimed'))` +
sybOrderContextFrom + where + `
ORDER BY so.updated_at DESC, so.syb_id DESC LIMIT ? OFFSET ?`
args = append(args, limit, offset)
ORDER BY so.updated_at DESC, so.syb_id DESC`
if limit >= 0 {
query += ` LIMIT ? OFFSET ?`
args = append(args, limit, offset)
}
rows, err := q.Query(query, args...)
if err != nil {
return nil, fmt.Errorf("查询顺运宝采购处理列表失败: %w", err)