作者 yangfu

fix:内容修改

@@ -87,6 +87,7 @@ func (l *MiniArticleBackupSearchLogic) MiniArticleBackupSearch(req *types.MiniAr @@ -87,6 +87,7 @@ func (l *MiniArticleBackupSearchLogic) MiniArticleBackupSearch(req *types.MiniAr
87 changeFiled = append(changeFiled, "修改了评论范围") 87 changeFiled = append(changeFiled, "修改了评论范围")
88 case "Section": 88 case "Section":
89 { 89 {
  90 + changeFiled = append(changeFiled, "修改了文章内容")
90 item.Title = backupList[i].Title 91 item.Title = backupList[i].Title
91 item.Content = content.String() 92 item.Content = content.String()
92 item.Images = images 93 item.Images = images
@@ -3,11 +3,8 @@ package domain @@ -3,11 +3,8 @@ package domain
3 import ( 3 import (
4 "bytes" 4 "bytes"
5 "context" 5 "context"
6 - "encoding/json"  
7 - "fmt"  
8 - "sort"  
9 -  
10 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction" 6 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
  7 + "reflect"
11 ) 8 )
12 9
13 // 编辑文章后保存的历史记录 10 // 编辑文章后保存的历史记录
@@ -51,95 +48,119 @@ func (bk *ArticleBackup) CheckChangeField(oldBackup *ArticleBackup) bool { @@ -51,95 +48,119 @@ func (bk *ArticleBackup) CheckChangeField(oldBackup *ArticleBackup) bool {
51 bk.ChangeField = make([]string, 0) 48 bk.ChangeField = make([]string, 0)
52 //比较 WhoRead 49 //比较 WhoRead
53 { 50 {
54 - whoReadChanged := false  
55 - sort.Slice(bk.WhoRead, func(i, j int) bool {  
56 - return bk.WhoRead[i] < bk.WhoRead[j]  
57 - })  
58 - sort.Slice(oldBackup.WhoRead, func(i, j int) bool {  
59 - return oldBackup.WhoRead[i] < oldBackup.WhoRead[j]  
60 - })  
61 -  
62 - if len(bk.WhoRead) != len(oldBackup.WhoRead) {  
63 - whoReadChanged = true  
64 - } else {  
65 - for i := range bk.WhoRead {  
66 - if bk.WhoRead[i] != oldBackup.WhoRead[i] {  
67 - whoReadChanged = true  
68 - }  
69 - }  
70 - }  
71 - if whoReadChanged { 51 + //whoReadChanged := false
  52 + //sort.Slice(bk.WhoRead, func(i, j int) bool {
  53 + // return bk.WhoRead[i] < bk.WhoRead[j]
  54 + //})
  55 + //sort.Slice(oldBackup.WhoRead, func(i, j int) bool {
  56 + // return oldBackup.WhoRead[i] < oldBackup.WhoRead[j]
  57 + //})
  58 + //
  59 + //if len(bk.WhoRead) != len(oldBackup.WhoRead) {
  60 + // whoReadChanged = true
  61 + //} else {
  62 + // for i := range bk.WhoRead {
  63 + // if bk.WhoRead[i] != oldBackup.WhoRead[i] {
  64 + // whoReadChanged = true
  65 + // }
  66 + // }
  67 + //}
  68 + //if whoReadChanged {
  69 + // bk.ChangeField = append(bk.ChangeField, "WhoRead")
  70 + //}
  71 + if !reflect.DeepEqual(oldBackup.WhoRead, bk.WhoRead) {
72 bk.ChangeField = append(bk.ChangeField, "WhoRead") 72 bk.ChangeField = append(bk.ChangeField, "WhoRead")
73 } 73 }
74 } 74 }
75 75
76 //比较 whoReview 76 //比较 whoReview
77 { 77 {
78 - whoReviewChanged := false  
79 - sort.Slice(bk.WhoReview, func(i, j int) bool {  
80 - return bk.WhoReview[i] < bk.WhoReview[j]  
81 - })  
82 - sort.Slice(oldBackup.WhoReview, func(i, j int) bool {  
83 - return oldBackup.WhoReview[i] < oldBackup.WhoReview[j]  
84 - })  
85 -  
86 - if len(bk.WhoReview) != len(oldBackup.WhoReview) {  
87 - whoReviewChanged = true  
88 - } else {  
89 - for i := range bk.WhoReview {  
90 - if bk.WhoReview[i] != oldBackup.WhoReview[i] {  
91 - whoReviewChanged = true  
92 - }  
93 - }  
94 - }  
95 - if whoReviewChanged { 78 + //whoReviewChanged := false
  79 + //sort.Slice(bk.WhoReview, func(i, j int) bool {
  80 + // return bk.WhoReview[i] < bk.WhoReview[j]
  81 + //})
  82 + //sort.Slice(oldBackup.WhoReview, func(i, j int) bool {
  83 + // return oldBackup.WhoReview[i] < oldBackup.WhoReview[j]
  84 + //})
  85 + //
  86 + //if len(bk.WhoReview) != len(oldBackup.WhoReview) {
  87 + // whoReviewChanged = true
  88 + //} else {
  89 + // for i := range bk.WhoReview {
  90 + // if bk.WhoReview[i] != oldBackup.WhoReview[i] {
  91 + // whoReviewChanged = true
  92 + // }
  93 + // }
  94 + //}
  95 + //if whoReviewChanged {
  96 + // bk.ChangeField = append(bk.ChangeField, "WhoReview")
  97 + //}
  98 + if !reflect.DeepEqual(oldBackup.WhoReview, bk.WhoReview) {
96 bk.ChangeField = append(bk.ChangeField, "WhoReview") 99 bk.ChangeField = append(bk.ChangeField, "WhoReview")
97 } 100 }
98 } 101 }
99 //比较段落内容+图片+视频 是否发生变更 102 //比较段落内容+图片+视频 是否发生变更
100 { 103 {
101 - sectionChanged := false  
102 - newSectionData := map[string]string{  
103 - "title": bk.Title,  
104 - }  
105 -  
106 - oldSectionData := map[string]string{  
107 - "title": oldBackup.Title,  
108 - }  
109 -  
110 - for _, val := range bk.Section {  
111 - mkey := fmt.Sprintf("section-%d", val.SortBy)  
112 - newSectionData[mkey] = val.Content  
113 - }  
114 - for _, val := range bk.Images {  
115 - newSectionData[val.Url] = ""  
116 - }  
117 - for _, val := range bk.Videos {  
118 - newSectionData[val.Url] = ""  
119 - }  
120 -  
121 - for _, val := range oldBackup.Section {  
122 - mKey := fmt.Sprintf("section-%d", val.SortBy)  
123 - oldSectionData[mKey] = val.Content  
124 - }  
125 - for _, val := range oldBackup.Images {  
126 - oldSectionData[val.Url] = ""  
127 - }  
128 - for _, val := range oldBackup.Videos {  
129 - oldSectionData[val.Url] = ""  
130 - }  
131 - newSectionJson, _ := json.Marshal(newSectionData)  
132 - oldSectionJson, _ := json.Marshal(oldSectionData)  
133 - if ok := bytes.Equal(newSectionJson, oldSectionJson); !ok {  
134 - sectionChanged = true  
135 - }  
136 - if sectionChanged { 104 + //sectionChanged := false
  105 + //newSectionData := map[string]string{
  106 + // "title": bk.Title,
  107 + //}
  108 + //
  109 + //oldSectionData := map[string]string{
  110 + // "title": oldBackup.Title,
  111 + //}
  112 + //
  113 + //for _, val := range bk.Section {
  114 + // mkey := fmt.Sprintf("section-%d", val.SortBy)
  115 + // newSectionData[mkey] = val.Content
  116 + //}
  117 + //for _, val := range bk.Images {
  118 + // newSectionData[val.Url] = ""
  119 + //}
  120 + //for _, val := range bk.Videos {
  121 + // newSectionData[val.Url] = ""
  122 + //}
  123 + //
  124 + //for _, val := range oldBackup.Section {
  125 + // mKey := fmt.Sprintf("section-%d", val.SortBy)
  126 + // oldSectionData[mKey] = val.Content
  127 + //}
  128 + //for _, val := range oldBackup.Images {
  129 + // oldSectionData[val.Url] = ""
  130 + //}
  131 + //for _, val := range oldBackup.Videos {
  132 + // oldSectionData[val.Url] = ""
  133 + //}
  134 + //newSectionJson, _ := json.Marshal(newSectionData)
  135 + //oldSectionJson, _ := json.Marshal(oldSectionData)
  136 + //if ok := bytes.Equal(newSectionJson, oldSectionJson); !ok {
  137 + // sectionChanged = true
  138 + //}
  139 + //if sectionChanged {
  140 + // bk.ChangeField = append(bk.ChangeField, "Section")
  141 + //}
  142 + if !reflect.DeepEqual(backUpContent(bk), backUpContent(oldBackup)) {
137 bk.ChangeField = append(bk.ChangeField, "Section") 143 bk.ChangeField = append(bk.ChangeField, "Section")
138 } 144 }
139 } 145 }
140 return len(bk.ChangeField) > 0 146 return len(bk.ChangeField) > 0
141 } 147 }
142 148
  149 +func backUpContent(bk *ArticleBackup) string {
  150 + buf := bytes.NewBuffer(nil)
  151 + buf.WriteString(bk.Title)
  152 + for _, val := range bk.Images {
  153 + buf.WriteString(val.Url)
  154 + }
  155 + for _, val := range bk.Videos {
  156 + buf.WriteString(val.Url)
  157 + }
  158 + for _, val := range bk.Section {
  159 + buf.WriteString(val.Content)
  160 + }
  161 + return buf.String()
  162 +}
  163 +
143 // 创建备份信息 164 // 创建备份信息
144 func (bk *ArticleBackup) MakeBackup(operator UserSimple, article *Article, section []*ArticleSection, action string) { 165 func (bk *ArticleBackup) MakeBackup(operator UserSimple, article *Article, section []*ArticleSection, action string) {
145 sectionBackup := make([]ArticleSection, len(section)) 166 sectionBackup := make([]ArticleSection, len(section))