作者 tangxvhui

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

... ... @@ -365,7 +365,7 @@ func (rs *EvaluationProjectService) Remove(in *command.DeleteProjectCommand) (in
projectRepository := factory.CreateEvaluationProjectRepository(map[string]interface{}{"transactionContext": transactionContext})
taskRepository := factory.CreateNodeTaskRepository(map[string]interface{}{"transactionContext": transactionContext})
staffRepository := factory.CreateStaffAssessTaskRepository(map[string]interface{}{"transactionContext": transactionContext})
summaryRepository := factory.CreateSummaryEvaluationRepository(map[string]interface{}{"transactionContext": transactionContext})
project, err := projectRepository.FindOne(map[string]interface{}{"id": in.Id})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -378,7 +378,10 @@ func (rs *EvaluationProjectService) Remove(in *command.DeleteProjectCommand) (in
if err := staffRepository.RemoveByProjectId(int(project.Id)); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 删除项目已生成的周期评估数据
if err := summaryRepository.RemoveByProjectId(int(project.Id)); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 移除项目关联的所有定时任务
tasks, err := taskRepository.Find(map[string]interface{}{"projectId": project.Id})
if err != nil {
... ...
... ... @@ -66,6 +66,7 @@ type SummaryEvaluationRepository interface {
Remove(id int) error
FindOne(queryOptions map[string]interface{}) (*SummaryEvaluation, error)
Find(queryOptions map[string]interface{}) (int, []*SummaryEvaluation, error)
RemoveByProjectId(id int) error
}
// 计算总分。TotalScore 保留1位小数
... ...
... ... @@ -184,3 +184,13 @@ func (repo *SummaryEvaluationRepository) Find(queryOptions map[string]interface{
}
return count, datas, nil
}
func (repo *SummaryEvaluationRepository) RemoveByProjectId(id int) error {
tx := repo.transactionContext.PgTx
nowTime := time.Now()
_, err := tx.Model(&models.SummaryEvaluation{}).
Where("evaluation_project_id=?", id).
Set("deleted_at=?", nowTime).
Update()
return err
}
... ...