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.

36 lines
919 B

  1. package datas
  2. import (
  3. "github.com/gookit/color"
  4. "gorm.io/gorm"
  5. "os"
  6. )
  7. type SysDataAuthorityId struct {
  8. SysAuthorityAuthorityId string
  9. DataAuthorityIdAuthorityId string
  10. }
  11. var DataAuthorityId = []SysDataAuthorityId{
  12. {"888", "888"},
  13. {"888", "8881"},
  14. {"888", "9528"},
  15. {"9528", "8881"},
  16. {"9528", "9528"},
  17. }
  18. func InitSysDataAuthorityId(db *gorm.DB) {
  19. if err := db.Table("sys_data_authority_id").Transaction(func(tx *gorm.DB) error {
  20. if tx.Where("sys_authority_authority_id IN ?", []string{"888", "9528"}).Find(&[]SysDataAuthorityId{}).RowsAffected == 5 {
  21. color.Danger.Println("sys_data_authority_id表的初始数据已存在!")
  22. return nil
  23. }
  24. if err := tx.Create(&DataAuthorityId).Error; err != nil { // 遇到错误时回滚事务
  25. return err
  26. }
  27. return nil
  28. }); err != nil {
  29. color.Warn.Printf("[Mysql]--> sys_data_authority_id 表的初始数据失败,err: %v\n", err)
  30. os.Exit(0)
  31. }
  32. }