<?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.qmth.exam.reserve.dao.CategoryDao">
    <select id="page" resultType="com.qmth.exam.reserve.bean.teaching.TeachingVO">
        SELECT
            c.id,
            c.CODE,
            c.NAME,
            c.capacity,
            c.ENABLE,
            p.NAME cityName,
            p.ID cityId
        FROM
            t_category c,
            t_category p
        WHERE
            c.parent_id = p.id
        <if test="req.level != null">
            and c.level=#{req.level}
        </if>
        <if test="req.name != null and req.name !=''">
            and c.name like concat('%', #{req.name}, '%')
        </if>
        <if test="req.code != null and req.code !=''">
            and c.code like concat('%', #{req.code}, '%')
        </if>
        <if test="req.enable != null">
            and c.enable=#{req.enable}
        </if>
        order by c.update_time desc
    </select>
    
    <update id="updateTeachingCapacity">
        UPDATE t_category SET capacity =( SELECT IFNULL(sum( capacity ),0) FROM t_exam_site WHERE category_id = #{teachingId} AND ENABLE = 1 )
        WHERE
            id = #{teachingId}
    </update>
</mapper>
