...
|
...
|
@@ -8,6 +8,7 @@ import ( |
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/user/command"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/user/query"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
// 用户
|
...
|
...
|
@@ -92,10 +93,43 @@ func (userService *UserService) CreateCooperator(createCooperatorCommand *comman |
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
nweUserInfo := &domain.UserInfo{
|
|
|
UserName: createCooperatorCommand.UserName,
|
|
|
Phone: createCooperatorCommand.Phone,
|
|
|
Avatar: createCooperatorCommand.Avatar,
|
|
|
Email: createCooperatorCommand.Email,
|
|
|
}
|
|
|
var sampleUserOrg = make([]*domain.Org, 0)
|
|
|
var sampleUserRole = make([]*domain.Role, 0)
|
|
|
newUser := &domain.User{
|
|
|
CompanyId: createCooperatorCommand.CompanyId,
|
|
|
UserType: domain.UserTypeCooperation,
|
|
|
UserCode: createCooperatorCommand.UserCode,
|
|
|
OrganizationId: createCooperatorCommand.OrgId,
|
|
|
UserOrg: sampleUserOrg,
|
|
|
UserRole: sampleUserRole,
|
|
|
FavoriteMenus: []string{},
|
|
|
CooperationInfo: &domain.CooperationInfo{},
|
|
|
UserInfo: nweUserInfo,
|
|
|
//EnableStatus: createUserCommand.EnableStatus,
|
|
|
Ext: &domain.Ext{
|
|
|
Phone: createCooperatorCommand.Phone,
|
|
|
},
|
|
|
CreatedAt: time.Now(),
|
|
|
UpdatedAt: time.Now(),
|
|
|
}
|
|
|
var user *domain.User
|
|
|
createUserService, _ := factory.CreatePgCreateUserService(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
if user, err = createUserService.CreateUser(nil, newUser, createCooperatorCommand.Password); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return nil, nil
|
|
|
return user, nil
|
|
|
}
|
|
|
|
|
|
// 创建
|
...
|
...
|
@@ -113,38 +147,49 @@ func (userService *UserService) CreateUser(createUserCommand *command.CreateUser |
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
nweUserInfo := &domain.UserInfo{
|
|
|
UserName: createUserCommand.UserName,
|
|
|
Phone: createUserCommand.Phone,
|
|
|
Avatar: createUserCommand.Avatar,
|
|
|
Email: createUserCommand.Email,
|
|
|
}
|
|
|
var sampleUserOrg = make([]*domain.Org, 0)
|
|
|
var sampleUserRole = make([]*domain.Role, 0)
|
|
|
for i := range createUserCommand.UserOrg {
|
|
|
sampleUserOrg = append(sampleUserOrg, createUserCommand.UserOrg[i].CloneSample())
|
|
|
}
|
|
|
for i := range createUserCommand.UserRole {
|
|
|
sampleUserRole = append(sampleUserRole, createUserCommand.UserRole[i].CloneSample())
|
|
|
}
|
|
|
newUser := &domain.User{
|
|
|
CompanyId: createUserCommand.CompanyId,
|
|
|
UserType: createUserCommand.UserType,
|
|
|
UserCode: createUserCommand.UserCode,
|
|
|
OrganizationId: createUserCommand.OrganizationId,
|
|
|
DepartmentId: createUserCommand.DepartmentId,
|
|
|
UserOrg: createUserCommand.UserOrg,
|
|
|
UserRole: createUserCommand.UserRole,
|
|
|
//CooperationInfo: createUserCommand.CooperationInfo,
|
|
|
UserOrg: sampleUserOrg,
|
|
|
UserRole: sampleUserRole,
|
|
|
FavoriteMenus: []string{},
|
|
|
CooperationInfo: &domain.CooperationInfo{},
|
|
|
UserInfo: nweUserInfo,
|
|
|
EnableStatus: createUserCommand.EnableStatus,
|
|
|
//Password: createUserCommand.Password,
|
|
|
//UserName: createUserCommand.UserName,
|
|
|
//Phone: createUserCommand.Phone,
|
|
|
//Avatar: createUserCommand.Avatar,
|
|
|
//Email: createUserCommand.Email,
|
|
|
}
|
|
|
var userRepository domain.UserRepository
|
|
|
if value, err := factory.CreateUserRepository(map[string]interface{}{
|
|
|
Ext: &domain.Ext{
|
|
|
Phone: createUserCommand.Phone,
|
|
|
},
|
|
|
CreatedAt: time.Now(),
|
|
|
UpdatedAt: time.Now(),
|
|
|
}
|
|
|
var user *domain.User
|
|
|
createUserService, _ := factory.CreatePgCreateUserService(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
userRepository = value
|
|
|
})
|
|
|
if user, err = createUserService.CreateUser(nil, newUser, createUserCommand.Password); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
if user, err := userRepository.Save(newUser); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return user, nil
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 移除我收藏的菜单
|
...
|
...
|
@@ -304,7 +349,7 @@ func (userService *UserService) ListUser(listUserQuery *query.ListUserQuery) (in |
|
|
}
|
|
|
}
|
|
|
|
|
|
// 移除
|
|
|
// 移除 (暂不需要)
|
|
|
func (userService *UserService) RemoveUser(removeUserCommand *command.RemoveUserCommand) (interface{}, error) {
|
|
|
if err := removeUserCommand.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
...
|
...
|
|