<?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.PmsProjectTestsheetCasesMapper">
    
    <resultMap type="PmsProjectTestsheetCases" id="PmsProjectTestsheetCasesResult">
        <result property="id"    column="id"    />
        <result property="projectTestsheetId"    column="project_testsheet_id"    />
        <result property="projectTestcaseId"    column="project_testcase_id"    />
        <result property="testStatus"    column="test_status"    />
        <result property="testerId"    column="tester_id"    />
        <result property="stepStatus"    column="step_status"    />
    </resultMap>

    <sql id="selectPmsProjectTestsheetCasesVo">
        select id, project_testsheet_id, project_testcase_id, test_status, tester_id, step_status from pms_project_testsheet_cases
    </sql>

    <select id="selectPmsProjectTestsheetCasesCount" parameterType="PmsProjectTestsheetCases"  resultType="java.lang.Integer">
        select count(0) from pms_project_testsheet_cases
        <where>
            <if test="projectTestsheetId != null "> and project_testsheet_id = #{projectTestsheetId}</if>
            <if test="projectTestcaseId != null "> and project_testcase_id = #{projectTestcaseId}</if>
            <if test="testStatus != null "> and test_status = #{testStatus}</if>
            <if test="testerId != null "> and tester_id = #{testerId}</if>
            <if test="stepStatus != null  and stepStatus != ''"> and step_status = #{stepStatus}</if>
        </where>
        <if test="testcaseIdList != null  and testcaseIdList.size() > 0 ">
            and project_testcase_id in
            <foreach item="testcaseId" collection="testcaseIdList" open="(" separator="," close=")">
                #{testcaseId}
            </foreach>
        </if>
    </select>


    <select id="selectPmsProjectTestcaseByRootModuleForTestsheetCount" parameterType="Long"  resultType="java.lang.Integer">
        select count(*) from pms_project_testcase where pms_module_id is null and exists(select * from pms_project_testsheet_cases where project_testcase_id = pms_project_testcase.id and project_testsheet_id =#{projectTestsheetId})
    </select>

    <select id="selectPmsProjectTestsheetCasesList" parameterType="PmsProjectTestsheetCases" resultMap="PmsProjectTestsheetCasesResult">
        <include refid="selectPmsProjectTestsheetCasesVo"/>
        <where>
            1=1
            <if test="projectTestsheetId != null "> and project_testsheet_id = #{projectTestsheetId}</if>
            <if test="projectTestcaseId != null "> and project_testcase_id = #{projectTestcaseId}</if>
            <if test="testStatus != null "> and test_status = #{testStatus}</if>
            <if test="testerId != null "> and tester_id = #{testerId}</if>
            <if test="stepStatus != null  and stepStatus != ''"> and step_status = #{stepStatus}</if>
        </where>
        <if test="testcaseIdList != null  and testcaseIdList.size() > 0 ">
            and project_testcase_id in
            <foreach item="testcaseId" collection="testcaseIdList" open="(" separator="," close=")">
                #{testcaseId}
            </foreach>
        </if>
        <if test="idsList != null  and idsList.size() > 0 ">
            and id in
            <foreach item="id" collection="idsList" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
    </select>

    <select id="selectPmsProjectTestsheetCasesListBy" resultMap="PmsProjectTestsheetCasesResult" parameterType="String">
        <include refid="selectPmsProjectTestsheetCasesVo"/>
        where project_testsheet_id in
        <foreach item="id" collection="testsheetIds" open="(" separator="," close=")">
            #{id}
        </foreach>
    </select>
    
    <select id="selectPmsProjectTestsheetCasesById" parameterType="Long" resultMap="PmsProjectTestsheetCasesResult">
        <include refid="selectPmsProjectTestsheetCasesVo"/>
        where id = #{id}
    </select>
    <select id="selectTestSheetCaseTesterIdsByTestSheetIds" resultType="java.lang.Long">
        select distinct(tester_id)
        from pms_project_testsheet_cases
        where tester_id is not null
        and  project_testsheet_id in
        <foreach item="id" collection="testSheetIds" open="(" separator="," close=")">
            #{id}
        </foreach>
    </select>

    <insert id="insertPmsProjectTestsheetCases" parameterType="PmsProjectTestsheetCases" useGeneratedKeys="true" keyProperty="id">
        insert into pms_project_testsheet_cases
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="projectTestsheetId != null">project_testsheet_id,</if>
            <if test="projectTestcaseId != null">project_testcase_id,</if>
            <if test="testStatus != null">test_status,</if>
            <if test="testerId != null">tester_id,</if>
            <if test="stepStatus != null">step_status,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="projectTestsheetId != null">#{projectTestsheetId},</if>
            <if test="projectTestcaseId != null">#{projectTestcaseId},</if>
            <if test="testStatus != null">#{testStatus},</if>
            <if test="testerId != null">#{testerId},</if>
            <if test="stepStatus != null">#{stepStatus},</if>
         </trim>
    </insert>

    <update id="updatePmsProjectTestsheetCases" parameterType="PmsProjectTestsheetCases">
        update pms_project_testsheet_cases
        <trim prefix="SET" suffixOverrides=",">
            <if test="projectTestsheetId != null">project_testsheet_id = #{projectTestsheetId},</if>
            <if test="projectTestcaseId != null">project_testcase_id = #{projectTestcaseId},</if>
            <if test="testStatus != null">test_status = #{testStatus},</if>
            <if test="stepStatus != null">step_status = #{stepStatus},</if>
            tester_id = #{testerId}
        </trim>
        where id = #{id}
    </update>

    <delete id="deletePmsProjectTestsheetCasesById" parameterType="Long">
        delete from pms_project_testsheet_cases where id = #{id}
    </delete>

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

    <delete id="deletePmsProjectTestsheetCasesByTestcaseId" parameterType="Long">
        delete from pms_project_testsheet_cases where project_testcase_id = #{id}
    </delete>

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