authority_Ids.go 784 字节
Newer Older
1 2 3
package datas

import (
Sliver_Horn's avatar
Sliver_Horn 已提交
4
	"github.com/gookit/color"
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
	"gorm.io/gorm"
)

type SysDataAuthorityId struct {
	SysAuthorityAuthorityId    string
	DataAuthorityIdAuthorityId string
}

var DataAuthorityId = []SysDataAuthorityId{
	{"888", "888"},
	{"888", "8881"},
	{"888", "9528"},
	{"9528", "8881"},
	{"9528", "9528"},
}

func InitSysDataAuthorityId(db *gorm.DB) (err error) {
22
	return db.Table("sys_data_authority_id").Transaction(func(tx *gorm.DB) error {
Sliver_Horn's avatar
Sliver_Horn 已提交
23 24 25 26
		if tx.Where("sys_authority_authority_id IN ?", []string{"888", "9528"}).Find(&[]SysDataAuthorityId{}).RowsAffected == 5 {
			color.Danger.Println("sys_data_authority_id表的初始数据已存在!")
			return nil
		}
27 28 29 30 31 32
		if tx.Create(&DataAuthorityId).Error != nil { // 遇到错误时回滚事务
			return err
		}
		return nil
	})
}