diff --git a/dbpool.go b/dbpool.go index bd9ef15..afcb3fb 100644 --- a/dbpool.go +++ b/dbpool.go @@ -84,6 +84,24 @@ func (this *dbPool) OrmSelect( this.internalQuery(dataSource, sql, params, cb) } +func (this *dbPool) SelectLike( + dataSource string, + tblName string, + fields []string, + whereKv [][]string, + likeWhere [][]string, + limit int, + cb QueryResultCb) { + var params []string + + sql := fmt.Sprintf("SELECT %s FROM %s WHERE 1=1 ", this.joinSelectFields(fields), tblName) + this.joinWhere(&sql, ¶ms, whereKv) + this.joinWhereLike(&sql, ¶ms, likeWhere) + sql = fmt.Sprintf("%s LIMIT %d", sql, limit) + + this.internalQuery(dataSource, sql, params, cb) +} + func (this *dbPool) SelectOne( dataSource string, tblName string, @@ -259,6 +277,13 @@ func (this *dbPool) joinWhere(sql *string, params *[]string, whereKv [][]string) } } +func (this *dbPool) joinWhereLike(sql *string, params *[]string, whereKv [][]string) { + for _, items := range whereKv { + *sql += " AND " + items[0] + " LIKE ? " + *params = append(*params, items[1]) + } +} + func (this *dbPool) joinUpdateFields(fieldsKv [][]string, params *[]string) string { sql := "" for index, items := range fieldsKv { diff --git a/tglog.go b/tglog.go index 3fc15a4..6f393a6 100644 --- a/tglog.go +++ b/tglog.go @@ -1,24 +1,24 @@ package f5 import ( - "q5" - "os" - "sync" "fmt" + "os" + "q5" + "sync" "time" ) type tgLogMsgNode struct { - gameId int32 + gameId int32 jsonStr string - next *tgLogMsgNode + next *tgLogMsgNode } type tgLog struct { - isPolyLog bool - topNode *tgLogMsgNode - botNode *tgLogMsgNode - msgMutex sync.Mutex + isPolyLog bool + topNode *tgLogMsgNode + botNode *tgLogMsgNode + msgMutex sync.Mutex chGoSaveExit chan int } @@ -36,35 +36,24 @@ func (this *tgLog) SetPolyLog(isPolyLog bool) { } func (this *tgLog) AddTrackLog( - gameId int32, - accountId string, - remoteAddr string, - logClass1 int32, - logClass2 int32, - prop map[string]string) { - eventName := fmt.Sprintf("event_%d_%d", logClass1, logClass2) - this.AddTrackLogEx(gameId, accountId, remoteAddr, eventName, prop) -} - -func (this *tgLog) AddTrackLogEx( gameId int32, accountId string, remoteAddr string, eventName string, prop map[string]string) { logObj := struct { - AccountId string `json:"#account_id"` - Type string `json:"#type""` - Time string `json:"#time"` - EventName string `json:"#event_name""` - Ip string `json:"#ip""` + AccountId string `json:"#account_id"` + Type string `json:"#type""` + Time string `json:"#time"` + EventName string `json:"#event_name""` + Ip string `json:"#ip""` Properties map[string]string `json:"properties"` - } { - AccountId: accountId, - Type: "track", - Time: q5.FormatUnixDateTime(_app.GetNowSeconds(), _app.GetLocation()), - EventName: eventName, - Ip: remoteAddr, + }{ + AccountId: accountId, + Type: "track", + Time: q5.FormatUnixDateTime(_app.GetNowSeconds(), _app.GetLocation()), + EventName: eventName, + Ip: remoteAddr, Properties: prop, } p := new(tgLogMsgNode) @@ -118,7 +107,7 @@ func (this *tgLog) getLogFile(gameId int32) *os.File { logDir = fmt.Sprintf(TGLOG_ROOT, _app.GetPkgName()) } q5.ForceCreateDir(logDir) - if f, err := os.OpenFile(logDir + fileName, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0666); err == nil { + if f, err := os.OpenFile(logDir+fileName, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0666); err == nil { return f } else { _sysLog.Warning("tgLog.goSaveToFile err:%s", err)