Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
T
test
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
邬友楠
test
Commits
becb26d0
Commit
becb26d0
authored
Aug 11, 2020
by
雍欢
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化平台日志分页查询功能,目前在单表数据多大的情况下存在分页查询慢的问题
parent
a70b45e6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
331 additions
and
126 deletions
+331
-126
LogApplication.java
.../java/com/huigou/uasp/log/application/LogApplication.java
+3
-2
SlicedQueryStrategy.java
.../com/huigou/uasp/log/application/SlicedQueryStrategy.java
+18
-0
DBLogApplicationImpl.java
...uigou/uasp/log/application/impl/DBLogApplicationImpl.java
+114
-5
InnerJoinSlicedQueryStrategy.java
...sp/log/application/impl/InnerJoinSlicedQueryStrategy.java
+123
-0
LoginLogApplicationImpl.java
...ou/uasp/log/application/impl/LoginLogApplicationImpl.java
+69
-15
OperationLogQueryRequest.java
...uigou/uasp/log/domain/query/OperationLogQueryRequest.java
+4
-104
No files found.
huigou-uasp/src/main/java/com/huigou/uasp/log/application/LogApplication.java
View file @
becb26d0
package
com
.
huigou
.
uasp
.
log
.
application
;
package
com
.
huigou
.
uasp
.
log
.
application
;
import
java.util.Map
;
import
com.huigou.uasp.log.domain.model.BizLog
;
import
com.huigou.uasp.log.domain.model.BizLog
;
import
com.huigou.uasp.log.domain.model.BizLogDetail
;
import
com.huigou.uasp.log.domain.model.BizLogDetail
;
import
com.huigou.uasp.log.domain.query.OperationLogQueryRequest
;
import
com.huigou.uasp.log.domain.query.OperationLogQueryRequest
;
import
java.util.Map
;
/**
/**
* 日志接口
* 日志接口
*
*
* @author
* @author
*/
*/
public
interface
LogApplication
{
public
interface
LogApplication
{
/**
/**
* 查询文件配置地址
* 查询文件配置地址
*/
*/
...
...
huigou-uasp/src/main/java/com/huigou/uasp/log/application/SlicedQueryStrategy.java
0 → 100644
View file @
becb26d0
package
com
.
huigou
.
uasp
.
log
.
application
;
import
com.huigou.data.domain.query.QueryAbstractRequest
;
import
java.util.Map
;
/**
* 单表分页查询策略。
*
* @author yonghuan
*/
public
interface
SlicedQueryStrategy
{
boolean
supports
(
String
tableName
,
QueryAbstractRequest
queryRequest
);
Map
<
String
,
Object
>
slicedQuery
(
String
tableName
,
QueryAbstractRequest
queryRequest
,
String
whereClause
,
Object
[]
args
);
}
huigou-uasp/src/main/java/com/huigou/uasp/log/application/impl/DBLogApplicationImpl.java
View file @
becb26d0
...
@@ -8,6 +8,7 @@ import com.huigou.data.query.model.QueryDescriptor;
...
@@ -8,6 +8,7 @@ import com.huigou.data.query.model.QueryDescriptor;
import
com.huigou.data.query.model.QueryModel
;
import
com.huigou.data.query.model.QueryModel
;
import
com.huigou.uasp.bmp.opm.repository.org.TMAuthorizeRepository
;
import
com.huigou.uasp.bmp.opm.repository.org.TMAuthorizeRepository
;
import
com.huigou.uasp.log.application.LogApplication
;
import
com.huigou.uasp.log.application.LogApplication
;
import
com.huigou.uasp.log.application.SlicedQueryStrategy
;
import
com.huigou.uasp.log.domain.model.BizLog
;
import
com.huigou.uasp.log.domain.model.BizLog
;
import
com.huigou.uasp.log.domain.model.BizLogDetail
;
import
com.huigou.uasp.log.domain.model.BizLogDetail
;
import
com.huigou.uasp.log.domain.model.DBBizLog
;
import
com.huigou.uasp.log.domain.model.DBBizLog
;
...
@@ -24,8 +25,7 @@ import org.springframework.transaction.annotation.Propagation;
...
@@ -24,8 +25,7 @@ import org.springframework.transaction.annotation.Propagation;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.util.Assert
;
import
org.springframework.util.Assert
;
import
java.util.HashMap
;
import
java.util.*
;
import
java.util.Map
;
/**
/**
* 日志应用
* 日志应用
...
@@ -49,6 +49,8 @@ public class DBLogApplicationImpl implements LogApplication {
...
@@ -49,6 +49,8 @@ public class DBLogApplicationImpl implements LogApplication {
@Autowired
@Autowired
private
TmspmConifg
tmspmConifg
;
private
TmspmConifg
tmspmConifg
;
@Autowired
private
SlicedQueryStrategy
slicedQueryStrategy
;
@Transactional
(
rollbackFor
=
RuntimeException
.
class
,
propagation
=
Propagation
.
REQUIRES_NEW
)
@Transactional
(
rollbackFor
=
RuntimeException
.
class
,
propagation
=
Propagation
.
REQUIRES_NEW
)
@Override
@Override
...
@@ -71,8 +73,7 @@ public class DBLogApplicationImpl implements LogApplication {
...
@@ -71,8 +73,7 @@ public class DBLogApplicationImpl implements LogApplication {
Assert
.
hasText
(
id
,
MessageSourceContext
.
getMessage
(
MessageConstants
.
ID_NOT_BLANK
));
Assert
.
hasText
(
id
,
MessageSourceContext
.
getMessage
(
MessageConstants
.
ID_NOT_BLANK
));
DBBizLog
dbBizLog
=
this
.
dbBizLogRepository
.
findOne
(
id
);
DBBizLog
dbBizLog
=
this
.
dbBizLogRepository
.
findOne
(
id
);
DBBizLogDetail
dbBizLogDetail
=
this
.
dbBizLogDetailRepository
.
findByBizLogId
(
dbBizLog
.
getId
());
DBBizLogDetail
dbBizLogDetail
=
this
.
dbBizLogDetailRepository
.
findByBizLogId
(
dbBizLog
.
getId
());
Map
<
String
,
Object
>
data
=
new
HashMap
<
String
,
Object
>();
Map
<
String
,
Object
>
data
=
ClassHelper
.
toMap
(
dbBizLog
);
data
=
ClassHelper
.
toMap
(
dbBizLog
);
if
(
dbBizLogDetail
!=
null
)
{
if
(
dbBizLogDetail
!=
null
)
{
data
.
putAll
(
ClassHelper
.
toMap
(
dbBizLogDetail
));
data
.
putAll
(
ClassHelper
.
toMap
(
dbBizLogDetail
));
}
}
...
@@ -83,7 +84,10 @@ public class DBLogApplicationImpl implements LogApplication {
...
@@ -83,7 +84,10 @@ public class DBLogApplicationImpl implements LogApplication {
public
Map
<
String
,
Object
>
slicedQueryOperationLogs
(
OperationLogQueryRequest
queryRequest
)
{
public
Map
<
String
,
Object
>
slicedQueryOperationLogs
(
OperationLogQueryRequest
queryRequest
)
{
Assert
.
notNull
(
queryRequest
,
MessageSourceContext
.
getMessage
(
MessageConstants
.
PARAMETER_NOT_NULL_FORMAT
,
"queryRequest"
));
Assert
.
notNull
(
queryRequest
,
MessageSourceContext
.
getMessage
(
MessageConstants
.
PARAMETER_NOT_NULL_FORMAT
,
"queryRequest"
));
if
(!
queryRequest
.
allowQuery
())
{
if
(!
queryRequest
.
allowQuery
())
{
return
new
HashMap
<
String
,
Object
>(
1
);
return
Collections
.
emptyMap
();
}
if
(
slicedQueryStrategy
.
supports
(
"sa_operationlog"
,
queryRequest
))
{
return
slicedQueryOperationLogs1
(
queryRequest
);
}
}
QueryModel
queryModel
=
queryRequest
.
initQueryModel
();
QueryModel
queryModel
=
queryRequest
.
initQueryModel
();
...
@@ -204,6 +208,111 @@ public class DBLogApplicationImpl implements LogApplication {
...
@@ -204,6 +208,111 @@ public class DBLogApplicationImpl implements LogApplication {
return
this
.
sqlExecutorDao
.
executeSlicedQuery
(
queryModel
);
return
this
.
sqlExecutorDao
.
executeSlicedQuery
(
queryModel
);
}
}
public
Map
<
String
,
Object
>
slicedQueryOperationLogs1
(
OperationLogQueryRequest
queryRequest
)
{
Map
<
String
,
String
>
map
=
queryRequest
.
getLogQueryCriteria
(
tmAuthorizeRepository
,
tmspmConifg
.
isEnableTspm
());
String
targetRoleKindId
=
map
.
get
(
"targetRoleKindId"
);
String
targetStatusId
=
map
.
get
(
"targetStatusId"
);
String
targetFullId
=
map
.
get
(
"targetFullId"
);
String
targetAppId
=
map
.
get
(
"targetAppId"
);
StringBuilder
whereClause
=
new
StringBuilder
(
"where 1=1 "
);
List
<
Object
>
parameters
=
new
ArrayList
<>(
16
);
int
i
=
0
;
if
(
StringUtil
.
isNotBlank
(
targetRoleKindId
))
{
String
[]
targetRoleKindIds
=
targetRoleKindId
.
split
(
StringPool
.
COMMA
);
whereClause
.
append
(
" and t.Role_Kind_Id in ("
);
for
(
String
item
:
targetRoleKindIds
)
{
if
(
i
++
<
targetRoleKindIds
.
length
-
1
)
{
whereClause
.
append
(
"?,"
);
}
else
{
whereClause
.
append
(
"?"
);
}
parameters
.
add
(
item
);
}
whereClause
.
append
(
")"
);
}
if
(
targetAppId
.
indexOf
(
StringPool
.
STAR
)
<
0
&&
StringUtil
.
isNotBlank
(
targetAppId
))
{
String
[]
targetAppIds
=
targetAppId
.
split
(
StringPool
.
COMMA
);
i
=
0
;
whereClause
.
append
(
"and t.App_Id in ("
);
for
(
String
item
:
targetAppIds
)
{
if
(
i
++
<
targetAppIds
.
length
-
1
)
{
whereClause
.
append
(
"?,"
);
}
else
{
whereClause
.
append
(
"?"
);
}
parameters
.
add
(
item
);
}
whereClause
.
append
(
")"
);
}
if
(
targetFullId
.
indexOf
(
StringPool
.
STAR
)
<
0
&&
StringUtil
.
isNotBlank
(
targetFullId
))
{
String
[]
targetFullIds
=
targetFullId
.
split
(
StringPool
.
COMMA
);
i
=
0
;
for
(
String
item
:
targetFullIds
)
{
if
(
i
++
==
0
)
{
whereClause
.
append
(
" and (t.Full_Id like ?"
);
}
else
{
whereClause
.
append
(
" or t.Full_Id like ?"
);
}
parameters
.
add
(
item
+
"%"
);
}
whereClause
.
append
(
")"
);
}
if
(
StringUtil
.
isNotBlank
(
queryRequest
.
getRoleKindId
()))
{
whereClause
.
append
(
" and t.Role_Kind_Id = ?"
);
parameters
.
add
(
queryRequest
.
getRoleKindId
());
}
if
(
StringUtil
.
isNotBlank
(
queryRequest
.
getFullId
()))
{
whereClause
.
append
(
" and t.Full_Id like ?"
);
parameters
.
add
(
queryRequest
.
getFullId
()
+
"%"
);
}
if
(
StringUtil
.
isNotBlank
(
queryRequest
.
getAppName
()))
{
whereClause
.
append
(
" and t.App_Name like ?"
);
parameters
.
add
(
"%"
+
queryRequest
.
getAppName
()
+
"%"
);
}
if
(
StringUtil
.
isNotBlank
(
targetStatusId
))
{
whereClause
.
append
(
" and t.Status_Id = ?"
);
parameters
.
add
(
targetStatusId
);
}
else
if
(
StringUtil
.
isNotBlank
(
queryRequest
.
getStatusId
()))
{
whereClause
.
append
(
" and t.Status_Id = ?"
);
parameters
.
add
(
queryRequest
.
getStatusId
());
}
if
(
StringUtil
.
isNotBlank
(
queryRequest
.
getDescription
()))
{
whereClause
.
append
(
" and t.Description like ?"
);
parameters
.
add
(
"%"
+
queryRequest
.
getDescription
()
+
"%"
);
}
if
(
StringUtil
.
isNotBlank
(
queryRequest
.
getIp
()))
{
whereClause
.
append
(
" and t.IP = ?"
);
parameters
.
add
(
"%"
+
queryRequest
.
getIp
()
+
"%"
);
}
if
(
StringUtil
.
isNotBlank
(
queryRequest
.
getPersonMemberName
()))
{
whereClause
.
append
(
" and t.Person_Member_Name like ?"
);
parameters
.
add
(
"%"
+
queryRequest
.
getPersonMemberName
()
+
"%"
);
}
if
(
queryRequest
.
getBeginDate
()
!=
null
)
{
whereClause
.
append
(
" and t.Begin_Date >= ?"
);
parameters
.
add
(
queryRequest
.
getBeginDate
());
}
if
(
queryRequest
.
getEndDate
()
!=
null
)
{
whereClause
.
append
(
" and t.End_Date <= ?"
);
parameters
.
add
(
queryRequest
.
getEndDate
());
}
if
(
StringUtil
.
isNotBlank
(
queryRequest
.
getLogType
()))
{
whereClause
.
append
(
" and t.Log_Type = ?"
);
parameters
.
add
(
queryRequest
.
getLogType
());
}
if
(
StringUtil
.
isNotBlank
(
queryRequest
.
getOperationType
()))
{
whereClause
.
append
(
" and t.Operate_Name = ?"
);
parameters
.
add
(
queryRequest
.
getOperationType
());
}
return
slicedQueryStrategy
.
slicedQuery
(
"sa_operationlog"
,
queryRequest
,
whereClause
.
toString
(),
parameters
.
toArray
());
}
/*
/*
@Override
@Override
public Map<String, Object> slicedQueryOperationLogs(String operatorRoleKindId, String roleKindId, String appName, String fullId, String statusId,
public Map<String, Object> slicedQueryOperationLogs(String operatorRoleKindId, String roleKindId, String appName, String fullId, String statusId,
...
...
huigou-uasp/src/main/java/com/huigou/uasp/log/application/impl/InnerJoinSlicedQueryStrategy.java
0 → 100644
View file @
becb26d0
package
com
.
huigou
.
uasp
.
log
.
application
.
impl
;
import
com.huigou.data.dialect.Dialect
;
import
com.huigou.data.dialect.DialectUtils
;
import
com.huigou.data.domain.query.QueryAbstractRequest
;
import
com.huigou.data.domain.query.QueryPageRequest
;
import
com.huigou.data.jdbc.util.RowSetUtil
;
import
com.huigou.data.jdbc.util.SQLRowSetOracleResultSetExtractor
;
import
com.huigou.data.query.model.QueryModel
;
import
com.huigou.uasp.log.application.SlicedQueryStrategy
;
import
com.huigou.util.Constants
;
import
org.apache.commons.lang3.ArrayUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.domain.PageRequest
;
import
org.springframework.jdbc.core.JdbcTemplate
;
import
org.springframework.jdbc.core.ResultSetExtractor
;
import
org.springframework.jdbc.core.SqlRowSetResultSetExtractor
;
import
org.springframework.jdbc.support.rowset.SqlRowSet
;
import
org.springframework.stereotype.Component
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
/**
* 使用inner join方式实现分页查询,SQL格式如下:
* <p>select t.* from t inner join (select t.id from t where t.name like 'xx%' order by create_date desc limit 20,40) lim on t.id=lim.id</p>
*
* @author yonghuan
*/
@Component
public
class
InnerJoinSlicedQueryStrategy
implements
SlicedQueryStrategy
{
private
final
static
Logger
LOG
=
LoggerFactory
.
getLogger
(
InnerJoinSlicedQueryStrategy
.
class
);
private
JdbcTemplate
jdbcTemplate
;
@Autowired
public
void
setJdbcTemplate
(
JdbcTemplate
jdbcTemplate
)
{
this
.
jdbcTemplate
=
jdbcTemplate
;
}
@Override
public
boolean
supports
(
String
tableName
,
QueryAbstractRequest
queryRequest
)
{
QueryModel
queryModel
=
queryRequest
.
initQueryModel
();
if
(
queryModel
.
isExportQuery
())
{
return
false
;
}
Dialect
dialect
=
DialectUtils
.
guessDialect
(
jdbcTemplate
.
getDataSource
());
return
(
dialect
.
isOracleFamily
()
||
dialect
.
isMySqlFamily
());
}
@Override
public
Map
<
String
,
Object
>
slicedQuery
(
String
tableName
,
QueryAbstractRequest
queryRequest
,
String
whereClause
,
Object
[]
args
)
{
QueryModel
queryModel
=
queryRequest
.
initQueryModel
();
QueryPageRequest
pageModel
=
queryRequest
.
getPageModel
();
String
countSql
=
new
StringBuilder
(
"select count(*) from "
+
tableName
+
" t "
)
.
append
(
whereClause
).
toString
();
long
count
=
jdbcTemplate
.
queryForObject
(
countSql
,
Long
.
class
,
args
);
LOG
.
info
(
countSql
);
LOG
.
info
(
"SQL Parameters: {}"
,
ArrayUtils
.
toString
(
args
));
List
<?>
rows
=
Collections
.
emptyList
();
if
(
count
>
0
)
{
StringBuilder
innerSql
=
new
StringBuilder
(
"select t.id from "
).
append
(
tableName
).
append
(
" t "
)
.
append
(
whereClause
);
String
sortOrders
=
queryModel
.
getSortFieldList
().
stream
()
.
map
(
sortField
->
String
.
format
(
"%s %s"
,
sortField
.
getColumnName
(),
sortField
.
getDirection
()))
.
distinct
()
.
collect
(
Collectors
.
joining
(
","
));
if
(
StringUtils
.
isNotBlank
(
sortOrders
))
{
innerSql
.
append
(
" order by "
).
append
(
sortOrders
);
}
if
(
pageModel
!=
null
)
{
Dialect
dialect
=
DialectUtils
.
guessDialect
(
jdbcTemplate
.
getDataSource
());
PageRequest
pageRequest
=
new
PageRequest
(
pageModel
.
getPageIndex
()
-
1
,
pageModel
.
getPageSize
());
if
(
dialect
.
isOracleFamily
())
{
// Oracle分页
innerSql
=
new
StringBuilder
(
"select t_t_.id from (select t_.id,rownum as rownum_ from ("
)
.
append
(
innerSql
)
.
append
(
") t_ where rownum<="
+
(
pageRequest
.
getOffset
()
+
pageRequest
.
getPageSize
()))
.
append
(
") t_t_ where t_t_.rownum_>="
+
pageRequest
.
getOffset
());
}
else
if
(
dialect
.
isMySqlFamily
())
{
// MySQL分页
innerSql
.
append
(
String
.
format
(
" limit %s,%s "
,
pageRequest
.
getOffset
(),
pageRequest
.
getPageSize
()));
}
}
String
sql
=
new
StringBuilder
(
"select log.* from "
)
.
append
(
tableName
)
.
append
(
" log inner join ("
)
.
append
(
innerSql
)
.
append
(
") lim on log.id=lim.id"
)
.
append
(
" order by "
)
.
append
(
sortOrders
)
.
toString
();
LOG
.
info
(
sql
);
LOG
.
info
(
"SQL Parameters: {}"
,
ArrayUtils
.
toString
(
args
));
SqlRowSet
srs
=
(
SqlRowSet
)
jdbcTemplate
.
query
(
sql
,
args
,
getResultSetExtractor
());
rows
=
RowSetUtil
.
toMapList
(
srs
);
}
Map
<
String
,
Object
>
result
=
new
HashMap
<>(
3
);
result
.
put
(
Constants
.
ROWS
,
rows
);
result
.
put
(
Constants
.
RECORD
,
count
);
if
(
pageModel
!=
null
)
{
result
.
put
(
Constants
.
PAGE_PARAM_NAME
,
pageModel
.
getPageIndex
());
}
return
result
;
}
private
ResultSetExtractor
<?>
getResultSetExtractor
()
{
Dialect
dialect
=
DialectUtils
.
guessDialect
(
jdbcTemplate
.
getDataSource
());
if
(
dialect
.
isOracleFamily
())
{
return
new
SQLRowSetOracleResultSetExtractor
();
}
return
new
SqlRowSetResultSetExtractor
();
}
}
huigou-uasp/src/main/java/com/huigou/uasp/log/application/impl/LoginLogApplicationImpl.java
View file @
becb26d0
package
com
.
huigou
.
uasp
.
log
.
application
.
impl
;
package
com
.
huigou
.
uasp
.
log
.
application
.
impl
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Map
;
import
org.apache.shiro.session.Session
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.util.Assert
;
import
com.huigou.context.ContextUtil
;
import
com.huigou.context.ContextUtil
;
import
com.huigou.context.Operator
;
import
com.huigou.context.Operator
;
import
com.huigou.context.TmspmConifg
;
import
com.huigou.context.TmspmConifg
;
...
@@ -21,6 +9,7 @@ import com.huigou.uasp.bmp.common.application.BaseApplication;
...
@@ -21,6 +9,7 @@ import com.huigou.uasp.bmp.common.application.BaseApplication;
import
com.huigou.uasp.bmp.opm.LoginStatus
;
import
com.huigou.uasp.bmp.opm.LoginStatus
;
import
com.huigou.uasp.bmp.opm.repository.org.TMAuthorizeRepository
;
import
com.huigou.uasp.bmp.opm.repository.org.TMAuthorizeRepository
;
import
com.huigou.uasp.log.application.LoginLogApplication
;
import
com.huigou.uasp.log.application.LoginLogApplication
;
import
com.huigou.uasp.log.application.SlicedQueryStrategy
;
import
com.huigou.uasp.log.domain.model.HistoricSession
;
import
com.huigou.uasp.log.domain.model.HistoricSession
;
import
com.huigou.uasp.log.domain.model.LogoutKind
;
import
com.huigou.uasp.log.domain.model.LogoutKind
;
import
com.huigou.uasp.log.domain.model.OnlineSession
;
import
com.huigou.uasp.log.domain.model.OnlineSession
;
...
@@ -32,6 +21,16 @@ import com.huigou.uasp.log.util.BizLogUtil;
...
@@ -32,6 +21,16 @@ import com.huigou.uasp.log.util.BizLogUtil;
import
com.huigou.util.ClassHelper
;
import
com.huigou.util.ClassHelper
;
import
com.huigou.util.Constants
;
import
com.huigou.util.Constants
;
import
com.huigou.util.StringUtil
;
import
com.huigou.util.StringUtil
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.shiro.session.Session
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.util.Assert
;
import
java.util.*
;
@Service
(
"loginLogApplication"
)
@Service
(
"loginLogApplication"
)
public
class
LoginLogApplicationImpl
extends
BaseApplication
implements
LoginLogApplication
{
public
class
LoginLogApplicationImpl
extends
BaseApplication
implements
LoginLogApplication
{
...
@@ -47,6 +46,8 @@ public class LoginLogApplicationImpl extends BaseApplication implements LoginLog
...
@@ -47,6 +46,8 @@ public class LoginLogApplicationImpl extends BaseApplication implements LoginLog
@Autowired
@Autowired
private
HistoricSessionRepository
historicSessionRepository
;
private
HistoricSessionRepository
historicSessionRepository
;
@Autowired
private
SlicedQueryStrategy
slicedQueryStrategy
;
@Override
@Override
@Transactional
@Transactional
...
@@ -89,11 +90,14 @@ public class LoginLogApplicationImpl extends BaseApplication implements LoginLog
...
@@ -89,11 +90,14 @@ public class LoginLogApplicationImpl extends BaseApplication implements LoginLog
@Override
@Override
public
Map
<
String
,
Object
>
sliceQueryHistoricSessions
(
LoginQueryRequest
queryRequest
)
{
public
Map
<
String
,
Object
>
sliceQueryHistoricSessions
(
LoginQueryRequest
queryRequest
)
{
if
(
StringUtil
.
isBlank
(
queryRequest
.
getOperatorRoleKindId
())
||
StringUtil
.
isBlank
(
queryRequest
.
getPersonMemberId
()))
{
if
(
StringUtil
.
isBlank
(
queryRequest
.
getOperatorRoleKindId
())
||
StringUtil
.
isBlank
(
queryRequest
.
getPersonMemberId
()))
{
return
null
;
return
Collections
.
emptyMap
()
;
}
}
Map
<
String
,
String
>
map
=
BizLogUtil
.
getLogQueryCriteria
(
queryRequest
.
getOperatorRoleKindId
(),
tmAuthorizeRepository
,
queryRequest
.
getPersonMemberId
(),
Map
<
String
,
String
>
map
=
BizLogUtil
.
getLogQueryCriteria
(
queryRequest
.
getOperatorRoleKindId
(),
tmAuthorizeRepository
,
queryRequest
.
getPersonMemberId
(),
tmspmConifg
.
isEnableTspm
());
tmspmConifg
.
isEnableTspm
());
String
targetFullId
=
map
.
get
(
"targetFullId"
);
String
targetFullId
=
map
.
get
(
"targetFullId"
);
if
(
slicedQueryStrategy
.
supports
(
"sa_historicsession"
,
queryRequest
))
{
return
sliceQueryHistoricSessions1
(
queryRequest
,
targetFullId
);
}
QueryDescriptor
queryDescriptor
=
this
.
sqlExecutorDao
.
getQuery
(
QUERY_XML_FILE_PATH
,
"log"
);
QueryDescriptor
queryDescriptor
=
this
.
sqlExecutorDao
.
getQuery
(
QUERY_XML_FILE_PATH
,
"log"
);
QueryModel
queryModel
=
this
.
sqlExecutorDao
.
getQueryModel
(
queryDescriptor
,
queryRequest
);
QueryModel
queryModel
=
this
.
sqlExecutorDao
.
getQueryModel
(
queryDescriptor
,
queryRequest
);
if
(
targetFullId
.
indexOf
(
"*"
)
<
0
&&
StringUtil
.
isNotBlank
(
targetFullId
))
{
if
(
targetFullId
.
indexOf
(
"*"
)
<
0
&&
StringUtil
.
isNotBlank
(
targetFullId
))
{
...
@@ -124,6 +128,56 @@ public class LoginLogApplicationImpl extends BaseApplication implements LoginLog
...
@@ -124,6 +128,56 @@ public class LoginLogApplicationImpl extends BaseApplication implements LoginLog
return
this
.
sqlExecutorDao
.
executeSlicedQuery
(
queryModel
);
return
this
.
sqlExecutorDao
.
executeSlicedQuery
(
queryModel
);
}
}
private
Map
<
String
,
Object
>
sliceQueryHistoricSessions1
(
LoginQueryRequest
queryRequest
,
String
targetFullId
)
{
StringBuilder
whereClause
=
new
StringBuilder
(
" where 1=1 "
);
List
<
Object
>
queryParameters
=
new
ArrayList
<>(
4
);
if
(
targetFullId
.
indexOf
(
"*"
)
<
0
&&
StringUtil
.
isNotBlank
(
targetFullId
))
{
String
[]
targetFullIds
=
targetFullId
.
split
(
","
);
int
i
=
0
;
whereClause
.
append
(
" and ("
);
for
(
String
item
:
targetFullIds
)
{
if
(
i
==
0
)
{
whereClause
.
append
(
"Full_Id like ?"
);
}
else
{
whereClause
.
append
(
" or Full_Id like ?"
);
}
queryParameters
.
add
(
item
+
"%"
);
i
++;
}
whereClause
.
append
(
")"
);
}
if
(
queryRequest
.
isQueryInvalidLoginName
())
{
whereClause
.
append
(
" and status != ? and organ_id is null "
);
queryParameters
.
add
(
LoginStatus
.
SUCCESS
.
getId
());
}
if
(
StringUtils
.
isNotBlank
(
queryRequest
.
getFullId
()))
{
whereClause
.
append
(
" and full_id like ? "
);
queryParameters
.
add
(
queryRequest
.
getFullId
()
+
"%"
);
}
if
(
StringUtils
.
isNotBlank
(
queryRequest
.
getLoginName
()))
{
whereClause
.
append
(
" and login_name like ? "
);
queryParameters
.
add
(
"%"
+
queryRequest
.
getLoginName
()
+
"%"
);
}
if
(
StringUtils
.
isNotBlank
(
queryRequest
.
getIp
()))
{
whereClause
.
append
(
" and client_ip like ? "
);
queryParameters
.
add
(
"%"
+
queryRequest
.
getIp
()
+
"%"
);
}
if
(
queryRequest
.
getBeginDate
()
!=
null
)
{
whereClause
.
append
(
" and login_Date >= ? "
);
queryParameters
.
add
(
queryRequest
.
getBeginDate
());
}
if
(
queryRequest
.
getEndDate
()
!=
null
)
{
whereClause
.
append
(
" and login_Date <= ? "
);
queryParameters
.
add
(
queryRequest
.
getEndDate
());
}
if
(
StringUtils
.
isNotBlank
(
queryRequest
.
getPersonName
()))
{
whereClause
.
append
(
" and person_member_name like ? "
);
queryParameters
.
add
(
"%"
+
queryRequest
.
getPersonName
()
+
"%"
);
}
return
slicedQueryStrategy
.
slicedQuery
(
"sa_historicsession"
,
queryRequest
,
whereClause
.
toString
(),
queryParameters
.
toArray
());
}
@Override
@Override
@Transactional
@Transactional
public
void
logout
(
Session
session
,
LogoutKind
logoutKind
)
{
public
void
logout
(
Session
session
,
LogoutKind
logoutKind
)
{
...
...
huigou-uasp/src/main/java/com/huigou/uasp/log/domain/query/OperationLogQueryRequest.java
View file @
becb26d0
...
@@ -6,6 +6,8 @@ import java.util.HashMap;
...
@@ -6,6 +6,8 @@ import java.util.HashMap;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
lombok.Getter
;
import
lombok.Setter
;
import
org.springframework.util.Assert
;
import
org.springframework.util.Assert
;
import
com.huigou.context.RoleKind
;
import
com.huigou.context.RoleKind
;
...
@@ -21,6 +23,8 @@ import com.huigou.util.StringUtil;
...
@@ -21,6 +23,8 @@ import com.huigou.util.StringUtil;
*
*
* @author gongmm
* @author gongmm
*/
*/
@Getter
@Setter
public
class
OperationLogQueryRequest
extends
QueryAbstractRequest
{
public
class
OperationLogQueryRequest
extends
QueryAbstractRequest
{
private
String
operatorRoleKindId
;
private
String
operatorRoleKindId
;
...
@@ -49,110 +53,6 @@ public class OperationLogQueryRequest extends QueryAbstractRequest {
...
@@ -49,110 +53,6 @@ public class OperationLogQueryRequest extends QueryAbstractRequest {
private
Date
endDate
;
private
Date
endDate
;
public
String
getOperatorRoleKindId
()
{
return
operatorRoleKindId
;
}
public
void
setOperatorRoleKindId
(
String
operatorRoleKindId
)
{
this
.
operatorRoleKindId
=
operatorRoleKindId
;
}
public
String
getRoleKindId
()
{
return
roleKindId
;
}
public
void
setRoleKindId
(
String
roleKindId
)
{
this
.
roleKindId
=
roleKindId
;
}
public
String
getAppName
()
{
return
appName
;
}
public
void
setAppName
(
String
appName
)
{
this
.
appName
=
appName
;
}
public
String
getFullId
()
{
return
fullId
;
}
public
void
setFullId
(
String
fullId
)
{
this
.
fullId
=
fullId
;
}
public
String
getStatusId
()
{
return
statusId
;
}
public
void
setStatusId
(
String
statusId
)
{
this
.
statusId
=
statusId
;
}
public
String
getDescription
()
{
return
description
;
}
public
void
setDescription
(
String
description
)
{
this
.
description
=
description
;
}
public
String
getLogType
()
{
return
logType
;
}
public
void
setLogType
(
String
logType
)
{
this
.
logType
=
logType
;
}
public
String
getOperationType
()
{
return
operationType
;
}
public
void
setOperationType
(
String
operationType
)
{
this
.
operationType
=
operationType
;
}
public
String
getIp
()
{
return
ip
;
}
public
void
setIp
(
String
ip
)
{
this
.
ip
=
ip
;
}
public
String
getPersonMemberId
()
{
return
personMemberId
;
}
public
void
setPersonMemberId
(
String
personMemberId
)
{
this
.
personMemberId
=
personMemberId
;
}
public
String
getPersonMemberName
()
{
return
personMemberName
;
}
public
void
setPersonMemberName
(
String
personMemberName
)
{
this
.
personMemberName
=
personMemberName
;
}
public
Date
getBeginDate
()
{
return
beginDate
;
}
public
void
setBeginDate
(
Date
beginDate
)
{
this
.
beginDate
=
beginDate
;
}
public
Date
getEndDate
()
{
return
endDate
;
}
public
void
setEndDate
(
Date
endDate
)
{
this
.
endDate
=
endDate
;
}
public
boolean
allowQuery
()
{
public
boolean
allowQuery
()
{
return
StringUtil
.
isNotBlank
(
operatorRoleKindId
)
&&
StringUtil
.
isNotBlank
(
personMemberId
);
return
StringUtil
.
isNotBlank
(
operatorRoleKindId
)
&&
StringUtil
.
isNotBlank
(
personMemberId
);
}
}
...
...
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