<?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.yinlihupo.enlish.service.domain.mapper.GradeUnitDOMapper">
    <resultMap id="BaseResultMap" type="com.yinlihupo.enlish.service.domain.dataobject.GradeUnitDO">
        <id column="id" jdbcType="INTEGER" property="id" />
        <result column="grade_id" jdbcType="INTEGER" property="gradeId" />
        <result column="unit_id" jdbcType="INTEGER" property="unitId" />
    </resultMap>

    <select id="selectUnitIdsByGradeId" resultType="java.lang.Integer">
        select unit_id
        from grade_unit
        where grade_id = #{gradeId}
    </select>

    <select id="selectByUnitId" resultMap="BaseResultMap">
        select *
        from grade_unit
        where unit_id = #{unitId}
    </select>

    <select id="selectByUnitIds" resultMap="BaseResultMap">
        select *
        from grade_unit
        <if test="unitIds != null">
            where unit_id in
            <foreach collection="unitIds" item="unitId" separator="," open="(" close=")">
                #{unitId}
            </foreach>
        </if>
    </select>

    <insert id="insert">
        insert into grade_unit (grade_id, unit_id)
        values (#{gradeId}, #{unitId})
    </insert>

    <delete id="deleteByUnitId">
        delete from grade_unit
        where unit_id = #{unitId}
    </delete>
</mapper>