<?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.microservices.pms.project.mapper.PmsProjectMembersMapper">

    <resultMap type="com.microservices.pms.project.domain.PmsProjectMembers" id="PmsProjectMembersResult">
        <result property="id"    column="id"    />
        <result property="pmsProjectId"    column="pms_project_id"    />
        <result property="pmsProjectMemberId"    column="pms_project_member_id"    />
        <result property="createTime"    column="create_time"    />
        <result property="userId" column="user_id"/>
    </resultMap>

    <sql id="selectPmsProjectMembersVo">
        select id, pms_project_id, pms_project_member_id, create_time, user_id
        from pms_project_members
    </sql>

    <select id="selectPmsProjectMembersList" parameterType="PmsProjectMembers" resultMap="PmsProjectMembersResult">
        <include refid="selectPmsProjectMembersVo"/>
        <where>  
            <if test="pmsProjectId != null "> and pms_project_id = #{pmsProjectId}</if>
            <if test="pmsProjectMemberId != null "> and pms_project_member_id = #{pmsProjectMemberId}</if>
            <if test="createTime != null "> and create_time = #{createTime}</if>
            <if test="userId != null  and userId != ''">and user_id = #{userId}</if>
        </where>
    </select>
    
    <select id="selectPmsProjectMembersById" parameterType="Long" resultMap="PmsProjectMembersResult">
        <include refid="selectPmsProjectMembersVo"/>
        where id = #{id}
    </select>
    <select id="countMemberByProjectId" resultType="java.lang.Integer">
        select count(*)
        from pms_project_members
        where pms_project_id = #{projectId}
    </select>
    <select id="selectPmsProjectMemberIdsByProjectId" resultType="java.lang.Integer">
        select pms_project_member_id
        from pms_project_members
        where pms_project_id = #{pmsProjectId}
    </select>
    <select id="selectPmsProjectMembersCount" resultType="java.lang.Integer">
        select count(*)
        from pms_project_members
        <where>
            <if test="pmsProjectId != null "> and pms_project_id = #{pmsProjectId}</if>
            <if test="pmsProjectMemberId != null "> and pms_project_member_id = #{pmsProjectMemberId}</if>
        </where>
    </select>
    <select id="countPmsProjectMembersByProjectIdAndMemberId" resultType="java.lang.Integer">
        select count(*)
        from pms_project_members
        where pms_project_id = #{pmsProjectId}
        and pms_project_member_id = #{pmsProjectMemberId}
    </select>

    <insert id="insertPmsProjectMembers" parameterType="PmsProjectMembers" useGeneratedKeys="true" keyProperty="id">
        insert into pms_project_members
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="pmsProjectId != null">pms_project_id,</if>
            <if test="pmsProjectMemberId != null">pms_project_member_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="userId != null">user_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="pmsProjectId != null">#{pmsProjectId},</if>
            <if test="pmsProjectMemberId != null">#{pmsProjectMemberId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="userId != null">#{userId},</if>
         </trim>
    </insert>

    <update id="updatePmsProjectMembers" parameterType="PmsProjectMembers">
        update pms_project_members
        <trim prefix="SET" suffixOverrides=",">
            <if test="pmsProjectId != null">pms_project_id = #{pmsProjectId},</if>
            <if test="pmsProjectMemberId != null">pms_project_member_id = #{pmsProjectMemberId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="userId != null">user_id = #{userId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deletePmsProjectMembersById" parameterType="Long">
        delete from pms_project_members where id = #{id}
    </delete>

    <delete id="deletePmsProjectMembersByIds" parameterType="String">
        delete from pms_project_members where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <delete id="deletePmsProjectMembersByProjectId">
        delete from pms_project_members where pms_project_id = #{projectId}
    </delete>
</mapper>