staff.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 TStaff struct {
  9. Id int64 `gorm:"column:id"`
  10. ProjectId int64 `gorm:"column:project_id"`
  11. WorkNo string `gorm:"column:work_no"`
  12. Name string `gorm:"column:name"`
  13. IdCert string `gorm:"column:id_cert"`
  14. Gender int64 `gorm:"column:gender"`
  15. StaffType int64 `gorm:"column:staff_type"`
  16. Birthday string `gorm:"column:birthday"`
  17. Address string `gorm:"column:address"`
  18. IdIssue string `gorm:"column:id_issue"`
  19. IdPeriod string `gorm:"column:id_period"`
  20. IdPhoto string `gorm:"column:id_photo"`
  21. Photo string `gorm:"column:photo"`
  22. InfPhoto string `gorm:"column:inf_photo"`
  23. Sn string `gorm:"column:sn"`
  24. Status int64 `gorm:"column:status"`
  25. Phone string `gorm:"column:phone"`
  26. WorkType string `gorm:"column:work_type"`
  27. LaborCompany string `gorm:"column:labor_company"`
  28. Group string `gorm:"column:group"`
  29. IsDelete int64 `gorm:"column:is_delete"`
  30. CreatedAt time.Time `gorm:"column:created_at"`
  31. UpdatedAt time.Time `gorm:"column:updated_at"`
  32. }
  33. func (TStaff) TableName() string {
  34. return "db_smart_staff.t_staff"
  35. }
  36. func (p *TStaff) Insert(db *gorm.DB) error {
  37. return db.Create(p).Error
  38. }
  39. func (p *TStaff) 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 *TStaff) 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 *TStaff) 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 *TStaff) Save(db *gorm.DB) error {
  61. return db.Save(p).Error
  62. }
  63. func (p *TStaff) 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 *TStaff) List(db *gorm.DB, where map[string]interface{}, page int) (list []TStaff, 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(PageSize).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. }
  89. func (p *TStaff) All(db *gorm.DB) (list []TStaff, err error) {
  90. result := db.Table(p.TableName()).Find(&list)
  91. return list, result.Error
  92. }