package com.jxy.marketall.service.impl;

import com.jxy.common.core.exception.GlobalException;
import com.jxy.common.core.web.Result.AjaxResult;
import com.jxy.marketall.enums.CoinType;
import com.jxy.marketall.enums.DerivativeType;
import com.jxy.marketall.service.DerivativeService;
import com.jxy.marketall.service.NodeJsMarketFeign;
import com.jxy.marketall.utils.EnumUtils;
import com.jxy.marketall.vo.CoinByTypeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;


/**
 * @Description 分配数据查询业务处理
 * @Date 2022/6/10 10:25
 * @Author 杜懿
 */
@Service
public class DerivativeServiceImpl implements DerivativeService {

    @Autowired
    private NodeJsMarketFeign nodeJsMarketFeign;

    @Override
    public AjaxResult findDerivativeDataByTypeAndCoin(CoinByTypeVo coinByTypeVo) {

        HashMap<String,String> map = new HashMap<>();
        String type = coinByTypeVo.getType();
        String coin = coinByTypeVo.getCoin();

        /** 条件范围 */
        if(!EnumUtils.isInclude(DerivativeType.class,type)){
            //todo 自定义异常
            throw new GlobalException("type传参不在查询访问之内！");
        }
        if(!EnumUtils.isInclude(CoinType.class,coin)){
            //todo 自定义异常
            throw new  GlobalException("coin传参不在查询访问之内！");
        }

        DerivativeType derivativeType = (DerivativeType) EnumUtils.get(DerivativeType.class,type);
        map.put("type",derivativeType.getInfo());

        CoinType coinType = (CoinType) EnumUtils.get(CoinType.class,coin);
        map.put("coin",coinType.getInfo());


        /** 调用查询接口 */
        Object returnDto = nodeJsMarketFeign.derivatives(map);
        return AjaxResult.success(returnDto);
    }


}
