<?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.DeptInfoMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.diagbot.entity.DeptInfo">
        <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="remark" property="remark" />
    </resultMap>

    <select id="getAllDeptInfo" resultType="com.diagbot.dto.GetDeptInfoDTO">
        SELECT * FROM `icss_dept_info` WHERE is_deleted = 'N'
         <if test="name != null and name != ''">
             AND `name` LIKE CONCAT('%',#{name},'%')
         </if>
        order by gmt_modified desc
    </select>

    <select id="getDeptName" resultType="com.diagbot.dto.DeptInfoDTO">
        SELECT
	      *
        FROM
	      `icss_dept_info` a
        WHERE
          a.is_deleted = 'N'
          AND a.id NOT IN (
		      SELECT
			    b.dept_id
		      FROM
			    icss_question_usual b
		      WHERE
		        b.is_deleted = 'N'
		        AND b.id IN (
				    SELECT
					  c.id
				    FROM
					  `icss_dept_info` c
				    WHERE c.is_deleted = 'N'
			  )
	      )
    </select>
</mapper>
