fix: bind overseas receiving to shared warehouse
This commit is contained in:
+26
@@ -7,6 +7,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.WarehouseRequests;
|
||||
import com.baiyue.warehouse.dto.SharedWarehouseReference;
|
||||
import com.baiyue.warehouse.entity.ServiceCapabilityEntity;
|
||||
import com.baiyue.warehouse.entity.WarehouseAddressEntity;
|
||||
import com.baiyue.warehouse.entity.WarehouseEntity;
|
||||
@@ -36,6 +37,7 @@ public class WarehouseApplicationService {
|
||||
captureBefore = false
|
||||
)
|
||||
public Long create(WarehouseRequests.SaveRequest request) {
|
||||
validateSharedWarehouse(request);
|
||||
ensureCodeUnique(request.customerId(), request.warehouseCode(), null);
|
||||
WarehouseEntity warehouse = toEntity(request);
|
||||
repository.insertWarehouse(warehouse);
|
||||
@@ -72,6 +74,7 @@ public class WarehouseApplicationService {
|
||||
if (request.customerId() == null || customerId != request.customerId()) {
|
||||
throw new BizException(ResultCode.FORBIDDEN, "租户不匹配");
|
||||
}
|
||||
validateSharedWarehouse(request);
|
||||
WarehouseEntity old = owned(customerId, id);
|
||||
ensureCodeUnique(customerId, request.warehouseCode(), id);
|
||||
|
||||
@@ -98,6 +101,29 @@ public class WarehouseApplicationService {
|
||||
return new WarehouseDetailResponse(warehouse, addresses, capabilities);
|
||||
}
|
||||
|
||||
public SharedWarehouseReference activeSharedReference(long warehouseId) {
|
||||
WarehouseEntity warehouse = repository.findOwned(0L, warehouseId);
|
||||
boolean receiving = warehouse != null && repository.findCapabilities(0L, warehouseId).stream()
|
||||
.anyMatch(value -> "RECEIVING".equals(value.getCapabilityCode()) && Boolean.TRUE.equals(value.getEnabled()));
|
||||
if (warehouse == null || !"ACTIVE".equals(warehouse.getStatus())
|
||||
|| !"OVERSEAS".equals(warehouse.getWarehouseType()) || !receiving) {
|
||||
throw new BizException(ResultCode.NOT_FOUND, "Active shared overseas warehouse not found");
|
||||
}
|
||||
return new SharedWarehouseReference(warehouse.getId(), warehouse.getWarehouseCode(),
|
||||
warehouse.getWarehouseName(), warehouse.getStatus());
|
||||
}
|
||||
|
||||
private void validateSharedWarehouse(WarehouseRequests.SaveRequest request) {
|
||||
if (request.customerId() == null || request.customerId() != 0L) return;
|
||||
boolean receiving = request.capabilities() != null && request.capabilities().stream()
|
||||
.anyMatch(value -> "RECEIVING".equals(value.capabilityCode())
|
||||
&& !Boolean.FALSE.equals(value.enabled()));
|
||||
if (!"OVERSEAS".equals(request.warehouseType()) || !receiving) {
|
||||
throw new BizException(ResultCode.BAD_REQUEST,
|
||||
"Shared physical warehouse must be OVERSEAS with RECEIVING enabled");
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@BusinessAudit(
|
||||
event = "WAREHOUSE_STATUS_CHANGE",
|
||||
|
||||
Reference in New Issue
Block a user