作者 tangxvhui
... ... @@ -631,22 +631,6 @@
"required": false,
"type": "integer",
"format": "int64"
},
{
"name": "articleId",
"description": " 文章id",
"in": "query",
"required": true,
"type": "integer",
"format": "int64"
},
{
"name": "tagId",
"description": " 标签id",
"in": "query",
"required": true,
"type": "integer",
"format": "int64"
}
],
"requestBody": {},
... ... @@ -1211,6 +1195,64 @@
]
}
},
"v1/system/article": {
"put": {
"summary": "管理后台编辑帖子",
"operationId": "SystemUpdateArticle",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/SystemArticleUpdateResponse"
}
}
},
"parameters": [
{
"name": "body",
"description": "编辑",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/SystemArticleUpdateRequest"
}
}
],
"requestBody": {},
"tags": [
"article"
]
}
},
"v1/system/article/history": {
"post": {
"summary": "管理后台编辑历史",
"operationId": "SystemHistoryArticle",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/SystemArticleHistoryResponse"
}
}
},
"parameters": [
{
"name": "body",
"description": "历史",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/SystemArticleHistoryRequest"
}
}
],
"requestBody": {},
"tags": [
"article"
]
}
},
"v1/system/article/search": {
"post": {
"summary": "管理后台获取文章列表",
... ... @@ -2240,6 +2282,25 @@
"totalComment"
]
},
"ArticleTagGroup": {
"type": "object",
"properties": {
"group": {
"type": "string"
},
"tags": {
"type": "array",
"items": {
"$ref": "#/definitions/ArticleTagItem"
}
}
},
"title": "ArticleTagGroup",
"required": [
"group",
"tags"
]
},
"ArticleTagItem": {
"type": "object",
"properties": {
... ... @@ -2252,13 +2313,17 @@
},
"name": {
"type": "string"
},
"image": {
"type": "string"
}
},
"title": "ArticleTagItem",
"required": [
"id",
"group",
"name"
"name",
"image"
]
},
"Auth": {
... ... @@ -2294,6 +2359,9 @@
},
"name": {
"type": "string"
},
"firstLetter": {
"type": "string"
}
},
"title": "CommentAtWho",
... ... @@ -2806,23 +2874,9 @@
"type": "integer",
"format": "int64",
"description": " 公司id"
},
"articleId": {
"type": "integer",
"format": "int64",
"description": " 文章id"
},
"tagId": {
"type": "integer",
"format": "int64",
"description": " 标签id"
}
},
"title": "MiniAllArticleTagRequest",
"required": [
"articleId",
"tagId"
]
"title": "MiniAllArticleTagRequest"
},
"MiniAllArticleTagResponse": {
"type": "object",
... ... @@ -2830,20 +2884,13 @@
"tagGroup": {
"type": "array",
"items": {
"type": "string"
}
},
"tags": {
"type": "array",
"items": {
"$ref": "#/definitions/ArticleTagItem"
"$ref": "#/definitions/ArticleTagGroup"
}
}
},
"title": "MiniAllArticleTagResponse",
"required": [
"tagGroup",
"tags"
"tagGroup"
]
},
"MiniArticleBackupItem": {
... ... @@ -5022,6 +5069,57 @@
"show"
]
},
"SystemArticleHistoryRequest": {
"type": "object",
"properties": {
"articleId": {
"type": "integer",
"format": "int64",
"description": "文章ID"
},
"author": {
"type": "string",
"description": "发布人"
},
"updatedAt": {
"type": "string",
"description": "修改日期"
}
},
"title": "SystemArticleHistoryRequest",
"required": [
"articleId"
]
},
"SystemArticleHistoryResponse": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64",
"description": "id"
},
"author": {
"type": "string",
"description": "编辑人"
},
"action": {
"type": "string",
"description": "编辑类型"
},
"updatedAt": {
"type": "string",
"description": "编辑时间"
}
},
"title": "SystemArticleHistoryResponse",
"required": [
"id",
"author",
"action",
"updatedAt"
]
},
"SystemArticleSearch": {
"type": "object",
"properties": {
... ... @@ -5149,23 +5247,37 @@
"SystemArticleSearchRequest": {
"type": "object",
"properties": {
"": {
"companyId": {
"type": "integer",
"format": "int64"
},
"page": {
"title": {
"type": "string",
"description": "标题"
},
"author": {
"type": "string",
"description": "发布人"
},
"publishDate": {
"type": "string",
"description": "发布日期"
},
"pageNumber": {
"type": "integer",
"format": "int32"
"format": "int32",
"description": "页码"
},
"size": {
"pageSize": {
"type": "integer",
"format": "int32"
"format": "int32",
"description": "每页行数"
}
},
"title": "SystemArticleSearchRequest",
"required": [
"page",
"size"
"pageNumber",
"pageSize"
]
},
"SystemArticleSearchResponse": {
... ... @@ -5188,6 +5300,149 @@
"list"
]
},
"SystemArticleUpdateRequest": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"companyId": {
"type": "integer",
"format": "int64"
},
"template": {
"type": "integer",
"format": "int32",
"description": " 使用哪个模板进行编辑 0、无 1、演绎式 2、归纳式"
},
"section": {
"type": "array",
"items": {
"$ref": "#/definitions/ArticleSection"
},
"description": " 填写的内容"
},
"title": {
"type": "string",
"description": " 标题"
},
"images": {
"type": "array",
"items": {
"type": "string"
},
"description": " 图片"
},
"whoRead": {
"type": "array",
"items": {
"type": "integer",
"format": "int64"
},
"description": " 谁可以看"
},
"whoReview": {
"type": "array",
"items": {
"type": "integer",
"format": "int64"
},
"description": " 评论人"
},
"location": {
"$ref": "#/definitions/Location",
"description": " 坐标"
},
"targetUser": {
"type": "integer",
"format": "int32",
"description": "分发方式 [0分发给所有人、1分发给指定的人]"
}
},
"title": "SystemArticleUpdateRequest",
"required": [
"id",
"template",
"section",
"title",
"images",
"whoRead",
"whoReview",
"location",
"targetUser"
]
},
"SystemArticleUpdateResponse": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64",
"description": "id"
},
"title": {
"type": "string",
"description": "标题"
},
"author": {
"type": "string",
"description": "发布人"
},
"images": {
"type": "array",
"items": {
"type": "string"
},
"description": "图片"
},
"createdAt": {
"type": "integer",
"format": "int64",
"description": "文章的创建日期"
},
"countLove": {
"type": "integer",
"format": "int32",
"description": "点赞数量"
},
"CountComment": {
"type": "integer",
"format": "int32",
"description": "评论数量"
},
"show": {
"type": "integer",
"format": "int32",
"description": "是否隐藏 [0显示、1不显示]"
},
"tags": {
"type": "array",
"items": {
"type": "string"
},
"description": "标签"
},
"targetUser": {
"type": "integer",
"format": "int32",
"description": "分发方式 [0分发给所有人、1分发给指定的人]"
}
},
"title": "SystemArticleUpdateResponse",
"required": [
"id",
"title",
"author",
"images",
"createdAt",
"countLove",
"CountComment",
"show",
"tags",
"targetUser"
]
},
"SystemUser": {
"type": "object",
"properties": {
... ... @@ -5608,7 +5863,7 @@
"TagCreateRequest": {
"type": "object",
"properties": {
"companyId": {
"": {
"type": "integer",
"format": "int64"
},
... ... @@ -5619,21 +5874,24 @@
"type": "string",
"description": " 标签名称"
},
"group": {
"category": {
"type": "string",
"description": " 标签分类"
},
"remark": {
"type": "string",
"description": " 备注"
},
"other": {
"type": "string"
}
},
"title": "TagCreateRequest",
"required": [
"companyId",
"image",
"name",
"group"
"category",
"other"
]
},
"TagCreateResponse": {
... ... @@ -5656,15 +5914,14 @@
"type": "integer",
"format": "int64"
},
"companyId": {
"": {
"type": "integer",
"format": "int64"
}
},
"title": "TagDeleteRequest",
"required": [
"id",
"-"
"id"
]
},
"TagDeleteResponse": {
... ... @@ -5687,7 +5944,7 @@
"type": "integer",
"format": "int64"
},
"companyId": {
"": {
"type": "integer",
"format": "int64"
},
... ... @@ -5698,22 +5955,25 @@
"type": "string",
"description": " 标签名称"
},
"group": {
"category": {
"type": "string",
"description": " 标签分类"
},
"remark": {
"type": "string",
"description": " 备注"
},
"other": {
"type": "string"
}
},
"title": "TagEditRequest",
"required": [
"id",
"-",
"image",
"name",
"group"
"category",
"other"
]
},
"TagEditResponse": {
... ... @@ -5736,15 +5996,14 @@
"type": "integer",
"format": "int64"
},
"companyId": {
"": {
"type": "integer",
"format": "int64"
}
},
"title": "TagGetRequest",
"required": [
"id",
"-"
"id"
]
},
"TagGetResponse": {
... ... @@ -5761,13 +6020,16 @@
"type": "string",
"description": " 标签名称"
},
"group": {
"category": {
"type": "string",
"description": " 标签分类"
},
"remark": {
"type": "string",
"description": " 备注"
},
"other": {
"type": "string"
}
},
"title": "TagGetResponse",
... ... @@ -5775,8 +6037,9 @@
"id",
"image",
"name",
"group",
"remark"
"category",
"remark",
"other"
]
},
"TagItem": {
... ... @@ -5793,7 +6056,7 @@
"type": "string",
"description": " 标签名称"
},
"group": {
"category": {
"type": "string",
"description": " 标签分类"
},
... ... @@ -5811,7 +6074,7 @@
"id",
"image",
"name",
"group",
"category",
"remark",
"createdAt"
]
... ... @@ -5827,14 +6090,14 @@
"type": "integer",
"format": "int32"
},
"companyId": {
"": {
"type": "integer",
"format": "int64"
},
"tagName": {
"type": "string"
},
"group": {
"category": {
"type": "string"
},
"remark": {
... ... @@ -5844,8 +6107,7 @@
"title": "TagListRequest",
"required": [
"page",
"size",
"-"
"size"
]
},
"TagListResponse": {
... ... @@ -6054,8 +6316,7 @@
"format": "int32"
},
"name": {
"type": "integer",
"format": "int32"
"type": "string"
}
},
"title": "UserShowName",
... ... @@ -6126,6 +6387,10 @@
"type": "string",
"description": " 人员头像"
},
"position": {
"type": "string",
"description": " 职位"
},
"createdAt": {
"type": "integer",
"format": "int64",
... ... @@ -6138,6 +6403,7 @@
"userId",
"name",
"avatar",
"position",
"createdAt"
]
}
... ...
... ... @@ -89,7 +89,16 @@ service Core {
@handler SystemSearchArticle
post /article/search (SystemArticleSearchRequest) returns (SystemArticleSearchResponse)
@doc "管理后台编辑帖子"
@handler SystemUpdateArticle
put /article (SystemArticleUpdateRequest) returns (SystemArticleUpdateResponse)
@doc "管理后台编辑历史"
@handler SystemHistoryArticle
post /article/history (SystemArticleHistoryRequest) returns (SystemArticleHistoryResponse)
@doc "管理后台获取我发布的文章"
@handler SystemArticleSearchMe
post /article/search/me (SystemArticleSearchMeRequest) returns (SystemArticleSearchMeResponse)
}
\ No newline at end of file
... ...
... ... @@ -337,7 +337,7 @@ type (
UserShowName {
Id int `json:"id"`
Name int `json:"name"`
Name string `json:"name"`
}
SystemArticleGetResponse {
... ... @@ -363,9 +363,12 @@ type (
//管理后台获取文章列表
type (
SystemArticleSearchRequest {
CompanyId int64 `json:",optional"`
Page int `json:"page"`
Size int `json:"size"`
CompanyId int64 `json:"companyId,optional"`
Title string `json:"title,optional"` //标题
Author string `json:"author,optional"` //发布人
PublishDate string `json:"publishDate,optional"` //发布日期
PageNumber int `json:"pageNumber"` //页码
PageSize int `json:"pageSize"` //每页行数
}
SystemArticleSearchResponse {
... ... @@ -384,4 +387,41 @@ type (
Tags []string `json:"tags"` //标签
TargetUser int `json:"targetUser"` //分发方式 [0分发给所有人、1分发给指定的人]
}
//编辑
SystemArticleUpdateRequest {
Id int64 `json:"id"`
CompanyId int64 `json:"companyId,optional"`
Template int `json:"template"` // 使用哪个模板进行编辑 0、无 1、演绎式 2、归纳式
Section []ArticleSection `json:"section"` // 填写的内容
Title string `json:"title"` // 标题
Images []string `json:"images"` // 图片
WhoRead []int64 `json:"whoRead"` // 谁可以看
WhoReview []int64 `json:"whoReview"` // 评论人
Location Location `json:"location"` // 坐标
TargetUser int `json:"targetUser"` //分发方式 [0分发给所有人、1分发给指定的人]
}
SystemArticleUpdateResponse {
Id int64 `json:"id"` //id
Title string `json:"title"` //标题
Author string `json:"author"` //发布人
Images []string `json:"images"` //图片
CreatedAt int64 `json:"createdAt"` //文章的创建日期
CountLove int `json:"countLove"` //点赞数量
CountComment int `json:"CountComment"` //评论数量
Show int `json:"show"` //是否隐藏 [0显示、1不显示]
Tags []string `json:"tags"` //标签
TargetUser int `json:"targetUser"` //分发方式 [0分发给所有人、1分发给指定的人]
}
//历史
SystemArticleHistoryRequest {
ArticleId int64 `json:"articleId"` //文章ID
Author string `json:"author,optional"` //发布人
UpdatedAt string `json:"updatedAt,optional"` //修改日期
}
SystemArticleHistoryResponse {
Id int64 `json:"id"` //id
Author string `json:"author"` //编辑人
Action string `json:"action"` //编辑类型
UpdatedAt string `json:"updatedAt"` //编辑时间
}
)
\ No newline at end of file
... ...
... ... @@ -44,18 +44,18 @@ service Core {
}
type (
CompanySearchRequest struct{
CompanySearchRequest {
Page int `json:"page,optional"`
Size int `json:"size,optional"`
Flag int `json:"flag,optional"` // 1:用户已加入的 2:用户未加入的公司
UserId int64 `json:"userId,optional"` // 按用户搜索(用户所加入的企业)
Code string `json:"code,optional"` // 按编码搜索
}
CompanySearchResponse{
CompanySearchResponse {
List []Company `json:"list"`
Total int64 `json:"total"`
}
Company struct{
Company {
Id int64 `json:"id,omitempty"` // 唯一标识
Name string `json:"name,omitempty"` // 名称
Code string `json:"code,omitempty"` // 编码(搜索使用,4位字母数字)
... ...
... ... @@ -36,37 +36,37 @@ type (
RoleGetRequest {
Id int64 `path:"id"`
}
RoleGetResponse struct{
RoleGetResponse {
Role RoleItem `json:"role"`
AuthList []Auth `json:"authList"`
}
RoleSaveRequest struct{
RoleSaveRequest {
Role RoleItem `json:"role"`
}
RoleSaveResponse struct{}
RoleDeleteRequest struct{
RoleDeleteRequest {
Id int64 `path:"id"`
}
RoleDeleteResponse struct{}
RoleUpdateRequest struct{
RoleUpdateRequest {
Id int64 `path:"id"`
Role RoleItem `json:"role"`
}
RoleUpdateResponse struct{}
RoleSearchRequest struct{
RoleSearchRequest {
Page int `json:"page,optional"`
Size int `json:"size,optional"`
Style string `json:"style,options=[simple,,full]"` // simple:只返回角色ID名称 full:所有字段都返回
}
RoleSearchResponse{
RoleSearchResponse {
List []RoleItem `json:"list"`
Total int64 `json:"total"`
}
RoleItem struct{
RoleItem {
Id int64 `json:"id,optional"` // 角色ID
CompanyId int64 `json:"companyId,optional,omitempty"` // 公司ID
Name string `json:"name"` // 角色名称
... ...
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 SystemHistoryArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.SystemArticleHistoryRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := article.NewSystemHistoryArticleLogic(r.Context(), svcCtx)
resp, err := l.SystemHistoryArticle(&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 SystemUpdateArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.SystemArticleUpdateRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := article.NewSystemUpdateArticleLogic(r.Context(), svcCtx)
resp, err := l.SystemUpdateArticle(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
... ... @@ -382,6 +382,16 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Handler: article.SystemSearchArticleHandler(serverCtx),
},
{
Method: http.MethodPut,
Path: "/article",
Handler: article.SystemUpdateArticleHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/article/history",
Handler: article.SystemHistoryArticleHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/article/search/me",
Handler: article.SystemArticleSearchMeHandler(serverCtx),
... ...
... ... @@ -2,6 +2,9 @@ package article
import (
"context"
"github.com/samber/lo"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
... ... @@ -24,7 +27,79 @@ func NewSystemGetArticleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *
}
func (l *SystemGetArticleLogic) SystemGetArticle(req *types.SystemArticleGetRequest) (resp *types.SystemArticleGetResponse, err error) {
// todo: add your logic here and delete this line
return
var conn = l.svcCtx.DefaultDBConn()
article, err := l.svcCtx.ArticleRepository.FindOne(l.ctx, conn, req.Id)
if err != nil {
return nil, xerr.NewErrMsgErr("获取帖子异常", err)
}
images := make([]string, 0)
lo.ForEach(article.Images, func(img domain.Image, n int) {
images = append(images, img.Url)
})
resp = &types.SystemArticleGetResponse{
Id: article.Id,
Title: article.Title,
AuthorId: article.AuthorId,
Author: types.ArticleAuthor{
Id: article.Author.Id,
Name: article.Author.Name,
Avatar: article.Author.Avatar,
Position: article.Author.Position,
Company: article.Author.Company,
},
CreatedAt: article.CreatedAt,
Section: make([]types.ArticleSection, 0),
Images: images,
WhoRead: article.WhoRead,
WhoReadInfo: make([]types.UserShowName, 0),
WhoReview: article.WhoReview,
WhoReviewInfo: make([]types.UserShowName, 0),
Location: types.Location{
Longitude: article.Location.Longitude,
Latitude: article.Location.Latitude,
Descript: article.Location.Descript,
},
CountLove: article.CountLove,
CountComment: article.CountComment,
CountRead: article.CountRead,
Show: int(article.Show),
}
//文章段落
_, articleSections, err := l.svcCtx.ArticleSectionRepository.Find(l.ctx, conn, domain.NewQueryOptions().WithKV("articleId", req.Id))
if err != nil {
return nil, xerr.NewErrMsgErr("获取帖子异常", err)
}
lo.ForEach(articleSections, func(item *domain.ArticleSection, index int) {
resp.Section = append(resp.Section, types.ArticleSection{
Id: item.Id,
Content: item.Content,
SortBy: item.SortBy,
TotalComment: item.TotalComment,
})
})
userIds := lo.Union(resp.WhoRead, resp.WhoReview)
if len(userIds) > 0 {
_, users, err := l.svcCtx.UserRepository.Find(l.ctx, conn, domain.NewQueryOptions().WithKV("ids", userIds))
if err != nil {
return nil, xerr.NewErrMsgErr("获取帖子异常", err)
}
userSlices := make(map[int64]types.UserShowName)
lo.ForEach(users, func(user *domain.User, index int) {
userSlices[user.Id] = types.UserShowName{
Id: int(user.Id),
Name: user.Name,
}
})
lo.ForEach(resp.WhoRead, func(userId int64, index int) {
if value, ok := userSlices[userId]; ok {
resp.WhoReadInfo = append(resp.WhoReadInfo, value)
}
})
lo.ForEach(resp.WhoReview, func(userId int64, index int) {
if value, ok := userSlices[userId]; ok {
resp.WhoReviewInfo = append(resp.WhoReviewInfo, value)
}
})
}
return resp, nil
}
... ...
package article
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"
"github.com/zeromicro/go-zero/core/logx"
)
type SystemHistoryArticleLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSystemHistoryArticleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemHistoryArticleLogic {
return &SystemHistoryArticleLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *SystemHistoryArticleLogic) SystemHistoryArticle(req *types.SystemArticleHistoryRequest) (resp *types.SystemArticleHistoryResponse, err error) {
var conn = l.svcCtx.DefaultDBConn()
l.svcCtx.ArticleBackupRepository.Find(
l.ctx,
conn,
domain.NewQueryOptions().
WithKV("articleId", req.ArticleId).
WithKV("author", req.Author).
WithKV("updatedAt", req.UpdatedAt),
)
return
}
... ...
... ... @@ -2,6 +2,11 @@ package article
import (
"context"
"github.com/jinzhu/now"
"github.com/samber/lo"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"time"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
... ... @@ -24,7 +29,40 @@ func NewSystemSearchArticleLogic(ctx context.Context, svcCtx *svc.ServiceContext
}
func (l *SystemSearchArticleLogic) SystemSearchArticle(req *types.SystemArticleSearchRequest) (resp *types.SystemArticleSearchResponse, err error) {
// todo: add your logic here and delete this line
return
var conn = l.svcCtx.DefaultDBConn()
queryOptions := domain.NewQueryOptions().WithOffsetLimit(req.PageNumber, req.PageSize).WithKV("title", req.Title).WithKV("author", req.Author)
if req.PublishDate != "" {
publishTime, err := now.ParseInLocation(time.Local, req.PublishDate)
if err == nil {
queryOptions.WithKV("beginCreatedAt", now.With(publishTime).BeginningOfDay().Unix())
queryOptions.WithKV("endCreatedAt", now.With(publishTime).EndOfDay().Unix())
}
}
total, articles, err := l.svcCtx.ArticleRepository.Find(l.ctx, conn, req.CompanyId, queryOptions)
if err != nil {
return nil, xerr.NewErrMsgErr("搜索帖子异常", err)
}
resp = &types.SystemArticleSearchResponse{
Total: int(total),
List: make([]types.SystemArticleSearch, 0),
}
lo.ForEach(articles, func(item *domain.Article, index int) {
images := make([]string, 0)
lo.ForEach(item.Images, func(img domain.Image, n int) {
images = append(images, img.Url)
})
resp.List = append(resp.List, types.SystemArticleSearch{
Id: item.Id,
Title: item.Title,
Author: item.Author.Name,
Images: images,
CreatedAt: item.CreatedAt,
CountLove: item.CountLove,
CountComment: item.CountComment,
Show: int(item.Show),
Tags: nil,
TargetUser: int(item.TargetUser),
})
})
return resp, nil
}
... ...
package article
import (
"context"
"github.com/samber/lo"
"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"
"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 SystemUpdateArticleLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSystemUpdateArticleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemUpdateArticleLogic {
return &SystemUpdateArticleLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *SystemUpdateArticleLogic) SystemUpdateArticle(req *types.SystemArticleUpdateRequest) (resp *types.SystemArticleUpdateResponse, err error) {
var conn = l.svcCtx.DefaultDBConn()
article, err := l.svcCtx.ArticleRepository.FindOne(l.ctx, conn, req.Id)
if err != nil {
return nil, xerr.NewErrMsgErr("帖子不存在", err)
}
//TODO 获取图片的尺寸大小
images := []domain.Image{}
for _, val := range req.Images {
images = append(images, domain.Image{
Url: val,
Width: 0,
Height: 0,
})
}
article.Title = req.Title
article.Version = article.Version + 1
article.Images = images
article.WhoRead = req.WhoRead
article.WhoReview = req.WhoReview
article.TargetUser = domain.ArticleTarget(req.TargetUser)
article.Location = domain.Location{
Longitude: req.Location.Longitude,
Latitude: req.Location.Latitude,
Descript: req.Location.Descript,
}
//文章内容
articleSections := []domain.ArticleSection{}
lo.ForEach(req.Section, func(item types.ArticleSection, index int) {
articleSections = append(articleSections, domain.ArticleSection{
Id: item.Id,
CompanyId: article.CompanyId,
Version: article.Version,
ArticleId: article.Id,
Content: item.Content,
SortBy: index + 1,
})
})
//设置内容概要
if len(req.Section) > 0 {
// 截取内容 30个字
runeNumber := 0 //字数
stringIndex := 0 //字符串长度
for i := range req.Section[0].Content {
if runeNumber > 30 {
break
}
runeNumber += 1
stringIndex = i
}
article.Summary = req.Section[0].Content[0:stringIndex]
}
err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error {
_, err = l.svcCtx.ArticleRepository.Update(l.ctx, conn, article)
if err != nil {
return xerr.NewErrMsgErr("保存文章失败", err)
}
//文章内容
updateSectionIds := []int64{}
for _, item := range articleSections {
if item.Id > 0 {
section, err := l.svcCtx.ArticleSectionRepository.FindOne(ctx, c, item.Id)
if err != nil {
return xerr.NewErrMsgErr("获取文章段落内容失败", err)
}
section.Content = item.Content
section.ArticleId = item.ArticleId
section.Version = item.Version
section.SortBy = item.SortBy
section.CompanyId = item.CompanyId
_, err = l.svcCtx.ArticleSectionRepository.Update(ctx, c, section)
if err != nil {
return xerr.NewErrMsgErr("保存文章段落内容失败", err)
}
} else {
_, err = l.svcCtx.ArticleSectionRepository.Insert(ctx, c, &item)
if err != nil {
return xerr.NewErrMsgErr("保存文章段落内容失败", err)
}
}
updateSectionIds = append(updateSectionIds, item.Id)
}
if len(updateSectionIds) > 0 {
err = l.svcCtx.ArticleSectionRepository.DeleteBy(ctx, c, domain.NewQueryOptions().WithKV("articleId", article.Id).WithKV("notIds", updateSectionIds))
if err != nil {
return xerr.NewErrMsgErr("保存文章内容失败", err)
}
}
//备份数据
backup := article.MakeBackup(article.Author, articleSections)
backup.Action = "编辑"
_, err = l.svcCtx.ArticleBackupRepository.Insert(ctx, c, backup)
if err != nil {
return xerr.NewErrMsgErr("保存文章内容失败", err)
}
return nil
}, true)
return
}
... ...
... ... @@ -870,7 +870,7 @@ type SystemArticleGetRequest struct {
type UserShowName struct {
Id int `json:"id"`
Name int `json:"name"`
Name string `json:"name"`
}
type SystemArticleGetResponse struct {
... ... @@ -894,8 +894,11 @@ type SystemArticleGetResponse struct {
type SystemArticleSearchRequest struct {
CompanyId int64 `json:",optional"`
Page int `json:"page"`
Size int `json:"size"`
Title string `json:"title"` //标题
Author string `json:"author"` //发布人
PublishDate string `json:"publishDate"` //发布日期
PageNumber int `json:"pageNumber"` //页码
PageSize int `json:"pageSize"` //每页行数
}
type SystemArticleSearchResponse struct {
... ... @@ -916,6 +919,45 @@ type SystemArticleSearch struct {
TargetUser int `json:"targetUser"` //分发方式 [0分发给所有人、1分发给指定的人]
}
type SystemArticleUpdateRequest struct {
Id int64 `json:"id"`
CompanyId int64 `json:",optional"`
Template int `json:"template"` // 使用哪个模板进行编辑 0、无 1、演绎式 2、归纳式
Section []ArticleSection `json:"section"` // 填写的内容
Title string `json:"title"` // 标题
Images []string `json:"images"` // 图片
WhoRead []int64 `json:"whoRead"` // 谁可以看
WhoReview []int64 `json:"whoReview"` // 评论人
Location Location `json:"location"` // 坐标
TargetUser int `json:"targetUser"` //分发方式 [0分发给所有人、1分发给指定的人]
}
type SystemArticleUpdateResponse struct {
Id int64 `json:"id"` //id
Title string `json:"title"` //标题
Author string `json:"author"` //发布人
Images []string `json:"images"` //图片
CreatedAt int64 `json:"createdAt"` //文章的创建日期
CountLove int `json:"countLove"` //点赞数量
CountComment int `json:"CountComment"` //评论数量
Show int `json:"show"` //是否隐藏 [0显示、1不显示]
Tags []string `json:"tags"` //标签
TargetUser int `json:"targetUser"` //分发方式 [0分发给所有人、1分发给指定的人]
}
type SystemArticleHistoryRequest struct {
ArticleId int64 `json:"articleId"` //文章ID
Author string `json:"author,optional"` //发布人
UpdatedAt string `json:"updatedAt,optional"` //修改日期
}
type SystemArticleHistoryResponse struct {
Id int64 `json:"id"` //id
Author string `json:"author"` //编辑人
Action string `json:"action"` //编辑类型
UpdatedAt string `json:"updatedAt"` //编辑时间
}
type RoleGetRequest struct {
Id int64 `path:"id"`
}
... ...
... ... @@ -121,11 +121,13 @@ func (repository *ArticleRepository) Find(ctx context.Context, conn transaction.
queryFunc := func() (interface{}, error) {
tx = tx.Model(&ms).Order("id desc").Where("company_id=?", companyId)
if v, ok := queryOptions["ids"]; ok {
tx.Where("id in (?)", v)
tx = tx.Where("id in (?)", v)
}
if v, ok := queryOptions["authorId"]; ok {
tx = tx.Where("author_id = ?", v)
if v, ok := queryOptions["title"]; ok && v.(string) != "" {
tx = tx.Where("title like ?", "%"+v.(string)+"%")
}
if v, ok := queryOptions["author"]; ok {
tx = tx.Where(`author #>> '{"name"}' like ?`, "%"+v.(string)+"%")
}
if v, ok := queryOptions["beginCreatedAt"]; ok {
tx = tx.Where("created_at >= ?", v)
... ...
... ... @@ -90,6 +90,28 @@ func (repository *ArticleSectionRepository) Delete(ctx context.Context, conn tra
return repository.ModelToDomainModel(m)
}
func (repository *ArticleSectionRepository) DeleteBy(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) error {
var (
tx = conn.DB()
m = &models.ArticleSection{}
)
queryFunc := func() (interface{}, error) {
tx = tx.Where("id = ?", m.Id)
if v, ok := queryOptions["articleId"]; ok {
tx = tx.Where("article_id = ?", v)
}
if v, ok := queryOptions["notIds"]; ok {
tx = tx.Where("id not in (?)", v)
}
tx.Delete(m)
return m, tx.Error
}
if _, err := repository.Query(queryFunc, m.CacheKeyFunc()); err != nil {
return err
}
return nil
}
func (repository *ArticleSectionRepository) FindOne(ctx context.Context, conn transaction.Conn, id int64) (*domain.ArticleSection, error) {
var (
err error
... ...
... ... @@ -25,6 +25,7 @@ type ArticleSectionRepository interface {
Update(ctx context.Context, conn transaction.Conn, dm *ArticleSection) (*ArticleSection, error)
UpdateWithVersion(ctx context.Context, conn transaction.Conn, dm *ArticleSection) (*ArticleSection, error)
Delete(ctx context.Context, conn transaction.Conn, dm *ArticleSection) (*ArticleSection, error)
DeleteBy(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) error
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)
IncreaseCountComment(ctx context.Context, conn transaction.Conn, incr int, sectionId int64) error //评论数量变动
... ...