...
|
...
|
@@ -271,8 +271,11 @@ func (userService *UserService) CreateUser(createUserCommand *command.CreateUser |
|
|
UserInfo: nweUserInfo,
|
|
|
EnableStatus: createUserCommand.EnableStatus,
|
|
|
Ext: &domain.Ext{
|
|
|
Phone: createUserCommand.Phone,
|
|
|
UserName: createUserCommand.UserName,
|
|
|
Phone: createUserCommand.Phone,
|
|
|
UserName: createUserCommand.UserName,
|
|
|
DepName: createUserCommand.DepartmentName,
|
|
|
IcCardNumber: createUserCommand.IcCardNumber,
|
|
|
EmployeeType: createUserCommand.EmployeeType,
|
|
|
},
|
|
|
CreatedAt: time.Now(),
|
|
|
UpdatedAt: time.Now(),
|
...
|
...
|
@@ -536,10 +539,12 @@ func (userService *UserService) ListUser(listUserQuery *query.ListUserQuery) (in |
|
|
_, 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 {
|
|
|
if dep != nil && org != nil && company != nil {
|
|
|
user.Department = dep.ConvDep()
|
|
|
user.Organization = org.CloneSample()
|
|
|
user.Company = company.CloneSample()
|
|
|
}
|
|
|
if userBase != nil {
|
|
|
user.UserInfo = userBase.UserInfo
|
|
|
user.Favorite = userBase.Favorite
|
|
|
}
|
...
|
...
|
@@ -702,7 +707,7 @@ func (userService *UserService) UpdateUser(updateUserCommand *command.UpdateUser |
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
_, user, err := factory.FastPgUser(transactionContext, updateUserCommand.UserId, factory.WithDataAuthRequired(), factory.WithOperator(updateUserCommand.OperateInfo))
|
|
|
_, user, err := factory.FastPgUser(transactionContext, updateUserCommand.UserId, factory.WithOperator(updateUserCommand.OperateInfo)) //, factory.WithDataAuthRequired()
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
...
|
...
|
@@ -720,11 +725,14 @@ func (userService *UserService) UpdateUser(updateUserCommand *command.UpdateUser |
|
|
user.UserRole = userRole
|
|
|
|
|
|
userInfo := &domain.UserInfo{
|
|
|
UserName: updateUserCommand.UserName,
|
|
|
Phone: updateUserCommand.Phone,
|
|
|
Avatar: updateUserCommand.Avatar,
|
|
|
Email: updateUserCommand.Email,
|
|
|
UserName: updateUserCommand.UserName,
|
|
|
Phone: updateUserCommand.Phone,
|
|
|
Avatar: updateUserCommand.Avatar,
|
|
|
Email: updateUserCommand.Email,
|
|
|
DepartmentName: updateUserCommand.DepartmentName,
|
|
|
}
|
|
|
user.Ext.EmployeeType = updateUserCommand.EmployeeType
|
|
|
user.Ext.IcCardNumber = updateUserCommand.IcCardNumber
|
|
|
|
|
|
updateUserService, _ := factory.CreatePgUpdateUserService(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -853,6 +861,123 @@ func (userService *UserService) UpdateFavorite(updateFavoriteCommand *command.Up |
|
|
return struct{}{}, nil
|
|
|
}
|
|
|
|
|
|
// 创建
|
|
|
func (userService *UserService) CreateAdminUser(createUserCommand *command.CreateAdminUserCommand) (interface{}, error) {
|
|
|
if err := createUserCommand.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
if err := transactionContext.StartTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
nweUserInfo := &domain.UserInfo{
|
|
|
UserName: createUserCommand.UserName,
|
|
|
Phone: createUserCommand.Phone,
|
|
|
Avatar: createUserCommand.Avatar,
|
|
|
Email: createUserCommand.Email,
|
|
|
DepartmentName: createUserCommand.DepartmentName,
|
|
|
}
|
|
|
var sampleUserOrg = make([]*domain.Org, 0)
|
|
|
var sampleUserRole = make([]*domain.Role, 0)
|
|
|
newUser := &domain.User{
|
|
|
CompanyId: createUserCommand.CompanyId,
|
|
|
UserType: createUserCommand.UserType,
|
|
|
UserCode: createUserCommand.UserCode,
|
|
|
OrganizationId: createUserCommand.OrganizationId,
|
|
|
DepartmentId: createUserCommand.DepartmentId,
|
|
|
UserOrg: sampleUserOrg,
|
|
|
UserRole: sampleUserRole,
|
|
|
FavoriteMenus: []string{},
|
|
|
//CooperationInfo: &domain.CooperationInfo{},
|
|
|
UserInfo: nweUserInfo,
|
|
|
EnableStatus: createUserCommand.EnableStatus,
|
|
|
Ext: &domain.Ext{
|
|
|
Phone: createUserCommand.Phone,
|
|
|
UserName: createUserCommand.UserName,
|
|
|
DepName: createUserCommand.DepartmentName,
|
|
|
},
|
|
|
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, createUserCommand.Password); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
userDto := &dto.UserDto{}
|
|
|
if err := userDto.LoadDto(user, nil); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return userDto, nil
|
|
|
}
|
|
|
|
|
|
// 更新
|
|
|
func (userService *UserService) UpdateAdminUser(updateUserCommand *command.UpdateAdminUserCommand) (interface{}, error) {
|
|
|
if err := updateUserCommand.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
if err := transactionContext.StartTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
_, user, err := factory.FastPgUser(transactionContext, updateUserCommand.UserId, factory.WithDataAuthRequired(), factory.WithOperator(updateUserCommand.OperateInfo))
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
user.DepartmentId = updateUserCommand.DepartmentId
|
|
|
user.OrganizationId = updateUserCommand.OrganizationId
|
|
|
var userOrg = make([]*domain.Org, 0)
|
|
|
for i := range updateUserCommand.UserOrg {
|
|
|
userOrg = append(userOrg, &domain.Org{OrgId: updateUserCommand.UserOrg[i]})
|
|
|
}
|
|
|
user.UserOrg = userOrg
|
|
|
var userRole = make([]*domain.Role, 0)
|
|
|
for i := range updateUserCommand.UserRole {
|
|
|
userRole = append(userRole, &domain.Role{RoleId: updateUserCommand.UserRole[i]})
|
|
|
}
|
|
|
user.UserRole = userRole
|
|
|
|
|
|
userInfo := &domain.UserInfo{
|
|
|
UserName: updateUserCommand.UserName,
|
|
|
Phone: updateUserCommand.Phone,
|
|
|
Avatar: updateUserCommand.Avatar,
|
|
|
Email: updateUserCommand.Email,
|
|
|
DepartmentName: updateUserCommand.DepartmentName,
|
|
|
}
|
|
|
|
|
|
updateUserService, _ := factory.CreatePgUpdateUserService(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
if user, err = updateUserService.UpdateUser(nil, user, userInfo, user.EnableStatus); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
userDto := &dto.UserDto{}
|
|
|
if err := userDto.LoadDto(user, nil); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return userDto, nil
|
|
|
}
|
|
|
|
|
|
func NewUserService(options map[string]interface{}) *UserService {
|
|
|
newUserService := &UserService{}
|
|
|
return newUserService
|
...
|
...
|
|