Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
J
jyzb_platformV2
概览
Overview
Details
Activity
Cycle Analytics
版本库
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
问题
0
Issues
0
列表
Board
标记
里程碑
合并请求
0
Merge Requests
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
Snippets
成员
Members
Collapse sidebar
Close sidebar
活动
图像
聊天
创建新问题
作业
提交
Issue Boards
Open sidebar
赵剑炜
jyzb_platformV2
Commits
5240b5de
Commit
5240b5de
authored
Dec 18, 2023
by
赵剑炜
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加ESlog,尚未完成
parent
831b1535
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
456 行增加
和
0 行删除
+456
-0
pom.xml
jyzb-biz/pom.xml
+6
-0
EsLog.java
jyzb-biz/src/main/java/com/junmp/jyzb/entity/EsLog.java
+165
-0
ESRecordManager.java
jyzb-biz/src/main/java/com/junmp/jyzb/logManager/ESRecordManager.java
+167
-0
EsLogManager.java
jyzb-biz/src/main/java/com/junmp/jyzb/logManager/EsLogManager.java
+55
-0
EsLogService.java
jyzb-biz/src/main/java/com/junmp/jyzb/logManager/service/EsLogService.java
+22
-0
EsLogServiceImpl.java
jyzb-biz/src/main/java/com/junmp/jyzb/logManager/service/impl/EsLogServiceImpl.java
+22
-0
EsLogMapper.java
jyzb-biz/src/main/java/com/junmp/jyzb/mapper/EsLogMapper.java
+19
-0
没有找到文件。
jyzb-biz/pom.xml
View file @
5240b5de
...
...
@@ -138,5 +138,11 @@
<version>
3.5.2
</version>
<scope>
compile
</scope>
</dependency>
<dependency>
<groupId>
com.junmp.v2
</groupId>
<artifactId>
v2-log-db
</artifactId>
<version>
1.0.0
</version>
<scope>
compile
</scope>
</dependency>
</dependencies>
</project>
jyzb-biz/src/main/java/com/junmp/jyzb/entity/EsLog.java
0 → 100644
View file @
5240b5de
package
com
.
junmp
.
jyzb
.
entity
;
import
com.baomidou.mybatisplus.annotation.IdType
;
import
com.baomidou.mybatisplus.annotation.TableField
;
import
com.baomidou.mybatisplus.annotation.TableId
;
import
com.baomidou.mybatisplus.annotation.TableName
;
import
com.junmp.v2.db.api.entity.BaseEntity
;
import
org.springframework.data.elasticsearch.annotations.Document
;
@TableName
(
"sys_log"
)
@Document
(
indexName
=
"sys_log"
,
shards
=
1
,
replicas
=
1
)
public
class
EsLog
extends
BaseEntity
{
@TableId
(
value
=
"log_id"
,
type
=
IdType
.
ASSIGN_ID
)
private
Long
logId
;
@TableField
(
"log_name"
)
private
String
logName
;
@TableField
(
"log_content"
)
private
String
logContent
;
@TableField
(
"app_name"
)
private
String
appName
;
@TableField
(
"log_type"
)
private
Integer
logType
;
@TableField
(
"request_url"
)
private
String
requestUrl
;
@TableField
(
"request_params"
)
private
String
requestParams
;
@TableField
(
"request_result"
)
private
String
requestResult
;
@TableField
(
"server_ip"
)
private
String
serverIp
;
@TableField
(
"client_ip"
)
private
String
clientIp
;
@TableField
(
"user_id"
)
private
Long
userId
;
@TableField
(
"http_method"
)
private
String
httpMethod
;
@TableField
(
"client_browser"
)
private
String
clientBrowser
;
@TableField
(
"client_os"
)
private
String
clientOs
;
public
EsLog
()
{
}
public
Long
getLogId
()
{
return
this
.
logId
;
}
public
String
getLogName
()
{
return
this
.
logName
;
}
public
String
getLogContent
()
{
return
this
.
logContent
;
}
public
String
getAppName
()
{
return
this
.
appName
;
}
public
Integer
getLogType
()
{
return
this
.
logType
;
}
public
String
getRequestUrl
()
{
return
this
.
requestUrl
;
}
public
String
getRequestParams
()
{
return
this
.
requestParams
;
}
public
String
getRequestResult
()
{
return
this
.
requestResult
;
}
public
String
getServerIp
()
{
return
this
.
serverIp
;
}
public
String
getClientIp
()
{
return
this
.
clientIp
;
}
public
Long
getUserId
()
{
return
this
.
userId
;
}
public
String
getHttpMethod
()
{
return
this
.
httpMethod
;
}
public
String
getClientBrowser
()
{
return
this
.
clientBrowser
;
}
public
String
getClientOs
()
{
return
this
.
clientOs
;
}
public
void
setLogId
(
final
Long
logId
)
{
this
.
logId
=
logId
;
}
public
void
setLogName
(
final
String
logName
)
{
this
.
logName
=
logName
;
}
public
void
setLogContent
(
final
String
logContent
)
{
this
.
logContent
=
logContent
;
}
public
void
setAppName
(
final
String
appName
)
{
this
.
appName
=
appName
;
}
public
void
setLogType
(
final
Integer
logType
)
{
this
.
logType
=
logType
;
}
public
void
setRequestUrl
(
final
String
requestUrl
)
{
this
.
requestUrl
=
requestUrl
;
}
public
void
setRequestParams
(
final
String
requestParams
)
{
this
.
requestParams
=
requestParams
;
}
public
void
setRequestResult
(
final
String
requestResult
)
{
this
.
requestResult
=
requestResult
;
}
public
void
setServerIp
(
final
String
serverIp
)
{
this
.
serverIp
=
serverIp
;
}
public
void
setClientIp
(
final
String
clientIp
)
{
this
.
clientIp
=
clientIp
;
}
public
void
setUserId
(
final
Long
userId
)
{
this
.
userId
=
userId
;
}
public
void
setHttpMethod
(
final
String
httpMethod
)
{
this
.
httpMethod
=
httpMethod
;
}
public
void
setClientBrowser
(
final
String
clientBrowser
)
{
this
.
clientBrowser
=
clientBrowser
;
}
public
void
setClientOs
(
final
String
clientOs
)
{
this
.
clientOs
=
clientOs
;
}
public
String
toString
()
{
return
"SysLog(logId="
+
this
.
getLogId
()
+
", logName="
+
this
.
getLogName
()
+
", logContent="
+
this
.
getLogContent
()
+
", appName="
+
this
.
getAppName
()
+
", logType="
+
this
.
getLogType
()
+
", requestUrl="
+
this
.
getRequestUrl
()
+
", requestParams="
+
this
.
getRequestParams
()
+
", requestResult="
+
this
.
getRequestResult
()
+
", serverIp="
+
this
.
getServerIp
()
+
", clientIp="
+
this
.
getClientIp
()
+
", userId="
+
this
.
getUserId
()
+
", httpMethod="
+
this
.
getHttpMethod
()
+
", clientBrowser="
+
this
.
getClientBrowser
()
+
", clientOs="
+
this
.
getClientOs
()
+
")"
;
}
}
\ No newline at end of file
jyzb-biz/src/main/java/com/junmp/jyzb/logManager/ESRecordManager.java
0 → 100644
View file @
5240b5de
package
com
.
junmp
.
jyzb
.
logManager
;
import
cn.hutool.core.bean.BeanUtil
;
import
cn.hutool.core.collection.CollectionUtil
;
import
cn.hutool.core.util.ObjectUtil
;
import
cn.hutool.core.util.StrUtil
;
import
com.junmp.jyzb.logManager.service.EsLogService
;
import
com.junmp.v2.log.api.LogRecordApi
;
import
com.junmp.v2.log.api.bean.dto.LogRecordDto
;
import
com.junmp.v2.log.api.thread.LogManagerPool
;
import
com.junmp.v2.log.db.entity.SysLog
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Queue
;
import
java.util.TimerTask
;
import
java.util.concurrent.ConcurrentLinkedQueue
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.atomic.AtomicInteger
;
import
java.util.concurrent.atomic.AtomicLong
;
import
java.util.stream.Collectors
;
public
class
ESRecordManager
implements
LogRecordApi
{
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
com
.
junmp
.
v2
.
log
.
db
.
DbLogRecordManager
.
class
);
private
final
EsLogService
esService
;
private
final
LogManagerPool
logManagerPool
;
private
final
LogRefreshManager
logRefreshManager
;
public
ESRecordManager
(
LogManagerPool
logManagerPool
,
EsLogService
esService
)
{
this
.
logManagerPool
=
logManagerPool
;
this
.
esService
=
esService
;
this
.
logRefreshManager
=
new
ESRecordManager
.
LogRefreshManager
();
this
.
logRefreshManager
.
start
();
}
public
void
add
(
LogRecordDto
logRecord
)
{
if
(
null
!=
logRecord
)
{
this
.
addBatch
(
CollectionUtil
.
list
(
false
,
new
LogRecordDto
[]{
logRecord
}));
}
}
public
void
addAsync
(
final
LogRecordDto
logRecord
)
{
this
.
logManagerPool
.
executeLog
(
new
TimerTask
()
{
public
void
run
()
{
ESRecordManager
.
this
.
logRefreshManager
.
putLog
(
logRecord
);
}
});
}
public
void
addBatch
(
List
<
LogRecordDto
>
logRecords
)
{
if
(!
ObjectUtil
.
isEmpty
(
logRecords
))
{
List
<
SysLog
>
sysLogList
=
(
List
)
logRecords
.
stream
().
map
((
dto
)
->
{
SysLog
sysLog
=
new
SysLog
();
BeanUtil
.
copyProperties
(
dto
,
sysLog
,
new
String
[
0
]);
if
(
StrUtil
.
isEmpty
(
sysLog
.
getLogName
()))
{
sysLog
.
setLogName
(
"API接口日志记录"
);
}
if
(
StrUtil
.
isEmpty
(
sysLog
.
getAppName
()))
{
sysLog
.
setAppName
(
"none-app-name"
);
}
return
sysLog
;
}).
collect
(
Collectors
.
toList
());
if
(
ObjectUtil
.
isNotEmpty
(
sysLogList
))
{
// this.esService.saveBatch(sysLogList);
}
}
}
class
LogRefreshManager
extends
Thread
{
private
final
long
sleepTime
;
private
final
int
maxCount
;
private
final
AtomicLong
refreshMark
=
new
AtomicLong
();
public
AtomicInteger
count
=
new
AtomicInteger
(
0
);
private
final
Queue
<
LogRecordDto
>
queue
=
new
ConcurrentLinkedQueue
();
public
LogRefreshManager
()
{
this
.
sleepTime
=
3000L
;
this
.
maxCount
=
300
;
}
public
LogRefreshManager
(
long
sleepTime
)
{
this
.
sleepTime
=
sleepTime
;
this
.
maxCount
=
300
;
}
public
LogRefreshManager
(
int
maxCount
)
{
this
.
sleepTime
=
3000L
;
this
.
maxCount
=
maxCount
;
}
public
LogRefreshManager
(
long
sleepTime
,
int
maxCount
)
{
this
.
sleepTime
=
sleepTime
;
this
.
maxCount
=
maxCount
;
}
public
void
putLog
(
LogRecordDto
record
)
{
int
queueDataCount
=
this
.
count
.
get
();
if
(
queueDataCount
==
0
)
{
this
.
refreshMark
.
getAndSet
(
System
.
currentTimeMillis
());
}
if
(
queueDataCount
<
this
.
maxCount
*
2
)
{
this
.
queue
.
offer
(
record
);
this
.
count
.
incrementAndGet
();
}
}
private
void
refresh
()
{
this
.
refreshMark
.
getAndSet
(
System
.
currentTimeMillis
());
int
num
=
this
.
count
.
getAndSet
(
0
);
List
<
LogRecordDto
>
cacheAll
=
new
ArrayList
(
num
);
for
(
int
i
=
0
;
i
<
num
;
++
i
)
{
LogRecordDto
item
=
(
LogRecordDto
)
this
.
queue
.
poll
();
if
(
null
==
item
)
{
break
;
}
cacheAll
.
add
(
item
);
}
// if (null != cacheAll && cacheAll.size() > 0) {
// this.addBatch(cacheAll);
// }
}
private
void
timing
()
{
long
currentTimeMillis
=
System
.
currentTimeMillis
();
if
(
this
.
refreshMark
.
get
()
+
this
.
sleepTime
<=
currentTimeMillis
&&
this
.
count
.
get
()
>
0
)
{
this
.
refresh
();
}
}
private
void
listener
()
{
if
(
this
.
count
.
get
()
>=
this
.
maxCount
)
{
this
.
refresh
();
}
}
public
void
run
()
{
try
{
while
(
true
)
{
this
.
listener
();
this
.
timing
();
TimeUnit
.
MILLISECONDS
.
sleep
(
10L
);
}
}
catch
(
InterruptedException
var2
)
{
if
(
ESRecordManager
.
log
.
isDebugEnabled
())
{
var2
.
printStackTrace
();
}
ESRecordManager
.
log
.
error
(
var2
.
getMessage
());
}
}
}
}
\ No newline at end of file
jyzb-biz/src/main/java/com/junmp/jyzb/logManager/EsLogManager.java
0 → 100644
View file @
5240b5de
package
com
.
junmp
.
jyzb
.
logManager
;
import
cn.hutool.core.bean.BeanUtil
;
import
cn.hutool.core.collection.CollUtil
;
import
cn.hutool.core.util.ObjectUtil
;
import
com.junmp.v2.db.api.page.PageResult
;
import
com.junmp.v2.log.api.LogManagerApi
;
import
com.junmp.v2.log.api.bean.dto.LogRecordDto
;
import
com.junmp.v2.log.api.bean.req.LogRequest
;
import
com.junmp.v2.log.db.entity.SysLog
;
import
com.junmp.v2.log.db.service.SysLogService
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
javax.annotation.Resource
;
import
java.util.*
;
public
class
EsLogManager
implements
LogManagerApi
{
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
EsLogManager
.
class
);
@Resource
private
SysLogService
sysLogService
;
public
EsLogManager
()
{
}
public
List
<
LogRecordDto
>
findList
(
LogRequest
request
)
{
List
<
SysLog
>
sysLogList
=
this
.
sysLogService
.
findList
(
request
);
List
<
LogRecordDto
>
dtoList
=
CollUtil
.
newArrayList
(
new
LogRecordDto
[
0
]);
BeanUtil
.
copyProperties
(
sysLogList
,
dtoList
,
new
String
[
0
]);
return
dtoList
;
}
public
PageResult
<
LogRecordDto
>
findPage
(
LogRequest
request
)
{
return
this
.
sysLogService
.
getLogPage
(
request
);
}
public
void
del
(
LogRequest
request
)
{
this
.
sysLogService
.
del
(
request
);
}
public
void
clearLog
(
LogRequest
request
)
{
if
(
ObjectUtil
.
isNotNull
(
request
)
&&
ObjectUtil
.
isNotNull
(
request
.
getLogType
()))
{
this
.
sysLogService
.
clearLogByDate
(
request
);
}
}
public
LogRecordDto
detail
(
LogRequest
request
)
{
SysLog
detail
=
this
.
sysLogService
.
detail
(
request
);
LogRecordDto
dto
=
new
LogRecordDto
();
BeanUtil
.
copyProperties
(
detail
,
dto
,
new
String
[
0
]);
return
dto
;
}
}
jyzb-biz/src/main/java/com/junmp/jyzb/logManager/service/EsLogService.java
0 → 100644
View file @
5240b5de
package
com
.
junmp
.
jyzb
.
logManager
.
service
;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.junmp.jyzb.api.bean.dto.ESTypeDto
;
import
com.junmp.jyzb.api.bean.dto.EquipmentTreeDto
;
import
com.junmp.jyzb.api.bean.dto.EquipmentTypeDto
;
import
com.junmp.jyzb.api.bean.query.QueryEquipmentTypeReq
;
import
com.junmp.jyzb.api.bean.req.UpdateEquipmentTypeReq
;
import
com.junmp.jyzb.entity.EquipmentType
;
import
com.junmp.jyzb.entity.EsLog
;
import
com.junmp.jyzb.utils.ResponseResult
;
import
java.io.IOException
;
import
java.util.List
;
public
interface
EsLogService
extends
IService
<
EsLog
>
{
Object
addEs
();
}
\ No newline at end of file
jyzb-biz/src/main/java/com/junmp/jyzb/logManager/service/impl/EsLogServiceImpl.java
0 → 100644
View file @
5240b5de
package
com
.
junmp
.
jyzb
.
logManager
.
service
.
impl
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.junmp.jyzb.entity.EquipmentType
;
import
com.junmp.jyzb.entity.EsLog
;
import
com.junmp.jyzb.logManager.service.EsLogService
;
import
com.junmp.jyzb.mapper.EquipmentTypeMapper
;
import
com.junmp.jyzb.mapper.EsLogMapper
;
import
com.junmp.jyzb.service.EquipmentTypeService
;
import
org.springframework.stereotype.Service
;
@Service
public
class
EsLogServiceImpl
extends
ServiceImpl
<
EsLogMapper
,
EsLog
>
implements
EsLogService
{
@Override
public
Object
addEs
()
{
return
null
;
}
}
jyzb-biz/src/main/java/com/junmp/jyzb/mapper/EsLogMapper.java
0 → 100644
View file @
5240b5de
package
com
.
junmp
.
jyzb
.
mapper
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
com.junmp.jyzb.entity.EquipmentType
;
import
com.junmp.jyzb.entity.EsLog
;
import
org.apache.ibatis.annotations.Mapper
;
import
org.apache.ibatis.annotations.Param
;
import
java.util.List
;
@Mapper
public
interface
EsLogMapper
extends
BaseMapper
<
EsLog
>
{
}
\ No newline at end of file
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论