callback_in.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package dbmodel
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/astaxie/beego/orm"
  6. )
  7. type CallbackIn struct {
  8. Id int `json:"id" orm:"column(id);auto" description:"增长id"`
  9. ServiceType int `json:"service_type" orm:"column(service_type)" description:"业务类型,101:维保记录"`
  10. SourceName string `json:"source_name" orm:"column(source_name)" description:"数据源名称,如 cbs表示查博士"`
  11. SourceObjectId string `json:"source_object_id" orm:"column(source_object_id)" description:"数据源对象id,如:order_id"`
  12. RequestCode int `json:"request_code" orm:"column(request_code)" description:"请求结果码,同request_params.code,1表示已出报告"`
  13. RequestParams string `json:"request_params" orm:"column(request_params)" description:"请求参数`
  14. ResponseParams string `json:"response_params" orm:"column(response_params)" description:"响应参数`
  15. Elapsed float64 `json:"elapsed" orm:"column(elapsed)" description:"调用耗时,单位:秒"`
  16. AddTime int64 `json:"add_time" orm:"column(add_time)" description:"生成时间戳"`
  17. }
  18. func (p *CallbackIn) DbName() string {
  19. return "db_gd_access_log"
  20. }
  21. func (p *CallbackIn) TableName() string {
  22. return "t_gd_callback_in_log"
  23. }
  24. func (p CallbackIn) String() string {
  25. vals, _ := json.Marshal(p)
  26. return string(vals)
  27. }
  28. func (p *CallbackIn) Create(db orm.Ormer) (int64, error) {
  29. return db.Insert(p)
  30. }
  31. func (p *CallbackIn) Update(db orm.Ormer, filters, values map[string]interface{}) (int64, error) {
  32. if len(values) == 0 {
  33. return 0, fmt.Errorf("update nil values")
  34. }
  35. qs := db.QueryTable(p.TableName())
  36. for k, v := range filters {
  37. qs = qs.Filter(k, v)
  38. }
  39. return qs.Update(values)
  40. }
  41. func (p *CallbackIn) Fetch(db orm.Ormer, filters map[string]interface{}, fields ...string) error {
  42. qs := db.QueryTable(p.TableName())
  43. for k, v := range filters {
  44. qs = qs.Filter(k, v)
  45. }
  46. return qs.One(p, fields...)
  47. }