<?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.nantian.cloud.dbcapp.mapper.record.FileExportMapper">

    <resultMap type="com.nantian.cloud.dbcapp.vo.FileExportVO" id="FileExportVOMap">
        <result property="id" column="id" jdbcType="INTEGER"/>
        <result property="createdBy" column="created_by" jdbcType="VARCHAR"/>
        <result property="createdTime" column="created_time" jdbcType="DATETIMEOFFSET"/>
        <result property="updatedBy" column="updated_by" jdbcType="VARCHAR"/>
        <result property="updatedTime" column="updated_time" jdbcType="DATE"/>
        <result property="fileName" column="file_name" jdbcType="VARCHAR"/>
        <result property="filePath" column="file_path" jdbcType="VARCHAR"/>
        <result property="startTime" column="start_time" jdbcType="DATE"/>
        <result property="endTime" column="end_time" jdbcType="DATE"/>
        <result property="completed" column="completed" jdbcType="VARCHAR"/>
        <result property="completedName" column="completedName" jdbcType="VARCHAR"/>
    </resultMap>

    <sql id="list">
        id,created_by,created_time,updated_by,updated_time,file_name,file_path,start_time,end_time,completed,
        case when completed = '0' then '未完成' else '已完成' end as completedName
    </sql>


    <select id="getFileExportByFileName" resultMap="FileExportVOMap">
        select id,completed
        from file_export
        where file_name = #{fileName}
        limit 1
    </select>

    <select id="getFileExportList" resultType="com.nantian.cloud.dbcapp.vo.FileExportVO">
        select <include refid="list"></include>
        from file_export
        <where>
            <if test="fileName != null and fileName != ''">
                and file_name like concat('%',#{fileName},'%')
            </if>
        </where>
    </select>

    <select id="getFileExportById" resultMap="FileExportVOMap">
        select <include refid="list"></include>
        from file_export
        where id = #{id}
    </select>

    <update id="updateFileExport" parameterType="com.nantian.cloud.dbcapp.vo.FileExportVO">
        update file_export
        <set>
            <if test="createdBy != null and createdBy != ''">
                created_by = #{createdBy},
            </if>
            <if test="createdTime != null">
                created_time = #{createdTime},
            </if>
            <if test="updatedBy != null and updatedBy != ''">
                updated_by = #{updatedBy},
            </if>
            <if test="updatedTime != null">
                updated_time = #{updatedTime},
            </if>
            <if test="fileName != null and fileName != ''">
                file_name = #{fileName},
            </if>
            <if test="filePath != null and filePath != ''">
                file_path = #{filePath},
            </if>
            <if test="startTime != null">
                start_time = #{startTime},
            </if>
            <if test="endTime != null">
                end_time = #{endTime},
            </if>
            <if test="completed != null and completed != ''">
                completed = #{completed},
            </if>
        </set>
        where id = #{id}
    </update>

    <insert id="saveFileExport" useGeneratedKeys="true" keyProperty="id" parameterType="com.nantian.cloud.dbcapp.vo.FileExportVO">
        insert into file_export(created_by,created_time,updated_by,updated_time,file_name,file_path,start_time,end_time,completed)
        values (#{createdBy},#{createdTime},#{updatedBy},#{updatedTime},#{fileName},#{filePath},#{startTime},#{endTime},#{completed})
    </insert>

    <delete id="deleteFileExportById" parameterType="int">
        delete from file_export where id = #{id}
    </delete>


</mapper>
