|
|
|
@@ -31,6 +31,8 @@ import com.baiyue.lastleg.mapper.LastlegOrderOperationLogMapper;
|
|
|
|
|
import com.baiyue.lastleg.mapper.LastlegOrderManualNodeMapper;
|
|
|
|
|
import com.baiyue.lastleg.mapper.ReceivingWarehouseOperationMapper;
|
|
|
|
|
import com.baiyue.lastleg.model.LastlegOrderType;
|
|
|
|
|
import com.baiyue.lastleg.shipping.entity.ContainerShippingGate;
|
|
|
|
|
import com.baiyue.lastleg.shipping.mapper.ContainerShippingGateMapper;
|
|
|
|
|
import jakarta.annotation.Resource;
|
|
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
@@ -74,12 +76,16 @@ public class LastlegOrderService {
|
|
|
|
|
@Resource private InboundOrderDetainedOutboxService detainedOutbox;
|
|
|
|
|
@Resource private ReceivingWarehouseOperationMapper receivingWarehouseOperations;
|
|
|
|
|
@Resource private WarehouseResourceGateway warehouseResourceGateway;
|
|
|
|
|
@Resource private ContainerShippingGateMapper containerShippingGates;
|
|
|
|
|
|
|
|
|
|
public PageResult<LastlegOrderSummary> page(String customerId, LastlegOrderRequests.Query query) {
|
|
|
|
|
Page<LastlegOrder> page = orderMapper.selectPage(
|
|
|
|
|
new Page<>(query.page(), query.size()), filter(customerId, query).orderByDesc(LastlegOrder::getCreatedAt));
|
|
|
|
|
Map<Long, List<LastlegOrderMapper.PalletMergeRelationRow>> mergeRelations = palletMergeRelations(page.getRecords());
|
|
|
|
|
return new PageResult<>(page.getRecords().stream().map(order -> summary(order, mergeRelations.get(order.getId()))).toList(),
|
|
|
|
|
Map<String, String> containerNodes = containerNodes(page.getRecords());
|
|
|
|
|
return new PageResult<>(page.getRecords().stream().map(order -> summary(order, mergeRelations.get(order.getId()),
|
|
|
|
|
StringUtils.hasText(order.getSourceContainerBookingId())
|
|
|
|
|
? containerNodes.get(order.getSourceContainerBookingId()) : null)).toList(),
|
|
|
|
|
page.getCurrent(), page.getSize(), page.getTotal(), page.getPages());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -261,7 +267,8 @@ public class LastlegOrderService {
|
|
|
|
|
.map(value -> new LastlegOrderCommandDtos.ManualNodeView(
|
|
|
|
|
value.getNodeCode(), value.getNodeAt(), value.getSource()))
|
|
|
|
|
.sorted(java.util.Comparator.comparingInt(value -> MANUAL_NODE_CODES.indexOf(value.nodeCode()))).toList();
|
|
|
|
|
return new LastlegOrderDetailResponse(summary(order, palletMergeRelations(List.of(order)).get(order.getId())), manualNodes, cargo, history.stream()
|
|
|
|
|
return new LastlegOrderDetailResponse(summary(order, palletMergeRelations(List.of(order)).get(order.getId()),
|
|
|
|
|
containerNode(order)), manualNodes, cargo, history.stream()
|
|
|
|
|
.map(value -> new LastlegOrderDetailResponse.History(value.getId(), value.getFromStatus(),
|
|
|
|
|
value.getToStatus(), value.getRemark(), value.getCreatedAt())).toList(), fees, operations.stream()
|
|
|
|
|
.map(value -> new LastlegOrderDetailResponse.Operation(value.getId(), value.getOperationNode(),
|
|
|
|
@@ -480,20 +487,22 @@ public class LastlegOrderService {
|
|
|
|
|
|
|
|
|
|
public void writeExportCsv(String customerId, LastlegOrderRequests.Query query, OutputStream output)
|
|
|
|
|
throws IOException {
|
|
|
|
|
output.write("\uFEFFID,尾程单号,订单类型,入仓码,头程单号,货主,海外仓,转仓,转仓编码,FBA仓库,集装箱号,货柜状态,是否异常,是否暂扣,托数,箱数,体积(m3),数量,体积重量,预计到港时间,实际到港时间,预计到仓,入库单号,换标单号,换标状态,合托标记,主流程状态,子单状态,备注(仅自己),备注(客户),备注(仓库)\r\n".getBytes(StandardCharsets.UTF_8));
|
|
|
|
|
output.write("\uFEFFID,尾程单号,订单类型,入仓码,头程单号,货主,海外仓,转仓,转仓编码,FBA仓库,集装箱号,货柜节点,是否异常,是否暂扣,托数,箱数,体积(m3),数量,体积重量,预计到港时间,实际到港时间,预计到仓,入库单号,换标单号,换标状态,合托标记,主流程状态,子单状态,备注(仅自己),备注(客户),备注(仓库)\r\n".getBytes(StandardCharsets.UTF_8));
|
|
|
|
|
final int batchSize = 1000;
|
|
|
|
|
long page = 1;
|
|
|
|
|
while (true) {
|
|
|
|
|
List<LastlegOrder> orders = orderMapper.selectPage(new com.baomidou.mybatisplus.extension.plugins.pagination.Page<>(page, batchSize),
|
|
|
|
|
filter(customerId, query).orderByDesc(LastlegOrder::getCreatedAt).orderByDesc(LastlegOrder::getId)).getRecords();
|
|
|
|
|
if (orders.isEmpty()) break;
|
|
|
|
|
Map<String, String> containerNodes = containerNodes(orders);
|
|
|
|
|
for (LastlegOrder order : orders) {
|
|
|
|
|
String line = String.join(",", List.of(
|
|
|
|
|
csv(order.getId()), csv(order.getOrderNo()), csv(LastlegOrderType.labelOf(order.getOrderType())),
|
|
|
|
|
csv(displayInboundCode(order)),
|
|
|
|
|
csv(order.getSourceOrderNo()), csv(order.getCustomerName()), csv(order.getOverseasWarehouseName()),
|
|
|
|
|
csv(order.getTransferWarehouseName()), csv(order.getTransferWarehouseCode()), csv(order.getFbaWarehouseCode()),
|
|
|
|
|
csv(order.getContainerNo()), csv(order.getContainerStatus()), csv(order.getAbnormal()), csv(order.getDetained()),
|
|
|
|
|
csv(order.getContainerNo()), csv(StringUtils.hasText(order.getSourceContainerBookingId())
|
|
|
|
|
? containerNodes.get(order.getSourceContainerBookingId()) : null), csv(order.getAbnormal()), csv(order.getDetained()),
|
|
|
|
|
csv(order.getPalletCount()), csv(order.getPackageCount()), csv(order.getVolumeCbm()), csv(order.getProductQuantity()),
|
|
|
|
|
csv(order.getVolumeWeightKg()), csv(order.getEstimatedArrivalAt()), csv(order.getActualArrivalAt()),
|
|
|
|
|
csv(order.getEstimatedWarehouseAt()), csv(order.getInboundOrderNo()), csv(order.getRelabelOrderNo()), csv(order.getRelabelStatus()),
|
|
|
|
@@ -558,13 +567,14 @@ public class LastlegOrderService {
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private LastlegOrderSummary summary(LastlegOrder o, List<LastlegOrderMapper.PalletMergeRelationRow> relations) {
|
|
|
|
|
private LastlegOrderSummary summary(LastlegOrder o, List<LastlegOrderMapper.PalletMergeRelationRow> relations,
|
|
|
|
|
String containerNode) {
|
|
|
|
|
List<LastlegOrderMapper.PalletMergeRelationRow> related = relations == null ? List.of() : relations;
|
|
|
|
|
return new LastlegOrderSummary(o.getId(), o.getOrderNo(), o.getOrderType(),
|
|
|
|
|
LastlegOrderType.labelOf(o.getOrderType()), o.getDestinationType(), o.getSourceInboundId(),
|
|
|
|
|
displayInboundCode(o), o.getLxCode(), o.getSourceOrderNo(), o.getCustomerId(), o.getCustomerName(), o.getOverseasWarehouseId(),
|
|
|
|
|
o.getOverseasWarehouseCode(), o.getOverseasWarehouseName(), o.getTransferWarehouseId(), o.getTransferWarehouseCode(),
|
|
|
|
|
o.getTransferWarehouseName(), o.getFbaWarehouseCode(), o.getContainerNo(), o.getContainerStatus(),
|
|
|
|
|
o.getTransferWarehouseName(), o.getFbaWarehouseCode(), o.getContainerNo(), containerNode,
|
|
|
|
|
o.getAbnormal(), o.getDetained(), o.getHoldChargeable(), o.getHoldReason(),
|
|
|
|
|
Boolean.TRUE.equals(o.getManualNodeOverride()), Boolean.TRUE.equals(o.getManualNodeOverride()) ? "MANUAL" : "CONTAINER",
|
|
|
|
|
o.getVersion() == null ? 0 : o.getVersion(), o.getPalletCount(), o.getPackageCount(), o.getVolumeCbm(),
|
|
|
|
@@ -576,6 +586,25 @@ public class LastlegOrderService {
|
|
|
|
|
o.getCustomerRemark(), o.getWarehouseRemark(), o.getCreatedAt(), o.getUpdatedAt());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String containerNode(LastlegOrder order) {
|
|
|
|
|
if (!StringUtils.hasText(order.getSourceContainerBookingId())) return null;
|
|
|
|
|
ContainerShippingGate gate = containerShippingGates.selectById(order.getSourceContainerBookingId());
|
|
|
|
|
return gate == null ? null : gate.getStandardNode();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Map<String, String> containerNodes(List<LastlegOrder> orders) {
|
|
|
|
|
List<String> bookingIds = orders.stream().map(LastlegOrder::getSourceContainerBookingId)
|
|
|
|
|
.filter(StringUtils::hasText).distinct().toList();
|
|
|
|
|
if (bookingIds.isEmpty()) return Map.of();
|
|
|
|
|
Map<String, String> result = new LinkedHashMap<>();
|
|
|
|
|
containerShippingGates.selectBatchIds(bookingIds).forEach(gate -> {
|
|
|
|
|
if (StringUtils.hasText(gate.getStandardNode())) {
|
|
|
|
|
result.put(gate.getContainerBookingId(), gate.getStandardNode());
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static String displayInboundCode(LastlegOrder order) {
|
|
|
|
|
String orderType = order.getOrderType();
|
|
|
|
|
return "RELABEL_APPLICATION".equals(orderType) || "LOCAL_LOOSEBOARD".equals(orderType)
|
|
|
|
|