admin
2025-08-08 035edfa382d349ba66240fbfef68c14c7cfc95d1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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<OrderTask> orderTaskList =  orderTaskService.listOrderTasks(query, 1, 20);
            if (orderTaskList != null) {
                for (OrderTask orderTask : orderTaskList) {
                    orderTaskService.assignTask(orderTask.getId());
                }
            }
        } catch (Exception e) {
 
        }
    }
 
}