Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
slm-bi
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
林锐标
slm-bi
Commits
92f3119d
Commit
92f3119d
authored
Apr 22, 2021
by
梁光意
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改RestTemplateUtils通过RequestContextHolder获取token
parent
ba944255
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
24 additions
and
12 deletions
+24
-12
RestTemplateUtils.java
.../java/com/syc/slm/common/core/util/RestTemplateUtils.java
+15
-1
SysMetaObjectHandler.java
...n/java/com/syc/slm/slmbi/config/SysMetaObjectHandler.java
+1
-1
BaseRestController.java
...java/com/syc/slm/slmbi/controller/BaseRestController.java
+1
-1
DeptServiceImpl.java
.../java/com/syc/slm/slmbi/service/impl/DeptServiceImpl.java
+1
-1
InstrumentPanelTreeServiceImpl.java
...lm/slmbi/service/impl/InstrumentPanelTreeServiceImpl.java
+1
-1
PositionServiceImpl.java
...a/com/syc/slm/slmbi/service/impl/PositionServiceImpl.java
+1
-1
UserServiceImpl.java
.../java/com/syc/slm/slmbi/service/impl/UserServiceImpl.java
+1
-1
VariableServiceImpl.java
...a/com/syc/slm/slmbi/service/impl/VariableServiceImpl.java
+3
-5
No files found.
src/main/java/com/syc/slm/common/core/util/RestTemplateUtils.java
View file @
92f3119d
package
com
.
syc
.
slm
.
common
.
core
.
util
;
package
com
.
syc
.
slm
.
common
.
core
.
util
;
import
com.baomidou.mybatisplus.core.toolkit.CollectionUtils
;
import
com.baomidou.mybatisplus.core.toolkit.StringUtils
;
import
com.google.common.collect.Maps
;
import
com.google.common.collect.Maps
;
import
com.syc.slm.common.core.constant.SlmConstants
;
import
com.syc.slm.common.core.constant.SlmConstants
;
import
com.syc.slm.slmbi.exception.SysException
;
import
com.syc.slm.slmbi.exception.SysException
;
...
@@ -7,6 +9,7 @@ import lombok.extern.slf4j.Slf4j;
...
@@ -7,6 +9,7 @@ import lombok.extern.slf4j.Slf4j;
import
org.springframework.http.*
;
import
org.springframework.http.*
;
import
org.springframework.web.client.RestTemplate
;
import
org.springframework.web.client.RestTemplate
;
import
javax.servlet.http.HttpServletRequest
;
import
java.lang.reflect.Type
;
import
java.lang.reflect.Type
;
import
java.util.Map
;
import
java.util.Map
;
...
@@ -40,8 +43,19 @@ public final class RestTemplateUtils {
...
@@ -40,8 +43,19 @@ public final class RestTemplateUtils {
// }
// }
public
static
<
TResult
>
TResult
get
(
String
url
,
String
token
,
final
Type
resultType
,
Map
<
String
,
?>
uriVariables
)
{
public
static
<
TResult
>
TResult
get
(
String
url
,
final
Type
resultType
,
Map
<
String
,
?>
uriVariables
)
{
try
{
try
{
// 获取token以及在请求头加上token
HttpServletRequest
request
=
ServletUtils
.
getHttpServletRequest
();
Map
<
String
,
String
>
headerMap
=
ServletUtils
.
getHeaderMap
(
request
);
if
(
CollectionUtils
.
isEmpty
(
headerMap
)){
throw
new
SysException
(
"头部不能为空"
);
}
String
token
=
request
.
getHeader
(
SlmConstants
.
TOKEN_PREFIX
);
if
(
StringUtils
.
isBlank
(
token
)){
throw
new
SysException
(
"token不能为空"
);
}
Map
<
String
,
String
>
headMap
=
Maps
.
newHashMap
();
Map
<
String
,
String
>
headMap
=
Maps
.
newHashMap
();
headMap
.
put
(
SlmConstants
.
TOKEN_PREFIX
,
token
);
headMap
.
put
(
SlmConstants
.
TOKEN_PREFIX
,
token
);
ResponseEntity
<
String
>
response
=
get
(
url
,
headMap
,
String
.
class
,
uriVariables
);
ResponseEntity
<
String
>
response
=
get
(
url
,
headMap
,
String
.
class
,
uriVariables
);
...
...
src/main/java/com/syc/slm/slmbi/config/SysMetaObjectHandler.java
View file @
92f3119d
...
@@ -44,7 +44,7 @@ public class SysMetaObjectHandler implements MetaObjectHandler {
...
@@ -44,7 +44,7 @@ public class SysMetaObjectHandler implements MetaObjectHandler {
if
(
CollectionUtils
.
isEmpty
(
headerMap
)){
if
(
CollectionUtils
.
isEmpty
(
headerMap
)){
throw
new
SysException
(
"头部不能为空"
);
throw
new
SysException
(
"头部不能为空"
);
}
}
String
token
=
request
.
getHeader
(
"X-Token"
);
String
token
=
request
.
getHeader
(
SlmConstants
.
TOKEN_PREFIX
);
if
(
StringUtils
.
isBlank
(
token
)){
if
(
StringUtils
.
isBlank
(
token
)){
throw
new
SysException
(
"token不能为空"
);
throw
new
SysException
(
"token不能为空"
);
}
}
...
...
src/main/java/com/syc/slm/slmbi/controller/BaseRestController.java
View file @
92f3119d
...
@@ -83,7 +83,7 @@ public class BaseRestController {
...
@@ -83,7 +83,7 @@ public class BaseRestController {
Map
<
String
,
String
>
uriVariables
=
Maps
.
newHashMap
();
Map
<
String
,
String
>
uriVariables
=
Maps
.
newHashMap
();
uriVariables
.
put
(
"appId"
,
map
.
get
(
"appId"
)+
""
);
uriVariables
.
put
(
"appId"
,
map
.
get
(
"appId"
)+
""
);
String
getUrl
=
dcClientHost
+
"/{appId}/users/user-info"
;
String
getUrl
=
dcClientHost
+
"/{appId}/users/user-info"
;
R
<
CurrentUser
>
result
=
RestTemplateUtils
.
get
(
getUrl
,
token
,
new
TypeToken
<
R
<
CurrentUser
>>()
{
R
<
CurrentUser
>
result
=
RestTemplateUtils
.
get
(
getUrl
,
new
TypeToken
<
R
<
CurrentUser
>>()
{
}.
getType
(),
uriVariables
);
}.
getType
(),
uriVariables
);
request
.
getSession
().
setAttribute
(
token
,
SlmConstants
.
gson
.
toJson
(
result
.
detach
()));
request
.
getSession
().
setAttribute
(
token
,
SlmConstants
.
gson
.
toJson
(
result
.
detach
()));
}
}
...
...
src/main/java/com/syc/slm/slmbi/service/impl/DeptServiceImpl.java
View file @
92f3119d
...
@@ -33,7 +33,7 @@ public class DeptServiceImpl implements DeptService {
...
@@ -33,7 +33,7 @@ public class DeptServiceImpl implements DeptService {
uriVariables
.
put
(
"deptName"
,
deptName
);
uriVariables
.
put
(
"deptName"
,
deptName
);
uriVariables
.
put
(
"appId"
,
appId
);
uriVariables
.
put
(
"appId"
,
appId
);
R
<
List
<
DeptVo
>>
result
=
RestTemplateUtils
.
get
(
uri
,
token
,
new
TypeToken
<
R
<
List
<
DeptVo
>>>()
{}.
getType
(),
uriVariables
);
R
<
List
<
DeptVo
>>
result
=
RestTemplateUtils
.
get
(
uri
,
new
TypeToken
<
R
<
List
<
DeptVo
>>>()
{}.
getType
(),
uriVariables
);
return
result
.
detach
();
return
result
.
detach
();
}
}
}
}
src/main/java/com/syc/slm/slmbi/service/impl/InstrumentPanelTreeServiceImpl.java
View file @
92f3119d
...
@@ -417,7 +417,7 @@ public class InstrumentPanelTreeServiceImpl extends ServiceImpl<InstrumentPanelT
...
@@ -417,7 +417,7 @@ public class InstrumentPanelTreeServiceImpl extends ServiceImpl<InstrumentPanelT
private
R
<
Map
<
String
,
String
>>
setDeptAndRole
(
CurrentUser
user
,
String
uri
){
private
R
<
Map
<
String
,
String
>>
setDeptAndRole
(
CurrentUser
user
,
String
uri
){
Map
<
String
,
String
>
uriVariables
=
Maps
.
newHashMap
();
Map
<
String
,
String
>
uriVariables
=
Maps
.
newHashMap
();
uriVariables
.
put
(
"appId"
,
user
.
getAppId
());
uriVariables
.
put
(
"appId"
,
user
.
getAppId
());
return
RestTemplateUtils
.
get
(
uri
,
user
.
getToken
(),
new
TypeToken
<
R
<
Map
<
String
,
String
>>>()
{}.
getType
(),
uriVariables
);
return
RestTemplateUtils
.
get
(
uri
,
new
TypeToken
<
R
<
Map
<
String
,
String
>>>()
{}.
getType
(),
uriVariables
);
}
}
}
}
src/main/java/com/syc/slm/slmbi/service/impl/PositionServiceImpl.java
View file @
92f3119d
...
@@ -31,7 +31,7 @@ public class PositionServiceImpl implements PositionService {
...
@@ -31,7 +31,7 @@ public class PositionServiceImpl implements PositionService {
uriVariables
.
put
(
"positionName"
,
name
);
uriVariables
.
put
(
"positionName"
,
name
);
uriVariables
.
put
(
"appId"
,
appId
);
uriVariables
.
put
(
"appId"
,
appId
);
R
<
List
<
PositionVo
>>
result
=
RestTemplateUtils
.
get
(
uri
,
token
,
new
TypeToken
<
R
<
List
<
PositionVo
>>>()
{}.
getType
(),
uriVariables
);
R
<
List
<
PositionVo
>>
result
=
RestTemplateUtils
.
get
(
uri
,
new
TypeToken
<
R
<
List
<
PositionVo
>>>()
{}.
getType
(),
uriVariables
);
return
result
.
detach
();
return
result
.
detach
();
}
}
}
}
src/main/java/com/syc/slm/slmbi/service/impl/UserServiceImpl.java
View file @
92f3119d
...
@@ -29,7 +29,7 @@ public class UserServiceImpl implements UserService {
...
@@ -29,7 +29,7 @@ public class UserServiceImpl implements UserService {
Map
<
String
,
String
>
uriVariables
=
Maps
.
newHashMap
();
Map
<
String
,
String
>
uriVariables
=
Maps
.
newHashMap
();
uriVariables
.
put
(
"userName"
,
userName
);
uriVariables
.
put
(
"userName"
,
userName
);
uriVariables
.
put
(
"appId"
,
appId
);
uriVariables
.
put
(
"appId"
,
appId
);
R
<
List
<
UserTreeVo
>>
result
=
RestTemplateUtils
.
get
(
uri
,
token
,
new
TypeToken
<
R
<
List
<
UserTreeVo
>>>()
{}.
getType
(),
uriVariables
);
R
<
List
<
UserTreeVo
>>
result
=
RestTemplateUtils
.
get
(
uri
,
new
TypeToken
<
R
<
List
<
UserTreeVo
>>>()
{}.
getType
(),
uriVariables
);
return
result
.
detach
();
return
result
.
detach
();
}
}
}
}
src/main/java/com/syc/slm/slmbi/service/impl/VariableServiceImpl.java
View file @
92f3119d
...
@@ -52,7 +52,7 @@ public class VariableServiceImpl implements VariableService {
...
@@ -52,7 +52,7 @@ public class VariableServiceImpl implements VariableService {
p
.
put
(
"current"
,
variableDTO
.
getCurrent
()+
""
);
p
.
put
(
"current"
,
variableDTO
.
getCurrent
()+
""
);
p
.
put
(
"size"
,
variableDTO
.
getSize
()+
""
);
p
.
put
(
"size"
,
variableDTO
.
getSize
()+
""
);
R
<
Map
<
String
,
Object
>>
result
=
RestTemplateUtils
.
get
(
uri
,
token
,
new
TypeToken
<
R
<
Map
<
String
,
Object
>>>()
{
R
<
Map
<
String
,
Object
>>
result
=
RestTemplateUtils
.
get
(
uri
,
new
TypeToken
<
R
<
Map
<
String
,
Object
>>>()
{
}.
getType
(),
p
);
}.
getType
(),
p
);
Map
<
String
,
Object
>
detach
=
result
.
detach
();
Map
<
String
,
Object
>
detach
=
result
.
detach
();
if
(
CollectionUtils
.
isNotEmpty
(
detach
))
{
if
(
CollectionUtils
.
isNotEmpty
(
detach
))
{
...
@@ -100,7 +100,7 @@ public class VariableServiceImpl implements VariableService {
...
@@ -100,7 +100,7 @@ public class VariableServiceImpl implements VariableService {
p
.
put
(
"warranty_status"
,
null
);
p
.
put
(
"warranty_status"
,
null
);
p
.
put
(
"page_num"
,
queryPageDTO
.
getCurrent
()
+
""
);
p
.
put
(
"page_num"
,
queryPageDTO
.
getCurrent
()
+
""
);
p
.
put
(
"page_size"
,
queryPageDTO
.
getSize
()
+
""
);
p
.
put
(
"page_size"
,
queryPageDTO
.
getSize
()
+
""
);
R
<
Map
<
String
,
Object
>>
result
=
RestTemplateUtils
.
get
(
uri
,
token
,
new
TypeToken
<
R
<
Map
<
String
,
Object
>>>()
{
R
<
Map
<
String
,
Object
>>
result
=
RestTemplateUtils
.
get
(
uri
,
new
TypeToken
<
R
<
Map
<
String
,
Object
>>>()
{
}.
getType
(),
p
);
}.
getType
(),
p
);
Map
<
String
,
Object
>
detach
=
result
.
detach
();
Map
<
String
,
Object
>
detach
=
result
.
detach
();
if
(
CollectionUtils
.
isNotEmpty
(
detach
))
{
if
(
CollectionUtils
.
isNotEmpty
(
detach
))
{
...
@@ -189,11 +189,9 @@ public class VariableServiceImpl implements VariableService {
...
@@ -189,11 +189,9 @@ public class VariableServiceImpl implements VariableService {
}
}
private
R
<
Map
<
String
,
String
>>
setDeptAndRole
(
CurrentUser
user
,
String
uri
){
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
();
Map
<
String
,
String
>
uriVariables
=
Maps
.
newHashMap
();
uriVariables
.
put
(
"appId"
,
user
.
getAppId
());
uriVariables
.
put
(
"appId"
,
user
.
getAppId
());
return
RestTemplateUtils
.
get
(
uri
,
heads
,
new
TypeToken
<
R
<
Map
<
String
,
String
>>>()
{}.
getType
(),
uriVariables
);
return
RestTemplateUtils
.
get
(
uri
,
new
TypeToken
<
R
<
Map
<
String
,
String
>>>()
{}.
getType
(),
uriVariables
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment