获取用户菜单列表,新增医生管理
This commit is contained in:
@@ -0,0 +1,202 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"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
|
||||
}
|
||||
|
||||
// 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, userId int64, data interface{}) error {
|
||||
err := tx.Model(&model.UserDoctor{}).Where("doctor_id = ?", userId).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
|
||||
}
|
||||
|
||||
// GetUserDoctorDaoPageSearch 获取医生列表-分页
|
||||
func (r *UserDoctorDao) GetUserDoctorDaoPageSearch(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 = ?", getUserDoctorPage.UserName)
|
||||
}
|
||||
|
||||
// 状态
|
||||
if getUserDoctorPage.UserStatus != 0 {
|
||||
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 != 0 {
|
||||
query = query.Where("idcard_status = ?", getUserDoctorPage.IDCardStatus)
|
||||
}
|
||||
|
||||
// 身份认证状态
|
||||
if getUserDoctorPage.IdenAuthStatus != 0 {
|
||||
query = query.Where("iden_auth_status = ?", getUserDoctorPage.IdenAuthStatus)
|
||||
}
|
||||
|
||||
// 医生多点执业认证状态
|
||||
if getUserDoctorPage.MultiPointStatus != 0 {
|
||||
query = query.Where("multi_point_status = ?", getUserDoctorPage.MultiPointStatus)
|
||||
}
|
||||
|
||||
// 是否首页推荐
|
||||
if getUserDoctorPage.IsRecommend != 0 {
|
||||
query = query.Where("is_recommend = ?", getUserDoctorPage.IsRecommend)
|
||||
}
|
||||
|
||||
if getUserDoctorPage.DoctorTitle != 0 {
|
||||
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 != 0 {
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user