<?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.ruoyi.mapper.ReviewStandardMapper">

    <resultMap id="StandardTreeResultMap" type="com.ruoyi.domain.ReviewStandard">

        <id property="id" column="id" jdbcType="BIGINT"/>
        <result property="type" column="type" jdbcType="VARBINARY"/>
        <result property="chapter" column="chapter" jdbcType="VARCHAR"/>
        <result property="text" column="text" jdbcType="VARCHAR"/>
        <result property="standardId" column="standard_id" jdbcType="BIGINT"/>
        <result property="name" column="name" jdbcType="VARCHAR"/>
        <result property="standardNo" column="standard_no" jdbcType="VARCHAR"/>
        <result property="file" column="file" jdbcType="VARCHAR"/>
        <result property="conformity" column="conformity" jdbcType="VARCHAR"/>
        <result property="inconformity" column="inconformity" jdbcType="VARCHAR"/>
        <result property="testMethod" column="test_method" jdbcType="VARCHAR"/>

        <collection property="keyPointList" ofType="com.ruoyi.domain.ReviewKeyPoint" select="com.ruoyi.mapper.ReviewKeyPointMapper.findAllByReviewStandardId" column="id">
            <result property="id" column="u_id" jdbcType="BIGINT"/>
            <result property="text" column="text" jdbcType="VARCHAR"/>
        </collection>

    </resultMap>

    <resultMap id="StandardListResultMap" type="com.ruoyi.web.response.ReviewStandardListResponse">
        <id property="id" column="id" jdbcType="BIGINT"/>
        <result property="chapter" column="chapter" jdbcType="VARCHAR"/>
        <result property="text" column="text" jdbcType="VARCHAR"/>
    </resultMap>

    <select id="findTree" resultMap="StandardTreeResultMap">
        SELECT id, chapter, text, standard_id, name, standard_no, file, conformity, inconformity FROM t_review_standard;
    </select>

    <select id="findListByStandardIdAndType" resultType="com.ruoyi.domain.ReviewStandard">
        SELECT id, type, chapter, text, standard_id, name, standard_no, file, conformity, inconformity FROM t_review_standard WHERE standard_id = #{standardId} AND type = #{type};
    </select>

    <select id="selectReviewStandardList" parameterType="com.ruoyi.web.request.ReviewStandardListByPageRequest" resultType="com.ruoyi.web.response.ReviewStandardResponse">
        select
            id,
            chapter,
            text,
            test_method AS testMethod
        from
            t_review_standard
        <where>
            <if test="standardId != null"> and standard_id = #{standardId} </if>
            <if test="type != null and type != ''"> and `type` = #{type} </if>
            <if test="chapter != null and chapter != ''"> and chapter like concat('%', #{chapter}, '%') </if>
            <if test="text != null and text != ''"> and text like concat('%', #{text}, '%') </if>
            <if test="testMethod != null and testMethod != ''"> and test_method like concat('%', #{testMethod}, '%') </if>
        </where>
        ORDER BY
            chapter
    </select>

    <select id="selectTestInspectionContent"
            resultType="com.ruoyi.web.response.ReviewStandardTestInspectionContentResponse">
        SELECT
            usecase.NAME useCaseName,
            usecase.usecase_no useCaseNumber,
            scenario.test_scenario,
            type.test_type
        FROM
            t_test_usecase usecase
                LEFT JOIN t_test_scenario scenario ON scenario.id = usecase.test_scenario_id
                LEFT JOIN t_test_type type ON type.id = usecase.test_type_id
        WHERE
            usecase.review_standard_id = #{id}
    </select>
    <select id="findReviewStandardList" resultType="com.ruoyi.web.response.ReviewStandardListResponse">
        SELECT id,chapter,text FROM t_review_standard
        <where>
            type = #{type}
            <if test="chapter != null and chapter != ''">
                and chapter like concat('%', #{chapter}, '%')
            </if>
            <if test="text != null and text != ''">
                and text like concat('%', #{text}, '%')
            </if>
        </where>
    </select>
    <select id="findByKeyPointList" resultType="com.ruoyi.domain.ReviewStandard">
        SELECT id, chapter, text FROM t_review_standard
        WHERE id IN
        <foreach collection="keyPointList" item="keyPoint" open="(" separator="," close=")">
            #{keyPoint.reviewStandardId}
        </foreach>
        and standard_id = #{request.standardId}
        and type = #{request.type}
    </select>


</mapper>