role_related_users_dto.go 1001 字节
package dto

import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain"

type RoleRelatedUsersDto struct {
	NotInRoleUser []interface{} `json:"notInRoleUser"`
	RoleUser      []interface{} `json:"roleUser"`
}

func (dto *RoleRelatedUsersDto) LoadDto(users []*domain.User, relatedRoleId int64) error {
	var notInRoleUser = make([]interface{}, 0)
	var roleUser = make([]interface{}, 0)

	for i := 0; i < len(users); i++ {
		if ok := users[i].ExistsUserRole(relatedRoleId); ok {
			roleUser = append(roleUser, newRelatedUsers(users[i]))
		} else {
			notInRoleUser = append(notInRoleUser, newRelatedUsers(users[i]))
		}
	}
	dto.NotInRoleUser = notInRoleUser
	dto.RoleUser = roleUser
	return nil
}

func newRelatedUsers(user *domain.User) map[string]interface{} {
	return map[string]interface{}{
		"departmentId":   user.DepartmentId,
		"departmentName": user.Ext.DepName,
		"userId":         user.UserId,
		"userName":       user.Ext.UserName,
		"userCode":       user.UserCode,
	}
}