作者 陈志颖

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

@@ -1009,6 +1009,12 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter @@ -1009,6 +1009,12 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter
1009 } 1009 }
1010 } 1010 }
1011 1011
  1012 +// 更新过期任务状态
  1013 +func (taskService *TaskService) UpdateTaskStatus() (interface{}, error) {
  1014 +
  1015 + return nil, nil
  1016 +}
  1017 +
1012 // 更新任务 1018 // 更新任务
1013 func (taskService *TaskService) UpdateTask(updateTaskCommand *command.UpdateTaskCommand) (interface{}, error) { 1019 func (taskService *TaskService) UpdateTask(updateTaskCommand *command.UpdateTaskCommand) (interface{}, error) {
1014 if err := updateTaskCommand.ValidateCommand(); err != nil { 1020 if err := updateTaskCommand.ValidateCommand(); err != nil {
@@ -1105,7 +1111,6 @@ func (taskService *TaskService) UpdateTask(updateTaskCommand *command.UpdateTask @@ -1105,7 +1111,6 @@ func (taskService *TaskService) UpdateTask(updateTaskCommand *command.UpdateTask
1105 // TODO 任务返回错误类型 1111 // TODO 任务返回错误类型
1106 if err := task.Update(updateData); err != nil { 1112 if err := task.Update(updateData); err != nil {
1107 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 1113 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
1108 - //return nil, err  
1109 } 1114 }
1110 if task, err := taskRepository.Save(task); err != nil { 1115 if task, err := taskRepository.Save(task); err != nil {
1111 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1116 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -32,14 +32,14 @@ func (dao *TaskDao) ListNearThePlannedCompletionTimeTask() ([]*models.Task, erro @@ -32,14 +32,14 @@ func (dao *TaskDao) ListNearThePlannedCompletionTimeTask() ([]*models.Task, erro
32 } 32 }
33 } 33 }
34 34
35 -// 更新已过期的竞标任务的状态 35 +// 更新已过期的竞标任务的状态,过期时间为竞标结束时间
36 func (dao *TaskDao) UpdateExpiredPlannedCompletionTimeBidTask() error { 36 func (dao *TaskDao) UpdateExpiredPlannedCompletionTimeBidTask() error {
37 currentTime := time.Now() 37 currentTime := time.Now()
38 currentDay := time.Date(currentTime.Year(), currentTime.Month(), currentTime.Day(), 23, 59, 59, 0, time.Now().Location()) 38 currentDay := time.Date(currentTime.Year(), currentTime.Month(), currentTime.Day(), 23, 59, 59, 0, time.Now().Location())
39 tx := dao.transactionContext.PgTx 39 tx := dao.transactionContext.PgTx
40 _, err := tx.Query( 40 _, err := tx.Query(
41 pg.Scan(), 41 pg.Scan(),
42 - "UPDATE tasks SET task_status = ? WHERE planned_completion_time < ? AND task_type = ? AND task_status = ?", 42 + "UPDATE tasks SET task_status = ? FROM bid_infos WHERE bid_infos.bid_end_time < ? AND tasks.task_type = ? AND tasks.task_status = ?",
43 domain.TASK_STATUS_EXPIRED, currentDay, domain.TASK_TYPE_BID, domain.TASK_STATUS_UNCLAIMED) 43 domain.TASK_STATUS_EXPIRED, currentDay, domain.TASK_TYPE_BID, domain.TASK_STATUS_UNCLAIMED)
44 return err 44 return err
45 } 45 }
@@ -214,6 +214,22 @@ func (controller *TaskController) UpdateTask() { @@ -214,6 +214,22 @@ func (controller *TaskController) UpdateTask() {
214 controller.ServeJSON() 214 controller.ServeJSON()
215 } 215 }
216 216
  217 +// 更新过期任务状态
  218 +func (controller *TaskController) UpdateTaskStatus() {
  219 + taskService := service.NewTaskService(nil)
  220 + updateTaskCommand := &command.UpdateTaskCommand{}
  221 + json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), updateTaskCommand)
  222 + data, err := taskService.UpdateTaskStatus()
  223 + var response utils.JsonResponse
  224 + if err != nil {
  225 + response = utils.ResponseError(controller.Ctx, err)
  226 + } else {
  227 + response = utils.ResponseData(controller.Ctx, data)
  228 + }
  229 + controller.Data["json"] = response
  230 + controller.ServeJSON()
  231 +}
  232 +
217 func (controller *TaskController) GetTask() { 233 func (controller *TaskController) GetTask() {
218 taskService := service.NewTaskService(nil) 234 taskService := service.NewTaskService(nil)
219 getTaskQuery := &query.GetTaskQuery{} 235 getTaskQuery := &query.GetTaskQuery{}
@@ -21,4 +21,5 @@ func init() { @@ -21,4 +21,5 @@ func init() {
21 beego.Router("/tasks/:taskId", &controllers.TaskController{}, "Get:GetTask") 21 beego.Router("/tasks/:taskId", &controllers.TaskController{}, "Get:GetTask")
22 beego.Router("/tasks/:taskId", &controllers.TaskController{}, "Delete:RemoveTask") 22 beego.Router("/tasks/:taskId", &controllers.TaskController{}, "Delete:RemoveTask")
23 beego.Router("/tasks/", &controllers.TaskController{}, "Get:ListTask") 23 beego.Router("/tasks/", &controllers.TaskController{}, "Get:ListTask")
  24 + beego.Router("/tasks/test/expired", &controllers.TaskController{}, "Put:UpdateTaskStatus")
24 } 25 }