This commit is contained in:
2026-09-11 11:51:26 +08:00
parent d60689ce02
commit d2cff49b9e
45 changed files with 569 additions and 66 deletions
@@ -6,6 +6,8 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestHeader;
import java.util.List;
/** 获取平台仓库主数据,供虚拟柜校验国内中转仓使用。 */
@FeignClient(name = "warehouse-service", contextId = "firstlegWarehouseMasterDataClient",
url = "${baiyue.clients.warehouse.url:}", path = "/internal/warehouses")
@@ -15,10 +17,17 @@ public interface WarehouseMasterDataClient {
@PathVariable long tenantId,
@PathVariable long warehouseId);
@GetMapping("/domestic")
ApiResponse<List<WarehouseOption>> domestic(
@RequestHeader("X-Internal-Service-Token") String token);
record Detail(Warehouse warehouse) {
}
record Warehouse(Long id, Long tenantId, String warehouseCode, String internalCode, String warehouseName,
String warehouseType, String status) {
}
record WarehouseOption(Long id, String warehouseCode, String warehouseName) {
}
}
@@ -39,9 +39,10 @@ public class PlatformDropshipPalletizationController {
@PreAuthorize("hasAuthority('platform:firstleg:pda:view')")
public ApiResponse<List<DropshipPalletizationDtos.PendingTask>> pending(
@AuthenticationPrincipal AuthenticatedUser user,
@RequestParam @Positive long warehouseId,
@RequestParam(required = false) @Size(max = 64) String keyword) {
FirstlegScopeGuard.platform(user);
return ApiResponse.success(service.pending(user.userId(), keyword));
return ApiResponse.success(service.pending(user.userId(), warehouseId, keyword));
}
@GetMapping("/tasks/{taskId}")
@@ -121,6 +122,21 @@ public class PlatformDropshipPalletizationController {
return ApiResponse.success(service.seal(taskId, palletId, request, user.userId(), user.username()));
}
@GetMapping("/tasks/{taskId}/pallets/{palletId}/print")
@PreAuthorize("hasAuthority('platform:firstleg:pda:view')")
public ResponseEntity<byte[]> printTaskPallet(@AuthenticationPrincipal AuthenticatedUser user,
@PathVariable @Positive long taskId,
@PathVariable @Positive long palletId,
@RequestParam @Positive long warehouseId,
@RequestHeader(value = "X-Request-Id", required = false) String requestId) {
FirstlegScopeGuard.platform(user);
Pallet pallet = service.task(taskId, warehouseId, user.userId()).pallets().stream()
.filter(item -> item.palletId() == palletId).findFirst()
.orElseThrow(() -> new com.baiyue.common.core.exception.BizException(
com.baiyue.common.core.api.ResultCode.NOT_FOUND, "托盘不存在"));
return printService.generateDropshipPallet(pallet, requestId);
}
@GetMapping("/inbound-orders/{inboundId}/pallets")
@PreAuthorize("hasAuthority('firstleg:inbound:list')")
public ApiResponse<List<Pallet>> inboundPallets(@AuthenticationPrincipal AuthenticatedUser user,
@@ -20,6 +20,8 @@ import java.util.List;
import com.baiyue.firstleg.dto.LoadingPickDtos.Task;
import com.baiyue.firstleg.service.FirstlegScopeGuard;
import com.baiyue.firstleg.service.LoadingPickService;
import com.baiyue.firstleg.service.PdaWarehouseCatalogService;
import com.baiyue.firstleg.client.WarehouseMasterDataClient.WarehouseOption;
import com.baiyue.firstleg.loading.service.CabinetLoadingEvidenceService;
import org.springframework.http.ResponseEntity;
import org.springframework.http.MediaType;
@@ -51,6 +53,8 @@ public class PlatformLoadingPdaController {
@Resource
private LoadingPickService service;
@Resource
private PdaWarehouseCatalogService warehouseCatalog;
@Resource
private CabinetLoadingEvidenceService evidenceService;
@GetMapping("/tasks")
@@ -66,10 +70,18 @@ public class PlatformLoadingPdaController {
@GetMapping("/tasks/pending")
@PreAuthorize("hasAuthority('platform:firstleg:pda:view')")
public ApiResponse<List<PendingTask>> pendingTasks(@AuthenticationPrincipal AuthenticatedUser user,
@RequestParam @Positive long warehouseId,
@RequestParam(required = false)
@Size(max = 64) String keyword) {
FirstlegScopeGuard.platform(user);
return ApiResponse.success(service.pendingTasks(user.userId(), keyword));
return ApiResponse.success(service.pendingTasks(user.userId(), warehouseId, keyword));
}
@GetMapping("/warehouses")
@PreAuthorize("hasAuthority('platform:firstleg:pda:view')")
public ApiResponse<List<WarehouseOption>> warehouses(@AuthenticationPrincipal AuthenticatedUser user) {
FirstlegScopeGuard.platform(user);
return ApiResponse.success(warehouseCatalog.activeDomesticWarehouses());
}
@GetMapping("/tasks/{taskId}")
@@ -30,10 +30,12 @@ public interface DropshipPalletizationMapper {
o.warehouse_name,t.total_cartons,t.counted_cartons,t.allocated_cartons bound_cartons,
t.counted_cartons-t.allocated_cartons unbound_cartons,t.discrepancy_cartons,t.task_status,t.created_at
FROM fl_dropship_pallet_task t JOIN fl_inbound_order o ON o.id=t.inbound_id AND o.tenant_id=t.tenant_id
WHERE t.task_status IN ('PENDING','CLAIMED') AND (t.assignee_id IS NULL OR t.assignee_id=#{operatorId})
WHERE t.task_status IN ('PENDING','CLAIMED') AND t.warehouse_id=#{warehouseId}
AND (t.assignee_id IS NULL OR t.assignee_id=#{operatorId})
AND (#{keyword} IS NULL OR o.inbound_code LIKE CONCAT('%',#{keyword},'%') OR o.customer_name LIKE CONCAT('%',#{keyword},'%'))
ORDER BY t.created_at,t.id""")
List<PendingTask> pending(@Param("operatorId") long operatorId,@Param("keyword") String keyword);
List<PendingTask> pending(@Param("operatorId") long operatorId,@Param("warehouseId") long warehouseId,
@Param("keyword") String keyword);
@Select("""
SELECT t.*,o.inbound_code,o.customer_name,o.warehouse_name,o.process_status,o.fulfillment_type
@@ -100,6 +100,7 @@ public interface LoadingPickTaskMapper extends BaseMapper<LoadingPickTaskEntity>
JOIN fl_loading_pick_item pick_item ON pick_item.pick_task_id = task.id
LEFT JOIN fl_loading_pick_assignment assignment ON assignment.pick_task_id = task.id
WHERE task.task_status IN ('LOADING','COMPLETING','COMPLETION_FAILED') AND booking.record_status = 'ACTIVE'
AND booking.warehouse_id = #{warehouseId}
AND (assignment.pick_task_id IS NULL OR assignment.assignee_id = #{operatorId})
<if test="keyword != null and keyword != ''">
AND (booking.container_no LIKE CONCAT('%', #{keyword}, '%')
@@ -115,6 +116,7 @@ public interface LoadingPickTaskMapper extends BaseMapper<LoadingPickTaskEntity>
</script>
""")
List<PendingTaskRow> selectPendingForOperator(@Param("operatorId") long operatorId,
@Param("warehouseId") long warehouseId,
@Param("keyword") String keyword);
class PendingTaskRow {
@@ -90,8 +90,8 @@ public class LoadingPickRepository {
return tasks.selectLoadingByPlan(loadingPlanId, warehouseId);
}
public List<PendingTaskRow> pendingTasks(long operatorId, String keyword) {
return tasks.selectPendingForOperator(operatorId, keyword);
public List<PendingTaskRow> pendingTasks(long operatorId, long warehouseId, String keyword) {
return tasks.selectPendingForOperator(operatorId, warehouseId, keyword);
}
public ContainerBookingEntity activeBookingByTask(long taskId) {
@@ -36,6 +36,7 @@ public class DropshipPalletizationService {
return view(task);
}
if(!"CLAIMED".equals(task.getTaskStatus())||!"WAIT_PALLETIZE".equals(task.getProcessStatus())) throw conflict("当前任务不允许创建托盘");
if(!Objects.equals(task.getCountedCartons(),task.getTotalCartons())) throw conflict("请先完成全部箱码清点,再生成托盘码");
int expected=mapper.unboundCount(taskId);
if(expected==0) throw conflict("当前没有待绑托箱,请先清点箱码");
long palletId=IdWorker.getId();
@@ -43,6 +44,10 @@ public class DropshipPalletizationService {
mapper.insertPallet(palletId,taskId,task.getTenantId(),task.getInboundId(),task.getWarehouseId(),palletNo,operation,operatorId,operatorName);
int bound=mapper.bindPending(taskId,palletId,operation,operatorId,operatorName);
if(bound!=expected||mapper.adjustBound(taskId,operatorId,bound)!=1) throw conflict("待绑托箱已变化,请刷新后重试");
if(mapper.seal(taskId,palletId,1,request.warehouseId(),operation,operatorId,operatorName)!=1)
throw conflict("托盘完成状态已变化,请刷新后重试");
if(mapper.completeTask(taskId)!=1 || mapper.completeInbound(taskId,task.getTenantId(),task.getInboundId(),operatorId)!=1)
throw conflict("一件代发入库完成状态已变化,请刷新后重试");
return view(requireTask(taskId,request.warehouseId()));
}
@@ -52,7 +57,7 @@ public class DropshipPalletizationService {
mapper.insertTask(IdWorker.getId(),inbound.getTenantId(),inbound.getId(),inbound.getWarehouseId(),inbound.getTotalPackageCount());
}
public List<PendingTask> pending(long operatorId,String keyword){ return mapper.pending(operatorId,normalize(keyword)); }
public List<PendingTask> pending(long operatorId,long warehouseId,String keyword){ return mapper.pending(operatorId,warehouseId,normalize(keyword)); }
@Transactional
public Task claim(long taskId,long warehouseId,long operatorId,String operatorName){
@@ -99,8 +104,8 @@ public class DropshipPalletizationService {
if(!mismatch && request.discrepancyAction()!=DiscrepancyAction.MATCH) throw invalid("实收数量一致时差异动作必须为 MATCH");
if(mismatch && request.discrepancyAction()!=DiscrepancyAction.ACCEPT_VARIANCE) throw conflict("实收数量存在差异,请确认差异处理结果");
if(mismatch && !StringUtils.hasText(remark)) throw invalid("接受数量差异时必须填写处理说明");
PalletRow pallet=StringUtils.hasText(request.palletNo())
? getOrCreatePallet(task,request.palletNo().trim(),operation,operatorId,operatorName):null;
if(StringUtils.hasText(request.palletNo())) throw invalid("逐箱清点阶段不能提前绑定托盘码");
PalletRow pallet=null;
long cartonId=IdWorker.getId();
mapper.insertCarton(cartonId,taskId,pallet==null?null:pallet.getId(),task.getTenantId(),task.getInboundId(),
label.getInboundDetailId(),label.getCartonLabelId(),label.getSkuCode(),label.getCargoName(),label.getBoxCode(),
@@ -113,6 +118,7 @@ public class DropshipPalletizationService {
@Transactional
public Task bindPending(long taskId,BindPendingRequest request,long operatorId,String operatorName){
TaskRow task=requireWorkingTask(taskId,request.warehouseId(),operatorId);
if(!Objects.equals(task.getCountedCartons(),task.getTotalCartons())) throw conflict("请先完成全部箱码清点,再绑定托盘码");
String operation=operation(request.operationId());
if(mapper.bindOperationCount(taskId,operation)>0) return view(requireTask(taskId,request.warehouseId()));
PalletRow pallet=getOrCreatePallet(task,request.palletNo().trim(),operation,operatorId,operatorName);
@@ -115,7 +115,8 @@ public class InboundCartonLabelPrintService {
/** 一件代发托盘标签:托盘号、入仓码、SKU箱数和托盘二维码。 */
public ResponseEntity<byte[]> generateDropshipPallet(Pallet pallet, String requestId) {
if (pallet == null || !StringUtils.hasText(pallet.palletNo()) || pallet.items().isEmpty()) {
if (pallet == null || !"SEALED".equals(pallet.status())
|| !StringUtils.hasText(pallet.palletNo()) || pallet.items().isEmpty()) {
throw new BizException(ResultCode.CONFLICT, "只有已完成且包含货物的一件代发托盘可以打印");
}
String inboundCodes = pallet.items().stream().map(item -> item.inboundCode())
@@ -233,9 +233,9 @@ public class LoadingPickService {
return view(requiredTask(taskId), warehouseId);
}
public List<PendingTask> pendingTasks(long operatorId, String keyword) {
public List<PendingTask> pendingTasks(long operatorId, long warehouseId, String keyword) {
String normalizedKeyword = StringUtils.hasText(keyword) ? keyword.trim() : null;
return repository.pendingTasks(operatorId, normalizedKeyword).stream()
return repository.pendingTasks(operatorId, warehouseId, normalizedKeyword).stream()
.map(row -> new PendingTask(row.getTaskId(), row.getLoadingPlanId(), row.getContainerBookingId(),
row.getCabinetNo(), row.getContainerNo(),
row.getSourceType(), row.getRecordStatus(), row.getMergedIntoContainerBookingId(),
@@ -0,0 +1,37 @@
package com.baiyue.firstleg.service;
import com.baiyue.common.core.api.ApiResponse;
import com.baiyue.common.core.api.ResultCode;
import com.baiyue.common.core.exception.BizException;
import com.baiyue.firstleg.client.WarehouseMasterDataClient;
import com.baiyue.firstleg.client.WarehouseMasterDataClient.WarehouseOption;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.List;
/** 为国内 PDA 提供启用中的国内仓选择项,主档仍由 Warehouse Service 唯一维护。 */
@Service
public class PdaWarehouseCatalogService {
@Resource private WarehouseMasterDataClient warehouses;
@Value("${baiyue.security.internal-service-token:}") private String internalToken;
public List<WarehouseOption> activeDomesticWarehouses() {
try {
ApiResponse<List<WarehouseOption>> response = warehouses.domestic(internalToken);
if (response == null || !response.successful() || response.data() == null) {
throw unavailable();
}
return response.data();
} catch (BizException exception) {
throw exception;
} catch (RuntimeException exception) {
throw unavailable();
}
}
private static BizException unavailable() {
return new BizException(ResultCode.SERVICE_UNAVAILABLE, "国内仓目录暂时不可用,请稍后重试");
}
}