erp.go 943 B

123456789101112131415161718192021222324252627282930313233
  1. package svc
  2. import (
  3. "fmt"
  4. "strings"
  5. "git.i2edu.net/i2/go-zero/core/stores/sqlc"
  6. "git.i2edu.net/i2/go-zero/core/stores/sqlx"
  7. "git.i2edu.net/i2/i2-bill-erp/internal/config"
  8. "git.i2edu.net/i2/i2-bill-erp/model"
  9. "github.com/thoas/go-funk"
  10. )
  11. type ErpUtil struct {
  12. Config config.Config
  13. SqlConn sqlx.SqlConn
  14. }
  15. func (rp *ErpUtil) InRoles(userId string, roles ...string) (bool, error) {
  16. user := model.SysUser{}
  17. role := strings.Join(funk.Map(roles, func(r string) string { return fmt.Sprintf("'%v'", r) }).([]string), ",")
  18. err := rp.SqlConn.QueryRowPartial(&user, fmt.Sprintf(`SELECT sys_user_role.user_id id FROM sys_user_role
  19. left join sys_role on sys_role.id=sys_user_role.role_id
  20. 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)
  21. switch err {
  22. case nil:
  23. return true, nil
  24. case sqlc.ErrNotFound:
  25. return false, nil
  26. default:
  27. return true, nil
  28. }
  29. }