dws26.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // Copyright 2026 autocareai.com. All rights reserved.
  2. // Use of this source code is governed by autocareai.com.
  3. package model
  4. import (
  5. "gorm.io/gorm"
  6. "time"
  7. )
  8. type Dws26 struct {
  9. ID int64 `gorm:"primary_key" json:"-"`
  10. IdCard string `json:"id_card"`
  11. Name string `json:"name"`
  12. IsDoubleFirstClassUniversity string `json:"is_double_first_class_university"`
  13. IsTwoOneOneUniversity string `json:"is_two_one_one_university"`
  14. EndDate string `json:"end_date"`
  15. TypeName string `json:"type_name"`
  16. EduCode string `json:"edu_code"`
  17. QualificationCode string `json:"qualification_code"`
  18. MajorCategory string `json:"major_category"`
  19. EduName string `json:"edu_name"`
  20. QualificationName string `json:"qualification_name"`
  21. TypeCode string `json:"type_code"`
  22. SecondaryCategory string `json:"secondary_category"`
  23. BeginDate string `json:"begin_date"`
  24. MajorCode string `json:"major_code"`
  25. IsNineEightFiveUniversity string `json:"is_nine_eight_five_university"`
  26. CreatedAt int64 `json:"-"`
  27. UpdatedAt int64 `json:"-"`
  28. }
  29. func (Dws26) TableName() string {
  30. return "t_adm_dws26"
  31. }
  32. // Insert 插入一条记录
  33. func (p *Dws26) Insert(db *gorm.DB) error {
  34. timeNow := time.Now().Unix()
  35. p.CreatedAt = timeNow
  36. p.UpdatedAt = timeNow
  37. err := db.Create(p).Error
  38. return err
  39. }
  40. func (p *Dws26) InsertByMap(db *gorm.DB, data map[string]interface{}) error {
  41. data["updated_at"] = time.Now().Unix()
  42. err := db.Model(p).Create(data).Error
  43. return err
  44. }
  45. func (p *Dws26) Delete(db *gorm.DB, filter map[string]interface{}) error {
  46. err := db.Where(filter).Delete(p).Error
  47. return err
  48. }
  49. func (p *Dws26) Save(db *gorm.DB) error {
  50. timeNow := time.Now().Unix()
  51. p.UpdatedAt = timeNow
  52. //db.Model().Update()
  53. err := db.Save(p).Error
  54. return err
  55. }
  56. func (p *Dws26) Update(db *gorm.DB) error {
  57. timeNow := time.Now().Unix()
  58. p.CreatedAt = 0
  59. p.UpdatedAt = timeNow
  60. err := db.Model(p).Updates(p).Error
  61. return err
  62. }
  63. func (p *Dws26) UpdateByMap(db *gorm.DB, data map[string]interface{}) error {
  64. data["updated_at"] = time.Now().Unix()
  65. err := db.Model(p).Updates(data).Error
  66. return err
  67. }
  68. // 通过结构体变量更新字段值, gorm库会忽略零值字段。就是字段值等于0, nil, "", false这些值会被忽略掉,不会更新。如果想更新零值,可以使用map类型替代结构体。
  69. func (p *Dws26) UpdateSome(db *gorm.DB, filed map[string]interface{}) error {
  70. /*if filed == nil {
  71. return errors.ParamsError
  72. }*/
  73. timeNow := time.Now().Unix()
  74. filed["updated_at"] = timeNow
  75. err := db.Model(p).Updates(filed).Error
  76. return err
  77. }
  78. func (p *Dws26) Query(db *gorm.DB, filter map[string]interface{}) error {
  79. err := db.Where(filter).Find(p).Error
  80. if p.ID == 0 {
  81. return gorm.ErrRecordNotFound
  82. }
  83. return err
  84. }
  85. func (p *Dws26) QueryAll(db *gorm.DB, filter map[string]interface{}, out interface{}) error {
  86. err := db.Where(filter).Find(out).Error
  87. return err
  88. }