作者 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)
}
err := taskStageRepo.Save(taskStages)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存任务里程碑数据"+err.Error())
}
for _, val := range taskList {
err = taskRepo.Save(val)
taskData.CurrentStage = domain.TaskStage{}
//设置下一个 待执行的里程碑
for _, val2 := range stageList {
if val2.RealCompletedAt == 0 {
taskData.CurrentStage = *val2
break
}
}
err = taskStageRepo.Save(stageList)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存任务里程碑数据"+err.Error())
}
err = taskRepo.Save(taskData)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存任务数据"+err.Error())
}
... ...
... ... @@ -19,22 +19,23 @@ const (
// 任务
type Task struct {
Id int `json:"id"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
DeletedAt *time.Time `json:"deletedAt"`
CompanyId int `json:"companyId,string"`
Name string `json:"name"` // 任务名称
Alias string `json:"alias"` // 任务别名
Leader TaskLeader `json:"leader"` // 任务负责人
Status TaskState `json:"status"` // 任务的状态
Level int `json:"level"` // 优先级,值越小优先级越高
LevelName string `json:"levelName"` // 优先级名称
RelatedUser []int `json:"relatedUser"` // 相关的员工id
RunAt int64 `json:"runAt"` // 启动的时间戳,秒
StopAt int64 `json:"stopAt"` // 停止的时间戳,秒
Anomaly int `json:"anomaly"` // 异常反馈的次数
WarnFlag TaskWarnFlag `json:"warnFlag"` // 里程碑异常标记
Id int `json:"id"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
DeletedAt *time.Time `json:"deletedAt"`
CompanyId int `json:"companyId,string"`
Name string `json:"name"` // 任务名称
Alias string `json:"alias"` // 任务别名
Leader TaskLeader `json:"leader"` // 任务负责人
Status TaskState `json:"status"` // 任务的状态
Level int `json:"level"` // 优先级,值越小优先级越高
LevelName string `json:"levelName"` // 优先级名称
RelatedUser []int `json:"relatedUser"` // 相关的员工id
RunAt int64 `json:"runAt"` // 启动的时间戳,秒
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=?
`
... ...
... ... @@ -8,21 +8,22 @@ import (
// 任务
type Task struct {
tableName struct{} `comment:"任务" pg:"task"`
Id int `pg:"id,pk"` //
CreatedAt time.Time `pg:"created_at"` //
UpdatedAt time.Time `pg:"updated_at"` //
DeletedAt *time.Time `pg:"deleted_at"` //
Name string `pg:"name"` // 任务名称
Alias string `pg:"alias"` //
CompanyId int `pg:"company_id"` //
Leader domain.TaskLeader `pg:"leader"` // 任务负责人
Status int `pg:"status,use_zero"` // 任务的状态
Level int `pg:"level,use_zero"` // 优先级,值越小优先级越高
LevelName string `pg:"level_name"` // 优先级名称
RelatedUser []int `pg:"related_user"` //
RunAt int64 `pg:"run_at,use_zero"` // 启动的时间
StopAt int64 `pg:"stop_at,use_zero" ` // 停止的时间
Anomaly int `pg:"anomaly,use_zero"` // 异常反馈的数量
WarnFlag int `pg:"warn_flag,use_zero"` // 里程碑异常标记
tableName struct{} `comment:"任务" pg:"task"`
Id int `pg:"id,pk"` //
CreatedAt time.Time `pg:"created_at"` //
UpdatedAt time.Time `pg:"updated_at"` //
DeletedAt *time.Time `pg:"deleted_at"` //
Name string `pg:"name"` // 任务名称
Alias string `pg:"alias"` //
CompanyId int `pg:"company_id"` //
Leader domain.TaskLeader `pg:"leader"` // 任务负责人
Status int `pg:"status,use_zero"` // 任务的状态
Level int `pg:"level,use_zero"` // 优先级,值越小优先级越高
LevelName string `pg:"level_name"` // 优先级名称
RelatedUser []int `pg:"related_user"` //
RunAt int64 `pg:"run_at,use_zero"` // 启动的时间
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"` // 当前执行的里程碑
}
... ...
... ... @@ -26,22 +26,23 @@ func NewTaskRepository(transactionContext *pgTransaction.TransactionContext) *Ta
func (repo *TaskRepository) TransformToDomain(d *models.Task) *domain.Task {
return &domain.Task{
Id: d.Id,
CreatedAt: d.CreatedAt,
UpdatedAt: d.UpdatedAt,
DeletedAt: d.DeletedAt,
CompanyId: d.CompanyId,
Name: d.Name,
Alias: d.Alias,
Leader: d.Leader,
Status: domain.TaskState(d.Status),
Level: d.Level,
LevelName: d.LevelName,
RelatedUser: d.RelatedUser,
RunAt: d.RunAt,
StopAt: d.StopAt,
Anomaly: d.Anomaly,
WarnFlag: domain.TaskWarnFlag(d.WarnFlag),
Id: d.Id,
CreatedAt: d.CreatedAt,
UpdatedAt: d.UpdatedAt,
DeletedAt: d.DeletedAt,
CompanyId: d.CompanyId,
Name: d.Name,
Alias: d.Alias,
Leader: d.Leader,
Status: domain.TaskState(d.Status),
Level: d.Level,
LevelName: d.LevelName,
RelatedUser: d.RelatedUser,
RunAt: d.RunAt,
StopAt: d.StopAt,
Anomaly: d.Anomaly,
WarnFlag: domain.TaskWarnFlag(d.WarnFlag),
CurrentStage: d.CurrentStage,
}
}
... ... @@ -51,22 +52,23 @@ func (repo *TaskRepository) Save(param *domain.Task) error {
param.CreatedAt = time.Now()
}
m := models.Task{
Id: param.Id,
CreatedAt: param.CreatedAt,
UpdatedAt: param.UpdatedAt,
DeletedAt: param.DeletedAt,
Name: param.Name,
Alias: param.Alias,
CompanyId: param.CompanyId,
Leader: param.Leader,
Status: int(param.Status),
Level: param.Level,
LevelName: param.LevelName,
RelatedUser: param.RelatedUser,
RunAt: param.RunAt,
StopAt: param.StopAt,
Anomaly: param.Anomaly,
WarnFlag: int(param.WarnFlag),
Id: param.Id,
CreatedAt: param.CreatedAt,
UpdatedAt: param.UpdatedAt,
DeletedAt: param.DeletedAt,
Name: param.Name,
Alias: param.Alias,
CompanyId: param.CompanyId,
Leader: param.Leader,
Status: int(param.Status),
Level: param.Level,
LevelName: param.LevelName,
RelatedUser: param.RelatedUser,
RunAt: param.RunAt,
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
... ...