作者 tangxvhui

删除任务时 连带删除 周期评估任务

@@ -365,7 +365,7 @@ func (rs *EvaluationProjectService) Remove(in *command.DeleteProjectCommand) (in @@ -365,7 +365,7 @@ func (rs *EvaluationProjectService) Remove(in *command.DeleteProjectCommand) (in
365 projectRepository := factory.CreateEvaluationProjectRepository(map[string]interface{}{"transactionContext": transactionContext}) 365 projectRepository := factory.CreateEvaluationProjectRepository(map[string]interface{}{"transactionContext": transactionContext})
366 taskRepository := factory.CreateNodeTaskRepository(map[string]interface{}{"transactionContext": transactionContext}) 366 taskRepository := factory.CreateNodeTaskRepository(map[string]interface{}{"transactionContext": transactionContext})
367 staffRepository := factory.CreateStaffAssessTaskRepository(map[string]interface{}{"transactionContext": transactionContext}) 367 staffRepository := factory.CreateStaffAssessTaskRepository(map[string]interface{}{"transactionContext": transactionContext})
368 - 368 + summaryRepository := factory.CreateSummaryEvaluationRepository(map[string]interface{}{"transactionContext": transactionContext})
369 project, err := projectRepository.FindOne(map[string]interface{}{"id": in.Id}) 369 project, err := projectRepository.FindOne(map[string]interface{}{"id": in.Id})
370 if err != nil { 370 if err != nil {
371 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 371 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -378,7 +378,10 @@ func (rs *EvaluationProjectService) Remove(in *command.DeleteProjectCommand) (in @@ -378,7 +378,10 @@ func (rs *EvaluationProjectService) Remove(in *command.DeleteProjectCommand) (in
378 if err := staffRepository.RemoveByProjectId(int(project.Id)); err != nil { 378 if err := staffRepository.RemoveByProjectId(int(project.Id)); err != nil {
379 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 379 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
380 } 380 }
381 - 381 + // 删除项目已生成的周期评估数据
  382 + if err := summaryRepository.RemoveByProjectId(int(project.Id)); err != nil {
  383 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  384 + }
382 // 移除项目关联的所有定时任务 385 // 移除项目关联的所有定时任务
383 tasks, err := taskRepository.Find(map[string]interface{}{"projectId": project.Id}) 386 tasks, err := taskRepository.Find(map[string]interface{}{"projectId": project.Id})
384 if err != nil { 387 if err != nil {
@@ -66,6 +66,7 @@ type SummaryEvaluationRepository interface { @@ -66,6 +66,7 @@ type SummaryEvaluationRepository interface {
66 Remove(id int) error 66 Remove(id int) error
67 FindOne(queryOptions map[string]interface{}) (*SummaryEvaluation, error) 67 FindOne(queryOptions map[string]interface{}) (*SummaryEvaluation, error)
68 Find(queryOptions map[string]interface{}) (int, []*SummaryEvaluation, error) 68 Find(queryOptions map[string]interface{}) (int, []*SummaryEvaluation, error)
  69 + RemoveByProjectId(id int) error
69 } 70 }
70 71
71 // 计算总分。TotalScore 保留1位小数 72 // 计算总分。TotalScore 保留1位小数
@@ -184,3 +184,13 @@ func (repo *SummaryEvaluationRepository) Find(queryOptions map[string]interface{ @@ -184,3 +184,13 @@ func (repo *SummaryEvaluationRepository) Find(queryOptions map[string]interface{
184 } 184 }
185 return count, datas, nil 185 return count, datas, nil
186 } 186 }
  187 +
  188 +func (repo *SummaryEvaluationRepository) RemoveByProjectId(id int) error {
  189 + tx := repo.transactionContext.PgTx
  190 + nowTime := time.Now()
  191 + _, err := tx.Model(&models.SummaryEvaluation{}).
  192 + Where("evaluation_project_id=?", id).
  193 + Set("deleted_at=?", nowTime).
  194 + Update()
  195 + return err
  196 +}