Skip to content

Commit 1dd82a6

Browse files
committed
perf: 优化模型自动更新表字段
1 parent f3846cc commit 1dd82a6

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

commands/command.go

+5
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@ func RegisterModel() {
143143
gob.Register(models.Document{})
144144
gob.Register(models.Template{})
145145
//migrate.RegisterMigration()
146+
err := orm.RunSyncdb("default", false, true)
147+
if err != nil {
148+
logs.Error("注册Model失败 ->", err)
149+
os.Exit(1)
150+
}
146151
}
147152

148153
// RegisterLogger 注册日志

controllers/BookController.go

+7
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ func (c *BookController) Setting() {
122122
if book.PrivateToken != "" {
123123
book.PrivateToken = conf.URLFor("DocumentController.Index", ":key", book.Identify, "token", book.PrivateToken)
124124
}
125+
fmt.Println("book.PrintState", book.PrintState)
125126
c.Data["Model"] = book
126127

127128
}
@@ -153,6 +154,7 @@ func (c *BookController) SaveBook() {
153154
isUseFirstDocument := strings.TrimSpace(c.GetString("is_use_first_document")) == "on"
154155
autoSave := strings.TrimSpace(c.GetString("auto_save")) == "on"
155156
itemId, _ := c.GetInt("itemId")
157+
pringState := strings.TrimSpace(c.GetString("print_state")) == "on"
156158

157159
if strings.Count(description, "") > 500 {
158160
c.JsonResult(6004, i18n.Tr(c.Lang, "message.project_desc_tips"))
@@ -211,6 +213,11 @@ func (c *BookController) SaveBook() {
211213
} else {
212214
book.AutoSave = 0
213215
}
216+
if pringState {
217+
book.PrintSate = 1
218+
} else {
219+
book.PrintSate = 0
220+
}
214221
if err := book.Update(); err != nil {
215222
c.JsonResult(6006, i18n.Tr(c.Lang, "message.failed"))
216223
}

models/BookModel.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ type Book struct {
8282
//是否使用第一篇文章项目为默认首页,0 否/1 是
8383
IsUseFirstDocument int `orm:"column(is_use_first_document);type(int);default(0);description(是否使用第一篇文章项目为默认首页,0 否/1 是)" json:"is_use_first_document"`
8484
//是否开启自动保存:0 否/1 是
85-
AutoSave int `orm:"column(auto_save);type(tinyint);default(0);description(是否开启自动保存:0 否/1 是)" json:"auto_save"`
85+
AutoSave int `orm:"column(auto_save);type(tinyint);default(0);description(是否开启自动保存:0 否/1 是)" json:"auto_save"`
86+
PrintSate int `orm:"column(print_state);type(tinyint);default(1);description(启用打印:0 否/1 是)" json:"print_state"`
8687
}
8788

8889
func (book *Book) String() string {

models/BookResult.go

+2
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ type BookResult struct {
7171
IsDisplayComment bool `json:"is_display_comment"`
7272
IsDownload bool `json:"is_download"`
7373
AutoSave bool `json:"auto_save"`
74+
PrintState bool `json:"print_state"`
7475
Lang string
7576
}
7677

@@ -213,6 +214,7 @@ func (m *BookResult) ToBookResult(book Book) *BookResult {
213214
m.HistoryCount = book.HistoryCount
214215
m.IsDownload = book.IsDownload == 0
215216
m.AutoSave = book.AutoSave == 1
217+
m.PrintState = book.PrintSate == 1
216218
m.ItemId = book.ItemId
217219
m.RoleId = conf.BookRoleNoSpecific
218220

0 commit comments

Comments
 (0)