Browse Source

重写 core-api 的 /user/info 接口,增加 departmentRemark 字段

boweniac 7 months ago
parent
commit
f4fa997ec8

+ 1 - 0
desc/all.api

@@ -11,6 +11,7 @@ import "./wechat/sop_stage.api"
 import "./wechat/sop_node.api"
 import "./wechat/message_records.api"
 import "./wechat/chatroom_member.api"
+import "./wechat/user.api"
 import "./openapi/contact.api"
 import "./wechat/batch_msg.api"
 import "./wechat/agent.api"

+ 102 - 0
desc/wechat/user.api

@@ -0,0 +1,102 @@
+import "../base.api"
+
+type (
+    // The response data of user information | 用户信息
+    UserInfo {
+        BaseUUIDInfo
+
+        // Status | 状态
+        Status *uint32 `json:"status,optional" validate:"omitempty,lt=20"`
+
+        // Username | 用户名
+        Username *string `json:"username,optional" validate:"omitempty,max=50"`
+
+        // Nickname | 昵称
+        Nickname *string `json:"nickname,optional" validate:"omitempty,max=40"`
+
+        // Password | 密码
+        Password *string `json:"password,optional" validate:"omitempty,min=6"`
+
+        // Description | 描述
+        Description *string `json:"description,optional" validate:"omitempty,max=100"`
+
+        // HomePath | 首页
+        HomePath *string `json:"homePath,optional" validate:"omitempty,max=70"`
+
+        // RoleId | 角色ID
+        RoleIds []uint64 `json:"roleIds,optional"`
+
+        // Mobile | 手机号
+        Mobile *string `json:"mobile,optional" validate:"omitempty,max=18"`
+
+        // Email | 邮箱
+        Email *string `json:"email,optional" validate:"omitempty,max=80"`
+
+        // Avatar | 头像地址
+        Avatar *string `json:"avatar,optional" validate:"omitempty,max=300"`
+
+        // Department ID | 部门ID
+        DepartmentId *uint64 `json:"departmentId,optional,omitempty"`
+
+        // Position ID | 职位ID
+        PositionIds []uint64 `json:"positionId,optional,omitempty"`
+    }
+
+    // User information response | 用户信息返回体
+    UserInfoResp {
+        BaseDataInfo
+
+        // User information | User数据
+        Data UserInfo `json:"data"`
+    }
+
+    // The response data of user's basic information | 用户基本信息返回数据
+    UserBaseIDInfoResp {
+        BaseDataInfo
+
+        // The  data of user's basic information | 用户基本信息
+        Data UserBaseIDInfo `json:"data"`
+    }
+
+    // The  data of user's basic information | 用户基本信息
+    UserBaseIDInfo {
+        // User's UUID | 用户的UUID
+        UUID *string `json:"userId"`
+
+        // User's name | 用户名
+        Username *string `json:"username"`
+
+        // User's nickname | 用户的昵称
+        Nickname *string `json:"nickname"`
+
+        // The user's avatar path | 用户的头像路径
+        Avatar *string `json:"avatar"`
+
+        // The home page that the user enters after logging in | 用户登陆后进入的首页
+        HomePath *string `json:"homePath"`
+
+        // The description of user | 用户的描述信息
+        Description *string `json:"desc"`
+
+        // User's Role Name | 用户的角色名称
+        RoleName   []string   `json:"roleName"`
+
+        // Department Name | 部门名称
+        DepartmentName string `json:"departmentName,optional"`
+
+        // Department Name | 部门备注
+        DepartmentRemark string `json:"departmentRemark,optional"`
+    }
+)
+
+@server(
+    jwt: Auth
+    group: User
+    middleware: Authority
+)
+
+service Wechat {
+    // Get user basic information | 获取用户基本信息
+    @handler getUserInfo
+    get /user/info returns (UserBaseIDInfoResp)
+}

+ 31 - 0
internal/handler/User/get_user_info_handler.go

@@ -0,0 +1,31 @@
+package User
+
+import (
+	"net/http"
+
+	"github.com/zeromicro/go-zero/rest/httpx"
+
+	"wechat-api/internal/logic/User"
+	"wechat-api/internal/svc"
+)
+
+// swagger:route get /user/info User GetUserInfo
+//
+// Get user basic information | 获取用户基本信息
+//
+// Get user basic information | 获取用户基本信息
+//
+// Responses:
+//  200: UserBaseIDInfoResp
+
+func GetUserInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		l := User.NewGetUserInfoLogic(r.Context(), svcCtx)
+		resp, err := l.GetUserInfo()
+		if err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+		} else {
+			httpx.OkJsonCtx(r.Context(), w, resp)
+		}
+	}
+}

+ 15 - 0
internal/handler/routes.go

@@ -6,6 +6,7 @@ import (
 
 	ChatRoomMember "wechat-api/internal/handler/ChatRoomMember"
 	Message "wechat-api/internal/handler/Message"
+	User "wechat-api/internal/handler/User"
 	WechatServer "wechat-api/internal/handler/WechatServer"
 	Wx "wechat-api/internal/handler/Wx"
 	Wxhook "wechat-api/internal/handler/Wxhook"
@@ -490,6 +491,20 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
 	)
 
 	server.AddRoutes(
+		rest.WithMiddlewares(
+			[]rest.Middleware{serverCtx.Authority},
+			[]rest.Route{
+				{
+					Method:  http.MethodGet,
+					Path:    "/user/info",
+					Handler: User.GetUserInfoHandler(serverCtx),
+				},
+			}...,
+		),
+		rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
+	)
+
+	server.AddRoutes(
 		[]rest.Route{
 			{
 				Method:  http.MethodPost,

+ 74 - 0
internal/logic/User/get_user_info_logic.go

@@ -0,0 +1,74 @@
+package User
+
+import (
+	"context"
+	"github.com/suyuan32/simple-admin-common/msg/errormsg"
+	"github.com/suyuan32/simple-admin-core/rpc/types/core"
+
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+type GetUserInfoLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewGetUserInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserInfoLogic {
+	return &GetUserInfoLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx}
+}
+
+func (l *GetUserInfoLogic) GetUserInfo() (resp *types.UserBaseIDInfoResp, err error) {
+	user, err := l.svcCtx.CoreRpc.GetUserById(l.ctx,
+		&core.UUIDReq{Id: l.ctx.Value("userId").(string)})
+	if err != nil {
+		return nil, err
+	}
+
+	departmentInfo, err := l.svcCtx.CoreRpc.GetDepartmentById(l.ctx, &core.IDReq{Id: user.GetDepartmentId()})
+	if err != nil {
+		return nil, err
+	}
+
+	departmentName := *departmentInfo.Name
+	if departmentName == "department.managementDepartment" {
+		departmentName = "冠客数字员工管理系统"
+	}
+	roleNameMap := map[string]string{
+		"role.admin":               "管理员",
+		"role.stuff":               "员工",
+		"role.seller":              "销售",
+		"role.member":              "会员",
+		"role.changeStatusSuccess": "已成功修改角色状态",
+		"role.changeStatusFailed":  "修改角色状态失败",
+		"role.duplicateRoleValue":  "角色值重复",
+		"role.userExists":          "请先删除该角色下的用户",
+		"role.roleForbidden":       "您的角色已停用",
+	}
+
+	var roleNames []string
+	for _, roleName := range user.GetRoleName() {
+		roleNames = append(roleNames, roleNameMap[roleName])
+	}
+
+	return &types.UserBaseIDInfoResp{
+		BaseDataInfo: types.BaseDataInfo{Msg: errormsg.Success},
+		Data: types.UserBaseIDInfo{
+			UUID:             user.Id,
+			Username:         user.Username,
+			Nickname:         user.Nickname,
+			Avatar:           user.Avatar,
+			HomePath:         user.HomePath,
+			Description:      user.Description,
+			DepartmentName:   departmentName,
+			DepartmentRemark: *departmentInfo.Remark,
+			RoleName:         roleNames,
+		},
+	}, nil
+}

+ 78 - 0
internal/types/types.go

@@ -1059,6 +1059,84 @@ type ChatroomMemberInfoResp struct {
 	Data ChatroomMemberInfo `json:"data"`
 }
 
+// The response data of user information | 用户信息
+// swagger:model UserInfo
+type UserInfo struct {
+	BaseUUIDInfo
+	// Status | 状态
+	// max : 20
+	Status *uint32 `json:"status,optional" validate:"omitempty,lt=20"`
+	// Username | 用户名
+	// max length : 50
+	Username *string `json:"username,optional" validate:"omitempty,max=50"`
+	// Nickname | 昵称
+	// max length : 40
+	Nickname *string `json:"nickname,optional" validate:"omitempty,max=40"`
+	// Password | 密码
+	// min length : 6
+	Password *string `json:"password,optional" validate:"omitempty,min=6"`
+	// Description | 描述
+	// max length : 100
+	Description *string `json:"description,optional" validate:"omitempty,max=100"`
+	// HomePath | 首页
+	// max length : 70
+	HomePath *string `json:"homePath,optional" validate:"omitempty,max=70"`
+	// RoleId | 角色ID
+	RoleIds []uint64 `json:"roleIds,optional"`
+	// Mobile | 手机号
+	// max length : 18
+	Mobile *string `json:"mobile,optional" validate:"omitempty,max=18"`
+	// Email | 邮箱
+	// max length : 80
+	Email *string `json:"email,optional" validate:"omitempty,max=80"`
+	// Avatar | 头像地址
+	// max length : 300
+	Avatar *string `json:"avatar,optional" validate:"omitempty,max=300"`
+	// Department ID | 部门ID
+	DepartmentId *uint64 `json:"departmentId,optional,omitempty"`
+	// Position ID | 职位ID
+	PositionIds []uint64 `json:"positionId,optional,omitempty"`
+}
+
+// User information response | 用户信息返回体
+// swagger:model UserInfoResp
+type UserInfoResp struct {
+	BaseDataInfo
+	// User information | User数据
+	Data UserInfo `json:"data"`
+}
+
+// The response data of user's basic information | 用户基本信息返回数据
+// swagger:model UserBaseIDInfoResp
+type UserBaseIDInfoResp struct {
+	BaseDataInfo
+	// The  data of user's basic information | 用户基本信息
+	Data UserBaseIDInfo `json:"data"`
+}
+
+// The  data of user's basic information | 用户基本信息
+// swagger:model UserBaseIDInfo
+type UserBaseIDInfo struct {
+	// User's UUID | 用户的UUID
+	UUID *string `json:"userId"`
+	// User's name | 用户名
+	Username *string `json:"username"`
+	// User's nickname | 用户的昵称
+	Nickname *string `json:"nickname"`
+	// The user's avatar path | 用户的头像路径
+	Avatar *string `json:"avatar"`
+	// The home page that the user enters after logging in | 用户登陆后进入的首页
+	HomePath *string `json:"homePath"`
+	// The description of user | 用户的描述信息
+	Description *string `json:"desc"`
+	// User's Role Name | 用户的角色名称
+	RoleName []string `json:"roleName"`
+	// Department Name | 部门名称
+	DepartmentName string `json:"departmentName,optional"`
+	// Department Name | 部门备注
+	DepartmentRemark string `json:"departmentRemark,optional"`
+}
+
 // swagger:model WxidReq
 type WxidReq struct {
 	Wxid string `json:"wxid"`