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.

32 lines
796 B

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