<?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="cn.iocoder.yudao.module.system.dal.mysql.home.HomeServiceMemberMapper">

    <select id="selectPageWithJoin" resultType="cn.iocoder.yudao.module.system.controller.admin.home.vo.HomeServiceMemeberPageRespVO">
        select
            m.id,
            m.name,
            m.id_card as idCard,
            m.sex,
            m.phone,
            m.avatar,
            m.live_address as liveAddress,
            m.live_detail as liveDetail,
            m.service_area_id as serviceAreaId,
            a.area as serviceArea,
            m.service_dept_id as serviceDeptId,
            d.name as serviceDeptName,
            m.tenant_id as tenantId,
            m.create_time as createTime,
            m.update_time as updateTime,
            m.creator,
            m.updater
        from home_service_member m
        left join home_service_area a on a.id = m.service_area_id
        left join home_service_department d on d.id = m.service_dept_id
        where 1 = 1
        <if test="params.name != null and params.name != ''">
            and m.name like concat('%', #{params.name}, '%')
        </if>
        <if test="params.idCard != null and params.idCard != ''">
            and m.id_card like concat('%', #{params.idCard}, '%')
        </if>
        <if test="params.phone != null and params.phone != ''">
            and m.phone like concat('%', #{params.phone}, '%')
        </if>
        <if test="params.serviceAreaId != null">
            and m.service_area_id = #{params.serviceAreaId}
        </if>
        <if test="params.serviceDeptId != null">
            and m.service_dept_id = #{params.serviceDeptId}
        </if>
        <if test="params.tenantId != null">
            and m.tenant_id = #{params.tenantId}
        </if>
        <if test="params.tenantIds != null and params.tenantIds.length > 0">
            and m.tenant_id in
            <foreach collection="params.tenantIds" item="tenantId" open="(" separator="," close=")">
                #{tenantId}
            </foreach>
        </if>
        order by m.id desc
    </select>

    <select id="selectWithJoinById" resultType="cn.iocoder.yudao.module.system.controller.admin.home.vo.HomeServiceMemeberPageRespVO">
        select
            m.id,
            m.name,
            m.id_card as idCard,
            m.sex,
            m.phone,
            m.avatar,
            m.live_address as liveAddress,
            m.live_detail as liveDetail,
            m.service_area_id as serviceAreaId,
            a.area as serviceArea,
            m.service_dept_id as serviceDeptId,
            d.name as serviceDeptName,
            m.tenant_id as tenantId,
            m.create_time as createTime,
            m.update_time as updateTime,
            m.creator,
            m.updater
        from home_service_member m
        left join home_service_area a on a.id = m.service_area_id
        left join home_service_department d on d.id = m.service_dept_id
        where m.id = #{id}
    </select>

</mapper>

