医生列表-导出
This commit is contained in:
+158
-38
@@ -1,12 +1,14 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"hospital-admin-api/api/model"
|
||||
"hospital-admin-api/api/requests"
|
||||
"hospital-admin-api/global"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type UserDoctorDao struct {
|
||||
@@ -174,44 +176,20 @@ func (r *UserDoctorDao) GetUserDoctorPageSearch(req requests.GetUserDoctorPage,
|
||||
query = query.Where("doctor_title = ?", req.DoctorTitle)
|
||||
}
|
||||
|
||||
// // 问诊类型
|
||||
// if req.InquiryService != "" {
|
||||
// result := strings.Split(req.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 req.CreatedAt != "" {
|
||||
createdAt := strings.Split(req.CreatedAt, "&")
|
||||
if len(createdAt) == 2 {
|
||||
startTime, _ := time.Parse("2006-01-02", createdAt[0])
|
||||
endTime, _ := time.Parse("2006-01-02", createdAt[1])
|
||||
|
||||
if startTime == endTime {
|
||||
endTime = endTime.Add(23*time.Hour + 59*time.Minute + 59*time.Second)
|
||||
}
|
||||
|
||||
query = query.Where("created_at BETWEEN ? AND ?", startTime, endTime)
|
||||
}
|
||||
}
|
||||
|
||||
// 排序
|
||||
query = query.Order("created_at desc")
|
||||
@@ -435,3 +413,145 @@ func (r *UserDoctorDao) GetUserDoctorListSearch(req requests.GetUserDoctorList)
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetUserDoctorExportListSearch 医生列表-导出
|
||||
func (r *UserDoctorDao) GetUserDoctorExportListSearch(req requests.UserDoctorExportList) (m []*model.UserDoctor, err error) {
|
||||
// 构建查询条件
|
||||
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("UserDoctorInfo")
|
||||
|
||||
// 医院
|
||||
query = query.Preload("Hospital", func(db *gorm.DB) *gorm.DB {
|
||||
return db.Select("hospital_id,hospital_name,hospital_level_name")
|
||||
})
|
||||
|
||||
// 医生问诊配置
|
||||
query = query.Preload("DoctorInquiryConfig")
|
||||
|
||||
// 当前搜索数据
|
||||
if req.Type == 1 {
|
||||
// 医生问诊配置
|
||||
if req.InquiryService != "" {
|
||||
result := strings.Split(req.InquiryService, ",")
|
||||
if len(result) > 0 {
|
||||
subQuery := global.Db.Model(&model.DoctorInquiryConfig{}).
|
||||
Where("gdxz_doctor_inquiry_config.doctor_id = gdxz_user_doctor.doctor_id").
|
||||
Where("gdxz_doctor_inquiry_config.inquiry_type IN (?)", req.InquiryService).
|
||||
Where("gdxz_doctor_inquiry_config.inquiry_mode = ?", 1).
|
||||
Where("gdxz_doctor_inquiry_config.is_enable = ?", 1).Select("1")
|
||||
|
||||
query = query.Where("EXISTS (?)", subQuery)
|
||||
}
|
||||
}
|
||||
|
||||
// 手机号
|
||||
if req.Mobile != "" {
|
||||
subQuery := global.Db.Model(&model.User{}).
|
||||
Select("user_id").
|
||||
Where("mobile LIKE ?", "%"+req.Mobile+"%")
|
||||
|
||||
query = query.Where(gorm.Expr("user_id IN (?)", subQuery))
|
||||
}
|
||||
|
||||
// 用户名称
|
||||
if req.UserName != "" {
|
||||
query = query.Where("user_name LIKE ?", "%"+req.UserName+"%")
|
||||
}
|
||||
|
||||
// 状态
|
||||
if req.UserStatus != nil {
|
||||
query = query.Where("status = ?", req.UserStatus)
|
||||
}
|
||||
|
||||
// 医院名称
|
||||
if req.HospitalName != "" {
|
||||
subQuery := global.Db.Model(&model.Hospital{}).
|
||||
Select("hospital_id").
|
||||
Where("hospital_name LIKE ?", "%"+req.HospitalName+"%")
|
||||
|
||||
query = query.Where(gorm.Expr("hospital_id IN (?)", subQuery))
|
||||
}
|
||||
|
||||
// 科室名称
|
||||
if req.DepartmentCustomName != "" {
|
||||
query = query.Where("department_custom_name = ?", req.DepartmentCustomName)
|
||||
}
|
||||
|
||||
// 实名认证状态
|
||||
if req.IDCardStatus != nil {
|
||||
query = query.Where("idcard_status = ?", req.IDCardStatus)
|
||||
}
|
||||
|
||||
// 身份认证状态
|
||||
if req.IdenAuthStatus != nil {
|
||||
query = query.Where("iden_auth_status = ?", req.IdenAuthStatus)
|
||||
}
|
||||
|
||||
// 医生多点执业认证状态
|
||||
if req.MultiPointStatus != nil {
|
||||
query = query.Where("multi_point_status = ?", req.MultiPointStatus)
|
||||
}
|
||||
|
||||
// 是否首页推荐
|
||||
if req.IsRecommend != nil {
|
||||
query = query.Where("is_recommend = ?", req.IsRecommend)
|
||||
}
|
||||
|
||||
if req.DoctorTitle != nil {
|
||||
query = query.Where("doctor_title = ?", req.DoctorTitle)
|
||||
}
|
||||
|
||||
// 注册时间
|
||||
if req.CreatedAt != "" {
|
||||
createdAt := strings.Split(req.CreatedAt, "&")
|
||||
if len(createdAt) == 2 {
|
||||
startTime, _ := time.Parse("2006-01-02", createdAt[0])
|
||||
endTime, _ := time.Parse("2006-01-02", createdAt[1])
|
||||
|
||||
if startTime == endTime {
|
||||
endTime = endTime.Add(23*time.Hour + 59*time.Minute + 59*time.Second)
|
||||
}
|
||||
|
||||
query = query.Where("created_at BETWEEN ? AND ?", startTime, endTime)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 当前选择数据
|
||||
if req.Type == 2 {
|
||||
if req.Id == "" {
|
||||
return nil, errors.New("未提供需导出数据编号")
|
||||
}
|
||||
|
||||
id := strings.Split(req.Id, ",")
|
||||
query = query.Where("doctor_id IN (?)", id)
|
||||
}
|
||||
|
||||
// 排序
|
||||
query = query.Order("created_at desc")
|
||||
|
||||
if req.IsEnterpriseDeepCooperation != nil {
|
||||
query = query.Where("is_enterprise_deep_cooperation = ?", req.IsEnterpriseDeepCooperation)
|
||||
}
|
||||
|
||||
if req.IsPlatformDeepCooperation != nil {
|
||||
query = query.Where("is_platform_deep_cooperation = ?", req.IsPlatformDeepCooperation)
|
||||
}
|
||||
|
||||
if req.IsSysDiagnoCooperation != nil {
|
||||
query = query.Where("is_sys_diagno_cooperation = ?", req.IsSysDiagnoCooperation)
|
||||
}
|
||||
|
||||
err = query.Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user