Merge branch 'dev' of http://gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss into dev-zhuang
正在显示
16 个修改的文件
包含
120 行增加
和
24 行删除
@@ -14,7 +14,7 @@ func SystemAddHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | @@ -14,7 +14,7 @@ func SystemAddHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||
14 | return func(w http.ResponseWriter, r *http.Request) { | 14 | return func(w http.ResponseWriter, r *http.Request) { |
15 | var req types.DepartmentAddRequest | 15 | var req types.DepartmentAddRequest |
16 | if err := httpx.Parse(r, &req); err != nil { | 16 | if err := httpx.Parse(r, &req); err != nil { |
17 | - httpx.ErrorCtx(r.Context(), w, err) | 17 | + result.ParamErrorResult(r, w, err) |
18 | return | 18 | return |
19 | } | 19 | } |
20 | 20 |
@@ -14,7 +14,7 @@ func SystemDeleteHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | @@ -14,7 +14,7 @@ func SystemDeleteHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||
14 | return func(w http.ResponseWriter, r *http.Request) { | 14 | return func(w http.ResponseWriter, r *http.Request) { |
15 | var req types.DepartmentGetRequest | 15 | var req types.DepartmentGetRequest |
16 | if err := httpx.Parse(r, &req); err != nil { | 16 | if err := httpx.Parse(r, &req); err != nil { |
17 | - httpx.ErrorCtx(r.Context(), w, err) | 17 | + result.ParamErrorResult(r, w, err) |
18 | return | 18 | return |
19 | } | 19 | } |
20 | 20 |
@@ -14,7 +14,7 @@ func SystemGetHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | @@ -14,7 +14,7 @@ func SystemGetHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||
14 | return func(w http.ResponseWriter, r *http.Request) { | 14 | return func(w http.ResponseWriter, r *http.Request) { |
15 | var req types.DepartmentGetRequest | 15 | var req types.DepartmentGetRequest |
16 | if err := httpx.Parse(r, &req); err != nil { | 16 | if err := httpx.Parse(r, &req); err != nil { |
17 | - httpx.ErrorCtx(r.Context(), w, err) | 17 | + result.ParamErrorResult(r, w, err) |
18 | return | 18 | return |
19 | } | 19 | } |
20 | 20 |
@@ -14,7 +14,7 @@ func SystemListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | @@ -14,7 +14,7 @@ func SystemListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||
14 | return func(w http.ResponseWriter, r *http.Request) { | 14 | return func(w http.ResponseWriter, r *http.Request) { |
15 | var req types.DepartmentListRequest | 15 | var req types.DepartmentListRequest |
16 | if err := httpx.Parse(r, &req); err != nil { | 16 | if err := httpx.Parse(r, &req); err != nil { |
17 | - httpx.ErrorCtx(r.Context(), w, err) | 17 | + result.ParamErrorResult(r, w, err) |
18 | return | 18 | return |
19 | } | 19 | } |
20 | 20 |
@@ -14,7 +14,7 @@ func SystemUpdateHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | @@ -14,7 +14,7 @@ func SystemUpdateHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||
14 | return func(w http.ResponseWriter, r *http.Request) { | 14 | return func(w http.ResponseWriter, r *http.Request) { |
15 | var req types.DepartmentUpdateRequest | 15 | var req types.DepartmentUpdateRequest |
16 | if err := httpx.Parse(r, &req); err != nil { | 16 | if err := httpx.Parse(r, &req); err != nil { |
17 | - httpx.ErrorCtx(r.Context(), w, err) | 17 | + result.ParamErrorResult(r, w, err) |
18 | return | 18 | return |
19 | } | 19 | } |
20 | 20 |
@@ -14,7 +14,7 @@ func MiniBusinessHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | @@ -14,7 +14,7 @@ func MiniBusinessHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||
14 | return func(w http.ResponseWriter, r *http.Request) { | 14 | return func(w http.ResponseWriter, r *http.Request) { |
15 | var req types.MessageBusinessRequest | 15 | var req types.MessageBusinessRequest |
16 | if err := httpx.Parse(r, &req); err != nil { | 16 | if err := httpx.Parse(r, &req); err != nil { |
17 | - httpx.ErrorCtx(r.Context(), w, err) | 17 | + result.ParamErrorResult(r, w, err) |
18 | return | 18 | return |
19 | } | 19 | } |
20 | 20 |
@@ -14,7 +14,7 @@ func MiniSystemHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | @@ -14,7 +14,7 @@ func MiniSystemHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||
14 | return func(w http.ResponseWriter, r *http.Request) { | 14 | return func(w http.ResponseWriter, r *http.Request) { |
15 | var req types.MessageSystemRequest | 15 | var req types.MessageSystemRequest |
16 | if err := httpx.Parse(r, &req); err != nil { | 16 | if err := httpx.Parse(r, &req); err != nil { |
17 | - httpx.ErrorCtx(r.Context(), w, err) | 17 | + result.ParamErrorResult(r, w, err) |
18 | return | 18 | return |
19 | } | 19 | } |
20 | 20 |
@@ -14,7 +14,7 @@ func MiniMyLikeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | @@ -14,7 +14,7 @@ func MiniMyLikeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||
14 | return func(w http.ResponseWriter, r *http.Request) { | 14 | return func(w http.ResponseWriter, r *http.Request) { |
15 | var req types.MiniMyLikeRequest | 15 | var req types.MiniMyLikeRequest |
16 | if err := httpx.Parse(r, &req); err != nil { | 16 | if err := httpx.Parse(r, &req); err != nil { |
17 | - httpx.ErrorCtx(r.Context(), w, err) | 17 | + result.ParamErrorResult(r, w, err) |
18 | return | 18 | return |
19 | } | 19 | } |
20 | 20 |
@@ -2,6 +2,7 @@ package article | @@ -2,6 +2,7 @@ package article | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "context" | 4 | "context" |
5 | + | ||
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" |
6 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata" | 7 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata" |
7 | 8 | ||
@@ -25,6 +26,7 @@ func NewMiniArticleMarkListLogic(ctx context.Context, svcCtx *svc.ServiceContext | @@ -25,6 +26,7 @@ func NewMiniArticleMarkListLogic(ctx context.Context, svcCtx *svc.ServiceContext | ||
25 | } | 26 | } |
26 | } | 27 | } |
27 | 28 | ||
29 | +// 获取我的文章浏览记录 | ||
28 | func (l *MiniArticleMarkListLogic) MiniArticleMarkList(req *types.MiniArticleMarkListRequest) (resp *types.MiniArticleMarkListResponse, err error) { | 30 | func (l *MiniArticleMarkListLogic) MiniArticleMarkList(req *types.MiniArticleMarkListRequest) (resp *types.MiniArticleMarkListResponse, err error) { |
29 | var userToken = contextdata.GetUserTokenFromCtx(l.ctx) | 31 | var userToken = contextdata.GetUserTokenFromCtx(l.ctx) |
30 | 32 |
@@ -5,6 +5,9 @@ import ( | @@ -5,6 +5,9 @@ import ( | ||
5 | 5 | ||
6 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" | 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" | 7 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" |
8 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction" | ||
9 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" | ||
10 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr" | ||
8 | 11 | ||
9 | "github.com/zeromicro/go-zero/core/logx" | 12 | "github.com/zeromicro/go-zero/core/logx" |
10 | ) | 13 | ) |
@@ -25,7 +28,63 @@ func NewMiniArticleSetTagLogic(ctx context.Context, svcCtx *svc.ServiceContext) | @@ -25,7 +28,63 @@ func NewMiniArticleSetTagLogic(ctx context.Context, svcCtx *svc.ServiceContext) | ||
25 | 28 | ||
26 | // 设置文章的定性标签 | 29 | // 设置文章的定性标签 |
27 | func (l *MiniArticleSetTagLogic) MiniArticleSetTag(req *types.MiniArticleSetTagRequest) (resp *types.MiniArticleSetTagResponse, err error) { | 30 | func (l *MiniArticleSetTagLogic) MiniArticleSetTag(req *types.MiniArticleSetTagRequest) (resp *types.MiniArticleSetTagResponse, err error) { |
28 | - | 31 | + var conn = l.svcCtx.DefaultDBConn() |
29 | // | 32 | // |
30 | - return | 33 | + articleInfo, err := l.svcCtx.ArticleRepository.FindOne(l.ctx, conn, req.ArticleId) |
34 | + if err != nil { | ||
35 | + return nil, xerr.NewErrMsgErr("获取文章信息失败", err) | ||
36 | + } | ||
37 | + if articleInfo.CompanyId != req.CompanyId { | ||
38 | + return nil, xerr.NewErrMsg("获取文章信息失败") | ||
39 | + } | ||
40 | + | ||
41 | + tagInfo, err := l.svcCtx.ArticleTagRepository.FindOne(l.ctx, conn, req.TagId) | ||
42 | + if err != nil { | ||
43 | + return nil, xerr.NewErrMsgErr("获取标签信息失败", err) | ||
44 | + } | ||
45 | + | ||
46 | + if tagInfo.CompanyId != req.CompanyId { | ||
47 | + return nil, xerr.NewErrMsg("获取标签信息失败") | ||
48 | + } | ||
49 | + // 查询可能存在的 ArticleAndTag | ||
50 | + queryOption := domain.NewQueryOptions().WithFindOnly().MustWithKV("articleId", articleInfo.Id) | ||
51 | + _, oldTags, err := l.svcCtx.ArticleAndTagRepository.Find(l.ctx, conn, queryOption) | ||
52 | + if err != nil { | ||
53 | + return nil, xerr.NewErrMsgErr("检查文章的标签失败", err) | ||
54 | + } | ||
55 | + // 更新article中的tags | ||
56 | + articleInfo.Tags = []int64{tagInfo.Id} | ||
57 | + // 额外保存一份ArticleAndTag | ||
58 | + articleAndTag := domain.ArticleAndTag{ | ||
59 | + Id: 0, | ||
60 | + CompanyId: articleInfo.CompanyId, | ||
61 | + CreatedAt: 0, | ||
62 | + UpdatedAt: 0, | ||
63 | + ArticleId: articleInfo.Id, | ||
64 | + TagId: tagInfo.Id, | ||
65 | + } | ||
66 | + err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error { | ||
67 | + //清理可能存在的 ArticleAndTag | ||
68 | + for _, v := range oldTags { | ||
69 | + _, err = l.svcCtx.ArticleAndTagRepository.Delete(ctx, c, v) | ||
70 | + if err != nil { | ||
71 | + return err | ||
72 | + } | ||
73 | + } | ||
74 | + // 更新article | ||
75 | + _, err = l.svcCtx.ArticleRepository.UpdateWithVersion(ctx, c, articleInfo) | ||
76 | + if err != nil { | ||
77 | + return err | ||
78 | + } | ||
79 | + _, err = l.svcCtx.ArticleAndTagRepository.Insert(ctx, c, &articleAndTag) | ||
80 | + if err != nil { | ||
81 | + return err | ||
82 | + } | ||
83 | + return nil | ||
84 | + }, true) | ||
85 | + | ||
86 | + resp = &types.MiniArticleSetTagResponse{ | ||
87 | + Id: articleAndTag.Id, | ||
88 | + } | ||
89 | + return resp, nil | ||
31 | } | 90 | } |
@@ -43,7 +43,6 @@ func (l *SystemAddLogic) SystemAdd(req *types.DepartmentAddRequest) (resp *types | @@ -43,7 +43,6 @@ func (l *SystemAddLogic) SystemAdd(req *types.DepartmentAddRequest) (resp *types | ||
43 | } | 43 | } |
44 | 44 | ||
45 | insert := &domain.Department{ | 45 | insert := &domain.Department{ |
46 | - Id: 0, | ||
47 | ParentId: 0, | 46 | ParentId: 0, |
48 | CompanyId: userToken.CompanyId, | 47 | CompanyId: userToken.CompanyId, |
49 | Name: req.Name, | 48 | Name: req.Name, |
@@ -26,6 +26,7 @@ type ServiceContext struct { | @@ -26,6 +26,7 @@ type ServiceContext struct { | ||
26 | ArticleRepository domain.ArticleRepository | 26 | ArticleRepository domain.ArticleRepository |
27 | ArticleSectionRepository domain.ArticleSectionRepository | 27 | ArticleSectionRepository domain.ArticleSectionRepository |
28 | ArticleTagRepository domain.ArticleTagRepository | 28 | ArticleTagRepository domain.ArticleTagRepository |
29 | + ArticleAndTagRepository domain.ArticleAndTagRepository | ||
29 | 30 | ||
30 | CompanyRepository domain.CompanyRepository | 31 | CompanyRepository domain.CompanyRepository |
31 | CommentRepository domain.CommentRepository // 待移除 | 32 | CommentRepository domain.CommentRepository // 待移除 |
@@ -59,12 +60,14 @@ func NewServiceContext(c config.Config) *ServiceContext { | @@ -59,12 +60,14 @@ func NewServiceContext(c config.Config) *ServiceContext { | ||
59 | ApiAuthService: apiAuth, | 60 | ApiAuthService: apiAuth, |
60 | LoginStatusCheck: middleware.NewLoginStatusCheckMiddleware(apiAuth).Handle, | 61 | LoginStatusCheck: middleware.NewLoginStatusCheckMiddleware(apiAuth).Handle, |
61 | 62 | ||
62 | - CommentRepository: repository.NewCommentRepository(cache.NewCachedRepository(mlCache)), | ||
63 | - ArticleBackupRepository: repository.NewArticleBackupRepository(cache.NewCachedRepository(mlCache)), | ||
64 | - ArticleCommentRepository: repository.NewArticleCommentRepository(cache.NewCachedRepository(mlCache)), | ||
65 | - ArticleDraftRepository: repository.NewArticleDraftRepository(cache.NewCachedRepository(mlCache)), | ||
66 | - ArticleRepository: repository.NewArticleRepository(cache.NewCachedRepository(mlCache)), | ||
67 | - ArticleSectionRepository: repository.NewArticleSectionRepository(cache.NewCachedRepository(mlCache)), | 63 | + CommentRepository: repository.NewCommentRepository(cache.NewCachedRepository(mlCache)), |
64 | + ArticleBackupRepository: repository.NewArticleBackupRepository(cache.NewCachedRepository(mlCache)), | ||
65 | + ArticleCommentRepository: repository.NewArticleCommentRepository(cache.NewCachedRepository(mlCache)), | ||
66 | + ArticleDraftRepository: repository.NewArticleDraftRepository(cache.NewCachedRepository(mlCache)), | ||
67 | + ArticleRepository: repository.NewArticleRepository(cache.NewCachedRepository(mlCache)), | ||
68 | + ArticleSectionRepository: repository.NewArticleSectionRepository(cache.NewCachedRepository(mlCache)), | ||
69 | + ArticleAndTagRepository: repository.NewArticleAndTagRepository(cache.NewCachedRepository(mlCache)), | ||
70 | + | ||
68 | CompanyRepository: repository.NewCompanyRepository(cache.NewCachedRepository(mlCache)), | 71 | CompanyRepository: repository.NewCompanyRepository(cache.NewCachedRepository(mlCache)), |
69 | DepartmentRepository: repository.NewDepartmentRepository(cache.NewCachedRepository(mlCache)), | 72 | DepartmentRepository: repository.NewDepartmentRepository(cache.NewCachedRepository(mlCache)), |
70 | MessageBusinessRepository: repository.NewMessageBusinessRepository(cache.NewCachedRepository(mlCache)), | 73 | MessageBusinessRepository: repository.NewMessageBusinessRepository(cache.NewCachedRepository(mlCache)), |
@@ -97,6 +97,9 @@ func (repository *ArticleAndTagRepository) Find(ctx context.Context, conn transa | @@ -97,6 +97,9 @@ func (repository *ArticleAndTagRepository) Find(ctx context.Context, conn transa | ||
97 | ) | 97 | ) |
98 | queryFunc := func() (interface{}, error) { | 98 | queryFunc := func() (interface{}, error) { |
99 | tx = tx.Model(&ms).Order("id desc") | 99 | tx = tx.Model(&ms).Order("id desc") |
100 | + if v, ok := queryOptions["articleId"]; ok { | ||
101 | + tx = tx.Where("article_id=?", v) | ||
102 | + } | ||
100 | if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil { | 103 | if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil { |
101 | return dms, tx.Error | 104 | return dms, tx.Error |
102 | } | 105 | } |
@@ -277,3 +277,35 @@ func (repository *ArticleRepository) IncreaseCountComment(ctx context.Context, c | @@ -277,3 +277,35 @@ func (repository *ArticleRepository) IncreaseCountComment(ctx context.Context, c | ||
277 | func NewArticleRepository(cache *cache.CachedRepository) domain.ArticleRepository { | 277 | func NewArticleRepository(cache *cache.CachedRepository) domain.ArticleRepository { |
278 | return &ArticleRepository{CachedRepository: cache} | 278 | return &ArticleRepository{CachedRepository: cache} |
279 | } | 279 | } |
280 | + | ||
281 | +// with | ||
282 | +// -- 按查看权限查询文章 | ||
283 | +// t_article as( | ||
284 | +// select article.id | ||
285 | +// from article | ||
286 | +// where article.deleted_at=0 | ||
287 | +// and article.company_id =1598224576532189184 | ||
288 | +// and article."show" =0 | ||
289 | +// and (article.target_user =0 or article.who_read @>'[1]') | ||
290 | +// ), | ||
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 | +// -- 查询人员已查看的文章 | ||
304 | +// t_user_read as( | ||
305 | +// select user_read_article.article_id from user_read_article where user_read_article.user_id =1 | ||
306 | +// ) | ||
307 | +// -- 汇总统计 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 | ||
309 | +// 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 | ||
311 | +// group by t_article_and_tag_2.tag_id |
@@ -14,8 +14,8 @@ type ArticleBackup struct { | @@ -14,8 +14,8 @@ type ArticleBackup struct { | ||
14 | UpdatedAt int64 `json:"updatedAt,omitempty"` | 14 | UpdatedAt int64 `json:"updatedAt,omitempty"` |
15 | DeletedAt int64 `json:"deletedAt,omitempty"` | 15 | DeletedAt int64 `json:"deletedAt,omitempty"` |
16 | Version int `json:"version,omitempty"` | 16 | Version int `json:"version,omitempty"` |
17 | - Operator UserSimple `json:"operator"` // 操作人 | ||
18 | - ArticleId int64 `json:"articleId"` | 17 | + Operator UserSimple `json:"operator"` // 操作人 |
18 | + ArticleId int64 `json:"articleId"` // | ||
19 | Title string `json:"title"` // 标题 | 19 | Title string `json:"title"` // 标题 |
20 | Section []ArticleSection `json:"section"` // 分段内容 | 20 | Section []ArticleSection `json:"section"` // 分段内容 |
21 | Images []Image `json:"images"` // 图片 | 21 | Images []Image `json:"images"` // 图片 |
@@ -29,11 +29,9 @@ type Opinion struct { | @@ -29,11 +29,9 @@ type Opinion struct { | ||
29 | } | 29 | } |
30 | 30 | ||
31 | type UserSimple struct { | 31 | type UserSimple struct { |
32 | - Id int64 `json:"id"` // 人员id | ||
33 | - Name string `json:"name"` // 人员的名字 | ||
34 | - Avatar string `json:"avatar,omitempty"` // 人员头像URL | ||
35 | - // GroupId int64 `json:"groupId"` //分组id | ||
36 | - //Group string `json:"group,omitempty"` // 人员的分组 | 32 | + Id int64 `json:"id"` // 人员id |
33 | + Name string `json:"name"` // 人员的名字 | ||
34 | + Avatar string `json:"avatar,omitempty"` // 人员头像URL | ||
37 | Position string `json:"position,omitempty"` // 职位 | 35 | Position string `json:"position,omitempty"` // 职位 |
38 | Company string `json:"company,omitempty"` // 公司 | 36 | Company string `json:"company,omitempty"` // 公司 |
39 | CompanyId int64 `json:"companyId"` | 37 | CompanyId int64 `json:"companyId"` |
-
请 注册 或 登录 后发表评论