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

    <resultMap type="AddOnUser" id="AddOnUserResult">
        <result property="userId" column="user_id"/>
        <result property="majorId" column="major_id"/>
        <result property="createBy" column="createBy"/>
        <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="selectAddOnUserVo">
        select user_id, major_id, createBy, create_time, update_by, update_time, remark
        from sim_add_on_user
    </sql>

    <select id="selectAddOnUserList" parameterType="AddOnUser" resultMap="AddOnUserResult">
        <include refid="selectAddOnUserVo"/>
        <where>
            <if test="majorId != null ">and major_id = #{majorId}</if>
            <if test="createBy != null  and createBy != ''">and createBy = #{createBy}</if>
        </where>
    </select>

    <select id="selectAddOnUserByUserId" parameterType="Long" resultMap="AddOnUserResult">
        <include refid="selectAddOnUserVo"/>
        where user_id = #{userId}
    </select>

    <insert id="insertAddOnUser" parameterType="AddOnUser" useGeneratedKeys="true" keyProperty="userId">
        insert into sim_add_on_user
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="majorId != null">major_id,</if>
            <if test="createBy != null">createBy,</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="majorId != null">#{majorId},</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="updateAddOnUser" parameterType="AddOnUser">
        update sim_add_on_user
        <trim prefix="SET" suffixOverrides=",">
            <if test="majorId != null">major_id = #{majorId},</if>
            <if test="createBy != null">createBy = #{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 user_id = #{userId}
    </update>

    <delete id="deleteAddOnUserByUserId" parameterType="Long">
        delete
        from sim_add_on_user
        where user_id = #{userId}
    </delete>

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