slag_vehicle.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // Copyright 2019 github.com. All rights reserved.
  2. // Use of this source code is governed by github.com.
  3. package model
  4. import (
  5. "github.com/jinzhu/gorm"
  6. "time"
  7. )
  8. type SlagcarDevice struct {
  9. ID int64 `gorm:"column:ID;PRIMARY_KEY" json:"id"`
  10. Code string `gorm:"column:Code" json:"code"`
  11. Name string `gorm:"column:name" json:"name"`
  12. DeviceNum string `gorm:"column:deviceNum" json:"devicenum"`
  13. DeviceModel string `gorm:"column:deviceModel" json:"devicemodel"`
  14. DeviceName string `gorm:"column:deviceName" json:"devicename"`
  15. Manufacturer string `gorm:"column:manufacturer" json:"manufacturer"`
  16. Batch string `gorm:"column:batch" json:"batch"`
  17. SN string `gorm:"column:SN" json:"sn"`
  18. SIM string `gorm:"column:SIM" json:"sim"`
  19. State int64 `gorm:"column:state" json:"state"`
  20. Unit string `gorm:"column:unit" json:"unit"`
  21. Person string `gorm:"column:contactName" json:"person"`
  22. Phone string `gorm:"column:contactPerson" json:"phone"`
  23. Remark string `gorm:"column:remark" json:"remark"`
  24. Longitude string `gorm:"column:longitude" json:"longitude"`
  25. Latitude string `gorm:"column:latitude" json:"latitude"`
  26. VerifyTime time.Time `gorm:"column:VerifyTime"`
  27. VerifyStatus int `gorm:"column:VerifyStatus"`
  28. Key string `gorm:"column:Key"`
  29. ProjectId int64 `gorm:"column:ProjectId"`
  30. ProviderId int64 `gorm:"column:ProviderId"`
  31. CreatedAt time.Time `gorm:"column:CreatedAt"`
  32. }
  33. func (SlagcarDevice) TableName() string {
  34. return "db_smart_v2.SlagcarDevice"
  35. }
  36. func (p *SlagcarDevice) Insert(db *gorm.DB) error {
  37. return db.Table(p.TableName()).Create(p).Error
  38. }
  39. func (p *SlagcarDevice) Del(db *gorm.DB, where map[string]interface{}) error {
  40. cond, val, err := whereBuild(where)
  41. if err != nil {
  42. return err
  43. }
  44. return db.Table(p.TableName()).Where(cond, val...).Delete(p).Error
  45. }
  46. func (p *SlagcarDevice) Find(db *gorm.DB, where map[string]interface{}) error {
  47. cond, val, err := whereBuild(where)
  48. if err != nil {
  49. return err
  50. }
  51. return db.Table(p.TableName()).Where(cond, val...).First(p).Error
  52. }
  53. func (p *SlagcarDevice) Update(db *gorm.DB, where map[string]interface{}, values map[string]interface{}) error {
  54. cond, val, err := whereBuild(where)
  55. if err != nil {
  56. return err
  57. }
  58. return db.Table(p.TableName()).Where(cond, val...).Updates(values).Error
  59. }
  60. func (p *SlagcarDevice) Save(db *gorm.DB) error {
  61. return db.Save(p).Error
  62. }
  63. func (p *SlagcarDevice) Count(db *gorm.DB, where map[string]interface{}) (int64, error) {
  64. if len(where) > 0 {
  65. cond, val, err := whereBuild(where)
  66. if err != nil {
  67. return 0, err
  68. }
  69. ret := int64(0)
  70. err = db.Table(p.TableName()).Where(cond, val...).Count(&ret).Error
  71. return ret, err
  72. }
  73. ret := int64(0)
  74. err := db.Table(p.TableName()).Count(&ret).Error
  75. return ret, err
  76. }
  77. func (p *SlagcarDevice) List(db *gorm.DB, where map[string]interface{}, page int) (list []SlagcarDevice, err error) {
  78. if len(where) > 0 {
  79. cond, val, err := whereBuild(where)
  80. if err != nil {
  81. return list, err
  82. }
  83. result := db.Table(p.TableName()).Where(cond, val...).Limit(10).Offset(page).Find(&list)
  84. return list, result.Error
  85. }
  86. result := db.Table(p.TableName()).Limit(10).Offset(page).Find(&list)
  87. return list, result.Error
  88. }