作者 tangxvhui
@@ -33,6 +33,9 @@ service Core { @@ -33,6 +33,9 @@ service Core {
33 @doc "用户信息" 33 @doc "用户信息"
34 @handler miniUserInfo 34 @handler miniUserInfo
35 post /mini/user/info (MiniUserInfoRequest) returns (MiniUserInfoResponse) 35 post /mini/user/info (MiniUserInfoRequest) returns (MiniUserInfoResponse)
  36 + @doc "用户统计"
  37 + @handler miniUserStatistics
  38 + post /mini/user/statistics (UserStatisticsRequest) returns (UserStatisticsResponse)
36 @doc "用户审核列表" 39 @doc "用户审核列表"
37 @handler miniUserAuditList 40 @handler miniUserAuditList
38 post /mini/user/audit-list (UserSearchRequest)returns(UserSearchResponse) 41 post /mini/user/audit-list (UserSearchRequest)returns(UserSearchResponse)
@@ -41,7 +44,10 @@ service Core { @@ -41,7 +44,10 @@ service Core {
41 post /mini/user/audit (MiniUserAuditRequest) 44 post /mini/user/audit (MiniUserAuditRequest)
42 @doc "部门用户列表" 45 @doc "部门用户列表"
43 @handler miniUserDepartmentUsers 46 @handler miniUserDepartmentUsers
44 - post /mini/user/department-users (MiniUserDepartmentUsersRequest)returns (MiniUserInfoResponse) 47 + post /mini/user/department-users (MiniUserDepartmentUsersRequest)
  48 + @doc "用户列表"
  49 + @handler miniUsersList
  50 + post /mini/user/user-list (MiniUsersListRequest)
45 @doc "关注我的人" 51 @doc "关注我的人"
46 @handler miniUserFollower 52 @handler miniUserFollower
47 post /mini/user/follower (MiniUserFollowedSearchRequest)returns(MiniUserFollowedSearchResponse) 53 post /mini/user/follower (MiniUserFollowedSearchRequest)returns(MiniUserFollowedSearchResponse)
@@ -105,6 +111,10 @@ type( @@ -105,6 +111,10 @@ type(
105 Departments []*Department `json:"departments"` 111 Departments []*Department `json:"departments"`
106 Users []*UserItem `json:"users"` 112 Users []*UserItem `json:"users"`
107 } 113 }
  114 + MiniUsersListRequest{
  115 + ArticleId int64 `json:"articleId,optional"` // 按文章ID(返回文章可见的用户)
  116 + RoleId int64 `json:"roleId,optional"` // 按角色角色关联的用户
  117 + }
108 MiniUserFollowedSearchRequest{ 118 MiniUserFollowedSearchRequest{
109 Page int `json:"page,optional"` 119 Page int `json:"page,optional"`
110 Size int `json:"size,optional"` 120 Size int `json:"size,optional"`
@@ -117,6 +127,7 @@ type( @@ -117,6 +127,7 @@ type(
117 Id int64 `json:"id,omitempty"` // 用户ID 127 Id int64 `json:"id,omitempty"` // 用户ID
118 CompanyId int64 `json:"companyId,omitempty"` // 公司ID 128 CompanyId int64 `json:"companyId,omitempty"` // 公司ID
119 CompanyName string `json:"companyName,omitempty"` // 公司名称 129 CompanyName string `json:"companyName,omitempty"` // 公司名称
  130 + CompanyCode string `json:"companyCode,omitempty"` // 公司编码(邀请码)
120 //DepartmentId int64 `json:"departmentId,omitempty"` // 部门ID 131 //DepartmentId int64 `json:"departmentId,omitempty"` // 部门ID
121 //Roles []int64 `json:"roleId,omitempty"` // 角色 132 //Roles []int64 `json:"roleId,omitempty"` // 角色
122 Flag int `json:"flag,omitempty"` // 标识 1:管理员 2:普通用户 (有绑定角色是管理员) 133 Flag int `json:"flag,omitempty"` // 标识 1:管理员 2:普通用户 (有绑定角色是管理员)
@@ -216,6 +227,9 @@ service Core { @@ -216,6 +227,9 @@ service Core {
216 @doc "用户统计" 227 @doc "用户统计"
217 @handler systemUserStatistics 228 @handler systemUserStatistics
218 post /system/user/statistics (UserStatisticsRequest) returns (UserStatisticsResponse) 229 post /system/user/statistics (UserStatisticsRequest) returns (UserStatisticsResponse)
  230 + @doc "用户列表"
  231 + @handler systemUsersList
  232 + post /system/user/user-list (MiniUsersListRequest)
219 233
220 @doc "用户详情" 234 @doc "用户详情"
221 @handler systemUserGet 235 @handler systemUserGet
@@ -149,6 +149,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { @@ -149,6 +149,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
149 }, 149 },
150 { 150 {
151 Method: http.MethodPost, 151 Method: http.MethodPost,
  152 + Path: "/mini/user/statistics",
  153 + Handler: user.MiniUserStatisticsHandler(serverCtx),
  154 + },
  155 + {
  156 + Method: http.MethodPost,
152 Path: "/mini/user/audit-list", 157 Path: "/mini/user/audit-list",
153 Handler: user.MiniUserAuditListHandler(serverCtx), 158 Handler: user.MiniUserAuditListHandler(serverCtx),
154 }, 159 },
@@ -164,6 +169,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { @@ -164,6 +169,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
164 }, 169 },
165 { 170 {
166 Method: http.MethodPost, 171 Method: http.MethodPost,
  172 + Path: "/mini/user/user-list",
  173 + Handler: user.MiniUsersListHandler(serverCtx),
  174 + },
  175 + {
  176 + Method: http.MethodPost,
167 Path: "/mini/user/follower", 177 Path: "/mini/user/follower",
168 Handler: user.MiniUserFollowerHandler(serverCtx), 178 Handler: user.MiniUserFollowerHandler(serverCtx),
169 }, 179 },
@@ -207,6 +217,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { @@ -207,6 +217,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
207 Handler: user.SystemUserStatisticsHandler(serverCtx), 217 Handler: user.SystemUserStatisticsHandler(serverCtx),
208 }, 218 },
209 { 219 {
  220 + Method: http.MethodPost,
  221 + Path: "/system/user/user-list",
  222 + Handler: user.SystemUsersListHandler(serverCtx),
  223 + },
  224 + {
210 Method: http.MethodGet, 225 Method: http.MethodGet,
211 Path: "/system/user/:id", 226 Path: "/system/user/:id",
212 Handler: user.SystemUserGetHandler(serverCtx), 227 Handler: user.SystemUserGetHandler(serverCtx),
  1 +package user
  2 +
  3 +import (
  4 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
  5 + "net/http"
  6 +
  7 + "github.com/zeromicro/go-zero/rest/httpx"
  8 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/user"
  9 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
  10 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
  11 +)
  12 +
  13 +func MiniUserStatisticsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
  14 + return func(w http.ResponseWriter, r *http.Request) {
  15 + var req types.UserStatisticsRequest
  16 + if err := httpx.Parse(r, &req); err != nil {
  17 + httpx.ErrorCtx(r.Context(), w, err)
  18 + return
  19 + }
  20 +
  21 + l := user.NewSystemUserStatisticsLogic(r.Context(), svcCtx)
  22 + resp, err := l.SystemUserStatistics(&req)
  23 + result.HttpResult(r, w, resp, err)
  24 + }
  25 +}
  1 +package user
  2 +
  3 +import (
  4 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
  5 + "net/http"
  6 +
  7 + "github.com/zeromicro/go-zero/rest/httpx"
  8 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/user"
  9 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
  10 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
  11 +)
  12 +
  13 +func MiniUsersListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
  14 + return func(w http.ResponseWriter, r *http.Request) {
  15 + var req types.MiniUsersListRequest
  16 + if err := httpx.Parse(r, &req); err != nil {
  17 + httpx.ErrorCtx(r.Context(), w, err)
  18 + return
  19 + }
  20 +
  21 + l := user.NewMiniAtUsersListLogic(r.Context(), svcCtx)
  22 + resp, err := l.MiniAtUsersList(&req)
  23 + result.HttpResult(r, w, resp, err)
  24 + }
  25 +}
  1 +package user
  2 +
  3 +import (
  4 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
  5 + "net/http"
  6 +
  7 + "github.com/zeromicro/go-zero/rest/httpx"
  8 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/user"
  9 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
  10 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
  11 +)
  12 +
  13 +func SystemUsersListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
  14 + return func(w http.ResponseWriter, r *http.Request) {
  15 + var req types.MiniUsersListRequest
  16 + if err := httpx.Parse(r, &req); err != nil {
  17 + httpx.ErrorCtx(r.Context(), w, err)
  18 + return
  19 + }
  20 +
  21 + l := user.NewMiniAtUsersListLogic(r.Context(), svcCtx)
  22 + resp, err := l.MiniAtUsersList(&req)
  23 + result.HttpResult(r, w, resp, err)
  24 + }
  25 +}
@@ -42,14 +42,21 @@ func (l *MiniUserInfoLogic) MiniUserInfo(req *types.MiniUserInfoRequest) (resp * @@ -42,14 +42,21 @@ func (l *MiniUserInfoLogic) MiniUserInfo(req *types.MiniUserInfoRequest) (resp *
42 if _, roles, err = l.svcCtx.RoleRepository.Find(l.ctx, conn, domain.IndexCompanyId(user.CompanyId)().MustWithKV("ids", user.Roles)); err != nil { 42 if _, roles, err = l.svcCtx.RoleRepository.Find(l.ctx, conn, domain.IndexCompanyId(user.CompanyId)().MustWithKV("ids", user.Roles)); err != nil {
43 return nil, xerr.NewErrMsgErr("角色不存在", err) 43 return nil, xerr.NewErrMsgErr("角色不存在", err)
44 } 44 }
  45 +
45 resp = &types.MiniUserInfoResponse{ 46 resp = &types.MiniUserInfoResponse{
46 User: &types.UserItem{ 47 User: &types.UserItem{
47 - Id: user.Id,  
48 - Name: user.Name, 48 + Id: user.Id,
  49 + Name: user.Name,
  50 + Avatar: user.Avatar,
  51 + Position: user.Position,
49 }, 52 },
50 Accounts: make([]types.Account, 0), 53 Accounts: make([]types.Account, 0),
51 Auths: make([]types.Auth, 0), 54 Auths: make([]types.Auth, 0),
52 } 55 }
  56 + if company, _ := domain.LazyLoad(companyMap, l.ctx, conn, user.CompanyId, l.svcCtx.CompanyRepository.FindOne); company != nil {
  57 + resp.User.CompanyName = company.Name
  58 + resp.User.CompanyCode = company.Code
  59 + }
53 _, accounts, err = l.svcCtx.UserRepository.Find(l.ctx, conn, domain.NewQueryOptions().MustWithKV("phone", user.Phone).MustWithKV("auditStatus", []int{domain.UserAuditStatusPassed})) 60 _, accounts, err = l.svcCtx.UserRepository.Find(l.ctx, conn, domain.NewQueryOptions().MustWithKV("phone", user.Phone).MustWithKV("auditStatus", []int{domain.UserAuditStatusPassed}))
54 if err != nil { 61 if err != nil {
55 return nil, xerr.NewErrMsgErr("用户不存在", err) 62 return nil, xerr.NewErrMsgErr("用户不存在", err)
  1 +package user
  2 +
  3 +import (
  4 + "context"
  5 +
  6 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
  7 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
  8 +
  9 + "github.com/zeromicro/go-zero/core/logx"
  10 +)
  11 +
  12 +type MiniUserStatisticsLogic struct {
  13 + logx.Logger
  14 + ctx context.Context
  15 + svcCtx *svc.ServiceContext
  16 +}
  17 +
  18 +func NewMiniUserStatisticsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniUserStatisticsLogic {
  19 + return &MiniUserStatisticsLogic{
  20 + Logger: logx.WithContext(ctx),
  21 + ctx: ctx,
  22 + svcCtx: svcCtx,
  23 + }
  24 +}
  25 +
  26 +func (l *MiniUserStatisticsLogic) MiniUserStatistics(req *types.UserStatisticsRequest) (resp *types.UserStatisticsResponse, err error) {
  27 + // todo: add your logic here and delete this line
  28 +
  29 + return
  30 +}
  1 +package user
  2 +
  3 +import (
  4 + "context"
  5 + "github.com/samber/lo"
  6 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
  7 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
  8 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
  9 +
  10 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
  11 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
  12 +
  13 + "github.com/zeromicro/go-zero/core/logx"
  14 +)
  15 +
  16 +type MiniAtUsersListLogic struct {
  17 + logx.Logger
  18 + ctx context.Context
  19 + svcCtx *svc.ServiceContext
  20 +}
  21 +
  22 +func NewMiniAtUsersListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniAtUsersListLogic {
  23 + return &MiniAtUsersListLogic{
  24 + Logger: logx.WithContext(ctx),
  25 + ctx: ctx,
  26 + svcCtx: svcCtx,
  27 + }
  28 +}
  29 +
  30 +func (l *MiniAtUsersListLogic) MiniAtUsersList(req *types.MiniUsersListRequest) (resp interface{}, err error) {
  31 + var (
  32 + conn = l.svcCtx.DefaultDBConn()
  33 + article *domain.Article
  34 + users []*domain.User
  35 + userToken = contextdata.GetUserTokenFromCtx(l.ctx)
  36 + onlyUsers []int64
  37 + )
  38 + if req.ArticleId != 0 {
  39 + if article, err = l.svcCtx.ArticleRepository.FindOne(l.ctx, conn, req.ArticleId); err != nil {
  40 + return nil, xerr.NewErrMsgErr("用户列表获取失败", err)
  41 + }
  42 + if article.TargetUser == domain.ArticleTargetLimit && len(article.WhoRead) > 0 {
  43 + onlyUsers = article.WhoRead
  44 + }
  45 + }
  46 + if _, users, err = l.svcCtx.UserRepository.FindDepartmentUsers(l.ctx, conn, userToken.CompanyId, domain.NewQueryOptions().WithFindOnly()); err != nil {
  47 + return nil, xerr.NewErrMsgErr("用户列表获取失败", err)
  48 + }
  49 + if len(onlyUsers) > 0 {
  50 + onlyUsersMap := lo.KeyBy(onlyUsers, func(item int64) int64 {
  51 + return item
  52 + })
  53 + users = lo.Filter(users, func(item *domain.User, index int) bool {
  54 + if _, ok := onlyUsersMap[item.Id]; ok {
  55 + return false
  56 + }
  57 + return true
  58 + })
  59 + }
  60 + var list = make([]*domain.User, 0)
  61 + lo.ForEach(users, func(item *domain.User, index int) {
  62 + list = append(list, &domain.User{
  63 + Id: item.Id,
  64 + Name: item.Name,
  65 + PinYinName: item.PinYinName,
  66 + })
  67 + })
  68 + return map[string]interface{}{
  69 + "list": list,
  70 + }, nil
  71 +}
  1 +package user
  2 +
  3 +import (
  4 + "context"
  5 +
  6 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
  7 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
  8 +
  9 + "github.com/zeromicro/go-zero/core/logx"
  10 +)
  11 +
  12 +type SystemUsersListLogic struct {
  13 + logx.Logger
  14 + ctx context.Context
  15 + svcCtx *svc.ServiceContext
  16 +}
  17 +
  18 +func NewSystemUsersListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemUsersListLogic {
  19 + return &SystemUsersListLogic{
  20 + Logger: logx.WithContext(ctx),
  21 + ctx: ctx,
  22 + svcCtx: svcCtx,
  23 + }
  24 +}
  25 +
  26 +func (l *SystemUsersListLogic) SystemUsersList(req *types.MiniUsersListRequest) error {
  27 + // todo: add your logic here and delete this line
  28 +
  29 + return nil
  30 +}
@@ -325,6 +325,11 @@ type MiniUserDepartmentUsersResponse struct { @@ -325,6 +325,11 @@ type MiniUserDepartmentUsersResponse struct {
325 Users []*UserItem `json:"users"` 325 Users []*UserItem `json:"users"`
326 } 326 }
327 327
  328 +type MiniUsersListRequest struct {
  329 + ArticleId int64 `json:"articleId,optional"` // 按文章ID(返回文章可见的用户)
  330 + RoleId int64 `json:"roleId,optional"` // 按角色角色关联的用户
  331 +}
  332 +
328 type MiniUserFollowedSearchRequest struct { 333 type MiniUserFollowedSearchRequest struct {
329 Page int `json:"page,optional"` 334 Page int `json:"page,optional"`
330 Size int `json:"size,optional"` 335 Size int `json:"size,optional"`
@@ -339,6 +344,7 @@ type UserItem struct { @@ -339,6 +344,7 @@ type UserItem struct {
339 Id int64 `json:"id,omitempty"` // 用户ID 344 Id int64 `json:"id,omitempty"` // 用户ID
340 CompanyId int64 `json:"companyId,omitempty"` // 公司ID 345 CompanyId int64 `json:"companyId,omitempty"` // 公司ID
341 CompanyName string `json:"companyName,omitempty"` // 公司名称 346 CompanyName string `json:"companyName,omitempty"` // 公司名称
  347 + CompanyCode string `json:"companyCode,omitempty"` // 公司编码(邀请码)
342 Flag int `json:"flag,omitempty"` // 标识 1:管理员 2:普通用户 (有绑定角色是管理员) 348 Flag int `json:"flag,omitempty"` // 标识 1:管理员 2:普通用户 (有绑定角色是管理员)
343 Name string `json:"name,omitempty"` // 名称 349 Name string `json:"name,omitempty"` // 名称
344 Avatar string `json:"avatar,omitempty"` // 头像 350 Avatar string `json:"avatar,omitempty"` // 头像