<?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="org.springblade.modules.business.project.servicePerson.mapper.ProjectServicePersonMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="servicePersonResultMap" type="org.springblade.modules.business.project.servicePerson.entity.ServicePersonEntity">
        <result column="id" property="id"/>
        <result column="create_user" property="createUser"/>
        <result column="create_time" property="createTime"/>
        <result column="update_user" property="updateUser"/>
        <result column="update_time" property="updateTime"/>
        <result column="status" property="status"/>
        <result column="is_deleted" property="isDeleted"/>
        <result column="person_name" property="personName"/>
        <result column="org_id" property="orgId"/>
        <result column="contact_phone" property="contactPhone"/>
        <result column="mail" property="mail"/>
        <result column="remark" property="remark"/>
        <result column="user_account" property="userAccount"/>
    </resultMap>

    <resultMap id="personListResultMap" type="org.springblade.modules.business.project.servicePerson.vo.ServicePersonVO">
        <result column="id" property="id"/>
        <result column="create_user" property="createUser"/>
        <result column="create_time" property="createTime"/>
        <result column="update_user" property="updateUser"/>
        <result column="update_time" property="updateTime"/>
        <result column="status" property="status"/>
        <result column="is_deleted" property="isDeleted"/>
        <result column="real_name" property="personName"/>
        <result column="dept_id" property="orgId"/>
        <result column="phone" property="contactPhone"/>
        <result column="mail" property="mail"/>
        <result column="remark" property="remark"/>
        <result column="account" property="userAccount"/>
        <result column="role_name" property="roleName"/>
    </resultMap>

    <select id="servicePersonList" resultMap="personListResultMap">

        SELECT
        u.*,
        r.role_name,p.mail,p.remark
        FROM
        blade_user u
        LEFT JOIN project_service_person p ON u.id = p.user_id
        LEFT JOIN blade_role r ON r.id = u.role_id
        WHERE
        u.is_deleted = 0
        <if test="orgId!=null">
            and u.dept_id =#{orgId}
        </if>
        ORDER BY
        p.person_name
    </select>

</mapper>
