正在显示
4 个修改的文件
包含
99 行增加
和
3 行删除
pkg/application/auth/adapter/me_info.go
0 → 100644
1 | +package adapter | ||
2 | + | ||
3 | +type MeInfo struct { | ||
4 | + UserId int64 `json:"userId"` //用户名称 | ||
5 | + CompanyId int64 `json:"companyId"` //公司id | ||
6 | + CompanyName string `json:"companyName"` //公司名称 | ||
7 | + Phone string `json:"phone"` // 手机号 | ||
8 | + Name string `json:"name"` // 员工名称 | ||
9 | + IsHrbp bool `json:"isHrbp"` //是否 是hrbp | ||
10 | + IsParent bool `json:"isParent"` //是否 是上级 | ||
11 | +} |
pkg/application/auth/command/me_info.go
0 → 100644
@@ -2,6 +2,7 @@ package service | @@ -2,6 +2,7 @@ package service | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "github.com/linmadan/egglib-go/core/application" | 4 | "github.com/linmadan/egglib-go/core/application" |
5 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/auth/adapter" | ||
5 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/auth/command" | 6 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/auth/command" |
6 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory" | 7 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory" |
7 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/constant" | 8 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/constant" |
@@ -156,3 +157,76 @@ func (service *AuthService) MobileLogin(param *command.MobileLoginCommand) (map[ | @@ -156,3 +157,76 @@ func (service *AuthService) MobileLogin(param *command.MobileLoginCommand) (map[ | ||
156 | } | 157 | } |
157 | return result, nil | 158 | return result, nil |
158 | } | 159 | } |
160 | + | ||
161 | +// 获取我的 | ||
162 | +func (service *AuthService) MeInfo(param *command.GetMeInfo) (*adapter.MeInfo, error) { | ||
163 | + | ||
164 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
165 | + if err != nil { | ||
166 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
167 | + } | ||
168 | + if errStart := transactionContext.StartTransaction(); errStart != nil { | ||
169 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, errStart.Error()) | ||
170 | + } | ||
171 | + defer func() { | ||
172 | + _ = transactionContext.RollbackTransaction() | ||
173 | + }() | ||
174 | + userRepository := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext}) | ||
175 | + companyRepository := factory.CreateCompanyRepository(map[string]interface{}{"transactionContext": transactionContext}) | ||
176 | + roleRepo := factory.CreateRoleRepository(map[string]interface{}{"transactionContext": transactionContext}) | ||
177 | + roleUserRepo := factory.CreateRoleUserRepository(map[string]interface{}{"transactionContext": transactionContext}) | ||
178 | + userData, err := userRepository.FindOne(map[string]interface{}{ | ||
179 | + "id": param.UserId, | ||
180 | + }) | ||
181 | + if err != nil { | ||
182 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取员工数据"+err.Error()) | ||
183 | + } | ||
184 | + _, parentUser, err := userRepository.Find(map[string]interface{}{ | ||
185 | + "parentId": userData.Id, | ||
186 | + "limit": 1, | ||
187 | + }) | ||
188 | + if err != nil { | ||
189 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取员工数据"+err.Error()) | ||
190 | + } | ||
191 | + companyData, err := companyRepository.FindOne(map[string]interface{}{ | ||
192 | + "id": param.CompanyId, | ||
193 | + }) | ||
194 | + if err != nil { | ||
195 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取公司数据"+err.Error()) | ||
196 | + } | ||
197 | + _, roleList, err := roleRepo.Find(map[string]interface{}{"type": domain.RoleTypeSystem, "companyId": param.CompanyId}) | ||
198 | + if err != nil { | ||
199 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取角色信息列表"+err.Error()) | ||
200 | + } | ||
201 | + _, userRoleList, err := roleUserRepo.Find(map[string]interface{}{"companyId": param.CompanyId, "userId": param.UserId}) | ||
202 | + if err != nil { | ||
203 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取用户的角色信息列表"+err.Error()) | ||
204 | + } | ||
205 | + // 拥有HRBP权限 | ||
206 | + isHrbp := false | ||
207 | +loop: | ||
208 | + for _, v := range userRoleList { | ||
209 | + for _, v2 := range roleList { | ||
210 | + if v.RoleId == v2.Id { | ||
211 | + isHrbp = true | ||
212 | + break loop | ||
213 | + } | ||
214 | + } | ||
215 | + } | ||
216 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
217 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
218 | + } | ||
219 | + info := adapter.MeInfo{ | ||
220 | + UserId: userData.Id, | ||
221 | + CompanyId: companyData.Id, | ||
222 | + CompanyName: companyData.Name, | ||
223 | + Phone: userData.Account, | ||
224 | + Name: userData.Name, | ||
225 | + IsHrbp: isHrbp, | ||
226 | + IsParent: false, | ||
227 | + } | ||
228 | + if len(parentUser) > 0 { | ||
229 | + info.IsParent = true | ||
230 | + } | ||
231 | + return &info, nil | ||
232 | +} |
@@ -20,11 +20,16 @@ func (controller *AuthController) Login() { | @@ -20,11 +20,16 @@ func (controller *AuthController) Login() { | ||
20 | controller.Response(resp, err) | 20 | controller.Response(resp, err) |
21 | } | 21 | } |
22 | 22 | ||
23 | +// 获取个人信息 | ||
23 | func (controller *AuthController) User() { | 24 | func (controller *AuthController) User() { |
24 | userAuth := controller.Ctx.Input.GetData(domain.UserAuth{}).(*domain.UserAuth) | 25 | userAuth := controller.Ctx.Input.GetData(domain.UserAuth{}).(*domain.UserAuth) |
25 | - controller.Response(map[string]interface{}{ | ||
26 | - "user": userAuth, | ||
27 | - }, nil) | 26 | + authService := &service.AuthService{} |
27 | + param := &command.GetMeInfo{ | ||
28 | + UserId: userAuth.UserId, | ||
29 | + CompanyId: userAuth.CompanyId, | ||
30 | + } | ||
31 | + resp, err := authService.MeInfo(param) | ||
32 | + controller.Response(resp, err) | ||
28 | } | 33 | } |
29 | 34 | ||
30 | // Login 手机端登录 | 35 | // Login 手机端登录 |
-
请 注册 或 登录 后发表评论