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");
@@ -382,6 +382,27 @@ paths:
- {name: bookingId, in: query, required: true, schema: {type: string, pattern: '^[1-9][0-9]*$'}}
- {name: warehouseId, in: query, required: true, schema: {type: string, pattern: '^[1-9][0-9]*$'}}
responses: {'200': {description: Candidates filtered by the server to the booking channel}}
/api/platform/v1/first-leg/smart-loading/channels:
get:
summary: 查询当前仓库智能装柜渠道目录及统计
description: >-
需要 platform:firstleg:smart-loading:list 权限。渠道目录只来自平台当前唯一 ACTIVE 价格版本中
对该国内仓存在 ACTIVE 价格行的渠道;候选入仓码数、可用箱数及可编排柜次数由 Firstleg 当前事实聚合。
零候选或零可用柜次的有效渠道仍返回,Admin 可展示空态;实际分配仍由服务端重新校验仓库、渠道和资格。
parameters:
- {name: warehouseId, in: query, required: true, schema: {type: string, pattern: '^[1-9][0-9]*$'}}
responses:
'200':
description: 成功;无 ACTIVE 价格版本时 data 为空数组
content:
application/json:
schema:
type: object
properties:
code: {type: string}
message: {type: string}
data: {type: array, items: {$ref: '#/components/schemas/SmartLoadingChannelSummary'}}
'403': {description: 无智能装柜查询权限}
/api/platform/v1/first-leg/smart-loading/inbound-candidates:
get:
summary: 按入仓码查询智能装柜候选
@@ -1700,6 +1721,16 @@ components:
required: [itemId]
properties:
itemId: {type: string, pattern: '^[1-9][0-9]*$'}
SmartLoadingChannelSummary:
type: object
additionalProperties: false
required: [channelCode, channelName, candidateInboundCount, availablePackageCount, availableContainerCount]
properties:
channelCode: {type: string, minLength: 1, maxLength: 64}
channelName: {type: string, minLength: 1, maxLength: 128}
candidateInboundCount: {type: integer, format: int64, minimum: 0, description: 当前可分配的唯一入仓码数量}
availablePackageCount: {type: integer, format: int64, minimum: 0, description: 当前候选规格剩余可分配箱数合计}
availableContainerCount: {type: integer, format: int64, minimum: 0, description: 当前 WAIT_LOADING、EDITING 或 LOADING 可编排柜次数量}
SmartLoadingPlan:
type: object
required: [id, planNo, status, bookingId, version, canAssign, canEdit, finalCompletionStatus, items]