135 lines
3.7 KiB
Go
135 lines
3.7 KiB
Go
package dao
|
|
|
|
import (
|
|
"gorm.io/gorm"
|
|
"hospital-admin-api/api/model"
|
|
"hospital-admin-api/api/requests"
|
|
"hospital-admin-api/global"
|
|
)
|
|
|
|
type DoctorInquiryConfigDao struct {
|
|
}
|
|
|
|
// GetDoctorInquiryConfigListByDoctorId 获取医生问诊配置数据列表-医生id
|
|
func (r *DoctorInquiryConfigDao) GetDoctorInquiryConfigListByDoctorId(doctorId int64) (m []*model.DoctorInquiryConfig, err error) {
|
|
err = global.Db.Where("doctor_id = ?", doctorId).Find(&m).Error
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return m, nil
|
|
}
|
|
|
|
// DeleteDoctorInquiryConfig 删除医生问诊配置
|
|
func (r *DoctorInquiryConfigDao) DeleteDoctorInquiryConfig(tx *gorm.DB, maps interface{}) error {
|
|
err := tx.Where(maps).Delete(&model.DoctorInquiryConfig{}).Error
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// EditDoctorInquiryConfigById 修改医生问诊配置-问诊配置id
|
|
func (r *DoctorInquiryConfigDao) EditDoctorInquiryConfigById(tx *gorm.DB, inquiryConfigId int64, data interface{}) error {
|
|
err := tx.Model(&model.DoctorInquiryConfig{}).Where("inquiry_config_id = ?", inquiryConfigId).Updates(data).Error
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// GetDoctorInquiryConfigList 获取医生问诊配置列表
|
|
func (r *DoctorInquiryConfigDao) GetDoctorInquiryConfigList(maps interface{}) (m []*model.DoctorInquiryConfig, err error) {
|
|
err = global.Db.Where(maps).Find(&m).Error
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return m, nil
|
|
}
|
|
|
|
// AddDoctorInquiryConfig 新增医生问诊配置
|
|
func (r *DoctorInquiryConfigDao) AddDoctorInquiryConfig(tx *gorm.DB, model *model.DoctorInquiryConfig) (*model.DoctorInquiryConfig, error) {
|
|
if err := tx.Create(model).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
return model, nil
|
|
}
|
|
|
|
// GetDoctorInquiryConfig 获取医生问诊配置
|
|
func (r *DoctorInquiryConfigDao) GetDoctorInquiryConfig(maps interface{}) (m *model.DoctorInquiryConfig, err error) {
|
|
err = global.Db.Where(maps).First(&m).Error
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return m, nil
|
|
}
|
|
|
|
// GetUserDoctorPageSearch 获取医生列表-分页
|
|
func (r *DoctorInquiryConfigDao) GetUserDoctorPageSearch(req requests.GetDoctorInquiryConfigPage, page, pageSize int) (m []*model.DoctorInquiryConfig, total int64, err error) {
|
|
var totalRecords int64
|
|
|
|
// 构建查询条件
|
|
query := global.Db.Model(&model.DoctorInquiryConfig{})
|
|
|
|
// 医生
|
|
query = query.Preload("UserDoctor", func(db *gorm.DB) *gorm.DB {
|
|
return db.Omit("open_id", "union_id", "wx_session_key")
|
|
})
|
|
|
|
// 用户表
|
|
query = query.Preload("UserDoctor.User", func(db *gorm.DB) *gorm.DB {
|
|
return db.Omit("user_password", "salt")
|
|
})
|
|
|
|
// 手机号
|
|
if req.Mobile != "" {
|
|
// 医生
|
|
doctorUserSubQuery := global.Db.Model(&model.User{}).
|
|
Select("user_id").
|
|
Where("mobile = ?", req.Mobile)
|
|
|
|
doctorSubQuery := global.Db.Model(&model.UserDoctor{}).
|
|
Select("doctor_id").
|
|
Where(gorm.Expr("user_id IN (?)", doctorUserSubQuery))
|
|
|
|
query = query.Where("doctor_id IN (?)", doctorSubQuery)
|
|
}
|
|
|
|
// 医生姓名
|
|
if req.DoctorName != "" {
|
|
subQuery := global.Db.Model(&model.UserDoctor{}).
|
|
Select("doctor_id").
|
|
Where("user_name LIKE ?", "%"+req.DoctorName+"%")
|
|
|
|
query = query.Where("doctor_id IN (?)", subQuery)
|
|
}
|
|
|
|
// 问诊类型
|
|
if req.InquiryType != nil {
|
|
query = query.Where("inquiry_type = ?", req.InquiryType)
|
|
}
|
|
|
|
// 问诊方式
|
|
if req.InquiryMode != nil {
|
|
query = query.Where("inquiry_mode = ?", req.InquiryMode)
|
|
}
|
|
|
|
// 是否启用
|
|
if req.IsEnable != nil {
|
|
query = query.Where("is_enable = ?", req.IsEnable)
|
|
}
|
|
|
|
// 排序
|
|
query = query.Order("created_at desc")
|
|
|
|
// 查询总数量
|
|
if err := query.Count(&totalRecords).Error; err != nil {
|
|
return nil, 0, err
|
|
}
|
|
|
|
err = query.Scopes(model.Paginate(page, pageSize)).Find(&m).Error
|
|
if err != nil {
|
|
return nil, 0, err
|
|
}
|
|
return m, totalRecords, nil
|
|
}
|