<?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.jarvis.mapper.GroupRebateExcelUploadMapper">

    <resultMap id="GroupRebateExcelUploadResult" type="GroupRebateExcelUpload">
        <id property="id" column="id"/>
        <result property="documentTitle" column="document_title"/>
        <result property="originalFilename" column="original_filename"/>
        <result property="filePath" column="file_path"/>
        <result property="fileSize" column="file_size"/>
        <result property="importStatus" column="import_status"/>
        <result property="dataRows" column="data_rows"/>
        <result property="updatedOrders" column="updated_orders"/>
        <result property="notFoundCount" column="not_found_count"/>
        <result property="resultDetailJson" column="result_detail_json"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
    </resultMap>

    <sql id="selectCols">
        select id, document_title, original_filename, file_path, file_size, import_status,
               data_rows, updated_orders, not_found_count, result_detail_json, create_by, create_time
        from jd_group_rebate_excel_upload
    </sql>

    <insert id="insertGroupRebateExcelUpload" parameterType="GroupRebateExcelUpload" useGeneratedKeys="true" keyProperty="id">
        insert into jd_group_rebate_excel_upload (
            document_title, original_filename, file_path, file_size, import_status,
            data_rows, updated_orders, not_found_count, result_detail_json, create_by, create_time
        ) values (
            #{documentTitle}, #{originalFilename}, #{filePath}, #{fileSize}, #{importStatus},
            #{dataRows}, #{updatedOrders}, #{notFoundCount}, #{resultDetailJson}, #{createBy}, now()
        )
    </insert>

    <update id="updateGroupRebateExcelUpload" parameterType="GroupRebateExcelUpload">
        update jd_group_rebate_excel_upload
        set document_title = #{documentTitle},
            original_filename = #{originalFilename},
            file_path = #{filePath},
            file_size = #{fileSize},
            import_status = #{importStatus},
            data_rows = #{dataRows},
            updated_orders = #{updatedOrders},
            not_found_count = #{notFoundCount},
            result_detail_json = #{resultDetailJson}
        where id = #{id}
    </update>

    <delete id="deleteGroupRebateExcelUploadById" parameterType="long">
        delete from jd_group_rebate_excel_upload where id = #{id}
    </delete>

    <select id="selectGroupRebateExcelUploadById" parameterType="long" resultMap="GroupRebateExcelUploadResult">
        <include refid="selectCols"/>
        where id = #{id}
    </select>

    <select id="selectGroupRebateExcelUploadList" parameterType="GroupRebateExcelUpload" resultMap="GroupRebateExcelUploadResult">
        <include refid="selectCols"/>
        <where>
            <if test="documentTitle != null and documentTitle != ''">
                and document_title like concat('%', #{documentTitle}, '%')
            </if>
            <if test="originalFilename != null and originalFilename != ''">
                and original_filename like concat('%', #{originalFilename}, '%')
            </if>
            <if test="importStatus != null">
                and import_status = #{importStatus}
            </if>
            <if test="params.beginTime != null and params.beginTime != ''">
                and date(create_time) &gt;= #{params.beginTime}
            </if>
            <if test="params.endTime != null and params.endTime != ''">
                and date(create_time) &lt;= #{params.endTime}
            </if>
        </where>
        order by id desc
    </select>
</mapper>
