<?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.diagbot.mapper.OrganizationMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.diagbot.entity.Organization">
        <id column="id" property="id"/>
        <result column="is_deleted" property="isDeleted"/>
        <result column="gmt_create" property="gmtCreate"/>
        <result column="gmt_modified" property="gmtModified"/>
        <result column="creator" property="creator"/>
        <result column="modifier" property="modifier"/>
        <result column="name" property="name"/>
        <result column="type" property="type"/>
        <result column="principal" property="principal"/>
        <result column="address" property="address"/>
        <result column="parent_id" property="parentId"/>
        <result column="sub_num" property="subNum"/>
        <result column="remark" property="remark"/>
    </resultMap>

    <select id="getByUserId" resultMap="BaseResultMap">
        SELECT a.* FROM `sys_organization` a, sys_user_organization b
        where a.id = b.organization_id and b.user_id = #{userId} and a.is_deleted = 'N' and b.is_deleted = 'N'
    </select>

    <select id="findOrganization" parameterType="java.lang.String"
            resultType="com.diagbot.entity.Organization">
		SELECT id,NAME FROM sys_organization WHERE is_deleted = "N" AND NAME LIKE
		CONCAT('%',  #{organizationName}, '%')
	</select>
</mapper>
