<?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.ho.user.mapper.SysUserPositionMapper">

    <sql id="Base_Column_List">
        id
        ,user_id,position_id,
        create_time
    </sql>

    <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultType="com.ho.user.entity.SysUserPosition">
        select
        <include refid="Base_Column_List"/>
        from sys_user_position
        where id = #{id}
    </select>

    <select id="selectByPostId" resultType="com.ho.user.entity.SysUserPosition">
        select
        <include refid="Base_Column_List"/>
        from sys_user_position
        where position_id = #{id}
    </select>

    <select id="selectPostIdsByUserId" parameterType="java.lang.String" resultType="java.lang.Integer">
        select position_id
        from sys_user_position
        where user_id = #{userId}
    </select>

    <select id="getUserIdsByPostIds" resultType="java.lang.String">
        select user_id
        from sys_user_position
        where position_id in
        <foreach collection="list" open="(" close=")" separator="," item="item">
            #{item}
        </foreach>
    </select>
    <select id="selectByPostIds" resultType="com.ho.user.entity.SysUserPosition">
        select
        <include refid="Base_Column_List"/>
        from sys_user_position
        <where>
            <if test="list != null and list.size != 0">
                position_id in
                <foreach collection="list" open="(" close=")" separator="," item="item">
                    #{item}
                </foreach>
            </if>
        </where>
    </select>

    <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.ho.user.entity.SysUserPosition"
            useGeneratedKeys="true">
        insert into sys_user_position
            (user_id, position_id, create_time)
        values (#{userId,jdbcType=VARCHAR},
                #{positionId,jdbcType=INTEGER},
                now())
    </insert>

    <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.ho.user.entity.SysUserPosition"
            useGeneratedKeys="true">
        insert into sys_user_position
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="userId != null">user_id,</if>
            <if test="positionId != null">position_id,</if>
            <if test="createTime != null">create_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id,jdbcType=INTEGER},</if>
            <if test="userId != null">#{userId,jdbcType=VARCHAR},</if>
            <if test="positionId != null">#{positionId,jdbcType=INTEGER},</if>
            <if test="createTime != null">#{createTime,jdbcType=TIMESTAMP},</if>
        </trim>
    </insert>

    <insert id="batchUserPosition" parameterType="com.ho.user.entity.SysUserPosition">
        INSERT INTO sys_user_position (
        user_id,
        position_id,
        create_time
        )
        VALUES
        <foreach item="item" collection="list" index="index" separator=",">
            (
            #{item.userId},
            #{item.positionId},
            now()
            )
        </foreach>
    </insert>

    <update id="updateByPrimaryKeySelective" parameterType="com.ho.user.entity.SysUserPosition">
        update sys_user_position
        <set>
            <if test="userId != null">
                user_id = #{userId,jdbcType=VARCHAR},
            </if>
            <if test="positionId != null">
                position_id = #{positionId,jdbcType=INTEGER},
            </if>
            <if test="createTime != null">
                create_time = #{createTime,jdbcType=TIMESTAMP},
            </if>
        </set>
        where id = #{id,jdbcType=INTEGER}
    </update>

    <update id="updateByPrimaryKey" parameterType="com.ho.user.entity.SysUserPosition">
        update sys_user_position
        set user_id     = #{userId,jdbcType=VARCHAR},
            position_id = #{positionId,jdbcType=INTEGER},
            create_time = #{createTime,jdbcType=TIMESTAMP}
        where id = #{id,jdbcType=INTEGER}
    </update>

    <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
        delete
        from sys_user_position
        where id = #{id,jdbcType=INTEGER}
    </delete>

    <delete id="removeByPostId" parameterType="java.lang.Integer">
        delete
        from sys_user_position
        where position_id = #{id}
    </delete>

    <!--根据用户id删除数据-->
    <delete id="removeByUserId" parameterType="java.lang.String">
        delete
        from sys_user_position
        where user_id = #{userId}
    </delete>

    <!--根据用户ids 删除多条数据-->
    <delete id="removeByUserIds">
        delete from sys_user_position
        where user_id in
        <foreach collection="list" open="(" close=")" separator="," item="item">
            #{item}
        </foreach>
    </delete>

</mapper>
