package com.ruoyi.framework.config;

import javax.servlet.http.HttpServletRequest;

import com.ruoyi.framework.config.properties.IpConfiguration;
import com.ruoyi.project.activiti.service.impl.BizLeaveServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import com.ruoyi.common.utils.ServletUtils;

import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * 服务相关配置
 * 
 * @author zdd
 */
@Component
public class ServerConfig
{
    protected static final Logger logger = LoggerFactory.getLogger(ServerConfig.class);


    /**
     * 获取完整的请求路径，包括：域名，端口，上下文访问路径
     * 
     * @return 服务地址
     */
    public String getUrl()
    {
        HttpServletRequest request = ServletUtils.getRequest();
        return getDomain(request);
    }
    @Autowired
    IpConfiguration ip;

    public String getDomain(HttpServletRequest request)
    {
        InetAddress   address = null;
        try {
            address = InetAddress.getLocalHost();
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
        String ipPort="http://"+address.getHostAddress()+":"+ip.getPort();
       /* StringBuffer url = request.getRequestURL();
        String contextPath = request.getServletContext().getContextPath();
        String s = url.delete(url.length() - request.getRequestURI().length(), url.length()).append(contextPath).toString();*/
        return ipPort;
    }
}
