作者 tangxvhui
@@ -1225,6 +1225,60 @@ @@ -1225,6 +1225,60 @@
1225 ] 1225 ]
1226 } 1226 }
1227 }, 1227 },
  1228 + "v1/system/article/history/{id}": {
  1229 + "get": {
  1230 + "summary": "管理后台帖子历史详情",
  1231 + "operationId": "SystemArticleGetHistory",
  1232 + "responses": {
  1233 + "200": {
  1234 + "description": "A successful response.",
  1235 + "schema": {
  1236 + "$ref": "#/definitions/SystemArticleGetHistoryResponse"
  1237 + }
  1238 + }
  1239 + },
  1240 + "parameters": [
  1241 + {
  1242 + "name": "id",
  1243 + "in": "path",
  1244 + "required": true,
  1245 + "type": "string"
  1246 + }
  1247 + ],
  1248 + "requestBody": {},
  1249 + "tags": [
  1250 + "article"
  1251 + ]
  1252 + }
  1253 + },
  1254 + "v1/system/article/restore": {
  1255 + "post": {
  1256 + "summary": "管理后台文章恢复",
  1257 + "operationId": "SystemArticleRestore",
  1258 + "responses": {
  1259 + "200": {
  1260 + "description": "A successful response.",
  1261 + "schema": {
  1262 + "$ref": "#/definitions/SystemArticleRestoreResponse"
  1263 + }
  1264 + }
  1265 + },
  1266 + "parameters": [
  1267 + {
  1268 + "name": "body",
  1269 + "in": "body",
  1270 + "required": true,
  1271 + "schema": {
  1272 + "$ref": "#/definitions/SystemArticleRestoreRequest"
  1273 + }
  1274 + }
  1275 + ],
  1276 + "requestBody": {},
  1277 + "tags": [
  1278 + "article"
  1279 + ]
  1280 + }
  1281 + },
1228 "v1/system/article/search": { 1282 "v1/system/article/search": {
1229 "post": { 1283 "post": {
1230 "summary": "管理后台获取文章列表", 1284 "summary": "管理后台获取文章列表",
@@ -4891,6 +4945,125 @@ @@ -4891,6 +4945,125 @@
4891 "total" 4945 "total"
4892 ] 4946 ]
4893 }, 4947 },
  4948 + "SystemArticleGetHistoryRequest": {
  4949 + "type": "object",
  4950 + "properties": {
  4951 + "id": {
  4952 + "type": "integer",
  4953 + "format": "int64",
  4954 + "description": "id"
  4955 + },
  4956 + "": {
  4957 + "type": "integer",
  4958 + "format": "int64"
  4959 + }
  4960 + },
  4961 + "title": "SystemArticleGetHistoryRequest",
  4962 + "required": [
  4963 + "id"
  4964 + ]
  4965 + },
  4966 + "SystemArticleGetHistoryResponse": {
  4967 + "type": "object",
  4968 + "properties": {
  4969 + "id": {
  4970 + "type": "integer",
  4971 + "format": "int64",
  4972 + "description": " id"
  4973 + },
  4974 + "articleId": {
  4975 + "type": "integer",
  4976 + "format": "int64",
  4977 + "description": " 文章ID"
  4978 + },
  4979 + "title": {
  4980 + "type": "string",
  4981 + "description": " 标题"
  4982 + },
  4983 + "createdAt": {
  4984 + "type": "integer",
  4985 + "format": "int64",
  4986 + "description": " 文章的发布时间"
  4987 + },
  4988 + "section": {
  4989 + "type": "array",
  4990 + "items": {
  4991 + "$ref": "#/definitions/ArticleSection"
  4992 + },
  4993 + "description": " 文章的文本内容"
  4994 + },
  4995 + "images": {
  4996 + "type": "array",
  4997 + "items": {
  4998 + "type": "string"
  4999 + },
  5000 + "description": " 图片"
  5001 + },
  5002 + "whoRead": {
  5003 + "type": "array",
  5004 + "items": {
  5005 + "type": "integer",
  5006 + "format": "int64"
  5007 + },
  5008 + "description": " 谁可查看"
  5009 + },
  5010 + "whoReadInfo": {
  5011 + "type": "array",
  5012 + "items": {
  5013 + "$ref": "#/definitions/UserShowName"
  5014 + },
  5015 + "description": " 谁可查看"
  5016 + },
  5017 + "whoReview": {
  5018 + "type": "array",
  5019 + "items": {
  5020 + "type": "integer",
  5021 + "format": "int64"
  5022 + },
  5023 + "description": " 谁可评论"
  5024 + },
  5025 + "whoReviewInfo": {
  5026 + "type": "array",
  5027 + "items": {
  5028 + "$ref": "#/definitions/UserShowName"
  5029 + },
  5030 + "description": " 谁可评论"
  5031 + },
  5032 + "location": {
  5033 + "$ref": "#/definitions/Location",
  5034 + "description": " 定位坐标"
  5035 + },
  5036 + "targetUser": {
  5037 + "type": "integer",
  5038 + "format": "int32",
  5039 + "description": " 分发方式 [0分发给所有人、1分发给指定的人]"
  5040 + },
  5041 + "tags": {
  5042 + "type": "array",
  5043 + "items": {
  5044 + "type": "integer",
  5045 + "format": "int64"
  5046 + },
  5047 + "description": " 标签"
  5048 + }
  5049 + },
  5050 + "title": "SystemArticleGetHistoryResponse",
  5051 + "required": [
  5052 + "id",
  5053 + "articleId",
  5054 + "title",
  5055 + "createdAt",
  5056 + "section",
  5057 + "images",
  5058 + "whoRead",
  5059 + "whoReadInfo",
  5060 + "whoReview",
  5061 + "whoReviewInfo",
  5062 + "location",
  5063 + "targetUser",
  5064 + "tags"
  5065 + ]
  5066 + },
4894 "SystemArticleGetRequest": { 5067 "SystemArticleGetRequest": {
4895 "type": "object", 5068 "type": "object",
4896 "properties": { 5069 "properties": {
@@ -5002,6 +5175,13 @@ @@ -5002,6 +5175,13 @@
5002 "type": "integer", 5175 "type": "integer",
5003 "format": "int32", 5176 "format": "int32",
5004 "description": " 评论的展示状态(0显示、1不显示)" 5177 "description": " 评论的展示状态(0显示、1不显示)"
  5178 + },
  5179 + "tags": {
  5180 + "type": "array",
  5181 + "items": {
  5182 + "$ref": "#/definitions/ArticleTagItem"
  5183 + },
  5184 + "description": "标签"
5005 } 5185 }
5006 }, 5186 },
5007 "title": "SystemArticleGetResponse", 5187 "title": "SystemArticleGetResponse",
@@ -5021,7 +5201,8 @@ @@ -5021,7 +5201,8 @@
5021 "countLove", 5201 "countLove",
5022 "countComment", 5202 "countComment",
5023 "countRead", 5203 "countRead",
5024 - "show" 5204 + "show",
  5205 + "tags"
5025 ] 5206 ]
5026 }, 5207 },
5027 "SystemArticleHistory": { 5208 "SystemArticleHistory": {
@@ -5114,6 +5295,45 @@ @@ -5114,6 +5295,45 @@
5114 "list" 5295 "list"
5115 ] 5296 ]
5116 }, 5297 },
  5298 + "SystemArticleRestoreRequest": {
  5299 + "type": "object",
  5300 + "properties": {
  5301 + "id": {
  5302 + "type": "integer",
  5303 + "format": "int64",
  5304 + "description": "ID"
  5305 + },
  5306 + "AccessToken": {
  5307 + "type": "string",
  5308 + "description": " 授权token"
  5309 + }
  5310 + },
  5311 + "title": "SystemArticleRestoreRequest",
  5312 + "required": [
  5313 + "id",
  5314 + "x-mmm-accesstoken"
  5315 + ]
  5316 + },
  5317 + "SystemArticleRestoreResponse": {
  5318 + "type": "object",
  5319 + "properties": {
  5320 + "id": {
  5321 + "type": "integer",
  5322 + "format": "int64",
  5323 + "description": "ID"
  5324 + },
  5325 + "articleId": {
  5326 + "type": "integer",
  5327 + "format": "int64",
  5328 + "description": "文章ID"
  5329 + }
  5330 + },
  5331 + "title": "SystemArticleRestoreResponse",
  5332 + "required": [
  5333 + "id",
  5334 + "articleId"
  5335 + ]
  5336 + },
5117 "SystemArticleSearch": { 5337 "SystemArticleSearch": {
5118 "type": "object", 5338 "type": "object",
5119 "properties": { 5339 "properties": {
@@ -5263,6 +5483,14 @@ @@ -5263,6 +5483,14 @@
5263 "format": "int64", 5483 "format": "int64",
5264 "description": "结束时间" 5484 "description": "结束时间"
5265 }, 5485 },
  5486 + "tags": {
  5487 + "type": "array",
  5488 + "items": {
  5489 + "type": "integer",
  5490 + "format": "int64"
  5491 + },
  5492 + "description": "标签"
  5493 + },
5266 "page": { 5494 "page": {
5267 "type": "integer", 5495 "type": "integer",
5268 "format": "int32", 5496 "format": "int32",
@@ -5358,6 +5586,14 @@ @@ -5358,6 +5586,14 @@
5358 "type": "integer", 5586 "type": "integer",
5359 "format": "int32", 5587 "format": "int32",
5360 "description": "分发方式 [0分发给所有人、1分发给指定的人]" 5588 "description": "分发方式 [0分发给所有人、1分发给指定的人]"
  5589 + },
  5590 + "tags": {
  5591 + "type": "array",
  5592 + "items": {
  5593 + "type": "integer",
  5594 + "format": "int64"
  5595 + },
  5596 + "description": " 标签"
5361 } 5597 }
5362 }, 5598 },
5363 "title": "SystemArticleUpdateRequest", 5599 "title": "SystemArticleUpdateRequest",
@@ -5370,7 +5606,8 @@ @@ -5370,7 +5606,8 @@
5370 "whoRead", 5606 "whoRead",
5371 "whoReview", 5607 "whoReview",
5372 "location", 5608 "location",
5373 - "targetUser" 5609 + "targetUser",
  5610 + "tags"
5374 ] 5611 ]
5375 }, 5612 },
5376 "SystemArticleUpdateResponse": { 5613 "SystemArticleUpdateResponse": {
@@ -5419,7 +5656,8 @@ @@ -5419,7 +5656,8 @@
5419 "tags": { 5656 "tags": {
5420 "type": "array", 5657 "type": "array",
5421 "items": { 5658 "items": {
5422 - "type": "string" 5659 + "type": "integer",
  5660 + "format": "int64"
5423 }, 5661 },
5424 "description": "标签" 5662 "description": "标签"
5425 }, 5663 },
@@ -111,4 +111,7 @@ service Core { @@ -111,4 +111,7 @@ service Core {
111 @handler SystemArticleSearchMe 111 @handler SystemArticleSearchMe
112 post /article/search/me (SystemArticleSearchMeRequest) returns (SystemArticleSearchMeResponse) 112 post /article/search/me (SystemArticleSearchMeRequest) returns (SystemArticleSearchMeResponse)
113 113
  114 + @doc "管理后台文章恢复"
  115 + @handler SystemArticleRestore
  116 + post /article/restore (SystemArticleRestoreRequest) returns (SystemArticleRestoreResponse)
114 } 117 }
@@ -398,8 +398,9 @@ type ( @@ -398,8 +398,9 @@ type (
398 WhoRead []int64 `json:"whoRead"` // 谁可以看 398 WhoRead []int64 `json:"whoRead"` // 谁可以看
399 WhoReview []int64 `json:"whoReview"` // 评论人 399 WhoReview []int64 `json:"whoReview"` // 评论人
400 Location Location `json:"location"` // 坐标 400 Location Location `json:"location"` // 坐标
401 - TargetUser int `json:"targetUser"` //分发方式 [0分发给所有人、1分发给指定的人] 401 + TargetUser int `json:"targetUser"` // 分发方式 [0分发给所有人、1分发给指定的人]
402 Tags []int64 `json:"tags"` // 标签 402 Tags []int64 `json:"tags"` // 标签
  403 + AccessToken string `header:"x-mmm-accesstoken"` // 授权token
403 } 404 }
404 SystemArticleUpdateResponse { 405 SystemArticleUpdateResponse {
405 Id int64 `json:"id"` //id 406 Id int64 `json:"id"` //id
@@ -408,7 +409,7 @@ type ( @@ -408,7 +409,7 @@ type (
408 Images []string `json:"images"` //图片 409 Images []string `json:"images"` //图片
409 CreatedAt int64 `json:"createdAt"` //文章的创建日期 410 CreatedAt int64 `json:"createdAt"` //文章的创建日期
410 CountLove int `json:"countLove"` //点赞数量 411 CountLove int `json:"countLove"` //点赞数量
411 - CountComment int `json:"CountComment"` //评论数量 412 + CountComment int `json:"countComment"` //评论数量
412 Show int `json:"show"` //是否隐藏 [0显示、1不显示] 413 Show int `json:"show"` //是否隐藏 [0显示、1不显示]
413 Tags []int64 `json:"tags"` //标签 414 Tags []int64 `json:"tags"` //标签
414 TargetUser int `json:"targetUser"` //分发方式 [0分发给所有人、1分发给指定的人] 415 TargetUser int `json:"targetUser"` //分发方式 [0分发给所有人、1分发给指定的人]
@@ -440,8 +441,6 @@ type ( @@ -440,8 +441,6 @@ type (
440 Id int64 `json:"id"` // id 441 Id int64 `json:"id"` // id
441 ArticleId int64 `json:"articleId"` // 文章ID 442 ArticleId int64 `json:"articleId"` // 文章ID
442 Title string `json:"title"` // 标题 443 Title string `json:"title"` // 标题
443 - AuthorId int64 `json:"authorId"` // 发布人id  
444 - Author ArticleAuthor `json:"author"` // 发布人  
445 CreatedAt int64 `json:"createdAt"` // 文章的发布时间 444 CreatedAt int64 `json:"createdAt"` // 文章的发布时间
446 Section []ArticleSection `json:"section"` // 文章的文本内容 445 Section []ArticleSection `json:"section"` // 文章的文本内容
447 Images []string `json:"images"` // 图片 446 Images []string `json:"images"` // 图片
@@ -450,11 +449,16 @@ type ( @@ -450,11 +449,16 @@ type (
450 WhoReview []int64 `json:"whoReview"` // 谁可评论 449 WhoReview []int64 `json:"whoReview"` // 谁可评论
451 WhoReviewInfo []UserShowName `json:"whoReviewInfo"` // 谁可评论 450 WhoReviewInfo []UserShowName `json:"whoReviewInfo"` // 谁可评论
452 Location Location `json:"location"` // 定位坐标 451 Location Location `json:"location"` // 定位坐标
453 - CountLove int `json:"countLove"` // 点赞数量  
454 - CountComment int `json:"countComment"` // 评论数量  
455 - CountRead int `json:"countRead"` // 浏览数量  
456 - Show int `json:"show"` // 评论的展示状态(0显示、1不显示)  
457 - TargetUser int `json:"targetUser"` //分发方式 [0分发给所有人、1分发给指定的人] 452 + TargetUser int `json:"targetUser"` // 分发方式 [0分发给所有人、1分发给指定的人]
  453 + Tags []int64 `json:"tags"` // 标签
  454 + }
  455 + SystemArticleRestoreRequest {
  456 + Id int64 `json:"id"` //ID
  457 + AccessToken string `header:"x-mmm-accesstoken"` // 授权token
  458 + }
  459 + SystemArticleRestoreResponse {
  460 + Id int64 `json:"id"` //ID
  461 + ArticleId int64 `json:"articleId"` //文章ID
458 } 462 }
459 ) 463 )
460 464
  1 +package article
  2 +
  3 +import (
  4 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
  5 + "net/http"
  6 +
  7 + "github.com/zeromicro/go-zero/rest/httpx"
  8 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/article"
  9 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
  10 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
  11 +)
  12 +
  13 +func SystemArticleRestoreHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
  14 + return func(w http.ResponseWriter, r *http.Request) {
  15 + var req types.SystemArticleRestoreRequest
  16 + if err := httpx.Parse(r, &req); err != nil {
  17 + result.ParamErrorResult(r, w, err)
  18 + return
  19 + }
  20 +
  21 + l := article.NewSystemArticleRestoreLogic(r.Context(), svcCtx)
  22 + resp, err := l.SystemArticleRestore(&req)
  23 + result.HttpResult(r, w, resp, err)
  24 + }
  25 +}
@@ -18,7 +18,7 @@ func SystemUpdateArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { @@ -18,7 +18,7 @@ func SystemUpdateArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
18 return 18 return
19 } 19 }
20 l := article.NewSystemUpdateArticleLogic(r.Context(), svcCtx) 20 l := article.NewSystemUpdateArticleLogic(r.Context(), svcCtx)
21 - resp, err := l.SystemUpdateArticle(&req, r.Header.Get("x-mmm-accesstoken")) 21 + resp, err := l.SystemUpdateArticle(&req)
22 result.HttpResult(r, w, resp, err) 22 result.HttpResult(r, w, resp, err)
23 } 23 }
24 } 24 }
@@ -406,6 +406,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { @@ -406,6 +406,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
406 Path: "/article/search/me", 406 Path: "/article/search/me",
407 Handler: article.SystemArticleSearchMeHandler(serverCtx), 407 Handler: article.SystemArticleSearchMeHandler(serverCtx),
408 }, 408 },
  409 + {
  410 + Method: http.MethodPost,
  411 + Path: "/article/restore",
  412 + Handler: article.SystemArticleRestoreHandler(serverCtx),
  413 + },
409 }, 414 },
410 rest.WithJwt(serverCtx.Config.SystemAuth.AccessSecret), 415 rest.WithJwt(serverCtx.Config.SystemAuth.AccessSecret),
411 rest.WithPrefix("/v1/system"), 416 rest.WithPrefix("/v1/system"),
@@ -2,6 +2,7 @@ package article @@ -2,6 +2,7 @@ package article
2 2
3 import ( 3 import (
4 "context" 4 "context"
  5 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/message"
5 6
6 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" 7 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
7 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" 8 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
@@ -80,6 +81,14 @@ func (l *MiniArticleSetTagLogic) MiniArticleSetTag(req *types.MiniArticleSetTagR @@ -80,6 +81,14 @@ func (l *MiniArticleSetTagLogic) MiniArticleSetTag(req *types.MiniArticleSetTagR
80 if err != nil { 81 if err != nil {
81 return err 82 return err
82 } 83 }
  84 +
  85 + // 定性消息通知
  86 + messageLogic := message.NewMiniSystemLogic(ctx, l.svcCtx)
  87 + err = messageLogic.ArticleDefined(c, articleInfo.CompanyId, articleInfo.AuthorId, articleInfo.Title)
  88 + if err != nil {
  89 + return err
  90 + }
  91 +
83 return nil 92 return nil
84 }, true) 93 }, true)
85 94
@@ -2,6 +2,9 @@ package article @@ -2,6 +2,9 @@ package article
2 2
3 import ( 3 import (
4 "context" 4 "context"
  5 + "github.com/samber/lo"
  6 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
  7 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
5 8
6 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" 9 "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" 10 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
@@ -24,7 +27,67 @@ func NewSystemArticleGetHistoryLogic(ctx context.Context, svcCtx *svc.ServiceCon @@ -24,7 +27,67 @@ func NewSystemArticleGetHistoryLogic(ctx context.Context, svcCtx *svc.ServiceCon
24 } 27 }
25 28
26 func (l *SystemArticleGetHistoryLogic) SystemArticleGetHistory(req *types.SystemArticleGetHistoryRequest) (resp *types.SystemArticleGetHistoryResponse, err error) { 29 func (l *SystemArticleGetHistoryLogic) SystemArticleGetHistory(req *types.SystemArticleGetHistoryRequest) (resp *types.SystemArticleGetHistoryResponse, err error) {
27 - //var conn = l.svcCtx.DefaultDBConn()  
28 - 30 + var conn = l.svcCtx.DefaultDBConn()
  31 + backup, err := l.svcCtx.ArticleBackupRepository.FindOne(l.ctx, conn, req.Id)
  32 + if err != nil {
  33 + return nil, xerr.NewErrMsgErr("获取编辑历史记录失败", err)
  34 + }
  35 + resp = &types.SystemArticleGetHistoryResponse{
  36 + Id: backup.Id,
  37 + ArticleId: backup.ArticleId,
  38 + Title: backup.Title,
  39 + CreatedAt: backup.CreatedAt,
  40 + Section: make([]types.ArticleSection, 0),
  41 + Images: make([]string, 0),
  42 + WhoRead: backup.WhoRead,
  43 + WhoReadInfo: make([]types.UserShowName, 0),
  44 + WhoReview: backup.WhoReview,
  45 + WhoReviewInfo: make([]types.UserShowName, 0),
  46 + Location: types.Location{
  47 + Longitude: backup.Location.Longitude,
  48 + Latitude: backup.Location.Latitude,
  49 + Descript: backup.Location.Descript,
  50 + },
  51 + TargetUser: int(backup.TargetUser),
  52 + Tags: backup.Tags,
  53 + }
  54 + //文章段落内容
  55 + lo.ForEach(backup.Section, func(item domain.ArticleSection, index int) {
  56 + resp.Section = append(resp.Section, types.ArticleSection{
  57 + Id: item.Id,
  58 + Content: item.Content,
  59 + SortBy: item.SortBy,
  60 + TotalComment: item.TotalComment,
  61 + })
  62 + })
  63 + //图片
  64 + lo.ForEach(backup.Images, func(item domain.Image, index int) {
  65 + resp.Images = append(resp.Images, item.Url)
  66 + })
  67 + //用户
  68 + userIds := lo.Union(resp.WhoRead, resp.WhoReview)
  69 + if len(userIds) > 0 {
  70 + _, users, err := l.svcCtx.UserRepository.Find(l.ctx, conn, domain.NewQueryOptions().WithKV("ids", userIds))
  71 + if err != nil {
  72 + return nil, xerr.NewErrMsgErr("获取帖子异常", err)
  73 + }
  74 + userSlices := make(map[int64]types.UserShowName)
  75 + lo.ForEach(users, func(user *domain.User, index int) {
  76 + userSlices[user.Id] = types.UserShowName{
  77 + Id: int(user.Id),
  78 + Name: user.Name,
  79 + }
  80 + })
  81 + lo.ForEach(resp.WhoRead, func(userId int64, index int) {
  82 + if value, ok := userSlices[userId]; ok {
  83 + resp.WhoReadInfo = append(resp.WhoReadInfo, value)
  84 + }
  85 + })
  86 + lo.ForEach(resp.WhoReview, func(userId int64, index int) {
  87 + if value, ok := userSlices[userId]; ok {
  88 + resp.WhoReviewInfo = append(resp.WhoReviewInfo, value)
  89 + }
  90 + })
  91 + }
29 return 92 return
30 } 93 }
  1 +package article
  2 +
  3 +import (
  4 + "context"
  5 + "github.com/samber/lo"
  6 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
  7 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
  8 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/gateway/authlib"
  9 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
  10 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
  11 +
  12 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
  13 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
  14 +
  15 + "github.com/zeromicro/go-zero/core/logx"
  16 +)
  17 +
  18 +type SystemArticleRestoreLogic struct {
  19 + logx.Logger
  20 + ctx context.Context
  21 + svcCtx *svc.ServiceContext
  22 +}
  23 +
  24 +func NewSystemArticleRestoreLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemArticleRestoreLogic {
  25 + return &SystemArticleRestoreLogic{
  26 + Logger: logx.WithContext(ctx),
  27 + ctx: ctx,
  28 + svcCtx: svcCtx,
  29 + }
  30 +}
  31 +
  32 +func (l *SystemArticleRestoreLogic) SystemArticleRestore(req *types.SystemArticleRestoreRequest) (resp *types.SystemArticleRestoreResponse, err error) {
  33 + var conn = l.svcCtx.DefaultDBConn()
  34 + backup, err := l.svcCtx.ArticleBackupRepository.FindOne(l.ctx, conn, req.Id)
  35 + if err != nil {
  36 + return nil, xerr.NewErrMsgErr("获取编辑历史记录失败", err)
  37 + }
  38 + article, err := l.svcCtx.ArticleRepository.FindOne(l.ctx, conn, backup.ArticleId)
  39 + if err != nil {
  40 + return nil, xerr.NewErrMsgErr("获取文章失败", err)
  41 + }
  42 + article.Version = article.Version + 1
  43 + article.Images = backup.Images
  44 + article.Title = backup.Title
  45 + articleSections := make([]domain.ArticleSection, 0)
  46 + lo.ForEach(backup.Section, func(item domain.ArticleSection, index int) {
  47 + articleSections = append(articleSections, domain.ArticleSection{
  48 + Id: item.Id,
  49 + CompanyId: item.CompanyId,
  50 + Version: article.Version,
  51 + ArticleId: article.Id,
  52 + Content: item.Content,
  53 + SortBy: item.SortBy,
  54 + })
  55 + })
  56 + //获取当前用户信息
  57 + userToken := contextdata.GetUserTokenFromCtx(l.ctx)
  58 + userMe, err := l.svcCtx.ApiAuthService.MeInfo(l.ctx, authlib.RequestUserMeQuery{Token: req.AccessToken})
  59 + if err != nil {
  60 + return nil, xerr.NewErrMsgErr("获取当前用户信息失败", err)
  61 + }
  62 + err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error {
  63 + //保存文章
  64 + _, err = l.svcCtx.ArticleRepository.Update(ctx, c, article)
  65 + if err != nil {
  66 + return xerr.NewErrMsgErr("恢复文章版本失败", err)
  67 + }
  68 + //保存段落
  69 + updateSectionIds := []int64{}
  70 + for _, item := range articleSections {
  71 + section, err := l.svcCtx.ArticleSectionRepository.FindOne(ctx, c, item.Id)
  72 + if err == nil && section.Id > 0 {
  73 + section.Content = item.Content
  74 + section.SortBy = item.SortBy
  75 + section.Version = item.Version
  76 + _, err = l.svcCtx.ArticleSectionRepository.Update(ctx, c, section)
  77 + if err != nil {
  78 + return xerr.NewErrMsgErr("恢复文章版本失败", err)
  79 + }
  80 + } else {
  81 + _, err = l.svcCtx.ArticleSectionRepository.Insert(ctx, c, &item)
  82 + if err != nil {
  83 + return xerr.NewErrMsgErr("恢复文章版本失败", err)
  84 + }
  85 + }
  86 + updateSectionIds = append(updateSectionIds, item.Id)
  87 + }
  88 + if len(updateSectionIds) > 0 {
  89 + err = l.svcCtx.ArticleSectionRepository.DeleteBy(ctx, c, domain.NewQueryOptions().WithKV("articleId", article.Id).WithKV("notIds", updateSectionIds))
  90 + if err != nil {
  91 + return xerr.NewErrMsgErr("保存文章内容失败", err)
  92 + }
  93 + }
  94 + //备份数据
  95 + newBackUp := article.MakeBackup(domain.UserSimple{
  96 + Id: userToken.UserId,
  97 + Name: userMe.User.NickName,
  98 + Avatar: userMe.User.Avatar,
  99 + CompanyId: userToken.CompanyId,
  100 + Company: userMe.CurrentCompany.Name,
  101 + }, articleSections)
  102 + newBackUp.Action = "恢复"
  103 + _, err = l.svcCtx.ArticleBackupRepository.Insert(ctx, c, newBackUp)
  104 + if err != nil {
  105 + return xerr.NewErrMsgErr("恢复文章版本失败", err)
  106 + }
  107 + return nil
  108 + }, true)
  109 + resp = &types.SystemArticleRestoreResponse{
  110 + Id: req.Id,
  111 + ArticleId: article.Id,
  112 + }
  113 + return
  114 +}
@@ -29,7 +29,7 @@ func NewSystemUpdateArticleLogic(ctx context.Context, svcCtx *svc.ServiceContext @@ -29,7 +29,7 @@ func NewSystemUpdateArticleLogic(ctx context.Context, svcCtx *svc.ServiceContext
29 } 29 }
30 } 30 }
31 31
32 -func (l *SystemUpdateArticleLogic) SystemUpdateArticle(req *types.SystemArticleUpdateRequest, accessToken string) (resp *types.SystemArticleUpdateResponse, err error) { 32 +func (l *SystemUpdateArticleLogic) SystemUpdateArticle(req *types.SystemArticleUpdateRequest) (resp *types.SystemArticleUpdateResponse, err error) {
33 var conn = l.svcCtx.DefaultDBConn() 33 var conn = l.svcCtx.DefaultDBConn()
34 userToken := contextdata.GetUserTokenFromCtx(l.ctx) 34 userToken := contextdata.GetUserTokenFromCtx(l.ctx)
35 article, err := l.svcCtx.ArticleRepository.FindOne(l.ctx, conn, req.Id) 35 article, err := l.svcCtx.ArticleRepository.FindOne(l.ctx, conn, req.Id)
@@ -84,7 +84,7 @@ func (l *SystemUpdateArticleLogic) SystemUpdateArticle(req *types.SystemArticleU @@ -84,7 +84,7 @@ func (l *SystemUpdateArticleLogic) SystemUpdateArticle(req *types.SystemArticleU
84 article.Summary = req.Section[0].Content[0:stringIndex] 84 article.Summary = req.Section[0].Content[0:stringIndex]
85 } 85 }
86 //获取当前用户信息 86 //获取当前用户信息
87 - userMe, err := l.svcCtx.ApiAuthService.MeInfo(l.ctx, authlib.RequestUserMeQuery{Token: accessToken}) 87 + userMe, err := l.svcCtx.ApiAuthService.MeInfo(l.ctx, authlib.RequestUserMeQuery{Token: req.AccessToken})
88 if err != nil { 88 if err != nil {
89 return nil, xerr.NewErrMsgErr("获取当前用户信息失败", err) 89 return nil, xerr.NewErrMsgErr("获取当前用户信息失败", err)
90 } 90 }
@@ -929,8 +929,9 @@ type SystemArticleUpdateRequest struct { @@ -929,8 +929,9 @@ type SystemArticleUpdateRequest struct {
929 WhoRead []int64 `json:"whoRead"` // 谁可以看 929 WhoRead []int64 `json:"whoRead"` // 谁可以看
930 WhoReview []int64 `json:"whoReview"` // 评论人 930 WhoReview []int64 `json:"whoReview"` // 评论人
931 Location Location `json:"location"` // 坐标 931 Location Location `json:"location"` // 坐标
932 - TargetUser int `json:"targetUser"` //分发方式 [0分发给所有人、1分发给指定的人] 932 + TargetUser int `json:"targetUser"` // 分发方式 [0分发给所有人、1分发给指定的人]
933 Tags []int64 `json:"tags"` // 标签 933 Tags []int64 `json:"tags"` // 标签
  934 + AccessToken string `header:"x-mmm-accesstoken"` // 授权token
934 } 935 }
935 936
936 type SystemArticleUpdateResponse struct { 937 type SystemArticleUpdateResponse struct {
@@ -940,7 +941,7 @@ type SystemArticleUpdateResponse struct { @@ -940,7 +941,7 @@ type SystemArticleUpdateResponse struct {
940 Images []string `json:"images"` //图片 941 Images []string `json:"images"` //图片
941 CreatedAt int64 `json:"createdAt"` //文章的创建日期 942 CreatedAt int64 `json:"createdAt"` //文章的创建日期
942 CountLove int `json:"countLove"` //点赞数量 943 CountLove int `json:"countLove"` //点赞数量
943 - CountComment int `json:"CountComment"` //评论数量 944 + CountComment int `json:"countComment"` //评论数量
944 Show int `json:"show"` //是否隐藏 [0显示、1不显示] 945 Show int `json:"show"` //是否隐藏 [0显示、1不显示]
945 Tags []int64 `json:"tags"` //标签 946 Tags []int64 `json:"tags"` //标签
946 TargetUser int `json:"targetUser"` //分发方式 [0分发给所有人、1分发给指定的人] 947 TargetUser int `json:"targetUser"` //分发方式 [0分发给所有人、1分发给指定的人]
@@ -976,8 +977,6 @@ type SystemArticleGetHistoryResponse struct { @@ -976,8 +977,6 @@ type SystemArticleGetHistoryResponse struct {
976 Id int64 `json:"id"` // id 977 Id int64 `json:"id"` // id
977 ArticleId int64 `json:"articleId"` // 文章ID 978 ArticleId int64 `json:"articleId"` // 文章ID
978 Title string `json:"title"` // 标题 979 Title string `json:"title"` // 标题
979 - AuthorId int64 `json:"authorId"` // 发布人id  
980 - Author ArticleAuthor `json:"author"` // 发布人  
981 CreatedAt int64 `json:"createdAt"` // 文章的发布时间 980 CreatedAt int64 `json:"createdAt"` // 文章的发布时间
982 Section []ArticleSection `json:"section"` // 文章的文本内容 981 Section []ArticleSection `json:"section"` // 文章的文本内容
983 Images []string `json:"images"` // 图片 982 Images []string `json:"images"` // 图片
@@ -986,11 +985,18 @@ type SystemArticleGetHistoryResponse struct { @@ -986,11 +985,18 @@ type SystemArticleGetHistoryResponse struct {
986 WhoReview []int64 `json:"whoReview"` // 谁可评论 985 WhoReview []int64 `json:"whoReview"` // 谁可评论
987 WhoReviewInfo []UserShowName `json:"whoReviewInfo"` // 谁可评论 986 WhoReviewInfo []UserShowName `json:"whoReviewInfo"` // 谁可评论
988 Location Location `json:"location"` // 定位坐标 987 Location Location `json:"location"` // 定位坐标
989 - CountLove int `json:"countLove"` // 点赞数量  
990 - CountComment int `json:"countComment"` // 评论数量  
991 - CountRead int `json:"countRead"` // 浏览数量  
992 - Show int `json:"show"` // 评论的展示状态(0显示、1不显示)  
993 - TargetUser int `json:"targetUser"` //分发方式 [0分发给所有人、1分发给指定的人] 988 + TargetUser int `json:"targetUser"` // 分发方式 [0分发给所有人、1分发给指定的人]
  989 + Tags []int64 `json:"tags"` // 标签
  990 +}
  991 +
  992 +type SystemArticleRestoreRequest struct {
  993 + Id int64 `json:"id"` //ID
  994 + AccessToken string `header:"x-mmm-accesstoken"` // 授权token
  995 +}
  996 +
  997 +type SystemArticleRestoreResponse struct {
  998 + Id int64 `json:"id"` //ID
  999 + ArticleId int64 `json:"articleId"` //文章ID
994 } 1000 }
995 1001
996 type MiniHomePageRequest struct { 1002 type MiniHomePageRequest struct {