<?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.pdaaphm.system.mapper.DataMapper">
    
    <resultMap type="Data" id="DataResult">
        <result property="id"    column="id"    />
        <result property="dataName"    column="data_name"    />
        <result property="dataType"    column="data_type"    />
        <result property="dataPath"    column="data_path"    />
        <result property="imagePath"    column="image_path"    />
        <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="remark"    column="remark"    />
    </resultMap>

    <sql id="selectDataVo">
        select id, data_name, data_type, data_path, image_path, create_by, create_time, update_by, update_time, remark from t_data
    </sql>

    <select id="selectDataList" parameterType="Data" resultMap="DataResult">
        <include refid="selectDataVo"/>
        <where>  
            <if test="dataName != null  and dataName != ''"> and data_name like concat('%', #{dataName}, '%')</if>
            <if test="dataType != null  and dataType != ''"> and data_type = #{dataType}</if>
            <if test="dataPath != null  and dataPath != ''"> and data_path = #{dataPath}</if>
        </where>
        order by create_time desc
    </select>

    <select id="selectPreprocessDataList" parameterType="Data" resultMap="DataResult">
        <include refid="selectDataVo"/>
        <where>
            data_type in ('0','1','2')
            <if test="dataName != null  and dataName != ''"> and data_name like concat('%', #{dataName}, '%')</if>
            <if test="dataType != null  and dataType != ''"> and data_type = #{dataType}</if>
            <if test="dataPath != null  and dataPath != ''"> and data_path = #{dataPath}</if>
        </where>
    </select>
    
    <select id="selectDataById" parameterType="Long" resultMap="DataResult">
        <include refid="selectDataVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertData" parameterType="Data" useGeneratedKeys="true" keyProperty="id">
        insert into t_data
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="dataName != null">data_name,</if>
            <if test="dataType != null and dataType != ''">data_type,</if>
            <if test="dataPath != null">data_path,</if>
            <if test="imagePath != null">image_path,</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>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="dataName != null">#{dataName},</if>
            <if test="dataType != null and dataType != ''">#{dataType},</if>
            <if test="dataPath != null">#{dataPath},</if>
            <if test="imagePath != null">#{imagePath},</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>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateData" parameterType="Data">
        update t_data
        <trim prefix="SET" suffixOverrides=",">
            <if test="dataName != null">data_name = #{dataName},</if>
            <if test="dataType != null and dataType != ''">data_type = #{dataType},</if>
            <if test="dataPath != null">data_path = #{dataPath},</if>
            <if test="imagePath != null">image_path = #{imagePath},</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>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteDataById" parameterType="Long">
        delete from t_data where id = #{id}
    </delete>

    <delete id="deleteDataByIds" parameterType="String">
        delete from t_data where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>