data_authorities.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package source
  2. import (
  3. "github.com/flipped-aurora/gin-vue-admin/server/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("sys_authority_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. }