fix: execute overseas pallet transitions

This commit is contained in:
2026-08-25 18:07:48 +08:00
parent 7471f7e81f
commit 335ad8269f
2 changed files with 34 additions and 2 deletions
@@ -20,12 +20,12 @@ public interface WarehousePalletTransitionMapper extends BaseMapper<WarehousePal
@Param("palletId") long palletId);
@Select("SELECT COUNT(*) FROM wh_location WHERE id=#{locationId} AND customer_id=0 " +
"AND warehouse_id=#{warehouseId} AND status&lt;&gt;'INACTIVE' AND deleted=0")
"AND warehouse_id=#{warehouseId} AND status<>'INACTIVE' AND deleted=0")
long countActiveLocation(@Param("warehouseId") long warehouseId, @Param("locationId") long locationId);
@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 " +
"AND warehouse_id=#{warehouseId} AND version=#{expectedVersion} AND status&lt;&gt;'SCRAPPED' AND deleted=0")
"AND warehouse_id=#{warehouseId} AND version=#{expectedVersion} AND status<>'SCRAPPED' AND deleted=0")
int transition(@Param("warehouseId") long warehouseId, @Param("palletId") long palletId,
@Param("targetStatus") String targetStatus, @Param("targetLocationId") long targetLocationId,
@Param("expectedVersion") int expectedVersion);
@@ -0,0 +1,32 @@
package com.baiyue.warehouse.mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.junit.jupiter.api.Test;
import java.lang.reflect.Method;
import java.util.Arrays;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
class WarehousePalletTransitionMapperContractTest {
@Test
void annotationSqlUsesNativeComparisonOperatorsInsteadOfXmlEntities() throws Exception {
Method locationQuery = WarehousePalletTransitionMapper.class.getMethod(
"countActiveLocation", long.class, long.class);
String selectSql = String.join(" ", locationQuery.getAnnotation(Select.class).value());
Method transition = Arrays.stream(WarehousePalletTransitionMapper.class.getMethods())
.filter(method -> method.getName().equals("transition"))
.findFirst()
.orElseThrow();
String updateSql = String.join(" ", transition.getAnnotation(Update.class).value());
assertTrue(selectSql.contains("status<>'INACTIVE'"));
assertTrue(updateSql.contains("status<>'SCRAPPED'"));
assertFalse(selectSql.contains("&lt;") || selectSql.contains("&gt;"));
assertFalse(updateSql.contains("&lt;") || updateSql.contains("&gt;"));
}
}