作者 yangfu

用户列表DTO

... ... @@ -52,11 +52,18 @@ func (dto *UserDto) LoadDto(user *domain.User, company *domain.Company) error {
dto.CooperationInfo = user.CooperationInfo
dto.EnableStatus = user.EnableStatus
dto.UserInfo = user.UserInfo
if company != nil {
dto.Company = &Company{
CompanyId: company.CompanyId,
CompanyInfo: *company.CompanyInfo,
Status: company.Status,
}
}
if user.UserInfo == nil {
dto.UserInfo = &domain.UserInfo{
UserName: user.Ext.UserName,
}
}
dto.Organization = user.Organization
dto.Department = user.Department
return nil
... ...
... ... @@ -25,6 +25,8 @@ type ListUserQuery struct {
DepName string `cname:"部门名称" json:"depName,omitempty"`
// 手机号码
Phone string `cname:"手机号码" json:"phone,omitempty"`
// 实时拉取数据 (获取最新的)
PullRealTime bool `cname:"拉群最新数据" json:"pullRealTime,omitempty"`
}
func (listUserQuery *ListUserQuery) Valid(validation *validation.Validation) {
... ...
... ... @@ -222,6 +222,7 @@ func (userService *UserService) CreateUser(createUserCommand *command.CreateUser
EnableStatus: createUserCommand.EnableStatus,
Ext: &domain.Ext{
Phone: createUserCommand.Phone,
UserName: createUserCommand.UserName,
},
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
... ... @@ -391,15 +392,36 @@ func (userService *UserService) ListUser(listUserQuery *query.ListUserQuery) (in
} else {
userRepository = value
}
_, company, _ := factory.FastPgCompany(transactionContext, listUserQuery.CompanyId)
var dtoUsers []*dto.UserDto
if count, users, err := userRepository.Find(utils.ObjectToMap(listUserQuery)); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
for i := range users {
user := users[i]
userDto := &dto.UserDto{}
if listUserQuery.PullRealTime {
_, dep, _ := factory.FastPgOrg(transactionContext, user.DepartmentId)
_, org, _ := factory.FastPgOrg(transactionContext, user.OrganizationId)
_, userBase, _ := factory.FastPgUserBase(transactionContext, user.UserBaseId)
if dep != nil && org != nil && company != nil && userBase != nil {
user.Department = dep.ConvDep()
user.Organization = org.CloneSample()
user.Company = company.CloneSample()
user.UserInfo = userBase.UserInfo
}
}
if err := userDto.LoadDto(users[i], company); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
dtoUsers = append(dtoUsers, userDto)
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return map[string]interface{}{
"count": count,
"users": users,
"users": dtoUsers,
}, nil
}
}
... ...
... ... @@ -36,7 +36,7 @@ func (ptr *PgCreateUserService) CreateUser(optUser *domain.User, newUser *domain
if err != nil {
return nil, err
}
// 0.冗余组织部门
// 0.冗余扩展数据
if newUser.Ext != nil {
if len(newUser.Ext.OrgName) == 0 && newUser.OrganizationId > 0 {
if org, err := orgRepository.FindOne(map[string]interface{}{"orgId": newUser.OrganizationId}); err != nil {
... ...