package com.taoke.autopay.task; import com.taoke.autopay.dao.OrderTaskMapper; import com.taoke.autopay.entity.js2.OrderTask; import com.taoke.autopay.service.js2.OrderTaskService; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.Scheduled; import javax.annotation.Resource; import java.util.Date; import java.util.List; @Configuration @EnableScheduling public class OrderTaskDistributeTask { @Value("${task-enable}") private boolean taskEnable; @Resource private OrderTaskService orderTaskService; /** * 为下单任务分配客户端设备 */ @Scheduled(cron = "0/5 * * * * ? ") private void assignOrderTask() { if(!taskEnable){ return; } // 对处于分配中的任务进行分配 try { OrderTaskMapper.DaoQuery query=new OrderTaskMapper.DaoQuery(); query.status = OrderTask.STATUS_ASSIGNING; // 对1小时内创建的任务进行分配 query.minCreateTime=new Date(System.currentTimeMillis() - 1000 * 60 * 60L); List orderTaskList = orderTaskService.listOrderTasks(query, 1, 20); if (orderTaskList != null) { for (OrderTask orderTask : orderTaskList) { orderTaskService.assignTask(orderTask.getId()); } } } catch (Exception e) { } } }