<?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.testItemStandard.TestItemStandardMapper">

    <resultMap type="TestItemStandard" id="TestItemStandardResult">
        <result property="id" column="id"/>
        <result property="testItemsId" column="test_items_id"/>
        <result property="standardType" column="standard_type"/>
        <result property="maxScore" column="max_score"/>
        <result property="minScore" column="min_score"/>
        <result property="levelDescription" column="level_description"/>
        <result property="sorting" column="sorting"/>
        <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"/>
    </resultMap>

    <sql id="selectTestItemStandardVo">
        select id, test_items_id, standard_type, max_score, min_score, level_description, sorting, del_flag, create_by, create_time, update_by, update_time from test_item_standard
    </sql>

    <select id="selectTestItemStandardList" parameterType="TestItemStandard" resultMap="TestItemStandardResult">
        <include refid="selectTestItemStandardVo"/>
        <where>
            <if test="testItemsId != null ">
                and test_items_id = #{testItemsId}
            </if>
            <if test="standardType != null ">
                and standard_type = #{standardType}
            </if>
            <if test="maxScore != null ">
                and max_score = #{maxScore}
            </if>
            <if test="minScore != null ">
                and min_score = #{minScore}
            </if>
            <if test="levelDescription != null  and levelDescription != ''">
                and level_description = #{levelDescription}
            </if>
            <if test="sorting != null ">
                and sorting = #{sorting}
            </if>
        </where>
    </select>

    <select id="selectTestItemStandardById" parameterType="Long"
            resultMap="TestItemStandardResult">
        <include refid="selectTestItemStandardVo"/>
        where id = #{id}
    </select>

    <insert id="insertTestItemStandard" parameterType="TestItemStandard" useGeneratedKeys="true"
            keyProperty="id">
        insert into test_item_standard
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="testItemsId != null">test_items_id,
            </if>
            <if test="standardType != null">standard_type,
            </if>
            <if test="maxScore != null">max_score,
            </if>
            <if test="minScore != null">min_score,
            </if>
            <if test="levelDescription != null">level_description,
            </if>
            <if test="sorting != null">sorting,
            </if>
            <if test="delFlag != null">del_flag,
            </if>
            <if test="createBy != null">create_by,
            </if>
            <if test="createTime != null">create_time,
            </if>
            <if test="updateBy != null">update_by,
            </if>
            <if test="updateTime != null">update_time,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="testItemsId != null">#{testItemsId},
            </if>
            <if test="standardType != null">#{standardType},
            </if>
            <if test="maxScore != null">#{maxScore},
            </if>
            <if test="minScore != null">#{minScore},
            </if>
            <if test="levelDescription != null">#{levelDescription},
            </if>
            <if test="sorting != null">#{sorting},
            </if>
            <if test="delFlag != null">#{delFlag},
            </if>
            <if test="createBy != null">#{createBy},
            </if>
            <if test="createTime != null">#{createTime},
            </if>
            <if test="updateBy != null">#{updateBy},
            </if>
            <if test="updateTime != null">#{updateTime},
            </if>
        </trim>
    </insert>

    <update id="updateTestItemStandard" parameterType="TestItemStandard">
        update test_item_standard
        <trim prefix="SET" suffixOverrides=",">
            <if test="testItemsId != null">test_items_id =
                #{testItemsId},
            </if>
            <if test="standardType != null">standard_type =
                #{standardType},
            </if>
            <if test="maxScore != null">max_score =
                #{maxScore},
            </if>
            <if test="minScore != null">min_score =
                #{minScore},
            </if>
            <if test="levelDescription != null">level_description =
                #{levelDescription},
            </if>
            <if test="sorting != null">sorting =
                #{sorting},
            </if>
            <if test="delFlag != null">del_flag =
                #{delFlag},
            </if>
            <if test="createBy != null">create_by =
                #{createBy},
            </if>
            <if test="createTime != null">create_time =
                #{createTime},
            </if>
            <if test="updateBy != null">update_by =
                #{updateBy},
            </if>
            <if test="updateTime != null">update_time =
                #{updateTime},
            </if>
        </trim>
        where test_items_id = #{id}
    </update>

    <delete id="deleteTestItemStandardById" parameterType="Long">
        delete from test_item_standard where id = #{id}
    </delete>

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

    <update id="updateTestItemStandardByIds" parameterType="java.lang.Long">
        update test_item_standard set del_flag =1, update_time = now() where test_items_id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>

    <update id="updateDisunityStandardScore">
        update test_items set
            unified_standard_score = null,
            update_by = #{updateBy},
            update_time = now()
        where id = #{id}
    </update>

    <update id="updateUnifiedStandardScore">
        update test_items set
            large_standard_score = null,
            middle_standard_score = null,
            small_standard_score = null,
            update_by = #{updateBy},
            update_time = now()
        where id = #{id}
    </update>

    <select id="getItemStandardByItemIds" parameterType="Long"
            resultMap="TestItemStandardResult">
        <include refid="selectTestItemStandardVo"/>
        <where>
            del_flag = 0
            <if test="testItemsIdList != null and testItemsIdList.size() > 0">
                and test_items_id in
                <foreach item="itemId" collection="testItemsIdList" open="(" separator="," close=")">
                    #{itemId}
                </foreach>
            </if>
        </where>
    </select>
</mapper>
