作者 tangxvhui

合并提交

@@ -2,4 +2,5 @@ import "core/comment.api" @@ -2,4 +2,5 @@ import "core/comment.api"
2 import "core/message.api" 2 import "core/message.api"
3 import "core/article_tag.api" 3 import "core/article_tag.api"
4 import "core/user.api" 4 import "core/user.api"
5 -import "core/company.api"  
  5 +import "core/company.api"
  6 +import "core/article.api"
@@ -10,9 +10,9 @@ info( @@ -10,9 +10,9 @@ info(
10 10
11 // 坐标地点描述 11 // 坐标地点描述
12 type Location { 12 type Location {
13 - Longitude float64 `json:"longitude"` //经度  
14 - Latitude float64 `json:"latitude"` //纬度  
15 - Descript string `json:"descript"` //地点描述 13 + Longitude float64 `json:"longitude,optional"` //经度
  14 + Latitude float64 `json:"latitude,optional"` //纬度
  15 + Descript string `json:"descript,optional"` //地点描述
16 } 16 }
17 17
18 // 人员的简单展示信息 18 // 人员的简单展示信息
@@ -24,36 +24,36 @@ type Author { @@ -24,36 +24,36 @@ type Author {
24 Position string `json:"position"` // 职位 24 Position string `json:"position"` // 职位
25 } 25 }
26 26
27 -// 创建发布文章 27 +//小程序端创建发布文章
28 type ( 28 type (
29 - ArticleCreateRequest {  
30 - Title string `json:"title"` //标题  
31 - Section []string `json:"section"` //文章的文本内容  
32 - AuthorId int `json:"authorId"` //发布人id  
33 - Images []string `json:"images"` //图片  
34 - WhoRead []int `json:"whoRead"` //谁可查看  
35 - WhoReview []int `json:"whoReview"` //谁可评论  
36 - Location Location `json:"location"` //定位坐标 29 + MiniArticleCreateRequest {
  30 + Title string `json:"title"` //标题
  31 + Section []string `json:"section"` //文章的文本内容
  32 + AuthorId int64 `json:"authorId,optional"` //发布人id
  33 + Images []string `json:"images,optional"` //图片
  34 + WhoRead []int64 `json:"whoRead,optional"` //谁可查看
  35 + WhoReview []int64 `json:"whoReview,optional"` //谁可评论
  36 + Location Location `json:"location,optional"` //定位坐标
37 } 37 }
38 - ArticleCreateResponse { 38 + MiniArticleCreateResponse {
39 Id int64 `json:"id"` 39 Id int64 `json:"id"`
40 } 40 }
41 ) 41 )
42 42
43 -// 查看文章的详情 43 +//小程序端查看文章的详情
44 type ( 44 type (
45 - ArticleGetRequest {  
46 - Id int64 `json:"id"` //id 45 + MiniArticleGetRequest {
  46 + Id int64 `path:"id"` //id
47 } 47 }
48 - ArticleGetResponse { 48 + MiniArticleGetResponse {
49 Title string `json:"title"` //标题 49 Title string `json:"title"` //标题
50 AuthorId int `json:"authorId"` //发布人id 50 AuthorId int `json:"authorId"` //发布人id
51 Author Author `json:"author"` //发布人 51 Author Author `json:"author"` //发布人
52 CreatedAt int64 `json:"createdAt"` //文章的发布时间 52 CreatedAt int64 `json:"createdAt"` //文章的发布时间
53 Section []string `json:"section"` //文章的文本内容 53 Section []string `json:"section"` //文章的文本内容
54 Images []string `json:"images"` //图片 54 Images []string `json:"images"` //图片
55 - WhoRead []int `json:"whoRead"` //谁可查看  
56 - WhoReview []int `json:"whoReview"` //谁可评论 55 + WhoRead []int64 `json:"whoRead"` //谁可查看
  56 + WhoReview []int64 `json:"whoReview"` //谁可评论
57 Location Location `json:"location"` //定位坐标 57 Location Location `json:"location"` //定位坐标
58 CountLove int `json:"countLove"` // 点赞数量 58 CountLove int `json:"countLove"` // 点赞数量
59 CountComment int `json:"countComment"` // 评论数量 59 CountComment int `json:"countComment"` // 评论数量
@@ -61,6 +61,31 @@ type ( @@ -61,6 +61,31 @@ type (
61 } 61 }
62 ) 62 )
63 63
  64 +// 获取我的发文章记录
  65 +type (
  66 + MiniArticleSearchMeRequest {
  67 + AuthorId int64 `json:"-"`
  68 + CompanyId int64 `json:"-"`
  69 + Page int `json:"page"`
  70 + Size int `json:"size"`
  71 + }
  72 +
  73 + MiniArticleSearchMeResponse {
  74 + Total int `json:"total"`
  75 + List []ArticleSearchMe `json:"list"`
  76 + }
  77 +
  78 + ArticleSearchMe {
  79 + Id int64 `json:"id"` //id
  80 + Title string `json:"title"` //标题
  81 + Images []string `json:"images"` //图片
  82 + CreatedAt int64 `json:"createdAt"` //文章的创建日期
  83 + CountLove int `json:"countLove"` //点赞数量
  84 + CountComment int `json:"CountComment"` //评论数量
  85 + Show int `json:"show"` //是否隐藏 [0显示、1不显示]
  86 + }
  87 +)
  88 +
64 // 小程序接口 89 // 小程序接口
65 @server( 90 @server(
66 prefix: v1/mini 91 prefix: v1/mini
@@ -69,9 +94,12 @@ type ( @@ -69,9 +94,12 @@ type (
69 ) 94 )
70 service Core { 95 service Core {
71 @doc "小程序创建发布内容" 96 @doc "小程序创建发布内容"
72 - @handler CreateArticle  
73 - post /article (ArticleCreateRequest) returns (ArticleCreateResponse) 97 + @handler MiniCreateArticle
  98 + post /article (MiniArticleCreateRequest) returns (MiniArticleCreateResponse)
  99 + @doc "小程序获取我发布的文章"
  100 + @handler MiniArticleSearchMe
  101 + post /article/search/me (MiniArticleSearchMeRequest) returns (MiniArticleSearchMeResponse)
74 @doc "小程序获取文章内容详情" 102 @doc "小程序获取文章内容详情"
75 - @handler GetArticle  
76 - get /article/:id (ArticleGetRequest) returns (ArticleGetResponse) 103 + @handler MiniGetArticle
  104 + get /article/:id (MiniArticleGetRequest) returns (MiniArticleGetResponse)
77 } 105 }
@@ -13,9 +13,9 @@ type ( @@ -13,9 +13,9 @@ type (
13 TagCreateRequest { 13 TagCreateRequest {
14 CompanyId int64 `json:"companyId"` 14 CompanyId int64 `json:"companyId"`
15 Image string `json:"image"` 15 Image string `json:"image"`
16 - Name string `json:"name"` // 标签名称  
17 - Group string `json:"group"` // 标签分类  
18 - Remark string `json:"remark"` // 备注 16 + Name string `json:"name"` // 标签名称
  17 + Group string `json:"group"` // 标签分类
  18 + Remark string `json:"remark,optional"` // 备注
19 } 19 }
20 20
21 TagCreateResponse { 21 TagCreateResponse {
@@ -27,11 +27,11 @@ type ( @@ -27,11 +27,11 @@ type (
27 type ( 27 type (
28 TagEditRequest { 28 TagEditRequest {
29 Id int64 `json:"id"` 29 Id int64 `json:"id"`
30 - CompanyId int64 `json:"companyId"` 30 + CompanyId int64 `json:"-"`
31 Image string `json:"image"` 31 Image string `json:"image"`
32 - Name string `json:"name"` // 标签名称  
33 - Group string `json:"group"` // 标签分类  
34 - Remark string `json:"remark"` // 备注 32 + Name string `json:"name"` // 标签名称
  33 + Group string `json:"group"` // 标签分类
  34 + Remark string `json:"remark,optional"` // 备注
35 } 35 }
36 36
37 TagEditResponse { 37 TagEditResponse {
@@ -42,7 +42,8 @@ type ( @@ -42,7 +42,8 @@ type (
42 // 获取标签详情 42 // 获取标签详情
43 type ( 43 type (
44 TagGetRequest { 44 TagGetRequest {
45 - Id int64 `json:"id"` 45 + Id int64 `path:"id"`
  46 + CompanyId int64 `path:"-"`
46 } 47 }
47 TagGetResponse { 48 TagGetResponse {
48 Id int64 `json:"id"` 49 Id int64 `json:"id"`
@@ -56,11 +57,15 @@ type ( @@ -56,11 +57,15 @@ type (
56 //标签列表 57 //标签列表
57 type ( 58 type (
58 TagListRequest { 59 TagListRequest {
59 - Page int `json:"page"`  
60 - Size int `json:"size"` 60 + Page int `json:"page"`
  61 + Size int `json:"size"`
  62 + CompanyId int64 `json:"-"`
  63 + TagName string `json:"tagName,optional"`
  64 + Group string `json:"group,optional"`
  65 + Remark string `json:"remark,optional"`
61 } 66 }
62 TagListResponse { 67 TagListResponse {
63 - Total int `json:"total"` 68 + Total int64 `json:"total"`
64 List []TagItem `json:"list"` 69 List []TagItem `json:"list"`
65 } 70 }
66 TagItem { 71 TagItem {
@@ -76,7 +81,8 @@ type ( @@ -76,7 +81,8 @@ type (
76 //删除标签 81 //删除标签
77 type ( 82 type (
78 TagDeleteRequest { 83 TagDeleteRequest {
79 - Id int64 `json:"id"` 84 + Id int64 `path:"id"`
  85 + CompanyId int64 `path:"-"`
80 } 86 }
81 TagDeleteResponse { 87 TagDeleteResponse {
82 Id int64 `json:"id"` 88 Id int64 `json:"id"`
@@ -84,7 +90,7 @@ type ( @@ -84,7 +90,7 @@ type (
84 ) 90 )
85 91
86 @server( 92 @server(
87 - prefix: v1/mini 93 + prefix: v1/system
88 group: tags 94 group: tags
89 jwt: MiniAuth 95 jwt: MiniAuth
90 ) 96 )
@@ -92,13 +98,20 @@ service Core { @@ -92,13 +98,20 @@ service Core {
92 @doc "后台创建文章标签" 98 @doc "后台创建文章标签"
93 @handler CreateTag 99 @handler CreateTag
94 post /article_tag (TagCreateRequest) returns (TagCreateResponse) 100 post /article_tag (TagCreateRequest) returns (TagCreateResponse)
  101 +
95 @doc "后台编辑文章标签" 102 @doc "后台编辑文章标签"
96 @handler EditTag 103 @handler EditTag
97 put /article_tag (TagEditRequest) returns (TagEditResponse) 104 put /article_tag (TagEditRequest) returns (TagEditResponse)
  105 +
98 @doc "后台获取文章标签" 106 @doc "后台获取文章标签"
99 @handler GetTag 107 @handler GetTag
100 get /article_tag/:id (TagGetRequest) returns (TagGetResponse) 108 get /article_tag/:id (TagGetRequest) returns (TagGetResponse)
  109 +
101 @doc "后台删除文章标签" 110 @doc "后台删除文章标签"
102 @handler DeleteTag 111 @handler DeleteTag
103 - delete /article_tag (TagDeleteRequest) returns (TagDeleteResponse) 112 + delete /article_tag/:id (TagDeleteRequest) returns (TagDeleteResponse)
  113 +
  114 + @doc "后台搜索标签"
  115 + @handler SearchTag
  116 + post/article_tag/search (TagListRequest) returns (TagListResponse)
104 } 117 }
  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 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
  11 +)
  12 +
  13 +func MiniArticleSearchMeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
  14 + return func(w http.ResponseWriter, r *http.Request) {
  15 + var req types.MiniArticleSearchMeRequest
  16 + if err := httpx.Parse(r, &req); err != nil {
  17 + httpx.ErrorCtx(r.Context(), w, err)
  18 + return
  19 + }
  20 +
  21 + l := article.NewMiniArticleSearchMeLogic(r.Context(), svcCtx)
  22 + token := contextdata.GetUserTokenFromCtx(r.Context())
  23 + req.AuthorId = token.UserId
  24 + req.CompanyId = token.CompanyId
  25 + resp, err := l.MiniArticleSearchMe(&req)
  26 + if err != nil {
  27 + httpx.ErrorCtx(r.Context(), w, err)
  28 + } else {
  29 + httpx.OkJsonCtx(r.Context(), w, resp)
  30 + }
  31 + }
  32 +}
  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 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
  11 +)
  12 +
  13 +func MiniCreateArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
  14 + return func(w http.ResponseWriter, r *http.Request) {
  15 + var req types.MiniArticleCreateRequest
  16 + if err := httpx.Parse(r, &req); err != nil {
  17 + httpx.ErrorCtx(r.Context(), w, err)
  18 + return
  19 + }
  20 + token := contextdata.GetUserTokenFromCtx(r.Context())
  21 +
  22 + l := article.NewMiniCreateArticleLogic(r.Context(), svcCtx)
  23 + req.AuthorId = token.UserId
  24 + resp, err := l.MiniCreateArticle(&req)
  25 + if err != nil {
  26 + httpx.ErrorCtx(r.Context(), w, err)
  27 + } else {
  28 + httpx.OkJsonCtx(r.Context(), w, resp)
  29 + }
  30 + }
  31 +}
  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 MiniGetArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
  13 + return func(w http.ResponseWriter, r *http.Request) {
  14 + var req types.MiniArticleGetRequest
  15 + if err := httpx.Parse(r, &req); err != nil {
  16 + httpx.ErrorCtx(r.Context(), w, err)
  17 + return
  18 + }
  19 +
  20 + l := article.NewMiniGetArticleLogic(r.Context(), svcCtx)
  21 +
  22 + resp, err := l.MiniGetArticle(&req)
  23 + if err != nil {
  24 + httpx.ErrorCtx(r.Context(), w, err)
  25 + } else {
  26 + httpx.OkJsonCtx(r.Context(), w, resp)
  27 + }
  28 + }
  29 +}
@@ -4,6 +4,7 @@ package handler @@ -4,6 +4,7 @@ package handler
4 import ( 4 import (
5 "net/http" 5 "net/http"
6 6
  7 + article "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/handler/article"
7 comment "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/handler/comment" 8 comment "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/handler/comment"
8 company "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/handler/company" 9 company "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/handler/company"
9 message "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/handler/message" 10 message "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/handler/message"
@@ -75,12 +76,17 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { @@ -75,12 +76,17 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
75 }, 76 },
76 { 77 {
77 Method: http.MethodDelete, 78 Method: http.MethodDelete,
78 - Path: "/article_tag", 79 + Path: "/article_tag/:id",
79 Handler: tags.DeleteTagHandler(serverCtx), 80 Handler: tags.DeleteTagHandler(serverCtx),
80 }, 81 },
  82 + {
  83 + Method: http.MethodPost,
  84 + Path: "/article_tag/search",
  85 + Handler: tags.SearchTagHandler(serverCtx),
  86 + },
81 }, 87 },
82 rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret), 88 rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret),
83 - rest.WithPrefix("/v1/mini"), 89 + rest.WithPrefix("/v1/system"),
84 ) 90 )
85 91
86 server.AddRoutes( 92 server.AddRoutes(
@@ -168,4 +174,26 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { @@ -168,4 +174,26 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
168 rest.WithJwt(serverCtx.Config.SystemAuth.AccessSecret), 174 rest.WithJwt(serverCtx.Config.SystemAuth.AccessSecret),
169 rest.WithPrefix("/v1"), 175 rest.WithPrefix("/v1"),
170 ) 176 )
  177 +
  178 + server.AddRoutes(
  179 + []rest.Route{
  180 + {
  181 + Method: http.MethodPost,
  182 + Path: "/article",
  183 + Handler: article.MiniCreateArticleHandler(serverCtx),
  184 + },
  185 + {
  186 + Method: http.MethodPost,
  187 + Path: "/article/search/me",
  188 + Handler: article.MiniArticleSearchMeHandler(serverCtx),
  189 + },
  190 + {
  191 + Method: http.MethodGet,
  192 + Path: "/article/:id",
  193 + Handler: article.MiniGetArticleHandler(serverCtx),
  194 + },
  195 + },
  196 + rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret),
  197 + rest.WithPrefix("/v1/mini"),
  198 + )
171 } 199 }
  1 +package tags
  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/tags"
  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 SearchTagHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
  13 + return func(w http.ResponseWriter, r *http.Request) {
  14 + var req types.TagListRequest
  15 + if err := httpx.Parse(r, &req); err != nil {
  16 + httpx.ErrorCtx(r.Context(), w, err)
  17 + return
  18 + }
  19 +
  20 + l := tags.NewSearchTagLogic(r.Context(), svcCtx)
  21 + resp, err := l.SearchTag(&req)
  22 + if err != nil {
  23 + httpx.ErrorCtx(r.Context(), w, err)
  24 + } else {
  25 + httpx.OkJsonCtx(r.Context(), w, resp)
  26 + }
  27 + }
  28 +}
  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 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
  9 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
  10 +
  11 + "github.com/zeromicro/go-zero/core/logx"
  12 +)
  13 +
  14 +type MiniArticleSearchMeLogic struct {
  15 + logx.Logger
  16 + ctx context.Context
  17 + svcCtx *svc.ServiceContext
  18 +}
  19 +
  20 +func NewMiniArticleSearchMeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniArticleSearchMeLogic {
  21 + return &MiniArticleSearchMeLogic{
  22 + Logger: logx.WithContext(ctx),
  23 + ctx: ctx,
  24 + svcCtx: svcCtx,
  25 + }
  26 +}
  27 +
  28 +// MiniArticleSearchMe 获取我发布的文章
  29 +func (l *MiniArticleSearchMeLogic) MiniArticleSearchMe(req *types.MiniArticleSearchMeRequest) (resp *types.MiniArticleSearchMeResponse, err error) {
  30 + var conn = l.svcCtx.DefaultDBConn()
  31 + queryOptions := domain.NewQueryOptions().
  32 + WithOffsetLimit(req.Page, req.Size).
  33 + MustWithKV("authorId", req.AuthorId)
  34 +
  35 + cnt, articleList, err := l.svcCtx.ArticleRepository.Find(l.ctx, conn, req.CompanyId, queryOptions)
  36 + if err != nil {
  37 + return &types.MiniArticleSearchMeResponse{}, xerr.NewErrMsgErr("获取文章列表失败", err)
  38 + }
  39 +
  40 + resp = &types.MiniArticleSearchMeResponse{
  41 + Total: int(cnt),
  42 + List: make([]types.ArticleSearchMe, len(articleList)),
  43 + }
  44 + for i := range articleList {
  45 + images := []string{}
  46 + for _, val2 := range articleList[i].Images {
  47 + images = append(images, val2.Url)
  48 + }
  49 + resp.List[i] = types.ArticleSearchMe{
  50 + Id: articleList[i].Id,
  51 + Title: articleList[i].Title,
  52 + Images: images,
  53 + CreatedAt: articleList[i].CreatedAt,
  54 + CountLove: articleList[i].CountLove,
  55 + CountComment: articleList[i].CountComment,
  56 + Show: int(articleList[i].Show),
  57 + }
  58 + }
  59 + return
  60 +}
  1 +package article
  2 +
  3 +import (
  4 + "context"
  5 + "strings"
  6 +
  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/types"
  9 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
  10 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
  11 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
  12 +
  13 + "github.com/samber/lo"
  14 + "github.com/zeromicro/go-zero/core/logx"
  15 +)
  16 +
  17 +type MiniCreateArticleLogic struct {
  18 + logx.Logger
  19 + ctx context.Context
  20 + svcCtx *svc.ServiceContext
  21 +}
  22 +
  23 +func NewMiniCreateArticleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniCreateArticleLogic {
  24 + return &MiniCreateArticleLogic{
  25 + Logger: logx.WithContext(ctx),
  26 + ctx: ctx,
  27 + svcCtx: svcCtx,
  28 + }
  29 +}
  30 +
  31 +func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateRequest) (resp *types.MiniArticleCreateResponse, err error) {
  32 + var conn = l.svcCtx.DefaultDBConn()
  33 + // 检查发布人
  34 + author, err := l.svcCtx.UserRepository.FindOne(l.ctx, conn, req.AuthorId)
  35 + if err != nil {
  36 + return nil, xerr.NewErrMsgErr("创建文章内容失败", err)
  37 + }
  38 + //TODO 获取人员信息
  39 + articleAuthor := domain.UserSimple{
  40 + Id: author.Id,
  41 + Name: author.Name,
  42 + Avatar: author.Avatar,
  43 + GroupId: 0,
  44 + Group: "",
  45 + Position: author.Position,
  46 + Company: "",
  47 + CompanyId: author.CompanyId,
  48 + }
  49 +
  50 + //TODO 获取图片的尺寸大小
  51 + images := []domain.Image{}
  52 + for _, val := range req.Images {
  53 + images = append(images, domain.Image{
  54 + Url: val,
  55 + Width: 0,
  56 + Height: 0,
  57 + })
  58 + }
  59 + //检查文章可被哪些人查看
  60 + whoRead := []int64{}
  61 + if len(req.WhoRead) > 0 {
  62 + whoRead = lo.Uniq(req.WhoRead)
  63 + var u *domain.User
  64 + for _, val := range whoRead {
  65 + u, err = l.svcCtx.UserRepository.FindOne(l.ctx, conn, val)
  66 + if err != nil {
  67 + return nil, xerr.NewErrMsgErr("文章可查看人设置错误", err)
  68 + }
  69 + if u.CompanyId != author.CompanyId {
  70 + return nil, xerr.NewErrMsg("文章可查看人设置错误")
  71 + }
  72 + }
  73 + }
  74 + //检查文章可被哪些人评论
  75 + whoReview := []int64{}
  76 + //有指定可查看人的情况
  77 + if len(whoRead) > 0 {
  78 + if len(whoReview) > 0 {
  79 + whoReview = lo.Uniq(req.WhoReview)
  80 + // 检查 whoRead 是否 完全包含 whoReview
  81 + ok := lo.Every(whoRead, whoReview)
  82 + if !ok {
  83 + return nil, xerr.NewErrMsg("文章可评论人设置错误")
  84 + }
  85 + }
  86 + if len(whoReview) == 0 {
  87 + //有指定可查看人 ,但未指定可评论人
  88 + return nil, xerr.NewErrMsg("文章可评论人设置错误")
  89 + }
  90 + }
  91 + //没有指定可查看人的情况
  92 + if len(whoRead) == 0 {
  93 + if len(whoReview) > 0 {
  94 + // 未指定可查看人(全员可看),有指定可评论人,
  95 + var u *domain.User
  96 + for _, val := range whoReview {
  97 + u, err = l.svcCtx.UserRepository.FindOne(l.ctx, conn, val)
  98 + if err != nil {
  99 + return nil, xerr.NewErrMsgErr("文章可评论人设置错误", err)
  100 + }
  101 + if u.CompanyId != author.CompanyId {
  102 + return nil, xerr.NewErrMsg("文章可评论人设置错误")
  103 + }
  104 + }
  105 + }
  106 + // if len(whoReview) == 0 {
  107 + // 未指定可查看人(全员可看),未指定可评论人 ,忽略判断
  108 + // }
  109 + }
  110 +
  111 + //切分文章分段
  112 + sectionList := []domain.ArticleSection{}
  113 + for i := range req.Section {
  114 + strList := strings.Split(req.Section[i], "\n")
  115 + for i2 := range strList {
  116 + newStr := strings.TrimSpace(strList[i2])
  117 + if len(newStr) == 0 {
  118 + continue
  119 + }
  120 + newSection := domain.ArticleSection{
  121 + Id: 0,
  122 + CompanyId: author.CompanyId,
  123 + ArticleId: 0,
  124 + Content: newStr,
  125 + SortBy: len(sectionList),
  126 + TotalComment: 0,
  127 + }
  128 + sectionList = append(sectionList, newSection)
  129 + }
  130 + }
  131 +
  132 + newArticle := &domain.Article{
  133 + Id: 0,
  134 + CompanyId: author.CompanyId,
  135 + AuthorId: author.Id,
  136 + Author: articleAuthor,
  137 + Title: req.Title,
  138 + Images: images,
  139 + WhoRead: whoRead,
  140 + WhoReview: whoReview,
  141 + Location: domain.Location{
  142 + Longitude: req.Location.Latitude,
  143 + Latitude: req.Location.Latitude,
  144 + Descript: req.Location.Descript,
  145 + },
  146 + TargetUser: domain.ArticleTargetAll,
  147 + }
  148 + if len(whoRead) > 0 {
  149 + newArticle.TargetUser = domain.ArticleTargetLimit
  150 + }
  151 +
  152 + err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error {
  153 + newArticle, err = l.svcCtx.ArticleRepository.Insert(ctx, c, newArticle)
  154 + if err != nil {
  155 + return xerr.NewErrMsgErr("创建文章失败", err)
  156 + }
  157 +
  158 + for i := range sectionList {
  159 + sectionList[i].ArticleId = newArticle.Id
  160 + _, err = l.svcCtx.ArticleSectionRepository.Insert(ctx, c, &sectionList[i])
  161 + if err != nil {
  162 + return xerr.NewErrMsgErr("创建文章内容失败", err)
  163 + }
  164 + }
  165 + // 设置保存备份
  166 + backup := newArticle.MakeBackup(newArticle.Author, sectionList)
  167 + backup.Action = "新增"
  168 + _, err = l.svcCtx.ArticleBackupRepository.Insert(ctx, c, backup)
  169 + if err != nil {
  170 + return xerr.NewErrMsgErr("创建文章内容失败", err)
  171 + }
  172 + return nil
  173 + }, true)
  174 + if err != nil {
  175 + return nil, xerr.NewErrMsgErr("创建文章失败", err)
  176 + }
  177 +
  178 + resp = &types.MiniArticleCreateResponse{
  179 + Id: newArticle.Id,
  180 + }
  181 + return
  182 +}
  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 MiniGetArticleLogic struct {
  13 + logx.Logger
  14 + ctx context.Context
  15 + svcCtx *svc.ServiceContext
  16 +}
  17 +
  18 +func NewMiniGetArticleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniGetArticleLogic {
  19 + return &MiniGetArticleLogic{
  20 + Logger: logx.WithContext(ctx),
  21 + ctx: ctx,
  22 + svcCtx: svcCtx,
  23 + }
  24 +}
  25 +
  26 +func (l *MiniGetArticleLogic) MiniGetArticle(req *types.MiniArticleGetRequest) (resp *types.MiniArticleGetResponse, 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 6
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/svc"
8 "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"
  9 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
9 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr" 10 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
10 11
11 "github.com/zeromicro/go-zero/core/logx" 12 "github.com/zeromicro/go-zero/core/logx"
@@ -25,8 +26,8 @@ func NewCreateTagLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateT @@ -25,8 +26,8 @@ func NewCreateTagLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateT
25 } 26 }
26 } 27 }
27 28
  29 +// 创建标签
28 func (l *CreateTagLogic) CreateTag(req *types.TagCreateRequest) (resp *types.TagCreateResponse, err error) { 30 func (l *CreateTagLogic) CreateTag(req *types.TagCreateRequest) (resp *types.TagCreateResponse, err error) {
29 - // todo: add your logic here and delete this line  
30 var conn = l.svcCtx.DefaultDBConn() 31 var conn = l.svcCtx.DefaultDBConn()
31 //检查重复 32 //检查重复
32 cnt, _, err := l.svcCtx.ArticleTagRepository.Find(l.ctx, conn, req.CompanyId, map[string]interface{}{ 33 cnt, _, err := l.svcCtx.ArticleTagRepository.Find(l.ctx, conn, req.CompanyId, map[string]interface{}{
@@ -40,5 +41,29 @@ func (l *CreateTagLogic) CreateTag(req *types.TagCreateRequest) (resp *types.Tag @@ -40,5 +41,29 @@ func (l *CreateTagLogic) CreateTag(req *types.TagCreateRequest) (resp *types.Tag
40 if cnt > 0 { 41 if cnt > 0 {
41 return nil, xerr.NewErrMsg(fmt.Sprintf("已存在标签 分类[%s]名称[%s]", req.Group, req.Name)) 42 return nil, xerr.NewErrMsg(fmt.Sprintf("已存在标签 分类[%s]名称[%s]", req.Group, req.Name))
42 } 43 }
  44 + //TODO 获取图片的尺寸大小
  45 +
  46 + newTag := &domain.ArticleTag{
  47 + Id: 0,
  48 + CompanyId: req.CompanyId,
  49 + CreatedAt: 0,
  50 + UpdatedAt: 0,
  51 + DeletedAt: 0,
  52 + Version: 0,
  53 + Image: domain.Image{
  54 + Url: req.Image,
  55 + Width: 0,
  56 + Height: 0,
  57 + },
  58 + Name: req.Name,
  59 + Group: req.Group,
  60 + Remark: req.Remark,
  61 + }
  62 +
  63 + newTag, err = l.svcCtx.ArticleTagRepository.Insert(l.ctx, conn, newTag)
  64 + if err != nil {
  65 + return nil, xerr.NewErrMsgErr("添加标签失败", err)
  66 + }
  67 + resp = &types.TagCreateResponse{Id: newTag.Id}
43 return 68 return
44 } 69 }
@@ -5,6 +5,7 @@ import ( @@ -5,6 +5,7 @@ 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/pkg/xerr"
8 9
9 "github.com/zeromicro/go-zero/core/logx" 10 "github.com/zeromicro/go-zero/core/logx"
10 ) 11 )
@@ -24,7 +25,18 @@ func NewDeleteTagLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteT @@ -24,7 +25,18 @@ func NewDeleteTagLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteT
24 } 25 }
25 26
26 func (l *DeleteTagLogic) DeleteTag(req *types.TagDeleteRequest) (resp *types.TagDeleteResponse, err error) { 27 func (l *DeleteTagLogic) DeleteTag(req *types.TagDeleteRequest) (resp *types.TagDeleteResponse, err error) {
27 - // todo: add your logic here and delete this line  
28 - 28 + var conn = l.svcCtx.DefaultDBConn()
  29 + oldTag, err := l.svcCtx.ArticleTagRepository.FindOne(l.ctx, conn, req.Id)
  30 + if err != nil {
  31 + return nil, xerr.NewErrMsgErr("不存在待修改的标签", err)
  32 + }
  33 + if oldTag.CompanyId != req.CompanyId {
  34 + return nil, xerr.NewErrMsg("删除标签失败")
  35 + }
  36 + _, err = l.svcCtx.ArticleTagRepository.Delete(l.ctx, conn, oldTag)
  37 + if err != nil {
  38 + return nil, xerr.NewErrMsg("删除标签失败")
  39 + }
  40 + resp = &types.TagDeleteResponse{Id: oldTag.Id}
29 return 41 return
30 } 42 }
@@ -2,9 +2,12 @@ package tags @@ -2,9 +2,12 @@ package tags
2 2
3 import ( 3 import (
4 "context" 4 "context"
  5 + "fmt"
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"
  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 )
@@ -23,8 +26,44 @@ func NewEditTagLogic(ctx context.Context, svcCtx *svc.ServiceContext) *EditTagLo @@ -23,8 +26,44 @@ func NewEditTagLogic(ctx context.Context, svcCtx *svc.ServiceContext) *EditTagLo
23 } 26 }
24 } 27 }
25 28
  29 +// 编辑标签
26 func (l *EditTagLogic) EditTag(req *types.TagEditRequest) (resp *types.TagEditResponse, err error) { 30 func (l *EditTagLogic) EditTag(req *types.TagEditRequest) (resp *types.TagEditResponse, err error) {
27 - // todo: add your logic here and delete this line 31 + var conn = l.svcCtx.DefaultDBConn()
  32 + //检查重复
  33 + queryOptions := domain.NewQueryOptions().
  34 + WithFindOnly().
  35 + MustWithKV("name", req.Name).
  36 + MustWithKV("group", req.Group).
  37 + WithOffsetLimit(1, 1)
28 38
  39 + _, tagList, err := l.svcCtx.ArticleTagRepository.Find(l.ctx, conn, req.CompanyId, queryOptions)
  40 + if err != nil {
  41 + return nil, xerr.NewErrMsgErr("修改标签失败", err)
  42 + }
  43 + if len(tagList) > 0 {
  44 + if tagList[0].Id != req.Id {
  45 + return nil, xerr.NewErrMsg(fmt.Sprintf("已存在标签 分类[%s]名称[%s]", req.Group, req.Name))
  46 + }
  47 + }
  48 + oldTag, err := l.svcCtx.ArticleTagRepository.FindOne(l.ctx, conn, req.Id)
  49 + if err != nil {
  50 + return nil, xerr.NewErrMsgErr("不存在待修改的标签", err)
  51 + }
  52 + if oldTag.CompanyId != req.CompanyId {
  53 + return nil, xerr.NewErrMsg("修改标签失败")
  54 + }
  55 +
  56 + //TODO 获取图片的尺寸大小
  57 +
  58 + oldTag.Group = req.Group
  59 + oldTag.Image.Url = req.Image
  60 + oldTag.Name = req.Name
  61 + oldTag.Remark = req.Remark
  62 +
  63 + oldTag, err = l.svcCtx.ArticleTagRepository.Update(l.ctx, conn, oldTag)
  64 + if err != nil {
  65 + return nil, xerr.NewErrMsgErr("添加标签失败", err)
  66 + }
  67 + resp = &types.TagEditResponse{Id: oldTag.Id}
29 return 68 return
30 } 69 }
@@ -5,6 +5,7 @@ import ( @@ -5,6 +5,7 @@ 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/pkg/xerr"
8 9
9 "github.com/zeromicro/go-zero/core/logx" 10 "github.com/zeromicro/go-zero/core/logx"
10 ) 11 )
@@ -23,8 +24,22 @@ func NewGetTagLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetTagLogi @@ -23,8 +24,22 @@ func NewGetTagLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetTagLogi
23 } 24 }
24 } 25 }
25 26
  27 +// 获取详情
26 func (l *GetTagLogic) GetTag(req *types.TagGetRequest) (resp *types.TagGetResponse, err error) { 28 func (l *GetTagLogic) GetTag(req *types.TagGetRequest) (resp *types.TagGetResponse, err error) {
27 - // todo: add your logic here and delete this line  
28 - 29 + var conn = l.svcCtx.DefaultDBConn()
  30 + oldTag, err := l.svcCtx.ArticleTagRepository.FindOne(l.ctx, conn, req.Id)
  31 + if err != nil {
  32 + return nil, xerr.NewErrMsgErr("不存在的标签", err)
  33 + }
  34 + if oldTag.CompanyId != req.CompanyId {
  35 + return nil, xerr.NewErrMsg("获取标签失败")
  36 + }
  37 + resp = &types.TagGetResponse{
  38 + Id: oldTag.Id,
  39 + Image: oldTag.Image.Url,
  40 + Name: oldTag.Name,
  41 + Group: oldTag.Group,
  42 + Remark: oldTag.Remark,
  43 + }
29 return 44 return
30 } 45 }
  1 +package tags
  2 +
  3 +import (
  4 + "context"
  5 +
  6 + "github.com/zeromicro/go-zero/core/logx"
  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/types"
  9 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
  10 +)
  11 +
  12 +type SearchTagLogic struct {
  13 + logx.Logger
  14 + ctx context.Context
  15 + svcCtx *svc.ServiceContext
  16 +}
  17 +
  18 +func NewSearchTagLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SearchTagLogic {
  19 + return &SearchTagLogic{
  20 + Logger: logx.WithContext(ctx),
  21 + ctx: ctx,
  22 + svcCtx: svcCtx,
  23 + }
  24 +}
  25 +
  26 +func (l *SearchTagLogic) SearchTag(req *types.TagListRequest) (resp *types.TagListResponse, err error) {
  27 + var conn = l.svcCtx.DefaultDBConn()
  28 + queryOptions := domain.NewQueryOptions().WithOffsetLimit(req.Page, req.Size)
  29 +
  30 + if len(req.Group) > 0 {
  31 + queryOptions = queryOptions.MustWithKV("group", req.Group)
  32 + }
  33 + if len(req.TagName) > 0 {
  34 + queryOptions = queryOptions.MustWithKV("name", req.TagName)
  35 + }
  36 +
  37 + if len(req.Remark) > 0 {
  38 + queryOptions = queryOptions.MustWithKV("remark", "%"+req.Remark+"%")
  39 + }
  40 + cnt, tagList, err := l.svcCtx.ArticleTagRepository.Find(l.ctx, conn, req.CompanyId, queryOptions)
  41 + if err != nil {
  42 + return &types.TagListResponse{}, nil
  43 + }
  44 + resp = &types.TagListResponse{
  45 + Total: cnt,
  46 + List: make([]types.TagItem, len(tagList)),
  47 + }
  48 + for i := range tagList {
  49 + resp.List[i] = types.TagItem{
  50 + Id: tagList[i].Id,
  51 + Image: tagList[i].Image.Url,
  52 + Name: tagList[i].Name,
  53 + Group: tagList[i].Group,
  54 + Remark: tagList[i].Remark,
  55 + CreatedAt: tagList[i].CreatedAt,
  56 + }
  57 + }
  58 + return
  59 +}
@@ -77,9 +77,9 @@ type SimpleArticle struct { @@ -77,9 +77,9 @@ type SimpleArticle struct {
77 type TagCreateRequest struct { 77 type TagCreateRequest struct {
78 CompanyId int64 `json:"companyId"` 78 CompanyId int64 `json:"companyId"`
79 Image string `json:"image"` 79 Image string `json:"image"`
80 - Name string `json:"name"` // 标签名称  
81 - Group string `json:"group"` // 标签分类  
82 - Remark string `json:"remark"` // 备注 80 + Name string `json:"name"` // 标签名称
  81 + Group string `json:"group"` // 标签分类
  82 + Remark string `json:"remark,optional"` // 备注
83 } 83 }
84 84
85 type TagCreateResponse struct { 85 type TagCreateResponse struct {
@@ -88,11 +88,11 @@ type TagCreateResponse struct { @@ -88,11 +88,11 @@ type TagCreateResponse struct {
88 88
89 type TagEditRequest struct { 89 type TagEditRequest struct {
90 Id int64 `json:"id"` 90 Id int64 `json:"id"`
91 - CompanyId int64 `json:"companyId"` 91 + CompanyId int64 `json:"-"`
92 Image string `json:"image"` 92 Image string `json:"image"`
93 - Name string `json:"name"` // 标签名称  
94 - Group string `json:"group"` // 标签分类  
95 - Remark string `json:"remark"` // 备注 93 + Name string `json:"name"` // 标签名称
  94 + Group string `json:"group"` // 标签分类
  95 + Remark string `json:"remark,optional"` // 备注
96 } 96 }
97 97
98 type TagEditResponse struct { 98 type TagEditResponse struct {
@@ -100,7 +100,8 @@ type TagEditResponse struct { @@ -100,7 +100,8 @@ type TagEditResponse struct {
100 } 100 }
101 101
102 type TagGetRequest struct { 102 type TagGetRequest struct {
103 - Id int64 `json:"id"` 103 + Id int64 `path:"id"`
  104 + CompanyId int64 `path:"-"`
104 } 105 }
105 106
106 type TagGetResponse struct { 107 type TagGetResponse struct {
@@ -112,12 +113,16 @@ type TagGetResponse struct { @@ -112,12 +113,16 @@ type TagGetResponse struct {
112 } 113 }
113 114
114 type TagListRequest struct { 115 type TagListRequest struct {
115 - Page int `json:"page"`  
116 - Size int `json:"size"` 116 + Page int `json:"page"`
  117 + Size int `json:"size"`
  118 + CompanyId int64 `json:"-"`
  119 + TagName string `json:"tagName,optional"`
  120 + Group string `json:"group,optional"`
  121 + Remark string `json:"remark,optional"`
117 } 122 }
118 123
119 type TagListResponse struct { 124 type TagListResponse struct {
120 - Total int `json:"total"` 125 + Total int64 `json:"total"`
121 List []TagItem `json:"list"` 126 List []TagItem `json:"list"`
122 } 127 }
123 128
@@ -131,7 +136,8 @@ type TagItem struct { @@ -131,7 +136,8 @@ type TagItem struct {
131 } 136 }
132 137
133 type TagDeleteRequest struct { 138 type TagDeleteRequest struct {
134 - Id int64 `json:"id"` 139 + Id int64 `path:"id"`
  140 + CompanyId int64 `path:"-"`
135 } 141 }
136 142
137 type TagDeleteResponse struct { 143 type TagDeleteResponse struct {
@@ -243,3 +249,72 @@ type Company struct { @@ -243,3 +249,72 @@ type Company struct {
243 Code string `json:"code,omitempty"` // 编码(搜索使用,4位字母数字) 249 Code string `json:"code,omitempty"` // 编码(搜索使用,4位字母数字)
244 Logo string `json:"logo,omitempty"` // 公司LOGO 250 Logo string `json:"logo,omitempty"` // 公司LOGO
245 } 251 }
  252 +
  253 +type Location struct {
  254 + Longitude float64 `json:"longitude,optional"` //经度
  255 + Latitude float64 `json:"latitude,optional"` //纬度
  256 + Descript string `json:"descript,optional"` //地点描述
  257 +}
  258 +
  259 +type Author struct {
  260 + Id int64 `json:"id"` // 人员id
  261 + Name string `json:"name"` // 人员的名字
  262 + Avatar string `json:"avatar"` // 人员头像URL
  263 + Group string `json:"group"` // 人员的分组
  264 + Position string `json:"position"` // 职位
  265 +}
  266 +
  267 +type MiniArticleCreateRequest struct {
  268 + Title string `json:"title"` //标题
  269 + Section []string `json:"section"` //文章的文本内容
  270 + AuthorId int64 `json:"authorId,optional"` //发布人id
  271 + Images []string `json:"images,optional"` //图片
  272 + WhoRead []int64 `json:"whoRead,optional"` //谁可查看
  273 + WhoReview []int64 `json:"whoReview,optional"` //谁可评论
  274 + Location Location `json:"location,optional"` //定位坐标
  275 +}
  276 +
  277 +type MiniArticleCreateResponse struct {
  278 + Id int64 `json:"id"`
  279 +}
  280 +
  281 +type MiniArticleGetRequest struct {
  282 + Id int64 `path:"id"` //id
  283 +}
  284 +
  285 +type MiniArticleGetResponse struct {
  286 + Title string `json:"title"` //标题
  287 + AuthorId int `json:"authorId"` //发布人id
  288 + Author Author `json:"author"` //发布人
  289 + CreatedAt int64 `json:"createdAt"` //文章的发布时间
  290 + Section []string `json:"section"` //文章的文本内容
  291 + Images []string `json:"images"` //图片
  292 + WhoRead []int64 `json:"whoRead"` //谁可查看
  293 + WhoReview []int64 `json:"whoReview"` //谁可评论
  294 + Location Location `json:"location"` //定位坐标
  295 + CountLove int `json:"countLove"` // 点赞数量
  296 + CountComment int `json:"countComment"` // 评论数量
  297 + Show int `json:"showState"` // 评论的展示状态(0显示、1不显示)
  298 +}
  299 +
  300 +type MiniArticleSearchMeRequest struct {
  301 + AuthorId int64 `json:"-"`
  302 + CompanyId int64 `json:"-"`
  303 + Page int `json:"page"`
  304 + Size int `json:"size"`
  305 +}
  306 +
  307 +type MiniArticleSearchMeResponse struct {
  308 + Total int `json:"total"`
  309 + List []ArticleSearchMe `json:"list"`
  310 +}
  311 +
  312 +type ArticleSearchMe struct {
  313 + Id int64 `json:"id"` //id
  314 + Title string `json:"title"` //标题
  315 + Images []string `json:"images"` //图片
  316 + CreatedAt int64 `json:"createdAt"` //文章的创建日期
  317 + CountLove int `json:"countLove"` //点赞数量
  318 + CountComment int `json:"CountComment"` //评论数量
  319 + Show int `json:"show"` //是否隐藏 [0显示、1不显示]
  320 +}
@@ -26,7 +26,9 @@ type Article struct { @@ -26,7 +26,9 @@ type Article struct {
26 Location domain.Location `gorm:"type:jsonb;serializer:json"` // 坐标 26 Location domain.Location `gorm:"type:jsonb;serializer:json"` // 坐标
27 TargetUser int // 分发方式 0 分发给所有人 1 分发给指定的人 27 TargetUser int // 分发方式 0 分发给所有人 1 分发给指定的人
28 CountLove int // 点赞数量 28 CountLove int // 点赞数量
  29 + CountRead int // 浏览数量
29 CountComment int // 评论数量 30 CountComment int // 评论数量
  31 + Tags []int64 `gorm:"type:jsonb;serializer:json"` //定性标签
30 Show int // 评论的展示状态(0显示、1不显示) 32 Show int // 评论的展示状态(0显示、1不显示)
31 } 33 }
32 34
@@ -35,8 +37,9 @@ func (m *Article) TableName() string { @@ -35,8 +37,9 @@ func (m *Article) TableName() string {
35 } 37 }
36 38
37 func (m *Article) BeforeCreate(tx *gorm.DB) (err error) { 39 func (m *Article) BeforeCreate(tx *gorm.DB) (err error) {
38 - m.CreatedAt = time.Now().Unix()  
39 - m.UpdatedAt = time.Now().Unix() 40 + nowTime := time.Now().Unix()
  41 + m.CreatedAt = nowTime
  42 + m.UpdatedAt = nowTime
40 return 43 return
41 } 44 }
42 45
@@ -24,7 +24,7 @@ type ArticleBackup struct { @@ -24,7 +24,7 @@ type ArticleBackup struct {
24 Action string // 操作 24 Action string // 操作
25 WhoRead []int64 `gorm:"type:jsonb;serializer:json"` // 谁可以看 25 WhoRead []int64 `gorm:"type:jsonb;serializer:json"` // 谁可以看
26 WhoReview []int64 `gorm:"type:jsonb;serializer:json"` // 评论人 26 WhoReview []int64 `gorm:"type:jsonb;serializer:json"` // 评论人
27 - Tags []int `gorm:"type:jsonb;serializer:json"` // 标签 27 + Tags []int64 `gorm:"type:jsonb;serializer:json"` // 标签
28 TargetUser int // 分发方式 0 分发给所有人 1 分发给指定的人 28 TargetUser int // 分发方式 0 分发给所有人 1 分发给指定的人
29 } 29 }
30 30
@@ -111,7 +111,7 @@ func (repository *ArticleRepository) FindOne(ctx context.Context, conn transacti @@ -111,7 +111,7 @@ func (repository *ArticleRepository) FindOne(ctx context.Context, conn transacti
111 return repository.ModelToDomainModel(m) 111 return repository.ModelToDomainModel(m)
112 } 112 }
113 113
114 -func (repository *ArticleRepository) Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*domain.Article, error) { 114 +func (repository *ArticleRepository) Find(ctx context.Context, conn transaction.Conn, companyId int64, queryOptions map[string]interface{}) (int64, []*domain.Article, error) {
115 var ( 115 var (
116 tx = conn.DB() 116 tx = conn.DB()
117 ms []*models.Article 117 ms []*models.Article
@@ -119,10 +119,15 @@ func (repository *ArticleRepository) Find(ctx context.Context, conn transaction. @@ -119,10 +119,15 @@ func (repository *ArticleRepository) Find(ctx context.Context, conn transaction.
119 total int64 119 total int64
120 ) 120 )
121 queryFunc := func() (interface{}, error) { 121 queryFunc := func() (interface{}, error) {
122 - tx = tx.Model(&ms).Order("id desc") 122 + tx = tx.Model(&ms).Order("id desc").Where("company_id=?", companyId)
123 if v, ok := queryOptions["ids"]; ok { 123 if v, ok := queryOptions["ids"]; ok {
124 tx.Where("id in (?)", v) 124 tx.Where("id in (?)", v)
125 } 125 }
  126 +
  127 + if v, ok := queryOptions["authorId"]; ok {
  128 + tx = tx.Where("author_id = ?", v)
  129 + }
  130 +
126 if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil { 131 if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
127 return dms, tx.Error 132 return dms, tx.Error
128 } 133 }
@@ -161,6 +166,7 @@ func (repository *ArticleRepository) ModelToDomainModel(from *models.Article) (* @@ -161,6 +166,7 @@ func (repository *ArticleRepository) ModelToDomainModel(from *models.Article) (*
161 TargetUser: domain.ArticleTarget(from.TargetUser), 166 TargetUser: domain.ArticleTarget(from.TargetUser),
162 CountLove: from.CountLove, 167 CountLove: from.CountLove,
163 CountComment: from.CountComment, 168 CountComment: from.CountComment,
  169 + CountRead: from.CountRead,
164 Show: domain.ArticleShow(from.Show), 170 Show: domain.ArticleShow(from.Show),
165 } 171 }
166 return to, nil 172 return to, nil
@@ -173,6 +179,7 @@ func (repository *ArticleRepository) DomainModelToModel(from *domain.Article) (* @@ -173,6 +179,7 @@ func (repository *ArticleRepository) DomainModelToModel(from *domain.Article) (*
173 CreatedAt: from.CreatedAt, 179 CreatedAt: from.CreatedAt,
174 UpdatedAt: from.UpdatedAt, 180 UpdatedAt: from.UpdatedAt,
175 DeletedAt: from.DeletedAt, 181 DeletedAt: from.DeletedAt,
  182 + IsDel: 0,
176 Version: from.Version, 183 Version: from.Version,
177 AuthorId: from.AuthorId, 184 AuthorId: from.AuthorId,
178 Author: from.Author, 185 Author: from.Author,
@@ -183,6 +190,7 @@ func (repository *ArticleRepository) DomainModelToModel(from *domain.Article) (* @@ -183,6 +190,7 @@ func (repository *ArticleRepository) DomainModelToModel(from *domain.Article) (*
183 Location: from.Location, 190 Location: from.Location,
184 TargetUser: int(from.TargetUser), 191 TargetUser: int(from.TargetUser),
185 CountLove: from.CountLove, 192 CountLove: from.CountLove,
  193 + CountRead: from.CountRead,
186 CountComment: from.CountComment, 194 CountComment: from.CountComment,
187 Show: int(from.Show), 195 Show: int(from.Show),
188 } 196 }
@@ -125,10 +125,10 @@ func (repository *ArticleTagRepository) Find(ctx context.Context, conn transacti @@ -125,10 +125,10 @@ func (repository *ArticleTagRepository) Find(ctx context.Context, conn transacti
125 Order("id desc") 125 Order("id desc")
126 126
127 if v, ok := queryOptions["name"]; ok { 127 if v, ok := queryOptions["name"]; ok {
128 - tx.Where("id like ?", v) 128 + tx = tx.Where("name like ?", v)
129 } 129 }
130 if v, ok := queryOptions["group"]; ok { 130 if v, ok := queryOptions["group"]; ok {
131 - tx.Where("group like ?", v) 131 + tx = tx.Where("group like ?", v)
132 } 132 }
133 133
134 if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil { 134 if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
@@ -24,10 +24,21 @@ type Article struct { @@ -24,10 +24,21 @@ type Article struct {
24 TargetUser ArticleTarget `json:"targetUser"` // 分发方式 0 分发给所有人 1 分发给指定的人 24 TargetUser ArticleTarget `json:"targetUser"` // 分发方式 0 分发给所有人 1 分发给指定的人
25 CountLove int `json:"countLove"` // 点赞数量 25 CountLove int `json:"countLove"` // 点赞数量
26 CountComment int `json:"countComment"` // 评论数量 26 CountComment int `json:"countComment"` // 评论数量
27 - Show ArticleShow `json:"showState"` // 评论的展示状态(0显示、1不显示) 27 + CountRead int `json:"countRead"` // 浏览数量
  28 + Show ArticleShow `json:"show"` // 评论的展示状态(0显示、1不显示)
  29 + Tags []int64 `json:"tags"` // 定性标签
28 // ...more 30 // ...more
29 } 31 }
30 32
  33 +type ArticleRepository interface {
  34 + Insert(ctx context.Context, conn transaction.Conn, dm *Article) (*Article, error)
  35 + Update(ctx context.Context, conn transaction.Conn, dm *Article) (*Article, error)
  36 + Delete(ctx context.Context, conn transaction.Conn, dm *Article) (*Article, error)
  37 + UpdateWithVersion(ctx context.Context, conn transaction.Conn, dm *Article) (*Article, error)
  38 + FindOne(ctx context.Context, conn transaction.Conn, id int64) (*Article, error)
  39 + Find(ctx context.Context, conn transaction.Conn, companyId int64, queryOptions map[string]interface{}) (int64, []*Article, error)
  40 +}
  41 +
31 type ArticleTarget int 42 type ArticleTarget int
32 43
33 const ( 44 const (
@@ -63,11 +74,24 @@ func (a ArticleShow) Named() string { @@ -63,11 +74,24 @@ func (a ArticleShow) Named() string {
63 return "" 74 return ""
64 } 75 }
65 76
66 -type ArticleRepository interface {  
67 - Insert(ctx context.Context, conn transaction.Conn, dm *Article) (*Article, error)  
68 - Update(ctx context.Context, conn transaction.Conn, dm *Article) (*Article, error)  
69 - Delete(ctx context.Context, conn transaction.Conn, dm *Article) (*Article, error)  
70 - UpdateWithVersion(ctx context.Context, conn transaction.Conn, dm *Article) (*Article, error)  
71 - FindOne(ctx context.Context, conn transaction.Conn, id int64) (*Article, error)  
72 - Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*Article, error) 77 +// 设置文章的备份数据
  78 +func (m *Article) MakeBackup(operator UserSimple, section []ArticleSection) *ArticleBackup {
  79 + b := ArticleBackup{
  80 + Id: 0,
  81 + CompanyId: 0,
  82 + CreatedAt: 0,
  83 + UpdatedAt: 0,
  84 + DeletedAt: 0,
  85 + Version: 0,
  86 + Operator: operator,
  87 + Title: m.Title,
  88 + Section: section,
  89 + Images: m.Images,
  90 + Action: "",
  91 + TargetUser: m.TargetUser,
  92 + WhoRead: m.WhoRead,
  93 + WhoReview: m.WhoReview,
  94 + Tags: m.Tags,
  95 + }
  96 + return &b
73 } 97 }
@@ -22,7 +22,7 @@ type ArticleBackup struct { @@ -22,7 +22,7 @@ type ArticleBackup struct {
22 TargetUser ArticleTarget `json:"targetUser"` // 分发方式 0 分发给所有人 1 分发给指定的人 22 TargetUser ArticleTarget `json:"targetUser"` // 分发方式 0 分发给所有人 1 分发给指定的人
23 WhoRead []int64 `json:"whoRead"` // 谁可以看 23 WhoRead []int64 `json:"whoRead"` // 谁可以看
24 WhoReview []int64 `json:"whoReview"` // 评论人 24 WhoReview []int64 `json:"whoReview"` // 评论人
25 - Tags []int `json:"tags"` // 标签 25 + Tags []int64 `json:"tags"` // 标签
26 } 26 }
27 27
28 type ArticleBackupRepository interface { 28 type ArticleBackupRepository interface {
@@ -28,3 +28,10 @@ type ArticleSectionRepository interface { @@ -28,3 +28,10 @@ type ArticleSectionRepository interface {
28 FindOne(ctx context.Context, conn transaction.Conn, id int64) (*ArticleSection, error) 28 FindOne(ctx context.Context, conn transaction.Conn, id int64) (*ArticleSection, error)
29 Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*ArticleSection, error) 29 Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*ArticleSection, error)
30 } 30 }
  31 +
  32 +// 排序文章分段列表
  33 +type SortArticleSection []*ArticleSection
  34 +
  35 +func (a SortArticleSection) Len() int { return len(a) }
  36 +func (a SortArticleSection) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
  37 +func (a SortArticleSection) Less(i, j int) bool { return a[i].SortBy < a[j].SortBy }
@@ -29,9 +29,12 @@ type Opinion struct { @@ -29,9 +29,12 @@ 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 - Group string `json:"group,omitempty"` // 人员的分组  
36 - Position string `json:"position,omitempty"` // 职位 32 + Id int64 `json:"id"` // 人员id
  33 + Name string `json:"name"` // 人员的名字
  34 + Avatar string `json:"avatar,omitempty"` // 人员头像URL
  35 + GroupId int64 `json:"groupId,omitempty"`
  36 + Group string `json:"group,omitempty"` // 人员的分组
  37 + Position string `json:"position,omitempty"` // 职位
  38 + Company string `json:"company,omitempty"` // 公司
  39 + CompanyId int64 `json:"companyId"`
37 } 40 }