system_user_depth_role.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package model
  2. import (
  3. "strconv"
  4. "strings"
  5. )
  6. type SystemUserDepthRole struct {
  7. Id int64 `json:"id"`
  8. UserId int64 `json:"userId"`
  9. PastureId int64 `json:"pastureId"`
  10. DepthIds string `json:"depthIds"`
  11. RoleIds string `json:"roleIds"`
  12. CreatedAt int64 `json:"createdAt"`
  13. UpdatedAt int64 `json:"updatedAt"`
  14. }
  15. func (s *SystemUserDepthRole) TableName() string {
  16. return "system_user_depth_role"
  17. }
  18. func NewSystemUserDepthRole(pastureId, userId int64, depthIds, roleIds string) *SystemUserDepthRole {
  19. return &SystemUserDepthRole{
  20. UserId: userId,
  21. PastureId: pastureId,
  22. DepthIds: depthIds,
  23. RoleIds: roleIds,
  24. }
  25. }
  26. func NewSystemUserDepthRoleList(userId int64, pastureDepth map[int64]string) []*SystemUserDepthRole {
  27. res := make([]*SystemUserDepthRole, 0)
  28. for pastureId, depthIds := range pastureDepth {
  29. res = append(res, NewSystemUserDepthRole(pastureId, userId, depthIds, ""))
  30. }
  31. return res
  32. }
  33. func (s *SystemUserDepthRole) GetRoleIds() []int32 {
  34. res := make([]int32, 0)
  35. if s.RoleIds != "" {
  36. roleIds := strings.Split(s.RoleIds, ",")
  37. for _, idStr := range roleIds {
  38. id, _ := strconv.Atoi(idStr)
  39. res = append(res, int32(id))
  40. }
  41. }
  42. return res
  43. }
  44. func (s *SystemUserDepthRole) GetDepthIds() []int32 {
  45. res := make([]int32, 0)
  46. if s.DepthIds != "" {
  47. depthIds := strings.Split(s.DepthIds, ",")
  48. for _, idStr := range depthIds {
  49. id, _ := strconv.Atoi(idStr)
  50. res = append(res, int32(id))
  51. }
  52. }
  53. return res
  54. }