package org.qinan.safetyeval.infrastructure.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.qinan.safetyeval.infrastructure.dataobject.QualFilingChangeDetailDO;

import java.util.List;

@Mapper
public interface QualFilingChangeDetailMapper extends BaseMapper<QualFilingChangeDetailDO> {

    @Select("SELECT d.* FROM qual_filing_change_detail d "
            + "INNER JOIN qual_filing_change c ON d.change_id = c.id "
            + "WHERE c.origin_filing_id = #{originFilingId} AND d.delete_enum = 'false' AND c.delete_enum = 'false' "
            + "ORDER BY d.create_time DESC")
    List<QualFilingChangeDetailDO> selectByOriginFilingId(@Param("originFilingId") Long originFilingId);

    @Select("SELECT COUNT(1) FROM qual_filing_change_detail d "
            + "INNER JOIN qual_filing_change c ON d.change_id = c.id "
            + "WHERE c.origin_filing_id = #{originFilingId} AND d.delete_enum = 'false' AND c.delete_enum = 'false'")
    int countByOriginFilingId(@Param("originFilingId") Long originFilingId);
}
