dao-perm.go 593 B

123456789101112131415161718192021222324252627282930
  1. package dao
  2. import (
  3. "exam_system/config"
  4. "exam_system/entity"
  5. "exam_system/result"
  6. "github.com/jmoiron/sqlx"
  7. )
  8. func FindPermByRoles(roleIds []int) *result.Result {
  9. sqlStr := `
  10. SELECT
  11. p.id,
  12. p.path,
  13. p.method,
  14. p.name
  15. FROM
  16. role r, perm_role pr , perm p
  17. where r.id in (?) and pr.role_id = r.id and pr.perm_id = p.id
  18. GROUP BY p.id;`
  19. query, args, _ := sqlx.In(sqlStr, roleIds)
  20. var r []*entity.Perm
  21. query = config.DB.Rebind(query)
  22. err := config.DB.Select(&r, query, args...)
  23. if err != nil {
  24. return result.UNKNOW_ERROR.SetMsg(err.Error())
  25. }
  26. return result.SuccessResult(r)
  27. }