作者 tangxvhui
... ... @@ -589,70 +589,76 @@ func (rs *EvaluationProjectService) Activate(in *command.ActivateProjectCommand)
principalId = intId
}
now := time.Now().Local()
year, month, day := now.Date()
nowO := time.Date(year, month, day, 0, 0, 0, 0, time.Local) // 当前时间0点0分0秒时刻
for i := range project.Template.LinkNodes {
node := project.Template.LinkNodes[i]
task := &domain.NodeTask{
Id: 0,
CompanyId: project.CompanyId,
CycleId: project.CycleId,
ProjectId: project.Id,
NodeId: node.Id,
NodeType: node.Type,
NodeName: node.Name,
NodeDescribe: node.Describe,
NodeSort: i + 1,
TimeStart: node.TimeStart,
TimeEnd: node.TimeEnd,
KpiCycle: node.KpiCycle,
}
// 环节起始和截止本地时间
startLocal := task.TimeStart.Local()
sY, sM, sD := startLocal.Date()
startLocal = time.Date(sY, sM, sD, 0, 0, 0, 0, time.Local) // 开始时间以0点开始计算
endLocal := task.TimeEnd.Local()
// 在当前时间之前,则计算下一个周期时间
if startLocal.Before(nowO) {
nextTime := utils.NextTime(nowO, startLocal, node.KpiCycle)
task.NextSentAt = &nextTime
} else {
task.NextSentAt = &startLocal
}
// 如果超出截至时间,则周期置空
if task.NextSentAt.After(endLocal) {
task.NextSentAt = nil
}
tasks, err := taskRepository.Find(map[string]interface{}{"projectId": project.Id})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if len(tasks) == 0 {
now := time.Now().Local()
year, month, day := now.Date()
nowO := time.Date(year, month, day, 0, 0, 0, 0, time.Local) // 当前时间0点0分0秒时刻
for i := range project.Template.LinkNodes {
node := project.Template.LinkNodes[i]
task := &domain.NodeTask{
Id: 0,
CompanyId: project.CompanyId,
CycleId: project.CycleId,
ProjectId: project.Id,
NodeId: node.Id,
NodeType: node.Type,
NodeName: node.Name,
NodeDescribe: node.Describe,
NodeSort: i + 1,
TimeStart: node.TimeStart,
TimeEnd: node.TimeEnd,
KpiCycle: node.KpiCycle,
}
_, err := taskRepository.Insert(task)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 环节起始和截止本地时间
startLocal := task.TimeStart.Local()
sY, sM, sD := startLocal.Date()
startLocal = time.Date(sY, sM, sD, 0, 0, 0, 0, time.Local) // 开始时间以0点开始计算
endLocal := task.TimeEnd.Local()
// 任务指标生成任务
for j := range node.NodeContents {
content := node.NodeContents[j]
if content.IndicatorType == domain.IndicatorTypeTask {
if principalId == 0 {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "请选择任务负责人")
}
err := projectTaskService.CreateTask(transactionContext, &taskCommand.CreateTaskCommand{
Name: content.Name,
LeaderId: principalId,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// 在当前时间之前,则计算下一个周期时间
if startLocal.Before(nowO) {
nextTime := utils.NextTime(nowO, startLocal, node.KpiCycle)
task.NextSentAt = &nextTime
} else {
task.NextSentAt = &startLocal
}
// 如果超出截至时间,则周期置空
if task.NextSentAt.After(endLocal) {
task.NextSentAt = nil
}
_, err := taskRepository.Insert(task)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 任务指标生成任务
for j := range node.NodeContents {
content := node.NodeContents[j]
if content.IndicatorType == domain.IndicatorTypeTask {
if principalId == 0 {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "请选择任务负责人")
}
err := projectTaskService.CreateTask(transactionContext, &taskCommand.CreateTaskCommand{
Name: content.Name,
LeaderId: principalId,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
}
}
}
}
err = rs.generateEvaluationItemUsed(transactionContext, project)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
err = rs.generateEvaluationItemUsed(transactionContext, project)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
}
if err := transactionContext.CommitTransaction(); err != nil {
... ...