feat(firstleg): expose smart-loading channel directory

This commit is contained in:
2026-08-31 14:54:00 +08:00
parent ea615b864a
commit 0122ad314b
9 changed files with 152 additions and 1 deletions
@@ -8,6 +8,8 @@ import org.springframework.security.core.annotation.AuthenticationPrincipal; imp
@Validated @RestController @RequestMapping("/api/platform/v1/first-leg/smart-loading")
public class PlatformSmartLoadingController {
@Resource private SmartLoadingService service;
@GetMapping("/channels") @PreAuthorize("hasAuthority('platform:firstleg:smart-loading:list')")
public ApiResponse<List<ChannelSummary>> channels(@AuthenticationPrincipal AuthenticatedUser u,@RequestParam @Positive long warehouseId){FirstlegScopeGuard.platform(u);return ApiResponse.success(service.channels(warehouseId));}
@GetMapping("/candidates") @PreAuthorize("hasAuthority('platform:firstleg:smart-loading:list')")
public ApiResponse<List<Candidate>> candidates(@AuthenticationPrincipal AuthenticatedUser u,@RequestParam @Positive long bookingId,@RequestParam @Positive long warehouseId){FirstlegScopeGuard.platform(u);return ApiResponse.success(service.candidates(bookingId,warehouseId));}
@GetMapping("/inbound-candidates") @PreAuthorize("hasAuthority('platform:firstleg:smart-loading:list')")
@@ -1,6 +1,8 @@
package com.baiyue.firstleg.dto;
import com.baiyue.firstleg.entity.LoadingPlanItemEntity; import jakarta.validation.constraints.*; import java.math.BigDecimal; import java.util.List;
public final class SmartLoadingDtos { private SmartLoadingDtos(){}
public record ChannelSummary(String channelCode, String channelName,
long candidateInboundCount, long availablePackageCount, long availableContainerCount) {}
public record InboundCandidate(Long accountId, Long inboundId, Long orderId, String orderNo, String inboundCode,
Long warehouseId, String channelCode, String channelName, Long destinationWarehouseId,
String destinationWarehouseCode, String destinationWarehouseName, String customerName, String goodsSummary,
@@ -1,6 +1,17 @@
package com.baiyue.firstleg.mapper;
import com.baiyue.firstleg.dto.SmartLoadingDtos.Candidate; import org.apache.ibatis.annotations.*; import java.util.List;
@Mapper public interface SmartLoadingCandidateMapper {
@Select("""
SELECT b.channel_code channelCode,COUNT(DISTINCT b.id) availableContainerCount
FROM fl_container_booking b
LEFT JOIN fl_loading_plan p ON p.container_booking_id=b.id
WHERE b.record_status='ACTIVE' AND b.warehouse_id=#{warehouseId}
AND b.channel_code IS NOT NULL AND TRIM(b.channel_code)<>''
AND (p.id IS NULL OR p.plan_status IN ('EDITING','LOADING'))
GROUP BY b.channel_code
""")
List<ChannelContainerCountRow> channelContainerCounts(@Param("warehouseId") long warehouseId);
@Select("""
SELECT o.tenant_id accountId,o.id inboundId,i.inbound_detail_id inboundDetailId,
o.order_id orderId,o.order_no orderNo,o.inbound_code inboundCode,
@@ -98,4 +109,9 @@ import com.baiyue.firstleg.dto.SmartLoadingDtos.Candidate; import org.apache.iba
""")
Candidate candidate(@Param("planId") long planId,@Param("warehouseId") long warehouseId,
@Param("inboundId") long inboundId,@Param("detailId") long detailId);
@lombok.Getter @lombok.Setter class ChannelContainerCountRow {
private String channelCode;
private Long availableContainerCount;
}
}
@@ -12,6 +12,7 @@ import com.baiyue.firstleg.mapper.LoadingPlanHistoryMapper;
import com.baiyue.firstleg.mapper.LoadingPlanItemMapper;
import com.baiyue.firstleg.mapper.LoadingPlanMapper;
import com.baiyue.firstleg.mapper.SmartLoadingCandidateMapper;
import com.baiyue.firstleg.mapper.SmartLoadingCandidateMapper.ChannelContainerCountRow;
import com.baiyue.firstleg.mapper.InboundOrderMapper;
import org.springframework.stereotype.Repository;
import jakarta.annotation.Resource;
@@ -31,6 +32,9 @@ public class SmartLoadingRepository {
@Resource private InboundOrderMapper inbounds;
public List<Candidate> candidates(long warehouseId) { return candidates.candidates(warehouseId); }
public List<ChannelContainerCountRow> channelContainerCounts(long warehouseId) {
return candidates.channelContainerCounts(warehouseId);
}
public Candidate candidate(long planId, long warehouseId, long inboundId, long detailId) {
return candidates.candidate(planId, warehouseId, inboundId, detailId);
}
@@ -12,6 +12,7 @@ import com.baiyue.firstleg.loading.bridge.service.LoadingModelBridgeService;
import com.baiyue.firstleg.loading.coload.model.ColoadGroupModels.GroupSnapshot;
import com.baiyue.firstleg.loading.coload.model.ColoadGroupModels.Member;
import com.baiyue.firstleg.loading.coload.port.ColoadGroupAssignmentPort;
import com.baiyue.firstleg.pricebookquery.application.port.in.PriceBookQueryUseCase;
import com.baiyue.firstleg.split.service.SplitPreloadService;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.dao.DataAccessException;
@@ -43,11 +44,35 @@ public class SmartLoadingService {
@Resource private LoadingModelBridgeService loadingModelBridge;
@Resource private SplitPreloadService splitPreloadService;
@Resource private ColoadGroupAssignmentPort coloadGroups;
@Resource private PriceBookQueryUseCase priceBooks;
@Resource private FirstlegDocumentNumberGenerator documentNumbers;
@Resource private ObjectMapper objectMapper;
@Value("${baiyue.security.internal-service-token:}") private String internalToken;
public SmartLoadingService() { }
public List<ChannelSummary> channels(long warehouseId) {
if (warehouseId <= 0) throw validation("warehouseId必须大于0");
Long versionId = priceBooks.activeVersionId();
if (versionId == null) return List.of();
Map<String, List<Candidate>> candidatesByChannel = repository.candidates(warehouseId).stream()
.filter(candidate -> StringUtils.hasText(candidate.channelCode()))
.collect(java.util.stream.Collectors.groupingBy(candidate -> candidate.channelCode().trim()));
Map<String, Long> containersByChannel = repository.channelContainerCounts(warehouseId).stream()
.filter(row -> StringUtils.hasText(row.getChannelCode()))
.collect(java.util.stream.Collectors.toMap(row -> row.getChannelCode().trim(),
row -> Objects.requireNonNullElse(row.getAvailableContainerCount(), 0L), Long::sum));
return priceBooks.channels(versionId, warehouseId).stream().map(channel -> {
String channelCode = channel.getChannelCode().trim();
List<Candidate> channelCandidates = candidatesByChannel.getOrDefault(channelCode, List.of());
long candidateInboundCount = channelCandidates.stream().map(Candidate::inboundId)
.filter(Objects::nonNull).distinct().count();
long availablePackageCount = channelCandidates.stream().map(Candidate::availablePackageCount)
.filter(Objects::nonNull).mapToLong(Integer::longValue).sum();
return new ChannelSummary(channelCode, channel.getChannelName(), candidateInboundCount,
availablePackageCount, containersByChannel.getOrDefault(channelCode, 0L));
}).toList();
}
public List<Candidate> candidates(long warehouseId) {
if (warehouseId <= 0) {
throw new BizException(ResultCode.BAD_REQUEST, "warehouseId必须大于0");