package com.friday.custody.service.dubboService;


import com.friday.custody.dto.InterProviderResponseDto;
import com.friday.custody.service.trustService.zx.utils.SearchReturnClass;
import com.friday.custody.exception.RRException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@Service
@Slf4j
public class HtscCdsServiceImpl implements HtscCdsService{

    @Resource
    private SearchReturnClass searchReturnClass;

    /**
     * @param tradingDay yyyy-MM-dd
     */
    @Override
    public BigDecimal bondYeildRate(String tradingDay) {
        InterProviderResponseDto resultData = searchReturnClass.tenYearsNationalBondYeildRate(tradingDay);
        List<Map<String, Object>> dataList = resultData.getDataList();
        if (!CollectionUtils.isEmpty(dataList)){
            Map<String, Object> map = dataList.get(0);
            BigDecimal riskFreeRate = (BigDecimal) map.getOrDefault("YIELDMATURITY",0);
            log.info("获取资讯平台10年期国债收益率,tradingDay:{},riskFreeRate:{}",tradingDay,riskFreeRate);
            return riskFreeRate;
        }
        log.info("获取资讯平台10年期国债收益率数据为空,tradingDay:{}",tradingDay);
        return null;
    }
}
