This commit is contained in:
2026-09-15 20:52:02 +08:00
parent 4b671bb0ab
commit 8b19085bc4
24 changed files with 387 additions and 38 deletions
@@ -13,6 +13,7 @@ import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestClient;
import org.springframework.web.client.RestClientException;
import org.springframework.web.server.ResponseStatusException;
@Component
@@ -32,24 +33,36 @@ public class HttpDomesticLoadingEvidenceGateway implements DomesticLoadingEviden
@Override
public DownloadedFile download(long containerBookingId, long fileId) {
ResponseEntity<byte[]> response = client.get()
.uri("/internal/file/v1/loading-evidence/{containerBookingId}/{fileId}/content",
containerBookingId, fileId)
.header("X-Internal-Service-Token", internalToken).retrieve()
.onStatus(HttpStatusCode::is4xxClientError, (request, result) -> {
throw new ResponseStatusException(result.getStatusCode().value() == 404
? HttpStatus.NOT_FOUND : HttpStatus.BAD_REQUEST, "国内装柜照片不可用");
})
.onStatus(HttpStatusCode::is5xxServerError, (request, result) -> {
throw new ResponseStatusException(HttpStatus.SERVICE_UNAVAILABLE, "国内装柜照片暂时无法加载");
}).toEntity(byte[].class);
ResponseEntity<byte[]> response;
try {
response = client.get()
.uri("/internal/file/v1/loading-evidence/{containerBookingId}/{fileId}/content",
containerBookingId, fileId)
.header("X-Internal-Service-Token", internalToken).retrieve()
.onStatus(HttpStatusCode::is4xxClientError, (request, result) -> {
throw new ResponseStatusException(result.getStatusCode().value() == 404
? HttpStatus.NOT_FOUND : HttpStatus.BAD_REQUEST, "国内装柜照片不可用");
})
.onStatus(HttpStatusCode::is5xxServerError, (request, result) -> {
throw new ResponseStatusException(HttpStatus.SERVICE_UNAVAILABLE, "国内装柜照片暂时无法加载");
}).toEntity(byte[].class);
} catch (ResponseStatusException exception) {
throw exception;
} catch (RestClientException exception) {
throw new ResponseStatusException(HttpStatus.SERVICE_UNAVAILABLE,
"国内装柜照片暂时无法加载", exception);
}
byte[] content = response.getBody() == null ? new byte[0] : response.getBody();
MediaType mediaType = response.getHeaders().getContentType();
if (content.length == 0 || mediaType == null || !"image".equalsIgnoreCase(mediaType.getType())) {
throw new ResponseStatusException(HttpStatus.SERVICE_UNAVAILABLE,
"国内装柜照片返回内容无效");
}
String disposition = response.getHeaders().getFirst(HttpHeaders.CONTENT_DISPOSITION);
String fileName = null;
try { fileName = disposition == null ? null : ContentDisposition.parse(disposition).getFilename(); }
catch (IllegalArgumentException ignored) { }
String contentType = response.getHeaders().getContentType() == null
? MediaType.APPLICATION_OCTET_STREAM_VALUE : response.getHeaders().getContentType().toString();
String contentType = mediaType.toString();
return new DownloadedFile(content, fileName == null ? fileId + ".bin" : fileName, contentType);
}
}
@@ -134,8 +134,10 @@ public class InboundPlanService {
requiredReceivingWarehouse(containerWarehouseId);
validateOrders(snapshots);
String orderType = trimToNull(orderMapper.findOrderType(customerId, request.orderId()));
List<DropshipPalletSnapshot> dropshipPalletSnapshots = "ONE_CLICK_DROPSHIP".equals(orderType)
? dropshipOrders.palletSnapshots(customerId, request.orderId()) : List.of();
int sourcePalletCount = "ONE_CLICK_DROPSHIP".equals(orderType)
? dropshipOrders.palletSnapshots(customerId, request.orderId()).size()
? dropshipPalletSnapshots.size()
: Objects.requireNonNullElse(
sourcePalletMapper.palletNos(customerId, request.orderId()), List.<String>of()).size();
if ("ONE_CLICK_DROPSHIP".equals(orderType)) {
@@ -154,7 +156,9 @@ public class InboundPlanService {
throw new ResponseStatusException(HttpStatus.BAD_REQUEST,
"人工计划托数不能少于柜级预览建议托数 " + minimumPalletCount);
}
InboundPlanResponse response = createPlan(customerId, request.orderId(), snapshots, List.of(), null,
List<WholePalletInput> wholePallets = "ONE_CLICK_DROPSHIP".equals(orderType)
? dropshipPalletSnapshots.stream().map(this::wholePallet).toList() : null;
InboundPlanResponse response = createPlan(customerId, request.orderId(), snapshots, List.of(), wholePallets,
request, receivingWarehouse, plannedArrivalDate);
LastlegOrderCommandRecord command = new LastlegOrderCommandRecord();
command.setId(IdWorker.getId()); command.setCustomerId(customerId); command.setOrderId(request.orderId());
@@ -500,7 +504,7 @@ public class InboundPlanService {
lineByOrder.values().forEach(lineMapper::insert);
Map<Long, Integer> palletCounts;
if (manual != null) {
if (manual != null && wholePallets == null) {
createManualPallets(plan, orders.get(0), lineByOrder.get(orders.get(0).orderId()), manual);
palletCounts = Map.of(orders.get(0).orderId(), manual.palletCount());
} else if (wholePallets == null) {
@@ -512,7 +516,8 @@ public class InboundPlanService {
item -> item.pallet().sequenceNo(), Collectors.toSet()), java.util.Set::size)));
} else {
SourceOrderSnapshot order = orders.get(0);
createWholePallets(plan, order, lineByOrder.get(order.orderId()), wholePallets, reservedPallets);
createWholePallets(plan, order, lineByOrder.get(order.orderId()), wholePallets, reservedPallets,
manual == null ? null : manual.palletType());
palletCounts = Map.of(order.orderId(), wholePallets.size());
}
for (SourceOrderSnapshot order : orders) {
@@ -804,7 +809,8 @@ public class InboundPlanService {
private void createWholePallets(InboundPlan plan, SourceOrderSnapshot order, InboundPlanLine line,
List<WholePalletInput> sourcePallets,
Map<Integer, WarehouseResourceGateway.PalletBatchItem> reservedPallets) {
Map<Integer, WarehouseResourceGateway.PalletBatchItem> reservedPallets,
String palletType) {
BigDecimal remainingVolume = volume(order);
int remainingPackages = order.packageCount();
for (int index = 0; index < sourcePallets.size(); index++) {
@@ -816,6 +822,7 @@ public class InboundPlanService {
InboundPlanPallet pallet = new InboundPlanPallet();
pallet.setId(IdWorker.getId()); pallet.setCustomerId(plan.getCustomerId()); pallet.setPlanId(plan.getId());
pallet.setPalletNo(source.palletNo().trim()); pallet.setSourcePalletNo(source.palletNo().trim());
pallet.setPalletType(trimToNull(palletType) == null ? null : palletType.trim().toUpperCase());
pallet.setDestinationWarehouseId(order.destinationWarehouseId());
pallet.setDestinationWarehouseCode(order.destinationWarehouseCode());
pallet.setDestinationWarehouseName(order.destinationWarehouseName());