fix(lastleg): restore dispatch returns from immutable pick source and expose customer receipts

This commit is contained in:
2026-09-30 12:09:19 +08:00
parent c7f880300c
commit 4a14001a09
11 changed files with 293 additions and 9 deletions
@@ -5,20 +5,24 @@ import com.baiyue.common.core.api.PageResult;
import com.baiyue.common.security.AuthenticatedUser;
import com.baiyue.lastleg.delivery.dto.DeliveryRequests;
import com.baiyue.lastleg.delivery.dto.DeliveryResponses;
import com.baiyue.lastleg.delivery.dto.DeliveryDocumentDtos;
import com.baiyue.lastleg.delivery.service.DeliveryDocumentService;
import com.baiyue.lastleg.delivery.service.DeliveryTransferService;
import com.baiyue.lastleg.security.OverseasPermissions;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.http.HttpStatus;
import org.springframework.http.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.server.ResponseStatusException;
import java.nio.charset.StandardCharsets;
@RestController
@RequestMapping("/api/merchant/v1/last-leg/delivery-orders")
public class MerchantDeliveryController {
@Resource private DeliveryTransferService service;
@Resource private DeliveryDocumentService documents;
@GetMapping
@PreAuthorize("hasAuthority('" + OverseasPermissions.MERCHANT_DELIVERY_LIST + "')")
@@ -42,9 +46,29 @@ public class MerchantDeliveryController {
return ApiResponse.success(service.deliveryDetail(customer(user), deliveryNo));
}
@GetMapping("/{deliveryNo}/documents/receipt")
@PreAuthorize("hasAuthority('" + OverseasPermissions.MERCHANT_DELIVERY_LIST + "')")
public ApiResponse<DeliveryDocumentDtos.MerchantReceipts> receipts(
@AuthenticationPrincipal AuthenticatedUser user, @PathVariable String deliveryNo) {
return ApiResponse.success(documents.merchantReceipts(customer(user), deliveryNo));
}
@GetMapping("/{deliveryNo}/documents/receipt/files/{fileId}/download")
@PreAuthorize("hasAuthority('" + OverseasPermissions.MERCHANT_DELIVERY_LIST + "')")
public ResponseEntity<byte[]> receiptDownload(@AuthenticationPrincipal AuthenticatedUser user,
@PathVariable String deliveryNo, @PathVariable long fileId) {
DeliveryDocumentService.Download downloaded = documents.merchantReceiptDownload(customer(user), deliveryNo, fileId);
return ResponseEntity.ok().cacheControl(CacheControl.noStore())
.contentType(MediaType.APPLICATION_OCTET_STREAM)
.header("X-Content-Type-Options", "nosniff")
.header(HttpHeaders.CONTENT_DISPOSITION, ContentDisposition.attachment()
.filename(downloaded.file().fileName(), StandardCharsets.UTF_8).build().toString())
.body(downloaded.content());
}
private String customer(AuthenticatedUser user) {
if (user == null || user.tenantId() == null) throw new ResponseStatusException(HttpStatus.UNAUTHORIZED);
if ("PLATFORM".equals(user.appCode()) || user.tenantId() == 0L) throw new ResponseStatusException(HttpStatus.FORBIDDEN, "Merchant identity is required");
if (!"MERCHANT".equals(user.appCode()) || user.tenantId() <= 0L) throw new ResponseStatusException(HttpStatus.FORBIDDEN, "Merchant identity is required");
return String.valueOf(user.tenantId());
}
private String operator(AuthenticatedUser user) { return user.userId() == null ? user.username() : String.valueOf(user.userId()); }