package com.yeejoin.equipmanage.utils;

import com.yeejoin.equipmanage.common.utils.SpringUtils;
import com.yeejoin.equipmanage.fegin.JcsFeign;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Component;
import org.typroject.tyboot.core.restful.utils.ResponseModel;

import javax.annotation.PostConstruct;

/***
 *
 * 获取动态值
 *
 * **/
@Component
public class RoleNameExplicitConstraint implements ExplicitInterface, BeanPostProcessor {


	private static JcsFeign jcsFeign1;

//	@PostConstruct
//	public void init(){
//		jcsFeign1 =   SpringUtils.getBean("jcsFeign",JcsFeign.class);
//	}

	@Override
	public Object postProcessAfterInitialization(@Nullable Object bean, String beanName) {
		if (bean != null && bean instanceof JcsFeign) {
			return 	jcsFeign1 = (JcsFeign)bean;
		}
		return bean;
	}

	@Override
	public String[] source(String type, String method,String token, String appKey, String product)  {
	    try {
            ResponseModel<String[]>  strarr =  jcsFeign1.getEquipmentInfo(appKey, product, token, null, method);
            if(null != strarr.getResult()) {
                return strarr.getResult();
            }
        } catch (Exception e){
	        throw new RuntimeException(e.getMessage());
        }
		return  null;
	}
}
