package model import ( "strconv" "strings" ) type SystemUserDepthRole struct { Id int64 `json:"id"` UserId int64 `json:"userId"` PastureId int64 `json:"pastureId"` DepthIds string `json:"depthIds"` RoleIds string `json:"roleIds"` CreatedAt int64 `json:"createdAt"` UpdatedAt int64 `json:"updatedAt"` } func (s *SystemUserDepthRole) TableName() string { return "system_user_depth_role" } func NewSystemUserDepthRole(pastureId, userId int64, depthIds, roleIds string) *SystemUserDepthRole { return &SystemUserDepthRole{ UserId: userId, PastureId: pastureId, DepthIds: depthIds, RoleIds: roleIds, } } func NewSystemUserDepthRoleList(userId int64, pastureDepth map[int64]string) []*SystemUserDepthRole { res := make([]*SystemUserDepthRole, 0) for pastureId, depthIds := range pastureDepth { res = append(res, NewSystemUserDepthRole(pastureId, userId, depthIds, "")) } return res } func (s *SystemUserDepthRole) GetRoleIds() []int32 { res := make([]int32, 0) if s.RoleIds != "" { roleIds := strings.Split(s.RoleIds, ",") for _, idStr := range roleIds { id, _ := strconv.Atoi(idStr) res = append(res, int32(id)) } } return res } func (s *SystemUserDepthRole) GetDepthIds() []int32 { res := make([]int32, 0) if s.DepthIds != "" { depthIds := strings.Split(s.DepthIds, ",") for _, idStr := range depthIds { id, _ := strconv.Atoi(idStr) res = append(res, int32(id)) } } return res }