From b4d4ebcc4c18eef786c9c5b736dd0768dc9b9d9e Mon Sep 17 00:00:00 2001 From: "leitao.zhang" Date: Wed, 4 Nov 2020 10:53:00 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E7=94=A8=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/dao/service_request_record.go | 26 ++++++++++++++------------ src/service/field.go | 22 +++++++++++++--------- 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/src/dao/service_request_record.go b/src/dao/service_request_record.go index 44c16d0..1c5a572 100644 --- a/src/dao/service_request_record.go +++ b/src/dao/service_request_record.go @@ -1,19 +1,21 @@ package dao -import "gitlab.wodcloud.com/apaas/apaas-meshproxy/src/tools" +import ( + "time" +) type ServiceRequestRecord struct { - Id int `json:"id" xorm:"id"` - ServiceId int `json:"service_id" xorm:"service_id"` - ApplyId int `json:"apply_id" xorm:"apply_id"` - UserId string `json:"user_id" xorm:"user_id"` - RequestTime tools.JsonTime `json:"request_time" xorm:"request_time created"` - DateDay int `json:"date_day" xorm:"date_day"` - DateMonth int `json:"date_month" xorm:"date_month"` - DateYear int `json:"date_year" xorm:"date_year"` - Status int `json:"status" xorm:"status"` - Error string `json:"error" xorm:"error"` - ReqUrl string `json:"req_url" xorm:"req_url"` + //Id int `json:"id" xorm:"id"` + ServiceId int `json:"service_id" xorm:"service_id"` + ApplyId int `json:"apply_id" xorm:"apply_id"` + UserId string `json:"user_id" xorm:"user_id"` + RequestTime time.Time `json:"request_time" xorm:"request_time created"` + DateDay int `json:"date_day" xorm:"date_day"` + DateMonth int `json:"date_month" xorm:"date_month"` + DateYear int `json:"date_year" xorm:"date_year"` + Status int `json:"status" xorm:"status"` + Error string `json:"error" xorm:"error"` + ReqUrl string `json:"req_url" xorm:"req_url"` } func (s ServiceRequestRecord) TableName() string { diff --git a/src/service/field.go b/src/service/field.go index 65902db..bbaadf6 100644 --- a/src/service/field.go +++ b/src/service/field.go @@ -18,7 +18,6 @@ import ( "gitlab.wodcloud.com/apaas/apaas-meshproxy/src/model" "gitlab.wodcloud.com/apaas/apaas-meshproxy/src/model/request" "gitlab.wodcloud.com/apaas/apaas-meshproxy/src/model/tables" - "gitlab.wodcloud.com/apaas/apaas-meshproxy/src/tools" "gitlab.wodcloud.com/apaas/apaas-meshproxy/src/tools/dataconvertutil" "log" "time" @@ -91,7 +90,7 @@ func GetExpire() time.Duration { //记录调用痕迹 func RecordCall(proxyData model.ProxyData, status int, res []byte) { acc := dao.ServiceRequestRecord{} - redis, err := client.GetRedisClient() + db, err := client.GetConnect() if err != nil { fmt.Println(err.Error()) return @@ -99,7 +98,7 @@ func RecordCall(proxyData model.ProxyData, status int, res []byte) { if status != 200 { acc.Error = string(res) } - acc.RequestTime = tools.JsonTime(time.Now()) + acc.RequestTime = time.Now() acc.ApplyId = cast.ToInt(proxyData.ApplyId) acc.UserId = proxyData.ApplyUserId acc.ServiceId = cast.ToInt(proxyData.ServiceId) @@ -110,13 +109,18 @@ func RecordCall(proxyData model.ProxyData, status int, res []byte) { acc.DateYear = time.Now().Year() acc.Status = status - b, _ := json.Marshal(acc) - if errs := redis.Conn.RPush(config.CallRecord, b).Err(); errs != nil { - err = errs - fmt.Println("rpush data to list failed:", errs.Error()) - return + + if _, err = db.Insert(&acc); err != nil { + fmt.Println(err) } - fmt.Println("调用记录进入队列") + + //b, _ := json.Marshal(acc) + //if errs := redis.Conn.RPush(config.CallRecord, b).Err(); errs != nil { + // err = errs + // fmt.Println("rpush data to list failed:", errs.Error()) + // return + //} + //fmt.Println("调用记录进入队列") return } -- 2.26.0