Merge branch 'test' of http://gitlab.fjmaimaimai.com/allied-creation/performance into test
正在显示
1 个修改的文件
包含
64 行增加
和
58 行删除
@@ -589,70 +589,76 @@ func (rs *EvaluationProjectService) Activate(in *command.ActivateProjectCommand) | @@ -589,70 +589,76 @@ func (rs *EvaluationProjectService) Activate(in *command.ActivateProjectCommand) | ||
589 | principalId = intId | 589 | principalId = intId |
590 | } | 590 | } |
591 | 591 | ||
592 | - now := time.Now().Local() | ||
593 | - year, month, day := now.Date() | ||
594 | - nowO := time.Date(year, month, day, 0, 0, 0, 0, time.Local) // 当前时间0点0分0秒时刻 | ||
595 | - for i := range project.Template.LinkNodes { | ||
596 | - node := project.Template.LinkNodes[i] | ||
597 | - task := &domain.NodeTask{ | ||
598 | - Id: 0, | ||
599 | - CompanyId: project.CompanyId, | ||
600 | - CycleId: project.CycleId, | ||
601 | - ProjectId: project.Id, | ||
602 | - NodeId: node.Id, | ||
603 | - NodeType: node.Type, | ||
604 | - NodeName: node.Name, | ||
605 | - NodeDescribe: node.Describe, | ||
606 | - NodeSort: i + 1, | ||
607 | - TimeStart: node.TimeStart, | ||
608 | - TimeEnd: node.TimeEnd, | ||
609 | - KpiCycle: node.KpiCycle, | ||
610 | - } | ||
611 | - | ||
612 | - // 环节起始和截止本地时间 | ||
613 | - startLocal := task.TimeStart.Local() | ||
614 | - sY, sM, sD := startLocal.Date() | ||
615 | - startLocal = time.Date(sY, sM, sD, 0, 0, 0, 0, time.Local) // 开始时间以0点开始计算 | ||
616 | - endLocal := task.TimeEnd.Local() | ||
617 | - | ||
618 | - // 在当前时间之前,则计算下一个周期时间 | ||
619 | - if startLocal.Before(nowO) { | ||
620 | - nextTime := utils.NextTime(nowO, startLocal, node.KpiCycle) | ||
621 | - task.NextSentAt = &nextTime | ||
622 | - } else { | ||
623 | - task.NextSentAt = &startLocal | ||
624 | - } | ||
625 | - // 如果超出截至时间,则周期置空 | ||
626 | - if task.NextSentAt.After(endLocal) { | ||
627 | - task.NextSentAt = nil | ||
628 | - } | 592 | + tasks, err := taskRepository.Find(map[string]interface{}{"projectId": project.Id}) |
593 | + if err != nil { | ||
594 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
595 | + } | ||
596 | + if len(tasks) == 0 { | ||
597 | + now := time.Now().Local() | ||
598 | + year, month, day := now.Date() | ||
599 | + nowO := time.Date(year, month, day, 0, 0, 0, 0, time.Local) // 当前时间0点0分0秒时刻 | ||
600 | + for i := range project.Template.LinkNodes { | ||
601 | + node := project.Template.LinkNodes[i] | ||
602 | + task := &domain.NodeTask{ | ||
603 | + Id: 0, | ||
604 | + CompanyId: project.CompanyId, | ||
605 | + CycleId: project.CycleId, | ||
606 | + ProjectId: project.Id, | ||
607 | + NodeId: node.Id, | ||
608 | + NodeType: node.Type, | ||
609 | + NodeName: node.Name, | ||
610 | + NodeDescribe: node.Describe, | ||
611 | + NodeSort: i + 1, | ||
612 | + TimeStart: node.TimeStart, | ||
613 | + TimeEnd: node.TimeEnd, | ||
614 | + KpiCycle: node.KpiCycle, | ||
615 | + } | ||
629 | 616 | ||
630 | - _, err := taskRepository.Insert(task) | ||
631 | - if err != nil { | ||
632 | - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
633 | - } | 617 | + // 环节起始和截止本地时间 |
618 | + startLocal := task.TimeStart.Local() | ||
619 | + sY, sM, sD := startLocal.Date() | ||
620 | + startLocal = time.Date(sY, sM, sD, 0, 0, 0, 0, time.Local) // 开始时间以0点开始计算 | ||
621 | + endLocal := task.TimeEnd.Local() | ||
634 | 622 | ||
635 | - // 任务指标生成任务 | ||
636 | - for j := range node.NodeContents { | ||
637 | - content := node.NodeContents[j] | ||
638 | - if content.IndicatorType == domain.IndicatorTypeTask { | ||
639 | - if principalId == 0 { | ||
640 | - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "请选择任务负责人") | ||
641 | - } | ||
642 | - err := projectTaskService.CreateTask(transactionContext, &taskCommand.CreateTaskCommand{ | ||
643 | - Name: content.Name, | ||
644 | - LeaderId: principalId, | ||
645 | - }) | ||
646 | - if err != nil { | ||
647 | - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 623 | + // 在当前时间之前,则计算下一个周期时间 |
624 | + if startLocal.Before(nowO) { | ||
625 | + nextTime := utils.NextTime(nowO, startLocal, node.KpiCycle) | ||
626 | + task.NextSentAt = &nextTime | ||
627 | + } else { | ||
628 | + task.NextSentAt = &startLocal | ||
629 | + } | ||
630 | + // 如果超出截至时间,则周期置空 | ||
631 | + if task.NextSentAt.After(endLocal) { | ||
632 | + task.NextSentAt = nil | ||
633 | + } | ||
634 | + | ||
635 | + _, err := taskRepository.Insert(task) | ||
636 | + if err != nil { | ||
637 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
638 | + } | ||
639 | + | ||
640 | + // 任务指标生成任务 | ||
641 | + for j := range node.NodeContents { | ||
642 | + content := node.NodeContents[j] | ||
643 | + if content.IndicatorType == domain.IndicatorTypeTask { | ||
644 | + if principalId == 0 { | ||
645 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "请选择任务负责人") | ||
646 | + } | ||
647 | + err := projectTaskService.CreateTask(transactionContext, &taskCommand.CreateTaskCommand{ | ||
648 | + Name: content.Name, | ||
649 | + LeaderId: principalId, | ||
650 | + }) | ||
651 | + if err != nil { | ||
652 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
653 | + } | ||
648 | } | 654 | } |
649 | } | 655 | } |
650 | } | 656 | } |
651 | - } | ||
652 | 657 | ||
653 | - err = rs.generateEvaluationItemUsed(transactionContext, project) | ||
654 | - if err != nil { | ||
655 | - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 658 | + err = rs.generateEvaluationItemUsed(transactionContext, project) |
659 | + if err != nil { | ||
660 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
661 | + } | ||
656 | } | 662 | } |
657 | 663 | ||
658 | if err := transactionContext.CommitTransaction(); err != nil { | 664 | if err := transactionContext.CommitTransaction(); err != nil { |
-
请 注册 或 登录 后发表评论