医生账户-导出
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"gorm.io/gorm"
|
||||
"hospital-admin-api/api/model"
|
||||
"hospital-admin-api/api/requests"
|
||||
"hospital-admin-api/global"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type DoctorAccountDao struct {
|
||||
@@ -90,7 +92,7 @@ func (r *DoctorAccountDao) Inc(tx *gorm.DB, maps interface{}, numeral float64, f
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetDoctorAccountPage 获取医生列表-分页
|
||||
// GetDoctorAccountPage 获取医生账户列表-分页
|
||||
func (r *DoctorAccountDao) GetDoctorAccountPage(req requests.GetDoctorAccountPage, page, pageSize int) (m []*model.DoctorAccount, total int64, err error) {
|
||||
var totalRecords int64
|
||||
|
||||
@@ -144,3 +146,64 @@ func (r *DoctorAccountDao) GetDoctorAccountPage(req requests.GetDoctorAccountPag
|
||||
}
|
||||
return m, totalRecords, nil
|
||||
}
|
||||
|
||||
// GetDoctorAccountExportListSearch 医生账户-导出
|
||||
func (r *DoctorAccountDao) GetDoctorAccountExportListSearch(req requests.DoctorAccountExportList) (m []*model.DoctorAccount, err error) {
|
||||
// 构建查询条件
|
||||
query := global.Db.Model(&model.DoctorAccount{})
|
||||
|
||||
// 医生
|
||||
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.Type == 1 {
|
||||
// 手机号
|
||||
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.UserName != "" {
|
||||
subQuery := global.Db.Model(&model.UserDoctor{}).
|
||||
Select("doctor_id").
|
||||
Where("user_name LIKE ?", "%"+req.UserName+"%")
|
||||
|
||||
query = query.Where(gorm.Expr("doctor_id IN (?)", subQuery))
|
||||
}
|
||||
}
|
||||
|
||||
// 当前选择数据
|
||||
if req.Type == 2 {
|
||||
if req.Id == "" {
|
||||
return nil, errors.New("未提供需导出数据编号")
|
||||
}
|
||||
|
||||
id := strings.Split(req.Id, ",")
|
||||
query = query.Where("account_id IN (?)", id)
|
||||
}
|
||||
|
||||
// 排序
|
||||
query = query.Order("created_at desc")
|
||||
|
||||
err = query.Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user