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.

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