-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
171 lines (151 loc) · 4.83 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
package controllers
import (
"mm-wiki/app/models"
)
type MainController struct {
BaseController
}
func (this *MainController) Index() {
collectDocs, err := models.CollectionModel.GetCollectionsByUserIdAndType(this.UserId, models.Collection_Type_Doc)
if err != nil {
this.ErrorLog("查找收藏文档错误: " + err.Error())
this.ViewError("查找收藏文档错误!")
}
docIds := []string{}
for _, collectDoc := range collectDocs {
docIds = append(docIds, collectDoc["resource_id"])
}
documents, err := models.DocumentModel.GetDocumentsByDocumentIds(docIds)
if err != nil {
this.ErrorLog("查找收藏文档错误: " + err.Error())
this.ViewError("查找收藏文档错误!")
}
this.Data["documents"] = documents
this.Data["count"] = len(documents)
this.viewLayout("main/index", "main")
}
func (this *MainController) Default() {
page, _ := this.GetInt("page", 1)
number, _ := this.GetInt("number", 10)
maxPage := 10
if page >= maxPage {
page = maxPage
}
//number := 8
limit := (page - 1) * number
logDocuments, err := models.LogDocumentModel.GetLogDocumentsByLimit(limit, number)
if err != nil {
this.ErrorLog("查找更新文档列表失败:" + err.Error())
this.ViewError("查找更新文档列表失败!")
}
count, err := models.LogDocumentModel.CountLogDocuments()
if err != nil {
this.ErrorLog("查找更新文档总数失败:" + err.Error())
this.ViewError("查找更新文档列表失败!")
}
if count >= int64(maxPage*number) {
count = int64(maxPage * number)
}
userIds := []string{}
docIds := []string{}
for _, logDocument := range logDocuments {
userIds = append(userIds, logDocument["user_id"])
docIds = append(docIds, logDocument["document_id"])
}
users, err := models.UserModel.GetUsersByUserIds(userIds)
if err != nil {
this.ErrorLog("查找更新文档用户失败:" + err.Error())
this.ViewError("查找更新文档列表失败!")
}
docs, err := models.DocumentModel.GetAllDocumentsByDocumentIds(docIds)
if err != nil {
this.ErrorLog("查找文档信息失败:" + err.Error())
this.ViewError("查找更新文档列表失败!")
}
for _, logDocument := range logDocuments {
logDocument["username"] = ""
for _, user := range users {
if logDocument["user_id"] == user["user_id"] {
logDocument["username"] = user["username"]
logDocument["given_name"] = user["given_name"]
break
}
}
for _, doc := range docs {
if logDocument["document_id"] == doc["document_id"] {
logDocument["document_name"] = doc["name"]
logDocument["document_type"] = doc["type"]
break
}
}
}
// link
links, err := models.LinkModel.GetLinksOrderBySequence()
if err != nil {
this.ErrorLog("查找快捷链接失败:" + err.Error())
this.ViewError("查找快捷链接失败!")
}
// contacts
contacts, err := models.ContactModel.GetAllContact()
if err != nil {
this.ErrorLog("查找快捷链接失败:" + err.Error())
this.ViewError("查找快捷链接失败!")
}
// main title config
mainTitle := ""
mainDescription := ""
mainTitleConfig, err := models.ConfigModel.GetConfigByKey(models.Config_Key_MainTitle)
if err != nil {
this.ErrorLog("查找 main_title 配置失败:" + err.Error())
} else {
if len(mainTitleConfig) > 0 {
mainTitle = mainTitleConfig["value"]
}
}
mainDescriptionConfig, err := models.ConfigModel.GetConfigByKey(models.Config_Key_MainDescription)
if err != nil {
this.ErrorLog("查找 main_description 配置失败:" + err.Error())
} else {
if len(mainDescriptionConfig) > 0 {
mainDescription = mainDescriptionConfig["value"]
}
}
this.Data["panel_title"] = mainTitle
this.Data["panel_description"] = mainDescription
this.Data["logDocuments"] = logDocuments
this.Data["links"] = links
this.Data["contacts"] = contacts
this.SetPaginator(number, count)
this.viewLayout("main/default", "default")
}
func (this *MainController) About() {
this.viewLayout("main/about", "default")
}
func (this *MainController) Search() {
page, _ := this.GetInt("page", 1)
documentName := this.GetString("document_name", "")
number, _ := this.GetRangeInt("number", 20, 10, 100)
limit := (page - 1) * number
var documents = []map[string]string{}
var err error
var count int64
if documentName != "" {
count, err = models.DocumentModel.CountDocumentsLikeName(documentName)
if err != nil {
this.ErrorLog("搜索文档总数出错:" + err.Error())
this.ViewError("搜索文档错误!")
}
if count > 0 {
documents, err = models.DocumentModel.GetDocumentsByLikeNameAndLimit(documentName, limit, number)
if err != nil {
this.ErrorLog("搜索文档列表出错:" + err.Error())
this.ViewError("搜索文档错误!")
}
}
}
this.Data["document_name"] = documentName
this.Data["documents"] = documents
this.Data["count"] = count
this.SetPaginator(number, count)
this.viewLayout("main/search", "default")
}