作者 yangfu

用户列表DTO

@@ -52,11 +52,18 @@ func (dto *UserDto) LoadDto(user *domain.User, company *domain.Company) error { @@ -52,11 +52,18 @@ func (dto *UserDto) LoadDto(user *domain.User, company *domain.Company) error {
52 dto.CooperationInfo = user.CooperationInfo 52 dto.CooperationInfo = user.CooperationInfo
53 dto.EnableStatus = user.EnableStatus 53 dto.EnableStatus = user.EnableStatus
54 dto.UserInfo = user.UserInfo 54 dto.UserInfo = user.UserInfo
  55 + if company != nil {
55 dto.Company = &Company{ 56 dto.Company = &Company{
56 CompanyId: company.CompanyId, 57 CompanyId: company.CompanyId,
57 CompanyInfo: *company.CompanyInfo, 58 CompanyInfo: *company.CompanyInfo,
58 Status: company.Status, 59 Status: company.Status,
59 } 60 }
  61 + }
  62 + if user.UserInfo == nil {
  63 + dto.UserInfo = &domain.UserInfo{
  64 + UserName: user.Ext.UserName,
  65 + }
  66 + }
60 dto.Organization = user.Organization 67 dto.Organization = user.Organization
61 dto.Department = user.Department 68 dto.Department = user.Department
62 return nil 69 return nil
@@ -25,6 +25,8 @@ type ListUserQuery struct { @@ -25,6 +25,8 @@ type ListUserQuery struct {
25 DepName string `cname:"部门名称" json:"depName,omitempty"` 25 DepName string `cname:"部门名称" json:"depName,omitempty"`
26 // 手机号码 26 // 手机号码
27 Phone string `cname:"手机号码" json:"phone,omitempty"` 27 Phone string `cname:"手机号码" json:"phone,omitempty"`
  28 + // 实时拉取数据 (获取最新的)
  29 + PullRealTime bool `cname:"拉群最新数据" json:"pullRealTime,omitempty"`
28 } 30 }
29 31
30 func (listUserQuery *ListUserQuery) Valid(validation *validation.Validation) { 32 func (listUserQuery *ListUserQuery) Valid(validation *validation.Validation) {
@@ -222,6 +222,7 @@ func (userService *UserService) CreateUser(createUserCommand *command.CreateUser @@ -222,6 +222,7 @@ func (userService *UserService) CreateUser(createUserCommand *command.CreateUser
222 EnableStatus: createUserCommand.EnableStatus, 222 EnableStatus: createUserCommand.EnableStatus,
223 Ext: &domain.Ext{ 223 Ext: &domain.Ext{
224 Phone: createUserCommand.Phone, 224 Phone: createUserCommand.Phone,
  225 + UserName: createUserCommand.UserName,
225 }, 226 },
226 CreatedAt: time.Now(), 227 CreatedAt: time.Now(),
227 UpdatedAt: time.Now(), 228 UpdatedAt: time.Now(),
@@ -391,15 +392,36 @@ func (userService *UserService) ListUser(listUserQuery *query.ListUserQuery) (in @@ -391,15 +392,36 @@ func (userService *UserService) ListUser(listUserQuery *query.ListUserQuery) (in
391 } else { 392 } else {
392 userRepository = value 393 userRepository = value
393 } 394 }
  395 + _, company, _ := factory.FastPgCompany(transactionContext, listUserQuery.CompanyId)
  396 + var dtoUsers []*dto.UserDto
394 if count, users, err := userRepository.Find(utils.ObjectToMap(listUserQuery)); err != nil { 397 if count, users, err := userRepository.Find(utils.ObjectToMap(listUserQuery)); err != nil {
395 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 398 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
396 } else { 399 } else {
  400 + for i := range users {
  401 + user := users[i]
  402 + userDto := &dto.UserDto{}
  403 + if listUserQuery.PullRealTime {
  404 + _, dep, _ := factory.FastPgOrg(transactionContext, user.DepartmentId)
  405 + _, org, _ := factory.FastPgOrg(transactionContext, user.OrganizationId)
  406 + _, userBase, _ := factory.FastPgUserBase(transactionContext, user.UserBaseId)
  407 + if dep != nil && org != nil && company != nil && userBase != nil {
  408 + user.Department = dep.ConvDep()
  409 + user.Organization = org.CloneSample()
  410 + user.Company = company.CloneSample()
  411 + user.UserInfo = userBase.UserInfo
  412 + }
  413 + }
  414 + if err := userDto.LoadDto(users[i], company); err != nil {
  415 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  416 + }
  417 + dtoUsers = append(dtoUsers, userDto)
  418 + }
397 if err := transactionContext.CommitTransaction(); err != nil { 419 if err := transactionContext.CommitTransaction(); err != nil {
398 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 420 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
399 } 421 }
400 return map[string]interface{}{ 422 return map[string]interface{}{
401 "count": count, 423 "count": count,
402 - "users": users, 424 + "users": dtoUsers,
403 }, nil 425 }, nil
404 } 426 }
405 } 427 }
@@ -36,7 +36,7 @@ func (ptr *PgCreateUserService) CreateUser(optUser *domain.User, newUser *domain @@ -36,7 +36,7 @@ func (ptr *PgCreateUserService) CreateUser(optUser *domain.User, newUser *domain
36 if err != nil { 36 if err != nil {
37 return nil, err 37 return nil, err
38 } 38 }
39 - // 0.冗余组织部门 39 + // 0.冗余扩展数据
40 if newUser.Ext != nil { 40 if newUser.Ext != nil {
41 if len(newUser.Ext.OrgName) == 0 && newUser.OrganizationId > 0 { 41 if len(newUser.Ext.OrgName) == 0 && newUser.OrganizationId > 0 {
42 if org, err := orgRepository.FindOne(map[string]interface{}{"orgId": newUser.OrganizationId}); err != nil { 42 if org, err := orgRepository.FindOne(map[string]interface{}{"orgId": newUser.OrganizationId}); err != nil {