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.

57 lines
2.5 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 DictionaryDetail = new(dictionaryDetail)
  9. type dictionaryDetail struct{}
  10. func (d *dictionaryDetail) TableName() string {
  11. return "sys_dictionary_details"
  12. }
  13. func (d *dictionaryDetail) Initialize() error {
  14. status := new(bool)
  15. *status = true
  16. entities := []system.SysDictionaryDetail{
  17. {Label: "smallint", Value: 1, Status: status, Sort: 1, SysDictionaryID: 2},
  18. {Label: "mediumint", Value: 2, Status: status, Sort: 2, SysDictionaryID: 2},
  19. {Label: "int", Value: 3, Status: status, Sort: 3, SysDictionaryID: 2},
  20. {Label: "bigint", Value: 4, Status: status, Sort: 4, SysDictionaryID: 2},
  21. {Label: "date", Status: status, SysDictionaryID: 3},
  22. {Label: "time", Value: 1, Status: status, Sort: 1, SysDictionaryID: 3},
  23. {Label: "year", Value: 2, Status: status, Sort: 2, SysDictionaryID: 3},
  24. {Label: "datetime", Value: 3, Status: status, Sort: 3, SysDictionaryID: 3},
  25. {Label: "timestamp", Value: 5, Status: status, Sort: 5, SysDictionaryID: 3},
  26. {Label: "float", Status: status, SysDictionaryID: 4},
  27. {Label: "double", Value: 1, Status: status, Sort: 1, SysDictionaryID: 4},
  28. {Label: "decimal", Value: 2, Status: status, Sort: 2, SysDictionaryID: 4},
  29. {Label: "char", Status: status, SysDictionaryID: 5},
  30. {Label: "varchar", Value: 1, Status: status, Sort: 1, SysDictionaryID: 5},
  31. {Label: "tinyblob", Value: 2, Status: status, Sort: 2, SysDictionaryID: 5},
  32. {Label: "tinytext", Value: 3, Status: status, Sort: 3, SysDictionaryID: 5},
  33. {Label: "text", Value: 4, Status: status, Sort: 4, SysDictionaryID: 5},
  34. {Label: "blob", Value: 5, Status: status, Sort: 5, SysDictionaryID: 5},
  35. {Label: "mediumblob", Value: 6, Status: status, Sort: 6, SysDictionaryID: 5},
  36. {Label: "mediumtext", Value: 7, Status: status, Sort: 7, SysDictionaryID: 5},
  37. {Label: "longblob", Value: 8, Status: status, Sort: 8, SysDictionaryID: 5},
  38. {Label: "longtext", Value: 9, Status: status, Sort: 9, SysDictionaryID: 5},
  39. {Label: "tinyint", Status: status, SysDictionaryID: 6},
  40. }
  41. if err := global.GVA_DB.Create(&entities).Error; err != nil {
  42. return errors.Wrap(err, d.TableName()+"表数据初始化失败!")
  43. }
  44. return nil
  45. }
  46. func (d *dictionaryDetail) CheckDataExist() bool {
  47. if errors.Is(global.GVA_DB.Where("id = ?", 23).First(&system.SysDictionaryDetail{}).Error, gorm.ErrRecordNotFound) { // 判断是否存在数据
  48. return false
  49. }
  50. return true
  51. }