From e28571a890c5af52a5f214164affb5a13a520c87 Mon Sep 17 00:00:00 2001 From: "leitao.zhang" Date: Wed, 4 Nov 2020 11:42:50 +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 | 25 ++++++++++++++----------- src/service/field.go | 30 ++++++++++++++++++------------ 2 files changed, 32 insertions(+), 23 deletions(-) diff --git a/src/dao/service_request_record.go b/src/dao/service_request_record.go index 1c5a572..115c98e 100644 --- a/src/dao/service_request_record.go +++ b/src/dao/service_request_record.go @@ -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 { diff --git a/src/service/field.go b/src/service/field.go index bbaadf6..a849405 100644 --- a/src/service/field.go +++ b/src/service/field.go @@ -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) -- 2.26.0