zhuyifan

fix

......@@ -247,12 +247,12 @@ public class MealOrderGrpcService extends MealOrderServiceRpcGrpc.MealOrderServi
queryWrapper.eq(MealOrder::getEnterpriseId, request.getEnterpriseId());
queryWrapper.in(!request.getDinerIdsList().isEmpty(), MealOrder::getDinerId, request.getDinerIdsList());
LocalDate today = LocalDate.now();
LocalDate nextMonday = today.with(TemporalAdjusters.next(DayOfWeek.MONDAY));
LocalDateTime nextMondayStart = LocalDateTime.of(nextMonday, LocalTime.MIN);
LocalDate nextSunday = nextMonday.plusDays(6);
LocalDateTime nextSundayEnd = LocalDateTime.of(nextSunday, LocalTime.MAX);
queryWrapper.ge(MealOrder::getReserveDate, nextMondayStart);
queryWrapper.lt(MealOrder::getReserveDate, nextSundayEnd);
LocalDate thisMonday = today.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
LocalDateTime thisMondayStart = LocalDateTime.of(thisMonday, LocalTime.MIN);
LocalDate thisSunday = today.with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY));
LocalDateTime thisSundayEnd = LocalDateTime.of(thisSunday, LocalTime.MAX);
queryWrapper.ge(MealOrder::getReserveDate, thisMondayStart);
queryWrapper.lt(MealOrder::getReserveDate, thisSundayEnd);
final var mealOrders = mealOrderService.list(queryWrapper);
if (!mealOrders.isEmpty()) {
for (final var mealOrder : mealOrders) {
......
......@@ -4,7 +4,6 @@ import brave.Span;
import brave.Tracing;
import brave.baggage.BaggagePropagation;
import brave.propagation.Propagation;
import com.tianting.infoloop.constants.ConfigConstants;
import io.grpc.Context;
import io.grpc.ForwardingServerCall;
import io.grpc.Grpc;
......@@ -14,6 +13,7 @@ import io.grpc.ServerCallHandler;
import io.grpc.ServerInterceptor;
import io.grpc.Status;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.MDC;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;
......@@ -24,6 +24,9 @@ import java.util.Objects;
import static com.tianting.infoloop.constants.ConfigConstants.BRAVE_PROPAGATION_DEBUG_FIELD;
import static com.tianting.infoloop.constants.ConfigConstants.ENTERPRISE_ID_KEY;
import static com.tianting.infoloop.constants.ConfigConstants.LOGGING_PARENT_TRACING_ID;
import static com.tianting.infoloop.constants.ConfigConstants.LOGGING_TRACING_ID;
import static com.tianting.infoloop.constants.ConfigConstants.LOGGING_UNIQUE_ID;
import static com.tianting.infoloop.constants.ConfigConstants.SOURCE_KEY;
import static com.tianting.infoloop.constants.ConfigConstants.USER_ID_KEY;
......@@ -71,6 +74,9 @@ public class GrpcServerInterceptor implements ServerInterceptor {
span.remoteIpAndPort(remoteAddressAndPort[0], Integer.parseInt(remoteAddressAndPort[1]));
span.name(fullMethodName);
span.start();
MDC.put(LOGGING_TRACING_ID, span.context().traceIdString());
MDC.put(LOGGING_UNIQUE_ID, span.context().spanIdString());
MDC.put(LOGGING_PARENT_TRACING_ID, span.context().parentIdString());
final var scope = tracing.currentTraceContext().newScope(span.context());
final var listener = next.startCall(new ForwardingServerCall.SimpleForwardingServerCall<>(call) {
......@@ -106,6 +112,7 @@ public class GrpcServerInterceptor implements ServerInterceptor {
}
scope.close();
span.finish();
MDC.clear();
}
}, headers);
Context context = setUserContextFromHeaders(headers, fullMethodName);
......
......@@ -9,6 +9,7 @@ import io.grpc.Context;
import io.grpc.ForwardingServerCallListener;
import io.grpc.ServerCall;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.MDC;
import static com.tianting.infoloop.constants.ConfigConstants.BRAVE_PROPAGATION_DEBUG_FIELD;
......@@ -67,6 +68,7 @@ public class MyContextualizedServerCallListener<ReqT> extends ForwardingServerCa
span.error(e);
scope.close();
span.finish();
MDC.clear();
throw e;
} finally {
context.detach(previous);
......@@ -82,6 +84,7 @@ public class MyContextualizedServerCallListener<ReqT> extends ForwardingServerCa
span.error(e);
scope.close();
span.finish();
MDC.clear();
throw e;
} finally {
context.detach(previous);
......