Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
I
isc-common
Overview
Overview
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
isc-v3.1-tmp
isc-common
Commits
53d36940
Commit
53d36940
authored
Sep 30, 2024
by
huangshunlin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改捕获的异常范围,退出删除lck 交易码需大写
parent
78b78815
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
54 deletions
+51
-54
DBLckBizLocker.java
...a/com/brilliance/isc/common/lock/impl/DBLckBizLocker.java
+39
-40
LckComponent.java
...ava/com/brilliance/isc/common/lock/impl/LckComponent.java
+12
-14
No files found.
isc-common-service-public/src/main/java/com/brilliance/isc/common/lock/impl/DBLckBizLocker.java
View file @
53d36940
package
com
.
brilliance
.
isc
.
common
.
lock
.
impl
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.Logger
;
import
com.brilliance.isc.bo.Lck
;
import
com.brilliance.isc.bo.Stb
;
import
com.brilliance.isc.common.lock.LockInfo
;
import
com.brilliance.isc.mda.dao.StbMapper
;
import
com.brilliance.isc.vo.manager.StbVo
;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Primary
;
import
org.springframework.stereotype.Service
;
...
...
@@ -31,63 +32,62 @@ public class DBLckBizLocker extends AbstractBizLocker {
private
final
String
DBLOCKER
=
"DBLOCK"
;
private
boolean
getSwitchFlag
(){
private
boolean
getSwitchFlag
()
{
StbVo
stbVo
=
new
StbVo
();
stbVo
.
setTbl
(
DBLOCKER
);
List
<
Stb
>
stbs
=
stbMapper
.
queryByPage
(
stbVo
);
if
(
stbs
==
null
||
stbs
.
size
()
==
0
)
{
if
(
stbs
==
null
||
stbs
.
size
()
==
0
)
{
return
false
;
}
return
"Y"
.
equals
(
stbs
.
get
(
0
).
getCod
())
?
true
:
false
;
}
/**
* @param key 为业务主键,使用LockInfo的方法生成key
* @param value 为业务锁定信息,一般为交易码+操作人,使用LockInfo的方法生成value
* @param key
为业务主键,使用LockInfo的方法生成key
* @param value
为业务锁定信息,一般为交易码+操作人,使用LockInfo的方法生成value
* @param seconds 锁定时间,db模式下无效
* @return
*/
@Transactional
(
propagation
=
Propagation
.
REQUIRES_NEW
,
rollbackFor
=
Exception
.
class
)
public
boolean
lock
(
String
key
,
String
value
,
long
seconds
)
{
if
(!
getSwitchFlag
())
{
@Transactional
(
propagation
=
Propagation
.
REQUIRES_NEW
,
rollbackFor
=
Exception
.
class
)
public
boolean
lock
(
String
key
,
String
value
,
long
seconds
)
{
if
(!
getSwitchFlag
())
{
logger
.
info
(
"锁定函数暂时关闭"
);
return
true
;
}
LockInfo
lockInfo
=
new
LockInfo
(
key
,
value
);
boolean
isSuccess
=
lckComponent
.
tryInsert
(
lockInfo
);
LockInfo
lockInfo
=
new
LockInfo
(
key
,
value
);
boolean
isSuccess
=
lckComponent
.
tryInsert
(
lockInfo
);
// 插入成功,新增
if
(
isSuccess
)
{
logger
.
info
(
"锁key:{},value:{},结果:成功"
,
key
,
value
);
logger
.
info
(
"锁key:{},value:{},结果:成功"
,
key
,
value
);
return
true
;
}
lockInfo
=
getLock
(
lockInfo
);
String
oldValue
=
lockInfo
.
genLockValue
();
// 相同时,刷新时间
if
(
oldValue
.
equals
(
value
))
{
if
(
value
.
endsWith
(
"#true"
))
{
logger
.
info
(
"锁已重入key:{},value:{}"
,
key
,
value
);
if
(
value
.
endsWith
(
"#true"
))
{
logger
.
info
(
"锁已重入key:{},value:{}"
,
key
,
value
);
isSuccess
=
true
;
}
else
{
logger
.
info
(
"锁无法重入key:{},value:{}"
,
key
,
value
);
}
else
{
logger
.
info
(
"锁无法重入key:{},value:{}"
,
key
,
value
);
}
}
return
isSuccess
;
}
@Override
public
LockInfo
getLock
(
LockInfo
lockInfo
)
{
if
(!
getSwitchFlag
())
{
if
(!
getSwitchFlag
())
{
logger
.
info
(
"锁定函数暂时关闭"
);
return
null
;
}
String
key
=
lockInfo
.
genLockKey
();
LockInfo
dbLockInfo
=
lckComponent
.
getLck
(
lockInfo
);
if
(
dbLockInfo
!=
null
)
{
if
(
dbLockInfo
!=
null
)
{
String
value
=
dbLockInfo
.
genLockValue
();
logger
.
info
(
"返回锁信息key:{},value:{}"
,
key
,
value
);
logger
.
info
(
"返回锁信息key:{},value:{}"
,
key
,
value
);
return
dbLockInfo
;
}
return
null
;
...
...
@@ -96,37 +96,36 @@ public class DBLckBizLocker extends AbstractBizLocker {
@Override
public
boolean
unlock
(
LockInfo
lockInfo
)
{
if
(!
getSwitchFlag
())
{
if
(!
getSwitchFlag
())
{
logger
.
info
(
"锁定函数暂时关闭"
);
return
true
;
}
String
key
=
lockInfo
.
genLockKey
();
LockInfo
oldLockInfo
=
getLock
(
lockInfo
);
if
(
oldLockInfo
!=
null
)
{
logger
.
info
(
"返回锁信息key:{},value:{}"
,
key
,
oldLockInfo
.
genLockValue
());
if
(
oldLockInfo
.
getUsrId
().
equals
(
lockInfo
.
getUsrId
()))
{
logger
.
info
(
"删除锁{}"
,
key
);
if
(
oldLockInfo
!=
null
)
{
logger
.
info
(
"返回锁信息key:{},value:{}"
,
key
,
oldLockInfo
.
genLockValue
());
if
(
oldLockInfo
.
getUsrId
().
equals
(
lockInfo
.
getUsrId
()))
{
logger
.
info
(
"删除锁{}"
,
key
);
int
cnt
=
lckComponent
.
deleteLck
(
oldLockInfo
);
logger
.
info
(
"删除锁成功{},影响行数{}"
,
key
,
cnt
);
logger
.
info
(
"删除锁成功{},影响行数{}"
,
key
,
cnt
);
return
true
;
}
else
{
logger
.
info
(
"{}锁定人不一致,不允许删除,oldUserId:{},curUserId{},"
,
key
,
oldLockInfo
.
getUsrId
(),
lockInfo
.
getUsrId
());
}
else
{
logger
.
info
(
"{}锁定人不一致,不允许删除,oldUserId:{},curUserId{},"
,
key
,
oldLockInfo
.
getUsrId
(),
lockInfo
.
getUsrId
());
}
}
return
false
;
}
@Transactional
(
propagation
=
Propagation
.
REQUIRES_NEW
,
rollbackFor
=
Exception
.
class
)
public
boolean
lockForce
(
String
key
,
String
value
,
long
seconds
)
{
logger
.
info
(
"强制占用锁{}:{}"
,
key
,
value
);
LockInfo
lockInfo
=
new
LockInfo
(
key
,
value
);
@Transactional
(
propagation
=
Propagation
.
REQUIRES_NEW
,
rollbackFor
=
Exception
.
class
)
public
boolean
lockForce
(
String
key
,
String
value
,
long
seconds
)
{
logger
.
info
(
"强制占用锁{}:{}"
,
key
,
value
);
LockInfo
lockInfo
=
new
LockInfo
(
key
,
value
);
lckComponent
.
updateLockInfo
(
lockInfo
);
logger
.
info
(
"强制占用锁{}:{}成功"
,
key
,
value
);
logger
.
info
(
"强制占用锁{}:{}成功"
,
key
,
value
);
return
true
;
}
/**
* 强制解锁
*
...
...
@@ -136,9 +135,9 @@ public class DBLckBizLocker extends AbstractBizLocker {
@Override
public
boolean
unlockForce
(
LockInfo
lockInfo
)
{
String
key
=
lockInfo
.
genLockKey
();
logger
.
info
(
"强制删除锁{}"
,
key
);
logger
.
info
(
"强制删除锁{}"
,
key
);
int
cnt
=
lckComponent
.
deleteLck
(
lockInfo
);
logger
.
info
(
"强制删除锁成功{},影响行数{}"
,
key
,
cnt
);
logger
.
info
(
"强制删除锁成功{},影响行数{}"
,
key
,
cnt
);
return
true
;
}
...
...
@@ -151,10 +150,10 @@ public class DBLckBizLocker extends AbstractBizLocker {
@Override
public
boolean
unlockAllOfTrans
(
String
transName
,
String
userId
)
{
Lck
lck
=
new
Lck
();
lck
.
setLcktrn
(
transName
);
lck
.
setLcktrn
(
StringUtils
.
upperCase
(
transName
)
);
lck
.
setLckusr
(
userId
);
int
cnt
=
lckComponent
.
deleteLckByUserAndTrn
(
lck
);
logger
.
info
(
"解除{}用户在{}交易的所有锁定,影响行数{}"
,
userId
,
transName
,
cnt
);
logger
.
info
(
"解除{}用户在{}交易的所有锁定,影响行数{}"
,
userId
,
transName
,
cnt
);
return
true
;
}
...
...
@@ -166,12 +165,12 @@ public class DBLckBizLocker extends AbstractBizLocker {
*/
@Override
public
boolean
unlockAllOfUser
(
String
userId
)
{
logger
.
info
(
"退出锁定{}"
,
userId
);
logger
.
info
(
"退出锁定{}"
,
userId
);
Lck
lck
=
new
Lck
();
lck
.
setLcktrn
(
null
);
lck
.
setLckusr
(
userId
);
int
cnt
=
lckComponent
.
deleteLckByUserAndTrn
(
lck
);
logger
.
info
(
"退出锁定成功{},影响行数{}"
,
userId
,
cnt
);
logger
.
info
(
"退出锁定成功{},影响行数{}"
,
userId
,
cnt
);
return
false
;
}
}
isc-common-service-public/src/main/java/com/brilliance/isc/common/lock/impl/LckComponent.java
View file @
53d36940
package
com
.
brilliance
.
isc
.
common
.
lock
.
impl
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.Logger
;
import
com.brilliance.isc.bo.Lck
;
import
com.brilliance.isc.common.lock.LockInfo
;
import
com.brilliance.isc.mda.dao.LckMapper
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.dao.DuplicateKeyException
;
import
org.springframework.stereotype.Service
;
import
java.util.Date
;
...
...
@@ -25,40 +24,39 @@ public class LckComponent {
int
cnt
=
lckMapper
.
insert
(
lck
);
logger
.
info
(
"锁定信息插入成功,影响行数:{}"
,
cnt
);
return
true
;
}
catch
(
DuplicateKeyException
e
){
logger
.
info
(
"已存在锁{}"
,
lockInfo
.
genLockKey
());
}
finally
{
}
catch
(
Exception
e
)
{
logger
.
info
(
"已存在锁{}"
,
lockInfo
.
genLockKey
());
}
finally
{
}
return
false
;
}
public
Lck
lockInfo2Lck
(
LockInfo
lockInfo
){
public
Lck
lockInfo2Lck
(
LockInfo
lockInfo
)
{
Lck
dataLck
=
new
Lck
();
dataLck
.
setLckdattim
(
new
Date
());
dataLck
.
setLcktrn
(
lockInfo
.
getTrnName
());
dataLck
.
setLckusr
(
lockInfo
.
getUsrId
());
dataLck
.
setLckstr
(
lockInfo
.
genLockKey
());
if
(
lockInfo
.
isReentrant
())
{
if
(
lockInfo
.
isReentrant
())
{
dataLck
.
setLckhld
(
""
);
}
else
{
}
else
{
dataLck
.
setLckhld
(
"X"
);
}
return
dataLck
;
}
public
LockInfo
lck2Info
(
Lck
dataLck
){
if
(
dataLck
==
null
)
{
public
LockInfo
lck2Info
(
Lck
dataLck
)
{
if
(
dataLck
==
null
)
{
return
null
;
}
LockInfo
lockInfo
=
new
LockInfo
(
dataLck
.
getLckstr
());
lockInfo
.
setTrnName
(
dataLck
.
getLcktrn
());
lockInfo
.
setUsrId
(
dataLck
.
getLckusr
());
if
(
dataLck
.
getLckhld
()
==
null
||
dataLck
.
getLckhld
().
trim
().
isEmpty
())
{
if
(
dataLck
.
getLckhld
()
==
null
||
dataLck
.
getLckhld
().
trim
().
isEmpty
())
{
lockInfo
.
setReentrant
(
true
);
}
else
{
}
else
{
lockInfo
.
setReentrant
(
false
);
}
return
lockInfo
;
...
...
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