diff --git a/src/dao/service_request_record.go b/src/dao/service_request_record.go index 44c16d0039b30f0383861eb0d6b3884d71de88be..1c5a5722554c1266708ff4f7ede9646d800c19e9 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 65902db04c4f2403eaeb7284affd1847047265f8..bbaadf6af251cb057fe8157c29dead706420cead 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 }