department.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package service
  2. import (
  3. "go-common/app/admin/main/manager/model"
  4. "go-common/library/log"
  5. bm "go-common/library/net/http/blademaster"
  6. )
  7. // Departments .
  8. func (s *Service) Departments(c *bm.Context) (res []*model.DepartCustom, err error) {
  9. if err = s.dao.DB().Table("user_department").Where("status = ?", model.ValidateState).Find(&res).Error; err != nil {
  10. log.Error("s.Departments err (%v)", err)
  11. }
  12. return
  13. }
  14. // Roles .
  15. func (s *Service) Roles(c *bm.Context) (res []*model.RoleCustom, err error) {
  16. if err = s.dao.DB().Table("auth_item").Where("type = ?", model.TypeRole).Find(&res).Error; err != nil {
  17. log.Error("s.Roles error (%v)", err)
  18. }
  19. return
  20. }
  21. // UsersByDepartment .
  22. func (s *Service) UsersByDepartment(c *bm.Context, ID int64) (res []*model.UserCustom, err error) {
  23. if err = s.dao.DB().Table("user").Where("state =? and department_id = ?", model.ValidateState, ID).Find(&res).Error; err != nil {
  24. log.Error("s.UsersByDepartment ID (%d) error (%v)", ID, err)
  25. }
  26. return
  27. }
  28. // UsersByRole .
  29. func (s *Service) UsersByRole(c *bm.Context, ID int64) (res []*model.UserCustom, err error) {
  30. resAuthAssign := []*model.AuthAssign{}
  31. if err = s.dao.DB().Table("auth_assignment").Where("item_id = ?", ID).Find(&resAuthAssign).Error; err != nil {
  32. log.Error("s.UsersByRole ID (%d) error (%v)", ID, err)
  33. return
  34. }
  35. for _, v := range resAuthAssign {
  36. temp := &model.UserCustom{
  37. ID: v.UserID,
  38. Username: s.userNames[v.UserID],
  39. Nickname: s.userNicknames[v.UserID],
  40. }
  41. res = append(res, temp)
  42. }
  43. return
  44. }