合并冲突
This commit is contained in:
@@ -2,48 +2,46 @@ package gmodel
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
"errors"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func (d *LdapDepartmentModel) GetOneById(ctx context.Context, id int64) (resp LdapDepartment, err error) {
|
||||
db := d.db.WithContext(ctx).Model(&FsShoppingCart{})
|
||||
return resp, db.Take(&resp).Error
|
||||
}
|
||||
|
||||
func (d *LdapDepartmentModel) GetList(ctx context.Context, page, pageSize int, sort string) (resp []LdapDepartment, total int64, err error) {
|
||||
db := d.db.WithContext(ctx).Model(&FsShoppingCart{})
|
||||
// 获取列表
|
||||
func (d *LdapDepartmentModel) GetAll(ctx context.Context, sort string) (resp []LdapDepartment, total int64, err error) {
|
||||
db := d.db.WithContext(ctx).Model(&LdapDepartment{})
|
||||
if sort != "" {
|
||||
db = db.Order(sort)
|
||||
}
|
||||
//查询数量
|
||||
if err = db.Limit(1).Count(&total).Error; err != nil {
|
||||
if err = db.Count(&total).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
offset := (page - 1) * pageSize
|
||||
err = db.Offset(offset).Limit(pageSize).Find(&resp).Error
|
||||
err = db.Find(&resp).Error
|
||||
return resp, total, err
|
||||
}
|
||||
|
||||
// InsertOne 单个插入
|
||||
func (d *LdapDepartmentModel) InsertOne(ctx context.Context, insertData LdapDepartment) error {
|
||||
var nowTime = time.Now().UTC()
|
||||
|
||||
insertData.Ctime = &nowTime
|
||||
insertData.Utime = &nowTime
|
||||
result := d.db.WithContext(ctx).Model(&LdapDepartment{}).Create(&insertData)
|
||||
if result.Error != nil {
|
||||
return result.Error
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
func (d *LdapDepartmentModel) FindOne(ctx context.Context, id int64) (resp *LdapDepartment, err error) {
|
||||
err = d.db.WithContext(ctx).Model(&LdapDepartment{}).Where("id = ?", id).Take(&resp).Error
|
||||
return resp, err
|
||||
}
|
||||
|
||||
// UpdateOne 单个更新
|
||||
func (d *LdapDepartmentModel) UpdateOne(ctx context.Context, Department LdapDepartment, updateData map[string]interface{}) error {
|
||||
result := d.db.WithContext(ctx).Model(&Department).Updates(updateData)
|
||||
if result.Error != nil {
|
||||
return result.Error
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
// 更新
|
||||
func (d *LdapDepartmentModel) Update(ctx context.Context, id int64, data *LdapDepartment) error {
|
||||
return d.db.WithContext(ctx).Model(&LdapDepartment{}).Where("id = ?", id).Updates(&data).Error
|
||||
}
|
||||
|
||||
// 创建
|
||||
func (d *LdapDepartmentModel) Create(ctx context.Context, data *LdapDepartment) error {
|
||||
return d.db.WithContext(ctx).Model(&LdapDepartment{}).Create(&data).Error
|
||||
}
|
||||
|
||||
func (d *LdapDepartmentModel) CreateOrUpdate(ctx context.Context, id int64, data *LdapDepartment) error {
|
||||
_, err := d.FindOne(ctx, id)
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return d.Create(ctx, data)
|
||||
}
|
||||
return err
|
||||
}
|
||||
return d.Update(ctx, id, data)
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ type LdapUsers struct {
|
||||
Password *string `gorm:"default:'';" json:"password"` //
|
||||
Nickname *string `gorm:"default:'';" json:"nickname"` //
|
||||
GivenName *string `gorm:"default:'';" json:"given_name"` //
|
||||
Email *string `gorm:"default:'';" json:"email"` //
|
||||
Email *string `gorm:"unique_key;default:'';" json:"email"` //
|
||||
JobNumber *string `gorm:"default:'';" json:"job_number"` //
|
||||
Mobile *string `gorm:"unique_key;default:'';" json:"mobile"` //
|
||||
Avatar *string `gorm:"default:'';" json:"avatar"` //
|
||||
|
||||
Reference in New Issue
Block a user