Commit 4ffc0051 authored by taabe's avatar taabe

平台获取字典接口示例

parent f3df8855
......@@ -10,14 +10,14 @@ import org.springframework.stereotype.Service;
import java.util.List;
/**
* Feign service
* 平台Feign service
*
* @author tb
*/
@Service
public class FeignService {
public class AmosFeignService {
private final Logger logger = LogManager.getLogger(FeignService.class);
private final Logger logger = LogManager.getLogger(AmosFeignService.class);
/**
* 根据dictCode从平台获取数据字典
......
package com.yeejoin.amos.boot.biz.common.feign;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.util.StringUtils;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
/**
* @author DELL
*/
public class FeignAuthRequestInterceptor implements RequestInterceptor {
public FeignAuthRequestInterceptor() {
}
@Override
public void apply(RequestTemplate template) {
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
if (attributes != null) {
HttpServletRequest request = attributes.getRequest();
/* Get token from header */
String authToken = StringUtils.isEmpty(request.getHeader("X-Access-Token")) ? request.getHeader("token") : request.getHeader("X-Access-Token");
/* If token not found get it from request parameter */
if (authToken == null) {
authToken = request.getParameter("token");
}
template.header("X-Access-Token", authToken);
template.header("token", authToken);
template.header("appKey", request.getHeader("appKey"));
template.header("product", request.getHeader("product"));
}
}
}
package com.yeejoin.amos.boot.biz.common.feign;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @author DELL
*/
@Configuration
public class FeignConfiguration {
/**
* 创建Feign请求拦截器,在发送请求前设置认证的token,各个微服务将token设置到环境变量中来达到通用
* @return
*/
@Bean
public FeignAuthRequestInterceptor basicAuthRequestInterceptor() {
return new FeignAuthRequestInterceptor();
}
}
......@@ -4,7 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.boot.biz.common.controller.BaseController;
import com.yeejoin.amos.boot.biz.common.feign.FeignService;
import com.yeejoin.amos.boot.biz.common.feign.AmosFeignService;
import com.yeejoin.amos.boot.biz.common.utils.NameUtils;
import com.yeejoin.amos.boot.module.tzs.api.entity.UseUnit;
import com.yeejoin.amos.boot.module.tzs.api.service.EquipFeignService;
......@@ -47,7 +47,7 @@ public class UseUnitController extends BaseController {
EquipFeignService equipFeignService;
@Autowired
FeignService feignService;
AmosFeignService amosFeignService;
/**
* 新增使用单位
......@@ -127,7 +127,7 @@ public class UseUnitController extends BaseController {
@PathVariable(value = "dictCode") String dictCode) {
ResponseModel<Object> result = new ResponseModel<>();
try {
result = ResponseHelper.buildResponse(feignService.listDictionaryByDictCode(dictCode));
result = ResponseHelper.buildResponse(amosFeignService.listDictionaryByDictCode(dictCode));
} catch (Exception e) {
e.printStackTrace();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment