This commit is contained in:
2026-08-26 13:58:33 +08:00
parent fc0a6ea7ca
commit 4398e8b347
78 changed files with 920 additions and 1549 deletions
@@ -5,6 +5,7 @@ import com.baiyue.common.core.api.ResultCode;
import com.baiyue.common.core.exception.BizException;
import com.baiyue.warehouse.dto.WarehouseDetailResponse;
import com.baiyue.warehouse.dto.OverseasPartnerWarehouseResponse;
import com.baiyue.warehouse.dto.SharedOverseasWarehouseResponse;
import com.baiyue.warehouse.service.WarehouseApplicationService;
import jakarta.annotation.Resource;
import jakarta.annotation.PostConstruct;
@@ -48,6 +49,21 @@ public class InternalWarehouseController {
return ApiResponse.success(service.activeOverseasPartners());
}
@GetMapping("/shared-overseas")
public ApiResponse<List<SharedOverseasWarehouseResponse>> sharedOverseasWarehouses(
@RequestHeader(value="X-Internal-Service-Token", required=false) String token) {
verifyToken(token);
return ApiResponse.success(service.activeSharedOverseasWarehouses());
}
@GetMapping("/shared-overseas/{warehouseId}")
public ApiResponse<SharedOverseasWarehouseResponse> sharedOverseasWarehouse(
@RequestHeader(value="X-Internal-Service-Token", required=false) String token,
@PathVariable long warehouseId) {
verifyToken(token);
return ApiResponse.success(service.activeSharedOverseasWarehouse(warehouseId));
}
private void verifyToken(String token) {
byte[] supplied = token == null ? new byte[0] : token.getBytes(StandardCharsets.UTF_8);
if (!MessageDigest.isEqual(expected, supplied)) {
@@ -0,0 +1,19 @@
package com.baiyue.warehouse.dto;
import com.baiyue.warehouse.entity.WarehouseEntity;
import io.swagger.v3.oas.annotations.media.Schema;
@Schema(name = "SharedOverseasWarehouseResponse",
description = "Domestic-authoritative active shared overseas receiving warehouse")
public record SharedOverseasWarehouseResponse(
Long warehouseId,
String warehouseCode,
String warehouseName,
String countryCode,
String status
) {
public static SharedOverseasWarehouseResponse of(WarehouseEntity warehouse) {
return new SharedOverseasWarehouseResponse(warehouse.getId(), warehouse.getWarehouseCode(),
warehouse.getWarehouseName(), warehouse.getCountryCode(), warehouse.getStatus());
}
}
@@ -9,6 +9,7 @@ import com.baiyue.warehouse.dto.WarehouseDetailResponse;
import com.baiyue.warehouse.dto.WarehouseRequests;
import com.baiyue.warehouse.dto.OverseasPartnerWarehouseResponse;
import com.baiyue.warehouse.dto.WarehouseSummaryResponse;
import com.baiyue.warehouse.dto.SharedOverseasWarehouseResponse;
import com.baiyue.warehouse.entity.ServiceCapabilityEntity;
import com.baiyue.warehouse.entity.WarehouseAddressEntity;
import com.baiyue.warehouse.entity.WarehouseEntity;
@@ -95,6 +96,32 @@ public class WarehouseApplicationService {
.toList();
}
public List<SharedOverseasWarehouseResponse> activeSharedOverseasWarehouses() {
return repository.findActiveByType(WarehouseSaveNormalizer.PUBLIC_TENANT_ID,
WarehouseSaveNormalizer.TYPE_OVERSEAS)
.stream()
.filter(warehouse -> hasReceivingCapability(warehouse.getId()))
.map(SharedOverseasWarehouseResponse::of)
.toList();
}
public SharedOverseasWarehouseResponse activeSharedOverseasWarehouse(long warehouseId) {
WarehouseEntity warehouse = repository.findOwned(WarehouseSaveNormalizer.PUBLIC_TENANT_ID, warehouseId);
if (warehouse == null || !"ACTIVE".equals(warehouse.getStatus())
|| !WarehouseSaveNormalizer.TYPE_OVERSEAS.equals(warehouse.getWarehouseType())
|| !hasReceivingCapability(warehouseId)) {
throw new BizException(ResultCode.NOT_FOUND,
"启用的公共海外收货仓不存在");
}
return SharedOverseasWarehouseResponse.of(warehouse);
}
private boolean hasReceivingCapability(long warehouseId) {
return repository.findCapabilities(WarehouseSaveNormalizer.PUBLIC_TENANT_ID, warehouseId).stream()
.anyMatch(capability -> "RECEIVING".equals(capability.getCapabilityCode())
&& Boolean.TRUE.equals(capability.getEnabled()));
}
public WarehouseDetailResponse activeDetail(long tenantId, long id) {
WarehouseEntity warehouse = repository.findOwned(tenantId, id);
if (warehouse == null) {
@@ -162,7 +162,7 @@ JOIN wh_warehouse warehouse
ON DUPLICATE KEY UPDATE
tenant_id = VALUES(tenant_id);
-- 国内固定作业仓必须启用收货能力,FBA 目的地址仍不得创建作业能力。
-- 四个固定平台作业仓必须启用收货能力,FBA 目的地址仍不得创建作业能力。
INSERT INTO wh_service_capability (
id, tenant_id, warehouse_id, capability_code, capability_name, enabled, cutoff_time,
description, created_by, created_at, updated_by, updated_at, deleted, version
@@ -171,7 +171,11 @@ VALUES
(193000000000400001,0,193000000000200001,'RECEIVING','头程收货',1,'16:00:00',
'义乌仓头程订单收货能力',NULL,CURRENT_TIMESTAMP(3),NULL,CURRENT_TIMESTAMP(3),0,0),
(193000000000400002,0,193000000000200002,'RECEIVING','头程收货',1,'16:00:00',
'东莞仓头程订单收货能力',NULL,CURRENT_TIMESTAMP(3),NULL,CURRENT_TIMESTAMP(3),0,0)
'东莞仓头程订单收货能力',NULL,CURRENT_TIMESTAMP(3),NULL,CURRENT_TIMESTAMP(3),0,0),
(193000000000400003,0,193000000000200003,'RECEIVING','海外收货',1,'16:00:00',
'洛杉矶仓海外接柜入仓收货能力',NULL,CURRENT_TIMESTAMP(3),NULL,CURRENT_TIMESTAMP(3),0,0),
(193000000000400004,0,193000000000200004,'RECEIVING','海外收货',1,'16:00:00',
'纽约仓海外接柜入仓收货能力',NULL,CURRENT_TIMESTAMP(3),NULL,CURRENT_TIMESTAMP(3),0,0)
ON DUPLICATE KEY UPDATE
capability_name = VALUES(capability_name),
enabled = VALUES(enabled),
@@ -677,11 +681,11 @@ BEGIN
IF (SELECT COUNT(*)
FROM wh_service_capability capability
WHERE capability.tenant_id = 0
AND capability.warehouse_id IN (193000000000200001,193000000000200002)
AND capability.warehouse_id IN (193000000000200001,193000000000200002,193000000000200003,193000000000200004)
AND capability.capability_code = 'RECEIVING'
AND capability.enabled = 1
AND capability.deleted = 0) <> 2 THEN
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = '国内固定作业仓收货能力写入校验失败';
AND capability.deleted = 0) <> 4 THEN
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = '固定平台作业仓收货能力写入校验失败';
END IF;
END//
DELIMITER ;
@@ -4,6 +4,7 @@ import com.baiyue.common.core.api.ResultCode;
import com.baiyue.common.core.exception.BizException;
import com.baiyue.warehouse.dto.WarehouseDetailResponse;
import com.baiyue.warehouse.dto.OverseasPartnerWarehouseResponse;
import com.baiyue.warehouse.dto.SharedOverseasWarehouseResponse;
import com.baiyue.warehouse.entity.WarehouseEntity;
import com.baiyue.warehouse.service.WarehouseApplicationService;
import org.junit.jupiter.api.BeforeEach;
@@ -83,4 +84,17 @@ class InternalWarehouseControllerTest {
assertThat(response.data()).containsExactly(option);
verify(service).activeOverseasPartners();
}
@Test
void exposesSharedOverseasReceivingDirectoryOnlyWithInternalToken() {
var warehouse = new SharedOverseasWarehouseResponse(200003L, "US-LAX-01",
"洛杉矶海外仓", "US", "ACTIVE");
when(service.activeSharedOverseasWarehouse(200003L)).thenReturn(warehouse);
assertThat(controller.sharedOverseasWarehouse(INTERNAL_TOKEN, 200003L).data())
.isEqualTo(warehouse);
assertThatThrownBy(() -> controller.sharedOverseasWarehouse("bad", 200003L))
.isInstanceOf(BizException.class);
verify(service).activeSharedOverseasWarehouse(200003L);
}
}
@@ -109,7 +109,7 @@ class WarehouseSchemaContractTest {
}
@Test
void shouldSeedReceivingCapabilityForDomesticOperatingWarehouses() throws IOException {
void shouldSeedReceivingCapabilityForFixedOperatingWarehouses() throws IOException {
String masterData = read("warehouse-public-master-data.sql");
String unified = Files.readString(Path.of("..", "deploy", "sql", "头程数据库统一增量-MySQL8.sql"));
@@ -117,7 +117,11 @@ class WarehouseSchemaContractTest {
assertThat(sql)
.contains("193000000000200001,'RECEIVING','头程收货',1")
.contains("193000000000200002,'RECEIVING','头程收货',1")
.contains("国内固定作业仓收货能力写入校验失败")
.contains("193000000000400003,0,193000000000200003,'RECEIVING','海外收货',1")
.contains("'洛杉矶仓海外接柜入仓收货能力'")
.contains("193000000000400004,0,193000000000200004,'RECEIVING','海外收货',1")
.contains("'纽约仓海外接柜入仓收货能力'")
.contains("固定平台作业仓收货能力写入校验失败")
.contains("warehouse.warehouse_type = 'FBA'")
.contains("FBA公共地址不得创建平台作业能力");
}
@@ -149,4 +149,23 @@ class WarehouseApplicationServiceTest {
.containsExactly(tuple(2L, "US-PARTNER-LAX", "洛杉矶合作仓", "US"));
verify(repository).findActiveByType(0L, "OVERSEAS_PARTNER");
}
@Test
void exposesOnlyActiveSharedOverseasWarehousesWithReceivingCapability() {
WarehouseEntity receiving = new WarehouseEntity();
receiving.setId(3L); receiving.setWarehouseCode("US-LAX-01");
receiving.setWarehouseName("洛杉矶海外仓"); receiving.setCountryCode("US");
receiving.setWarehouseType("OVERSEAS"); receiving.setStatus("ACTIVE");
ServiceCapabilityEntity capability = new ServiceCapabilityEntity();
capability.setCapabilityCode("RECEIVING"); capability.setEnabled(true);
when(repository.findActiveByType(0L, "OVERSEAS")).thenReturn(java.util.List.of(receiving));
when(repository.findOwned(0L, 3L)).thenReturn(receiving);
when(repository.findCapabilities(0L, 3L)).thenReturn(java.util.List.of(capability));
assertThat(service.activeSharedOverseasWarehouses())
.extracting("warehouseId", "warehouseCode", "status")
.containsExactly(tuple(3L, "US-LAX-01", "ACTIVE"));
assertThat(service.activeSharedOverseasWarehouse(3L).warehouseName())
.isEqualTo("洛杉矶海外仓");
}
}
@@ -19,6 +19,38 @@ SELECT COUNT(*) AS fixed_platform_address_count
AND address.deleted = 0
AND warehouse.deleted = 0;
SELECT COUNT(*) AS fixed_platform_receiving_capability_count
FROM wh_service_capability capability
WHERE capability.tenant_id = 0
AND capability.warehouse_id IN (
193000000000200001, 193000000000200002,
193000000000200003, 193000000000200004
)
AND capability.capability_code = 'RECEIVING'
AND capability.enabled = 1
AND capability.deleted = 0;
SELECT COUNT(*) AS overseas_receiving_capability_violations
FROM wh_service_capability capability
WHERE capability.tenant_id = 0
AND (
(capability.id = 193000000000400003
AND (capability.warehouse_id <> 193000000000200003
OR capability.capability_code <> 'RECEIVING'
OR capability.capability_name <> '海外收货'
OR capability.description <> '洛杉矶仓海外接柜入仓收货能力'
OR capability.enabled <> 1
OR capability.deleted <> 0))
OR
(capability.id = 193000000000400004
AND (capability.warehouse_id <> 193000000000200004
OR capability.capability_code <> 'RECEIVING'
OR capability.capability_name <> '海外收货'
OR capability.description <> '纽约仓海外接柜入仓收货能力'
OR capability.enabled <> 1
OR capability.deleted <> 0))
);
SELECT COUNT(*) AS fba_public_warehouse_count
FROM wh_warehouse
WHERE tenant_id = 0
@@ -111,8 +111,11 @@ assert.doesNotMatch(sql, /contact_name\s*=\s*VALUES\(contact_name\)/)
assert.doesNotMatch(sql, /contact_phone\s*=\s*VALUES\(contact_phone\)/)
assert.doesNotMatch(sql, /contact_email\s*=\s*VALUES\(contact_email\)/)
assert.doesNotMatch(sql, /remark\s*=\s*VALUES\(remark\)/)
assert.match(sql, /国内固定作业仓必须启用收货能力/)
assert.match(sql, /四个固定平台作业仓必须启用收货能力/)
assert.match(sql, /INSERT INTO wh_service_capability[\s\S]+?'RECEIVING'/i)
assert.match(sql, /193000000000400003,0,193000000000200003,'RECEIVING','海外收货',1,'16:00:00',[\s\S]*?'洛杉矶仓海外接柜入仓收货能力'/)
assert.match(sql, /193000000000400004,0,193000000000200004,'RECEIVING','海外收货',1,'16:00:00',[\s\S]*?'纽约仓海外接柜入仓收货能力'/)
assert.match(sql, /warehouse_id IN \(193000000000200001,193000000000200002,193000000000200003,193000000000200004\)[\s\S]*?<> 4 THEN[\s\S]*?固定平台作业仓收货能力写入校验失败/)
const fbaBlock = sql.slice(sql.indexOf('CREATE TEMPORARY TABLE tmp_wh_fba_public_master_data'))
assert.doesNotMatch(fbaBlock, /INSERT INTO wh_service_capability/i)
assert.match(sql, /FBA公共主数据地址种子ID与既有数据冲突/)