新增用户相关接口

This commit is contained in:
2023-06-29 16:16:21 +08:00
parent 966057fa5b
commit 98aa3263bb
11 changed files with 475 additions and 114 deletions
+114 -9
View File
@@ -1,9 +1,13 @@
package userResponse
import "hospital-admin-api/api/model"
import (
"hospital-admin-api/api/model"
"hospital-admin-api/config"
"strconv"
)
// GetUserPage 获取用户列表-分页
type GetUserPage struct {
// getUserPage 获取用户列表-分页
type getUserPage struct {
UserID string `json:"user_id"` // 主键id
Access string `json:"access"` // 账号
Status int `json:"status"` // 状态(1:正常 2:审核中 3:审核失败)
@@ -19,22 +23,123 @@ type GetUserPage struct {
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"` // 岗位
Role *getUserPageRole `json:"role"` // 角色
Dept *getUserPageDept `json:"dept"` // 部门
Post *getUserPagePost `json:"post"` // 岗位
}
type GetUserPageRole struct {
type getUserPageRole struct {
RoleId string `json:"role_id"` // 角色id
RoleName string `json:"role_name"` // 角色名称
}
type GetUserPageDept struct {
type getUserPageDept struct {
DeptId string `json:"dept_id"` // 部门id
DeptName string `json:"dept_name"` // 部门名称
}
type GetUserPagePost struct {
type getUserPagePost struct {
PostId string `json:"post_id"` // 岗位id
PostName string `json:"post_name"` // 岗位名称
}
// getUser 用户详情
type getUser struct {
UserID string `json:"user_id"`
Access string `json:"access"`
Status int `json:"status"`
IsDeleted int `json:"is_deleted"`
IsDisabled int `json:"is_disabled"`
NickName string `json:"nick_name"`
Phone string `json:"phone"`
Avatar string `json:"avatar"`
Sex int `json:"sex"`
Email string `json:"email"`
RoleID string `json:"role_id"`
DeptID string `json:"dept_id"`
PostID string `json:"post_id"`
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
UpdatedAt model.LocalTime `json:"updated_at"` // 修改时间
}
// GetUserPageResponse 获取用户列表-分页
func GetUserPageResponse(adminUser []*model.AdminUser) []getUserPage {
// 处理返回值
getUserPageResponses := make([]getUserPage, len(adminUser))
if len(adminUser) > 0 {
for i, v := range adminUser {
var role *getUserPageRole
if v.Role != nil {
role = &getUserPageRole{
RoleId: strconv.FormatInt(v.Role.RoleId, 10),
RoleName: v.Role.RoleName,
}
}
var dept *getUserPageDept
if v.Dept != nil {
dept = &getUserPageDept{
DeptId: strconv.FormatInt(v.Dept.DeptId, 10),
DeptName: v.Dept.DeptName,
}
}
var post *getUserPagePost
if v.Post != nil {
post = &getUserPagePost{
PostId: strconv.FormatInt(v.Post.PostId, 10),
PostName: v.Post.PostName,
}
}
// 将原始结构体转换为新结构体
getUserPageResponse := 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: config.C.Oss.OssCustomDomainName + "/" + 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
}
}
return getUserPageResponses
}
// GetUserResponse 用户详情
func GetUserResponse(adminUser *model.AdminUser) *getUser {
return &getUser{
UserID: strconv.FormatInt(adminUser.UserID, 10),
Access: adminUser.Access,
Status: adminUser.Status,
IsDeleted: adminUser.IsDeleted,
IsDisabled: adminUser.IsDisabled,
NickName: adminUser.NickName,
Phone: adminUser.Phone,
Avatar: config.C.Oss.OssCustomDomainName + "/" + adminUser.Avatar,
Sex: adminUser.Sex,
Email: adminUser.Email,
RoleID: strconv.FormatInt(adminUser.RoleID, 10),
DeptID: strconv.FormatInt(adminUser.DeptID, 10),
PostID: strconv.FormatInt(adminUser.PostID, 10),
CreatedAt: adminUser.CreatedAt,
UpdatedAt: adminUser.UpdatedAt,
}
}