<?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.sy.mapper.SyMajorMajorMapper">
    
    <resultMap type="SyMajorMajor" id="SyMajorMajorResult">
        <result property="id"    column="id"    />
        <result property="majorCode"    column="major_code"    />
        <result property="majorName"    column="major_name"    />
        <result property="majorCategoryCode"    column="major_category_code"    />
        <result property="type"    column="type"    />
        <result property="level"    column="level"    />
    </resultMap>

    <sql id="selectSyMajorMajorVo">
        select id, major_code, major_name, major_category_code, type, level from sy_major_major
    </sql>

    <select id="selectSyMajorMajorList" parameterType="SyMajorMajor" resultMap="SyMajorMajorResult">
        <include refid="selectSyMajorMajorVo"/>
        <where>  
            <if test="majorCode != null  and majorCode != ''"> and major_code = #{majorCode}</if>
            <if test="majorName != null  and majorName != ''"> and major_name like concat('%', #{majorName}, '%')</if>
            <if test="majorCategoryCode != null  and majorCategoryCode != ''"> and major_category_code = #{majorCategoryCode}</if>
            <if test="type != null  and type != ''"> and type = #{type}</if>
            <if test="level != null "> and level = #{level}</if>
        </where>
    </select>
    
    <select id="selectSyMajorMajorById" parameterType="Long" resultMap="SyMajorMajorResult">
        <include refid="selectSyMajorMajorVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertSyMajorMajor" parameterType="SyMajorMajor" useGeneratedKeys="true" keyProperty="id">
        insert into sy_major_major
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="majorCode != null">major_code,</if>
            <if test="majorName != null">major_name,</if>
            <if test="majorCategoryCode != null">major_category_code,</if>
            <if test="type != null">type,</if>
            <if test="level != null">level,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="majorCode != null">#{majorCode},</if>
            <if test="majorName != null">#{majorName},</if>
            <if test="majorCategoryCode != null">#{majorCategoryCode},</if>
            <if test="type != null">#{type},</if>
            <if test="level != null">#{level},</if>
         </trim>
    </insert>

    <update id="updateSyMajorMajor" parameterType="SyMajorMajor">
        update sy_major_major
        <trim prefix="SET" suffixOverrides=",">
            <if test="majorCode != null">major_code = #{majorCode},</if>
            <if test="majorName != null">major_name = #{majorName},</if>
            <if test="majorCategoryCode != null">major_category_code = #{majorCategoryCode},</if>
            <if test="type != null">type = #{type},</if>
            <if test="level != null">level = #{level},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSyMajorMajorById" parameterType="Long">
        delete from sy_major_major where id = #{id}
    </delete>

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