Commit c01b2f57 authored by 赵啸非's avatar 赵啸非

前端页面添加

parent b86d8606
......@@ -3,30 +3,38 @@
-- ----------------------------
DROP TABLE IF EXISTS `mortals_xhx_access_log`;
CREATE TABLE mortals_xhx_access_log(
`id` bigint(20) AUTO_INCREMENT COMMENT '主键ID,主键,自增长',
`traceID` varchar(64) COMMENT '追踪Id',
`id` bigint(20) NOT NULL COMMENT '主键ID',
`traceID` varchar(64) COMMENT 'TraceId',
`pspanId` int(9) COMMENT '父服务调用id',
`spanId` int(9) COMMENT '当前服务跨度Id',
`appName` varchar(64) COMMENT '应用名称',
`hostName` varchar(64) COMMENT '实例IP',
`targetServer` varchar(64) COMMENT '目标服务',
`logLevel` varchar(64) COMMENT '日志等级',
`requestIp` varchar(64) COMMENT '请求者IP',
`method` varchar(64) COMMENT '请求方式',
`schema` varchar(64) COMMENT '协议',
`ua` varchar(64) COMMENT '用户浏览器UA',
`uri` varchar(64) COMMENT '请求URI',
`requestParam` text COMMENT '请求参数,json序列化',
`response` text COMMENT '响应结果',
`logTime` datetime COMMENT '日志产生时间',
`duration` int(4) COMMENT '持续时间,单位毫秒',
`requestData` varchar(2048) COMMENT '请求参数,json序列化',
`responseData` mediumtext COMMENT '响应结果,',
`logTime` datetime NOT NULL COMMENT '日志产生时间',
`requestTime` datetime COMMENT '请求时间',
`responseTime` datetime COMMENT '响应时间',
`duration` bigint(20) COMMENT '持续时间,单位毫秒',
`createUserId` bigint(20) NOT NULL COMMENT '创建用户',
`createTime` datetime NOT NULL COMMENT '创建时间',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='访问日志';
-- ----------------------------
-- 业务日志表
-- ----------------------------
DROP TABLE IF EXISTS `mortals_xhx_biz_log`;
CREATE TABLE mortals_xhx_biz_log(
`id` bigint(20) AUTO_INCREMENT COMMENT '主键ID,主键,自增长',
`id` bigint(20) COMMENT '主键ID',
`traceID` varchar(64) COMMENT '追踪Id',
`appName` varchar(64) COMMENT '应用名称',
`hostName` varchar(64) COMMENT '实例IP',
......@@ -47,7 +55,7 @@ PRIMARY KEY (`id`)
-- ----------------------------
DROP TABLE IF EXISTS `mortals_xhx_error_log`;
CREATE TABLE mortals_xhx_error_log(
`id` bigint(20) AUTO_INCREMENT COMMENT '主键ID,主键,自增长',
`id` bigint(20) COMMENT '主键ID',
`traceID` varchar(64) COMMENT '追踪Id',
`serverType` varchar(64) COMMENT '服务类型,webOS,android,IOS,服务后端',
`appName` varchar(64) COMMENT '应用名称',
......@@ -67,13 +75,13 @@ PRIMARY KEY (`id`)
-- ----------------------------
DROP TABLE IF EXISTS `mortals_xhx_operate_log`;
CREATE TABLE mortals_xhx_operate_log(
`id` bigint(20) AUTO_INCREMENT COMMENT '序号,主键,自增长',
`id` bigint(20) COMMENT '主键ID',
`platformMark` varchar(50) COMMENT '平台标识',
`userId` bigint(20) COMMENT '用户id',
`userName` varchar(50) COMMENT '用户名称',
`loginName` varchar(50) COMMENT '用户登录名',
`requestUrl` varchar(200) COMMENT '请求地址',
`content` varchar(2000) COMMENT '操作内容,记录操作具体信息,如修改前修改或的数据',
`content` varchar(2048) COMMENT '操作内容,记录操作具体信息,如修改前修改或的数据',
`ip` varchar(30) COMMENT '操作IP地址',
`logDate` datetime COMMENT '操作时间',
`operType` tinyint(2) COMMENT '操作类型,0:新增,1:修改,2:删除',
......
This diff is collapsed.
......@@ -5,7 +5,7 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
<title>设备管理平台</title>
<title>日志管理平台</title>
<link rel="stylesheet" href="https://unpkg.com/element-ui@2.15.5/lib/theme-chalk/index.css">
</head>
<body>
......
......@@ -5,7 +5,7 @@ import cookie from './cookie';
import httpErrorHandler from './httpErrorHandler';
const instance = axios.create({
baseURL: '/m',
baseURL: '/logservice',
headers: {
post: {
'Content-Type': 'application/json;charset=UTF-8',
......
......@@ -57,6 +57,11 @@ export default {
type: Number,
default: 12,
},
rows: {
type: Number,
default: 2,
},
// 字段类型: text,password,textarea,select,radio,checkbox,date,datetime
type: {
type: String,
......
......@@ -9,7 +9,7 @@
<i class="el-icon-menu" @click='showMobileMenu=!showMobileMenu'> </i>
<router-link to="/">
<img src="../assets/images/logo.png" style="margin-bottom:5px" height="40" alt="">
<b style="color:white;font-size:18px;">&nbsp;&nbsp;&nbsp; AIOT智慧边缘物联网系统 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b>
<b style="color:white;font-size:18px;">&nbsp;&nbsp;&nbsp; 日志管理系统 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b>
</router-link>
</div>
......
......@@ -40,10 +40,10 @@ const router = new Router({
...restBuilder('task', 'system/task'), // 系统管理--任务管理
...restBuilder('access', 'access'), //链路访问日志
...restBuilder('biz', 'biz'), //业务日志
...restBuilder('biz', 'biz'), //异常日志
...restBuilder('operate', 'operate'), //操作日志
...restBuilder('access/log', 'access/log'), //链路访问日志
...restBuilder('biz/log', 'biz/log'), //业务日志
...restBuilder('error/log', 'error/log'), //异常日志
...restBuilder('operate/log', 'operate/log'), //操作日志
//以下为基础路由配置
......
This diff is collapsed.
......@@ -4,25 +4,25 @@
:title="title"
:visible.sync="open"
:direction="direction"
size="50%">
size="70%">
<el-form ref="form" :model="form" :rules="rules" label-width="120px">
<el-row>
<Field label="追踪Id" prop="traceID" v-model="form.traceID" placeholder="请输入追踪Id"/>
<Field label="追踪Id" prop="traceID" v-model="form.traceID" placeholder="请输入追踪Id"/>
<Field label="应用名称" prop="appName" v-model="form.appName" placeholder="请输入应用名称"/>
<Field label="实例IP" prop="hostName" v-model="form.hostName" placeholder="请输入实例IP"/>
<Field label="日志等级" prop="logLevel" v-model="form.logLevel" placeholder="请输入日志等级"/>
<Field label="请求者IP" prop="requestIp" v-model="form.requestIp" placeholder="请输入请求者IP"/>
<Field label="请求方式" prop="method" v-model="form.method" placeholder="请输入请求方式"/>
<Field label="用户浏览器UA" prop="ua" v-model="form.ua" placeholder="请输入用户浏览器UA"/>
<Field label="请求URI" prop="uri" v-model="form.uri" placeholder="请输入请求URI"/>
<Field label="请求参数,json序列化" prop="requestParam" v-model="form.requestParam" type="textarea" placeholder="请输入请求参数,json序列化"/>
<Field label="响应结果" prop="response" v-model="form.response" type="textarea" placeholder="请输入响应结果"/>
<Field label="日志产生时间" prop="logTime" v-model="form.logTime" type="date" />
<Field label="持续时间,单位毫秒" prop="duration" v-model="form.duration" placeholder="请输入持续时间,单位毫秒"/>
<Field label="日志时间" prop="logTime" v-model="form.logTime" type="date" />
<Field label="持续时间" prop="duration" v-model="form.duration+'ms'" placeholder="请输入持续时间,单位毫秒"/>
<Field label="请求参数" :span="22" prop="requestData" v-model="form.requestData" type="textarea" placeholder="请输入请求参数,json序列化"/>
<Field label="响应结果" :span="22" prop="responseData" v-model="form.responseData" rows=6 type="textarea" placeholder="请输入响应结果"/>
</el-row>
<form-buttons @submit='submitForm' noCancelBtn />
</el-form>
</el-drawer>
......@@ -41,6 +41,7 @@
},
data() {
return {
row:6,
// 遮罩层
loading: true,
// 弹出层标题
......
<template>
<div class="page">
<LayoutTable :data="tableData" :config="tableConfig">
<LayoutTable :data="tableData" notAdd notDel :config="tableConfig">
</LayoutTable>
......@@ -60,26 +60,40 @@
},
],
columns: [
{type: "selection", width: 60},
{type: "index",label: "序号",width: 50},
{type: "index",label: "序号",width: 50,align:"center"},
{label: "追踪Id", prop: "traceID"},
{label: "TraceID", prop: "traceID"},
{label: "应用名称", prop: "appName"},
{label: "spanId", prop: "spanId",width: 70},
{label: "pspanId", prop: "pspanId",width: 70},
{label: "请求方式", prop: "method",width: 70},
{label: "当前服务", prop: "appName"},
{label: "目标服务", prop: "targetServer"},
{label: "请求方式", prop: "method"},
{label: "请求URI", prop: "uri"},
{label: "请求参数", prop: "requestData"},
{label: "日志时间", prop: "logTime", formatter: this.formatterDate},
{label: "日志产生时间", prop: "logTime", formatter: this.formatterDate},
{label: "持续时间,单位毫秒", prop: "duration",formatter: this.formatter},
{label: "持续时间", prop: "duration",width:70, formatter: row => {
return (
<span>{row.duration}ms</span>
)}},
{
label: "操作",
width: 240,
width: 120,
formatter: row => {
return (
<table-buttons noAdd row={row} onEdit={this.toEdit} onView={this.toView} onDel={this.toDel} />
<table-buttons noAdd noEdit noDel row={row} onEdit={this.toEdit} onView={this.toView} onDel={this.toDel} />
);
}
}
......
<template>
<div class="page">
<LayoutTable :data="tableData" :config="tableConfig">
<LayoutTable :data="tableData" notAdd notDel :config="tableConfig">
</LayoutTable>
......@@ -84,10 +84,10 @@
},
],
columns: [
{type: "selection", width: 60},
{type: "index",label: "序号",width: 50},
{label: "追踪Id", prop: "traceID"},
{label: "TraceID", prop: "traceID"},
{label: "应用名称", prop: "appName"},
......@@ -102,10 +102,10 @@
{label: "日志产生时间", prop: "logTime", formatter: this.formatterDate},
{
label: "操作",
width: 240,
width: 120,
formatter: row => {
return (
<table-buttons noAdd row={row} onEdit={this.toEdit} onView={this.toView} onDel={this.toDel} />
<table-buttons noAdd noDel noEdit row={row} onEdit={this.toEdit} onView={this.toView} onDel={this.toDel} />
);
}
}
......
<template>
<div class="page">
<LayoutTable :data="tableData" :config="tableConfig">
<LayoutTable :data="tableData" notAdd notDel :config="tableConfig">
</LayoutTable>
......@@ -43,7 +43,7 @@
{
name: "traceID",
type: "text",
label: "追踪Id",
label: "TraceID",
fuzzy: true
},
{
......@@ -66,12 +66,12 @@
},
],
columns: [
{type: "selection", width: 60},
{type: "index",label: "序号",width: 50},
{type: "index",label: "序号",width: 50 ,align:"center"},
{label: "追踪Id", prop: "traceID"},
{label: "TraceID", prop: "traceID"},
{label: "服务类型,webOS,android,IOS,服务后端", prop: "serverType"},
{label: "服务类型", prop: "serverType"},
{label: "应用名称", prop: "appName"},
......@@ -83,7 +83,7 @@
width: 240,
formatter: row => {
return (
<table-buttons noAdd row={row} onEdit={this.toEdit} onView={this.toView} onDel={this.toDel} />
<table-buttons noAdd noDel noEdit row={row} onEdit={this.toEdit} onView={this.toView} onDel={this.toDel} />
);
}
}
......
......@@ -4,7 +4,7 @@
<div class="page page-login flex flex-v">
<div class="form-wrap flex flex-1">
<el-form @submit.prevent='onSubmit' ref="form" :model="form" label-width="80px" size="small">
<h1>设备管理平台</h1>
<h1>日志管理平台</h1>
<el-form-item label="用户名">
<el-input v-model="form.loginName"></el-input>
</el-form-item>
......@@ -20,64 +20,6 @@
<div class="footer">
登陆 &copy; <a href="">信宏翔网络科技有限公司</a> 出品
</div>
<!-- <Map ref="map1" :markersData="originData" @choose="getDetailData" /> -->
<!-- <el-card :body-style="{ padding: '5px' }" style="width: 300px">
<el-row type="flex" class="row-bg" justify="space-around">
<span style="font-size: 18px"><b>高新区政务服务中心</b></span>
<el-button type="text" size="mini" class="button">查看详情</el-button>
</el-row>
<el-divider></el-divider>
<el-row type="flex" justify="space-around">
<el-col :span="4">
<span style="font-size: 13px"><b>100</b></span
><br />
<span style="font-size: 12px">设备总数</span>
</el-col>
<el-col :span="4">
<span style="font-size: 13px"><b>100</b></span
><br />
<span style="font-size: 12px">在线</span>
</el-col>
<el-col :span="4">
<span style="font-size: 13px"><b>100</b></span
><br />
<span style="font-size: 12px">离线</span>
</el-col>
<el-col :span="4">
<span style="font-size: 13px"><b>100</b></span
><br />
<span style="font-size: 12px">停用</span>
</el-col>
<el-col :span="4">
<span style="font-size: 13px"><b>100</b></span
><br />
<span style="font-size: 12px">待激活</span>
</el-col>
</el-row>
<el-divider></el-divider>
<el-descriptions :column="1" size="small">
<el-descriptions-item label="站点编码"
>kooriookami</el-descriptions-item
>
<el-descriptions-item label="站点地址"
>18100000000</el-descriptions-item
>
<el-descriptions-item
label="联系人"
:labelStyle="{ 'text-align': 'right', width: '50px' }"
>苏州市</el-descriptions-item
>
<el-descriptions-item label="联系电话">
<el-tag size="small">学校</el-tag>
</el-descriptions-item>
<el-descriptions-item label="创建时间"
>江苏省苏州市吴中区吴中大道 1188 号</el-descriptions-item
>
</el-descriptions>
</el-card> -->
</div>
</template>
......
<template>
<div class="page">
<LayoutTable :data="tableData" :config="tableConfig">
<LayoutTable :data="tableData" notAdd notDel :config="tableConfig">
</LayoutTable>
......@@ -54,8 +54,8 @@
},
],
columns: [
{type: "selection", width: 60},
{type: "index",label: "序号",width: 50},
{type: "index",label: "序号",align:"center",width: 50},
{label: "平台标识", prop: "platformMark"},
......@@ -65,17 +65,17 @@
{label: "请求地址", prop: "requestUrl"},
{label: "操作内容,记录操作具体信息,如修改前修改或的数据", prop: "content"},
{label: "操作内容", prop: "content"},
{label: "操作IP地址", prop: "ip"},
{label: "操作时间", prop: "logDate", formatter: this.formatterDate},
{
label: "操作",
width: 240,
width: 120,
formatter: row => {
return (
<table-buttons noAdd row={row} onEdit={this.toEdit} onView={this.toView} onDel={this.toDel} />
<table-buttons noAdd noEdit noDel row={row} onEdit={this.toEdit} onView={this.toView} onDel={this.toDel} />
);
}
}
......
......@@ -16,7 +16,7 @@ module.exports = {
port: 8086,
hot: true,//自动保存
proxy: {
'/m': {
'/logservice': {
target: 'http://127.0.0.1:18225',
changeOrigin: true,
secure: false,
......
......@@ -32,11 +32,11 @@
<profiles.redis.username></profiles.redis.username>
<profiles.redis.password>hotel@2020</profiles.redis.password>
<profiles.redis.database>8</profiles.redis.database>
<profiles.rabbitmq.host>192.168.0.251</profiles.rabbitmq.host>
<profiles.rabbitmq.host>192.168.0.98</profiles.rabbitmq.host>
<profiles.rabbitmq.port>5672</profiles.rabbitmq.port>
<profiles.rabbitmq.username>taxi_mq</profiles.rabbitmq.username>
<profiles.rabbitmq.password>admin@2020</profiles.rabbitmq.password>
<profiles.rabbitmq.virtualhost>/test</profiles.rabbitmq.virtualhost>
<profiles.rabbitmq.virtualhost>/</profiles.rabbitmq.virtualhost>
<profiles.rabbitmq.exchange></profiles.rabbitmq.exchange>
<profiles.filepath>/mortals/data</profiles.filepath>
<profiles.log.level>DEBUG</profiles.log.level>
......@@ -113,6 +113,12 @@
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- 实现对 RabbitMQ 的自动化配置 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
......@@ -157,8 +163,8 @@
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
......
package com.mortals.xhx.base.framework.config;
import com.mortals.xhx.common.key.QueueKey;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.AsyncRabbitTemplate;
import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.boot.autoconfigure.amqp.SimpleRabbitListenerContainerFactoryConfigurer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.HashMap;
import java.util.Map;
@Configuration
public class RabbitConfig {
public Integer messageTtl = 86400000;
public Map<String, Object> args = new HashMap<>();
// 创建 Queue
@Bean
public Queue accessLogQueue() {
args.put("x-message-ttl", messageTtl);
return new Queue(QueueKey.ACCESS_LOG_QUEUE, // Queue 名字
true, // durable: 是否持久化
false, // exclusive: 是否排它
false,
args); // autoDelete: 是否自动删除
}
@Bean
public Queue bizLogQueue() {
args.put("x-message-ttl", messageTtl);
return new Queue(QueueKey.BIZ_LOG_QUEUE, // Queue 名字
true, // durable: 是否持久化
false, // exclusive: 是否排它
false, args); // autoDelete: 是否自动删除
}
@Bean
public Queue errorLogQueue() {
return new Queue(QueueKey.ERROR_LOG_QUEUE, // Queue 名字
true, // durable: 是否持久化
false, // exclusive: 是否排它
false, args); // autoDelete: 是否自动删除
}
@Bean
public Queue operationLogQueue() {
return new Queue(QueueKey.OPERATION_LOG_QUEUE, // Queue 名字
true, // durable: 是否持久化
false, // exclusive: 是否排它
false, args); // autoDelete: 是否自动删除
}
// 创建 Direct Exchange
@Bean
public DirectExchange exchange() {
return new DirectExchange(QueueKey.EXCHANGE,
true, // durable: 是否持久化
false); // exclusive: 是否排它
}
// 创建 Binding
@Bean
public Binding accessBinding() {
return BindingBuilder.bind(accessLogQueue()).to(exchange()).with(QueueKey.ACCESS_LOG_QUEUE);
}
@Bean
public Binding bizBinding() {
return BindingBuilder.bind(bizLogQueue()).to(exchange()).with(QueueKey.BIZ_LOG_QUEUE);
}
@Bean
public Binding errorBinding() {
return BindingBuilder.bind(errorLogQueue()).to(exchange()).with(QueueKey.ERROR_LOG_QUEUE);
}
@Bean
public Binding operBinding() {
return BindingBuilder.bind(operationLogQueue()).to(exchange()).with(QueueKey.OPERATION_LOG_QUEUE);
}
@Bean(name = "consumerBatchContainerFactory")
public SimpleRabbitListenerContainerFactory consumerBatchContainerFactory(
SimpleRabbitListenerContainerFactoryConfigurer configurer, ConnectionFactory connectionFactory) {
// 创建 SimpleRabbitListenerContainerFactory 对象
SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
configurer.configure(factory, connectionFactory);
// 额外添加批量消费的属性
factory.setBatchListener(true);
factory.setBatchSize(10);
factory.setReceiveTimeout(5 * 1000L);
factory.setConsumerBatchEnabled(true);
return factory;
}
//修改系列和与反序列化转换器
@Bean
public MessageConverter messageConverter() {
return new Jackson2JsonMessageConverter();
}
@Bean
public AsyncRabbitTemplate asyncRabbitTemplate(RabbitTemplate rabbitTemplate) {
AsyncRabbitTemplate asyncRabbitTemplate = new AsyncRabbitTemplate(rabbitTemplate);
asyncRabbitTemplate.setReceiveTimeout(10000);
return asyncRabbitTemplate;
}
}
package com.mortals.xhx.base.framework.listener;
import cn.hutool.core.util.IdUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.mortals.xhx.common.key.QueueKey;
import com.mortals.xhx.common.pdu.access.AccessLogPdu;
import com.mortals.xhx.module.access.model.AccessLogEntity;
import com.mortals.xhx.module.access.service.AccessLogService;
import com.mortals.xhx.module.biz.model.BizLogEntity;
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.impl.AMQImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.amqp.RabbitProperties;
import org.springframework.messaging.handler.annotation.Headers;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;
import java.nio.charset.StandardCharsets;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* rabbitmq 访问日志消息消费类
*
* @author: zxfei
* @date: 2022/8/17 20:45
* @description:
**/
@Slf4j
@Component
@RabbitListener(queues = QueueKey.ACCESS_LOG_QUEUE,
containerFactory = "consumerBatchContainerFactory")
public class AccessMessageConsumerListener {
@Autowired
private AccessLogService accessLogService;
@RabbitHandler
public void onMessage(@Payload List<String> messages, Channel channel) throws Exception {
log.info("[onMessage][线程编号:{} 消息数量:{}]", Thread.currentThread().getId(), messages.size());
// messages.forEach(entity -> {
// entity.setId(IdUtil.getSnowflake(0, 1).nextId());
// entity.setCreateUserId(1L);
// entity.setCreateTime(new Date());
// });
// accessLogService.save(messages);
List<AccessLogEntity> collect = messages.stream().map(message -> {
try {
//String json = JSONUtil.formatJsonStr(new String(message, StandardCharsets.UTF_8));
AccessLogEntity entity = JSON.parseObject(message, AccessLogEntity.class);
entity.setId(IdUtil.getSnowflake(0, 1).nextId());
entity.setCreateUserId(1L);
entity.setCreateTime(new Date());
return entity;
}catch (Exception e){
log.info("反序列化异常",e);
return null;
}
}).filter(f->f!=null).collect(Collectors.toList());
// collect.forEach(accessLogEntity -> accessLogService.save(accessLogEntity));
accessLogService.save(collect);
}
public static void main(String[] args) {
String json="{\n" +
" \"appName\":\"smart-gateway\",\n" +
" \"deleted\":0,\n" +
" \"duration\":12,\n" +
" \"hostName\":\"172.17.0.1\",\n" +
" \"logLevel\":\"INFO\",\n" +
" \"logTime\":1661239155832,\n" +
" \"method\":\"POST\",\n" +
" \"pspanId\":0,\n" +
" \"requestData\":\"\",\n" +
" \"requestIp\":\"192.168.0.217\",\n" +
" \"requestTime\":1661239155832,\n" +
" \"responseData\":\"\",\n" +
" \"responseTime\":1661239155844,\n" +
" \"schemaData\":\"http\",\n" +
" \"spanId\":1,\n" +
" \"targetServer\":\"base-manager\",\n" +
" \"traceID\":\"63047f73dacc9d863249b7c5\",\n" +
" \"ua\":\"\",\n" +
" \"uri\":\"/base/business/list\"\n" +
"}";
System.out.println(json);
AccessLogEntity accessLogEntity = new AccessLogEntity();
accessLogEntity.setRequestData(json);
System.out.println(JSON.toJSONString(accessLogEntity));
JSONObject jsonObject = new JSONObject();
jsonObject.put("111",json);
System.out.println(JSON.toJSONString(jsonObject));
System.out.println(JSONUtil.formatJsonStr(JSON.toJSONString(jsonObject)));
}
}
package com.mortals.xhx.base.framework.listener;
import com.alibaba.fastjson.JSON;
import com.mortals.xhx.common.key.QueueKey;
import com.mortals.xhx.module.access.model.AccessLogEntity;
import com.mortals.xhx.module.access.service.AccessLogService;
import com.mortals.xhx.module.biz.model.BizLogEntity;
import com.mortals.xhx.module.biz.service.BizLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
/**
* rabbitmq 业务日志消息消费类
*
* @author: zxfei
* @date: 2022/8/17 20:45
* @description:
**/
@Slf4j
@Component
@RabbitListener(queues = QueueKey.BIZ_LOG_QUEUE,
containerFactory = "consumerBatchContainerFactory")
public class BizMessageConsumerListener {
@Autowired
private BizLogService bizLogService;
@RabbitHandler
public void onMessage(List<String> messages) {
log.info("[onMessage][线程编号:{} 消息数量:{}]", Thread.currentThread().getId(), messages.size());
List<BizLogEntity> collect = messages.stream().map(str -> {
BizLogEntity entity = JSON.parseObject(str, BizLogEntity.class);
entity.setCreateUserId(1L);
entity.setCreateTime(new Date());
return entity;
}).collect(Collectors.toList());
bizLogService.save(collect);
}
}
package com.mortals.xhx.base.framework.listener;
import com.alibaba.fastjson.JSON;
import com.mortals.xhx.common.key.QueueKey;
import com.mortals.xhx.module.access.model.AccessLogEntity;
import com.mortals.xhx.module.biz.model.BizLogEntity;
import com.mortals.xhx.module.biz.service.BizLogService;
import com.mortals.xhx.module.error.model.ErrorLogEntity;
import com.mortals.xhx.module.error.service.ErrorLogService;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.Headers;
import org.springframework.stereotype.Component;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* rabbitmq 异常日志消息消费类
*
* @author: zxfei
* @date: 2022/8/17 20:45
* @description:
**/
@Slf4j
@Component
@RabbitListener(queues = QueueKey.ERROR_LOG_QUEUE,
containerFactory = "consumerBatchContainerFactory")
public class ErrorMessageConsumerListener {
@Autowired
private ErrorLogService errorLogService;
@RabbitHandler
public void onMessage(List<String> messages) throws Exception {
log.info("[onMessage][线程编号:{} 消息数量:{}]", Thread.currentThread().getId(), messages.size());
List<ErrorLogEntity> collect = messages.stream().map(str -> {
ErrorLogEntity entity = JSON.parseObject(str, ErrorLogEntity.class);
entity.setCreateUserId(1L);
entity.setCreateTime(new Date());
return entity;
}).collect(Collectors.toList());
errorLogService.save(collect);
}
}
package com.mortals.xhx.base.framework.listener;
import cn.hutool.core.util.IdUtil;
import com.alibaba.fastjson.JSON;
import com.mortals.xhx.common.key.QueueKey;
import com.mortals.xhx.module.error.model.ErrorLogEntity;
import com.mortals.xhx.module.error.service.ErrorLogService;
import com.mortals.xhx.module.operate.model.OperateLogEntity;
import com.mortals.xhx.module.operate.service.OperateLogService;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.Headers;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* rabbitmq 操作日志消息消费类
*
* @author: zxfei
* @date: 2022/8/17 20:45
* @description:
**/
@Slf4j
@Component
@RabbitListener(queues = QueueKey.OPERATION_LOG_QUEUE,
containerFactory = "consumerBatchContainerFactory")
public class OperateMessageConsumerListener {
@Autowired
private OperateLogService operateLogService;
@RabbitHandler
public void onMessage(@Payload List<String> messages, Channel channel) throws Exception {
log.info("[OperateLog onMessage][线程编号:{} 消息数量:{}]", Thread.currentThread().getId(), messages.size());
List<OperateLogEntity> collect = messages.stream().map(str -> {
OperateLogEntity entity = JSON.parseObject(str, OperateLogEntity.class);
entity.setId(IdUtil.getSnowflake(0, 1).nextId());
entity.setCreateUserId(1L);
entity.setCreateTime(new Date());
return entity;
}).collect(Collectors.toList());
operateLogService.save(collect);
}
}
package com.mortals.xhx.common.key;
/**
* rabbit 队列key定义
*/
public class QueueKey {
public static final String ACCESS_LOG_QUEUE = "ACCESS_LOG_QUEUE";
public static final String BIZ_LOG_QUEUE = "BIZ_LOG_QUEUE";
public static final String ERROR_LOG_QUEUE = "ERROR_LOG_QUEUE";
public static final String OPERATION_LOG_QUEUE = "OPERATION_LOG_QUEUE";
public static final String EXCHANGE = "LOG";
public static final String ROUTING_KEY = "LOG_ROUTING_KEY";
}
......@@ -7,7 +7,7 @@ import java.util.List;
* 访问日志视图对象
*
* @author zxfei
* @date 2022-08-17
* @date 2022-08-19
*/
public class AccessLogVo extends BaseEntityLong {
......
package com.mortals.xhx.module.access.service.impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
import org.springframework.stereotype.Service;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.framework.exception.AppException;
......@@ -6,6 +9,9 @@ import com.mortals.framework.model.Context;
import com.mortals.xhx.module.access.dao.AccessLogDao;
import com.mortals.xhx.module.access.model.AccessLogEntity;
import com.mortals.xhx.module.access.service.AccessLogService;
import java.util.Date;
/**
* AccessLogService
* 访问日志 service实现
......@@ -15,5 +21,26 @@ import com.mortals.xhx.module.access.service.AccessLogService;
*/
@Service("accessLogService")
public class AccessLogServiceImpl extends AbstractCRUDServiceImpl<AccessLogDao, AccessLogEntity, Long> implements AccessLogService {
@Override
public AccessLogEntity get(Long key, Context context) throws AppException {
AccessLogEntity accessLogEntity = new AccessLogEntity();
Snowflake snowflake = IdUtil.getSnowflake(0, 1);
long generateDateTime = snowflake.getGenerateDateTime(key);
accessLogEntity.setCreateTime(new Date(generateDateTime));
return this.getDao().get(key,accessLogEntity);
//return super.get(key, context);
}
public static void main(String[] args) {
Snowflake snowflake = IdUtil.getSnowflake(0, 1);
long id = snowflake.nextId();
System.out.println(id);
long generateDateTime = snowflake.getGenerateDateTime(id);
System.out.println(DateUtil.date(generateDateTime).toString());
}
}
\ No newline at end of file
package com.mortals.xhx.module.access.web;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.OrderCol;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.xhx.base.system.param.service.ParamService;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -13,12 +15,10 @@ import com.mortals.xhx.module.access.model.AccessLogEntity;
import com.mortals.xhx.module.access.service.AccessLogService;
import org.apache.commons.lang3.ArrayUtils;
import com.mortals.framework.util.StringUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
import com.alibaba.fastjson.JSONObject;
import java.util.Arrays;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import static com.mortals.framework.ap.SysConstains.*;
......@@ -46,4 +46,19 @@ public class AccessLogController extends BaseCRUDJsonBodyMappingController<Acces
}
@Override
protected void doListBefore(AccessLogEntity query, Map<String, Object> model, Context context) throws AppException {
List<OrderCol> orderColList = new ArrayList<>();
orderColList.add(new OrderCol("createTime", OrderCol.DESCENDING));
query.setOrderColList(orderColList);
super.doListBefore(query, model, context);
}
@Override
public String view(Long id) {
return super.view(id);
}
}
\ No newline at end of file
package com.mortals.xhx.module.biz.service.impl;
import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
import com.mortals.xhx.module.access.model.AccessLogEntity;
import org.springframework.stereotype.Service;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.framework.exception.AppException;
......@@ -6,6 +9,9 @@ import com.mortals.framework.model.Context;
import com.mortals.xhx.module.biz.dao.BizLogDao;
import com.mortals.xhx.module.biz.model.BizLogEntity;
import com.mortals.xhx.module.biz.service.BizLogService;
import java.util.Date;
/**
* BizLogService
* 业务日志 service实现
......@@ -15,5 +21,13 @@ import com.mortals.xhx.module.biz.service.BizLogService;
*/
@Service("bizLogService")
public class BizLogServiceImpl extends AbstractCRUDServiceImpl<BizLogDao, BizLogEntity, Long> implements BizLogService {
@Override
public BizLogEntity get(Long key, Context context) throws AppException {
BizLogEntity bizLogEntity = new BizLogEntity();
Snowflake snowflake = IdUtil.getSnowflake(0, 1);
long generateDateTime = snowflake.getGenerateDateTime(key);
bizLogEntity.setCreateTime(new Date(generateDateTime));
return this.getDao().get(key,bizLogEntity);
}
}
\ No newline at end of file
package com.mortals.xhx.module.biz.web;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.OrderCol;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.xhx.base.system.param.service.ParamService;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -13,12 +15,10 @@ import com.mortals.xhx.module.biz.model.BizLogEntity;
import com.mortals.xhx.module.biz.service.BizLogService;
import org.apache.commons.lang3.ArrayUtils;
import com.mortals.framework.util.StringUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
import com.alibaba.fastjson.JSONObject;
import java.util.Arrays;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import static com.mortals.framework.ap.SysConstains.*;
......@@ -46,4 +46,12 @@ public class BizLogController extends BaseCRUDJsonBodyMappingController<BizLogSe
}
@Override
protected void doListBefore(BizLogEntity query, Map<String, Object> model, Context context) throws AppException {
List<OrderCol> orderColList = new ArrayList<>();
orderColList.add(new OrderCol("createTime", OrderCol.DESCENDING));
query.setOrderColList(orderColList);
super.doListBefore(query, model, context);
}
}
\ No newline at end of file
......@@ -48,4 +48,6 @@ public class ErrorLogDaoImpl extends SubmeterDaoImpl<ErrorLogEntity,Long> implem
}
package com.mortals.xhx.module.error.service.impl;
import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
import com.mortals.xhx.module.biz.model.BizLogEntity;
import org.springframework.stereotype.Service;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.framework.exception.AppException;
......@@ -6,6 +9,9 @@ import com.mortals.framework.model.Context;
import com.mortals.xhx.module.error.dao.ErrorLogDao;
import com.mortals.xhx.module.error.model.ErrorLogEntity;
import com.mortals.xhx.module.error.service.ErrorLogService;
import java.util.Date;
/**
* ErrorLogService
* 异常日志 service实现
......@@ -15,5 +21,13 @@ import com.mortals.xhx.module.error.service.ErrorLogService;
*/
@Service("errorLogService")
public class ErrorLogServiceImpl extends AbstractCRUDServiceImpl<ErrorLogDao, ErrorLogEntity, Long> implements ErrorLogService {
@Override
public ErrorLogEntity get(Long key, Context context) throws AppException {
ErrorLogEntity errorLogEntity = new ErrorLogEntity();
Snowflake snowflake = IdUtil.getSnowflake(0, 1);
long generateDateTime = snowflake.getGenerateDateTime(key);
errorLogEntity.setCreateTime(new Date(generateDateTime));
return this.getDao().get(key,errorLogEntity);
}
}
\ No newline at end of file
package com.mortals.xhx.module.error.web;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.OrderCol;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.xhx.base.system.param.service.ParamService;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -13,12 +15,10 @@ import com.mortals.xhx.module.error.model.ErrorLogEntity;
import com.mortals.xhx.module.error.service.ErrorLogService;
import org.apache.commons.lang3.ArrayUtils;
import com.mortals.framework.util.StringUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
import com.alibaba.fastjson.JSONObject;
import java.util.Arrays;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import static com.mortals.framework.ap.SysConstains.*;
......@@ -46,4 +46,12 @@ public class ErrorLogController extends BaseCRUDJsonBodyMappingController<ErrorL
}
@Override
protected void doListBefore(ErrorLogEntity query, Map<String, Object> model, Context context) throws AppException {
List<OrderCol> orderColList = new ArrayList<>();
orderColList.add(new OrderCol("createTime", OrderCol.DESCENDING));
query.setOrderColList(orderColList);
super.doListBefore(query, model, context);
}
}
\ No newline at end of file
package com.mortals.xhx.module.operate.service.impl;
import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
import com.mortals.xhx.module.error.model.ErrorLogEntity;
import org.springframework.stereotype.Service;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.framework.exception.AppException;
......@@ -6,6 +9,9 @@ import com.mortals.framework.model.Context;
import com.mortals.xhx.module.operate.dao.OperateLogDao;
import com.mortals.xhx.module.operate.model.OperateLogEntity;
import com.mortals.xhx.module.operate.service.OperateLogService;
import java.util.Date;
/**
* OperateLogService
* 平台用户操作日志业务 service实现
......@@ -15,5 +21,13 @@ import com.mortals.xhx.module.operate.service.OperateLogService;
*/
@Service("operateLogService")
public class OperateLogServiceImpl extends AbstractCRUDServiceImpl<OperateLogDao, OperateLogEntity, Long> implements OperateLogService {
@Override
public OperateLogEntity get(Long key, Context context) throws AppException {
OperateLogEntity operateLogEntity = new OperateLogEntity();
Snowflake snowflake = IdUtil.getSnowflake(0, 1);
long generateDateTime = snowflake.getGenerateDateTime(key);
operateLogEntity.setCreateTime(new Date(generateDateTime));
return this.getDao().get(key,operateLogEntity);
}
}
\ No newline at end of file
package com.mortals.xhx.module.operate.web;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.OrderCol;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.xhx.base.system.param.service.ParamService;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -13,12 +15,10 @@ import com.mortals.xhx.module.operate.model.OperateLogEntity;
import com.mortals.xhx.module.operate.service.OperateLogService;
import org.apache.commons.lang3.ArrayUtils;
import com.mortals.framework.util.StringUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
import com.alibaba.fastjson.JSONObject;
import java.util.Arrays;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import static com.mortals.framework.ap.SysConstains.*;
......@@ -46,5 +46,11 @@ public class OperateLogController extends BaseCRUDJsonBodyMappingController<Oper
super.init(model, context);
}
@Override
protected void doListBefore(OperateLogEntity query, Map<String, Object> model, Context context) throws AppException {
List<OrderCol> orderColList = new ArrayList<>();
orderColList.add(new OrderCol("createTime", OrderCol.DESCENDING));
query.setOrderColList(orderColList);
super.doListBefore(query, model, context);
}
}
\ No newline at end of file
server:
port: @profiles.server.port@
servlet:
context-path: /m
context-path: /logservice
spring:
application:
name: device-manager
name: log-manager
profiles:
active: @profiles.active@
servlet:
......@@ -17,11 +17,6 @@ spring:
default-property-inclusion: NON_NULL
# time-zone: GMT+8
# date-format: yyyy-MM-dd HH:mm:ss
security:
enable: true
user:
name: admin
password: 1
redis:
host: @profiles.redis.uri@
port: @profiles.redis.port@
......@@ -54,6 +49,7 @@ spring:
port: @profiles.rabbitmq.port@
username: @profiles.rabbitmq.username@
password: @profiles.rabbitmq.password@
virtualHost: @profiles.rabbitmq.virtualhost@
dao:
exceptiontranslation:
enabled: false
......
package producer;
import cn.hutool.core.util.IdUtil;
import com.mortals.xhx.ManagerApplication;
import com.mortals.xhx.base.system.message.MessageProducer;
import com.mortals.xhx.module.biz.model.BizLogEntity;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.Date;
import java.util.concurrent.CountDownLatch;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = ManagerApplication.class)
@Slf4j
public class ProducerTest {
@Autowired
private MessageProducer producer;
@Test
public void testSyncSend() {
//for (int i)
while (true){
BizLogEntity bizLogEntity = new BizLogEntity();
bizLogEntity.initAttrValue();
bizLogEntity.setTraceID(IdUtil.fastSimpleUUID());
bizLogEntity.setLogTime(new Date());
producer.syncBizSend(bizLogEntity);
log.info("[testSyncSend][发送编号:[{}] 发送成功]", bizLogEntity.getTraceID());
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment