作者 tangxvhui

修复bug ,项目出现多次反复启动停止

@@ -506,7 +506,9 @@ func (rs *EvaluationProjectService) Activate(in *command.ActivateProjectCommand) @@ -506,7 +506,9 @@ func (rs *EvaluationProjectService) Activate(in *command.ActivateProjectCommand)
506 if project.State == domain.ProjectStateEnable { 506 if project.State == domain.ProjectStateEnable {
507 return nil, application.ThrowError(application.BUSINESS_ERROR, "项目已启动") 507 return nil, application.ThrowError(application.BUSINESS_ERROR, "项目已启动")
508 } 508 }
509 - 509 + if project.State == domain.ProjectStatePause {
  510 + return nil, application.ThrowError(application.BUSINESS_ERROR, "项目暂停中,先进行恢复")
  511 + }
510 // 周期内的所有项目,已启用的员工不能重复被评估 512 // 周期内的所有项目,已启用的员工不能重复被评估
511 _, projects, err := projectRepository.Find(map[string]interface{}{"companyId": project.CompanyId, "cycleId": project.CycleId}, "template") 513 _, projects, err := projectRepository.Find(map[string]interface{}{"companyId": project.CompanyId, "cycleId": project.CycleId}, "template")
512 if err != nil { 514 if err != nil {
@@ -599,7 +601,7 @@ func (rs *EvaluationProjectService) Activate(in *command.ActivateProjectCommand) @@ -599,7 +601,7 @@ func (rs *EvaluationProjectService) Activate(in *command.ActivateProjectCommand)
599 task.NextSentAt = nil 601 task.NextSentAt = nil
600 } 602 }
601 603
602 - task, err := taskRepository.Insert(task) 604 + _, err := taskRepository.Insert(task)
603 if err != nil { 605 if err != nil {
604 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 606 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
605 } 607 }
@@ -827,7 +829,17 @@ func (rs *EvaluationProjectService) CheckRecipients(in *command.CheckRecipientCo @@ -827,7 +829,17 @@ func (rs *EvaluationProjectService) CheckRecipients(in *command.CheckRecipientCo
827 } 829 }
828 830
829 func (rs *EvaluationProjectService) generateEvaluationItemUsed(transactionContext application.TransactionContext, project *domain.EvaluationProject) error { 831 func (rs *EvaluationProjectService) generateEvaluationItemUsed(transactionContext application.TransactionContext, project *domain.EvaluationProject) error {
830 - 832 + itemUsedRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{
  833 + "transactionContext": transactionContext,
  834 + })
  835 + var err error
  836 + cnt, _, err := itemUsedRepo.Find(map[string]interface{}{"projectId": project.Id})
  837 + if err != nil {
  838 + return application.ThrowError(application.TRANSACTION_ERROR, "检查评估选项"+err.Error())
  839 + }
  840 + if cnt > 0 {
  841 + return nil
  842 + }
831 var itemUsedList []*domain.EvaluationItemUsed 843 var itemUsedList []*domain.EvaluationItemUsed
832 nowTime := time.Now() 844 nowTime := time.Now()
833 for _, v := range project.Template.LinkNodes { 845 for _, v := range project.Template.LinkNodes {
@@ -859,10 +871,8 @@ func (rs *EvaluationProjectService) generateEvaluationItemUsed(transactionContex @@ -859,10 +871,8 @@ func (rs *EvaluationProjectService) generateEvaluationItemUsed(transactionContex
859 itemUsedList = append(itemUsedList, &item) 871 itemUsedList = append(itemUsedList, &item)
860 } 872 }
861 } 873 }
862 - itemUsedRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{  
863 - "transactionContext": transactionContext,  
864 - })  
865 - err := itemUsedRepo.BatchInsert(itemUsedList) 874 +
  875 + err = itemUsedRepo.BatchInsert(itemUsedList)
866 if err != nil { 876 if err != nil {
867 return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 877 return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
868 } 878 }