<?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.yanzhu.manage.mapper.ProProjectInfoUsersMapper">
    
    <resultMap type="ProProjectInfoUsers" id="ProProjectInfoUsersResult">
        <result property="id"    column="id"    />
        <result property="deptId"    column="dept_id"    />
        <result property="deptName"    column="dept_name"    />
        <result property="projectId"    column="project_id"    />
        <result property="userId"    column="user_id"    />
        <result property="userName"    column="user_name"    />
        <result property="userCode"    column="user_code"    />
        <result property="userPhone"    column="user_phone"    />
        <result property="useStatus"    column="use_status"    />
        <result property="isDel"    column="is_del"    />
        <result property="createBy"    column="create_by"    />
        <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="selectProProjectInfoUsersVo">
        select pu.id, pu.dept_id, sd.dept_name, pu.project_id, pi.project_name, pu.user_id, pu.user_name, pu.user_code, pu.user_phone, pu.use_status, pu.is_del, pu.create_by, pu.create_time, pu.update_by, pu.update_time, pu.remark from pro_project_info_users pu
        left join pro_project_info pi on pi.id = pu.project_id
        left join sys_dept sd on sd.dept_id = pi.dept_id
    </sql>

    <select id="selectProProjectInfoUsersList" parameterType="ProProjectInfoUsers" resultMap="ProProjectInfoUsersResult">
        <include refid="selectProProjectInfoUsersVo"/>
        <where>
            <if test="activeDeptId != null "> and sd.dept_id = #{activeDeptId}</if>
            <if test="deptId != null "> and pu.dept_id = #{deptId}</if>
            <if test="projectId != null "> and pu.project_id = #{projectId}</if>
            <if test="projectName != null  and projectName != ''"> and pi.project_name like concat('%', #{projectName}, '%')</if>
            <if test="userId != null "> and pu.user_id = #{userId}</if>
            <if test="userName != null  and userName != ''"> and pu.user_name like concat('%', #{userName}, '%')</if>
            <if test="userCode != null  and userCode != ''"> and pu.user_code = #{userCode}</if>
            <if test="userPhone != null  and userPhone != ''"> and pu.user_phone = #{userPhone}</if>
            <if test="useStatus != null  and useStatus != ''"> and pu.use_status = #{useStatus}</if>
            <if test="isDel != null "> and pu.is_del = #{isDel}</if>
        </where>
        order by pu.id desc
    </select>
    
    <select id="selectProProjectInfoUsersById" parameterType="Long" resultMap="ProProjectInfoUsersResult">
        <include refid="selectProProjectInfoUsersVo"/>
        where pu.id = #{id}
    </select>
        
    <insert id="insertProProjectInfoUsers" parameterType="ProProjectInfoUsers" useGeneratedKeys="true" keyProperty="id">
        insert into pro_project_info_users
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="deptId != null">dept_id,</if>
            <if test="projectId != null">project_id,</if>
            <if test="userId != null">user_id,</if>
            <if test="userName != null">user_name,</if>
            <if test="userCode != null">user_code,</if>
            <if test="userPhone != null">user_phone,</if>
            <if test="useStatus != null">use_status,</if>
            <if test="isDel != null">is_del,</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>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="deptId != null">#{deptId},</if>
            <if test="projectId != null">#{projectId},</if>
            <if test="userId != null">#{userId},</if>
            <if test="userName != null">#{userName},</if>
            <if test="userCode != null">#{userCode},</if>
            <if test="userPhone != null">#{userPhone},</if>
            <if test="useStatus != null">#{useStatus},</if>
            <if test="isDel != null">#{isDel},</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="updateProProjectInfoUsers" parameterType="ProProjectInfoUsers">
        update pro_project_info_users
        <trim prefix="SET" suffixOverrides=",">
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="projectId != null">project_id = #{projectId},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="userName != null">user_name = #{userName},</if>
            <if test="userCode != null">user_code = #{userCode},</if>
            <if test="userPhone != null">user_phone = #{userPhone},</if>
            <if test="useStatus != null">use_status = #{useStatus},</if>
            <if test="isDel != null">is_del = #{isDel},</if>
            <if test="createBy != null">create_by = #{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 id = #{id}
    </update>

    <delete id="deleteProProjectInfoUsersById" parameterType="Long">
        delete from pro_project_info_users where id = #{id}
    </delete>

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