Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
afanti-open-api
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
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
java-ms
afanti-open-api
Commits
d2a56755
Commit
d2a56755
authored
Apr 28, 2023
by
陈炎
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dev-8.9.0' into 'develop'
Dev 8.9.0 See merge request
!9
parents
3399367d
0e98bcdb
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
185 additions
and
13 deletions
+185
-13
GlobalExceptionHandler.java
...fanticar/afantiopenapi/config/GlobalExceptionHandler.java
+46
-0
Constant.java
...n/java/com/afanticar/afantiopenapi/constant/Constant.java
+1
-1
ExceptionEnum.java
...a/com/afanticar/afantiopenapi/constant/ExceptionEnum.java
+112
-0
CommonDataController.java
...nticar/afantiopenapi/controller/CommonDataController.java
+8
-1
FawOpenController.java
...afanticar/afantiopenapi/controller/FawOpenController.java
+5
-2
BaseService.java
...java/com/afanticar/afantiopenapi/service/BaseService.java
+7
-3
CommonDataService.java
...om/afanticar/afantiopenapi/service/CommonDataService.java
+2
-2
FawOpenService.java
...a/com/afanticar/afantiopenapi/service/FawOpenService.java
+4
-4
No files found.
src/main/java/com/afanticar/afantiopenapi/config/GlobalExceptionHandler.java
0 → 100644
View file @
d2a56755
package
com
.
afanticar
.
afantiopenapi
.
config
;
import
com.afanticar.afantiopenapi.constant.ExceptionEnum
;
import
com.afanticar.afantiopenapi.controller.BaseController
;
import
com.afanticar.afantiopenapi.model.BaseResponse
;
import
org.apache.commons.lang3.exception.ExceptionUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.web.bind.annotation.ExceptionHandler
;
import
org.springframework.web.bind.annotation.RestControllerAdvice
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.validation.ConstraintViolationException
;
import
java.util.StringJoiner
;
@RestControllerAdvice
public
class
GlobalExceptionHandler
{
protected
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
this
.
getClass
());
@ExceptionHandler
(
ConstraintViolationException
.
class
)
public
BaseResponse
processMethodArgumentNotValidException
(
HttpServletResponse
response
,
ConstraintViolationException
e
)
{
StringJoiner
message
=
new
StringJoiner
(
";"
);
e
.
getConstraintViolations
().
forEach
(
constraintViolation
->
message
.
add
(
constraintViolation
.
getMessage
()));
LOGGER
.
error
(
"参数校验异常 => "
,
e
);
return
handleError
(
ExceptionEnum
.
PARAM_INVALID
.
getCode
(),
String
.
join
(
":"
,
ExceptionEnum
.
PARAM_INVALID
.
getMessage
(),
message
.
toString
()),
null
);
}
@ExceptionHandler
(
Exception
.
class
)
public
BaseResponse
processException
(
Exception
e
)
{
LOGGER
.
error
(
"未知异常 => :{}"
,
ExceptionUtils
.
getStackTrace
(
e
));
return
handleError
(
ExceptionEnum
.
ERROR
,
e
);
}
private
BaseResponse
<
Object
>
handleError
(
int
code
,
String
message
,
Exception
ex
)
{
return
BaseController
.
error
(
code
+
""
,
message
);
}
private
BaseResponse
<
Object
>
handleError
(
ExceptionEnum
exceptionEnum
,
Exception
ex
)
{
// 状态码
Integer
code
=
exceptionEnum
.
getCode
();
// 状态码描述
String
message
=
exceptionEnum
.
getMessage
();
return
handleError
(
code
,
message
,
ex
);
}
}
src/main/java/com/afanticar/afantiopenapi/con
fig
/Constant.java
→
src/main/java/com/afanticar/afantiopenapi/con
stant
/Constant.java
View file @
d2a56755
package
com
.
afanticar
.
afantiopenapi
.
con
fig
;
package
com
.
afanticar
.
afantiopenapi
.
con
stant
;
/**
* @author chin
...
...
src/main/java/com/afanticar/afantiopenapi/constant/ExceptionEnum.java
0 → 100644
View file @
d2a56755
package
com
.
afanticar
.
afantiopenapi
.
constant
;
import
lombok.AllArgsConstructor
;
import
lombok.Getter
;
import
lombok.NoArgsConstructor
;
/**
* @author Wsr
* @ClassName ExceptionEnum
* @desc 异常枚举
* @date 2023/01/06 18:59
**/
@AllArgsConstructor
@NoArgsConstructor
public
enum
ExceptionEnum
{
/**
*
*/
USER_ERROR
(
400
,
"用户错误"
),
ERROR
(
500
,
"发生未知异常,请联系管理员"
),
SUCCESS
(
200
,
"成功"
),
PARAM_INVALID
(
90001
,
"请求参数不合法"
),
FLOW_LIMIT_ALL
(
10010
,
"访问过于频繁"
),
// ==================== token ====================
/**
* token 无效 401
*/
TOKEN_INVALID
(
10002
,
"token 无效"
),
/**
* token 过期
*/
TOKEN_EXPIRED
(
10003
,
"token过期"
),
/**
* token 不存在
*/
TOKEN_NOT_EXIST
(
10004
,
"请求头未传递token"
),
// ==================== 限流 ====================
/**
* api限流
*/
API_LIMIT_EXCEEDED
(
20001
,
"api限流"
),
/**
* api-app限流
*/
API_APP_LIMIT_EXCEEDED
(
20002
,
"特殊app限流"
),
/**
* app限流
*/
APP_LIMIT_EXCEEDED
(
20003
,
"app限流"
),
// ==================== 授权 ====================
/**
* app未授权
*/
APP_UNAUTHORIZED
(
30001
,
"app未授权"
),
/**
* app不存在
*/
APP_NOT_EXIST
(
30002
,
"app不存在"
),
// ==================== 超时 ====================
/**
* 接口超时
*/
API_TIMEOUT
(
40001
,
"接口超时"
),
/**
* sql超时
*/
SQL_TIMEOUT
(
40002
,
"sql超时"
),
// ==================== app ====================
/**
* app未注册
*/
APP_UNREGISTERED
(
50001
,
"app未注册"
),
/**
* app密钥错误 业务异常
*/
APP_ERROR_SECRET
(
50002
,
"app密钥错误"
),
// ==================== data ====================
/**
* 字段重复
*/
DUPLICATE_FIELD_ERROR
(
60001
,
"字段重复"
);
@Getter
private
Integer
code
;
@Getter
private
String
message
;
public
static
ExceptionEnum
findExceptionEnumByCode
(
Integer
code
)
{
for
(
ExceptionEnum
exceptionEnum
:
values
())
{
if
(
exceptionEnum
.
code
.
equals
(
code
))
{
return
exceptionEnum
;
}
}
return
null
;
}
}
src/main/java/com/afanticar/afantiopenapi/controller/CommonDataController.java
View file @
d2a56755
...
...
@@ -15,10 +15,12 @@ import io.swagger.annotations.ApiOperation;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.*
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.validation.Valid
;
import
javax.validation.constraints.Max
;
/**
* @author chin
...
...
@@ -29,6 +31,7 @@ import javax.validation.Valid;
@RestController
@RequestMapping
(
"/public"
)
@Slf4j
@Validated
public
class
CommonDataController
extends
BaseController
{
@Autowired
...
...
@@ -54,7 +57,7 @@ public class CommonDataController extends BaseController {
@ApiImplicitParam
(
name
=
"page_size"
,
value
=
"页数"
,
paramType
=
"path"
,
dataType
=
"Integer"
),
})
@GetMapping
(
"/activity"
)
public
BaseResponse
<
BasePageVO
<
ActivityInfoVO
>>
getActionData
(
HttpServletRequest
request
,
@RequestParam
(
name
=
"page_size"
,
defaultValue
=
"100"
,
required
=
false
)
Integer
pageSize
,
public
BaseResponse
<
BasePageVO
<
ActivityInfoVO
>>
getActionData
(
HttpServletRequest
request
,
@
Max
(
value
=
500
,
message
=
"单页数据page_size过大"
)
@
RequestParam
(
name
=
"page_size"
,
defaultValue
=
"100"
,
required
=
false
)
Integer
pageSize
,
@RequestParam
(
name
=
"current_page"
,
defaultValue
=
"1"
,
required
=
false
)
Integer
pageNum
)
{
BaseResponse
check
=
baseService
.
baseLimit
(
request
,
dateType
,
limit
,
limitPeriod
);
if
(
check
!=
null
)
{
...
...
@@ -67,6 +70,10 @@ public class CommonDataController extends BaseController {
@ApiOperation
(
value
=
"获取token"
,
notes
=
"token数据"
,
produces
=
"application/json"
)
@PostMapping
(
"/token"
)
public
BaseResponse
<
TokenVO
>
getToken
(
@RequestBody
@Valid
TokenDTO
dto
)
{
BaseResponse
check
=
baseService
.
baseLimit
(
null
,
dateType
,
limit
,
limitPeriod
);
if
(
check
!=
null
)
{
return
check
;
}
TokenVO
vo
=
commonDataService
.
token
(
dto
);
if
(
vo
==
null
)
{
return
error
();
...
...
src/main/java/com/afanticar/afantiopenapi/controller/FawOpenController.java
View file @
d2a56755
...
...
@@ -14,12 +14,14 @@ import lombok.extern.slf4j.Slf4j;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.format.annotation.DateTimeFormat
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.validation.constraints.Max
;
import
java.util.Date
;
/**
...
...
@@ -31,6 +33,7 @@ import java.util.Date;
@RestController
@RequestMapping
(
"/faw"
)
@Slf4j
@Validated
public
class
FawOpenController
extends
BaseController
{
@Autowired
...
...
@@ -59,7 +62,7 @@ public class FawOpenController extends BaseController {
@ApiImplicitParam
(
name
=
"page_size"
,
value
=
"页数"
,
paramType
=
"path"
,
dataType
=
"Integer"
),
})
@GetMapping
(
"/aweme"
)
public
BaseResponse
<
BasePageVO
<
HongqiAwemeIncentiveVO
>>
getAwemeData
(
HttpServletRequest
request
,
@RequestParam
(
name
=
"page_size"
,
defaultValue
=
"100"
,
required
=
false
)
Integer
pageSize
,
public
BaseResponse
<
BasePageVO
<
HongqiAwemeIncentiveVO
>>
getAwemeData
(
HttpServletRequest
request
,
@
Max
(
value
=
500
,
message
=
"单页数据page_size过大"
)
@
RequestParam
(
name
=
"page_size"
,
defaultValue
=
"100"
,
required
=
false
)
Integer
pageSize
,
@RequestParam
(
name
=
"current_page"
,
defaultValue
=
"1"
,
required
=
false
)
Integer
pageNum
,
@RequestParam
(
name
=
"publish_date_start"
)
@DateTimeFormat
(
pattern
=
"yyyy-MM-dd"
)
Date
publishDateStart
,
@RequestParam
(
name
=
"publish_date_end"
)
@DateTimeFormat
(
pattern
=
"yyyy-MM-dd"
)
Date
publishDateEnd
,
...
...
@@ -80,7 +83,7 @@ public class FawOpenController extends BaseController {
@ApiImplicitParam
(
name
=
"page_size"
,
value
=
"页数"
,
paramType
=
"path"
,
dataType
=
"Integer"
),
})
@GetMapping
(
"/live"
)
public
BaseResponse
<
BasePageVO
<
HongqiLiveIncentiveVO
>>
getLiveData
(
HttpServletRequest
request
,
@RequestParam
(
name
=
"page_size"
,
defaultValue
=
"100"
,
required
=
false
)
Integer
pageSize
,
public
BaseResponse
<
BasePageVO
<
HongqiLiveIncentiveVO
>>
getLiveData
(
HttpServletRequest
request
,
@
Max
(
value
=
500
,
message
=
"单页数据page_size过大"
)
@
RequestParam
(
name
=
"page_size"
,
defaultValue
=
"100"
,
required
=
false
)
Integer
pageSize
,
@RequestParam
(
name
=
"current_page"
,
defaultValue
=
"1"
,
required
=
false
)
Integer
pageNum
,
@RequestParam
(
name
=
"publish_date_start"
)
@DateTimeFormat
(
pattern
=
"yyyy-MM-dd"
)
Date
publishDateStart
,
@RequestParam
(
name
=
"publish_date_end"
)
@DateTimeFormat
(
pattern
=
"yyyy-MM-dd"
)
Date
publishDateEnd
,
...
...
src/main/java/com/afanticar/afantiopenapi/service/BaseService.java
View file @
d2a56755
...
...
@@ -33,17 +33,21 @@ public class BaseService {
RRateLimiter
rateLimiter
=
redissonClient
.
getRateLimiter
(
fawKey
);
rateLimiter
.
trySetRate
(
RateType
.
OVERALL
,
limit
,
limitPeriod
,
RateIntervalUnit
.
SECONDS
);
if
(!
rateLimiter
.
tryAcquire
(
1
,
waiting
,
TimeUnit
.
MILLISECONDS
))
{
return
BaseController
.
error
(
"
403
"
,
"您的请求太过频繁,请稍后再试!"
);
return
BaseController
.
error
(
"
10010
"
,
"您的请求太过频繁,请稍后再试!"
);
}
return
null
;
}
public
BaseResponse
baseLimit
(
HttpServletRequest
request
,
String
dataType
,
Integer
limit
,
Integer
limitPeriod
)
{
String
fawKey
=
String
.
format
(
"%s:%s:limit"
,
dataType
,
request
.
getAttribute
(
BaseController
.
header
));
String
header
=
"token"
;
if
(
request
!=
null
)
{
header
=
(
String
)
request
.
getAttribute
(
BaseController
.
header
);
}
String
fawKey
=
String
.
format
(
"%s:%s:limit"
,
dataType
,
header
);
RRateLimiter
rateLimiter
=
redissonClient
.
getRateLimiter
(
fawKey
);
rateLimiter
.
trySetRate
(
RateType
.
OVERALL
,
limit
,
limitPeriod
,
RateIntervalUnit
.
SECONDS
);
if
(!
rateLimiter
.
tryAcquire
(
1
,
waiting
,
TimeUnit
.
MILLISECONDS
))
{
return
BaseController
.
error
(
"
403
"
,
"您的请求太过频繁,请稍后再试!"
);
return
BaseController
.
error
(
"
10010
"
,
"您的请求太过频繁,请稍后再试!"
);
}
return
null
;
}
...
...
src/main/java/com/afanticar/afantiopenapi/service/CommonDataService.java
View file @
d2a56755
package
com
.
afanticar
.
afantiopenapi
.
service
;
import
com.afanticar.afantiopenapi.con
fig
.Constant
;
import
com.afanticar.afantiopenapi.con
stant
.Constant
;
import
com.afanticar.afantiopenapi.feign.AfantiCasFeign
;
import
com.afanticar.afantiopenapi.mapper.ActivityInfoMapper
;
import
com.afanticar.afantiopenapi.mapper.struct.ActivityInfoStructMapper
;
...
...
@@ -45,7 +45,7 @@ public class CommonDataService {
IPage
<
ActivityInfo
>
activityPage
=
activityInfoMapper
.
selectPage
(
page
,
queryWrapper
);
ActivityInfoStructMapper
mapper
=
Mappers
.
getMapper
(
ActivityInfoStructMapper
.
class
);
List
<
ActivityInfoVO
>
vos
=
mapper
.
listActivityInfoToVO
(
activityPage
.
getRecords
());
return
BasePageVO
.
restPage
(
pageNum
,
pageSize
,
(
int
)
activityPage
.
getTotal
(),
(
int
)
activityPage
.
getPages
(),
vos
);
return
BasePageVO
.
restPage
(
pageNum
,
(
int
)
activityPage
.
getSize
()
,
(
int
)
activityPage
.
getTotal
(),
(
int
)
activityPage
.
getPages
(),
vos
);
}
public
TokenVO
token
(
TokenDTO
dto
)
{
...
...
src/main/java/com/afanticar/afantiopenapi/service/FawOpenService.java
View file @
d2a56755
...
...
@@ -57,7 +57,7 @@ public class FawOpenService {
IPage
<
HongqiAwemeIncentiveMonthly
>
awemePage
=
hongqiAwemeIncentiveMonthlyMapper
.
selectPage
(
page
,
queryWrapper
);
HongqiAwemeIncentiveStructMapper
mapper
=
Mappers
.
getMapper
(
HongqiAwemeIncentiveStructMapper
.
class
);
List
<
HongqiAwemeIncentiveVO
>
vos
=
mapper
.
listLiveMonthlyToVO
(
awemePage
.
getRecords
());
return
BasePageVO
.
restPage
(
pageNum
,
pageSize
,
(
int
)
awemePage
.
getTotal
(),
(
int
)
awemePage
.
getPages
(),
vos
);
return
BasePageVO
.
restPage
(
pageNum
,
(
int
)
awemePage
.
getSize
()
,
(
int
)
awemePage
.
getTotal
(),
(
int
)
awemePage
.
getPages
(),
vos
);
}
else
if
(
quarter
.
equals
(
type
))
{
IPage
<
HongqiAwemeIncentiveQuarter
>
page
=
new
Page
<>(
pageNum
,
pageSize
);
QueryWrapper
<
HongqiAwemeIncentiveQuarter
>
queryWrapper
=
new
QueryWrapper
<>();
...
...
@@ -65,7 +65,7 @@ public class FawOpenService {
IPage
<
HongqiAwemeIncentiveQuarter
>
awemePage
=
hongqiAwemeIncentiveQuarterMapper
.
selectPage
(
page
,
queryWrapper
);
HongqiAwemeIncentiveStructMapper
mapper
=
Mappers
.
getMapper
(
HongqiAwemeIncentiveStructMapper
.
class
);
List
<
HongqiAwemeIncentiveVO
>
vos
=
mapper
.
listLiveQuarterToVO
(
awemePage
.
getRecords
());
return
BasePageVO
.
restPage
(
pageNum
,
pageSize
,
(
int
)
awemePage
.
getTotal
(),
(
int
)
awemePage
.
getPages
(),
vos
);
return
BasePageVO
.
restPage
(
pageNum
,
(
int
)
awemePage
.
getSize
()
,
(
int
)
awemePage
.
getTotal
(),
(
int
)
awemePage
.
getPages
(),
vos
);
}
else
{
return
new
BasePageVO
<>();
}
...
...
@@ -80,7 +80,7 @@ public class FawOpenService {
IPage
<
HongqiLiveIncentiveMonthly
>
awemePage
=
hongqiLiveIncentiveMonthlyMapper
.
selectPage
(
page
,
queryWrapper
);
HongqiLiveIncentiveStructMapper
mapper
=
Mappers
.
getMapper
(
HongqiLiveIncentiveStructMapper
.
class
);
List
<
HongqiLiveIncentiveVO
>
vos
=
mapper
.
listLiveMonthlyToVO
(
awemePage
.
getRecords
());
return
BasePageVO
.
restPage
(
pageNum
,
pageSize
,
(
int
)
awemePage
.
getTotal
(),
(
int
)
awemePage
.
getPages
(),
vos
);
return
BasePageVO
.
restPage
(
pageNum
,
(
int
)
awemePage
.
getSize
()
,
(
int
)
awemePage
.
getTotal
(),
(
int
)
awemePage
.
getPages
(),
vos
);
}
else
if
(
quarter
.
equals
(
type
))
{
IPage
<
HongqiLiveIncentiveQuarter
>
page
=
new
Page
<>(
pageNum
,
pageSize
);
QueryWrapper
<
HongqiLiveIncentiveQuarter
>
queryWrapper
=
new
QueryWrapper
<>();
...
...
@@ -88,7 +88,7 @@ public class FawOpenService {
IPage
<
HongqiLiveIncentiveQuarter
>
awemePage
=
hongqiLiveIncentiveQuarterMapper
.
selectPage
(
page
,
queryWrapper
);
HongqiLiveIncentiveStructMapper
mapper
=
Mappers
.
getMapper
(
HongqiLiveIncentiveStructMapper
.
class
);
List
<
HongqiLiveIncentiveVO
>
vos
=
mapper
.
listLiveQuarterToVO
(
awemePage
.
getRecords
());
return
BasePageVO
.
restPage
(
pageNum
,
pageSize
,
(
int
)
awemePage
.
getTotal
(),
(
int
)
awemePage
.
getPages
(),
vos
);
return
BasePageVO
.
restPage
(
pageNum
,
(
int
)
awemePage
.
getSize
()
,
(
int
)
awemePage
.
getTotal
(),
(
int
)
awemePage
.
getPages
(),
vos
);
}
else
{
return
new
BasePageVO
<>();
}
...
...
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