优化
This commit is contained in:
+2
-4
@@ -44,9 +44,6 @@ public class OceanBookingPrintService {
|
||||
private GeneratedPdf generate(long id, String requestId, String template, String suffix) {
|
||||
Detail detail = bookings.detail(id);
|
||||
OceanBookingEntity booking = detail.oceanBooking();
|
||||
if (!"RELEASED".equals(booking.getStatus())) {
|
||||
throw new BizException(ResultCode.CONFLICT, "订舱放舱后才可打印正式单据");
|
||||
}
|
||||
String fileName = booking.getBookingNo() + "-" + suffix + ".pdf";
|
||||
PrintPdfClient.FreightA4PdfRequest request = new PrintPdfClient.FreightA4PdfRequest(
|
||||
template, A4, fileName, List.of(new PrintPdfClient.FreightDocument(
|
||||
@@ -97,7 +94,8 @@ public class OceanBookingPrintService {
|
||||
fields.put("containerSummary", requirementSummary(detail.containerRequirements()));
|
||||
fields.put("notes", text(booking.getRemark()));
|
||||
}
|
||||
fields.values().removeIf(String::isEmpty);
|
||||
// Missing booking data is displayed explicitly, including required PDF template fields.
|
||||
fields.replaceAll((key, value) -> value.isEmpty() ? "—" : value);
|
||||
return fields;
|
||||
}
|
||||
|
||||
|
||||
+7
-3
@@ -9,6 +9,10 @@ import com.baiyue.firstleg.terminaldrayage.dto.TerminalDrayageDtos.FleetSelectio
|
||||
import com.baiyue.firstleg.terminaldrayage.dto.TerminalDrayageDtos.History;
|
||||
import com.baiyue.firstleg.terminaldrayage.dto.TerminalDrayageDtos.PickupAppointmentRequest;
|
||||
import com.baiyue.firstleg.terminaldrayage.dto.TerminalDrayageDtos.View;
|
||||
import com.baiyue.firstleg.terminaldrayage.dto.TerminalDrayageDtos.EmailRequest;
|
||||
import com.baiyue.firstleg.terminaldrayage.service.TerminalDrayageMailService;
|
||||
import com.baiyue.firstleg.terminaldrayage.service.TerminalDrayageMailService.Mailbox;
|
||||
import jakarta.annotation.Resource;
|
||||
import com.baiyue.firstleg.terminaldrayage.service.TerminalDrayageService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
@@ -36,20 +40,20 @@ import java.util.List;
|
||||
@Tag(name = "目的港码头拖车")
|
||||
@RequestMapping("/api/platform/v1/terminal-drayages")
|
||||
public class PlatformTerminalDrayageController {
|
||||
@jakarta.annotation.Resource private com.baiyue.firstleg.terminaldrayage.service.TerminalDrayageMailService mails;
|
||||
@Resource private TerminalDrayageMailService mails;
|
||||
|
||||
@PostMapping("/{containerBookingId}/pickup-email")
|
||||
@PreAuthorize("hasAuthority('platform:firstleg:terminal-drayage:fleet:edit')")
|
||||
public ApiResponse<View> sendPickupEmail(@AuthenticationPrincipal AuthenticatedUser user,
|
||||
@PathVariable @Positive long containerBookingId, @RequestHeader("Idempotency-Key") String key,
|
||||
@Valid @RequestBody com.baiyue.firstleg.terminaldrayage.dto.TerminalDrayageDtos.EmailRequest request) {
|
||||
@Valid @RequestBody EmailRequest request) {
|
||||
FirstlegScopeGuard.platform(user);
|
||||
return ApiResponse.success(service.authorize(service.sendPickupEmail(containerBookingId, user.userId(), user.username(), key, request), user.permissions()));
|
||||
}
|
||||
|
||||
@GetMapping("/{containerBookingId}/emails")
|
||||
@PreAuthorize("hasAuthority('platform:firstleg:terminal-drayage:list')")
|
||||
public ApiResponse<com.baiyue.firstleg.terminaldrayage.service.TerminalDrayageMailService.Mailbox> emails(
|
||||
public ApiResponse<Mailbox> emails(
|
||||
@AuthenticationPrincipal AuthenticatedUser user, @PathVariable @Positive long containerBookingId) {
|
||||
FirstlegScopeGuard.platform(user); service.detail(containerBookingId);
|
||||
return ApiResponse.success(mails.list(containerBookingId));
|
||||
|
||||
+3
-3
@@ -125,17 +125,17 @@ public interface TerminalDrayageMapper extends BaseMapper<TerminalDrayageEntity>
|
||||
@Param("kind") String kind, @Param("subject") String subject, @Param("body") String body,
|
||||
@Param("operatorId") long operatorId);
|
||||
|
||||
@Select("SELECT * FROM fl_terminal_drayage_mail WHERE container_booking_id=#{containerId} ORDER BY id DESC LIMIT 100")
|
||||
@Select("SELECT id,container_booking_id AS containerBookingId,fleet_supplier_id AS fleetSupplierId,fleet_name AS fleetName,recipient,kind,subject,body,status,attempts,failure_reason AS failureReason,created_at AS createdAt,sent_at AS sentAt FROM fl_terminal_drayage_mail WHERE container_booking_id=#{containerId} ORDER BY id DESC LIMIT 100")
|
||||
List<MailTask> mails(@Param("containerId") long containerId);
|
||||
|
||||
@Select("""
|
||||
SELECT * FROM fl_terminal_drayage_mail WHERE container_booking_id=#{containerId}
|
||||
SELECT id,container_booking_id AS containerBookingId,fleet_supplier_id AS fleetSupplierId,fleet_name AS fleetName,recipient,kind,subject,body,status,attempts,failure_reason AS failureReason,created_at AS createdAt,sent_at AS sentAt FROM fl_terminal_drayage_mail WHERE container_booking_id=#{containerId}
|
||||
AND fleet_supplier_id=#{supplierId} AND kind='REQUEST_PICKUP' ORDER BY id DESC LIMIT 1
|
||||
""")
|
||||
MailTask lastPickupMail(@Param("containerId") long containerId, @Param("supplierId") long supplierId);
|
||||
|
||||
@Select("""
|
||||
SELECT m.* FROM fl_terminal_drayage_mail m WHERE m.status='PENDING'
|
||||
SELECT m.id,m.container_booking_id AS containerBookingId,m.fleet_supplier_id AS fleetSupplierId,m.fleet_name AS fleetName,m.recipient,m.kind,m.subject,m.body,m.status,m.attempts,m.failure_reason AS failureReason,m.created_at AS createdAt,m.sent_at AS sentAt FROM fl_terminal_drayage_mail m WHERE m.status='PENDING'
|
||||
AND NOT EXISTS(SELECT 1 FROM fl_terminal_drayage_mail earlier
|
||||
WHERE earlier.container_booking_id=m.container_booking_id AND earlier.id<m.id AND earlier.status<>'SENT')
|
||||
ORDER BY m.id LIMIT 20
|
||||
|
||||
+1
-2
@@ -43,14 +43,13 @@ public class TerminalDrayageMailDispatcher {
|
||||
@Scheduled(fixedDelayString="${baiyue.terminal-drayage.mail.scan-delay:10000}")
|
||||
public void dispatch() {
|
||||
mapper.expireMails();
|
||||
var sender = sender();
|
||||
for (var mail : mapper.pendingMails()) {
|
||||
if (mapper.claimMail(mail.id()) != 1) continue;
|
||||
try {
|
||||
var message = new SimpleMailMessage();
|
||||
message.setFrom(from); message.setTo(mail.recipient());
|
||||
message.setSubject(mail.subject()); message.setText(mail.body());
|
||||
sender.send(message);
|
||||
sender().send(message);
|
||||
if (mapper.completeMail(mail.id()) != 1) log.warn("Terminal drayage mail completion requires review: {}", mail.id());
|
||||
} catch (Exception exception) {
|
||||
// SMTP 超时不等于未送达,禁止自动重发;失败阻断同柜后续邮件,交由人工核对。
|
||||
|
||||
+1
-1
@@ -60,7 +60,7 @@ public class TerminalDrayageMailService {
|
||||
|
||||
static void validateAddress(String email) {
|
||||
try {
|
||||
if (!StringUtils.hasText(email) || email.contains("\r") || email.contains("\n")) throw new IllegalArgumentException();
|
||||
if (!StringUtils.hasText(email) || email.length() > 254 || email.contains("\r") || email.contains("\n")) throw new IllegalArgumentException();
|
||||
InternetAddress[] parsed = InternetAddress.parse(email.trim(), true);
|
||||
if (parsed.length != 1 || parsed[0].isGroup() || !email.trim().equals(parsed[0].getAddress())) throw new IllegalArgumentException();
|
||||
parsed[0].validate();
|
||||
|
||||
+2
-1
@@ -20,6 +20,7 @@ import com.baiyue.firstleg.terminaldrayage.mapper.TerminalDrayageMapper.Context;
|
||||
import com.baiyue.firstleg.terminaldrayage.mapper.TerminalDrayageMapper.Operation;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.baiyue.firstleg.terminaldrayage.dto.TerminalDrayageDtos.EmailRequest;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -204,7 +205,7 @@ public class TerminalDrayageService {
|
||||
|
||||
@Transactional
|
||||
public View sendPickupEmail(long containerBookingId, long operatorId, String operatorName, String key,
|
||||
com.baiyue.firstleg.terminaldrayage.dto.TerminalDrayageDtos.EmailRequest request) {
|
||||
EmailRequest request) {
|
||||
String action = "SEND_PICKUP_EMAIL";
|
||||
WorkContext context = requiredLockedContext(containerBookingId);
|
||||
View replay = replay(context, action, key, request);
|
||||
|
||||
@@ -30,6 +30,16 @@ spring:
|
||||
size: ${FIRSTLEG_SCHEDULING_POOL_SIZE:5}
|
||||
thread-name-prefix: firstleg-scheduler-
|
||||
baiyue:
|
||||
terminal-drayage:
|
||||
mail:
|
||||
enabled: ${TERMINAL_DRAYAGE_MAIL_ENABLED:false}
|
||||
host: ${TERMINAL_DRAYAGE_MAIL_HOST:}
|
||||
port: ${TERMINAL_DRAYAGE_MAIL_PORT:587}
|
||||
username: ${TERMINAL_DRAYAGE_MAIL_USERNAME:}
|
||||
password: ${TERMINAL_DRAYAGE_MAIL_PASSWORD:}
|
||||
from: ${TERMINAL_DRAYAGE_MAIL_FROM:}
|
||||
ssl: ${TERMINAL_DRAYAGE_MAIL_SSL:false}
|
||||
scan-delay: ${TERMINAL_DRAYAGE_MAIL_SCAN_DELAY:10000}
|
||||
carrier-schedule:
|
||||
providers:
|
||||
matson-automated: ${MATSON_TRACKING_ENABLED:false}
|
||||
|
||||
@@ -2032,7 +2032,7 @@ components:
|
||||
allowedActions:
|
||||
type: array
|
||||
description: 已同时按真实业务状态与当前用户权限裁剪
|
||||
items: {type: string, enum: [EDIT_CONTAINER, MANAGE_CUSTOMS, CONFIRM_OUTBOUND, MANAGE_DESTINATION_DOCUMENTS, SELECT_FLEET, SCHEDULE_PICKUP, RECORD_PICKUP, RECORD_EMPTY_RETURN]}
|
||||
items: {type: string, enum: [EDIT_CONTAINER, MANAGE_CUSTOMS, CONFIRM_OUTBOUND, MANAGE_DESTINATION_DOCUMENTS, SELECT_FLEET, SCHEDULE_PICKUP, RECORD_PICKUP, RECORD_EMPTY_RETURN, SEND_PICKUP_EMAIL]}
|
||||
actualFacts: {$ref: '#/components/schemas/ContainerActualFacts'}
|
||||
terminalDrayage: {$ref: '#/components/schemas/ContainerTerminalDrayage'}
|
||||
ContainerWorkbenchStatusSummary:
|
||||
@@ -2079,7 +2079,7 @@ components:
|
||||
actualEmptyReturnAt: {type: string, format: date-time, nullable: true}
|
||||
unloadingCompletedAt: {type: string, format: date-time, nullable: true}
|
||||
emptyReturnWarning: {type: object, nullable: true}
|
||||
allowedActions: {type: array, items: {type: string, enum: [SELECT_FLEET, SCHEDULE_PICKUP, RECORD_PICKUP, RECORD_EMPTY_RETURN]}}
|
||||
allowedActions: {type: array, items: {type: string, enum: [SELECT_FLEET, SCHEDULE_PICKUP, RECORD_PICKUP, RECORD_EMPTY_RETURN, SEND_PICKUP_EMAIL]}}
|
||||
ContainerBooking:
|
||||
type: object
|
||||
required: [id, bookingNo, cabinetNo, sourceType, recordStatus, warehouseId, warehouseName, containerType, capacityCbm, maxWeightKg, planStatus, exceptionActive, destinationClearanceDocumentStatus, customsDeclarationDocumentStatus, deliveryOrderDocumentStatus, version]
|
||||
|
||||
@@ -88,16 +88,16 @@ paths:
|
||||
'200': {description: Original file bytes, content: {application/octet-stream: {schema: {type: string, format: binary}}}}
|
||||
/api/platform/v1/ocean-bookings/{oceanBookingId}/prints/shipping-instruction:
|
||||
get:
|
||||
summary: Render the released booking as an export shipping instruction PDF
|
||||
description: Firstleg maps the authoritative released aggregate to SEA_FREIGHT_SHIPPING_INSTRUCTION_A4_V1 and synchronously proxies the generated PDF.
|
||||
summary: Render the current saved booking as an export shipping instruction PDF
|
||||
description: Firstleg maps the authoritative saved aggregate (DRAFT or RELEASED, with missing fields displayed as —) to SEA_FREIGHT_SHIPPING_INSTRUCTION_A4_V1 and synchronously proxies the generated PDF.
|
||||
x-permission: platform:firstleg:ocean-booking:list
|
||||
parameters: [{$ref: '#/components/parameters/OceanBookingId'}]
|
||||
responses:
|
||||
'200': {description: PDF or a business-error JSON envelope, content: {application/pdf: {schema: {type: string, format: binary}}, application/json: {schema: {type: object}}}}
|
||||
/api/platform/v1/ocean-bookings/{oceanBookingId}/prints/bill-of-lading-confirmation:
|
||||
get:
|
||||
summary: Render the released booking as a bill-of-lading confirmation PDF
|
||||
description: Firstleg maps the authoritative released aggregate to BILL_OF_LADING_CONFIRMATION_A4_V1 and synchronously proxies the generated PDF.
|
||||
summary: Render the current saved booking as a bill-of-lading confirmation PDF
|
||||
description: Firstleg maps the authoritative saved aggregate (DRAFT or RELEASED, with missing fields displayed as —) to BILL_OF_LADING_CONFIRMATION_A4_V1 and synchronously proxies the generated PDF.
|
||||
x-permission: platform:firstleg:ocean-booking:list
|
||||
parameters: [{$ref: '#/components/parameters/OceanBookingId'}]
|
||||
responses:
|
||||
|
||||
@@ -52,11 +52,63 @@ paths:
|
||||
parameters: [{$ref: '#/components/parameters/ContainerBookingId'}, {$ref: '#/components/parameters/IdempotencyKey'}]
|
||||
requestBody: {required: true, content: {application/json: {schema: {$ref: '#/components/schemas/ActualTimeRequest'}}}}
|
||||
responses: {'200': {$ref: '#/components/responses/ViewResponse'}}
|
||||
/api/platform/v1/terminal-drayages/{containerBookingId}/pickup-email:
|
||||
post:
|
||||
summary: 将当前车队提柜邮件加入发送队列
|
||||
description: 初次选择车队不发信;此命令携带版本和幂等键,发送成功是任务已入队,不表示已送达。首次更换车队自动原子入队取消和新提柜两封邮件。同一车队重复选择不发信。
|
||||
x-permission: platform:firstleg:terminal-drayage:fleet:edit
|
||||
parameters: [{$ref: '#/components/parameters/ContainerBookingId'}, {$ref: '#/components/parameters/IdempotencyKey'}]
|
||||
requestBody: {required: true, content: {application/json: {schema: {type: object, required: [expectedVersion], properties: {expectedVersion: {type: integer, minimum: 0}}}}}}
|
||||
responses: {'200': {$ref: '#/components/responses/ViewResponse'}}
|
||||
/api/platform/v1/terminal-drayages/{containerBookingId}/emails:
|
||||
get:
|
||||
summary: 查询最近100封车队邮件及发信开关
|
||||
x-permission: platform:firstleg:terminal-drayage:list
|
||||
parameters: [{$ref: '#/components/parameters/ContainerBookingId'}]
|
||||
responses:
|
||||
'200':
|
||||
description: 邮件记录;SENT表示SMTP已接受,不表示收件人已阅读
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
code: {type: string}
|
||||
data:
|
||||
type: object
|
||||
properties:
|
||||
deliveryEnabled: {type: boolean}
|
||||
records: {type: array, items: {$ref: '#/components/schemas/EmailTask'}}
|
||||
/api/platform/v1/terminal-drayages/{containerBookingId}/emails/{mailId}/retry:
|
||||
post:
|
||||
summary: 核对失败邮件未收到后手动重试
|
||||
description: 仅FAILED状态可重试,服务端校验mailId归属本柜;失败可能已经送达,须人工核对。同柜邮件依次发送,失败阻断后续邮件。
|
||||
x-permission: platform:firstleg:terminal-drayage:fleet:edit
|
||||
parameters:
|
||||
- {$ref: '#/components/parameters/ContainerBookingId'}
|
||||
- {name: mailId, in: path, required: true, schema: {type: string, pattern: '^[1-9][0-9]*$'}}
|
||||
responses: {'200': {description: 已重新入队}}
|
||||
components:
|
||||
parameters:
|
||||
ContainerBookingId: {name: containerBookingId, in: path, required: true, schema: {type: string, pattern: '^[1-9][0-9]*$'}}
|
||||
IdempotencyKey: {name: Idempotency-Key, in: header, required: true, schema: {type: string, minLength: 1, maxLength: 255}}
|
||||
schemas:
|
||||
EmailTask:
|
||||
type: object
|
||||
properties:
|
||||
id: {type: string}
|
||||
containerBookingId: {type: string}
|
||||
fleetSupplierId: {type: string}
|
||||
fleetName: {type: string}
|
||||
recipient: {type: string, format: email}
|
||||
kind: {type: string, enum: [REQUEST_PICKUP, CANCEL_PICKUP]}
|
||||
subject: {type: string}
|
||||
body: {type: string}
|
||||
status: {type: string, enum: [PENDING, SENDING, SENT, FAILED]}
|
||||
attempts: {type: integer}
|
||||
failureReason: {type: string, nullable: true}
|
||||
createdAt: {type: string, format: date-time}
|
||||
sentAt: {type: string, format: date-time, nullable: true}
|
||||
FleetSelectionRequest:
|
||||
type: object
|
||||
required: [expectedVersion, fleetSupplierId]
|
||||
@@ -104,7 +156,7 @@ components:
|
||||
actualEmptyReturnAt: {type: string, format: date-time, nullable: true}
|
||||
unloadingCompletedAt: {type: string, format: date-time, nullable: true}
|
||||
emptyReturnWarning: {$ref: '#/components/schemas/Warning'}
|
||||
allowedActions: {type: array, items: {type: string, enum: [SELECT_FLEET, SCHEDULE_PICKUP, RECORD_PICKUP, RECORD_EMPTY_RETURN]}}
|
||||
allowedActions: {type: array, items: {type: string, enum: [SELECT_FLEET, SCHEDULE_PICKUP, RECORD_PICKUP, RECORD_EMPTY_RETURN, SEND_PICKUP_EMAIL]}}
|
||||
actualFacts: {$ref: '#/components/schemas/ContainerActualFacts'}
|
||||
updatedAt: {type: string, format: date-time, nullable: true}
|
||||
ContainerActualFacts:
|
||||
@@ -127,7 +179,7 @@ components:
|
||||
type: object
|
||||
required: [action, fromStatus, toStatus, fromVersion, toVersion, operatorId, createdAt]
|
||||
properties:
|
||||
action: {type: string, enum: [SELECT_FLEET, SCHEDULE_PICKUP, RECORD_PICKUP, RECORD_EMPTY_RETURN]}
|
||||
action: {type: string, enum: [SELECT_FLEET, SCHEDULE_PICKUP, RECORD_PICKUP, RECORD_EMPTY_RETURN, SEND_PICKUP_EMAIL]}
|
||||
fromStatus: {type: string}
|
||||
toStatus: {type: string}
|
||||
fromVersion: {type: integer, minimum: 0}
|
||||
|
||||
Reference in New Issue
Block a user