<?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.baseinfo.servicePerson.mapper.ServicePersonMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="servicePersonResultMap" type="org.springblade.modules.baseinfo.servicePerson.entity.ServicePersonEntity">

        <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="servicePersonVOResultMap" type="org.springblade.modules.baseinfo.servicePerson.vo.ServicePersonVO">

        <result column="person_name" property="personName"/>
        <result column="dept_id" property="orgId"/>
        <result column="contact_phone" property="contactPhone"/>
        <result column="mail" property="mail"/>
        <result column="remark" property="remark"/>
        <result column="account" property="userAccount"/>
        <result column="role_name" property="roleName"/>
        <result column="dept_name" property="orgName"/>
    </resultMap>

    <select id="selectPage" resultMap="servicePersonVOResultMap">

        SELECT
        p.*,
        r.role_name,d.dept_name,u.real_name,u.account,u.phone,u.dept_id
        FROM
        project_service_person p
        LEFT JOIN blade_user u ON u.id = p.user_id and u.is_deleted = 0
        LEFT JOIN blade_role r ON r.id = u.role_id and r.is_deleted = 0
        LEFT JOIN blade_dept d ON p.org_id = d.id and d.is_deleted = 0
        WHERE
        p.is_deleted = 0
        <if test="entity.personName!=null">
            and p.person_name like concat(concat('%', #{entity.personName}), '%')
        </if>
        <if test="entity.contactPhone!=null">
            and p.contact_phone like concat(concat('%', #{entity.contactPhone}), '%')
        </if>
        <if test="entity.orgId!=null">
            and p.org_id =#{entity.orgId}
        </if>
        ORDER BY
        p.person_name
    </select>

    <select id="selectAllList" resultMap="servicePersonVOResultMap">
        SELECT
        p.*,
        r.role_name,d.dept_name,u.real_name,u.account,u.phone,u.dept_id
        FROM
        project_service_person p
        LEFT JOIN blade_user u ON u.id = p.user_id and u.is_deleted = 0
        LEFT JOIN blade_role r ON r.id = u.role_id and r.is_deleted = 0
        LEFT JOIN blade_dept d ON u.dept_id = d.id and d.is_deleted = 0
        WHERE
        u.is_deleted = 0
        <if test="entity.personName!=null">
            and p.person_name like concat(concat('%', #{entity.personName}), '%')
        </if>
        <if test="entity.contactPhone!=null">
            and p.contact_phone like concat(concat('%', #{entity.contactPhone}), '%')
        </if>
        <if test="entity.orgId!=null">
            and u.dept_id =#{entity.orgId}
        </if>
        ORDER BY
        u.name,u.real_name
    </select>
</mapper>
