正在显示
4 个修改的文件
包含
45 行增加
和
55 行删除
@@ -18,35 +18,35 @@ type UserService struct { | @@ -18,35 +18,35 @@ type UserService struct { | ||
18 | } | 18 | } |
19 | 19 | ||
20 | // 批量添加用户 | 20 | // 批量添加用户 |
21 | -func (userService *UserService) BatchAdd(batchAddCommand *command.BatchAddCommand) (interface{}, error) { | ||
22 | - if err := batchAddCommand.ValidateCommand(); err != nil { | ||
23 | - return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
24 | - } | ||
25 | - transactionContext, err := factory.CreateTransactionContext(nil) | ||
26 | - if err != nil { | ||
27 | - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
28 | - } | ||
29 | - if err := transactionContext.StartTransaction(); err != nil { | ||
30 | - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
31 | - } | ||
32 | - defer func() { | ||
33 | - transactionContext.RollbackTransaction() | ||
34 | - }() | ||
35 | - | ||
36 | - batchAddUserService, _ := factory.CreateBatchAddUserService(map[string]interface{}{ | ||
37 | - "transactionContext": transactionContext, | ||
38 | - }) | ||
39 | - if err = batchAddUserService.BatchAddUser(batchAddCommand.OperateInfo, batchAddCommand.Users, batchAddCommand.Password); err != nil { | ||
40 | - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
41 | - } | ||
42 | - | ||
43 | - if err := transactionContext.CommitTransaction(); err != nil { | ||
44 | - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
45 | - } | ||
46 | - return nil, nil | ||
47 | -} | ||
48 | - | ||
49 | -// 批量添加用户 | 21 | +//func (userService *UserService) BatchAdd(batchAddCommand *command.BatchAddCommand) (interface{}, error) { |
22 | +// if err := batchAddCommand.ValidateCommand(); err != nil { | ||
23 | +// return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
24 | +// } | ||
25 | +// transactionContext, err := factory.CreateTransactionContext(nil) | ||
26 | +// if err != nil { | ||
27 | +// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
28 | +// } | ||
29 | +// if err := transactionContext.StartTransaction(); err != nil { | ||
30 | +// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
31 | +// } | ||
32 | +// defer func() { | ||
33 | +// transactionContext.RollbackTransaction() | ||
34 | +// }() | ||
35 | +// | ||
36 | +// batchAddUserService, _ := factory.CreateBatchAddUserService(map[string]interface{}{ | ||
37 | +// "transactionContext": transactionContext, | ||
38 | +// }) | ||
39 | +// if err = batchAddUserService.BatchAddUser(batchAddCommand.OperateInfo, batchAddCommand.Users, batchAddCommand.Password); err != nil { | ||
40 | +// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
41 | +// } | ||
42 | +// | ||
43 | +// if err := transactionContext.CommitTransaction(); err != nil { | ||
44 | +// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
45 | +// } | ||
46 | +// return nil, nil | ||
47 | +//} | ||
48 | + | ||
49 | +// BatchAdd2 批量添加用户 | ||
50 | func (userService *UserService) BatchAdd2(batchAddCommand *command.BatchAdd2Command) (interface{}, error) { | 50 | func (userService *UserService) BatchAdd2(batchAddCommand *command.BatchAdd2Command) (interface{}, error) { |
51 | if err := batchAddCommand.ValidateCommand(); err != nil { | 51 | if err := batchAddCommand.ValidateCommand(); err != nil { |
52 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | 52 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) |
@@ -13,7 +13,7 @@ type PgBatchAddUserService struct { | @@ -13,7 +13,7 @@ type PgBatchAddUserService struct { | ||
13 | transactionContext *pgTransaction.TransactionContext | 13 | transactionContext *pgTransaction.TransactionContext |
14 | } | 14 | } |
15 | 15 | ||
16 | -// CreateUser 批量添加用户服务 | 16 | +// BatchAddUser 批量添加用户服务 |
17 | // | 17 | // |
18 | // optUser 操作用户 | 18 | // optUser 操作用户 |
19 | // users 待添加用户列表数据 | 19 | // users 待添加用户列表数据 |
@@ -107,7 +107,6 @@ func (ptr *PgBatchAddUserService) BatchAddUser2(optUser *domain.OperateInfo, use | @@ -107,7 +107,6 @@ func (ptr *PgBatchAddUserService) BatchAddUser2(optUser *domain.OperateInfo, use | ||
107 | user.FailReason = err.Error() | 107 | user.FailReason = err.Error() |
108 | failRows = append(failRows, user) | 108 | failRows = append(failRows, user) |
109 | continue | 109 | continue |
110 | - //return err | ||
111 | } | 110 | } |
112 | var org, dep *domain.Org | 111 | var org, dep *domain.Org |
113 | var ok bool | 112 | var ok bool |
@@ -115,26 +114,22 @@ func (ptr *PgBatchAddUserService) BatchAddUser2(optUser *domain.OperateInfo, use | @@ -115,26 +114,22 @@ func (ptr *PgBatchAddUserService) BatchAddUser2(optUser *domain.OperateInfo, use | ||
115 | user.FailReason = "导入的组织机构不存在:" + user.Org | 114 | user.FailReason = "导入的组织机构不存在:" + user.Org |
116 | failRows = append(failRows, user) | 115 | failRows = append(failRows, user) |
117 | continue | 116 | continue |
118 | - //return fmt.Errorf("导入的组织机构不存在:" + user.Org) | ||
119 | } | 117 | } |
120 | if dep, ok = mapOrg[user.Department]; !ok && user.UserType != domain.UserTypeCooperation { | 118 | if dep, ok = mapOrg[user.Department]; !ok && user.UserType != domain.UserTypeCooperation { |
121 | user.FailReason = "导入的所属部门不存在:" + user.Department | 119 | user.FailReason = "导入的所属部门不存在:" + user.Department |
122 | failRows = append(failRows, user) | 120 | failRows = append(failRows, user) |
123 | continue | 121 | continue |
124 | - //return fmt.Errorf("导入的所属部门不存在:" + user.Department) | ||
125 | } | 122 | } |
126 | newUser := &domain.User{ | 123 | newUser := &domain.User{ |
127 | CompanyId: user.CompanyId, | 124 | CompanyId: user.CompanyId, |
128 | UserType: user.UserType, | 125 | UserType: user.UserType, |
129 | UserCode: user.UserCode, | 126 | UserCode: user.UserCode, |
130 | OrganizationId: org.OrgId, | 127 | OrganizationId: org.OrgId, |
131 | - //DepartmentId: dep.OrgId, | ||
132 | - UserOrg: []*domain.Org{}, | ||
133 | - UserRole: []*domain.Role{}, | ||
134 | - FavoriteMenus: []string{}, | 128 | + UserOrg: []*domain.Org{}, |
129 | + UserRole: []*domain.Role{}, | ||
130 | + FavoriteMenus: []string{}, | ||
135 | CooperationInfo: &domain.CooperationInfo{ | 131 | CooperationInfo: &domain.CooperationInfo{ |
136 | CooperationCompany: user.CooperationCompany, | 132 | CooperationCompany: user.CooperationCompany, |
137 | - //CooperationDeadline: user.CooperationDeadline, | ||
138 | }, | 133 | }, |
139 | UserInfo: &domain.UserInfo{ | 134 | UserInfo: &domain.UserInfo{ |
140 | UserName: user.UserName, | 135 | UserName: user.UserName, |
@@ -147,7 +142,6 @@ func (ptr *PgBatchAddUserService) BatchAddUser2(optUser *domain.OperateInfo, use | @@ -147,7 +142,6 @@ func (ptr *PgBatchAddUserService) BatchAddUser2(optUser *domain.OperateInfo, use | ||
147 | Phone: user.Phone, | 142 | Phone: user.Phone, |
148 | UserName: user.UserName, | 143 | UserName: user.UserName, |
149 | OrgName: org.OrgName, | 144 | OrgName: org.OrgName, |
150 | - //DepName: dep.OrgName, | ||
151 | }, | 145 | }, |
152 | CreatedAt: time.Now(), | 146 | CreatedAt: time.Now(), |
153 | UpdatedAt: time.Now(), | 147 | UpdatedAt: time.Now(), |
@@ -164,11 +158,13 @@ func (ptr *PgBatchAddUserService) BatchAddUser2(optUser *domain.OperateInfo, use | @@ -164,11 +158,13 @@ func (ptr *PgBatchAddUserService) BatchAddUser2(optUser *domain.OperateInfo, use | ||
164 | continue | 158 | continue |
165 | } | 159 | } |
166 | } | 160 | } |
161 | + if user.UserType == domain.UserTypeEmployee { | ||
162 | + newUser.UserOrg = append(newUser.UserOrg, org.CloneSample()) | ||
163 | + } | ||
167 | if newUser, err = createUserService.CreateUser(nil, newUser, password); err != nil { | 164 | if newUser, err = createUserService.CreateUser(nil, newUser, password); err != nil { |
168 | user.FailReason = err.Error() | 165 | user.FailReason = err.Error() |
169 | failRows = append(failRows, user) | 166 | failRows = append(failRows, user) |
170 | continue | 167 | continue |
171 | - //return fmt.Errorf("%v %v", user.UserName, err.Error()) | ||
172 | } | 168 | } |
173 | } | 169 | } |
174 | return failRows, nil | 170 | return failRows, nil |
@@ -206,12 +202,6 @@ func (ptr *PgBatchAddUserService) preCheck2(user *domain.BatchAddUserItem) error | @@ -206,12 +202,6 @@ func (ptr *PgBatchAddUserService) preCheck2(user *domain.BatchAddUserItem) error | ||
206 | if len(user.Phone) == 0 || len(user.Phone) != 11 { | 202 | if len(user.Phone) == 0 || len(user.Phone) != 11 { |
207 | return fmt.Errorf("导入的手机号不是有效手机号") | 203 | return fmt.Errorf("导入的手机号不是有效手机号") |
208 | } | 204 | } |
209 | - //if len(user.Org) == 0 { | ||
210 | - // return fmt.Errorf("导入的组织机构不存在") | ||
211 | - //} | ||
212 | - //if len(user.Department) == 0 && user.UserType == domain.UserTypeEmployee { | ||
213 | - // return fmt.Errorf("导入的所属部门不存在") | ||
214 | - //} | ||
215 | return nil | 205 | return nil |
216 | } | 206 | } |
217 | 207 |
@@ -84,14 +84,14 @@ func (controller *UserController) GetUserProfile() { | @@ -84,14 +84,14 @@ func (controller *UserController) GetUserProfile() { | ||
84 | controller.Response(data, err) | 84 | controller.Response(data, err) |
85 | } | 85 | } |
86 | 86 | ||
87 | -func (controller *UserController) BatchAdd() { | ||
88 | - userService := service.NewUserService(nil) | ||
89 | - batchAddCommand := &command.BatchAddCommand{} | ||
90 | - Must(controller.Unmarshal(batchAddCommand)) | ||
91 | - batchAddCommand.OperateInfo = ParseOperateInfo(controller.BaseController) | ||
92 | - data, err := userService.BatchAdd(batchAddCommand) | ||
93 | - controller.Response(data, err) | ||
94 | -} | 87 | +//func (controller *UserController) BatchAdd() { |
88 | +// userService := service.NewUserService(nil) | ||
89 | +// batchAddCommand := &command.BatchAddCommand{} | ||
90 | +// Must(controller.Unmarshal(batchAddCommand)) | ||
91 | +// batchAddCommand.OperateInfo = ParseOperateInfo(controller.BaseController) | ||
92 | +// data, err := userService.BatchAdd(batchAddCommand) | ||
93 | +// controller.Response(data, err) | ||
94 | +//} | ||
95 | 95 | ||
96 | func (controller *UserController) BatchAdd2() { | 96 | func (controller *UserController) BatchAdd2() { |
97 | userService := service.NewUserService(nil) | 97 | userService := service.NewUserService(nil) |
@@ -13,7 +13,7 @@ func init() { | @@ -13,7 +13,7 @@ func init() { | ||
13 | web.Router("/user/search", &controllers.UserController{}, "Post:SearchUser") | 13 | web.Router("/user/search", &controllers.UserController{}, "Post:SearchUser") |
14 | web.Router("/user/:userId/access-menus", &controllers.UserController{}, "Get:GetUserAccessMenus") | 14 | web.Router("/user/:userId/access-menus", &controllers.UserController{}, "Get:GetUserAccessMenus") |
15 | web.Router("/user/:userId/profile", &controllers.UserController{}, "Get:GetUserProfile") | 15 | web.Router("/user/:userId/profile", &controllers.UserController{}, "Get:GetUserProfile") |
16 | - web.Router("/user/batch-add", &controllers.UserController{}, "Post:BatchAdd") | 16 | + //web.Router("/user/batch-add", &controllers.UserController{}, "Post:BatchAdd") |
17 | web.Router("/user/batch-add2", &controllers.UserController{}, "Post:BatchAdd2") | 17 | web.Router("/user/batch-add2", &controllers.UserController{}, "Post:BatchAdd2") |
18 | web.Router("/user/batch-enable", &controllers.UserController{}, "Post:BatchEnable") | 18 | web.Router("/user/batch-enable", &controllers.UserController{}, "Post:BatchEnable") |
19 | web.Router("/user/batch-reset-password", &controllers.UserController{}, "Post:BatchResetPassword") | 19 | web.Router("/user/batch-reset-password", &controllers.UserController{}, "Post:BatchResetPassword") |
-
请 注册 或 登录 后发表评论