332 lines
8.9 KiB
Go
332 lines
8.9 KiB
Go
package dao
|
|
|
|
import (
|
|
"gorm.io/gorm"
|
|
"gorm.io/gorm/clause"
|
|
"hospital-admin-api/api/model"
|
|
"hospital-admin-api/api/requests"
|
|
"hospital-admin-api/global"
|
|
"strings"
|
|
)
|
|
|
|
type UserDoctorDao struct {
|
|
}
|
|
|
|
// GetUserDoctorById 获取医生数据-医生id
|
|
func (r *UserDoctorDao) GetUserDoctorById(doctorId int64) (m *model.UserDoctor, err error) {
|
|
err = global.Db.First(&m, doctorId).Error
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return m, nil
|
|
}
|
|
|
|
// GetUserDoctorPreloadById 获取医生数据-加载全部关联-医生id
|
|
func (r *UserDoctorDao) GetUserDoctorPreloadById(doctorId int64) (m *model.UserDoctor, err error) {
|
|
err = global.Db.Preload(clause.Associations).First(&m, doctorId).Error
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return m, nil
|
|
}
|
|
|
|
// DeleteUserDoctor 删除医生
|
|
func (r *UserDoctorDao) DeleteUserDoctor(tx *gorm.DB, maps interface{}) error {
|
|
err := tx.Where(maps).Delete(&model.UserDoctor{}).Error
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// DeleteUserDoctorById 删除医生-医生id
|
|
func (r *UserDoctorDao) DeleteUserDoctorById(tx *gorm.DB, userId int64) error {
|
|
if err := tx.Delete(&model.UserDoctor{}, userId).Error; err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// EditUserDoctor 修改医生
|
|
func (r *UserDoctorDao) EditUserDoctor(tx *gorm.DB, maps interface{}, data interface{}) error {
|
|
err := tx.Model(&model.UserDoctor{}).Where(maps).Updates(data).Error
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// EditUserDoctorById 修改医生-医生id
|
|
func (r *UserDoctorDao) EditUserDoctorById(tx *gorm.DB, doctorId int64, data interface{}) error {
|
|
err := tx.Model(&model.UserDoctor{}).Where("doctor_id = ?", doctorId).Updates(data).Error
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// GetUserDoctorList 获取医生列表
|
|
func (r *UserDoctorDao) GetUserDoctorList(maps interface{}) (m []*model.UserDoctor, err error) {
|
|
err = global.Db.Where(maps).Find(&m).Error
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return m, nil
|
|
}
|
|
|
|
// GetUserDoctorPageSearch 获取医生列表-分页
|
|
func (r *UserDoctorDao) GetUserDoctorPageSearch(getUserDoctorPage requests.GetUserDoctorPage, page, pageSize int) (m []*model.UserDoctor, total int64, err error) {
|
|
var totalRecords int64
|
|
|
|
// 构建查询条件
|
|
query := global.Db.Model(&model.UserDoctor{}).Omit("open_id", "union_id", "wx_session_key")
|
|
|
|
// 用户
|
|
query = query.Preload("User", func(db *gorm.DB) *gorm.DB {
|
|
return db.Omit("user_password", "salt")
|
|
})
|
|
|
|
// 医院
|
|
query = query.Preload("Hospital", func(db *gorm.DB) *gorm.DB {
|
|
return db.Select("hospital_id,hospital_name,hospital_level_name")
|
|
})
|
|
|
|
// 手机号
|
|
if getUserDoctorPage.Mobile != "" {
|
|
subQuery := global.Db.Model(&model.User{}).
|
|
Select("user_id").
|
|
Where("mobile LIKE ?", "%"+getUserDoctorPage.Mobile+"%")
|
|
|
|
query = query.Where(gorm.Expr("user_id IN (?)", subQuery))
|
|
}
|
|
|
|
// 用户名称
|
|
if getUserDoctorPage.UserName != "" {
|
|
query = query.Where("user_name LIKE ?", "%"+getUserDoctorPage.UserName+"%")
|
|
}
|
|
|
|
// 状态
|
|
if getUserDoctorPage.UserStatus != nil {
|
|
query = query.Where("status = ?", getUserDoctorPage.UserStatus)
|
|
}
|
|
|
|
// 医院名称
|
|
if getUserDoctorPage.HospitalName != "" {
|
|
subQuery := global.Db.Model(&model.Hospital{}).
|
|
Select("hospital_id").
|
|
Where("hospital_name LIKE ?", "%"+getUserDoctorPage.HospitalName+"%")
|
|
|
|
query = query.Where(gorm.Expr("hospital_id IN (?)", subQuery))
|
|
}
|
|
|
|
// 科室名称
|
|
if getUserDoctorPage.DepartmentCustomName != "" {
|
|
query = query.Where("department_custom_name = ?", getUserDoctorPage.DepartmentCustomName)
|
|
}
|
|
|
|
// 实名认证状态
|
|
if getUserDoctorPage.IDCardStatus != nil {
|
|
query = query.Where("idcard_status = ?", getUserDoctorPage.IDCardStatus)
|
|
}
|
|
|
|
// 身份认证状态
|
|
if getUserDoctorPage.IdenAuthStatus != nil {
|
|
query = query.Where("iden_auth_status = ?", getUserDoctorPage.IdenAuthStatus)
|
|
}
|
|
|
|
// 医生多点执业认证状态
|
|
if getUserDoctorPage.MultiPointStatus != nil {
|
|
query = query.Where("multi_point_status = ?", getUserDoctorPage.MultiPointStatus)
|
|
}
|
|
|
|
// 是否首页推荐
|
|
if getUserDoctorPage.IsRecommend != nil {
|
|
query = query.Where("is_recommend = ?", getUserDoctorPage.IsRecommend)
|
|
}
|
|
|
|
if getUserDoctorPage.DoctorTitle != nil {
|
|
query = query.Where("doctor_title = ?", getUserDoctorPage.DoctorTitle)
|
|
}
|
|
|
|
// 问诊类型
|
|
if getUserDoctorPage.InquiryService != "" {
|
|
result := strings.Split(getUserDoctorPage.InquiryService, ",")
|
|
if len(result) > 0 {
|
|
subQuery := global.Db
|
|
for _, v := range result {
|
|
if v == "1" {
|
|
subQuery = subQuery.Where("is_img_expert_reception = ?", 1)
|
|
}
|
|
|
|
if v == "2" {
|
|
if subQuery != nil {
|
|
subQuery = subQuery.Or("is_img_quick_reception = ?", 1)
|
|
} else {
|
|
subQuery = subQuery.Where("is_img_quick_reception = ?", 1)
|
|
}
|
|
}
|
|
|
|
if v == "3" {
|
|
if subQuery != nil {
|
|
subQuery = subQuery.Or("is_img_welfare_reception = ?", 1)
|
|
} else {
|
|
subQuery = subQuery.Where("is_img_welfare_reception = ?", 1)
|
|
}
|
|
}
|
|
|
|
if v == "4" {
|
|
if subQuery != nil {
|
|
subQuery = subQuery.Or("multi_point_status = ?", 1)
|
|
} else {
|
|
subQuery = subQuery.Where("multi_point_status = ?", 1)
|
|
}
|
|
}
|
|
|
|
}
|
|
query = query.Where(subQuery)
|
|
}
|
|
|
|
}
|
|
|
|
if getUserDoctorPage.IsEnterpriseDeepCooperation != nil {
|
|
query = query.Where("doctor_title = ?", getUserDoctorPage.DoctorTitle)
|
|
}
|
|
|
|
// 查询总数量
|
|
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
|
|
}
|
|
|
|
// AddUserDoctor 新增医生
|
|
func (r *UserDoctorDao) AddUserDoctor(tx *gorm.DB, model *model.UserDoctor) (*model.UserDoctor, error) {
|
|
if err := tx.Create(model).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
return model, nil
|
|
}
|
|
|
|
// GetUserDoctorPendingPageSearch 身份审核-获取医生列表-分页
|
|
func (r *UserDoctorDao) GetUserDoctorPendingPageSearch(p requests.GetUserDoctorPendingPage, page, pageSize int) (m []*model.UserDoctor, total int64, err error) {
|
|
var totalRecords int64
|
|
|
|
// 构建查询条件
|
|
query := global.Db.Model(&model.UserDoctor{}).Omit("open_id", "union_id", "wx_session_key")
|
|
|
|
// 用户
|
|
query = query.Preload("User", func(db *gorm.DB) *gorm.DB {
|
|
return db.Omit("user_password", "salt")
|
|
})
|
|
|
|
// 医院
|
|
query = query.Preload("Hospital", func(db *gorm.DB) *gorm.DB {
|
|
return db.Select("hospital_id,hospital_name,hospital_level_name")
|
|
})
|
|
|
|
// 手机号
|
|
if p.Mobile != "" {
|
|
subQuery := global.Db.Model(&model.User{}).
|
|
Select("user_id").
|
|
Where("mobile LIKE ?", "%"+p.Mobile+"%")
|
|
|
|
query = query.Where(gorm.Expr("user_id IN (?)", subQuery))
|
|
}
|
|
|
|
// 用户名称
|
|
if p.UserName != "" {
|
|
query = query.Where("user_name LIKE ?", "%"+p.UserName+"%")
|
|
}
|
|
|
|
// 身份认证状态
|
|
if p.IdenAuthStatus != nil {
|
|
query = query.Where("iden_auth_status = ?", p.IdenAuthStatus)
|
|
} else {
|
|
query = query.Where("iden_auth_status IN ?", []string{"2", "3"})
|
|
}
|
|
|
|
// 医院名称
|
|
if p.HospitalName != "" {
|
|
subQuery := global.Db.Model(&model.Hospital{}).
|
|
Select("hospital_id").
|
|
Where("hospital_name LIKE ?", "%"+p.HospitalName+"%")
|
|
|
|
query = query.Where(gorm.Expr("hospital_id IN (?)", subQuery))
|
|
}
|
|
|
|
// 查询总数量
|
|
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
|
|
}
|
|
|
|
// GetUserDoctorMultiPageSearch 多点-获取医生列表-分页
|
|
func (r *UserDoctorDao) GetUserDoctorMultiPageSearch(p requests.GetMultiPage, page, pageSize int) (m []*model.UserDoctor, total int64, err error) {
|
|
var totalRecords int64
|
|
|
|
// 构建查询条件
|
|
query := global.Db.Model(&model.UserDoctor{}).Omit("open_id", "union_id", "wx_session_key")
|
|
|
|
// 用户
|
|
query = query.Preload("User", func(db *gorm.DB) *gorm.DB {
|
|
return db.Omit("user_password", "salt")
|
|
})
|
|
|
|
// 医院
|
|
query = query.Preload("Hospital", func(db *gorm.DB) *gorm.DB {
|
|
return db.Select("hospital_id,hospital_name,hospital_level_name")
|
|
})
|
|
|
|
// 手机号
|
|
if p.Mobile != "" {
|
|
subQuery := global.Db.Model(&model.User{}).
|
|
Select("user_id").
|
|
Where("mobile LIKE ?", "%"+p.Mobile+"%")
|
|
|
|
query = query.Where(gorm.Expr("user_id IN (?)", subQuery))
|
|
}
|
|
|
|
// 用户名称
|
|
if p.UserName != "" {
|
|
query = query.Where("user_name LIKE ?", "%"+p.UserName+"%")
|
|
}
|
|
|
|
// 身份认证状态
|
|
if p.MultiPointStatus != nil {
|
|
query = query.Where("multi_point_status = ?", p.MultiPointStatus)
|
|
} else {
|
|
query = query.Where("multi_point_status IN ?", []string{"2", "3"})
|
|
}
|
|
|
|
// 医院名称
|
|
if p.HospitalName != "" {
|
|
subQuery := global.Db.Model(&model.Hospital{}).
|
|
Select("hospital_id").
|
|
Where("hospital_name LIKE ?", "%"+p.HospitalName+"%")
|
|
|
|
query = query.Where(gorm.Expr("hospital_id IN (?)", subQuery))
|
|
}
|
|
|
|
// 查询总数量
|
|
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
|
|
}
|