Commit 9e292f2b authored by huyuchen's avatar huyuchen

Merge remote-tracking branch 'origin/fxj-dev' into fxj-dev

parents 10d6ec94 98a7360a
......@@ -107,6 +107,7 @@
<module>yifu-msg</module>
<module>yifu-permission</module>
<module>yifu-ekp</module>
<module>yifu-nginx-log</module>
</modules>
<dependencyManagement>
......
......@@ -73,6 +73,10 @@ public class DateUtil {
* yyyy-MM-dd hh:mm:ss
*/
public static final String DATETIME_PATTERN_MINUTE = "yyyy-MM-dd HH:mm";
/**
* yyyy-MM-dd-hh
*/
public static final String DATETIME_PATTERN_HOUR = "yyyyMMddHH";
/**
* yyyyMMddHHmmss
*/
......@@ -478,6 +482,20 @@ public class DateUtil {
return cal.getTime();
}
/**
* @param date
* @param mnt
* @return java.util.Date
*/
public static String dateIncreaseByHour(Date date, int mnt, String fmt) {
Calendar cal = GregorianCalendar.getInstance(TimeZone.getTimeZone("GMT"));
cal.setTime(date);
cal.add(Calendar.HOUR, mnt);
return dateToString(cal.getTime(), fmt);
}
/**
* @param date
* @param mnt
......
# 忽略匹配下列规则的Git 提交 V2.1.0
### gradle ###
.gradle
/build/
!gradle/wrapper/gradle-wrapper.jar
### STS ###
.settings/
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
bin/
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
*.lock
rebel.xml
### NetBeans ###
nbproject/private/
build/
nbbuild/
nbdist/
.nb-gradle/
### maven ###
target/
*.war
*.ear
*.zip
*.tar
*.tar.gz
### logs ####
/logs/
*.log
### temp ignore ###
*.cache
*.diff
*.patch
*.tmp
*.java~
*.properties~
*.xml~
### system ignore ###
.DS_Store
Thumbs.db
Servers
.metadata
upload
gen_code
### node ###
node_modules
<?xml version="1.0" encoding="UTF-8"?>
<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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.yifu.cloud.plus.v1</groupId>
<artifactId>yifu</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>yifu-nginx-log</artifactId>
<description>nginx-log-insert-mysql</description>
<packaging>pom</packaging>
<!--项目子模块-->
<modules>
<module>yifu-nginx-log-api</module>
<module>yifu-nginx-log-biz</module>
</modules>
</project>
<?xml version="1.0"?>
<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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.yifu.cloud.plus.v1</groupId>
<artifactId>yifu</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>yifu-nginx-log-api</artifactId>
<packaging>jar</packaging>
<description>nginx日志记录到数据库</description>
<dependencies>
<!-- core 工具类 -->
<dependency>
<groupId>com.yifu.cloud.plus.v1</groupId>
<artifactId>yifu-common-core</artifactId>
</dependency>
<!--swagger 注解-->
<!--<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-annotations</artifactId>
</dependency>-->
<!--feign 注解依赖-->
<!--<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-openfeign-core</artifactId>
<optional>true</optional>
</dependency>-->
<!--mybatis 依赖-->
<dependency>
<groupId>com.yifu.cloud.plus.v1</groupId>
<artifactId>yifu-common-mybatis</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
</dependencies>
</project>
package com.yifu.cloud.plus.v1.check.constant;
/**
* @Author fxj
* @Date 2022/6/21
* @Description
* @Version 1.0
*/
public interface ChecksConstants {
String NACOS_CHECK_CONFIG_ERROR="校验服务验证开关关闭!";
String CHECK_CONFIG_ACCESS="校验服务验证关闭,自动放行!";
String CODE="code";
String DATA="data";
String CODE_200000="200000";
String NO_DATA_RESULT="接口无返回数据";
String MESSAGE="message";
String MESSAGE_INFO = ",msg:";
String MOBILE="mobile";
String AREA="area";
String NUMBER_TYPE ="numberType";
String CHARGES_STATUS = "chargesStatus";
String STATUS="status";
String RESULT="result";
String REMARK="remark";
String APP_ID ="appId";
String APP_KEY="appKey";
String MOBILES="mobiles";
String NAME="name";
String ID_NUM="idNum";
String CARD_NO="cardNo";
}
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the yifu4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.yifu.cloud.plus.v1.nginx.entity;
import com.alibaba.excel.annotation.ExcelProperty;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.yifu.cloud.plus.v1.yifu.common.mybatis.base.BaseEntity;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.ExcelAttribute;
import org.hibernate.validator.constraints.Length;
import javax.validation.constraints.NotBlank;
/**
* @author fxj
* @date 2024-02-27 16:17:54
*/
@Data
@TableName("nginx_log")
@EqualsAndHashCode(callSuper = true)
@Schema(description = "")
public class NginxLog extends BaseEntity {
/**
* id
*/
@TableId(type = IdType.ASSIGN_ID)
@ExcelProperty("id")
@Schema(description = "id")
private String id;
/**
* 访问时间和时区
*/
@ExcelAttribute(name = "访问时间和时区", maxLength = 255)
@Length(max = 255, message = "访问时间和时区不能超过255个字符")
@ExcelProperty("访问时间和时区")
@Schema(description = "访问时间和时区")
private String timestamp;
/**
* 客户端的IP地址
*/
@ExcelAttribute(name = "客户端的IP地址", maxLength = 255)
@Length(max = 255, message = "客户端的IP地址不能超过255个字符")
@ExcelProperty("客户端的IP地址")
@Schema(description = "客户端的IP地址")
private String remoteAdr;
/**
* 记录请求的URL及请求方法
*/
@ExcelAttribute(name = "记录请求的URL及请求方法", maxLength = 255)
@Length(max = 255, message = "记录请求的URL及请求方法不能超过255个字符")
@ExcelProperty("记录请求的URL及请求方法")
@Schema(description = "记录请求的URL及请求方法")
private String request;
/**
* HTTP请求状态
*/
@ExcelAttribute(name = "HTTP请求状态", maxLength = 255)
@Length(max = 255, message = "HTTP请求状态不能超过255个字符")
@ExcelProperty("HTTP请求状态")
@Schema(description = "HTTP请求状态")
private String status;
/**
* 给客户端发送的文件主题内容字节数,响应头不计算在内
*/
@ExcelAttribute(name = "给客户端发送的文件主题内容字节数,响应头不计算在内", maxLength = 255)
@Length(max = 255, message = "给客户端发送的文件主题内容字节数,响应头不计算在内不能超过255个字符")
@ExcelProperty("给客户端发送的文件主题内容字节数,响应头不计算在内")
@Schema(description = "给客户端发送的文件主题内容字节数,响应头不计算在内")
private String bytes;
/**
* 用户所使用的代理
*/
@ExcelAttribute(name = "用户所使用的代理", maxLength = 255)
@Length(max = 255, message = "用户所使用的代理不能超过255个字符")
@ExcelProperty("用户所使用的代理")
@Schema(description = "用户所使用的代理")
private String agent;
/**
* 重定向URL
*/
@ExcelAttribute(name = "重定向URL", maxLength = 255)
@Length(max = 255, message = "重定向URL不能超过255个字符")
@ExcelProperty("重定向URL")
@Schema(description = "重定向URL")
private String forwarded;
/**
* 后台提供服务的地址(即转发处理的目标地址)
*/
@ExcelAttribute(name = "后台提供服务的地址(即转发处理的目标地址)", maxLength = 255)
@Length(max = 255, message = "后台提供服务的地址(即转发处理的目标地址)不能超过255个字符")
@ExcelProperty("后台提供服务的地址(即转发处理的目标地址)")
@Schema(description = "后台提供服务的地址(即转发处理的目标地址)")
private String upAddr;
/**
* 后台提供服务的地址(即转发处理的目标地址)
*/
@ExcelAttribute(name = "后台提供服务的地址(即转发处理的目标地址)", maxLength = 255)
@Length(max = 255, message = "后台提供服务的地址(即转发处理的目标地址)不能超过255个字符")
@ExcelProperty("后台提供服务的地址(即转发处理的目标地址)")
@Schema(description = "后台提供服务的地址(即转发处理的目标地址)")
private String upHost;
/**
* 从nginx向后端建立连接开始到接受完数据然后关闭连接为止的时间
*/
@ExcelAttribute(name = "从nginx向后端建立连接开始到接受完数据然后关闭连接为止的时间")
@ExcelProperty("从nginx向后端建立连接开始到接受完数据然后关闭连接为止的时间")
@Schema(description = "从nginx向后端建立连接开始到接受完数据然后关闭连接为止的时间")
private Double upRespTime;
/**
* 整个请求的总时间,从接收用户请求的第一个字节到发送完响应数据的时间,即包括接收请求数据时间,程序响应时间,输出响应数据时间
*/
@ExcelAttribute(name = "整个请求的总时间,从接收用户请求的第一个字节到发送完响应数据的时间,即包括接收请求数据时间,程序响应时间,输出响应数据时间")
@ExcelProperty("整个请求的总时间,从接收用户请求的第一个字节到发送完响应数据的时间,即包括接收请求数据时间,程序响应时间,输出响应数据时间")
@Schema(description = "整个请求的总时间,从接收用户请求的第一个字节到发送完响应数据的时间,即包括接收请求数据时间,程序响应时间,输出响应数据时间")
private Double requestTime;
/**
* 请求中的参数
*/
@ExcelAttribute(name = "请求中的参数", maxLength = 255)
@Length(max = 255, message = "请求中的参数不能超过255个字符")
@ExcelProperty("请求中的参数")
@Schema(description = "请求中的参数")
private String args;
}
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the yifu4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.yifu.cloud.plus.v1.nginx.vo;
import com.yifu.cloud.plus.v1.nginx.entity.NginxLog;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.time.LocalDateTime;
/**
* @author fxj
* @date 2024-02-27 16:17:54
*/
@Data
public class NginxLogSearchVo extends NginxLog {
/**
* 多选导出或删除等操作
*/
@Schema(description = "选中ID,多个逗号分割")
private String ids;
/**
* 创建时间区间 [开始时间,结束时间]
*/
@Schema(description = "创建时间区间")
private LocalDateTime[] createTimes;
/**
* @Author fxj
* 查询数据起
**/
@Schema(description = "查询limit 开始")
private int limitStart;
/**
* @Author fxj
* 查询数据止
**/
@Schema(description = "查询limit 数据条数")
private int limitEnd;
}
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the yifu4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.yifu.cloud.plus.v1.nginx.vo;
import com.alibaba.excel.annotation.ExcelProperty;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.yifu.cloud.plus.v1.yifu.common.core.vo.RowIndex;
import com.yifu.cloud.plus.v1.yifu.common.mybatis.base.BaseEntity;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.ExcelAttribute;
import org.hibernate.validator.constraints.Length;
import javax.validation.constraints.NotBlank;
import java.io.Serializable;
/**
* @author fxj
* @date 2024-02-27 16:17:54
*/
@Data
public class NginxLogVo extends RowIndex implements Serializable {
/**
* id
*/
@TableId(type = IdType.ASSIGN_ID)
@NotBlank(message = "id 不能为空")
@Length(max = 255, message = "id 不能超过255 个字符")
@ExcelAttribute(name = "id", isNotEmpty = true, errorInfo = "id 不能为空", maxLength = 255)
@Schema(description = "id")
@ExcelProperty("id")
private String id;
/**
* 访问时间和时区
*/
@Length(max = 255, message = "访问时间和时区 不能超过255 个字符")
@ExcelAttribute(name = "访问时间和时区", maxLength = 255)
@Schema(description = "访问时间和时区")
@ExcelProperty("访问时间和时区")
private String timestamp;
/**
* 客户端的IP地址
*/
@Length(max = 255, message = "客户端的IP地址 不能超过255 个字符")
@ExcelAttribute(name = "客户端的IP地址", maxLength = 255)
@Schema(description = "客户端的IP地址")
@ExcelProperty("客户端的IP地址")
private String remoteAdr;
/**
* 记录请求的URL及请求方法
*/
@Length(max = 255, message = "记录请求的URL及请求方法 不能超过255 个字符")
@ExcelAttribute(name = "记录请求的URL及请求方法", maxLength = 255)
@Schema(description = "记录请求的URL及请求方法")
@ExcelProperty("记录请求的URL及请求方法")
private String request;
/**
* HTTP请求状态
*/
@Length(max = 255, message = "HTTP请求状态 不能超过255 个字符")
@ExcelAttribute(name = "HTTP请求状态", maxLength = 255)
@Schema(description = "HTTP请求状态")
@ExcelProperty("HTTP请求状态")
private String status;
/**
* 给客户端发送的文件主题内容字节数,响应头不计算在内
*/
@Length(max = 255, message = "给客户端发送的文件主题内容字节数,响应头不计算在内 不能超过255 个字符")
@ExcelAttribute(name = "给客户端发送的文件主题内容字节数,响应头不计算在内", maxLength = 255)
@Schema(description = "给客户端发送的文件主题内容字节数,响应头不计算在内")
@ExcelProperty("给客户端发送的文件主题内容字节数,响应头不计算在内")
private String bytes;
/**
* 用户所使用的代理
*/
@Length(max = 255, message = "用户所使用的代理 不能超过255 个字符")
@ExcelAttribute(name = "用户所使用的代理", maxLength = 255)
@Schema(description = "用户所使用的代理")
@ExcelProperty("用户所使用的代理")
private String agent;
/**
* 重定向URL
*/
@Length(max = 255, message = "重定向URL 不能超过255 个字符")
@ExcelAttribute(name = "重定向URL", maxLength = 255)
@Schema(description = "重定向URL")
@ExcelProperty("重定向URL")
private String forwarded;
/**
* 后台提供服务的地址(即转发处理的目标地址)
*/
@Length(max = 255, message = "后台提供服务的地址(即转发处理的目标地址) 不能超过255 个字符")
@ExcelAttribute(name = "后台提供服务的地址(即转发处理的目标地址)", maxLength = 255)
@Schema(description = "后台提供服务的地址(即转发处理的目标地址)")
@ExcelProperty("后台提供服务的地址(即转发处理的目标地址)")
private String upAddr;
/**
* 后台提供服务的地址(即转发处理的目标地址)
*/
@Length(max = 255, message = "后台提供服务的地址(即转发处理的目标地址) 不能超过255 个字符")
@ExcelAttribute(name = "后台提供服务的地址(即转发处理的目标地址)", maxLength = 255)
@Schema(description = "后台提供服务的地址(即转发处理的目标地址)")
@ExcelProperty("后台提供服务的地址(即转发处理的目标地址)")
private String upHost;
/**
* 从nginx向后端建立连接开始到接受完数据然后关闭连接为止的时间
*/
@ExcelAttribute(name = "从nginx向后端建立连接开始到接受完数据然后关闭连接为止的时间")
@Schema(description = "从nginx向后端建立连接开始到接受完数据然后关闭连接为止的时间")
@ExcelProperty("从nginx向后端建立连接开始到接受完数据然后关闭连接为止的时间")
private Long upRespTime;
/**
* 整个请求的总时间,从接收用户请求的第一个字节到发送完响应数据的时间,即包括接收请求数据时间,程序响应时间,输出响应数据时间
*/
@ExcelAttribute(name = "整个请求的总时间,从接收用户请求的第一个字节到发送完响应数据的时间,即包括接收请求数据时间,程序响应时间,输出响应数据时间")
@Schema(description = "整个请求的总时间,从接收用户请求的第一个字节到发送完响应数据的时间,即包括接收请求数据时间,程序响应时间,输出响应数据时间")
@ExcelProperty("整个请求的总时间,从接收用户请求的第一个字节到发送完响应数据的时间,即包括接收请求数据时间,程序响应时间,输出响应数据时间")
private Long requestTime;
/**
* 请求中的参数
*/
@Length(max = 255, message = "请求中的参数 不能超过255 个字符")
@ExcelAttribute(name = "请求中的参数", maxLength = 255)
@Schema(description = "请求中的参数")
@ExcelProperty("请求中的参数")
private String args;
}
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.yifu.cloud.plus.v1.job.config.SchedulerBeanFactoryConfig
\ No newline at end of file
FROM moxm/java:1.8-full
RUN mkdir -p /yifu-nginx-log-biz
WORKDIR yifu-nginx-log-biz
ARG JAR_FILE=target/yifu-nginx-log-biz.jar
COPY ${JAR_FILE} app.jar
EXPOSE 5066
ENV TZ=Asia/Shanghai JAVA_OPTS="-Xms128m -Xmx256m -Djava.security.egd=file:/dev/./urandom"
CMD sleep 60; java -jar app.jar $JAVA_OPTS
#!/usr/bin/env bash
mvn clean package -Pprd -Dmaven.test.skip=true docker:build -DpushImage
\ No newline at end of file
#!/usr/bin/env bash
mvn clean package -Ptest -Dmaven.test.skip=true docker:build -DpushImage
\ No newline at end of file
#!/usr/bin/env bash
mvn clean package -Dmaven.test.skip=true docker:build -DpushImage
\ No newline at end of file
<?xml version="1.0"?>
<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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.yifu.cloud.plus.v1</groupId>
<artifactId>yifu</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>yifu-nginx-log-biz</artifactId>
<packaging>jar</packaging>
<description>nginx log 日志记录到数据库</description>
<dependencies>
<!--选配: 依赖seata模块-->
<dependency>
<groupId>com.yifu.cloud.plus.v1</groupId>
<artifactId>yifu-common-seata</artifactId>
</dependency>
<!--必备: 依赖api模块-->
<dependency>
<groupId>com.yifu.cloud.plus.v1</groupId>
<artifactId>yifu-nginx-log-api</artifactId>
<version>1.0.0</version>
</dependency>
<!--选配: orm 模块-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!--必备:安全模块-->
<dependency>
<groupId>com.yifu.cloud.plus.v1</groupId>
<artifactId>yifu-common-security</artifactId>
</dependency>
<!--必备:日志处理-->
<dependency>
<groupId>com.yifu.cloud.plus.v1</groupId>
<artifactId>yifu-common-log</artifactId>
</dependency>
<!--必备:swagger-->
<dependency>
<groupId>com.yifu.cloud.plus.v1</groupId>
<artifactId>yifu-common-swagger</artifactId>
</dependency>
<!--必备:undertow容器-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>1.1.0</version>
<configuration>
<serverId>docker-hub</serverId>
<!--指定生成的镜像名-->
<imageName>${my.hub.host}/${map.group.name}/${project.artifactId}:${project.version}</imageName>
<dockerDirectory>${project.basedir}/</dockerDirectory>
<!--指定远程 docker api地址-->
<!--<dockerHost>http://172.16.66.232:2375</dockerHost>-->
<!-- 这里是复制 jar 包到 docker 容器指定目录配置-->
<resources>
<resource>
<targetPath>/</targetPath>
<!--jar 包所在的路径 此处配置的 即对应 target 目录-->
<directory>${project.build.directory}</directory>
<!-- 需要包含的 jar包 ,这里对应的是 Dockerfile中添加的文件名 -->
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
<forceTags>true</forceTags>
</configuration>
</plugin>
</plugins>
</build>
</project>
package com.yifu.cloud.plus.v1.nginx;
import com.yifu.cloud.plus.v1.yifu.common.security.annotation.EnableYifuResourceServer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* @author pig archetype
* <p>
* 项目启动类
*/
@EnableYifuResourceServer
@SpringBootApplication
public class NginxLogApplication {
public static void main(String[] args) {
SpringApplication.run(NginxLogApplication.class, args);
}
}
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the yifu4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.yifu.cloud.plus.v1.nginx.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yifu.cloud.plus.v1.nginx.entity.NginxLog;
import com.yifu.cloud.plus.v1.nginx.service.NginxLogService;
import com.yifu.cloud.plus.v1.nginx.service.impl.NginxLogServiceImpl;
import com.yifu.cloud.plus.v1.nginx.vo.NginxLogSearchVo;
import com.yifu.cloud.plus.v1.yifu.common.core.util.ErrorMessage;
import com.yifu.cloud.plus.v1.yifu.common.core.util.R;
import com.yifu.cloud.plus.v1.yifu.common.log.annotation.SysLog;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
*
*
* @author fxj
* @date 2024-02-27 16:17:54
*/
@RestController
@RequiredArgsConstructor
@RequestMapping("/nginxlog" )
@Tag(name = "管理")
public class NginxLogController {
private final NginxLogService nginxLogService;
/**
* 简单分页查询
* @param page 分页对象
* @param nginxLog
* @return
*/
@Operation(description = "简单分页查询")
@GetMapping("/page")
public R<IPage<NginxLog>> getNginxLogPage(Page<NginxLog> page, NginxLogSearchVo nginxLog) {
return new R<>(nginxLogService.getNginxLogPage(page,nginxLog));
}
/**
* 不分页查询
* @param nginxLog
* @return
*/
@Operation(summary = "不分页查询", description = "不分页查询")
@PostMapping("/noPage" )
//@PreAuthorize("@pms.hasPermission('demo_nginxlog_get')" )
public R<List<NginxLog>> getNginxLogNoPage(@RequestBody NginxLogSearchVo nginxLog) {
return R.ok(nginxLogService.noPageDiy(nginxLog));
}
/**
* 通过id查询
* @param id id
* @return R
*/
@Operation(summary = "通过id查询", description = "通过id查询:hasPermission('demo_nginxlog_get')")
@GetMapping("/{id}" )
@PreAuthorize("@pms.hasPermission('demo_nginxlog_get')" )
public R<NginxLog> getById(@PathVariable("id" ) String id) {
return R.ok(nginxLogService.getById(id));
}
/**
* 新增
* @param nginxLog
* @return R
*/
@Operation(summary = "新增", description = "新增:hasPermission('demo_nginxlog_add')")
@SysLog("新增" )
@PostMapping
@PreAuthorize("@pms.hasPermission('demo_nginxlog_add')" )
public R<Boolean> save(@RequestBody NginxLog nginxLog) {
return R.ok(nginxLogService.save(nginxLog));
}
/**
* 修改
* @param nginxLog
* @return R
*/
@Operation(summary = "修改", description = "修改:hasPermission('demo_nginxlog_edit')")
@SysLog("修改" )
@PutMapping
@PreAuthorize("@pms.hasPermission('demo_nginxlog_edit')" )
public R<Boolean> updateById(@RequestBody NginxLog nginxLog) {
return R.ok(nginxLogService.updateById(nginxLog));
}
/**
* 通过id删除
* @param id id
* @return R
*/
@Operation(summary = "通过id删除", description = "通过id删除:hasPermission('demo_nginxlog_del')")
@SysLog("通过id删除" )
@DeleteMapping("/{id}" )
@PreAuthorize("@pms.hasPermission('demo_nginxlog_del')" )
public R<Boolean> removeById(@PathVariable String id) {
return R.ok(nginxLogService.removeById(id));
}
/**
* 批量导入
*
* @author fxj
* @date 2024-02-27 16:17:54
**/
@SneakyThrows
@Operation(description = "批量新增 hasPermission('demo_nginxlog-batch-import')")
@SysLog("批量新增")
@PostMapping("/importListAdd")
@PreAuthorize("@pms.hasPermission('demo_nginxlog-batch-import')")
public R<List<ErrorMessage>> importListAdd(@RequestBody MultipartFile file){
return nginxLogService.importDiy(file.getInputStream());
}
/**
* 批量导出
* @author fxj
* @date 2024-02-27 16:17:54
**/
@Operation(description = "导出 hasPermission('demo_nginxlog-export')")
@PostMapping("/export")
@PreAuthorize("@pms.hasPermission('demo_nginxlog-export')")
public void export(HttpServletResponse response, @RequestBody NginxLogSearchVo searchVo) {
nginxLogService.listExport(response,searchVo);
}
}
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the yifu4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.yifu.cloud.plus.v1.nginx.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yifu.cloud.plus.v1.nginx.entity.NginxLog;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
/**
*
*
* @author fxj
* @date 2024-02-27 16:17:54
*/
@Mapper
public interface NginxLogMapper extends BaseMapper<NginxLog> {
/**
* 简单分页查询
* @param nginxLog
* @return
*/
IPage<NginxLog> getNginxLogPage(Page<NginxLog> page, @Param("nginxLog") NginxLog nginxLog);
}
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the yifu4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.yifu.cloud.plus.v1.nginx.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.yifu.cloud.plus.v1.nginx.entity.NginxLog;
import com.yifu.cloud.plus.v1.nginx.vo.NginxLogSearchVo;
import com.yifu.cloud.plus.v1.yifu.common.core.util.ErrorMessage;
import com.yifu.cloud.plus.v1.yifu.common.core.util.R;
import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
import java.util.List;
/**
*
*
* @author fxj
* @date 2024-02-27 16:17:54
*/
public interface NginxLogService extends IService<NginxLog> {
/**
* 简单分页查询
* @param nginxLog
* @return
*/
IPage<NginxLog> getNginxLogPage(Page<NginxLog> page, NginxLogSearchVo nginxLog);
R<List<ErrorMessage>> importDiy(InputStream inputStream);
void listExport(HttpServletResponse response, NginxLogSearchVo searchVo);
List<NginxLog> noPageDiy(NginxLogSearchVo searchVo);
void readAndWriteLogAsys();
void readAndWriteLog();
}
package com.yifu.cloud.plus.v1.nginx.util;
import com.yifu.cloud.plus.v1.nginx.service.NginxLogService;
import com.yifu.cloud.plus.v1.yifu.common.core.util.DateUtil;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
/**
* @Author fxj
* @Date 2024/2/27
* @Description
* @Version 1.0
*/
@Log4j2
@Component
public class NginxLogCommandLineRunner implements CommandLineRunner {
@Autowired
NginxLogService nginxLogService;
@Override
public void run(String... args) throws Exception {
nginxLogService.readAndWriteLogAsys();
}
}
# 数据源配置
spring:
mvc:
pathmatch:
matching-strategy: ant_path_matcher
config:
activate:
on-profile: dev
redis:
host: 127.0.0.1
password: '@yf_2017'
datasource:
type: com.zaxxer.hikari.HikariDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
username: root
password: yf_zsk
url: jdbc:mysql://192.168.1.122:33306/yifu_nginx_log?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true
## spring security 配置
security:
oauth2:
resource:
loadBalanced: true
token-info-uri: http://127.0.0.1:3000/oauth/check_token
# 直接放行URL
ignore:
urls:
- /v3/api-docs
- /actuator/**
- /swagger-ui/**
- /checkBankNo/**
# 创蓝云智校验配置
canCheck: true
\ No newline at end of file
# 数据源配置
spring:
mvc:
pathmatch:
matching-strategy: ant_path_matcher
config:
activate:
on-profile: prd
redis:
host: 192.168.0.153
password: '@yf_2022'
port: 22379
datasource:
type: com.zaxxer.hikari.HikariDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
username: root
password: yf_zsk
url: jdbc:mysql://192.168.0.222:22306/yifu_checks?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true
## spring security 配置
security:
oauth2:
resource:
loadBalanced: true
token-info-uri: http://127.0.0.1:3000/oauth/check_token
# 直接放行URL
ignore:
urls:
- /v3/api-docs
- /actuator/**
- /swagger-ui/**
- /checkBankNo/**
# 创蓝云智校验配置
canCheck: true
\ No newline at end of file
# 数据源配置
spring:
mvc:
pathmatch:
matching-strategy: ant_path_matcher
config:
activate:
on-profile: test
redis:
host: 192.168.1.65
port: 22379
password: '@yf_2017'
datasource:
type: com.zaxxer.hikari.HikariDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
username: root
password: ll_mysql
url: jdbc:mysql://192.168.1.122:33306/yifu_nginx_log?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true
hikari:
driver-class-name: ${spring.datasource.driver-class-name}
jdbc-url: ${spring.datasource.url}
username: ${spring.datasource.username}
password: ${spring.datasource.password}
pool-name: AmytangHikariCP
connection-timeout: 600000 #最大超时时间
minimum-idle: 10 # 最小空闲连接数量
validation-timeout: 3000 #此属性控制测试连接是否活跃的最长时间。此值必须小于 connectionTimeout
idle-timeout: 60000 # 空闲连接存活最大时间,默认600000(10分钟)此属性控制允许连接在池中处于空闲状态的最长时间
maximum-pool-size: 20 # 连接池最大连接数,默认是10
auto-commit: true #此属性控制从池返回的连接的默认自动提交行为,默认值:true
max-lifetime: 1800000 #此属性控制池中连接的最长生命周期,值0表示无限生命周期,默认1800000即30分钟
## spring security 配置
security:
oauth2:
resource:
loadBalanced: true
token-info-uri: http://127.0.0.1:3000/oauth/check_token
# 直接放行URL
ignore:
urls:
- /v3/api-docs
- /actuator/**
- /swagger-ui/**
\ No newline at end of file
server:
port: 5066
# 加解密根密码
jasypt:
encryptor:
password: yifu #根密码
# 暴露监控端点
management:
endpoints:
web:
exposure:
include: "*"
endpoint:
health:
show-details: ALWAYS
# mybaits-plus配置
mybatis-plus:
mapper-locations: classpath:/mapper/*Mapper.xml
global-config:
banner: false
db-config:
id-type: auto
table-underline: true
logic-delete-value: 1
logic-not-delete-value: 0
configuration:
map-underscore-to-camel-case: true
spring:
application:
name: @artifactId@
#swagger 文档 https://springdoc.org/
### OpenAPI3 注解
# OpenAPI 3 注解位置
# @Tag(name = “接口类描述”) Controller 类上
# @Operation(summary =“接口方法描述”) Controller 方法上
# @Parameters Controller 方法上
# @Parameter(description=“参数描述”) Controller 方法上 @Parameters 里
# @Parameter(description=“参数描述”) Controller 方法的参数上
# @Parameter(hidden = true) 或 @Hidden --
# @Schema DTO类上
# @Schema DTO属性上
springdoc:
api-docs:
#是否开启文档功能
enabled: true
#swagger后端请求地址
path: /api-docs
swagger-ui:
#自定义swagger前端请求路径,输入http:127.0.0.1:8080/test会自动重定向到swagger页面
path: /api
#包扫描路径
packages-to-scan: com.yifu.cloud.plus.v1.nginx.controller
#这里定义了两个分组,可定义多个,也可以不定义
group-configs:
#分组名
#- group: admin
#按路径匹配
# pathsToMatch: /admin/**
#分组名
- group: nginx-log
#按包路径匹配
packagesToScan: com.yifu.cloud.plus.v1.nginx.controller
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="false" scan="false">
<springProperty scop="context" name="spring.application.name" source="spring.application.name" defaultValue=""/>
<property name="log.path" value="logs/${spring.application.name}"/>
<!-- 彩色日志格式 -->
<property name="CONSOLE_LOG_PATTERN"
value="${CONSOLE_LOG_PATTERN:-%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/>
<!-- 彩色日志依赖的渲染类 -->
<conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter"/>
<conversionRule conversionWord="wex"
converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter"/>
<conversionRule conversionWord="wEx"
converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter"/>
<!-- Console log output -->
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
</encoder>
</appender>
<!-- Log file debug output -->
<appender name="debug" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.path}/debug.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${log.path}/%d{yyyy-MM, aux}/debug.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
<maxFileSize>50MB</maxFileSize>
<maxHistory>30</maxHistory>
</rollingPolicy>
<encoder>
<pattern>%date [%thread] %-5level [%logger{50}] %file:%line - %msg%n</pattern>
</encoder>
</appender>
<!-- Log file error output -->
<appender name="error" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.path}/error.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${log.path}/%d{yyyy-MM}/error.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
<maxFileSize>50MB</maxFileSize>
<maxHistory>30</maxHistory>
</rollingPolicy>
<encoder>
<pattern>%date [%thread] %-5level [%logger{50}] %file:%line - %msg%n</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>ERROR</level>
</filter>
</appender>
<!--nacos 心跳 INFO 屏蔽-->
<logger name="com.alibaba.nacos" level="OFF">
<appender-ref ref="error"/>
</logger>
<!-- Level: FATAL 0 ERROR 3 WARN 4 INFO 6 DEBUG 7 -->
<root level="INFO">
<appender-ref ref="console"/>
<appender-ref ref="debug"/>
<appender-ref ref="error"/>
</root>
</configuration>
<?xml version="1.0" encoding="UTF-8"?>
<!--
~
~ Copyright (c) 2018-2025, lengleng All rights reserved.
~
~ Redistribution and use in source and binary forms, with or without
~ modification, are permitted provided that the following conditions are met:
~
~ Redistributions of source code must retain the above copyright notice,
~ this list of conditions and the following disclaimer.
~ Redistributions in binary form must reproduce the above copyright
~ notice, this list of conditions and the following disclaimer in the
~ documentation and/or other materials provided with the distribution.
~ Neither the name of the yifu4cloud.com developer nor the names of its
~ contributors may be used to endorse or promote products derived from
~ this software without specific prior written permission.
~ Author: lengleng (wangiegie@gmail.com)
~
-->
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yifu.cloud.plus.v1.nginx.mapper.NginxLogMapper">
<resultMap id="nginxLogMap" type="com.yifu.cloud.plus.v1.nginx.entity.NginxLog">
<id property="id" column="id"/>
<result property="timestamp" column="timestamp"/>
<result property="remoteAdr" column="remote_adr"/>
<result property="request" column="request"/>
<result property="status" column="status"/>
<result property="bytes" column="bytes"/>
<result property="agent" column="agent"/>
<result property="forwarded" column="forwarded"/>
<result property="upAddr" column="up_addr"/>
<result property="upHost" column="up_host"/>
<result property="upRespTime" column="up_resp_time"/>
<result property="requestTime" column="request_time"/>
<result property="args" column="args"/>
</resultMap>
<sql id="Base_Column_List">
a.id,
a.timestamp,
a.remote_adr,
a.request,
a.status,
a.bytes,
a.agent,
a.forwarded,
a.up_addr,
a.up_host,
a.up_resp_time,
a.request_time,
a.args
</sql>
<sql id="nginxLog_where">
<if test="nginxLog != null">
<if test="nginxLog.id != null and nginxLog.id.trim() != ''">
AND a.id = #{nginxLog.id}
</if>
<if test="nginxLog.timestamp != null and nginxLog.timestamp.trim() != ''">
AND a.timestamp = #{nginxLog.timestamp}
</if>
<if test="nginxLog.remoteAdr != null and nginxLog.remoteAdr.trim() != ''">
AND a.remote_adr = #{nginxLog.remoteAdr}
</if>
<if test="nginxLog.request != null and nginxLog.request.trim() != ''">
AND a.request = #{nginxLog.request}
</if>
<if test="nginxLog.status != null and nginxLog.status.trim() != ''">
AND a.status = #{nginxLog.status}
</if>
<if test="nginxLog.bytes != null and nginxLog.bytes.trim() != ''">
AND a.bytes = #{nginxLog.bytes}
</if>
<if test="nginxLog.agent != null and nginxLog.agent.trim() != ''">
AND a.agent = #{nginxLog.agent}
</if>
<if test="nginxLog.forwarded != null and nginxLog.forwarded.trim() != ''">
AND a.forwarded = #{nginxLog.forwarded}
</if>
<if test="nginxLog.upAddr != null and nginxLog.upAddr.trim() != ''">
AND a.up_addr = #{nginxLog.upAddr}
</if>
<if test="nginxLog.upHost != null and nginxLog.upHost.trim() != ''">
AND a.up_host = #{nginxLog.upHost}
</if>
<if test="nginxLog.upRespTime != null">
AND a.up_resp_time = #{nginxLog.upRespTime}
</if>
<if test="nginxLog.requestTime != null">
AND a.request_time = #{nginxLog.requestTime}
</if>
<if test="nginxLog.args != null and nginxLog.args.trim() != ''">
AND a.args = #{nginxLog.args}
</if>
</if>
</sql>
<!--nginxLog简单分页查询-->
<select id="getNginxLogPage" resultMap="nginxLogMap">
SELECT
<include refid="Base_Column_List"/>
FROM nginx_log a
<where>
1=1
<include refid="nginxLog_where"/>
</where>
</select>
</mapper>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment