package com.erp.invoice.repository;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.erp.invoice.entity.InvoiceItem;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 发票明细数据访问层
 */
@Mapper
public interface InvoiceItemRepository extends BaseMapper<InvoiceItem> {
    
    /**
     * 根据发票ID查询所有明细
     */
    @Select("SELECT * FROM invoice_items WHERE invoice_id = #{invoiceId} AND deleted_at IS NULL ORDER BY id")
    List<InvoiceItem> findByInvoiceId(@Param("invoiceId") Long invoiceId);
    
    /**
     * 根据发票ID删除所有明细（逻辑删除）
     */
    @Select("UPDATE invoice_items SET deleted_at = NOW() WHERE invoice_id = #{invoiceId}")
    int deleteByInvoiceId(@Param("invoiceId") Long invoiceId);
}
