Commit 07a4621d by xmh

基本组件构建完成,任务报表完成

1 parent 5d613068
HELP.md
target/
.mvn/
logs/
### STS ###
.apt_generated
.classpath
......
......@@ -13,7 +13,7 @@
<version>0.0.1-SNAPSHOT</version>
<name>report</name>
<description>fx_reoprt_serv</description>
<packaging>war</packaging>
<properties>
<java.version>1.8</java.version>
</properties>
......@@ -27,7 +27,24 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.4.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
......@@ -52,6 +69,7 @@
</dependencies>
<build>
<finalName>fx_report_serv</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
......
package com.viontech.report;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
@Slf4j
public class ReportApplication {
public static void main(String[] args) {
SpringApplication.run(ReportApplication.class, args);
try {
SpringApplication.run(ReportApplication.class, args);
} catch (Exception e) {
log.error("Spring Start Error ", e);
}
}
}
package com.viontech.report.configuration;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import javax.sql.DataSource;
/**
* .
*
* @author 谢明辉
* @date 2020/9/17
*/
@Configuration
@ConfigurationProperties(prefix = "vion.datasource")
@Getter
@Setter
@SuppressWarnings("ALL")
public class JDBCConfiguration {
private String preUrl;
private String username;
private String password;
private String driverClassName;
@Bean(value = "taskDataSource")
public DataSource taskDataSource() {
HikariConfig hikariConfig = new HikariConfig();
hikariConfig.setJdbcUrl(preUrl + "devconf_fx");
hikariConfig.setDriverClassName(driverClassName);
hikariConfig.setUsername(username);
hikariConfig.setPassword(password);
return new HikariDataSource(hikariConfig);
}
@Bean(name = "taskJdbcTemplate")
@ConditionalOnBean(name = "taskDataSource")
public JdbcTemplate taskJdbctemplate(DataSource taskDataSource) {
return new JdbcTemplate(taskDataSource);
}
@Bean(name = "taskNamedParameterJdbcTemplate")
@ConditionalOnBean(name = "taskDataSource")
public NamedParameterJdbcTemplate taskNamedParameterJdbcTemplate(DataSource taskDataSource) {
return new NamedParameterJdbcTemplate(taskDataSource);
}
@Bean(value = "trafficDataSource")
public DataSource trafficDataSource() {
HikariConfig hikariConfig = new HikariConfig();
hikariConfig.setJdbcUrl(preUrl + "traffic");
hikariConfig.setDriverClassName(driverClassName);
hikariConfig.setUsername(username);
hikariConfig.setPassword(password);
return new HikariDataSource(hikariConfig);
}
@Bean(name = "trafficJdbcTemplate")
@ConditionalOnBean(name = "trafficDataSource")
public JdbcTemplate trafficJdbctemplate(DataSource trafficDataSource) {
return new JdbcTemplate(trafficDataSource);
}
@Bean(name = "trafficNamedParameterJdbcTemplate")
@ConditionalOnBean(name = "trafficDataSource")
public NamedParameterJdbcTemplate trafficNamedParameterJdbcTemplate(DataSource trafficDataSource) {
return new NamedParameterJdbcTemplate(trafficDataSource);
}
@Bean(value = "behaviorDataSource")
public DataSource behaviorDataSource() {
HikariConfig hikariConfig = new HikariConfig();
hikariConfig.setJdbcUrl(preUrl + "behavior");
hikariConfig.setDriverClassName(driverClassName);
hikariConfig.setUsername(username);
hikariConfig.setPassword(password);
return new HikariDataSource(hikariConfig);
}
@Bean(name = "behaviorJdbcTemplate")
@ConditionalOnBean(name = "behaviorDataSource")
public JdbcTemplate behaviorJdbctemplate(DataSource behaviorDataSource) {
return new JdbcTemplate(behaviorDataSource);
}
@Bean(name = "behaviorNamedParameterJdbcTemplate")
@ConditionalOnBean(name = "behaviorDataSource")
public NamedParameterJdbcTemplate behaviorNamedParameterJdbcTemplate(DataSource behaviorDataSource) {
return new NamedParameterJdbcTemplate(behaviorDataSource);
}
}
package com.viontech.report.configuration;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
*
* @author vion
*
*/
@Configuration
public class WebConfiguration implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("*")
.allowCredentials(true)
.allowedMethods("GET", "POST", "DELETE", "PUT", "OPTION")
.maxAge(3600);
}
}
package com.viontech.report.controller;
import com.viontech.report.entity.QueryParam;
import com.viontech.report.entity.Result;
import com.viontech.report.entity.Task;
import com.viontech.report.service.TaskService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Collection;
import java.util.List;
/**
* .
*
* @author 谢明辉
* @date 2020/9/15
*/
@RestController
@RequestMapping("/task")
@Slf4j
public class TaskController {
@Autowired
private TaskService taskService;
@GetMapping("/statistics")
public Result statistics(QueryParam param) {
try {
Collection<Task> statistics = taskService.getStatistics(param);
return Result.success(statistics);
} catch (Exception e) {
log.error("", e);
}
return Result.error();
}
}
package com.viontech.report.convert;
import cn.hutool.core.date.DateUtil;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;
import java.util.Date;
/**
* .
*
* @author 谢明辉
* @date 2020/9/15
*/
@Component
public class DateConvert implements Converter<String, Date> {
@Override
public Date convert(String s) {
return DateUtil.parse(s);
}
}
package com.viontech.report.entity;
import lombok.Getter;
import lombok.Setter;
/**
* .
*
* @author 谢明辉
* @date 2020/9/22
*/
@Getter
@Setter
public class Behavior {
private String taskId;
private String subtaskId;
}
package com.viontech.report.entity;
import lombok.Getter;
import lombok.Setter;
import java.util.Collection;
import java.util.Date;
import java.util.List;
/**
* .
*
* @author 谢明辉
* @date 2020/9/15
*/
@SuppressWarnings("ALL")
@Getter
@Setter
public class QueryParam {
private Date start_dt;
private Date end_dt;
private String task_id;
private String subtask_id;
private String type;
private Collection<String> taskIds;
}
package com.viontech.report.entity;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
/**
* .
*
* @author 谢明辉
* @date 2020/9/15
*/
@SuppressWarnings("ALL")
@Getter
@Setter
@Accessors(chain = true)
public class Result {
private Integer ecode;
private String msg;
@JsonProperty(value = "list_data")
private Object listData;
public Result() {
}
public Result(Integer ecode, String msg, Object listData) {
this.ecode = ecode;
this.msg = msg;
this.listData = listData;
}
public static Result success(String msg, Object listData) {
return new Result(200, msg, listData);
}
public static Result success(Object listData) {
return success("success", listData);
}
public static Result success() {
return success(null);
}
public static Result error(String msg, Object listData) {
return new Result(500, msg, listData);
}
public static Result error(Object listData) {
return error("error", listData);
}
public static Result error() {
return error(null);
}
}
package com.viontech.report.entity;
import lombok.Getter;
import lombok.Setter;
/**
* .
*
* @author 谢明辉
* @date 2020/9/16
*/
@Getter
@Setter
@SuppressWarnings("ALL")
public class SubTask {
private String taskId;
private String subTaskId;
private String subtaskname;
private Integer vechile = 0;
private Integer illegal = 0;
private Integer event = 0;
}
package com.viontech.report.entity;
import lombok.Getter;
import lombok.Setter;
import java.util.ArrayList;
import java.util.List;
/**
* .
*
* @author 谢明辉
* @date 2020/9/16
*/
@Getter
@Setter
@SuppressWarnings("all")
public class Task {
private String taskname;
private String taskid;
private List<SubTask> subtaskList = new ArrayList<>();
}
package com.viontech.report.entity;
import java.io.Serializable;
import java.util.Date;
import lombok.Data;
/**
* tb_traffic
* @author xmh
*/
@Data
public class Traffic implements Serializable {
private String unid;
private String eventCate;
private String taskId;
private String taskType;
private String subtaskId;
private String sourceType;
private String eventType;
private String devUnid;
private String vchanRefid;
private String vdevUnid;
private String vchanDuid;
private Date eventDt;
/**
* 车牌颜色
*/
private String plateColorCode;
/**
* 车牌号
*/
private String plateText;
/**
* 位置编码
*/
private String locationCode;
/**
* 车道号
*/
private String laneCode;
/**
* 卡口方向编码
*/
private String directionCode;
/**
* 车辆类型编码
*/
private String bodyTypeCode;
/**
* 设备名称
*/
private String deviceName;
/**
* 违法行为编码
*/
private String illegalCode;
/**
* 违法信息是否可用
*/
private String illegalState;
/**
* 车身颜色
*/
private String bodyColorCode;
/**
* 车标编码
*/
private String bodyLogoCode;
/**
* 年检标
*/
private Boolean refinedfeatureRannualinspection;
/**
* 摆件
*/
private Boolean refinedfeatureRdecoration;
/**
* 吊坠
*/
private Boolean refinedfeatureRpendant;
/**
* 遮阳板
*/
private Boolean refinedfeatureRsunshading;
/**
* 非机动车类型
*/
private String xcycleType;
private String locationName;
private String eventId;
private Date shootDt;
private String isActive;
private String specialType;
/**
* 是否带头盔 默认0为不带
*/
private Short withHats;
private Object jsonData;
private String picName;
private String videoName;
private static final long serialVersionUID = 1L;
}
\ No newline at end of file
package com.viontech.report.repository;
import cn.hutool.core.date.DateUtil;
import com.viontech.report.entity.Behavior;
import com.viontech.report.entity.QueryParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Repository;
import java.time.LocalDateTime;
import java.util.List;
/**
* .
*
* @author 谢明辉
* @date 2020/9/18
*/
@Repository
@Slf4j
public class BehaviorRepository {
@Autowired
@Qualifier("behaviorJdbcTemplate")
private JdbcTemplate behaviorJdbcTemplate;
@Autowired
@Qualifier("behaviorNamedParameterJdbcTemplate")
private NamedParameterJdbcTemplate behaviorNamedParameterJdbcTemplate;
public List<Behavior> queryBehaviors(QueryParam param) {
long begin = System.currentTimeMillis();
BeanPropertySqlParameterSource parameterSource = new BeanPropertySqlParameterSource(param);
StringBuilder sb = new StringBuilder("select task_id,subtask_id from tb_behavior_event where event_dt between :start_dt and :end_dt ");
if (param.getTask_id() != null && !param.getTask_id().isEmpty()) {
sb.append(" and task_id=:task_id ");
}
if (param.getTaskIds() != null && param.getTaskIds().size() > 0) {
sb.append(" and task_id in (:taskIds) ");
}
if (param.getSubtask_id() != null && !param.getTask_id().isEmpty()) {
sb.append(" and subtask_id=:subtask_id ");
}
List<Behavior> query = behaviorNamedParameterJdbcTemplate.query(sb.toString(), parameterSource, new BeanPropertyRowMapper<>(Behavior.class));
log.info("耗时:[{}]", (System.currentTimeMillis() - begin) / 1000);
return query;
}
}
package com.viontech.report.repository;
import com.viontech.report.entity.SubTask;
import com.viontech.report.entity.Task;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Repository;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
/**
* .
*
* @author 谢明辉
* @date 2020/9/15
*/
@Repository
@Slf4j
public class TaskRepository {
@Autowired
@Qualifier("taskJdbcTemplate")
private JdbcTemplate taskJdbcTemplate;
@Autowired
@Qualifier("taskNamedParameterJdbcTemplate")
private NamedParameterJdbcTemplate taskNamedParameterJdbcTemplate;
public List<Task> queryTaskByIds(Collection<String> ids) {
return taskNamedParameterJdbcTemplate.query("select id as taskid,task_name as taskname from tb_task where id in (:ids)", Collections.singletonMap("ids", ids), new BeanPropertyRowMapper<>(Task.class));
}
public List<SubTask> querySubTaskByTaskIds(Collection<String> ids) {
return taskNamedParameterJdbcTemplate.query("select id as subTaskId,parent_task as taskId,subtask_name as subtaskname from tb_subtask where parent_task in (:ids)", Collections.singletonMap("ids", ids), new BeanPropertyRowMapper<>(SubTask.class));
}
}
package com.viontech.report.repository;
import com.viontech.report.entity.QueryParam;
import com.viontech.report.entity.Traffic;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* .
*
* @author 谢明辉
* @date 2020/9/18
*/
@Repository
@Slf4j
public class TrafficRepository {
@Autowired
@Qualifier("trafficJdbcTemplate")
private JdbcTemplate trafficJdbcTemplate;
@Autowired
@Qualifier("trafficNamedParameterJdbcTemplate")
private NamedParameterJdbcTemplate trafficNamedParameterJdbcTemplate;
public List<Traffic> queryTraffic(QueryParam param) {
long begin = System.currentTimeMillis();
BeanPropertySqlParameterSource parameterSource = new BeanPropertySqlParameterSource(param);
StringBuilder sb = new StringBuilder("select * from tb_traffic where shoot_dt between :start_dt and :end_dt");
if (param.getTask_id() != null && !param.getTask_id().isEmpty()) {
sb.append(" and task_id=:task_id ");
}
if (param.getTaskIds() != null && param.getTaskIds().size() > 0) {
sb.append(" and task_id in (:taskIds) ");
}
if (param.getSubtask_id() != null && !param.getSubtask_id().isEmpty()) {
sb.append(" and subtask_id=:subtask_id ");
}
sb.append(" and event_type='vehicle' ");
if ("illegal".equals(param.getType())) {
sb.append(" and illegal_state='true' ");
}
List<Traffic> query = trafficNamedParameterJdbcTemplate.query(sb.toString(), parameterSource, new BeanPropertyRowMapper<>(Traffic.class));
log.info("耗时:[{}]", (System.currentTimeMillis() - begin) / 1000);
return query;
}
}
package com.viontech.report.service;
import com.viontech.report.entity.*;
import com.viontech.report.repository.BehaviorRepository;
import com.viontech.report.repository.TaskRepository;
import com.viontech.report.repository.TrafficRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.stream.Collectors;
/**
* .
*
* @author 谢明辉
* @date 2020/9/15
*/
@Service
@Slf4j
public class TaskService {
@Autowired
private TaskRepository taskRepository;
@Autowired
private TrafficRepository trafficRepository;
@Autowired
private BehaviorRepository behaviorRepository;
public Collection<Task> getStatistics(QueryParam param) {
List<Traffic> trafficList = Collections.emptyList();
List<Behavior> behaviors = Collections.emptyList();
Set<String> taskIdSet = null;
if ("vechile".equals(param.getType()) || "illegal".equals(param.getType())) {
trafficList = trafficRepository.queryTraffic(param);
taskIdSet = trafficList.stream().map(Traffic::getTaskId).collect(Collectors.toSet());
if (taskIdSet.size() == 0) {
return Collections.emptyList();
}
param.setTaskIds(taskIdSet);
behaviors = behaviorRepository.queryBehaviors(param);
} else if ("event".equals(param.getType())) {
behaviors = behaviorRepository.queryBehaviors(param);
taskIdSet = behaviors.stream().map(Behavior::getTaskId).collect(Collectors.toSet());
if (taskIdSet.size() == 0) {
return Collections.emptyList();
}
trafficList = trafficRepository.queryTraffic(param);
}
if (taskIdSet == null) {
return Collections.emptyList();
}
Map<String, Task> taskMap = taskRepository.queryTaskByIds(taskIdSet).stream().collect(Collectors.toMap(Task::getTaskid, x -> x, (a, b) -> a));
Map<String, SubTask> subTaskMap = taskRepository.querySubTaskByTaskIds(taskIdSet).stream().collect(Collectors.toMap(SubTask::getSubTaskId, x -> x, (x, y) -> x));
Iterator<Map.Entry<String, SubTask>> subTaskIterator = subTaskMap.entrySet().iterator();
// 能找到主任务的放入task中,找不到的直接移除
while (subTaskIterator.hasNext()) {
Map.Entry<String, SubTask> next = subTaskIterator.next();
String taskId = next.getValue().getTaskId();
Task task = taskMap.get(taskId);
if (task == null) {
subTaskIterator.remove();
continue;
}
task.getSubtaskList().add(next.getValue());
}
for (Traffic item : trafficList) {
String subtaskId = item.getSubtaskId();
SubTask subTask = subTaskMap.get(subtaskId);
if (subTask == null) {
continue;
}
subTask.setVechile(subTask.getVechile() + 1);
if ("true".equals(item.getIllegalState())) {
subTask.setIllegal(subTask.getIllegal() + 1);
}
}
for (Behavior item : behaviors) {
String subtaskId = item.getSubtaskId();
SubTask subTask = subTaskMap.get(subtaskId);
if (subTask == null) {
continue;
}
subTask.setEvent(subTask.getEvent() + 1);
}
return taskMap.values();
}
}
spring.datasource.url=jdbc:postgresql://192.168.9.62:5432/shoppingMall_huawei_snapshot
spring.datasource.username=
spring.datasource.password=
spring.redis.url=192.168.9.62
spring.redis.host=6379
spring.redis.password=
server.port=22222
# datasource
vion.datasource.driver-class-name=org.postgresql.Driver
vion.datasource.pre-url=jdbc:postgresql://192.168.9.233:5432/
vion.datasource.username=postgres
vion.datasource.password=authpass
# redis
spring.redis.host=192.168.9.233
spring.redis.port=6379
spring:
profiles:
active: option
datasource:
driver-class-name: org.postgresql.Driver
jackson:
date-format: yyyy-MM-dd HH:mm:ss
time-zone: GMT+8
time-zone: UTC
application:
name: fx_report_serv
<?xml version="1.0" encoding="UTF-8"?>
<!-- 日志级别从低到高分为TRACE < DEBUG < INFO < WARN < ERROR < FATAL,如果设置为WARN,则低于WARN的信息都不会输出 -->
<!-- scan:当此属性设置为true时,配置文件如果发生改变,将会被重新加载,默认值为true -->
<!-- scanPeriod:设置监测配置文件是否有修改的时间间隔,如果没有给出时间单位,默认单位是毫秒。当scan为true时,此属性生效。默认的时间间隔为1分钟。 -->
<!-- debug:当此属性设置为true时,将打印出logback内部日志信息,实时查看logback运行状态。默认值为false。 -->
<configuration scan="true" scanPeriod="10 seconds">
<!--<include resource="org/springframework/boot/logging/logback/base.xml" />-->
<contextName>logback</contextName>
<!-- name的值是变量的名称,value的值时变量定义的值。通过定义的值会被插入到logger上下文中。定义变量后,可以使“${}”来使用变量。 -->
<property name="log.path" value="logs"/>
<property name="pattern" value="[%d{yyyy-MM-dd HH:mm:ss.SSS}] [%-5level] [%thread] %logger{50} - %msg%n"/>
<!--输出到控制台-->
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<!--此日志appender是为开发使用,只配置最底级别,控制台输出的日志级别是大于或等于此级别的日志信息-->
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>info</level>
</filter>
<encoder>
<Pattern>${pattern}</Pattern>
<!-- 设置字符集 -->
</encoder>
</appender>
<!--输出到文件-->
<!-- 时间滚动输出 level为 DEBUG 日志 -->
<appender name="DEBUG_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!-- 正在记录的日志文件的路径及文件名 -->
<file>${log.path}/log_debug.log</file>
<!--日志文件输出格式-->
<encoder>
<Pattern>${pattern}</Pattern>
<charset>UTF-8</charset> <!-- 设置字符集 -->
</encoder>
<!-- 日志记录器的滚动策略,按日期,按大小记录 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 日志归档 -->
<fileNamePattern>${log.path}/debug/log-debug-%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>100MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<!--日志文件保留天数-->
<maxHistory>15</maxHistory>
</rollingPolicy>
<!-- 此日志文件只记录debug级别的 -->
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>debug</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<!-- 时间滚动输出 level为 INFO 日志 -->
<appender name="INFO_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!-- 正在记录的日志文件的路径及文件名 -->
<file>${log.path}/log_info.log</file>
<!--日志文件输出格式-->
<encoder>
<Pattern>${pattern}</Pattern>
<charset>UTF-8</charset>
</encoder>
<!-- 日志记录器的滚动策略,按日期,按大小记录 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 每天日志归档路径以及格式 -->
<fileNamePattern>${log.path}/info/log-info-%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>100MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<!--日志文件保留天数-->
<maxHistory>15</maxHistory>
</rollingPolicy>
<!-- 此日志文件只记录info级别的 -->
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>info</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>NEUTRAL</onMismatch>
</filter>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>warn</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<!-- 时间滚动输出 level为 WARN 日志 -->
<appender name="WARN_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!-- 正在记录的日志文件的路径及文件名 -->
<file>${log.path}/log_warn.log</file>
<!--日志文件输出格式-->
<encoder>
<Pattern>${pattern}</Pattern>
<charset>UTF-8</charset> <!-- 此处设置字符集 -->
</encoder>
<!-- 日志记录器的滚动策略,按日期,按大小记录 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${log.path}/warn/log-warn-%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>100MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<!--日志文件保留天数-->
<maxHistory>5</maxHistory>
</rollingPolicy>
<!-- 此日志文件只记录warn级别的 -->
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>warn</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<!-- 时间滚动输出 level为 ERROR 日志 -->
<appender name="ERROR_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!-- 正在记录的日志文件的路径及文件名 -->
<file>${log.path}/log_error.log</file>
<!--日志文件输出格式-->
<encoder>
<Pattern>${pattern}</Pattern>
<charset>UTF-8</charset> <!-- 此处设置字符集 -->
</encoder>
<!-- 日志记录器的滚动策略,按日期,按大小记录 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${log.path}/error/log-error-%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>100MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<!--日志文件保留天数-->
<maxHistory>15</maxHistory>
</rollingPolicy>
<!-- 此日志文件只记录ERROR级别的 -->
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>ERROR</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<logger name="com.viontech.report" level="debug">
<appender-ref ref="DEBUG_FILE"/>
</logger>
<root level="info">
<appender-ref ref="CONSOLE"/>
<appender-ref ref="INFO_FILE"/>
<appender-ref ref="WARN_FILE"/>
<appender-ref ref="ERROR_FILE"/>
</root>
</configuration>
\ No newline at end of file
package com.viontech.report;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.test.context.SpringBootTest;
import javax.annotation.Resource;
@SpringBootTest
class ReportApplicationTests {
@Qualifier
@Test
void contextLoads() {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!