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
9383f254
Commit
9383f254
authored
Apr 17, 2021
by
linruibiao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
接口编写
parent
73362b87
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
115 additions
and
0 deletions
+115
-0
ServletUtils.java
src/main/java/com/syc/slm/common/core/util/ServletUtils.java
+46
-0
CurrentUser.java
src/main/java/com/syc/slm/slmbi/entity/CurrentUser.java
+18
-0
Function2.java
src/main/java/com/syc/slm/slmbi/function/Function2.java
+16
-0
SysExceptionHandler.java
...n/java/com/syc/slm/slmbi/handler/SysExceptionHandler.java
+35
-0
No files found.
src/main/java/com/syc/slm/common/core/util/ServletUtils.java
0 → 100644
View file @
9383f254
package
com
.
syc
.
slm
.
common
.
core
.
util
;
import
com.google.common.collect.Maps
;
import
com.syc.slm.slmbi.exception.SysException
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.web.context.request.RequestAttributes
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
org.springframework.web.context.request.ServletRequestAttributes
;
import
javax.servlet.http.HttpServletRequest
;
import
java.util.Enumeration
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* slm-bi
* ServletUtils 工具类
* @author : lin
* @date : 2021-04-13 10:15
**/
public
final
class
ServletUtils
{
/**
* 获取HttpServletRequest
* @return request
*/
public
static
HttpServletRequest
getHttpServletRequest
()
{
RequestAttributes
attr
=
RequestContextHolder
.
getRequestAttributes
();
if
(
attr
==
null
)
{
throw
new
SysException
(
"无法提取 request"
);
}
return
((
ServletRequestAttributes
)
attr
).
getRequest
();
}
public
static
Map
<
String
,
String
>
getHeaderMap
(
HttpServletRequest
request
){
Map
<
String
,
String
>
result
=
Maps
.
newHashMap
();
Enumeration
<
String
>
names
=
request
.
getHeaderNames
();
String
name
;
while
(
names
.
hasMoreElements
()){
name
=
names
.
nextElement
();
String
val
=
request
.
getHeader
(
name
);
if
(
StringUtils
.
isNotEmpty
(
val
))
{
result
.
put
(
name
,
val
);
}
}
return
result
;
}
}
src/main/java/com/syc/slm/slmbi/entity/CurrentUser.java
0 → 100644
View file @
9383f254
package
com
.
syc
.
slm
.
slmbi
.
entity
;
import
lombok.Data
;
/**
* slm-bi
* 当前用户
* @author : lin
* @date : 2021-04-16 18:30
**/
@Data
public
class
CurrentUser
{
private
String
uid
;
private
String
appId
;
private
String
platformId
;
private
String
name
;
private
String
token
;
}
src/main/java/com/syc/slm/slmbi/function/Function2.java
0 → 100644
View file @
9383f254
package
com
.
syc
.
slm
.
slmbi
.
function
;
import
java.io.Serializable
;
/**
* @author lin
* @date 2021/4/1
*/
public
interface
Function2
<
T1
,
T2
,
R
>
extends
Serializable
{
R
get
(
T1
t1
,
T2
t2
);
@SafeVarargs
static
<
T1
,
T2
>
Function2
<
T1
,
T2
,?>[]
of
(
Function2
<
T1
,
T2
,?>...
funcs
){
return
funcs
;
}
}
src/main/java/com/syc/slm/slmbi/handler/SysExceptionHandler.java
0 → 100644
View file @
9383f254
package
com
.
syc
.
slm
.
slmbi
.
handler
;
import
com.syc.slm.common.core.util.R
;
import
com.syc.slm.slmbi.exception.SysException
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.web.bind.annotation.ControllerAdvice
;
import
org.springframework.web.bind.annotation.ExceptionHandler
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
javax.servlet.http.HttpServletRequest
;
/**
* slm-bi
* 全局业务异常处理
* @author : lin
* @date : 2021-04-16 17:34
**/
@ControllerAdvice
@Slf4j
public
class
SysExceptionHandler
{
/**
* 业务异常
*
* @param e exception
* @return exception
*/
@ExceptionHandler
(
SysException
.
class
)
@ResponseBody
public
R
<
Object
>
handleSysException
(
SysException
e
,
HttpServletRequest
request
)
{
log
.
info
(
e
.
getMsg
());
return
R
.
bad
(
e
.
getMsg
(),
e
.
getDebugMsg
());
}
}
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