<?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.test.test.mapper.TestDefectMapper">

    <resultMap type="TestDefect" id="TestDefectResult">
        <result property="id"    column="id"    />
        <result property="serialNumber"    column="serial_number"    />
        <result property="name"    column="name"    />
        <result property="outline"    column="outline"    />
        <result property="detail"    column="detail"    />
        <result property="status"    column="status"    />
        <result property="manager"    column="manager"    />
        <result property="dev"    column="dev"    />
        <result property="level"    column="level"    />
        <result property="type"    column="type"    />
        <result property="reappearance"    column="reappearance"    />
        <result property="test"    column="test"    />
        <result property="mail"    column="mail"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="version"    column="version"    />
        <result property="delFlag"    column="del_flag"    />
    </resultMap>

    <sql id="selectTestDefectVo">
        select id, serial_number, name, outline, detail, status, manager, dev, level, type, reappearance, test, mail, create_time, update_time, version, del_flag from test_defect
    </sql>

    <select id="selectTestDefectList" parameterType="TestDefectListQO" resultMap="TestDefectResult">
        SELECT
        tp.id,
        tp.serial_number,
        tp.name ,
        tp.outline,
        tp.level,
        tp.type,
        tp.status,
        su.user_name AS manager,
        tp.create_time,
        tp.reappearance,
        tp.version,
        tp.test
        FROM test_defect tp
        LEFT JOIN sys_user su ON su.user_id = tp.manager
        where tp.del_flag = '0'
        <if test="serialNumber != null and serialNumber != ''">
            AND serial_number LIKE concat('%', #{serialNumber}, '%')
        </if>
        <if test="outline != null and outline != ''">
            AND outline LIKE concat('%', #{outline}, '%')
        </if>
        <if test="startCreateTime != null">
            AND DATE_FORMAT(IFNULL(tp.create_time,''),'%Y%m%d') <![CDATA[ >= ]]> DATE_FORMAT(#{startCreateTime},'%Y%m%d')
        </if>
        <if test="endCreateTime != null">
            AND DATE_FORMAT(IFNULL(tp.create_time,''),'%Y%m%d') <![CDATA[ <= ]]> DATE_FORMAT(#{endCreateTime},'%Y%m%d')
        </if>
        <if test="manager != null and manager != ''">
            AND manager = #{manager}
        </if>
        <if test="level != null and level != ''">
            AND level = #{level}
        </if>
        <if test="status !=null and status != ''">
            AND tp.status = #{status}
        </if>
    </select>

    <select id="selectTestDefectById" parameterType="Long" resultMap="TestDefectResult">
        <include refid="selectTestDefectVo"/>
        where id = #{id}
    </select>

    <insert id="insertTestDefect" parameterType="TestDefect">
        insert into test_defect
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="serialNumber != null and serialNumber != ''">serial_number,</if>
            <if test="name != null and name != ''">name,</if>
            <if test="outline != null and outline != ''">outline,</if>
            <if test="detail != null">detail,</if>
            <if test="status != null and status != ''">status,</if>
            <if test="manager != null and manager != ''">manager,</if>
            <if test="dev != null and dev != ''">dev,</if>
            <if test="level != null and level != ''">level,</if>
            <if test="type != null and type != ''">type,</if>
            <if test="reappearance != null and reappearance != ''">reappearance,</if>
            <if test="test != null and test != ''">test,</if>
            <if test="mail != null">mail,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="version != null">version,</if>
            <if test="delFlag != null">del_flag,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="serialNumber != null and serialNumber != ''">#{serialNumber},</if>
            <if test="name != null and name != ''">#{name},</if>
            <if test="outline != null and outline != ''">#{outline},</if>
            <if test="detail != null">#{detail},</if>
            <if test="status != null and status != ''">#{status},</if>
            <if test="manager != null and manager != ''">#{manager},</if>
            <if test="dev != null and dev != ''">#{dev},</if>
            <if test="level != null and level != ''">#{level},</if>
            <if test="type != null and type != ''">#{type},</if>
            <if test="reappearance != null and reappearance != ''">#{reappearance},</if>
            <if test="test != null and test != ''">#{test},</if>
            <if test="mail != null">#{mail},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="version != null">#{version},</if>
            <if test="delFlag != null">#{delFlag},</if>
         </trim>
    </insert>

    <update id="updateTestDefect" parameterType="TestDefect">
        update test_defect
        <trim prefix="SET" suffixOverrides=",">
            <if test="serialNumber != null and serialNumber != ''">serial_number = #{serialNumber},</if>
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="outline != null and outline != ''">outline = #{outline},</if>
            <if test="detail != null">detail = #{detail},</if>
            <if test="status != null and status != ''">status = #{status},</if>
            <if test="manager != null and manager != ''">manager = #{manager},</if>
            <if test="dev != null and dev != ''">dev = #{dev},</if>
            <if test="level != null and level != ''">level = #{level},</if>
            <if test="type != null and type != ''">type = #{type},</if>
            <if test="reappearance != null and reappearance != ''">reappearance = #{reappearance},</if>
            <if test="test != null and test != ''">test = #{test},</if>
            <if test="mail != null">mail = #{mail},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="version != null">version = #{version},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTestDefectById" parameterType="Long">
        delete from test_defect where id = #{id}
    </delete>

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