@@ -3,10 +3,13 @@ package com.ningdatech.pmapi.common.config; | |||||
import com.alibaba.fastjson.serializer.SerializerFeature; | import com.alibaba.fastjson.serializer.SerializerFeature; | ||||
import com.alibaba.fastjson.support.config.FastJsonConfig; | import com.alibaba.fastjson.support.config.FastJsonConfig; | ||||
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter; | import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter; | ||||
import com.ningdatech.pmapi.common.interceptor.LogInterceptor; | |||||
import org.springframework.context.annotation.Configuration; | import org.springframework.context.annotation.Configuration; | ||||
import org.springframework.http.MediaType; | import org.springframework.http.MediaType; | ||||
import org.springframework.http.converter.HttpMessageConverter; | 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.EnableWebMvc; | ||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry; | |||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||||
import java.nio.charset.StandardCharsets; | import java.nio.charset.StandardCharsets; | ||||
@@ -34,4 +37,9 @@ public class ConfigurerAdapter implements WebMvcConfigurer { | |||||
converter.setDefaultCharset(StandardCharsets.UTF_8); | converter.setDefaultCharset(StandardCharsets.UTF_8); | ||||
converters.add(converter); | converters.add(converter); | ||||
} | } | ||||
@Override | |||||
public void addInterceptors(@NonNull InterceptorRegistry registry) { | |||||
registry.addInterceptor(new LogInterceptor()).addPathPatterns("/**").order(-100); | |||||
} | |||||
} | } |
@@ -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(); | |||||
} | |||||
} |
@@ -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); | |||||
} | |||||
} |
@@ -268,7 +268,7 @@ public class ExpertExportManage { | |||||
ExpertInfoDTO expert = new ExpertInfoDTO(); | ExpertInfoDTO expert = new ExpertInfoDTO(); | ||||
expert.setNo(integer.incrementAndGet()); | expert.setNo(integer.incrementAndGet()); | ||||
if (ExpertAttendStatusEnum.ON_LEAVE.eq(w.getStatus())) { | if (ExpertAttendStatusEnum.ON_LEAVE.eq(w.getStatus())) { | ||||
expert.setBank(w.getExpertName() + "(请假)"); | |||||
expert.setName(w.getExpertName() + "(请假)"); | |||||
} else { | } else { | ||||
expert.setName(w.getExpertName()); | expert.setName(w.getExpertName()); | ||||
} | } | ||||
@@ -23,6 +23,7 @@ import java.time.LocalDateTime; | |||||
import java.util.Collection; | import java.util.Collection; | ||||
import java.util.List; | import java.util.List; | ||||
import java.util.Map; | import java.util.Map; | ||||
import java.util.Optional; | |||||
import java.util.stream.Collectors; | import java.util.stream.Collectors; | ||||
/** | /** | ||||
@@ -102,7 +103,8 @@ public class MeetingExpertServiceImpl extends ServiceImpl<MeetingExpertMapper, M | |||||
@Override | @Override | ||||
public Page<MeetingExpert> pageExpertByStatusAndMeetingId(Page<MeetingExpert> page, Long meetingId, ExpertAttendStatusEnum status, Integer inviteType) { | 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 | @Override | ||||
@@ -19,7 +19,7 @@ | |||||
</rollingPolicy> | </rollingPolicy> | ||||
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder"> | <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder"> | ||||
<layout class="ch.qos.logback.classic.PatternLayout"> | <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> | </Pattern> | ||||
</layout> | </layout> | ||||
<charset>UTF-8</charset> | <charset>UTF-8</charset> | ||||
@@ -41,7 +41,7 @@ | |||||
</rollingPolicy> | </rollingPolicy> | ||||
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder"> | <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder"> | ||||
<layout class="ch.qos.logback.classic.PatternLayout"> | <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> | </Pattern> | ||||
</layout> | </layout> | ||||
<charset>UTF-8</charset> | <charset>UTF-8</charset> | ||||
@@ -51,7 +51,7 @@ | |||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||||
<encoder> | <encoder> | ||||
<pattern> | <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> | </pattern> | ||||
<charset>UTF-8</charset> | <charset>UTF-8</charset> | ||||
</encoder> | </encoder> | ||||