You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.3 KiB

  1. package system
  2. import (
  3. "github.com/flipped-aurora/gin-vue-admin/server/global"
  4. "github.com/flipped-aurora/gin-vue-admin/server/model/system"
  5. "github.com/pkg/errors"
  6. "gorm.io/gorm"
  7. )
  8. var Dictionary = new(dictionary)
  9. type dictionary struct{}
  10. func (d *dictionary) TableName() string {
  11. return "sys_dictionaries"
  12. }
  13. func (d *dictionary) Initialize() error {
  14. status := new(bool)
  15. *status = true
  16. entities := []system.SysDictionary{
  17. {Name: "性别", Type: "gender", Status: status, Desc: "性别字典"},
  18. {Name: "数据库int类型", Type: "int", Status: status, Desc: "int类型对应的数据库类型"},
  19. {Name: "数据库时间日期类型", Type: "time.Time", Status: status, Desc: "数据库时间日期类型"},
  20. {Name: "数据库浮点型", Type: "float64", Status: status, Desc: "数据库浮点型"},
  21. {Name: "数据库字符串", Type: "string", Status: status, Desc: "数据库字符串"},
  22. {Name: "数据库bool类型", Type: "bool", Status: status, Desc: "数据库bool类型"},
  23. }
  24. if err := global.GVA_DB.Create(&entities).Error; err != nil {
  25. return errors.Wrap(err, d.TableName()+"表数据初始化失败!")
  26. }
  27. return nil
  28. }
  29. func (d *dictionary) CheckDataExist() bool {
  30. if errors.Is(global.GVA_DB.Where("type = ?", "bool").First(&system.SysDictionary{}).Error, gorm.ErrRecordNotFound) { // 判断是否存在数据
  31. return false
  32. }
  33. return true
  34. }