plugin: Add history elapsed

This commit is contained in:
qianmoQ 2022-10-05 02:53:29 +08:00
parent 710c82d36e
commit 0e2da300f4
6 changed files with 48 additions and 7 deletions

View File

@ -11,6 +11,8 @@ import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
import java.sql.Timestamp;
@ -23,6 +25,7 @@ public class AuditPluginHandler
{
private final PluginAuditRepository pluginAuditRepository;
private final SourceRepository sourceRepository;
private PluginAuditEntity pluginAudit;
public AuditPluginHandler(PluginAuditRepository pluginAuditRepository, SourceRepository sourceRepository)
{
@ -30,11 +33,21 @@ public class AuditPluginHandler
this.sourceRepository = sourceRepository;
}
@Pointcut("@annotation(auditPlugin)")
public void cut(AuditPlugin auditPlugin)
{
}
@Before("cut(auditPlugin)")
public void doBefore(AuditPlugin auditPlugin)
{
this.pluginAudit = new PluginAuditEntity();
pluginAudit.setCreateTime(Timestamp.valueOf(LocalDateTime.now()));
}
@AfterReturning(pointcut = "@annotation(auditPlugin)", returning = "jsonResult")
public void doAfterReturning(JoinPoint joinPoint, AuditPlugin auditPlugin, Response jsonResult)
{
PluginAuditEntity pluginAudit = new PluginAuditEntity();
pluginAudit.setCreateTime(Timestamp.valueOf(LocalDateTime.now()));
handlerPlugin(joinPoint, pluginAudit, jsonResult);
}

View File

@ -50,8 +50,17 @@ public class PluginAuditEntity
@Column(name = "end_time", columnDefinition = "datetime(5) default CURRENT_TIMESTAMP()")
private Timestamp endTime;
@Column(name = "elapsed")
private Long elapsed;
@ManyToOne
@JoinColumn(name = "plugin_id")
@JsonIncludeProperties(value = {"name", "type"})
private SourceEntity plugin;
public void setEndTime(Timestamp endTime)
{
this.endTime = endTime;
this.elapsed = this.endTime.getTime() - this.createTime.getTime();
}
}

View File

@ -36,8 +36,3 @@ CREATE TABLE IF NOT EXISTS `source`
PRIMARY KEY (`id`)
) DEFAULT CHARSET = utf8
COLLATE = utf8_bin COMMENT ='The storage is used to query the data connection source';
-- If it already contains historical data, please use the following script to fix it
ALTER TABLE `datacap`.`audit_plugin`
MODIFY COLUMN `create_time` timestamp(5) NULL DEFAULT CURRENT_TIMESTAMP(5),
MODIFY COLUMN `end_time` timestamp(5) NULL DEFAULT CURRENT_TIMESTAMP(5);

View File

@ -0,0 +1,6 @@
-- If it already contains historical data, please use the following script to fix it
ALTER TABLE `datacap`.`audit_plugin`
MODIFY COLUMN `create_time` timestamp(5) NULL DEFAULT CURRENT_TIMESTAMP(5),
MODIFY COLUMN `end_time` timestamp(5) NULL DEFAULT CURRENT_TIMESTAMP(5);
ALTER TABLE `datacap`.`audit_plugin`
ADD COLUMN `elapsed` bigint NULL DEFAULT 0;

View File

@ -26,6 +26,12 @@ const headers = [
key: 'endTime',
ellipsis: true
},
{
title: 'Elapsed',
name: 'elapsed',
dataIndex: 'elapsed',
key: 'elapsed'
},
{
title: 'State',
name: 'state',

View File

@ -3,6 +3,18 @@
<a-card title="Plugin Audit" size="small">
<a-table size="middle" :loading="loading" :columns="headers" :data-source="columns" :pagination="pagination"
@change="handlerTableChange($event)">
<template #headerCell="{ column }">
<template v-if="column.key === 'elapsed'">
<span>
{{column.title}} &nbsp;
<a-tooltip>
<template #title>The value is expressed in milliseconds</template>
<question-circle-outlined />
</a-tooltip>
</span>
</template>
</template>
<template #bodyCell="{ column, record }">
<template v-if="column.dataIndex === 'plugin'">
{{record.plugin.name}}