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

调用记录

parent b4d4ebcc
......@@ -5,17 +5,20 @@ import (
)
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 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"`
Id int64 `json:"id" xorm:"pk default nextval('service_request_record_id_pk'::regclass) autoincr BIGINT"`
ServiceId int64 `json:"service_id" xorm:"BIGINT"`
ApplyId int64 `json:"apply_id" xorm:"BIGINT"`
UserId string `json:"user_id" xorm:"VARCHAR(50)"`
RequestTime time.Time `json:"request_time" xorm:"DATETIME"`
DateDay int `json:"date_day" xorm:"SMALLINT"`
DateMonth int `json:"date_month" xorm:"SMALLINT"`
DateYear int `json:"date_year" xorm:"SMALLINT"`
Status int `json:"status" xorm:"SMALLINT"`
Error string `json:"error" xorm:"TEXT"`
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 {
......
......@@ -89,26 +89,32 @@ func GetExpire() time.Duration {
//记录调用痕迹
func RecordCall(proxyData model.ProxyData, status int, res []byte) {
acc := dao.ServiceRequestRecord{}
db, err := client.GetConnect()
if err != nil {
fmt.Println(err.Error())
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 {
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 {
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