fix(risk_control,message_gateway): fix SQL LIKE escape syntax and use UserService contract

This commit is contained in:
ryan
2026-08-28 20:19:24 +08:00
parent df351cbd33
commit 0035e548a5
6 changed files with 125 additions and 36 deletions
@@ -19,6 +19,8 @@ var (
cacheSvc contracts.CacheService
taskMu sync.RWMutex
taskSvc contracts.TaskService
userMu sync.RWMutex
userSvc contracts.UserService
)
// SetDBServiceForTest injects a DBService for tests. Production wiring must use Apply.
@@ -44,6 +46,12 @@ func setTaskService(s contracts.TaskService) {
taskSvc = s
}
func setUserService(s contracts.UserService) {
userMu.Lock()
defer userMu.Unlock()
userSvc = s
}
func getDB(ctx context.Context) *gorm.DB {
if c, ok := ctx.(*core.Context); ok && c != nil {
if s, err := core.Inject[contracts.DBService](c); err == nil && s != nil {
@@ -76,3 +84,14 @@ func getTaskService() contracts.TaskService {
defer taskMu.RUnlock()
return taskSvc
}
func getUserService(ctx context.Context) contracts.UserService {
if c, ok := ctx.(*core.Context); ok && c != nil {
if s, err := core.Inject[contracts.UserService](c); err == nil && s != nil {
return s
}
}
userMu.RLock()
defer userMu.RUnlock()
return userSvc
}