<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"mybatis-3-mapper.dtd">
<mapper namespace="com.mortals.xhx.module.area.dao.ibatis.AreaDaoImpl">

    <!-- 字段和属性映射 -->
    <resultMap type="AreaEntity" id="AreaEntity-Map">
            <id  property="id" column="id" />
            <result property="ancestors" column="ancestors" />
            <result property="name" column="name" />
            <result property="iid" column="iid" />
            <result property="pid" column="pid" />
            <result property="haveSonArea" column="haveSonArea" />
            <result property="haveSonDept" column="haveSonDept" />
            <result property="haveGetDept" column="haveGetDept" />
            <result property="haveGetMatterList" column="haveGetMatterList" />
            <result property="areaCode" column="areaCode" />
            <result property="areaLevel" column="areaLevel" />
            <result property="shortName" column="shortName" />
            <result property="domain" column="domain" />
            <result property="status" column="status" />
            <result property="createTime" column="createTime" />
            <result property="createUserId" column="createUserId" />
            <result property="updateTime" column="updateTime" />
            
    </resultMap>


    <!-- 表所有列 -->
    <sql id="_columns">
        <trim suffixOverrides="," suffix="">
                <if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('id') or colPickMode == 1 and data.containsKey('id')))">
                    a.id as id,
                </if>
                <if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('ancestors') or colPickMode == 1 and data.containsKey('ancestors')))">
                    a.ancestors as ancestors,
                </if>
                <if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('name') or colPickMode == 1 and data.containsKey('name')))">
                    a.name as name,
                </if>
                <if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('iid') or colPickMode == 1 and data.containsKey('iid')))">
                    a.iid as iid,
                </if>
                <if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('pid') or colPickMode == 1 and data.containsKey('pid')))">
                    a.pid as pid,
                </if>
                <if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('haveSonArea') or colPickMode == 1 and data.containsKey('haveSonArea')))">
                    a.haveSonArea as haveSonArea,
                </if>
                <if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('haveSonDept') or colPickMode == 1 and data.containsKey('haveSonDept')))">
                    a.haveSonDept as haveSonDept,
                </if>
                <if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('haveGetDept') or colPickMode == 1 and data.containsKey('haveGetDept')))">
                    a.haveGetDept as haveGetDept,
                </if>
                <if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('haveGetMatterList') or colPickMode == 1 and data.containsKey('haveGetMatterList')))">
                    a.haveGetMatterList as haveGetMatterList,
                </if>
                <if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('areaCode') or colPickMode == 1 and data.containsKey('areaCode')))">
                    a.areaCode as areaCode,
                </if>
                <if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('areaLevel') or colPickMode == 1 and data.containsKey('areaLevel')))">
                    a.areaLevel as areaLevel,
                </if>
                <if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('shortName') or colPickMode == 1 and data.containsKey('shortName')))">
                    a.shortName as shortName,
                </if>
                <if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('domain') or colPickMode == 1 and data.containsKey('domain')))">
                    a.domain as domain,
                </if>
                <if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('status') or colPickMode == 1 and data.containsKey('status')))">
                    a.status as status,
                </if>
                <if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('createTime') or colPickMode == 1 and data.containsKey('createTime')))">
                    a.createTime as createTime,
                </if>
                <if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('createUserId') or colPickMode == 1 and data.containsKey('createUserId')))">
                    a.createUserId as createUserId,
                </if>
                <if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('updateTime') or colPickMode == 1 and data.containsKey('updateTime')))">
                    a.updateTime as updateTime,
                </if>
        </trim>
    </sql>
    <!-- 新增 区分主键自增加还是业务插入 -->
    <insert id="insert" parameterType="AreaEntity"  useGeneratedKeys="true" keyProperty="id">
        insert into mortals_sys_area
        (ancestors,name,iid,pid,haveSonArea,haveSonDept,haveGetDept,haveGetMatterList,areaCode,areaLevel,shortName,domain,status,createTime,createUserId,updateTime)
        VALUES
        (#{ancestors},#{name},#{iid},#{pid},#{haveSonArea},#{haveSonDept},#{haveGetDept},#{haveGetMatterList},#{areaCode},#{areaLevel},#{shortName},#{domain},#{status},#{createTime},#{createUserId},#{updateTime})
    </insert>

    <!-- 批量新增 -->
    <insert id="insertBatch" parameterType="paramDto">
        insert into mortals_sys_area
        (ancestors,name,iid,pid,haveSonArea,haveSonDept,haveGetDept,haveGetMatterList,areaCode,areaLevel,shortName,domain,status,createTime,createUserId,updateTime)
        VALUES
        <foreach collection="data.dataList" item="item" index="index" separator="," >
            (#{item.ancestors},#{item.name},#{item.iid},#{item.pid},#{item.haveSonArea},#{item.haveSonDept},#{item.haveGetDept},#{item.haveGetMatterList},#{item.areaCode},#{item.areaLevel},#{item.shortName},#{item.domain},#{item.status},#{item.createTime},#{item.createUserId},#{item.updateTime})
        </foreach>
    </insert>


    <!-- 根据ParamDto更新 -->
    <update id="update" parameterType="paramDto">
        update mortals_sys_area as a
        set
        <trim suffixOverrides="," suffix="">
            <if test="(colPickMode==0 and data.containsKey('ancestors')) or (colPickMode==1 and !data.containsKey('ancestors'))">
                a.ancestors=#{data.ancestors},
            </if>
            <if test="(colPickMode==0 and data.containsKey('name')) or (colPickMode==1 and !data.containsKey('name'))">
                a.name=#{data.name},
            </if>
            <if test="(colPickMode==0 and data.containsKey('iid')) or (colPickMode==1 and !data.containsKey('iid'))">
                a.iid=#{data.iid},
            </if>
            <if test="(colPickMode==0 and data.containsKey('pid')) or (colPickMode==1 and !data.containsKey('pid'))">
                a.pid=#{data.pid},
            </if>
            <if test="(colPickMode==0 and data.containsKey('haveSonArea')) or (colPickMode==1 and !data.containsKey('haveSonArea'))">
                a.haveSonArea=#{data.haveSonArea},
            </if>
            <if test="(colPickMode==0 and data.containsKey('haveSonDept')) or (colPickMode==1 and !data.containsKey('haveSonDept'))">
                a.haveSonDept=#{data.haveSonDept},
            </if>
            <if test="(colPickMode==0 and data.containsKey('haveGetDept')) or (colPickMode==1 and !data.containsKey('haveGetDept'))">
                a.haveGetDept=#{data.haveGetDept},
            </if>
            <if test="(colPickMode==0 and data.containsKey('haveGetMatterList')) or (colPickMode==1 and !data.containsKey('haveGetMatterList'))">
                a.haveGetMatterList=#{data.haveGetMatterList},
            </if>
            <if test="(colPickMode==0 and data.containsKey('areaCode')) or (colPickMode==1 and !data.containsKey('areaCode'))">
                a.areaCode=#{data.areaCode},
            </if>
            <if test="(colPickMode==0 and data.containsKey('areaLevel')) or (colPickMode==1 and !data.containsKey('areaLevel'))">
                a.areaLevel=#{data.areaLevel},
            </if>
            <if test="(colPickMode==0 and data.containsKey('areaLevelIncrement')) or (colPickMode==1 and !data.containsKey('areaLevelIncrement'))">
                a.areaLevel=ifnull(a.areaLevel,0) + #{data.areaLevelIncrement},
            </if>
            <if test="(colPickMode==0 and data.containsKey('shortName')) or (colPickMode==1 and !data.containsKey('shortName'))">
                a.shortName=#{data.shortName},
            </if>
            <if test="(colPickMode==0 and data.containsKey('domain')) or (colPickMode==1 and !data.containsKey('domain'))">
                a.domain=#{data.domain},
            </if>
            <if test="(colPickMode==0 and data.containsKey('status')) or (colPickMode==1 and !data.containsKey('status'))">
                a.status=#{data.status},
            </if>
            <if test="(colPickMode==0 and data.containsKey('statusIncrement')) or (colPickMode==1 and !data.containsKey('statusIncrement'))">
                a.status=ifnull(a.status,0) + #{data.statusIncrement},
            </if>
            <if test="(colPickMode==0 and data.containsKey('createTime')) or (colPickMode==1 and !data.containsKey('createTime'))">
                a.createTime=#{data.createTime},
            </if>
            <if test="(colPickMode==0 and data.containsKey('createUserId')) or (colPickMode==1 and !data.containsKey('createUserId'))">
                a.createUserId=#{data.createUserId},
            </if>
            <if test="(colPickMode==0 and data.containsKey('createUserIdIncrement')) or (colPickMode==1 and !data.containsKey('createUserIdIncrement'))">
                a.createUserId=ifnull(a.createUserId,0) + #{data.createUserIdIncrement},
            </if>
            <if test="(colPickMode==0 and data.containsKey('updateTime')) or (colPickMode==1 and !data.containsKey('updateTime'))">
                a.updateTime=#{data.updateTime},
            </if>
        </trim>
        <trim suffixOverrides="where" suffix="">
            where
            <trim prefixOverrides="and" prefix="">
                <include refid="_condition_"/>
            </trim>
        </trim>
    </update>
    <!-- 批量更新 -->
    <update id="updateBatch" parameterType="paramDto">
        update mortals_sys_area as a
        <trim prefix="set" suffixOverrides=",">
                <trim prefix="ancestors=(case" suffix="ELSE ancestors end),">
                    <foreach collection="data.dataList" item="item" index="index" separator="" >
                        <if test="(colPickMode==0 and item.containsKey('ancestors')) or (colPickMode==1 and !item.containsKey('ancestors'))">
                            when a.id=#{item.id} then #{item.ancestors}
                        </if>
                    </foreach>
                </trim>
                <trim prefix="name=(case" suffix="ELSE name end),">
                    <foreach collection="data.dataList" item="item" index="index" separator="" >
                        <if test="(colPickMode==0 and item.containsKey('name')) or (colPickMode==1 and !item.containsKey('name'))">
                            when a.id=#{item.id} then #{item.name}
                        </if>
                    </foreach>
                </trim>
                <trim prefix="iid=(case" suffix="ELSE iid end),">
                    <foreach collection="data.dataList" item="item" index="index" separator="" >
                        <if test="(colPickMode==0 and item.containsKey('iid')) or (colPickMode==1 and !item.containsKey('iid'))">
                            when a.id=#{item.id} then #{item.iid}
                        </if>
                    </foreach>
                </trim>
                <trim prefix="pid=(case" suffix="ELSE pid end),">
                    <foreach collection="data.dataList" item="item" index="index" separator="" >
                        <if test="(colPickMode==0 and item.containsKey('pid')) or (colPickMode==1 and !item.containsKey('pid'))">
                            when a.id=#{item.id} then #{item.pid}
                        </if>
                    </foreach>
                </trim>
                <trim prefix="haveSonArea=(case" suffix="ELSE haveSonArea end),">
                    <foreach collection="data.dataList" item="item" index="index" separator="" >
                        <if test="(colPickMode==0 and item.containsKey('haveSonArea')) or (colPickMode==1 and !item.containsKey('haveSonArea'))">
                            when a.id=#{item.id} then #{item.haveSonArea}
                        </if>
                    </foreach>
                </trim>
                <trim prefix="haveSonDept=(case" suffix="ELSE haveSonDept end),">
                    <foreach collection="data.dataList" item="item" index="index" separator="" >
                        <if test="(colPickMode==0 and item.containsKey('haveSonDept')) or (colPickMode==1 and !item.containsKey('haveSonDept'))">
                            when a.id=#{item.id} then #{item.haveSonDept}
                        </if>
                    </foreach>
                </trim>
                <trim prefix="haveGetDept=(case" suffix="ELSE haveGetDept end),">
                    <foreach collection="data.dataList" item="item" index="index" separator="" >
                        <if test="(colPickMode==0 and item.containsKey('haveGetDept')) or (colPickMode==1 and !item.containsKey('haveGetDept'))">
                            when a.id=#{item.id} then #{item.haveGetDept}
                        </if>
                    </foreach>
                </trim>
                <trim prefix="haveGetMatterList=(case" suffix="ELSE haveGetMatterList end),">
                    <foreach collection="data.dataList" item="item" index="index" separator="" >
                        <if test="(colPickMode==0 and item.containsKey('haveGetMatterList')) or (colPickMode==1 and !item.containsKey('haveGetMatterList'))">
                            when a.id=#{item.id} then #{item.haveGetMatterList}
                        </if>
                    </foreach>
                </trim>
                <trim prefix="areaCode=(case" suffix="ELSE areaCode end),">
                    <foreach collection="data.dataList" item="item" index="index" separator="" >
                        <if test="(colPickMode==0 and item.containsKey('areaCode')) or (colPickMode==1 and !item.containsKey('areaCode'))">
                            when a.id=#{item.id} then #{item.areaCode}
                        </if>
                    </foreach>
                </trim>
                        <trim prefix="areaLevel=(case" suffix="ELSE areaLevel end),">
                            <foreach collection="data.dataList" item="item" index="index" separator="" >
                                <choose>
                                    <when test="(colPickMode==0 and item.containsKey('areaLevel')) or (colPickMode==1 and !item.containsKey('areaLevel'))">
                                        when a.id=#{item.id} then #{item.areaLevel}
                                    </when>
                                    <when test="(colPickMode==0 and item.containsKey('areaLevelIncrement')) or (colPickMode==1 and !item.containsKey('areaLevelIncrement'))">
                                        when a.id=#{item.id} then ifnull(a.areaLevel,0) + #{item.areaLevelIncrement}
                                    </when>
                                </choose>
                            </foreach>
                        </trim>
                <trim prefix="shortName=(case" suffix="ELSE shortName end),">
                    <foreach collection="data.dataList" item="item" index="index" separator="" >
                        <if test="(colPickMode==0 and item.containsKey('shortName')) or (colPickMode==1 and !item.containsKey('shortName'))">
                            when a.id=#{item.id} then #{item.shortName}
                        </if>
                    </foreach>
                </trim>
                <trim prefix="domain=(case" suffix="ELSE domain end),">
                    <foreach collection="data.dataList" item="item" index="index" separator="" >
                        <if test="(colPickMode==0 and item.containsKey('domain')) or (colPickMode==1 and !item.containsKey('domain'))">
                            when a.id=#{item.id} then #{item.domain}
                        </if>
                    </foreach>
                </trim>
                        <trim prefix="status=(case" suffix="ELSE status end),">
                            <foreach collection="data.dataList" item="item" index="index" separator="" >
                                <choose>
                                    <when test="(colPickMode==0 and item.containsKey('status')) or (colPickMode==1 and !item.containsKey('status'))">
                                        when a.id=#{item.id} then #{item.status}
                                    </when>
                                    <when test="(colPickMode==0 and item.containsKey('statusIncrement')) or (colPickMode==1 and !item.containsKey('statusIncrement'))">
                                        when a.id=#{item.id} then ifnull(a.status,0) + #{item.statusIncrement}
                                    </when>
                                </choose>
                            </foreach>
                        </trim>
                <trim prefix="createTime=(case" suffix="ELSE createTime end),">
                    <foreach collection="data.dataList" item="item" index="index" separator="" >
                        <if test="(colPickMode==0 and item.containsKey('createTime')) or (colPickMode==1 and !item.containsKey('createTime'))">
                            when a.id=#{item.id} then #{item.createTime}
                        </if>
                    </foreach>
                </trim>
                        <trim prefix="createUserId=(case" suffix="ELSE createUserId end),">
                            <foreach collection="data.dataList" item="item" index="index" separator="" >
                                <choose>
                                    <when test="(colPickMode==0 and item.containsKey('createUserId')) or (colPickMode==1 and !item.containsKey('createUserId'))">
                                        when a.id=#{item.id} then #{item.createUserId}
                                    </when>
                                    <when test="(colPickMode==0 and item.containsKey('createUserIdIncrement')) or (colPickMode==1 and !item.containsKey('createUserIdIncrement'))">
                                        when a.id=#{item.id} then ifnull(a.createUserId,0) + #{item.createUserIdIncrement}
                                    </when>
                                </choose>
                            </foreach>
                        </trim>
                <trim prefix="updateTime=(case" suffix="ELSE updateTime end),">
                    <foreach collection="data.dataList" item="item" index="index" separator="" >
                        <if test="(colPickMode==0 and item.containsKey('updateTime')) or (colPickMode==1 and !item.containsKey('updateTime'))">
                            when a.id=#{item.id} then #{item.updateTime}
                        </if>
                    </foreach>
                </trim>
        </trim>
        where id in
        <foreach collection="data.dataList" item="item" index="index" open="(" separator="," close=")">
            #{item.id}
        </foreach>
    </update>
    <!-- 根据主健查询 -->
    <select id="getByKey" parameterType="paramDto" resultMap="AreaEntity-Map">
        select <include refid="_columns"/>
        from mortals_sys_area as a
        where a.id=#{condition.id}
    </select>
    <!-- 根据主健删除 -->
    <delete id="deleteByKey" parameterType="paramDto">
        delete a.* from mortals_sys_area as a where a.id=#{condition.id}
    </delete>
    <!-- 根据主健删除一批，针对单一主健有效 -->
    <delete id="deleteByKeys">
        delete from mortals_sys_area where id in
        <foreach collection="array" item="item" index="index" open="(" separator="," close=")">
            #{item}
        </foreach>
    </delete>
    <!-- 根据paramDto删除一批 -->
    <delete id="deleteByMap" parameterType="paramDto">
        delete a.* from mortals_sys_area as a
        <trim suffixOverrides="where" suffix="">
            where
            <trim prefixOverrides="and" prefix="">
                <include refid="_condition_"/>
            </trim>
        </trim>
    </delete>
    <!-- 获取列表 -->
    <select id="getList" parameterType="paramDto" resultMap="AreaEntity-Map">
        select <include refid="_columns"/>
        from mortals_sys_area as a
        <trim suffixOverrides="where" suffix="">
            where
            <trim prefixOverrides="and" prefix="">
                <include refid="_condition_"/>
            </trim>
        </trim>
        <include refid="_orderCols_"/>
    </select>


    <!-- 获取子节点 -->
    <select id="selectChildrenAreaById" parameterType="String" resultMap="AreaEntity-Map">
        select * from mortals_sys_area as a where find_in_set(#{areaId}, ancestors)
    </select>

    <!-- 获取 -->
    <select id="getListCount" parameterType="paramDto" resultType="int">
        select count(1)
        from mortals_sys_area as a
        <trim suffixOverrides="where" suffix="">
            where
            <trim prefixOverrides="and" prefix="">
                <include refid="_condition_"/>
            </trim>
        </trim>
    </select>
    <!-- 条件映射 -->
    <sql id="_condition_">
        <if test="condition != null and !condition.isEmpty()">
            <!-- 条件映射-普通条件 -->
            <include refid="_condition_param_">
                <property name="_conditionParam_" value="condition"/>
                <property name="_conditionType_" value="and"/>
            </include>
            <!-- 条件映射-集合之间使用AND，集合中元素使用OR-(list[0].1 or list[0].2) and (list[1].3 or list[1].4) -->
            <if test="condition.containsKey('andConditionList') and !condition.andConditionList.isEmpty()">
                and
                <foreach collection="condition.andConditionList" open="(" close=")" index="index" item="andCondition" separator=" and ">
                    <trim prefixOverrides="or" prefix="(" suffix=")">
                        <include refid="_condition_param_">
                            <property name="_conditionParam_" value="andCondition"/>
                            <property name="_conditionType_" value="or"/>
                        </include>
                    </trim>
                </foreach>
            </if>
            <!-- 条件映射-集合之间使用OR，集合中元素使用AND-(list[0].1 and list[0].2) or (list[1].3 and list[1].4) -->
            <if test="condition.containsKey('orConditionList') and !condition.orConditionList.isEmpty()">
                and
                <foreach collection="condition.orConditionList" open="(" close=")" index="index" item="orCondition" separator=" or ">
                    <trim prefixOverrides="and" prefix="(" suffix=")">
                        <include refid="_condition_param_">
                            <property name="_conditionParam_" value="orCondition"/>
                            <property name="_conditionType_" value="and"/>
                        </include>
                    </trim>
                </foreach>
            </if>
        </if>
    </sql>
    <!-- 条件映射-代参数 -->
    <sql id="_condition_param_">
        <bind name="conditionParamRef" value="${_conditionParam_}"/>
        <if test="conditionParamRef.containsKey('id')">
            <if test="conditionParamRef.id != null">
                ${_conditionType_} a.id=#{${_conditionParam_}.id}
            </if>
        </if>
            <if test="conditionParamRef.containsKey('id')">
                <if test="conditionParamRef.id != null ">
                    ${_conditionType_} a.id = #{${_conditionParam_}.id}
                </if>
                <if test="conditionParamRef.id == null">
                    ${_conditionType_} a.id is null
                </if>
            </if>
            <if test="conditionParamRef.containsKey('idList')">
                ${_conditionType_} a.id in
                <foreach collection="conditionParamRef.idList" open="(" close=")" index="index" item="item" separator=",">
                    #{item}
                </foreach>
            </if>
            <if test="conditionParamRef.containsKey('idStart') and conditionParamRef.idStart != null">
                ${_conditionType_} a.id <![CDATA[ >= ]]> #{${_conditionParam_}.idStart}
            </if>
            <if test="conditionParamRef.containsKey('idEnd') and conditionParamRef.idEnd != null">
                ${_conditionType_} a.id <![CDATA[ <= ]]> #{${_conditionParam_}.idEnd}
            </if>


            <if test="conditionParamRef.containsKey('ancestors')">
                <if test="conditionParamRef.ancestors != null and conditionParamRef.ancestors != ''">
                    ${_conditionType_} a.ancestors like #{${_conditionParam_}.ancestors}
                </if>
                <if test="conditionParamRef.ancestors == null">
                    ${_conditionType_} a.ancestors is null
                </if>
            </if>
            <if test="conditionParamRef.containsKey('ancestorsList')">
                ${_conditionType_} a.ancestors in
                <foreach collection="conditionParamRef.ancestorsList" open="(" close=")" index="index" item="item" separator=",">
                    #{item}
                </foreach>
            </if>

            <if test="conditionParamRef.containsKey('name')">
                <if test="conditionParamRef.name != null and conditionParamRef.name != ''">
                    ${_conditionType_} a.name like #{${_conditionParam_}.name}
                </if>
                <if test="conditionParamRef.name == null">
                    ${_conditionType_} a.name is null
                </if>
            </if>
            <if test="conditionParamRef.containsKey('nameList')">
                ${_conditionType_} a.name in
                <foreach collection="conditionParamRef.nameList" open="(" close=")" index="index" item="item" separator=",">
                    #{item}
                </foreach>
            </if>

            <if test="conditionParamRef.containsKey('iid')">
                <if test="conditionParamRef.iid != null and conditionParamRef.iid != ''">
                    ${_conditionType_} a.iid like #{${_conditionParam_}.iid}
                </if>
                <if test="conditionParamRef.iid == null">
                    ${_conditionType_} a.iid is null
                </if>
            </if>
            <if test="conditionParamRef.containsKey('iidList')">
                ${_conditionType_} a.iid in
                <foreach collection="conditionParamRef.iidList" open="(" close=")" index="index" item="item" separator=",">
                    #{item}
                </foreach>
            </if>

            <if test="conditionParamRef.containsKey('pid')">
                <if test="conditionParamRef.pid != null and conditionParamRef.pid != ''">
                    ${_conditionType_} a.pid like #{${_conditionParam_}.pid}
                </if>
                <if test="conditionParamRef.pid == null">
                    ${_conditionType_} a.pid is null
                </if>
            </if>
            <if test="conditionParamRef.containsKey('pidList')">
                ${_conditionType_} a.pid in
                <foreach collection="conditionParamRef.pidList" open="(" close=")" index="index" item="item" separator=",">
                    #{item}
                </foreach>
            </if>

            <if test="conditionParamRef.containsKey('haveSonArea')">
                <if test="conditionParamRef.haveSonArea != null and conditionParamRef.haveSonArea != ''">
                    ${_conditionType_} a.haveSonArea like #{${_conditionParam_}.haveSonArea}
                </if>
                <if test="conditionParamRef.haveSonArea == null">
                    ${_conditionType_} a.haveSonArea is null
                </if>
            </if>
            <if test="conditionParamRef.containsKey('haveSonAreaList')">
                ${_conditionType_} a.haveSonArea in
                <foreach collection="conditionParamRef.haveSonAreaList" open="(" close=")" index="index" item="item" separator=",">
                    #{item}
                </foreach>
            </if>

            <if test="conditionParamRef.containsKey('haveSonDept')">
                <if test="conditionParamRef.haveSonDept != null and conditionParamRef.haveSonDept != ''">
                    ${_conditionType_} a.haveSonDept like #{${_conditionParam_}.haveSonDept}
                </if>
                <if test="conditionParamRef.haveSonDept == null">
                    ${_conditionType_} a.haveSonDept is null
                </if>
            </if>
            <if test="conditionParamRef.containsKey('haveSonDeptList')">
                ${_conditionType_} a.haveSonDept in
                <foreach collection="conditionParamRef.haveSonDeptList" open="(" close=")" index="index" item="item" separator=",">
                    #{item}
                </foreach>
            </if>

            <if test="conditionParamRef.containsKey('haveGetDept')">
                <if test="conditionParamRef.haveGetDept != null and conditionParamRef.haveGetDept != ''">
                    ${_conditionType_} a.haveGetDept like #{${_conditionParam_}.haveGetDept}
                </if>
                <if test="conditionParamRef.haveGetDept == null">
                    ${_conditionType_} a.haveGetDept is null
                </if>
            </if>
            <if test="conditionParamRef.containsKey('haveGetDeptList')">
                ${_conditionType_} a.haveGetDept in
                <foreach collection="conditionParamRef.haveGetDeptList" open="(" close=")" index="index" item="item" separator=",">
                    #{item}
                </foreach>
            </if>

            <if test="conditionParamRef.containsKey('haveGetMatterList')">
                <if test="conditionParamRef.haveGetMatterList != null and conditionParamRef.haveGetMatterList != ''">
                    ${_conditionType_} a.haveGetMatterList like #{${_conditionParam_}.haveGetMatterList}
                </if>
                <if test="conditionParamRef.haveGetMatterList == null">
                    ${_conditionType_} a.haveGetMatterList is null
                </if>
            </if>
            <if test="conditionParamRef.containsKey('haveGetMatterListList')">
                ${_conditionType_} a.haveGetMatterList in
                <foreach collection="conditionParamRef.haveGetMatterListList" open="(" close=")" index="index" item="item" separator=",">
                    #{item}
                </foreach>
            </if>

            <if test="conditionParamRef.containsKey('areaCode')">
                <if test="conditionParamRef.areaCode != null and conditionParamRef.areaCode != ''">
                    ${_conditionType_} a.areaCode like #{${_conditionParam_}.areaCode}
                </if>
                <if test="conditionParamRef.areaCode == null">
                    ${_conditionType_} a.areaCode is null
                </if>
            </if>
            <if test="conditionParamRef.containsKey('areaCodeList')">
                ${_conditionType_} a.areaCode in
                <foreach collection="conditionParamRef.areaCodeList" open="(" close=")" index="index" item="item" separator=",">
                    #{item}
                </foreach>
            </if>
            <if test="conditionParamRef.containsKey('areaLevel')">
                <if test="conditionParamRef.areaLevel != null ">
                    ${_conditionType_} a.areaLevel = #{${_conditionParam_}.areaLevel}
                </if>
                <if test="conditionParamRef.areaLevel == null">
                    ${_conditionType_} a.areaLevel is null
                </if>
            </if>
            <if test="conditionParamRef.containsKey('areaLevelList')">
                ${_conditionType_} a.areaLevel in
                <foreach collection="conditionParamRef.areaLevelList" open="(" close=")" index="index" item="item" separator=",">
                    #{item}
                </foreach>
            </if>
            <if test="conditionParamRef.containsKey('areaLevelStart') and conditionParamRef.areaLevelStart != null">
                ${_conditionType_} a.areaLevel <![CDATA[ >= ]]> #{${_conditionParam_}.areaLevelStart}
            </if>
            <if test="conditionParamRef.containsKey('areaLevelEnd') and conditionParamRef.areaLevelEnd != null">
                ${_conditionType_} a.areaLevel <![CDATA[ <= ]]> #{${_conditionParam_}.areaLevelEnd}
            </if>


            <if test="conditionParamRef.containsKey('shortName')">
                <if test="conditionParamRef.shortName != null and conditionParamRef.shortName != ''">
                    ${_conditionType_} a.shortName like #{${_conditionParam_}.shortName}
                </if>
                <if test="conditionParamRef.shortName == null">
                    ${_conditionType_} a.shortName is null
                </if>
            </if>
            <if test="conditionParamRef.containsKey('shortNameList')">
                ${_conditionType_} a.shortName in
                <foreach collection="conditionParamRef.shortNameList" open="(" close=")" index="index" item="item" separator=",">
                    #{item}
                </foreach>
            </if>

            <if test="conditionParamRef.containsKey('domain')">
                <if test="conditionParamRef.domain != null and conditionParamRef.domain != ''">
                    ${_conditionType_} a.domain like #{${_conditionParam_}.domain}
                </if>
                <if test="conditionParamRef.domain == null">
                    ${_conditionType_} a.domain is null
                </if>
            </if>
            <if test="conditionParamRef.containsKey('domainList')">
                ${_conditionType_} a.domain in
                <foreach collection="conditionParamRef.domainList" open="(" close=")" index="index" item="item" separator=",">
                    #{item}
                </foreach>
            </if>
            <if test="conditionParamRef.containsKey('status')">
                <if test="conditionParamRef.status != null ">
                    ${_conditionType_} a.status = #{${_conditionParam_}.status}
                </if>
                <if test="conditionParamRef.status == null">
                    ${_conditionType_} a.status is null
                </if>
            </if>
            <if test="conditionParamRef.containsKey('statusList')">
                ${_conditionType_} a.status in
                <foreach collection="conditionParamRef.statusList" open="(" close=")" index="index" item="item" separator=",">
                    #{item}
                </foreach>
            </if>
            <if test="conditionParamRef.containsKey('statusStart') and conditionParamRef.statusStart != null">
                ${_conditionType_} a.status <![CDATA[ >= ]]> #{${_conditionParam_}.statusStart}
            </if>
            <if test="conditionParamRef.containsKey('statusEnd') and conditionParamRef.statusEnd != null">
                ${_conditionType_} a.status <![CDATA[ <= ]]> #{${_conditionParam_}.statusEnd}
            </if>


            <if test="conditionParamRef.containsKey('createTime')">
                <if test="conditionParamRef.createTime != null ">
                    ${_conditionType_} a.createTime = #{${_conditionParam_}.createTime}
                </if>
                <if test="conditionParamRef.createTime == null">
                    ${_conditionType_} a.createTime is null
                </if>
            </if>
            <if test="conditionParamRef.containsKey('createTimeStart') and conditionParamRef.createTimeStart != null and conditionParamRef.createTimeStart!=''">
                ${_conditionType_} a.createTime <![CDATA[ >= ]]> STR_TO_DATE(left(concat(#{${_conditionParam_}.createTimeStart},' 00:00:00'),19),'%Y-%m-%d %k:%i:%s')
            </if>
            <if test="conditionParamRef.containsKey('createTimeEnd') and conditionParamRef.createTimeEnd != null and conditionParamRef.createTimeEnd!=''">
                ${_conditionType_} a.createTime <![CDATA[ <= ]]> STR_TO_DATE(left(concat(#{${_conditionParam_}.createTimeEnd},' 23:59:59'),19),'%Y-%m-%d %k:%i:%s')
            </if>
            <if test="conditionParamRef.containsKey('createUserId')">
                <if test="conditionParamRef.createUserId != null ">
                    ${_conditionType_} a.createUserId = #{${_conditionParam_}.createUserId}
                </if>
                <if test="conditionParamRef.createUserId == null">
                    ${_conditionType_} a.createUserId is null
                </if>
            </if>
            <if test="conditionParamRef.containsKey('createUserIdList')">
                ${_conditionType_} a.createUserId in
                <foreach collection="conditionParamRef.createUserIdList" open="(" close=")" index="index" item="item" separator=",">
                    #{item}
                </foreach>
            </if>
            <if test="conditionParamRef.containsKey('createUserIdStart') and conditionParamRef.createUserIdStart != null">
                ${_conditionType_} a.createUserId <![CDATA[ >= ]]> #{${_conditionParam_}.createUserIdStart}
            </if>
            <if test="conditionParamRef.containsKey('createUserIdEnd') and conditionParamRef.createUserIdEnd != null">
                ${_conditionType_} a.createUserId <![CDATA[ <= ]]> #{${_conditionParam_}.createUserIdEnd}
            </if>


            <if test="conditionParamRef.containsKey('updateTime')">
                <if test="conditionParamRef.updateTime != null ">
                    ${_conditionType_} a.updateTime = #{${_conditionParam_}.updateTime}
                </if>
                <if test="conditionParamRef.updateTime == null">
                    ${_conditionType_} a.updateTime is null
                </if>
            </if>
            <if test="conditionParamRef.containsKey('updateTimeStart') and conditionParamRef.updateTimeStart != null and conditionParamRef.updateTimeStart!=''">
                ${_conditionType_} a.updateTime <![CDATA[ >= ]]> STR_TO_DATE(left(concat(#{${_conditionParam_}.updateTimeStart},' 00:00:00'),19),'%Y-%m-%d %k:%i:%s')
            </if>
            <if test="conditionParamRef.containsKey('updateTimeEnd') and conditionParamRef.updateTimeEnd != null and conditionParamRef.updateTimeEnd!=''">
                ${_conditionType_} a.updateTime <![CDATA[ <= ]]> STR_TO_DATE(left(concat(#{${_conditionParam_}.updateTimeEnd},' 23:59:59'),19),'%Y-%m-%d %k:%i:%s')
            </if>
    </sql>
    <sql id="_orderCols_">
        <if test="orderColList != null and !orderColList.isEmpty()">
            order by
            <trim suffixOverrides=","  suffix="">
                <foreach collection="orderColList" open="" close="" index="index" item="item" separator=",">
                     ${item.colName} ${item.sortKind}
                </foreach>
            </trim>
        </if>
        <if test="(orderColList == null or orderColList.isEmpty()) and orderCol != null and !orderCol.isEmpty()">
            order by
            <trim suffixOverrides=","  suffix="">
                    <if test="orderCol.containsKey('id')">
                        a.id
                        <if test='orderCol.id != null and "DESC".equalsIgnoreCase(orderCol.id)'>DESC</if>
                        ,
                    </if>
                    <if test="orderCol.containsKey('ancestors')">
                        a.ancestors
                        <if test='orderCol.ancestors != null and "DESC".equalsIgnoreCase(orderCol.ancestors)'>DESC</if>
                        ,
                    </if>
                    <if test="orderCol.containsKey('name')">
                        a.name
                        <if test='orderCol.name != null and "DESC".equalsIgnoreCase(orderCol.name)'>DESC</if>
                        ,
                    </if>
                    <if test="orderCol.containsKey('iid')">
                        a.iid
                        <if test='orderCol.iid != null and "DESC".equalsIgnoreCase(orderCol.iid)'>DESC</if>
                        ,
                    </if>
                    <if test="orderCol.containsKey('pid')">
                        a.pid
                        <if test='orderCol.pid != null and "DESC".equalsIgnoreCase(orderCol.pid)'>DESC</if>
                        ,
                    </if>
                    <if test="orderCol.containsKey('haveSonArea')">
                        a.haveSonArea
                        <if test='orderCol.haveSonArea != null and "DESC".equalsIgnoreCase(orderCol.haveSonArea)'>DESC</if>
                        ,
                    </if>
                    <if test="orderCol.containsKey('haveSonDept')">
                        a.haveSonDept
                        <if test='orderCol.haveSonDept != null and "DESC".equalsIgnoreCase(orderCol.haveSonDept)'>DESC</if>
                        ,
                    </if>
                    <if test="orderCol.containsKey('haveGetDept')">
                        a.haveGetDept
                        <if test='orderCol.haveGetDept != null and "DESC".equalsIgnoreCase(orderCol.haveGetDept)'>DESC</if>
                        ,
                    </if>
                    <if test="orderCol.containsKey('haveGetMatterList')">
                        a.haveGetMatterList
                        <if test='orderCol.haveGetMatterList != null and "DESC".equalsIgnoreCase(orderCol.haveGetMatterList)'>DESC</if>
                        ,
                    </if>
                    <if test="orderCol.containsKey('areaCode')">
                        a.areaCode
                        <if test='orderCol.areaCode != null and "DESC".equalsIgnoreCase(orderCol.areaCode)'>DESC</if>
                        ,
                    </if>
                    <if test="orderCol.containsKey('areaLevel')">
                        a.areaLevel
                        <if test='orderCol.areaLevel != null and "DESC".equalsIgnoreCase(orderCol.areaLevel)'>DESC</if>
                        ,
                    </if>
                    <if test="orderCol.containsKey('shortName')">
                        a.shortName
                        <if test='orderCol.shortName != null and "DESC".equalsIgnoreCase(orderCol.shortName)'>DESC</if>
                        ,
                    </if>
                    <if test="orderCol.containsKey('domain')">
                        a.domain
                        <if test='orderCol.domain != null and "DESC".equalsIgnoreCase(orderCol.domain)'>DESC</if>
                        ,
                    </if>
                    <if test="orderCol.containsKey('status')">
                        a.status
                        <if test='orderCol.status != null and "DESC".equalsIgnoreCase(orderCol.status)'>DESC</if>
                        ,
                    </if>
                    <if test="orderCol.containsKey('createTime')">
                        a.createTime
                        <if test='orderCol.createTime != null and "DESC".equalsIgnoreCase(orderCol.createTime)'>DESC</if>
                        ,
                    </if>
                    <if test="orderCol.containsKey('createUserId')">
                        a.createUserId
                        <if test='orderCol.createUserId != null and "DESC".equalsIgnoreCase(orderCol.createUserId)'>DESC</if>
                        ,
                    </if>
                    <if test="orderCol.containsKey('updateTime')">
                        a.updateTime
                        <if test='orderCol.updateTime != null and "DESC".equalsIgnoreCase(orderCol.updateTime)'>DESC</if>
                        ,
                    </if>
            </trim>
        </if>
    </sql>
    <sql id="_group_by_">
        <if test="groupList != null and !groupList.isEmpty()">
            GROUP BY
            <trim suffixOverrides=","  suffix="">
                <foreach collection="groupList" open="" close="" index="index" item="item" separator=",">
                    ${item}
                </foreach>
            </trim>
        </if>
    </sql>
</mapper>