Merge branch 'dev' of http://gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss into dev-zhuang
正在显示
42 个修改的文件
包含
283 行增加
和
87 行删除
1 | package main | 1 | package main |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | + "context" | ||
4 | "flag" | 5 | "flag" |
6 | + "github.com/zeromicro/go-zero/rest/httpx" | ||
5 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db" | 7 | "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" | ||
9 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result" | ||
10 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr" | ||
6 | "net/http" | 11 | "net/http" |
7 | "strings" | 12 | "strings" |
8 | 13 | ||
9 | - "github.com/zeromicro/go-zero/core/logx" | ||
10 | - "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" | ||
11 | - | ||
12 | "github.com/golang-jwt/jwt/v4/request" | 14 | "github.com/golang-jwt/jwt/v4/request" |
13 | "github.com/zeromicro/go-zero/core/conf" | 15 | "github.com/zeromicro/go-zero/core/conf" |
16 | + "github.com/zeromicro/go-zero/core/logx" | ||
14 | "github.com/zeromicro/go-zero/rest" | 17 | "github.com/zeromicro/go-zero/rest" |
15 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/config" | 18 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/config" |
16 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/handler" | 19 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/handler" |
@@ -20,27 +23,16 @@ import ( | @@ -20,27 +23,16 @@ import ( | ||
20 | var configFile = flag.String("f", "cmd/discuss/api/etc/core.yaml", "the config file") | 23 | var configFile = flag.String("f", "cmd/discuss/api/etc/core.yaml", "the config file") |
21 | 24 | ||
22 | func main() { | 25 | func main() { |
26 | + // 配置加载 | ||
23 | flag.Parse() | 27 | flag.Parse() |
24 | - | ||
25 | var c config.Config | 28 | var c config.Config |
26 | conf.MustLoad(*configFile, &c) | 29 | conf.MustLoad(*configFile, &c) |
27 | 30 | ||
28 | - // 默认的token头 Authorization 修改未 x-token | ||
29 | - request.AuthorizationHeaderExtractor = &request.PostExtractionFilter{ | ||
30 | - request.HeaderExtractor{"x-mmm-accesstoken"}, func(tok string) (string, error) { | ||
31 | - // Should be a bearer token | ||
32 | - if len(tok) > 6 && strings.ToUpper(tok[0:7]) == "BEARER " { | ||
33 | - return tok[7:], nil | ||
34 | - } | ||
35 | - return tok, nil | ||
36 | - }, | ||
37 | - } | ||
38 | - | ||
39 | - // 初始化Domain里面的配置 | ||
40 | - domain.ProjectName = c.Name | 31 | + // 系统设置 |
32 | + systemSetup(c) | ||
41 | 33 | ||
34 | + // 服务初始化 | ||
42 | opts := make([]rest.RunOption, 0) | 35 | opts := make([]rest.RunOption, 0) |
43 | - // cors | ||
44 | opt := rest.WithCustomCors(func(header http.Header) { | 36 | opt := rest.WithCustomCors(func(header http.Header) { |
45 | header.Set("Access-Control-Allow-Headers", "*") | 37 | header.Set("Access-Control-Allow-Headers", "*") |
46 | }, func(writer http.ResponseWriter) { | 38 | }, func(writer http.ResponseWriter) { |
@@ -49,14 +41,40 @@ func main() { | @@ -49,14 +41,40 @@ func main() { | ||
49 | opts = append(opts, opt) | 41 | opts = append(opts, opt) |
50 | server := rest.MustNewServer(c.RestConf, opts...) | 42 | server := rest.MustNewServer(c.RestConf, opts...) |
51 | defer server.Stop() | 43 | defer server.Stop() |
52 | - | ||
53 | ctx := svc.NewServiceContext(c) | 44 | ctx := svc.NewServiceContext(c) |
54 | handler.RegisterHandlers(server, ctx) | 45 | handler.RegisterHandlers(server, ctx) |
55 | 46 | ||
47 | + // 数据迁移 | ||
56 | if c.Migrate { | 48 | if c.Migrate { |
57 | db.Migrate(ctx.DB) | 49 | db.Migrate(ctx.DB) |
58 | } | 50 | } |
59 | 51 | ||
52 | + // 服务启动 | ||
60 | logx.Infof("Starting server at %s:%d... \n", c.Host, c.Port) | 53 | logx.Infof("Starting server at %s:%d... \n", c.Host, c.Port) |
61 | server.Start() | 54 | server.Start() |
62 | } | 55 | } |
56 | + | ||
57 | +func systemSetup(c config.Config) { | ||
58 | + // 初始化Domain里面的配置 | ||
59 | + domain.ProjectName = c.Name | ||
60 | + | ||
61 | + // 默认的token头 Authorization 修改为 x-mmm-accesstoken | ||
62 | + request.AuthorizationHeaderExtractor = &request.PostExtractionFilter{ | ||
63 | + request.HeaderExtractor{"x-mmm-accesstoken"}, func(tok string) (string, error) { | ||
64 | + // Should be a bearer token | ||
65 | + if len(tok) > 6 && strings.ToUpper(tok[0:7]) == "BEARER " { | ||
66 | + return tok[7:], nil | ||
67 | + } | ||
68 | + return tok, nil | ||
69 | + }, | ||
70 | + } | ||
71 | + | ||
72 | + // 系统错误应答包装 | ||
73 | + httpx.SetErrorHandlerCtx(func(ctx context.Context, err error) (int, any) { | ||
74 | + return http.StatusOK, result.Error(xerr.ServerCommonError, err.Error()) | ||
75 | + }) | ||
76 | + // 系统成功应答包装 | ||
77 | + httpx.SetOkHandler(func(ctx context.Context, a any) any { | ||
78 | + return result.Success(a) | ||
79 | + }) | ||
80 | +} |
@@ -72,6 +72,12 @@ service Core { | @@ -72,6 +72,12 @@ service Core { | ||
72 | @doc "小程序所有的定性标签" | 72 | @doc "小程序所有的定性标签" |
73 | @handler MiniAllArticleTag | 73 | @handler MiniAllArticleTag |
74 | get /article_tag/list/all (MiniAllArticleTagRequest) returns (MiniAllArticleTagResponse) | 74 | get /article_tag/list/all (MiniAllArticleTagRequest) returns (MiniAllArticleTagResponse) |
75 | + | ||
76 | + @doc "小程序首页数据展示" | ||
77 | + @handler MiniShowHomePage | ||
78 | + get /show/home_page (MiniHomePageRequest) returns (MiniHomePageRespose) | ||
79 | + | ||
80 | + | ||
75 | } | 81 | } |
76 | 82 | ||
77 | // 管理后台接口 | 83 | // 管理后台接口 |
@@ -281,13 +281,13 @@ type ( | @@ -281,13 +281,13 @@ type ( | ||
281 | } | 281 | } |
282 | 282 | ||
283 | MiniArticleMarkItem { | 283 | MiniArticleMarkItem { |
284 | - Id int64 `json:"id"` | ||
285 | - CompanyId int64 `json:"companyId"` | ||
286 | - UserId int64 `json:"userId"` | ||
287 | - ArticleId int64 `json:"articleId"` | ||
288 | - Title string `json:"title"` | 284 | + Id int64 `json:"id"` |
285 | + CompanyId int64 `json:"companyId"` | ||
286 | + UserId int64 `json:"userId"` | ||
287 | + ArticleId int64 `json:"articleId"` | ||
288 | + Title string `json:"title"` | ||
289 | Author SimpleUser `json:"author"` // 发布人 | 289 | Author SimpleUser `json:"author"` // 发布人 |
290 | - UpdatedAt int64 `json:"updatedAt"` | 290 | + UpdatedAt int64 `json:"updatedAt"` |
291 | } | 291 | } |
292 | ) | 292 | ) |
293 | 293 | ||
@@ -460,4 +460,25 @@ type ( | @@ -460,4 +460,25 @@ type ( | ||
460 | Id int64 `json:"id"` //ID | 460 | Id int64 `json:"id"` //ID |
461 | ArticleId int64 `json:"articleId"` //文章ID | 461 | ArticleId int64 `json:"articleId"` //文章ID |
462 | } | 462 | } |
463 | +) | ||
464 | + | ||
465 | +//小程序端 首页数据展示 | ||
466 | +// 统计各标签下的文章数量,和已被人员阅读的数量 | ||
467 | +type ( | ||
468 | + MiniHomePageRequest { | ||
469 | + CompanyId int64 `path:",optional"` | ||
470 | + UserId int64 `path:",optional"` | ||
471 | + } | ||
472 | + MiniHomePageRespose { | ||
473 | + Tags []ArticleTagCount `json:"tags"` | ||
474 | + } | ||
475 | + ArticleTagCount { | ||
476 | + TagGroup string `json:"tagGroup"` // 标签分组 | ||
477 | + TagId int64 `json:"tagId"` // 标签id | ||
478 | + TagImage string `json:"tagImage"` // 对应的图标 | ||
479 | + TagName string `json:"tagName"` // 标签名称 | ||
480 | + TagRemark string `json:"tagRemark"` // 标签备注 | ||
481 | + TotalArticle int `json:"totalArticle"` // 总的文章数量 | ||
482 | + ReadArticle int `json:"readArticle"` // 已读的标签数量 | ||
483 | + } | ||
463 | ) | 484 | ) |
@@ -84,9 +84,6 @@ type( | @@ -84,9 +84,6 @@ type( | ||
84 | } | 84 | } |
85 | MiniUserInfoResponse { | 85 | MiniUserInfoResponse { |
86 | User *UserItem `json:"user,omitempty"` // 用户信息 | 86 | User *UserItem `json:"user,omitempty"` // 用户信息 |
87 | - TotalArticle int64 `json:"totalArticle"` // 累计信息发布 | ||
88 | - TotalLoved int64 `json:"totalLoved"` // 累计收到的赞 | ||
89 | - TotalAccepted int64 `json:"totalAccepted"` // 累计被采纳 | ||
90 | Accounts []Account `json:"accounts"` // 公司账号 | 87 | Accounts []Account `json:"accounts"` // 公司账号 |
91 | Auths []Auth `json:"auths"` // 权限列表 | 88 | Auths []Auth `json:"auths"` // 权限列表 |
92 | } | 89 | } |
@@ -15,7 +15,7 @@ func MiniAllArticleTagHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | @@ -15,7 +15,7 @@ func MiniAllArticleTagHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||
15 | return func(w http.ResponseWriter, r *http.Request) { | 15 | return func(w http.ResponseWriter, r *http.Request) { |
16 | var req types.MiniAllArticleTagRequest | 16 | var req types.MiniAllArticleTagRequest |
17 | if err := httpx.Parse(r, &req); err != nil { | 17 | if err := httpx.Parse(r, &req); err != nil { |
18 | - httpx.ErrorCtx(r.Context(), w, err) | 18 | + result.HttpResult(r, w, nil, err) |
19 | return | 19 | return |
20 | } | 20 | } |
21 | 21 |
@@ -15,7 +15,7 @@ func MiniArticleBackupSearchHandler(svcCtx *svc.ServiceContext) http.HandlerFunc | @@ -15,7 +15,7 @@ func MiniArticleBackupSearchHandler(svcCtx *svc.ServiceContext) http.HandlerFunc | ||
15 | return func(w http.ResponseWriter, r *http.Request) { | 15 | return func(w http.ResponseWriter, r *http.Request) { |
16 | var req types.MiniArticleBackupSearchRequest | 16 | var req types.MiniArticleBackupSearchRequest |
17 | if err := httpx.Parse(r, &req); err != nil { | 17 | if err := httpx.Parse(r, &req); err != nil { |
18 | - httpx.ErrorCtx(r.Context(), w, err) | 18 | + result.HttpResult(r, w, nil, err) |
19 | return | 19 | return |
20 | } | 20 | } |
21 | token := contextdata.GetUserTokenFromCtx(r.Context()) | 21 | token := contextdata.GetUserTokenFromCtx(r.Context()) |
1 | package article | 1 | package article |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | - "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result" | ||
5 | "net/http" | 4 | "net/http" |
6 | 5 | ||
6 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result" | ||
7 | + | ||
7 | "github.com/zeromicro/go-zero/rest/httpx" | 8 | "github.com/zeromicro/go-zero/rest/httpx" |
8 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/article" | 9 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/article" |
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/svc" |
@@ -14,7 +15,7 @@ func MiniArticleMarkListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | @@ -14,7 +15,7 @@ func MiniArticleMarkListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||
14 | return func(w http.ResponseWriter, r *http.Request) { | 15 | return func(w http.ResponseWriter, r *http.Request) { |
15 | var req types.MiniArticleMarkListRequest | 16 | var req types.MiniArticleMarkListRequest |
16 | if err := httpx.Parse(r, &req); err != nil { | 17 | if err := httpx.Parse(r, &req); err != nil { |
17 | - httpx.ErrorCtx(r.Context(), w, err) | 18 | + result.HttpResult(r, w, nil, err) |
18 | return | 19 | return |
19 | } | 20 | } |
20 | 21 |
@@ -16,7 +16,7 @@ func MiniArticleMarkUserReadHandler(svcCtx *svc.ServiceContext) http.HandlerFunc | @@ -16,7 +16,7 @@ func MiniArticleMarkUserReadHandler(svcCtx *svc.ServiceContext) http.HandlerFunc | ||
16 | return func(w http.ResponseWriter, r *http.Request) { | 16 | return func(w http.ResponseWriter, r *http.Request) { |
17 | var req types.MiniArticleMarkUserReadRequest | 17 | var req types.MiniArticleMarkUserReadRequest |
18 | if err := httpx.Parse(r, &req); err != nil { | 18 | if err := httpx.Parse(r, &req); err != nil { |
19 | - httpx.ErrorCtx(r.Context(), w, err) | 19 | + result.HttpResult(r, w, nil, err) |
20 | return | 20 | return |
21 | } | 21 | } |
22 | 22 |
@@ -15,7 +15,7 @@ func MiniArticleSearchMeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | @@ -15,7 +15,7 @@ func MiniArticleSearchMeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||
15 | return func(w http.ResponseWriter, r *http.Request) { | 15 | return func(w http.ResponseWriter, r *http.Request) { |
16 | var req types.MiniArticleSearchMeRequest | 16 | var req types.MiniArticleSearchMeRequest |
17 | if err := httpx.Parse(r, &req); err != nil { | 17 | if err := httpx.Parse(r, &req); err != nil { |
18 | - httpx.ErrorCtx(r.Context(), w, err) | 18 | + result.HttpResult(r, w, nil, err) |
19 | return | 19 | return |
20 | } | 20 | } |
21 | 21 |
@@ -15,7 +15,7 @@ func MiniArticleSetTagHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | @@ -15,7 +15,7 @@ func MiniArticleSetTagHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||
15 | return func(w http.ResponseWriter, r *http.Request) { | 15 | return func(w http.ResponseWriter, r *http.Request) { |
16 | var req types.MiniArticleSetTagRequest | 16 | var req types.MiniArticleSetTagRequest |
17 | if err := httpx.Parse(r, &req); err != nil { | 17 | if err := httpx.Parse(r, &req); err != nil { |
18 | - httpx.ErrorCtx(r.Context(), w, err) | 18 | + result.HttpResult(r, w, nil, err) |
19 | return | 19 | return |
20 | } | 20 | } |
21 | 21 |
@@ -15,7 +15,7 @@ func MiniCreateArticleDraftHandler(svcCtx *svc.ServiceContext) http.HandlerFunc | @@ -15,7 +15,7 @@ func MiniCreateArticleDraftHandler(svcCtx *svc.ServiceContext) http.HandlerFunc | ||
15 | return func(w http.ResponseWriter, r *http.Request) { | 15 | return func(w http.ResponseWriter, r *http.Request) { |
16 | var req types.MiniArticleDraftCreateRequest | 16 | var req types.MiniArticleDraftCreateRequest |
17 | if err := httpx.Parse(r, &req); err != nil { | 17 | if err := httpx.Parse(r, &req); err != nil { |
18 | - httpx.ErrorCtx(r.Context(), w, err) | 18 | + result.HttpResult(r, w, nil, err) |
19 | return | 19 | return |
20 | } | 20 | } |
21 | 21 |
@@ -15,7 +15,7 @@ func MiniCreateArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | @@ -15,7 +15,7 @@ func MiniCreateArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||
15 | return func(w http.ResponseWriter, r *http.Request) { | 15 | return func(w http.ResponseWriter, r *http.Request) { |
16 | var req types.MiniArticleCreateRequest | 16 | var req types.MiniArticleCreateRequest |
17 | if err := httpx.Parse(r, &req); err != nil { | 17 | if err := httpx.Parse(r, &req); err != nil { |
18 | - httpx.ErrorCtx(r.Context(), w, err) | 18 | + result.HttpResult(r, w, nil, err) |
19 | return | 19 | return |
20 | } | 20 | } |
21 | token := contextdata.GetUserTokenFromCtx(r.Context()) | 21 | token := contextdata.GetUserTokenFromCtx(r.Context()) |
@@ -15,7 +15,7 @@ func MiniDeleteArticleDraftMeHandler(svcCtx *svc.ServiceContext) http.HandlerFun | @@ -15,7 +15,7 @@ func MiniDeleteArticleDraftMeHandler(svcCtx *svc.ServiceContext) http.HandlerFun | ||
15 | return func(w http.ResponseWriter, r *http.Request) { | 15 | return func(w http.ResponseWriter, r *http.Request) { |
16 | var req types.MiniArticleDraftDeleteMeRequest | 16 | var req types.MiniArticleDraftDeleteMeRequest |
17 | if err := httpx.Parse(r, &req); err != nil { | 17 | if err := httpx.Parse(r, &req); err != nil { |
18 | - httpx.ErrorCtx(r.Context(), w, err) | 18 | + result.HttpResult(r, w, nil, err) |
19 | return | 19 | return |
20 | } | 20 | } |
21 | 21 |
@@ -7,22 +7,23 @@ import ( | @@ -7,22 +7,23 @@ import ( | ||
7 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/article" | 7 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/article" |
8 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" | 8 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" |
9 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" | 9 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" |
10 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata" | ||
11 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result" | ||
10 | ) | 12 | ) |
11 | 13 | ||
12 | func MiniGetArticleDraftMeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | 14 | func MiniGetArticleDraftMeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { |
13 | return func(w http.ResponseWriter, r *http.Request) { | 15 | return func(w http.ResponseWriter, r *http.Request) { |
14 | var req types.MiniArticleDraftGetMeRequest | 16 | var req types.MiniArticleDraftGetMeRequest |
15 | if err := httpx.Parse(r, &req); err != nil { | 17 | if err := httpx.Parse(r, &req); err != nil { |
16 | - httpx.ErrorCtx(r.Context(), w, err) | 18 | + result.HttpResult(r, w, nil, err) |
17 | return | 19 | return |
18 | } | 20 | } |
19 | 21 | ||
20 | l := article.NewMiniGetArticleDraftMeLogic(r.Context(), svcCtx) | 22 | l := article.NewMiniGetArticleDraftMeLogic(r.Context(), svcCtx) |
23 | + token := contextdata.GetUserTokenFromCtx(r.Context()) | ||
24 | + req.AuthorId = token.UserId | ||
25 | + req.CompanyId = token.CompanyId | ||
21 | resp, err := l.MiniGetArticleDraftMe(&req) | 26 | resp, err := l.MiniGetArticleDraftMe(&req) |
22 | - if err != nil { | ||
23 | - httpx.ErrorCtx(r.Context(), w, err) | ||
24 | - } else { | ||
25 | - httpx.OkJsonCtx(r.Context(), w, resp) | ||
26 | - } | 27 | + result.HttpResult(r, w, resp, err) |
27 | } | 28 | } |
28 | } | 29 | } |
@@ -15,7 +15,7 @@ func MiniGetArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | @@ -15,7 +15,7 @@ func MiniGetArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||
15 | return func(w http.ResponseWriter, r *http.Request) { | 15 | return func(w http.ResponseWriter, r *http.Request) { |
16 | var req types.MiniArticleGetRequest | 16 | var req types.MiniArticleGetRequest |
17 | if err := httpx.Parse(r, &req); err != nil { | 17 | if err := httpx.Parse(r, &req); err != nil { |
18 | - httpx.ErrorCtx(r.Context(), w, err) | 18 | + result.HttpResult(r, w, nil, err) |
19 | return | 19 | return |
20 | } | 20 | } |
21 | 21 |
@@ -15,7 +15,7 @@ func MiniSearchArticleDraftMeHandler(svcCtx *svc.ServiceContext) http.HandlerFun | @@ -15,7 +15,7 @@ func MiniSearchArticleDraftMeHandler(svcCtx *svc.ServiceContext) http.HandlerFun | ||
15 | return func(w http.ResponseWriter, r *http.Request) { | 15 | return func(w http.ResponseWriter, r *http.Request) { |
16 | var req types.MiniArticleDraftSearchMeRequest | 16 | var req types.MiniArticleDraftSearchMeRequest |
17 | if err := httpx.Parse(r, &req); err != nil { | 17 | if err := httpx.Parse(r, &req); err != nil { |
18 | - httpx.ErrorCtx(r.Context(), w, err) | 18 | + result.HttpResult(r, w, nil, err) |
19 | return | 19 | return |
20 | } | 20 | } |
21 | 21 |
@@ -15,7 +15,7 @@ func MiniSetUserLikeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | @@ -15,7 +15,7 @@ func MiniSetUserLikeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||
15 | return func(w http.ResponseWriter, r *http.Request) { | 15 | return func(w http.ResponseWriter, r *http.Request) { |
16 | var req types.MiniSetUserLikeRequset | 16 | var req types.MiniSetUserLikeRequset |
17 | if err := httpx.Parse(r, &req); err != nil { | 17 | if err := httpx.Parse(r, &req); err != nil { |
18 | - httpx.ErrorCtx(r.Context(), w, err) | 18 | + result.HttpResult(r, w, nil, err) |
19 | return | 19 | return |
20 | } | 20 | } |
21 | 21 |
1 | +package article | ||
2 | + | ||
3 | +import ( | ||
4 | + "net/http" | ||
5 | + | ||
6 | + "github.com/zeromicro/go-zero/rest/httpx" | ||
7 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/article" | ||
8 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" | ||
9 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" | ||
10 | +) | ||
11 | + | ||
12 | +func MiniShowHomePageHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||
13 | + return func(w http.ResponseWriter, r *http.Request) { | ||
14 | + var req types.MiniHomePageRequest | ||
15 | + if err := httpx.Parse(r, &req); err != nil { | ||
16 | + httpx.ErrorCtx(r.Context(), w, err) | ||
17 | + return | ||
18 | + } | ||
19 | + | ||
20 | + l := article.NewMiniShowHomePageLogic(r.Context(), svcCtx) | ||
21 | + resp, err := l.MiniShowHomePage(&req) | ||
22 | + if err != nil { | ||
23 | + httpx.ErrorCtx(r.Context(), w, err) | ||
24 | + } else { | ||
25 | + httpx.OkJsonCtx(r.Context(), w, resp) | ||
26 | + } | ||
27 | + } | ||
28 | +} |
@@ -15,7 +15,7 @@ func MiniUpdateArticleDraftHandler(svcCtx *svc.ServiceContext) http.HandlerFunc | @@ -15,7 +15,7 @@ func MiniUpdateArticleDraftHandler(svcCtx *svc.ServiceContext) http.HandlerFunc | ||
15 | return func(w http.ResponseWriter, r *http.Request) { | 15 | return func(w http.ResponseWriter, r *http.Request) { |
16 | var req types.MiniArticleDraftUpdateRequest | 16 | var req types.MiniArticleDraftUpdateRequest |
17 | if err := httpx.Parse(r, &req); err != nil { | 17 | if err := httpx.Parse(r, &req); err != nil { |
18 | - httpx.ErrorCtx(r.Context(), w, err) | 18 | + result.HttpResult(r, w, nil, err) |
19 | return | 19 | return |
20 | } | 20 | } |
21 | l := article.NewMiniUpdateArticleDraftLogic(r.Context(), svcCtx) | 21 | l := article.NewMiniUpdateArticleDraftLogic(r.Context(), svcCtx) |
@@ -15,7 +15,7 @@ func MiniUserLikeArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | @@ -15,7 +15,7 @@ func MiniUserLikeArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||
15 | return func(w http.ResponseWriter, r *http.Request) { | 15 | return func(w http.ResponseWriter, r *http.Request) { |
16 | var req types.MiniUserLikeArticleRequest | 16 | var req types.MiniUserLikeArticleRequest |
17 | if err := httpx.Parse(r, &req); err != nil { | 17 | if err := httpx.Parse(r, &req); err != nil { |
18 | - httpx.ErrorCtx(r.Context(), w, err) | 18 | + result.HttpResult(r, w, nil, err) |
19 | return | 19 | return |
20 | } | 20 | } |
21 | 21 |
@@ -15,7 +15,7 @@ func MiniArticleCommentAtWhoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc | @@ -15,7 +15,7 @@ func MiniArticleCommentAtWhoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc | ||
15 | return func(w http.ResponseWriter, r *http.Request) { | 15 | return func(w http.ResponseWriter, r *http.Request) { |
16 | var req types.MiniArticleCommentAtWhoRequest | 16 | var req types.MiniArticleCommentAtWhoRequest |
17 | if err := httpx.Parse(r, &req); err != nil { | 17 | if err := httpx.Parse(r, &req); err != nil { |
18 | - httpx.ErrorCtx(r.Context(), w, err) | 18 | + result.HttpResult(r, w, nil, err) |
19 | return | 19 | return |
20 | } | 20 | } |
21 | 21 |
@@ -15,7 +15,7 @@ func MiniCreateArticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFun | @@ -15,7 +15,7 @@ func MiniCreateArticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFun | ||
15 | return func(w http.ResponseWriter, r *http.Request) { | 15 | return func(w http.ResponseWriter, r *http.Request) { |
16 | var req types.MiniCreateArticleCommentRequest | 16 | var req types.MiniCreateArticleCommentRequest |
17 | if err := httpx.Parse(r, &req); err != nil { | 17 | if err := httpx.Parse(r, &req); err != nil { |
18 | - httpx.ErrorCtx(r.Context(), w, err) | 18 | + result.HttpResult(r, w, nil, err) |
19 | return | 19 | return |
20 | } | 20 | } |
21 | l := comment.NewMiniCreateArticleCommentLogic(r.Context(), svcCtx) | 21 | l := comment.NewMiniCreateArticleCommentLogic(r.Context(), svcCtx) |
@@ -15,7 +15,7 @@ func MiniDeleteArticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFun | @@ -15,7 +15,7 @@ func MiniDeleteArticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFun | ||
15 | return func(w http.ResponseWriter, r *http.Request) { | 15 | return func(w http.ResponseWriter, r *http.Request) { |
16 | var req types.MiniDeleteArticleCommentRequest | 16 | var req types.MiniDeleteArticleCommentRequest |
17 | if err := httpx.Parse(r, &req); err != nil { | 17 | if err := httpx.Parse(r, &req); err != nil { |
18 | - httpx.ErrorCtx(r.Context(), w, err) | 18 | + result.HttpResult(r, w, nil, err) |
19 | return | 19 | return |
20 | } | 20 | } |
21 | 21 |
@@ -15,7 +15,7 @@ func MiniGetArticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | @@ -15,7 +15,7 @@ func MiniGetArticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||
15 | return func(w http.ResponseWriter, r *http.Request) { | 15 | return func(w http.ResponseWriter, r *http.Request) { |
16 | var req types.MiniGetArticleCommentRequest | 16 | var req types.MiniGetArticleCommentRequest |
17 | if err := httpx.Parse(r, &req); err != nil { | 17 | if err := httpx.Parse(r, &req); err != nil { |
18 | - httpx.ErrorCtx(r.Context(), w, err) | 18 | + result.HttpResult(r, w, nil, err) |
19 | return | 19 | return |
20 | } | 20 | } |
21 | 21 |
@@ -15,7 +15,7 @@ func MiniListArticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc | @@ -15,7 +15,7 @@ func MiniListArticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc | ||
15 | return func(w http.ResponseWriter, r *http.Request) { | 15 | return func(w http.ResponseWriter, r *http.Request) { |
16 | var req types.MiniListArticleCommentRequest | 16 | var req types.MiniListArticleCommentRequest |
17 | if err := httpx.Parse(r, &req); err != nil { | 17 | if err := httpx.Parse(r, &req); err != nil { |
18 | - httpx.ErrorCtx(r.Context(), w, err) | 18 | + result.HttpResult(r, w, nil, err) |
19 | return | 19 | return |
20 | } | 20 | } |
21 | l := comment.NewMiniListArticleCommentLogic(r.Context(), svcCtx) | 21 | l := comment.NewMiniListArticleCommentLogic(r.Context(), svcCtx) |
@@ -15,7 +15,7 @@ func MiniTop5ArticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc | @@ -15,7 +15,7 @@ func MiniTop5ArticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc | ||
15 | return func(w http.ResponseWriter, r *http.Request) { | 15 | return func(w http.ResponseWriter, r *http.Request) { |
16 | var req types.MiniTop5ArticleCommentRequest | 16 | var req types.MiniTop5ArticleCommentRequest |
17 | if err := httpx.Parse(r, &req); err != nil { | 17 | if err := httpx.Parse(r, &req); err != nil { |
18 | - httpx.ErrorCtx(r.Context(), w, err) | 18 | + result.HttpResult(r, w, nil, err) |
19 | return | 19 | return |
20 | } | 20 | } |
21 | 21 |
@@ -364,6 +364,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { | @@ -364,6 +364,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { | ||
364 | Path: "/article_tag/list/all", | 364 | Path: "/article_tag/list/all", |
365 | Handler: article.MiniAllArticleTagHandler(serverCtx), | 365 | Handler: article.MiniAllArticleTagHandler(serverCtx), |
366 | }, | 366 | }, |
367 | + { | ||
368 | + Method: http.MethodGet, | ||
369 | + Path: "/show/home_page", | ||
370 | + Handler: article.MiniShowHomePageHandler(serverCtx), | ||
371 | + }, | ||
367 | }, | 372 | }, |
368 | rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret), | 373 | rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret), |
369 | rest.WithPrefix("/v1/mini"), | 374 | rest.WithPrefix("/v1/mini"), |
@@ -15,7 +15,7 @@ func CreateTagHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | @@ -15,7 +15,7 @@ func CreateTagHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||
15 | return func(w http.ResponseWriter, r *http.Request) { | 15 | return func(w http.ResponseWriter, r *http.Request) { |
16 | var req types.TagCreateRequest | 16 | var req types.TagCreateRequest |
17 | if err := httpx.Parse(r, &req); err != nil { | 17 | if err := httpx.Parse(r, &req); err != nil { |
18 | - httpx.ErrorCtx(r.Context(), w, err) | 18 | + result.HttpResult(r, w, nil, err) |
19 | return | 19 | return |
20 | } | 20 | } |
21 | 21 |
@@ -15,7 +15,7 @@ func DeleteTagHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | @@ -15,7 +15,7 @@ func DeleteTagHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||
15 | return func(w http.ResponseWriter, r *http.Request) { | 15 | return func(w http.ResponseWriter, r *http.Request) { |
16 | var req types.TagDeleteRequest | 16 | var req types.TagDeleteRequest |
17 | if err := httpx.Parse(r, &req); err != nil { | 17 | if err := httpx.Parse(r, &req); err != nil { |
18 | - httpx.ErrorCtx(r.Context(), w, err) | 18 | + result.HttpResult(r, w, nil, err) |
19 | return | 19 | return |
20 | } | 20 | } |
21 | 21 |
@@ -15,7 +15,7 @@ func EditTagHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | @@ -15,7 +15,7 @@ func EditTagHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||
15 | return func(w http.ResponseWriter, r *http.Request) { | 15 | return func(w http.ResponseWriter, r *http.Request) { |
16 | var req types.TagEditRequest | 16 | var req types.TagEditRequest |
17 | if err := httpx.Parse(r, &req); err != nil { | 17 | if err := httpx.Parse(r, &req); err != nil { |
18 | - httpx.ErrorCtx(r.Context(), w, err) | 18 | + result.HttpResult(r, w, nil, err) |
19 | return | 19 | return |
20 | } | 20 | } |
21 | 21 |
@@ -15,7 +15,7 @@ func GetTagHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | @@ -15,7 +15,7 @@ func GetTagHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||
15 | return func(w http.ResponseWriter, r *http.Request) { | 15 | return func(w http.ResponseWriter, r *http.Request) { |
16 | var req types.TagGetRequest | 16 | var req types.TagGetRequest |
17 | if err := httpx.Parse(r, &req); err != nil { | 17 | if err := httpx.Parse(r, &req); err != nil { |
18 | - httpx.ErrorCtx(r.Context(), w, err) | 18 | + result.HttpResult(r, w, nil, err) |
19 | return | 19 | return |
20 | } | 20 | } |
21 | token := contextdata.GetUserTokenFromCtx(r.Context()) | 21 | token := contextdata.GetUserTokenFromCtx(r.Context()) |
@@ -15,7 +15,7 @@ func SearchTagHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | @@ -15,7 +15,7 @@ func SearchTagHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||
15 | return func(w http.ResponseWriter, r *http.Request) { | 15 | return func(w http.ResponseWriter, r *http.Request) { |
16 | var req types.TagListRequest | 16 | var req types.TagListRequest |
17 | if err := httpx.Parse(r, &req); err != nil { | 17 | if err := httpx.Parse(r, &req); err != nil { |
18 | - httpx.ErrorCtx(r.Context(), w, err) | 18 | + result.HttpResult(r, w, nil, err) |
19 | return | 19 | return |
20 | } | 20 | } |
21 | 21 |
@@ -2,6 +2,7 @@ package article | @@ -2,6 +2,7 @@ package article | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "context" | 4 | "context" |
5 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/message" | ||
5 | 6 | ||
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/svc" |
7 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" | 8 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" |
@@ -80,6 +81,14 @@ func (l *MiniArticleSetTagLogic) MiniArticleSetTag(req *types.MiniArticleSetTagR | @@ -80,6 +81,14 @@ func (l *MiniArticleSetTagLogic) MiniArticleSetTag(req *types.MiniArticleSetTagR | ||
80 | if err != nil { | 81 | if err != nil { |
81 | return err | 82 | return err |
82 | } | 83 | } |
84 | + | ||
85 | + // 定性消息通知 | ||
86 | + messageLogic := message.NewMiniSystemLogic(ctx, l.svcCtx) | ||
87 | + err = messageLogic.ArticleDefined(c, articleInfo.CompanyId, articleInfo.AuthorId, articleInfo.Title) | ||
88 | + if err != nil { | ||
89 | + return err | ||
90 | + } | ||
91 | + | ||
83 | return nil | 92 | return nil |
84 | }, true) | 93 | }, true) |
85 | 94 |
1 | +package article | ||
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 MiniShowHomePageLogic struct { | ||
13 | + logx.Logger | ||
14 | + ctx context.Context | ||
15 | + svcCtx *svc.ServiceContext | ||
16 | +} | ||
17 | + | ||
18 | +func NewMiniShowHomePageLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniShowHomePageLogic { | ||
19 | + return &MiniShowHomePageLogic{ | ||
20 | + Logger: logx.WithContext(ctx), | ||
21 | + ctx: ctx, | ||
22 | + svcCtx: svcCtx, | ||
23 | + } | ||
24 | +} | ||
25 | + | ||
26 | +func (l *MiniShowHomePageLogic) MiniShowHomePage(req *types.MiniHomePageRequest) (resp *types.MiniHomePageRespose, err error) { | ||
27 | + // todo: add your logic here and delete this line | ||
28 | + | ||
29 | + return | ||
30 | +} |
@@ -6,6 +6,7 @@ import ( | @@ -6,6 +6,7 @@ import ( | ||
6 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" | 6 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" |
7 | "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/db/transaction" |
8 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" | 8 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" |
9 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr" | ||
9 | 10 | ||
10 | "github.com/zeromicro/go-zero/core/logx" | 11 | "github.com/zeromicro/go-zero/core/logx" |
11 | ) | 12 | ) |
@@ -29,13 +30,13 @@ func (l *SystemDeleteLogic) SystemDelete(req *types.DepartmentGetRequest) (resp | @@ -29,13 +30,13 @@ func (l *SystemDeleteLogic) SystemDelete(req *types.DepartmentGetRequest) (resp | ||
29 | 30 | ||
30 | one, err := l.svcCtx.DepartmentRepository.FindOne(l.ctx, conn, req.Id) | 31 | one, err := l.svcCtx.DepartmentRepository.FindOne(l.ctx, conn, req.Id) |
31 | if err != nil { | 32 | if err != nil { |
32 | - return nil, err | 33 | + return nil, xerr.NewErrMsg("数据不存在") |
33 | } | 34 | } |
34 | 35 | ||
35 | // 获取公司下的所有用户 | 36 | // 获取公司下的所有用户 |
36 | _, users, err := l.svcCtx.UserRepository.Find(l.ctx, conn, domain.NewQueryOptions(). | 37 | _, users, err := l.svcCtx.UserRepository.Find(l.ctx, conn, domain.NewQueryOptions(). |
37 | WithFindOnly(). | 38 | WithFindOnly(). |
38 | - WithKV(" companyId", one.CompanyId)) | 39 | + WithKV("companyId", one.CompanyId)) |
39 | if err != nil { | 40 | if err != nil { |
40 | return nil, err | 41 | return nil, err |
41 | } | 42 | } |
@@ -4,6 +4,7 @@ import ( | @@ -4,6 +4,7 @@ import ( | ||
4 | "context" | 4 | "context" |
5 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" | 5 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" |
6 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" | 6 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" |
7 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr" | ||
7 | 8 | ||
8 | "github.com/zeromicro/go-zero/core/logx" | 9 | "github.com/zeromicro/go-zero/core/logx" |
9 | ) | 10 | ) |
@@ -26,7 +27,7 @@ func (l *SystemGetLogic) SystemGet(req *types.DepartmentGetRequest) (resp *types | @@ -26,7 +27,7 @@ func (l *SystemGetLogic) SystemGet(req *types.DepartmentGetRequest) (resp *types | ||
26 | var conn = l.svcCtx.DefaultDBConn() | 27 | var conn = l.svcCtx.DefaultDBConn() |
27 | department, err := l.svcCtx.DepartmentRepository.FindOne(l.ctx, conn, req.Id) | 28 | department, err := l.svcCtx.DepartmentRepository.FindOne(l.ctx, conn, req.Id) |
28 | if err != nil { | 29 | if err != nil { |
29 | - return nil, err | 30 | + return nil, xerr.NewErrMsg("数据不存在") |
30 | } | 31 | } |
31 | resp = &types.DepartmentGetResponse{ | 32 | resp = &types.DepartmentGetResponse{ |
32 | Department: types.Department{ | 33 | Department: types.Department{ |
@@ -58,7 +58,7 @@ func (l *SystemUpdateLogic) SystemUpdate(req *types.DepartmentUpdateRequest) (re | @@ -58,7 +58,7 @@ func (l *SystemUpdateLogic) SystemUpdate(req *types.DepartmentUpdateRequest) (re | ||
58 | // 获取公司下的所有用户 | 58 | // 获取公司下的所有用户 |
59 | _, users, err := l.svcCtx.UserRepository.Find(l.ctx, conn, domain.NewQueryOptions(). | 59 | _, users, err := l.svcCtx.UserRepository.Find(l.ctx, conn, domain.NewQueryOptions(). |
60 | WithFindOnly(). | 60 | WithFindOnly(). |
61 | - WithKV(" companyId", one.CompanyId)) | 61 | + WithKV("companyId", one.CompanyId)) |
62 | if err != nil { | 62 | if err != nil { |
63 | return nil, err | 63 | return nil, err |
64 | } | 64 | } |
@@ -83,7 +83,7 @@ func (l *SystemUpdateLogic) SystemUpdate(req *types.DepartmentUpdateRequest) (re | @@ -83,7 +83,7 @@ func (l *SystemUpdateLogic) SystemUpdate(req *types.DepartmentUpdateRequest) (re | ||
83 | if _, ok := newIdMap[user.Id]; ok { | 83 | if _, ok := newIdMap[user.Id]; ok { |
84 | var targetIndex = findIndex(user.Departments, req.Id) | 84 | var targetIndex = findIndex(user.Departments, req.Id) |
85 | if targetIndex == -1 { // 归属分组不存在,则新增 | 85 | if targetIndex == -1 { // 归属分组不存在,则新增 |
86 | - user.Departments = append(user.Departments) | 86 | + user.Departments = append(user.Departments, req.Id) |
87 | _, err = l.svcCtx.UserRepository.UpdateWithVersion(l.ctx, conn, user) | 87 | _, err = l.svcCtx.UserRepository.UpdateWithVersion(l.ctx, conn, user) |
88 | if err != nil { | 88 | if err != nil { |
89 | return err | 89 | return err |
@@ -299,12 +299,9 @@ type MiniUserInfoRequest struct { | @@ -299,12 +299,9 @@ type MiniUserInfoRequest struct { | ||
299 | } | 299 | } |
300 | 300 | ||
301 | type MiniUserInfoResponse struct { | 301 | type MiniUserInfoResponse struct { |
302 | - User *UserItem `json:"user,omitempty"` // 用户信息 | ||
303 | - TotalArticle int64 `json:"totalArticle"` // 累计信息发布 | ||
304 | - TotalLoved int64 `json:"totalLoved"` // 累计收到的赞 | ||
305 | - TotalAccepted int64 `json:"totalAccepted"` // 累计被采纳 | ||
306 | - Accounts []Account `json:"accounts"` // 公司账号 | ||
307 | - Auths []Auth `json:"auths"` // 权限列表 | 302 | + User *UserItem `json:"user,omitempty"` // 用户信息 |
303 | + Accounts []Account `json:"accounts"` // 公司账号 | ||
304 | + Auths []Auth `json:"auths"` // 权限列表 | ||
308 | } | 305 | } |
309 | 306 | ||
310 | type MiniUserApplyJoinCompanyRequest struct { | 307 | type MiniUserApplyJoinCompanyRequest struct { |
@@ -1002,6 +999,25 @@ type SystemArticleRestoreResponse struct { | @@ -1002,6 +999,25 @@ type SystemArticleRestoreResponse struct { | ||
1002 | ArticleId int64 `json:"articleId"` //文章ID | 999 | ArticleId int64 `json:"articleId"` //文章ID |
1003 | } | 1000 | } |
1004 | 1001 | ||
1002 | +type MiniHomePageRequest struct { | ||
1003 | + CompanyId int64 `path:",optional"` | ||
1004 | + UserId int64 `path:",optional"` | ||
1005 | +} | ||
1006 | + | ||
1007 | +type MiniHomePageRespose struct { | ||
1008 | + Tags []ArticleTagCount `json:"tags"` | ||
1009 | +} | ||
1010 | + | ||
1011 | +type ArticleTagCount struct { | ||
1012 | + TagGroup string `json:"tagGroup"` // 标签分组 | ||
1013 | + TagId int64 `json:"tagId"` // 标签id | ||
1014 | + TagImage string `json:"tagImage"` // 对应的图标 | ||
1015 | + TagName string `json:"tagName"` // 标签名称 | ||
1016 | + TagRemark string `json:"tagRemark"` // 标签备注 | ||
1017 | + TotalArticle int `json:"totalArticle"` // 总的文章数量 | ||
1018 | + ReadArticle int `json:"readArticle"` // 已读的标签数量 | ||
1019 | +} | ||
1020 | + | ||
1005 | type RoleGetRequest struct { | 1021 | type RoleGetRequest struct { |
1006 | Id int64 `path:"id"` | 1022 | Id int64 `path:"id"` |
1007 | } | 1023 | } |
@@ -53,3 +53,10 @@ func (m *ArticleAndTag) CachePrimaryKeyFunc() string { | @@ -53,3 +53,10 @@ func (m *ArticleAndTag) CachePrimaryKeyFunc() string { | ||
53 | } | 53 | } |
54 | return fmt.Sprintf("%v:cache:%v:primarykey:%v", domain.ProjectName, m.TableName(), "key") | 54 | return fmt.Sprintf("%v:cache:%v:primarykey:%v", domain.ProjectName, m.TableName(), "key") |
55 | } | 55 | } |
56 | + | ||
57 | +// 统计所有已有标签的文章和人员已读的文章 | ||
58 | +type CountArticleTagRead struct { | ||
59 | + TotalArticle int `gorm:"total_article"` //标签下文章的数量 | ||
60 | + ReadArticle int `gorm:"read_article"` //人员已读的文章 | ||
61 | + TagId int64 `gorm:"tag_id"` // 标签的id | ||
62 | +} |
@@ -2,6 +2,7 @@ package repository | @@ -2,6 +2,7 @@ package repository | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "context" | 4 | "context" |
5 | + "fmt" | ||
5 | 6 | ||
6 | "github.com/jinzhu/copier" | 7 | "github.com/jinzhu/copier" |
7 | "github.com/pkg/errors" | 8 | "github.com/pkg/errors" |
@@ -132,6 +133,59 @@ func (repository *ArticleAndTagRepository) DomainModelToModel(from *domain.Artic | @@ -132,6 +133,59 @@ func (repository *ArticleAndTagRepository) DomainModelToModel(from *domain.Artic | ||
132 | return to, err | 133 | return to, err |
133 | } | 134 | } |
134 | 135 | ||
136 | +// 以TagId作为分组,统计所有已有标签的文章和人员已读的文章 | ||
137 | +func (repository *ArticleAndTagRepository) CountArticleReadGroupByTag(ctx context.Context, conn transaction.Conn, userId int64, companyId int64) ([]*domain.CountArticleTagRead, error) { | ||
138 | + | ||
139 | + sqlStr := ` | ||
140 | +-- 首页统计数据 | ||
141 | +with | ||
142 | +-- 按查看权限查询文章 | ||
143 | +-- 获取有标签的文章 | ||
144 | +-- 过滤出可展示的文章id | ||
145 | +t_article_and_tag_2 as ( | ||
146 | + select article_and_tag.article_id , article_and_tag.tag_id | ||
147 | + from article_and_tag | ||
148 | + join article on article_and_tag.article_id = article.id | ||
149 | + where article.deleted_at=0 | ||
150 | + and article.company_id =1598224576532189184 | ||
151 | + and article."show" =0 | ||
152 | + and (article.target_user =0 or article.who_read @>'[1]') | ||
153 | +), | ||
154 | +-- 查询人员已查看的文章 | ||
155 | +t_user_read as( | ||
156 | + select user_read_article.article_id from user_read_article where user_read_article.user_id =1 | ||
157 | +) | ||
158 | +-- 汇总统计 total_article 符合条件的文章总数,read_article 已浏览的数量 | ||
159 | +select count(t_article_and_tag_2.article_id) as total_article ,count(t_user_read.article_id) as read_article, t_article_and_tag_2.tag_id | ||
160 | +from t_article_and_tag_2 | ||
161 | +left join t_user_read on t_article_and_tag_2.article_id=t_user_read.article_id | ||
162 | +group by t_article_and_tag_2.tag_id | ||
163 | +` | ||
164 | + condition := []interface{}{ | ||
165 | + companyId, | ||
166 | + fmt.Sprintf("[%d]", userId), | ||
167 | + userId, | ||
168 | + } | ||
169 | + | ||
170 | + m := []*models.CountArticleTagRead{} | ||
171 | + db := conn.DB() | ||
172 | + result := db.Raw(sqlStr, condition...).Scan(&m) | ||
173 | + if result.Error != nil { | ||
174 | + return nil, result.Error | ||
175 | + } | ||
176 | + | ||
177 | + var dm []*domain.CountArticleTagRead | ||
178 | + | ||
179 | + for _, val := range m { | ||
180 | + dm = append(dm, &domain.CountArticleTagRead{ | ||
181 | + TagId: val.TagId, | ||
182 | + TotalArticle: val.TotalArticle, | ||
183 | + ReadArticle: val.ReadArticle, | ||
184 | + }) | ||
185 | + } | ||
186 | + return dm, nil | ||
187 | +} | ||
188 | + | ||
135 | func NewArticleAndTagRepository(cache *cache.CachedRepository) domain.ArticleAndTagRepository { | 189 | func NewArticleAndTagRepository(cache *cache.CachedRepository) domain.ArticleAndTagRepository { |
136 | return &ArticleAndTagRepository{CachedRepository: cache} | 190 | return &ArticleAndTagRepository{CachedRepository: cache} |
137 | } | 191 | } |
@@ -278,34 +278,27 @@ func NewArticleRepository(cache *cache.CachedRepository) domain.ArticleRepositor | @@ -278,34 +278,27 @@ func NewArticleRepository(cache *cache.CachedRepository) domain.ArticleRepositor | ||
278 | return &ArticleRepository{CachedRepository: cache} | 278 | return &ArticleRepository{CachedRepository: cache} |
279 | } | 279 | } |
280 | 280 | ||
281 | +// -- 首页统计数据 | ||
281 | // with | 282 | // with |
282 | // -- 按查看权限查询文章 | 283 | // -- 按查看权限查询文章 |
283 | -// t_article as( | ||
284 | -// select article.id | ||
285 | -// from article | 284 | +// -- 获取有标签的文章 |
285 | +// -- 过滤出可展示的文章id | ||
286 | +// t_article_and_tag_2 as ( | ||
287 | +// select article_and_tag.article_id , article_and_tag.tag_id | ||
288 | +// from article_and_tag | ||
289 | +// join article on article_and_tag.article_id = article.id | ||
286 | // where article.deleted_at=0 | 290 | // where article.deleted_at=0 |
287 | // and article.company_id =1598224576532189184 | 291 | // and article.company_id =1598224576532189184 |
288 | // and article."show" =0 | 292 | // and article."show" =0 |
289 | // and (article.target_user =0 or article.who_read @>'[1]') | 293 | // and (article.target_user =0 or article.who_read @>'[1]') |
290 | // ), | 294 | // ), |
291 | -// -- 获取有标签的文章 | ||
292 | -// t_article_and_tag as ( | ||
293 | -// select article_and_tag.article_id ,article_and_tag.tag_id | ||
294 | -// from article_and_tag | ||
295 | -// where article_and_tag.company_id =1598224576532189184 | ||
296 | -// ), | ||
297 | -// -- 过滤出可展示的文章id | ||
298 | -// t_article_and_tag_2 as ( | ||
299 | -// select t_article_and_tag.article_id, t_article_and_tag.tag_id | ||
300 | -// from t_article_and_tag | ||
301 | -// join t_article on t_article_and_tag.article_id = t_article.id | ||
302 | -// ), | ||
303 | // -- 查询人员已查看的文章 | 295 | // -- 查询人员已查看的文章 |
304 | // t_user_read as( | 296 | // t_user_read as( |
305 | -// select user_read_article.article_id from user_read_article where user_read_article.user_id =1 | 297 | +// select user_read_article.article_id from user_read_article where user_read_article.user_id =1 |
306 | // ) | 298 | // ) |
307 | // -- 汇总统计 cnt_1符合条件的文章总数,cnt_2 已浏览的数量 | 299 | // -- 汇总统计 cnt_1符合条件的文章总数,cnt_2 已浏览的数量 |
308 | // select count(t_article_and_tag_2.article_id) as cnt_1 ,count(t_user_read.article_id) as cnt_2, t_article_and_tag_2.tag_id | 300 | // select count(t_article_and_tag_2.article_id) as cnt_1 ,count(t_user_read.article_id) as cnt_2, t_article_and_tag_2.tag_id |
309 | // from t_article_and_tag_2 | 301 | // from t_article_and_tag_2 |
310 | // left join t_user_read on t_article_and_tag_2.article_id=t_user_read.article_id | 302 | // left join t_user_read on t_article_and_tag_2.article_id=t_user_read.article_id |
311 | // group by t_article_and_tag_2.tag_id | 303 | // group by t_article_and_tag_2.tag_id |
304 | +// ; |
@@ -16,10 +16,18 @@ type ArticleAndTag struct { | @@ -16,10 +16,18 @@ type ArticleAndTag struct { | ||
16 | TagId int64 `json:"tagId"` | 16 | TagId int64 `json:"tagId"` |
17 | } | 17 | } |
18 | 18 | ||
19 | +// 以TagId作为分组,统计所有已有标签的文章和人员已读的文章 | ||
20 | +type CountArticleTagRead struct { | ||
21 | + TotalArticle int `gorm:"total_article"` //标签下文章的数量 | ||
22 | + ReadArticle int `gorm:"read_article"` //人员已读的文章 | ||
23 | + TagId int64 `gorm:"tag_id"` // 标签的id | ||
24 | +} | ||
25 | + | ||
19 | type ArticleAndTagRepository interface { | 26 | type ArticleAndTagRepository interface { |
20 | Insert(ctx context.Context, conn transaction.Conn, dm *ArticleAndTag) (*ArticleAndTag, error) | 27 | Insert(ctx context.Context, conn transaction.Conn, dm *ArticleAndTag) (*ArticleAndTag, error) |
21 | Update(ctx context.Context, conn transaction.Conn, dm *ArticleAndTag) (*ArticleAndTag, error) | 28 | Update(ctx context.Context, conn transaction.Conn, dm *ArticleAndTag) (*ArticleAndTag, error) |
22 | Delete(ctx context.Context, conn transaction.Conn, dm *ArticleAndTag) (*ArticleAndTag, error) | 29 | Delete(ctx context.Context, conn transaction.Conn, dm *ArticleAndTag) (*ArticleAndTag, error) |
23 | FindOne(ctx context.Context, conn transaction.Conn, id int64) (*ArticleAndTag, error) | 30 | FindOne(ctx context.Context, conn transaction.Conn, id int64) (*ArticleAndTag, error) |
24 | Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*ArticleAndTag, error) | 31 | Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*ArticleAndTag, error) |
32 | + CountArticleReadGroupByTag(ctx context.Context, con transaction.Conn, userId int64, companyId int64) ([]*CountArticleTagRead, error) | ||
25 | } | 33 | } |
-
请 注册 或 登录 后发表评论