zj
2024-06-03 287ac389edd047696d956afafdb855a93830bc0c
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
package com.nq.utils;
 
import com.alibaba.fastjson2.JSONObject;
import com.nq.StockApplication;
import com.nq.service.IStockFuturesService;
import com.nq.service.IStockIndexService;
import com.nq.utils.redis.RedisShardedPoolUtils;
import com.nq.utils.stock.sina.SinaStockApi;
import com.nq.vo.foreigncurrency.ExchangeVO;
import com.nq.vo.stock.MarketVO;
import com.nq.vo.stock.StockListVO;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.stereotype.Component;
 
import java.math.BigDecimal;
@Component
public class CurrencyUtils {
//    private static IStockFuturesService iStockFuturesService;
 
    @Autowired
    IStockFuturesService iStockFuturesService;
    @Autowired
    IStockIndexService iStockIndexService;
    //股票
    public String getNowStockPrice(String stockGid, String coinCode) {
        StockListVO stockListVO = new StockListVO();
        BigDecimal price = new BigDecimal(0);
        if (stockGid.contains("us")) {
            String us = RedisShardedPoolUtils.get(stockGid, 2);
            stockListVO = SinaStockApi.otherStockListVO(us);
            ExchangeVO exchangeVO = iStockFuturesService.queryExchangeVO(coinCode).getData();
            price = new BigDecimal(stockListVO.getNowPrice()).multiply(new BigDecimal(exchangeVO.getNowPrice()));
        }else if (stockGid.contains("hk")) {
            String hk = RedisShardedPoolUtils.get(stockGid, 1);
            stockListVO = SinaStockApi.otherStockListVO(hk);
            ExchangeVO exchangeVO = iStockFuturesService.queryExchangeVO(coinCode).getData();
            price = new BigDecimal(stockListVO.getNowPrice()).multiply(new BigDecimal(exchangeVO.getNowPrice()));
        }
        return price.toString();
    }
    //指数
    public  BigDecimal getNowIndexPrice(String indexGid,String coinCode) {
 
        MarketVO marketVO = this.iStockIndexService.querySingleIndex(indexGid);
        ExchangeVO exchangeVO = iStockFuturesService.queryExchangeVO(coinCode).getData();
        BigDecimal  price = new BigDecimal(marketVO.getNowPrice()).multiply(new BigDecimal(exchangeVO.getNowPrice()));
 
        return price;
    }
}