<?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.xhkjedu.sapi.mapper.assess.AssessTemplateMapper">

    <!--所有模版-->
    <select id="listTemplates" resultType="java.util.Map">
        select t.templateid,t.templatename,t.quotanum,t.templateorder,t.comm,
        t.createid,u.username as createname,t.createtime
        from t_assess_template t left join t_user u on t.createid=u.userid
        where t.schoolid=#{schoolid} and t.templatestate=1 order by t.templateorder,t.templateid
    </select>

    <!--删除模版指标关联-->
    <delete id="deleteTemplateQuota">
        delete from t_assess_template_quota where templateid=#{templateid}
    </delete>

    <!--修改模版状态-->
    <update id="updateTemplatestate">
        update t_assess_template set templatestate=#{templatestate} where templateid=#{templateid}
    </update>

    <!--模版关联的指标集合-->
    <select id="listQutosByTemplateid" resultType="java.lang.Integer">
        select distinct quotaid from t_assess_template_quota where templateid=#{templateid}
    </select>

    <!--修改模版关联指标数量-->
    <update id="updateQuotanum">
        update t_assess_template set quotanum=quotanum-1 where templateid in
        <foreach collection="templateids" item="templateid" index="index" open="(" separator="," close=")">
            ${templateid}
        </foreach>
    </update>

    <!--指标关联的模版id-->
    <select id="listTeimplateidsByQutoaid" resultType="java.lang.Integer">
        select templateid from t_assess_template_quota where quotaid=#{quotaid}
    </select>
</mapper>
