Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
poc-api
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
poc
poc-api
Commits
22dd17ce
Commit
22dd17ce
authored
Nov 07, 2024
by
alex yao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:收藏冪等
parent
24c5e077
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
347 additions
and
143 deletions
+347
-143
BizAgentApplicationMallRestImpl.java
...pplication/rest/impl/BizAgentApplicationMallRestImpl.java
+5
-2
CurrentUserRolePermission.java
.../com/poc/common/annotation/CurrentUserRolePermission.java
+24
-0
RedisLimit.java
src/main/java/cn/com/poc/common/annotation/RedisLimit.java
+83
-0
RedisLimitAspect.java
src/main/java/cn/com/poc/common/aspect/RedisLimitAspect.java
+91
-0
exception.properties
...in/resources/framemax-config/i18n/en/exception.properties
+2
-1
exception.properties
...resources/framemax-config/i18n/zh_cn/exception.properties
+71
-70
exception.properties
...resources/framemax-config/i18n/zh_tw/exception.properties
+71
-70
No files found.
src/main/java/cn/com/poc/agent_application/rest/impl/BizAgentApplicationMallRestImpl.java
View file @
22dd17ce
...
@@ -16,6 +16,7 @@ import cn.com.poc.agent_application.service.BizAgentApplicationCategoryService;
...
@@ -16,6 +16,7 @@ import cn.com.poc.agent_application.service.BizAgentApplicationCategoryService;
import
cn.com.poc.agent_application.service.BizAgentApplicationMallService
;
import
cn.com.poc.agent_application.service.BizAgentApplicationMallService
;
import
cn.com.poc.agent_application.service.BizAgentApplicationPublishService
;
import
cn.com.poc.agent_application.service.BizAgentApplicationPublishService
;
import
cn.com.poc.agent_application.service.BizMemberAgentApplicationCollectService
;
import
cn.com.poc.agent_application.service.BizMemberAgentApplicationCollectService
;
import
cn.com.poc.common.annotation.RedisLimit
;
import
cn.com.poc.common.constant.CommonConstant
;
import
cn.com.poc.common.constant.CommonConstant
;
import
cn.com.poc.common.constant.XLangConstant
;
import
cn.com.poc.common.constant.XLangConstant
;
import
cn.com.poc.common.utils.StringUtils
;
import
cn.com.poc.common.utils.StringUtils
;
...
@@ -28,6 +29,7 @@ import javax.annotation.Resource;
...
@@ -28,6 +29,7 @@ import javax.annotation.Resource;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
import
java.util.concurrent.TimeUnit
;
@Component
@Component
public
class
BizAgentApplicationMallRestImpl
implements
BizAgentApplicationMallRest
{
public
class
BizAgentApplicationMallRestImpl
implements
BizAgentApplicationMallRest
{
...
@@ -115,14 +117,14 @@ public class BizAgentApplicationMallRestImpl implements BizAgentApplicationMallR
...
@@ -115,14 +117,14 @@ public class BizAgentApplicationMallRestImpl implements BizAgentApplicationMallR
for
(
MallAgentApplicationQueryItem
item
:
items
)
{
for
(
MallAgentApplicationQueryItem
item
:
items
)
{
BizAgentApplicationMallDto
mallDto
=
BizAgentApplicationMallConvert
.
itemToDto
(
item
);
BizAgentApplicationMallDto
mallDto
=
BizAgentApplicationMallConvert
.
itemToDto
(
item
);
// 如果应用上架了
// 如果应用上架了
if
(
CommonConstant
.
IsDeleted
.
Y
.
equals
(
mallDto
.
getIsSale
()))
{
if
(
CommonConstant
.
YOrN
.
Y
.
equals
(
mallDto
.
getIsSale
()))
{
// 设置当前用户是否收藏了
// 设置当前用户是否收藏了
if
(
mallDto
.
getBaseInfo
()
!=
null
)
{
if
(
mallDto
.
getBaseInfo
()
!=
null
)
{
BizMemberAgentApplicationCollectEntity
collect
=
bizMemberAgentApplicationCollectService
.
getByAgentId
(
mallDto
.
getBaseInfo
().
getAgentId
());
BizMemberAgentApplicationCollectEntity
collect
=
bizMemberAgentApplicationCollectService
.
getByAgentId
(
mallDto
.
getBaseInfo
().
getAgentId
());
if
(
collect
!=
null
)
{
if
(
collect
!=
null
)
{
mallDto
.
setIsCollect
(
collect
.
getIsCollect
());
mallDto
.
setIsCollect
(
collect
.
getIsCollect
());
}
else
{
}
else
{
mallDto
.
setIsCollect
(
CommonConstant
.
IsDeleted
.
N
);
mallDto
.
setIsCollect
(
CommonConstant
.
YOrN
.
N
);
}
}
}
}
resultList
.
add
(
mallDto
);
resultList
.
add
(
mallDto
);
...
@@ -143,6 +145,7 @@ public class BizAgentApplicationMallRestImpl implements BizAgentApplicationMallR
...
@@ -143,6 +145,7 @@ public class BizAgentApplicationMallRestImpl implements BizAgentApplicationMallR
}
}
@Override
@Override
@RedisLimit
(
currentUser
=
true
,
key
=
"collect:agent"
,
count
=
1
,
timeout
=
1
,
exceptionInfo
=
"exception/collect.limit.message"
)
public
void
collectOrCancelAgentInMall
(
Integer
id
)
throws
Exception
{
public
void
collectOrCancelAgentInMall
(
Integer
id
)
throws
Exception
{
Assert
.
notNull
(
id
);
Assert
.
notNull
(
id
);
agentApplicationMallService
.
collectOrCancelAgentInMall
(
id
);
agentApplicationMallService
.
collectOrCancelAgentInMall
(
id
);
...
...
src/main/java/cn/com/poc/common/annotation/CurrentUserRolePermission.java
0 → 100644
View file @
22dd17ce
package
cn
.
com
.
poc
.
common
.
annotation
;
import
org.springframework.stereotype.Component
;
import
java.lang.annotation.*
;
/**
* @author Ken
*/
@Target
({
ElementType
.
METHOD
})
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Documented
@Component
public
@interface
CurrentUserRolePermission
{
String
[]
permissionCodeArr
();
String
prompt
()
default
"无权限,请联系管理员"
;
}
src/main/java/cn/com/poc/common/annotation/RedisLimit.java
0 → 100644
View file @
22dd17ce
package
cn
.
com
.
poc
.
common
.
annotation
;
import
org.springframework.stereotype.Component
;
import
java.lang.annotation.*
;
/**
* 限流
*/
@Target
(
ElementType
.
METHOD
)
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Component
@Documented
public
@interface
RedisLimit
{
/**
* 限流key
*/
String
key
();
/**
* 限流数量 [单位时间内次数]
*/
int
count
();
/**
* 限流时间 默认60秒
*/
long
timeout
()
default
60
;
/**
* 限流时间单位 [默认秒]
*/
LimitTimeUnit
timeUnit
()
default
LimitTimeUnit
.
SECONDS
;
/**
* 是否针对当前用户
*
* @return
*/
boolean
currentUser
()
default
false
;
/**
* 异常信息
*/
String
exceptionInfo
()
default
""
;
enum
LimitTimeUnit
{
/**
* 秒
*/
SECONDS
,
/**
* 分钟
*/
MINUTES
,
/**
* 小时
*/
HOURS
,
/**
* 天
*/
DAYS
,
/**
* 当日
*/
DAY_OF_MONTH
,
/**
* 当月
*/
MONTH_OF_YEAR
;
LimitTimeUnit
(){}
}
}
src/main/java/cn/com/poc/common/aspect/RedisLimitAspect.java
0 → 100644
View file @
22dd17ce
package
cn
.
com
.
poc
.
common
.
aspect
;
import
cn.com.poc.common.annotation.RedisLimit
;
import
cn.com.poc.common.utils.BlContext
;
import
cn.com.poc.common.utils.DateUtils
;
import
cn.com.poc.support.security.oauth.entity.UserBaseEntity
;
import
cn.com.yict.framemax.core.exception.BusinessException
;
import
cn.com.yict.framemax.core.i18n.I18nMessageException
;
import
org.aspectj.lang.ProceedingJoinPoint
;
import
org.aspectj.lang.annotation.Around
;
import
org.aspectj.lang.annotation.Aspect
;
import
org.aspectj.lang.annotation.Pointcut
;
import
org.aspectj.lang.reflect.MethodSignature
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.stereotype.Component
;
import
javax.annotation.Resource
;
import
java.lang.reflect.Method
;
import
java.util.Date
;
import
java.util.concurrent.TimeUnit
;
/**
* 限流切面
*/
@Aspect
@Component
public
class
RedisLimitAspect
{
private
final
Logger
logger
=
LoggerFactory
.
getLogger
(
RedisLimitAspect
.
class
);
@Resource
private
RedisTemplate
<
String
,
Integer
>
redisTemplate
;
@Pointcut
(
"@annotation( cn.com.poc.common.annotation.RedisLimit)"
)
public
void
redisLimitAnnotation
()
{
}
@Around
(
value
=
"redisLimitAnnotation()"
)
public
Object
around
(
ProceedingJoinPoint
joinPoint
)
throws
Throwable
{
Method
method
=
((
MethodSignature
)
joinPoint
.
getSignature
()).
getMethod
();
RedisLimit
annotation
=
method
.
getAnnotation
(
RedisLimit
.
class
);
StringBuilder
redisKey
=
new
StringBuilder
();
String
key
=
annotation
.
key
();
redisKey
.
append
(
"Limit_"
);
redisKey
.
append
(
key
);
redisKey
.
append
(
":"
);
if
(
annotation
.
currentUser
())
{
UserBaseEntity
currentUser
=
BlContext
.
getCurrentUserNotException
();
redisKey
.
append
(
currentUser
.
getUserId
());
}
if
(
Boolean
.
FALSE
.
equals
(
redisTemplate
.
hasKey
(
redisKey
.
toString
())))
{
redisTemplate
.
opsForValue
().
increment
(
redisKey
.
toString
(),
1
);
redisTemplate
.
expire
(
redisKey
.
toString
(),
expireTime
(
annotation
.
timeout
(),
annotation
.
timeUnit
()),
TimeUnit
.
MILLISECONDS
);
}
else
if
(
redisTemplate
.
opsForValue
().
get
(
redisKey
.
toString
()).
intValue
()
>=
annotation
.
count
())
{
throw
new
I18nMessageException
(
annotation
.
exceptionInfo
());
}
else
{
redisTemplate
.
opsForValue
().
increment
(
redisKey
.
toString
(),
1
);
}
return
joinPoint
.
proceed
();
}
private
Long
expireTime
(
Long
timeout
,
RedisLimit
.
LimitTimeUnit
limitTimeUnit
)
{
switch
(
limitTimeUnit
)
{
case
SECONDS:
return
timeout
*
1000
;
case
MINUTES:
return
timeout
*
60
*
1000
;
case
HOURS:
return
timeout
*
60
*
60
*
1000
;
case
DAYS:
Date
date
=
new
Date
();
return
DateUtils
.
diffTwoDate
(
DateUtils
.
addDays
(
date
,
timeout
.
intValue
()),
date
);
case
DAY_OF_MONTH:
Date
dayBegin
=
DateUtils
.
getDayBegin
(
DateUtils
.
addDays
(
DateUtils
.
getToday
(),
timeout
.
intValue
()));
return
DateUtils
.
diffTwoDate
(
dayBegin
,
DateUtils
.
getToday
());
case
MONTH_OF_YEAR:
Date
monthBegin
=
DateUtils
.
getMonthBegin
(
DateUtils
.
getMonthAfter
(
DateUtils
.
getToday
(),
timeout
.
intValue
()));
return
DateUtils
.
diffTwoDate
(
monthBegin
,
DateUtils
.
getToday
());
default
:
throw
new
BusinessException
(
"不支持的单位"
);
}
}
}
src/main/resources/framemax-config/i18n/en/exception.properties
View file @
22dd17ce
...
@@ -68,3 +68,4 @@ model.not.exist=Model not exist
...
@@ -68,3 +68,4 @@ model.not.exist=Model not exist
upload.more.than.10m
=
The uploaded file cannot exceed 10M file name
upload.more.than.10m
=
The uploaded file cannot exceed 10M file name
error.file.content.is.null
=
Incorrect file, file contents cannot be empty, file name
error.file.content.is.null
=
Incorrect file, file contents cannot be empty, file name
file.content.more.than.100w
=
The number of characters in a file cannot exceed 100w
file.content.more.than.100w
=
The number of characters in a file cannot exceed 100w
collect.limit.message
=
Click too fast, do not repeat the operation
\ No newline at end of file
src/main/resources/framemax-config/i18n/zh_cn/exception.properties
View file @
22dd17ce
This diff is collapsed.
Click to expand it.
src/main/resources/framemax-config/i18n/zh_tw/exception.properties
View file @
22dd17ce
This diff is collapsed.
Click to expand it.
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