Merge branch 'dev' of http://gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss into dev
正在显示
29 个修改的文件
包含
818 行增加
和
35 行删除
| @@ -2,11 +2,12 @@ package main | @@ -2,11 +2,12 @@ package main | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "flag" | 4 | "flag" |
| 5 | + "net/http" | ||
| 6 | + "strings" | ||
| 7 | + | ||
| 5 | "github.com/zeromicro/go-zero/core/logx" | 8 | "github.com/zeromicro/go-zero/core/logx" |
| 6 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db" | 9 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db" |
| 7 | "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" |
| 8 | - "net/http" | ||
| 9 | - "strings" | ||
| 10 | 11 | ||
| 11 | "github.com/golang-jwt/jwt/v4/request" | 12 | "github.com/golang-jwt/jwt/v4/request" |
| 12 | "github.com/zeromicro/go-zero/core/conf" | 13 | "github.com/zeromicro/go-zero/core/conf" |
cmd/discuss/api/dsl/core/article.api
0 → 100644
| 1 | +syntax = "v1" | ||
| 2 | + | ||
| 3 | +info( | ||
| 4 | + title: "文章内容处理" | ||
| 5 | + desc: "编辑处理文章内容" | ||
| 6 | + author: "author" | ||
| 7 | + email: "email" | ||
| 8 | + version: "v1" | ||
| 9 | +) | ||
| 10 | + | ||
| 11 | +// 坐标地点描述 | ||
| 12 | +type Location { | ||
| 13 | + Longitude float64 `json:"longitude"` //经度 | ||
| 14 | + Latitude float64 `json:"latitude"` //纬度 | ||
| 15 | + Descript string `json:"descript"` //地点描述 | ||
| 16 | +} | ||
| 17 | + | ||
| 18 | +// 人员的简单展示信息 | ||
| 19 | +type Author { | ||
| 20 | + Id int64 `json:"id"` // 人员id | ||
| 21 | + Name string `json:"name"` // 人员的名字 | ||
| 22 | + Avatar string `json:"avatar"` // 人员头像URL | ||
| 23 | + Group string `json:"group"` // 人员的分组 | ||
| 24 | + Position string `json:"position"` // 职位 | ||
| 25 | +} | ||
| 26 | + | ||
| 27 | +// 创建发布文章 | ||
| 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"` //定位坐标 | ||
| 37 | + } | ||
| 38 | + ArticleCreateResponse { | ||
| 39 | + Id int64 `json:"id"` | ||
| 40 | + } | ||
| 41 | +) | ||
| 42 | + | ||
| 43 | +// 查看文章的详情 | ||
| 44 | +type ( | ||
| 45 | + ArticleGetRequest { | ||
| 46 | + Id int64 `json:"id"` //id | ||
| 47 | + } | ||
| 48 | + ArticleGetResponse { | ||
| 49 | + Title string `json:"title"` //标题 | ||
| 50 | + AuthorId int `json:"authorId"` //发布人id | ||
| 51 | + Author Author `json:"author"` //发布人 | ||
| 52 | + CreatedAt int64 `json:"createdAt"` //文章的发布时间 | ||
| 53 | + Section []string `json:"section"` //文章的文本内容 | ||
| 54 | + Images []string `json:"images"` //图片 | ||
| 55 | + WhoRead []int `json:"whoRead"` //谁可查看 | ||
| 56 | + WhoReview []int `json:"whoReview"` //谁可评论 | ||
| 57 | + Location Location `json:"location"` //定位坐标 | ||
| 58 | + CountLove int `json:"countLove"` // 点赞数量 | ||
| 59 | + CountComment int `json:"countComment"` // 评论数量 | ||
| 60 | + Show int `json:"showState"` // 评论的展示状态(0显示、1不显示) | ||
| 61 | + } | ||
| 62 | +) | ||
| 63 | + | ||
| 64 | +// 小程序接口 | ||
| 65 | +@server( | ||
| 66 | + prefix: v1/mini | ||
| 67 | + group: article | ||
| 68 | + jwt: MiniAuth | ||
| 69 | +) | ||
| 70 | +service Core { | ||
| 71 | + @doc "小程序创建发布内容" | ||
| 72 | + @handler CreateArticle | ||
| 73 | + post /article (ArticleCreateRequest) returns (ArticleCreateResponse) | ||
| 74 | + @doc "小程序获取文章内容详情" | ||
| 75 | + @handler GetArticle | ||
| 76 | + get /article/:id (ArticleGetRequest) returns (ArticleGetResponse) | ||
| 77 | +} |
cmd/discuss/api/dsl/core/article_tag.api
0 → 100644
| 1 | +syntax = "v1" | ||
| 2 | + | ||
| 3 | +info( | ||
| 4 | + title: "后台编辑标签" | ||
| 5 | + desc: "编辑处理标签信息" | ||
| 6 | + author: "author" | ||
| 7 | + email: "email" | ||
| 8 | + version: "v1" | ||
| 9 | +) | ||
| 10 | + | ||
| 11 | +// 创建标签 | ||
| 12 | +type ( | ||
| 13 | + TagCreateRequest { | ||
| 14 | + CompanyId int64 `json:"companyId"` | ||
| 15 | + Image string `json:"image"` | ||
| 16 | + Name string `json:"name"` // 标签名称 | ||
| 17 | + Group string `json:"group"` // 标签分类 | ||
| 18 | + Remark string `json:"remark"` // 备注 | ||
| 19 | + } | ||
| 20 | + | ||
| 21 | + TagCreateResponse { | ||
| 22 | + Id int64 `json:"id"` | ||
| 23 | + } | ||
| 24 | +) | ||
| 25 | + | ||
| 26 | +// 编辑标签 | ||
| 27 | +type ( | ||
| 28 | + TagEditRequest { | ||
| 29 | + Id int64 `json:"id"` | ||
| 30 | + CompanyId int64 `json:"companyId"` | ||
| 31 | + Image string `json:"image"` | ||
| 32 | + Name string `json:"name"` // 标签名称 | ||
| 33 | + Group string `json:"group"` // 标签分类 | ||
| 34 | + Remark string `json:"remark"` // 备注 | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + TagEditResponse { | ||
| 38 | + Id int64 `json:"id"` | ||
| 39 | + } | ||
| 40 | +) | ||
| 41 | + | ||
| 42 | +// 获取标签详情 | ||
| 43 | +type ( | ||
| 44 | + TagGetRequest { | ||
| 45 | + Id int64 `json:"id"` | ||
| 46 | + } | ||
| 47 | + TagGetResponse { | ||
| 48 | + Id int64 `json:"id"` | ||
| 49 | + Image string `json:"image"` | ||
| 50 | + Name string `json:"name"` // 标签名称 | ||
| 51 | + Group string `json:"group"` // 标签分类 | ||
| 52 | + Remark string `json:"remark"` // 备注 | ||
| 53 | + } | ||
| 54 | +) | ||
| 55 | + | ||
| 56 | +//标签列表 | ||
| 57 | +type ( | ||
| 58 | + TagListRequest { | ||
| 59 | + Page int `json:"page"` | ||
| 60 | + Size int `json:"size"` | ||
| 61 | + } | ||
| 62 | + TagListResponse { | ||
| 63 | + Total int `json:"total"` | ||
| 64 | + List []TagItem `json:"list"` | ||
| 65 | + } | ||
| 66 | + TagItem { | ||
| 67 | + Id int64 `json:"id"` | ||
| 68 | + Image string `json:"image"` | ||
| 69 | + Name string `json:"name"` // 标签名称 | ||
| 70 | + Group string `json:"group"` // 标签分类 | ||
| 71 | + Remark string `json:"remark"` // 备注 | ||
| 72 | + CreatedAt int64 `json:"createdAt"` | ||
| 73 | + } | ||
| 74 | +) | ||
| 75 | + | ||
| 76 | +//删除标签 | ||
| 77 | +type ( | ||
| 78 | + TagDeleteRequest { | ||
| 79 | + Id int64 `json:"id"` | ||
| 80 | + } | ||
| 81 | + TagDeleteResponse { | ||
| 82 | + Id int64 `json:"id"` | ||
| 83 | + } | ||
| 84 | +) | ||
| 85 | + | ||
| 86 | +@server( | ||
| 87 | + prefix: v1/mini | ||
| 88 | + group: tags | ||
| 89 | + jwt: MiniAuth | ||
| 90 | +) | ||
| 91 | +service Core { | ||
| 92 | + @doc "后台创建文章标签" | ||
| 93 | + @handler CreateTag | ||
| 94 | + post /article_tag (TagCreateRequest) returns (TagCreateResponse) | ||
| 95 | + @doc "后台编辑文章标签" | ||
| 96 | + @handler EditTag | ||
| 97 | + put /article_tag (TagEditRequest) returns (TagEditResponse) | ||
| 98 | + @doc "后台获取文章标签" | ||
| 99 | + @handler GetTag | ||
| 100 | + get /article_tag/:id (TagGetRequest) returns (TagGetResponse) | ||
| 101 | + @doc "后台删除文章标签" | ||
| 102 | + @handler DeleteTag | ||
| 103 | + delete /article_tag (TagDeleteRequest) returns (TagDeleteResponse) | ||
| 104 | +} |
| @@ -16,7 +16,7 @@ info( | @@ -16,7 +16,7 @@ info( | ||
| 16 | service Core { | 16 | service Core { |
| 17 | @doc "系统消息" | 17 | @doc "系统消息" |
| 18 | @handler miniSystem | 18 | @handler miniSystem |
| 19 | - post /mini/message/system (MessageSystemRequest) returns (MessageBusinessResponse) | 19 | + post /mini/message/system (MessageSystemRequest) returns (MessageSystemResponse) |
| 20 | 20 | ||
| 21 | @doc "业务消息" | 21 | @doc "业务消息" |
| 22 | @handler miniBusiness | 22 | @handler miniBusiness |
| @@ -37,6 +37,7 @@ type ( | @@ -37,6 +37,7 @@ type ( | ||
| 37 | Type int `json:"type"` // 系统分类 | 37 | Type int `json:"type"` // 系统分类 |
| 38 | Title string `json:"title"` // 标题 | 38 | Title string `json:"title"` // 标题 |
| 39 | Content string `json:"content"` // 内容 | 39 | Content string `json:"content"` // 内容 |
| 40 | + CreatedAt int64 `json:"createdAt"` // 创建时间 | ||
| 40 | } | 41 | } |
| 41 | 42 | ||
| 42 | MessageBusinessRequest struct { | 43 | MessageBusinessRequest struct { |
| 1 | package message | 1 | package message |
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result" | ||
| 4 | "net/http" | 5 | "net/http" |
| 5 | 6 | ||
| 6 | "github.com/zeromicro/go-zero/rest/httpx" | 7 | "github.com/zeromicro/go-zero/rest/httpx" |
| @@ -19,10 +20,11 @@ func MiniSystemHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | @@ -19,10 +20,11 @@ func MiniSystemHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||
| 19 | 20 | ||
| 20 | l := message.NewMiniSystemLogic(r.Context(), svcCtx) | 21 | l := message.NewMiniSystemLogic(r.Context(), svcCtx) |
| 21 | resp, err := l.MiniSystem(&req) | 22 | resp, err := l.MiniSystem(&req) |
| 22 | - if err != nil { | ||
| 23 | - httpx.ErrorCtx(r.Context(), w, err) | ||
| 24 | - } else { | ||
| 25 | - httpx.OkJsonCtx(r.Context(), w, resp) | ||
| 26 | - } | 23 | + result.HttpResult(r, w, resp, err) |
| 24 | + //if err != nil { | ||
| 25 | + // httpx.ErrorCtx(r.Context(), w, err) | ||
| 26 | + //} else { | ||
| 27 | + // httpx.OkJsonCtx(r.Context(), w, resp) | ||
| 28 | + //} | ||
| 27 | } | 29 | } |
| 28 | } | 30 | } |
| @@ -7,6 +7,7 @@ import ( | @@ -7,6 +7,7 @@ import ( | ||
| 7 | comment "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/handler/comment" | 7 | 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" | 8 | 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" | 9 | message "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/handler/message" |
| 10 | + tags "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/handler/tags" | ||
| 10 | user "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/handler/user" | 11 | user "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/handler/user" |
| 11 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" | 12 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" |
| 12 | 13 | ||
| @@ -59,6 +60,33 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { | @@ -59,6 +60,33 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { | ||
| 59 | []rest.Route{ | 60 | []rest.Route{ |
| 60 | { | 61 | { |
| 61 | Method: http.MethodPost, | 62 | Method: http.MethodPost, |
| 63 | + Path: "/article_tag", | ||
| 64 | + Handler: tags.CreateTagHandler(serverCtx), | ||
| 65 | + }, | ||
| 66 | + { | ||
| 67 | + Method: http.MethodPut, | ||
| 68 | + Path: "/article_tag", | ||
| 69 | + Handler: tags.EditTagHandler(serverCtx), | ||
| 70 | + }, | ||
| 71 | + { | ||
| 72 | + Method: http.MethodGet, | ||
| 73 | + Path: "/article_tag/:id", | ||
| 74 | + Handler: tags.GetTagHandler(serverCtx), | ||
| 75 | + }, | ||
| 76 | + { | ||
| 77 | + Method: http.MethodDelete, | ||
| 78 | + Path: "/article_tag", | ||
| 79 | + Handler: tags.DeleteTagHandler(serverCtx), | ||
| 80 | + }, | ||
| 81 | + }, | ||
| 82 | + rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret), | ||
| 83 | + rest.WithPrefix("/v1/mini"), | ||
| 84 | + ) | ||
| 85 | + | ||
| 86 | + server.AddRoutes( | ||
| 87 | + []rest.Route{ | ||
| 88 | + { | ||
| 89 | + Method: http.MethodPost, | ||
| 62 | Path: "/mini/user/apply-join-company", | 90 | Path: "/mini/user/apply-join-company", |
| 63 | Handler: user.MiniUserApplyJoinCompanyHandler(serverCtx), | 91 | Handler: user.MiniUserApplyJoinCompanyHandler(serverCtx), |
| 64 | }, | 92 | }, |
| 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 CreateTagHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||
| 13 | + return func(w http.ResponseWriter, r *http.Request) { | ||
| 14 | + var req types.TagCreateRequest | ||
| 15 | + if err := httpx.Parse(r, &req); err != nil { | ||
| 16 | + httpx.ErrorCtx(r.Context(), w, err) | ||
| 17 | + return | ||
| 18 | + } | ||
| 19 | + | ||
| 20 | + l := tags.NewCreateTagLogic(r.Context(), svcCtx) | ||
| 21 | + resp, err := l.CreateTag(&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 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 DeleteTagHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||
| 13 | + return func(w http.ResponseWriter, r *http.Request) { | ||
| 14 | + var req types.TagDeleteRequest | ||
| 15 | + if err := httpx.Parse(r, &req); err != nil { | ||
| 16 | + httpx.ErrorCtx(r.Context(), w, err) | ||
| 17 | + return | ||
| 18 | + } | ||
| 19 | + | ||
| 20 | + l := tags.NewDeleteTagLogic(r.Context(), svcCtx) | ||
| 21 | + resp, err := l.DeleteTag(&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 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 EditTagHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||
| 13 | + return func(w http.ResponseWriter, r *http.Request) { | ||
| 14 | + var req types.TagEditRequest | ||
| 15 | + if err := httpx.Parse(r, &req); err != nil { | ||
| 16 | + httpx.ErrorCtx(r.Context(), w, err) | ||
| 17 | + return | ||
| 18 | + } | ||
| 19 | + | ||
| 20 | + l := tags.NewEditTagLogic(r.Context(), svcCtx) | ||
| 21 | + resp, err := l.EditTag(&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 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 GetTagHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||
| 13 | + return func(w http.ResponseWriter, r *http.Request) { | ||
| 14 | + var req types.TagGetRequest | ||
| 15 | + if err := httpx.Parse(r, &req); err != nil { | ||
| 16 | + httpx.ErrorCtx(r.Context(), w, err) | ||
| 17 | + return | ||
| 18 | + } | ||
| 19 | + | ||
| 20 | + l := tags.NewGetTagLogic(r.Context(), svcCtx) | ||
| 21 | + resp, err := l.GetTag(&req) | ||
| 22 | + if err != nil { | ||
| 23 | + httpx.ErrorCtx(r.Context(), w, err) | ||
| 24 | + } else { | ||
| 25 | + httpx.OkJsonCtx(r.Context(), w, resp) | ||
| 26 | + } | ||
| 27 | + } | ||
| 28 | +} |
| @@ -2,11 +2,10 @@ package message | @@ -2,11 +2,10 @@ package message | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "context" | 4 | "context" |
| 5 | - | 5 | + "github.com/zeromicro/go-zero/core/logx" |
| 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 | - | ||
| 9 | - "github.com/zeromicro/go-zero/core/logx" | 8 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" |
| 10 | ) | 9 | ) |
| 11 | 10 | ||
| 12 | type MiniSystemLogic struct { | 11 | type MiniSystemLogic struct { |
| @@ -23,8 +22,37 @@ func NewMiniSystemLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniSy | @@ -23,8 +22,37 @@ func NewMiniSystemLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniSy | ||
| 23 | } | 22 | } |
| 24 | } | 23 | } |
| 25 | 24 | ||
| 26 | -func (l *MiniSystemLogic) MiniSystem(req *types.MessageSystemRequest) (resp *types.MessageBusinessResponse, err error) { | ||
| 27 | - // todo: add your logic here and delete this line | 25 | +func (l *MiniSystemLogic) MiniSystem(req *types.MessageSystemRequest) (resp *types.MessageSystemResponse, err error) { |
| 26 | + queryOptions := domain.NewQueryOptions().WithOffsetLimit(req.Page, req.Size) | ||
| 27 | + total, list, err := l.svcCtx.MessageSystemRepository.Find(l.ctx, l.svcCtx.DefaultDBConn(), queryOptions) | ||
| 28 | + if err != nil { | ||
| 29 | + return nil, err | ||
| 30 | + } | ||
| 31 | + resp = &types.MessageSystemResponse{} | ||
| 32 | + resp.Total = total | ||
| 33 | + resp.List = make([]types.MessageSystemItem, 0) | ||
| 34 | + for _, item := range list { | ||
| 35 | + to := types.MessageSystemItem{ | ||
| 36 | + Id: item.Id, | ||
| 37 | + Type: item.Type, | ||
| 38 | + Title: item.Title, | ||
| 39 | + Content: item.Content, | ||
| 40 | + CreatedAt: item.CreatedAt, | ||
| 41 | + } | ||
| 42 | + resp.List = append(resp.List, to) | ||
| 43 | + } | ||
| 44 | + return resp, nil | ||
| 45 | +} | ||
| 28 | 46 | ||
| 29 | - return | 47 | +func (l *MiniSystemLogic) CreateMessage(dm *domain.MessageSystem) error { |
| 48 | + _, err := l.svcCtx.MessageSystemRepository.Insert(l.ctx, l.svcCtx.DefaultDBConn(), dm) | ||
| 49 | + l.Debugf("") | ||
| 50 | + return err | ||
| 30 | } | 51 | } |
| 52 | + | ||
| 53 | +//// CreateSystemMessage 生成一条信息 | ||
| 54 | +//func CreateSystemMessage(ctx context.Context, svcCtx *svc.ServiceContext, dm *domain.MessageSystem) error { | ||
| 55 | +// l := NewMiniSystemLogic(ctx, svcCtx) | ||
| 56 | +// err := l.CreateMessage(dm) | ||
| 57 | +// return err | ||
| 58 | +//} |
| 1 | +package tags | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "context" | ||
| 5 | + "fmt" | ||
| 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/pkg/xerr" | ||
| 10 | + | ||
| 11 | + "github.com/zeromicro/go-zero/core/logx" | ||
| 12 | +) | ||
| 13 | + | ||
| 14 | +type CreateTagLogic struct { | ||
| 15 | + logx.Logger | ||
| 16 | + ctx context.Context | ||
| 17 | + svcCtx *svc.ServiceContext | ||
| 18 | +} | ||
| 19 | + | ||
| 20 | +func NewCreateTagLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateTagLogic { | ||
| 21 | + return &CreateTagLogic{ | ||
| 22 | + Logger: logx.WithContext(ctx), | ||
| 23 | + ctx: ctx, | ||
| 24 | + svcCtx: svcCtx, | ||
| 25 | + } | ||
| 26 | +} | ||
| 27 | + | ||
| 28 | +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 | + //检查重复 | ||
| 32 | + cnt, _, err := l.svcCtx.ArticleTagRepository.Find(l.ctx, conn, req.CompanyId, map[string]interface{}{ | ||
| 33 | + "name": req.Name, | ||
| 34 | + "group": req.Group, | ||
| 35 | + "countOnly": true, | ||
| 36 | + }) | ||
| 37 | + if err != nil { | ||
| 38 | + return nil, xerr.NewErrMsgErr("添加标签失败", err) | ||
| 39 | + } | ||
| 40 | + if cnt > 0 { | ||
| 41 | + return nil, xerr.NewErrMsg(fmt.Sprintf("已存在标签 分类[%s]名称[%s]", req.Group, req.Name)) | ||
| 42 | + } | ||
| 43 | + return | ||
| 44 | +} |
| 1 | +package tags | ||
| 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 DeleteTagLogic struct { | ||
| 13 | + logx.Logger | ||
| 14 | + ctx context.Context | ||
| 15 | + svcCtx *svc.ServiceContext | ||
| 16 | +} | ||
| 17 | + | ||
| 18 | +func NewDeleteTagLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteTagLogic { | ||
| 19 | + return &DeleteTagLogic{ | ||
| 20 | + Logger: logx.WithContext(ctx), | ||
| 21 | + ctx: ctx, | ||
| 22 | + svcCtx: svcCtx, | ||
| 23 | + } | ||
| 24 | +} | ||
| 25 | + | ||
| 26 | +func (l *DeleteTagLogic) DeleteTag(req *types.TagDeleteRequest) (resp *types.TagDeleteResponse, err error) { | ||
| 27 | + // todo: add your logic here and delete this line | ||
| 28 | + | ||
| 29 | + return | ||
| 30 | +} |
| 1 | +package tags | ||
| 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 EditTagLogic struct { | ||
| 13 | + logx.Logger | ||
| 14 | + ctx context.Context | ||
| 15 | + svcCtx *svc.ServiceContext | ||
| 16 | +} | ||
| 17 | + | ||
| 18 | +func NewEditTagLogic(ctx context.Context, svcCtx *svc.ServiceContext) *EditTagLogic { | ||
| 19 | + return &EditTagLogic{ | ||
| 20 | + Logger: logx.WithContext(ctx), | ||
| 21 | + ctx: ctx, | ||
| 22 | + svcCtx: svcCtx, | ||
| 23 | + } | ||
| 24 | +} | ||
| 25 | + | ||
| 26 | +func (l *EditTagLogic) EditTag(req *types.TagEditRequest) (resp *types.TagEditResponse, err error) { | ||
| 27 | + // todo: add your logic here and delete this line | ||
| 28 | + | ||
| 29 | + return | ||
| 30 | +} |
| 1 | +package tags | ||
| 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 GetTagLogic struct { | ||
| 13 | + logx.Logger | ||
| 14 | + ctx context.Context | ||
| 15 | + svcCtx *svc.ServiceContext | ||
| 16 | +} | ||
| 17 | + | ||
| 18 | +func NewGetTagLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetTagLogic { | ||
| 19 | + return &GetTagLogic{ | ||
| 20 | + Logger: logx.WithContext(ctx), | ||
| 21 | + ctx: ctx, | ||
| 22 | + svcCtx: svcCtx, | ||
| 23 | + } | ||
| 24 | +} | ||
| 25 | + | ||
| 26 | +func (l *GetTagLogic) GetTag(req *types.TagGetRequest) (resp *types.TagGetResponse, err error) { | ||
| 27 | + // todo: add your logic here and delete this line | ||
| 28 | + | ||
| 29 | + return | ||
| 30 | +} |
| @@ -21,6 +21,7 @@ type ServiceContext struct { | @@ -21,6 +21,7 @@ type ServiceContext struct { | ||
| 21 | ArticleDraftRepository domain.ArticleDraftRepository | 21 | ArticleDraftRepository domain.ArticleDraftRepository |
| 22 | ArticleRepository domain.ArticleRepository | 22 | ArticleRepository domain.ArticleRepository |
| 23 | ArticleSectionRepository domain.ArticleSectionRepository | 23 | ArticleSectionRepository domain.ArticleSectionRepository |
| 24 | + ArticleTagRepository domain.ArticleTagRepository | ||
| 24 | 25 | ||
| 25 | CompanyRepository domain.CompanyRepository | 26 | CompanyRepository domain.CompanyRepository |
| 26 | CommentRepository domain.CommentRepository // 待移除 | 27 | CommentRepository domain.CommentRepository // 待移除 |
| @@ -36,6 +37,7 @@ type ServiceContext struct { | @@ -36,6 +37,7 @@ type ServiceContext struct { | ||
| 36 | func NewServiceContext(c config.Config) *ServiceContext { | 37 | func NewServiceContext(c config.Config) *ServiceContext { |
| 37 | 38 | ||
| 38 | db := database.OpenGormPGDB(c.DB.DataSource, c.Log.Mode) | 39 | db := database.OpenGormPGDB(c.DB.DataSource, c.Log.Mode) |
| 40 | + | ||
| 39 | mlCache := cache.NewMultiLevelCache([]string{c.Redis.Host}, c.Redis.Pass) | 41 | mlCache := cache.NewMultiLevelCache([]string{c.Redis.Host}, c.Redis.Pass) |
| 40 | redis, _ := redis.NewRedis(redis.RedisConf{Host: c.Redis.Host, Pass: c.Redis.Pass, Type: "node"}) | 42 | redis, _ := redis.NewRedis(redis.RedisConf{Host: c.Redis.Host, Pass: c.Redis.Pass, Type: "node"}) |
| 41 | 43 | ||
| @@ -57,6 +59,7 @@ func NewServiceContext(c config.Config) *ServiceContext { | @@ -57,6 +59,7 @@ func NewServiceContext(c config.Config) *ServiceContext { | ||
| 57 | UserFollowRepository: repository.NewUserFollowRepository(cache.NewCachedRepository(mlCache)), | 59 | UserFollowRepository: repository.NewUserFollowRepository(cache.NewCachedRepository(mlCache)), |
| 58 | UserLoveFlagRepository: repository.NewUserLoveFlagRepository(cache.NewCachedRepository(mlCache)), | 60 | UserLoveFlagRepository: repository.NewUserLoveFlagRepository(cache.NewCachedRepository(mlCache)), |
| 59 | UserRepository: repository.NewUserRepository(cache.NewCachedRepository(mlCache)), | 61 | UserRepository: repository.NewUserRepository(cache.NewCachedRepository(mlCache)), |
| 62 | + ArticleTagRepository: repository.NewArticleTagRepository(cache.NewCachedRepository(mlCache)), | ||
| 60 | } | 63 | } |
| 61 | } | 64 | } |
| 62 | 65 |
| @@ -22,10 +22,11 @@ type MessageSystemResponse struct { | @@ -22,10 +22,11 @@ type MessageSystemResponse struct { | ||
| 22 | } | 22 | } |
| 23 | 23 | ||
| 24 | type MessageSystemItem struct { | 24 | type MessageSystemItem struct { |
| 25 | - Id int64 `json:"id"` // ID | ||
| 26 | - Type int `json:"type"` // 系统分类 | ||
| 27 | - Title string `json:"title"` // 标题 | ||
| 28 | - Content string `json:"content"` // 内容 | 25 | + Id int64 `json:"id"` // ID |
| 26 | + Type int `json:"type"` // 系统分类 | ||
| 27 | + Title string `json:"title"` // 标题 | ||
| 28 | + Content string `json:"content"` // 内容 | ||
| 29 | + CreatedAt int64 `json:"createdAt"` // 创建时间 | ||
| 29 | } | 30 | } |
| 30 | 31 | ||
| 31 | type MessageBusinessRequest struct { | 32 | type MessageBusinessRequest struct { |
| @@ -63,6 +64,70 @@ type User struct { | @@ -63,6 +64,70 @@ type User struct { | ||
| 63 | Position string `json:"position,omitempty"` // 职位 | 64 | Position string `json:"position,omitempty"` // 职位 |
| 64 | } | 65 | } |
| 65 | 66 | ||
| 67 | +type TagCreateRequest struct { | ||
| 68 | + CompanyId int64 `json:"companyId"` | ||
| 69 | + Image string `json:"image"` | ||
| 70 | + Name string `json:"name"` // 标签名称 | ||
| 71 | + Group string `json:"group"` // 标签分类 | ||
| 72 | + Remark string `json:"remark"` // 备注 | ||
| 73 | +} | ||
| 74 | + | ||
| 75 | +type TagCreateResponse struct { | ||
| 76 | + Id int64 `json:"id"` | ||
| 77 | +} | ||
| 78 | + | ||
| 79 | +type TagEditRequest struct { | ||
| 80 | + Id int64 `json:"id"` | ||
| 81 | + CompanyId int64 `json:"companyId"` | ||
| 82 | + Image string `json:"image"` | ||
| 83 | + Name string `json:"name"` // 标签名称 | ||
| 84 | + Group string `json:"group"` // 标签分类 | ||
| 85 | + Remark string `json:"remark"` // 备注 | ||
| 86 | +} | ||
| 87 | + | ||
| 88 | +type TagEditResponse struct { | ||
| 89 | + Id int64 `json:"id"` | ||
| 90 | +} | ||
| 91 | + | ||
| 92 | +type TagGetRequest struct { | ||
| 93 | + Id int64 `json:"id"` | ||
| 94 | +} | ||
| 95 | + | ||
| 96 | +type TagGetResponse struct { | ||
| 97 | + Id int64 `json:"id"` | ||
| 98 | + Image string `json:"image"` | ||
| 99 | + Name string `json:"name"` // 标签名称 | ||
| 100 | + Group string `json:"group"` // 标签分类 | ||
| 101 | + Remark string `json:"remark"` // 备注 | ||
| 102 | +} | ||
| 103 | + | ||
| 104 | +type TagListRequest struct { | ||
| 105 | + Page int `json:"page"` | ||
| 106 | + Size int `json:"size"` | ||
| 107 | +} | ||
| 108 | + | ||
| 109 | +type TagListResponse struct { | ||
| 110 | + Total int `json:"total"` | ||
| 111 | + List []TagItem `json:"list"` | ||
| 112 | +} | ||
| 113 | + | ||
| 114 | +type TagItem struct { | ||
| 115 | + Id int64 `json:"id"` | ||
| 116 | + Image string `json:"image"` | ||
| 117 | + Name string `json:"name"` // 标签名称 | ||
| 118 | + Group string `json:"group"` // 标签分类 | ||
| 119 | + Remark string `json:"remark"` // 备注 | ||
| 120 | + CreatedAt int64 `json:"createdAt"` | ||
| 121 | +} | ||
| 122 | + | ||
| 123 | +type TagDeleteRequest struct { | ||
| 124 | + Id int64 `json:"id"` | ||
| 125 | +} | ||
| 126 | + | ||
| 127 | +type TagDeleteResponse struct { | ||
| 128 | + Id int64 `json:"id"` | ||
| 129 | +} | ||
| 130 | + | ||
| 66 | type MiniUserLoginRequest struct { | 131 | type MiniUserLoginRequest struct { |
| 67 | LoginType string `json:"loginType"` // 登录类型 wechat-login whchat-phone-login phone-password-login phone-smscode-login | 132 | LoginType string `json:"loginType"` // 登录类型 wechat-login whchat-phone-login phone-password-login phone-smscode-login |
| 68 | WechatAuthCode string `json:"wechatAuthcode,optional"` // 微信登录 授权码 | 133 | WechatAuthCode string `json:"wechatAuthcode,optional"` // 微信登录 授权码 |
| @@ -12,11 +12,14 @@ func Migrate(db *gorm.DB) { | @@ -12,11 +12,14 @@ func Migrate(db *gorm.DB) { | ||
| 12 | &models.ArticleBackup{}, | 12 | &models.ArticleBackup{}, |
| 13 | &models.ArticleDraft{}, | 13 | &models.ArticleDraft{}, |
| 14 | &models.ArticleComment{}, | 14 | &models.ArticleComment{}, |
| 15 | + &models.ArticleTag{}, | ||
| 15 | &models.UserLoveFlag{}, | 16 | &models.UserLoveFlag{}, |
| 16 | &models.User{}, | 17 | &models.User{}, |
| 17 | &models.Role{}, | 18 | &models.Role{}, |
| 18 | &models.Company{}, | 19 | &models.Company{}, |
| 19 | &models.UserFollow{}, | 20 | &models.UserFollow{}, |
| 21 | + &models.MessageSystem{}, | ||
| 22 | + &models.MessageBusiness{}, | ||
| 20 | } | 23 | } |
| 21 | 24 | ||
| 22 | db.AutoMigrate(modelsList...) | 25 | db.AutoMigrate(modelsList...) |
| @@ -27,7 +27,6 @@ type Article struct { | @@ -27,7 +27,6 @@ type Article struct { | ||
| 27 | TargetUser int // 分发方式 0 分发给所有人 1 分发给指定的人 | 27 | TargetUser int // 分发方式 0 分发给所有人 1 分发给指定的人 |
| 28 | CountLove int // 点赞数量 | 28 | CountLove int // 点赞数量 |
| 29 | CountComment int // 评论数量 | 29 | CountComment int // 评论数量 |
| 30 | - Tags []int `gorm:"type:jsonb;serializer:json"` // 标签 | ||
| 31 | Show int // 评论的展示状态(0显示、1不显示) | 30 | Show int // 评论的展示状态(0显示、1不显示) |
| 32 | } | 31 | } |
| 33 | 32 |
| 1 | +package models | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "time" | ||
| 6 | + | ||
| 7 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" | ||
| 8 | + "gorm.io/gorm" | ||
| 9 | + "gorm.io/plugin/soft_delete" | ||
| 10 | +) | ||
| 11 | + | ||
| 12 | +type ArticleTag struct { | ||
| 13 | + Id int64 `gorm:"primaryKey"` // 唯一标识 | ||
| 14 | + CompanyId int64 | ||
| 15 | + CreatedAt int64 | ||
| 16 | + UpdatedAt int64 | ||
| 17 | + DeletedAt int64 | ||
| 18 | + IsDel soft_delete.DeletedAt `gorm:"softDelete:flag,DeletedAtField:DeletedAt"` | ||
| 19 | + Version int | ||
| 20 | + Image domain.Image `gorm:"type:jsonb;serializer:json"` // 图片 | ||
| 21 | + Name string // 标签名称 | ||
| 22 | + Group string // 标签分类 | ||
| 23 | + Remark string // 备注 | ||
| 24 | +} | ||
| 25 | + | ||
| 26 | +func (m *ArticleTag) TableName() string { | ||
| 27 | + return "article_tag" | ||
| 28 | +} | ||
| 29 | + | ||
| 30 | +func (m *ArticleTag) BeforeCreate(tx *gorm.DB) (err error) { | ||
| 31 | + m.CreatedAt = time.Now().Unix() | ||
| 32 | + m.UpdatedAt = time.Now().Unix() | ||
| 33 | + return | ||
| 34 | +} | ||
| 35 | + | ||
| 36 | +func (m *ArticleTag) BeforeUpdate(tx *gorm.DB) (err error) { | ||
| 37 | + m.UpdatedAt = time.Now().Unix() | ||
| 38 | + return | ||
| 39 | +} | ||
| 40 | + | ||
| 41 | +func (m *ArticleTag) CacheKeyFunc() string { | ||
| 42 | + if m.Id == 0 { | ||
| 43 | + return "" | ||
| 44 | + } | ||
| 45 | + return fmt.Sprintf("%v:cache:%v:id:%v", domain.ProjectName, m.TableName(), m.Id) | ||
| 46 | +} | ||
| 47 | + | ||
| 48 | +func (m *ArticleTag) CacheKeyFuncByObject(obj interface{}) string { | ||
| 49 | + if v, ok := obj.(*ArticleTag); ok { | ||
| 50 | + return v.CacheKeyFunc() | ||
| 51 | + } | ||
| 52 | + return "" | ||
| 53 | +} | ||
| 54 | + | ||
| 55 | +func (m *ArticleTag) CachePrimaryKeyFunc() string { | ||
| 56 | + if len("") == 0 { | ||
| 57 | + return "" | ||
| 58 | + } | ||
| 59 | + return fmt.Sprintf("%v:cache:%v:primarykey:%v", domain.ProjectName, m.TableName(), "key") | ||
| 60 | +} |
| @@ -5,16 +5,17 @@ import ( | @@ -5,16 +5,17 @@ import ( | ||
| 5 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" | 5 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" |
| 6 | "gorm.io/gorm" | 6 | "gorm.io/gorm" |
| 7 | "gorm.io/plugin/soft_delete" | 7 | "gorm.io/plugin/soft_delete" |
| 8 | + "time" | ||
| 8 | ) | 9 | ) |
| 9 | 10 | ||
| 10 | // MessageSystem 消息中心-系统消息 | 11 | // MessageSystem 消息中心-系统消息 |
| 11 | type MessageSystem struct { | 12 | type MessageSystem struct { |
| 12 | Id int64 // 唯一标识 | 13 | Id int64 // 唯一标识 |
| 13 | - CompanyId int64 `json:"companyId"` // 公司ID | ||
| 14 | - RecipientId int64 `json:"recipientId"` // 接收者ID | ||
| 15 | - Type int `json:"type"` // 系统分类(0待定、1业务正常通知、2业务异常通知) | ||
| 16 | - Title string `json:"title"` // 标题 | ||
| 17 | - Content string `json:"content"` // 内容 | 14 | + CompanyId int64 `json:"companyId"` // 公司ID |
| 15 | + RecipientId int64 `json:"recipientId"` // 接收者ID | ||
| 16 | + Type int `json:"type"` // 系统分类(0待定、1业务正常通知、2业务异常通知) | ||
| 17 | + Title string `json:"title,omitempty"` // 标题 | ||
| 18 | + Content string `json:"content,omitempty"` // 内容 | ||
| 18 | CreatedAt int64 `json:",omitempty"` | 19 | CreatedAt int64 `json:",omitempty"` |
| 19 | UpdatedAt int64 `json:",omitempty"` | 20 | UpdatedAt int64 `json:",omitempty"` |
| 20 | DeletedAt int64 `json:",omitempty"` | 21 | DeletedAt int64 `json:",omitempty"` |
| @@ -27,13 +28,13 @@ func (m *MessageSystem) TableName() string { | @@ -27,13 +28,13 @@ func (m *MessageSystem) TableName() string { | ||
| 27 | } | 28 | } |
| 28 | 29 | ||
| 29 | func (m *MessageSystem) BeforeCreate(tx *gorm.DB) (err error) { | 30 | func (m *MessageSystem) BeforeCreate(tx *gorm.DB) (err error) { |
| 30 | - // m.CreatedAt = time.Now().Unix() | ||
| 31 | - // m.UpdatedAt = time.Now().Unix() | 31 | + m.CreatedAt = time.Now().Unix() |
| 32 | + m.UpdatedAt = time.Now().Unix() | ||
| 32 | return | 33 | return |
| 33 | } | 34 | } |
| 34 | 35 | ||
| 35 | func (m *MessageSystem) BeforeUpdate(tx *gorm.DB) (err error) { | 36 | func (m *MessageSystem) BeforeUpdate(tx *gorm.DB) (err error) { |
| 36 | - // m.UpdatedAt = time.Now().Unix() | 37 | + m.UpdatedAt = time.Now().Unix() |
| 37 | return | 38 | return |
| 38 | } | 39 | } |
| 39 | 40 |
| @@ -158,7 +158,6 @@ func (repository *ArticleRepository) ModelToDomainModel(from *models.Article) (* | @@ -158,7 +158,6 @@ func (repository *ArticleRepository) ModelToDomainModel(from *models.Article) (* | ||
| 158 | TargetUser: domain.ArticleTarget(from.TargetUser), | 158 | TargetUser: domain.ArticleTarget(from.TargetUser), |
| 159 | CountLove: from.CountLove, | 159 | CountLove: from.CountLove, |
| 160 | CountComment: from.CountComment, | 160 | CountComment: from.CountComment, |
| 161 | - Tags: from.Tags, | ||
| 162 | Show: domain.ArticleShow(from.Show), | 161 | Show: domain.ArticleShow(from.Show), |
| 163 | } | 162 | } |
| 164 | return to, nil | 163 | return to, nil |
| @@ -182,7 +181,6 @@ func (repository *ArticleRepository) DomainModelToModel(from *domain.Article) (* | @@ -182,7 +181,6 @@ func (repository *ArticleRepository) DomainModelToModel(from *domain.Article) (* | ||
| 182 | TargetUser: int(from.TargetUser), | 181 | TargetUser: int(from.TargetUser), |
| 183 | CountLove: from.CountLove, | 182 | CountLove: from.CountLove, |
| 184 | CountComment: from.CountComment, | 183 | CountComment: from.CountComment, |
| 185 | - Tags: from.Tags, | ||
| 186 | Show: int(from.Show), | 184 | Show: int(from.Show), |
| 187 | } | 185 | } |
| 188 | // err := copier.Copy(to, from) | 186 | // err := copier.Copy(to, from) |
| 1 | +package repository | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "context" | ||
| 5 | + | ||
| 6 | + "github.com/jinzhu/copier" | ||
| 7 | + "github.com/pkg/errors" | ||
| 8 | + "github.com/tiptok/gocomm/pkg/cache" | ||
| 9 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/models" | ||
| 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/domain" | ||
| 12 | + "gorm.io/gorm" | ||
| 13 | +) | ||
| 14 | + | ||
| 15 | +type ArticleTagRepository struct { | ||
| 16 | + *cache.CachedRepository | ||
| 17 | +} | ||
| 18 | + | ||
| 19 | +func (repository *ArticleTagRepository) Insert(ctx context.Context, conn transaction.Conn, dm *domain.ArticleTag) (*domain.ArticleTag, error) { | ||
| 20 | + var ( | ||
| 21 | + err error | ||
| 22 | + m = &models.ArticleTag{} | ||
| 23 | + tx = conn.DB() | ||
| 24 | + ) | ||
| 25 | + if m, err = repository.DomainModelToModel(dm); err != nil { | ||
| 26 | + return nil, err | ||
| 27 | + } | ||
| 28 | + if tx = tx.Model(m).Save(m); tx.Error != nil { | ||
| 29 | + return nil, tx.Error | ||
| 30 | + } | ||
| 31 | + dm.Id = m.Id | ||
| 32 | + return repository.ModelToDomainModel(m) | ||
| 33 | + | ||
| 34 | +} | ||
| 35 | + | ||
| 36 | +func (repository *ArticleTagRepository) Update(ctx context.Context, conn transaction.Conn, dm *domain.ArticleTag) (*domain.ArticleTag, error) { | ||
| 37 | + var ( | ||
| 38 | + err error | ||
| 39 | + m *models.ArticleTag | ||
| 40 | + tx = conn.DB() | ||
| 41 | + ) | ||
| 42 | + if m, err = repository.DomainModelToModel(dm); err != nil { | ||
| 43 | + return nil, err | ||
| 44 | + } | ||
| 45 | + queryFunc := func() (interface{}, error) { | ||
| 46 | + tx = tx.Model(m).Updates(m) | ||
| 47 | + return nil, tx.Error | ||
| 48 | + } | ||
| 49 | + if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil { | ||
| 50 | + return nil, err | ||
| 51 | + } | ||
| 52 | + return repository.ModelToDomainModel(m) | ||
| 53 | +} | ||
| 54 | + | ||
| 55 | +func (repository *ArticleTagRepository) UpdateWithVersion(ctx context.Context, transaction transaction.Conn, dm *domain.ArticleTag) (*domain.ArticleTag, error) { | ||
| 56 | + var ( | ||
| 57 | + err error | ||
| 58 | + m *models.ArticleTag | ||
| 59 | + tx = transaction.DB() | ||
| 60 | + ) | ||
| 61 | + if m, err = repository.DomainModelToModel(dm); err != nil { | ||
| 62 | + return nil, err | ||
| 63 | + } | ||
| 64 | + oldVersion := dm.Version | ||
| 65 | + m.Version += 1 | ||
| 66 | + queryFunc := func() (interface{}, error) { | ||
| 67 | + tx = tx.Model(m).Select("*").Where("id = ?", m.Id).Where("version = ?", oldVersion).Updates(m) | ||
| 68 | + if tx.RowsAffected == 0 { | ||
| 69 | + return nil, domain.ErrUpdateFail | ||
| 70 | + } | ||
| 71 | + return nil, tx.Error | ||
| 72 | + } | ||
| 73 | + if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil { | ||
| 74 | + return nil, err | ||
| 75 | + } | ||
| 76 | + return repository.ModelToDomainModel(m) | ||
| 77 | +} | ||
| 78 | + | ||
| 79 | +func (repository *ArticleTagRepository) Delete(ctx context.Context, conn transaction.Conn, dm *domain.ArticleTag) (*domain.ArticleTag, error) { | ||
| 80 | + var ( | ||
| 81 | + tx = conn.DB() | ||
| 82 | + m = &models.ArticleTag{Id: dm.Id} | ||
| 83 | + ) | ||
| 84 | + queryFunc := func() (interface{}, error) { | ||
| 85 | + tx = tx.Where("id = ?", m.Id).Delete(m) | ||
| 86 | + return m, tx.Error | ||
| 87 | + } | ||
| 88 | + if _, err := repository.Query(queryFunc, m.CacheKeyFunc()); err != nil { | ||
| 89 | + return dm, err | ||
| 90 | + } | ||
| 91 | + return repository.ModelToDomainModel(m) | ||
| 92 | +} | ||
| 93 | + | ||
| 94 | +func (repository *ArticleTagRepository) FindOne(ctx context.Context, conn transaction.Conn, id int64) (*domain.ArticleTag, error) { | ||
| 95 | + var ( | ||
| 96 | + err error | ||
| 97 | + tx = conn.DB() | ||
| 98 | + m = new(models.ArticleTag) | ||
| 99 | + ) | ||
| 100 | + queryFunc := func() (interface{}, error) { | ||
| 101 | + tx = tx.Model(m).Where("id = ?", id).First(m) | ||
| 102 | + if errors.Is(tx.Error, gorm.ErrRecordNotFound) { | ||
| 103 | + return nil, domain.ErrNotFound | ||
| 104 | + } | ||
| 105 | + return m, tx.Error | ||
| 106 | + } | ||
| 107 | + cacheModel := new(models.ArticleTag) | ||
| 108 | + cacheModel.Id = id | ||
| 109 | + if err = repository.QueryCache(cacheModel.CacheKeyFunc, m, queryFunc); err != nil { | ||
| 110 | + return nil, err | ||
| 111 | + } | ||
| 112 | + return repository.ModelToDomainModel(m) | ||
| 113 | +} | ||
| 114 | + | ||
| 115 | +func (repository *ArticleTagRepository) Find(ctx context.Context, conn transaction.Conn, companyId int64, queryOptions map[string]interface{}) (int64, []*domain.ArticleTag, error) { | ||
| 116 | + var ( | ||
| 117 | + tx = conn.DB() | ||
| 118 | + ms []*models.ArticleTag | ||
| 119 | + dms = make([]*domain.ArticleTag, 0) | ||
| 120 | + total int64 | ||
| 121 | + ) | ||
| 122 | + queryFunc := func() (interface{}, error) { | ||
| 123 | + tx = tx.Model(&ms). | ||
| 124 | + Where("company_id=?", companyId). | ||
| 125 | + Order("id desc") | ||
| 126 | + | ||
| 127 | + if v, ok := queryOptions["name"]; ok { | ||
| 128 | + tx.Where("id like ?", v) | ||
| 129 | + } | ||
| 130 | + if v, ok := queryOptions["group"]; ok { | ||
| 131 | + tx.Where("group like ?", v) | ||
| 132 | + } | ||
| 133 | + | ||
| 134 | + if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil { | ||
| 135 | + return dms, tx.Error | ||
| 136 | + } | ||
| 137 | + return dms, nil | ||
| 138 | + } | ||
| 139 | + | ||
| 140 | + if _, err := repository.Query(queryFunc); err != nil { | ||
| 141 | + return 0, nil, err | ||
| 142 | + } | ||
| 143 | + | ||
| 144 | + for _, item := range ms { | ||
| 145 | + if dm, err := repository.ModelToDomainModel(item); err != nil { | ||
| 146 | + return 0, dms, err | ||
| 147 | + } else { | ||
| 148 | + dms = append(dms, dm) | ||
| 149 | + } | ||
| 150 | + } | ||
| 151 | + return total, dms, nil | ||
| 152 | +} | ||
| 153 | + | ||
| 154 | +func (repository *ArticleTagRepository) ModelToDomainModel(from *models.ArticleTag) (*domain.ArticleTag, error) { | ||
| 155 | + to := &domain.ArticleTag{} | ||
| 156 | + err := copier.Copy(to, from) | ||
| 157 | + return to, err | ||
| 158 | +} | ||
| 159 | + | ||
| 160 | +func (repository *ArticleTagRepository) DomainModelToModel(from *domain.ArticleTag) (*models.ArticleTag, error) { | ||
| 161 | + to := &models.ArticleTag{} | ||
| 162 | + err := copier.Copy(to, from) | ||
| 163 | + return to, err | ||
| 164 | +} | ||
| 165 | + | ||
| 166 | +func NewArticleTagRepository(cache *cache.CachedRepository) domain.ArticleTagRepository { | ||
| 167 | + return &ArticleTagRepository{CachedRepository: cache} | ||
| 168 | +} |
| @@ -120,7 +120,7 @@ func (repository *MessageSystemRepository) Find(ctx context.Context, conn transa | @@ -120,7 +120,7 @@ func (repository *MessageSystemRepository) Find(ctx context.Context, conn transa | ||
| 120 | total int64 | 120 | total int64 |
| 121 | ) | 121 | ) |
| 122 | queryFunc := func() (interface{}, error) { | 122 | queryFunc := func() (interface{}, error) { |
| 123 | - tx = tx.Model(&ms).Order("id desc") | 123 | + tx = tx.Model(&ms).Order("created_at desc") // 创建时间降序 |
| 124 | if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil { | 124 | if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil { |
| 125 | return dms, tx.Error | 125 | return dms, tx.Error |
| 126 | } | 126 | } |
| @@ -24,7 +24,6 @@ type Article struct { | @@ -24,7 +24,6 @@ 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 | - Tags []int `json:"tags"` // 标签 | ||
| 28 | Show ArticleShow `json:"showState"` // 评论的展示状态(0显示、1不显示) | 27 | Show ArticleShow `json:"showState"` // 评论的展示状态(0显示、1不显示) |
| 29 | // ...more | 28 | // ...more |
| 30 | } | 29 | } |
| @@ -26,5 +26,5 @@ type ArticleTagRepository interface { | @@ -26,5 +26,5 @@ type ArticleTagRepository interface { | ||
| 26 | Delete(ctx context.Context, conn transaction.Conn, dm *ArticleTag) (*ArticleTag, error) | 26 | Delete(ctx context.Context, conn transaction.Conn, dm *ArticleTag) (*ArticleTag, error) |
| 27 | UpdateWithVersion(ctx context.Context, conn transaction.Conn, dm *ArticleTag) (*ArticleTag, error) | 27 | UpdateWithVersion(ctx context.Context, conn transaction.Conn, dm *ArticleTag) (*ArticleTag, error) |
| 28 | FindOne(ctx context.Context, conn transaction.Conn, id int64) (*ArticleTag, error) | 28 | FindOne(ctx context.Context, conn transaction.Conn, id int64) (*ArticleTag, error) |
| 29 | - Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*ArticleTag, error) | 29 | + Find(ctx context.Context, conn transaction.Conn, companyId int64, queryOptions map[string]interface{}) (int64, []*ArticleTag, error) |
| 30 | } | 30 | } |
| @@ -21,8 +21,8 @@ type MessageSystem struct { | @@ -21,8 +21,8 @@ type MessageSystem struct { | ||
| 21 | type MsgSystemType int | 21 | type MsgSystemType int |
| 22 | 22 | ||
| 23 | const ( | 23 | const ( |
| 24 | - MsgTypeNormal MsgSystemType = 0 | ||
| 25 | - MsgTypeAbnormal MsgSystemType = 1 | 24 | + MsgTypeNormal MsgSystemType = 1 |
| 25 | + MsgTypeAbnormal MsgSystemType = 2 | ||
| 26 | ) | 26 | ) |
| 27 | 27 | ||
| 28 | type MessageSystemRepository interface { | 28 | type MessageSystemRepository interface { |
-
请 注册 或 登录 后发表评论