作者 tangxvhui

更新 task结构

... ... @@ -91,6 +91,7 @@ func (srv TaskService) CreateTask(transactionContext application.TransactionCont
}
leaderData := leaderList[0]
nowTime := time.Now()
nowEndTime := dayEndTime(nowTime)
newTask := domain.Task{
Id: 0,
CreatedAt: time.Time{},
... ... @@ -116,7 +117,6 @@ func (srv TaskService) CreateTask(transactionContext application.TransactionCont
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, "创建任务失败:"+err.Error())
}
nowEndTime := dayEndTime(nowTime)
newTaskStage := []*domain.TaskStage{
{
Id: 0,
... ... @@ -143,11 +143,15 @@ func (srv TaskService) CreateTask(transactionContext application.TransactionCont
RealCompletedAt: 0,
},
}
err = taskStageRepo.Save(newTaskStage)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, "创建任务失败:"+err.Error())
}
newTask.CurrentStage = *newTaskStage[0]
err = taskRepo.Save(&newTask)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存任务失败:"+err.Error())
}
return nil
}
... ... @@ -282,11 +286,17 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string]
}
}
}
//更新当前 执行的里程碑
err = taskStageRepo.Save(stageList)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
for _, val := range stageList {
if val.RealCompletedAt == 0 {
taskData.CurrentStage = *val
break
}
}
err = taskRepo.Save(taskData)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -770,6 +780,7 @@ func (srv TaskService) ListTask2(param *command.SearchTaskCommand) (map[string]i
case 5:
taskData.StageE = stage
}
}
result := tool_funs.SimpleWrapGridMap(int64(taskCount), taskResult)
result["taskStageAnomaly"] = taskStageAnomalyCnt
... ... @@ -896,38 +907,43 @@ func (srv TaskService) ReplyTaskStage(transactionContext application.Transaction
taskStageRepo := factory.CreateTaskStageRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
var taskList []*domain.Task
var taskStages []*domain.TaskStage
for _, val := range param {
taskData, err := taskRepo.FindOne(map[string]interface{}{"id": val.TaskId})
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, "找不到任务数据"+err.Error())
}
_, stageList, err := taskStageRepo.Find(map[string]interface{}{"ids": []int{val.TaskStageCheck.Id}})
_, stageList, err := taskStageRepo.Find(map[string]interface{}{"taskId": []int{val.TaskId}})
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, "找不到任务里程碑数据"+err.Error())
}
if val.AnomalyState == domain.AnomalyState1 {
taskData.Anomaly = 0
}
if len(stageList) > 0 {
stageList[0].RealCompletedAt = val.TaskStageCheck.RealCompletedAt
taskStages = append(taskStages, stageList[0])
if stageList[0].PlanCompletedAt < stageList[0].RealCompletedAt {
for _, val2 := range stageList {
if val2.Id == val.TaskStageCheck.Id {
continue
}
val2.RealCompletedAt = val.TaskStageCheck.RealCompletedAt
if val2.PlanCompletedAt < val2.RealCompletedAt {
taskData.WarnFlag = domain.TaskWarn
} else {
taskData.WarnFlag = domain.TaskWarnNull
}
break
}
taskList = append(taskList, taskData)
taskData.CurrentStage = domain.TaskStage{}
//设置下一个 待执行的里程碑
for _, val2 := range stageList {
if val2.RealCompletedAt == 0 {
taskData.CurrentStage = *val2
break
}
err := taskStageRepo.Save(taskStages)
}
err = taskStageRepo.Save(stageList)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存任务里程碑数据"+err.Error())
}
for _, val := range taskList {
err = taskRepo.Save(val)
err = taskRepo.Save(taskData)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存任务数据"+err.Error())
}
... ...
... ... @@ -35,6 +35,7 @@ type Task struct {
StopAt int64 `json:"stopAt"` // 停止的时间戳,秒
Anomaly int `json:"anomaly"` // 异常反馈的次数
WarnFlag TaskWarnFlag `json:"warnFlag"` // 里程碑异常标记
CurrentStage TaskStage `json:"currentStage"` // 当前执行的里程碑
}
type TaskLeader struct {
... ...
... ... @@ -196,6 +196,7 @@ func (d *StaffAssessDao) SearchTargetUserCycleProject(companyId int, targetUserI
and staff_assess."types" ='self'
and staff_assess_task.deleted_at isnull
and staff_assess.deleted_at isnull
and staff_assess.end_time <=now()
and staff_assess.target_user ->>'userId'='?'
and staff_assess.company_id=?
`
... ...
... ... @@ -25,4 +25,5 @@ type Task struct {
StopAt int64 `pg:"stop_at,use_zero" ` // 停止的时间
Anomaly int `pg:"anomaly,use_zero"` // 异常反馈的数量
WarnFlag int `pg:"warn_flag,use_zero"` // 里程碑异常标记
CurrentStage domain.TaskStage `pg:"current_stage"` // 当前执行的里程碑
}
... ...
... ... @@ -42,6 +42,7 @@ func (repo *TaskRepository) TransformToDomain(d *models.Task) *domain.Task {
StopAt: d.StopAt,
Anomaly: d.Anomaly,
WarnFlag: domain.TaskWarnFlag(d.WarnFlag),
CurrentStage: d.CurrentStage,
}
}
... ... @@ -67,6 +68,7 @@ func (repo *TaskRepository) Save(param *domain.Task) error {
StopAt: param.StopAt,
Anomaly: param.Anomaly,
WarnFlag: int(param.WarnFlag),
CurrentStage: param.CurrentStage,
}
db := repo.transactionContext.PgTx
if m.Id == 0 {
... ...
... ... @@ -75,28 +75,3 @@ SET
WHERE
id IN (18404, 18458);
--
WITH t1 AS (
SELECT
summary_evaluation_value.evaluation_item_id,
summary_evaluation_value.value,
summary_evaluation_value.id AS value_id,
summary_evaluation_value.score,
summary_evaluation.company_id
FROM
summary_evaluation_value
JOIN summary_evaluation ON summary_evaluation_value.summary_evaluation_id = summary_evaluation.id
WHERE
summary_evaluation_value.value = summary_evaluation_value.score
AND summary_evaluation."types" = 1
ORDER BY
summary_evaluation_value.created_at
)
SELECT
t1.value_id,
cast(evaluation_item_used.weight AS float) AS weight,
cast(t1.value AS float) AS value,
cast(t1.value AS float) * cast(evaluation_item_used.weight AS float) AS real_value
FROM
evaluation_item_used
JOIN t1 ON t1.evaluation_item_id = evaluation_item_used.id
... ...
-- 调整 summary_evaluation_value 数据
WITH t1 AS (
SELECT
summary_evaluation_value.evaluation_item_id,
summary_evaluation_value.value,
summary_evaluation_value.id AS value_id,
summary_evaluation_value.score,
summary_evaluation.company_id
FROM
summary_evaluation_value
JOIN summary_evaluation ON summary_evaluation_value.summary_evaluation_id = summary_evaluation.id
JOIN evaluation_item_used ON evaluation_item_used.id = summary_evaluation_value.evaluation_item_id
WHERE
summary_evaluation_value.value = summary_evaluation_value.score
AND summary_evaluation."types" = 1
AND evaluation_item_used.weight > 0
ORDER BY
summary_evaluation_value.created_at
),
t2 AS (
SELECT
t1.value_id,
cast(evaluation_item_used.weight AS float) AS weight,
cast(t1.value AS float) AS value,
cast(t1.value AS float) * cast(evaluation_item_used.weight AS float) AS real_value
FROM
evaluation_item_used
JOIN t1 ON t1.evaluation_item_id = evaluation_item_used.id)
UPDATE
summary_evaluation_value
SET
score = t2.real_value
FROM
t2
WHERE
summary_evaluation_value.id = t2.value_id;
-- 调整summary_evaluation 数据
WITH t1 AS (
SELECT
sum(cast(summary_evaluation_value.score AS float)) AS total_score,
summary_evaluation_value.summary_evaluation_id
FROM
summary_evaluation_value
JOIN summary_evaluation ON summary_evaluation_value.summary_evaluation_id = summary_evaluation.id
JOIN evaluation_item_used ON evaluation_item_used.id = summary_evaluation_value.evaluation_item_id
WHERE
summary_evaluation."types" = 1
AND evaluation_item_used.weight > 0
GROUP BY
summary_evaluation_value.summary_evaluation_id)
UPDATE
summary_evaluation
SET
total_score = t1.total_score
FROM
t1
WHERE
summary_evaluation.id = t1.summary_evaluation_id
... ...