暂存提交
This commit is contained in:
+112
@@ -0,0 +1,112 @@
|
||||
package com.baiyue.warehouse.repository;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baiyue.common.core.api.PageResult;
|
||||
import com.baiyue.warehouse.dto.WarehouseRequests;
|
||||
import com.baiyue.warehouse.entity.ServiceCapabilityEntity;
|
||||
import com.baiyue.warehouse.entity.WarehouseAddressEntity;
|
||||
import com.baiyue.warehouse.entity.WarehouseEntity;
|
||||
import com.baiyue.warehouse.entity.WarehouseLocationEntity;
|
||||
import com.baiyue.warehouse.mapper.ServiceCapabilityMapper;
|
||||
import com.baiyue.warehouse.mapper.WarehouseAddressMapper;
|
||||
import com.baiyue.warehouse.mapper.WarehouseMapper;
|
||||
import com.baiyue.warehouse.mapper.WarehouseLocationMapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import org.springframework.util.StringUtils;
|
||||
import jakarta.annotation.Resource;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 仓库聚合持久化仓储,组合仓库、地址和服务能力 Mapper,并强制按租户范围执行查询与写入。
|
||||
*/
|
||||
@Repository
|
||||
public class WarehouseRepository {
|
||||
@Resource private WarehouseMapper warehouses;
|
||||
@Resource private WarehouseLocationMapper locations;
|
||||
@Resource private WarehouseAddressMapper addresses;
|
||||
@Resource private ServiceCapabilityMapper capabilities;
|
||||
|
||||
public void insertWarehouse(WarehouseEntity warehouse) {
|
||||
warehouses.insert(warehouse);
|
||||
}
|
||||
|
||||
public void insertLocation(WarehouseLocationEntity location) {
|
||||
locations.insert(location);
|
||||
}
|
||||
|
||||
public boolean existsLocationCode(long customerId, long warehouseId, String locationCode) {
|
||||
return locations.selectCount(new LambdaQueryWrapper<WarehouseLocationEntity>()
|
||||
.eq(WarehouseLocationEntity::getCustomerId, customerId)
|
||||
.eq(WarehouseLocationEntity::getWarehouseId, warehouseId)
|
||||
.eq(WarehouseLocationEntity::getLocationCode, locationCode)) > 0;
|
||||
}
|
||||
|
||||
public void saveWarehouse(WarehouseEntity warehouse) {
|
||||
warehouses.updateById(warehouse);
|
||||
}
|
||||
|
||||
public WarehouseEntity findOwned(long customerId, long id) {
|
||||
return warehouses.selectOne(new LambdaQueryWrapper<WarehouseEntity>()
|
||||
.eq(WarehouseEntity::getCustomerId, customerId)
|
||||
.eq(WarehouseEntity::getId, id));
|
||||
}
|
||||
|
||||
public boolean existsCode(long customerId, String code, Long excludedId) {
|
||||
return warehouses.selectCount(new LambdaQueryWrapper<WarehouseEntity>()
|
||||
.eq(WarehouseEntity::getCustomerId, customerId)
|
||||
.eq(WarehouseEntity::getWarehouseCode, code)
|
||||
.ne(excludedId != null, WarehouseEntity::getId, excludedId)) > 0;
|
||||
}
|
||||
|
||||
public PageResult<WarehouseEntity> page(long customerId, WarehouseRequests.QueryRequest query) {
|
||||
LambdaQueryWrapper<WarehouseEntity> wrapper = new LambdaQueryWrapper<WarehouseEntity>()
|
||||
.eq(WarehouseEntity::getCustomerId, customerId)
|
||||
.eq(StringUtils.hasText(query.status()), WarehouseEntity::getStatus, query.status())
|
||||
.eq(StringUtils.hasText(query.countryCode()), WarehouseEntity::getCountryCode, query.countryCode())
|
||||
.orderByDesc(WarehouseEntity::getCreatedAt);
|
||||
|
||||
if (StringUtils.hasText(query.capabilityCode())) {
|
||||
List<Long> ids = capabilities.selectList(new LambdaQueryWrapper<ServiceCapabilityEntity>()
|
||||
.select(ServiceCapabilityEntity::getWarehouseId)
|
||||
.eq(ServiceCapabilityEntity::getCustomerId, customerId)
|
||||
.eq(ServiceCapabilityEntity::getCapabilityCode, query.capabilityCode())
|
||||
.eq(ServiceCapabilityEntity::getEnabled, true))
|
||||
.stream()
|
||||
.map(ServiceCapabilityEntity::getWarehouseId)
|
||||
.distinct()
|
||||
.toList();
|
||||
if (ids.isEmpty()) {
|
||||
return new PageResult<>(List.of(), query.page(), query.size(), 0, 0);
|
||||
}
|
||||
wrapper.in(WarehouseEntity::getId, ids);
|
||||
}
|
||||
return PageResult.from(warehouses.selectPage(new Page<>(query.page(), query.size()), wrapper));
|
||||
}
|
||||
|
||||
public List<WarehouseAddressEntity> findAddresses(long customerId, long warehouseId) {
|
||||
return addresses.selectList(new LambdaQueryWrapper<WarehouseAddressEntity>()
|
||||
.eq(WarehouseAddressEntity::getCustomerId, customerId)
|
||||
.eq(WarehouseAddressEntity::getWarehouseId, warehouseId));
|
||||
}
|
||||
|
||||
public List<ServiceCapabilityEntity> findCapabilities(long customerId, long warehouseId) {
|
||||
return capabilities.selectList(new LambdaQueryWrapper<ServiceCapabilityEntity>()
|
||||
.eq(ServiceCapabilityEntity::getCustomerId, customerId)
|
||||
.eq(ServiceCapabilityEntity::getWarehouseId, warehouseId));
|
||||
}
|
||||
|
||||
public void physicallyDeleteChildren(long customerId, long warehouseId) {
|
||||
addresses.physicallyDeleteByWarehouse(customerId, warehouseId);
|
||||
capabilities.physicallyDeleteByWarehouse(customerId, warehouseId);
|
||||
}
|
||||
|
||||
public void insertAddress(WarehouseAddressEntity address) {
|
||||
addresses.insert(address);
|
||||
}
|
||||
|
||||
public void insertCapability(ServiceCapabilityEntity capability) {
|
||||
capabilities.insert(capability);
|
||||
}
|
||||
}
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
package com.baiyue.warehouse.repository;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baiyue.warehouse.entity.WarehouseLocationEntity;
|
||||
import com.baiyue.warehouse.entity.WarehousePalletEntity;
|
||||
import com.baiyue.warehouse.entity.WarehouseResourceLockEntity;
|
||||
import com.baiyue.warehouse.mapper.WarehouseLocationMapper;
|
||||
import com.baiyue.warehouse.mapper.WarehousePalletMapper;
|
||||
import com.baiyue.warehouse.mapper.WarehouseResourceLockMapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import jakarta.annotation.Resource;
|
||||
|
||||
@Repository
|
||||
public class WarehouseResourceLockRepository {
|
||||
@Resource private WarehouseResourceLockMapper locks;
|
||||
@Resource private WarehousePalletMapper pallets;
|
||||
@Resource private WarehouseLocationMapper locations;
|
||||
|
||||
public WarehouseResourceLockEntity findByReservationKey(long customerId, String reservationKey) {
|
||||
return locks.findByReservationKey(customerId, reservationKey);
|
||||
}
|
||||
|
||||
public WarehouseResourceLockEntity find(long customerId, long lockId) {
|
||||
return locks.selectOne(new LambdaQueryWrapper<WarehouseResourceLockEntity>()
|
||||
.eq(WarehouseResourceLockEntity::getCustomerId, customerId)
|
||||
.eq(WarehouseResourceLockEntity::getId, lockId));
|
||||
}
|
||||
|
||||
public WarehouseResourceLockEntity findActiveByPallet(long customerId, long palletId) {
|
||||
return locks.findActiveByPallet(customerId, palletId);
|
||||
}
|
||||
|
||||
public WarehousePalletEntity findPallet(long customerId, long palletId) {
|
||||
return pallets.selectOne(new LambdaQueryWrapper<WarehousePalletEntity>()
|
||||
.eq(WarehousePalletEntity::getCustomerId, customerId)
|
||||
.eq(WarehousePalletEntity::getId, palletId));
|
||||
}
|
||||
|
||||
public WarehousePalletEntity findPallet(long customerId, long warehouseId, long palletId) {
|
||||
return pallets.selectOne(new LambdaQueryWrapper<WarehousePalletEntity>()
|
||||
.eq(WarehousePalletEntity::getCustomerId, customerId)
|
||||
.eq(WarehousePalletEntity::getWarehouseId, warehouseId)
|
||||
.eq(WarehousePalletEntity::getId, palletId));
|
||||
}
|
||||
|
||||
public WarehouseLocationEntity findLocation(long customerId, long warehouseId, long locationId) {
|
||||
return locations.selectOne(new LambdaQueryWrapper<WarehouseLocationEntity>()
|
||||
.eq(WarehouseLocationEntity::getCustomerId, customerId)
|
||||
.eq(WarehouseLocationEntity::getWarehouseId, warehouseId)
|
||||
.eq(WarehouseLocationEntity::getId, locationId));
|
||||
}
|
||||
|
||||
public int occupyPallet(long customerId, long warehouseId, long palletId, long locationId) {
|
||||
return locks.occupyPallet(customerId, warehouseId, palletId, locationId);
|
||||
}
|
||||
|
||||
public int occupyLocation(long customerId, long warehouseId, long locationId) {
|
||||
return locks.occupyLocation(customerId, warehouseId, locationId);
|
||||
}
|
||||
|
||||
public void insert(WarehouseResourceLockEntity lock) { locks.insert(lock); }
|
||||
|
||||
public int releasePallet(WarehouseResourceLockEntity lock) {
|
||||
return locks.releasePallet(lock.getCustomerId(), lock.getWarehouseId(), lock.getPalletId(), lock.getLocationId());
|
||||
}
|
||||
|
||||
public int releasePalletAtVirtualLocation(WarehouseResourceLockEntity lock) {
|
||||
return locks.releasePalletAtVirtualLocation(lock.getCustomerId(), lock.getWarehouseId(),
|
||||
lock.getPalletId(), lock.getLocationId());
|
||||
}
|
||||
|
||||
public int scrapPallet(WarehouseResourceLockEntity lock) {
|
||||
return locks.scrapPallet(lock.getCustomerId(), lock.getWarehouseId(), lock.getPalletId(), lock.getLocationId());
|
||||
}
|
||||
|
||||
public int scrapPalletWithoutLock(long customerId, long palletId) {
|
||||
return locks.scrapPalletWithoutLock(customerId, palletId);
|
||||
}
|
||||
|
||||
public int scrapPalletAtVirtualLocation(WarehouseResourceLockEntity lock) {
|
||||
return locks.scrapPalletAtVirtualLocation(lock.getCustomerId(), lock.getWarehouseId(),
|
||||
lock.getPalletId(), lock.getLocationId());
|
||||
}
|
||||
|
||||
public int releaseLocation(WarehouseResourceLockEntity lock) {
|
||||
return locks.releaseLocation(lock.getCustomerId(), lock.getWarehouseId(), lock.getLocationId());
|
||||
}
|
||||
|
||||
public int close(WarehouseResourceLockEntity lock, String status) { return locks.closeLock(lock.getId(), status); }
|
||||
}
|
||||
+158
@@ -0,0 +1,158 @@
|
||||
package com.baiyue.warehouse.repository;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baiyue.common.core.api.PageResult;
|
||||
import com.baiyue.warehouse.dto.LocationRequests;
|
||||
import com.baiyue.warehouse.dto.PalletRequests;
|
||||
import com.baiyue.warehouse.entity.WarehouseEntity;
|
||||
import com.baiyue.warehouse.entity.WarehouseLocationEntity;
|
||||
import com.baiyue.warehouse.entity.WarehousePalletEntity;
|
||||
import com.baiyue.warehouse.mapper.WarehouseLocationMapper;
|
||||
import com.baiyue.warehouse.mapper.WarehouseMapper;
|
||||
import com.baiyue.warehouse.mapper.WarehousePalletMapper;
|
||||
import com.baiyue.warehouse.mapper.WarehousePalletBindingMapper;
|
||||
import com.baiyue.warehouse.entity.WarehousePalletBindingEntity;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import org.springframework.util.StringUtils;
|
||||
import jakarta.annotation.Resource;
|
||||
|
||||
@Repository
|
||||
public class WarehouseResourceRepository {
|
||||
@Resource private WarehouseMapper warehouses;
|
||||
@Resource private WarehouseLocationMapper locations;
|
||||
@Resource private WarehousePalletMapper pallets;
|
||||
@Resource private WarehousePalletBindingMapper bindings;
|
||||
|
||||
public WarehousePalletBindingEntity findPalletBinding(long customerId, long warehouseId,
|
||||
String businessType, String businessId) {
|
||||
return bindings.find(customerId, warehouseId, businessType, businessId);
|
||||
}
|
||||
|
||||
public void insertPalletBinding(WarehousePalletBindingEntity entity) {
|
||||
bindings.insert(entity);
|
||||
}
|
||||
|
||||
public boolean warehouseOwned(long customerId, long warehouseId) {
|
||||
return warehouses.selectCount(new LambdaQueryWrapper<WarehouseEntity>()
|
||||
.eq(WarehouseEntity::getCustomerId, customerId)
|
||||
.eq(WarehouseEntity::getId, warehouseId)) > 0;
|
||||
}
|
||||
|
||||
public WarehouseEntity findWarehouse(long customerId, long warehouseId) {
|
||||
return warehouses.selectOne(new LambdaQueryWrapper<WarehouseEntity>()
|
||||
.eq(WarehouseEntity::getCustomerId, customerId)
|
||||
.eq(WarehouseEntity::getId, warehouseId));
|
||||
}
|
||||
|
||||
public WarehouseLocationEntity findDefaultVirtualLocation(long customerId, long warehouseId) {
|
||||
return locations.selectOne(new LambdaQueryWrapper<WarehouseLocationEntity>()
|
||||
.eq(WarehouseLocationEntity::getCustomerId, customerId)
|
||||
.eq(WarehouseLocationEntity::getWarehouseId, warehouseId)
|
||||
.eq(WarehouseLocationEntity::getLocationType, "VIRTUAL")
|
||||
.eq(WarehouseLocationEntity::getStatus, "ACTIVE")
|
||||
.orderByAsc(WarehouseLocationEntity::getCreatedAt)
|
||||
.last("LIMIT 1"));
|
||||
}
|
||||
|
||||
public WarehouseLocationEntity findLocationByCode(long customerId, long warehouseId, String locationCode) {
|
||||
return locations.selectOne(new LambdaQueryWrapper<WarehouseLocationEntity>()
|
||||
.eq(WarehouseLocationEntity::getCustomerId, customerId)
|
||||
.eq(WarehouseLocationEntity::getWarehouseId, warehouseId)
|
||||
.eq(WarehouseLocationEntity::getLocationCode, locationCode));
|
||||
}
|
||||
|
||||
public void insertLocation(WarehouseLocationEntity entity) {
|
||||
locations.insert(entity);
|
||||
}
|
||||
|
||||
public int insertDefaultVirtualLocationIgnore(WarehouseLocationEntity entity) {
|
||||
return locations.insertDefaultVirtualLocationIgnore(entity);
|
||||
}
|
||||
|
||||
public void updateLocation(WarehouseLocationEntity entity) {
|
||||
locations.updateById(entity);
|
||||
}
|
||||
|
||||
public WarehouseLocationEntity findLocation(long customerId, long warehouseId, long id) {
|
||||
return locations.selectOne(new LambdaQueryWrapper<WarehouseLocationEntity>()
|
||||
.eq(WarehouseLocationEntity::getCustomerId, customerId)
|
||||
.eq(WarehouseLocationEntity::getWarehouseId, warehouseId)
|
||||
.eq(WarehouseLocationEntity::getId, id));
|
||||
}
|
||||
|
||||
public boolean locationCodeExists(long customerId, long warehouseId, String code, Long excludedId) {
|
||||
return locations.selectCount(new LambdaQueryWrapper<WarehouseLocationEntity>()
|
||||
.eq(WarehouseLocationEntity::getCustomerId, customerId)
|
||||
.eq(WarehouseLocationEntity::getWarehouseId, warehouseId)
|
||||
.eq(WarehouseLocationEntity::getLocationCode, code)
|
||||
.ne(excludedId != null, WarehouseLocationEntity::getId, excludedId)) > 0;
|
||||
}
|
||||
|
||||
public PageResult<WarehouseLocationEntity> pageLocations(long customerId, long warehouseId,
|
||||
LocationRequests.QueryRequest query) {
|
||||
var wrapper = new LambdaQueryWrapper<WarehouseLocationEntity>()
|
||||
.eq(WarehouseLocationEntity::getCustomerId, customerId)
|
||||
.eq(WarehouseLocationEntity::getWarehouseId, warehouseId)
|
||||
.eq(StringUtils.hasText(query.zoneCode()), WarehouseLocationEntity::getZoneCode, query.zoneCode())
|
||||
.eq(StringUtils.hasText(query.locationType()), WarehouseLocationEntity::getLocationType, query.locationType())
|
||||
.eq(StringUtils.hasText(query.status()), WarehouseLocationEntity::getStatus, query.status())
|
||||
.and(StringUtils.hasText(query.keyword()), q -> q
|
||||
.like(WarehouseLocationEntity::getLocationCode, query.keyword())
|
||||
.or().like(WarehouseLocationEntity::getZoneCode, query.keyword()))
|
||||
.orderByAsc(WarehouseLocationEntity::getZoneCode)
|
||||
.orderByAsc(WarehouseLocationEntity::getLocationCode);
|
||||
return PageResult.from(locations.selectPage(new Page<>(query.page(), query.size()), wrapper));
|
||||
}
|
||||
|
||||
public void deleteLocation(long id) {
|
||||
locations.deleteById(id);
|
||||
}
|
||||
|
||||
public boolean locationHasPallets(long customerId, long warehouseId, long locationId) {
|
||||
return pallets.selectCount(new LambdaQueryWrapper<WarehousePalletEntity>()
|
||||
.eq(WarehousePalletEntity::getCustomerId, customerId)
|
||||
.eq(WarehousePalletEntity::getWarehouseId, warehouseId)
|
||||
.eq(WarehousePalletEntity::getLocationId, locationId)) > 0;
|
||||
}
|
||||
|
||||
public void insertPallet(WarehousePalletEntity entity) {
|
||||
pallets.insert(entity);
|
||||
}
|
||||
|
||||
public void updatePallet(WarehousePalletEntity entity) {
|
||||
pallets.updateById(entity);
|
||||
}
|
||||
|
||||
public WarehousePalletEntity findPallet(long customerId, long warehouseId, long id) {
|
||||
return pallets.selectOne(new LambdaQueryWrapper<WarehousePalletEntity>()
|
||||
.eq(WarehousePalletEntity::getCustomerId, customerId)
|
||||
.eq(WarehousePalletEntity::getWarehouseId, warehouseId)
|
||||
.eq(WarehousePalletEntity::getId, id));
|
||||
}
|
||||
|
||||
public boolean palletCodeExists(long customerId, long warehouseId, String code, Long excludedId) {
|
||||
return pallets.selectCount(new LambdaQueryWrapper<WarehousePalletEntity>()
|
||||
.eq(WarehousePalletEntity::getCustomerId, customerId)
|
||||
.eq(WarehousePalletEntity::getWarehouseId, warehouseId)
|
||||
.eq(WarehousePalletEntity::getPalletCode, code)
|
||||
.ne(excludedId != null, WarehousePalletEntity::getId, excludedId)) > 0;
|
||||
}
|
||||
|
||||
public PageResult<WarehousePalletEntity> pagePallets(long customerId, long warehouseId,
|
||||
PalletRequests.QueryRequest query) {
|
||||
var wrapper = new LambdaQueryWrapper<WarehousePalletEntity>()
|
||||
.eq(WarehousePalletEntity::getCustomerId, customerId)
|
||||
.eq(WarehousePalletEntity::getWarehouseId, warehouseId)
|
||||
.eq(StringUtils.hasText(query.palletType()), WarehousePalletEntity::getPalletType, query.palletType())
|
||||
.eq(StringUtils.hasText(query.status()), WarehousePalletEntity::getStatus, query.status())
|
||||
.eq(query.locationId() != null, WarehousePalletEntity::getLocationId, query.locationId())
|
||||
.like(StringUtils.hasText(query.keyword()), WarehousePalletEntity::getPalletCode, query.keyword())
|
||||
.orderByDesc(WarehousePalletEntity::getCreatedAt);
|
||||
return PageResult.from(pallets.selectPage(new Page<>(query.page(), query.size()), wrapper));
|
||||
}
|
||||
|
||||
public void deletePallet(long id) {
|
||||
pallets.deleteById(id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user