|
@@ -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,93 +48,117 @@ func (bk *ArticleBackup) CheckChangeField(oldBackup *ArticleBackup) bool { |
|
@@ -51,93 +48,117 @@ 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
|
+ //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)) {
|
|
|
143
|
+ bk.ChangeField = append(bk.ChangeField, "Section")
|
104
|
}
|
144
|
}
|
105
|
-
|
|
|
106
|
- oldSectionData := map[string]string{
|
|
|
107
|
- "title": oldBackup.Title,
|
|
|
108
|
}
|
145
|
}
|
|
|
146
|
+ return len(bk.ChangeField) > 0
|
|
|
147
|
+}
|
109
|
|
148
|
|
110
|
- for _, val := range bk.Section {
|
|
|
111
|
- mkey := fmt.Sprintf("section-%d", val.SortBy)
|
|
|
112
|
- newSectionData[mkey] = val.Content
|
|
|
113
|
- }
|
149
|
+func backUpContent(bk *ArticleBackup) string {
|
|
|
150
|
+ buf := bytes.NewBuffer(nil)
|
|
|
151
|
+ buf.WriteString(bk.Title)
|
114
|
for _, val := range bk.Images {
|
152
|
for _, val := range bk.Images {
|
115
|
- newSectionData[val.Url] = ""
|
153
|
+ buf.WriteString(val.Url)
|
116
|
}
|
154
|
}
|
117
|
for _, val := range bk.Videos {
|
155
|
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 {
|
|
|
137
|
- bk.ChangeField = append(bk.ChangeField, "Section")
|
156
|
+ buf.WriteString(val.Url)
|
138
|
}
|
157
|
}
|
|
|
158
|
+ for _, val := range bk.Section {
|
|
|
159
|
+ buf.WriteString(val.Content)
|
139
|
}
|
160
|
}
|
140
|
- return len(bk.ChangeField) > 0
|
161
|
+ return buf.String()
|
141
|
}
|
162
|
}
|
142
|
|
163
|
|
143
|
// 创建备份信息
|
164
|
// 创建备份信息
|