提交 4954d427 编写于 作者: sq3536's avatar sq3536

默认的addr

上级 8abd0cbf
......@@ -13,7 +13,11 @@ import cn.ibizlab.util.security.AuthenticationUser;
import cn.ibizlab.util.service.IBZConfigService;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.nacos.api.naming.NamingFactory;
import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.api.naming.pojo.Instance;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.context.annotation.Primary;
......@@ -22,10 +26,7 @@ import org.springframework.data.domain.PageImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
@Primary
@Service
......@@ -41,6 +42,8 @@ public class SysAppService extends SysAppServiceImpl
@Autowired
private UAACoreService uaaCoreService;
@Value("${spring.cloud.nacos.discovery.server-addr:127.0.0.1:8848}")
private String serverAddr;
//@Cacheable( value="ibzuaa_switcher",key = "'id:'+#p0+'||'+#p1")
public JSONObject getAppSwitcher(String id,String userId)
......@@ -79,6 +82,31 @@ public class SysAppService extends SysAppServiceImpl
sysApp.setVisabled(0);
list.add(sysApp);
});
try {
Properties properties = new Properties();
properties.setProperty("serverAddr", serverAddr);
NamingService naming = NamingFactory.createNamingService(properties);
list.forEach(sysApp -> {
if(StringUtils.isEmpty(sysApp.getAddr()))
{
try {
Instance instance = naming.selectOneHealthyInstance(sysApp.getId());
if(instance!=null)
{
String domains="http://"+instance.getIp();
if(instance.getPort()!=80)
domains=domains+":"+instance.getPort();
sysApp.setAddr(domains);
}
}
catch (Exception ex){}
}
});
}
catch (Exception ex){}
jo.remove("model");
jo.put("model",JSONArray.toJSON(list));
return jo;
......
......@@ -17,11 +17,14 @@ import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.http.HttpRequest;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.validation.constraints.NotBlank;
import java.util.List;
import java.util.Map;
......@@ -82,8 +85,16 @@ public class UAACoreResource {
private SysAppService sysAppService;
@GetMapping(value = "uaa/access-center/app-switcher/{id}")
public ResponseEntity<JSONObject> appswitcher(@PathVariable("id") String id)
public ResponseEntity<JSONObject> appswitcher(@PathVariable("id") String id, HttpServletRequest request)
{
String proto=request.getHeader("x-forwarded-proto");
String hosts=request.getHeader("x-forwarded-for");
String domains="";
if(StringUtils.isEmpty(proto))
proto="http";
if(!StringUtils.isEmpty(hosts))
domains=proto+"://"+hosts;
return ResponseEntity.ok(sysAppService.getAppSwitcher(id, AuthenticationUser.getAuthenticationUser().getUserid()));
}
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册