department_users_dto.go 1.3 KB
package dto

import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user"

type DepartmentUsersDto struct {
	Departments []*Department `json:"departments"`
}

type Department struct {
	DepartmentID   int64  `json:"departmentId"`
	DepartmentName string `json:"departmentName"`
	Users          []User `json:"users"`
}
type User struct {
	UserID   int                    `json:"userId"`
	UserInfo map[string]interface{} `json:"userInfo"`
}

func (dto *DepartmentUsersDto) LoadDto(subDepartment *allied_creation_user.DataOrgGetSubDepartment, userSearch *allied_creation_user.DataUserSearch) error {
	var mapDepartment = make(map[int64]*Department)

	for i := range subDepartment.Orgs {
		org := subDepartment.Orgs[i]
		dep := &Department{
			DepartmentID:   int64(org.OrgID),
			DepartmentName: org.OrgName,
			Users:          make([]User, 0),
		}
		dto.Departments = append(dto.Departments, dep)
		mapDepartment[dep.DepartmentID] = dep
	}

	for i := range userSearch.Users {
		user := userSearch.Users[i]
		if user.Department == nil {
			continue
		}
		if v, ok := mapDepartment[int64(user.Department.DepartmentId)]; ok {
			v.Users = append(v.Users, User{
				UserID: user.UserId,
				UserInfo: map[string]interface{}{
					"userName": user.UserInfo.UserName,
				},
			})
		}
	}
	return nil
}