<?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.jeeplus.sys.mapper.OfficeMapper">

    <sql id="officeColumns">
    	a.id as "id",
        a.parent_id as "parent.id",
        a.parent_ids as "parentIds",
        a.name as "name",
        a.sort as "sort",
        a.area_id as "areaId",
        a.code as "code",
        a.type as "type",
        a.grade as "grade",
        a.address as "address",
        a.zip_code as "zipCode",
        a.master as "master",
        a.phone as "phone",
        a.fax as "fax",
        a.email as "email",
        a.useable as "useable",
        a.primary_person as "primaryPerson",
        a.deputy_person as "deputyPerson",
		a.create_by as "createBy.id",
		a.create_date as "createDate",
		a.update_by as "updateBy.id",
		a.update_date as "updateDate",
        a.remarks as "remarks",
        a.del_flag as "delFlag"
    </sql>

    <select id="getOfficeByName" resultType="com.jeeplus.sys.service.dto.OfficeDTO">
        select
        <include refid="officeColumns"/>
        from sys_office a
        <where>
            a.name = #{officeName}
            <if test="null != parentName and '' != parentName">
                ${parentName}
            </if>
            and a.del_flag = 0
        </where>
    </select>

    <select id="getOfficeAllByOfficeName" resultType="com.jeeplus.sys.service.dto.OfficeDTO">
        select
        <include refid="officeColumns"/>
        from sys_office a
        <where>
            <if test="officeName != null and officeName != ''">
                a.id = (select id from sys_office where name = #{officeName})
                or
                a.parent_ids like concat('%',(select id from sys_office where name = #{officeName}),'%')
            </if>
        </where>
    </select>
</mapper>
