新版仿ok交易所-后端
1
zj
2025-10-30 14c1946eae86a86f8d1edee6cf3bdaf7572fc966
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package com.yami.trading.admin.task;
 
import com.yami.trading.bean.item.domain.Item;
import com.yami.trading.common.domain.Result;
import com.yami.trading.common.exception.YamiShopBindException;
import com.yami.trading.huobi.data.internal.KlineInitService;
import com.yami.trading.huobi.data.internal.KlineService;
import com.yami.trading.service.item.ItemService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
 
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Collectors;
 
/**
 * @program: trading-order-master
 * @description:
 * @create: 2025-10-30 15:49
 **/
@Component
public class KineTask {
 
    private final AtomicBoolean syncINStockData = new AtomicBoolean(false);
 
    private final Lock syncINStockDataLock = new ReentrantLock();
 
 
    @Autowired
    private KlineInitService klineInitService ;
    @Autowired
    private ItemService itemService;
 
 
 
    /**
     * 同步系统所需要的股票
     */
    @Scheduled(cron = "0 0 0/1 * * ?")
    public void syncINStockData() {
        if (syncINStockData.get()) { // 判断任务是否在处理中
            return;
        }
        if (syncINStockDataLock.tryLock()) {
            try {
                syncINStockData.set(true); // 设置处理中标识为true
 
                String symbols = itemService.list().stream().map(Item::getSymbol).collect(Collectors.joining(","));
                try {
                    klineInitService.klineInit(symbols);
                }catch (Exception e){
                    throw new YamiShopBindException("定时任务k线图初始化失败");
                }
            } finally {
                syncINStockDataLock.unlock();
                syncINStockData.set(false); // 设置处理中标识为false
            }
        }
    }
 
 
}