Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
I
ibzdst
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
1
议题
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
ibiz4jteam
ibzdst
提交
62fa3795
提交
62fa3795
编写于
3年前
作者:
ibiz4j
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
lock
上级
958624c0
变更
7
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
134 行增加
和
11 行删除
+134
-11
webSecurityConfig.java
...rc/main/java/cn/ibizlab/web/config/webSecurityConfig.java
+2
-0
DevBootSecurityConfig.java
...rc/main/java/cn/ibizlab/config/DevBootSecurityConfig.java
+1
-0
apiSecurityConfig.java
...rc/main/java/cn/ibizlab/api/config/apiSecurityConfig.java
+1
-0
DstCoreResource.java
.../java/cn/ibizlab/api/rest/extensions/DstCoreResource.java
+17
-1
RunLock.java
...til/src/main/java/cn/ibizlab/util/annotation/RunLock.java
+15
-0
LockAspect.java
...util/src/main/java/cn/ibizlab/util/aspect/LockAspect.java
+85
-0
LockService.java
...il/src/main/java/cn/ibizlab/util/service/LockService.java
+13
-10
未找到文件。
ibzdst-app/ibzdst-app-web/src/main/java/cn/ibizlab/web/config/webSecurityConfig.java
浏览文件 @
62fa3795
...
...
@@ -121,6 +121,8 @@ public class webSecurityConfig extends WebSecurityConfigurerAdapter {
.
antMatchers
(
"/"
+
uploadpath
).
permitAll
()
.
antMatchers
(
"/"
+
previewpath
+
"/**"
).
permitAll
()
.
antMatchers
(
"/ibizutil/**"
).
permitAll
()
.
antMatchers
(
"/dictionarys/**"
).
permitAll
()
.
antMatchers
(
"/lite/**"
).
permitAll
()
.
antMatchers
(
"/dst/**"
).
permitAll
();
...
...
This diff is collapsed.
Click to expand it.
ibzdst-boot/src/main/java/cn/ibizlab/config/DevBootSecurityConfig.java
浏览文件 @
62fa3795
...
...
@@ -119,6 +119,7 @@ public class DevBootSecurityConfig extends WebSecurityConfigurerAdapter {
.
antMatchers
(
"/dst/**"
).
permitAll
()
.
antMatchers
(
"/lite/**"
).
permitAll
()
.
antMatchers
(
"/ibizutil/**"
).
permitAll
()
.
antMatchers
(
"/dictionarys/**"
).
permitAll
()
.
antMatchers
(
"/"
+
previewpath
+
"/**"
).
permitAll
();
...
...
This diff is collapsed.
Click to expand it.
ibzdst-provider/ibzdst-provider-api/src/main/java/cn/ibizlab/api/config/apiSecurityConfig.java
浏览文件 @
62fa3795
...
...
@@ -124,6 +124,7 @@ public class apiSecurityConfig extends WebSecurityConfigurerAdapter {
.
antMatchers
(
"/"
+
previewpath
+
"/**"
).
permitAll
()
.
antMatchers
(
"/dst/**"
).
permitAll
()
.
antMatchers
(
"/ibizutil/**"
).
permitAll
()
.
antMatchers
(
"/dictionarys/**"
).
permitAll
()
.
antMatchers
(
"/lite/**"
).
permitAll
();
for
(
String
excludePattern
:
excludesPattern
)
{
...
...
This diff is collapsed.
Click to expand it.
ibzdst-provider/ibzdst-provider-api/src/main/java/cn/ibizlab/api/rest/extensions/DstCoreResource.java
浏览文件 @
62fa3795
...
...
@@ -18,6 +18,7 @@ import cn.ibizlab.core.lite.service.IMetaEntityService;
import
cn.ibizlab.core.lite.service.IMetaFieldService
;
import
cn.ibizlab.core.rule.domain.RuleItem
;
import
cn.ibizlab.core.rule.service.IRuleItemService
;
import
cn.ibizlab.util.annotation.RunLock
;
import
cn.ibizlab.util.dict.CodeItem
;
import
cn.ibizlab.util.dict.CodeList
;
import
cn.ibizlab.util.dict.Option
;
...
...
@@ -29,7 +30,6 @@ import io.swagger.annotations.Api;
import
io.swagger.annotations.ApiOperation
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.cache.annotation.Cacheable
;
import
org.springframework.context.annotation.Lazy
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
...
...
@@ -59,6 +59,22 @@ public class DstCoreResource
@Autowired
private
IRuleItemService
ruleItemService
;
@RequestMapping
(
method
=
RequestMethod
.
GET
,
value
=
{
"/dst/lock/{rulecode}/{key}"
})
public
ResponseEntity
<
Boolean
>
testLock
(
@PathVariable
(
"rulecode"
)
String
rulecode
,
@PathVariable
(
"key"
)
String
key
)
{
System
.
out
.
println
(
"start"
);
try
{
Thread
.
sleep
(
20000
);
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
System
.
out
.
println
(
"end"
);
return
ResponseEntity
.
status
(
HttpStatus
.
OK
).
body
(
true
);
}
@RequestMapping
(
method
=
RequestMethod
.
GET
,
value
=
{
"/dst/test/{rulecode}/{key}"
})
public
ResponseEntity
<
Boolean
>
testRule
(
@PathVariable
(
"rulecode"
)
String
rulecode
,
@PathVariable
(
"key"
)
String
key
)
...
...
This diff is collapsed.
Click to expand it.
ibzdst-util/src/main/java/cn/ibizlab/util/annotation/RunLock.java
0 → 100644
浏览文件 @
62fa3795
package
cn
.
ibizlab
.
util
.
annotation
;
import
org.springframework.core.annotation.AliasFor
;
import
java.lang.annotation.*
;
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Target
({
ElementType
.
METHOD
})
public
@interface
RunLock
{
String
value
()
default
""
;
long
lockTimeMillis
()
default
300000
;
}
This diff is collapsed.
Click to expand it.
ibzdst-util/src/main/java/cn/ibizlab/util/aspect/LockAspect.java
0 → 100644
浏览文件 @
62fa3795
package
cn
.
ibizlab
.
util
.
aspect
;
import
cn.ibizlab.util.annotation.RunLock
;
import
cn.ibizlab.util.annotation.VersionCheck
;
import
cn.ibizlab.util.errors.BadRequestAlertException
;
import
cn.ibizlab.util.service.LockService
;
import
lombok.SneakyThrows
;
import
org.aspectj.lang.JoinPoint
;
import
org.aspectj.lang.ProceedingJoinPoint
;
import
org.aspectj.lang.annotation.Around
;
import
org.aspectj.lang.annotation.Aspect
;
import
org.aspectj.lang.annotation.Before
;
import
org.aspectj.lang.annotation.Pointcut
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Lazy
;
import
org.springframework.core.LocalVariableTableParameterNameDiscoverer
;
import
org.springframework.core.annotation.Order
;
import
org.springframework.expression.EvaluationContext
;
import
org.springframework.expression.Expression
;
import
org.springframework.expression.ExpressionParser
;
import
org.springframework.expression.spel.standard.SpelExpressionParser
;
import
org.springframework.expression.spel.support.StandardEvaluationContext
;
import
org.springframework.stereotype.Component
;
import
java.lang.reflect.Method
;
@Component
@Order
(
5000
)
@Aspect
public
class
LockAspect
{
@Autowired
@Lazy
private
LockService
lockService
;
@SneakyThrows
@Around
(
"@annotation(runLock)"
)
public
Object
checkLock
(
ProceedingJoinPoint
point
,
RunLock
runLock
)
{
String
targetName
=
point
.
getTarget
().
getClass
().
getName
();
String
simpleName
=
point
.
getTarget
().
getClass
().
getSimpleName
();
String
methodName
=
point
.
getSignature
().
getName
();
Object
[]
arguments
=
point
.
getArgs
();
Class
targetClass
=
Class
.
forName
(
targetName
);
Method
[]
methods
=
targetClass
.
getMethods
();
String
key
=
""
;
long
lockTimeMillis
=
0L
;
String
[]
paramNames
=
{};
for
(
Method
method:
methods
){
if
(
method
.
getName
().
equals
(
methodName
)){
key
=
runLock
.
value
();
lockTimeMillis
=
runLock
.
lockTimeMillis
();
paramNames
=
getParamterNames
(
method
);
}
}
ExpressionParser
parser
=
new
SpelExpressionParser
();
Expression
expression
=
parser
.
parseExpression
(
key
);
EvaluationContext
context
=
new
StandardEvaluationContext
();
for
(
int
i
=
0
;
i
<
arguments
.
length
;
i
++){
context
.
setVariable
(
paramNames
[
i
],
arguments
[
i
]);
}
String
lockName
=(
expression
.
getValue
(
context
,
String
.
class
));
boolean
locked
=
lockService
.
isLocked
(
lockName
,
lockTimeMillis
);
System
.
out
.
println
(
lockName
+
locked
);
if
(
locked
)
throw
new
BadRequestAlertException
(
"服务正在执行中,已上锁"
,
methodName
,
lockName
);
try
{
return
point
.
proceed
();
}
finally
{
if
(!
locked
)
lockService
.
unLock
(
lockName
);
}
}
public
String
[]
getParamterNames
(
Method
method
){
LocalVariableTableParameterNameDiscoverer
u
=
new
LocalVariableTableParameterNameDiscoverer
();
return
u
.
getParameterNames
(
method
);
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
ibzdst-util/src/main/java/cn/ibizlab/util/service/LockService.java
浏览文件 @
62fa3795
...
...
@@ -16,24 +16,26 @@ public class LockService {
private
LockService
proxy
;
@Cacheable
(
value
=
"lock"
,
key
=
"'key:'+#p0"
)
p
rotect
ed
Long
getLock
(
String
key
)
p
ublic
synchroniz
ed
Long
getLock
(
String
key
)
{
return
System
.
currentTimeMillis
();
long
lockTime
=
System
.
currentTimeMillis
();
System
.
out
.
println
(
"lockTime"
+
lockTime
);
return
lockTime
;
}
@Cacheable
(
value
=
"lock"
,
key
=
"'key:'+#p0"
)
p
rivate
Long
resetLock
(
String
key
,
Long
newLockTime
)
p
ublic
Long
resetLock
(
String
key
,
Long
newLockTime
)
{
return
newLockTime
;
}
@CacheEvict
(
value
=
"lock"
,
key
=
"'key:'+#p0"
)
p
rivate
void
deleteLock
(
String
key
)
p
ublic
void
deleteLock
(
String
key
)
{
}
public
boolean
lock
(
String
key
,
Long
lockTimeMillis
)
public
synchronized
boolean
isLocked
(
String
key
,
Long
lockTimeMillis
)
{
if
(
StringUtils
.
isEmpty
(
key
))
return
false
;
...
...
@@ -41,10 +43,11 @@ public class LockService {
Long
lockTime
=
proxy
.
getLock
(
key
);
System
.
out
.
println
(
lockTime
+
":"
+
now
);
if
(
lockTime
>=
now
)
return
tru
e
;
return
fals
e
;
if
(
lockTime
+
lockTimeMillis
>
now
)
if
(
lockTime
+
lockTimeMillis
<
now
)
{
proxy
.
deleteLock
(
key
);
proxy
.
resetLock
(
key
,
now
);
...
...
@@ -58,11 +61,11 @@ public class LockService {
}
proxy
.
resetLock
(
key
,
now
);
}
});
return
tru
e
;
})
.
start
()
;
return
fals
e
;
}
return
fals
e
;
return
tru
e
;
}
public
void
unLock
(
String
key
)
...
...
This diff is collapsed.
Click to expand it.
编辑
预览
Markdown
格式
0%
请重试
or
添加新附件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录