<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.erp.product.sku.repository.PlatformRepository">
    
    <!-- 查询未绑定的平台SKU -->
    <select id="findUnmatched" resultType="com.erp.product.sku.entity.Platform">
        SELECT p.* FROM platforms p 
        WHERE NOT EXISTS (
            SELECT 1 FROM platform_sku_bindings b 
            WHERE b.platform_sku_id = p.id AND b.is_active = true
        ) 
        ORDER BY p.updated_at DESC
    </select>
    
    <!-- 根据状态查询未绑定的平台SKU -->
    <select id="findUnmatchedByStatus" resultType="com.erp.product.sku.entity.Platform">
        SELECT p.* FROM platforms p 
        WHERE NOT EXISTS (
            SELECT 1 FROM platform_sku_bindings b 
            WHERE b.platform_sku_id = p.id AND b.is_active = true
        ) 
        AND p.status = #{status}
        ORDER BY p.updated_at DESC
    </select>
    
    <!-- 根据ID列表查询未绑定的平台SKU -->
    <select id="findUnmatchedByIds" resultType="com.erp.product.sku.entity.Platform">
        SELECT p.* FROM platforms p 
        WHERE p.id IN 
        <foreach collection="list" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
        AND NOT EXISTS (
            SELECT 1 FROM platform_sku_bindings b 
            WHERE b.platform_sku_id = p.id AND b.is_active = true
        )
    </select>
    
</mapper>
