api_source.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /**********************************************
  2. ** @Des: 接口资源
  3. ** @Author: haodaquan
  4. ** @Date: 2018-01-14 15:42:43
  5. ** @Last Modified by: haodaquan
  6. ** @Last Modified time: 2018-01-14 15:42:43
  7. ***********************************************/
  8. package backgroundm
  9. import (
  10. "github.com/astaxie/beego/orm"
  11. "wuyebaoxiuapi/models"
  12. )
  13. type ApiSource struct {
  14. Id int
  15. GroupId int
  16. SourceName string
  17. Status int
  18. CreateId int
  19. AuditId int
  20. UpdateId int
  21. CreateTime int64
  22. UpdateTime int64
  23. AuditTime int64
  24. }
  25. func (a *ApiSource) TableName() string {
  26. return models.TableName("api_source")
  27. }
  28. func ApiSourceAdd(a *ApiSource) (int64, error) {
  29. return orm.NewOrm().Insert(a)
  30. }
  31. func ApiSourceGetByName(ApiSourceName string) (*ApiSource, error) {
  32. a := new(ApiSource)
  33. err := orm.NewOrm().QueryTable(models.TableName("api_source")).Filter("source_name", ApiSourceName).One(a)
  34. if err != nil {
  35. return nil, err
  36. }
  37. return a, nil
  38. }
  39. func ApiSourceGetList(page, pageSize int, filters ...interface{}) ([]*ApiSource, int64) {
  40. offset := (page - 1) * pageSize
  41. list := make([]*ApiSource, 0)
  42. query := orm.NewOrm().QueryTable(models.TableName("api_source"))
  43. if len(filters) > 0 {
  44. l := len(filters)
  45. for k := 0; k < l; k += 2 {
  46. query = query.Filter(filters[k].(string), filters[k+1])
  47. }
  48. }
  49. total, _ := query.Count()
  50. query.OrderBy("-id").Limit(pageSize, offset).All(&list)
  51. // total := int64(12)
  52. return list, total
  53. }
  54. func init() {
  55. orm.RegisterModel(new(ApiSource))
  56. }
  57. func ApiSourceGetById(id int) (*ApiSource, error) {
  58. r := new(ApiSource)
  59. err := orm.NewOrm().QueryTable(models.TableName("api_source")).Filter("id", id).One(r)
  60. if err != nil {
  61. return nil, err
  62. }
  63. return r, nil
  64. }
  65. func (a *ApiSource) Update(fields ...string) error {
  66. if _, err := orm.NewOrm().Update(a, fields...); err != nil {
  67. return err
  68. }
  69. return nil
  70. }