瀏覽代碼

Merge remote-tracking branch 'origin/master'

master
PoffyZhang 1 年之前
父節點
當前提交
18d2de323e
共有 6 個文件被更改,包括 79 次插入5 次删除
  1. +8
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/common/config/ConfigurerAdapter.java
  2. +38
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/common/interceptor/LogInterceptor.java
  3. +26
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/common/util/MDCUtil.java
  4. +1
    -1
      pmapi/src/main/java/com/ningdatech/pmapi/meeting/manage/ExpertExportManage.java
  5. +3
    -1
      pmapi/src/main/java/com/ningdatech/pmapi/meeting/service/impl/MeetingExpertServiceImpl.java
  6. +3
    -3
      pmapi/src/main/resources/logback-spring.xml

+ 8
- 0
pmapi/src/main/java/com/ningdatech/pmapi/common/config/ConfigurerAdapter.java 查看文件

@@ -3,10 +3,13 @@ package com.ningdatech.pmapi.common.config;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.support.config.FastJsonConfig;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
import com.ningdatech.pmapi.common.interceptor.LogInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.lang.NonNull;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.nio.charset.StandardCharsets;
@@ -34,4 +37,9 @@ public class ConfigurerAdapter implements WebMvcConfigurer {
converter.setDefaultCharset(StandardCharsets.UTF_8);
converters.add(converter);
}

@Override
public void addInterceptors(@NonNull InterceptorRegistry registry) {
registry.addInterceptor(new LogInterceptor()).addPathPatterns("/**").order(-100);
}
}

+ 38
- 0
pmapi/src/main/java/com/ningdatech/pmapi/common/interceptor/LogInterceptor.java 查看文件

@@ -0,0 +1,38 @@
package com.ningdatech.pmapi.common.interceptor;

import cn.hutool.core.lang.UUID;
import com.ningdatech.pmapi.common.util.MDCUtil;
import org.springframework.lang.NonNull;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
* <p>
* LogInterceptor
* </p>
*
* @author WendyYang
* @since 2023/10/26
**/
public class LogInterceptor implements HandlerInterceptor {

@Override
public boolean preHandle(@NonNull HttpServletRequest request,
@NonNull HttpServletResponse response,
@NonNull Object handler) {
String traceId = UUID.randomUUID().toString(true);
response.addHeader(MDCUtil.TRACE_ID_HEADER, traceId);
MDCUtil.setTraceId(traceId);
return true;
}

@Override
public void afterCompletion(@NonNull HttpServletRequest request,
@NonNull HttpServletResponse response,
@NonNull Object handler, Exception ex) {
MDCUtil.removeTraceId();
}

}

+ 26
- 0
pmapi/src/main/java/com/ningdatech/pmapi/common/util/MDCUtil.java 查看文件

@@ -0,0 +1,26 @@
package com.ningdatech.pmapi.common.util;

import org.slf4j.MDC;

/**
* <p>
* MDCUtil
* </p>
*
* @author WendyYang
* @since 2023/10/26
**/
public class MDCUtil {

public static final String TRACE_ID = "traceId";
public static final String TRACE_ID_HEADER = "Trace-Id";

public static void setTraceId(String traceId) {
MDC.put(TRACE_ID, traceId);
}

public static void removeTraceId() {
MDC.remove(TRACE_ID);
}

}

+ 1
- 1
pmapi/src/main/java/com/ningdatech/pmapi/meeting/manage/ExpertExportManage.java 查看文件

@@ -268,7 +268,7 @@ public class ExpertExportManage {
ExpertInfoDTO expert = new ExpertInfoDTO();
expert.setNo(integer.incrementAndGet());
if (ExpertAttendStatusEnum.ON_LEAVE.eq(w.getStatus())) {
expert.setBank(w.getExpertName() + "(请假)");
expert.setName(w.getExpertName() + "(请假)");
} else {
expert.setName(w.getExpertName());
}


+ 3
- 1
pmapi/src/main/java/com/ningdatech/pmapi/meeting/service/impl/MeetingExpertServiceImpl.java 查看文件

@@ -23,6 +23,7 @@ import java.time.LocalDateTime;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

/**
@@ -102,7 +103,8 @@ public class MeetingExpertServiceImpl extends ServiceImpl<MeetingExpertMapper, M

@Override
public Page<MeetingExpert> pageExpertByStatusAndMeetingId(Page<MeetingExpert> page, Long meetingId, ExpertAttendStatusEnum status, Integer inviteType) {
return baseMapper.selectExpertByStatusAndMeetingId(page, status.getCode(), meetingId, inviteType);
Integer statusCode = Optional.ofNullable(status).flatMap(w -> Optional.of(w.getCode())).orElse(null);
return baseMapper.selectExpertByStatusAndMeetingId(page, statusCode, meetingId, inviteType);
}

@Override


+ 3
- 3
pmapi/src/main/resources/logback-spring.xml 查看文件

@@ -19,7 +19,7 @@
</rollingPolicy>
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} -%msg%n
<Pattern>[traceId:%X{traceId}] %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} -%msg%n
</Pattern>
</layout>
<charset>UTF-8</charset>
@@ -41,7 +41,7 @@
</rollingPolicy>
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} -%msg%n
<Pattern>[traceId:%X{traceId}] %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} -%msg%n
</Pattern>
</layout>
<charset>UTF-8</charset>
@@ -51,7 +51,7 @@
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>
%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} -%msg%n
[traceId:%X{traceId}] %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} -%msg%n
</pattern>
<charset>UTF-8</charset>
</encoder>


Loading…
取消
儲存