<?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.microservices.pms.project.mapper.PmsProjectTestReportMapper">
    
    <resultMap type="PmsProjectTestReport" id="PmsProjectTestReportResult">
        <result property="id"    column="id"    />
        <result property="pmsProjectId"    column="pms_project_id"    />
        <result property="reportAssigneeId"    column="report_assignee_id"    />
        <result property="name"    column="name"    />
        <result property="summary"    column="summary"    />
        <result property="startTime"     column="start_time" />
        <result property="endTime"     column="end_time" />
        <result property="updateTime"    column="update_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
    </resultMap>

    <sql id="selectPmsProjectTestReportVo">
        select id, pms_project_id, report_assignee_id, name, summary, start_time, end_time, update_time, update_by, create_time, create_by from pms_project_test_report
    </sql>

    <select id="selectPmsProjectTestReportList" parameterType="PmsProjectTestReport" resultMap="PmsProjectTestReportResult">
        <include refid="selectPmsProjectTestReportVo"/>
        <where>  
            <if test="pmsProjectId != null "> and pms_project_id = #{pmsProjectId}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="summary != null  and summary != ''"> and summary = #{summary}</if>
        </where>
    </select>
    
    <select id="selectPmsProjectTestReportById" parameterType="Long" resultMap="PmsProjectTestReportResult">
        <include refid="selectPmsProjectTestReportVo"/>
        where id = #{id}
    </select>

    <select id="selectPmsProjectTestReportListBySearchVo"
            resultMap="PmsProjectTestReportResult">
        select t1.id, t1.pms_project_id, t1.name, t1.summary, t1.update_time, t1.update_by, t1.create_time, t1.create_by
        from pms_project_test_report t1
        <if test="testSheetId != null">
            JOIN
            pms_project_test_report_sheet t2
            ON
            t1.id = t2.project_test_report_id
        </if>
        <where>
            <if test="testSheetId != null">
                and t2.project_test_sheet_id = #{testSheetId}
            </if>
            <if test="pmsProjectId != null"> and t1.pms_project_id = #{pmsProjectId}</if>
            <if test="name != null  and name != ''"> and t1.name like concat('%', #{name}, '%')</if>
            <if test="createBy != null  and createBy != ''"> and t1.create_by = #{createBy}</if>
        </where>
    </select>

    <insert id="insertPmsProjectTestReport" parameterType="PmsProjectTestReport" useGeneratedKeys="true" keyProperty="id">
        insert into pms_project_test_report
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="pmsProjectId != null">pms_project_id,</if>
            <if test="reportAssigneeId != null">report_assignee_id,</if>
            <if test="name != null and name != ''">name,</if>
            <if test="summary != null">summary,</if>
            <if test="startTime != null">start_time,</if>
            <if test="endTime != null">end_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="pmsProjectId != null">#{pmsProjectId},</if>
            <if test="reportAssigneeId != null">#{reportAssigneeId},</if>
            <if test="name != null and name != ''">#{name},</if>
            <if test="summary != null">#{summary},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
         </trim>
    </insert>

    <update id="updatePmsProjectTestReport" parameterType="PmsProjectTestReport">
        update pms_project_test_report
        <trim prefix="SET" suffixOverrides=",">
            <if test="pmsProjectId != null">pms_project_id = #{pmsProjectId},</if>
            <if test="reportAssigneeId != null">report_assignee_id = #{reportAssigneeId},</if>
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="summary != null">summary = #{summary},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deletePmsProjectTestReportById" parameterType="Long">
        delete from pms_project_test_report where id = #{id}
    </delete>

    <delete id="deletePmsProjectTestReportByIds" parameterType="String">
        delete from pms_project_test_report where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <delete id="deletePmsProjectTestReportByProjectId">
        delete from pms_project_test_report where pms_project_id = #{projectId}
    </delete>
</mapper>