<?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.cn.fdapfe.biz.mapper.DataMapper">
    
    <resultMap type="com.cn.fdapfe.biz.domain.Data" id="DataResult" >
        <result property="id"    column="id"    />
        <result property="name"    column="name"    />
        <result property="type"    column="type"    />
        <result property="filePath"    column="file_path"    />
        <result property="remark"    column="remark"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="fileName"    column="file_name"    />
        <result property="fileSize"    column="file_size"    />
        <result property="fileSizeBytes"    column="file_size_bytes"    />
        <result property="fileSuffix"    column="file_suffix"    />
        <result property="url"    column="url"    />
    </resultMap>

    <sql id="selectDataVo">
        select id, name, type, file_path, remark, create_by, create_time, update_by, update_time ,file_name , file_size , file_size_bytes , file_suffix ,url from biz_data
    </sql>

    <select id="selectDataList"  resultMap="DataResult">
        <include refid="selectDataVo"/>
        <where>  
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="type != null  and type != ''"> and type = #{type}</if>
        </where>
    </select>
    
    <select id="selectDataById"  resultMap="DataResult">
        <include refid="selectDataVo"/>
        where id = #{id}
    </select>

    <insert id="insertData"  useGeneratedKeys="true" keyProperty="id">
        insert into biz_data
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null">name,</if>
            <if test="type != null">type,</if>
            <if test="filePath != null">file_path,</if>
            <if test="remark != null">remark,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null">#{name},</if>
            <if test="type != null">#{type},</if>
            <if test="filePath != null">#{filePath},</if>
            <if test="remark != null">#{remark},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateData">
        update biz_data
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null">name = #{name},</if>
            <if test="type != null">type = #{type},</if>
            <if test="filePath != null">file_path = #{filePath},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteDataById" >
        delete from biz_data where id = #{id}
    </delete>

    <delete id="deleteDataByIds">
        delete from biz_data where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <select id="getOptions" resultType="map">
        select id,name from biz_data order by id desc
    </select>
</mapper>