99 lines
3.0 KiB
Go
99 lines
3.0 KiB
Go
package dao
|
|
|
|
import (
|
|
"gorm.io/gorm"
|
|
"gorm.io/gorm/clause"
|
|
"hospital-admin-api/api/model"
|
|
"hospital-admin-api/global"
|
|
)
|
|
|
|
type UserPharmacistInfoDao struct {
|
|
}
|
|
|
|
// GetUserPharmacistInfoById 获取药师详情数据-药师详情id
|
|
func (r *UserPharmacistInfoDao) GetUserPharmacistInfoById(infoId int64) (m *model.UserPharmacistInfo, err error) {
|
|
err = global.Db.First(&m, infoId).Error
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return m, nil
|
|
}
|
|
|
|
func (r *UserPharmacistInfoDao) GetUserPharmacistInfoByUserId(userId int64) (m *model.UserPharmacistInfo, err error) {
|
|
err = global.Db.Where("user_id = ?", userId).First(&m).Error
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return m, nil
|
|
}
|
|
|
|
func (r *UserPharmacistInfoDao) GetUserPharmacistInfoByPharmacistId(pharmacistId int64) (m *model.UserPharmacistInfo, err error) {
|
|
err = global.Db.Where("pharmacist_id = ?", pharmacistId).First(&m).Error
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return m, nil
|
|
}
|
|
|
|
// GetUserPharmacistInfoPreloadById 获取药师详情数据-加载全部关联-药师详情id
|
|
func (r *UserPharmacistInfoDao) GetUserPharmacistInfoPreloadById(infoId int64) (m *model.UserPharmacistInfo, err error) {
|
|
err = global.Db.Preload(clause.Associations).First(&m, infoId).Error
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return m, nil
|
|
}
|
|
|
|
// DeleteUserPharmacistInfo 删除药师详情
|
|
func (r *UserPharmacistInfoDao) DeleteUserPharmacistInfo(tx *gorm.DB, maps interface{}) error {
|
|
err := tx.Where(maps).Delete(&model.UserPharmacistInfo{}).Error
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// EditUserPharmacistInfo 修改药师详情
|
|
func (r *UserPharmacistInfoDao) EditUserPharmacistInfo(tx *gorm.DB, maps interface{}, data interface{}) error {
|
|
err := tx.Model(&model.UserPharmacistInfo{}).Where(maps).Updates(data).Error
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// EditUserPharmacistInfoByUserId 修改药师详情-药师详情id
|
|
func (r *UserPharmacistInfoDao) EditUserPharmacistInfoByUserId(tx *gorm.DB, userId int64, data interface{}) error {
|
|
err := tx.Model(&model.UserPharmacistInfo{}).Where("user_id = ?", userId).Updates(data).Error
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// EditUserPharmacistInfoByPharmacistId 修改药师详情-药师详情id
|
|
func (r *UserPharmacistInfoDao) EditUserPharmacistInfoByPharmacistId(tx *gorm.DB, pharmacistId int64, data interface{}) error {
|
|
err := tx.Model(&model.UserPharmacistInfo{}).Where("pharmacist_id = ?", pharmacistId).Updates(data).Error
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// GetUserPharmacistInfoList 获取药师详情列表
|
|
func (r *UserPharmacistInfoDao) GetUserPharmacistInfoList(maps interface{}) (m []*model.UserPharmacistInfo, err error) {
|
|
err = global.Db.Where(maps).Find(&m).Error
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return m, nil
|
|
}
|
|
|
|
// AddUserPharmacistInfo 新增药师详情
|
|
func (r *UserPharmacistInfoDao) AddUserPharmacistInfo(tx *gorm.DB, model *model.UserPharmacistInfo) (*model.UserPharmacistInfo, error) {
|
|
if err := tx.Create(model).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
return model, nil
|
|
}
|