...
|
...
|
@@ -3,11 +3,8 @@ package domain |
|
|
import (
|
|
|
"bytes"
|
|
|
"context"
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
"sort"
|
|
|
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
|
|
|
"reflect"
|
|
|
)
|
|
|
|
|
|
// 编辑文章后保存的历史记录
|
...
|
...
|
@@ -51,95 +48,119 @@ func (bk *ArticleBackup) CheckChangeField(oldBackup *ArticleBackup) bool { |
|
|
bk.ChangeField = make([]string, 0)
|
|
|
//比较 WhoRead
|
|
|
{
|
|
|
whoReadChanged := false
|
|
|
sort.Slice(bk.WhoRead, func(i, j int) bool {
|
|
|
return bk.WhoRead[i] < bk.WhoRead[j]
|
|
|
})
|
|
|
sort.Slice(oldBackup.WhoRead, func(i, j int) bool {
|
|
|
return oldBackup.WhoRead[i] < oldBackup.WhoRead[j]
|
|
|
})
|
|
|
|
|
|
if len(bk.WhoRead) != len(oldBackup.WhoRead) {
|
|
|
whoReadChanged = true
|
|
|
} else {
|
|
|
for i := range bk.WhoRead {
|
|
|
if bk.WhoRead[i] != oldBackup.WhoRead[i] {
|
|
|
whoReadChanged = true
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if whoReadChanged {
|
|
|
//whoReadChanged := false
|
|
|
//sort.Slice(bk.WhoRead, func(i, j int) bool {
|
|
|
// return bk.WhoRead[i] < bk.WhoRead[j]
|
|
|
//})
|
|
|
//sort.Slice(oldBackup.WhoRead, func(i, j int) bool {
|
|
|
// return oldBackup.WhoRead[i] < oldBackup.WhoRead[j]
|
|
|
//})
|
|
|
//
|
|
|
//if len(bk.WhoRead) != len(oldBackup.WhoRead) {
|
|
|
// whoReadChanged = true
|
|
|
//} else {
|
|
|
// for i := range bk.WhoRead {
|
|
|
// if bk.WhoRead[i] != oldBackup.WhoRead[i] {
|
|
|
// whoReadChanged = true
|
|
|
// }
|
|
|
// }
|
|
|
//}
|
|
|
//if whoReadChanged {
|
|
|
// bk.ChangeField = append(bk.ChangeField, "WhoRead")
|
|
|
//}
|
|
|
if !reflect.DeepEqual(oldBackup.WhoRead, bk.WhoRead) {
|
|
|
bk.ChangeField = append(bk.ChangeField, "WhoRead")
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//比较 whoReview
|
|
|
{
|
|
|
whoReviewChanged := false
|
|
|
sort.Slice(bk.WhoReview, func(i, j int) bool {
|
|
|
return bk.WhoReview[i] < bk.WhoReview[j]
|
|
|
})
|
|
|
sort.Slice(oldBackup.WhoReview, func(i, j int) bool {
|
|
|
return oldBackup.WhoReview[i] < oldBackup.WhoReview[j]
|
|
|
})
|
|
|
|
|
|
if len(bk.WhoReview) != len(oldBackup.WhoReview) {
|
|
|
whoReviewChanged = true
|
|
|
} else {
|
|
|
for i := range bk.WhoReview {
|
|
|
if bk.WhoReview[i] != oldBackup.WhoReview[i] {
|
|
|
whoReviewChanged = true
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if whoReviewChanged {
|
|
|
//whoReviewChanged := false
|
|
|
//sort.Slice(bk.WhoReview, func(i, j int) bool {
|
|
|
// return bk.WhoReview[i] < bk.WhoReview[j]
|
|
|
//})
|
|
|
//sort.Slice(oldBackup.WhoReview, func(i, j int) bool {
|
|
|
// return oldBackup.WhoReview[i] < oldBackup.WhoReview[j]
|
|
|
//})
|
|
|
//
|
|
|
//if len(bk.WhoReview) != len(oldBackup.WhoReview) {
|
|
|
// whoReviewChanged = true
|
|
|
//} else {
|
|
|
// for i := range bk.WhoReview {
|
|
|
// if bk.WhoReview[i] != oldBackup.WhoReview[i] {
|
|
|
// whoReviewChanged = true
|
|
|
// }
|
|
|
// }
|
|
|
//}
|
|
|
//if whoReviewChanged {
|
|
|
// bk.ChangeField = append(bk.ChangeField, "WhoReview")
|
|
|
//}
|
|
|
if !reflect.DeepEqual(oldBackup.WhoReview, bk.WhoReview) {
|
|
|
bk.ChangeField = append(bk.ChangeField, "WhoReview")
|
|
|
}
|
|
|
}
|
|
|
//比较段落内容+图片+视频 是否发生变更
|
|
|
{
|
|
|
sectionChanged := false
|
|
|
newSectionData := map[string]string{
|
|
|
"title": bk.Title,
|
|
|
}
|
|
|
|
|
|
oldSectionData := map[string]string{
|
|
|
"title": oldBackup.Title,
|
|
|
}
|
|
|
|
|
|
for _, val := range bk.Section {
|
|
|
mkey := fmt.Sprintf("section-%d", val.SortBy)
|
|
|
newSectionData[mkey] = val.Content
|
|
|
}
|
|
|
for _, val := range bk.Images {
|
|
|
newSectionData[val.Url] = ""
|
|
|
}
|
|
|
for _, val := range bk.Videos {
|
|
|
newSectionData[val.Url] = ""
|
|
|
}
|
|
|
|
|
|
for _, val := range oldBackup.Section {
|
|
|
mKey := fmt.Sprintf("section-%d", val.SortBy)
|
|
|
oldSectionData[mKey] = val.Content
|
|
|
}
|
|
|
for _, val := range oldBackup.Images {
|
|
|
oldSectionData[val.Url] = ""
|
|
|
}
|
|
|
for _, val := range oldBackup.Videos {
|
|
|
oldSectionData[val.Url] = ""
|
|
|
}
|
|
|
newSectionJson, _ := json.Marshal(newSectionData)
|
|
|
oldSectionJson, _ := json.Marshal(oldSectionData)
|
|
|
if ok := bytes.Equal(newSectionJson, oldSectionJson); !ok {
|
|
|
sectionChanged = true
|
|
|
}
|
|
|
if sectionChanged {
|
|
|
//sectionChanged := false
|
|
|
//newSectionData := map[string]string{
|
|
|
// "title": bk.Title,
|
|
|
//}
|
|
|
//
|
|
|
//oldSectionData := map[string]string{
|
|
|
// "title": oldBackup.Title,
|
|
|
//}
|
|
|
//
|
|
|
//for _, val := range bk.Section {
|
|
|
// mkey := fmt.Sprintf("section-%d", val.SortBy)
|
|
|
// newSectionData[mkey] = val.Content
|
|
|
//}
|
|
|
//for _, val := range bk.Images {
|
|
|
// newSectionData[val.Url] = ""
|
|
|
//}
|
|
|
//for _, val := range bk.Videos {
|
|
|
// newSectionData[val.Url] = ""
|
|
|
//}
|
|
|
//
|
|
|
//for _, val := range oldBackup.Section {
|
|
|
// mKey := fmt.Sprintf("section-%d", val.SortBy)
|
|
|
// oldSectionData[mKey] = val.Content
|
|
|
//}
|
|
|
//for _, val := range oldBackup.Images {
|
|
|
// oldSectionData[val.Url] = ""
|
|
|
//}
|
|
|
//for _, val := range oldBackup.Videos {
|
|
|
// oldSectionData[val.Url] = ""
|
|
|
//}
|
|
|
//newSectionJson, _ := json.Marshal(newSectionData)
|
|
|
//oldSectionJson, _ := json.Marshal(oldSectionData)
|
|
|
//if ok := bytes.Equal(newSectionJson, oldSectionJson); !ok {
|
|
|
// sectionChanged = true
|
|
|
//}
|
|
|
//if sectionChanged {
|
|
|
// bk.ChangeField = append(bk.ChangeField, "Section")
|
|
|
//}
|
|
|
if !reflect.DeepEqual(backUpContent(bk), backUpContent(oldBackup)) {
|
|
|
bk.ChangeField = append(bk.ChangeField, "Section")
|
|
|
}
|
|
|
}
|
|
|
return len(bk.ChangeField) > 0
|
|
|
}
|
|
|
|
|
|
func backUpContent(bk *ArticleBackup) string {
|
|
|
buf := bytes.NewBuffer(nil)
|
|
|
buf.WriteString(bk.Title)
|
|
|
for _, val := range bk.Images {
|
|
|
buf.WriteString(val.Url)
|
|
|
}
|
|
|
for _, val := range bk.Videos {
|
|
|
buf.WriteString(val.Url)
|
|
|
}
|
|
|
for _, val := range bk.Section {
|
|
|
buf.WriteString(val.Content)
|
|
|
}
|
|
|
return buf.String()
|
|
|
}
|
|
|
|
|
|
// 创建备份信息
|
|
|
func (bk *ArticleBackup) MakeBackup(operator UserSimple, article *Article, section []*ArticleSection, action string) {
|
|
|
sectionBackup := make([]ArticleSection, len(section))
|
...
|
...
|
|