Commit Graph
579 Commits
Author SHA1 Message Date
QiuSW 31ff045e8c docs(#352): mirror SYB source-date API contract 2026-09-30 10:00:19 +08:00
QiuSW b4186a9228 docs(#352): mirror SYB source-time rules and architecture 2026-09-30 09:58:14 +08:00
QiuSW f9c48a018a fix(#352): filter SYB products by source stock created time 2026-09-30 09:46:57 +08:00
QiuSW bf06b2d500 Merge #348: distinguish absent reveal swipe targets 2026-09-29 18:03:52 +08:00
QiuSW fcb7dad878 docs: record reveal swipe result policy and version boundary (#348) 2026-09-29 17:52:32 +08:00
QiuSW 6550b9fd45 fix(android): skip reveal swipe without a scroll target (#348) 2026-09-29 17:43:46 +08:00
QiuSW 7a2c2d1eac merge: SYB excluded-product marking and recompute (#340) 2026-09-29 16:32:35 +08:00
QiuSW d01540b9fd fix(web): label SYB sync filter counts as hits (#340) 2026-09-29 16:31:54 +08:00
QiuSWandClaude Opus 5.5 ec010b42fc docs: SYB excluded-product marking and recompute contract (#340)
Mirrors of Wiki revisions Architecture-and-Code-Map 4bf8482e,
Business-Rules-and-Glossary c0b1a842, SYB-ERP-Interface-Contract 5979a142,
Android-Agent-API-Contract 92e9f856: filter hits are stored and marked
(first creation only), PDD isolation, 无需采购 stage position, purchaseType
list filter, recompute preview/execute with fingerprint and 409, hit vs
markedCount wording. SYB-ERP page also restores #343's unified-session
paragraph (was only in the mirror) and corrects the structure rule to #286's
single `-#` all-characters rule.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NTDbDcwbDw1TSAcE6wfh2F
2026-09-29 16:21:47 +08:00
QiuSWandClaude Opus 5.5 a56df9d908 fix(syb): #340 phase 4 — fingerprint includes rule evidence + MySQL IT
1. recomputeFingerprint now hashes a JSON-serialized (not naive string-
   concatenated, to avoid delimiter-collision) sorted list of
   {id, direction, ruleId, ruleKind, ruleKeyword} per planned change — the
   rule kind/keyword are exactly what gets written into
   excluded_rule_kind/excluded_rule_keyword, so a plan that affects the
   same ids/directions via a since-edited rule must now be rejected as
   stale, not silently accepted. New tests:
   TestRecomputeFingerprintChangesWhenRuleEvidenceChanges (edits the rule
   row directly between preview and execute, since the API has no edit
   endpoint, and asserts RECOMPUTE_PREVIEW_STALE with nothing written and
   no log row) and TestRecomputeFingerprintStableAcrossUnchangedPreviews
   (two previews of the same data yield the same fingerprint and execute
   succeeds).

2. New server/app/goauto/sybproductfilter/recompute_mysql_integration_test.go,
   gated on GOAUTO_IT_MYSQL_DSN (t.Skip when unset, so `go test` is
   unaffected normally). It creates a uniquely named throwaway database
   (zz_goauto_it_340_<ts>), migrates it, and drops it in t.Cleanup — never
   touches an existing database. Two real-MySQL, two-connection scenarios
   reproduce the exact race the phase-3 fix closes: connection A takes its
   REPEATABLE-READ snapshot via the planning step, connection B takes the
   row's FOR UPDATE lock and holds it (confirmed via a channel) while A's
   write phase is proven to actually block on that same lock (asserted via
   a wait window), B then inserts a purchase_task / active return_match
   and commits, and A is asserted to unblock, see it, and skip the row.
   Verified locally against the dev MySQL server (this session never
   printed the password: read via a shell one-liner into an env var,
   exported only for the go test invocation): both tests PASS with the
   phase-3 fix in place. Temporarily reverted purchaseTaskLockedQuery to a
   plain (non-locking) read (not committed) and reran —
   TestRecomputeConcurrentPurchaseTaskUnderRealMySQL correctly FAILED
   ("expected A to skip the row ... got {PDDToExcluded:1 SkippedHasTask:0}"),
   proving the test is meaningful; restored and diffed byte-identical
   against a backup before rerunning to confirm both tests pass again.
   Confirmed via `SHOW DATABASES LIKE 'zz_goauto_it_%'` (empty) that every
   throwaway database, across all these runs, was actually dropped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NTDbDcwbDw1TSAcE6wfh2F
2026-09-29 16:05:06 +08:00
QiuSWandClaude Opus 5.5 cd4bd6acb1 fix(syb): #340 phase 3 review — recheck reads must be locking, not plain
writeRecomputeChanges' purchase_task/return_match rechecks (added in the
previous phase 3 commit) used plain SELECT COUNT(*). On MySQL 8.4 under
REPEATABLE-READ, a plain read inside a transaction reuses the snapshot
taken at that transaction's first read (recomputeChanges' own SELECT), so
a purchase_task or return_match row committed by another connection AFTER
that snapshot was invisible to the recheck even after the syb_product row's
FOR UPDATE lock was granted — the row lock only serializes writers against
each other, it doesn't force a later plain read to see newer committed
data. Confirmed against a real local MySQL 8.4 server with two connections:
after the other transaction committed a task, plain COUNT(*) returned 0
while COUNT(*) ... FOR SHARE correctly returned 1. Every existing test
passed anyway because this package's tests run on SQLite, which has no
multi-connection snapshot isolation to reproduce the race at all.

Fix: both rechecks now use clause.Locking{Strength: "SHARE"} (a locking/
"current" read is enough since they only need to observe committed rows,
not lock them further). Split the three per-row queries (row FOR UPDATE,
purchase_task FOR SHARE, return_match FOR SHARE) into small query-builder
helpers (sybProductRowLockQuery / purchaseTaskLockedQuery /
returnMatchLockedQuery) so writeRecomputeChanges consumes them and a test
can independently assert their generated SQL.

New test: TestRecheckQueriesUseLockingReads opens a DryRun gorm session
against the MySQL dialector (mysql.New with SkipInitializeWithVersion,
DisableAutomaticPing — no real network connection is ever made) and pins
the exact SQL shape via db.ToSQL:
  SELECT * FROM `syb_product` WHERE id = 1 FOR UPDATE
  SELECT count(*) FROM `purchase_task` WHERE syb_product_id = 1 FOR SHARE
  SELECT count(*) FROM `return_match` WHERE syb_product_id = 1
    AND active_syb_product_id IS NOT NULL FOR SHARE
The test's own comment documents why SQLite cannot reproduce this race
(gorm's SQLite driver drops clause.Locking entirely; SQLite also has no
multi-connection REPEATABLE-READ snapshot semantics to begin with).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NTDbDcwbDw1TSAcE6wfh2F
2026-09-29 15:43:37 +08:00
QiuSWandClaude Opus 5.5 baa20af530 fix(syb): #340 phase 3 — recompute race protection, fingerprint, wording
Merge origin/main (1e582cd, #350/#351 inner-code fixes) — no conflicts.

sybproductfilter/recompute.go:
1. Row-level protection in RecomputeExecute: the write phase is split out
   into writeRecomputeChanges(ctx, tx, planned), independently testable.
   For every planned change it takes the same clause.Locking{Strength:
   "UPDATE"} row lock purchase.Service.create and returnmatch's
   matchOneWithLock take, then re-checks under that lock: a purchase task
   or active return match that appeared after planning skips the row
   (counted), and a row already at its target mark is left alone. The
   execute response and audit log now report ACTUAL writes/skips
   (plan-time skips + write-time skips), not the initial plan.
2. Preview/execute binding: RecomputePreview returns a `fingerprint`
   (sha256 over the sorted id:direction:ruleId list). RecomputeExecute now
   requires it, recomputes the plan inside the same transaction and
   compares before writing; a mismatch returns RECOMPUTE_PREVIEW_STALE
   (HTTP 409, "数据或规则已变化,请重新预览后再执行") and writes nothing.
   Frontend passes the preview's fingerprint to execute and re-previews
   automatically on that error.
3. syb-product-filters List gains a per-rule `markedCount` (one grouped
   COUNT(*)...GROUP BY excluded_rule_id query, no N+1): the REAL current
   count of syb_product rows marked by that rule. The disable-structure-
   rule confirm dialog now quotes this instead of the stale lastHitCount
   sync snapshot; the 上次同步命中 column still shows lastHitCount.
4. recomputeChanges now selects only id/order_code/shopee_item_id/
   raw_json/pdd_purchase_excluded instead of full syb_product rows.

Wording (user-approved deviation from the prototype text):
- syb-sync-runs detail: 其中无需采购 N 条 -> 其中本次规则命中 N 条.
- syb-product-filters: 上次同步标记 reverted back to 上次同步命中 (both
  tables); the confirm-dialog text now cites markedCount, not lastHitCount.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NTDbDcwbDw1TSAcE6wfh2F
2026-09-29 15:34:20 +08:00
QiuSW f54ace7ccf Merge remote-tracking branch 'origin/main' into feat/340-syb-excluded-products 2026-09-29 15:25:46 +08:00
QiuSW 1e582cd868 merge: filter and freeze eligible inner-code apply selection (#351) 2026-09-29 15:00:04 +08:00
QiuSW d72d77ddf4 docs: bind mixed-selection apply confirmation rules (#351) 2026-09-29 14:59:57 +08:00
QiuSW ee8f80f987 fix: submit only frozen eligible inner-code apply selections (#351) 2026-09-29 14:57:23 +08:00
QiuSW 4959f3d17f merge: inner-code layout comparison regression fix (#350) 2026-09-29 14:15:12 +08:00
QiuSW 15d331bee9 fix: normalize layout controls in inner-code match evidence (#350) 2026-09-29 14:15:04 +08:00
QiuSW 897c1817d2 merge: restore inner-code matching and batch retry (#350) 2026-09-29 12:02:14 +08:00
QiuSW 5729ba048f docs: bind inner-code matching recovery contract #350 2026-09-29 11:49:32 +08:00
QiuSW 9c5e20e249 fix: recover inner-code matching and enable batch rematch #350 2026-09-29 11:45:46 +08:00
QiuSWandClaude Opus 5.5 8c95790135 feat(syb): #340 sync-run detail wording + excluded count (phase 2 cont.)
Rewords 结构过滤命中/关键词过滤命中 -> 结构过滤标记/关键词过滤标记 on the
sync-run detail (SYB 同步记录), and shows "其中无需采购 N 条" next to 商品明细,
computed client-side as charFilterSkipped + keywordFilterSkipped (exactly
the rows this run marked pdd_purchase_excluded) — no backend field needed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NTDbDcwbDw1TSAcE6wfh2F
2026-09-29 11:00:15 +08:00
QiuSWandClaude Opus 5.5 316d5aa412 feat(syb): #340 phase 2 — merge main, recompute samples, frontend UI
Merge origin/main (through #345/e7c049d) into feat/340-syb-excluded-products.
Resolved conflicts in sybimport/service.go, handler.go, service_test.go
(kept #342's createdFrom/createdTo AND #340's purchaseType, all combined
with processStage), and took origin/main's syb-products/index.vue as the
base for the new UI work below. Renamed the migration version file from
1789801100000 to 1789801500000 (next free slot after main's highest,
1789801400000) — content unchanged, version comes from the filename.

Backend: sybproductfilter recompute preview now also returns up to 20
sample rows (order code, shopee item id, change direction, matched rule)
alongside the existing counts; execute stays count + audit-log only.

Frontend (feat/340 issue "## 设计证据"/"## 页面", prototype v1):
- SYB 订单商品页: 采购类型 filter (需 PDD 采购 default / 无需 PDD 采购 / 全部),
  处理阶段 gains 无需采购 (pdd_excluded); selecting 退货待确认/已用退货/无需采购
  auto-switches 采购类型 to 全部; pdd_excluded rows are tickable only for
  匹配退货 (never collection/purchase/AI-match/image-search); rows show the
  stage tag plus 规则:<kind> <keyword>; detail drawer shows 采购类型 and rule.
- SYB 过滤规则页: 跳过导入 -> 标记为无需 PDD 采购 wording, 上次同步命中 ->
  上次同步标记, rewritten scope note, admin-only 按当前规则重算 button with
  preview dialog (4 counts + up to 20 samples) -> confirm -> execute.
- SYB 同步记录: 结构/关键词过滤命中 -> 结构/关键词过滤标记 (see #340 point 8;
  the run-level "其中无需采购 N 条" count is derivable client-side from the
  existing char/keyword counts, no backend field added).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NTDbDcwbDw1TSAcE6wfh2F
2026-09-29 10:59:12 +08:00
QiuSW e55645ff66 Merge remote-tracking branch 'origin/main' into feat/340-syb-excluded-products
# Conflicts:
#	server/app/goauto/sybimport/handler.go
#	server/app/goauto/sybimport/service.go
#	server/app/goauto/sybimport/service_test.go
#	web/src/views/goauto/syb-products/index.vue
2026-09-29 10:50:54 +08:00
QiuSW dd9160ec42 merge: batch cancel and use return matches (#347 #349) 2026-09-29 10:30:30 +08:00
QiuSW 14231c62a7 docs: record batch return use contract and verification #349 2026-09-29 10:24:54 +08:00
QiuSW 4280115e11 feat: batch use pending return matches #349 2026-09-29 10:21:28 +08:00
QiuSW a4c7b5e97b feat: add pending return match batch cancellation #347 2026-09-29 09:40:16 +08:00
QiuSW e7c049dbd6 merge: Yeeke reshipped return sync (#345) 2026-09-28 16:33:05 +08:00
QiuSW 3b95d4e879 feat(yeeke): sync reshipped returns and exclude new matching (#345) 2026-09-28 16:30:37 +08:00
QiuSW bce4897390 merge: serve Admin SPA at / and document nginx deployment (#346) 2026-09-28 16:16:20 +08:00
QiuSWandClaude Opus 5.5 c13dcd3ebc docs: record nginx 9527 config, content-based checks and migration (#346)
Mirror of Wiki Deployment-and-Operations revision 3a76e16: current host
122.228.200.167, the standard 9527 vhost (nginx serves dist, / returns
index.html) and why, release verification by content rather than status
code, a server-migration checklist, and the 2026-09-28 migration fix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NTDbDcwbDw1TSAcE6wfh2F
2026-09-28 16:14:43 +08:00
QiuSWandClaude Opus 5.5 0b01b92c98 fix(server): serve the Admin SPA at / when dist exists (#346)
go-admin registered its welcome page on GET / in every non-prod mode, so a
reverse proxy that forwarded / to the server showed 「GO-ADMIN欢迎您」
instead of the Admin (happened after the 2026-09-28 server migration).
When dist/index.html exists, / now returns it; without a dist (vite
development) the previous welcome/prod behaviour is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NTDbDcwbDw1TSAcE6wfh2F
2026-09-28 16:07:49 +08:00
QiuSWandClaude Opus 5.5 9dace6ac89 fix(sybinnercode): add identity/stall/id guards to #289 assignment (#344)
Port the remaining consistency guards from cmautobuy's
planExistingMatchedInnerCodeItems into assignExistingBoundItems:

- Reject the whole multi-piece group if any candidate's raw ProductSpec,
  sku or variationSku differs from the lowest-ID candidate. Candidates
  are matched via NormalizeSpecKey, so raw values can legitimately differ
  even when normalized keys agree; auto-assigning across genuinely
  different items must be blocked.
- Re-verify each candidate against stallMatches when record.Stall is
  non-empty, since the no-SKU fallback path in matchEvidence can hand
  back candidates that were never stall-checked.
- Reject candidates with a non-positive or duplicate detail ID.

Added one regression test per guard plus a happy-path test confirming
legitimate multi-piece assignment still succeeds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NTDbDcwbDw1TSAcE6wfh2F
2026-09-28 10:35:16 +08:00
QiuSWandClaude Opus 5.5 e99bbc2327 fix(sybinnercode): align stall article matching with cmautobuy rules (#344)
Port cmautobuy's innerCodeStallMatches rule set (#259/#273 fixes) into
strictStall's underlying match: split stall on the last '#', compare the
article only against alphanumeric tokens, require leading-zero equivalence
plus stall-name confirmation for numeric articles, exact token match for
non-numeric articles, and a ProductSpec-prefix rule. This replaces the old
plain substring containment that could bind an inbound code to the wrong
SYB product detail (weight numbers mistaken for articles, short numeric
articles matching inside long codes, 067/67 not aligning, stall names
containing '#' splitting incorrectly).

Also fixes #289: when N single-piece inbound codes are matched against N
existing qty=1 SYB details and some details already carry a correctly
bound code out of ID order, planRecord now preserves those existing
bindings (matching by code value first via assignExistingBoundItems) and
only assigns the remaining blank details to the missing codes, instead of
reassigning by index/ID order and overwriting a correct binding.

Added regression tests for both fixes, including an end-to-end
RunMatchJob test reproducing the #289 bug against the pre-fix assignment
(verified to fail on the old code, pass on the new code).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NTDbDcwbDw1TSAcE6wfh2F
2026-09-28 10:31:11 +08:00
QiuSW abdf90775c docs: record unified SYB writeback sessions (#343) 2026-09-27 23:00:46 +08:00
QiuSW 934a7beabc fix(purchase): unify SYB session refresh for writeback (#343) 2026-09-27 22:56:54 +08:00
QiuSW 24100f04d4 merge: place return matching after purchase (#342) 2026-09-27 17:24:06 +08:00
QiuSW 266418ac47 fix(syb): place return matching after purchase (#342) 2026-09-27 17:23:57 +08:00
QiuSW 5e5fdd797e merge: arrange SYB filter row (#342) 2026-09-27 17:19:45 +08:00
QiuSW 58c8c077ad fix(syb): arrange created-time filter row (#342) 2026-09-27 17:19:35 +08:00
QiuSW 9f679f6403 merge: SYB created-time filter and page size (#342) 2026-09-27 16:59:54 +08:00
QiuSW 977ac235e2 feat(syb): filter products by created time (#342) 2026-09-27 16:59:22 +08:00
QiuSWandClaude Opus 5.5 573f5b8cf3 feat(syb): support 200/500 rows per page on SYB products list (#339)
Bump the syb-products page-size options to 20/50/100/200/500 with a new
100 default, cap the server-side sybimport.List page size at 500, chunk
the per-page purchase-readiness preview into <=100-id requests, and add
per-button selection limits (with disabled+tooltip) for AI 匹配, 创建采购,
创建采集, 图搜采集 and 匹配退货 so a larger page never silently exceeds a
batch endpoint's cap. 创建采购's 100-item server cap is left untouched.
Also caps returnmatch.BatchMatch at 500 ids (INVALID_REQUEST beyond that).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NTDbDcwbDw1TSAcE6wfh2F
2026-09-27 16:52:09 +08:00
QiuSW 1491a9677a fix(access): allow after-sales purchase readiness (#341) 2026-09-27 11:59:31 +08:00
QiuSW d4d32c6e89 docs: restore wiki mirrors after return-match update (#338) 2026-09-27 11:46:28 +08:00
QiuSW b7038633f0 test(returnmatch): cover after-sales access and migration repair (#341) 2026-09-27 11:38:43 +08:00
QiuSW 844f611d77 fix(access): repair return-match API catalog migration (#341) 2026-09-27 11:25:01 +08:00
QiuSW d415971268 feat(returnmatch): publish return matching and after-sales access (#338 #341) 2026-09-27 11:16:18 +08:00
QiuSW 6fe588d5e3 fix(web): show after-sales GoAuto actions (#341) 2026-09-27 11:04:25 +08:00