admin
2024-06-16 6dc80d22028789ff8f6f42e552247e75e93516bc
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
package com.taoke.autopay.task;
 
import com.taoke.autopay.entity.KeyOrder;
import com.taoke.autopay.service.KeyOrderService;
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 KeyOrderDistributeTask {
    @Resource
    private KeyOrderService keyOrderService;
 
    @Scheduled(cron = "0/5 * * * * ? ")
    private void distribute(){
        try {
            List<KeyOrder> results = keyOrderService.listNotDistributed(1, 20);
            if (results != null) {
                for (KeyOrder order : results) {
                    if (order.getDistributeClientUid() == null) {
                        continue;
                    }
                    Long uid = keyOrderService.getCanDistributeUid();
                    if (uid != null) {
                        KeyOrder orderUpdate = new KeyOrder();
                        orderUpdate.setId(order.getId());
                        orderUpdate.setDistributeClientUid(uid);
                        orderUpdate.setDistributeTime(new Date());
                        keyOrderService.update(orderUpdate);
                    }
                }
            }
        }catch(Exception e){
 
        }
    }
 
}