作者 陈志颖

fix:修复定时任务更新过期竞标任务问题

... ... @@ -1009,6 +1009,12 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter
}
}
// 更新过期任务状态
func (taskService *TaskService) UpdateTaskStatus() (interface{}, error) {
return nil, nil
}
// 更新任务
func (taskService *TaskService) UpdateTask(updateTaskCommand *command.UpdateTaskCommand) (interface{}, error) {
if err := updateTaskCommand.ValidateCommand(); err != nil {
... ... @@ -1105,7 +1111,6 @@ func (taskService *TaskService) UpdateTask(updateTaskCommand *command.UpdateTask
// TODO 任务返回错误类型
if err := task.Update(updateData); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
//return nil, err
}
if task, err := taskRepository.Save(task); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ...
... ... @@ -32,14 +32,14 @@ func (dao *TaskDao) ListNearThePlannedCompletionTimeTask() ([]*models.Task, erro
}
}
// 更新已过期的竞标任务的状态
// 更新已过期的竞标任务的状态,过期时间为竞标结束时间
func (dao *TaskDao) UpdateExpiredPlannedCompletionTimeBidTask() error {
currentTime := time.Now()
currentDay := time.Date(currentTime.Year(), currentTime.Month(), currentTime.Day(), 23, 59, 59, 0, time.Now().Location())
tx := dao.transactionContext.PgTx
_, err := tx.Query(
pg.Scan(),
"UPDATE tasks SET task_status = ? WHERE planned_completion_time < ? AND task_type = ? AND task_status = ?",
"UPDATE tasks SET task_status = ? FROM bid_infos WHERE bid_infos.bid_end_time < ? AND tasks.task_type = ? AND tasks.task_status = ?",
domain.TASK_STATUS_EXPIRED, currentDay, domain.TASK_TYPE_BID, domain.TASK_STATUS_UNCLAIMED)
return err
}
... ...
... ... @@ -214,6 +214,22 @@ func (controller *TaskController) UpdateTask() {
controller.ServeJSON()
}
// 更新过期任务状态
func (controller *TaskController) UpdateTaskStatus() {
taskService := service.NewTaskService(nil)
updateTaskCommand := &command.UpdateTaskCommand{}
json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), updateTaskCommand)
data, err := taskService.UpdateTaskStatus()
var response utils.JsonResponse
if err != nil {
response = utils.ResponseError(controller.Ctx, err)
} else {
response = utils.ResponseData(controller.Ctx, data)
}
controller.Data["json"] = response
controller.ServeJSON()
}
func (controller *TaskController) GetTask() {
taskService := service.NewTaskService(nil)
getTaskQuery := &query.GetTaskQuery{}
... ...
... ... @@ -21,4 +21,5 @@ func init() {
beego.Router("/tasks/:taskId", &controllers.TaskController{}, "Get:GetTask")
beego.Router("/tasks/:taskId", &controllers.TaskController{}, "Delete:RemoveTask")
beego.Router("/tasks/", &controllers.TaskController{}, "Get:ListTask")
beego.Router("/tasks/test/expired", &controllers.TaskController{}, "Put:UpdateTaskStatus")
}
... ...