Commit 115abd61 authored by 梁光意's avatar 梁光意

修改RestTemplateUtils方法

parent 32e82fcb
......@@ -30,4 +30,9 @@ public final class SlmConstants {
*/
public static final Integer DATA_DELETED = -1;
/**
* 请求头token的key名称
*/
public static final String TOKEN_PREFIX = "X-Token";
}
......@@ -20,14 +20,12 @@
package com.syc.slm.common.core.util;
import com.syc.slm.common.core.constant.CommonConstants;
import com.syc.slm.common.core.constant.SlmConstants;
import com.syc.slm.slmbi.exception.SysException;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import lombok.experimental.Accessors;
import javax.sound.midi.SysexMessage;
import java.io.Serializable;
/**
......
......@@ -31,7 +31,6 @@ import java.util.function.Supplier;
* @date : 2021-04-06 09:09
**/
@Slf4j
public class BaseRestController {
@Value("${dc_client.host}")
......@@ -73,7 +72,7 @@ public class BaseRestController {
}
}
log.info("请求头参数--->>>>"+SlmConstants.gson.toJson(headers));
String token=request.getHeader("X-Token");
String token=request.getHeader(SlmConstants.TOKEN_PREFIX);
if(!uri.contains("tokens")) {
if (StringUtils.isEmpty(token)) {
throw new SysException("token不能为空");
......@@ -81,13 +80,10 @@ public class BaseRestController {
log.info("获取用户信息");
NativeWebRequest webRequest = new ServletWebRequest(request);
Map<String, String> map = (Map<String, String>) webRequest.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST);
// Map<String, Object> map = (Map<String, Object>) webRequest.getAttribute(View.PATH_VARIABLES, RequestAttributes.SCOPE_REQUEST);
Map<String,String> heads = Maps.newHashMap();
heads.put("X-Token",token);
Map<String,String> uriVariables =Maps.newHashMap();
uriVariables.put("appId",map.get("appId")+"");
String getUrl =dcClientHost+"/{appId}/users/user-info";
R<CurrentUser> result = RestTemplateUtils.get(getUrl, heads, new TypeToken<R<CurrentUser>>() {
R<CurrentUser> result = RestTemplateUtils.get(getUrl, token, new TypeToken<R<CurrentUser>>() {
}.getType(), uriVariables);
request.getSession().setAttribute(token, SlmConstants.gson.toJson(result.detach()));
}
......@@ -103,7 +99,7 @@ public class BaseRestController {
}
protected CurrentUser getCurrentUser (HttpServletRequest request){
String token=request.getHeader("X-Token");
String token=request.getHeader(SlmConstants.TOKEN_PREFIX);
return SlmConstants.gson.fromJson(request.getSession().getAttribute(token).toString(),CurrentUser.class);
}
}
......@@ -2,6 +2,7 @@ package com.syc.slm.slmbi.service.impl;
import com.google.common.collect.Maps;
import com.google.gson.reflect.TypeToken;
import com.syc.slm.common.core.constant.SlmConstants;
import com.syc.slm.common.core.util.R;
import com.syc.slm.common.core.util.RestTemplateUtils;
import com.syc.slm.slmbi.service.DeptService;
......@@ -28,13 +29,11 @@ public class DeptServiceImpl implements DeptService {
public List<DeptVo> selectPositionList(String uri, String token, String appId, String deptName) {
log.info("部门查询uri:---------------->"+uri);
log.info("部门查询token:---------------->"+token);
Map<String,String> heads = Maps.newHashMap();
heads.put("X-Token",token);
Map<String,String> uriVariables =Maps.newHashMap();
uriVariables.put("deptName",deptName);
uriVariables.put("appId",appId);
R<List<DeptVo>> result = RestTemplateUtils.get(uri, heads, new TypeToken<R<List<DeptVo>>>() {}.getType(), uriVariables);
R<List<DeptVo>> result = RestTemplateUtils.get(uri, token, new TypeToken<R<List<DeptVo>>>() {}.getType(), uriVariables);
return result.detach();
}
}
......@@ -415,11 +415,9 @@ public class InstrumentPanelTreeServiceImpl extends ServiceImpl<InstrumentPanelT
private R<Map<String,String>> setDeptAndRole(CurrentUser user,String uri){
Map<String,String> heads = Maps.newHashMap();
heads.put("X-Token",user.getToken());
Map<String,String> uriVariables =Maps.newHashMap();
uriVariables.put("appId",user.getAppId());
return RestTemplateUtils.get(uri, heads, new TypeToken<R<Map<String,String>>>() {}.getType(), uriVariables);
return RestTemplateUtils.get(uri, user.getToken(), new TypeToken<R<Map<String,String>>>() {}.getType(), uriVariables);
}
}
......@@ -27,13 +27,11 @@ public class PositionServiceImpl implements PositionService {
@Override
public List<PositionVo> selectPositionList(String uri ,String token,String appId,String name) {
Map<String,String> heads = Maps.newHashMap();
heads.put("X-Token",token);
Map<String,String> uriVariables =Maps.newHashMap();
uriVariables.put("positionName",name);
uriVariables.put("appId",appId);
R<List<PositionVo>> result = RestTemplateUtils.get(uri, heads, new TypeToken<R<List<PositionVo>>>() {}.getType(), uriVariables);
R<List<PositionVo>> result = RestTemplateUtils.get(uri, token, new TypeToken<R<List<PositionVo>>>() {}.getType(), uriVariables);
return result.detach();
}
}
......@@ -26,12 +26,10 @@ import java.util.Map;
public class UserServiceImpl implements UserService {
@Override
public List<UserTreeVo> selectUserList(String appId,String uri,String token,String userName) {
Map<String,String> heads = Maps.newHashMap();
heads.put("X-Token",token);
Map<String,String> uriVariables =Maps.newHashMap();
uriVariables.put("userName",userName);
uriVariables.put("appId",appId);
R<List<UserTreeVo>> result = RestTemplateUtils.get(uri, heads, new TypeToken<R<List<UserTreeVo>>>() {}.getType(), uriVariables);
R<List<UserTreeVo>> result = RestTemplateUtils.get(uri, token, new TypeToken<R<List<UserTreeVo>>>() {}.getType(), uriVariables);
return result.detach();
}
}
......@@ -47,10 +47,8 @@ public class VariableServiceImpl implements VariableService {
p.put("isCustomer",null);
p.put("current",variableDTO.getCurrent()+"");
p.put("size",variableDTO.getSize()+"");
Map<String,String> heads = Maps.newHashMap();
heads.put("X-Token",token);
R<Map<String, Object>> result = RestTemplateUtils.get(uri, heads, new TypeToken<R<Map<String, Object>>>() {
R<Map<String, Object>> result = RestTemplateUtils.get(uri, token, new TypeToken<R<Map<String, Object>>>() {
}.getType(), p);
Map<String, Object> detach = result.detach();
if (CollectionUtils.isNotEmpty(detach)) {
......@@ -98,9 +96,7 @@ public class VariableServiceImpl implements VariableService {
p.put("warranty_status", null);
p.put("page_num", queryPageDTO.getCurrent() + "");
p.put("page_size", queryPageDTO.getSize() + "");
Map<String, String> heads = Maps.newHashMap();
heads.put("X-Token", token);
R<Map<String, Object>> result = RestTemplateUtils.get(uri, heads, new TypeToken<R<Map<String, Object>>>() {
R<Map<String, Object>> result = RestTemplateUtils.get(uri, token, new TypeToken<R<Map<String, Object>>>() {
}.getType(), p);
Map<String, Object> detach = result.detach();
if (CollectionUtils.isNotEmpty(detach)) {
......
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