perf: 优化模型自动更新表字段

This commit is contained in:
zhanzhenping
2024-07-05 16:08:43 +08:00
parent f3846cc431
commit 1dd82a67fb
4 changed files with 16 additions and 1 deletions

View File

@@ -143,6 +143,11 @@ func RegisterModel() {
gob.Register(models.Document{}) gob.Register(models.Document{})
gob.Register(models.Template{}) gob.Register(models.Template{})
//migrate.RegisterMigration() //migrate.RegisterMigration()
err := orm.RunSyncdb("default", false, true)
if err != nil {
logs.Error("注册Model失败 ->", err)
os.Exit(1)
}
} }
// RegisterLogger 注册日志 // RegisterLogger 注册日志

View File

@@ -122,6 +122,7 @@ func (c *BookController) Setting() {
if book.PrivateToken != "" { if book.PrivateToken != "" {
book.PrivateToken = conf.URLFor("DocumentController.Index", ":key", book.Identify, "token", book.PrivateToken) book.PrivateToken = conf.URLFor("DocumentController.Index", ":key", book.Identify, "token", book.PrivateToken)
} }
fmt.Println("book.PrintState", book.PrintState)
c.Data["Model"] = book c.Data["Model"] = book
} }
@@ -153,6 +154,7 @@ func (c *BookController) SaveBook() {
isUseFirstDocument := strings.TrimSpace(c.GetString("is_use_first_document")) == "on" isUseFirstDocument := strings.TrimSpace(c.GetString("is_use_first_document")) == "on"
autoSave := strings.TrimSpace(c.GetString("auto_save")) == "on" autoSave := strings.TrimSpace(c.GetString("auto_save")) == "on"
itemId, _ := c.GetInt("itemId") itemId, _ := c.GetInt("itemId")
pringState := strings.TrimSpace(c.GetString("print_state")) == "on"
if strings.Count(description, "") > 500 { if strings.Count(description, "") > 500 {
c.JsonResult(6004, i18n.Tr(c.Lang, "message.project_desc_tips")) c.JsonResult(6004, i18n.Tr(c.Lang, "message.project_desc_tips"))
@@ -211,6 +213,11 @@ func (c *BookController) SaveBook() {
} else { } else {
book.AutoSave = 0 book.AutoSave = 0
} }
if pringState {
book.PrintSate = 1
} else {
book.PrintSate = 0
}
if err := book.Update(); err != nil { if err := book.Update(); err != nil {
c.JsonResult(6006, i18n.Tr(c.Lang, "message.failed")) c.JsonResult(6006, i18n.Tr(c.Lang, "message.failed"))
} }

View File

@@ -83,6 +83,7 @@ type Book struct {
IsUseFirstDocument int `orm:"column(is_use_first_document);type(int);default(0);description(是否使用第一篇文章项目为默认首页,0 否/1 是)" json:"is_use_first_document"` IsUseFirstDocument int `orm:"column(is_use_first_document);type(int);default(0);description(是否使用第一篇文章项目为默认首页,0 否/1 是)" json:"is_use_first_document"`
//是否开启自动保存0 否/1 是 //是否开启自动保存0 否/1 是
AutoSave int `orm:"column(auto_save);type(tinyint);default(0);description(是否开启自动保存0 否/1 是)" json:"auto_save"` AutoSave int `orm:"column(auto_save);type(tinyint);default(0);description(是否开启自动保存0 否/1 是)" json:"auto_save"`
PrintSate int `orm:"column(print_state);type(tinyint);default(1);description(启用打印0 否/1 是)" json:"print_state"`
} }
func (book *Book) String() string { func (book *Book) String() string {

View File

@@ -71,6 +71,7 @@ type BookResult struct {
IsDisplayComment bool `json:"is_display_comment"` IsDisplayComment bool `json:"is_display_comment"`
IsDownload bool `json:"is_download"` IsDownload bool `json:"is_download"`
AutoSave bool `json:"auto_save"` AutoSave bool `json:"auto_save"`
PrintState bool `json:"print_state"`
Lang string Lang string
} }
@@ -213,6 +214,7 @@ func (m *BookResult) ToBookResult(book Book) *BookResult {
m.HistoryCount = book.HistoryCount m.HistoryCount = book.HistoryCount
m.IsDownload = book.IsDownload == 0 m.IsDownload = book.IsDownload == 0
m.AutoSave = book.AutoSave == 1 m.AutoSave = book.AutoSave == 1
m.PrintState = book.PrintSate == 1
m.ItemId = book.ItemId m.ItemId = book.ItemId
m.RoleId = conf.BookRoleNoSpecific m.RoleId = conf.BookRoleNoSpecific