作者 yangfu
正在显示 30 个修改的文件 包含 1362 行增加174 行删除
... ... @@ -2,4 +2,5 @@ import "core/comment.api"
import "core/message.api"
import "core/article_tag.api"
import "core/user.api"
import "core/company.api"
\ No newline at end of file
import "core/company.api"
import "core/article.api"
\ No newline at end of file
... ...
... ... @@ -15,6 +15,119 @@
"application/json"
],
"paths": {
"v1/mini/article_tag": {
"delete": {
"summary": "后台删除文章标签",
"operationId": "DeleteTag",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/TagDeleteResponse"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/TagDeleteRequest"
}
}
],
"requestBody": {},
"tags": [
"tags"
]
},
"post": {
"summary": "后台创建文章标签",
"operationId": "CreateTag",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/TagCreateResponse"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/TagCreateRequest"
}
}
],
"requestBody": {},
"tags": [
"tags"
]
},
"put": {
"summary": "后台编辑文章标签",
"operationId": "EditTag",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/TagEditResponse"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/TagEditRequest"
}
}
],
"requestBody": {},
"tags": [
"tags"
]
}
},
"v1/mini/article_tag/{id}": {
"get": {
"summary": "后台获取文章标签",
"operationId": "GetTag",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/TagGetResponse"
}
}
},
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"type": "string"
},
{
"name": "id",
"in": "query",
"required": true,
"type": "integer",
"format": "int64"
}
],
"requestBody": {},
"tags": [
"tags"
]
}
},
"v1/mini/comment": {
"get": {
"summary": "小程序评论",
... ... @@ -97,7 +210,7 @@
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/MessageBusinessResponse"
"$ref": "#/definitions/MessageSystemResponse"
}
}
},
... ... @@ -589,11 +702,6 @@
"type": "integer",
"format": "int64"
},
"companyId": {
"type": "integer",
"format": "int64",
"description": " 公司ID"
},
"type": {
"type": "integer",
"format": "int32",
... ... @@ -604,10 +712,15 @@
"format": "int32",
"description": " 操作类型(1针对文章、1针对评论、2针对圆桌)"
},
"triggerId": {
"companyId": {
"type": "integer",
"format": "int64",
"description": " 操作人公司ID"
},
"userId": {
"type": "integer",
"format": "int64",
"description": " 触发者ID"
"description": " 操作人用户ID"
},
"recipientId": {
"type": "integer",
... ... @@ -643,18 +756,26 @@
"format": "int64",
"description": " 创建时间"
},
"userTrigger": {
"user": {
"$ref": "#/definitions/User",
"description": " 触发者"
"description": " 操作人"
},
"article": {
"$ref": "#/definitions/SimpleArticle",
"description": " 文章"
},
"comment": {
"$ref": "#/definitions/Comment",
"description": " 评论(不一定是自己,可能是被人@到)"
}
},
"title": "MessageBusinessItem",
"required": [
"id",
"companyId",
"type",
"optType",
"triggerId",
"companyId",
"userId",
"recipientId",
"articleId",
"commentId",
... ... @@ -662,12 +783,18 @@
"discussionOpinionId",
"content",
"createdAt",
"userTrigger"
"user",
"article",
"comment"
]
},
"MessageBusinessRequest": {
"type": "object",
"properties": {
"type": {
"type": "integer",
"format": "int32"
},
"page": {
"type": "integer",
"format": "int32"
... ... @@ -679,6 +806,7 @@
},
"title": "MessageBusinessRequest",
"required": [
"type",
"page",
"size"
]
... ... @@ -723,6 +851,11 @@
"content": {
"type": "string",
"description": " 内容"
},
"createdAt": {
"type": "integer",
"format": "int64",
"description": " 创建时间"
}
},
"title": "MessageSystemItem",
... ... @@ -730,7 +863,8 @@
"id",
"type",
"title",
"content"
"content",
"createdAt"
]
},
"MessageSystemRequest": {
... ... @@ -938,6 +1072,277 @@
"success"
]
},
"SimpleArticle": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"title": {
"type": "string",
"description": " 文章标题"
},
"countLove": {
"type": "integer",
"format": "int32",
"description": " 点赞数量"
},
"countComment": {
"type": "integer",
"format": "int32",
"description": " 评论数量"
}
},
"title": "SimpleArticle",
"required": [
"id",
"title",
"countLove",
"countComment"
]
},
"TagCreateRequest": {
"type": "object",
"properties": {
"companyId": {
"type": "integer",
"format": "int64"
},
"image": {
"type": "string"
},
"name": {
"type": "string",
"description": " 标签名称"
},
"group": {
"type": "string",
"description": " 标签分类"
},
"remark": {
"type": "string",
"description": " 备注"
}
},
"title": "TagCreateRequest",
"required": [
"companyId",
"image",
"name",
"group",
"remark"
]
},
"TagCreateResponse": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
}
},
"title": "TagCreateResponse",
"required": [
"id"
]
},
"TagDeleteRequest": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
}
},
"title": "TagDeleteRequest",
"required": [
"id"
]
},
"TagDeleteResponse": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
}
},
"title": "TagDeleteResponse",
"required": [
"id"
]
},
"TagEditRequest": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"companyId": {
"type": "integer",
"format": "int64"
},
"image": {
"type": "string"
},
"name": {
"type": "string",
"description": " 标签名称"
},
"group": {
"type": "string",
"description": " 标签分类"
},
"remark": {
"type": "string",
"description": " 备注"
}
},
"title": "TagEditRequest",
"required": [
"id",
"companyId",
"image",
"name",
"group",
"remark"
]
},
"TagEditResponse": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
}
},
"title": "TagEditResponse",
"required": [
"id"
]
},
"TagGetRequest": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
}
},
"title": "TagGetRequest",
"required": [
"id"
]
},
"TagGetResponse": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"image": {
"type": "string"
},
"name": {
"type": "string",
"description": " 标签名称"
},
"group": {
"type": "string",
"description": " 标签分类"
},
"remark": {
"type": "string",
"description": " 备注"
}
},
"title": "TagGetResponse",
"required": [
"id",
"image",
"name",
"group",
"remark"
]
},
"TagItem": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"image": {
"type": "string"
},
"name": {
"type": "string",
"description": " 标签名称"
},
"group": {
"type": "string",
"description": " 标签分类"
},
"remark": {
"type": "string",
"description": " 备注"
},
"createdAt": {
"type": "integer",
"format": "int64"
}
},
"title": "TagItem",
"required": [
"id",
"image",
"name",
"group",
"remark",
"createdAt"
]
},
"TagListRequest": {
"type": "object",
"properties": {
"page": {
"type": "integer",
"format": "int32"
},
"size": {
"type": "integer",
"format": "int32"
}
},
"title": "TagListRequest",
"required": [
"page",
"size"
]
},
"TagListResponse": {
"type": "object",
"properties": {
"total": {
"type": "integer",
"format": "int32"
},
"list": {
"type": "array",
"items": {
"$ref": "#/definitions/TagItem"
}
}
},
"title": "TagListResponse",
"required": [
"total",
"list"
]
},
"User": {
"type": "object",
"properties": {
... ... @@ -950,10 +1355,9 @@
"format": "int64",
"description": " 公司ID"
},
"departmentId": {
"type": "integer",
"format": "int64",
"description": " 部门ID"
"companyName": {
"type": "string",
"description": " 公司名称"
},
"name": {
"type": "string",
... ... @@ -972,7 +1376,7 @@
"required": [
"id",
"companyId",
"departmentId",
"companyName",
"name",
"avatar",
"position"
... ...
... ... @@ -10,9 +10,9 @@ info(
// 坐标地点描述
type Location {
Longitude float64 `json:"longitude"` //经度
Latitude float64 `json:"latitude"` //纬度
Descript string `json:"descript"` //地点描述
Longitude float64 `json:"longitude,optional"` //经度
Latitude float64 `json:"latitude,optional"` //纬度
Descript string `json:"descript,optional"` //地点描述
}
// 人员的简单展示信息
... ... @@ -24,36 +24,36 @@ type Author {
Position string `json:"position"` // 职位
}
// 创建发布文章
//小程序端创建发布文章
type (
ArticleCreateRequest {
Title string `json:"title"` //标题
Section []string `json:"section"` //文章的文本内容
AuthorId int `json:"authorId"` //发布人id
Images []string `json:"images"` //图片
WhoRead []int `json:"whoRead"` //谁可查看
WhoReview []int `json:"whoReview"` //谁可评论
Location Location `json:"location"` //定位坐标
MiniArticleCreateRequest {
Title string `json:"title"` //标题
Section []string `json:"section"` //文章的文本内容
AuthorId int64 `json:"authorId,optional"` //发布人id
Images []string `json:"images,optional"` //图片
WhoRead []int64 `json:"whoRead,optional"` //谁可查看
WhoReview []int64 `json:"whoReview,optional"` //谁可评论
Location Location `json:"location,optional"` //定位坐标
}
ArticleCreateResponse {
MiniArticleCreateResponse {
Id int64 `json:"id"`
}
)
// 查看文章的详情
//小程序端查看文章的详情
type (
ArticleGetRequest {
Id int64 `json:"id"` //id
MiniArticleGetRequest {
Id int64 `path:"id"` //id
}
ArticleGetResponse {
MiniArticleGetResponse {
Title string `json:"title"` //标题
AuthorId int `json:"authorId"` //发布人id
Author Author `json:"author"` //发布人
CreatedAt int64 `json:"createdAt"` //文章的发布时间
Section []string `json:"section"` //文章的文本内容
Images []string `json:"images"` //图片
WhoRead []int `json:"whoRead"` //谁可查看
WhoReview []int `json:"whoReview"` //谁可评论
WhoRead []int64 `json:"whoRead"` //谁可查看
WhoReview []int64 `json:"whoReview"` //谁可评论
Location Location `json:"location"` //定位坐标
CountLove int `json:"countLove"` // 点赞数量
CountComment int `json:"countComment"` // 评论数量
... ... @@ -61,6 +61,31 @@ type (
}
)
// 获取我的发文章记录
type (
MiniArticleSearchMeRequest {
AuthorId int64 `json:"-"`
CompanyId int64 `json:"-"`
Page int `json:"page"`
Size int `json:"size"`
}
MiniArticleSearchMeResponse {
Total int `json:"total"`
List []ArticleSearchMe `json:"list"`
}
ArticleSearchMe {
Id int64 `json:"id"` //id
Title string `json:"title"` //标题
Images []string `json:"images"` //图片
CreatedAt int64 `json:"createdAt"` //文章的创建日期
CountLove int `json:"countLove"` //点赞数量
CountComment int `json:"CountComment"` //评论数量
Show int `json:"show"` //是否隐藏 [0显示、1不显示]
}
)
// 小程序接口
@server(
prefix: v1/mini
... ... @@ -69,9 +94,12 @@ type (
)
service Core {
@doc "小程序创建发布内容"
@handler CreateArticle
post /article (ArticleCreateRequest) returns (ArticleCreateResponse)
@handler MiniCreateArticle
post /article (MiniArticleCreateRequest) returns (MiniArticleCreateResponse)
@doc "小程序获取我发布的文章"
@handler MiniArticleSearchMe
post /article/search/me (MiniArticleSearchMeRequest) returns (MiniArticleSearchMeResponse)
@doc "小程序获取文章内容详情"
@handler GetArticle
get /article/:id (ArticleGetRequest) returns (ArticleGetResponse)
@handler MiniGetArticle
get /article/:id (MiniArticleGetRequest) returns (MiniArticleGetResponse)
}
\ No newline at end of file
... ...
... ... @@ -13,9 +13,9 @@ type (
TagCreateRequest {
CompanyId int64 `json:"companyId"`
Image string `json:"image"`
Name string `json:"name"` // 标签名称
Group string `json:"group"` // 标签分类
Remark string `json:"remark"` // 备注
Name string `json:"name"` // 标签名称
Group string `json:"group"` // 标签分类
Remark string `json:"remark,optional"` // 备注
}
TagCreateResponse {
... ... @@ -27,11 +27,11 @@ type (
type (
TagEditRequest {
Id int64 `json:"id"`
CompanyId int64 `json:"companyId"`
CompanyId int64 `json:"-"`
Image string `json:"image"`
Name string `json:"name"` // 标签名称
Group string `json:"group"` // 标签分类
Remark string `json:"remark"` // 备注
Name string `json:"name"` // 标签名称
Group string `json:"group"` // 标签分类
Remark string `json:"remark,optional"` // 备注
}
TagEditResponse {
... ... @@ -42,7 +42,8 @@ type (
// 获取标签详情
type (
TagGetRequest {
Id int64 `json:"id"`
Id int64 `path:"id"`
CompanyId int64 `path:"-"`
}
TagGetResponse {
Id int64 `json:"id"`
... ... @@ -56,11 +57,15 @@ type (
//标签列表
type (
TagListRequest {
Page int `json:"page"`
Size int `json:"size"`
Page int `json:"page"`
Size int `json:"size"`
CompanyId int64 `json:"-"`
TagName string `json:"tagName,optional"`
Group string `json:"group,optional"`
Remark string `json:"remark,optional"`
}
TagListResponse {
Total int `json:"total"`
Total int64 `json:"total"`
List []TagItem `json:"list"`
}
TagItem {
... ... @@ -76,7 +81,8 @@ type (
//删除标签
type (
TagDeleteRequest {
Id int64 `json:"id"`
Id int64 `path:"id"`
CompanyId int64 `path:"-"`
}
TagDeleteResponse {
Id int64 `json:"id"`
... ... @@ -84,7 +90,7 @@ type (
)
@server(
prefix: v1/mini
prefix: v1/system
group: tags
jwt: MiniAuth
)
... ... @@ -92,13 +98,20 @@ service Core {
@doc "后台创建文章标签"
@handler CreateTag
post /article_tag (TagCreateRequest) returns (TagCreateResponse)
@doc "后台编辑文章标签"
@handler EditTag
put /article_tag (TagEditRequest) returns (TagEditResponse)
@doc "后台获取文章标签"
@handler GetTag
get /article_tag/:id (TagGetRequest) returns (TagGetResponse)
@doc "后台删除文章标签"
@handler DeleteTag
delete /article_tag (TagDeleteRequest) returns (TagDeleteResponse)
delete /article_tag/:id (TagDeleteRequest) returns (TagDeleteResponse)
@doc "后台搜索标签"
@handler SearchTag
post/article_tag/search (TagListRequest) returns (TagListResponse)
}
\ No newline at end of file
... ...
package article
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/article"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
)
func MiniArticleSearchMeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniArticleSearchMeRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := article.NewMiniArticleSearchMeLogic(r.Context(), svcCtx)
token := contextdata.GetUserTokenFromCtx(r.Context())
req.AuthorId = token.UserId
req.CompanyId = token.CompanyId
resp, err := l.MiniArticleSearchMe(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
package article
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/article"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
)
func MiniCreateArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniArticleCreateRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
token := contextdata.GetUserTokenFromCtx(r.Context())
l := article.NewMiniCreateArticleLogic(r.Context(), svcCtx)
req.AuthorId = token.UserId
resp, err := l.MiniCreateArticle(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
package article
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/article"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
)
func MiniGetArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniArticleGetRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := article.NewMiniGetArticleLogic(r.Context(), svcCtx)
resp, err := l.MiniGetArticle(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
... ... @@ -4,6 +4,7 @@ package handler
import (
"net/http"
article "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/handler/article"
comment "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/handler/comment"
company "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/handler/company"
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) {
},
{
Method: http.MethodDelete,
Path: "/article_tag",
Path: "/article_tag/:id",
Handler: tags.DeleteTagHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/article_tag/search",
Handler: tags.SearchTagHandler(serverCtx),
},
},
rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret),
rest.WithPrefix("/v1/mini"),
rest.WithPrefix("/v1/system"),
)
server.AddRoutes(
... ... @@ -168,4 +174,26 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
rest.WithJwt(serverCtx.Config.SystemAuth.AccessSecret),
rest.WithPrefix("/v1"),
)
server.AddRoutes(
[]rest.Route{
{
Method: http.MethodPost,
Path: "/article",
Handler: article.MiniCreateArticleHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/article/search/me",
Handler: article.MiniArticleSearchMeHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/article/:id",
Handler: article.MiniGetArticleHandler(serverCtx),
},
},
rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret),
rest.WithPrefix("/v1/mini"),
)
}
... ...
package tags
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/tags"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
)
func SearchTagHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.TagListRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := tags.NewSearchTagLogic(r.Context(), svcCtx)
resp, err := l.SearchTag(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
package article
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"github.com/zeromicro/go-zero/core/logx"
)
type MiniArticleSearchMeLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewMiniArticleSearchMeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniArticleSearchMeLogic {
return &MiniArticleSearchMeLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
// MiniArticleSearchMe 获取我发布的文章
func (l *MiniArticleSearchMeLogic) MiniArticleSearchMe(req *types.MiniArticleSearchMeRequest) (resp *types.MiniArticleSearchMeResponse, err error) {
var conn = l.svcCtx.DefaultDBConn()
queryOptions := domain.NewQueryOptions().
WithOffsetLimit(req.Page, req.Size).
MustWithKV("authorId", req.AuthorId)
cnt, articleList, err := l.svcCtx.ArticleRepository.Find(l.ctx, conn, req.CompanyId, queryOptions)
if err != nil {
return &types.MiniArticleSearchMeResponse{}, xerr.NewErrMsgErr("获取文章列表失败", err)
}
resp = &types.MiniArticleSearchMeResponse{
Total: int(cnt),
List: make([]types.ArticleSearchMe, len(articleList)),
}
for i := range articleList {
images := []string{}
for _, val2 := range articleList[i].Images {
images = append(images, val2.Url)
}
resp.List[i] = types.ArticleSearchMe{
Id: articleList[i].Id,
Title: articleList[i].Title,
Images: images,
CreatedAt: articleList[i].CreatedAt,
CountLove: articleList[i].CountLove,
CountComment: articleList[i].CountComment,
Show: int(articleList[i].Show),
}
}
return
}
... ...
package article
import (
"context"
"strings"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"github.com/samber/lo"
"github.com/zeromicro/go-zero/core/logx"
)
type MiniCreateArticleLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewMiniCreateArticleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniCreateArticleLogic {
return &MiniCreateArticleLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateRequest) (resp *types.MiniArticleCreateResponse, err error) {
var conn = l.svcCtx.DefaultDBConn()
// 检查发布人
author, err := l.svcCtx.UserRepository.FindOne(l.ctx, conn, req.AuthorId)
if err != nil {
return nil, xerr.NewErrMsgErr("创建文章内容失败", err)
}
//TODO 获取人员信息
articleAuthor := domain.UserSimple{
Id: author.Id,
Name: author.Name,
Avatar: author.Avatar,
GroupId: 0,
Group: "",
Position: author.Position,
Company: "",
CompanyId: author.CompanyId,
}
//TODO 获取图片的尺寸大小
images := []domain.Image{}
for _, val := range req.Images {
images = append(images, domain.Image{
Url: val,
Width: 0,
Height: 0,
})
}
//检查文章可被哪些人查看
whoRead := []int64{}
if len(req.WhoRead) > 0 {
whoRead = lo.Uniq(req.WhoRead)
var u *domain.User
for _, val := range whoRead {
u, err = l.svcCtx.UserRepository.FindOne(l.ctx, conn, val)
if err != nil {
return nil, xerr.NewErrMsgErr("文章可查看人设置错误", err)
}
if u.CompanyId != author.CompanyId {
return nil, xerr.NewErrMsg("文章可查看人设置错误")
}
}
}
//检查文章可被哪些人评论
whoReview := []int64{}
//有指定可查看人的情况
if len(whoRead) > 0 {
if len(whoReview) > 0 {
whoReview = lo.Uniq(req.WhoReview)
// 检查 whoRead 是否 完全包含 whoReview
ok := lo.Every(whoRead, whoReview)
if !ok {
return nil, xerr.NewErrMsg("文章可评论人设置错误")
}
}
if len(whoReview) == 0 {
//有指定可查看人 ,但未指定可评论人
return nil, xerr.NewErrMsg("文章可评论人设置错误")
}
}
//没有指定可查看人的情况
if len(whoRead) == 0 {
if len(whoReview) > 0 {
// 未指定可查看人(全员可看),有指定可评论人,
var u *domain.User
for _, val := range whoReview {
u, err = l.svcCtx.UserRepository.FindOne(l.ctx, conn, val)
if err != nil {
return nil, xerr.NewErrMsgErr("文章可评论人设置错误", err)
}
if u.CompanyId != author.CompanyId {
return nil, xerr.NewErrMsg("文章可评论人设置错误")
}
}
}
// if len(whoReview) == 0 {
// 未指定可查看人(全员可看),未指定可评论人 ,忽略判断
// }
}
//切分文章分段
sectionList := []domain.ArticleSection{}
for i := range req.Section {
strList := strings.Split(req.Section[i], "\n")
for i2 := range strList {
newStr := strings.TrimSpace(strList[i2])
if len(newStr) == 0 {
continue
}
newSection := domain.ArticleSection{
Id: 0,
CompanyId: author.CompanyId,
ArticleId: 0,
Content: newStr,
SortBy: len(sectionList),
TotalComment: 0,
}
sectionList = append(sectionList, newSection)
}
}
newArticle := &domain.Article{
Id: 0,
CompanyId: author.CompanyId,
AuthorId: author.Id,
Author: articleAuthor,
Title: req.Title,
Images: images,
WhoRead: whoRead,
WhoReview: whoReview,
Location: domain.Location{
Longitude: req.Location.Latitude,
Latitude: req.Location.Latitude,
Descript: req.Location.Descript,
},
TargetUser: domain.ArticleTargetAll,
}
if len(whoRead) > 0 {
newArticle.TargetUser = domain.ArticleTargetLimit
}
err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error {
newArticle, err = l.svcCtx.ArticleRepository.Insert(ctx, c, newArticle)
if err != nil {
return xerr.NewErrMsgErr("创建文章失败", err)
}
for i := range sectionList {
sectionList[i].ArticleId = newArticle.Id
_, err = l.svcCtx.ArticleSectionRepository.Insert(ctx, c, &sectionList[i])
if err != nil {
return xerr.NewErrMsgErr("创建文章内容失败", err)
}
}
// 设置保存备份
backup := newArticle.MakeBackup(newArticle.Author, sectionList)
backup.Action = "新增"
_, err = l.svcCtx.ArticleBackupRepository.Insert(ctx, c, backup)
if err != nil {
return xerr.NewErrMsgErr("创建文章内容失败", err)
}
return nil
}, true)
if err != nil {
return nil, xerr.NewErrMsgErr("创建文章失败", err)
}
resp = &types.MiniArticleCreateResponse{
Id: newArticle.Id,
}
return
}
... ...
package article
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type MiniGetArticleLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewMiniGetArticleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniGetArticleLogic {
return &MiniGetArticleLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *MiniGetArticleLogic) MiniGetArticle(req *types.MiniArticleGetRequest) (resp *types.MiniArticleGetResponse, err error) {
// todo: add your logic here and delete this line
return
}
... ...
... ... @@ -2,10 +2,12 @@ package message
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
"github.com/zeromicro/go-zero/core/logx"
)
... ... @@ -25,9 +27,11 @@ func NewMiniBusinessLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Mini
}
func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (resp *types.MessageBusinessResponse, err error) {
var userToken = contextdata.GetUserTokenFromCtx(l.ctx)
var conn = l.svcCtx.DefaultDBConn()
var msgType = req.Type
total, list, err := l.svcCtx.MessageBusinessRepository.Find(l.ctx, l.svcCtx.DefaultDBConn(), domain.NewQueryOptions().
total, list, err := l.svcCtx.MessageBusinessRepository.Find(l.ctx, conn, domain.NewQueryOptions().
WithOffsetLimit(req.Page, req.Size).
WithKV("type", msgType))
if err != nil {
... ... @@ -94,11 +98,10 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (res
// 获取公司
if len(companyIds) > 0 {
_, companyList, err := l.svcCtx.CompanyRepository.Find(l.ctx, l.svcCtx.DefaultDBConn(),
domain.NewQueryOptions().
WithFindOnly().
WithKV("ids", userIds).
WithKV("limit", len(userIds)))
_, companyList, err := l.svcCtx.CompanyRepository.Find(l.ctx, conn, domain.NewQueryOptions().
WithFindOnly().
WithKV("ids", userIds).
WithKV("limit", len(userIds)))
if err != nil {
return nil, err
}
... ... @@ -109,11 +112,10 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (res
// 获取用户
if len(userIds) > 0 {
_, userList, err := l.svcCtx.UserRepository.Find(l.ctx, l.svcCtx.DefaultDBConn(),
domain.NewQueryOptions().
WithFindOnly().
WithKV("ids", userIds).
WithKV("limit", len(userIds)))
_, userList, err := l.svcCtx.UserRepository.Find(l.ctx, conn, domain.NewQueryOptions().
WithFindOnly().
WithKV("ids", userIds).
WithKV("limit", len(userIds)))
if err != nil {
return nil, err
}
... ... @@ -124,11 +126,10 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (res
// 获取评论
if len(commentIds) > 0 {
_, commentList, err := l.svcCtx.CommentRepository.Find(l.ctx, l.svcCtx.DefaultDBConn(),
domain.NewQueryOptions().
WithFindOnly().
WithKV("ids", commentIds).
WithKV("limit", len(commentIds)))
_, commentList, err := l.svcCtx.CommentRepository.Find(l.ctx, conn, domain.NewQueryOptions().
WithFindOnly().
WithKV("ids", commentIds).
WithKV("limit", len(commentIds)))
if err != nil {
return nil, err
}
... ... @@ -137,38 +138,34 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (res
}
}
// 只有这个才需要
if msgType == int(domain.MsgTypeReply) || msgType == int(domain.MsgTypeLike) {
// 获取文章数据
if len(articleIds) > 0 {
_, articleList, err := l.svcCtx.ArticleRepository.Find(l.ctx, l.svcCtx.DefaultDBConn(),
domain.NewQueryOptions().
WithFindOnly().
WithKV("ids", articleIds).
WithKV("limit", len(articleIds)))
if err != nil {
return nil, err
}
for i := range articleList {
articleIdMap[articleList[i].Id] = articleList[i]
}
// 获取文章数据
if len(articleIds) > 0 {
_, articleList, err := l.svcCtx.ArticleRepository.Find(l.ctx, conn, userToken.CompanyId, domain.NewQueryOptions().
WithFindOnly().
WithKV("ids", articleIds).
WithKV("limit", len(articleIds)))
if err != nil {
return nil, err
}
for i := range articleList {
articleIdMap[articleList[i].Id] = articleList[i]
}
}
for _, item := range list {
to := types.MessageBusinessItem{
Id: item.Id,
Type: item.Type,
OptType: item.OptType,
CompanyId: item.CompanyId,
UserId: item.UserId,
RecipientId: item.RecipientId,
ArticleId: item.ArticleId,
CommentId: item.CommentId,
DiscussionId: item.DiscussionId,
DiscussionOpinionId: item.DiscussionOpinionId,
Content: item.Content,
CreatedAt: item.CreatedAt,
Id: item.Id,
Type: int(item.Type),
OptType: int(item.OptType),
CompanyId: item.CompanyId,
UserId: item.UserId,
RecipientId: item.RecipientId,
ArticleId: item.ArticleId,
CommentId: item.CommentId,
//DiscussionId: item.DiscussionId,
//DiscussionOpinionId: item.DiscussionOpinionId,
Content: item.Content,
CreatedAt: item.CreatedAt,
}
if v, ok := userIdMap[item.UserId]; ok {
... ... @@ -177,6 +174,7 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (res
CompanyId: v.CompanyId,
Position: v.Position,
Name: v.Name,
Avatar: v.Avatar,
}
if v, ok := companyIdMap[item.CompanyId]; ok {
... ... @@ -206,3 +204,53 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (res
}
return resp, nil
}
// CommentArticle 评论文章
func (l *MiniBusinessLogic) CommentArticle(conn transaction.Conn, articleId int64, content string, at []int64) (err error) {
return l.submit(conn, domain.MsgTypeReply, domain.OptTypeArticle, articleId, 0, content, at)
}
// CommentReply 评论回复
func (l *MiniBusinessLogic) CommentReply(conn transaction.Conn, articleId int64, commentId int64, content string, at []int64) (err error) {
return l.submit(conn, domain.MsgTypeReply, domain.OptTypeComment, articleId, commentId, content, at)
}
// LikeArticle 点赞文章
func (l *MiniBusinessLogic) LikeArticle(conn transaction.Conn, articleId int64, at int64) (err error) {
return l.submit(conn, domain.MsgTypeLike, domain.OptTypeArticle, articleId, 0, "", []int64{at})
}
// LikeComment 点赞评论
func (l *MiniBusinessLogic) LikeComment(conn transaction.Conn, articleId int64, commentId int64, at int64) (err error) {
return l.submit(conn, domain.MsgTypeLike, domain.OptTypeComment, articleId, commentId, "", []int64{at})
}
func (l *MiniBusinessLogic) submit(
conn transaction.Conn,
msgType domain.MsgBusinessType,
optType domain.MsgBusinessOpt,
articleId int64,
commentId int64,
content string,
at []int64) (err error) {
var userToken = contextdata.GetUserTokenFromCtx(l.ctx)
// 评论中携带了 @其他用户
for i := range at {
var msg = &domain.MessageBusiness{
Type: msgType,
OptType: optType,
CompanyId: userToken.CompanyId,
UserId: userToken.UserId,
RecipientId: at[i],
ArticleId: articleId,
CommentId: commentId,
Content: content,
}
msg, err = l.svcCtx.MessageBusinessRepository.Insert(l.ctx, conn, msg)
if err != nil {
return err
}
}
return nil
}
... ...
... ... @@ -6,6 +6,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"github.com/zeromicro/go-zero/core/logx"
... ... @@ -25,8 +26,8 @@ func NewCreateTagLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateT
}
}
// 创建标签
func (l *CreateTagLogic) CreateTag(req *types.TagCreateRequest) (resp *types.TagCreateResponse, err error) {
// todo: add your logic here and delete this line
var conn = l.svcCtx.DefaultDBConn()
//检查重复
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
if cnt > 0 {
return nil, xerr.NewErrMsg(fmt.Sprintf("已存在标签 分类[%s]名称[%s]", req.Group, req.Name))
}
//TODO 获取图片的尺寸大小
newTag := &domain.ArticleTag{
Id: 0,
CompanyId: req.CompanyId,
CreatedAt: 0,
UpdatedAt: 0,
DeletedAt: 0,
Version: 0,
Image: domain.Image{
Url: req.Image,
Width: 0,
Height: 0,
},
Name: req.Name,
Group: req.Group,
Remark: req.Remark,
}
newTag, err = l.svcCtx.ArticleTagRepository.Insert(l.ctx, conn, newTag)
if err != nil {
return nil, xerr.NewErrMsgErr("添加标签失败", err)
}
resp = &types.TagCreateResponse{Id: newTag.Id}
return
}
... ...
... ... @@ -5,6 +5,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"github.com/zeromicro/go-zero/core/logx"
)
... ... @@ -24,7 +25,18 @@ func NewDeleteTagLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteT
}
func (l *DeleteTagLogic) DeleteTag(req *types.TagDeleteRequest) (resp *types.TagDeleteResponse, err error) {
// todo: add your logic here and delete this line
var conn = l.svcCtx.DefaultDBConn()
oldTag, err := l.svcCtx.ArticleTagRepository.FindOne(l.ctx, conn, req.Id)
if err != nil {
return nil, xerr.NewErrMsgErr("不存在待修改的标签", err)
}
if oldTag.CompanyId != req.CompanyId {
return nil, xerr.NewErrMsg("删除标签失败")
}
_, err = l.svcCtx.ArticleTagRepository.Delete(l.ctx, conn, oldTag)
if err != nil {
return nil, xerr.NewErrMsg("删除标签失败")
}
resp = &types.TagDeleteResponse{Id: oldTag.Id}
return
}
... ...
... ... @@ -2,9 +2,12 @@ package tags
import (
"context"
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"github.com/zeromicro/go-zero/core/logx"
)
... ... @@ -23,8 +26,44 @@ func NewEditTagLogic(ctx context.Context, svcCtx *svc.ServiceContext) *EditTagLo
}
}
// 编辑标签
func (l *EditTagLogic) EditTag(req *types.TagEditRequest) (resp *types.TagEditResponse, err error) {
// todo: add your logic here and delete this line
var conn = l.svcCtx.DefaultDBConn()
//检查重复
queryOptions := domain.NewQueryOptions().
WithFindOnly().
MustWithKV("name", req.Name).
MustWithKV("group", req.Group).
WithOffsetLimit(1, 1)
_, tagList, err := l.svcCtx.ArticleTagRepository.Find(l.ctx, conn, req.CompanyId, queryOptions)
if err != nil {
return nil, xerr.NewErrMsgErr("修改标签失败", err)
}
if len(tagList) > 0 {
if tagList[0].Id != req.Id {
return nil, xerr.NewErrMsg(fmt.Sprintf("已存在标签 分类[%s]名称[%s]", req.Group, req.Name))
}
}
oldTag, err := l.svcCtx.ArticleTagRepository.FindOne(l.ctx, conn, req.Id)
if err != nil {
return nil, xerr.NewErrMsgErr("不存在待修改的标签", err)
}
if oldTag.CompanyId != req.CompanyId {
return nil, xerr.NewErrMsg("修改标签失败")
}
//TODO 获取图片的尺寸大小
oldTag.Group = req.Group
oldTag.Image.Url = req.Image
oldTag.Name = req.Name
oldTag.Remark = req.Remark
oldTag, err = l.svcCtx.ArticleTagRepository.Update(l.ctx, conn, oldTag)
if err != nil {
return nil, xerr.NewErrMsgErr("添加标签失败", err)
}
resp = &types.TagEditResponse{Id: oldTag.Id}
return
}
... ...
... ... @@ -5,6 +5,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"github.com/zeromicro/go-zero/core/logx"
)
... ... @@ -23,8 +24,22 @@ func NewGetTagLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetTagLogi
}
}
// 获取详情
func (l *GetTagLogic) GetTag(req *types.TagGetRequest) (resp *types.TagGetResponse, err error) {
// todo: add your logic here and delete this line
var conn = l.svcCtx.DefaultDBConn()
oldTag, err := l.svcCtx.ArticleTagRepository.FindOne(l.ctx, conn, req.Id)
if err != nil {
return nil, xerr.NewErrMsgErr("不存在的标签", err)
}
if oldTag.CompanyId != req.CompanyId {
return nil, xerr.NewErrMsg("获取标签失败")
}
resp = &types.TagGetResponse{
Id: oldTag.Id,
Image: oldTag.Image.Url,
Name: oldTag.Name,
Group: oldTag.Group,
Remark: oldTag.Remark,
}
return
}
... ...
package tags
import (
"context"
"github.com/zeromicro/go-zero/core/logx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
)
type SearchTagLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSearchTagLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SearchTagLogic {
return &SearchTagLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *SearchTagLogic) SearchTag(req *types.TagListRequest) (resp *types.TagListResponse, err error) {
var conn = l.svcCtx.DefaultDBConn()
queryOptions := domain.NewQueryOptions().WithOffsetLimit(req.Page, req.Size)
if len(req.Group) > 0 {
queryOptions = queryOptions.MustWithKV("group", req.Group)
}
if len(req.TagName) > 0 {
queryOptions = queryOptions.MustWithKV("name", req.TagName)
}
if len(req.Remark) > 0 {
queryOptions = queryOptions.MustWithKV("remark", "%"+req.Remark+"%")
}
cnt, tagList, err := l.svcCtx.ArticleTagRepository.Find(l.ctx, conn, req.CompanyId, queryOptions)
if err != nil {
return &types.TagListResponse{}, nil
}
resp = &types.TagListResponse{
Total: cnt,
List: make([]types.TagItem, len(tagList)),
}
for i := range tagList {
resp.List[i] = types.TagItem{
Id: tagList[i].Id,
Image: tagList[i].Image.Url,
Name: tagList[i].Name,
Group: tagList[i].Group,
Remark: tagList[i].Remark,
CreatedAt: tagList[i].CreatedAt,
}
}
return
}
... ...
... ... @@ -77,9 +77,9 @@ type SimpleArticle struct {
type TagCreateRequest struct {
CompanyId int64 `json:"companyId"`
Image string `json:"image"`
Name string `json:"name"` // 标签名称
Group string `json:"group"` // 标签分类
Remark string `json:"remark"` // 备注
Name string `json:"name"` // 标签名称
Group string `json:"group"` // 标签分类
Remark string `json:"remark,optional"` // 备注
}
type TagCreateResponse struct {
... ... @@ -88,11 +88,11 @@ type TagCreateResponse struct {
type TagEditRequest struct {
Id int64 `json:"id"`
CompanyId int64 `json:"companyId"`
CompanyId int64 `json:"-"`
Image string `json:"image"`
Name string `json:"name"` // 标签名称
Group string `json:"group"` // 标签分类
Remark string `json:"remark"` // 备注
Name string `json:"name"` // 标签名称
Group string `json:"group"` // 标签分类
Remark string `json:"remark,optional"` // 备注
}
type TagEditResponse struct {
... ... @@ -100,7 +100,8 @@ type TagEditResponse struct {
}
type TagGetRequest struct {
Id int64 `json:"id"`
Id int64 `path:"id"`
CompanyId int64 `path:"-"`
}
type TagGetResponse struct {
... ... @@ -112,12 +113,16 @@ type TagGetResponse struct {
}
type TagListRequest struct {
Page int `json:"page"`
Size int `json:"size"`
Page int `json:"page"`
Size int `json:"size"`
CompanyId int64 `json:"-"`
TagName string `json:"tagName,optional"`
Group string `json:"group,optional"`
Remark string `json:"remark,optional"`
}
type TagListResponse struct {
Total int `json:"total"`
Total int64 `json:"total"`
List []TagItem `json:"list"`
}
... ... @@ -131,7 +136,8 @@ type TagItem struct {
}
type TagDeleteRequest struct {
Id int64 `json:"id"`
Id int64 `path:"id"`
CompanyId int64 `path:"-"`
}
type TagDeleteResponse struct {
... ... @@ -263,3 +269,72 @@ type Company struct {
Code string `json:"code,omitempty"` // 编码(搜索使用,4位字母数字)
Logo string `json:"logo,omitempty"` // 公司LOGO
}
type Location struct {
Longitude float64 `json:"longitude,optional"` //经度
Latitude float64 `json:"latitude,optional"` //纬度
Descript string `json:"descript,optional"` //地点描述
}
type Author struct {
Id int64 `json:"id"` // 人员id
Name string `json:"name"` // 人员的名字
Avatar string `json:"avatar"` // 人员头像URL
Group string `json:"group"` // 人员的分组
Position string `json:"position"` // 职位
}
type MiniArticleCreateRequest struct {
Title string `json:"title"` //标题
Section []string `json:"section"` //文章的文本内容
AuthorId int64 `json:"authorId,optional"` //发布人id
Images []string `json:"images,optional"` //图片
WhoRead []int64 `json:"whoRead,optional"` //谁可查看
WhoReview []int64 `json:"whoReview,optional"` //谁可评论
Location Location `json:"location,optional"` //定位坐标
}
type MiniArticleCreateResponse struct {
Id int64 `json:"id"`
}
type MiniArticleGetRequest struct {
Id int64 `path:"id"` //id
}
type MiniArticleGetResponse struct {
Title string `json:"title"` //标题
AuthorId int `json:"authorId"` //发布人id
Author Author `json:"author"` //发布人
CreatedAt int64 `json:"createdAt"` //文章的发布时间
Section []string `json:"section"` //文章的文本内容
Images []string `json:"images"` //图片
WhoRead []int64 `json:"whoRead"` //谁可查看
WhoReview []int64 `json:"whoReview"` //谁可评论
Location Location `json:"location"` //定位坐标
CountLove int `json:"countLove"` // 点赞数量
CountComment int `json:"countComment"` // 评论数量
Show int `json:"showState"` // 评论的展示状态(0显示、1不显示)
}
type MiniArticleSearchMeRequest struct {
AuthorId int64 `json:"-"`
CompanyId int64 `json:"-"`
Page int `json:"page"`
Size int `json:"size"`
}
type MiniArticleSearchMeResponse struct {
Total int `json:"total"`
List []ArticleSearchMe `json:"list"`
}
type ArticleSearchMe struct {
Id int64 `json:"id"` //id
Title string `json:"title"` //标题
Images []string `json:"images"` //图片
CreatedAt int64 `json:"createdAt"` //文章的创建日期
CountLove int `json:"countLove"` //点赞数量
CountComment int `json:"CountComment"` //评论数量
Show int `json:"show"` //是否隐藏 [0显示、1不显示]
}
... ...
... ... @@ -26,7 +26,9 @@ type Article struct {
Location domain.Location `gorm:"type:jsonb;serializer:json"` // 坐标
TargetUser int // 分发方式 0 分发给所有人 1 分发给指定的人
CountLove int // 点赞数量
CountRead int // 浏览数量
CountComment int // 评论数量
Tags []int64 `gorm:"type:jsonb;serializer:json"` //定性标签
Show int // 评论的展示状态(0显示、1不显示)
}
... ... @@ -35,8 +37,9 @@ func (m *Article) TableName() string {
}
func (m *Article) BeforeCreate(tx *gorm.DB) (err error) {
m.CreatedAt = time.Now().Unix()
m.UpdatedAt = time.Now().Unix()
nowTime := time.Now().Unix()
m.CreatedAt = nowTime
m.UpdatedAt = nowTime
return
}
... ...
... ... @@ -24,7 +24,7 @@ type ArticleBackup struct {
Action string // 操作
WhoRead []int64 `gorm:"type:jsonb;serializer:json"` // 谁可以看
WhoReview []int64 `gorm:"type:jsonb;serializer:json"` // 评论人
Tags []int `gorm:"type:jsonb;serializer:json"` // 标签
Tags []int64 `gorm:"type:jsonb;serializer:json"` // 标签
TargetUser int // 分发方式 0 分发给所有人 1 分发给指定的人
}
... ...
... ... @@ -10,22 +10,22 @@ import (
// MessageBusiness 消息中心业务
type MessageBusiness struct {
Id int64 // 唯一标识
Type int `json:"type"` // 分类 (1回复 2点赞 3被采纳)
OptType int `json:"optType"` // 操作类型(1针对文章、1针对评论、2针对圆桌)
CompanyId int64 `json:"companyId"` // 操作人公司ID
UserId int64 `json:"userId"` // 操作人用户ID
RecipientId int64 `json:"recipientId"` // 接收人用户ID
ArticleId int64 `json:"articleId"` // 文章ID
CommentId int64 `json:"commentId,omitempty"` // 评论ID
DiscussionId int64 `json:"discussionId,omitempty"` // 圆桌ID
DiscussionOpinionId int64 `json:"discussionOpinionId,omitempty"` // 观点ID
Content string `json:"content,omitempty"` // 消息内容
CreatedAt int64 `json:",omitempty"`
UpdatedAt int64 `json:",omitempty"`
DeletedAt int64 `json:",omitempty"`
Version int `json:",omitempty"`
IsDel soft_delete.DeletedAt `gorm:"softDelete:flag,DeletedAtField:DeletedAt"`
Id int64 // 唯一标识
Type int `json:"type"` // 分类 (1回复 2点赞 3被采纳)
OptType int `json:"optType"` // 操作类型(1针对文章、1针对评论、2针对圆桌)
CompanyId int64 `json:"companyId"` // 操作人公司ID
UserId int64 `json:"userId"` // 操作人用户ID
RecipientId int64 `json:"recipientId"` // 接收人用户ID
ArticleId int64 `json:"articleId,omitempty"` // 文章ID
CommentId int64 `json:"commentId,omitempty"` // 评论ID
Content string `json:"content,omitempty"` // 消息内容
CreatedAt int64 `json:",omitempty"`
UpdatedAt int64 `json:",omitempty"`
DeletedAt int64 `json:",omitempty"`
Version int `json:",omitempty"`
IsDel soft_delete.DeletedAt `gorm:"softDelete:flag,DeletedAtField:DeletedAt"`
//DiscussionId int64 `json:"discussionId,omitempty"` // 圆桌ID
//DiscussionOpinionId int64 `json:"discussionOpinionId,omitempty"` // 观点ID
}
func (m *MessageBusiness) TableName() string {
... ...
... ... @@ -111,7 +111,7 @@ func (repository *ArticleRepository) FindOne(ctx context.Context, conn transacti
return repository.ModelToDomainModel(m)
}
func (repository *ArticleRepository) Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*domain.Article, error) {
func (repository *ArticleRepository) Find(ctx context.Context, conn transaction.Conn, companyId int64, queryOptions map[string]interface{}) (int64, []*domain.Article, error) {
var (
tx = conn.DB()
ms []*models.Article
... ... @@ -119,10 +119,15 @@ func (repository *ArticleRepository) Find(ctx context.Context, conn transaction.
total int64
)
queryFunc := func() (interface{}, error) {
tx = tx.Model(&ms).Order("id desc")
tx = tx.Model(&ms).Order("id desc").Where("company_id=?", companyId)
if v, ok := queryOptions["ids"]; ok {
tx.Where("id in (?)", v)
}
if v, ok := queryOptions["authorId"]; ok {
tx = tx.Where("author_id = ?", v)
}
if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
return dms, tx.Error
}
... ... @@ -161,6 +166,7 @@ func (repository *ArticleRepository) ModelToDomainModel(from *models.Article) (*
TargetUser: domain.ArticleTarget(from.TargetUser),
CountLove: from.CountLove,
CountComment: from.CountComment,
CountRead: from.CountRead,
Show: domain.ArticleShow(from.Show),
}
return to, nil
... ... @@ -173,6 +179,7 @@ func (repository *ArticleRepository) DomainModelToModel(from *domain.Article) (*
CreatedAt: from.CreatedAt,
UpdatedAt: from.UpdatedAt,
DeletedAt: from.DeletedAt,
IsDel: 0,
Version: from.Version,
AuthorId: from.AuthorId,
Author: from.Author,
... ... @@ -183,6 +190,7 @@ func (repository *ArticleRepository) DomainModelToModel(from *domain.Article) (*
Location: from.Location,
TargetUser: int(from.TargetUser),
CountLove: from.CountLove,
CountRead: from.CountRead,
CountComment: from.CountComment,
Show: int(from.Show),
}
... ...
... ... @@ -125,10 +125,10 @@ func (repository *ArticleTagRepository) Find(ctx context.Context, conn transacti
Order("id desc")
if v, ok := queryOptions["name"]; ok {
tx.Where("id like ?", v)
tx = tx.Where("name like ?", v)
}
if v, ok := queryOptions["group"]; ok {
tx.Where("group like ?", v)
tx = tx.Where("group like ?", v)
}
if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
... ...
... ... @@ -121,6 +121,9 @@ func (repository *MessageBusinessRepository) Find(ctx context.Context, conn tran
)
queryFunc := func() (interface{}, error) {
tx = tx.Model(&ms).Order("created_at desc")
if v, ok := queryOptions["companyId"]; ok {
tx.Where("company_id = ?", v)
}
if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
return dms, tx.Error
}
... ...
... ... @@ -24,10 +24,21 @@ type Article struct {
TargetUser ArticleTarget `json:"targetUser"` // 分发方式 0 分发给所有人 1 分发给指定的人
CountLove int `json:"countLove"` // 点赞数量
CountComment int `json:"countComment"` // 评论数量
Show ArticleShow `json:"showState"` // 评论的展示状态(0显示、1不显示)
CountRead int `json:"countRead"` // 浏览数量
Show ArticleShow `json:"show"` // 评论的展示状态(0显示、1不显示)
Tags []int64 `json:"tags"` // 定性标签
// ...more
}
type ArticleRepository interface {
Insert(ctx context.Context, conn transaction.Conn, dm *Article) (*Article, error)
Update(ctx context.Context, conn transaction.Conn, dm *Article) (*Article, error)
Delete(ctx context.Context, conn transaction.Conn, dm *Article) (*Article, error)
UpdateWithVersion(ctx context.Context, conn transaction.Conn, dm *Article) (*Article, error)
FindOne(ctx context.Context, conn transaction.Conn, id int64) (*Article, error)
Find(ctx context.Context, conn transaction.Conn, companyId int64, queryOptions map[string]interface{}) (int64, []*Article, error)
}
type ArticleTarget int
const (
... ... @@ -63,11 +74,24 @@ func (a ArticleShow) Named() string {
return ""
}
type ArticleRepository interface {
Insert(ctx context.Context, conn transaction.Conn, dm *Article) (*Article, error)
Update(ctx context.Context, conn transaction.Conn, dm *Article) (*Article, error)
Delete(ctx context.Context, conn transaction.Conn, dm *Article) (*Article, error)
UpdateWithVersion(ctx context.Context, conn transaction.Conn, dm *Article) (*Article, error)
FindOne(ctx context.Context, conn transaction.Conn, id int64) (*Article, error)
Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*Article, error)
// 设置文章的备份数据
func (m *Article) MakeBackup(operator UserSimple, section []ArticleSection) *ArticleBackup {
b := ArticleBackup{
Id: 0,
CompanyId: 0,
CreatedAt: 0,
UpdatedAt: 0,
DeletedAt: 0,
Version: 0,
Operator: operator,
Title: m.Title,
Section: section,
Images: m.Images,
Action: "",
TargetUser: m.TargetUser,
WhoRead: m.WhoRead,
WhoReview: m.WhoReview,
Tags: m.Tags,
}
return &b
}
... ...
... ... @@ -22,7 +22,7 @@ type ArticleBackup struct {
TargetUser ArticleTarget `json:"targetUser"` // 分发方式 0 分发给所有人 1 分发给指定的人
WhoRead []int64 `json:"whoRead"` // 谁可以看
WhoReview []int64 `json:"whoReview"` // 评论人
Tags []int `json:"tags"` // 标签
Tags []int64 `json:"tags"` // 标签
}
type ArticleBackupRepository interface {
... ...
... ... @@ -28,3 +28,10 @@ type ArticleSectionRepository interface {
FindOne(ctx context.Context, conn transaction.Conn, id int64) (*ArticleSection, error)
Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*ArticleSection, error)
}
// 排序文章分段列表
type SortArticleSection []*ArticleSection
func (a SortArticleSection) Len() int { return len(a) }
func (a SortArticleSection) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a SortArticleSection) Less(i, j int) bool { return a[i].SortBy < a[j].SortBy }
... ...
... ... @@ -6,28 +6,29 @@ import (
)
type MessageBusiness struct {
Id int64 // 唯一标识
Type int `json:"type"` // 分类 (1回复 2点赞 3被采纳)
OptType int `json:"optType"` // 操作类型(1针对文章、1针对评论、2针对圆桌)
CompanyId int64 `json:"companyId"` // 操作人公司ID
UserId int64 `json:"userId"` // 操作人用户ID
RecipientId int64 `json:"recipientId"` // 接收人用户ID
ArticleId int64 `json:"articleId"` // 文章ID
CommentId int64 `json:"commentId"` // 评论ID
DiscussionId int64 `json:"discussionId"` // 圆桌ID
DiscussionOpinionId int64 `json:"discussionOpinionId"` // 观点ID
Content string `json:"content"` // 消息内容
CreatedAt int64 `json:",omitempty"`
UpdatedAt int64 `json:",omitempty"`
DeletedAt int64 `json:",omitempty"`
Version int `json:",omitempty"`
Id int64 // 唯一标识
Type MsgBusinessType `json:"type"` // 分类 (1回复 2点赞 3被采纳)
OptType MsgBusinessOpt `json:"optType"` // 操作类型(1针对文章、1针对评论、2针对圆桌)
CompanyId int64 `json:"companyId"` // 操作人公司ID
UserId int64 `json:"userId"` // 操作人用户ID
RecipientId int64 `json:"recipientId"` // 接收人用户ID
ArticleId int64 `json:"articleId"` // 文章ID
CommentId int64 `json:"commentId"` // 评论ID
Content string `json:"content"` // 消息内容
CreatedAt int64 `json:",omitempty"`
UpdatedAt int64 `json:",omitempty"`
DeletedAt int64 `json:",omitempty"`
Version int `json:",omitempty"`
//DiscussionId int64 `json:"discussionId"` // 圆桌ID
//DiscussionOpinionId int64 `json:"discussionOpinionId"` // 观点ID
}
type MsgBusinessType int
type MsgBusinessOpt int
const (
MsgTypeReply MsgBusinessType = 1 // 消息分类-回复
MsgTypeReply MsgBusinessType = 1 // 消息分类-评论
MsgTypeLike MsgBusinessType = 2 // 消息分类-点赞
MsgTypeAccept MsgBusinessType = 3 // 消息分类-被采纳
)
... ...
... ... @@ -29,9 +29,12 @@ type Opinion struct {
}
type UserSimple struct {
Id int64 `json:"id"` // 人员id
Name string `json:"name"` // 人员的名字
Avatar string `json:"avatar,omitempty"` // 人员头像URL
Group string `json:"group,omitempty"` // 人员的分组
Position string `json:"position,omitempty"` // 职位
Id int64 `json:"id"` // 人员id
Name string `json:"name"` // 人员的名字
Avatar string `json:"avatar,omitempty"` // 人员头像URL
GroupId int64 `json:"groupId,omitempty"`
Group string `json:"group,omitempty"` // 人员的分组
Position string `json:"position,omitempty"` // 职位
Company string `json:"company,omitempty"` // 公司
CompanyId int64 `json:"companyId"`
}
... ...