<?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.ruoyi.excel.wecom.mapper.CustomerExportDataHistoryMapper">

    <!-- 根据客户ID查询最大版本号 -->
    <select id="selectMaxVersionByCustomerId" resultType="java.lang.Integer">
        SELECT MAX(version)
        FROM customer_export_data_history
        WHERE customer_id = #{customerId}
    </select>

    <!-- 根据客户ID和版本号查询历史记录 -->
    <select id="selectByCustomerIdAndVersion" resultType="com.ruoyi.excel.wecom.domain.CustomerExportDataHistory">
        SELECT *
        FROM customer_export_data_history
        WHERE customer_id = #{customerId} AND version = #{version}
    </select>

    <!-- 根据客户ID查询所有历史记录（按版本号倒序） -->
    <select id="selectHistoryByCustomerId" resultType="com.ruoyi.excel.wecom.domain.CustomerExportDataHistory">
        SELECT *
        FROM customer_export_data_history
        WHERE customer_id = #{customerId}
        ORDER BY version DESC
    </select>

</mapper>
