Commit e28571a8 authored by leitao.zhang's avatar leitao.zhang

调用记录

parent b4d4ebcc
...@@ -5,17 +5,20 @@ import ( ...@@ -5,17 +5,20 @@ import (
) )
type ServiceRequestRecord struct { type ServiceRequestRecord struct {
//Id int `json:"id" xorm:"id"` Id int64 `json:"id" xorm:"pk default nextval('service_request_record_id_pk'::regclass) autoincr BIGINT"`
ServiceId int `json:"service_id" xorm:"service_id"` ServiceId int64 `json:"service_id" xorm:"BIGINT"`
ApplyId int `json:"apply_id" xorm:"apply_id"` ApplyId int64 `json:"apply_id" xorm:"BIGINT"`
UserId string `json:"user_id" xorm:"user_id"` UserId string `json:"user_id" xorm:"VARCHAR(50)"`
RequestTime time.Time `json:"request_time" xorm:"request_time created"` RequestTime time.Time `json:"request_time" xorm:"DATETIME"`
DateDay int `json:"date_day" xorm:"date_day"` DateDay int `json:"date_day" xorm:"SMALLINT"`
DateMonth int `json:"date_month" xorm:"date_month"` DateMonth int `json:"date_month" xorm:"SMALLINT"`
DateYear int `json:"date_year" xorm:"date_year"` DateYear int `json:"date_year" xorm:"SMALLINT"`
Status int `json:"status" xorm:"status"` Status int `json:"status" xorm:"SMALLINT"`
Error string `json:"error" xorm:"error"` Error string `json:"error" xorm:"TEXT"`
ReqUrl string `json:"req_url" xorm:"req_url"` ReqUrl string `json:"req_url" xorm:"VARCHAR"`
ApiId int64 `json:"api_id" xorm:"BIGINT"`
ApplyOid string `json:"apply_oid" xorm:"VARCHAR"`
ServiceOid string `json:"service_oid" xorm:"VARCHAR"`
} }
func (s ServiceRequestRecord) TableName() string { func (s ServiceRequestRecord) TableName() string {
......
...@@ -89,26 +89,32 @@ func GetExpire() time.Duration { ...@@ -89,26 +89,32 @@ func GetExpire() time.Duration {
//记录调用痕迹 //记录调用痕迹
func RecordCall(proxyData model.ProxyData, status int, res []byte) { func RecordCall(proxyData model.ProxyData, status int, res []byte) {
acc := dao.ServiceRequestRecord{}
db, err := client.GetConnect() db, err := client.GetConnect()
if err != nil { if err != nil {
fmt.Println(err.Error()) fmt.Println(err.Error())
return return
} }
acc := dao.ServiceRequestRecord{
Id: 0,
ServiceId: proxyData.ServiceId,
ApplyId: proxyData.ApplyId,
UserId: proxyData.ApplyUserId,
RequestTime: time.Now(),
DateDay: time.Now().Day(),
DateMonth: int(time.Now().Month()),
DateYear: time.Now().Year(),
Status: status,
Error: "",
ReqUrl: proxyData.ReqUrl,
ApiId: proxyData.ApiId,
ApplyOid: proxyData.ApplyOid,
ServiceOid: proxyData.ServiceOid,
}
//错误信息
if status != 200 { if status != 200 {
acc.Error = string(res) acc.Error = string(res)
} }
acc.RequestTime = time.Now()
acc.ApplyId = cast.ToInt(proxyData.ApplyId)
acc.UserId = proxyData.ApplyUserId
acc.ServiceId = cast.ToInt(proxyData.ServiceId)
acc.ReqUrl = proxyData.ReqUrl
acc.DateDay = time.Now().Day()
fmt.Println(time.Now().Month().String())
acc.DateMonth = int(time.Now().Month())
acc.DateYear = time.Now().Year()
acc.Status = status
if _, err = db.Insert(&acc); err != nil { if _, err = db.Insert(&acc); err != nil {
fmt.Println(err) fmt.Println(err)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment