<?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.project.mapper.BizProjectUserMapper">
    
    <resultMap type="BizProjectUser" id="BizProjectUserResult">
        <result property="id"    column="id"    />
        <result property="projectId"    column="project_id"    />
        <result property="userId"    column="user_id"    />
        <result property="roleType"    column="role_type"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectBizProjectUserVo">
        select id, project_id, user_id, role_type, create_by, create_time, update_by, update_time from biz_project_user
    </sql>

    <select id="selectBizProjectUserList" parameterType="BizProjectUser" resultMap="BizProjectUserResult">
        <include refid="selectBizProjectUserVo"/>
        <where>  
            <if test="id != null  and id != ''"> and id = #{id}</if>
            <if test="projectId != null  and projectId != ''"> and project_id = #{projectId}</if>
            <if test="userId != null  and userId != ''"> and user_id = #{userId}</if>
            <if test="roleType != null  and roleType != ''"> and role_type = #{roleType}</if>
        </where>
    </select>
    
    <select id="selectBizProjectUserById" parameterType="Long" resultMap="BizProjectUserResult">
        <include refid="selectBizProjectUserVo"/>
        where id = #{id}
    </select>

    <select id="selectByProjectAndUser" parameterType="map" resultMap="BizProjectUserResult">
        <include refid="selectBizProjectUserVo"/>
        where project_id = #{projectId} and user_id = #{userId}
    </select>
        
    <insert id="insertBizProjectUser" parameterType="BizProjectUser" useGeneratedKeys="true" keyProperty="id">
        insert into biz_project_user
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="projectId != null">project_id,</if>
            <if test="userId != null">user_id,</if>
            <if test="roleType != null">role_type,</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>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="projectId != null">#{projectId},</if>
            <if test="userId != null">#{userId},</if>
            <if test="roleType != null">#{roleType},</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>
         </trim>
    </insert>

    <update id="updateBizProjectUser" parameterType="BizProjectUser">
        update biz_project_user
        <trim prefix="SET" suffixOverrides=",">
            <if test="projectId != null">project_id = #{projectId},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="roleType != null">role_type = #{roleType},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteBizProjectUserById" parameterType="Long">
        delete from biz_project_user where id = #{id}
    </delete>

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