新增全局变量问题
This commit is contained in:
+29
-2
@@ -1,6 +1,7 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gorm.io/gorm"
|
||||
"hospital-admin-api/api/model"
|
||||
"hospital-admin-api/api/requests"
|
||||
@@ -70,13 +71,39 @@ func (r *AdminUserDao) GetAdminUserPageSearch(getUserPage requests.GetUserPage,
|
||||
var totalRecords int64
|
||||
|
||||
// 构建查询条件
|
||||
query := global.Db.Model(&model.AdminUser{}).Preload("Role")
|
||||
query := global.Db.Model(&model.AdminUser{}).Omit("password", "salt")
|
||||
|
||||
// 岗位
|
||||
query = query.Preload("Post", func(db *gorm.DB) *gorm.DB {
|
||||
return db.Select("post_id, post_name")
|
||||
})
|
||||
|
||||
// 部门
|
||||
query = query.Preload("Dept", func(db *gorm.DB) *gorm.DB {
|
||||
return db.Select("dept_id, dept_name")
|
||||
})
|
||||
|
||||
// 角色
|
||||
query = query.Preload("Role", func(db *gorm.DB) *gorm.DB {
|
||||
return db.Select("role_id, role_name")
|
||||
})
|
||||
|
||||
if getUserPage.PostName != "" {
|
||||
query = query.Preload("Post", "post_name like ?", "%"+getUserPage.PostName+"%")
|
||||
fmt.Println(1111)
|
||||
subQuery := global.Db.Model(&model.AdminPost{}).
|
||||
Select("post_id").
|
||||
Where("post_name LIKE ?", "%"+getUserPage.PostName+"%")
|
||||
|
||||
query = query.Where(gorm.Expr("post_id IN (?)", subQuery))
|
||||
}
|
||||
|
||||
if getUserPage.DeptName != "" {
|
||||
query = query.Preload("Dept", "dept_name like ?", "%"+getUserPage.DeptName+"%")
|
||||
subQuery := global.Db.Model(&model.AdminDept{}).
|
||||
Select("dept_id").
|
||||
Where("dept_name LIKE ?", "%"+getUserPage.DeptName+"%")
|
||||
|
||||
query = query.Where(gorm.Expr("dept_id IN (?)", subQuery))
|
||||
}
|
||||
|
||||
if getUserPage.NickName != "" {
|
||||
|
||||
Reference in New Issue
Block a user