Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jz-dmp-service
Project
Project
Details
Activity
Releases
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
姚本章
jz-dmp-service
Commits
0d912774
Commit
0d912774
authored
Jan 26, 2021
by
mcb
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dmp_dev' of
http://gitlab.ioubuy.cn/yaobenzhang/jz-dmp-service
into dmp_dev
parents
b0153f6f
31c5d53d
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
314 additions
and
1 deletion
+314
-1
ResubmitCheck.java
src/main/java/com/jz/common/annotation/ResubmitCheck.java
+19
-0
CommConstant.java
src/main/java/com/jz/common/constant/CommConstant.java
+4
-0
ResubmitCheckInterceptor.java
...a/com/jz/common/interceptor/ResubmitCheckInterceptor.java
+71
-0
CommonUtils.java
src/main/java/com/jz/common/utils/CommonUtils.java
+40
-0
HttpRequestUtil.java
src/main/java/com/jz/common/utils/HttpRequestUtil.java
+66
-0
WebAppConfig.java
src/main/java/com/jz/dmp/config/WebAppConfig.java
+2
-0
DmpMemberController.java
...om/jz/dmp/modules/controller/sys/DmpMemberController.java
+0
-1
SystemCommonController.java
...jz/dmp/modules/controller/sys/SystemCommonController.java
+49
-0
SystemCommonService.java
...a/com/jz/dmp/modules/service/sys/SystemCommonService.java
+27
-0
SystemCommonServiceImpl.java
...dmp/modules/service/sys/impl/SystemCommonServiceImpl.java
+36
-0
No files found.
src/main/java/com/jz/common/annotation/ResubmitCheck.java
0 → 100644
View file @
0d912774
package
com
.
jz
.
common
.
annotation
;
import
java.lang.annotation.ElementType
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.RetentionPolicy
;
import
java.lang.annotation.Target
;
/**
* @ClassName: ResubmitCheck
* @Description: TODO(校验重复提交)
* @author ybz
* @date 2021年1月21日
*
*/
@Target
({
ElementType
.
METHOD
})
@Retention
(
RetentionPolicy
.
RUNTIME
)
public
@interface
ResubmitCheck
{
}
src/main/java/com/jz/common/constant/CommConstant.java
View file @
0d912774
...
...
@@ -28,5 +28,9 @@ public class CommConstant {
public
static
final
String
TRACE_ID
=
"traceId"
;
/***************************************************/
//重复提交校验token
public
static
final
String
RE_SUBMIT_TOKEN
=
"resubmitToken"
;
/***************************************************/
}
src/main/java/com/jz/common/interceptor/ResubmitCheckInterceptor.java
0 → 100644
View file @
0d912774
package
com
.
jz
.
common
.
interceptor
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpSession
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.web.method.HandlerMethod
;
import
org.springframework.web.servlet.HandlerInterceptor
;
import
org.springframework.web.servlet.ModelAndView
;
import
com.alibaba.fastjson.JSONObject
;
import
com.jz.common.annotation.ResubmitCheck
;
import
com.jz.common.bean.BaseResponse
;
import
com.jz.common.constant.CommConstant
;
import
com.jz.common.constant.StatuConstant
;
/**
* @ClassName: LogInterceptor
* @Description: TODO(重复提交校验)
* @author ybz
* @date 2021年1月25日
*
*/
public
class
ResubmitCheckInterceptor
implements
HandlerInterceptor
{
@Override
public
boolean
preHandle
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Object
handler
)
throws
Exception
{
HandlerMethod
handlerMethod
=
(
HandlerMethod
)
handler
;
ResubmitCheck
resubmitCheck
=
handlerMethod
.
getMethod
().
getAnnotation
(
ResubmitCheck
.
class
);
if
(
resubmitCheck
!=
null
)
{
//判断是否需要进行重复提交校验
String
resubmitToken
=
request
.
getHeader
(
CommConstant
.
RE_SUBMIT_TOKEN
);
if
(
resubmitToken
==
null
)
{
resubmitToken
=
request
.
getParameter
(
CommConstant
.
RE_SUBMIT_TOKEN
);
}
if
(
StringUtils
.
isEmpty
(
resubmitToken
))
{
//没有上传校验token
BaseResponse
baseResponse
=
new
BaseResponse
();
baseResponse
.
setCode
(
StatuConstant
.
CODE_ERROR_PARAMETER
);
baseResponse
.
setMessage
(
"重复提交校验token不能为空!"
);
response
.
getWriter
().
write
(
JSONObject
.
toJSONString
(
baseResponse
));
return
false
;
}
HttpSession
session
=
request
.
getSession
();
String
resubmitTokenSession
=
(
String
)
session
.
getAttribute
(
CommConstant
.
RE_SUBMIT_TOKEN
);
if
(!
resubmitToken
.
equals
(
resubmitTokenSession
))
{
//判断是否重复提交
BaseResponse
baseResponse
=
new
BaseResponse
();
baseResponse
.
setCode
(
StatuConstant
.
FAILURE_CODE
);
baseResponse
.
setMessage
(
"重复提交!"
);
response
.
getWriter
().
write
(
JSONObject
.
toJSONString
(
baseResponse
));
return
false
;
}
//校验通过,置空token
session
.
setAttribute
(
CommConstant
.
RE_SUBMIT_TOKEN
,
null
);
}
return
true
;
}
@Override
public
void
postHandle
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Object
handler
,
ModelAndView
modelAndView
)
throws
Exception
{
}
@Override
public
void
afterCompletion
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Object
handler
,
Exception
ex
)
throws
Exception
{
}
}
src/main/java/com/jz/common/utils/CommonUtils.java
0 → 100644
View file @
0d912774
package
com
.
jz
.
common
.
utils
;
import
java.util.UUID
;
public
class
CommonUtils
{
/**
* UUID随机数
* @return
*/
public
static
String
generatePrimaryKeyId
()
{
String
id
=
UUID
.
randomUUID
().
toString
().
toUpperCase
().
replaceAll
(
"-"
,
""
);
return
id
;
}
/**
* @Title: generateTraceId
* @Description: TODO(生成traceId)
* @param @return 参数
* @return String 返回类型
* @throws
*/
public
static
String
generateTraceId
()
{
String
traceId
=
UUID
.
randomUUID
().
toString
().
toUpperCase
().
replaceAll
(
"-"
,
""
);
return
traceId
;
}
/**
* @Title: generateUuid
* @Description: TODO(生成uuid)
* @param @return 参数
* @return String 返回类型
* @throws
*/
public
static
String
generateUuid
()
{
String
uuid
=
UUID
.
randomUUID
().
toString
().
toUpperCase
().
replaceAll
(
"-"
,
""
);
return
uuid
;
}
}
src/main/java/com/jz/common/utils/HttpRequestUtil.java
0 → 100644
View file @
0d912774
package
com
.
jz
.
common
.
utils
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpSession
;
import
com.jz.common.constant.CommConstant
;
/**
*
* @author hack2003
* @date 2016-8-11
* @version v1.0
*
*/
public
class
HttpRequestUtil
{
/**
* 获取有nginx代理的真实地址IP
*
* @param request
* @return
* @throws Exception
*/
public
static
String
getNginxRealIp
(
HttpServletRequest
request
)
throws
Exception
{
String
ip
=
request
.
getHeader
(
"X-Forwarded-For"
);
if
(!
org
.
springframework
.
util
.
StringUtils
.
isEmpty
(
ip
)
&&
!
"unKnown"
.
equalsIgnoreCase
(
ip
))
{
// 多次反向代理后会有多个ip值,第一个ip才是真实ip
int
index
=
ip
.
indexOf
(
","
);
if
(
index
!=
-
1
)
{
return
ip
.
substring
(
0
,
index
);
}
else
{
return
ip
;
}
}
ip
=
request
.
getHeader
(
"X-Real-IP"
);
// 需要在代理服务器上配置该属性
if
(!
org
.
springframework
.
util
.
StringUtils
.
isEmpty
(
ip
)
&&
!
"unKnown"
.
equalsIgnoreCase
(
ip
))
{
return
ip
;
}
return
request
.
getRemoteAddr
();
}
/**
* 根据httpRequest获取url地址
*
* @param httpRequest
* @return
*/
public
static
String
getRequestUrl
(
HttpServletRequest
httpRequest
)
{
StringBuffer
url
=
httpRequest
.
getRequestURL
();
return
url
.
toString
();
}
/**
* @Title: getResubmitToken
* @Description: TODO(获取并设置重复提交判断token)
* @param @param request
* @param @return 参数
* @return String 返回类型
* @throws
*/
public
static
String
getResubmitToken
(
HttpServletRequest
request
)
{
HttpSession
sesson
=
request
.
getSession
();
String
uuid
=
CommonUtils
.
generateUuid
();
sesson
.
setAttribute
(
CommConstant
.
RE_SUBMIT_TOKEN
,
uuid
);
return
uuid
;
}
}
src/main/java/com/jz/dmp/config/WebAppConfig.java
View file @
0d912774
...
...
@@ -5,6 +5,7 @@ import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurer
;
import
com.jz.common.interceptor.LogInterceptor
;
import
com.jz.common.interceptor.ResubmitCheckInterceptor
;
/**
* @ClassName: WebAppConfig
...
...
@@ -22,6 +23,7 @@ public class WebAppConfig implements WebMvcConfigurer {
@Override
public
void
addInterceptors
(
InterceptorRegistry
registry
)
{
registry
.
addInterceptor
(
new
LogInterceptor
());
registry
.
addInterceptor
(
new
ResubmitCheckInterceptor
());
}
}
src/main/java/com/jz/dmp/modules/controller/sys/DmpMemberController.java
View file @
0d912774
...
...
@@ -16,7 +16,6 @@ import org.springframework.web.bind.annotation.RestController;
import
com.jz.common.bean.BaseBeanResponse
;
import
com.jz.common.bean.BaseResponse
;
import
com.jz.common.bean.PageInfoResponse
;
import
com.jz.common.constant.ResultCode
;
import
com.jz.common.constant.StatuConstant
;
import
com.jz.dmp.modules.controller.sys.bean.DmpMemberBatch
;
...
...
src/main/java/com/jz/dmp/modules/controller/sys/SystemCommonController.java
0 → 100644
View file @
0d912774
package
com
.
jz
.
dmp
.
modules
.
controller
.
sys
;
import
javax.servlet.http.HttpServletRequest
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RestController
;
import
com.jz.common.bean.BaseBeanResponse
;
import
com.jz.common.constant.StatuConstant
;
import
com.jz.dmp.modules.service.sys.SystemCommonService
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
/**
* 系统公共服务
* @author ybz
*
*/
@RestController
@RequestMapping
(
"/sys/common"
)
@Api
(
tags
=
"系统公共服务"
)
public
class
SystemCommonController
{
@Autowired
private
SystemCommonService
systemCommonService
;
/**获取防止重复提交token
* @param dmpMemberRequest
* @return
*/
@RequestMapping
(
method
=
RequestMethod
.
GET
,
value
=
"/getResubmitToken"
)
@ApiOperation
(
value
=
"获取防止重复提交token"
,
notes
=
"获取防止重复提交token"
)
public
BaseBeanResponse
<
String
>
getResubmitToken
(
HttpServletRequest
httpRequest
){
BaseBeanResponse
<
String
>
baseBeanResponse
=
new
BaseBeanResponse
<
String
>();
try
{
baseBeanResponse
=
systemCommonService
.
getResubmitToken
(
httpRequest
);
}
catch
(
Exception
e
)
{
baseBeanResponse
.
setMessage
(
"获取失败"
);
baseBeanResponse
.
setCode
(
StatuConstant
.
FAILURE_CODE
);
e
.
printStackTrace
();
}
return
baseBeanResponse
;
}
}
src/main/java/com/jz/dmp/modules/service/sys/SystemCommonService.java
0 → 100644
View file @
0d912774
package
com
.
jz
.
dmp
.
modules
.
service
.
sys
;
import
javax.servlet.http.HttpServletRequest
;
import
com.jz.common.bean.BaseBeanResponse
;
/**
* @ClassName: SystemCommonService
* @Description: TODO(系统公共服务service)
* @author ybz
* @date 2021年1月25日
*
*/
public
interface
SystemCommonService
{
/**
* @Title: getResubmitToken
* @Description: TODO(获取重复提交校验token)
* @param @param httpRequest
* @param @return
* @param @throws Exception 参数
* @return BaseBeanResponse<String> 返回类型
* @throws
*/
public
BaseBeanResponse
<
String
>
getResubmitToken
(
HttpServletRequest
httpRequest
)
throws
Exception
;
}
src/main/java/com/jz/dmp/modules/service/sys/impl/SystemCommonServiceImpl.java
0 → 100644
View file @
0d912774
package
com
.
jz
.
dmp
.
modules
.
service
.
sys
.
impl
;
import
javax.servlet.http.HttpServletRequest
;
import
org.springframework.stereotype.Service
;
import
com.jz.common.bean.BaseBeanResponse
;
import
com.jz.common.constant.StatuConstant
;
import
com.jz.common.utils.HttpRequestUtil
;
import
com.jz.dmp.modules.service.sys.SystemCommonService
;
/**
* @ClassName: SystemCommonServiceImpl
* @Description: TODO(公共服务实现类)
* @author ybz
* @date 2021年1月25日
*
*/
@Service
public
class
SystemCommonServiceImpl
implements
SystemCommonService
{
/**
*获取重复提交校验token
*/
@Override
public
BaseBeanResponse
<
String
>
getResubmitToken
(
HttpServletRequest
httpRequest
)
throws
Exception
{
BaseBeanResponse
<
String
>
baseBeanResponse
=
new
BaseBeanResponse
<
String
>();
String
resubmitToken
=
HttpRequestUtil
.
getResubmitToken
(
httpRequest
);
baseBeanResponse
.
setCode
(
StatuConstant
.
SUCCESS_CODE
);
baseBeanResponse
.
setMessage
(
"获取成功"
);
baseBeanResponse
.
setData
(
resubmitToken
);
return
baseBeanResponse
;
}
}
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