<?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.system.mapper.TblUserProjectMapper">

    <select id="selectTblUserProjectByUser" parameterType="Long" resultType="String">
        select project_id
        from tbl_user_project
        where user_id = #{userId}
    </select>

    <select id="selectTblUserProjectByProject" parameterType="String" resultType="Long">
        select user_id
        from tbl_user_project
        where project_id = #{projectId}
    </select>

    <insert id="insertTblUserProject" parameterType="Arraylist">
        insert into tbl_user_project(user_id,project_id) values
        <foreach collection="list" item="item" index="index"
                 separator=",">
            (#{item.userId},#{item.projectId})
        </foreach>
    </insert>

    <insert id="insertTblUserProjectAllProject" parameterType="Long">
        insert into tbl_user_project
        select #{userId} as user_id, p.id as project_id
        from tbl_project p
        where p.del_flag = '0'
    </insert>

    <insert id="insertTblUserProjectAllUser" parameterType="String">
        insert into tbl_user_project
        select u.user_id as user_id, #{projectId} as project_id
        from sys_user u
        where u.del_flag = '0' AND u.status = '0'
    </insert>

    <delete id="deleteTblUserProjectByUser" parameterType="Long">
        delete
        from tbl_user_project
        where user_id = #{userId}
    </delete>
    <delete id="deleteTblUserProjectByProject" parameterType="String">
        delete
        from tbl_user_project
        where project_id = #{projectId}
    </delete>

</mapper>