<?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.MajorMapper">

    <resultMap type="Major" id="MajorResult">
        <result property="majorId" column="major_id"/>
        <result property="majorName" column="major_name"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="remark" column="remark"/>
    </resultMap>

    <sql id="selectMajorVo">
        select major_id, major_name, create_by, create_time, update_by, update_time, remark
        from sim_major
    </sql>

    <select id="selectMajorList" parameterType="Major" resultMap="MajorResult">
        <include refid="selectMajorVo"/>
        <where>
            <if test="majorName != null  and majorName != ''">and major_name like concat('%', #{majorName}, '%')</if>
        </where>
    </select>

    <select id="selectMajorByMajorId" parameterType="Long" resultMap="MajorResult">
        <include refid="selectMajorVo"/>
        where major_id = #{majorId}
    </select>

    <insert id="insertMajor" parameterType="Major" useGeneratedKeys="true" keyProperty="majorId">
        insert into sim_major
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="majorName != null and majorName != ''">major_name,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="majorName != null and majorName != ''">#{majorName},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
        </trim>
    </insert>

    <update id="updateMajor" parameterType="Major">
        update sim_major
        <trim prefix="SET" suffixOverrides=",">
            <if test="majorName != null and majorName != ''">major_name = #{majorName},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where major_id = #{majorId}
    </update>

    <delete id="deleteMajorByMajorId" parameterType="Long">
        delete
        from sim_major
        where major_id = #{majorId}
    </delete>

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