diff --git a/src/dao/service_request_record.go b/src/dao/service_request_record.go index 1c5a5722554c1266708ff4f7ede9646d800c19e9..115c98e07d5caf39d4f9856d406af03ee0268373 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 bbaadf6af251cb057fe8157c29dead706420cead..a849405e5db3f16e7909f28ebe7e57f521abce24 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)