Add: 1. select like function, 2. tglog

This commit is contained in:
殷勇 2023-09-12 17:31:47 +08:00
parent 4c371afe63
commit 0317dc9f5e
2 changed files with 46 additions and 32 deletions

View File

@ -84,6 +84,24 @@ func (this *dbPool) OrmSelect(
this.internalQuery(dataSource, sql, params, cb) 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, &params, whereKv)
this.joinWhereLike(&sql, &params, likeWhere)
sql = fmt.Sprintf("%s LIMIT %d", sql, limit)
this.internalQuery(dataSource, sql, params, cb)
}
func (this *dbPool) SelectOne( func (this *dbPool) SelectOne(
dataSource string, dataSource string,
tblName 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 { func (this *dbPool) joinUpdateFields(fieldsKv [][]string, params *[]string) string {
sql := "" sql := ""
for index, items := range fieldsKv { for index, items := range fieldsKv {

View File

@ -1,24 +1,24 @@
package f5 package f5
import ( import (
"q5"
"os"
"sync"
"fmt" "fmt"
"os"
"q5"
"sync"
"time" "time"
) )
type tgLogMsgNode struct { type tgLogMsgNode struct {
gameId int32 gameId int32
jsonStr string jsonStr string
next *tgLogMsgNode next *tgLogMsgNode
} }
type tgLog struct { type tgLog struct {
isPolyLog bool isPolyLog bool
topNode *tgLogMsgNode topNode *tgLogMsgNode
botNode *tgLogMsgNode botNode *tgLogMsgNode
msgMutex sync.Mutex msgMutex sync.Mutex
chGoSaveExit chan int chGoSaveExit chan int
} }
@ -36,35 +36,24 @@ func (this *tgLog) SetPolyLog(isPolyLog bool) {
} }
func (this *tgLog) AddTrackLog( 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, gameId int32,
accountId string, accountId string,
remoteAddr string, remoteAddr string,
eventName string, eventName string,
prop map[string]string) { prop map[string]string) {
logObj := struct { logObj := struct {
AccountId string `json:"#account_id"` AccountId string `json:"#account_id"`
Type string `json:"#type""` Type string `json:"#type""`
Time string `json:"#time"` Time string `json:"#time"`
EventName string `json:"#event_name""` EventName string `json:"#event_name""`
Ip string `json:"#ip""` Ip string `json:"#ip""`
Properties map[string]string `json:"properties"` Properties map[string]string `json:"properties"`
} { }{
AccountId: accountId, AccountId: accountId,
Type: "track", Type: "track",
Time: q5.FormatUnixDateTime(_app.GetNowSeconds(), _app.GetLocation()), Time: q5.FormatUnixDateTime(_app.GetNowSeconds(), _app.GetLocation()),
EventName: eventName, EventName: eventName,
Ip: remoteAddr, Ip: remoteAddr,
Properties: prop, Properties: prop,
} }
p := new(tgLogMsgNode) p := new(tgLogMsgNode)
@ -118,7 +107,7 @@ func (this *tgLog) getLogFile(gameId int32) *os.File {
logDir = fmt.Sprintf(TGLOG_ROOT, _app.GetPkgName()) logDir = fmt.Sprintf(TGLOG_ROOT, _app.GetPkgName())
} }
q5.ForceCreateDir(logDir) 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 return f
} else { } else {
_sysLog.Warning("tgLog.goSaveToFile err:%s", err) _sysLog.Warning("tgLog.goSaveToFile err:%s", err)