<?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.xinyilu.system.mapper.TestBodyScoreInfo.TestBodyScoreInfoMapper">

    <resultMap type="TestBodyScoreInfoVO" id="TestBodyScoreInfoResult">
        <result property="id" column="id"/>
        <result property="userId" column="user_id"/>
        <result property="classId" column="class_id"/>
        <result property="studentId" column="student_id"/>
        <result property="testItemId" column="test_item_id"/>
        <result property="scoreDictId" column="score_dict_id"/>
        <result property="scoreDictValue" column="score_dict_value"/>
        <result property="batchCode" column="batch_code"/>
        <result property="itemScore" column="item_score"/>
        <result property="syntheticalAssess" column="synthetical_assess"/>
        <result property="delFlag" column="del_flag"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="itemName" column="item_name"/>
        <result property="leveName" column="level_name"/>
        <result property="measureUnit" column="measure_unit"/>
        <result property="levelMinScore" column="level_min_score"/>
        <result property="levelMaxScore" column="level_max_score"/>
    </resultMap>


    <sql id="selectTestItemScoreVo">
        select id,
               user_id,
               class_id,
               student_id,
               test_item_id,
               score_dict_id,
               score_dict_value,
               batch_code,
               item_score,
               synthetical_assess,
               del_flag,
               create_by,
               create_time,
               update_by,
               update_time
        from test_item_score
    </sql>



    <select id="selectTestBodyScoreList" parameterType="TestBodyScoreInfoVO" resultMap="TestBodyScoreInfoResult">
        SELECT
            tis.test_item_id,
            ti.item_name,
            ti.measure_unit,
            tis.id,
            tis.student_id,
            tis.test_item_id,
            tis.score_dict_value,
            tis.batch_code,
            tis.item_score,
            tis.synthetical_assess
        FROM
        test_item_score tis
        LEFT JOIN test_items ti ON ti.id = tis.test_item_id
        <where>
        <if test="studentId != null ">
            and tis.student_id = #{studentId}
        </if>
        <if test="batchCode != null  and batchCode != ''">
            and tis.batch_code = #{batchCode}
        </if>
        and tis.del_flag = 0 and ti.item_code &lt;&gt; #{itemCode}
        </where>
        order by tis.create_time desc
    </select>

    <select id="getItemType" parameterType="long" resultType="string">
        SELECT IFNULL(sd.dict_value, '') AS dictValue
        FROM test_items ti
        INNER JOIN sys_dict_data sd ON ti.result_dict_type = sd.dict_code
        where ti.id = #{itemId}
    </select>


    <select id="getTestItemLevel"  resultType="TestItemLevel">
        SELECT
            til.item_id,
            til.level_name,
            til.level_min_score,
            til.level_max_score
        FROM
            test_item_level til
        <where>
            <if test="itemIdList != null and itemIdList.size() > 0">
             and til.item_id in
            </if>
            <foreach collection="itemIdList" item="itemId" open="(" separator="," close=")">
            #{itemId}
            </foreach>
        </where>
    </select>

   <select id="getTestBodyStandardList" parameterType="testBodyScoreInfoVO" resultType="TestBodyScoreInfoVO" >
       SELECT
           ti.item_name,
           til.level_name,
           til.level_min_score,
           til.level_max_score,
           ti.measure_unit,
           tis.class_id,
           tis.student_id,
           tis.test_item_id,
           tis.score_dict_id,
           tis.score_dict_value,
           tis.batch_code,
           tis.item_score,
           tis.synthetical_assess
       FROM
           test_item_score tis
           LEFT JOIN test_items ti ON ti.id = tis.test_item_id
           LEFT JOIN test_item_level til ON til.item_id = ti.id
       <where>
       <if test="studentId != null ">
           and tis.student_id = #{studentId}
       </if>
       <if test="batchCode != null  and batchCode != ''">
         and tis.batch_code = #{batchCode}
       </if>
           and tis.del_flag = 0
       </where>
       order by tis.create_time desc
   </select>
</mapper>
