Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
ADC-uniformity
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
凡昌松
ADC-uniformity
Commits
5efd5675
Commit
5efd5675
authored
Dec 08, 2021
by
凡昌松
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update:修改mybatis扫包
parent
e522626d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
59 deletions
+66
-59
SqlInterceptor.java
.../src/main/java/com/adc/da/main/aspect/SqlInterceptor.java
+60
-53
pom.xml
pom.xml
+6
-6
No files found.
adcbs-main/src/main/java/com/adc/da/main/aspect/SqlInterceptor.java
View file @
5efd5675
package
com
.
adc
.
da
.
main
.
aspect
;
import
com.adc.da.system.entity.CheckCertificateMainInfo
;
import
com.adc.da.util.utils.StringUtils
;
import
com.adc.da.util.utils.UserUtil
;
import
com.baomidou.mybatisplus.core.toolkit.PluginUtils
;
...
...
@@ -64,81 +65,86 @@ public class SqlInterceptor extends AbstractSqlParserHandler implements Intercep
if
(
null
==
parameter
){
return
invocation
.
proceed
();
}
boolean
isNotIntercept
=
false
;
// 获取对象中所有的私有成员变量(对应表字段)
Field
[]
declaredFields
=
parameter
.
getClass
().
getDeclaredFields
();
if
(
parameter
.
getClass
().
getSuperclass
()
!=
null
)
{
if
(
parameter
.
getClass
().
getSuperclass
().
getCanonicalName
().
equals
(
CheckCertificateMainInfo
.
class
.
getCanonicalName
())
)
{
isNotIntercept
=
true
;
}
Field
[]
superField
=
parameter
.
getClass
().
getSuperclass
().
getDeclaredFields
();
declaredFields
=
ArrayUtils
.
addAll
(
declaredFields
,
superField
);
}
// mybatis plus判断
boolean
plus
=
parameter
.
getClass
().
getDeclaredFields
().
length
==
1
&&
parameter
.
getClass
().
getDeclaredFields
()[
0
].
getName
().
equals
(
"serialVersionUID"
);
if
(!
isNotIntercept
)
{
// mybatis plus判断
boolean
plus
=
parameter
.
getClass
().
getDeclaredFields
().
length
==
1
&&
parameter
.
getClass
().
getDeclaredFields
()[
0
].
getName
().
equals
(
"serialVersionUID"
);
//兼容mybatis plus
if
(
plus
)
{
Map
<
String
,
Object
>
updateParam
=
(
Map
<
String
,
Object
>)
parameter
;
if
(
updateParam
.
containsKey
(
"param1"
)&&
StringUtils
.
isNotEmpty
(
updateParam
.
get
(
"param1"
))){
Class
<?>
updateParamType
=
updateParam
.
get
(
"param1"
).
getClass
();
declaredFields
=
updateParamType
.
getDeclaredFields
();
if
(
updateParamType
.
getSuperclass
()
!=
null
)
{
Field
[]
superField
=
updateParamType
.
getSuperclass
().
getDeclaredFields
();
declaredFields
=
ArrayUtils
.
addAll
(
declaredFields
,
superField
);
//兼容mybatis plus
if
(
plus
)
{
Map
<
String
,
Object
>
updateParam
=
(
Map
<
String
,
Object
>)
parameter
;
if
(
updateParam
.
containsKey
(
"param1"
)
&&
StringUtils
.
isNotEmpty
(
updateParam
.
get
(
"param1"
)))
{
Class
<?>
updateParamType
=
updateParam
.
get
(
"param1"
).
getClass
();
declaredFields
=
updateParamType
.
getDeclaredFields
();
if
(
updateParamType
.
getSuperclass
()
!=
null
)
{
Field
[]
superField
=
updateParamType
.
getSuperclass
().
getDeclaredFields
();
declaredFields
=
ArrayUtils
.
addAll
(
declaredFields
,
superField
);
}
}
}
}
String
currentUserId
=
UserUtil
.
getCurrentUserId
();
String
currentUserId
=
UserUtil
.
getCurrentUserId
();
// if(StringUtils.isEmpty(loginUserEO)){
// throw new AdcDaBaseException("登录失效,请重新登录!");
// }
String
fieldName
=
null
;
for
(
Field
field
:
declaredFields
)
{
fieldName
=
field
.
getName
();
if
(
Objects
.
equals
(
CREATE_TIME
,
fieldName
))
{
if
(
SqlCommandType
.
INSERT
.
equals
(
sqlCommandType
))
{
try
{
field
.
setAccessible
(
true
);
field
.
set
(
parameter
,
new
Timestamp
(
System
.
currentTimeMillis
()));
}
catch
(
Exception
e
)
{
log
.
warn
(
"添加创建时间报错"
,
e
);
}
}
}
if
(
Objects
.
equals
(
CREATE_USER_ID
,
fieldName
)&&
StringUtils
.
isNotEmpty
(
currentUserId
))
{
if
(
SqlCommandType
.
INSERT
.
equals
(
sqlCommandType
))
{
field
.
setAccessible
(
true
);
field
.
set
(
parameter
,
currentUserId
);
}
}
if
(
Objects
.
equals
(
UPDATE_TIME
,
fieldName
))
{
if
(
SqlCommandType
.
INSERT
.
equals
(
sqlCommandType
)
||
SqlCommandType
.
UPDATE
.
equals
(
sqlCommandType
))
{
field
.
setAccessible
(
true
);
//兼容mybatis plus的update
if
(
plus
)
{
Map
<
String
,
Object
>
updateParam
=
(
Map
<
String
,
Object
>)
parameter
;
field
.
set
(
updateParam
.
get
(
"param1"
),
new
Timestamp
(
System
.
currentTimeMillis
()));
}
else
{
String
fieldName
=
null
;
for
(
Field
field
:
declaredFields
)
{
fieldName
=
field
.
getName
();
if
(
Objects
.
equals
(
CREATE_TIME
,
fieldName
))
{
if
(
SqlCommandType
.
INSERT
.
equals
(
sqlCommandType
))
{
try
{
field
.
setAccessible
(
true
);
field
.
set
(
parameter
,
new
Timestamp
(
System
.
currentTimeMillis
()));
}
catch
(
Exception
e
)
{
log
.
warn
(
"添加
修改时间报错"
,
e
);
log
.
warn
(
"添加
创建时间报错"
,
e
);
}
}
}
}
if
(
Objects
.
equals
(
UPDATE_USER_ID
,
fieldName
)&&
StringUtils
.
isNotEmpty
(
currentUserId
)
){
if
(
SqlCommandType
.
INSERT
.
equals
(
sqlCommandType
)
||
SqlCommandType
.
UPDATE
.
equals
(
sqlCommandType
))
{
field
.
setAccessible
(
true
);
//兼容mybatis plus的update
if
(
plus
)
{
Map
<
String
,
Object
>
updateParam
=
(
Map
<
String
,
Object
>)
parameter
;
field
.
set
(
updateParam
.
get
(
"param1"
),
currentUserId
);
}
else
{
if
(
Objects
.
equals
(
CREATE_USER_ID
,
fieldName
)
&&
StringUtils
.
isNotEmpty
(
currentUserId
))
{
if
(
SqlCommandType
.
INSERT
.
equals
(
sqlCommandType
))
{
field
.
setAccessible
(
true
);
field
.
set
(
parameter
,
currentUserId
);
}
}
if
(
Objects
.
equals
(
UPDATE_TIME
,
fieldName
))
{
if
(
SqlCommandType
.
INSERT
.
equals
(
sqlCommandType
)
||
SqlCommandType
.
UPDATE
.
equals
(
sqlCommandType
))
{
field
.
setAccessible
(
true
);
//兼容mybatis plus的update
if
(
plus
)
{
Map
<
String
,
Object
>
updateParam
=
(
Map
<
String
,
Object
>)
parameter
;
field
.
set
(
updateParam
.
get
(
"param1"
),
new
Timestamp
(
System
.
currentTimeMillis
()));
}
else
{
try
{
field
.
set
(
parameter
,
new
Timestamp
(
System
.
currentTimeMillis
()));
}
catch
(
Exception
e
)
{
log
.
warn
(
"添加修改时间报错"
,
e
);
}
}
}
}
if
(
Objects
.
equals
(
UPDATE_USER_ID
,
fieldName
)
&&
StringUtils
.
isNotEmpty
(
currentUserId
))
{
if
(
SqlCommandType
.
INSERT
.
equals
(
sqlCommandType
)
||
SqlCommandType
.
UPDATE
.
equals
(
sqlCommandType
))
{
field
.
setAccessible
(
true
);
//兼容mybatis plus的update
if
(
plus
)
{
Map
<
String
,
Object
>
updateParam
=
(
Map
<
String
,
Object
>)
parameter
;
field
.
set
(
updateParam
.
get
(
"param1"
),
currentUserId
);
}
else
{
field
.
set
(
parameter
,
currentUserId
);
}
}
}
}
}
// //校验登录用户
// for(Method m : ms){
// if(m.getName().equals(methedName)){
...
...
@@ -149,6 +155,7 @@ public class SqlInterceptor extends AbstractSqlParserHandler implements Intercep
// }
// }
// }
}
return
invocation
.
proceed
();
}
...
...
pom.xml
View file @
5efd5675
...
...
@@ -90,12 +90,12 @@
<version>
${mysql.driver.version}
</version>
<scope>
runtime
</scope>
</dependency>
<dependency
>
<groupId>
com.oracle
</groupId
>
<artifactId>
ojdbc14
</artifactId
>
<version>
${oracle.driver.version}
</version
>
<scope>
runtime
</scope
>
</dependency
>
<!-- <dependency>--
>
<!-- <groupId>com.oracle</groupId>--
>
<!-- <artifactId>ojdbc14</artifactId>--
>
<!-- <version>${oracle.driver.version}</version>--
>
<!-- <scope>runtime</scope>--
>
<!-- </dependency>--
>
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
druid
</artifactId>
...
...
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