feat: automate business upgrades and sync reviewed frontend
This commit is contained in:
@@ -204,26 +204,11 @@ func (r *accountRepo) Update(ctx context.Context, a *business.Account) error {
|
||||
}
|
||||
|
||||
func (r *accountRepo) AuthorityForLevel(ctx context.Context, level int) (uint, error) {
|
||||
// 原角色 ID 仅用于查迁移映射,不作为 Kra 角色 ID 使用。
|
||||
legacy := map[int]string{1: "2083497078545207297", 2: "2087435436573081601", 3: "2087361690139152385"}
|
||||
oldID, ok := legacy[level]
|
||||
if !ok {
|
||||
if level < 1 || level > 3 {
|
||||
return 0, business.ErrBusinessRole
|
||||
}
|
||||
db := r.data.DB().WithContext(ctx)
|
||||
var id uint
|
||||
if db.Migrator().HasTable("sw_kra_id_map") {
|
||||
if err := db.Table("sw_kra_id_map m").Select("m.new_id").Joins("JOIN sys_authorities a ON a.authority_id=m.new_id AND a.deleted_at IS NULL").Where("m.entity = ? AND m.old_id = ?", "role", oldID).Scan(&id).Error; err != nil {
|
||||
return 0, business.ErrStorage
|
||||
}
|
||||
if id != 0 && id != 888 {
|
||||
return id, nil
|
||||
}
|
||||
}
|
||||
// 新安装可使用对应中文角色;匹配不唯一时停止创建,避免错授权限。
|
||||
names := map[int]string{1: "一级商务", 2: "二级商务", 3: "三级商务"}
|
||||
var ids []uint
|
||||
if err := db.Table("sys_authorities").Where("authority_name = ? AND deleted_at IS NULL AND authority_id <> ?", names[level], 888).Pluck("authority_id", &ids).Error; err != nil {
|
||||
if err := r.data.DB().WithContext(ctx).Table("sys_authorities").Where("business_level=? AND deleted_at IS NULL AND authority_id<>888", level).Pluck("authority_id", &ids).Error; err != nil {
|
||||
return 0, business.ErrStorage
|
||||
}
|
||||
if len(ids) != 1 {
|
||||
|
||||
Reference in New Issue
Block a user