优化
This commit is contained in:
+9
-21
@@ -7,9 +7,9 @@ import com.baiyue.warehouse.dto.LocationRequests;
|
||||
import com.baiyue.warehouse.dto.PalletRequests;
|
||||
import com.baiyue.warehouse.dto.WarehousePalletResolveResponse;
|
||||
import com.baiyue.warehouse.dto.WarehouseLocationResolveResponse;
|
||||
import com.baiyue.warehouse.dto.SharedWarehouseReference;
|
||||
import com.baiyue.warehouse.entity.WarehouseLocationEntity;
|
||||
import com.baiyue.warehouse.entity.WarehousePalletEntity;
|
||||
import com.baiyue.warehouse.entity.WarehouseEntity;
|
||||
import com.baiyue.warehouse.entity.WarehousePalletBindingEntity;
|
||||
import com.baiyue.warehouse.repository.WarehouseResourceRepository;
|
||||
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||
@@ -29,6 +29,7 @@ public class WarehouseResourceService {
|
||||
private static final Set<String> PALLET_STATUSES = Set.of("IDLE", "OCCUPIED", "SCRAPPED");
|
||||
|
||||
@Resource private WarehouseResourceRepository repository;
|
||||
@Resource private DomesticWarehouseDirectory warehouseDirectory;
|
||||
|
||||
@Transactional
|
||||
public Long createLocation(long customerId, long warehouseId, LocationRequests.SaveRequest request) {
|
||||
@@ -78,11 +79,11 @@ public class WarehouseResourceService {
|
||||
|
||||
@Transactional
|
||||
public Long createPallet(long customerId, long warehouseId, PalletRequests.SaveRequest request) {
|
||||
WarehouseEntity warehouse = requireWarehouseEntity(customerId, warehouseId);
|
||||
SharedWarehouseReference warehouse = requireWarehouseReference(warehouseId);
|
||||
validatePalletStatus(request.status());
|
||||
Long palletId = IdWorker.getId();
|
||||
String palletCode = StringUtils.hasText(request.palletCode()) ? request.palletCode().trim()
|
||||
: generatedPalletCode(warehouse.getWarehouseCode(), palletId);
|
||||
: generatedPalletCode(warehouse.warehouseCode(), palletId);
|
||||
Long locationId = request.locationId();
|
||||
if (locationId == null) {
|
||||
locationId = ensureDefaultVirtualLocation(customerId, warehouseId).getId();
|
||||
@@ -121,8 +122,8 @@ public class WarehouseResourceService {
|
||||
*/
|
||||
@Transactional
|
||||
public WarehouseLocationEntity ensureDefaultVirtualLocation(long customerId, long warehouseId) {
|
||||
WarehouseEntity warehouse = requireWarehouseEntity(customerId, warehouseId);
|
||||
String locationCode = defaultLocationCode(warehouse.getWarehouseCode());
|
||||
SharedWarehouseReference warehouse = requireWarehouseReference(warehouseId);
|
||||
String locationCode = defaultLocationCode(warehouse.warehouseCode());
|
||||
WarehouseLocationEntity existing = repository.findLocationByCode(customerId, warehouseId, locationCode);
|
||||
if (existing != null) {
|
||||
if (!"VIRTUAL".equals(existing.getLocationType()) || !"ACTIVE".equals(existing.getStatus())) {
|
||||
@@ -230,24 +231,11 @@ public class WarehouseResourceService {
|
||||
}
|
||||
|
||||
private void requireWarehouse(long customerId, long warehouseId) {
|
||||
if (customerId == PUBLIC_RESOURCE_SCOPE) {
|
||||
if (repository.findWarehouseById(warehouseId) == null) {
|
||||
throw new BizException(ResultCode.NOT_FOUND, "Warehouse not found");
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!repository.warehouseOwned(customerId, warehouseId)) {
|
||||
throw new BizException(ResultCode.NOT_FOUND, "当前租户下仓库不存在");
|
||||
}
|
||||
warehouseDirectory.required(warehouseId);
|
||||
}
|
||||
|
||||
private WarehouseEntity requireWarehouseEntity(long customerId, long warehouseId) {
|
||||
WarehouseEntity warehouse = customerId == PUBLIC_RESOURCE_SCOPE
|
||||
? repository.findWarehouseById(warehouseId) : repository.findWarehouse(customerId, warehouseId);
|
||||
if (warehouse == null) {
|
||||
throw new BizException(ResultCode.NOT_FOUND, "Tenant warehouse not found");
|
||||
}
|
||||
return warehouse;
|
||||
private SharedWarehouseReference requireWarehouseReference(long warehouseId) {
|
||||
return warehouseDirectory.required(warehouseId);
|
||||
}
|
||||
|
||||
private WarehouseLocationEntity requireLocation(long customerId, long warehouseId, long id) {
|
||||
|
||||
Reference in New Issue
Block a user