作者 tangxvhui

新增接口, 获取单条文章编辑历史

@@ -65,6 +65,9 @@ service Core { @@ -65,6 +65,9 @@ service Core {
65 @handler MiniArticleBackupSearch 65 @handler MiniArticleBackupSearch
66 post /article_backup/search (MiniArticleBackupSearchRequest) returns (MiniArticleBackupSearchResponse) 66 post /article_backup/search (MiniArticleBackupSearchRequest) returns (MiniArticleBackupSearchResponse)
67 67
  68 + @doc "小程序获取文章的编辑记录"
  69 + @handler MiniGetArticleBackup
  70 + get /article_backup/:id (MiniGetArticleBackupRequest) returns (MiniGetArticleBackupResponse)
68 71
69 @doc "小程序设置文章的定性标签" 72 @doc "小程序设置文章的定性标签"
70 @handler MiniArticleSetTag 73 @handler MiniArticleSetTag
@@ -176,8 +176,32 @@ type ( @@ -176,8 +176,32 @@ type (
176 ChangeField []string `json:"changeField"` 176 ChangeField []string `json:"changeField"`
177 CreatedAt int64 `json:"createdAt"` 177 CreatedAt int64 `json:"createdAt"`
178 Location Location `json:"location"` 178 Location Location `json:"location"`
  179 + Action string `json:"action"`
  180 + Show int `json:"show"`
179 } 181 }
180 ) 182 )
  183 +
  184 +type (
  185 + MiniGetArticleBackupRequest {
  186 + BackupId int64 `path:"id"`
  187 + CompanyId int64 `path:",optional"` // 服务端自动获取
  188 + }
  189 + MiniGetArticleBackupResponse {
  190 + Id int64 `json:"id"`
  191 + Title string `json:"title"`
  192 + Content string `json:"content"`
  193 + Images []string `json:"images"`
  194 + Videos []Video `json:"videos"`
  195 + ChangeField []string `json:"changeField"`
  196 + CreatedAt int64 `json:"createdAt"`
  197 + Location Location `json:"location"`
  198 + Action string `json:"action"`
  199 + Show int `json:"show"`
  200 + }
  201 +)
  202 +
  203 +
  204 +
181 // 标记人员浏览了那个文章 205 // 标记人员浏览了那个文章
182 type ( 206 type (
183 MiniArticleMarkUserReadRequest { 207 MiniArticleMarkUserReadRequest {
  1 +package article
  2 +
  3 +import (
  4 + "net/http"
  5 +
  6 + "github.com/zeromicro/go-zero/rest/httpx"
  7 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/article"
  8 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
  9 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
  10 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
  11 +)
  12 +
  13 +func MiniGetArticleBackupHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
  14 + return func(w http.ResponseWriter, r *http.Request) {
  15 + var req types.MiniGetArticleBackupRequest
  16 + if err := httpx.Parse(r, &req); err != nil {
  17 + result.HttpResult(r, w, nil, err)
  18 + return
  19 + }
  20 +
  21 + l := article.NewMiniGetArticleBackupLogic(r.Context(), svcCtx)
  22 + resp, err := l.MiniGetArticleBackup(&req)
  23 + result.HttpResult(r, w, resp, err)
  24 + }
  25 +}
@@ -529,6 +529,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { @@ -529,6 +529,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
529 Handler: article.MiniArticleBackupSearchHandler(serverCtx), 529 Handler: article.MiniArticleBackupSearchHandler(serverCtx),
530 }, 530 },
531 { 531 {
  532 + Method: http.MethodGet,
  533 + Path: "/article_backup/:id",
  534 + Handler: article.MiniGetArticleBackupHandler(serverCtx),
  535 + },
  536 + {
532 Method: http.MethodPost, 537 Method: http.MethodPost,
533 Path: "/article/set_tag", 538 Path: "/article/set_tag",
534 Handler: article.MiniArticleSetTagHandler(serverCtx), 539 Handler: article.MiniArticleSetTagHandler(serverCtx),
@@ -74,6 +74,8 @@ func (l *MiniArticleBackupSearchLogic) MiniArticleBackupSearch(req *types.MiniAr @@ -74,6 +74,8 @@ func (l *MiniArticleBackupSearchLogic) MiniArticleBackupSearch(req *types.MiniAr
74 Descript: backupList[i].Location.Descript, 74 Descript: backupList[i].Location.Descript,
75 }, 75 },
76 ChangeField: backupList[i].ChangeField, 76 ChangeField: backupList[i].ChangeField,
  77 + Action: backupList[i].Action,
  78 + Show: int(backupList[i].Show),
77 } 79 }
78 } 80 }
79 return resp, nil 81 return resp, nil
@@ -192,8 +192,9 @@ func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateR @@ -192,8 +192,9 @@ func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateR
192 } 192 }
193 193
194 // 生成 备份数据 194 // 生成 备份数据
195 - backupData := newArticle.MakeBackup(articleAuthor, sectionList, "原始版本")  
196 - _, err = l.svcCtx.ArticleBackupRepository.Insert(l.ctx, conn, backupData) 195 + var backupData domain.ArticleBackup
  196 + backupData.MakeBackup(articleAuthor, newArticle, sectionList, "原始版本")
  197 + _, err = l.svcCtx.ArticleBackupRepository.Insert(l.ctx, conn, &backupData)
197 if err != nil { 198 if err != nil {
198 return xerr.NewErrMsgErr("创建文章失败", err) 199 return xerr.NewErrMsgErr("创建文章失败", err)
199 } 200 }
  1 +package article
  2 +
  3 +import (
  4 + "context"
  5 + "strings"
  6 +
  7 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
  8 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
  9 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
  10 +
  11 + "github.com/zeromicro/go-zero/core/logx"
  12 +)
  13 +
  14 +type MiniGetArticleBackupLogic struct {
  15 + logx.Logger
  16 + ctx context.Context
  17 + svcCtx *svc.ServiceContext
  18 +}
  19 +
  20 +func NewMiniGetArticleBackupLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniGetArticleBackupLogic {
  21 + return &MiniGetArticleBackupLogic{
  22 + Logger: logx.WithContext(ctx),
  23 + ctx: ctx,
  24 + svcCtx: svcCtx,
  25 + }
  26 +}
  27 +
  28 +func (l *MiniGetArticleBackupLogic) MiniGetArticleBackup(req *types.MiniGetArticleBackupRequest) (resp *types.MiniGetArticleBackupResponse, err error) {
  29 + var conn = l.svcCtx.DefaultDBConn()
  30 +
  31 + backupInfo, err := l.svcCtx.ArticleBackupRepository.FindOne(l.ctx, conn, req.BackupId)
  32 + if err != nil {
  33 + return &types.MiniGetArticleBackupResponse{}, xerr.NewErrMsgErr("获取编辑记录失败", err)
  34 + }
  35 +
  36 + content := strings.Builder{}
  37 + for _, val2 := range backupInfo.Section {
  38 + content.WriteString(val2.Content)
  39 + }
  40 + images := []string{}
  41 + for _, val2 := range backupInfo.Images {
  42 + images = append(images, val2.Url)
  43 + }
  44 +
  45 + videos := []types.Video{}
  46 + for _, val2 := range backupInfo.Videos {
  47 + videos = append(videos, types.Video{
  48 + Url: val2.Url,
  49 + Cover: val2.Cover,
  50 + Width: val2.Width,
  51 + Height: val2.Height,
  52 + })
  53 + }
  54 +
  55 + resp = &types.MiniGetArticleBackupResponse{
  56 + Id: backupInfo.Id,
  57 + Title: backupInfo.Title,
  58 + Content: content.String(),
  59 + Images: images,
  60 + Videos: videos,
  61 + CreatedAt: backupInfo.CreatedAt,
  62 + Location: types.Location{
  63 + Longitude: backupInfo.Location.Longitude,
  64 + Latitude: backupInfo.Location.Latitude,
  65 + Descript: backupInfo.Location.Descript,
  66 + },
  67 + ChangeField: backupInfo.ChangeField,
  68 + Action: backupInfo.Action,
  69 + Show: int(backupInfo.Show),
  70 + }
  71 +
  72 + return
  73 +}
@@ -52,13 +52,14 @@ func (l *SystemArticleRestoreLogic) SystemArticleRestore(req *types.SystemArticl @@ -52,13 +52,14 @@ func (l *SystemArticleRestoreLogic) SystemArticleRestore(req *types.SystemArticl
52 } 52 }
53 53
54 // 备份数据 54 // 备份数据
55 - newBackUp := article.MakeBackup(domain.UserSimple{ 55 + var newBackUp domain.ArticleBackup
  56 + newBackUp.MakeBackup(domain.UserSimple{
56 Id: userToken.UserId, 57 Id: userToken.UserId,
57 Name: userMe.User.NickName, 58 Name: userMe.User.NickName,
58 Avatar: userMe.User.Avatar, 59 Avatar: userMe.User.Avatar,
59 CompanyId: userToken.CompanyId, 60 CompanyId: userToken.CompanyId,
60 Company: userMe.CurrentCompany.Name, 61 Company: userMe.CurrentCompany.Name,
61 - }, sectionList, "恢复") 62 + }, article, sectionList, "恢复")
62 _ = newBackUp.CheckChangeField(oldBackup) 63 _ = newBackUp.CheckChangeField(oldBackup)
63 64
64 article.Version = article.Version + 1 65 article.Version = article.Version + 1
@@ -114,7 +115,7 @@ func (l *SystemArticleRestoreLogic) SystemArticleRestore(req *types.SystemArticl @@ -114,7 +115,7 @@ func (l *SystemArticleRestoreLogic) SystemArticleRestore(req *types.SystemArticl
114 } 115 }
115 } 116 }
116 117
117 - _, err = l.svcCtx.ArticleBackupRepository.Insert(ctx, c, newBackUp) 118 + _, err = l.svcCtx.ArticleBackupRepository.Insert(ctx, c, &newBackUp)
118 if err != nil { 119 if err != nil {
119 return xerr.NewErrMsgErr("恢复文章版本失败", err) 120 return xerr.NewErrMsgErr("恢复文章版本失败", err)
120 } 121 }
@@ -75,7 +75,9 @@ func (l *SystemUpdateArticleLogic) SystemUpdateArticle(req *types.SystemArticleU @@ -75,7 +75,9 @@ func (l *SystemUpdateArticleLogic) SystemUpdateArticle(req *types.SystemArticleU
75 if err != nil { 75 if err != nil {
76 return nil, xerr.NewErrMsgErr("帖子不存在", err) 76 return nil, xerr.NewErrMsgErr("帖子不存在", err)
77 } 77 }
78 - oldBackup := article.MakeBackup(operator, sectionList, "编辑") 78 + var oldBackup domain.ArticleBackup
  79 + oldBackup.MakeBackup(operator, article, sectionList, "编辑")
  80 +
79 // 获取图片的尺寸大小 81 // 获取图片的尺寸大小
80 images, err := l.getImages(req) 82 images, err := l.getImages(req)
81 if err != nil { 83 if err != nil {
@@ -158,11 +160,11 @@ func (l *SystemUpdateArticleLogic) SystemUpdateArticle(req *types.SystemArticleU @@ -158,11 +160,11 @@ func (l *SystemUpdateArticleLogic) SystemUpdateArticle(req *types.SystemArticleU
158 return xerr.NewErrMsgErr("保存文章内容失败", err) 160 return xerr.NewErrMsgErr("保存文章内容失败", err)
159 } 161 }
160 } 162 }
  163 + var backup domain.ArticleBackup
  164 + backup.MakeBackup(operator, article, updateSection, "编辑")
161 165
162 - backup := article.MakeBackup(operator, updateSection, "编辑")  
163 -  
164 - if ok := backup.CheckChangeField(oldBackup); ok {  
165 - _, err = l.svcCtx.ArticleBackupRepository.Insert(ctx, c, backup) 166 + if ok := backup.CheckChangeField(&oldBackup); ok {
  167 + _, err = l.svcCtx.ArticleBackupRepository.Insert(ctx, c, &backup)
166 if err != nil { 168 if err != nil {
167 return xerr.NewErrMsgErr("保存文章内容失败", err) 169 return xerr.NewErrMsgErr("保存文章内容失败", err)
168 } 170 }
@@ -489,10 +489,10 @@ type MiniHomepageUserNewsRequest struct { @@ -489,10 +489,10 @@ type MiniHomepageUserNewsRequest struct {
489 LastArticleId int64 `json:"lastArticleId,optional"` // 最后文章ID 489 LastArticleId int64 `json:"lastArticleId,optional"` // 最后文章ID
490 Size int `json:"size"` // 数量 490 Size int `json:"size"` // 数量
491 OrderByKey string `json:"orderByKey,options=HotScore|All|Time,optional,default=desc"` // 按规则排序 (热度:HotScore All:时间排序 Time:时间排序) 491 OrderByKey string `json:"orderByKey,options=HotScore|All|Time,optional,default=desc"` // 按规则排序 (热度:HotScore All:时间排序 Time:时间排序)
492 - OrderByValue string `json:"orderByValue,options=asc||desc,optional"`  
493 - Keywords string `json:"keywords,optional"` // 关键字  
494 - BeginTime int64 `json:"beginTime,optional"` // 开始时间  
495 - EndTime int64 `json:"endTime,optional"` // 结束时间 492 + OrderByValue string `json:"orderByValue,options=asc||desc,optional"` // 排序值 升序 asc 降序 desc
  493 + Keywords string `json:"keywords,optional"` // 关键字
  494 + BeginTime int64 `json:"beginTime,optional"` // 开始时间
  495 + EndTime int64 `json:"endTime,optional"` // 结束时间
496 } 496 }
497 497
498 type MiniHomepageUserNewsResposne struct { 498 type MiniHomepageUserNewsResposne struct {
@@ -1037,6 +1037,26 @@ type MiniArticleBackupItem struct { @@ -1037,6 +1037,26 @@ type MiniArticleBackupItem struct {
1037 ChangeField []string `json:"changeField"` 1037 ChangeField []string `json:"changeField"`
1038 CreatedAt int64 `json:"createdAt"` 1038 CreatedAt int64 `json:"createdAt"`
1039 Location Location `json:"location"` 1039 Location Location `json:"location"`
  1040 + Action string `json:"action"`
  1041 + Show int `json:"show"`
  1042 +}
  1043 +
  1044 +type MiniGetArticleBackupRequest struct {
  1045 + BackupId int64 `path:"id"`
  1046 + CompanyId int64 `path:",optional"` // 服务端自动获取
  1047 +}
  1048 +
  1049 +type MiniGetArticleBackupResponse struct {
  1050 + Id int64 `json:"id"`
  1051 + Title string `json:"title"`
  1052 + Content string `json:"content"`
  1053 + Images []string `json:"images"`
  1054 + Videos []Video `json:"videos"`
  1055 + ChangeField []string `json:"changeField"`
  1056 + CreatedAt int64 `json:"createdAt"`
  1057 + Location Location `json:"location"`
  1058 + Action string `json:"action"`
  1059 + Show int `json:"show"`
1040 } 1060 }
1041 1061
1042 type MiniArticleMarkUserReadRequest struct { 1062 type MiniArticleMarkUserReadRequest struct {
@@ -95,44 +95,6 @@ func (a ArticleShow) Named() string { @@ -95,44 +95,6 @@ func (a ArticleShow) Named() string {
95 return "" 95 return ""
96 } 96 }
97 97
98 -// 设置文章的备份数据  
99 -func (m *Article) MakeBackup(operator UserSimple, section []*ArticleSection, action string) *ArticleBackup {  
100 - sectionBackup := make([]ArticleSection, len(section))  
101 - for i := range section {  
102 - sectionBackup[i] = *section[i]  
103 - }  
104 - b := ArticleBackup{  
105 - Id: 0,  
106 - CompanyId: m.CompanyId,  
107 - CreatedAt: 0,  
108 - UpdatedAt: 0,  
109 - DeletedAt: 0,  
110 - Version: m.Version,  
111 - Operator: operator,  
112 - ArticleId: m.Id,  
113 - Title: m.Title,  
114 - Section: sectionBackup,  
115 - Images: make([]Image, len(m.Images)),  
116 - Videos: make([]Video, len(m.Videos)),  
117 - Action: action,  
118 - TargetUser: m.TargetUser,  
119 - WhoRead: m.WhoRead,  
120 - WhoReview: m.WhoReview,  
121 - Tags: m.Tags,  
122 - MatchUrl: map[string]string{},  
123 - Location: m.Location,  
124 - }  
125 - if action == "原始版本" {  
126 - b.ChangeField = append(b.ChangeField, "Section")  
127 - }  
128 - copy(b.Videos, m.Videos)  
129 - copy(b.Images, m.Images)  
130 - for k, v := range m.MatchUrl {  
131 - b.MatchUrl[k] = v  
132 - }  
133 - return &b  
134 -}  
135 -  
136 func (m *Article) SetSummary(sectionList []*ArticleSection) { 98 func (m *Article) SetSummary(sectionList []*ArticleSection) {
137 if len(sectionList) == 0 { 99 if len(sectionList) == 0 {
138 return 100 return
@@ -33,6 +33,7 @@ type ArticleBackup struct { @@ -33,6 +33,7 @@ type ArticleBackup struct {
33 WhoReview []int64 `json:"whoReview"` // 评论人 33 WhoReview []int64 `json:"whoReview"` // 评论人
34 Tags []int64 `json:"tags"` // 标签 34 Tags []int64 `json:"tags"` // 标签
35 MatchUrl map[string]string `json:"matchUrl"` // 匹配文章内容中的url文本 35 MatchUrl map[string]string `json:"matchUrl"` // 匹配文章内容中的url文本
  36 + Show ArticleShow `json:"show"` // 评论的展示状态(1显示,2不显示、)
36 } 37 }
37 38
38 type ArticleBackupRepository interface { 39 type ArticleBackupRepository interface {
@@ -138,3 +139,42 @@ func (bk *ArticleBackup) CheckChangeField(oldBackup *ArticleBackup) bool { @@ -138,3 +139,42 @@ func (bk *ArticleBackup) CheckChangeField(oldBackup *ArticleBackup) bool {
138 } 139 }
139 return len(bk.ChangeField) > 0 140 return len(bk.ChangeField) > 0
140 } 141 }
  142 +
  143 +// 创建备份信息
  144 +func (bk *ArticleBackup) MakeBackup(operator UserSimple, article *Article, section []*ArticleSection, action string) {
  145 + sectionBackup := make([]ArticleSection, len(section))
  146 + for i := range section {
  147 + sectionBackup[i] = *section[i]
  148 + }
  149 + b := ArticleBackup{
  150 + Id: 0,
  151 + CompanyId: article.CompanyId,
  152 + CreatedAt: 0,
  153 + UpdatedAt: 0,
  154 + DeletedAt: 0,
  155 + Version: article.Version,
  156 + Operator: operator,
  157 + ArticleId: article.Id,
  158 + Title: article.Title,
  159 + Section: sectionBackup,
  160 + Images: make([]Image, len(article.Images)),
  161 + Videos: make([]Video, len(article.Videos)),
  162 + Action: action,
  163 + TargetUser: article.TargetUser,
  164 + WhoRead: article.WhoRead,
  165 + WhoReview: article.WhoReview,
  166 + Tags: article.Tags,
  167 + MatchUrl: map[string]string{},
  168 + Show: article.Show,
  169 + Location: article.Location,
  170 + }
  171 + if action == "原始版本" {
  172 + b.ChangeField = append(b.ChangeField, "Section")
  173 + }
  174 + copy(b.Videos, article.Videos)
  175 + copy(b.Images, article.Images)
  176 + for k, v := range article.MatchUrl {
  177 + b.MatchUrl[k] = v
  178 + }
  179 + *bk = b
  180 +}