正在显示
52 个修改的文件
包含
661 行增加
和
64 行删除
@@ -3,13 +3,14 @@ package main | @@ -3,13 +3,14 @@ package main | ||
3 | import ( | 3 | import ( |
4 | "context" | 4 | "context" |
5 | "flag" | 5 | "flag" |
6 | + "net/http" | ||
7 | + "strings" | ||
8 | + | ||
6 | "github.com/zeromicro/go-zero/rest/httpx" | 9 | "github.com/zeromicro/go-zero/rest/httpx" |
7 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db" | 10 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db" |
8 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" | 11 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" |
9 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result" | 12 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result" |
10 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr" | 13 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr" |
11 | - "net/http" | ||
12 | - "strings" | ||
13 | 14 | ||
14 | "github.com/golang-jwt/jwt/v4/request" | 15 | "github.com/golang-jwt/jwt/v4/request" |
15 | "github.com/zeromicro/go-zero/core/conf" | 16 | "github.com/zeromicro/go-zero/core/conf" |
@@ -65,7 +66,8 @@ func systemSetup(c config.Config) { | @@ -65,7 +66,8 @@ func systemSetup(c config.Config) { | ||
65 | 66 | ||
66 | // 默认的token头 Authorization 修改为 x-mmm-accesstoken | 67 | // 默认的token头 Authorization 修改为 x-mmm-accesstoken |
67 | request.AuthorizationHeaderExtractor = &request.PostExtractionFilter{ | 68 | request.AuthorizationHeaderExtractor = &request.PostExtractionFilter{ |
68 | - request.HeaderExtractor{"x-mmm-accesstoken"}, func(tok string) (string, error) { | 69 | + Extractor: request.HeaderExtractor{"x-mmm-accesstoken"}, |
70 | + Filter: func(tok string) (string, error) { | ||
69 | // Should be a bearer token | 71 | // Should be a bearer token |
70 | if len(tok) > 6 && strings.ToUpper(tok[0:7]) == "BEARER " { | 72 | if len(tok) > 6 && strings.ToUpper(tok[0:7]) == "BEARER " { |
71 | return tok[7:], nil | 73 | return tok[7:], nil |
@@ -130,7 +130,7 @@ type ( | @@ -130,7 +130,7 @@ type ( | ||
130 | type ( | 130 | type ( |
131 | MiniSetUserLikeRequset { | 131 | MiniSetUserLikeRequset { |
132 | ArticleId int64 `json:"articleId"` //文章id | 132 | ArticleId int64 `json:"articleId"` //文章id |
133 | - CommentId int64 `json:"commentId"` //评论id | 133 | + CommentId int64 `json:"commentId,optional"` //评论id |
134 | UserId int64 `json:",optional"` //操作人 | 134 | UserId int64 `json:",optional"` //操作人 |
135 | Flag int `json:"flag"` //点赞标志 1、点赞 2 、取消点赞 | 135 | Flag int `json:"flag"` //点赞标志 1、点赞 2 、取消点赞 |
136 | } | 136 | } |
@@ -68,7 +68,7 @@ type ( | @@ -68,7 +68,7 @@ type ( | ||
68 | } | 68 | } |
69 | RoleItem { | 69 | RoleItem { |
70 | Id int64 `json:"id,optional"` // 角色ID | 70 | Id int64 `json:"id,optional"` // 角色ID |
71 | - CompanyId int64 `json:"companyId,optional,omitempty"` // 公司ID | 71 | + CompanyId int64 `json:"companyId,optional,string,omitempty"` // 公司ID |
72 | Name string `json:"name"` // 角色名称 | 72 | Name string `json:"name"` // 角色名称 |
73 | AuthIds []int64 `json:"authIds,optional,omitempty"` // 角色权限列表 | 73 | AuthIds []int64 `json:"authIds,optional,omitempty"` // 角色权限列表 |
74 | AuthsDesc string `json:"authsDesc,optional,omitempty"` // 权限列表描述 | 74 | AuthsDesc string `json:"authsDesc,optional,omitempty"` // 权限列表描述 |
@@ -139,8 +139,10 @@ type( | @@ -139,8 +139,10 @@ type( | ||
139 | Type string `json:"type"` // 快讯类型 文章:Article 讨论:Discuss ... | 139 | Type string `json:"type"` // 快讯类型 文章:Article 讨论:Discuss ... |
140 | Title string `json:"title"` // 标题 | 140 | Title string `json:"title"` // 标题 |
141 | Summary string `json:"summary"` // 快讯概要 | 141 | Summary string `json:"summary"` // 快讯概要 |
142 | - Time int64 `json:"time"` // 时间 | 142 | + Time int64 `json:"time"` // 时间 |
143 | ReadFlag bool `json:"readFlag"` // 已读标识 true:已读 false:未读 | 143 | ReadFlag bool `json:"readFlag"` // 已读标识 true:已读 false:未读 |
144 | + Images []string `json:"images"` // 图片列表 | ||
145 | + Author UserItem `json:"author"` // 作者 | ||
144 | } | 146 | } |
145 | MiniUserFollowedSearchRequest{ | 147 | MiniUserFollowedSearchRequest{ |
146 | Page int `json:"page,optional"` | 148 | Page int `json:"page,optional"` |
@@ -166,7 +168,7 @@ type( | @@ -166,7 +168,7 @@ type( | ||
166 | //Roles []int64 `json:"roleId,omitempty"` // 角色 | 168 | //Roles []int64 `json:"roleId,omitempty"` // 角色 |
167 | Flag int `json:"flag,omitempty"` // 标识 1:管理员 2:普通用户 (有绑定角色是管理员) | 169 | Flag int `json:"flag,omitempty"` // 标识 1:管理员 2:普通用户 (有绑定角色是管理员) |
168 | Name string `json:"name,omitempty"` // 名称 | 170 | Name string `json:"name,omitempty"` // 名称 |
169 | - Avatar string `json:"avatar,omitempty"` // 头像 | 171 | + Avatar *string `json:"avatar,omitempty"` // 头像 |
170 | Phone string `json:"phone,omitempty"` // 手机号 唯一 | 172 | Phone string `json:"phone,omitempty"` // 手机号 唯一 |
171 | Position string `json:"position,omitempty"` // 职位 | 173 | Position string `json:"position,omitempty"` // 职位 |
172 | Enable int `json:"enable,omitempty"` // 启用状态 1:启用 2:禁用 | 174 | Enable int `json:"enable,omitempty"` // 启用状态 1:启用 2:禁用 |
@@ -389,6 +391,9 @@ type( | @@ -389,6 +391,9 @@ type( | ||
389 | } | 391 | } |
390 | SystemUserAccountUpdateRequest struct{ | 392 | SystemUserAccountUpdateRequest struct{ |
391 | Id int64 `path:"id"` | 393 | Id int64 `path:"id"` |
394 | + Name string `json:"name"` // 姓名 | ||
395 | + Roles []int64 `json:"roles"` // 权限角色 | ||
396 | + Status int `json:"enable"` // 状态 1:启用 2:禁用 | ||
392 | } | 397 | } |
393 | SystemUserAccountUpdateResponse struct{} | 398 | SystemUserAccountUpdateResponse struct{} |
394 | 399 |
@@ -11,6 +11,7 @@ import ( | @@ -11,6 +11,7 @@ import ( | ||
11 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result" | 11 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result" |
12 | ) | 12 | ) |
13 | 13 | ||
14 | +// 获取所有的标签 | ||
14 | func MiniAllArticleTagHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | 15 | func MiniAllArticleTagHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { |
15 | return func(w http.ResponseWriter, r *http.Request) { | 16 | return func(w http.ResponseWriter, r *http.Request) { |
16 | var req types.MiniAllArticleTagRequest | 17 | var req types.MiniAllArticleTagRequest |
@@ -11,6 +11,7 @@ import ( | @@ -11,6 +11,7 @@ import ( | ||
11 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result" | 11 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result" |
12 | ) | 12 | ) |
13 | 13 | ||
14 | +// 获取文章的编辑记录 | ||
14 | func MiniArticleBackupSearchHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | 15 | func MiniArticleBackupSearchHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { |
15 | return func(w http.ResponseWriter, r *http.Request) { | 16 | return func(w http.ResponseWriter, r *http.Request) { |
16 | var req types.MiniArticleBackupSearchRequest | 17 | var req types.MiniArticleBackupSearchRequest |
@@ -11,6 +11,7 @@ import ( | @@ -11,6 +11,7 @@ import ( | ||
11 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" | 11 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" |
12 | ) | 12 | ) |
13 | 13 | ||
14 | +// 获取我的文章浏览记录 | ||
14 | func MiniArticleMarkListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | 15 | func MiniArticleMarkListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { |
15 | return func(w http.ResponseWriter, r *http.Request) { | 16 | return func(w http.ResponseWriter, r *http.Request) { |
16 | var req types.MiniArticleMarkListRequest | 17 | var req types.MiniArticleMarkListRequest |
@@ -11,6 +11,7 @@ import ( | @@ -11,6 +11,7 @@ import ( | ||
11 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result" | 11 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result" |
12 | ) | 12 | ) |
13 | 13 | ||
14 | +// 获取我发布的文章 | ||
14 | func MiniArticleSearchMeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | 15 | func MiniArticleSearchMeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { |
15 | return func(w http.ResponseWriter, r *http.Request) { | 16 | return func(w http.ResponseWriter, r *http.Request) { |
16 | var req types.MiniArticleSearchMeRequest | 17 | var req types.MiniArticleSearchMeRequest |
@@ -11,6 +11,7 @@ import ( | @@ -11,6 +11,7 @@ import ( | ||
11 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result" | 11 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result" |
12 | ) | 12 | ) |
13 | 13 | ||
14 | +// 设置文章的定性标签 | ||
14 | func MiniArticleSetTagHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | 15 | func MiniArticleSetTagHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { |
15 | return func(w http.ResponseWriter, r *http.Request) { | 16 | return func(w http.ResponseWriter, r *http.Request) { |
16 | var req types.MiniArticleSetTagRequest | 17 | var req types.MiniArticleSetTagRequest |
@@ -11,6 +11,7 @@ import ( | @@ -11,6 +11,7 @@ import ( | ||
11 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result" | 11 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result" |
12 | ) | 12 | ) |
13 | 13 | ||
14 | +// 保存文章进草稿箱 | ||
14 | func MiniCreateArticleDraftHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | 15 | func MiniCreateArticleDraftHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { |
15 | return func(w http.ResponseWriter, r *http.Request) { | 16 | return func(w http.ResponseWriter, r *http.Request) { |
16 | var req types.MiniArticleDraftCreateRequest | 17 | var req types.MiniArticleDraftCreateRequest |
@@ -11,6 +11,7 @@ import ( | @@ -11,6 +11,7 @@ import ( | ||
11 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result" | 11 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result" |
12 | ) | 12 | ) |
13 | 13 | ||
14 | +// 发布新的文章 | ||
14 | func MiniCreateArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | 15 | func MiniCreateArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { |
15 | return func(w http.ResponseWriter, r *http.Request) { | 16 | return func(w http.ResponseWriter, r *http.Request) { |
16 | var req types.MiniArticleCreateRequest | 17 | var req types.MiniArticleCreateRequest |
@@ -11,6 +11,7 @@ import ( | @@ -11,6 +11,7 @@ import ( | ||
11 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result" | 11 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result" |
12 | ) | 12 | ) |
13 | 13 | ||
14 | +// 删除文章的草稿箱 | ||
14 | func MiniDeleteArticleDraftMeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | 15 | func MiniDeleteArticleDraftMeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { |
15 | return func(w http.ResponseWriter, r *http.Request) { | 16 | return func(w http.ResponseWriter, r *http.Request) { |
16 | var req types.MiniArticleDraftDeleteMeRequest | 17 | var req types.MiniArticleDraftDeleteMeRequest |
@@ -11,6 +11,7 @@ import ( | @@ -11,6 +11,7 @@ import ( | ||
11 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result" | 11 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result" |
12 | ) | 12 | ) |
13 | 13 | ||
14 | +// 获取我的文章草稿内容 | ||
14 | func MiniGetArticleDraftMeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | 15 | func MiniGetArticleDraftMeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { |
15 | return func(w http.ResponseWriter, r *http.Request) { | 16 | return func(w http.ResponseWriter, r *http.Request) { |
16 | var req types.MiniArticleDraftGetMeRequest | 17 | var req types.MiniArticleDraftGetMeRequest |
@@ -11,6 +11,7 @@ import ( | @@ -11,6 +11,7 @@ import ( | ||
11 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result" | 11 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result" |
12 | ) | 12 | ) |
13 | 13 | ||
14 | +// 小程序端展示文章内容 | ||
14 | func MiniGetArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | 15 | func MiniGetArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { |
15 | return func(w http.ResponseWriter, r *http.Request) { | 16 | return func(w http.ResponseWriter, r *http.Request) { |
16 | var req types.MiniArticleGetRequest | 17 | var req types.MiniArticleGetRequest |
@@ -11,6 +11,7 @@ import ( | @@ -11,6 +11,7 @@ import ( | ||
11 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result" | 11 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result" |
12 | ) | 12 | ) |
13 | 13 | ||
14 | +// 查询我的草稿箱内容列表 | ||
14 | func MiniSearchArticleDraftMeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | 15 | func MiniSearchArticleDraftMeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { |
15 | return func(w http.ResponseWriter, r *http.Request) { | 16 | return func(w http.ResponseWriter, r *http.Request) { |
16 | var req types.MiniArticleDraftSearchMeRequest | 17 | var req types.MiniArticleDraftSearchMeRequest |
@@ -11,6 +11,7 @@ import ( | @@ -11,6 +11,7 @@ import ( | ||
11 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result" | 11 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result" |
12 | ) | 12 | ) |
13 | 13 | ||
14 | +// 设置文章\评论的点赞操作 | ||
14 | func MiniSetUserLikeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | 15 | func MiniSetUserLikeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { |
15 | return func(w http.ResponseWriter, r *http.Request) { | 16 | return func(w http.ResponseWriter, r *http.Request) { |
16 | var req types.MiniSetUserLikeRequset | 17 | var req types.MiniSetUserLikeRequset |
@@ -11,6 +11,7 @@ import ( | @@ -11,6 +11,7 @@ import ( | ||
11 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result" | 11 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result" |
12 | ) | 12 | ) |
13 | 13 | ||
14 | +// 更新文章草稿箱的内容 | ||
14 | func MiniUpdateArticleDraftHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | 15 | func MiniUpdateArticleDraftHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { |
15 | return func(w http.ResponseWriter, r *http.Request) { | 16 | return func(w http.ResponseWriter, r *http.Request) { |
16 | var req types.MiniArticleDraftUpdateRequest | 17 | var req types.MiniArticleDraftUpdateRequest |
@@ -11,6 +11,7 @@ import ( | @@ -11,6 +11,7 @@ import ( | ||
11 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result" | 11 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result" |
12 | ) | 12 | ) |
13 | 13 | ||
14 | +// 获取点赞文章的的人员列表 | ||
14 | func MiniUserLikeArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | 15 | func MiniUserLikeArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { |
15 | return func(w http.ResponseWriter, r *http.Request) { | 16 | return func(w http.ResponseWriter, r *http.Request) { |
16 | var req types.MiniUserLikeArticleRequest | 17 | var req types.MiniUserLikeArticleRequest |
@@ -11,6 +11,7 @@ import ( | @@ -11,6 +11,7 @@ import ( | ||
11 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result" | 11 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result" |
12 | ) | 12 | ) |
13 | 13 | ||
14 | +// 填写评估时@谁 的可选择者列表 | ||
14 | func MiniArticleCommentAtWhoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | 15 | func MiniArticleCommentAtWhoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { |
15 | return func(w http.ResponseWriter, r *http.Request) { | 16 | return func(w http.ResponseWriter, r *http.Request) { |
16 | var req types.MiniArticleCommentAtWhoRequest | 17 | var req types.MiniArticleCommentAtWhoRequest |
@@ -11,6 +11,7 @@ import ( | @@ -11,6 +11,7 @@ import ( | ||
11 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result" | 11 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result" |
12 | ) | 12 | ) |
13 | 13 | ||
14 | +// 填写评论 | ||
14 | func MiniCreateArticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | 15 | func MiniCreateArticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { |
15 | return func(w http.ResponseWriter, r *http.Request) { | 16 | return func(w http.ResponseWriter, r *http.Request) { |
16 | var req types.MiniCreateArticleCommentRequest | 17 | var req types.MiniCreateArticleCommentRequest |
@@ -11,6 +11,7 @@ import ( | @@ -11,6 +11,7 @@ import ( | ||
11 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result" | 11 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result" |
12 | ) | 12 | ) |
13 | 13 | ||
14 | +// 小程序端人员删除评论 | ||
14 | func MiniDeleteArticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | 15 | func MiniDeleteArticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { |
15 | return func(w http.ResponseWriter, r *http.Request) { | 16 | return func(w http.ResponseWriter, r *http.Request) { |
16 | var req types.MiniDeleteArticleCommentRequest | 17 | var req types.MiniDeleteArticleCommentRequest |
@@ -11,6 +11,7 @@ import ( | @@ -11,6 +11,7 @@ import ( | ||
11 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result" | 11 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result" |
12 | ) | 12 | ) |
13 | 13 | ||
14 | +// 获取单条评论详情 | ||
14 | func MiniGetArticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | 15 | func MiniGetArticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { |
15 | return func(w http.ResponseWriter, r *http.Request) { | 16 | return func(w http.ResponseWriter, r *http.Request) { |
16 | var req types.MiniGetArticleCommentRequest | 17 | var req types.MiniGetArticleCommentRequest |
@@ -11,6 +11,7 @@ import ( | @@ -11,6 +11,7 @@ import ( | ||
11 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result" | 11 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result" |
12 | ) | 12 | ) |
13 | 13 | ||
14 | +// 小程序端获取 根据文章id 获取评论列表 | ||
14 | func MiniListArticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | 15 | func MiniListArticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { |
15 | return func(w http.ResponseWriter, r *http.Request) { | 16 | return func(w http.ResponseWriter, r *http.Request) { |
16 | var req types.MiniListArticleCommentRequest | 17 | var req types.MiniListArticleCommentRequest |
@@ -11,6 +11,7 @@ import ( | @@ -11,6 +11,7 @@ import ( | ||
11 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result" | 11 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result" |
12 | ) | 12 | ) |
13 | 13 | ||
14 | +// 获取前5的评论 | ||
14 | func MiniTop5ArticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | 15 | func MiniTop5ArticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { |
15 | return func(w http.ResponseWriter, r *http.Request) { | 16 | return func(w http.ResponseWriter, r *http.Request) { |
16 | var req types.MiniTop5ArticleCommentRequest | 17 | var req types.MiniTop5ArticleCommentRequest |
@@ -25,6 +25,7 @@ func NewMiniSearchArticleDraftMeLogic(ctx context.Context, svcCtx *svc.ServiceCo | @@ -25,6 +25,7 @@ func NewMiniSearchArticleDraftMeLogic(ctx context.Context, svcCtx *svc.ServiceCo | ||
25 | } | 25 | } |
26 | } | 26 | } |
27 | 27 | ||
28 | +// 查询我的草稿箱内容列表 | ||
28 | func (l *MiniSearchArticleDraftMeLogic) MiniSearchArticleDraftMe(req *types.MiniArticleDraftSearchMeRequest) (resp *types.MiniArticleDraftSearchMeResponse, err error) { | 29 | func (l *MiniSearchArticleDraftMeLogic) MiniSearchArticleDraftMe(req *types.MiniArticleDraftSearchMeRequest) (resp *types.MiniArticleDraftSearchMeResponse, err error) { |
29 | var conn = l.svcCtx.DefaultDBConn() | 30 | var conn = l.svcCtx.DefaultDBConn() |
30 | 31 |
@@ -26,6 +26,7 @@ func NewMiniUpdateArticleDraftLogic(ctx context.Context, svcCtx *svc.ServiceCont | @@ -26,6 +26,7 @@ func NewMiniUpdateArticleDraftLogic(ctx context.Context, svcCtx *svc.ServiceCont | ||
26 | } | 26 | } |
27 | } | 27 | } |
28 | 28 | ||
29 | +// 更新文章草稿箱的内容 | ||
29 | func (l *MiniUpdateArticleDraftLogic) MiniUpdateArticleDraft(req *types.MiniArticleDraftUpdateRequest) (resp *types.MiniArticleDraftUpdateResponse, err error) { | 30 | func (l *MiniUpdateArticleDraftLogic) MiniUpdateArticleDraft(req *types.MiniArticleDraftUpdateRequest) (resp *types.MiniArticleDraftUpdateResponse, err error) { |
30 | var conn = l.svcCtx.DefaultDBConn() | 31 | var conn = l.svcCtx.DefaultDBConn() |
31 | 32 |
@@ -2,6 +2,7 @@ package article | @@ -2,6 +2,7 @@ package article | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "context" | 4 | "context" |
5 | + | ||
5 | "github.com/samber/lo" | 6 | "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/cmd/discuss/interanl/pkg/domain" |
7 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr" | 8 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr" |
@@ -26,6 +27,7 @@ func NewSystemArticleGetHistoryLogic(ctx context.Context, svcCtx *svc.ServiceCon | @@ -26,6 +27,7 @@ func NewSystemArticleGetHistoryLogic(ctx context.Context, svcCtx *svc.ServiceCon | ||
26 | } | 27 | } |
27 | } | 28 | } |
28 | 29 | ||
30 | +// 获取文章的编辑历史记录详情 | ||
29 | func (l *SystemArticleGetHistoryLogic) SystemArticleGetHistory(req *types.SystemArticleGetHistoryRequest) (resp *types.SystemArticleGetHistoryResponse, err error) { | 31 | func (l *SystemArticleGetHistoryLogic) SystemArticleGetHistory(req *types.SystemArticleGetHistoryRequest) (resp *types.SystemArticleGetHistoryResponse, err error) { |
30 | var conn = l.svcCtx.DefaultDBConn() | 32 | var conn = l.svcCtx.DefaultDBConn() |
31 | backup, err := l.svcCtx.ArticleBackupRepository.FindOne(l.ctx, conn, req.Id) | 33 | backup, err := l.svcCtx.ArticleBackupRepository.FindOne(l.ctx, conn, req.Id) |
@@ -2,6 +2,7 @@ package comment | @@ -2,6 +2,7 @@ package comment | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "context" | 4 | "context" |
5 | + | ||
5 | "github.com/samber/lo" | 6 | "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/cmd/discuss/interanl/pkg/domain" |
7 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr" | 8 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr" |
@@ -26,6 +27,7 @@ func NewSystemArticleCommentSearchLogic(ctx context.Context, svcCtx *svc.Service | @@ -26,6 +27,7 @@ func NewSystemArticleCommentSearchLogic(ctx context.Context, svcCtx *svc.Service | ||
26 | } | 27 | } |
27 | } | 28 | } |
28 | 29 | ||
30 | +// 搜索文章的评论 | ||
29 | func (l *SystemArticleCommentSearchLogic) SystemArticleCommentSearch(req *types.SystemArticleCommentSearchRequest) (resp *types.SystemArticleCommentSearchResponse, err error) { | 31 | func (l *SystemArticleCommentSearchLogic) SystemArticleCommentSearch(req *types.SystemArticleCommentSearchRequest) (resp *types.SystemArticleCommentSearchResponse, err error) { |
30 | var conn = l.svcCtx.DefaultDBConn() | 32 | var conn = l.svcCtx.DefaultDBConn() |
31 | queryOptions := domain.NewQueryOptions(). | 33 | queryOptions := domain.NewQueryOptions(). |
@@ -24,6 +24,7 @@ func NewSystemGetAticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceCont | @@ -24,6 +24,7 @@ func NewSystemGetAticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceCont | ||
24 | } | 24 | } |
25 | } | 25 | } |
26 | 26 | ||
27 | +// 后台获取文章的评论详情 | ||
27 | func (l *SystemGetAticleCommentLogic) SystemGetAticleComment(req *types.SystemGetCommentRequest) (resp *types.SystemGetCommentResponse, err error) { | 28 | func (l *SystemGetAticleCommentLogic) SystemGetAticleComment(req *types.SystemGetCommentRequest) (resp *types.SystemGetCommentResponse, err error) { |
28 | var conn = l.svcCtx.DefaultDBConn() | 29 | var conn = l.svcCtx.DefaultDBConn() |
29 | 30 |
@@ -31,14 +31,16 @@ func (l *SystemDeleteRoleLogic) SystemDeleteRole(req *types.RoleDeleteRequest) ( | @@ -31,14 +31,16 @@ func (l *SystemDeleteRoleLogic) SystemDeleteRole(req *types.RoleDeleteRequest) ( | ||
31 | conn = l.svcCtx.DefaultDBConn() | 31 | conn = l.svcCtx.DefaultDBConn() |
32 | role *domain.Role | 32 | role *domain.Role |
33 | userRemoveRoleList []*domain.User | 33 | userRemoveRoleList []*domain.User |
34 | + userRoles []*domain.UserRole | ||
34 | ) | 35 | ) |
35 | if role, err = l.svcCtx.RoleRepository.FindOne(l.ctx, conn, req.Id); err != nil { | 36 | if role, err = l.svcCtx.RoleRepository.FindOne(l.ctx, conn, req.Id); err != nil { |
36 | return nil, xerr.NewErrMsgErr("角色不存在", err) | 37 | return nil, xerr.NewErrMsgErr("角色不存在", err) |
37 | } | 38 | } |
38 | - for _, item := range role.Users { | 39 | + _, userRoles, _ = l.svcCtx.UserRoleRepository.Find(l.ctx, conn, domain.IndexCompanyId(role.CompanyId)().WithKV("roleId", role.Id).WithFindOnly()) |
40 | + for _, item := range userRoles { | ||
39 | var user *domain.User | 41 | var user *domain.User |
40 | - if user, err = l.svcCtx.UserRepository.FindOne(l.ctx, conn, item.Id); err != nil { | ||
41 | - return nil, xerr.NewErrMsgErr("用户存在", err) | 42 | + if user, err = l.svcCtx.UserRepository.FindOne(l.ctx, conn, item.UserId); err != nil { |
43 | + continue | ||
42 | } | 44 | } |
43 | userRemoveRoleList = append(userRemoveRoleList, user) | 45 | userRemoveRoleList = append(userRemoveRoleList, user) |
44 | } | 46 | } |
@@ -52,6 +54,9 @@ func (l *SystemDeleteRoleLogic) SystemDeleteRole(req *types.RoleDeleteRequest) ( | @@ -52,6 +54,9 @@ func (l *SystemDeleteRoleLogic) SystemDeleteRole(req *types.RoleDeleteRequest) ( | ||
52 | return err | 54 | return err |
53 | } | 55 | } |
54 | } | 56 | } |
57 | + if err = l.svcCtx.UserRoleRepository.DeleteRole(l.ctx, conn, role.Id); err != nil { | ||
58 | + return err | ||
59 | + } | ||
55 | return nil | 60 | return nil |
56 | }, true); err != nil { | 61 | }, true); err != nil { |
57 | return nil, xerr.NewErrMsgErr("删除角色失败", err) | 62 | return nil, xerr.NewErrMsgErr("删除角色失败", err) |
@@ -2,7 +2,9 @@ package role | @@ -2,7 +2,9 @@ package role | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "context" | 4 | "context" |
5 | + "github.com/samber/lo" | ||
5 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" | 6 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" |
7 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata" | ||
6 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr" | 8 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr" |
7 | 9 | ||
8 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" | 10 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" |
@@ -27,15 +29,26 @@ func NewSystemGetRoleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Sys | @@ -27,15 +29,26 @@ func NewSystemGetRoleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Sys | ||
27 | 29 | ||
28 | func (l *SystemGetRoleLogic) SystemGetRole(req *types.RoleGetRequest) (resp *types.RoleGetResponse, err error) { | 30 | func (l *SystemGetRoleLogic) SystemGetRole(req *types.RoleGetRequest) (resp *types.RoleGetResponse, err error) { |
29 | var ( | 31 | var ( |
30 | - conn = l.svcCtx.DefaultDBConn() | ||
31 | - role *domain.Role | 32 | + conn = l.svcCtx.DefaultDBConn() |
33 | + role *domain.Role | ||
34 | + users []*domain.User | ||
35 | + userToken = contextdata.GetUserTokenFromCtx(l.ctx) | ||
32 | ) | 36 | ) |
33 | if role, err = l.svcCtx.RoleRepository.FindOne(l.ctx, conn, req.Id); err != nil { | 37 | if role, err = l.svcCtx.RoleRepository.FindOne(l.ctx, conn, req.Id); err != nil { |
34 | return nil, xerr.NewErrMsgErr("角色不存在", err) | 38 | return nil, xerr.NewErrMsgErr("角色不存在", err) |
35 | } | 39 | } |
40 | + _, users, _ = l.svcCtx.UserRepository.FindByCompanyRoles(l.ctx, conn, userToken.CompanyId, []int64{role.Id}, domain.NewQueryOptions().WithFindOnly()) | ||
41 | + typesRole := NewTypesRole(role) | ||
42 | + lo.ForEach(users, func(item *domain.User, index int) { | ||
43 | + typesRole.Users = append(typesRole.Users, types.RoleUser{ | ||
44 | + Id: item.Id, | ||
45 | + Name: item.Name, | ||
46 | + }) | ||
47 | + }) | ||
36 | resp = &types.RoleGetResponse{ | 48 | resp = &types.RoleGetResponse{ |
37 | - Role: NewTypesRole(role), | 49 | + Role: typesRole, |
38 | } | 50 | } |
51 | + | ||
39 | for _, auth := range domain.Auths { | 52 | for _, auth := range domain.Auths { |
40 | resp.AuthList = append(resp.AuthList, types.Auth{ | 53 | resp.AuthList = append(resp.AuthList, types.Auth{ |
41 | Id: auth.Id, | 54 | Id: auth.Id, |
@@ -56,6 +56,13 @@ func (l *SystemSaveRoleLogic) SystemSaveRole(req *types.RoleSaveRequest) (resp * | @@ -56,6 +56,13 @@ func (l *SystemSaveRoleLogic) SystemSaveRole(req *types.RoleSaveRequest) (resp * | ||
56 | if user, err = l.svcCtx.UserRepository.UpdateWithVersion(ctx, conn, user); err != nil { | 56 | if user, err = l.svcCtx.UserRepository.UpdateWithVersion(ctx, conn, user); err != nil { |
57 | return err | 57 | return err |
58 | } | 58 | } |
59 | + if _, err = l.svcCtx.UserRoleRepository.Insert(l.ctx, conn, &domain.UserRole{ | ||
60 | + CompanyId: user.CompanyId, | ||
61 | + UserId: user.Id, | ||
62 | + RoleId: role.Id, | ||
63 | + }); err != nil { | ||
64 | + return err | ||
65 | + } | ||
59 | } | 66 | } |
60 | return nil | 67 | return nil |
61 | }, true); err != nil { | 68 | }, true); err != nil { |
@@ -82,7 +89,7 @@ func NewDomainRole(ctx context.Context, item types.RoleItem) *domain.Role { | @@ -82,7 +89,7 @@ func NewDomainRole(ctx context.Context, item types.RoleItem) *domain.Role { | ||
82 | Name: item.Name, | 89 | Name: item.Name, |
83 | Auths: item.AuthIds, | 90 | Auths: item.AuthIds, |
84 | Remark: item.Remark, | 91 | Remark: item.Remark, |
85 | - Users: users, | 92 | + //Users: users, |
86 | } | 93 | } |
87 | return role | 94 | return role |
88 | } | 95 | } |
@@ -92,12 +99,6 @@ func NewTypesRole(item *domain.Role) types.RoleItem { | @@ -92,12 +99,6 @@ func NewTypesRole(item *domain.Role) types.RoleItem { | ||
92 | role types.RoleItem | 99 | role types.RoleItem |
93 | users []types.RoleUser = make([]types.RoleUser, 0) | 100 | users []types.RoleUser = make([]types.RoleUser, 0) |
94 | ) | 101 | ) |
95 | - lo.ForEach(item.Users, func(item domain.User, index int) { | ||
96 | - users = append(users, types.RoleUser{ | ||
97 | - Id: item.Id, | ||
98 | - Name: item.Name, | ||
99 | - }) | ||
100 | - }) | ||
101 | role = types.RoleItem{ | 102 | role = types.RoleItem{ |
102 | Id: item.Id, | 103 | Id: item.Id, |
103 | CompanyId: item.CompanyId, | 104 | CompanyId: item.CompanyId, |
@@ -35,6 +35,7 @@ func (l *SystemSearchRoleLogic) SystemSearchRole(req *types.RoleSearchRequest) ( | @@ -35,6 +35,7 @@ func (l *SystemSearchRoleLogic) SystemSearchRole(req *types.RoleSearchRequest) ( | ||
35 | userToken = contextdata.GetUserTokenFromCtx(l.ctx) | 35 | userToken = contextdata.GetUserTokenFromCtx(l.ctx) |
36 | roles []*domain.Role | 36 | roles []*domain.Role |
37 | total int64 | 37 | total int64 |
38 | + users []*domain.User | ||
38 | ) | 39 | ) |
39 | queryOptions := domain.IndexCompanyId(userToken.CompanyId)() | 40 | queryOptions := domain.IndexCompanyId(userToken.CompanyId)() |
40 | if req.Page != 0 && req.Size != 0 { | 41 | if req.Page != 0 && req.Size != 0 { |
@@ -57,17 +58,27 @@ func (l *SystemSearchRoleLogic) SystemSearchRole(req *types.RoleSearchRequest) ( | @@ -57,17 +58,27 @@ func (l *SystemSearchRoleLogic) SystemSearchRole(req *types.RoleSearchRequest) ( | ||
57 | }) | 58 | }) |
58 | return | 59 | return |
59 | } | 60 | } |
61 | + roleIds := domain.Values(roles, func(item *domain.Role) int64 { | ||
62 | + return item.Id | ||
63 | + }) | ||
64 | + _, users, _ = l.svcCtx.UserRepository.FindByCompanyRoles(l.ctx, conn, userToken.CompanyId, roleIds, domain.NewQueryOptions().WithFindOnly()) | ||
60 | lo.ForEach(roles, func(item *domain.Role, index int) { | 65 | lo.ForEach(roles, func(item *domain.Role, index int) { |
61 | role := NewTypesRole(item) | 66 | role := NewTypesRole(item) |
62 | - role.UsersDesc = usersDesc(item) | 67 | + usersAll := make([]domain.User, 0) |
68 | + for _, u := range users { | ||
69 | + if lo.Contains(u.Roles, item.Id) { | ||
70 | + usersAll = append(usersAll, *u) | ||
71 | + } | ||
72 | + } | ||
73 | + role.UsersDesc = usersDesc(usersAll) | ||
63 | role.AuthsDesc = authsDesc(item) | 74 | role.AuthsDesc = authsDesc(item) |
64 | resp.List = append(resp.List, role) | 75 | resp.List = append(resp.List, role) |
65 | }) | 76 | }) |
66 | return | 77 | return |
67 | } | 78 | } |
68 | 79 | ||
69 | -func usersDesc(item *domain.Role) string { | ||
70 | - users := lo.Slice(item.Users, 0, 3) | 80 | +func usersDesc(usersAll []domain.User) string { |
81 | + users := lo.Slice(usersAll, 0, 3) | ||
71 | var ( | 82 | var ( |
72 | nameList = make([]string, 0) | 83 | nameList = make([]string, 0) |
73 | desc string = " " | 84 | desc string = " " |
@@ -79,7 +90,7 @@ func usersDesc(item *domain.Role) string { | @@ -79,7 +90,7 @@ func usersDesc(item *domain.Role) string { | ||
79 | return desc | 90 | return desc |
80 | } | 91 | } |
81 | desc = fmt.Sprintf("%s%s", strings.Join(nameList, "、"), | 92 | desc = fmt.Sprintf("%s%s", strings.Join(nameList, "、"), |
82 | - lo.Ternary(len(item.Users) > 3, fmt.Sprintf("...共%d人", len(item.Users)), ""), | 93 | + lo.Ternary(len(usersAll) > 3, fmt.Sprintf("...共%d人", len(usersAll)), ""), |
83 | ) | 94 | ) |
84 | return desc | 95 | return desc |
85 | } | 96 | } |
@@ -37,6 +37,8 @@ func (l *SystemUpdateRoleLogic) SystemUpdateRole(req *types.RoleUpdateRequest) ( | @@ -37,6 +37,8 @@ func (l *SystemUpdateRoleLogic) SystemUpdateRole(req *types.RoleUpdateRequest) ( | ||
37 | 37 | ||
38 | userRemoveRoleList []*domain.User | 38 | userRemoveRoleList []*domain.User |
39 | userAddRoleList []*domain.User | 39 | userAddRoleList []*domain.User |
40 | + | ||
41 | + userRoles []*domain.UserRole | ||
40 | ) | 42 | ) |
41 | if role, err = l.svcCtx.RoleRepository.FindOne(l.ctx, conn, req.Id); err != nil { | 43 | if role, err = l.svcCtx.RoleRepository.FindOne(l.ctx, conn, req.Id); err != nil { |
42 | return nil, xerr.NewErrMsgErr("角色不存在", err) | 44 | return nil, xerr.NewErrMsgErr("角色不存在", err) |
@@ -46,11 +48,12 @@ func (l *SystemUpdateRoleLogic) SystemUpdateRole(req *types.RoleUpdateRequest) ( | @@ -46,11 +48,12 @@ func (l *SystemUpdateRoleLogic) SystemUpdateRole(req *types.RoleUpdateRequest) ( | ||
46 | return nil, xerr.NewErrMsg(fmt.Sprintf("unknown auth %d ", authId)) | 48 | return nil, xerr.NewErrMsg(fmt.Sprintf("unknown auth %d ", authId)) |
47 | } | 49 | } |
48 | } | 50 | } |
49 | - lo.ForEach(role.Users, func(item domain.User, index int) { | ||
50 | - beforeUserIds = append(beforeUserIds, item.Id) | 51 | + _, userRoles, _ = l.svcCtx.UserRoleRepository.Find(l.ctx, conn, domain.IndexCompanyId(role.CompanyId)().WithKV("roleId", role.Id).WithFindOnly()) |
52 | + beforeUserIds = domain.Values(userRoles, func(item *domain.UserRole) int64 { | ||
53 | + return item.UserId | ||
51 | }) | 54 | }) |
52 | tempRole := NewDomainRole(l.ctx, req.Role) | 55 | tempRole := NewDomainRole(l.ctx, req.Role) |
53 | - lo.ForEach(tempRole.Users, func(item domain.User, index int) { | 56 | + lo.ForEach(req.Role.Users, func(item types.RoleUser, index int) { |
54 | afterUserIds = append(afterUserIds, item.Id) | 57 | afterUserIds = append(afterUserIds, item.Id) |
55 | }) | 58 | }) |
56 | removeList, addList := lo.Difference(beforeUserIds, afterUserIds) | 59 | removeList, addList := lo.Difference(beforeUserIds, afterUserIds) |
@@ -69,26 +72,36 @@ func (l *SystemUpdateRoleLogic) SystemUpdateRole(req *types.RoleUpdateRequest) ( | @@ -69,26 +72,36 @@ func (l *SystemUpdateRoleLogic) SystemUpdateRole(req *types.RoleUpdateRequest) ( | ||
69 | userAddRoleList = append(userAddRoleList, user) | 72 | userAddRoleList = append(userAddRoleList, user) |
70 | } | 73 | } |
71 | if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error { | 74 | if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error { |
75 | + // 更新角色 | ||
72 | role.Name = tempRole.Name | 76 | role.Name = tempRole.Name |
73 | role.Auths = tempRole.Auths | 77 | role.Auths = tempRole.Auths |
74 | role.Remark = tempRole.Remark | 78 | role.Remark = tempRole.Remark |
75 | - role.Users = tempRole.Users | ||
76 | if role, err = l.svcCtx.RoleRepository.UpdateWithVersion(ctx, conn, role); err != nil { | 79 | if role, err = l.svcCtx.RoleRepository.UpdateWithVersion(ctx, conn, role); err != nil { |
77 | return err | 80 | return err |
78 | } | 81 | } |
79 | - | 82 | + // 移除角色用户 |
80 | for _, user := range userRemoveRoleList { | 83 | for _, user := range userRemoveRoleList { |
81 | user.RemoveRole(role.Id) | 84 | user.RemoveRole(role.Id) |
82 | if user, err = l.svcCtx.UserRepository.UpdateWithVersion(ctx, conn, user); err != nil { | 85 | if user, err = l.svcCtx.UserRepository.UpdateWithVersion(ctx, conn, user); err != nil { |
83 | return err | 86 | return err |
84 | } | 87 | } |
88 | + if err = l.svcCtx.UserRoleRepository.DeleteByUserAndRole(ctx, conn, user.Id, role.Id); err != nil { | ||
89 | + return err | ||
90 | + } | ||
85 | } | 91 | } |
86 | - | 92 | + // 新增角色用户 |
87 | for _, user := range userAddRoleList { | 93 | for _, user := range userAddRoleList { |
88 | user.AddRole(role.Id) | 94 | user.AddRole(role.Id) |
89 | if user, err = l.svcCtx.UserRepository.UpdateWithVersion(ctx, conn, user); err != nil { | 95 | if user, err = l.svcCtx.UserRepository.UpdateWithVersion(ctx, conn, user); err != nil { |
90 | return err | 96 | return err |
91 | } | 97 | } |
98 | + if _, err = l.svcCtx.UserRoleRepository.Insert(l.ctx, conn, &domain.UserRole{ | ||
99 | + CompanyId: user.CompanyId, | ||
100 | + UserId: user.Id, | ||
101 | + RoleId: role.Id, | ||
102 | + }); err != nil { | ||
103 | + return err | ||
104 | + } | ||
92 | } | 105 | } |
93 | return nil | 106 | return nil |
94 | }, true); err != nil { | 107 | }, true); err != nil { |
@@ -58,7 +58,7 @@ func NewUserItemSimple(user *domain.User, company *domain.Company) *types.UserIt | @@ -58,7 +58,7 @@ func NewUserItemSimple(user *domain.User, company *domain.Company) *types.UserIt | ||
58 | Id: user.Id, | 58 | Id: user.Id, |
59 | Name: user.Name, | 59 | Name: user.Name, |
60 | CompanyName: lo.Ternary(company != nil, company.Name, ""), | 60 | CompanyName: lo.Ternary(company != nil, company.Name, ""), |
61 | - Avatar: user.Avatar, | 61 | + Avatar: lo.ToPtr(user.Avatar), |
62 | Phone: user.Phone, | 62 | Phone: user.Phone, |
63 | Position: user.Position, | 63 | Position: user.Position, |
64 | AuditStatus: &user.AuditStatus, | 64 | AuditStatus: &user.AuditStatus, |
@@ -48,7 +48,7 @@ func (l *MiniUserInfoLogic) MiniUserInfo(req *types.MiniUserInfoRequest) (resp * | @@ -48,7 +48,7 @@ func (l *MiniUserInfoLogic) MiniUserInfo(req *types.MiniUserInfoRequest) (resp * | ||
48 | User: &types.UserItem{ | 48 | User: &types.UserItem{ |
49 | Id: user.Id, | 49 | Id: user.Id, |
50 | Name: user.Name, | 50 | Name: user.Name, |
51 | - Avatar: user.Avatar, | 51 | + Avatar: lo.ToPtr(user.Avatar), |
52 | Position: user.Position, | 52 | Position: user.Position, |
53 | AuditStatus: lo.ToPtr(user.AuditStatus), | 53 | AuditStatus: lo.ToPtr(user.AuditStatus), |
54 | Enable: user.Enable, | 54 | Enable: user.Enable, |
@@ -34,6 +34,7 @@ func (l *MiniUserNewsLogic) MiniUserNews(req *types.MiniUserNewsRequest) (resp * | @@ -34,6 +34,7 @@ func (l *MiniUserNewsLogic) MiniUserNews(req *types.MiniUserNewsRequest) (resp * | ||
34 | userToken = contextdata.GetUserTokenFromCtx(l.ctx) | 34 | userToken = contextdata.GetUserTokenFromCtx(l.ctx) |
35 | articles []*domain.Article | 35 | articles []*domain.Article |
36 | readArticles = make([]*domain.UserReadArticle, 0) | 36 | readArticles = make([]*domain.UserReadArticle, 0) |
37 | + userMap = make(map[int64]*domain.User) | ||
37 | ) | 38 | ) |
38 | if user, err = l.svcCtx.UserRepository.FindOne(l.ctx, conn, userToken.UserId); err != nil { | 39 | if user, err = l.svcCtx.UserRepository.FindOne(l.ctx, conn, userToken.UserId); err != nil { |
39 | return nil, xerr.NewErrMsgErr("用户不存在", err) | 40 | return nil, xerr.NewErrMsgErr("用户不存在", err) |
@@ -67,8 +68,19 @@ func (l *MiniUserNewsLogic) MiniUserNews(req *types.MiniUserNewsRequest) (resp * | @@ -67,8 +68,19 @@ func (l *MiniUserNewsLogic) MiniUserNews(req *types.MiniUserNewsRequest) (resp * | ||
67 | Title: item.Title, | 68 | Title: item.Title, |
68 | Summary: item.Summary, | 69 | Summary: item.Summary, |
69 | Time: item.CreatedAt, | 70 | Time: item.CreatedAt, |
71 | + Images: make([]string, 0), | ||
70 | ReadFlag: false, | 72 | ReadFlag: false, |
71 | } | 73 | } |
74 | + if author, _ := domain.LazyLoad(userMap, l.ctx, conn, item.AuthorId, l.svcCtx.UserRepository.FindOne); author != nil { | ||
75 | + newsItem.Author = types.UserItem{ | ||
76 | + Id: author.Id, | ||
77 | + Name: author.Name, | ||
78 | + Avatar: lo.ToPtr(author.Avatar), | ||
79 | + } | ||
80 | + } | ||
81 | + for _, img := range item.Images { | ||
82 | + newsItem.Images = append(newsItem.Images, img.Url) | ||
83 | + } | ||
72 | if _, ok := readArticlesMap[item.Id]; ok { | 84 | if _, ok := readArticlesMap[item.Id]; ok { |
73 | newsItem.ReadFlag = true | 85 | newsItem.ReadFlag = true |
74 | } | 86 | } |
@@ -67,10 +67,20 @@ func (l *SystemUserAccountSaveLogic) SystemUserAccountSave(req *types.SystemUser | @@ -67,10 +67,20 @@ func (l *SystemUserAccountSaveLogic) SystemUserAccountSave(req *types.SystemUser | ||
67 | AuditStatus: domain.UserAuditStatusPassed, | 67 | AuditStatus: domain.UserAuditStatusPassed, |
68 | } | 68 | } |
69 | user.WithName(name) | 69 | user.WithName(name) |
70 | + if user, err = l.svcCtx.UserRepository.Insert(ctx, conn, user); err != nil { | ||
71 | + return err | ||
72 | + } | ||
70 | for _, roleId := range req.Roles { | 73 | for _, roleId := range req.Roles { |
74 | + if _, err = l.svcCtx.UserRoleRepository.Insert(l.ctx, conn, &domain.UserRole{ | ||
75 | + CompanyId: user.CompanyId, | ||
76 | + UserId: user.Id, | ||
77 | + RoleId: roleId, | ||
78 | + }); err != nil { | ||
79 | + return err | ||
80 | + } | ||
71 | user.AddRole(roleId) | 81 | user.AddRole(roleId) |
72 | } | 82 | } |
73 | - if user, err = l.svcCtx.UserRepository.Insert(ctx, conn, user); err != nil { | 83 | + if user, err = l.svcCtx.UserRepository.UpdateWithVersion(ctx, conn, user); err != nil { |
74 | return err | 84 | return err |
75 | } | 85 | } |
76 | return nil | 86 | return nil |
@@ -2,6 +2,11 @@ package user | @@ -2,6 +2,11 @@ package user | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "context" | 4 | "context" |
5 | + "github.com/samber/lo" | ||
6 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction" | ||
7 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" | ||
8 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata" | ||
9 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr" | ||
5 | 10 | ||
6 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" | 11 | "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" | 12 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" |
@@ -24,7 +29,49 @@ func NewSystemUserAccountUpdateLogic(ctx context.Context, svcCtx *svc.ServiceCon | @@ -24,7 +29,49 @@ func NewSystemUserAccountUpdateLogic(ctx context.Context, svcCtx *svc.ServiceCon | ||
24 | } | 29 | } |
25 | 30 | ||
26 | func (l *SystemUserAccountUpdateLogic) SystemUserAccountUpdate(req *types.SystemUserAccountUpdateRequest) (resp *types.SystemUserAccountUpdateResponse, err error) { | 31 | func (l *SystemUserAccountUpdateLogic) SystemUserAccountUpdate(req *types.SystemUserAccountUpdateRequest) (resp *types.SystemUserAccountUpdateResponse, err error) { |
27 | - // todo: add your logic here and delete this line | ||
28 | - | 32 | + var ( |
33 | + userToken = contextdata.GetUserTokenFromCtx(l.ctx) | ||
34 | + user *domain.User | ||
35 | + conn = l.svcCtx.DefaultDBConn() | ||
36 | + ) | ||
37 | + if user, err = l.svcCtx.UserRepository.FindOne(l.ctx, conn, req.Id); err != nil { | ||
38 | + return nil, xerr.NewErrMsgErr("用户不存在", err) | ||
39 | + } | ||
40 | + if user.CompanyId != userToken.CompanyId { | ||
41 | + return nil, xerr.NewErrMsgErr("无权限更改", err) | ||
42 | + } | ||
43 | + if req.Name != user.Name { | ||
44 | + user.WithName(req.Name) | ||
45 | + } | ||
46 | + removeList, addList := lo.Difference(user.Roles, req.Roles) | ||
47 | + if len(removeList) > 0 || len(addList) > 0 { | ||
48 | + user.Roles = req.Roles | ||
49 | + } | ||
50 | + user.Enable = req.Status | ||
51 | + if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error { | ||
52 | + if user, err = l.svcCtx.UserRepository.UpdateWithVersion(ctx, conn, user); err != nil { | ||
53 | + return err | ||
54 | + } | ||
55 | + if len(removeList) > 0 || len(addList) > 0 { | ||
56 | + if err = l.svcCtx.UserRoleRepository.DeleteByUser(ctx, conn, user.Id); err != nil { | ||
57 | + return err | ||
58 | + } | ||
59 | + user.Roles = []int64{} | ||
60 | + for _, roleId := range req.Roles { | ||
61 | + if _, err = l.svcCtx.UserRoleRepository.Insert(l.ctx, conn, &domain.UserRole{ | ||
62 | + CompanyId: user.CompanyId, | ||
63 | + UserId: user.Id, | ||
64 | + RoleId: roleId, | ||
65 | + }); err != nil { | ||
66 | + return err | ||
67 | + } | ||
68 | + user.AddRole(roleId) | ||
69 | + } | ||
70 | + } | ||
71 | + return nil | ||
72 | + }, true); err != nil { | ||
73 | + return nil, xerr.NewErrMsgErr("更新用户信息失败", err) | ||
74 | + } | ||
75 | + resp = &types.SystemUserAccountUpdateResponse{} | ||
29 | return | 76 | return |
30 | } | 77 | } |
@@ -39,6 +39,7 @@ type ServiceContext struct { | @@ -39,6 +39,7 @@ type ServiceContext struct { | ||
39 | UserLoveFlagRepository domain.UserLoveFlagRepository | 39 | UserLoveFlagRepository domain.UserLoveFlagRepository |
40 | UserReadArticleRepository domain.UserReadArticleRepository | 40 | UserReadArticleRepository domain.UserReadArticleRepository |
41 | UserRepository domain.UserRepository | 41 | UserRepository domain.UserRepository |
42 | + UserRoleRepository domain.UserRoleRepository | ||
42 | 43 | ||
43 | ApiAuthService authlib.ApiAuthService | 44 | ApiAuthService authlib.ApiAuthService |
44 | SmsService smslib.SMSService | 45 | SmsService smslib.SMSService |
@@ -80,6 +81,7 @@ func NewServiceContext(c config.Config) *ServiceContext { | @@ -80,6 +81,7 @@ func NewServiceContext(c config.Config) *ServiceContext { | ||
80 | UserRepository: repository.NewUserRepository(cache.NewCachedRepository(mlCache)), | 81 | UserRepository: repository.NewUserRepository(cache.NewCachedRepository(mlCache)), |
81 | UserReadArticleRepository: repository.NewUserReadArticleRepository(cache.NewCachedRepository(mlCache)), | 82 | UserReadArticleRepository: repository.NewUserReadArticleRepository(cache.NewCachedRepository(mlCache)), |
82 | ArticleTagRepository: repository.NewArticleTagRepository(cache.NewCachedRepository(mlCache)), | 83 | ArticleTagRepository: repository.NewArticleTagRepository(cache.NewCachedRepository(mlCache)), |
84 | + UserRoleRepository: repository.NewUserRoleRepository(cache.NewCachedRepository(mlCache)), | ||
83 | } | 85 | } |
84 | } | 86 | } |
85 | 87 |
@@ -472,12 +472,14 @@ type MiniUserNewsResposne struct { | @@ -472,12 +472,14 @@ type MiniUserNewsResposne struct { | ||
472 | } | 472 | } |
473 | 473 | ||
474 | type UserNewsItem struct { | 474 | type UserNewsItem struct { |
475 | - NewsId int64 `json:"newsId"` // 快讯ID | ||
476 | - Type string `json:"type"` // 快讯类型 文章:Article 讨论:Discuss ... | ||
477 | - Title string `json:"title"` // 标题 | ||
478 | - Summary string `json:"summary"` // 快讯概要 | ||
479 | - Time int64 `json:"time"` // 时间 | ||
480 | - ReadFlag bool `json:"readFlag"` // 已读标识 true:已读 false:未读 | 475 | + NewsId int64 `json:"newsId"` // 快讯ID |
476 | + Type string `json:"type"` // 快讯类型 文章:Article 讨论:Discuss ... | ||
477 | + Title string `json:"title"` // 标题 | ||
478 | + Summary string `json:"summary"` // 快讯概要 | ||
479 | + Time int64 `json:"time"` // 时间 | ||
480 | + ReadFlag bool `json:"readFlag"` // 已读标识 true:已读 false:未读 | ||
481 | + Images []string `json:"images"` // 图片列表 | ||
482 | + Author UserItem `json:"author"` // 作者 | ||
481 | } | 483 | } |
482 | 484 | ||
483 | type MiniUserFollowedSearchRequest struct { | 485 | type MiniUserFollowedSearchRequest struct { |
@@ -503,7 +505,7 @@ type UserItem struct { | @@ -503,7 +505,7 @@ type UserItem struct { | ||
503 | CompanyLogo *string `json:"companyLogo,omitempty"` // 公司LOGO | 505 | CompanyLogo *string `json:"companyLogo,omitempty"` // 公司LOGO |
504 | Flag int `json:"flag,omitempty"` // 标识 1:管理员 2:普通用户 (有绑定角色是管理员) | 506 | Flag int `json:"flag,omitempty"` // 标识 1:管理员 2:普通用户 (有绑定角色是管理员) |
505 | Name string `json:"name,omitempty"` // 名称 | 507 | Name string `json:"name,omitempty"` // 名称 |
506 | - Avatar string `json:"avatar,omitempty"` // 头像 | 508 | + Avatar *string `json:"avatar,omitempty"` // 头像 |
507 | Phone string `json:"phone,omitempty"` // 手机号 唯一 | 509 | Phone string `json:"phone,omitempty"` // 手机号 唯一 |
508 | Position string `json:"position,omitempty"` // 职位 | 510 | Position string `json:"position,omitempty"` // 职位 |
509 | Enable int `json:"enable,omitempty"` // 启用状态 1:启用 2:禁用 | 511 | Enable int `json:"enable,omitempty"` // 启用状态 1:启用 2:禁用 |
@@ -689,7 +691,10 @@ type SystemUserAccountEnableResponse struct { | @@ -689,7 +691,10 @@ type SystemUserAccountEnableResponse struct { | ||
689 | } | 691 | } |
690 | 692 | ||
691 | type SystemUserAccountUpdateRequest struct { | 693 | type SystemUserAccountUpdateRequest struct { |
692 | - Id int64 `path:"id"` | 694 | + Id int64 `path:"id"` |
695 | + Name string `json:"name"` // 姓名 | ||
696 | + Roles []int64 `json:"roles"` // 权限角色 | ||
697 | + Status int `json:"enable"` // 状态 1:启用 2:禁用 | ||
693 | } | 698 | } |
694 | 699 | ||
695 | type SystemUserAccountUpdateResponse struct { | 700 | type SystemUserAccountUpdateResponse struct { |
@@ -864,10 +869,10 @@ type WhichUserLikeArticle struct { | @@ -864,10 +869,10 @@ type WhichUserLikeArticle struct { | ||
864 | } | 869 | } |
865 | 870 | ||
866 | type MiniSetUserLikeRequset struct { | 871 | type MiniSetUserLikeRequset struct { |
867 | - ArticleId int64 `json:"articleId"` //文章id | ||
868 | - CommentId int64 `json:"commentId"` //评论id | ||
869 | - UserId int64 `json:",optional"` //操作人 | ||
870 | - Flag int `json:"flag"` //点赞标志 1、点赞 2 、取消点赞 | 872 | + ArticleId int64 `json:"articleId"` //文章id |
873 | + CommentId int64 `json:"commentId,optional"` //评论id | ||
874 | + UserId int64 `json:",optional"` //操作人 | ||
875 | + Flag int `json:"flag"` //点赞标志 1、点赞 2 、取消点赞 | ||
871 | } | 876 | } |
872 | 877 | ||
873 | type MiniSetUserLikeResponse struct { | 878 | type MiniSetUserLikeResponse struct { |
@@ -1220,7 +1225,7 @@ type MiniSearchArticleItem struct { | @@ -1220,7 +1225,7 @@ type MiniSearchArticleItem struct { | ||
1220 | ArticleId int64 `json:"articleId"` | 1225 | ArticleId int64 `json:"articleId"` |
1221 | Title string `json:"title"` | 1226 | Title string `json:"title"` |
1222 | Author string `json:"author"` // 发布人 | 1227 | Author string `json:"author"` // 发布人 |
1223 | - Avatar string `json:"avatar"` | 1228 | + Avatar string `json:"avatar"` // 发布人的头像 |
1224 | Images []string `json:"images"` | 1229 | Images []string `json:"images"` |
1225 | CreatedAt int64 `json:"createdAt"` | 1230 | CreatedAt int64 `json:"createdAt"` |
1226 | MeReadFlag int `json:"meReadFlag"` //已读标识 [0:未读] [1:已读] | 1231 | MeReadFlag int `json:"meReadFlag"` //已读标识 [0:未读] [1:已读] |
@@ -1269,15 +1274,15 @@ type RoleSearchResponse struct { | @@ -1269,15 +1274,15 @@ type RoleSearchResponse struct { | ||
1269 | } | 1274 | } |
1270 | 1275 | ||
1271 | type RoleItem struct { | 1276 | type RoleItem struct { |
1272 | - Id int64 `json:"id,optional"` // 角色ID | ||
1273 | - CompanyId int64 `json:"companyId,optional,omitempty"` // 公司ID | ||
1274 | - Name string `json:"name"` // 角色名称 | ||
1275 | - AuthIds []int64 `json:"authIds,optional,omitempty"` // 角色权限列表 | ||
1276 | - AuthsDesc string `json:"authsDesc,optional,omitempty"` // 权限列表描述 | ||
1277 | - UsersDesc string `json:"usersDesc,optional,omitempty"` // 用户列表描述 | ||
1278 | - Remark string `json:"remark,optional,omitempty"` // 备注 | ||
1279 | - Users []RoleUser `json:"users,optional,omitempty"` // 绑定的用户 | ||
1280 | - UpdatedAt int64 `json:"updatedAt,optional,omitempty"` // 更新时间 | 1277 | + Id int64 `json:"id,optional"` // 角色ID |
1278 | + CompanyId int64 `json:"companyId,optional,string,omitempty"` // 公司ID | ||
1279 | + Name string `json:"name"` // 角色名称 | ||
1280 | + AuthIds []int64 `json:"authIds,optional,omitempty"` // 角色权限列表 | ||
1281 | + AuthsDesc string `json:"authsDesc,optional,omitempty"` // 权限列表描述 | ||
1282 | + UsersDesc string `json:"usersDesc,optional,omitempty"` // 用户列表描述 | ||
1283 | + Remark string `json:"remark,optional,omitempty"` // 备注 | ||
1284 | + Users []RoleUser `json:"users,optional,omitempty"` // 绑定的用户 | ||
1285 | + UpdatedAt int64 `json:"updatedAt,optional,omitempty"` // 更新时间 | ||
1281 | } | 1286 | } |
1282 | 1287 | ||
1283 | type RoleUser struct { | 1288 | type RoleUser struct { |
cmd/discuss/doc/dsl/api/user_role.api
0 → 100644
1 | + | ||
2 | +syntax = "v1" | ||
3 | + | ||
4 | +info( | ||
5 | + title: "xx实例" | ||
6 | + desc: "xx实例" | ||
7 | + author: "author" | ||
8 | + email: "email" | ||
9 | + version: "v1" | ||
10 | +) | ||
11 | + | ||
12 | +@server( | ||
13 | + prefix: user_role/v1 | ||
14 | + group: user_role | ||
15 | + jwt: JwtAuth | ||
16 | +) | ||
17 | +service Core { | ||
18 | + @handler getUserRole | ||
19 | + post /user_role/:id (UserRoleGetRequest) returns (UserRoleGetResponse) | ||
20 | + @handler saveUserRole | ||
21 | + post /user_role (UserRoleSaveRequest) returns (UserRoleSaveResponse) | ||
22 | + @handler deleteUserRole | ||
23 | + delete /user_role/:id (UserRoleDeleteRequest) returns (UserRoleDeleteResponse) | ||
24 | + @handler updateUserRole | ||
25 | + put /user_role/:id (UserRoleUpdateRequest) returns (UserRoleUpdateResponse) | ||
26 | + @handler searchUserRole | ||
27 | + post /user_role/search (UserRoleSearchRequest) returns (UserRoleSearchResponse) | ||
28 | +} | ||
29 | + | ||
30 | +type ( | ||
31 | + UserRoleGetRequest { | ||
32 | + Id int64 `path:"id"` | ||
33 | + } | ||
34 | + UserRoleGetResponse struct{ | ||
35 | + UserRole UserRoleItem `json:"user_role"` | ||
36 | + } | ||
37 | + | ||
38 | + UserRoleSaveRequest struct{ | ||
39 | + UserRole UserRoleItem `json:"user_role"` | ||
40 | + } | ||
41 | + UserRoleSaveResponse struct{} | ||
42 | + | ||
43 | + UserRoleDeleteRequest struct{ | ||
44 | + Id int64 `path:"id"` | ||
45 | + } | ||
46 | + UserRoleDeleteResponse struct{} | ||
47 | + | ||
48 | + UserRoleUpdateRequest struct{ | ||
49 | + Id int64 `path:"id"` | ||
50 | + UserRole UserRoleItem `json:"user_role"` | ||
51 | + } | ||
52 | + UserRoleUpdateResponse struct{} | ||
53 | + | ||
54 | + UserRoleSearchRequest struct{ | ||
55 | + Page int `json:"page"` | ||
56 | + Size int `json:"size"` | ||
57 | + } | ||
58 | + UserRoleSearchResponse{ | ||
59 | + List []UserRoleItem `json:"list"` | ||
60 | + Total int64 `json:"total"` | ||
61 | + } | ||
62 | + UserRoleItem struct{ | ||
63 | + | ||
64 | + } | ||
65 | +) |
cmd/discuss/doc/dsl/rpc/user_role.proto
0 → 100644
1 | + | ||
2 | +syntax = "proto3"; | ||
3 | + | ||
4 | +option go_package ="./pb"; | ||
5 | + | ||
6 | +package pb; | ||
7 | + | ||
8 | +message UserRoleGetReq { | ||
9 | + int64 Id = 1; | ||
10 | +} | ||
11 | +message UserRoleGetResp{ | ||
12 | + UserRoleItem User = 1; | ||
13 | +} | ||
14 | + | ||
15 | +message UserRoleSaveReq { | ||
16 | + | ||
17 | +} | ||
18 | +message UserRoleSaveResp{ | ||
19 | + | ||
20 | +} | ||
21 | + | ||
22 | +message UserRoleDeleteReq { | ||
23 | + int64 Id = 1; | ||
24 | +} | ||
25 | +message UserRoleDeleteResp{ | ||
26 | + | ||
27 | +} | ||
28 | + | ||
29 | +message UserRoleUpdateReq { | ||
30 | + int64 Id = 1; | ||
31 | +} | ||
32 | +message UserRoleUpdateResp{ | ||
33 | + | ||
34 | +} | ||
35 | + | ||
36 | +message UserRoleSearchReq { | ||
37 | + int64 PageNumber = 1; | ||
38 | + int64 PageSize = 2; | ||
39 | +} | ||
40 | +message UserRoleSearchResp{ | ||
41 | + repeated UserRoleItem List =1; | ||
42 | + int64 Total =2; | ||
43 | +} | ||
44 | +message UserRoleItem { | ||
45 | + | ||
46 | +} | ||
47 | + | ||
48 | +service UserRoleService { | ||
49 | + rpc UserRoleGet(UserRoleGetReq) returns(UserRoleGetResp); | ||
50 | + rpc UserRoleSave(UserRoleSaveReq) returns(UserRoleSaveResp); | ||
51 | + rpc UserRoleDelete(UserRoleDeleteReq) returns(UserRoleDeleteResp); | ||
52 | + rpc UserRoleUpdate(UserRoleUpdateReq) returns(UserRoleUpdateResp); | ||
53 | + rpc UserRoleSearch(UserRoleSearchReq) returns(UserRoleSearchResp); | ||
54 | +} |
@@ -16,6 +16,7 @@ func Migrate(db *gorm.DB) { | @@ -16,6 +16,7 @@ func Migrate(db *gorm.DB) { | ||
16 | &models.UserLoveFlag{}, | 16 | &models.UserLoveFlag{}, |
17 | &models.UserReadArticle{}, | 17 | &models.UserReadArticle{}, |
18 | &models.User{}, | 18 | &models.User{}, |
19 | + &models.UserRole{}, | ||
19 | &models.Role{}, | 20 | &models.Role{}, |
20 | &models.Company{}, | 21 | &models.Company{}, |
21 | &models.UserFollow{}, | 22 | &models.UserFollow{}, |
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "gorm.io/gorm" | ||
5 | +) | ||
6 | + | ||
7 | +type UserRole struct { | ||
8 | + Id int64 // 唯一标识 | ||
9 | + CompanyId int64 // 公司ID | ||
10 | + UserId int64 | ||
11 | + RoleId int64 | ||
12 | + CreatedAt int64 | ||
13 | + UpdatedAt int64 | ||
14 | + DeletedAt int64 | ||
15 | + Version int | ||
16 | +} | ||
17 | + | ||
18 | +func (m *UserRole) TableName() string { | ||
19 | + return "user_role" | ||
20 | +} | ||
21 | + | ||
22 | +func (m *UserRole) BeforeCreate(tx *gorm.DB) (err error) { | ||
23 | + // m.CreatedAt = time.Now().Unix() | ||
24 | + // m.UpdatedAt = time.Now().Unix() | ||
25 | + return | ||
26 | +} | ||
27 | + | ||
28 | +func (m *UserRole) BeforeUpdate(tx *gorm.DB) (err error) { | ||
29 | + // m.UpdatedAt = time.Now().Unix() | ||
30 | + return | ||
31 | +} | ||
32 | + | ||
33 | +func (m *UserRole) CacheKeyFunc() string { | ||
34 | + return "" | ||
35 | +} | ||
36 | + | ||
37 | +func (m *UserRole) CacheKeyFuncByObject(obj interface{}) string { | ||
38 | + if v, ok := obj.(*UserRole); ok { | ||
39 | + return v.CacheKeyFunc() | ||
40 | + } | ||
41 | + return "" | ||
42 | +} | ||
43 | + | ||
44 | +func (m *UserRole) CachePrimaryKeyFunc() string { | ||
45 | + return "" | ||
46 | +} |
@@ -242,6 +242,39 @@ func (repository *UserRepository) FindDepartmentUsers(ctx context.Context, conn | @@ -242,6 +242,39 @@ func (repository *UserRepository) FindDepartmentUsers(ctx context.Context, conn | ||
242 | return total, dms, nil | 242 | return total, dms, nil |
243 | } | 243 | } |
244 | 244 | ||
245 | +func (repository *UserRepository) FindByCompanyRoles(ctx context.Context, conn transaction.Conn, companyId int64, roles []int64, queryOptions map[string]interface{}) (int64, []*domain.User, error) { | ||
246 | + var ( | ||
247 | + tx = conn.DB() | ||
248 | + ms []*models.User | ||
249 | + dms = make([]*domain.User, 0) | ||
250 | + total int64 | ||
251 | + ) | ||
252 | + queryFunc := func() (interface{}, error) { | ||
253 | + tx = tx.Model(&ms).Order("id asc") | ||
254 | + tx.Select("id", "name", "roles") | ||
255 | + tx.Where("company_id = ?", companyId) | ||
256 | + tx.Where("flag = ?", domain.UserAdmin) | ||
257 | + tx.Where("id in (select user_id from user_role where role_id in(?)) ", roles) | ||
258 | + if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil { | ||
259 | + return dms, tx.Error | ||
260 | + } | ||
261 | + return dms, nil | ||
262 | + } | ||
263 | + | ||
264 | + if _, err := repository.Query(queryFunc); err != nil { | ||
265 | + return 0, nil, err | ||
266 | + } | ||
267 | + | ||
268 | + for _, item := range ms { | ||
269 | + if dm, err := repository.ModelToDomainModel(item); err != nil { | ||
270 | + return 0, dms, err | ||
271 | + } else { | ||
272 | + dms = append(dms, dm) | ||
273 | + } | ||
274 | + } | ||
275 | + return total, dms, nil | ||
276 | +} | ||
277 | + | ||
245 | func (repository *UserRepository) FindCompanyPositions(ctx context.Context, conn transaction.Conn, companyId int64, queryOptions map[string]interface{}) (int64, []*domain.User, error) { | 278 | func (repository *UserRepository) FindCompanyPositions(ctx context.Context, conn transaction.Conn, companyId int64, queryOptions map[string]interface{}) (int64, []*domain.User, error) { |
246 | var ( | 279 | var ( |
247 | tx = conn.DB() | 280 | tx = conn.DB() |
1 | +package repository | ||
2 | + | ||
3 | +import ( | ||
4 | + "context" | ||
5 | + "github.com/jinzhu/copier" | ||
6 | + "github.com/pkg/errors" | ||
7 | + "github.com/tiptok/gocomm/pkg/cache" | ||
8 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/models" | ||
9 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction" | ||
10 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" | ||
11 | + "gorm.io/gorm" | ||
12 | +) | ||
13 | + | ||
14 | +type UserRoleRepository struct { | ||
15 | + *cache.CachedRepository | ||
16 | +} | ||
17 | + | ||
18 | +func (repository *UserRoleRepository) Insert(ctx context.Context, conn transaction.Conn, dm *domain.UserRole) (*domain.UserRole, error) { | ||
19 | + var ( | ||
20 | + err error | ||
21 | + m = &models.UserRole{} | ||
22 | + tx = conn.DB() | ||
23 | + ) | ||
24 | + if m, err = repository.DomainModelToModel(dm); err != nil { | ||
25 | + return nil, err | ||
26 | + } | ||
27 | + if tx = tx.Model(m).Save(m); tx.Error != nil { | ||
28 | + return nil, tx.Error | ||
29 | + } | ||
30 | + dm.Id = m.Id | ||
31 | + return repository.ModelToDomainModel(m) | ||
32 | + | ||
33 | +} | ||
34 | + | ||
35 | +func (repository *UserRoleRepository) Update(ctx context.Context, conn transaction.Conn, dm *domain.UserRole) (*domain.UserRole, error) { | ||
36 | + var ( | ||
37 | + err error | ||
38 | + m *models.UserRole | ||
39 | + tx = conn.DB() | ||
40 | + ) | ||
41 | + if m, err = repository.DomainModelToModel(dm); err != nil { | ||
42 | + return nil, err | ||
43 | + } | ||
44 | + queryFunc := func() (interface{}, error) { | ||
45 | + tx = tx.Model(m).Updates(m) | ||
46 | + return nil, tx.Error | ||
47 | + } | ||
48 | + if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil { | ||
49 | + return nil, err | ||
50 | + } | ||
51 | + return repository.ModelToDomainModel(m) | ||
52 | +} | ||
53 | + | ||
54 | +func (repository *UserRoleRepository) UpdateWithVersion(ctx context.Context, transaction transaction.Conn, dm *domain.UserRole) (*domain.UserRole, error) { | ||
55 | + var ( | ||
56 | + err error | ||
57 | + m *models.UserRole | ||
58 | + tx = transaction.DB() | ||
59 | + ) | ||
60 | + if m, err = repository.DomainModelToModel(dm); err != nil { | ||
61 | + return nil, err | ||
62 | + } | ||
63 | + oldVersion := dm.Version | ||
64 | + m.Version += 1 | ||
65 | + queryFunc := func() (interface{}, error) { | ||
66 | + tx = tx.Model(m).Select("*").Where("id = ?", m.Id).Where("version = ?", oldVersion).Updates(m) | ||
67 | + if tx.RowsAffected == 0 { | ||
68 | + return nil, domain.ErrUpdateFail | ||
69 | + } | ||
70 | + return nil, tx.Error | ||
71 | + } | ||
72 | + if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil { | ||
73 | + return nil, err | ||
74 | + } | ||
75 | + return repository.ModelToDomainModel(m) | ||
76 | +} | ||
77 | + | ||
78 | +func (repository *UserRoleRepository) Delete(ctx context.Context, conn transaction.Conn, dm *domain.UserRole) (*domain.UserRole, error) { | ||
79 | + var ( | ||
80 | + tx = conn.DB() | ||
81 | + m = &models.UserRole{Id: dm.Identify().(int64)} | ||
82 | + ) | ||
83 | + queryFunc := func() (interface{}, error) { | ||
84 | + tx = tx.Where("id = ?", m.Id).Delete(m) | ||
85 | + return m, tx.Error | ||
86 | + } | ||
87 | + if _, err := repository.Query(queryFunc, m.CacheKeyFunc()); err != nil { | ||
88 | + return dm, err | ||
89 | + } | ||
90 | + return repository.ModelToDomainModel(m) | ||
91 | +} | ||
92 | + | ||
93 | +func (repository *UserRoleRepository) DeleteByUser(ctx context.Context, conn transaction.Conn, userId int64) error { | ||
94 | + var ( | ||
95 | + tx = conn.DB() | ||
96 | + m = &models.UserRole{} | ||
97 | + ) | ||
98 | + queryFunc := func() (interface{}, error) { | ||
99 | + tx = tx.Where("user_id = ?", userId).Delete(m) | ||
100 | + return m, tx.Error | ||
101 | + } | ||
102 | + if _, err := repository.Query(queryFunc, m.CacheKeyFunc()); err != nil { | ||
103 | + return err | ||
104 | + } | ||
105 | + return nil | ||
106 | +} | ||
107 | + | ||
108 | +func (repository *UserRoleRepository) DeleteRole(ctx context.Context, conn transaction.Conn, roleId int64) error { | ||
109 | + var ( | ||
110 | + tx = conn.DB() | ||
111 | + m = &models.UserRole{} | ||
112 | + ) | ||
113 | + queryFunc := func() (interface{}, error) { | ||
114 | + tx = tx.Where("role_id = ?", roleId).Delete(m) | ||
115 | + return m, tx.Error | ||
116 | + } | ||
117 | + if _, err := repository.Query(queryFunc, m.CacheKeyFunc()); err != nil { | ||
118 | + return err | ||
119 | + } | ||
120 | + return nil | ||
121 | +} | ||
122 | + | ||
123 | +func (repository *UserRoleRepository) DeleteByUserAndRole(ctx context.Context, conn transaction.Conn, userId int64, roleId int64) error { | ||
124 | + var ( | ||
125 | + tx = conn.DB() | ||
126 | + m = &models.UserRole{} | ||
127 | + ) | ||
128 | + queryFunc := func() (interface{}, error) { | ||
129 | + tx = tx.Where("user_id = ?", userId).Where("role_id = ?", roleId).Delete(m) | ||
130 | + return m, tx.Error | ||
131 | + } | ||
132 | + if _, err := repository.Query(queryFunc, m.CacheKeyFunc()); err != nil { | ||
133 | + return err | ||
134 | + } | ||
135 | + return nil | ||
136 | +} | ||
137 | + | ||
138 | +func (repository *UserRoleRepository) FindOne(ctx context.Context, conn transaction.Conn, id int64) (*domain.UserRole, error) { | ||
139 | + var ( | ||
140 | + err error | ||
141 | + tx = conn.DB() | ||
142 | + m = new(models.UserRole) | ||
143 | + ) | ||
144 | + queryFunc := func() (interface{}, error) { | ||
145 | + tx = tx.Model(m).Where("id = ?", id).First(m) | ||
146 | + if errors.Is(tx.Error, gorm.ErrRecordNotFound) { | ||
147 | + return nil, domain.ErrNotFound | ||
148 | + } | ||
149 | + return m, tx.Error | ||
150 | + } | ||
151 | + cacheModel := new(models.UserRole) | ||
152 | + cacheModel.Id = id | ||
153 | + if err = repository.QueryCache(cacheModel.CacheKeyFunc, m, queryFunc); err != nil { | ||
154 | + return nil, err | ||
155 | + } | ||
156 | + return repository.ModelToDomainModel(m) | ||
157 | +} | ||
158 | + | ||
159 | +func (repository *UserRoleRepository) Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*domain.UserRole, error) { | ||
160 | + var ( | ||
161 | + tx = conn.DB() | ||
162 | + ms []*models.UserRole | ||
163 | + dms = make([]*domain.UserRole, 0) | ||
164 | + total int64 | ||
165 | + ) | ||
166 | + queryFunc := func() (interface{}, error) { | ||
167 | + tx = tx.Model(&ms).Order("id desc") | ||
168 | + if v, ok := queryOptions["companyId"]; ok { | ||
169 | + tx.Where("company_id = ?", v) | ||
170 | + } | ||
171 | + if v, ok := queryOptions["roleId"]; ok { | ||
172 | + tx.Where("role_id = ?", v) | ||
173 | + } | ||
174 | + if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil { | ||
175 | + return dms, tx.Error | ||
176 | + } | ||
177 | + return dms, nil | ||
178 | + } | ||
179 | + | ||
180 | + if _, err := repository.Query(queryFunc); err != nil { | ||
181 | + return 0, nil, err | ||
182 | + } | ||
183 | + | ||
184 | + for _, item := range ms { | ||
185 | + if dm, err := repository.ModelToDomainModel(item); err != nil { | ||
186 | + return 0, dms, err | ||
187 | + } else { | ||
188 | + dms = append(dms, dm) | ||
189 | + } | ||
190 | + } | ||
191 | + return total, dms, nil | ||
192 | +} | ||
193 | + | ||
194 | +func (repository *UserRoleRepository) ModelToDomainModel(from *models.UserRole) (*domain.UserRole, error) { | ||
195 | + to := &domain.UserRole{} | ||
196 | + err := copier.Copy(to, from) | ||
197 | + return to, err | ||
198 | +} | ||
199 | + | ||
200 | +func (repository *UserRoleRepository) DomainModelToModel(from *domain.UserRole) (*models.UserRole, error) { | ||
201 | + to := &models.UserRole{} | ||
202 | + err := copier.Copy(to, from) | ||
203 | + return to, err | ||
204 | +} | ||
205 | + | ||
206 | +func NewUserRoleRepository(cache *cache.CachedRepository) domain.UserRoleRepository { | ||
207 | + return &UserRoleRepository{CachedRepository: cache} | ||
208 | +} |
@@ -11,7 +11,7 @@ type Role struct { | @@ -11,7 +11,7 @@ type Role struct { | ||
11 | Name string `json:"name"` // 角色名称 | 11 | Name string `json:"name"` // 角色名称 |
12 | Auths []int64 `json:"auths"` // 角色权限列表 | 12 | Auths []int64 `json:"auths"` // 角色权限列表 |
13 | Remark string `json:"remark"` // 备注 | 13 | Remark string `json:"remark"` // 备注 |
14 | - Users []User `json:"users"` // 绑定的用户 | 14 | + //Users []User `json:"users"` // (废弃)绑定的用户 |
15 | 15 | ||
16 | CreatedAt int64 `json:"createdAt,omitempty"` | 16 | CreatedAt int64 `json:"createdAt,omitempty"` |
17 | UpdatedAt int64 `json:"updatedAt,omitempty"` | 17 | UpdatedAt int64 `json:"updatedAt,omitempty"` |
@@ -39,6 +39,7 @@ type UserRepository interface { | @@ -39,6 +39,7 @@ type UserRepository interface { | ||
39 | FindOne(ctx context.Context, conn transaction.Conn, id int64) (*User, error) | 39 | FindOne(ctx context.Context, conn transaction.Conn, id int64) (*User, error) |
40 | FindOneByCompanyIdAndPhone(ctx context.Context, conn transaction.Conn, companyId int64, phone string, status []int) (*User, error) | 40 | FindOneByCompanyIdAndPhone(ctx context.Context, conn transaction.Conn, companyId int64, phone string, status []int) (*User, error) |
41 | Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*User, error) | 41 | Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*User, error) |
42 | + FindByCompanyRoles(ctx context.Context, conn transaction.Conn, companyId int64, roles []int64, queryOptions map[string]interface{}) (int64, []*User, error) | ||
42 | FindDepartmentUsers(ctx context.Context, conn transaction.Conn, companyId int64, queryOptions map[string]interface{}) (int64, []*User, error) | 43 | FindDepartmentUsers(ctx context.Context, conn transaction.Conn, companyId int64, queryOptions map[string]interface{}) (int64, []*User, error) |
43 | FindCompanyPositions(ctx context.Context, conn transaction.Conn, companyId int64, queryOptions map[string]interface{}) (int64, []*User, error) | 44 | FindCompanyPositions(ctx context.Context, conn transaction.Conn, companyId int64, queryOptions map[string]interface{}) (int64, []*User, error) |
44 | } | 45 | } |
cmd/discuss/interanl/pkg/domain/user_role.go
0 → 100644
1 | +package domain | ||
2 | + | ||
3 | +import ( | ||
4 | + "context" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction" | ||
6 | +) | ||
7 | + | ||
8 | +type UserRole struct { | ||
9 | + Id int64 // 唯一标识 | ||
10 | + CompanyId int64 // 公司ID | ||
11 | + UserId int64 | ||
12 | + RoleId int64 | ||
13 | + CreatedAt int64 | ||
14 | + UpdatedAt int64 | ||
15 | + DeletedAt int64 | ||
16 | + Version int | ||
17 | +} | ||
18 | + | ||
19 | +type UserRoleRepository interface { | ||
20 | + Insert(ctx context.Context, conn transaction.Conn, dm *UserRole) (*UserRole, error) | ||
21 | + Update(ctx context.Context, conn transaction.Conn, dm *UserRole) (*UserRole, error) | ||
22 | + UpdateWithVersion(ctx context.Context, conn transaction.Conn, dm *UserRole) (*UserRole, error) | ||
23 | + Delete(ctx context.Context, conn transaction.Conn, dm *UserRole) (*UserRole, error) | ||
24 | + DeleteByUser(ctx context.Context, conn transaction.Conn, userId int64) error | ||
25 | + DeleteRole(ctx context.Context, conn transaction.Conn, roleId int64) error | ||
26 | + DeleteByUserAndRole(ctx context.Context, conn transaction.Conn, userId int64, roleId int64) error | ||
27 | + FindOne(ctx context.Context, conn transaction.Conn, id int64) (*UserRole, error) | ||
28 | + Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*UserRole, error) | ||
29 | +} | ||
30 | + | ||
31 | +func (m *UserRole) Identify() interface{} { | ||
32 | + if m.Id == 0 { | ||
33 | + return nil | ||
34 | + } | ||
35 | + return m.Id | ||
36 | +} |
1 | -CREATE TABLE `comment` ( | ||
2 | - `id` int(0) NOT NULL COMMENT '唯一标识', | ||
3 | - PRIMARY KEY (`id`) USING BTREE | ||
4 | -) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic; | ||
5 | - | ||
6 | CREATE TABLE `department` ( | 1 | CREATE TABLE `department` ( |
7 | `id` int(0) NOT NULL COMMENT '唯一标识', | 2 | `id` int(0) NOT NULL COMMENT '唯一标识', |
8 | PRIMARY KEY (`id`) USING BTREE | 3 | PRIMARY KEY (`id`) USING BTREE |
@@ -18,6 +13,11 @@ CREATE TABLE `user` ( | @@ -18,6 +13,11 @@ CREATE TABLE `user` ( | ||
18 | PRIMARY KEY (`id`) USING BTREE | 13 | PRIMARY KEY (`id`) USING BTREE |
19 | ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic; | 14 | ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic; |
20 | 15 | ||
16 | +CREATE TABLE `user_role` ( | ||
17 | + `id` int(0) NOT NULL COMMENT '唯一标识', | ||
18 | + PRIMARY KEY (`id`) USING BTREE | ||
19 | +) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic; | ||
20 | + | ||
21 | CREATE TABLE `company` ( | 21 | CREATE TABLE `company` ( |
22 | `id` int(0) NOT NULL COMMENT '唯一标识', | 22 | `id` int(0) NOT NULL COMMENT '唯一标识', |
23 | PRIMARY KEY (`id`) USING BTREE | 23 | PRIMARY KEY (`id`) USING BTREE |
-
请 注册 或 登录 后发表评论