user_dto.go
3.0 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package dto
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain"
"time"
)
type UserDto struct {
// 用户Id 用户唯一标识
UserId int64 `json:"userId,omitempty"`
// 用户基础数据id
UserBaseId int64 `json:"userBaseId,omitempty"`
// 用户类型 1:企业内部用户(内部添加) 2:共创用户 1024:企业注册用户(注册添加)
UserType int `json:"userType,omitempty"`
// 用户编号 企业内标识
UserCode string `json:"userCode,omitempty"`
// 用户关联的组织
UserOrg []*domain.Org `json:"userOrg"`
// 用户关联的角色
UserRole []*domain.Role `json:"userRole"`
// 收藏的菜单(工作台)(菜单编码列表)
FavoriteMenus []string `json:"favoriteMenus"`
// 收藏
Favorite *domain.Favorite `json:"favorite"`
// 共创信息 (共创用户有效)
CooperationInfo *domain.CooperationInfo `json:"cooperationInfo,omitempty"`
// 状态(1:启用 2:禁用 3:注销)
EnableStatus int `json:"enableStatus,omitempty"`
// 用户信息 (冗余,数据存在userBase里面)
UserInfo *domain.UserInfo `json:"userInfo,omitempty"`
// 企业id
Company *Company `json:"company,omitempty"`
// 组织机构
Organization *domain.Org `json:"org,omitempty"`
// 部门
Department *domain.Department `json:"department,omitempty"`
Im *domain.Im `json:"im,omitempty"`
// 创建时间
CreatedAt time.Time `json:"createdAt,omitempty"`
}
type Company struct {
// 企业id
CompanyId int64 `json:"companyId"`
// 企业基本信息
domain.CompanyInfo
Status int `json:"status"`
// 系统名称
SystemName string `json:"systemName,omitempty"`
}
func (dto *UserDto) LoadDto(user *domain.User, company *domain.Company) error {
dto.UserId = user.UserId
dto.UserBaseId = user.UserBaseId
dto.UserType = user.UserType
dto.UserCode = user.UserCode
dto.UserOrg = user.UserOrg
dto.UserRole = user.UserRole
dto.FavoriteMenus = user.FavoriteMenus
dto.CooperationInfo = user.CooperationInfo
dto.EnableStatus = user.EnableStatus
dto.UserInfo = user.UserInfo
dto.Favorite = user.Favorite
if company != nil {
dto.Company = &Company{
CompanyId: company.CompanyId,
CompanyInfo: *company.CompanyInfo,
Status: company.Status,
SystemName: company.CompanyConfig.SystemName,
}
}
if user.UserInfo == nil {
dto.UserInfo = &domain.UserInfo{
UserName: user.Ext.UserName,
Phone: user.Ext.Phone,
IcCardNumber: user.Ext.IcCardNumber,
EmployeeType: user.Ext.EmployeeType,
}
} else {
dto.UserInfo.IcCardNumber = user.Ext.IcCardNumber
dto.UserInfo.EmployeeType = user.Ext.EmployeeType
}
if len(dto.UserRole) == 0 {
dto.UserRole = make([]*domain.Role, 0)
}
if len(dto.UserOrg) == 0 {
dto.UserOrg = make([]*domain.Org, 0)
}
dto.Organization = user.Organization
dto.Department = user.Department
dto.CreatedAt = user.CreatedAt
if user.UserType == domain.UserTypeCooperation {
dto.Department = &domain.Department{
DepartmentName: "共创用户",
}
}
return nil
}