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.1 KiB

  1. package information
  2. import (
  3. "gin-vue-admin/global"
  4. "github.com/gookit/color"
  5. "gorm.io/gorm"
  6. )
  7. var DataAuthorities = new(dataAuthorities)
  8. type dataAuthorities struct{}
  9. type DataAuthority struct {
  10. AuthorityId string `gorm:"column:sys_authority_authority_id"`
  11. DataAuthority string `gorm:"column:data_authority_id_authority_id"`
  12. }
  13. var infos = []DataAuthority{
  14. {"888", "888"},
  15. {"888", "8881"},
  16. {"888", "9528"},
  17. {"9528", "8881"},
  18. {"9528", "9528"},
  19. }
  20. //@author: [SliverHorn](https://github.com/SliverHorn)
  21. //@description: sys_data_authority_id 表数据初始化
  22. func (d *dataAuthorities) Init() error {
  23. return global.GVA_DB.Table("sys_data_authority_id").Transaction(func(tx *gorm.DB) error {
  24. if tx.Where("authority_id IN ('888', '9528') ").Find(&[]DataAuthority{}).RowsAffected == 5 {
  25. color.Danger.Println("\n[Mysql] --> sys_data_authority_id 表初始数据已存在!")
  26. return nil
  27. }
  28. if err := tx.Create(&infos).Error; err != nil { // 遇到错误时回滚事务
  29. return err
  30. }
  31. color.Info.Println("\n[Mysql] --> sys_data_authority_id 表初始数据成功!")
  32. return nil
  33. })
  34. }