fix(warehouse-overseas): enforce pallet location invariant

This commit is contained in:
2026-09-08 14:47:35 +08:00
parent 07688005a1
commit a0ad3382af
9 changed files with 276 additions and 25 deletions
@@ -4,6 +4,7 @@ import org.apache.ibatis.annotations.Mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baiyue.warehouse.entity.WarehousePalletEntity;
import com.baiyue.warehouse.entity.WarehouseLocationEntity;
import com.baiyue.warehouse.entity.WarehousePalletOperationEntity;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
@@ -22,9 +23,17 @@ public interface WarehousePalletTransitionMapper extends BaseMapper<WarehousePal
WarehousePalletEntity lockPublicPallet(@Param("warehouseId") long warehouseId,
@Param("palletId") long palletId);
@Select("SELECT COUNT(*) FROM wh_location WHERE id=#{locationId} AND customer_id=0 " +
"AND warehouse_id=#{warehouseId} AND status<>'INACTIVE' AND deleted=0")
long countActiveLocation(@Param("warehouseId") long warehouseId, @Param("locationId") long locationId);
@Select("SELECT * FROM wh_location WHERE id=#{locationId} AND customer_id=0 " +
"AND warehouse_id=#{warehouseId} AND deleted=0 LIMIT 1 FOR UPDATE")
WarehouseLocationEntity lockPublicLocation(@Param("warehouseId") long warehouseId,
@Param("locationId") long locationId);
@Update("UPDATE wh_location SET status=#{targetStatus},version=version+1,updated_at=CURRENT_TIMESTAMP(3) " +
"WHERE id=#{locationId} AND customer_id=0 AND warehouse_id=#{warehouseId} " +
"AND status=#{expectedStatus} AND deleted=0")
int transitionLocation(@Param("warehouseId") long warehouseId, @Param("locationId") long locationId,
@Param("expectedStatus") String expectedStatus,
@Param("targetStatus") String targetStatus);
@Update("UPDATE wh_pallet SET status=#{targetStatus},location_id=#{targetLocationId},version=version+1," +
"updated_at=CURRENT_TIMESTAMP(3) WHERE id=#{palletId} AND customer_id=0 " +
@@ -43,7 +43,7 @@ public interface WarehouseResourceLockMapper extends BaseMapper<WarehouseResourc
@Update("""
UPDATE wh_pallet
SET status = 'IDLE', location_id = NULL, updated_at = CURRENT_TIMESTAMP(3), version = version + 1
SET status = 'IDLE', updated_at = CURRENT_TIMESTAMP(3), version = version + 1
WHERE id = #{palletId} AND customer_id = #{customerId} AND warehouse_id = #{warehouseId}
AND location_id = #{locationId} AND status = 'OCCUPIED' AND deleted = 0
""")