Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
Eladmin
Commits
bf7c1eeb
Commit
bf7c1eeb
authored
Oct 24, 2019
by
dqjdda
Browse files
代码优化完成,去除大量idea警告,代码生成器优化等
parent
e3c3ebb1
Changes
146
Hide whitespace changes
Inline
Side-by-side
eladmin-generator/src/main/java/me/zhengjie/service/impl/GeneratorServiceImpl.java
View file @
bf7c1eeb
...
@@ -37,10 +37,11 @@ public class GeneratorServiceImpl implements GeneratorService {
...
@@ -37,10 +37,11 @@ public class GeneratorServiceImpl implements GeneratorService {
query
.
setFirstResult
(
startEnd
[
0
]);
query
.
setFirstResult
(
startEnd
[
0
]);
query
.
setMaxResults
(
startEnd
[
1
]-
startEnd
[
0
]);
query
.
setMaxResults
(
startEnd
[
1
]-
startEnd
[
0
]);
query
.
setParameter
(
1
,
StringUtils
.
isNotBlank
(
name
)
?
(
"%"
+
name
+
"%"
)
:
"%%"
);
query
.
setParameter
(
1
,
StringUtils
.
isNotBlank
(
name
)
?
(
"%"
+
name
+
"%"
)
:
"%%"
);
List
<
Object
[]>
result
=
query
.
getResultList
();
List
result
=
query
.
getResultList
();
List
<
TableInfo
>
tableInfos
=
new
ArrayList
<>();
List
<
TableInfo
>
tableInfos
=
new
ArrayList
<>();
for
(
Object
[]
obj
:
result
)
{
for
(
Object
obj
:
result
)
{
tableInfos
.
add
(
new
TableInfo
(
obj
[
0
],
obj
[
1
],
obj
[
2
],
obj
[
3
],
ObjectUtil
.
isNotEmpty
(
obj
[
4
])?
obj
[
4
]
:
"-"
));
Object
[]
arr
=
(
Object
[])
obj
;
tableInfos
.
add
(
new
TableInfo
(
arr
[
0
],
arr
[
1
],
arr
[
2
],
arr
[
3
],
ObjectUtil
.
isNotEmpty
(
arr
[
4
])?
arr
[
4
]
:
"-"
));
}
}
Query
query1
=
em
.
createNativeQuery
(
"SELECT COUNT(*) from information_schema.tables where table_schema = (select database())"
);
Query
query1
=
em
.
createNativeQuery
(
"SELECT COUNT(*) from information_schema.tables where table_schema = (select database())"
);
Object
totalElements
=
query1
.
getSingleResult
();
Object
totalElements
=
query1
.
getSingleResult
();
...
@@ -54,10 +55,11 @@ public class GeneratorServiceImpl implements GeneratorService {
...
@@ -54,10 +55,11 @@ public class GeneratorServiceImpl implements GeneratorService {
"where table_name = ? and table_schema = (select database()) order by ordinal_position"
;
"where table_name = ? and table_schema = (select database()) order by ordinal_position"
;
Query
query
=
em
.
createNativeQuery
(
sql
);
Query
query
=
em
.
createNativeQuery
(
sql
);
query
.
setParameter
(
1
,
StringUtils
.
isNotBlank
(
name
)
?
name
:
null
);
query
.
setParameter
(
1
,
StringUtils
.
isNotBlank
(
name
)
?
name
:
null
);
List
<
Object
[]>
result
=
query
.
getResultList
();
List
result
=
query
.
getResultList
();
List
<
ColumnInfo
>
columnInfos
=
new
ArrayList
<>();
List
<
ColumnInfo
>
columnInfos
=
new
ArrayList
<>();
for
(
Object
[]
obj
:
result
)
{
for
(
Object
obj
:
result
)
{
columnInfos
.
add
(
new
ColumnInfo
(
obj
[
0
],
obj
[
1
],
obj
[
2
],
obj
[
3
],
obj
[
4
],
obj
[
5
],
null
,
"true"
));
Object
[]
arr
=
(
Object
[])
obj
;
columnInfos
.
add
(
new
ColumnInfo
(
arr
[
0
],
arr
[
1
],
arr
[
2
],
arr
[
3
],
arr
[
4
],
arr
[
5
],
null
,
"true"
));
}
}
return
PageUtil
.
toPage
(
columnInfos
,
columnInfos
.
size
());
return
PageUtil
.
toPage
(
columnInfos
,
columnInfos
.
size
());
}
}
...
...
eladmin-generator/src/main/java/me/zhengjie/utils/ColUtil.java
View file @
bf7c1eeb
...
@@ -12,11 +12,12 @@ public class ColUtil {
...
@@ -12,11 +12,12 @@ public class ColUtil {
/**
/**
* 转换mysql数据类型为java数据类型
* 转换mysql数据类型为java数据类型
* @param type
* @param type
数据库字段类型
* @return
* @return
String
*/
*/
public
static
String
cloToJava
(
String
type
){
static
String
cloToJava
(
String
type
){
Configuration
config
=
getConfig
();
Configuration
config
=
getConfig
();
assert
config
!=
null
;
return
config
.
getString
(
type
,
"unknowType"
);
return
config
.
getString
(
type
,
"unknowType"
);
}
}
...
...
eladmin-generator/src/main/java/me/zhengjie/utils/GenUtil.java
View file @
bf7c1eeb
...
@@ -34,9 +34,9 @@ public class GenUtil {
...
@@ -34,9 +34,9 @@ public class GenUtil {
/**
/**
* 获取后端代码模板名称
* 获取后端代码模板名称
* @return
* @return
List
*/
*/
p
ublic
static
List
<
String
>
getAdminTemplateNames
()
{
p
rivate
static
List
<
String
>
getAdminTemplateNames
()
{
List
<
String
>
templateNames
=
new
ArrayList
<>();
List
<
String
>
templateNames
=
new
ArrayList
<>();
templateNames
.
add
(
"Entity"
);
templateNames
.
add
(
"Entity"
);
templateNames
.
add
(
"Dto"
);
templateNames
.
add
(
"Dto"
);
...
@@ -51,9 +51,9 @@ public class GenUtil {
...
@@ -51,9 +51,9 @@ public class GenUtil {
/**
/**
* 获取前端代码模板名称
* 获取前端代码模板名称
* @return
* @return
List
*/
*/
p
ublic
static
List
<
String
>
getFrontTemplateNames
()
{
p
rivate
static
List
<
String
>
getFrontTemplateNames
()
{
List
<
String
>
templateNames
=
new
ArrayList
<>();
List
<
String
>
templateNames
=
new
ArrayList
<>();
templateNames
.
add
(
"api"
);
templateNames
.
add
(
"api"
);
templateNames
.
add
(
"index"
);
templateNames
.
add
(
"index"
);
...
@@ -67,7 +67,7 @@ public class GenUtil {
...
@@ -67,7 +67,7 @@ public class GenUtil {
* @param genConfig 生成代码的参数配置,如包路径,作者
* @param genConfig 生成代码的参数配置,如包路径,作者
*/
*/
public
static
void
generatorCode
(
List
<
ColumnInfo
>
columnInfos
,
GenConfig
genConfig
,
String
tableName
)
throws
IOException
{
public
static
void
generatorCode
(
List
<
ColumnInfo
>
columnInfos
,
GenConfig
genConfig
,
String
tableName
)
throws
IOException
{
Map
<
String
,
Object
>
map
=
new
HashMap
();
Map
<
String
,
Object
>
map
=
new
HashMap
<>
();
map
.
put
(
"package"
,
genConfig
.
getPack
());
map
.
put
(
"package"
,
genConfig
.
getPack
());
map
.
put
(
"moduleName"
,
genConfig
.
getModuleName
());
map
.
put
(
"moduleName"
,
genConfig
.
getModuleName
());
map
.
put
(
"author"
,
genConfig
.
getAuthor
());
map
.
put
(
"author"
,
genConfig
.
getAuthor
());
...
@@ -85,6 +85,8 @@ public class GenUtil {
...
@@ -85,6 +85,8 @@ public class GenUtil {
map
.
put
(
"upperCaseClassName"
,
className
.
toUpperCase
());
map
.
put
(
"upperCaseClassName"
,
className
.
toUpperCase
());
map
.
put
(
"changeClassName"
,
changeClassName
);
map
.
put
(
"changeClassName"
,
changeClassName
);
map
.
put
(
"hasTimestamp"
,
false
);
map
.
put
(
"hasTimestamp"
,
false
);
map
.
put
(
"queryHasTimestamp"
,
false
);
map
.
put
(
"queryHasBigDecimal"
,
false
);
map
.
put
(
"hasBigDecimal"
,
false
);
map
.
put
(
"hasBigDecimal"
,
false
);
map
.
put
(
"hasQuery"
,
false
);
map
.
put
(
"hasQuery"
,
false
);
map
.
put
(
"auto"
,
false
);
map
.
put
(
"auto"
,
false
);
...
@@ -92,7 +94,7 @@ public class GenUtil {
...
@@ -92,7 +94,7 @@ public class GenUtil {
List
<
Map
<
String
,
Object
>>
columns
=
new
ArrayList
<>();
List
<
Map
<
String
,
Object
>>
columns
=
new
ArrayList
<>();
List
<
Map
<
String
,
Object
>>
queryColumns
=
new
ArrayList
<>();
List
<
Map
<
String
,
Object
>>
queryColumns
=
new
ArrayList
<>();
for
(
ColumnInfo
column
:
columnInfos
)
{
for
(
ColumnInfo
column
:
columnInfos
)
{
Map
<
String
,
Object
>
listMap
=
new
HashMap
();
Map
<
String
,
Object
>
listMap
=
new
HashMap
<>
();
listMap
.
put
(
"columnComment"
,
column
.
getColumnComment
());
listMap
.
put
(
"columnComment"
,
column
.
getColumnComment
());
listMap
.
put
(
"columnKey"
,
column
.
getColumnKey
());
listMap
.
put
(
"columnKey"
,
column
.
getColumnKey
());
...
@@ -124,6 +126,12 @@ public class GenUtil {
...
@@ -124,6 +126,12 @@ public class GenUtil {
if
(!
StringUtils
.
isBlank
(
column
.
getColumnQuery
())){
if
(!
StringUtils
.
isBlank
(
column
.
getColumnQuery
())){
listMap
.
put
(
"columnQuery"
,
column
.
getColumnQuery
());
listMap
.
put
(
"columnQuery"
,
column
.
getColumnQuery
());
map
.
put
(
"hasQuery"
,
true
);
map
.
put
(
"hasQuery"
,
true
);
if
(
TIMESTAMP
.
equals
(
colType
)){
map
.
put
(
"queryHasTimestamp"
,
true
);
}
if
(
BIGDECIMAL
.
equals
(
colType
)){
map
.
put
(
"queryHasBigDecimal"
,
true
);
}
queryColumns
.
add
(
listMap
);
queryColumns
.
add
(
listMap
);
}
}
columns
.
add
(
listMap
);
columns
.
add
(
listMap
);
...
@@ -138,6 +146,7 @@ public class GenUtil {
...
@@ -138,6 +146,7 @@ public class GenUtil {
Template
template
=
engine
.
getTemplate
(
"generator/admin/"
+
templateName
+
".ftl"
);
Template
template
=
engine
.
getTemplate
(
"generator/admin/"
+
templateName
+
".ftl"
);
String
filePath
=
getAdminFilePath
(
templateName
,
genConfig
,
className
);
String
filePath
=
getAdminFilePath
(
templateName
,
genConfig
,
className
);
assert
filePath
!=
null
;
File
file
=
new
File
(
filePath
);
File
file
=
new
File
(
filePath
);
// 如果非覆盖生成
// 如果非覆盖生成
...
@@ -154,6 +163,7 @@ public class GenUtil {
...
@@ -154,6 +163,7 @@ public class GenUtil {
Template
template
=
engine
.
getTemplate
(
"generator/front/"
+
templateName
+
".ftl"
);
Template
template
=
engine
.
getTemplate
(
"generator/front/"
+
templateName
+
".ftl"
);
String
filePath
=
getFrontFilePath
(
templateName
,
genConfig
,
map
.
get
(
"changeClassName"
).
toString
());
String
filePath
=
getFrontFilePath
(
templateName
,
genConfig
,
map
.
get
(
"changeClassName"
).
toString
());
assert
filePath
!=
null
;
File
file
=
new
File
(
filePath
);
File
file
=
new
File
(
filePath
);
// 如果非覆盖生成
// 如果非覆盖生成
...
@@ -168,7 +178,7 @@ public class GenUtil {
...
@@ -168,7 +178,7 @@ public class GenUtil {
/**
/**
* 定义后端文件路径以及名称
* 定义后端文件路径以及名称
*/
*/
p
ublic
static
String
getAdminFilePath
(
String
templateName
,
GenConfig
genConfig
,
String
className
)
{
p
rivate
static
String
getAdminFilePath
(
String
templateName
,
GenConfig
genConfig
,
String
className
)
{
String
projectPath
=
System
.
getProperty
(
"user.dir"
)
+
File
.
separator
+
genConfig
.
getModuleName
();
String
projectPath
=
System
.
getProperty
(
"user.dir"
)
+
File
.
separator
+
genConfig
.
getModuleName
();
String
packagePath
=
projectPath
+
File
.
separator
+
"src"
+
File
.
separator
+
"main"
+
File
.
separator
+
"java"
+
File
.
separator
;
String
packagePath
=
projectPath
+
File
.
separator
+
"src"
+
File
.
separator
+
"main"
+
File
.
separator
+
"java"
+
File
.
separator
;
if
(!
ObjectUtils
.
isEmpty
(
genConfig
.
getPack
()))
{
if
(!
ObjectUtils
.
isEmpty
(
genConfig
.
getPack
()))
{
...
@@ -213,7 +223,7 @@ public class GenUtil {
...
@@ -213,7 +223,7 @@ public class GenUtil {
/**
/**
* 定义前端文件路径以及名称
* 定义前端文件路径以及名称
*/
*/
p
ublic
static
String
getFrontFilePath
(
String
templateName
,
GenConfig
genConfig
,
String
apiName
)
{
p
rivate
static
String
getFrontFilePath
(
String
templateName
,
GenConfig
genConfig
,
String
apiName
)
{
String
path
=
genConfig
.
getPath
();
String
path
=
genConfig
.
getPath
();
if
(
"api"
.
equals
(
templateName
))
{
if
(
"api"
.
equals
(
templateName
))
{
...
@@ -230,18 +240,17 @@ public class GenUtil {
...
@@ -230,18 +240,17 @@ public class GenUtil {
return
null
;
return
null
;
}
}
p
ublic
static
void
genFile
(
File
file
,
Template
template
,
Map
<
String
,
Object
>
map
)
throws
IOException
{
p
rivate
static
void
genFile
(
File
file
,
Template
template
,
Map
<
String
,
Object
>
map
)
throws
IOException
{
// 生成目标文件
// 生成目标文件
Writer
writer
=
null
;
Writer
writer
=
null
;
try
{
try
{
FileUtil
.
touch
(
file
);
FileUtil
.
touch
(
file
);
writer
=
new
FileWriter
(
file
);
writer
=
new
FileWriter
(
file
);
template
.
render
(
map
,
writer
);
template
.
render
(
map
,
writer
);
}
catch
(
TemplateException
e
)
{
}
catch
(
TemplateException
|
IOException
e
)
{
throw
new
RuntimeException
(
e
);
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
e
);
throw
new
RuntimeException
(
e
);
}
finally
{
}
finally
{
assert
writer
!=
null
;
writer
.
close
();
writer
.
close
();
}
}
}
}
...
...
eladmin-logging/src/main/java/me/zhengjie/aspect/LogAspect.java
View file @
bf7c1eeb
...
@@ -48,7 +48,7 @@ public class LogAspect {
...
@@ -48,7 +48,7 @@ public class LogAspect {
*/
*/
@Around
(
"logPointcut()"
)
@Around
(
"logPointcut()"
)
public
Object
logAround
(
ProceedingJoinPoint
joinPoint
)
throws
Throwable
{
public
Object
logAround
(
ProceedingJoinPoint
joinPoint
)
throws
Throwable
{
Object
result
=
null
;
Object
result
;
currentTime
=
System
.
currentTimeMillis
();
currentTime
=
System
.
currentTimeMillis
();
result
=
joinPoint
.
proceed
();
result
=
joinPoint
.
proceed
();
Log
log
=
new
Log
(
"INFO"
,
System
.
currentTimeMillis
()
-
currentTime
);
Log
log
=
new
Log
(
"INFO"
,
System
.
currentTimeMillis
()
-
currentTime
);
...
...
eladmin-logging/src/main/java/me/zhengjie/domain/Log.java
View file @
bf7c1eeb
...
@@ -21,56 +21,38 @@ public class Log implements Serializable {
...
@@ -21,56 +21,38 @@ public class Log implements Serializable {
@GeneratedValue
(
strategy
=
GenerationType
.
IDENTITY
)
@GeneratedValue
(
strategy
=
GenerationType
.
IDENTITY
)
private
Long
id
;
private
Long
id
;
/**
// 操作用户
* 操作用户
*/
private
String
username
;
private
String
username
;
/**
// 描述
* 描述
*/
private
String
description
;
private
String
description
;
/**
// 方法名
* 方法名
*/
private
String
method
;
private
String
method
;
/**
// 参数
* 参数
*/
@Column
(
columnDefinition
=
"text"
)
@Column
(
columnDefinition
=
"text"
)
private
String
params
;
private
String
params
;
/**
// 日志类型
* 日志类型
*/
@Column
(
name
=
"log_type"
)
@Column
(
name
=
"log_type"
)
private
String
logType
;
private
String
logType
;
/**
// 请求ip
* 请求ip
*/
@Column
(
name
=
"request_ip"
)
@Column
(
name
=
"request_ip"
)
private
String
requestIp
;
private
String
requestIp
;
@Column
(
name
=
"address"
)
@Column
(
name
=
"address"
)
private
String
address
;
private
String
address
;
/**
// 请求耗时
* 请求耗时
*/
private
Long
time
;
private
Long
time
;
/**
// 异常详细
* 异常详细
*/
@Column
(
name
=
"exception_detail"
,
columnDefinition
=
"text"
)
@Column
(
name
=
"exception_detail"
,
columnDefinition
=
"text"
)
private
byte
[]
exceptionDetail
;
private
byte
[]
exceptionDetail
;
/**
// 创建日期
* 创建日期
*/
@CreationTimestamp
@CreationTimestamp
@Column
(
name
=
"create_time"
)
@Column
(
name
=
"create_time"
)
private
Timestamp
createTime
;
private
Timestamp
createTime
;
...
...
eladmin-logging/src/main/java/me/zhengjie/repository/LogRepository.java
View file @
bf7c1eeb
...
@@ -11,22 +11,14 @@ import org.springframework.stereotype.Repository;
...
@@ -11,22 +11,14 @@ import org.springframework.stereotype.Repository;
* @date 2018-11-24
* @date 2018-11-24
*/
*/
@Repository
@Repository
public
interface
LogRepository
extends
JpaRepository
<
Log
,
Long
>,
JpaSpecificationExecutor
{
public
interface
LogRepository
extends
JpaRepository
<
Log
,
Long
>,
JpaSpecificationExecutor
<
Log
>
{
/**
/**
* 获取一个时间段的IP记录
* 获取一个时间段的IP记录
* @param date1
* @param date2
* @return
*/
*/
@Query
(
value
=
"select count(*) FROM (select request_ip FROM log where create_time between ?1 and ?2 GROUP BY request_ip) as s"
,
nativeQuery
=
true
)
@Query
(
value
=
"select count(*) FROM (select request_ip FROM log where create_time between ?1 and ?2 GROUP BY request_ip) as s"
,
nativeQuery
=
true
)
Long
findIp
(
String
date1
,
String
date2
);
Long
findIp
(
String
date1
,
String
date2
);
/**
@Query
(
value
=
"select l FROM Log l where l.id = ?1"
)
* findExceptionById
Log
findExceptionById
(
Long
id
);
* @param id
* @return
*/
@Query
(
value
=
"select exception_detail FROM log where id = ?1"
,
nativeQuery
=
true
)
String
findExceptionById
(
Long
id
);
}
}
eladmin-logging/src/main/java/me/zhengjie/rest/LogController.java
View file @
bf7c1eeb
package
me.zhengjie.rest
;
package
me.zhengjie.rest
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
me.zhengjie.service.LogService
;
import
me.zhengjie.service.LogService
;
import
me.zhengjie.service.dto.LogQueryCriteria
;
import
me.zhengjie.service.dto.LogQueryCriteria
;
import
me.zhengjie.utils.SecurityUtils
;
import
me.zhengjie.utils.SecurityUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.http.ResponseEntity
;
...
@@ -18,36 +19,44 @@ import org.springframework.web.bind.annotation.RestController;
...
@@ -18,36 +19,44 @@ import org.springframework.web.bind.annotation.RestController;
* @date 2018-11-24
* @date 2018-11-24
*/
*/
@RestController
@RestController
@RequestMapping
(
"api"
)
@RequestMapping
(
"/api/logs"
)
@Api
(
tags
=
"监控:日志管理"
)
public
class
LogController
{
public
class
LogController
{
@Autowired
private
final
LogService
logService
;
private
LogService
logService
;
@GetMapping
(
value
=
"/logs"
)
public
LogController
(
LogService
logService
)
{
this
.
logService
=
logService
;
}
@GetMapping
@ApiOperation
(
"日志查询"
)
@PreAuthorize
(
"hasAnyRole('ADMIN')"
)
@PreAuthorize
(
"hasAnyRole('ADMIN')"
)
public
ResponseEntity
getLogs
(
LogQueryCriteria
criteria
,
Pageable
pageable
){
public
ResponseEntity
getLogs
(
LogQueryCriteria
criteria
,
Pageable
pageable
){
criteria
.
setLogType
(
"INFO"
);
criteria
.
setLogType
(
"INFO"
);
return
new
ResponseEntity
(
logService
.
queryAll
(
criteria
,
pageable
),
HttpStatus
.
OK
);
return
new
ResponseEntity
<>
(
logService
.
queryAll
(
criteria
,
pageable
),
HttpStatus
.
OK
);
}
}
@GetMapping
(
value
=
"/logs/user"
)
@GetMapping
(
value
=
"/user"
)
@ApiOperation
(
"用户日志查询"
)
public
ResponseEntity
getUserLogs
(
LogQueryCriteria
criteria
,
Pageable
pageable
){
public
ResponseEntity
getUserLogs
(
LogQueryCriteria
criteria
,
Pageable
pageable
){
criteria
.
setLogType
(
"INFO"
);
criteria
.
setLogType
(
"INFO"
);
criteria
.
setBlurry
(
SecurityUtils
.
getUsername
());
criteria
.
setBlurry
(
SecurityUtils
.
getUsername
());
return
new
ResponseEntity
(
logService
.
queryAllByUser
(
criteria
,
pageable
),
HttpStatus
.
OK
);
return
new
ResponseEntity
<>
(
logService
.
queryAllByUser
(
criteria
,
pageable
),
HttpStatus
.
OK
);
}
}
@GetMapping
(
value
=
"/logs/error"
)
@GetMapping
(
value
=
"/error"
)
@ApiOperation
(
"错误日志查询"
)
@PreAuthorize
(
"hasAnyRole('ADMIN')"
)
@PreAuthorize
(
"hasAnyRole('ADMIN')"
)
public
ResponseEntity
getErrorLogs
(
LogQueryCriteria
criteria
,
Pageable
pageable
){
public
ResponseEntity
getErrorLogs
(
LogQueryCriteria
criteria
,
Pageable
pageable
){
criteria
.
setLogType
(
"ERROR"
);
criteria
.
setLogType
(
"ERROR"
);
return
new
ResponseEntity
(
logService
.
queryAll
(
criteria
,
pageable
),
HttpStatus
.
OK
);
return
new
ResponseEntity
<>
(
logService
.
queryAll
(
criteria
,
pageable
),
HttpStatus
.
OK
);
}
}
@GetMapping
(
value
=
"/logs/error/{id}"
)
@GetMapping
(
value
=
"/error/{id}"
)
@ApiOperation
(
"日志异常详情查询"
)
@PreAuthorize
(
"hasAnyRole('ADMIN')"
)
@PreAuthorize
(
"hasAnyRole('ADMIN')"
)
public
ResponseEntity
getErrorLogs
(
@PathVariable
Long
id
){
public
ResponseEntity
getErrorLogs
(
@PathVariable
Long
id
){
return
new
ResponseEntity
(
logService
.
findByErrDetail
(
id
),
HttpStatus
.
OK
);
return
new
ResponseEntity
<>
(
logService
.
findByErrDetail
(
id
),
HttpStatus
.
OK
);
}
}
}
}
eladmin-logging/src/main/java/me/zhengjie/service/LogService.java
View file @
bf7c1eeb
...
@@ -12,36 +12,17 @@ import org.springframework.scheduling.annotation.Async;
...
@@ -12,36 +12,17 @@ import org.springframework.scheduling.annotation.Async;
*/
*/
public
interface
LogService
{
public
interface
LogService
{
/**
* queryAll
* @param criteria
* @param pageable
* @return
*/
Object
queryAll
(
LogQueryCriteria
criteria
,
Pageable
pageable
);
Object
queryAll
(
LogQueryCriteria
criteria
,
Pageable
pageable
);
/**
* queryAllByUser
* @param criteria
* @param pageable
* @return
*/
Object
queryAllByUser
(
LogQueryCriteria
criteria
,
Pageable
pageable
);
Object
queryAllByUser
(
LogQueryCriteria
criteria
,
Pageable
pageable
);
/**
* 新增日志
* @param username
* @param ip
* @param joinPoint
* @param log
*/
@Async
@Async
void
save
(
String
username
,
String
ip
,
ProceedingJoinPoint
joinPoint
,
Log
log
);
void
save
(
String
username
,
String
ip
,
ProceedingJoinPoint
joinPoint
,
Log
log
);
/**
/**
* 查询异常详情
* 查询异常详情
* @param id
* @param id
日志ID
* @return
* @return
Object
*/
*/
Object
findByErrDetail
(
Long
id
);
Object
findByErrDetail
(
Long
id
);
}
}
eladmin-logging/src/main/java/me/zhengjie/service/dto/LogErrorDTO.java
View file @
bf7c1eeb
...
@@ -13,36 +13,24 @@ public class LogErrorDTO implements Serializable {
...
@@ -13,36 +13,24 @@ public class LogErrorDTO implements Serializable {
private
Long
id
;
private
Long
id
;
/**
// 操作用户
* 操作用户
*/
private
String
username
;
private
String
username
;
/**
// 描述
* 描述
*/
private
String
description
;
private
String
description
;
/**
// 方法名
* 方法名
*/
private
String
method
;
private
String
method
;
/**
// 参数
* 参数
*/
private
String
params
;
private
String
params
;
/**
// 请求ip
* 请求ip
*/
private
String
requestIp
;
private
String
requestIp
;
private
String
address
;
private
String
address
;
/**
// 创建日期
* 创建日期
*/
private
Timestamp
createTime
;
private
Timestamp
createTime
;
}
}
\ No newline at end of file
eladmin-logging/src/main/java/me/zhengjie/service/dto/LogSmallDTO.java
View file @
bf7c1eeb
package
me.zhengjie.service.dto
;
package
me.zhengjie.service.dto
;
import
lombok.Data
;
import
lombok.Data
;
import
java.io.Serializable
;
import
java.io.Serializable
;
import
java.sql.Timestamp
;
import
java.sql.Timestamp
;
...
@@ -12,25 +11,17 @@ import java.sql.Timestamp;
...
@@ -12,25 +11,17 @@ import java.sql.Timestamp;
@Data
@Data
public
class
LogSmallDTO
implements
Serializable
{
public
class
LogSmallDTO
implements
Serializable
{
/**
// 描述
* 描述
*/
private
String
description
;
private
String
description
;
/**
// 请求ip
* 请求ip
*/
private
String
requestIp
;
private
String
requestIp
;
/**
// 请求耗时
* 请求耗时
*/
private
Long
time
;
private
Long
time
;
private
String
address
;
private
String
address
;
/**
// 创建日期
* 创建日期
*/
private
Timestamp
createTime
;
private
Timestamp
createTime
;
}
}
eladmin-logging/src/main/java/me/zhengjie/service/impl/LogServiceImpl.java
View file @
bf7c1eeb
...
@@ -13,7 +13,6 @@ import me.zhengjie.utils.QueryHelp;
...
@@ -13,7 +13,6 @@ import me.zhengjie.utils.QueryHelp;
import
me.zhengjie.utils.StringUtils
;
import
me.zhengjie.utils.StringUtils
;
import
org.aspectj.lang.ProceedingJoinPoint
;
import
org.aspectj.lang.ProceedingJoinPoint
;
import
org.aspectj.lang.reflect.MethodSignature
;
import
org.aspectj.lang.reflect.MethodSignature
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
...
@@ -29,16 +28,17 @@ import java.lang.reflect.Method;
...
@@ -29,16 +28,17 @@ import java.lang.reflect.Method;
@Transactional
(
propagation
=
Propagation
.
SUPPORTS
,
readOnly
=
true
,
rollbackFor
=
Exception
.
class
)
@Transactional
(
propagation
=
Propagation
.
SUPPORTS
,
readOnly
=
true
,
rollbackFor
=
Exception
.
class
)
public
class
LogServiceImpl
implements
LogService
{
public
class
LogServiceImpl
implements
LogService
{
@Autowired
private
final
LogRepository
logRepository
;
private
LogRepository
logRepository
;
@Autowired
private
final
LogErrorMapper
logErrorMapper
;
private
LogErrorMapper
logErrorMapper
;
@Autowired
private
final
LogSmallMapper
logSmallMapper
;
private
LogSmallMapper
logSmallMapper
;
private
final
String
LOGINPATH
=
"login"
;
public
LogServiceImpl
(
LogRepository
logRepository
,
LogErrorMapper
logErrorMapper
,
LogSmallMapper
logSmallMapper
)
{
this
.
logRepository
=
logRepository
;
this
.
logErrorMapper
=
logErrorMapper
;
this
.
logSmallMapper
=
logSmallMapper
;
}
@Override
@Override
public
Object
queryAll
(
LogQueryCriteria
criteria
,
Pageable
pageable
){
public
Object
queryAll
(
LogQueryCriteria
criteria
,
Pageable
pageable
){
...
@@ -63,32 +63,31 @@ public class LogServiceImpl implements LogService {
...
@@ -63,32 +63,31 @@ public class LogServiceImpl implements LogService {
Method
method
=
signature
.
getMethod
();
Method
method
=
signature
.
getMethod
();
me
.
zhengjie
.
aop
.
log
.
Log
aopLog
=
method
.
getAnnotation
(
me
.
zhengjie
.
aop
.
log
.
Log
.
class
);
me
.
zhengjie
.
aop
.
log
.
Log
aopLog
=
method
.
getAnnotation
(
me
.
zhengjie
.
aop
.
log
.
Log
.
class
);
// 描述
if
(
log
!=
null
)
{
log
.
setDescription
(
aopLog
.
value
());
}
// 方法路径
// 方法路径
String
methodName
=
joinPoint
.
getTarget
().
getClass
().
getName
()+
"."
+
signature
.
getName
()+
"()"
;
String
methodName
=
joinPoint
.
getTarget
().
getClass
().
getName
()+
"."
+
signature
.
getName
()+
"()"
;
String
params
=
"{"
;
String
Builder
params
=
new
StringBuilder
(
"{"
)
;
//参数值
//参数值
Object
[]
argValues
=
joinPoint
.
getArgs
();
Object
[]
argValues
=
joinPoint
.
getArgs
();
//参数名称
//参数名称
String
[]
argNames
=
((
MethodSignature
)
joinPoint
.
getSignature
()).
getParameterNames
();
String
[]
argNames
=
((
MethodSignature
)
joinPoint
.
getSignature
()).
getParameterNames
();
if
(
argValues
!=
null
){
if
(
argValues
!=
null
){
for
(
int
i
=
0
;
i
<
argValues
.
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
argValues
.
length
;
i
++)
{
params
+=
" "
+
argNames
[
i
]
+
": "
+
argValues
[
i
];
params
.
append
(
" "
).
append
(
argNames
[
i
]).
append
(
": "
).
append
(
argValues
[
i
]
)
;
}
}
}
}
// 描述
// 获取IP地址
if
(
log
!=
null
)
{
log
.
setDescription
(
aopLog
.
value
());
}
assert
log
!=
null
;
log
.
setRequestIp
(
ip
);
log
.
setRequestIp
(
ip
);
String
LOGINPATH
=
"login"
;
if
(
LOGINPATH
.
equals
(
signature
.
getName
())){
if
(
LOGINPATH
.
equals
(
signature
.
getName
())){
try
{
try
{
JSONObject
jsonObject
=
new
JSONObject
(
argValues
[
0
])
;
assert
argValues
!=
null
;
username
=
jsonObject
.
get
(
"username"
).
toString
();
username
=
new
JSONObject
(
argValues
[
0
])
.
get
(
"username"
).
toString
();
}
catch
(
Exception
e
){
}
catch
(
Exception
e
){
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
...
@@ -96,12 +95,12 @@ public class LogServiceImpl implements LogService {
...
@@ -96,12 +95,12 @@ public class LogServiceImpl implements LogService {
log
.
setAddress
(
StringUtils
.
getCityInfo
(
log
.
getRequestIp
()));
log
.
setAddress
(
StringUtils
.
getCityInfo
(
log
.
getRequestIp
()));
log
.
setMethod
(
methodName
);
log
.
setMethod
(
methodName
);
log
.
setUsername
(
username
);
log
.
setUsername
(
username
);
log
.
setParams
(
params
+
" }"
);
log
.
setParams
(
params
.
toString
()
+
" }"
);
logRepository
.
save
(
log
);
logRepository
.
save
(
log
);
}
}
@Override
@Override
public
Object
findByErrDetail
(
Long
id
)
{
public
Object
findByErrDetail
(
Long
id
)
{
return
Dict
.
create
().
set
(
"exception"
,
logRepository
.
findExceptionById
(
id
));
return
Dict
.
create
().
set
(
"exception"
,
logRepository
.
findExceptionById
(
id
)
.
getExceptionDetail
()
);
}
}
}
}
eladmin-logging/src/main/java/me/zhengjie/service/mapper/LogErrorMapper.java
View file @
bf7c1eeb
...
@@ -10,7 +10,7 @@ import org.mapstruct.ReportingPolicy;
...
@@ -10,7 +10,7 @@ import org.mapstruct.ReportingPolicy;
* @author Zheng Jie
* @author Zheng Jie
* @date 2019-5-22
* @date 2019-5-22
*/
*/
@Mapper
(
componentModel
=
"spring"
,
uses
=
{},
unmappedTargetPolicy
=
ReportingPolicy
.
IGNORE
)
@Mapper
(
componentModel
=
"spring"
,
unmappedTargetPolicy
=
ReportingPolicy
.
IGNORE
)
public
interface
LogErrorMapper
extends
EntityMapper
<
LogErrorDTO
,
Log
>
{
public
interface
LogErrorMapper
extends
EntityMapper
<
LogErrorDTO
,
Log
>
{
}
}
\ No newline at end of file
eladmin-logging/src/main/java/me/zhengjie/service/mapper/LogSmallMapper.java
View file @
bf7c1eeb
...
@@ -10,7 +10,7 @@ import org.mapstruct.ReportingPolicy;
...
@@ -10,7 +10,7 @@ import org.mapstruct.ReportingPolicy;
* @author Zheng Jie
* @author Zheng Jie
* @date 2019-5-22
* @date 2019-5-22
*/
*/
@Mapper
(
componentModel
=
"spring"
,
uses
=
{},
unmappedTargetPolicy
=
ReportingPolicy
.
IGNORE
)
@Mapper
(
componentModel
=
"spring"
,
unmappedTargetPolicy
=
ReportingPolicy
.
IGNORE
)
public
interface
LogSmallMapper
extends
EntityMapper
<
LogSmallDTO
,
Log
>
{
public
interface
LogSmallMapper
extends
EntityMapper
<
LogSmallDTO
,
Log
>
{
}
}
\ No newline at end of file
eladmin-system/src/main/java/me/zhengjie/config/DataScope.java
View file @
bf7c1eeb
...
@@ -25,14 +25,17 @@ public class DataScope {
...
@@ -25,14 +25,17 @@ public class DataScope {
private
final
String
[]
scopeType
=
{
"全部"
,
"本级"
,
"自定义"
};
private
final
String
[]
scopeType
=
{
"全部"
,
"本级"
,
"自定义"
};
@Autowired
private
final
UserService
userService
;
private
UserService
userService
;
@Autowired
private
final
RoleService
roleService
;
private
RoleService
roleService
;
@Autowired
private
final
DeptService
deptService
;
private
DeptService
deptService
;
public
DataScope
(
UserService
userService
,
RoleService
roleService
,
DeptService
deptService
)
{
this
.
userService
=
userService
;
this
.
roleService
=
roleService
;
this
.
deptService
=
deptService
;
}
public
Set
<
Long
>
getDeptIds
()
{
public
Set
<
Long
>
getDeptIds
()
{
...
@@ -76,7 +79,7 @@ public class DataScope {
...
@@ -76,7 +79,7 @@ public class DataScope {
deptList
.
forEach
(
dept
->
{
deptList
.
forEach
(
dept
->
{
if
(
dept
!=
null
&&
dept
.
getEnabled
()){
if
(
dept
!=
null
&&
dept
.
getEnabled
()){
List
<
Dept
>
depts
=
deptService
.
findByPid
(
dept
.
getId
());
List
<
Dept
>
depts
=
deptService
.
findByPid
(
dept
.
getId
());
if
(
deptList
!=
null
&&
deptList
.
size
()!=
0
){
if
(
deptList
.
size
()
!=
0
){
list
.
addAll
(
getDeptChildren
(
depts
));
list
.
addAll
(
getDeptChildren
(
depts
));
}
}
list
.
add
(
dept
.
getId
());
list
.
add
(
dept
.
getId
());
...
...
eladmin-system/src/main/java/me/zhengjie/modules/monitor/config/VisitsInitialization.java
View file @
bf7c1eeb
package
me.zhengjie.modules.monitor.config
;
package
me.zhengjie.modules.monitor.config
;
import
me.zhengjie.modules.monitor.service.VisitsService
;
import
me.zhengjie.modules.monitor.service.VisitsService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.ApplicationArguments
;
import
org.springframework.boot.ApplicationArguments
;
import
org.springframework.boot.ApplicationRunner
;
import
org.springframework.boot.ApplicationRunner
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
...
@@ -13,8 +12,11 @@ import org.springframework.stereotype.Component;
...
@@ -13,8 +12,11 @@ import org.springframework.stereotype.Component;
@Component
@Component
public
class
VisitsInitialization
implements
ApplicationRunner
{
public
class
VisitsInitialization
implements
ApplicationRunner
{
@Autowired
private
final
VisitsService
visitsService
;
private
VisitsService
visitsService
;
public
VisitsInitialization
(
VisitsService
visitsService
)
{
this
.
visitsService
=
visitsService
;
}
@Override
@Override
public
void
run
(
ApplicationArguments
args
)
throws
Exception
{
public
void
run
(
ApplicationArguments
args
)
throws
Exception
{
...
...
eladmin-system/src/main/java/me/zhengjie/modules/monitor/repository/VisitsRepository.java
View file @
bf7c1eeb
...
@@ -4,7 +4,6 @@ import me.zhengjie.modules.monitor.domain.Visits;
...
@@ -4,7 +4,6 @@ import me.zhengjie.modules.monitor.domain.Visits;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.data.jpa.repository.Query
;
import
org.springframework.data.jpa.repository.Query
;
import
org.springframework.stereotype.Repository
;
import
org.springframework.stereotype.Repository
;
import
java.util.List
;
import
java.util.List
;
/**
/**
...
@@ -16,18 +15,17 @@ public interface VisitsRepository extends JpaRepository<Visits,Long> {
...
@@ -16,18 +15,17 @@ public interface VisitsRepository extends JpaRepository<Visits,Long> {
/**
/**
* findByDate
* findByDate
* @param date
* @param date
日期
* @return
* @return
Visits
*/
*/
Visits
findByDate
(
String
date
);
Visits
findByDate
(
String
date
);
/**
/**
* 获得一个时间段的记录
* 获得一个时间段的记录
* @param date1
* @param date1
日期1
* @param date2
* @param date2
日期2
* @return
* @return
List
*/
*/
@Query
(
value
=
"select * FROM visits where "
+
@Query
(
value
=
"select * FROM visits where create_time between ?1 and ?2"
,
nativeQuery
=
true
)
"create_time between ?1 and ?2"
,
nativeQuery
=
true
)
List
<
Visits
>
findAllVisits
(
String
date1
,
String
date2
);
List
<
Visits
>
findAllVisits
(
String
date1
,
String
date2
);
}
}
eladmin-system/src/main/java/me/zhengjie/modules/monitor/rest/LimitController.java
View file @
bf7c1eeb
package
me.zhengjie.modules.monitor.rest
;
package
me.zhengjie.modules.monitor.rest
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
me.zhengjie.annotation.Limit
;
import
me.zhengjie.annotation.Limit
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
...
@@ -12,15 +14,17 @@ import java.util.concurrent.atomic.AtomicInteger;
...
@@ -12,15 +14,17 @@ import java.util.concurrent.atomic.AtomicInteger;
* 接口限流测试类
* 接口限流测试类
*/
*/
@RestController
@RestController
@RequestMapping
(
"api"
)
@RequestMapping
(
"/api/limit"
)
@Api
(
tags
=
"系统:限流测试管理"
)
public
class
LimitController
{
public
class
LimitController
{
private
static
final
AtomicInteger
ATOMIC_INTEGER
=
new
AtomicInteger
();
private
static
final
AtomicInteger
ATOMIC_INTEGER
=
new
AtomicInteger
();
/**
/**
* 测试限流注解,下面配置说明该接口 60秒内最多只能访问 10次,保存到redis的键名为 limit_test,
* 测试限流注解,下面配置说明该接口 60秒内最多只能访问 10次,保存到redis的键名为 limit_test,
*/
*/
@GetMapping
@ApiOperation
(
"测试"
)
@Limit
(
key
=
"test"
,
period
=
60
,
count
=
10
,
name
=
"testLimit"
,
prefix
=
"limit"
)
@Limit
(
key
=
"test"
,
period
=
60
,
count
=
10
,
name
=
"testLimit"
,
prefix
=
"limit"
)
@GetMapping
(
"/limit"
)
public
int
testLimit
()
{
public
int
testLimit
()
{
return
ATOMIC_INTEGER
.
incrementAndGet
();
return
ATOMIC_INTEGER
.
incrementAndGet
();
}
}
...
...
eladmin-system/src/main/java/me/zhengjie/modules/monitor/rest/RedisController.java
View file @
bf7c1eeb
package
me.zhengjie.modules.monitor.rest
;
package
me.zhengjie.modules.monitor.rest
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
me.zhengjie.aop.log.Log
;
import
me.zhengjie.aop.log.Log
;
import
me.zhengjie.modules.monitor.domain.vo.RedisVo
;
import
me.zhengjie.modules.monitor.domain.vo.RedisVo
;
import
me.zhengjie.modules.monitor.service.RedisService
;
import
me.zhengjie.modules.monitor.service.RedisService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
/**
/**
...
@@ -16,21 +16,27 @@ import org.springframework.web.bind.annotation.*;
...
@@ -16,21 +16,27 @@ import org.springframework.web.bind.annotation.*;
* @date 2018-12-10
* @date 2018-12-10
*/
*/
@RestController
@RestController
@RequestMapping
(
"api"
)
@RequestMapping
(
"/api/redis"
)
@Api
(
tags
=
"系统:Redis缓存管理"
)
public
class
RedisController
{
public
class
RedisController
{
@Autowired
private
final
RedisService
redisService
;
private
RedisService
redisService
;
public
RedisController
(
RedisService
redisService
)
{
this
.
redisService
=
redisService
;
}
@Log
(
"查询Redis缓存"
)
@Log
(
"查询Redis缓存"
)
@GetMapping
(
value
=
"/redis"
)
@GetMapping
@ApiOperation
(
"查询Redis缓存"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','REDIS_ALL','REDIS_SELECT')"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','REDIS_ALL','REDIS_SELECT')"
)
public
ResponseEntity
getRedis
(
String
key
,
Pageable
pageable
){
public
ResponseEntity
getRedis
(
String
key
,
Pageable
pageable
){
return
new
ResponseEntity
(
redisService
.
findByKey
(
key
,
pageable
),
HttpStatus
.
OK
);
return
new
ResponseEntity
<>
(
redisService
.
findByKey
(
key
,
pageable
),
HttpStatus
.
OK
);
}
}
@Log
(
"删除Redis缓存"
)
@Log
(
"删除Redis缓存"
)
@DeleteMapping
(
value
=
"/redis"
)
@DeleteMapping
@ApiOperation
(
"删除Redis缓存"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','REDIS_ALL','REDIS_DELETE')"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','REDIS_ALL','REDIS_DELETE')"
)
public
ResponseEntity
delete
(
@RequestBody
RedisVo
resources
){
public
ResponseEntity
delete
(
@RequestBody
RedisVo
resources
){
redisService
.
delete
(
resources
.
getKey
());
redisService
.
delete
(
resources
.
getKey
());
...
@@ -38,7 +44,8 @@ public class RedisController {
...
@@ -38,7 +44,8 @@ public class RedisController {
}
}
@Log
(
"清空Redis缓存"
)
@Log
(
"清空Redis缓存"
)
@DeleteMapping
(
value
=
"/redis/all"
)
@DeleteMapping
(
value
=
"/all"
)
@ApiOperation
(
"清空Redis缓存"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','REDIS_ALL','REDIS_DELETE')"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','REDIS_ALL','REDIS_DELETE')"
)
public
ResponseEntity
deleteAll
(){
public
ResponseEntity
deleteAll
(){
redisService
.
flushdb
();
redisService
.
flushdb
();
...
...
eladmin-system/src/main/java/me/zhengjie/modules/monitor/rest/VisitsController.java
View file @
bf7c1eeb
package
me.zhengjie.modules.monitor.rest
;
package
me.zhengjie.modules.monitor.rest
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
me.zhengjie.modules.monitor.service.VisitsService
;
import
me.zhengjie.modules.monitor.service.VisitsService
;
import
me.zhengjie.utils.RequestHolder
;
import
me.zhengjie.utils.RequestHolder
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
@@ -15,25 +17,32 @@ import org.springframework.web.bind.annotation.RestController;
...
@@ -15,25 +17,32 @@ import org.springframework.web.bind.annotation.RestController;
* @date 2018-12-13
* @date 2018-12-13
*/
*/
@RestController
@RestController
@RequestMapping
(
"api"
)
@RequestMapping
(
"/api/visits"
)
@Api
(
tags
=
"系统:访问记录管理"
)
public
class
VisitsController
{
public
class
VisitsController
{
@Autowired
private
final
VisitsService
visitsService
;
private
VisitsService
visitsService
;
@PostMapping
(
value
=
"/visits"
)
public
VisitsController
(
VisitsService
visitsService
)
{
this
.
visitsService
=
visitsService
;
}
@PostMapping
@ApiOperation
(
"创建访问记录"
)
public
ResponseEntity
create
(){
public
ResponseEntity
create
(){
visitsService
.
count
(
RequestHolder
.
getHttpServletRequest
());
visitsService
.
count
(
RequestHolder
.
getHttpServletRequest
());
return
new
ResponseEntity
(
HttpStatus
.
CREATED
);
return
new
ResponseEntity
(
HttpStatus
.
CREATED
);
}
}
@GetMapping
(
value
=
"/visits"
)
@GetMapping
@ApiOperation
(
"查询"
)
public
ResponseEntity
get
(){
public
ResponseEntity
get
(){
return
new
ResponseEntity
(
visitsService
.
get
(),
HttpStatus
.
OK
);
return
new
ResponseEntity
<>
(
visitsService
.
get
(),
HttpStatus
.
OK
);
}
}
@GetMapping
(
value
=
"/visits/chartData"
)
@GetMapping
(
value
=
"/chartData"
)
@ApiOperation
(
"查询图表数据"
)
public
ResponseEntity
getChartData
(){
public
ResponseEntity
getChartData
(){
return
new
ResponseEntity
(
visitsService
.
getChartData
(),
HttpStatus
.
OK
);
return
new
ResponseEntity
<>
(
visitsService
.
getChartData
(),
HttpStatus
.
OK
);
}
}
}
}
eladmin-system/src/main/java/me/zhengjie/modules/monitor/service/RedisService.java
View file @
bf7c1eeb
...
@@ -13,28 +13,28 @@ public interface RedisService {
...
@@ -13,28 +13,28 @@ public interface RedisService {
/**
/**
* findById
* findById
* @param key
* @param key
键
* @return
* @return
/
*/
*/
Page
findByKey
(
String
key
,
Pageable
pageable
);
Page
findByKey
(
String
key
,
Pageable
pageable
);
/**
/**
* 查询验证码的值
* 查询验证码的值
* @param key
* @param key
键
* @return
* @return
/
*/
*/
String
getCodeVal
(
String
key
);
String
getCodeVal
(
String
key
);
/**
/**
* 保存验证码
* 保存验证码
* @param key
* @param key
键
* @param val
* @param val
值
*/
*/
void
saveCode
(
String
key
,
Object
val
);
void
saveCode
(
String
key
,
Object
val
);
/**
/**
* delete
* delete
* @param key
* @param key
键
*/
*/
void
delete
(
String
key
);
void
delete
(
String
key
);
...
...
Prev
1
2
3
4
5
6
…
8
Next
Write
Preview
Supports
Markdown
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