commit
026a79d2bd
@ -1,3 +1,3 @@
|
|||||||
FROM harbor.axzo.cn/images_base/jdk1.8-fc:v1
|
FROM harbor.axzo.cn/images_base/jdk1.8-fc:v1
|
||||||
COPY xlog-server/target/xlog-server.jar ./xlog.jar
|
COPY axzo-log-server/target/axzo-log-server.jar ./axzo-log-server.jar
|
||||||
ENTRYPOINT [{ENTRYPOINT}]
|
ENTRYPOINT [{ENTRYPOINT}]
|
||||||
|
|||||||
@ -1,19 +1,16 @@
|
|||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
<artifactId>xlog</artifactId>
|
<artifactId>axzo-log-plat</artifactId>
|
||||||
<groupId>cn.axzo.xlog</groupId>
|
<groupId>cn.axzo.platform</groupId>
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<artifactId>xlog-client</artifactId>
|
<artifactId>axzo-log-api</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>xlog-client</name>
|
<name>axzo-log-api</name>
|
||||||
<url>http://maven.apache.org</url>
|
<url>http://maven.apache.org</url>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
@ -21,7 +18,6 @@
|
|||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.cloud</groupId>
|
<groupId>org.springframework.cloud</groupId>
|
||||||
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||||
@ -1,9 +1,9 @@
|
|||||||
package cn.axzo.xlog.client;
|
package cn.axzo.log.platform.client;
|
||||||
|
|
||||||
import cn.axzo.xlog.client.feign.XLogApi;
|
import cn.axzo.log.platform.client.feign.LogPlatApi;
|
||||||
import cn.axzo.xlog.client.model.OperateLogQueryReq;
|
import cn.axzo.log.platform.client.model.OperateLogQueryReq;
|
||||||
import cn.axzo.xlog.client.model.OperateLogQueryResp;
|
import cn.axzo.log.platform.client.model.OperateLogQueryResp;
|
||||||
import cn.axzo.xlog.client.model.OperateLogReq;
|
import cn.axzo.log.platform.client.model.OperateLogReq;
|
||||||
import cn.azxo.framework.common.model.CommonPageResponse;
|
import cn.azxo.framework.common.model.CommonPageResponse;
|
||||||
import cn.azxo.framework.common.model.CommonResponse;
|
import cn.azxo.framework.common.model.CommonResponse;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
@ -16,12 +16,12 @@ import javax.validation.Valid;
|
|||||||
* @Description:
|
* @Description:
|
||||||
*/
|
*/
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class XLogClient {
|
public class LogPlatClient {
|
||||||
|
|
||||||
private final XLogApi xLogApi;
|
private final LogPlatApi logPlatApi;
|
||||||
|
|
||||||
public Boolean createOperateLog(@Valid OperateLogReq req) {
|
public Boolean createOperateLog(@Valid OperateLogReq req) {
|
||||||
CommonResponse<Boolean> apiResult = xLogApi.operateLogCreate(req);
|
CommonResponse<Boolean> apiResult = logPlatApi.operateLogCreate(req);
|
||||||
if (apiResult.getCode() == 200) {
|
if (apiResult.getCode() == 200) {
|
||||||
return apiResult.getData();
|
return apiResult.getData();
|
||||||
}
|
}
|
||||||
@ -29,7 +29,7 @@ public class XLogClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public CommonPageResponse<OperateLogQueryResp> queryForPage(@Valid OperateLogQueryReq req) {
|
public CommonPageResponse<OperateLogQueryResp> queryForPage(@Valid OperateLogQueryReq req) {
|
||||||
CommonResponse<CommonPageResponse<OperateLogQueryResp>> apiResult = xLogApi.queryForPage(req);
|
CommonResponse<CommonPageResponse<OperateLogQueryResp>> apiResult = logPlatApi.queryForPage(req);
|
||||||
if (apiResult.getCode() == 200) {
|
if (apiResult.getCode() == 200) {
|
||||||
return apiResult.getData();
|
return apiResult.getData();
|
||||||
}
|
}
|
||||||
@ -0,0 +1,21 @@
|
|||||||
|
package cn.axzo.log.platform.client.config;
|
||||||
|
|
||||||
|
|
||||||
|
import cn.axzo.log.platform.client.LogPlatClient;
|
||||||
|
import cn.axzo.log.platform.client.feign.LogPlatApi;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: liyong.tian
|
||||||
|
* @Date: 2022/9/17
|
||||||
|
* @Description:
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class LogPlatAutoConfiguration {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public LogPlatClient logPlatApi(LogPlatApi logPlatApi) {
|
||||||
|
return new LogPlatClient(logPlatApi);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,8 +1,8 @@
|
|||||||
package cn.axzo.xlog.client.feign;
|
package cn.axzo.log.platform.client.feign;
|
||||||
|
|
||||||
import cn.axzo.xlog.client.model.OperateLogQueryReq;
|
import cn.axzo.log.platform.client.model.OperateLogQueryReq;
|
||||||
import cn.axzo.xlog.client.model.OperateLogQueryResp;
|
import cn.axzo.log.platform.client.model.OperateLogQueryResp;
|
||||||
import cn.axzo.xlog.client.model.OperateLogReq;
|
import cn.axzo.log.platform.client.model.OperateLogReq;
|
||||||
import cn.azxo.framework.common.model.CommonPageResponse;
|
import cn.azxo.framework.common.model.CommonPageResponse;
|
||||||
import cn.azxo.framework.common.model.CommonResponse;
|
import cn.azxo.framework.common.model.CommonResponse;
|
||||||
import org.springframework.cloud.openfeign.FeignClient;
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
@ -18,12 +18,12 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
|
|||||||
* @description: TODO
|
* @description: TODO
|
||||||
* @date: 2022/9/16
|
* @date: 2022/9/16
|
||||||
*/
|
*/
|
||||||
@FeignClient(name = "xlog", url = "http://xlog:10999", fallbackFactory = XLogApiFallback.class)
|
@FeignClient(name = "log-plat", url = "http://log-plat:8080", fallbackFactory = LogPlatApiFallback.class)
|
||||||
public interface XLogApi {
|
public interface LogPlatApi {
|
||||||
|
|
||||||
@PostMapping(value = "/api/operateLog/create", consumes = APPLICATION_JSON_VALUE)
|
@PostMapping(value = "/api/v1/operateLog/create", consumes = APPLICATION_JSON_VALUE)
|
||||||
CommonResponse<Boolean> operateLogCreate(@RequestBody OperateLogReq req);
|
CommonResponse<Boolean> operateLogCreate(@RequestBody OperateLogReq req);
|
||||||
|
|
||||||
@PostMapping(value = "api/unified/operateLog/queryForPage", consumes = APPLICATION_JSON_VALUE)
|
@PostMapping(value = "/api/v1/operateLog/queryForPage", consumes = APPLICATION_JSON_VALUE)
|
||||||
CommonResponse<CommonPageResponse<OperateLogQueryResp>> queryForPage(@RequestBody @Valid OperateLogQueryReq req);
|
CommonResponse<CommonPageResponse<OperateLogQueryResp>> queryForPage(@RequestBody @Valid OperateLogQueryReq req);
|
||||||
}
|
}
|
||||||
@ -1,8 +1,8 @@
|
|||||||
package cn.axzo.xlog.client.feign;
|
package cn.axzo.log.platform.client.feign;
|
||||||
|
|
||||||
import cn.axzo.xlog.client.model.OperateLogQueryReq;
|
import cn.axzo.log.platform.client.model.OperateLogQueryReq;
|
||||||
import cn.axzo.xlog.client.model.OperateLogQueryResp;
|
import cn.axzo.log.platform.client.model.OperateLogQueryResp;
|
||||||
import cn.axzo.xlog.client.model.OperateLogReq;
|
import cn.axzo.log.platform.client.model.OperateLogReq;
|
||||||
import cn.azxo.framework.common.model.CommonPageResponse;
|
import cn.azxo.framework.common.model.CommonPageResponse;
|
||||||
import cn.azxo.framework.common.model.CommonResponse;
|
import cn.azxo.framework.common.model.CommonResponse;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
@ -16,7 +16,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class XLogApiFallback implements XLogApi{
|
public class LogPlatApiFallback implements LogPlatApi {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommonResponse<Boolean> operateLogCreate(OperateLogReq req) {
|
public CommonResponse<Boolean> operateLogCreate(OperateLogReq req) {
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package cn.axzo.xlog.client.model;
|
package cn.axzo.log.platform.client.model;
|
||||||
|
|
||||||
import cn.axzo.core.domain.PageRequest;
|
import cn.axzo.core.domain.PageRequest;
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package cn.axzo.xlog.client.model;
|
package cn.axzo.log.platform.client.model;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package cn.axzo.xlog.client.model;
|
package cn.axzo.log.platform.client.model;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
@ -24,6 +24,7 @@ public class OperateLogReq {
|
|||||||
/**
|
/**
|
||||||
* 调用方服务名
|
* 调用方服务名
|
||||||
*/
|
*/
|
||||||
|
@NotNull
|
||||||
private String serviceName;
|
private String serviceName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -123,4 +124,14 @@ public class OperateLogReq {
|
|||||||
* 操作表名
|
* 操作表名
|
||||||
*/
|
*/
|
||||||
private String operateTable;
|
private String operateTable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当前操作人姓名
|
||||||
|
*/
|
||||||
|
private String operateUserName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当前操作人手机号码
|
||||||
|
*/
|
||||||
|
private String operateUserPhone;
|
||||||
}
|
}
|
||||||
@ -1,2 +1,2 @@
|
|||||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||||
cn.axzo.xlog.client.config.XLogClientAutoConfiguration
|
cn.axzo.log.platform.client.config.LogPlatAutoConfiguration
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
package cn.axzo.log.platform.client;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unit test for simple App.
|
||||||
|
*/
|
||||||
|
public class AppTest {
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,22 +1,22 @@
|
|||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<parent>
|
<parent>
|
||||||
<artifactId>xlog</artifactId>
|
<artifactId>axzo-log-plat</artifactId>
|
||||||
<groupId>cn.axzo.xlog</groupId>
|
<groupId>cn.axzo.platform</groupId>
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<artifactId>xlog-server</artifactId>
|
<artifactId>axzo-log-server</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>xlog-server</name>
|
<name>axzo-log-server</name>
|
||||||
<url>http://maven.apache.org</url>
|
<url>http://maven.apache.org</url>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<maven.install.skip>true</maven.install.skip>
|
||||||
|
<maven.deploy.skip>true</maven.deploy.skip>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@ -128,6 +128,14 @@
|
|||||||
<artifactId>basics-profiles-api</artifactId>
|
<artifactId>basics-profiles-api</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 测试 client 使用
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.axzo.platform</groupId>
|
||||||
|
<artifactId>axzo-log-api</artifactId>
|
||||||
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
-->
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
30
axzo-log-server/scripts/createtable_20221014.sql
Normal file
30
axzo-log-server/scripts/createtable_20221014.sql
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
create table log_record (
|
||||||
|
id bigint auto_increment not null comment '主键' primary key,
|
||||||
|
service_name varchar(64) default '' not null comment '调用方服务名',
|
||||||
|
feature_name varchar(128) default '' not null comment '功能名称',
|
||||||
|
feature_code varchar(128) default '' not null comment '功能名称Code',
|
||||||
|
log_grade tinyint default 4 not null comment '日志等级 0:P0 1:P1 2:P2 3:P3 4:P4',
|
||||||
|
operate_time datetime default CURRENT_TIMESTAMP not null comment '操作时间',
|
||||||
|
terminal varchar(64) default '' not null comment '所属终端',
|
||||||
|
identity_id bigint default 0 not null comment '操作人Id',
|
||||||
|
identity_user_name varchar(64) default '' not null comment '操作人名字',
|
||||||
|
identity_user_phone varchar(64) default '' not null comment '操作人手机号',
|
||||||
|
identity_type bigint default 0 not null comment '操作人类型-与档案域一致 1:工人 2:班组长 3:从业人员 4:监管人员 5:运营人员',
|
||||||
|
workspace_id bigint default 0 not null comment '工作台Id',
|
||||||
|
ou_id bigint default 0 not null comment '单位Id',
|
||||||
|
workspace_name varchar(255) default '0' not null comment '工作台名字',
|
||||||
|
ou_name varchar(255) default '0' not null comment '单位名字',
|
||||||
|
resource_id bigint default 0 not null comment '资源Id 预防更小范围数据权限预留字段',
|
||||||
|
resource_type int default 0 not null comment '资源类型 预防更小范围数据权限预留字段',
|
||||||
|
operate_user_ip varchar(32) default '' not null comment '操作人Ip',
|
||||||
|
operate_before text null comment '操作前内容',
|
||||||
|
is_delete bigint default 0 not null,
|
||||||
|
create_at datetime default CURRENT_TIMESTAMP not null,
|
||||||
|
update_at datetime null,
|
||||||
|
content_summary varchar(255) default '' not null comment '内容摘要',
|
||||||
|
log_ext varchar(255) default '' not null comment '日志拓展内容',
|
||||||
|
operate_table varchar(64) default '' not null comment '操作表名',
|
||||||
|
operate_after text null comment '操作后内容',
|
||||||
|
operate_type tinyint not null comment '操作类型 1:add 2:add_batch 3:update 4:update_batch 5:delete 6:delete_batch',
|
||||||
|
operate_param text null comment '操作参数'
|
||||||
|
) comment '操作日志记录表';
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package cn.axzo.xlog.server;
|
package cn.axzo.log.platform.server;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -22,26 +22,21 @@ import org.springframework.core.env.Environment;
|
|||||||
"cn.axzo.basics"
|
"cn.axzo.basics"
|
||||||
})
|
})
|
||||||
@EnableDiscoveryClient
|
@EnableDiscoveryClient
|
||||||
@SpringBootApplication(scanBasePackages = "cn.axzo.xlog.server")
|
@SpringBootApplication(scanBasePackages = "cn.axzo.log.platform.server")
|
||||||
public class XlogApplication {
|
public class LogPlatApplication {
|
||||||
private static final Logger logger = LoggerFactory.getLogger(XlogApplication.class);
|
private static final Logger logger = LoggerFactory.getLogger(LogPlatApplication.class);
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
ConfigurableApplicationContext context = SpringApplication.run(XlogApplication.class, args);
|
ConfigurableApplicationContext context = SpringApplication.run(LogPlatApplication.class, args);
|
||||||
Environment env = context.getEnvironment();
|
Environment env = context.getEnvironment();
|
||||||
logger.info("Application 【{}】 is running on 【{}】 environment!\n\t" +
|
logger.info("Application 【{}】 is running on 【{}】 environment!\n\t" +
|
||||||
"MySQL: \t{}\t username:{}\t\n\t" +
|
"MySQL: \t{}\t username:{}\t\n\t" +
|
||||||
"Redis: \t{}:{}\t database:{}\t\n\t" +
|
|
||||||
"RabbitMQ: \t{}\t username:{},\t\n",
|
"RabbitMQ: \t{}\t username:{},\t\n",
|
||||||
env.getProperty("spring.application.name"),
|
env.getProperty("spring.application.name"),
|
||||||
env.getProperty("spring.profiles.active"),
|
env.getProperty("spring.profiles.active"),
|
||||||
env.getProperty("spring.datasource.url"),
|
env.getProperty("spring.datasource.url"),
|
||||||
env.getProperty("spring.datasource.username"),
|
env.getProperty("spring.datasource.username"),
|
||||||
env.getProperty("spring.redis.host"),
|
|
||||||
env.getProperty("spring.redis.port"),
|
|
||||||
env.getProperty("spring.redis.database"),
|
|
||||||
env.getProperty("spring.rabbitmq.addresses"),
|
env.getProperty("spring.rabbitmq.addresses"),
|
||||||
env.getProperty("spring.rabbitmq.username"));
|
env.getProperty("spring.rabbitmq.username"));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package cn.axzo.xlog.server.config;
|
package cn.axzo.log.platform.server.config;
|
||||||
|
|
||||||
import org.apache.http.HttpHost;
|
import org.apache.http.HttpHost;
|
||||||
import org.apache.http.auth.AuthScope;
|
import org.apache.http.auth.AuthScope;
|
||||||
@ -25,16 +25,16 @@ public class EsClientConfig {
|
|||||||
|
|
||||||
private final Logger logger = LoggerFactory.getLogger(EsClientConfig.class);
|
private final Logger logger = LoggerFactory.getLogger(EsClientConfig.class);
|
||||||
|
|
||||||
@Value("${xlog.elasticsearch.host:121.196.20.126}")
|
@Value("${log-plat.elasticsearch.host:121.196.20.126}")
|
||||||
private String host;
|
private String host;
|
||||||
|
|
||||||
@Value("${xlog.elasticsearch.port:31647}")
|
@Value("${log-plat.elasticsearch.port:31647}")
|
||||||
private int port;
|
private int port;
|
||||||
|
|
||||||
@Value("${xlog.elasticsearch.username:elastic}")
|
@Value("${log-plat.elasticsearch.username:elastic}")
|
||||||
private String userName;
|
private String userName;
|
||||||
|
|
||||||
@Value("${xlog.elasticsearch.pwd:Axz0ES2021}")
|
@Value("${log-plat.elasticsearch.pwd:Axz0ES2021}")
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package cn.axzo.xlog.server.config;
|
package cn.axzo.log.platform.server.config;
|
||||||
|
|
||||||
import cn.axzo.pudge.core.service.ServiceException;
|
import cn.axzo.pudge.core.service.ServiceException;
|
||||||
import cn.azxo.framework.common.constatns.Constants;
|
import cn.azxo.framework.common.constatns.Constants;
|
||||||
@ -30,7 +30,7 @@ import java.util.regex.Pattern;
|
|||||||
* @author xiajiafu
|
* @author xiajiafu
|
||||||
* @date 2022/08/08
|
* @date 2022/08/08
|
||||||
**/
|
**/
|
||||||
@Configuration(value = "xlogFeignConfig")
|
@Configuration(value = "logPlatFeignConfig")
|
||||||
public class FeignConfig implements RequestInterceptor {
|
public class FeignConfig implements RequestInterceptor {
|
||||||
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(FeignConfig.class);
|
private static final Logger log = LoggerFactory.getLogger(FeignConfig.class);
|
||||||
@ -1,6 +1,6 @@
|
|||||||
package cn.axzo.xlog.server.config;
|
package cn.axzo.log.platform.server.config;
|
||||||
|
|
||||||
import cn.axzo.xlog.server.entity.BaseEntity;
|
import cn.axzo.log.platform.server.entity.BaseEntity;
|
||||||
import com.baomidou.mybatisplus.annotation.DbType;
|
import com.baomidou.mybatisplus.annotation.DbType;
|
||||||
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
|
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package cn.axzo.xlog.server.config;
|
package cn.axzo.log.platform.server.config;
|
||||||
|
|
||||||
import org.springframework.beans.BeansException;
|
import org.springframework.beans.BeansException;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
@ -1,13 +1,13 @@
|
|||||||
package cn.axzo.xlog.server.consumer;
|
package cn.axzo.log.platform.server.consumer;
|
||||||
|
|
||||||
import cn.axzo.xlog.server.config.RabbitMqConfig;
|
import cn.axzo.log.platform.server.dto.OperateLogReqDTO;
|
||||||
import cn.axzo.xlog.server.dto.OperateLogReqDTO;
|
import cn.axzo.log.platform.server.service.OperateLogService;
|
||||||
import cn.axzo.xlog.server.service.OperateLogService;
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.rabbitmq.client.Channel;
|
import com.rabbitmq.client.Channel;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.amqp.core.Message;
|
import org.springframework.amqp.core.Message;
|
||||||
|
import org.springframework.amqp.rabbit.annotation.Queue;
|
||||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ public class OperateLogMqConsumer {
|
|||||||
@Resource
|
@Resource
|
||||||
private OperateLogService operateLogService;
|
private OperateLogService operateLogService;
|
||||||
|
|
||||||
@RabbitListener(queues = RabbitMqConfig.OPERATE_LOG_QUEUE_NAME)
|
@RabbitListener(queuesToDeclare = @Queue("${log-plat.oprlog.queue.name:log-plat.oprlog.queue}"))
|
||||||
public void consumerOprlogs(Message message, Channel channel) throws IOException {
|
public void consumerOprlogs(Message message, Channel channel) throws IOException {
|
||||||
String msg = new String(message.getBody(), StandardCharsets.UTF_8);
|
String msg = new String(message.getBody(), StandardCharsets.UTF_8);
|
||||||
try {
|
try {
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package cn.axzo.xlog.server.controller;
|
package cn.axzo.log.platform.server.controller;
|
||||||
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
@ -0,0 +1,110 @@
|
|||||||
|
package cn.axzo.log.platform.server.controller.api;
|
||||||
|
|
||||||
|
import cn.axzo.log.platform.server.dto.*;
|
||||||
|
import cn.axzo.log.platform.server.service.OperateLogService;
|
||||||
|
import cn.azxo.framework.common.model.CommonPageResponse;
|
||||||
|
import cn.azxo.framework.common.model.CommonResponse;
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.validation.BindingResult;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import javax.validation.Valid;
|
||||||
|
|
||||||
|
/***
|
||||||
|
* @author: pepsi
|
||||||
|
* @description: TODO
|
||||||
|
* @date: 2022/9/16
|
||||||
|
*/
|
||||||
|
@Api(tags = "web-操作日志接口")
|
||||||
|
@ApiSupport(author = "田立勇")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/v1")
|
||||||
|
public class OperateLogController {
|
||||||
|
|
||||||
|
private final Logger logger = LoggerFactory.getLogger(OperateLogController.class);
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private OperateLogService operateLogService;
|
||||||
|
|
||||||
|
@RequestMapping(value = "/operateLog/create", method = RequestMethod.POST)
|
||||||
|
@ApiOperation(value = "操作日志创建")
|
||||||
|
public CommonResponse<Boolean> operateLogCreate(@RequestBody @Valid OperateLogReqDTO req,
|
||||||
|
BindingResult bindingResult) {
|
||||||
|
//参数缺失等返回
|
||||||
|
if (bindingResult.hasErrors()) {
|
||||||
|
return CommonResponse.fail(bindingResult.getAllErrors().get(0).getDefaultMessage());
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return CommonResponse.success(operateLogService.insertOperaLog(req));
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("create operate log failed.", e);
|
||||||
|
return CommonResponse.fail(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping(value = "/operateLog/queryForPage", method = RequestMethod.POST)
|
||||||
|
@ApiOperation(value = "操作日志分页查询")
|
||||||
|
public CommonResponse<CommonPageResponse<OperateLogQueryRespDTO>> operateLogsQuery(@RequestBody @Valid OperateLogQueryReqDTO req,
|
||||||
|
BindingResult bindingResult) {
|
||||||
|
//参数缺失等返回
|
||||||
|
if (bindingResult.hasErrors()) {
|
||||||
|
return CommonResponse.fail(bindingResult.getAllErrors().get(0).getDefaultMessage());
|
||||||
|
}
|
||||||
|
//时间跨度校验。
|
||||||
|
if (DateUtil.betweenDay(req.getStartTime(), req.getEndTime(), true) > 7) {
|
||||||
|
logger.error("start and end date interval greater than 7.");
|
||||||
|
return CommonResponse.fail("the time span is greater than 7");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
CommonPageResponse<OperateLogQueryRespDTO> resp = operateLogService.queryBasicInfoForPage(req);
|
||||||
|
return CommonResponse.success(resp);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("query operate logs failed,", e);
|
||||||
|
return CommonResponse.fail(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@RequestMapping(value = "/operateLog/queryDetailForPage", method = RequestMethod.POST)
|
||||||
|
@ApiOperation(value = "操作日志分页查询(详情列表)")
|
||||||
|
public CommonResponse<CommonPageResponse<OperateLogQueryDetailRespDTO>> operateLogsQueryDetail(@RequestBody @Valid OperateLogQueryReqDTO req,
|
||||||
|
BindingResult bindingResult) {
|
||||||
|
//参数缺失等返回
|
||||||
|
if (bindingResult.hasErrors()) {
|
||||||
|
return CommonResponse.fail(bindingResult.getAllErrors().get(0).getDefaultMessage());
|
||||||
|
}
|
||||||
|
//时间跨度校验。
|
||||||
|
if (DateUtil.betweenDay(req.getStartTime(), req.getEndTime(), true) > 7) {
|
||||||
|
logger.error("start and end date interval greater than 7.");
|
||||||
|
return CommonResponse.fail("the time span is greater than 7");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
CommonPageResponse<OperateLogQueryDetailRespDTO> resp = operateLogService.queryForPage(req);
|
||||||
|
return CommonResponse.success(resp);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("query operate logs failed,", e);
|
||||||
|
return CommonResponse.fail(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@RequestMapping(value = "/operateLog/queryDetail", method = RequestMethod.POST)
|
||||||
|
@ApiOperation(value = "单条操作日志详情查询")
|
||||||
|
public CommonResponse<OperateLogQueryDetailRespDTO> operateLogDetail(@RequestBody OperateLogQueryDetailReqDTO reqDTO) {
|
||||||
|
try {
|
||||||
|
OperateLogQueryDetailRespDTO detail = operateLogService.queryOperateLogDetail(reqDTO);
|
||||||
|
return CommonResponse.success(detail);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return CommonResponse.fail(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,34 @@
|
|||||||
|
package cn.axzo.log.platform.server.dto;
|
||||||
|
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author : liuchuntao
|
||||||
|
* @date : 2022/6/28 20:08
|
||||||
|
* @description : 操作日志请求参数
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class OperateLogQueryDetailReqDTO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ID
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "记录ID", position = 1, required = true)
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 操作时间
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "操作时间", position = 2)
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||||
|
@NotNull
|
||||||
|
private Date operateTime;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,110 @@
|
|||||||
|
package cn.axzo.log.platform.server.dto;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/***
|
||||||
|
* @author: pepsi
|
||||||
|
* @description: 操作日志详情返回
|
||||||
|
* @date: 2022/10/8
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class OperateLogQueryDetailRespDTO {
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "记录ID", position = 1)
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 事件类型
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "事件code", position = 2)
|
||||||
|
private String featureCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 事件类型
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "事件名称", position = 3)
|
||||||
|
private String featureName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 事件摘要
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "事件摘要", position = 4)
|
||||||
|
private String contentSummary;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 操作时间
|
||||||
|
*/
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||||
|
@ApiModelProperty(value = "操作时间", position = 5)
|
||||||
|
private Date operateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 所属单位名称
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "单位名称", position = 7)
|
||||||
|
private String ouName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 操作人IP
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "操作人IP", position = 8)
|
||||||
|
private String operateUserIp;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 操作那张表
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "操作的表名称", position = 9)
|
||||||
|
private String operateTable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 操作前内容
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "操作前信息", position = 10)
|
||||||
|
private String operateBefore;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 操作后内容
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "操作后信息", position = 11)
|
||||||
|
private String operateAfter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 操作参数
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "操作的参数信息", position = 12)
|
||||||
|
private String operateParam;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 日志拓展内容
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "扩展信息", position = 13)
|
||||||
|
private String logExt;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 工作台
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "工作台名字", position = 14)
|
||||||
|
private String workspaceName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 操作人名字
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "操作人名称", position = 15)
|
||||||
|
private String identityUserName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 操作人手机号
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "操作人电话", position = 16)
|
||||||
|
private String identityUserPhone;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 所属终端
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "所属终端", position = 17)
|
||||||
|
private String terminal;
|
||||||
|
}
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package cn.axzo.xlog.server.dto;
|
package cn.axzo.log.platform.server.dto;
|
||||||
|
|
||||||
|
|
||||||
import cn.axzo.basics.common.page.PageRequest;
|
import cn.axzo.basics.common.page.PageRequest;
|
||||||
@ -7,6 +7,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
|
|||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -27,72 +28,74 @@ public class OperateLogQueryReqDTO extends PageRequest {
|
|||||||
/**
|
/**
|
||||||
* 操作人
|
* 操作人
|
||||||
*/
|
*/
|
||||||
@ApiModelProperty(value = "操作人", position = 1)
|
@ApiModelProperty(value = "操作人", position = 2)
|
||||||
private String operateUserName;
|
private String operateUserName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 事件类型
|
* 事件类型
|
||||||
*/
|
*/
|
||||||
@ApiModelProperty(value = "事件类型", position = 1)
|
@ApiModelProperty(value = "事件类型", position = 3)
|
||||||
private List<String> featureCodes;
|
private List<String> featureCodes;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 功能name
|
* 功能name
|
||||||
*/
|
*/
|
||||||
@ApiModelProperty(value = "功能名称", position = 1)
|
@ApiModelProperty(value = "功能名称", position = 4)
|
||||||
private String featureName;
|
private String featureName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 开始时间
|
* 开始时间
|
||||||
*/
|
*/
|
||||||
@ApiModelProperty(value = "开始时间", position = 1)
|
@ApiModelProperty(value = "操作开始时间", position = 5, required = true, example = "2022-10-10 12:12:12")
|
||||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||||
|
@NotNull
|
||||||
private Date startTime;
|
private Date startTime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 结束时间
|
* 结束时间
|
||||||
*/
|
*/
|
||||||
@ApiModelProperty(value = "结束时间", position = 1)
|
@ApiModelProperty(value = "操作结束时间", position = 6, required = true, example = "2022-10-10 12:12:12")
|
||||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||||
|
@NotNull
|
||||||
private Date endTime;
|
private Date endTime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 工作台Id
|
* 工作台Id
|
||||||
*/
|
*/
|
||||||
@ApiModelProperty(value = "工作台Id", position = 1)
|
@ApiModelProperty(value = "工作台Id", position = 7)
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
private Long workspaceId;
|
private Long workspaceId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 单位Id
|
* 单位Id
|
||||||
*/
|
*/
|
||||||
@ApiModelProperty(value = "单位Id", position = 1)
|
@ApiModelProperty(value = "单位Id", position = 8)
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
private Long ouId;
|
private Long ouId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 身份Id
|
* 身份Id
|
||||||
*/
|
*/
|
||||||
@ApiModelProperty(value = "身份Id", position = 1)
|
@ApiModelProperty(value = "身份Id", position = 9)
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
private Long identityId;
|
private Long identityId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 身份类型
|
* 身份类型
|
||||||
*/
|
*/
|
||||||
@ApiModelProperty(value = "身份类型", position = 1)
|
@ApiModelProperty(value = "身份类型", position = 10)
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
private Integer identityType;
|
private Integer identityType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 操作类型 1:add 2:add_batch 3:update 4:update_batch 5:delete 6:delete_batch
|
* 操作类型 1:add 2:add_batch 3:update 4:update_batch 5:delete 6:delete_batch
|
||||||
*/
|
*/
|
||||||
@ApiModelProperty(value = "操作类型", position = 1)
|
@ApiModelProperty(value = "操作类型", position = 11)
|
||||||
private Integer operateType;
|
private Integer operateType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 操作表名
|
* 操作表名
|
||||||
*/
|
*/
|
||||||
@ApiModelProperty(value = "操作表名", position = 1)
|
@ApiModelProperty(value = "操作表名", position = 12)
|
||||||
private String operateTable;
|
private String operateTable;
|
||||||
}
|
}
|
||||||
@ -1,6 +1,7 @@
|
|||||||
package cn.axzo.xlog.server.dto;
|
package cn.axzo.log.platform.server.dto;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@ -13,39 +14,52 @@ import java.util.Date;
|
|||||||
@Data
|
@Data
|
||||||
public class OperateLogQueryRespDTO {
|
public class OperateLogQueryRespDTO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 记录ID,为后面单条详情查询提供
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "ID", position = 0)
|
||||||
|
private String id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 操作人
|
* 操作人
|
||||||
*/
|
*/
|
||||||
|
@ApiModelProperty(value = "操作人名称", position = 1)
|
||||||
private String operateUserName;
|
private String operateUserName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 事件类型
|
* 事件类型
|
||||||
*/
|
*/
|
||||||
|
@ApiModelProperty(value = "事件code", position = 2)
|
||||||
private String featureCode;
|
private String featureCode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 事件类型
|
* 事件类型
|
||||||
*/
|
*/
|
||||||
|
@ApiModelProperty(value = "事件名称", position = 3)
|
||||||
private String featureName;
|
private String featureName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 事件摘要
|
* 事件摘要
|
||||||
*/
|
*/
|
||||||
|
@ApiModelProperty(value = "事件摘要", position = 4)
|
||||||
private String contentSummary;
|
private String contentSummary;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 操作时间
|
* 操作时间
|
||||||
*/
|
*/
|
||||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||||
|
@ApiModelProperty(value = "操作时间", position = 5)
|
||||||
private Date operateTime;
|
private Date operateTime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 操作人手机号
|
* 操作人手机号
|
||||||
*/
|
*/
|
||||||
|
@ApiModelProperty(value = "操作人手机号", position = 6)
|
||||||
private String operateUserPhone;
|
private String operateUserPhone;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 所属单位名称
|
* 所属单位名称
|
||||||
*/
|
*/
|
||||||
|
@ApiModelProperty(value = "单位名称", position = 7)
|
||||||
private String ouName;
|
private String ouName;
|
||||||
}
|
}
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package cn.axzo.xlog.server.dto;
|
package cn.axzo.log.platform.server.dto;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
@ -26,6 +26,7 @@ public class OperateLogReqDTO {
|
|||||||
* 调用方服务名
|
* 调用方服务名
|
||||||
*/
|
*/
|
||||||
@ApiModelProperty(value = "调用方服务名", position = 1)
|
@ApiModelProperty(value = "调用方服务名", position = 1)
|
||||||
|
@NotNull
|
||||||
private String serviceName;
|
private String serviceName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -49,8 +50,9 @@ public class OperateLogReqDTO {
|
|||||||
/**
|
/**
|
||||||
* 操作时间
|
* 操作时间
|
||||||
*/
|
*/
|
||||||
@ApiModelProperty(value = "操作时间", required = true, position = 5)
|
@ApiModelProperty(value = "操作时间", required = true, position = 5, example = "2022-10-10 12:12:12")
|
||||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||||
|
@NotNull(message = "操作时间不能为空")
|
||||||
private Date operateTime;
|
private Date operateTime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -143,4 +145,16 @@ public class OperateLogReqDTO {
|
|||||||
*/
|
*/
|
||||||
@ApiModelProperty(value = "操作表名", position = 20)
|
@ApiModelProperty(value = "操作表名", position = 20)
|
||||||
private String operateTable;
|
private String operateTable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当前操作人姓名()
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "操作人姓名", position = 21)
|
||||||
|
private String identityUserName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当前操作人手机号码
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "操作人手机号", position = 22)
|
||||||
|
private String identityUserPhone;
|
||||||
}
|
}
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package cn.axzo.xlog.server.entity;
|
package cn.axzo.log.platform.server.entity;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||||
import com.baomidou.mybatisplus.annotation.IdType;
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package cn.axzo.xlog.server.entity;
|
package cn.axzo.log.platform.server.entity;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
@ -18,7 +18,7 @@ import java.util.Date;
|
|||||||
@Setter
|
@Setter
|
||||||
@ToString
|
@ToString
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@TableName("unified_log_record")
|
@TableName("log_record")
|
||||||
public class OperateLogRecordEntity extends BaseEntity<OperateLogRecordEntity> {
|
public class OperateLogRecordEntity extends BaseEntity<OperateLogRecordEntity> {
|
||||||
/**
|
/**
|
||||||
* 调用方服务名
|
* 调用方服务名
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package cn.axzo.xlog.server.enums;
|
package cn.axzo.log.platform.server.enums;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 项目名称:pudge
|
* 项目名称:pudge
|
||||||
@ -1,6 +1,6 @@
|
|||||||
package cn.axzo.xlog.server.enums;
|
package cn.axzo.log.platform.server.enums;
|
||||||
|
|
||||||
import cn.axzo.xlog.server.exception.ServiceException;
|
import cn.axzo.log.platform.server.exception.ServiceException;
|
||||||
import com.baomidou.mybatisplus.annotation.EnumValue;
|
import com.baomidou.mybatisplus.annotation.EnumValue;
|
||||||
import com.fasterxml.jackson.annotation.JsonValue;
|
import com.fasterxml.jackson.annotation.JsonValue;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package cn.axzo.xlog.server.enums;
|
package cn.axzo.log.platform.server.enums;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package cn.axzo.xlog.server.exception;
|
package cn.axzo.log.platform.server.exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Smile
|
* @author Smile
|
||||||
@ -1,6 +1,6 @@
|
|||||||
package cn.axzo.xlog.server.mapper;
|
package cn.axzo.log.platform.server.mapper;
|
||||||
|
|
||||||
import cn.axzo.xlog.server.entity.OperateLogRecordEntity;
|
import cn.axzo.log.platform.server.entity.OperateLogRecordEntity;
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
@ -0,0 +1,35 @@
|
|||||||
|
package cn.axzo.log.platform.server.repository;
|
||||||
|
|
||||||
|
import cn.axzo.log.platform.server.dto.OperateLogQueryReqDTO;
|
||||||
|
import cn.axzo.log.platform.server.entity.OperateLogRecordEntity;
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
|
||||||
|
/***
|
||||||
|
* @author: pepsi
|
||||||
|
* @description: TODO
|
||||||
|
* @date: 2022/9/15
|
||||||
|
*/
|
||||||
|
public interface OperateLogRepository {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param user
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
OperateLogRecordEntity save(OperateLogRecordEntity user);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询
|
||||||
|
*
|
||||||
|
* @param req
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
IPage<OperateLogRecordEntity> pageLogRecord(OperateLogQueryReqDTO req);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据ID获取
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
OperateLogRecordEntity queryById(Long id);
|
||||||
|
}
|
||||||
@ -1,9 +1,9 @@
|
|||||||
package cn.axzo.xlog.server.repository.impl;
|
package cn.axzo.log.platform.server.repository.impl;
|
||||||
|
|
||||||
import cn.axzo.xlog.server.dto.OperateLogQueryReqDTO;
|
import cn.axzo.log.platform.server.dto.OperateLogQueryReqDTO;
|
||||||
import cn.axzo.xlog.server.entity.OperateLogRecordEntity;
|
import cn.axzo.log.platform.server.entity.OperateLogRecordEntity;
|
||||||
import cn.axzo.xlog.server.mapper.OperateLogMapper;
|
import cn.axzo.log.platform.server.mapper.OperateLogMapper;
|
||||||
import cn.axzo.xlog.server.repository.OperateLogRepository;
|
import cn.axzo.log.platform.server.repository.OperateLogRepository;
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
@ -45,4 +45,9 @@ public class OperateLogRepositoryImpl implements OperateLogRepository {
|
|||||||
.orderByDesc(OperateLogRecordEntity::getCreateAt)
|
.orderByDesc(OperateLogRecordEntity::getCreateAt)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OperateLogRecordEntity queryById(Long id) {
|
||||||
|
return mapper.selectById(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -1,8 +1,13 @@
|
|||||||
package cn.axzo.xlog.server.service;
|
package cn.axzo.log.platform.server.service;
|
||||||
|
|
||||||
import cn.axzo.xlog.server.config.SpringContextAware;
|
import cn.axzo.log.platform.server.config.SpringContextAware;
|
||||||
|
import com.google.common.cache.CacheBuilder;
|
||||||
|
import com.google.common.cache.CacheLoader;
|
||||||
|
import com.google.common.cache.LoadingCache;
|
||||||
import org.elasticsearch.action.bulk.BulkRequest;
|
import org.elasticsearch.action.bulk.BulkRequest;
|
||||||
import org.elasticsearch.action.bulk.BulkResponse;
|
import org.elasticsearch.action.bulk.BulkResponse;
|
||||||
|
import org.elasticsearch.action.get.GetRequest;
|
||||||
|
import org.elasticsearch.action.get.GetResponse;
|
||||||
import org.elasticsearch.action.index.IndexRequest;
|
import org.elasticsearch.action.index.IndexRequest;
|
||||||
import org.elasticsearch.action.index.IndexResponse;
|
import org.elasticsearch.action.index.IndexResponse;
|
||||||
import org.elasticsearch.action.search.SearchRequest;
|
import org.elasticsearch.action.search.SearchRequest;
|
||||||
@ -16,7 +21,10 @@ import org.elasticsearch.rest.RestStatus;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/***
|
/***
|
||||||
* @author: pepsi
|
* @author: pepsi
|
||||||
@ -27,13 +35,55 @@ public class BaseEsService {
|
|||||||
|
|
||||||
private final Logger logger = LoggerFactory.getLogger(BaseEsService.class);
|
private final Logger logger = LoggerFactory.getLogger(BaseEsService.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 索引缓存, 索引数量不大、新增频率不高等。可以做成内存缓存。
|
||||||
|
*/
|
||||||
|
private LoadingCache<String, List<String>> INDICES_CACHE = CacheBuilder.newBuilder()
|
||||||
|
.expireAfterWrite(10, TimeUnit.MINUTES)
|
||||||
|
.build(new CacheLoader<String, List<String>>() {
|
||||||
|
@Override
|
||||||
|
public List<String> load(String key) throws Exception {
|
||||||
|
return loadIndices(key);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
public List<String> getIndices(String indexName) {
|
||||||
|
try {
|
||||||
|
return INDICES_CACHE.get(indexName);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("get indices from cache exception,indexName=" + indexName, e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
* 根据索引前置获取到索引列表,并排序
|
||||||
|
* @param key
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private List<String> loadIndices(String key) {
|
||||||
|
ArrayList<String> lists = new ArrayList<String>();
|
||||||
|
try {
|
||||||
|
String[] indices = queryIndices(key + "*");
|
||||||
|
if (indices.length == 0) {
|
||||||
|
return lists;
|
||||||
|
}
|
||||||
|
lists.addAll(Arrays.asList(indices));
|
||||||
|
return lists;
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("load indices exception", e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取索引
|
* 获取索引
|
||||||
*
|
*
|
||||||
* @param wildcardIndex
|
* @param wildcardIndex
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public String[] getIndices(String wildcardIndex) throws Exception {
|
public String[] queryIndices(String wildcardIndex) throws Exception {
|
||||||
GetIndexRequest request = new GetIndexRequest(wildcardIndex);
|
GetIndexRequest request = new GetIndexRequest(wildcardIndex);
|
||||||
try {
|
try {
|
||||||
RestHighLevelClient client = SpringContextAware.getBean(RestHighLevelClient.class);
|
RestHighLevelClient client = SpringContextAware.getBean(RestHighLevelClient.class);
|
||||||
@ -89,7 +139,7 @@ public class BaseEsService {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("bulk insert failed,", e);
|
logger.error("es bulk insert failed,", e);
|
||||||
throw new Exception(e.getMessage());
|
throw new Exception(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -107,8 +157,25 @@ public class BaseEsService {
|
|||||||
RestHighLevelClient client = SpringContextAware.getBean(RestHighLevelClient.class);
|
RestHighLevelClient client = SpringContextAware.getBean(RestHighLevelClient.class);
|
||||||
return client.search(request, RequestOptions.DEFAULT);
|
return client.search(request, RequestOptions.DEFAULT);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("query failed,", e);
|
logger.error("es search query occur exception,", e);
|
||||||
throw new Exception("");
|
throw new Exception(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get 方式获取
|
||||||
|
*
|
||||||
|
* @param request
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public GetResponse get(GetRequest request) throws Exception {
|
||||||
|
try {
|
||||||
|
RestHighLevelClient client = SpringContextAware.getBean(RestHighLevelClient.class);
|
||||||
|
return client.get(request, RequestOptions.DEFAULT);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("es get query occur exception,", e);
|
||||||
|
throw new Exception(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -0,0 +1,44 @@
|
|||||||
|
package cn.axzo.log.platform.server.service;
|
||||||
|
|
||||||
|
import cn.axzo.log.platform.server.dto.*;
|
||||||
|
import cn.azxo.framework.common.model.CommonPageResponse;
|
||||||
|
|
||||||
|
/***
|
||||||
|
* @author: pepsi
|
||||||
|
* @description: TODO
|
||||||
|
* @date: 2022/9/15
|
||||||
|
*/
|
||||||
|
public interface OperateLogService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param operateLogReq
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
boolean insertOperaLog(OperateLogReqDTO operateLogReq) throws Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询 返回基本字段
|
||||||
|
*
|
||||||
|
* @param req
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
CommonPageResponse<OperateLogQueryRespDTO> queryBasicInfoForPage(OperateLogQueryReqDTO req) throws Exception;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回详情信息
|
||||||
|
*
|
||||||
|
* @param req
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
CommonPageResponse<OperateLogQueryDetailRespDTO> queryForPage(OperateLogQueryReqDTO req) throws Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询每个日志的详情
|
||||||
|
*
|
||||||
|
* @param req
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
OperateLogQueryDetailRespDTO queryOperateLogDetail(OperateLogQueryDetailReqDTO req) throws Exception;
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package cn.axzo.xlog.server.service.converter;
|
package cn.axzo.log.platform.server.service.converter;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -1,7 +1,8 @@
|
|||||||
package cn.axzo.xlog.server.service.converter;
|
package cn.axzo.log.platform.server.service.converter;
|
||||||
|
|
||||||
import cn.axzo.xlog.server.dto.OperateLogReqDTO;
|
import cn.axzo.log.platform.server.dto.OperateLogQueryDetailRespDTO;
|
||||||
import cn.axzo.xlog.server.entity.OperateLogRecordEntity;
|
import cn.axzo.log.platform.server.dto.OperateLogReqDTO;
|
||||||
|
import cn.axzo.log.platform.server.entity.OperateLogRecordEntity;
|
||||||
import org.mapstruct.Mapper;
|
import org.mapstruct.Mapper;
|
||||||
|
|
||||||
import static org.mapstruct.NullValueCheckStrategy.ALWAYS;
|
import static org.mapstruct.NullValueCheckStrategy.ALWAYS;
|
||||||
@ -18,4 +19,7 @@ import static org.mapstruct.NullValueCheckStrategy.ALWAYS;
|
|||||||
public interface OperateLogConverter {
|
public interface OperateLogConverter {
|
||||||
|
|
||||||
OperateLogRecordEntity toEntity(OperateLogReqDTO dto);
|
OperateLogRecordEntity toEntity(OperateLogReqDTO dto);
|
||||||
|
|
||||||
|
OperateLogQueryDetailRespDTO toDetailDto(OperateLogRecordEntity entity);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -0,0 +1,383 @@
|
|||||||
|
package cn.axzo.log.platform.server.service.impl;
|
||||||
|
|
||||||
|
import cn.axzo.apollo.core.web.Result;
|
||||||
|
import cn.axzo.apollo.workspace.api.workspace.WorkspaceApi;
|
||||||
|
import cn.axzo.apollo.workspace.api.workspace.req.GetDetailReq;
|
||||||
|
import cn.axzo.apollo.workspace.api.workspace.res.GetDetailRes;
|
||||||
|
import cn.axzo.basics.organizational.api.OrganizationalUnitApi;
|
||||||
|
import cn.axzo.basics.organizational.api.vo.response.OrganizationalUnitVO;
|
||||||
|
import cn.axzo.basics.profiles.api.UserProfileServiceApi;
|
||||||
|
import cn.axzo.basics.profiles.dto.basic.IdentityProfileDto;
|
||||||
|
import cn.axzo.log.platform.server.dto.*;
|
||||||
|
import cn.axzo.log.platform.server.entity.OperateLogRecordEntity;
|
||||||
|
import cn.axzo.log.platform.server.repository.OperateLogRepository;
|
||||||
|
import cn.axzo.log.platform.server.service.BaseEsService;
|
||||||
|
import cn.axzo.log.platform.server.service.OperateLogService;
|
||||||
|
import cn.axzo.log.platform.server.service.converter.OperateLogConverter;
|
||||||
|
import cn.axzo.pudge.core.service.ServiceException;
|
||||||
|
import cn.azxo.framework.common.model.CommonPageResponse;
|
||||||
|
import cn.azxo.framework.common.model.CommonResponse;
|
||||||
|
import cn.hutool.core.date.CalendarUtil;
|
||||||
|
import cn.hutool.core.date.DatePattern;
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import org.elasticsearch.action.get.GetRequest;
|
||||||
|
import org.elasticsearch.action.get.GetResponse;
|
||||||
|
import org.elasticsearch.action.search.SearchRequest;
|
||||||
|
import org.elasticsearch.action.search.SearchResponse;
|
||||||
|
import org.elasticsearch.index.query.*;
|
||||||
|
import org.elasticsearch.search.SearchHit;
|
||||||
|
import org.elasticsearch.search.SearchHits;
|
||||||
|
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||||
|
import org.elasticsearch.search.sort.SortOrder;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
|
||||||
|
/***
|
||||||
|
* @author: pepsi
|
||||||
|
* @description: TODO
|
||||||
|
* @date: 2022/9/15
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class OperateLogServiceImpl extends BaseEsService implements OperateLogService {
|
||||||
|
|
||||||
|
private final Logger logger = LoggerFactory.getLogger(OperateLogServiceImpl.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 索引前置名称,看后续是否要修改。
|
||||||
|
*/
|
||||||
|
@Value("${xlog.elastic.index.name:axzo_operatelog_}")
|
||||||
|
private String indexNamePrex;
|
||||||
|
|
||||||
|
@Value("${xlog.es.storage:false}")
|
||||||
|
private boolean esStorageFlag;
|
||||||
|
|
||||||
|
@Value("${oprlog.index.interval.days:7}")
|
||||||
|
private int intervalDays;
|
||||||
|
|
||||||
|
@Value("${oprlog.index.interval.mills:604800000}")
|
||||||
|
private long intervalMills;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private OperateLogRepository operateLogRepository;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private OrganizationalUnitApi organizationalUnitApi;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private WorkspaceApi workspaceApi;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private UserProfileServiceApi profileServiceApi;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private OperateLogConverter operateLogConverter;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean insertOperaLog(OperateLogReqDTO operateLogReq) throws Exception {
|
||||||
|
//调用接口字段补全
|
||||||
|
OperateLogRecordEntity record = fieldFill(operateLogReq);
|
||||||
|
//落库
|
||||||
|
if (!esStorageFlag) {
|
||||||
|
operateLogRepository.save(record);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//目前决定根据operateTime时间定,7天 (一般查询限制时间都是7天或者30天) 数据落一个索引中,
|
||||||
|
// 目前查看pre_new环境数据很少,上线前再查看一波线上数据决定索引生成的时间跨度,再做调整。
|
||||||
|
String indexSuffixDate = findIndexSuffixDate(operateLogReq.getOperateTime());
|
||||||
|
String json = JSONObject.toJSONString(operateLogReq);
|
||||||
|
return insert(json, indexNamePrex + indexSuffixDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CommonPageResponse<OperateLogQueryDetailRespDTO> queryForPage(OperateLogQueryReqDTO req) throws Exception {
|
||||||
|
//这里做个区分。时从ES查询获取还是从DB获取.
|
||||||
|
if (esStorageFlag) {
|
||||||
|
return queryForPageFromEs(req);
|
||||||
|
}
|
||||||
|
IPage<OperateLogRecordEntity> page = operateLogRepository.pageLogRecord(req);
|
||||||
|
//为空则返回空
|
||||||
|
List<OperateLogRecordEntity> recordList = page.getRecords();
|
||||||
|
if (recordList == null || recordList.isEmpty()) {
|
||||||
|
return CommonPageResponse.zero(req.getPage(), req.getPageSize());
|
||||||
|
}
|
||||||
|
List<OperateLogQueryDetailRespDTO> respList = new ArrayList<>();
|
||||||
|
recordList.forEach(item -> {
|
||||||
|
OperateLogQueryDetailRespDTO detail = operateLogConverter.toDetailDto(item);
|
||||||
|
detail.setId(item.getId().toString());
|
||||||
|
respList.add(detail);
|
||||||
|
});
|
||||||
|
return CommonPageResponse.list(req.getPage(), req.getPageSize(), page.getTotal(), respList);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CommonPageResponse<OperateLogQueryRespDTO> queryBasicInfoForPage(OperateLogQueryReqDTO req) throws Exception {
|
||||||
|
CommonPageResponse<OperateLogQueryDetailRespDTO> detailResp = queryForPage(req);
|
||||||
|
if (detailResp.getList() == null || detailResp.getList().isEmpty()) {
|
||||||
|
return CommonPageResponse.zero(detailResp.getPage(), detailResp.getPageSize());
|
||||||
|
}
|
||||||
|
List<OperateLogQueryRespDTO> respList = assembleOperateLogResp(detailResp.getList());
|
||||||
|
return CommonPageResponse.list(detailResp.getPage(), detailResp.getPageSize(), detailResp.getTotalCount(), respList);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OperateLogQueryDetailRespDTO queryOperateLogDetail(OperateLogQueryDetailReqDTO req) throws Exception {
|
||||||
|
if (esStorageFlag) {
|
||||||
|
return queryOperateLogDetailFromEs(req.getOperateTime(), req.getId());
|
||||||
|
}
|
||||||
|
//从DB查询
|
||||||
|
OperateLogRecordEntity entity = operateLogRepository.queryById(Long.valueOf(req.getId()));
|
||||||
|
if (entity == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return operateLogConverter.toDetailDto(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
* 从ES获取查询结果
|
||||||
|
* @param req
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public CommonPageResponse<OperateLogQueryDetailRespDTO> queryForPageFromEs(OperateLogQueryReqDTO req) throws Exception {
|
||||||
|
//根据查询的时间段获取所属的索引集合
|
||||||
|
Set<String> indices = betweenIndices(req.getStartTime(), req.getEndTime());
|
||||||
|
if (indices.isEmpty()) {
|
||||||
|
logger.warn("can not find index,startDate={}.", DateUtil.format(req.getStartTime(), DatePattern.PURE_DATE_PATTERN));
|
||||||
|
return CommonPageResponse.zero(req.getPage(), req.getPageSize());
|
||||||
|
}
|
||||||
|
//组装查询条件.
|
||||||
|
SearchSourceBuilder builder = assembleQueryBuilder(req);
|
||||||
|
SearchRequest request = new SearchRequest();
|
||||||
|
request.source(builder);
|
||||||
|
SearchResponse response = search(request, indices.toArray(new String[]{}));
|
||||||
|
//处理查询结果的数据
|
||||||
|
SearchHits hits = response.getHits();
|
||||||
|
SearchHit[] searchHits = hits.getHits();
|
||||||
|
Map<String, OperateLogRecordEntity> resMap = new HashMap<>(searchHits.length);
|
||||||
|
if (searchHits.length == 0) {
|
||||||
|
return CommonPageResponse.zero(req.getPage(), req.getPageSize());
|
||||||
|
}
|
||||||
|
for (SearchHit hit : searchHits) {
|
||||||
|
String oprLogStr = hit.getSourceAsString();
|
||||||
|
resMap.put(hit.getId(), JSONObject.parseObject(oprLogStr, OperateLogRecordEntity.class));
|
||||||
|
}
|
||||||
|
List<OperateLogQueryDetailRespDTO> detailLists = new ArrayList<>();
|
||||||
|
resMap.forEach(new BiConsumer<String, OperateLogRecordEntity>() {
|
||||||
|
@Override
|
||||||
|
public void accept(String id, OperateLogRecordEntity entity) {
|
||||||
|
OperateLogQueryDetailRespDTO detail = operateLogConverter.toDetailDto(entity);
|
||||||
|
detail.setId(id);
|
||||||
|
detailLists.add(detail);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return CommonPageResponse.list(req.getPage(), req.getPageSize(), hits.getTotalHits().value, detailLists);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对于 es 而言,需要索引信息.
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public OperateLogQueryDetailRespDTO queryOperateLogDetailFromEs(Date oprDateTime, String id) throws Exception {
|
||||||
|
//根据日期找索引,
|
||||||
|
String indexName = indexNamePrex + findIndexSuffixDate(oprDateTime);
|
||||||
|
//需要判断下索引是否存在,
|
||||||
|
List<String> indices = getIndices(indexNamePrex);
|
||||||
|
if (!indices.contains(indexName)) {
|
||||||
|
logger.warn("can not find index,oprDateTime={},id={}", oprDateTime, id);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
GetRequest getRequest = new GetRequest(indexName, id);
|
||||||
|
GetResponse response = get(getRequest);
|
||||||
|
String oprLogStr = response.getSourceAsString();
|
||||||
|
OperateLogRecordEntity entity = JSONObject.parseObject(oprLogStr, OperateLogRecordEntity.class);
|
||||||
|
return operateLogConverter.toDetailDto(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
* 根据数据中的日期信息找到所属的索引
|
||||||
|
* 目前是按7天的规则。
|
||||||
|
* @param date
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private String findIndexSuffixDate(Date date) {
|
||||||
|
long mills = date.getTime();
|
||||||
|
long weekMills = mills % intervalMills;
|
||||||
|
Date currDate = new Date(mills - weekMills);
|
||||||
|
return DateUtil.format(currDate, DatePattern.PURE_DATE_PATTERN);
|
||||||
|
}
|
||||||
|
|
||||||
|
private OperateLogRecordEntity fieldFill(OperateLogReqDTO req) {
|
||||||
|
//补充 termimnal identityType featureName.
|
||||||
|
OperateLogRecordEntity unifiedLogRecord = operateLogConverter.toEntity(req);
|
||||||
|
//判断是否已经传手机和姓名存在,如果不存在则(通过接口调用,获取用户手机姓名)
|
||||||
|
if (!StringUtils.hasText(unifiedLogRecord.getIdentityUserPhone())
|
||||||
|
|| StringUtils.hasText(unifiedLogRecord.getIdentityUserName())) {
|
||||||
|
IdentityProfileDto identityProfile = qryIdentityProfile(req.getIdentityId(), req.getIdentityType());
|
||||||
|
if (identityProfile != null && identityProfile.getPersonProfile() != null) {
|
||||||
|
unifiedLogRecord.setIdentityUserName(identityProfile.getPersonProfile().getRealName());
|
||||||
|
unifiedLogRecord.setIdentityUserPhone(identityProfile.getPersonProfile().getPhone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 通过接口方式调用 workspaceApi单位等信息,
|
||||||
|
GetDetailRes workspaceInf = qryWorkspaceInfo(req.getWorkspaceId());
|
||||||
|
unifiedLogRecord.setWorkspaceName(null != workspaceInf ? workspaceInf.getName() : null);
|
||||||
|
OrganizationalUnitVO ouInf = qryOrgUnitInf(req.getOuId());
|
||||||
|
unifiedLogRecord.setOuName(ouInf != null ? ouInf.getName() : null);
|
||||||
|
return unifiedLogRecord;
|
||||||
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
* 获取2个时间段之间的索引。startTime + 7 < endTime 即可。
|
||||||
|
* @param startDate
|
||||||
|
* @param endDate
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private Set<String> betweenIndices(Date startDate, Date endDate) {
|
||||||
|
Set<String> betweenIndices = new HashSet<>();
|
||||||
|
long startMills = startDate.getTime();
|
||||||
|
long startIntervalMills = startMills % intervalMills;
|
||||||
|
Date startWeekDate = new Date(startMills - startIntervalMills);
|
||||||
|
while (startWeekDate.before(endDate)) {
|
||||||
|
String index = indexNamePrex + DateUtil.format(startWeekDate, DatePattern.PURE_DATE_PATTERN);
|
||||||
|
betweenIndices.add(index);
|
||||||
|
Calendar calendar = CalendarUtil.calendar(startWeekDate);
|
||||||
|
calendar.add(Calendar.DAY_OF_MONTH, intervalDays);
|
||||||
|
startWeekDate = calendar.getTime();
|
||||||
|
}
|
||||||
|
//需要判断下索引是否存在,
|
||||||
|
List<String> indices = getIndices(indexNamePrex);
|
||||||
|
betweenIndices.removeIf(index -> !indices.contains(index));
|
||||||
|
return betweenIndices;
|
||||||
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
* 组装ES查询条件
|
||||||
|
* @param req
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private SearchSourceBuilder assembleQueryBuilder(OperateLogQueryReqDTO req) {
|
||||||
|
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
|
||||||
|
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
|
||||||
|
if (StringUtils.hasText(req.getServiceName())) {
|
||||||
|
MatchQueryBuilder builder = QueryBuilders.matchQuery("serviceName", req.getServiceName());
|
||||||
|
boolQueryBuilder.filter(builder);
|
||||||
|
}
|
||||||
|
if (StringUtils.hasText(req.getOperateUserName())) {
|
||||||
|
MatchQueryBuilder builder = QueryBuilders.matchQuery("operateUserName", req.getServiceName());
|
||||||
|
boolQueryBuilder.filter(builder);
|
||||||
|
}
|
||||||
|
if (req.getWorkspaceId() != null && req.getWorkspaceId() > 0) {
|
||||||
|
TermQueryBuilder builder = QueryBuilders.termQuery("workspaceId", req.getServiceName());
|
||||||
|
boolQueryBuilder.filter(builder);
|
||||||
|
}
|
||||||
|
if (req.getOuId() != null && req.getOuId() > 0) {
|
||||||
|
TermQueryBuilder builder = QueryBuilders.termQuery("ouId", req.getServiceName());
|
||||||
|
boolQueryBuilder.filter(builder);
|
||||||
|
}
|
||||||
|
if (req.getIdentityId() != null && req.getIdentityId() > 0) {
|
||||||
|
TermQueryBuilder builder = QueryBuilders.termQuery("identityId", req.getServiceName());
|
||||||
|
boolQueryBuilder.filter(builder);
|
||||||
|
}
|
||||||
|
if (req.getIdentityType() != null) {
|
||||||
|
TermQueryBuilder builder = QueryBuilders.termQuery("identityType", req.getServiceName());
|
||||||
|
boolQueryBuilder.filter(builder);
|
||||||
|
}
|
||||||
|
if (req.getOperateType() != null) {
|
||||||
|
TermQueryBuilder builder = QueryBuilders.termQuery("operateType", req.getServiceName());
|
||||||
|
boolQueryBuilder.filter(builder);
|
||||||
|
}
|
||||||
|
if (StringUtils.hasText(req.getOperateTable())) {
|
||||||
|
TermQueryBuilder builder = QueryBuilders.termQuery("operateTable", req.getServiceName());
|
||||||
|
boolQueryBuilder.filter(builder);
|
||||||
|
}
|
||||||
|
//时间段
|
||||||
|
RangeQueryBuilder rangeQueryBuilder = QueryBuilders.rangeQuery("operateTime")
|
||||||
|
.gte(req.getStartTime().getTime())
|
||||||
|
.lte(req.getEndTime().getTime());
|
||||||
|
boolQueryBuilder.filter(rangeQueryBuilder);
|
||||||
|
searchSourceBuilder.sort("operateTime", SortOrder.DESC);
|
||||||
|
//采用 from +size,条件限制多一点。不做深查询了,因为scroll 快照数据不准确问题。
|
||||||
|
int page = req.getPage() == null ? 1 : req.getPage().intValue();
|
||||||
|
int size = req.getPageSize() == null ? 20 : req.getPageSize().intValue();
|
||||||
|
searchSourceBuilder.from((page - 1) * size).size(size);
|
||||||
|
searchSourceBuilder.query(boolQueryBuilder);
|
||||||
|
return searchSourceBuilder;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<OperateLogQueryRespDTO> assembleOperateLogResp(List<OperateLogQueryDetailRespDTO> recordList) {
|
||||||
|
List<OperateLogQueryRespDTO> resList = new ArrayList<>();
|
||||||
|
recordList.forEach((ele) -> {
|
||||||
|
OperateLogQueryRespDTO response = new OperateLogQueryRespDTO();
|
||||||
|
response.setOperateUserName(ele.getIdentityUserName());
|
||||||
|
response.setFeatureCode(ele.getFeatureCode());
|
||||||
|
response.setFeatureName(ele.getFeatureName());
|
||||||
|
response.setContentSummary(ele.getContentSummary());
|
||||||
|
response.setOperateTime(ele.getOperateTime());
|
||||||
|
response.setOperateUserPhone(ele.getIdentityUserPhone());
|
||||||
|
response.setOuName(ele.getOuName());
|
||||||
|
response.setId(ele.getId());
|
||||||
|
resList.add(response);
|
||||||
|
});
|
||||||
|
return resList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
* workspaceId 查询 WS 信息
|
||||||
|
* @param workspaceId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private GetDetailRes qryWorkspaceInfo(Long workspaceId) {
|
||||||
|
GetDetailReq getDetailReq = new GetDetailReq();
|
||||||
|
getDetailReq.setId(workspaceId);
|
||||||
|
Result<GetDetailRes> res = workspaceApi.getDetail(getDetailReq);
|
||||||
|
if (res.getCode() != 200) {
|
||||||
|
logger.error("query workspace with wsId failed,wsId={},errMsg={}.", workspaceId, res.getMsg());
|
||||||
|
throw new ServiceException(res.getMsg());
|
||||||
|
}
|
||||||
|
return res.getData();
|
||||||
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
* 通过ouId查询 OrganizationalUnit 信息
|
||||||
|
* @param ouId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private OrganizationalUnitVO qryOrgUnitInf(Long ouId) {
|
||||||
|
CommonResponse<OrganizationalUnitVO> response = organizationalUnitApi.getById(ouId);
|
||||||
|
if (response.getCode() != 200) {
|
||||||
|
throw new ServiceException(response.getMsg());
|
||||||
|
}
|
||||||
|
return response.getData();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param identityId
|
||||||
|
* @param identityType
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private IdentityProfileDto qryIdentityProfile(Long identityId, Integer identityType) {
|
||||||
|
//todo 需要根据类型判断用那个接口查询
|
||||||
|
|
||||||
|
List<Long> ids = new ArrayList<>();
|
||||||
|
ids.add(identityId);
|
||||||
|
CommonResponse<List<IdentityProfileDto>> response = profileServiceApi.getIdentitiesByIdSet(ids, identityType);
|
||||||
|
if (response.getCode() != 200) {
|
||||||
|
throw new ServiceException(response.getMsg());
|
||||||
|
}
|
||||||
|
List<IdentityProfileDto> profileList = response.getData();
|
||||||
|
if (profileList.size() != 1) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return profileList.get(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,6 +1,6 @@
|
|||||||
spring:
|
spring:
|
||||||
application:
|
application:
|
||||||
name: xlog
|
name: axzo-log-plat
|
||||||
cloud:
|
cloud:
|
||||||
nacos:
|
nacos:
|
||||||
config:
|
config:
|
||||||
@ -0,0 +1,25 @@
|
|||||||
|
package cn.axzo.log.platform.server;
|
||||||
|
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||||
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
|
/***
|
||||||
|
* @author: pepsi
|
||||||
|
* @description: TODO
|
||||||
|
* @date: 2022/9/16
|
||||||
|
*/
|
||||||
|
@RunWith(SpringRunner.class)
|
||||||
|
@SpringBootTest
|
||||||
|
@EnableFeignClients(basePackages = {
|
||||||
|
"cn.axzo.third.api",
|
||||||
|
"cn.axzo.apollo",
|
||||||
|
"cn.axzo.pudge",
|
||||||
|
"cn.axzo.elise",
|
||||||
|
"cn.axzo.basics",
|
||||||
|
"cn.axzo.log.platform.client",
|
||||||
|
})
|
||||||
|
public class LogPlatApplicationTestBase {
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,63 @@
|
|||||||
|
package cn.axzo.log.platform.server.api;
|
||||||
|
|
||||||
|
import cn.axzo.log.platform.client.LogPlatClient;
|
||||||
|
import cn.axzo.log.platform.client.model.OperateLogQueryReq;
|
||||||
|
import cn.axzo.log.platform.client.model.OperateLogQueryResp;
|
||||||
|
import cn.axzo.log.platform.client.model.OperateLogReq;
|
||||||
|
import cn.axzo.log.platform.server.LogPlatApplicationTestBase;
|
||||||
|
import cn.azxo.framework.common.model.CommonPageResponse;
|
||||||
|
import cn.hutool.core.date.DatePattern;
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/***
|
||||||
|
* @author: pepsi
|
||||||
|
* @description: TODO
|
||||||
|
* @date: 2022/10/13
|
||||||
|
*/
|
||||||
|
public class LogPlatClientTest extends LogPlatApplicationTestBase {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private LogPlatClient logPlatClient;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInsert() {
|
||||||
|
OperateLogReq req = new OperateLogReq();
|
||||||
|
req.setServiceName("ServiceName");
|
||||||
|
req.setFeatureCode("FeatureCode");
|
||||||
|
req.setFeatureName("FeatureName");
|
||||||
|
req.setLogGrade(4);
|
||||||
|
req.setOperateTime(new Date());
|
||||||
|
req.setIdentityId(1L);
|
||||||
|
req.setIdentityType(1);
|
||||||
|
req.setWorkspaceId(1L);
|
||||||
|
req.setOuId(1L);
|
||||||
|
req.setTerminal("macos");
|
||||||
|
req.setOperateUserIp("macos-ip-test");
|
||||||
|
req.setOperateBefore("OperateBefore");
|
||||||
|
req.setOperateAfter("OperateAfter");
|
||||||
|
req.setOperateParam("OperateParam");
|
||||||
|
req.setContentSummary("ContentSummary");
|
||||||
|
req.setContentSummary("ContentSummary");
|
||||||
|
req.setLogExt("LogExt");
|
||||||
|
req.setResourceId(1L);
|
||||||
|
req.setResourceType(1);
|
||||||
|
req.setOperateType(1);
|
||||||
|
req.setOperateTable("table_name");
|
||||||
|
logPlatClient.createOperateLog(req);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testQuery() {
|
||||||
|
OperateLogQueryReq queryReq = new OperateLogQueryReq();
|
||||||
|
queryReq.setServiceName("ServiceName");
|
||||||
|
queryReq.setStartTime(DateUtil.parse("2022-10-01 12:00:00", DatePattern.NORM_DATETIME_FORMAT));
|
||||||
|
queryReq.setEndTime(new Date());
|
||||||
|
CommonPageResponse<OperateLogQueryResp> response = logPlatClient.queryForPage(queryReq);
|
||||||
|
assert response.getTotalCount() == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,118 @@
|
|||||||
|
package cn.axzo.log.platform.server.config;
|
||||||
|
|
||||||
|
import cn.axzo.log.platform.server.entity.OperateLogRecordEntity;
|
||||||
|
import cn.axzo.log.platform.server.service.BaseEsService;
|
||||||
|
import cn.hutool.core.date.CalendarUtil;
|
||||||
|
import cn.hutool.core.date.DatePattern;
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import org.elasticsearch.client.RestHighLevelClient;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/***
|
||||||
|
* @author: pepsi
|
||||||
|
* @description: TODO
|
||||||
|
* @date: 2022/9/19
|
||||||
|
*/
|
||||||
|
@RunWith(SpringRunner.class)
|
||||||
|
@SpringBootTest
|
||||||
|
public class ElasticClientConfigTest extends BaseEsService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RestHighLevelClient client;
|
||||||
|
|
||||||
|
private long sevenDayMills = 7 * 24 * 60 * 60 * 1000;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInsert() throws Exception {
|
||||||
|
OperateLogRecordEntity entity = new OperateLogRecordEntity();
|
||||||
|
entity.setLogGrade(1);
|
||||||
|
entity.setLogExt("test");
|
||||||
|
entity.setIdentityId(15L);
|
||||||
|
entity.setOperateAfter("test");
|
||||||
|
entity.setOperateParam("test");
|
||||||
|
entity.setFeatureCode("test");
|
||||||
|
entity.setOperateTable("test");
|
||||||
|
entity.setOperateType(1);
|
||||||
|
entity.setContentSummary("test");
|
||||||
|
entity.setOperateTime(new Date());
|
||||||
|
entity.setServiceName("test");
|
||||||
|
entity.setOuId(1L);
|
||||||
|
entity.setOperateUserIp("test");
|
||||||
|
entity.setWorkspaceId(1L);
|
||||||
|
entity.setResourceType(1);
|
||||||
|
entity.setIdentityType(3);
|
||||||
|
entity.setTerminal("test");
|
||||||
|
entity.setOperateBefore("test");
|
||||||
|
entity.setFeatureName("test");
|
||||||
|
entity.setResourceId(1L);
|
||||||
|
String data = JSONObject.toJSONString(entity);
|
||||||
|
String index = "xlog_operatelog_202209";
|
||||||
|
List<String> list = new ArrayList<>();
|
||||||
|
list.add(data);
|
||||||
|
boolean flag = this.bulkInsert(list, index);
|
||||||
|
Assert.assertTrue(flag);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIndexInterval() {
|
||||||
|
long sevenDayMills = 7 * 24 * 60 * 60 * 1000;
|
||||||
|
Date now = new Date();
|
||||||
|
String weekDate = interval(now);
|
||||||
|
System.out.println("now:" + weekDate);
|
||||||
|
|
||||||
|
String weekDateThreeDaysAgo = interval(add(now, -3));
|
||||||
|
System.out.println("ThreeDaysAgo:" + weekDateThreeDaysAgo);
|
||||||
|
|
||||||
|
String weekDateTwoDaysAgo = interval(add(now, -2));
|
||||||
|
System.out.println("now:" + weekDateTwoDaysAgo);
|
||||||
|
|
||||||
|
String weekDateAfter1 = interval(add(now, 1));
|
||||||
|
System.out.println("After1:" + weekDateAfter1);
|
||||||
|
|
||||||
|
String weekDateAfter2 = interval(add(now, 2));
|
||||||
|
System.out.println("After2:" + weekDateAfter2);
|
||||||
|
|
||||||
|
String weekDateAfter3 = interval(add(now, 3));
|
||||||
|
System.out.println("After3:" + weekDateAfter3);
|
||||||
|
|
||||||
|
String weekDateAfter4 = interval(add(now, 4));
|
||||||
|
System.out.println("After4:" + weekDateAfter4);
|
||||||
|
|
||||||
|
String weekDateAfter5 = interval(add(now, 5));
|
||||||
|
System.out.println("After5:" + weekDateAfter5);
|
||||||
|
|
||||||
|
String weekDateAfter6 = interval(add(now, 6));
|
||||||
|
System.out.println("After6:" + weekDateAfter6);
|
||||||
|
|
||||||
|
String weekDateAfter7 = interval(add(now, 7));
|
||||||
|
System.out.println("After7:" + weekDateAfter7);
|
||||||
|
|
||||||
|
String weekDateAfter8 = interval(add(now, 8));
|
||||||
|
System.out.println("After8:" + weekDateAfter8);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Date add(Date date, int interval) {
|
||||||
|
Calendar calendar = CalendarUtil.calendar(date);
|
||||||
|
calendar.add(Calendar.DAY_OF_MONTH, interval);
|
||||||
|
return calendar.getTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String interval(Date date) {
|
||||||
|
long mills = date.getTime();
|
||||||
|
long intervalMills = mills % sevenDayMills;
|
||||||
|
Date currDate = new Date(mills - intervalMills);
|
||||||
|
return DateUtil.format(currDate, DatePattern.PURE_DATE_PATTERN);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,6 +1,6 @@
|
|||||||
package cn.axzo.xlog.server.config;
|
package cn.axzo.log.platform.server.config;
|
||||||
|
|
||||||
import cn.axzo.xlog.server.XlogApplicationTestBase;
|
import cn.axzo.log.platform.server.LogPlatApplicationTestBase;
|
||||||
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
|
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
|
||||||
import org.elasticsearch.action.support.master.AcknowledgedResponse;
|
import org.elasticsearch.action.support.master.AcknowledgedResponse;
|
||||||
import org.elasticsearch.client.RequestOptions;
|
import org.elasticsearch.client.RequestOptions;
|
||||||
@ -14,7 +14,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
* @description: TODO
|
* @description: TODO
|
||||||
* @date: 2022/9/19
|
* @date: 2022/9/19
|
||||||
*/
|
*/
|
||||||
public class IndexOprTest extends XlogApplicationTestBase {
|
public class IndexOprTest extends LogPlatApplicationTestBase {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private RestHighLevelClient client;
|
private RestHighLevelClient client;
|
||||||
@ -1,7 +1,7 @@
|
|||||||
package cn.axzo.xlog.server.config;
|
package cn.axzo.log.platform.server.config;
|
||||||
|
|
||||||
import cn.axzo.xlog.server.XlogApplicationTestBase;
|
import cn.axzo.log.platform.server.LogPlatApplicationTestBase;
|
||||||
import cn.axzo.xlog.server.dto.OperateLogReqDTO;
|
import cn.axzo.log.platform.server.dto.OperateLogReqDTO;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||||
@ -14,14 +14,17 @@ import java.util.Date;
|
|||||||
* @description: TODO
|
* @description: TODO
|
||||||
* @date: 2022/9/16
|
* @date: 2022/9/16
|
||||||
*/
|
*/
|
||||||
public class RabbitMqConsumerTest extends XlogApplicationTestBase {
|
public class RabbitMqConsumerTest extends LogPlatApplicationTestBase {
|
||||||
|
|
||||||
|
public static final String OPERATE_LOG_QUEUE_NAME = "log-plat.oprlog.queue";
|
||||||
|
public static final String OPERATE_LOG_EXCHANGE = "log-plat.oprlog.test.exchange";
|
||||||
|
public static final String OPERATE_LOG_ROUTING_KEY = "log-plat.oprlog.test.routingKey";
|
||||||
@Resource
|
@Resource
|
||||||
private RabbitTemplate rabbitTemplate;
|
private RabbitTemplate rabbitTemplate;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSendMsg() throws InterruptedException {
|
public void testSendMsg() throws InterruptedException {
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 1; i++) {
|
||||||
OperateLogReqDTO reqData = new OperateLogReqDTO();
|
OperateLogReqDTO reqData = new OperateLogReqDTO();
|
||||||
reqData.setLogGrade(1);
|
reqData.setLogGrade(1);
|
||||||
reqData.setLogExt("test");
|
reqData.setLogExt("test");
|
||||||
@ -43,7 +46,7 @@ public class RabbitMqConsumerTest extends XlogApplicationTestBase {
|
|||||||
reqData.setOperateBefore("test");
|
reqData.setOperateBefore("test");
|
||||||
reqData.setFeatureName("test");
|
reqData.setFeatureName("test");
|
||||||
reqData.setResourceId(1L);
|
reqData.setResourceId(1L);
|
||||||
rabbitTemplate.convertAndSend(RabbitMqConfig.OPERATE_LOG_QUEUE_NAME, JSONObject.toJSONString(reqData));
|
rabbitTemplate.convertAndSend(OPERATE_LOG_QUEUE_NAME, JSONObject.toJSONString(reqData));
|
||||||
System.out.println("send msg success");
|
System.out.println("send msg success");
|
||||||
}
|
}
|
||||||
Thread.sleep(1000 * 10);
|
Thread.sleep(1000 * 10);
|
||||||
@ -1,11 +1,11 @@
|
|||||||
package cn.axzo.xlog.server.service;
|
package cn.axzo.log.platform.server.service;
|
||||||
|
|
||||||
import cn.axzo.xlog.server.XlogApplicationTestBase;
|
import cn.axzo.log.platform.server.LogPlatApplicationTestBase;
|
||||||
import cn.axzo.xlog.server.dto.OperateLogQueryReqDTO;
|
import cn.axzo.log.platform.server.dto.OperateLogQueryReqDTO;
|
||||||
import cn.axzo.xlog.server.dto.OperateLogQueryRespDTO;
|
import cn.axzo.log.platform.server.dto.OperateLogQueryRespDTO;
|
||||||
import cn.axzo.xlog.server.dto.OperateLogReqDTO;
|
import cn.axzo.log.platform.server.dto.OperateLogReqDTO;
|
||||||
import cn.axzo.xlog.server.entity.OperateLogRecordEntity;
|
import cn.axzo.log.platform.server.entity.OperateLogRecordEntity;
|
||||||
import cn.axzo.xlog.server.service.converter.OperateLogConverter;
|
import cn.axzo.log.platform.server.service.converter.OperateLogConverter;
|
||||||
import cn.azxo.framework.common.model.CommonPageResponse;
|
import cn.azxo.framework.common.model.CommonPageResponse;
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
@ -22,7 +22,7 @@ import java.util.List;
|
|||||||
* @description: TODO
|
* @description: TODO
|
||||||
* @date: 2022/9/16
|
* @date: 2022/9/16
|
||||||
*/
|
*/
|
||||||
public class OperateLogServiceTest extends XlogApplicationTestBase {
|
public class OperateLogServiceTest extends LogPlatApplicationTestBase {
|
||||||
|
|
||||||
private OperateLogReqDTO reqData;
|
private OperateLogReqDTO reqData;
|
||||||
|
|
||||||
@ -73,11 +73,11 @@ public class OperateLogServiceTest extends XlogApplicationTestBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPageQuery() {
|
public void testPageQuery() throws Exception {
|
||||||
OperateLogQueryReqDTO req = new OperateLogQueryReqDTO();
|
OperateLogQueryReqDTO req = new OperateLogQueryReqDTO();
|
||||||
req.setPage(1L);
|
req.setPage(1L);
|
||||||
req.setPageSize(3L);
|
req.setPageSize(3L);
|
||||||
CommonPageResponse<OperateLogQueryRespDTO> response = operateLogService.queryForPage(req);
|
CommonPageResponse<OperateLogQueryRespDTO> response = operateLogService.queryBasicInfoForPage(req);
|
||||||
long totalCount = response.getTotalCount();
|
long totalCount = response.getTotalCount();
|
||||||
Assert.assertEquals(3L, totalCount);
|
Assert.assertEquals(3L, totalCount);
|
||||||
List<OperateLogQueryRespDTO> respList = response.getList();
|
List<OperateLogQueryRespDTO> respList = response.getList();
|
||||||
@ -91,7 +91,7 @@ public class OperateLogServiceTest extends XlogApplicationTestBase {
|
|||||||
req.setPageSize(20L);
|
req.setPageSize(20L);
|
||||||
req.setStartTime(DateUtil.parse("2022-09-01 00:00:00", "yyyy-MM-dd HH:mm:ss").toJdkDate());
|
req.setStartTime(DateUtil.parse("2022-09-01 00:00:00", "yyyy-MM-dd HH:mm:ss").toJdkDate());
|
||||||
req.setEndTime(DateUtil.parse("2023-09-01 00:00:00", "yyyy-MM-dd HH:mm:ss").toJdkDate());
|
req.setEndTime(DateUtil.parse("2023-09-01 00:00:00", "yyyy-MM-dd HH:mm:ss").toJdkDate());
|
||||||
CommonPageResponse<OperateLogQueryRespDTO> response = operateLogService.queryForPageFromEs(req);
|
CommonPageResponse<OperateLogQueryRespDTO> response = operateLogService.queryBasicInfoForPage(req);
|
||||||
long totalCount = response.getTotalCount();
|
long totalCount = response.getTotalCount();
|
||||||
Assert.assertEquals(103L, totalCount);
|
Assert.assertEquals(103L, totalCount);
|
||||||
List<OperateLogQueryRespDTO> respList = response.getList();
|
List<OperateLogQueryRespDTO> respList = response.getList();
|
||||||
31
pom.xml
31
pom.xml
@ -5,22 +5,23 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>cn.axzo.infra</groupId>
|
<groupId>cn.axzo.infra</groupId>
|
||||||
<artifactId>axzo-parent</artifactId>
|
<artifactId>axzo-parent</artifactId>
|
||||||
<version>2.4.13</version>
|
<version>2.4.13.4</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<groupId>cn.axzo.xlog</groupId>
|
<groupId>cn.axzo.platform</groupId>
|
||||||
<artifactId>xlog</artifactId>
|
<artifactId>axzo-log-plat</artifactId>
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
<packaging>pom</packaging>
|
|
||||||
|
|
||||||
<name>xlog</name>
|
|
||||||
<url>http://maven.apache.org</url>
|
|
||||||
|
|
||||||
<modules>
|
<modules>
|
||||||
<module>xlog-client</module>
|
<module>axzo-log-server</module>
|
||||||
<module>xlog-server</module>
|
<module>axzo-log-api</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
|
<name>axzo-log-plat</name>
|
||||||
|
<url>http://maven.apache.org</url>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<mapstruct.version>1.4.2.Final</mapstruct.version>
|
<mapstruct.version>1.4.2.Final</mapstruct.version>
|
||||||
@ -29,6 +30,7 @@
|
|||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>cn.axzo.infra</groupId>
|
<groupId>cn.axzo.infra</groupId>
|
||||||
@ -46,6 +48,7 @@
|
|||||||
<scope>import</scope>
|
<scope>import</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@ -80,6 +83,7 @@
|
|||||||
<artifactId>spring-boot-starter-test</artifactId>
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
@ -105,4 +109,13 @@
|
|||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>axzo</id>
|
||||||
|
<name>axzo repository</name>
|
||||||
|
<url>https://nexus.axzo.cn/repository/axzo/</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@ -1,20 +0,0 @@
|
|||||||
package cn.axzo.xlog.client.config;
|
|
||||||
|
|
||||||
import cn.axzo.xlog.client.XLogClient;
|
|
||||||
import cn.axzo.xlog.client.feign.XLogApi;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author: liyong.tian
|
|
||||||
* @Date: 2022/9/17
|
|
||||||
* @Description:
|
|
||||||
*/
|
|
||||||
@Configuration
|
|
||||||
public class XLogClientAutoConfiguration {
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public XLogClient xLogClient(XLogApi xLogApi) {
|
|
||||||
return new XLogClient(xLogApi);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,41 +0,0 @@
|
|||||||
package cn.axzo.xlog.server.config;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
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.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
/***
|
|
||||||
* @author: pepsi
|
|
||||||
* @description: TODO
|
|
||||||
* @date: 2022/9/16
|
|
||||||
*/
|
|
||||||
@Configuration
|
|
||||||
public class RabbitMqConfig {
|
|
||||||
private final Logger logger = LoggerFactory.getLogger(RabbitMqConfig.class);
|
|
||||||
// 操作日志队列
|
|
||||||
public static final String OPERATE_LOG_QUEUE_NAME = "unified.operate.log";
|
|
||||||
public static final String OPERATE_LOG_EXCHANGE = "unified.operate.log.exchange";
|
|
||||||
public static final String OPERATE_LOG_ROUTING_KEY = "unified.operate.log.routingKey";
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public Queue operateLogQueue() {
|
|
||||||
return new Queue(OPERATE_LOG_QUEUE_NAME, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public DirectExchange operateLogExchange() {
|
|
||||||
return new DirectExchange(OPERATE_LOG_EXCHANGE, true, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public Binding operateLogBindingDirect(DirectExchange exchange, Queue oprlogeQueue) {
|
|
||||||
Binding binding = BindingBuilder.bind(oprlogeQueue).to(exchange).with(OPERATE_LOG_ROUTING_KEY);
|
|
||||||
logger.info("rabbitmq queue:[{}] binding exchange:[{}] success.", oprlogeQueue.getName(), exchange.getName());
|
|
||||||
return binding;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,10 +0,0 @@
|
|||||||
package cn.axzo.xlog.server.controller;
|
|
||||||
|
|
||||||
/***
|
|
||||||
* @author: pepsi
|
|
||||||
* @description: TODO
|
|
||||||
* @date: 2022/9/16
|
|
||||||
*/
|
|
||||||
public abstract class BaseController {
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,60 +0,0 @@
|
|||||||
package cn.axzo.xlog.server.controller.api;
|
|
||||||
|
|
||||||
import cn.axzo.xlog.server.dto.OperateLogQueryReqDTO;
|
|
||||||
import cn.axzo.xlog.server.dto.OperateLogQueryRespDTO;
|
|
||||||
import cn.axzo.xlog.server.dto.OperateLogReqDTO;
|
|
||||||
import cn.axzo.xlog.server.exception.ServiceException;
|
|
||||||
import cn.axzo.xlog.server.service.OperateLogService;
|
|
||||||
import cn.azxo.framework.common.model.CommonPageResponse;
|
|
||||||
import cn.azxo.framework.common.model.CommonResponse;
|
|
||||||
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
|
|
||||||
import io.swagger.annotations.Api;
|
|
||||||
import io.swagger.annotations.ApiOperation;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMethod;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import javax.validation.Valid;
|
|
||||||
|
|
||||||
/***
|
|
||||||
* @author: pepsi
|
|
||||||
* @description: TODO
|
|
||||||
* @date: 2022/9/16
|
|
||||||
*/
|
|
||||||
@Api(tags = "web-操作日志接口")
|
|
||||||
@ApiSupport(author = "田立勇")
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/api/v1")
|
|
||||||
public class OperateLogController {
|
|
||||||
|
|
||||||
private final Logger logger = LoggerFactory.getLogger(OperateLogController.class);
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private OperateLogService operateLogService;
|
|
||||||
|
|
||||||
@RequestMapping(value = "/operateLog/create", method = RequestMethod.POST)
|
|
||||||
@ApiOperation(value = "操作日志创建")
|
|
||||||
public CommonResponse<Boolean> operateLogCreate(@RequestBody @Valid OperateLogReqDTO req) {
|
|
||||||
try {
|
|
||||||
return CommonResponse.success(operateLogService.insertOperaLog(req));
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.error("create operate log failed,", e);
|
|
||||||
return CommonResponse.fail(e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@RequestMapping(value = "/operateLog/queryForPage", method = RequestMethod.POST)
|
|
||||||
@ApiOperation(value = "操作日志查询")
|
|
||||||
public CommonResponse<CommonPageResponse<OperateLogQueryRespDTO>> operateLogsQuery(@RequestBody @Valid OperateLogQueryReqDTO req) {
|
|
||||||
try {
|
|
||||||
return CommonResponse.success(operateLogService.queryForPage(req));
|
|
||||||
} catch (ServiceException e) {
|
|
||||||
logger.error("query operate logs failed,", e);
|
|
||||||
return CommonResponse.fail(e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,22 +0,0 @@
|
|||||||
package cn.axzo.xlog.server.repository;
|
|
||||||
|
|
||||||
import cn.axzo.xlog.server.dto.OperateLogQueryReqDTO;
|
|
||||||
import cn.axzo.xlog.server.entity.OperateLogRecordEntity;
|
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
||||||
|
|
||||||
/***
|
|
||||||
* @author: pepsi
|
|
||||||
* @description: TODO
|
|
||||||
* @date: 2022/9/15
|
|
||||||
*/
|
|
||||||
public interface OperateLogRepository {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param user
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
OperateLogRecordEntity save(OperateLogRecordEntity user);
|
|
||||||
|
|
||||||
IPage<OperateLogRecordEntity> pageLogRecord(OperateLogQueryReqDTO req);
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,38 +0,0 @@
|
|||||||
package cn.axzo.xlog.server.service;
|
|
||||||
|
|
||||||
import cn.axzo.xlog.server.dto.OperateLogQueryReqDTO;
|
|
||||||
import cn.axzo.xlog.server.dto.OperateLogQueryRespDTO;
|
|
||||||
import cn.axzo.xlog.server.dto.OperateLogReqDTO;
|
|
||||||
import cn.axzo.xlog.server.entity.OperateLogRecordEntity;
|
|
||||||
import cn.azxo.framework.common.model.CommonPageResponse;
|
|
||||||
|
|
||||||
/***
|
|
||||||
* @author: pepsi
|
|
||||||
* @description: TODO
|
|
||||||
* @date: 2022/9/15
|
|
||||||
*/
|
|
||||||
public interface OperateLogService {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param operateLogReq
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
boolean insertOperaLog(OperateLogReqDTO operateLogReq) throws Exception;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 分页查询
|
|
||||||
*
|
|
||||||
* @param req
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
CommonPageResponse<OperateLogQueryRespDTO> queryForPage(OperateLogQueryReqDTO req);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* query from es
|
|
||||||
*
|
|
||||||
* @param req
|
|
||||||
* @return
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
CommonPageResponse<OperateLogQueryRespDTO> queryForPageFromEs(OperateLogQueryReqDTO req) throws Exception;
|
|
||||||
}
|
|
||||||
@ -1,261 +0,0 @@
|
|||||||
package cn.axzo.xlog.server.service.impl;
|
|
||||||
|
|
||||||
import cn.axzo.apollo.core.web.Result;
|
|
||||||
import cn.axzo.apollo.workspace.api.workspace.WorkspaceApi;
|
|
||||||
import cn.axzo.apollo.workspace.api.workspace.req.GetDetailReq;
|
|
||||||
import cn.axzo.apollo.workspace.api.workspace.res.GetDetailRes;
|
|
||||||
import cn.axzo.basics.organizational.api.OrganizationalUnitApi;
|
|
||||||
import cn.axzo.basics.organizational.api.vo.response.OrganizationalUnitVO;
|
|
||||||
import cn.axzo.basics.profiles.api.UserProfileServiceApi;
|
|
||||||
import cn.axzo.basics.profiles.dto.basic.IdentityProfileDto;
|
|
||||||
import cn.axzo.pudge.core.service.ServiceException;
|
|
||||||
import cn.axzo.xlog.server.dto.OperateLogQueryReqDTO;
|
|
||||||
import cn.axzo.xlog.server.dto.OperateLogQueryRespDTO;
|
|
||||||
import cn.axzo.xlog.server.dto.OperateLogReqDTO;
|
|
||||||
import cn.axzo.xlog.server.entity.OperateLogRecordEntity;
|
|
||||||
import cn.axzo.xlog.server.enums.IdentityType;
|
|
||||||
import cn.axzo.xlog.server.repository.OperateLogRepository;
|
|
||||||
import cn.axzo.xlog.server.service.BaseEsService;
|
|
||||||
import cn.axzo.xlog.server.service.OperateLogService;
|
|
||||||
import cn.axzo.xlog.server.service.converter.OperateLogConverter;
|
|
||||||
import cn.azxo.framework.common.model.CommonPageResponse;
|
|
||||||
import cn.azxo.framework.common.model.CommonResponse;
|
|
||||||
import cn.hutool.core.date.DateUtil;
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
||||||
import org.elasticsearch.action.search.SearchRequest;
|
|
||||||
import org.elasticsearch.action.search.SearchResponse;
|
|
||||||
import org.elasticsearch.index.query.*;
|
|
||||||
import org.elasticsearch.search.SearchHit;
|
|
||||||
import org.elasticsearch.search.SearchHits;
|
|
||||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
|
||||||
import org.elasticsearch.search.sort.SortOrder;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.util.StringUtils;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/***
|
|
||||||
* @author: pepsi
|
|
||||||
* @description: TODO
|
|
||||||
* @date: 2022/9/15
|
|
||||||
*/
|
|
||||||
@Service
|
|
||||||
public class OperateLogServiceImpl extends BaseEsService implements OperateLogService {
|
|
||||||
|
|
||||||
private final Logger logger = LoggerFactory.getLogger(OperateLogServiceImpl.class);
|
|
||||||
|
|
||||||
@Value("${xlog.elastic.index.name:xlog_operatelog_}")
|
|
||||||
private String indexNamePrex;
|
|
||||||
|
|
||||||
@Value("${xlog.es.storage:true}")
|
|
||||||
private boolean esStorageFlag;
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private OperateLogRepository operateLogRepository;
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private OrganizationalUnitApi organizationalUnitApi;
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private WorkspaceApi workspaceApi;
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private UserProfileServiceApi profileServiceApi;
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private OperateLogConverter operateLogConverter;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean insertOperaLog(OperateLogReqDTO operateLogReq) throws Exception {
|
|
||||||
//调用接口字段补全
|
|
||||||
OperateLogRecordEntity record = fieldFill(operateLogReq);
|
|
||||||
//落库
|
|
||||||
if (!esStorageFlag) {
|
|
||||||
operateLogRepository.save(record);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
//todo 落 ES,根据日期决定索引,目前索引规则还没定,暂定一个月一个。
|
|
||||||
String indexDate = DateUtil.format(operateLogReq.getOperateTime(), "YYYYMM");
|
|
||||||
String json = JSONObject.toJSONString(operateLogReq);
|
|
||||||
return insert(json, indexNamePrex + indexDate);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private OperateLogRecordEntity fieldFill(OperateLogReqDTO req) {
|
|
||||||
//补充 termimnal identityType featureName
|
|
||||||
OperateLogRecordEntity unifiedLogRecord = operateLogConverter.toEntity(req);
|
|
||||||
|
|
||||||
// 通过接口调用,获取用户手机姓名
|
|
||||||
IdentityProfileDto identityProfile = qryIdentityProfile(req.getIdentityId(), req.getIdentityType());
|
|
||||||
if (identityProfile != null && identityProfile.getPersonProfile() != null) {
|
|
||||||
unifiedLogRecord.setIdentityUserName(identityProfile.getPersonProfile().getRealName());
|
|
||||||
unifiedLogRecord.setIdentityUserPhone(identityProfile.getPersonProfile().getPhone());
|
|
||||||
}
|
|
||||||
// 通过接口方式调用 workspaceApi单位等信息,
|
|
||||||
GetDetailRes workspaceInf = qryWorkspaceInfo(req.getWorkspaceId());
|
|
||||||
unifiedLogRecord.setWorkspaceName(null != workspaceInf ? workspaceInf.getName() : null);
|
|
||||||
OrganizationalUnitVO ouInf = qryOrgUnitInf(req.getOuId());
|
|
||||||
unifiedLogRecord.setOuName(ouInf != null ? ouInf.getName() : null);
|
|
||||||
return unifiedLogRecord;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CommonPageResponse<OperateLogQueryRespDTO> queryForPage(OperateLogQueryReqDTO req) {
|
|
||||||
//todo 转 entity 对象
|
|
||||||
IPage<OperateLogRecordEntity> page = operateLogRepository.pageLogRecord(req);
|
|
||||||
//为空则返回空
|
|
||||||
List<OperateLogRecordEntity> recordList = page.getRecords();
|
|
||||||
if (recordList == null || recordList.isEmpty()) {
|
|
||||||
return CommonPageResponse.zero(req.getPage(), req.getPageSize());
|
|
||||||
}
|
|
||||||
List<OperateLogQueryRespDTO> respList = assembleOperateLogResp(recordList);
|
|
||||||
return CommonPageResponse.list(req.getPage(), req.getPageSize(), page.getTotal(), respList);
|
|
||||||
}
|
|
||||||
|
|
||||||
/***
|
|
||||||
* 从ES获取查询结果
|
|
||||||
* @param req
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public CommonPageResponse<OperateLogQueryRespDTO> queryForPageFromEs(OperateLogQueryReqDTO req) throws Exception {
|
|
||||||
//todo 根据时间段获取数据所在的索引s,目前索引规则还没定
|
|
||||||
String[] indices = new String[]{"xlog_operatelog_202209"};
|
|
||||||
//组装查询条件.
|
|
||||||
SearchSourceBuilder builder = assembleQueryBuilder(req);
|
|
||||||
SearchRequest request = new SearchRequest();
|
|
||||||
request.source(builder);
|
|
||||||
SearchResponse response = search(request, indices);
|
|
||||||
//处理查询结果的数据
|
|
||||||
SearchHits hits = response.getHits();
|
|
||||||
SearchHit[] searchHits = hits.getHits();
|
|
||||||
List<OperateLogRecordEntity> resList = new ArrayList<>(searchHits.length);
|
|
||||||
if (searchHits.length == 0) {
|
|
||||||
return CommonPageResponse.zero(req.getPage(), req.getPageSize());
|
|
||||||
}
|
|
||||||
for (SearchHit hit : searchHits) {
|
|
||||||
String oprLogStr = hit.getSourceAsString();
|
|
||||||
resList.add(JSONObject.parseObject(oprLogStr, OperateLogRecordEntity.class));
|
|
||||||
}
|
|
||||||
List<OperateLogQueryRespDTO> respList = assembleOperateLogResp(resList);
|
|
||||||
return CommonPageResponse.list(req.getPage(), req.getPageSize(), hits.getTotalHits().value, respList);
|
|
||||||
}
|
|
||||||
|
|
||||||
/***
|
|
||||||
* 组装ES查询条件
|
|
||||||
* @param req
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private SearchSourceBuilder assembleQueryBuilder(OperateLogQueryReqDTO req) {
|
|
||||||
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
|
|
||||||
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
|
|
||||||
if (StringUtils.hasText(req.getServiceName())) {
|
|
||||||
MatchQueryBuilder builder = QueryBuilders.matchQuery("serviceName", req.getServiceName());
|
|
||||||
boolQueryBuilder.filter(builder);
|
|
||||||
}
|
|
||||||
if (StringUtils.hasText(req.getOperateUserName())) {
|
|
||||||
MatchQueryBuilder builder = QueryBuilders.matchQuery("operateUserName", req.getServiceName());
|
|
||||||
boolQueryBuilder.filter(builder);
|
|
||||||
}
|
|
||||||
if (req.getWorkspaceId() != null && req.getWorkspaceId() > 0) {
|
|
||||||
TermQueryBuilder builder = QueryBuilders.termQuery("workspaceId", req.getServiceName());
|
|
||||||
boolQueryBuilder.filter(builder);
|
|
||||||
}
|
|
||||||
if (req.getOuId() != null && req.getOuId() > 0) {
|
|
||||||
TermQueryBuilder builder = QueryBuilders.termQuery("ouId", req.getServiceName());
|
|
||||||
boolQueryBuilder.filter(builder);
|
|
||||||
}
|
|
||||||
if (req.getIdentityId() != null && req.getIdentityId() > 0) {
|
|
||||||
TermQueryBuilder builder = QueryBuilders.termQuery("identityId", req.getServiceName());
|
|
||||||
boolQueryBuilder.filter(builder);
|
|
||||||
}
|
|
||||||
if (req.getIdentityType() != null) {
|
|
||||||
TermQueryBuilder builder = QueryBuilders.termQuery("identityType", req.getServiceName());
|
|
||||||
boolQueryBuilder.filter(builder);
|
|
||||||
}
|
|
||||||
if (req.getOperateType() != null) {
|
|
||||||
TermQueryBuilder builder = QueryBuilders.termQuery("operateType", req.getServiceName());
|
|
||||||
boolQueryBuilder.filter(builder);
|
|
||||||
}
|
|
||||||
if (StringUtils.hasText(req.getOperateTable())) {
|
|
||||||
TermQueryBuilder builder = QueryBuilders.termQuery("operateTable", req.getServiceName());
|
|
||||||
boolQueryBuilder.filter(builder);
|
|
||||||
}
|
|
||||||
//时间段
|
|
||||||
RangeQueryBuilder rangeQueryBuilder = QueryBuilders.rangeQuery("operateTime")
|
|
||||||
.gte(req.getStartTime().getTime())
|
|
||||||
.lte(req.getEndTime().getTime());
|
|
||||||
boolQueryBuilder.filter(rangeQueryBuilder);
|
|
||||||
searchSourceBuilder.sort("operateTime", SortOrder.DESC);
|
|
||||||
//todo 分页,先采用 from +size 模式,后续优化考虑scroll或者 after.
|
|
||||||
int offset = (req.getPage().intValue() - 1) * req.getPageSize().intValue();
|
|
||||||
searchSourceBuilder.from(offset).size(req.getPageSize().intValue());
|
|
||||||
searchSourceBuilder.query(boolQueryBuilder);
|
|
||||||
return searchSourceBuilder;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private List<OperateLogQueryRespDTO> assembleOperateLogResp(List<OperateLogRecordEntity> recordList) {
|
|
||||||
List<OperateLogQueryRespDTO> resList = new ArrayList<>();
|
|
||||||
recordList.forEach(item -> {
|
|
||||||
OperateLogQueryRespDTO resp = new OperateLogQueryRespDTO();
|
|
||||||
resp.setOperateUserName(item.getIdentityUserName());
|
|
||||||
resp.setFeatureCode(item.getFeatureCode());
|
|
||||||
resp.setFeatureName(item.getFeatureName());
|
|
||||||
resp.setContentSummary(item.getContentSummary());
|
|
||||||
resp.setOperateTime(item.getOperateTime());
|
|
||||||
resp.setOperateUserPhone(item.getIdentityUserPhone());
|
|
||||||
resp.setOuName(item.getOuName());
|
|
||||||
resList.add(resp);
|
|
||||||
});
|
|
||||||
return resList;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/***
|
|
||||||
* workspaceId 查询 WS 信息
|
|
||||||
* @param workspaceId
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private GetDetailRes qryWorkspaceInfo(Long workspaceId) {
|
|
||||||
GetDetailReq getDetailReq = new GetDetailReq();
|
|
||||||
getDetailReq.setId(workspaceId);
|
|
||||||
Result<GetDetailRes> res = workspaceApi.getDetail(getDetailReq);
|
|
||||||
if (res.getCode() != 200) {
|
|
||||||
throw new ServiceException(res.getMsg());
|
|
||||||
}
|
|
||||||
return res.getData();
|
|
||||||
}
|
|
||||||
|
|
||||||
/***
|
|
||||||
* 通过ouId查询 OrganizationalUnit 信息
|
|
||||||
* @param ouId
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private OrganizationalUnitVO qryOrgUnitInf(Long ouId) {
|
|
||||||
CommonResponse<OrganizationalUnitVO> response = organizationalUnitApi.getById(ouId);
|
|
||||||
if (response.getCode() != 200) {
|
|
||||||
throw new ServiceException(response.getMsg());
|
|
||||||
}
|
|
||||||
return response.getData();
|
|
||||||
}
|
|
||||||
|
|
||||||
private IdentityProfileDto qryIdentityProfile(Long identityId, Integer identityType) {
|
|
||||||
List<Long> ids = new ArrayList<>();
|
|
||||||
ids.add(identityId);
|
|
||||||
CommonResponse<List<IdentityProfileDto>> response = profileServiceApi.getIdentitiesByIdSet(ids, identityType);
|
|
||||||
if (response.getCode() != 200) {
|
|
||||||
throw new ServiceException(response.getMsg());
|
|
||||||
}
|
|
||||||
List<IdentityProfileDto> profileList = response.getData();
|
|
||||||
if (profileList.size() != 1) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return profileList.get(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,16 +0,0 @@
|
|||||||
package cn.axzo.xlog.server;
|
|
||||||
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
|
||||||
|
|
||||||
/***
|
|
||||||
* @author: pepsi
|
|
||||||
* @description: TODO
|
|
||||||
* @date: 2022/9/16
|
|
||||||
*/
|
|
||||||
@RunWith(SpringRunner.class)
|
|
||||||
@SpringBootTest
|
|
||||||
public class XlogApplicationTestBase {
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,61 +0,0 @@
|
|||||||
package cn.axzo.xlog.server.config;
|
|
||||||
|
|
||||||
import cn.axzo.xlog.server.entity.OperateLogRecordEntity;
|
|
||||||
import cn.axzo.xlog.server.service.BaseEsService;
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
|
||||||
import org.elasticsearch.client.RestHighLevelClient;
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/***
|
|
||||||
* @author: pepsi
|
|
||||||
* @description: TODO
|
|
||||||
* @date: 2022/9/19
|
|
||||||
*/
|
|
||||||
@RunWith(SpringRunner.class)
|
|
||||||
@SpringBootTest
|
|
||||||
public class ElasticClientConfigTest extends BaseEsService {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private RestHighLevelClient client;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testInsert() throws Exception {
|
|
||||||
OperateLogRecordEntity entity = new OperateLogRecordEntity();
|
|
||||||
entity.setLogGrade(1);
|
|
||||||
entity.setLogExt("test");
|
|
||||||
entity.setIdentityId(15L);
|
|
||||||
entity.setOperateAfter("test");
|
|
||||||
entity.setOperateParam("test");
|
|
||||||
entity.setFeatureCode("test");
|
|
||||||
entity.setOperateTable("test");
|
|
||||||
entity.setOperateType(1);
|
|
||||||
entity.setContentSummary("test");
|
|
||||||
entity.setOperateTime(new Date());
|
|
||||||
entity.setServiceName("test");
|
|
||||||
entity.setOuId(1L);
|
|
||||||
entity.setOperateUserIp("test");
|
|
||||||
entity.setWorkspaceId(1L);
|
|
||||||
entity.setResourceType(1);
|
|
||||||
entity.setIdentityType(3);
|
|
||||||
entity.setTerminal("test");
|
|
||||||
entity.setOperateBefore("test");
|
|
||||||
entity.setFeatureName("test");
|
|
||||||
entity.setResourceId(1L);
|
|
||||||
String data = JSONObject.toJSONString(entity);
|
|
||||||
String index = "xlog_operatelog_202209";
|
|
||||||
List<String> list = new ArrayList<>();
|
|
||||||
list.add(data);
|
|
||||||
boolean flag = this.bulkInsert(list, index);
|
|
||||||
Assert.assertTrue(flag);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user