作者 tangxvhui
... ... @@ -33,6 +33,9 @@ service Core {
@doc "用户信息"
@handler miniUserInfo
post /mini/user/info (MiniUserInfoRequest) returns (MiniUserInfoResponse)
@doc "用户统计"
@handler miniUserStatistics
post /mini/user/statistics (UserStatisticsRequest) returns (UserStatisticsResponse)
@doc "用户审核列表"
@handler miniUserAuditList
post /mini/user/audit-list (UserSearchRequest)returns(UserSearchResponse)
... ... @@ -41,7 +44,10 @@ service Core {
post /mini/user/audit (MiniUserAuditRequest)
@doc "部门用户列表"
@handler miniUserDepartmentUsers
post /mini/user/department-users (MiniUserDepartmentUsersRequest)returns (MiniUserInfoResponse)
post /mini/user/department-users (MiniUserDepartmentUsersRequest)
@doc "用户列表"
@handler miniUsersList
post /mini/user/user-list (MiniUsersListRequest)
@doc "关注我的人"
@handler miniUserFollower
post /mini/user/follower (MiniUserFollowedSearchRequest)returns(MiniUserFollowedSearchResponse)
... ... @@ -105,6 +111,10 @@ type(
Departments []*Department `json:"departments"`
Users []*UserItem `json:"users"`
}
MiniUsersListRequest{
ArticleId int64 `json:"articleId,optional"` // 按文章ID(返回文章可见的用户)
RoleId int64 `json:"roleId,optional"` // 按角色角色关联的用户
}
MiniUserFollowedSearchRequest{
Page int `json:"page,optional"`
Size int `json:"size,optional"`
... ... @@ -117,6 +127,7 @@ type(
Id int64 `json:"id,omitempty"` // 用户ID
CompanyId int64 `json:"companyId,omitempty"` // 公司ID
CompanyName string `json:"companyName,omitempty"` // 公司名称
CompanyCode string `json:"companyCode,omitempty"` // 公司编码(邀请码)
//DepartmentId int64 `json:"departmentId,omitempty"` // 部门ID
//Roles []int64 `json:"roleId,omitempty"` // 角色
Flag int `json:"flag,omitempty"` // 标识 1:管理员 2:普通用户 (有绑定角色是管理员)
... ... @@ -216,6 +227,9 @@ service Core {
@doc "用户统计"
@handler systemUserStatistics
post /system/user/statistics (UserStatisticsRequest) returns (UserStatisticsResponse)
@doc "用户列表"
@handler systemUsersList
post /system/user/user-list (MiniUsersListRequest)
@doc "用户详情"
@handler systemUserGet
... ...
... ... @@ -149,6 +149,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
},
{
Method: http.MethodPost,
Path: "/mini/user/statistics",
Handler: user.MiniUserStatisticsHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/mini/user/audit-list",
Handler: user.MiniUserAuditListHandler(serverCtx),
},
... ... @@ -164,6 +169,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
},
{
Method: http.MethodPost,
Path: "/mini/user/user-list",
Handler: user.MiniUsersListHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/mini/user/follower",
Handler: user.MiniUserFollowerHandler(serverCtx),
},
... ... @@ -207,6 +217,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Handler: user.SystemUserStatisticsHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/system/user/user-list",
Handler: user.SystemUsersListHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/system/user/:id",
Handler: user.SystemUserGetHandler(serverCtx),
... ...
package user
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/user"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
)
func MiniUserStatisticsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.UserStatisticsRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := user.NewSystemUserStatisticsLogic(r.Context(), svcCtx)
resp, err := l.SystemUserStatistics(&req)
result.HttpResult(r, w, resp, err)
}
}
... ...
package user
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/user"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
)
func MiniUsersListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniUsersListRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := user.NewMiniAtUsersListLogic(r.Context(), svcCtx)
resp, err := l.MiniAtUsersList(&req)
result.HttpResult(r, w, resp, err)
}
}
... ...
package user
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/user"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
)
func SystemUsersListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniUsersListRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := user.NewMiniAtUsersListLogic(r.Context(), svcCtx)
resp, err := l.MiniAtUsersList(&req)
result.HttpResult(r, w, resp, err)
}
}
... ...
... ... @@ -42,14 +42,21 @@ func (l *MiniUserInfoLogic) MiniUserInfo(req *types.MiniUserInfoRequest) (resp *
if _, roles, err = l.svcCtx.RoleRepository.Find(l.ctx, conn, domain.IndexCompanyId(user.CompanyId)().MustWithKV("ids", user.Roles)); err != nil {
return nil, xerr.NewErrMsgErr("角色不存在", err)
}
resp = &types.MiniUserInfoResponse{
User: &types.UserItem{
Id: user.Id,
Name: user.Name,
Id: user.Id,
Name: user.Name,
Avatar: user.Avatar,
Position: user.Position,
},
Accounts: make([]types.Account, 0),
Auths: make([]types.Auth, 0),
}
if company, _ := domain.LazyLoad(companyMap, l.ctx, conn, user.CompanyId, l.svcCtx.CompanyRepository.FindOne); company != nil {
resp.User.CompanyName = company.Name
resp.User.CompanyCode = company.Code
}
_, accounts, err = l.svcCtx.UserRepository.Find(l.ctx, conn, domain.NewQueryOptions().MustWithKV("phone", user.Phone).MustWithKV("auditStatus", []int{domain.UserAuditStatusPassed}))
if err != nil {
return nil, xerr.NewErrMsgErr("用户不存在", err)
... ...
package user
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type MiniUserStatisticsLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewMiniUserStatisticsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniUserStatisticsLogic {
return &MiniUserStatisticsLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *MiniUserStatisticsLogic) MiniUserStatistics(req *types.UserStatisticsRequest) (resp *types.UserStatisticsResponse, err error) {
// todo: add your logic here and delete this line
return
}
... ...
package user
import (
"context"
"github.com/samber/lo"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type MiniAtUsersListLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewMiniAtUsersListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniAtUsersListLogic {
return &MiniAtUsersListLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *MiniAtUsersListLogic) MiniAtUsersList(req *types.MiniUsersListRequest) (resp interface{}, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
article *domain.Article
users []*domain.User
userToken = contextdata.GetUserTokenFromCtx(l.ctx)
onlyUsers []int64
)
if req.ArticleId != 0 {
if article, err = l.svcCtx.ArticleRepository.FindOne(l.ctx, conn, req.ArticleId); err != nil {
return nil, xerr.NewErrMsgErr("用户列表获取失败", err)
}
if article.TargetUser == domain.ArticleTargetLimit && len(article.WhoRead) > 0 {
onlyUsers = article.WhoRead
}
}
if _, users, err = l.svcCtx.UserRepository.FindDepartmentUsers(l.ctx, conn, userToken.CompanyId, domain.NewQueryOptions().WithFindOnly()); err != nil {
return nil, xerr.NewErrMsgErr("用户列表获取失败", err)
}
if len(onlyUsers) > 0 {
onlyUsersMap := lo.KeyBy(onlyUsers, func(item int64) int64 {
return item
})
users = lo.Filter(users, func(item *domain.User, index int) bool {
if _, ok := onlyUsersMap[item.Id]; ok {
return false
}
return true
})
}
var list = make([]*domain.User, 0)
lo.ForEach(users, func(item *domain.User, index int) {
list = append(list, &domain.User{
Id: item.Id,
Name: item.Name,
PinYinName: item.PinYinName,
})
})
return map[string]interface{}{
"list": list,
}, nil
}
... ...
package user
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type SystemUsersListLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSystemUsersListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemUsersListLogic {
return &SystemUsersListLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *SystemUsersListLogic) SystemUsersList(req *types.MiniUsersListRequest) error {
// todo: add your logic here and delete this line
return nil
}
... ...
... ... @@ -325,6 +325,11 @@ type MiniUserDepartmentUsersResponse struct {
Users []*UserItem `json:"users"`
}
type MiniUsersListRequest struct {
ArticleId int64 `json:"articleId,optional"` // 按文章ID(返回文章可见的用户)
RoleId int64 `json:"roleId,optional"` // 按角色角色关联的用户
}
type MiniUserFollowedSearchRequest struct {
Page int `json:"page,optional"`
Size int `json:"size,optional"`
... ... @@ -339,6 +344,7 @@ type UserItem struct {
Id int64 `json:"id,omitempty"` // 用户ID
CompanyId int64 `json:"companyId,omitempty"` // 公司ID
CompanyName string `json:"companyName,omitempty"` // 公司名称
CompanyCode string `json:"companyCode,omitempty"` // 公司编码(邀请码)
Flag int `json:"flag,omitempty"` // 标识 1:管理员 2:普通用户 (有绑定角色是管理员)
Name string `json:"name,omitempty"` // 名称
Avatar string `json:"avatar,omitempty"` // 头像
... ...