123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- // Copyright 2026 autocareai.com. All rights reserved.
- // Use of this source code is governed by autocareai.com.
- package model
- import (
- "gorm.io/gorm"
- "time"
- )
- type Dws26 struct {
- ID int64 `gorm:"primary_key" json:"-"`
- IdCard string `json:"id_card"`
- Name string `json:"name"`
- IsDoubleFirstClassUniversity string `json:"is_double_first_class_university"`
- IsTwoOneOneUniversity string `json:"is_two_one_one_university"`
- EndDate string `json:"end_date"`
- TypeName string `json:"type_name"`
- EduCode string `json:"edu_code"`
- QualificationCode string `json:"qualification_code"`
- MajorCategory string `json:"major_category"`
- EduName string `json:"edu_name"`
- QualificationName string `json:"qualification_name"`
- TypeCode string `json:"type_code"`
- SecondaryCategory string `json:"secondary_category"`
- BeginDate string `json:"begin_date"`
- MajorCode string `json:"major_code"`
- IsNineEightFiveUniversity string `json:"is_nine_eight_five_university"`
- CreatedAt int64 `json:"-"`
- UpdatedAt int64 `json:"-"`
- }
- func (Dws26) TableName() string {
- return "t_adm_dws26"
- }
- // Insert 插入一条记录
- func (p *Dws26) Insert(db *gorm.DB) error {
- timeNow := time.Now().Unix()
- p.CreatedAt = timeNow
- p.UpdatedAt = timeNow
- err := db.Create(p).Error
- return err
- }
- func (p *Dws26) InsertByMap(db *gorm.DB, data map[string]interface{}) error {
- data["updated_at"] = time.Now().Unix()
- err := db.Model(p).Create(data).Error
- return err
- }
- func (p *Dws26) Delete(db *gorm.DB, filter map[string]interface{}) error {
- err := db.Where(filter).Delete(p).Error
- return err
- }
- func (p *Dws26) Save(db *gorm.DB) error {
- timeNow := time.Now().Unix()
- p.UpdatedAt = timeNow
- //db.Model().Update()
- err := db.Save(p).Error
- return err
- }
- func (p *Dws26) Update(db *gorm.DB) error {
- timeNow := time.Now().Unix()
- p.CreatedAt = 0
- p.UpdatedAt = timeNow
- err := db.Model(p).Updates(p).Error
- return err
- }
- func (p *Dws26) UpdateByMap(db *gorm.DB, data map[string]interface{}) error {
- data["updated_at"] = time.Now().Unix()
- err := db.Model(p).Updates(data).Error
- return err
- }
- // 通过结构体变量更新字段值, gorm库会忽略零值字段。就是字段值等于0, nil, "", false这些值会被忽略掉,不会更新。如果想更新零值,可以使用map类型替代结构体。
- func (p *Dws26) UpdateSome(db *gorm.DB, filed map[string]interface{}) error {
- /*if filed == nil {
- return errors.ParamsError
- }*/
- timeNow := time.Now().Unix()
- filed["updated_at"] = timeNow
- err := db.Model(p).Updates(filed).Error
- return err
- }
- func (p *Dws26) Query(db *gorm.DB, filter map[string]interface{}) error {
- err := db.Where(filter).Find(p).Error
- if p.ID == 0 {
- return gorm.ErrRecordNotFound
- }
- return err
- }
- func (p *Dws26) QueryAll(db *gorm.DB, filter map[string]interface{}, out interface{}) error {
- err := db.Where(filter).Find(out).Error
- return err
- }
|