用户int64转string
This commit is contained in:
parent
3263520334
commit
966057fa5b
@ -5,8 +5,10 @@ import (
|
||||
"hospital-admin-api/api/dao"
|
||||
"hospital-admin-api/api/requests"
|
||||
"hospital-admin-api/api/responses"
|
||||
"hospital-admin-api/api/responses/userResponse"
|
||||
"hospital-admin-api/global"
|
||||
"hospital-admin-api/utils"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type User struct{}
|
||||
@ -43,11 +45,67 @@ func (r *User) GetUserPage(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// 处理返回值
|
||||
getUserPageResponses := make([]userResponse.GetUserPage, len(adminUser))
|
||||
|
||||
if len(adminUser) > 0 {
|
||||
for i, v := range adminUser {
|
||||
var Role *userResponse.GetUserPageRole
|
||||
if v.Role != nil {
|
||||
Role = &userResponse.GetUserPageRole{
|
||||
RoleId: strconv.FormatInt(v.Role.RoleId, 10),
|
||||
RoleName: v.Role.RoleName,
|
||||
}
|
||||
}
|
||||
|
||||
var Dept *userResponse.GetUserPageDept
|
||||
if v.Dept != nil {
|
||||
Dept = &userResponse.GetUserPageDept{
|
||||
DeptId: strconv.FormatInt(v.Dept.DeptId, 10),
|
||||
DeptName: v.Dept.DeptName,
|
||||
}
|
||||
}
|
||||
|
||||
var Post *userResponse.GetUserPagePost
|
||||
if v.Post != nil {
|
||||
Post = &userResponse.GetUserPagePost{
|
||||
PostId: strconv.FormatInt(v.Post.PostId, 10),
|
||||
PostName: v.Post.PostName,
|
||||
}
|
||||
}
|
||||
|
||||
// 将原始结构体转换为新结构体
|
||||
getUserPageResponse := userResponse.GetUserPage{
|
||||
UserID: strconv.Itoa(int(v.UserID)),
|
||||
Access: v.Access,
|
||||
Status: v.Status,
|
||||
IsDeleted: v.IsDeleted,
|
||||
IsDisabled: v.IsDisabled,
|
||||
NickName: v.NickName,
|
||||
Phone: v.Phone,
|
||||
Avatar: v.Avatar,
|
||||
Sex: v.Sex,
|
||||
Email: v.Email,
|
||||
RoleID: strconv.Itoa(int(v.RoleID)),
|
||||
DeptID: strconv.Itoa(int(v.DeptID)),
|
||||
PostID: strconv.Itoa(int(v.PostID)),
|
||||
CreatedAt: v.CreatedAt,
|
||||
UpdatedAt: v.UpdatedAt,
|
||||
Role: Role,
|
||||
Dept: Dept,
|
||||
Post: Post,
|
||||
}
|
||||
|
||||
// 将转换后的结构体添加到新切片中
|
||||
getUserPageResponses[i] = getUserPageResponse
|
||||
}
|
||||
}
|
||||
|
||||
result := make(map[string]interface{})
|
||||
result["page"] = UserRequest.GetUserPage.Page
|
||||
result["page_size"] = UserRequest.GetUserPage.PageSize
|
||||
result["total"] = total
|
||||
result["data"] = adminUser
|
||||
result["data"] = getUserPageResponses
|
||||
responses.OkWithData(result, c)
|
||||
}
|
||||
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gorm.io/gorm"
|
||||
"hospital-admin-api/api/model"
|
||||
"hospital-admin-api/api/requests"
|
||||
@ -89,7 +88,6 @@ func (r *AdminUserDao) GetAdminUserPageSearch(getUserPage requests.GetUserPage,
|
||||
})
|
||||
|
||||
if getUserPage.PostName != "" {
|
||||
fmt.Println(1111)
|
||||
subQuery := global.Db.Model(&model.AdminPost{}).
|
||||
Select("post_id").
|
||||
Where("post_name LIKE ?", "%"+getUserPage.PostName+"%")
|
||||
|
||||
40
api/responses/userResponse/user.go
Normal file
40
api/responses/userResponse/user.go
Normal file
@ -0,0 +1,40 @@
|
||||
package userResponse
|
||||
|
||||
import "hospital-admin-api/api/model"
|
||||
|
||||
// GetUserPage 获取用户列表-分页
|
||||
type GetUserPage struct {
|
||||
UserID string `json:"user_id"` // 主键id
|
||||
Access string `json:"access"` // 账号
|
||||
Status int `json:"status"` // 状态(1:正常 2:审核中 3:审核失败)
|
||||
IsDeleted int `json:"is_deleted"` // 是否被删除(0:否 1:是)
|
||||
IsDisabled int `json:"is_disabled"` // 是否被禁用(0:否 1:是)
|
||||
NickName string `json:"nick_name"` // 昵称
|
||||
Phone string `json:"phone"` // 手机号
|
||||
Avatar string `json:"avatar"` // 头像
|
||||
Sex int `json:"sex"` // 性别(1:男 2:女)
|
||||
Email string `json:"email"` // 邮箱
|
||||
RoleID string `json:"role_id"` // 角色id
|
||||
DeptID string `json:"dept_id"` // 部门id
|
||||
PostID string `json:"post_id"` // 岗位id
|
||||
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
||||
UpdatedAt model.LocalTime `json:"updated_at"` // 修改时间
|
||||
Role *GetUserPageRole `json:"role"` // 角色
|
||||
Dept *GetUserPageDept `json:"dept"` // 部门
|
||||
Post *GetUserPagePost `json:"post"` // 岗位
|
||||
}
|
||||
|
||||
type GetUserPageRole struct {
|
||||
RoleId string `json:"role_id"` // 角色id
|
||||
RoleName string `json:"role_name"` // 角色名称
|
||||
}
|
||||
|
||||
type GetUserPageDept struct {
|
||||
DeptId string `json:"dept_id"` // 部门id
|
||||
DeptName string `json:"dept_name"` // 部门名称
|
||||
}
|
||||
|
||||
type GetUserPagePost struct {
|
||||
PostId string `json:"post_id"` // 岗位id
|
||||
PostName string `json:"post_name"` // 岗位名称
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user