Service (app/goauto/returnmatch/service.go) wires the pure matching
functions to the database:
- BatchMatch: manual-only trigger (no scheduler, not called from
yeeke sync or SYB import) for ticked SYB product rows. Filters to
the participating process stages (待人工处理 excluded per the
confirmed rule), loads the available return pool (no active match,
non-nil future destroy deadline) via purchase.ProcessStages +a
join query, runs SelectMatches, and inserts one return_match row per
outcome. A unique-constraint violation on insert (lost race) is
reported per-row as a conflict skip, never fails the whole batch.
- Confirm/Cancel: state transitions with row locking; Cancel clears
both Active* columns so the same pair can be rematched later.
- Remark, List (by SYB product id / return item id / status) and
Detail for both admin pages' filter/column needs.
Handler + router (app/goauto/returnmatch/{handler,router}.go) expose
POST /api/admin/v1/return-matches/batch-match, GET .../return-matches,
GET .../return-matches/:id, POST .../:id/{confirm,cancel,remark}.
Write actions require admin/purchaser (same requireCanPurchase gate
already used by yeeke.Handler.TriggerSync); list/detail are read-only
for any authenticated user. Registered in
app/admin/router/init_router.go.
Tests cover end-to-end batch match, expired-deadline exclusion,
multi-colour cross-pairing through the DB path, 待人工处理 exclusion,
confirm-then-cancel restoring availability and rematch-ability, and a
concurrent-insert test asserting exactly one winner against the
unique constraint.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NTDbDcwbDw1TSAcE6wfh2F
77 lines
2.5 KiB
Go
77 lines
2.5 KiB
Go
package router
|
|
|
|
import (
|
|
goautoclientapi "go-admin/app/goauto/clientapi"
|
|
"os"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
log "github.com/go-admin-team/go-admin-core/logger"
|
|
"github.com/go-admin-team/go-admin-core/sdk"
|
|
goautoaimatching "go-admin/app/goauto/aimatching"
|
|
goautoapprelease "go-admin/app/goauto/apprelease"
|
|
goautodevice "go-admin/app/goauto/device"
|
|
goautoproduct "go-admin/app/goauto/product"
|
|
goautopurchase "go-admin/app/goauto/purchase"
|
|
goautopurchaserule "go-admin/app/goauto/purchaserule"
|
|
goautoreplacement "go-admin/app/goauto/replacement"
|
|
goautoreturnmatch "go-admin/app/goauto/returnmatch"
|
|
goautorule "go-admin/app/goauto/rule"
|
|
goautoshopeeproduct "go-admin/app/goauto/shopeeproduct"
|
|
goautosybimport "go-admin/app/goauto/sybimport"
|
|
goautosybinnercode "go-admin/app/goauto/sybinnercode"
|
|
goautosybproductfilter "go-admin/app/goauto/sybproductfilter"
|
|
goautosybshop "go-admin/app/goauto/sybshop"
|
|
goautotask "go-admin/app/goauto/task"
|
|
goautoyeeke "go-admin/app/goauto/yeeke"
|
|
common "go-admin/common/middleware"
|
|
)
|
|
|
|
// InitRouter 路由初始化,不要怀疑,这里用到了
|
|
func InitRouter() {
|
|
var r *gin.Engine
|
|
h := sdk.Runtime.GetEngine()
|
|
if h == nil {
|
|
log.Fatal("not found engine...")
|
|
os.Exit(-1)
|
|
}
|
|
switch h.(type) {
|
|
case *gin.Engine:
|
|
r = h.(*gin.Engine)
|
|
default:
|
|
log.Fatal("not support other engine")
|
|
os.Exit(-1)
|
|
}
|
|
|
|
// the jwt middleware
|
|
authMiddleware, err := common.AuthInit()
|
|
if err != nil {
|
|
log.Fatalf("JWT Init Error, %s", err.Error())
|
|
}
|
|
|
|
// 注册系统路由
|
|
InitSysRouter(r, authMiddleware)
|
|
|
|
// 注册业务路由
|
|
// TODO: 这里可存放业务路由,里边并无实际路由只有演示代码
|
|
InitExamplesRouter(r, authMiddleware)
|
|
|
|
// 注册 GoAuto Agent 与设备管理路由。
|
|
goautodevice.InitRouter(r, authMiddleware)
|
|
goautoclientapi.InitRouter(r, authMiddleware)
|
|
goautoapprelease.InitRouter(r, authMiddleware)
|
|
goautoaimatching.InitRouter(r, authMiddleware)
|
|
goautotask.InitRouter(r, authMiddleware)
|
|
goautopurchase.InitRouter(r, authMiddleware)
|
|
goautopurchaserule.InitRouter(r, authMiddleware)
|
|
goautoproduct.InitRouter(r, authMiddleware)
|
|
goautoreplacement.InitRouter(r, authMiddleware)
|
|
goautorule.InitRouter(r, authMiddleware)
|
|
goautoshopeeproduct.InitRouter(r, authMiddleware, goautopurchase.ValidateQuickReplacement)
|
|
goautosybimport.InitRouter(r, authMiddleware)
|
|
goautosybinnercode.InitRouter(r, authMiddleware)
|
|
goautosybshop.InitRouter(r, authMiddleware)
|
|
goautosybproductfilter.InitRouter(r, authMiddleware)
|
|
goautoyeeke.InitRouter(r, authMiddleware)
|
|
goautoreturnmatch.InitRouter(r, authMiddleware)
|
|
}
|