|
|
@@ -1,14 +1,9 @@
|
|
|
package svc
|
|
|
|
|
|
import (
|
|
|
- "fmt"
|
|
|
- "strings"
|
|
|
-
|
|
|
"git.i2edu.net/i2/i2-bill-erp/internal/config"
|
|
|
"git.i2edu.net/i2/i2-bill-erp/model"
|
|
|
- "github.com/thoas/go-funk"
|
|
|
|
|
|
- "git.i2edu.net/i2/go-zero/core/stores/sqlc"
|
|
|
"git.i2edu.net/i2/go-zero/core/stores/sqlx"
|
|
|
)
|
|
|
|
|
|
@@ -21,27 +16,6 @@ type ServiceContext struct {
|
|
|
MktPartTimeUser model.MktPartTimeUserModel
|
|
|
}
|
|
|
|
|
|
-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
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
func NewServiceContext(c config.Config) *ServiceContext {
|
|
|
sc := ServiceContext{
|
|
|
Config: c,
|