正在显示
7 个修改的文件
包含
106 行增加
和
35 行删除
| @@ -7,7 +7,6 @@ import ( | @@ -7,7 +7,6 @@ import ( | ||
| 7 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/evaluation_cycle/command" | 7 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/evaluation_cycle/command" |
| 8 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory" | 8 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory" |
| 9 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" | 9 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" |
| 10 | - "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/utils" | ||
| 11 | "strconv" | 10 | "strconv" |
| 12 | ) | 11 | ) |
| 13 | 12 | ||
| @@ -174,14 +173,13 @@ func (rs *EvaluationCycleService) Update(in *command.UpdateCycleCommand) (interf | @@ -174,14 +173,13 @@ func (rs *EvaluationCycleService) Update(in *command.UpdateCycleCommand) (interf | ||
| 174 | } | 173 | } |
| 175 | 174 | ||
| 176 | func (rs *EvaluationCycleService) Get(in *command.GetCycleCommand) (interface{}, error) { | 175 | func (rs *EvaluationCycleService) Get(in *command.GetCycleCommand) (interface{}, error) { |
| 177 | - // Get 不需要事务 | ||
| 178 | - if err := utils.ValidateCommand(in); err != nil { | ||
| 179 | - return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
| 180 | - } | ||
| 181 | - transactionContext, err := factory.CreateTransactionContext(nil) | 176 | + transactionContext, err := factory.ValidateStartTransaction(in) |
| 182 | if err != nil { | 177 | if err != nil { |
| 183 | - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 178 | + return nil, err |
| 184 | } | 179 | } |
| 180 | + defer func() { | ||
| 181 | + transactionContext.RollbackTransaction() | ||
| 182 | + }() | ||
| 185 | cycleRepository := factory.CreateEvaluationCycleRepository(map[string]interface{}{"transactionContext": transactionContext}) | 183 | cycleRepository := factory.CreateEvaluationCycleRepository(map[string]interface{}{"transactionContext": transactionContext}) |
| 186 | cycleTemplateRepository := factory.CreateEvaluationCycleTemplateRepository(map[string]interface{}{"transactionContext": transactionContext}) | 184 | cycleTemplateRepository := factory.CreateEvaluationCycleTemplateRepository(map[string]interface{}{"transactionContext": transactionContext}) |
| 187 | 185 | ||
| @@ -204,6 +202,10 @@ func (rs *EvaluationCycleService) Get(in *command.GetCycleCommand) (interface{}, | @@ -204,6 +202,10 @@ func (rs *EvaluationCycleService) Get(in *command.GetCycleCommand) (interface{}, | ||
| 204 | CreatedAt: cycleTemplates[i].CreatedAt, | 202 | CreatedAt: cycleTemplates[i].CreatedAt, |
| 205 | }) | 203 | }) |
| 206 | } | 204 | } |
| 205 | + | ||
| 206 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
| 207 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 208 | + } | ||
| 207 | return ctAdapter, nil | 209 | return ctAdapter, nil |
| 208 | } | 210 | } |
| 209 | 211 | ||
| @@ -247,12 +249,8 @@ func (rs *EvaluationCycleService) List(in *command.QueryCycleCommand) (interface | @@ -247,12 +249,8 @@ func (rs *EvaluationCycleService) List(in *command.QueryCycleCommand) (interface | ||
| 247 | transactionContext.RollbackTransaction() | 249 | transactionContext.RollbackTransaction() |
| 248 | }() | 250 | }() |
| 249 | cycleRepository := factory.CreateEvaluationCycleRepository(map[string]interface{}{"transactionContext": transactionContext}) | 251 | cycleRepository := factory.CreateEvaluationCycleRepository(map[string]interface{}{"transactionContext": transactionContext}) |
| 250 | - inMap := tool_funs.SimpleStructToMap(in) | ||
| 251 | - if len(in.Name) > 0 { | ||
| 252 | - inMap["name"] = "%" + in.Name + "%" | ||
| 253 | - } | ||
| 254 | // FIXME 总数量是否使用Count获取一个总数量 | 252 | // FIXME 总数量是否使用Count获取一个总数量 |
| 255 | - count, cycles, err := cycleRepository.Find(inMap) | 253 | + count, cycles, err := cycleRepository.Find(tool_funs.SimpleStructToMap(in)) |
| 256 | if err != nil { | 254 | if err != nil { |
| 257 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 255 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
| 258 | } | 256 | } |
| @@ -17,3 +17,12 @@ func (in *QueryProjectCommand) Valid(validation *validation.Validation) { | @@ -17,3 +17,12 @@ func (in *QueryProjectCommand) Valid(validation *validation.Validation) { | ||
| 17 | return | 17 | return |
| 18 | } | 18 | } |
| 19 | } | 19 | } |
| 20 | + | ||
| 21 | +type StatisticCycleProjectUserCommand struct { | ||
| 22 | + CompanyId int64 `cname:"公司ID" json:"companyId"` | ||
| 23 | + CycleId int64 `cname:"周期ID" json:"cycleId,string"` | ||
| 24 | +} | ||
| 25 | + | ||
| 26 | +func (in *StatisticCycleProjectUserCommand) Valid(*validation.Validation) { | ||
| 27 | + | ||
| 28 | +} |
| @@ -42,7 +42,7 @@ func (in *UpdateProjectCommand) Valid(validation *validation.Validation) { | @@ -42,7 +42,7 @@ func (in *UpdateProjectCommand) Valid(validation *validation.Validation) { | ||
| 42 | 42 | ||
| 43 | func (in *UpdateProjectTemplateCommand) Valid(validation *validation.Validation) { | 43 | func (in *UpdateProjectTemplateCommand) Valid(validation *validation.Validation) { |
| 44 | if len(in.Recipients) == 0 { | 44 | if len(in.Recipients) == 0 { |
| 45 | - validation.SetError("recipients", "请选择被评估人") | 45 | + validation.SetError("recipients", "请添加被评估人") |
| 46 | return | 46 | return |
| 47 | } | 47 | } |
| 48 | } | 48 | } |
| @@ -7,7 +7,6 @@ import ( | @@ -7,7 +7,6 @@ import ( | ||
| 7 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/evaluation_project/command" | 7 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/evaluation_project/command" |
| 8 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory" | 8 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory" |
| 9 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" | 9 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" |
| 10 | - "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/utils" | ||
| 11 | "strconv" | 10 | "strconv" |
| 12 | ) | 11 | ) |
| 13 | 12 | ||
| @@ -172,16 +171,14 @@ func (rs *EvaluationProjectService) UpdateTemplateNode(in *command.UpdateProject | @@ -172,16 +171,14 @@ func (rs *EvaluationProjectService) UpdateTemplateNode(in *command.UpdateProject | ||
| 172 | } | 171 | } |
| 173 | 172 | ||
| 174 | func (rs *EvaluationProjectService) Get(in *command.GetProjectCommand) (interface{}, error) { | 173 | func (rs *EvaluationProjectService) Get(in *command.GetProjectCommand) (interface{}, error) { |
| 175 | - // Get 不需要事务 | ||
| 176 | - if err := utils.ValidateCommand(in); err != nil { | ||
| 177 | - return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
| 178 | - } | ||
| 179 | - transactionContext, err := factory.CreateTransactionContext(nil) | 174 | + transactionContext, err := factory.ValidateStartTransaction(in) |
| 180 | if err != nil { | 175 | if err != nil { |
| 181 | - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 176 | + return nil, err |
| 182 | } | 177 | } |
| 178 | + defer func() { | ||
| 179 | + transactionContext.RollbackTransaction() | ||
| 180 | + }() | ||
| 183 | projectRepository := factory.CreateEvaluationProjectRepository(map[string]interface{}{"transactionContext": transactionContext}) | 181 | projectRepository := factory.CreateEvaluationProjectRepository(map[string]interface{}{"transactionContext": transactionContext}) |
| 184 | - | ||
| 185 | project, err := projectRepository.FindOne(map[string]interface{}{"id": in.Id}) | 182 | project, err := projectRepository.FindOne(map[string]interface{}{"id": in.Id}) |
| 186 | if err != nil { | 183 | if err != nil { |
| 187 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 184 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
| @@ -201,6 +198,9 @@ func (rs *EvaluationProjectService) Get(in *command.GetProjectCommand) (interfac | @@ -201,6 +198,9 @@ func (rs *EvaluationProjectService) Get(in *command.GetProjectCommand) (interfac | ||
| 201 | projectAdapter.TransformRecipientAdapter(users) | 198 | projectAdapter.TransformRecipientAdapter(users) |
| 202 | } | 199 | } |
| 203 | 200 | ||
| 201 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
| 202 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 203 | + } | ||
| 204 | return projectAdapter, nil | 204 | return projectAdapter, nil |
| 205 | } | 205 | } |
| 206 | 206 | ||
| @@ -317,3 +317,52 @@ func (rs *EvaluationProjectService) Copy(in *command.CopyProjectCommand) (interf | @@ -317,3 +317,52 @@ func (rs *EvaluationProjectService) Copy(in *command.CopyProjectCommand) (interf | ||
| 317 | } | 317 | } |
| 318 | return project, nil | 318 | return project, nil |
| 319 | } | 319 | } |
| 320 | + | ||
| 321 | +func (rs *EvaluationProjectService) StatisticCycleUser(in *command.StatisticCycleProjectUserCommand) (interface{}, error) { | ||
| 322 | + transactionContext, err := factory.ValidateStartTransaction(in) | ||
| 323 | + if err != nil { | ||
| 324 | + return nil, err | ||
| 325 | + } | ||
| 326 | + defer func() { | ||
| 327 | + transactionContext.RollbackTransaction() | ||
| 328 | + }() | ||
| 329 | + projectRepository := factory.CreateEvaluationProjectRepository(map[string]interface{}{"transactionContext": transactionContext}) | ||
| 330 | + _, projects, err := projectRepository.Find(tool_funs.SimpleStructToMap(in), "linkNodes") | ||
| 331 | + if err != nil { | ||
| 332 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 333 | + } | ||
| 334 | + | ||
| 335 | + userIds := make([]int64, 0) | ||
| 336 | + userIdMap := map[int64]int64{} | ||
| 337 | + for i := range projects { | ||
| 338 | + project := projects[i] | ||
| 339 | + for j := range project.Recipients { | ||
| 340 | + userId, _ := strconv.ParseInt(project.Recipients[j], 10, 64) | ||
| 341 | + userIdMap[userId] = userId | ||
| 342 | + } | ||
| 343 | + } | ||
| 344 | + for _, v := range userIdMap { | ||
| 345 | + userIds = append(userIds, v) | ||
| 346 | + } | ||
| 347 | + | ||
| 348 | + userTotal := 0 | ||
| 349 | + departmentTotal := 0 | ||
| 350 | + if len(userIds) > 0 { | ||
| 351 | + userRepository := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext}) | ||
| 352 | + _, users, _ := userRepository.Find(map[string]interface{}{"ids": userIds, "limit": len(userIds)}) | ||
| 353 | + departmentIdMap := map[int]int{} | ||
| 354 | + for i := range users { | ||
| 355 | + user := users[i] | ||
| 356 | + for _, v := range user.DepartmentId { | ||
| 357 | + departmentIdMap[v] = v | ||
| 358 | + } | ||
| 359 | + } | ||
| 360 | + userTotal = len(users) | ||
| 361 | + departmentTotal = len(departmentIdMap) | ||
| 362 | + } | ||
| 363 | + | ||
| 364 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
| 365 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 366 | + } | ||
| 367 | + return map[string]interface{}{"userTotal": userTotal, "departmentTotal": departmentTotal}, nil | ||
| 368 | +} |
| @@ -7,7 +7,6 @@ import ( | @@ -7,7 +7,6 @@ import ( | ||
| 7 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/evaluation_rule/command" | 7 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/evaluation_rule/command" |
| 8 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory" | 8 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory" |
| 9 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" | 9 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" |
| 10 | - "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/utils" | ||
| 11 | ) | 10 | ) |
| 12 | 11 | ||
| 13 | type EvaluationRuleService struct { | 12 | type EvaluationRuleService struct { |
| @@ -100,19 +99,22 @@ func (rs *EvaluationRuleService) Update(in *command.UpdateRuleCommand) (interfac | @@ -100,19 +99,22 @@ func (rs *EvaluationRuleService) Update(in *command.UpdateRuleCommand) (interfac | ||
| 100 | } | 99 | } |
| 101 | 100 | ||
| 102 | func (rs *EvaluationRuleService) Get(in *command.GetRuleCommand) (interface{}, error) { | 101 | func (rs *EvaluationRuleService) Get(in *command.GetRuleCommand) (interface{}, error) { |
| 103 | - // Get 不需要事务 | ||
| 104 | - if err := utils.ValidateCommand(in); err != nil { | ||
| 105 | - return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
| 106 | - } | ||
| 107 | - transactionContext, err := factory.CreateTransactionContext(nil) | 102 | + transactionContext, err := factory.ValidateStartTransaction(in) |
| 108 | if err != nil { | 103 | if err != nil { |
| 109 | - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 104 | + return nil, err |
| 110 | } | 105 | } |
| 106 | + defer func() { | ||
| 107 | + transactionContext.RollbackTransaction() | ||
| 108 | + }() | ||
| 111 | ruleRepository := factory.CreateEvaluationRuleRepository(map[string]interface{}{"transactionContext": transactionContext}) | 109 | ruleRepository := factory.CreateEvaluationRuleRepository(map[string]interface{}{"transactionContext": transactionContext}) |
| 112 | rule, err := ruleRepository.FindOne(map[string]interface{}{"id": in.Id}) | 110 | rule, err := ruleRepository.FindOne(map[string]interface{}{"id": in.Id}) |
| 113 | if err != nil { | 111 | if err != nil { |
| 114 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 112 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
| 115 | } | 113 | } |
| 114 | + | ||
| 115 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
| 116 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 117 | + } | ||
| 116 | return rule, nil | 118 | return rule, nil |
| 117 | } | 119 | } |
| 118 | 120 |
| @@ -6,7 +6,6 @@ import ( | @@ -6,7 +6,6 @@ import ( | ||
| 6 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/evaluation_template/command" | 6 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/evaluation_template/command" |
| 7 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory" | 7 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory" |
| 8 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" | 8 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" |
| 9 | - "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/utils" | ||
| 10 | ) | 9 | ) |
| 11 | 10 | ||
| 12 | type EvaluationTemplateService struct { | 11 | type EvaluationTemplateService struct { |
| @@ -124,19 +123,22 @@ func (rs *EvaluationTemplateService) Update(in *command.UpdateTemplateCommand) ( | @@ -124,19 +123,22 @@ func (rs *EvaluationTemplateService) Update(in *command.UpdateTemplateCommand) ( | ||
| 124 | } | 123 | } |
| 125 | 124 | ||
| 126 | func (rs *EvaluationTemplateService) Get(in *command.GetTemplateCommand) (interface{}, error) { | 125 | func (rs *EvaluationTemplateService) Get(in *command.GetTemplateCommand) (interface{}, error) { |
| 127 | - // Get 不需要事务 | ||
| 128 | - if err := utils.ValidateCommand(in); err != nil { | ||
| 129 | - return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
| 130 | - } | ||
| 131 | - transactionContext, err := factory.CreateTransactionContext(nil) | 126 | + transactionContext, err := factory.ValidateStartTransaction(in) |
| 132 | if err != nil { | 127 | if err != nil { |
| 133 | - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 128 | + return nil, err |
| 134 | } | 129 | } |
| 130 | + defer func() { | ||
| 131 | + transactionContext.RollbackTransaction() | ||
| 132 | + }() | ||
| 135 | templateRepository := factory.CreateEvaluationTemplateRepository(map[string]interface{}{"transactionContext": transactionContext}) | 133 | templateRepository := factory.CreateEvaluationTemplateRepository(map[string]interface{}{"transactionContext": transactionContext}) |
| 136 | template, err := templateRepository.FindOne(map[string]interface{}{"id": in.Id}) | 134 | template, err := templateRepository.FindOne(map[string]interface{}{"id": in.Id}) |
| 137 | if err != nil { | 135 | if err != nil { |
| 138 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 136 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
| 139 | } | 137 | } |
| 138 | + | ||
| 139 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
| 140 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 141 | + } | ||
| 140 | return template, nil | 142 | return template, nil |
| 141 | } | 143 | } |
| 142 | 144 |
| @@ -112,3 +112,14 @@ func (controller *ProjectController) CopyProject() { | @@ -112,3 +112,14 @@ func (controller *ProjectController) CopyProject() { | ||
| 112 | controller.Response(ruService.Copy(in)) | 112 | controller.Response(ruService.Copy(in)) |
| 113 | } | 113 | } |
| 114 | } | 114 | } |
| 115 | + | ||
| 116 | +func (controller *ProjectController) StatisticCycleUser() { | ||
| 117 | + ruService := service.NewEvaluationProjectService() | ||
| 118 | + in := &command.StatisticCycleProjectUserCommand{} | ||
| 119 | + if err := controller.Unmarshal(in); err != nil { | ||
| 120 | + controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error())) | ||
| 121 | + } else { | ||
| 122 | + in.CompanyId = middlewares.GetCompanyId(controller.Ctx) | ||
| 123 | + controller.Response(ruService.StatisticCycleUser(in)) | ||
| 124 | + } | ||
| 125 | +} |
-
请 注册 或 登录 后发表评论