attendance_device.go 3.2 KB

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