package model import ( "bigdata_archives/app/e" "bigdata_archives/global" "bigdata_archives/utils" "log" ) type SystemSettings struct { utils.BaseModel Title string `json:"title"` } func (*SystemSettings) TableName() string { return "system_settings" } func (s SystemSettings) GetSystemSettings() (SystemSettings, e.Rescode) { //TODO implement me tx := global.DBLink.First(&s) if tx.Error == nil && tx.RowsAffected > 0 { return s, e.SUCCESS } return s, e.TheSystemIsAbnormal } func (s *SystemSettings) UpdateSystemSettings(systemSettings SystemSettings) (SystemSettings, e.Rescode) { //TODO implement me tx := global.DBLink.Where("id = ?", systemSettings.ID).Updates(systemSettings) if tx.Error == nil && tx.RowsAffected > 0 { return systemSettings, e.SUCCESS } return systemSettings, e.UPDATEFAIL } func (s *SystemSettings) CreateSystemSettings(systemSettings SystemSettings) (SystemSettings, e.Rescode) { //TODO implement me tx := global.DBLink.Create(&systemSettings) if tx.Error == nil && tx.RowsAffected > 0 { return systemSettings, e.SUCCESS } return systemSettings, e.CreateFailed } func (s *SystemSettings) DeleteSystemSettings(id int) (SystemSettings, e.Rescode) { //TODO implement me tx := global.DBLink.Where("id = ?", id).Delete(s) if tx.Error == nil && tx.RowsAffected > 0 { return *s, e.SUCCESS } return *s, e.DELETEFAIL } func CreateSystemSettings() { var setting = SystemSettings{} var count int64 global.DBLink.Table("system_settings").Where("id = ?", "1").Count(&count) if count == 0 { setting.Title = "可视化管理平台" create := global.DBLink.Create(&setting) if create.Error == nil && create.RowsAffected > 0 { log.Println("创建系统设置成功") } } }