provider_device_testing.go 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // Copyright 2019 githup.com. All rights reserved.
  2. // Use of this source code is governed by githup.com.
  3. package model
  4. import (
  5. "github.com/jinzhu/gorm"
  6. "time"
  7. )
  8. type ProviderDeviceTesting struct {
  9. Id int64 `gorm:"column:ID" json:"id" form:"id"`
  10. ProviderId int64 `gorm:"column:ProviderId" json:"provider_id" form:"provider_id"`
  11. DeviceCode int32 `gorm:"column:DeviceCode" json:"device_code" form:"device_code"`
  12. Status int32 `gorm:"column:Status" json:"status" form:"status"`
  13. CreatedAt time.Time `gorm:"column:CreatedAt"`
  14. Feedback string `gorm:"column:Feedback"`
  15. Comment string `gorm:"column:Comment"`
  16. Appendix string `gorm:"column:Appendix"`
  17. Agent string `gorm:"column:Agent"`
  18. AgentPhone string `gorm:"column:AgentPhone"`
  19. ApproveTime time.Time `gorm:"column:ApproveTime"`
  20. Reviewer string `gorm:"column:Reviewer"`
  21. }
  22. func (ProviderDeviceTesting) TableName() string {
  23. return "ProviderDeviceTesting"
  24. }
  25. func (p *ProviderDeviceTesting) Insert(db *gorm.DB) error {
  26. return db.Table(p.TableName()).Create(p).Error
  27. }
  28. func (p *ProviderDeviceTesting) Find(db *gorm.DB, where map[string]interface{}) error {
  29. cond, val, err := whereBuild(where)
  30. if err != nil {
  31. return err
  32. }
  33. return db.Table(p.TableName()).Where(cond, val...).First(p).Error
  34. }
  35. func (p *ProviderDeviceTesting) Update(db *gorm.DB, where map[string]interface{}, values map[string]interface{}) error {
  36. cond, val, err := whereBuild(where)
  37. if err != nil {
  38. return err
  39. }
  40. return db.Table(p.TableName()).Table(p.TableName()).Where(cond, val...).Updates(values).Error
  41. }
  42. func (p *ProviderDeviceTesting) Save(db *gorm.DB) error {
  43. return db.Table(p.TableName()).Save(p).Error
  44. }
  45. func (p *ProviderDeviceTesting) List(db *gorm.DB, where map[string]interface{}) (list []ProviderDeviceTesting, err error) {
  46. if len(where) > 0 {
  47. cond, val, err := whereBuild(where)
  48. if err != nil {
  49. return list, err
  50. }
  51. result := db.Table(p.TableName()).Where(cond, val...).Find(&list)
  52. return list, result.Error
  53. }
  54. result := db.Table(p.TableName()).Find(&list)
  55. return list, result.Error
  56. }
  57. func (p *ProviderDeviceTesting) Count(db *gorm.DB, where map[string]interface{}) (int64, error) {
  58. if len(where) > 0 {
  59. cond, val, err := whereBuild(where)
  60. if err != nil {
  61. return 0, err
  62. }
  63. ret := int64(0)
  64. err = db.Table(p.TableName()).Where(cond, val...).Count(&ret).Error
  65. return ret, err
  66. }
  67. ret := int64(0)
  68. err := db.Table(p.TableName()).Count(&ret).Error
  69. return ret, err
  70. }
  71. func (p *ProviderDeviceTesting) Del(db *gorm.DB, where map[string]interface{}) error {
  72. cond, val, err := whereBuild(where)
  73. if err != nil {
  74. return err
  75. }
  76. return db.Table(p.TableName()).Where(cond, val...).Delete(p).Error
  77. }