<?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.ruoyi.sim.mapper.AddOnDeptMapper">

    <resultMap type="AddOnDept" id="AddOnDeptResult">
        <result property="deptId" column="dept_id"/>
        <result property="majorId" column="major_id"/>
    </resultMap>

    <sql id="selectAddOnDeptVo">
        select dept_id, major_id
        from sim_add_on_dept
    </sql>

    <select id="selectAddOnDeptList" parameterType="AddOnDept" resultMap="AddOnDeptResult">
        <include refid="selectAddOnDeptVo"/>
        <where>
            <if test="majorId != null ">and major_id = #{majorId}</if>
        </where>
    </select>

    <select id="selectAddOnDeptByDeptId" parameterType="Long" resultMap="AddOnDeptResult">
        <include refid="selectAddOnDeptVo"/>
        where dept_id = #{deptId}
    </select>

    <insert id="insertAddOnDept" parameterType="AddOnDept">
        insert into sim_add_on_dept
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="deptId != null">dept_id,</if>
            <if test="majorId != null">major_id,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="deptId != null">#{deptId},</if>
            <if test="majorId != null">#{majorId},</if>
        </trim>
    </insert>

    <update id="updateAddOnDept" parameterType="AddOnDept">
        update sim_add_on_dept
        <trim prefix="SET" suffixOverrides=",">
            <if test="majorId != null">major_id = #{majorId},</if>
        </trim>
        where dept_id = #{deptId}
    </update>

    <delete id="deleteAddOnDeptByDeptId" parameterType="Long">
        delete
        from sim_add_on_dept
        where dept_id = #{deptId}
    </delete>

    <delete id="deleteAddOnDeptByDeptIds" parameterType="String">
        delete from sim_add_on_dept where dept_id in
        <foreach item="deptId" collection="array" open="(" separator="," close=")">
            #{deptId}
        </foreach>
    </delete>
</mapper>