feat(firstleg): count actionable customer customs cabinets
This commit is contained in:
+6
@@ -26,6 +26,12 @@ import java.util.List;
|
||||
public class MerchantContainerCustomsController {
|
||||
@Resource private ContainerCustomsService service;
|
||||
|
||||
@GetMapping("/pending-summary")
|
||||
@PreAuthorize("hasAuthority('merchant:order:view')")
|
||||
public ApiResponse<PendingSummary> pendingSummary(@AuthenticationPrincipal AuthenticatedUser user) {
|
||||
return ApiResponse.success(service.merchantPendingSummary(FirstlegScopeGuard.merchant(user)));
|
||||
}
|
||||
|
||||
@GetMapping("/orders/{orderId}")
|
||||
@PreAuthorize("hasAuthority('merchant:order:view')")
|
||||
public ApiResponse<ContainerView> order(@AuthenticationPrincipal AuthenticatedUser user,
|
||||
|
||||
+1
@@ -74,4 +74,5 @@ public final class ContainerCustomsDtos {
|
||||
@Size(max = 1000) String resolution) {}
|
||||
|
||||
public record Download(String fileName, String contentType, byte[] content) {}
|
||||
public record PendingSummary(long pendingCount) {}
|
||||
}
|
||||
|
||||
+36
@@ -87,6 +87,42 @@ public interface ContainerCustomsMapper {
|
||||
""")
|
||||
Long completedPlanForOrder(@Param("tenantId") long tenantId, @Param("orderId") long orderId);
|
||||
|
||||
/** One customer action badge per actual loaded cabinet, including receipt confirmation. */
|
||||
@Select("""
|
||||
SELECT COUNT(DISTINCT p.container_booking_id)
|
||||
FROM fl_loading_plan p
|
||||
JOIN fl_container_booking b ON b.id=p.container_booking_id AND b.record_status='ACTIVE'
|
||||
JOIN fl_loading_plan_item item ON item.loading_plan_id=p.id AND item.deleted=0
|
||||
JOIN fl_inbound_order i ON i.id=item.inbound_id AND i.tenant_id=item.account_id AND i.deleted=0
|
||||
LEFT JOIN fl_customs_container c ON c.loading_plan_id=p.id
|
||||
WHERE p.plan_status='COMPLETED' AND i.tenant_id=#{tenantId} AND i.tax_mode='TAX_REFUND'
|
||||
AND
|
||||
""" + ACTUAL_ITEM_SCOPE + """
|
||||
AND p.id=(
|
||||
SELECT latest.id FROM fl_loading_plan latest
|
||||
JOIN fl_loading_plan_item item ON item.loading_plan_id=latest.id AND item.deleted=0
|
||||
JOIN fl_inbound_order own ON own.id=item.inbound_id AND own.tenant_id=item.account_id AND own.deleted=0
|
||||
WHERE latest.plan_status='COMPLETED' AND own.tenant_id=i.tenant_id AND own.order_id=i.order_id
|
||||
AND own.tax_mode='TAX_REFUND' AND
|
||||
""" + ACTUAL_ITEM_SCOPE + """
|
||||
ORDER BY COALESCE(latest.confirmed_at,latest.updated_at) DESC,latest.id DESC LIMIT 1
|
||||
)
|
||||
AND (
|
||||
((c.id IS NULL OR c.status IN ('WAITING_CUSTOMER_DOCUMENTS','READY_TO_START')) AND NOT EXISTS (
|
||||
SELECT 1 FROM fl_customs_customer_document_inbound scope
|
||||
JOIN fl_customs_customer_document d ON d.id=scope.document_id AND d.status='ACTIVE'
|
||||
WHERE d.customs_container_id=c.id AND d.tenant_id=i.tenant_id
|
||||
AND scope.tenant_id=i.tenant_id AND scope.inbound_id=i.id))
|
||||
OR (c.status='DECLARING' AND EXISTS (
|
||||
SELECT 1 FROM fl_customs_customer_document d
|
||||
JOIN fl_customs_customer_document_inbound scope ON scope.document_id=d.id AND scope.tenant_id=d.tenant_id
|
||||
JOIN fl_customs_completion_document receipt ON receipt.source_document_id=d.id
|
||||
WHERE d.customs_container_id=c.id AND d.tenant_id=i.tenant_id AND d.status='ACTIVE'
|
||||
AND d.frozen_at IS NOT NULL AND scope.inbound_id=i.id AND receipt.customer_confirm_status='PENDING'))
|
||||
)
|
||||
""")
|
||||
long merchantPendingCount(@Param("tenantId") long tenantId);
|
||||
|
||||
@Insert("""
|
||||
INSERT INTO fl_customs_container
|
||||
(id,loading_plan_id,container_booking_id,status,created_at,updated_at,version)
|
||||
|
||||
+5
@@ -44,6 +44,11 @@ public class ContainerCustomsService {
|
||||
@Resource private ApplicationEventPublisher events;
|
||||
@Value("${baiyue.security.internal-service-token}") private String internalToken;
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public PendingSummary merchantPendingSummary(long tenantId) {
|
||||
return new PendingSummary(mapper.merchantPendingCount(tenantId));
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public ContainerView platformView(long planId) {
|
||||
List<InboundRow> rows = actualPlanRows(planId);
|
||||
|
||||
Reference in New Issue
Block a user