- 替换 Beego 框架为 GoFrame v2 - 重构项目结构: controller/service/dao/middleware 分层 - 替换自定义 crons 包为 gcron - 模板从 views/ 迁移到 resource/template/ - 配置从 conf/app.conf 迁移到 config.yml - 数据库从 MySQL 切换为 SQLite (modernc.org/sqlite) - 移除 agent/ 远程执行器(待后续迁移) - 移除 crons/ 自定义定时器包 - 静态资源整理到 resource/static/
53 lines
1.7 KiB
Go
53 lines
1.7 KiB
Go
package dao
|
|
|
|
import (
|
|
"context"
|
|
"ppgo_job/consts"
|
|
"ppgo_job/model/entity"
|
|
"strings"
|
|
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
"github.com/gogf/gf/v2/util/gconv"
|
|
)
|
|
|
|
var RoleAuth = new(roleAuthDao)
|
|
type roleAuthDao struct{}
|
|
|
|
func (d *roleAuthDao) Add(ctx context.Context, data *entity.RoleAuth) error {
|
|
_, err := g.DB().Model(consts.TableRoleAuth).Ctx(ctx).Data(data).Insert()
|
|
return err
|
|
}
|
|
func (d *roleAuthDao) BatchAdd(ctx context.Context, roleId int, authIds []int) error {
|
|
for _, authId := range authIds {
|
|
if err := d.Add(ctx, &entity.RoleAuth{AuthId: authId, RoleId: roleId}); err != nil { return err }
|
|
}
|
|
return nil
|
|
}
|
|
func (d *roleAuthDao) MultiAdd(ctx context.Context, roleId int, authIds []int) error {
|
|
_, err := g.DB().Model(consts.TableRoleAuth).Ctx(ctx).Where(entity.RoleAuthCols.RoleId, roleId).Delete()
|
|
if err != nil { return err }
|
|
return d.BatchAdd(ctx, roleId, authIds)
|
|
}
|
|
func (d *roleAuthDao) GetAuthIdsByRoleIds(ctx context.Context, roleIds string) (string, error) {
|
|
roleIdArr := strings.Split(roleIds, ",")
|
|
intIds := make([]int, 0)
|
|
for _, v := range roleIdArr {
|
|
if id := gconv.Int(v); id > 0 { intIds = append(intIds, id) }
|
|
}
|
|
if len(intIds) == 0 { return "", nil }
|
|
|
|
r, err := g.DB().Model(consts.TableRoleAuth).Ctx(ctx).Where(entity.RoleAuthCols.RoleId+"__in", intIds).All()
|
|
if err != nil { return "", err }
|
|
authIdSet := make(map[int]bool)
|
|
for _, item := range r {
|
|
authIdSet[item[entity.RoleAuthCols.AuthId].Int()] = true
|
|
}
|
|
ids := make([]string, 0)
|
|
for id := range authIdSet { ids = append(ids, gconv.String(id)) }
|
|
return strings.Join(ids, ","), nil
|
|
}
|
|
func (d *roleAuthDao) DeleteByRoleId(ctx context.Context, roleId int) error {
|
|
_, err := g.DB().Model(consts.TableRoleAuth).Ctx(ctx).Where(entity.RoleAuthCols.RoleId, roleId).Delete()
|
|
return err
|
|
}
|