fusenapi/model/gmodel/ldap_department_logic.go
2023-11-14 11:45:25 +08:00

50 lines
1.3 KiB
Go

package gmodel
import (
"context"
"time"
)
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{})
if sort != "" {
db = db.Order(sort)
}
//查询数量
if err = db.Limit(1).Count(&total).Error; err != nil {
return nil, 0, err
}
offset := (page - 1) * pageSize
err = db.Offset(offset).Limit(pageSize).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
}
}
// 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
}
}