正在显示
19 个修改的文件
包含
283 行增加
和
39 行删除
@@ -75,9 +75,11 @@ service Core { | @@ -75,9 +75,11 @@ service Core { | ||
75 | 75 | ||
76 | @doc "小程序首页数据展示" | 76 | @doc "小程序首页数据展示" |
77 | @handler MiniShowHomePage | 77 | @handler MiniShowHomePage |
78 | - get /show/home_page (MiniHomePageRequest) returns (MiniHomePageRespose) | ||
79 | - | 78 | + get /show/home_page (MiniHomePageRequest) returns (MiniHomePageResponse) |
80 | 79 | ||
80 | + @doc "小程序首页搜索文章" | ||
81 | + @handler MiniSearchArticlePage | ||
82 | + post /show/search_article (MiniSearchArticleRequest) returns (MiniSearchArticleResponse) | ||
81 | } | 83 | } |
82 | 84 | ||
83 | // 管理后台接口 | 85 | // 管理后台接口 |
@@ -53,9 +53,10 @@ type ( | @@ -53,9 +53,10 @@ type ( | ||
53 | CountLove int `json:"countLove"` // 点赞数量 | 53 | CountLove int `json:"countLove"` // 点赞数量 |
54 | CountComment int `json:"countComment"` // 评论数量 | 54 | CountComment int `json:"countComment"` // 评论数量 |
55 | CountRead int `json:"countRead"` // 浏览数量 | 55 | CountRead int `json:"countRead"` // 浏览数量 |
56 | - Show int `json:"show"` // 评论的展示状态(0显示、1不显示) | 56 | + Show int `json:"show"` // 评论的展示状态(1显示、2不显示) |
57 | Edit int `json:"edit"` // 文章是否存在变更记录 (0 不存在 1存在) | 57 | Edit int `json:"edit"` // 文章是否存在变更记录 (0 不存在 1存在) |
58 | MeLoveFlag int `json:"meLoveFlag"` // 当前人员对文章的点赞标识 (0 没有点赞 1有点赞) | 58 | MeLoveFlag int `json:"meLoveFlag"` // 当前人员对文章的点赞标识 (0 没有点赞 1有点赞) |
59 | + Tags []string `json:"tags"` //文章的标签 | ||
59 | } | 60 | } |
60 | ArticleSection { | 61 | ArticleSection { |
61 | Id int64 `json:"id"` //段落id | 62 | Id int64 `json:"id"` //段落id |
@@ -469,7 +470,7 @@ type ( | @@ -469,7 +470,7 @@ type ( | ||
469 | CompanyId int64 `path:",optional"` | 470 | CompanyId int64 `path:",optional"` |
470 | UserId int64 `path:",optional"` | 471 | UserId int64 `path:",optional"` |
471 | } | 472 | } |
472 | - MiniHomePageRespose { | 473 | + MiniHomePageResponse { |
473 | TagCategory []string `json:"tagCategory"` | 474 | TagCategory []string `json:"tagCategory"` |
474 | Tags []ArticleTagCount `json:"tags"` | 475 | Tags []ArticleTagCount `json:"tags"` |
475 | } | 476 | } |
@@ -482,4 +483,33 @@ type ( | @@ -482,4 +483,33 @@ type ( | ||
482 | TotalArticle int `json:"totalArticle"` // 总的文章数量 | 483 | TotalArticle int `json:"totalArticle"` // 总的文章数量 |
483 | ReadArticle int `json:"readArticle"` // 已读的标签数量 | 484 | ReadArticle int `json:"readArticle"` // 已读的标签数量 |
484 | } | 485 | } |
486 | +) | ||
487 | + | ||
488 | +//小程序首页搜索文章 | ||
489 | +type ( | ||
490 | + MiniSearchArticleRequest { | ||
491 | + Page int `json:"page"` | ||
492 | + Size int `json:"size"` | ||
493 | + CompanyId int64 `json:",optional"` | ||
494 | + UserId int64 `json:",optional"` | ||
495 | + TagGroup string `json:"tagGroup"` | ||
496 | + TagId int64 `json:"tagId"` | ||
497 | + BeginTime int64 `json:"beginTime"` | ||
498 | + EndTime int `json:"endTime"` | ||
499 | + SearchWord string `json:"searchWord"` | ||
500 | + } | ||
501 | + // | ||
502 | + MiniSearchArticleResponse { | ||
503 | + Total int `json:"total"` | ||
504 | + List []MiniSearchArticleItem `json:"list"` | ||
505 | + } | ||
506 | + // | ||
507 | + MiniSearchArticleItem{ | ||
508 | + ArticleId int64 `json:"articleId"` | ||
509 | + Title string `json:"title"` | ||
510 | + Author string `json:"author"` // 发布人 | ||
511 | + Images []string `json:"images"` | ||
512 | + CreatedAt int64 `json:"createdAt"` | ||
513 | + MeReadFlag int `json:"meReadFlag"` //已读标识 [0:未读] [1:已读] | ||
514 | + } | ||
485 | ) | 515 | ) |
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 MiniSearchArticlePageHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||
13 | + return func(w http.ResponseWriter, r *http.Request) { | ||
14 | + var req types.MiniSearchArticleRequest | ||
15 | + if err := httpx.Parse(r, &req); err != nil { | ||
16 | + httpx.ErrorCtx(r.Context(), w, err) | ||
17 | + return | ||
18 | + } | ||
19 | + | ||
20 | + l := article.NewMiniSearchArticlePageLogic(r.Context(), svcCtx) | ||
21 | + resp, err := l.MiniSearchArticlePage(&req) | ||
22 | + if err != nil { | ||
23 | + httpx.ErrorCtx(r.Context(), w, err) | ||
24 | + } else { | ||
25 | + httpx.OkJsonCtx(r.Context(), w, resp) | ||
26 | + } | ||
27 | + } | ||
28 | +} |
@@ -369,6 +369,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { | @@ -369,6 +369,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { | ||
369 | Path: "/show/home_page", | 369 | Path: "/show/home_page", |
370 | Handler: article.MiniShowHomePageHandler(serverCtx), | 370 | Handler: article.MiniShowHomePageHandler(serverCtx), |
371 | }, | 371 | }, |
372 | + { | ||
373 | + Method: http.MethodPost, | ||
374 | + Path: "/show/search_article", | ||
375 | + Handler: article.MiniSearchArticlePageHandler(serverCtx), | ||
376 | + }, | ||
372 | }, | 377 | }, |
373 | rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret), | 378 | rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret), |
374 | rest.WithPrefix("/v1/mini"), | 379 | rest.WithPrefix("/v1/mini"), |
@@ -2,6 +2,7 @@ package article | @@ -2,6 +2,7 @@ package article | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "context" | 4 | "context" |
5 | + "strconv" | ||
5 | "strings" | 6 | "strings" |
6 | "text/template" | 7 | "text/template" |
7 | 8 | ||
@@ -9,6 +10,7 @@ import ( | @@ -9,6 +10,7 @@ import ( | ||
9 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" | 10 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" |
10 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction" | 11 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction" |
11 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" | 12 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" |
13 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/tool/oss" | ||
12 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr" | 14 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr" |
13 | 15 | ||
14 | "github.com/samber/lo" | 16 | "github.com/samber/lo" |
@@ -52,13 +54,16 @@ func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateR | @@ -52,13 +54,16 @@ func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateR | ||
52 | if len(req.Images) > 9 { | 54 | if len(req.Images) > 9 { |
53 | return nil, xerr.NewErrMsg("图片数量最多9张") | 55 | return nil, xerr.NewErrMsg("图片数量最多9张") |
54 | } | 56 | } |
55 | - //TODO 获取图片的尺寸大小 | 57 | + //获取图片的尺寸大小 |
56 | images := []domain.Image{} | 58 | images := []domain.Image{} |
57 | for _, val := range req.Images { | 59 | for _, val := range req.Images { |
60 | + fInfo, _ := oss.GetImageInfo(val) | ||
61 | + w, _ := strconv.Atoi(fInfo.ImageWidth.Value) | ||
62 | + h, _ := strconv.Atoi(fInfo.ImageHeight.Value) | ||
58 | images = append(images, domain.Image{ | 63 | images = append(images, domain.Image{ |
59 | Url: val, | 64 | Url: val, |
60 | - Width: 0, | ||
61 | - Height: 0, | 65 | + Width: w, |
66 | + Height: h, | ||
62 | }) | 67 | }) |
63 | } | 68 | } |
64 | 69 | ||
@@ -157,7 +162,7 @@ func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateR | @@ -157,7 +162,7 @@ func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateR | ||
157 | CountLove: 0, | 162 | CountLove: 0, |
158 | CountComment: 0, | 163 | CountComment: 0, |
159 | CountRead: 0, | 164 | CountRead: 0, |
160 | - Show: 0, | 165 | + Show: domain.ArticleShowEnable, |
161 | Tags: []int64{}, | 166 | Tags: []int64{}, |
162 | } | 167 | } |
163 | if len(whoRead) > 0 { | 168 | if len(whoRead) > 0 { |
@@ -38,9 +38,7 @@ func (l *MiniGetArticleLogic) MiniGetArticle(req *types.MiniArticleGetRequest) ( | @@ -38,9 +38,7 @@ func (l *MiniGetArticleLogic) MiniGetArticle(req *types.MiniArticleGetRequest) ( | ||
38 | if articleInfo.CompanyId != req.CompanyId { | 38 | if articleInfo.CompanyId != req.CompanyId { |
39 | return nil, xerr.NewErrMsg("没有查看权限") | 39 | return nil, xerr.NewErrMsg("没有查看权限") |
40 | } | 40 | } |
41 | - | ||
42 | //TODO 检查可查看人 | 41 | //TODO 检查可查看人 |
43 | - | ||
44 | if articleInfo.Show == domain.ArticleShowDisable { | 42 | if articleInfo.Show == domain.ArticleShowDisable { |
45 | // 文章内容不显示 | 43 | // 文章内容不显示 |
46 | resp = &types.MiniArticleGetResponse{ | 44 | resp = &types.MiniArticleGetResponse{ |
@@ -71,6 +69,14 @@ func (l *MiniGetArticleLogic) MiniGetArticle(req *types.MiniArticleGetRequest) ( | @@ -71,6 +69,14 @@ func (l *MiniGetArticleLogic) MiniGetArticle(req *types.MiniArticleGetRequest) ( | ||
71 | meLoveFlag = 1 | 69 | meLoveFlag = 1 |
72 | } | 70 | } |
73 | } | 71 | } |
72 | + tags := []string{} | ||
73 | + if len(articleInfo.Tags) > 0 { | ||
74 | + queryOption := domain.NewQueryOptions().WithFindOnly().MustWithKV("ids", articleInfo.Tags) | ||
75 | + _, tagList, _ := l.svcCtx.ArticleTagRepository.Find(l.ctx, conn, req.CompanyId, queryOption) | ||
76 | + for _, val := range tagList { | ||
77 | + tags = append(tags, val.Name) | ||
78 | + } | ||
79 | + } | ||
74 | 80 | ||
75 | sortBy := domain.SortArticleSection(sectionList) | 81 | sortBy := domain.SortArticleSection(sectionList) |
76 | sort.Sort(sortBy) | 82 | sort.Sort(sortBy) |
@@ -111,6 +117,7 @@ func (l *MiniGetArticleLogic) MiniGetArticle(req *types.MiniArticleGetRequest) ( | @@ -111,6 +117,7 @@ func (l *MiniGetArticleLogic) MiniGetArticle(req *types.MiniArticleGetRequest) ( | ||
111 | Show: int(articleInfo.Show), | 117 | Show: int(articleInfo.Show), |
112 | Edit: 0, | 118 | Edit: 0, |
113 | MeLoveFlag: meLoveFlag, | 119 | MeLoveFlag: meLoveFlag, |
120 | + Tags: tags, | ||
114 | } | 121 | } |
115 | if articleInfo.CreatedAt != articleInfo.UpdatedAt { | 122 | if articleInfo.CreatedAt != articleInfo.UpdatedAt { |
116 | resp.Edit = 1 | 123 | resp.Edit = 1 |
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 MiniSearchArticlePageLogic struct { | ||
13 | + logx.Logger | ||
14 | + ctx context.Context | ||
15 | + svcCtx *svc.ServiceContext | ||
16 | +} | ||
17 | + | ||
18 | +func NewMiniSearchArticlePageLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniSearchArticlePageLogic { | ||
19 | + return &MiniSearchArticlePageLogic{ | ||
20 | + Logger: logx.WithContext(ctx), | ||
21 | + ctx: ctx, | ||
22 | + svcCtx: svcCtx, | ||
23 | + } | ||
24 | +} | ||
25 | + | ||
26 | +func (l *MiniSearchArticlePageLogic) MiniSearchArticlePage(req *types.MiniSearchArticleRequest) (resp *types.MiniSearchArticleResponse, err error) { | ||
27 | + // todo: add your logic here and delete this line | ||
28 | + | ||
29 | + return | ||
30 | +} |
@@ -26,7 +26,7 @@ func NewMiniShowHomePageLogic(ctx context.Context, svcCtx *svc.ServiceContext) * | @@ -26,7 +26,7 @@ func NewMiniShowHomePageLogic(ctx context.Context, svcCtx *svc.ServiceContext) * | ||
26 | } | 26 | } |
27 | } | 27 | } |
28 | 28 | ||
29 | -func (l *MiniShowHomePageLogic) MiniShowHomePage(req *types.MiniHomePageRequest) (resp *types.MiniHomePageRespose, err error) { | 29 | +func (l *MiniShowHomePageLogic) MiniShowHomePage(req *types.MiniHomePageRequest) (resp *types.MiniHomePageResponse, err error) { |
30 | // 获取所有的标签 | 30 | // 获取所有的标签 |
31 | var conn = l.svcCtx.DefaultDBConn() | 31 | var conn = l.svcCtx.DefaultDBConn() |
32 | queryOption := domain.NewQueryOptions().WithFindOnly() | 32 | queryOption := domain.NewQueryOptions().WithFindOnly() |
@@ -64,7 +64,7 @@ func (l *MiniShowHomePageLogic) MiniShowHomePage(req *types.MiniHomePageRequest) | @@ -64,7 +64,7 @@ func (l *MiniShowHomePageLogic) MiniShowHomePage(req *types.MiniHomePageRequest) | ||
64 | tagCount = append(tagCount, m) | 64 | tagCount = append(tagCount, m) |
65 | } | 65 | } |
66 | tagCategory = lo.Uniq(tagCategory) | 66 | tagCategory = lo.Uniq(tagCategory) |
67 | - resp = &types.MiniHomePageRespose{ | 67 | + resp = &types.MiniHomePageResponse{ |
68 | TagCategory: tagCategory, | 68 | TagCategory: tagCategory, |
69 | Tags: tagCount, | 69 | Tags: tagCount, |
70 | } | 70 | } |
@@ -2,11 +2,14 @@ package article | @@ -2,11 +2,14 @@ package article | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "context" | 4 | "context" |
5 | + "strconv" | ||
6 | + | ||
5 | "github.com/samber/lo" | 7 | "github.com/samber/lo" |
6 | "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/db/transaction" |
7 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" | 9 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" |
8 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/gateway/authlib" | 10 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/gateway/authlib" |
9 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata" | 11 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata" |
12 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/tool/oss" | ||
10 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr" | 13 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr" |
11 | 14 | ||
12 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" | 15 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" |
@@ -36,13 +39,16 @@ func (l *SystemUpdateArticleLogic) SystemUpdateArticle(req *types.SystemArticleU | @@ -36,13 +39,16 @@ func (l *SystemUpdateArticleLogic) SystemUpdateArticle(req *types.SystemArticleU | ||
36 | if err != nil { | 39 | if err != nil { |
37 | return nil, xerr.NewErrMsgErr("帖子不存在", err) | 40 | return nil, xerr.NewErrMsgErr("帖子不存在", err) |
38 | } | 41 | } |
39 | - //TODO 获取图片的尺寸大小 | 42 | + //获取图片的尺寸大小 |
40 | images := []domain.Image{} | 43 | images := []domain.Image{} |
41 | for _, val := range req.Images { | 44 | for _, val := range req.Images { |
45 | + fInfo, _ := oss.GetImageInfo(val) | ||
46 | + w, _ := strconv.Atoi(fInfo.ImageWidth.Value) | ||
47 | + h, _ := strconv.Atoi(fInfo.ImageHeight.Value) | ||
42 | images = append(images, domain.Image{ | 48 | images = append(images, domain.Image{ |
43 | Url: val, | 49 | Url: val, |
44 | - Width: 0, | ||
45 | - Height: 0, | 50 | + Width: w, |
51 | + Height: h, | ||
46 | }) | 52 | }) |
47 | } | 53 | } |
48 | article.Title = req.Title | 54 | article.Title = req.Title |
@@ -130,7 +130,7 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini | @@ -130,7 +130,7 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini | ||
130 | CountReply: 0, | 130 | CountReply: 0, |
131 | CountUserLove: 0, | 131 | CountUserLove: 0, |
132 | CountAdminLove: 0, | 132 | CountAdminLove: 0, |
133 | - Show: 0, | 133 | + Show: domain.CommentShowEnable, |
134 | AtWho: []domain.UserSimple{}, | 134 | AtWho: []domain.UserSimple{}, |
135 | } | 135 | } |
136 | 136 |
@@ -3,10 +3,12 @@ package tags | @@ -3,10 +3,12 @@ package tags | ||
3 | import ( | 3 | import ( |
4 | "context" | 4 | "context" |
5 | "fmt" | 5 | "fmt" |
6 | + "strconv" | ||
6 | 7 | ||
7 | "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" |
8 | "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" |
9 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" | 10 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" |
11 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/tool/oss" | ||
10 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr" | 12 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr" |
11 | 13 | ||
12 | "github.com/zeromicro/go-zero/core/logx" | 14 | "github.com/zeromicro/go-zero/core/logx" |
@@ -41,8 +43,10 @@ func (l *CreateTagLogic) CreateTag(req *types.TagCreateRequest) (resp *types.Tag | @@ -41,8 +43,10 @@ func (l *CreateTagLogic) CreateTag(req *types.TagCreateRequest) (resp *types.Tag | ||
41 | if cnt > 0 { | 43 | if cnt > 0 { |
42 | return nil, xerr.NewErrMsg(fmt.Sprintf("已存在标签 分类[%s]名称[%s]", req.Category, req.Name)) | 44 | return nil, xerr.NewErrMsg(fmt.Sprintf("已存在标签 分类[%s]名称[%s]", req.Category, req.Name)) |
43 | } | 45 | } |
44 | - //TODO 获取图片的尺寸大小 | ||
45 | - | 46 | + //获取图片的尺寸大小 |
47 | + fInfo, _ := oss.GetImageInfo(req.Image) | ||
48 | + w, _ := strconv.Atoi(fInfo.ImageWidth.Value) | ||
49 | + h, _ := strconv.Atoi(fInfo.ImageHeight.Value) | ||
46 | newTag := &domain.ArticleTag{ | 50 | newTag := &domain.ArticleTag{ |
47 | Id: 0, | 51 | Id: 0, |
48 | CompanyId: req.CompanyId, | 52 | CompanyId: req.CompanyId, |
@@ -52,8 +56,8 @@ func (l *CreateTagLogic) CreateTag(req *types.TagCreateRequest) (resp *types.Tag | @@ -52,8 +56,8 @@ func (l *CreateTagLogic) CreateTag(req *types.TagCreateRequest) (resp *types.Tag | ||
52 | Version: 0, | 56 | Version: 0, |
53 | Image: domain.Image{ | 57 | Image: domain.Image{ |
54 | Url: req.Image, | 58 | Url: req.Image, |
55 | - Width: 0, | ||
56 | - Height: 0, | 59 | + Width: w, |
60 | + Height: h, | ||
57 | }, | 61 | }, |
58 | Name: req.Name, | 62 | Name: req.Name, |
59 | Category: req.Category, | 63 | Category: req.Category, |
@@ -3,10 +3,12 @@ package tags | @@ -3,10 +3,12 @@ package tags | ||
3 | import ( | 3 | import ( |
4 | "context" | 4 | "context" |
5 | "fmt" | 5 | "fmt" |
6 | + "strconv" | ||
6 | 7 | ||
7 | "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" |
8 | "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" |
9 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" | 10 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" |
11 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/tool/oss" | ||
10 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr" | 12 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr" |
11 | 13 | ||
12 | "github.com/zeromicro/go-zero/core/logx" | 14 | "github.com/zeromicro/go-zero/core/logx" |
@@ -52,11 +54,16 @@ func (l *EditTagLogic) EditTag(req *types.TagEditRequest) (resp *types.TagEditRe | @@ -52,11 +54,16 @@ func (l *EditTagLogic) EditTag(req *types.TagEditRequest) (resp *types.TagEditRe | ||
52 | if oldTag.CompanyId != req.CompanyId { | 54 | if oldTag.CompanyId != req.CompanyId { |
53 | return nil, xerr.NewErrMsg("修改标签失败") | 55 | return nil, xerr.NewErrMsg("修改标签失败") |
54 | } | 56 | } |
55 | - | ||
56 | - //TODO 获取图片的尺寸大小 | ||
57 | - | 57 | + //获取图片的尺寸大小 |
58 | + fInfo, _ := oss.GetImageInfo(req.Image) | ||
59 | + w, _ := strconv.Atoi(fInfo.ImageWidth.Value) | ||
60 | + h, _ := strconv.Atoi(fInfo.ImageHeight.Value) | ||
58 | oldTag.Category = req.Category | 61 | oldTag.Category = req.Category |
59 | - oldTag.Image.Url = req.Image | 62 | + oldTag.Image = domain.Image{ |
63 | + Url: req.Image, | ||
64 | + Width: w, | ||
65 | + Height: h, | ||
66 | + } | ||
60 | oldTag.Name = req.Name | 67 | oldTag.Name = req.Name |
61 | oldTag.Remark = req.Remark | 68 | oldTag.Remark = req.Remark |
62 | oldTag.Other = req.Other | 69 | oldTag.Other = req.Other |
@@ -615,9 +615,10 @@ type MiniArticleGetResponse struct { | @@ -615,9 +615,10 @@ type MiniArticleGetResponse struct { | ||
615 | CountLove int `json:"countLove"` // 点赞数量 | 615 | CountLove int `json:"countLove"` // 点赞数量 |
616 | CountComment int `json:"countComment"` // 评论数量 | 616 | CountComment int `json:"countComment"` // 评论数量 |
617 | CountRead int `json:"countRead"` // 浏览数量 | 617 | CountRead int `json:"countRead"` // 浏览数量 |
618 | - Show int `json:"show"` // 评论的展示状态(0显示、1不显示) | 618 | + Show int `json:"show"` // 评论的展示状态(1显示、2不显示) |
619 | Edit int `json:"edit"` // 文章是否存在变更记录 (0 不存在 1存在) | 619 | Edit int `json:"edit"` // 文章是否存在变更记录 (0 不存在 1存在) |
620 | MeLoveFlag int `json:"meLoveFlag"` // 当前人员对文章的点赞标识 (0 没有点赞 1有点赞) | 620 | MeLoveFlag int `json:"meLoveFlag"` // 当前人员对文章的点赞标识 (0 没有点赞 1有点赞) |
621 | + Tags []string `json:"tags"` //文章的标签 | ||
621 | } | 622 | } |
622 | 623 | ||
623 | type ArticleSection struct { | 624 | type ArticleSection struct { |
@@ -1004,7 +1005,7 @@ type MiniHomePageRequest struct { | @@ -1004,7 +1005,7 @@ type MiniHomePageRequest struct { | ||
1004 | UserId int64 `path:",optional"` | 1005 | UserId int64 `path:",optional"` |
1005 | } | 1006 | } |
1006 | 1007 | ||
1007 | -type MiniHomePageRespose struct { | 1008 | +type MiniHomePageResponse struct { |
1008 | TagCategory []string `json:"tagCategory"` | 1009 | TagCategory []string `json:"tagCategory"` |
1009 | Tags []ArticleTagCount `json:"tags"` | 1010 | Tags []ArticleTagCount `json:"tags"` |
1010 | } | 1011 | } |
@@ -1019,6 +1020,32 @@ type ArticleTagCount struct { | @@ -1019,6 +1020,32 @@ type ArticleTagCount struct { | ||
1019 | ReadArticle int `json:"readArticle"` // 已读的标签数量 | 1020 | ReadArticle int `json:"readArticle"` // 已读的标签数量 |
1020 | } | 1021 | } |
1021 | 1022 | ||
1023 | +type MiniSearchArticleRequest struct { | ||
1024 | + Page int `json:"page"` | ||
1025 | + Size int `json:"size"` | ||
1026 | + CompanyId int64 `json:",optional"` | ||
1027 | + UserId int64 `json:",optional"` | ||
1028 | + TagGroup string `json:"tagGroup"` | ||
1029 | + TagId int64 `json:"tagId"` | ||
1030 | + BeginTime int64 `json:"beginTime"` | ||
1031 | + EndTime int `json:"endTime"` | ||
1032 | + SearchWord string `json:"searchWord"` | ||
1033 | +} | ||
1034 | + | ||
1035 | +type MiniSearchArticleResponse struct { | ||
1036 | + Total int `json:"total"` | ||
1037 | + List []MiniSearchArticleItem `json:"list"` | ||
1038 | +} | ||
1039 | + | ||
1040 | +type MiniSearchArticleItem struct { | ||
1041 | + ArticleId int64 `json:"articleId"` | ||
1042 | + Title string `json:"title"` | ||
1043 | + Author string `json:"author"` // 发布人 | ||
1044 | + Images []string `json:"images"` | ||
1045 | + CreatedAt int64 `json:"createdAt"` | ||
1046 | + MeReadFlag int `json:"meReadFlag"` //已读标识 [0:未读] [1:已读] | ||
1047 | +} | ||
1048 | + | ||
1022 | type RoleGetRequest struct { | 1049 | type RoleGetRequest struct { |
1023 | Id int64 `path:"id"` | 1050 | Id int64 `path:"id"` |
1024 | } | 1051 | } |
@@ -147,13 +147,13 @@ t_article_and_tag_2 as ( | @@ -147,13 +147,13 @@ t_article_and_tag_2 as ( | ||
147 | from article_and_tag | 147 | from article_and_tag |
148 | join article on article_and_tag.article_id = article.id | 148 | join article on article_and_tag.article_id = article.id |
149 | where article.deleted_at=0 | 149 | where article.deleted_at=0 |
150 | - and article.company_id =? | ||
151 | - and article."show" =0 | 150 | + and article.company_id = ? |
151 | + and article."show" = ? | ||
152 | and (article.target_user =0 or article.who_read @> ?) | 152 | and (article.target_user =0 or article.who_read @> ?) |
153 | ), | 153 | ), |
154 | -- 查询人员已查看的文章 | 154 | -- 查询人员已查看的文章 |
155 | t_user_read as( | 155 | t_user_read as( |
156 | - select user_read_article.article_id from user_read_article where user_read_article.user_id =? | 156 | + select user_read_article.article_id from user_read_article where user_read_article.user_id = ? |
157 | ) | 157 | ) |
158 | -- 汇总统计 total_article 符合条件的文章总数,read_article 已浏览的数量 | 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 | 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 |
@@ -163,6 +163,7 @@ group by t_article_and_tag_2.tag_id | @@ -163,6 +163,7 @@ group by t_article_and_tag_2.tag_id | ||
163 | ` | 163 | ` |
164 | condition := []interface{}{ | 164 | condition := []interface{}{ |
165 | companyId, | 165 | companyId, |
166 | + domain.ArticleShowEnable, | ||
166 | fmt.Sprintf("[%d]", userId), | 167 | fmt.Sprintf("[%d]", userId), |
167 | userId, | 168 | userId, |
168 | } | 169 | } |
@@ -279,11 +279,11 @@ func (repository *ArticleCommentRepository) Top5Comment(ctx context.Context, con | @@ -279,11 +279,11 @@ func (repository *ArticleCommentRepository) Top5Comment(ctx context.Context, con | ||
279 | article_comment.id , | 279 | article_comment.id , |
280 | (article_comment.count_reply +article_comment.count_user_love +article_comment.count_admin_love ) cnt | 280 | (article_comment.count_reply +article_comment.count_user_love +article_comment.count_admin_love ) cnt |
281 | from article_comment | 281 | from article_comment |
282 | - where top_id =0 and article_id =? and deleted_at=0 and show=0 and company_id=? | 282 | + where top_id =0 and article_id =? and deleted_at=0 and show= ? and company_id=? |
283 | order by cnt desc,article_comment.id desc | 283 | order by cnt desc,article_comment.id desc |
284 | limit 5 ` | 284 | limit 5 ` |
285 | db := conn.DB() | 285 | db := conn.DB() |
286 | - rows, err := db.Raw(sql1, articleId, companyId).Rows() | 286 | + rows, err := db.Raw(sql1, articleId, domain.CommentShowEnable, companyId).Rows() |
287 | if err != nil { | 287 | if err != nil { |
288 | return nil, err | 288 | return nil, err |
289 | } | 289 | } |
@@ -25,7 +25,7 @@ type Article struct { | @@ -25,7 +25,7 @@ type Article struct { | ||
25 | CountLove int `json:"countLove"` // 点赞数量 | 25 | CountLove int `json:"countLove"` // 点赞数量 |
26 | CountComment int `json:"countComment"` // 评论数量 | 26 | CountComment int `json:"countComment"` // 评论数量 |
27 | CountRead int `json:"countRead"` // 浏览数量 | 27 | CountRead int `json:"countRead"` // 浏览数量 |
28 | - Show ArticleShow `json:"show"` // 评论的展示状态(0显示、1不显示) | 28 | + Show ArticleShow `json:"show"` // 评论的展示状态(1显示,2不显示、) |
29 | Tags []int64 `json:"tags"` // 定性标签 | 29 | Tags []int64 `json:"tags"` // 定性标签 |
30 | Summary string `json:"summary"` // 内容概要 | 30 | Summary string `json:"summary"` // 内容概要 |
31 | // ...more | 31 | // ...more |
@@ -60,12 +60,12 @@ func (a ArticleTarget) Named() string { | @@ -60,12 +60,12 @@ func (a ArticleTarget) Named() string { | ||
60 | return "" | 60 | return "" |
61 | } | 61 | } |
62 | 62 | ||
63 | -// 文章的展示状态(0显示、1不显示) | 63 | +// 文章的展示状态(1显示,2不显示) |
64 | type ArticleShow int | 64 | type ArticleShow int |
65 | 65 | ||
66 | const ( | 66 | const ( |
67 | - ArticleShowEnable ArticleShow = 0 | ||
68 | - ArticleShowDisable ArticleShow = 1 | 67 | + ArticleShowEnable ArticleShow = 1 |
68 | + ArticleShowDisable ArticleShow = 2 | ||
69 | ) | 69 | ) |
70 | 70 | ||
71 | func (a ArticleShow) Named() string { | 71 | func (a ArticleShow) Named() string { |
@@ -27,17 +27,17 @@ type ArticleComment struct { | @@ -27,17 +27,17 @@ type ArticleComment struct { | ||
27 | CountReply int `json:"countReply"` // 回复数量 | 27 | CountReply int `json:"countReply"` // 回复数量 |
28 | CountUserLove int `json:"countUserLove"` // 用户点赞数量 | 28 | CountUserLove int `json:"countUserLove"` // 用户点赞数量 |
29 | CountAdminLove int `json:"countAdminLove"` // 运营点赞数量 | 29 | CountAdminLove int `json:"countAdminLove"` // 运营点赞数量 |
30 | - Show CommentShow `json:"showState"` // 评论的展示状态(0显示、1不显示) | 30 | + Show CommentShow `json:"showState"` // 评论的展示状态(1显示、2不显示) |
31 | AtWho []UserSimple `json:"atWho"` // 填写评论时@的人 | 31 | AtWho []UserSimple `json:"atWho"` // 填写评论时@的人 |
32 | // ...more | 32 | // ...more |
33 | } | 33 | } |
34 | 34 | ||
35 | -// 评论的展示状态(0显示、1不显示) | 35 | +// 评论的展示状态(1显示、2不显示) |
36 | type CommentShow int | 36 | type CommentShow int |
37 | 37 | ||
38 | const ( | 38 | const ( |
39 | - CommentShowEnable CommentShow = 0 | ||
40 | - CommentShowDisable CommentShow = 1 | 39 | + CommentShowEnable CommentShow = 1 |
40 | + CommentShowDisable CommentShow = 2 | ||
41 | ) | 41 | ) |
42 | 42 | ||
43 | func (show CommentShow) Named() string { | 43 | func (show CommentShow) Named() string { |
pkg/tool/oss/ali_oss.go
0 → 100644
1 | +package oss | ||
2 | + | ||
3 | +import ( | ||
4 | + "encoding/json" | ||
5 | + "fmt" | ||
6 | + "image" | ||
7 | + _ "image/jpeg" | ||
8 | + "net/http" | ||
9 | + "strings" | ||
10 | + "time" | ||
11 | +) | ||
12 | + | ||
13 | +type FileInfo struct { | ||
14 | + FileSize struct { | ||
15 | + Value string | ||
16 | + } | ||
17 | + Format struct { | ||
18 | + Value string | ||
19 | + } | ||
20 | + ImageHeight struct { | ||
21 | + Value string | ||
22 | + } | ||
23 | + ImageWidth struct { | ||
24 | + Value string | ||
25 | + } | ||
26 | +} | ||
27 | + | ||
28 | +func GetImageInfo(url string) (info FileInfo, err error) { | ||
29 | + //ok := strings.HasPrefix(url, "https://timeless-world.oss-cn-shenzhen.aliyuncs.com") | ||
30 | + ok := strings.HasPrefix(url, "http") | ||
31 | + if !ok { | ||
32 | + return | ||
33 | + } | ||
34 | + ok = strings.Contains(url, "aliyuncs") | ||
35 | + if !ok { | ||
36 | + return | ||
37 | + } | ||
38 | + apiUrl := url + `?x-oss-process=image/info` | ||
39 | + req, err := http.NewRequest(http.MethodGet, apiUrl, nil) | ||
40 | + if err != nil { | ||
41 | + return info, err | ||
42 | + } | ||
43 | + httpclient := http.Client{ | ||
44 | + Timeout: 30 * time.Second, | ||
45 | + } | ||
46 | + resp, err := httpclient.Do(req) | ||
47 | + if err != nil { | ||
48 | + return info, err | ||
49 | + } | ||
50 | + defer resp.Body.Close() | ||
51 | + if resp.StatusCode != http.StatusOK { | ||
52 | + return | ||
53 | + } | ||
54 | + jDecoder := json.NewDecoder(resp.Body) | ||
55 | + err = jDecoder.Decode(&info) | ||
56 | + if err != nil { | ||
57 | + return info, err | ||
58 | + } | ||
59 | + return info, nil | ||
60 | +} | ||
61 | + | ||
62 | +// 获取视频封面图 | ||
63 | +func GetVideoCover(videoUrl string) (coverUrl string, w int, h int, err error) { | ||
64 | + ok := strings.HasPrefix(videoUrl, "http") | ||
65 | + if !ok { | ||
66 | + return | ||
67 | + } | ||
68 | + ok = strings.Contains(videoUrl, "aliyuncs") | ||
69 | + if !ok { | ||
70 | + return | ||
71 | + } | ||
72 | + videoUrl = videoUrl + "?x-oss-process=video/snapshot,t_100,f_jpg,m_fast" | ||
73 | + res, err := http.Get(videoUrl) | ||
74 | + if err != nil || res.StatusCode != http.StatusOK { | ||
75 | + return videoUrl, 600, 600, fmt.Errorf("获取图片失败:%s", err) | ||
76 | + } | ||
77 | + defer res.Body.Close() | ||
78 | + m, _, err := image.Decode(res.Body) | ||
79 | + if err != nil { | ||
80 | + return videoUrl, 600, 600, fmt.Errorf("获取图片失败:%s", err) | ||
81 | + } | ||
82 | + return videoUrl, m.Bounds().Dx(), m.Bounds().Dy(), nil | ||
83 | +} |
pkg/tool/oss/ali_oss_test.go
0 → 100644
1 | +package oss | ||
2 | + | ||
3 | +import "testing" | ||
4 | + | ||
5 | +func TestGetVideoCover(t *testing.T) { | ||
6 | + | ||
7 | + cover, w, h, err := GetVideoCover("https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20230913/object/1694587897_yYfG6TYTsGMCKETxdnTEhAQjXpYGD3MB.mp4") | ||
8 | + t.Logf("cover=%v, w=%v, h=%v, err=%v", cover, w, h, err) | ||
9 | +} |
-
请 注册 或 登录 后发表评论