<?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.mirs.biz.mapper.SampleMapper">
    
    <resultMap type="Sample" id="SampleResult">
        <result property="id"    column="id"    />
        <result property="dataType"    column="data_type"    />
        <result property="sampleType"    column="sample_type"    />
        <result property="sampleModel"    column="sample_model"    />
        <result property="sampleImage"    column="sample_image"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectSampleVo">
        select id, data_type, sample_type, sample_model, sample_image, create_by, create_time, update_by, update_time from biz_sample_t
    </sql>

    <select id="selectSampleList" parameterType="Sample" resultMap="SampleResult">
        <include refid="selectSampleVo"/>
        <where>  
            <if test="dataType != null  and dataType != ''"> and data_type = #{dataType}</if>
            <if test="sampleType != null  and sampleType != ''"> and sample_type like concat('%', #{sampleType}, '%')</if>
            <if test="sampleModel != null  and sampleModel != ''"> and sample_model like concat('%', #{sampleModel}, '%')</if>
        </where>
    </select>

    <select id="getOne" parameterType="Sample" resultMap="SampleResult">
        <include refid="selectSampleVo"/>
        <where>
            <if test="dataType != null  and dataType != ''"> and data_type = #{dataType}</if>
            <if test="sampleType != null  and sampleType != ''"> and sample_type = #{sampleType}</if>
            <if test="sampleModel != null  and sampleModel != ''"> and sample_model = #{sampleModel}</if>
        </where>
        limit 1
    </select>
    
    <select id="selectSampleById" parameterType="Long" resultMap="SampleResult">
        <include refid="selectSampleVo"/>
        where id = #{id}
    </select>

    <insert id="insertSample" parameterType="Sample" useGeneratedKeys="true" keyProperty="id">
        insert into biz_sample_t
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="dataType != null">data_type,</if>
            <if test="sampleType != null">sample_type,</if>
            <if test="sampleModel != null">sample_model,</if>
            <if test="sampleImage != null">sample_image,</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="dataType != null">#{dataType},</if>
            <if test="sampleType != null">#{sampleType},</if>
            <if test="sampleModel != null">#{sampleModel},</if>
            <if test="sampleImage != null">#{sampleImage},</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="updateSample" parameterType="Sample">
        update biz_sample_t
        <trim prefix="SET" suffixOverrides=",">
            <if test="dataType != null">data_type = #{dataType},</if>
            <if test="sampleType != null">sample_type = #{sampleType},</if>
            <if test="sampleModel != null">sample_model = #{sampleModel},</if>
            <if test="sampleImage != null">sample_image = #{sampleImage},</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="deleteSampleById" parameterType="Long">
        delete from biz_sample_t where id = #{id}
    </delete>

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

    <select id="getSampleType" parameterType="String" resultType="HashMap">
        select distinct sample_type name, sample_type value from biz_sample_t where data_type = #{value}
    </select>
    <select id="getSampleModel" parameterType="Sample" resultType="HashMap">
        select distinct sample_model name, sample_model value from biz_sample_t where data_type = #{dataType} and sample_type = #{sampleType}
    </select>
</mapper>