2023-08-14 07:07:12 +00:00
|
|
|
package gmodel
|
2023-08-14 06:40:50 +00:00
|
|
|
|
2023-08-14 07:08:24 +00:00
|
|
|
// TODO: 使用model的属性做你想做的
|
|
|
|
|
2023-08-14 06:40:50 +00:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fusenapi/utils/handlers"
|
|
|
|
|
|
|
|
"gorm.io/gorm"
|
|
|
|
)
|
|
|
|
|
|
|
|
// TODO: 使用model的属性做你想做的
|
|
|
|
|
|
|
|
func (m *FsUserInfoModel) BuilderDB(ctx context.Context, selectData []string) *gorm.DB {
|
|
|
|
if selectData != nil {
|
|
|
|
return m.db.WithContext(ctx).Select(selectData)
|
|
|
|
} else {
|
|
|
|
return m.db.WithContext(ctx).Select("*")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *FsUserInfoModel) FindOne(gormDB *gorm.DB, filterMap map[string]string) (*FsUserInfo, error) {
|
|
|
|
var resp FsUserInfo
|
|
|
|
|
|
|
|
if filterMap != nil {
|
|
|
|
gormDB = gormDB.Scopes(handlers.FilterData(filterMap))
|
|
|
|
}
|
|
|
|
|
|
|
|
result := gormDB.Limit(1).Find(&resp)
|
|
|
|
if result.Error != nil {
|
|
|
|
return nil, result.Error
|
|
|
|
} else {
|
|
|
|
return &resp, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *FsUserInfoModel) CreateOrUpdate(gormDB *gorm.DB, req *FsUserInfo) (resp *FsUserInfo, err error) {
|
|
|
|
if req.Id > 0 {
|
|
|
|
err = gormDB.Save(req).Error
|
|
|
|
} else {
|
|
|
|
err = gormDB.Create(req).Error
|
|
|
|
}
|
|
|
|
return req, err
|
|
|
|
}
|