格式修改

This commit is contained in:
2026-08-05 10:35:07 +08:00
parent 81c9c92f5d
commit 496fc58a90
241 changed files with 5600 additions and 2088 deletions
@@ -1,5 +1,8 @@
package com.baiyue.print.config;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.Resource;
import java.io.InputStream;
import org.apache.fontbox.ttf.TTFParser;
import org.apache.fontbox.ttf.TrueTypeFont;
@@ -11,11 +14,11 @@ import org.springframework.stereotype.Component;
/** Exposes font packaging/parsing failures through readiness health. */
@Component("printFont")
public class PrintFontHealthIndicator implements HealthIndicator {
private final Health validationResult;
@Resource private PrintPdfProperties properties;
private Health validationResult;
public PrintFontHealthIndicator(PrintPdfProperties properties) {
this.validationResult = validate(properties.getFontResource());
}
@PostConstruct
void initializeHealth() { validationResult = validate(properties.getFontResource()); }
@Override
public Health health() {
@@ -1,5 +1,7 @@
package com.baiyue.print.controller;
import jakarta.annotation.Resource;
import com.baiyue.common.web.CorrelationContext;
import com.baiyue.print.dto.InboundMarkPdfDtos;
import com.baiyue.print.service.InboundMarkPdfService;
@@ -24,13 +26,8 @@ public class InternalPdfController {
static final String INTERNAL_TOKEN_HEADER = "X-Internal-Service-Token";
static final String PAGE_COUNT_HEADER = "X-Print-Page-Count";
private final InboundMarkPdfService pdfService;
private final InternalServiceTokenGuard tokenGuard;
public InternalPdfController(InboundMarkPdfService pdfService, InternalServiceTokenGuard tokenGuard) {
this.pdfService = pdfService;
this.tokenGuard = tokenGuard;
}
@Resource private InboundMarkPdfService pdfService;
@Resource private InternalServiceTokenGuard tokenGuard;
@PostMapping(value = "/inbound-marks", consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<byte[]> generateInboundMarks(
@@ -1,5 +1,7 @@
package com.baiyue.print.controller;
import jakarta.annotation.PostConstruct;
import com.baiyue.common.core.api.ResultCode;
import com.baiyue.common.core.exception.BizException;
import org.springframework.beans.factory.annotation.Value;
@@ -11,9 +13,11 @@ import java.security.MessageDigest;
/** Verifies the shared credential used by internal service callers. */
@Component
public class InternalServiceTokenGuard {
private final byte[] expectedToken;
@Value("${baiyue.security.internal-service-token}") private String token;
private byte[] expectedToken;
public InternalServiceTokenGuard(@Value("${baiyue.security.internal-service-token}") String token) {
@PostConstruct
void initializeToken() {
if (token == null || token.getBytes(StandardCharsets.UTF_8).length < 32) {
throw new IllegalStateException("INTERNAL_SERVICE_TOKEN must contain at least 32 bytes");
}
@@ -1,5 +1,7 @@
package com.baiyue.print.controller;
import jakarta.annotation.Resource;
import com.baiyue.common.core.api.ApiResponse;
import com.baiyue.common.core.api.ResultCode;
import com.baiyue.common.web.CorrelationContext;
@@ -28,13 +30,8 @@ import org.springframework.web.filter.OncePerRequestFilter;
public class PrintRequestSizeFilter extends OncePerRequestFilter {
private static final String PATH = "/internal/print/v1/pdfs/inbound-marks";
private final PrintPdfProperties properties;
private final ObjectMapper objectMapper;
public PrintRequestSizeFilter(PrintPdfProperties properties, ObjectMapper objectMapper) {
this.properties = properties;
this.objectMapper = objectMapper;
}
@Resource private PrintPdfProperties properties;
@Resource private ObjectMapper objectMapper;
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
@@ -1,5 +1,7 @@
package com.baiyue.print.renderer;
import jakarta.annotation.Resource;
import com.baiyue.print.dto.InboundMarkPdfDtos;
import com.google.zxing.common.BitMatrix;
import java.io.IOException;
@@ -24,11 +26,7 @@ public class InboundMarkV1Renderer {
private static final float QR_LEFT_PT = (PAGE_WIDTH_PT - QR_SIZE_PT) / 2f;
private static final float QR_BOTTOM_PT = PAGE_HEIGHT_PT - PdfUnits.mmToPt(84);
private final PdfQrRenderer qrRenderer;
public InboundMarkV1Renderer(PdfQrRenderer qrRenderer) {
this.qrRenderer = qrRenderer;
}
@Resource private PdfQrRenderer qrRenderer;
public void renderPage(PDDocument document, PDFont font, InboundMarkPdfDtos.Label label,
BitMatrix qrMatrix) throws IOException {
@@ -1,5 +1,7 @@
package com.baiyue.print.service;
import jakarta.annotation.Resource;
import com.baiyue.common.core.api.ResultCode;
import com.baiyue.common.core.exception.BizException;
import com.baiyue.print.config.PrintPdfProperties;
@@ -30,18 +32,10 @@ public class InboundMarkPdfService {
private static final Set<Character> FORBIDDEN_FILE_NAME_CHARACTERS =
Set.of('/', '\\', ':', '*', '?', '"', '<', '>', '|');
private final PrintPdfProperties properties;
private final PdfGenerationLimiter limiter;
private final InboundMarkV1Renderer renderer;
private final PdfQrRenderer qrRenderer;
public InboundMarkPdfService(PrintPdfProperties properties, PdfGenerationLimiter limiter,
InboundMarkV1Renderer renderer, PdfQrRenderer qrRenderer) {
this.properties = properties;
this.limiter = limiter;
this.renderer = renderer;
this.qrRenderer = qrRenderer;
}
@Resource private PrintPdfProperties properties;
@Resource private PdfGenerationLimiter limiter;
@Resource private InboundMarkV1Renderer renderer;
@Resource private PdfQrRenderer qrRenderer;
public GeneratedPdf generate(InboundMarkPdfDtos.Request request) {
NormalizedRequest normalized = validateAndNormalize(request);
@@ -1,5 +1,8 @@
package com.baiyue.print.service;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.Resource;
import com.baiyue.common.core.api.ResultCode;
import com.baiyue.common.core.exception.BizException;
import com.baiyue.print.config.PrintPdfProperties;
@@ -13,10 +16,12 @@ import org.springframework.stereotype.Component;
*/
@Component
public class PdfGenerationLimiter {
private final Semaphore semaphore;
private final Duration acquireTimeout;
@Resource private PrintPdfProperties properties;
private Semaphore semaphore;
private Duration acquireTimeout;
public PdfGenerationLimiter(PrintPdfProperties properties) {
@PostConstruct
void initializeLimiter() {
if (properties.getMaxConcurrentGenerations() < 1) {
throw new IllegalArgumentException("print.pdf.max-concurrent-generations must be positive");
}
+1 -1
View File
@@ -44,6 +44,6 @@ logging:
rollingpolicy:
file-name-pattern: "${LOGGING_ROLLING_FILE_NAME_PATTERN:${LOG_PATH:./logs}/${spring.application.name}.%d{yyyy-MM-dd}.%i.log.gz}"
max-file-size: "${LOGGING_ROLLING_MAX_FILE_SIZE:100MB}"
max-history: "${LOGGING_ROLLING_MAX_HISTORY:30}"
max-history: "${LOGGING_ROLLING_MAX_HISTORY:7}"
total-size-cap: "${LOGGING_ROLLING_TOTAL_SIZE_CAP:5GB}"
clean-history-on-start: "${LOGGING_ROLLING_CLEAN_HISTORY_ON_START:false}"