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
4765785c
Commit
4765785c
authored
Dec 25, 2018
by
郑杰
Browse files
v1.1 版本发布,详细信息查看发行版说明
parent
55d48240
Changes
17
Hide whitespace changes
Inline
Side-by-side
README.md
View file @
4765785c
...
...
@@ -24,6 +24,7 @@
-
权限管理 权限细化到接口
-
菜单管理 已实现动态路由,后端可配置化
-
系统日志 记录用户访问监控异常信息
-
实时控制台 显示logback实时日志
-
系统缓存管理 将redis的操作可视化,提供对redis的基本操作
-
Sql监控 采用 druid 监控数据库访问性能
...
...
pom.xml
View file @
4765785c
...
...
@@ -55,6 +55,11 @@
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-data-redis
</artifactId>
</dependency>
<!--websocket-->
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-websocket
</artifactId>
</dependency>
<!--Spring boot end-->
<!--jedis-->
...
...
sql/eladmin.sql
View file @
4765785c
This source diff could not be displayed because it is too large. You can
view the blob
instead.
src/main/java/me/zhengjie/AppRun.java
View file @
4765785c
...
...
@@ -2,16 +2,22 @@ package me.zhengjie;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.scheduling.annotation.EnableScheduling
;
import
org.springframework.transaction.annotation.EnableTransactionManagement
;
import
org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker
;
/**
* @author jie
* @date 2018/11/15 9:20:19
*/
@SpringBootApplication
//开启定时任务
@EnableScheduling
@EnableTransactionManagement
@EnableWebSocketMessageBroker
public
class
AppRun
{
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
AppRun
.
class
,
args
);
}
}
src/main/java/me/zhengjie/core/config/WebSecurityConfig.java
View file @
4765785c
...
...
@@ -77,6 +77,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
.
authorizeRequests
()
.
antMatchers
(
"/auth/**"
).
permitAll
()
.
antMatchers
(
"/websocket/**"
).
anonymous
()
.
antMatchers
(
"/druid/**"
).
anonymous
()
// swagger start
...
...
src/main/java/me/zhengjie/monitor/config/LogFilter.java
0 → 100644
View file @
4765785c
package
me.zhengjie.monitor.config
;
import
ch.qos.logback.classic.spi.ILoggingEvent
;
import
ch.qos.logback.classic.spi.IThrowableProxy
;
import
ch.qos.logback.core.filter.Filter
;
import
ch.qos.logback.core.spi.FilterReply
;
import
me.zhengjie.monitor.domain.LogMessage
;
import
java.text.DateFormat
;
import
java.util.Date
;
/**
* 定义Logfilter拦截输出日志
* @author jie
* @date 2018-12-24
*/
public
class
LogFilter
extends
Filter
<
ILoggingEvent
>{
@Override
public
FilterReply
decide
(
ILoggingEvent
event
)
{
String
exception
=
""
;
IThrowableProxy
iThrowableProxy1
=
event
.
getThrowableProxy
();
if
(
iThrowableProxy1
!=
null
){
exception
=
"<span class='excehtext'>"
+
iThrowableProxy1
.
getClassName
()+
" "
+
iThrowableProxy1
.
getMessage
()+
"</span></br>"
;
for
(
int
i
=
0
;
i
<
iThrowableProxy1
.
getStackTraceElementProxyArray
().
length
;
i
++){
exception
+=
"<span class='excetext'>"
+
iThrowableProxy1
.
getStackTraceElementProxyArray
()[
i
].
toString
()+
"</span></br>"
;
}
}
LogMessage
loggerMessage
=
new
LogMessage
(
event
.
getMessage
()
,
DateFormat
.
getDateTimeInstance
().
format
(
new
Date
(
event
.
getTimeStamp
())),
event
.
getThreadName
(),
event
.
getLoggerName
(),
event
.
getLevel
().
levelStr
,
exception
);
LoggerQueue
.
getInstance
().
push
(
loggerMessage
);
return
FilterReply
.
ACCEPT
;
}
}
\ No newline at end of file
src/main/java/me/zhengjie/monitor/config/LoggerQueue.java
0 → 100644
View file @
4765785c
package
me.zhengjie.monitor.config
;
import
me.zhengjie.monitor.domain.LogMessage
;
import
java.util.concurrent.BlockingQueue
;
import
java.util.concurrent.LinkedBlockingQueue
;
/**
* 创建一个阻塞队列,作为日志系统输出的日志的一个临时载体
* @author jie
* @date 2018-12-24
*/
public
class
LoggerQueue
{
//队列大小
public
static
final
int
QUEUE_MAX_SIZE
=
10000
;
private
static
LoggerQueue
alarmMessageQueue
=
new
LoggerQueue
();
//阻塞队列
private
BlockingQueue
blockingQueue
=
new
LinkedBlockingQueue
<>(
QUEUE_MAX_SIZE
);
private
LoggerQueue
()
{
}
public
static
LoggerQueue
getInstance
()
{
return
alarmMessageQueue
;
}
/**
* 消息入队
*
* @param log
* @return
*/
public
boolean
push
(
LogMessage
log
)
{
return
this
.
blockingQueue
.
add
(
log
);
//队列满了就抛出异常,不阻塞
}
/**
* 消息出队
*
* @return
*/
public
LogMessage
poll
()
{
LogMessage
result
=
null
;
try
{
result
=
(
LogMessage
)
this
.
blockingQueue
.
take
();
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
return
result
;
}
}
src/main/java/me/zhengjie/monitor/config/VisitsScheduling.java
0 → 100644
View file @
4765785c
package
me.zhengjie.monitor.config
;
import
me.zhengjie.monitor.service.VisitsService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.scheduling.annotation.Async
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
/**
* @author jie
* @date 2018-12-25
*/
@Component
@Async
public
class
VisitsScheduling
{
@Autowired
private
VisitsService
visitsService
;
/**
* 每天0:01运行
*/
@Scheduled
(
cron
=
"1 0 0 * * ?"
)
public
void
save
(){
visitsService
.
save
();
}
}
src/main/java/me/zhengjie/monitor/config/WebSocketConfig.java
0 → 100644
View file @
4765785c
package
me.zhengjie.monitor.config
;
import
lombok.extern.slf4j.Slf4j
;
import
me.zhengjie.monitor.domain.LogMessage
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.messaging.simp.SimpMessagingTemplate
;
import
org.springframework.web.socket.config.annotation.StompEndpointRegistry
;
import
org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer
;
import
javax.annotation.PostConstruct
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
/**
* 配置WebSocket消息代理端点,即stomp服务端
* @author jie
* @date 2018-12-24
*/
@Slf4j
@Configuration
public
class
WebSocketConfig
implements
WebSocketMessageBrokerConfigurer
{
@Autowired
private
SimpMessagingTemplate
messagingTemplate
;
@Override
public
void
registerStompEndpoints
(
StompEndpointRegistry
registry
)
{
registry
.
addEndpoint
(
"/websocket"
)
.
setAllowedOrigins
(
"*"
)
.
withSockJS
();
}
/**
* 推送日志到/topic/pullLogger
*/
@PostConstruct
public
void
pushLogger
(){
ExecutorService
executorService
=
Executors
.
newFixedThreadPool
(
2
);
Runnable
runnable
=
new
Runnable
()
{
@Override
public
void
run
()
{
while
(
true
)
{
try
{
LogMessage
log
=
LoggerQueue
.
getInstance
().
poll
();
if
(
log
!=
null
){
if
(
log
.
getClassName
().
equals
(
"jdbc.resultsettable"
)){
log
.
setBody
(
"<br><pre>"
+
log
.
getBody
()+
"</pre>"
);
}
if
(
messagingTemplate
!=
null
){
messagingTemplate
.
convertAndSend
(
"/topic/logMsg"
,
log
);
}
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
}
};
executorService
.
submit
(
runnable
);
executorService
.
submit
(
runnable
);
}
}
\ No newline at end of file
src/main/java/me/zhengjie/monitor/domain/LogMessage.java
0 → 100644
View file @
4765785c
package
me.zhengjie.monitor.domain
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
/**
* @author 郑杰
* @date 2018-12-24
*/
@Data
@AllArgsConstructor
public
class
LogMessage
{
private
String
body
;
private
String
timestamp
;
private
String
threadName
;
private
String
className
;
private
String
level
;
private
String
exception
;
}
src/main/java/me/zhengjie/monitor/rest/VisitsController.java
View file @
4765785c
...
...
@@ -23,7 +23,7 @@ public class VisitsController {
@PostMapping
(
value
=
"/visits"
)
public
ResponseEntity
create
(){
visitsService
.
save
(
RequestHolder
.
getHttpServletRequest
());
visitsService
.
count
(
RequestHolder
.
getHttpServletRequest
());
return
new
ResponseEntity
(
HttpStatus
.
CREATED
);
}
...
...
src/main/java/me/zhengjie/monitor/service/VisitsService.java
View file @
4765785c
...
...
@@ -10,12 +10,17 @@ import javax.servlet.http.HttpServletRequest;
*/
public
interface
VisitsService
{
/**
* 提供给定时任务,每天0点执行
*/
void
save
();
/**
* 新增记录
* @param request
*/
@Async
void
save
(
HttpServletRequest
request
);
void
count
(
HttpServletRequest
request
);
/**
* 获取数据
...
...
src/main/java/me/zhengjie/monitor/service/impl/VisitsServiceImpl.java
View file @
4765785c
package
me.zhengjie.monitor.service.impl
;
import
lombok.extern.slf4j.Slf4j
;
import
me.zhengjie.common.utils.IpUtil
;
import
me.zhengjie.common.utils.RequestHolder
;
import
me.zhengjie.common.utils.TimeUtil
;
import
me.zhengjie.monitor.domain.Logging
;
import
me.zhengjie.monitor.domain.Visits
;
import
me.zhengjie.monitor.repository.LoggingRepository
;
import
me.zhengjie.monitor.repository.VisitsRepository
;
...
...
@@ -15,7 +12,6 @@ import org.springframework.transaction.annotation.Propagation;
import
org.springframework.transaction.annotation.Transactional
;
import
javax.servlet.http.HttpServletRequest
;
import
java.time.LocalDate
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -37,20 +33,28 @@ public class VisitsServiceImpl implements VisitsService {
private
LoggingRepository
loggingRepository
;
@Override
public
void
save
(
HttpServletRequest
request
)
{
public
void
save
()
{
LocalDate
localDate
=
LocalDate
.
now
();
Visits
visits
=
visitsRepository
.
findByDate
(
localDate
.
toString
());
if
(
visits
!=
null
){
visits
.
setPvCounts
(
visits
.
getPvCounts
()+
1
);
long
ipCounts
=
loggingRepository
.
findIp
(
localDate
.
toString
(),
localDate
.
plusDays
(
1
).
toString
());
visits
.
setIpCounts
(
ipCounts
);
}
else
{
if
(
visits
==
null
){
visits
=
new
Visits
();
visits
.
setWeekDay
(
TimeUtil
.
getWeekDay
());
visits
.
setPvCounts
(
1L
);
visits
.
setIpCounts
(
1L
);
visits
.
setDate
(
localDate
.
toString
());
}
}
@Override
public
void
count
(
HttpServletRequest
request
)
{
// 部署到线上后,可将save()删除
save
();
LocalDate
localDate
=
LocalDate
.
now
();
Visits
visits
=
visitsRepository
.
findByDate
(
localDate
.
toString
());
visits
.
setPvCounts
(
visits
.
getPvCounts
()+
1
);
long
ipCounts
=
loggingRepository
.
findIp
(
localDate
.
toString
(),
localDate
.
plusDays
(
1
).
toString
());
visits
.
setIpCounts
(
ipCounts
);
visitsRepository
.
save
(
visits
);
}
...
...
@@ -59,13 +63,6 @@ public class VisitsServiceImpl implements VisitsService {
Map
map
=
new
HashMap
();
LocalDate
localDate
=
LocalDate
.
now
();
Visits
visits
=
visitsRepository
.
findByDate
(
localDate
.
toString
());
if
(
visits
==
null
){
try
{
save
(
RequestHolder
.
getHttpServletRequest
());
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
());
}
}
List
<
Visits
>
list
=
visitsRepository
.
findAllVisits
(
localDate
.
minusDays
(
6
).
toString
(),
localDate
.
plusDays
(
1
).
toString
());
long
recentVisits
=
0
,
recentIp
=
0
;
...
...
src/main/java/me/zhengjie/system/repository/MenuRepository.java
View file @
4765785c
...
...
@@ -25,7 +25,7 @@ public interface MenuRepository extends JpaRepository<Menu, Long>, JpaSpecificat
* @param roleSet
* @return
*/
Set
<
Menu
>
findByRoles
(
Set
<
Role
>
roleSet
);
Set
<
Menu
>
findByRoles
OrderBySoft
(
Set
<
Role
>
roleSet
);
/**
* findByPid
...
...
src/main/java/me/zhengjie/system/rest/MenuController.java
View file @
4765785c
...
...
@@ -53,7 +53,6 @@ public class MenuController {
@GetMapping
(
value
=
"/menus/build"
)
public
ResponseEntity
buildMenus
(
HttpServletRequest
request
){
User
user
=
userService
.
findByName
(
jwtTokenUtil
.
getUserName
(
request
));
List
<
MenuDTO
>
menuDTOList
=
menuService
.
findByRoles
(
user
.
getRoles
());
return
new
ResponseEntity
(
menuService
.
buildMenus
((
List
<
MenuDTO
>)
menuService
.
buildTree
(
menuDTOList
).
get
(
"content"
)),
HttpStatus
.
OK
);
}
...
...
src/main/java/me/zhengjie/system/service/impl/MenuServiceImpl.java
View file @
4765785c
...
...
@@ -37,7 +37,7 @@ public class MenuServiceImpl implements MenuService {
@Override
public
List
<
MenuDTO
>
findByRoles
(
Set
<
Role
>
roles
)
{
Set
<
Menu
>
menus
=
menuRepository
.
findByRoles
(
roles
);
Set
<
Menu
>
menus
=
menuRepository
.
findByRoles
OrderBySoft
(
roles
);
return
menus
.
stream
().
map
(
menuMapper:
:
toDto
).
collect
(
Collectors
.
toList
());
}
...
...
@@ -141,6 +141,7 @@ public class MenuServiceImpl implements MenuService {
if
(
menuDTO
.
getPid
().
equals
(
0L
)){
//一级目录需要加斜杠,不然访问不了
menuVo
.
setPath
(
"/"
+
menuDTO
.
getPath
());
menuVo
.
setName
(
null
);
}
menuVo
.
setComponent
(
StrUtil
.
isEmpty
(
menuDTO
.
getComponent
())?
"Layout"
:
menuDTO
.
getComponent
());
}
...
...
src/main/resources/logback.xml
View file @
4765785c
...
...
@@ -9,6 +9,9 @@
<pattern>
%black(%contextName-) %red(%d{yyyy-MM-dd HH:mm:ss}) %green([%thread]) %highlight(%-5level) %boldMagenta(%logger{36}) - %gray(%msg%n)
</pattern>
<charset>
utf-8
</charset>
</encoder>
<!--添加我们自定义的filter-->
<filter
class=
"me.zhengjie.monitor.config.LogFilter"
></filter>
</appender>
<!--输出到文件-->
...
...
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