fix: finalize smart dispatch drafts

This commit is contained in:
2026-09-07 15:54:10 +08:00
parent 1b47158770
commit ff2b02b102
4 changed files with 54 additions and 3 deletions
@@ -24,6 +24,7 @@ public class DispatchPalletLock {
private Long planPalletId;
private Long warehousePalletId;
private Long dispatchOrderId;
@TableField(updateStrategy = FieldStrategy.ALWAYS)
private Long draftContainerId;
@TableField(updateStrategy = FieldStrategy.ALWAYS)
private String draftToken;
@@ -7,8 +7,16 @@ import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import java.util.List;
@Mapper
public interface DispatchPalletLockMapper extends BaseMapper<DispatchPalletLock> {
@Select("SELECT * FROM ll_dispatch_pallet_lock WHERE draft_token=#{draftToken} " +
"AND draft_container_id=#{draftContainerId} AND status='ACTIVE' " +
"AND (expires_at IS NULL OR expires_at>CURRENT_TIMESTAMP(3)) ORDER BY locked_at,id")
List<DispatchPalletLock> findActiveByDraftContainer(@Param("draftToken") String draftToken,
@Param("draftContainerId") Long draftContainerId);
@Select("SELECT * FROM ll_dispatch_pallet_lock WHERE customer_id=#{customerId} AND source_pallet_key=#{sourcePalletKey} " +
"AND status='ACTIVE' LIMIT 1 FOR UPDATE")
DispatchPalletLock lockActive(@Param("customerId") String customerId,
@@ -95,7 +95,8 @@ public class DispatchService {
private List<DispatchContainerResponse> containers(String token) {
return draftContainers.findByToken(token).stream().map(c -> new DispatchContainerResponse(String.valueOf(c.getId()), c.getCapacity(),
locks.selectList(new LambdaQueryWrapper<DispatchPalletLock>().eq(DispatchPalletLock::getDraftContainerId, c.getId()).eq(DispatchPalletLock::getStatus, "ACTIVE")).stream().map(x -> String.valueOf(x.getPlanPalletId())).toList())).toList();
locks.findActiveByDraftContainer(token, c.getId()).stream()
.map(x -> String.valueOf(x.getPlanPalletId())).toList())).toList();
}
@Transactional
@@ -274,6 +275,7 @@ public class DispatchService {
if (draftToken != null) {
requireDraftOwner(lock, operatorId, draftToken);
lock.setDispatchOrderId(dispatch.getId());
lock.setDraftContainerId(null);
lock.setDraftToken(null);
lock.setExpiresAt(null);
lock.setUpdatedAt(now);
@@ -335,6 +337,17 @@ public class DispatchService {
pdaTask.setCreatedAt(now);
pdaTask.setUpdatedAt(now);
pdaTasks.insert(pdaTask);
if (draftToken != null) {
draftContainers.delete(new LambdaQueryWrapper<DispatchDraftContainer>()
.eq(DispatchDraftContainer::getDraftToken, draftToken));
DispatchDraft draft = drafts.lockActive(draftToken, trimToNull(operatorId));
if (draft != null) {
draft.setStatus("RELEASED");
draft.setReleasedAt(now);
draft.setUpdatedAt(now);
drafts.updateById(draft);
}
}
return response(dispatch, items.findByDispatchOrder(customerId, dispatch.getId()));
}