91 lines
2.5 KiB
Go
91 lines
2.5 KiB
Go
package dao
|
|
|
|
import (
|
|
"gorm.io/gorm"
|
|
"hospital-admin-api/api/model"
|
|
"hospital-admin-api/global"
|
|
)
|
|
|
|
type DoctorAccountDao struct {
|
|
}
|
|
|
|
// GetDoctorAccountById 获取医生账户数据-账户id
|
|
func (r *DoctorAccountDao) GetDoctorAccountById(accountId int64) (m *model.DoctorAccount, err error) {
|
|
err = global.Db.First(&m, accountId).Error
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return m, nil
|
|
}
|
|
|
|
// GetDoctorAccountByDoctorId 获取医生账户数据-医生id
|
|
func (r *DoctorAccountDao) GetDoctorAccountByDoctorId(doctorId int64) (m *model.DoctorAccount, err error) {
|
|
err = global.Db.Where("doctor_id = ?", doctorId).First(&m).Error
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return m, nil
|
|
}
|
|
|
|
// DeleteDoctorAccount 删除医生账户
|
|
func (r *DoctorAccountDao) DeleteDoctorAccount(tx *gorm.DB, maps interface{}) error {
|
|
err := tx.Where(maps).Delete(&model.DoctorAccount{}).Error
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// EditDoctorAccount 修改医生账户
|
|
func (r *DoctorAccountDao) EditDoctorAccount(tx *gorm.DB, maps interface{}, data interface{}) error {
|
|
err := tx.Model(&model.DoctorAccount{}).Where(maps).Updates(data).Error
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// EditDoctorAccountById 修改医生账户-医生账户id
|
|
func (r *DoctorAccountDao) EditDoctorAccountById(tx *gorm.DB, accountId int64, data interface{}) error {
|
|
err := tx.Model(&model.DoctorAccount{}).Where("account_id = ?", accountId).Updates(data).Error
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// GetDoctorAccountList 获取医生账户列表
|
|
func (r *DoctorAccountDao) GetDoctorAccountList(maps interface{}) (m []*model.DoctorAccount, err error) {
|
|
err = global.Db.Where(maps).Find(&m).Error
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return m, nil
|
|
}
|
|
|
|
// AddDoctorAccount 新增医生账户
|
|
func (r *DoctorAccountDao) AddDoctorAccount(tx *gorm.DB, model *model.DoctorAccount) (*model.DoctorAccount, error) {
|
|
if err := tx.Create(model).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
return model, nil
|
|
}
|
|
|
|
// Dec 自减
|
|
func (r *DoctorAccountDao) Dec(tx *gorm.DB, maps interface{}, numeral float64, field string) error {
|
|
err := tx.Model(&model.DoctorAccount{}).Where(maps).Update(field, gorm.Expr(field+" - ?", numeral)).Error
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Inc 自增
|
|
func (r *DoctorAccountDao) Inc(tx *gorm.DB, maps interface{}, numeral float64, field string) error {
|
|
err := tx.Model(&model.DoctorAccount{}).Where(maps).Update(field, gorm.Expr(field+" + ?", numeral)).Error
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|