修改提交
This commit is contained in:
+1
@@ -14,6 +14,7 @@ import java.time.LocalDateTime;
|
||||
public class LocalLooseboardOrder {
|
||||
@TableId(type = IdType.INPUT) private Long id;
|
||||
private String customerId;
|
||||
private Long lastlegOrderId;
|
||||
private String orderNo;
|
||||
private String transportMode;
|
||||
private String palletRequired;
|
||||
|
||||
+65
@@ -4,12 +4,17 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baiyue.common.core.api.PageResult;
|
||||
import com.baiyue.lastleg.entity.LastlegOrder;
|
||||
import com.baiyue.lastleg.entity.LastlegOrderStatusHistory;
|
||||
import com.baiyue.lastleg.mapper.LastlegOrderMapper;
|
||||
import com.baiyue.lastleg.mapper.LastlegOrderStatusHistoryMapper;
|
||||
import com.baiyue.lastleg.looseboard.dto.LocalLooseboardRequests;
|
||||
import com.baiyue.lastleg.looseboard.dto.LocalLooseboardResponses;
|
||||
import com.baiyue.lastleg.looseboard.entity.LocalLooseboardHistory;
|
||||
import com.baiyue.lastleg.looseboard.entity.LocalLooseboardOrder;
|
||||
import com.baiyue.lastleg.looseboard.mapper.LocalLooseboardHistoryMapper;
|
||||
import com.baiyue.lastleg.looseboard.mapper.LocalLooseboardOrderMapper;
|
||||
import com.baiyue.lastleg.service.LastlegOrderNoGenerator;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
@@ -46,6 +51,9 @@ public class LocalLooseboardService {
|
||||
|
||||
@Resource private LocalLooseboardOrderMapper orders;
|
||||
@Resource private LocalLooseboardHistoryMapper histories;
|
||||
@Resource private LastlegOrderMapper lastlegOrders;
|
||||
@Resource private LastlegOrderStatusHistoryMapper lastlegHistories;
|
||||
@Resource private LastlegOrderNoGenerator lastlegOrderNoGenerator;
|
||||
@Resource private ObjectMapper objectMapper;
|
||||
|
||||
@Transactional
|
||||
@@ -71,6 +79,8 @@ public class LocalLooseboardService {
|
||||
order.setVersion(0L);
|
||||
order.setCreatedAt(now);
|
||||
order.setUpdatedAt(now);
|
||||
LastlegOrder lastlegOrder = createLastlegOrder(order, requestHash, now);
|
||||
order.setLastlegOrderId(lastlegOrder.getId());
|
||||
try {
|
||||
orders.insert(order);
|
||||
} catch (DuplicateKeyException exception) {
|
||||
@@ -79,6 +89,8 @@ public class LocalLooseboardService {
|
||||
throw exception;
|
||||
}
|
||||
history(order, "CREATE", null, PENDING_ACCEPTANCE, operatorId, null, request.remark(), now);
|
||||
lastlegHistory(customerId, lastlegOrder.getId(), null, lastlegOrder.getCurrentStatus(),
|
||||
"Local looseboard order submitted", now);
|
||||
return detail(customerId, order.getOrderNo());
|
||||
}
|
||||
|
||||
@@ -147,6 +159,7 @@ public class LocalLooseboardService {
|
||||
order.setStatus(next);
|
||||
touch(order, now);
|
||||
orders.updateById(order);
|
||||
syncLastlegOrder(order, next, now);
|
||||
history(order, "STATUS", from, next, operatorId, null, request.remark(), now);
|
||||
return response(order);
|
||||
}
|
||||
@@ -220,6 +233,58 @@ public class LocalLooseboardService {
|
||||
histories.insert(history);
|
||||
}
|
||||
|
||||
private LastlegOrder createLastlegOrder(LocalLooseboardOrder source, String requestHash, LocalDateTime now) {
|
||||
LastlegOrder order = new LastlegOrder();
|
||||
order.setId(IdWorker.getId());
|
||||
order.setOrderNo(lastlegOrderNoGenerator.next());
|
||||
order.setCustomerId(source.getCustomerId());
|
||||
order.setOrderType("LOCAL_LOOSEBOARD");
|
||||
order.setInboundCode(source.getOrderNo());
|
||||
order.setSourceRegion("OVERSEAS_LOCAL");
|
||||
order.setSourceInboundId("LOCAL_LOOSEBOARD:" + source.getId());
|
||||
order.setSourceOrderId(String.valueOf(source.getId()));
|
||||
order.setSourceOrderNo(source.getOrderNo());
|
||||
order.setPalletCount(0);
|
||||
order.setPackageCount(Objects.requireNonNullElse(source.getPackageCount(), 0));
|
||||
order.setPickedPackageCount(0);
|
||||
order.setShippedPackageCount(0);
|
||||
order.setVolumeCbm(source.getTotalVolumeCbm());
|
||||
order.setCurrentStatus("PENDING_ASSIGNMENT");
|
||||
order.setSubOrderStatus("LOCAL_LOOSEBOARD:" + PENDING_ACCEPTANCE);
|
||||
order.setCustomerRemark(source.getRemark());
|
||||
order.setSourceEventId("LOCAL_LOOSEBOARD:" + source.getId());
|
||||
order.setSourceLoadingPlanId("LOCAL_LOOSEBOARD");
|
||||
order.setSourcePayloadHash("sha256:" + requestHash);
|
||||
order.setCreatedAt(now);
|
||||
order.setUpdatedAt(now);
|
||||
lastlegOrders.insert(order);
|
||||
return order;
|
||||
}
|
||||
|
||||
private void syncLastlegOrder(LocalLooseboardOrder source, String status, LocalDateTime now) {
|
||||
if (source.getLastlegOrderId() == null) return;
|
||||
LastlegOrder order = lastlegOrders.selectById(source.getLastlegOrderId());
|
||||
if (order == null || !source.getCustomerId().equals(order.getCustomerId())) {
|
||||
throw conflict("Linked tail-leg order is missing");
|
||||
}
|
||||
order.setSubOrderStatus("LOCAL_LOOSEBOARD:" + status);
|
||||
order.setUpdatedAt(now);
|
||||
lastlegOrders.updateById(order);
|
||||
}
|
||||
|
||||
private void lastlegHistory(String customerId, Long orderId, String from, String to, String remark,
|
||||
LocalDateTime now) {
|
||||
LastlegOrderStatusHistory history = new LastlegOrderStatusHistory();
|
||||
history.setCustomerId(customerId);
|
||||
history.setOrderId(orderId);
|
||||
history.setFromStatus(from);
|
||||
history.setToStatus(to);
|
||||
history.setEventId("LOCAL_LOOSEBOARD");
|
||||
history.setRemark(remark);
|
||||
history.setCreatedAt(now);
|
||||
lastlegHistories.insert(history);
|
||||
}
|
||||
|
||||
private void validateQuery(LocalLooseboardRequests.Query query) {
|
||||
if (StringUtils.hasText(query.status()) && !STATUSES.contains(norm(query.status()))) {
|
||||
throw badRequest("Unsupported looseboard order status");
|
||||
|
||||
Reference in New Issue
Block a user