123456789101112131415161718192021222324252627282930313233 |
- package svc
- import (
- "fmt"
- "strings"
- "git.i2edu.net/i2/go-zero/core/stores/sqlc"
- "git.i2edu.net/i2/go-zero/core/stores/sqlx"
- "git.i2edu.net/i2/i2-bill-erp/internal/config"
- "git.i2edu.net/i2/i2-bill-erp/model"
- "github.com/thoas/go-funk"
- )
- type ErpUtil struct {
- Config config.Config
- SqlConn sqlx.SqlConn
- }
- func (rp *ErpUtil) InRoles(userId string, roles ...string) (bool, error) {
- user := model.SysUser{}
- role := strings.Join(funk.Map(roles, func(r string) string { return fmt.Sprintf("'%v'", r) }).([]string), ",")
- err := rp.SqlConn.QueryRowPartial(&user, fmt.Sprintf(`SELECT sys_user_role.user_id id FROM sys_user_role
- left join sys_role on sys_role.id=sys_user_role.role_id
- where sys_role.code in (%v) and sys_role.del_flag=0 and sys_user_role.del_flag=0 and sys_user_role.user_id=?`, role), userId)
- switch err {
- case nil:
- return true, nil
- case sqlc.ErrNotFound:
- return false, nil
- default:
- return true, nil
- }
- }
|