Merge branch 'dev-chenzhiying' into dev
正在显示
7 个修改的文件
包含
166 行增加
和
16 行删除
| @@ -19,6 +19,8 @@ type EndCooperationProjectCommand struct { | @@ -19,6 +19,8 @@ type EndCooperationProjectCommand struct { | ||
| 19 | UserId int64 `cname:"用户ID" json:"userId" valid:"Required"` | 19 | UserId int64 `cname:"用户ID" json:"userId" valid:"Required"` |
| 20 | // 用户基础数据id | 20 | // 用户基础数据id |
| 21 | UserBaseId int64 `cname:"用户基础数据ID" json:"userBaseId" valid:"Required"` | 21 | UserBaseId int64 `cname:"用户基础数据ID" json:"userBaseId" valid:"Required"` |
| 22 | + // 状态 | ||
| 23 | + Status int32 `cname:"状态" json:"status"` | ||
| 22 | } | 24 | } |
| 23 | 25 | ||
| 24 | func (endCooperationProjectCommand *EndCooperationProjectCommand) Valid(validation *validation.Validation) { | 26 | func (endCooperationProjectCommand *EndCooperationProjectCommand) Valid(validation *validation.Validation) { |
| @@ -463,6 +463,110 @@ func (cooperationProjectService *CooperationProjectService) UpdateCooperationPro | @@ -463,6 +463,110 @@ func (cooperationProjectService *CooperationProjectService) UpdateCooperationPro | ||
| 463 | } | 463 | } |
| 464 | } | 464 | } |
| 465 | 465 | ||
| 466 | +// EndCooperationProject 结束共创项目 | ||
| 467 | +func (cooperationProjectService *CooperationProjectService) EndCooperationProject(updateCooperationProjectCommand *command.EndCooperationProjectCommand) (interface{}, error) { | ||
| 468 | + if err := updateCooperationProjectCommand.ValidateCommand(); err != nil { | ||
| 469 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
| 470 | + } | ||
| 471 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
| 472 | + if err != nil { | ||
| 473 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 474 | + } | ||
| 475 | + if err := transactionContext.StartTransaction(); err != nil { | ||
| 476 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 477 | + } | ||
| 478 | + defer func() { | ||
| 479 | + _ = transactionContext.RollbackTransaction() | ||
| 480 | + }() | ||
| 481 | + var cooperationProjectRepository domain.CooperationProjectRepository | ||
| 482 | + if value, err := factory.CreateCooperationProjectRepository(map[string]interface{}{ | ||
| 483 | + "transactionContext": transactionContext, | ||
| 484 | + }); err != nil { | ||
| 485 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 486 | + } else { | ||
| 487 | + cooperationProjectRepository = value | ||
| 488 | + } | ||
| 489 | + cooperationProjectId, err := strconv.ParseInt(updateCooperationProjectCommand.CooperationProjectId, 10, 64) | ||
| 490 | + if err != nil { | ||
| 491 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 492 | + } | ||
| 493 | + cooperationProject, err := cooperationProjectRepository.FindOne(map[string]interface{}{"cooperationProjectId": cooperationProjectId}) | ||
| 494 | + if err != nil { | ||
| 495 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 496 | + } | ||
| 497 | + if cooperationProject == nil { | ||
| 498 | + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", updateCooperationProjectCommand.CooperationProjectId)) | ||
| 499 | + } | ||
| 500 | + // 设置结束状态 | ||
| 501 | + updateCooperationProjectCommand.Status = 2 | ||
| 502 | + if err := cooperationProject.Update(tool_funs.SimpleStructToMap(updateCooperationProjectCommand)); err != nil { | ||
| 503 | + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | ||
| 504 | + } | ||
| 505 | + if cooperationProject, err := cooperationProjectRepository.Save(cooperationProject); err != nil { | ||
| 506 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 507 | + } else { | ||
| 508 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
| 509 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 510 | + } | ||
| 511 | + return cooperationProject, nil | ||
| 512 | + } | ||
| 513 | +} | ||
| 514 | + | ||
| 515 | +// BatchEndCooperationProject 批量结束共创项目 | ||
| 516 | +func (cooperationProjectService *CooperationProjectService) BatchEndCooperationProject(batchEndCooperationProjectCommand *command.BatchEndCooperationProjectCommand) (interface{}, error) { | ||
| 517 | + if err := batchEndCooperationProjectCommand.ValidateCommand(); err != nil { | ||
| 518 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
| 519 | + } | ||
| 520 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
| 521 | + if err != nil { | ||
| 522 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 523 | + } | ||
| 524 | + if err := transactionContext.StartTransaction(); err != nil { | ||
| 525 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 526 | + } | ||
| 527 | + defer func() { | ||
| 528 | + _ = transactionContext.RollbackTransaction() | ||
| 529 | + }() | ||
| 530 | + | ||
| 531 | + // 共创项目仓储初始化 | ||
| 532 | + //var cooperationProjectRepository domain.CooperationProjectRepository | ||
| 533 | + //if value, err := factory.CreateCooperationProjectRepository(map[string]interface{}{ | ||
| 534 | + // "transactionContext": transactionContext, | ||
| 535 | + //}); err != nil { | ||
| 536 | + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 537 | + //} else { | ||
| 538 | + // cooperationProjectRepository = value | ||
| 539 | + //} | ||
| 540 | + | ||
| 541 | + // 转换共创项目ID列表类型 | ||
| 542 | + //cooperationProjectIds, err := utils.SliceAtoi(batchEndCooperationProjectCommand.CooperationProjectIds) | ||
| 543 | + //if err != nil { | ||
| 544 | + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 545 | + //} | ||
| 546 | + | ||
| 547 | + //cooperationProject, err := cooperationProjectRepository.FindOne(map[string]interface{}{"cooperationProjectId": batchEndCooperationProjectCommand.CooperationProjectId}) | ||
| 548 | + //if err != nil { | ||
| 549 | + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 550 | + //} | ||
| 551 | + //if cooperationProject == nil { | ||
| 552 | + // return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(batchEndCooperationProjectCommand.CooperationProjectId))) | ||
| 553 | + //} | ||
| 554 | + | ||
| 555 | + //if err := cooperationProject.Update(tool_funs.SimpleStructToMap(batchEndCooperationProjectCommand)); err != nil { | ||
| 556 | + // return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | ||
| 557 | + //} | ||
| 558 | + // | ||
| 559 | + //if cooperationProject, err := cooperationProjectRepository.Save(cooperationProject); err != nil { | ||
| 560 | + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 561 | + //} else { | ||
| 562 | + // if err := transactionContext.CommitTransaction(); err != nil { | ||
| 563 | + // return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 564 | + // } | ||
| 565 | + // return cooperationProject, nil | ||
| 566 | + //} | ||
| 567 | + return nil, nil | ||
| 568 | +} | ||
| 569 | + | ||
| 466 | func NewCooperationProjectService(options map[string]interface{}) *CooperationProjectService { | 570 | func NewCooperationProjectService(options map[string]interface{}) *CooperationProjectService { |
| 467 | newCooperationProjectService := &CooperationProjectService{} | 571 | newCooperationProjectService := &CooperationProjectService{} |
| 468 | return newCooperationProjectService | 572 | return newCooperationProjectService |
| @@ -574,6 +574,20 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent | @@ -574,6 +574,20 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent | ||
| 574 | log.Logger.Info("新增的分红预算单", map[string]interface{}{ | 574 | log.Logger.Info("新增的分红预算单", map[string]interface{}{ |
| 575 | "dividendsEstimates": dividendsEstimates, | 575 | "dividendsEstimates": dividendsEstimates, |
| 576 | }) | 576 | }) |
| 577 | + | ||
| 578 | + // 创建成功的分红预算单 | ||
| 579 | + var dividendsEstimatesSavedSuccessfully []*domain.DividendsEstimate | ||
| 580 | + // 创建失败的分红预算单 | ||
| 581 | + var dividendsEstimateSaveFailed []*domain.DividendsEstimate | ||
| 582 | + for _, dividendsEstimate := range dividendsEstimates { | ||
| 583 | + if dividendsEstimateSaved, err := dividendsEstimateRepository.Save(dividendsEstimate); err != nil { | ||
| 584 | + dividendsEstimateSaveFailed = append(dividendsEstimateSaveFailed, dividendsEstimate) | ||
| 585 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 586 | + } else if dividendsEstimateSaved != nil { | ||
| 587 | + dividendsEstimatesSavedSuccessfully = append(dividendsEstimatesSavedSuccessfully, dividendsEstimate) | ||
| 588 | + } | ||
| 589 | + } | ||
| 590 | + | ||
| 577 | dividendsEstimatesSaved, err := dividendsEstimateRepository.SaveMany(dividendsEstimates) | 591 | dividendsEstimatesSaved, err := dividendsEstimateRepository.SaveMany(dividendsEstimates) |
| 578 | if err != nil { | 592 | if err != nil { |
| 579 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 593 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
| @@ -581,6 +595,8 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent | @@ -581,6 +595,8 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent | ||
| 581 | if err := transactionContext.CommitTransaction(); err != nil { | 595 | if err := transactionContext.CommitTransaction(); err != nil { |
| 582 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 596 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
| 583 | } | 597 | } |
| 598 | + // TODO 分析成功和失败原因 | ||
| 599 | + | ||
| 584 | return dividendsEstimatesSaved, nil | 600 | return dividendsEstimatesSaved, nil |
| 585 | } | 601 | } |
| 586 | } | 602 | } |
| @@ -27,7 +27,7 @@ type OrderGood struct { | @@ -27,7 +27,7 @@ type OrderGood struct { | ||
| 27 | // 订单产品支出费用 | 27 | // 订单产品支出费用 |
| 28 | OrderGoodExpense float64 `comment:"订单产品支出费用"` | 28 | OrderGoodExpense float64 `comment:"订单产品支出费用"` |
| 29 | // 订单产品分红状态, 1待分红,2已分红 | 29 | // 订单产品分红状态, 1待分红,2已分红 |
| 30 | - OrderGoodDividendsStatus int32 `comment:"订单产品分红状态"` | 30 | + OrderGoodDividendsStatus int32 `comment:"订单产品分红状态" pg:",default:1"` |
| 31 | // 创建时间 | 31 | // 创建时间 |
| 32 | CreatedAt time.Time `comment:"创建时间"` | 32 | CreatedAt time.Time `comment:"创建时间"` |
| 33 | // 删除时间 | 33 | // 删除时间 |
| @@ -56,12 +56,12 @@ func (repository *DividendsEstimateRepository) Save(dividendsEstimate *domain.Di | @@ -56,12 +56,12 @@ func (repository *DividendsEstimateRepository) Save(dividendsEstimate *domain.Di | ||
| 56 | updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields) | 56 | updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields) |
| 57 | tx := repository.transactionContext.PgTx | 57 | tx := repository.transactionContext.PgTx |
| 58 | if dividendsEstimate.Identify() == nil { | 58 | if dividendsEstimate.Identify() == nil { |
| 59 | - dividendsEstimateId, err := repository.nextIdentify() | ||
| 60 | - if err != nil { | ||
| 61 | - return dividendsEstimate, err | ||
| 62 | - } else { | ||
| 63 | - dividendsEstimate.DividendsEstimateId = dividendsEstimateId | ||
| 64 | - } | 59 | + //dividendsEstimateId, err := repository.nextIdentify() |
| 60 | + //if err != nil { | ||
| 61 | + // return dividendsEstimate, err | ||
| 62 | + //} else { | ||
| 63 | + // dividendsEstimate.DividendsEstimateId = dividendsEstimateId | ||
| 64 | + //} | ||
| 65 | if _, err := tx.QueryOne( | 65 | if _, err := tx.QueryOne( |
| 66 | pg.Scan( | 66 | pg.Scan( |
| 67 | ÷ndsEstimate.DividendsEstimateId, | 67 | ÷ndsEstimate.DividendsEstimateId, |
| @@ -83,7 +83,7 @@ func (controller *CooperationProjectController) RemoveCooperationProject() { | @@ -83,7 +83,7 @@ func (controller *CooperationProjectController) RemoveCooperationProject() { | ||
| 83 | func (controller *CooperationProjectController) SearchCooperationProject() { | 83 | func (controller *CooperationProjectController) SearchCooperationProject() { |
| 84 | cooperationProjectService := service.NewCooperationProjectService(nil) | 84 | cooperationProjectService := service.NewCooperationProjectService(nil) |
| 85 | searchCooperationProjectQuery := &query.SearchCooperationProjectQuery{} | 85 | searchCooperationProjectQuery := &query.SearchCooperationProjectQuery{} |
| 86 | - controller.Unmarshal(searchCooperationProjectQuery) | 86 | + _ = controller.Unmarshal(searchCooperationProjectQuery) |
| 87 | header := controller.GetRequestHeader(controller.Ctx) | 87 | header := controller.GetRequestHeader(controller.Ctx) |
| 88 | searchCooperationProjectQuery.CompanyId = header.CompanyId | 88 | searchCooperationProjectQuery.CompanyId = header.CompanyId |
| 89 | searchCooperationProjectQuery.OrgId = header.OrgId | 89 | searchCooperationProjectQuery.OrgId = header.OrgId |
| @@ -120,3 +120,29 @@ func (controller *CooperationProjectController) ListCooperationProject() { | @@ -120,3 +120,29 @@ func (controller *CooperationProjectController) ListCooperationProject() { | ||
| 120 | data, err := cooperationProjectService.ListCooperationProject(listCooperationProjectQuery) | 120 | data, err := cooperationProjectService.ListCooperationProject(listCooperationProjectQuery) |
| 121 | controller.Response(data, err) | 121 | controller.Response(data, err) |
| 122 | } | 122 | } |
| 123 | + | ||
| 124 | +func (controller *CooperationProjectController) EndCooperationProject() { | ||
| 125 | + cooperationProjectService := service.NewCooperationProjectService(nil) | ||
| 126 | + endCooperationProjectCommand := &command.EndCooperationProjectCommand{} | ||
| 127 | + _ = controller.Unmarshal(endCooperationProjectCommand) | ||
| 128 | + header := controller.GetRequestHeader(controller.Ctx) | ||
| 129 | + endCooperationProjectCommand.CompanyId = header.CompanyId | ||
| 130 | + endCooperationProjectCommand.OrgId = header.OrgId | ||
| 131 | + endCooperationProjectCommand.UserId = header.UserId | ||
| 132 | + endCooperationProjectCommand.UserBaseId = header.UserBaseId | ||
| 133 | + data, err := cooperationProjectService.EndCooperationProject(endCooperationProjectCommand) | ||
| 134 | + controller.Response(data, err) | ||
| 135 | +} | ||
| 136 | + | ||
| 137 | +func (controller *CooperationProjectController) BatchEndCooperationProject() { | ||
| 138 | + cooperationProjectService := service.NewCooperationProjectService(nil) | ||
| 139 | + batchEndCooperationProjectCommand := &command.BatchEndCooperationProjectCommand{} | ||
| 140 | + _ = controller.Unmarshal(batchEndCooperationProjectCommand) | ||
| 141 | + header := controller.GetRequestHeader(controller.Ctx) | ||
| 142 | + batchEndCooperationProjectCommand.CompanyId = header.CompanyId | ||
| 143 | + batchEndCooperationProjectCommand.OrgId = header.OrgId | ||
| 144 | + batchEndCooperationProjectCommand.UserId = header.UserId | ||
| 145 | + batchEndCooperationProjectCommand.UserBaseId = header.UserBaseId | ||
| 146 | + data, err := cooperationProjectService.BatchEndCooperationProject(batchEndCooperationProjectCommand) | ||
| 147 | + controller.Response(data, err) | ||
| 148 | +} |
| @@ -6,12 +6,14 @@ import ( | @@ -6,12 +6,14 @@ import ( | ||
| 6 | ) | 6 | ) |
| 7 | 7 | ||
| 8 | func init() { | 8 | func init() { |
| 9 | - web.Router("/cooperation-projects/release-cooperation-project", &controllers.CooperationProjectController{}, "Post:ReleaseCooperationProject") | ||
| 10 | - web.Router("/cooperation-projects/", &controllers.CooperationProjectController{}, "Post:CreateCooperationProject") | ||
| 11 | - web.Router("/cooperation-projects/:cooperationProjectId", &controllers.CooperationProjectController{}, "Put:UpdateCooperationProject") | ||
| 12 | - web.Router("/cooperation-projects/:cooperationProjectId", &controllers.CooperationProjectController{}, "Get:GetCooperationProject") | ||
| 13 | - web.Router("/cooperation-projects/:cooperationProjectId", &controllers.CooperationProjectController{}, "Delete:RemoveCooperationProject") | ||
| 14 | - web.Router("/cooperation-projects/search", &controllers.CooperationProjectController{}, "Post:SearchCooperationProject") | ||
| 15 | - web.Router("/cooperation-projects/check", &controllers.CooperationProjectController{}, "Post:CheckUndertaker") | ||
| 16 | - web.Router("/cooperation-projects/", &controllers.CooperationProjectController{}, "Get:ListCooperationProject") | 9 | + web.Router("/cooperation-projects/release-cooperation-project", &controllers.CooperationProjectController{}, "Post:ReleaseCooperationProject") // 发布共创项目 |
| 10 | + web.Router("/cooperation-projects/", &controllers.CooperationProjectController{}, "Post:CreateCooperationProject") // 新增共创项目 | ||
| 11 | + web.Router("/cooperation-projects/:cooperationProjectId", &controllers.CooperationProjectController{}, "Put:UpdateCooperationProject") // 编辑共创项目 | ||
| 12 | + web.Router("/cooperation-projects/:cooperationProjectId", &controllers.CooperationProjectController{}, "Get:GetCooperationProject") // 获取共创项目详情 | ||
| 13 | + web.Router("/cooperation-projects/:cooperationProjectId", &controllers.CooperationProjectController{}, "Delete:RemoveCooperationProject") // 移除共创项目 | ||
| 14 | + web.Router("/cooperation-projects/search", &controllers.CooperationProjectController{}, "Post:SearchCooperationProject") // 查找共创项目 | ||
| 15 | + web.Router("/cooperation-projects/check", &controllers.CooperationProjectController{}, "Post:CheckUndertaker") // | ||
| 16 | + web.Router("/cooperation-projects/", &controllers.CooperationProjectController{}, "Get:ListCooperationProject") // 返回共创项目列表 | ||
| 17 | + web.Router("/cooperation-projects/end", &controllers.CooperationProjectController{}, "Post:EndCooperationProject") // 结束共创项目 | ||
| 18 | + web.Router("/cooperation-projects/batch-end", &controllers.CooperationProjectController{}, "Post:BatchEndCooperationProject") // 批量结束共创项目 | ||
| 17 | } | 19 | } |
-
请 注册 或 登录 后发表评论