system_settings.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package model
  2. import (
  3. "bigdata_archives/app/e"
  4. "bigdata_archives/global"
  5. "bigdata_archives/utils"
  6. "log"
  7. )
  8. type SystemSettings struct {
  9. utils.BaseModel
  10. Title string `json:"title"`
  11. }
  12. func (*SystemSettings) TableName() string {
  13. return "system_settings"
  14. }
  15. func (s SystemSettings) GetSystemSettings() (SystemSettings, e.Rescode) {
  16. //TODO implement me
  17. tx := global.DBLink.First(&s)
  18. if tx.Error == nil && tx.RowsAffected > 0 {
  19. return s, e.SUCCESS
  20. }
  21. return s, e.TheSystemIsAbnormal
  22. }
  23. func (s *SystemSettings) UpdateSystemSettings(systemSettings SystemSettings) (SystemSettings, e.Rescode) {
  24. //TODO implement me
  25. tx := global.DBLink.Where("id = ?", systemSettings.ID).Updates(systemSettings)
  26. if tx.Error == nil && tx.RowsAffected > 0 {
  27. return systemSettings, e.SUCCESS
  28. }
  29. return systemSettings, e.UPDATEFAIL
  30. }
  31. func (s *SystemSettings) CreateSystemSettings(systemSettings SystemSettings) (SystemSettings, e.Rescode) {
  32. //TODO implement me
  33. tx := global.DBLink.Create(&systemSettings)
  34. if tx.Error == nil && tx.RowsAffected > 0 {
  35. return systemSettings, e.SUCCESS
  36. }
  37. return systemSettings, e.CreateFailed
  38. }
  39. func (s *SystemSettings) DeleteSystemSettings(id int) (SystemSettings, e.Rescode) {
  40. //TODO implement me
  41. tx := global.DBLink.Where("id = ?", id).Delete(s)
  42. if tx.Error == nil && tx.RowsAffected > 0 {
  43. return *s, e.SUCCESS
  44. }
  45. return *s, e.DELETEFAIL
  46. }
  47. func CreateSystemSettings() {
  48. var setting = SystemSettings{}
  49. var count int64
  50. global.DBLink.Table("system_settings").Where("id = ?", "1").Count(&count)
  51. if count == 0 {
  52. setting.Title = "可视化管理平台"
  53. create := global.DBLink.Create(&setting)
  54. if create.Error == nil && create.RowsAffected > 0 {
  55. log.Println("创建系统设置成功")
  56. }
  57. }
  58. }