<?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.OrderItemRepository">
    
    <!-- 根据平台SKU更新匹配状态 -->
    <update id="updateMatchByPlatformSku">
        UPDATE order_items 
        SET erp_sku_id = #{erpSkuId}, 
            erp_sku = #{erpSku}, 
            match_status = 1 
        WHERE platform_sku = #{platformSku} AND match_status = 0
    </update>
    
    <!-- 解除匹配状态 -->
    <update id="resetMatchStatus">
        UPDATE order_items 
        SET match_status = 0 
        WHERE platform_sku = #{platformSku} AND erp_sku_id = #{erpSkuId}
    </update>
    
    <!-- 查询订单的所有明细 -->
    <select id="findByOrderId" resultType="com.erp.product.sku.entity.OrderItem">
        SELECT * FROM order_items 
        WHERE order_id = #{orderId}
    </select>
    
</mapper>
