<?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.sitestat.dao.ibatis.SitestatDaoImpl">

    <!-- 字段和属性映射 -->
    <resultMap type="SitestatEntity" id="SitestatEntity-Map">
            <id  property="id" column="id" />
            <result property="siteId" column="siteId" />
            <result property="siteCode" column="siteCode" />
            <result property="siteName" column="siteName" />
            <result property="deviceTotal" column="deviceTotal" />
            <result property="onlineCount" column="onlineCount" />
            <result property="offlineCount" column="offlineCount" />
            <result property="stopCount" column="stopCount" />
            <result property="unActiveCount" column="unActiveCount" />
            <result property="createTime" column="createTime" />
            <result property="updateUserId" column="updateUserId" />
            <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,
                </if>
                <if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('siteId') or colPickMode == 1 and data.containsKey('siteId')))">
                    a.siteId,
                </if>
                <if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('siteCode') or colPickMode == 1 and data.containsKey('siteCode')))">
                    a.siteCode,
                </if>
                <if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('siteName') or colPickMode == 1 and data.containsKey('siteName')))">
                    a.siteName,
                </if>
                <if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('deviceTotal') or colPickMode == 1 and data.containsKey('deviceTotal')))">
                    a.deviceTotal,
                </if>
                <if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('onlineCount') or colPickMode == 1 and data.containsKey('onlineCount')))">
                    a.onlineCount,
                </if>
                <if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('offlineCount') or colPickMode == 1 and data.containsKey('offlineCount')))">
                    a.offlineCount,
                </if>
                <if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('stopCount') or colPickMode == 1 and data.containsKey('stopCount')))">
                    a.stopCount,
                </if>
                <if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('unActiveCount') or colPickMode == 1 and data.containsKey('unActiveCount')))">
                    a.unActiveCount,
                </if>
                <if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('createTime') or colPickMode == 1 and data.containsKey('createTime')))">
                    a.createTime,
                </if>
                <if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('updateUserId') or colPickMode == 1 and data.containsKey('updateUserId')))">
                    a.updateUserId,
                </if>
                <if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('updateTime') or colPickMode == 1 and data.containsKey('updateTime')))">
                    a.updateTime,
                </if>
        </trim>
    </sql>
    <!-- 新增 区分主键自增加还是业务插入 -->
    <insert id="insert" parameterType="SitestatEntity"  useGeneratedKeys="true" keyProperty="id">
        insert into mortals_xhx_sitestat
        (siteId,siteCode,siteName,deviceTotal,onlineCount,offlineCount,stopCount,unActiveCount,createTime,updateUserId,updateTime)
        VALUES
        (#{siteId},#{siteCode},#{siteName},#{deviceTotal},#{onlineCount},#{offlineCount},#{stopCount},#{unActiveCount},#{createTime},#{updateUserId},#{updateTime})
    </insert>

    <!-- 批量新增 -->
    <insert id="insertBatch" parameterType="paramDto">
        insert into mortals_xhx_sitestat
        (siteId,siteCode,siteName,deviceTotal,onlineCount,offlineCount,stopCount,unActiveCount,createTime,updateUserId,updateTime)
        VALUES
        <foreach collection="data.dataList" item="item" index="index" separator="," >
            (#{item.siteId},#{item.siteCode},#{item.siteName},#{item.deviceTotal},#{item.onlineCount},#{item.offlineCount},#{item.stopCount},#{item.unActiveCount},#{item.createTime},#{item.updateUserId},#{item.updateTime})
        </foreach>
    </insert>


    <!-- 根据ParamDto更新 -->
    <update id="update" parameterType="paramDto">
        update mortals_xhx_sitestat as a
        set
        <trim suffixOverrides="," suffix="">
            <if test="(colPickMode==0 and data.containsKey('siteId')) or (colPickMode==1 and !data.containsKey('siteId'))">
                a.siteId=#{data.siteId},
            </if>
            <if test="(colPickMode==0 and data.containsKey('siteIdIncrement')) or (colPickMode==1 and !data.containsKey('siteIdIncrement'))">
                a.siteId=ifnull(a.siteId,0) + #{data.siteIdIncrement},
            </if>
            <if test="(colPickMode==0 and data.containsKey('siteCode')) or (colPickMode==1 and !data.containsKey('siteCode'))">
                a.siteCode=#{data.siteCode},
            </if>
            <if test="(colPickMode==0 and data.containsKey('siteName')) or (colPickMode==1 and !data.containsKey('siteName'))">
                a.siteName=#{data.siteName},
            </if>
            <if test="(colPickMode==0 and data.containsKey('deviceTotal')) or (colPickMode==1 and !data.containsKey('deviceTotal'))">
                a.deviceTotal=#{data.deviceTotal},
            </if>
            <if test="(colPickMode==0 and data.containsKey('deviceTotalIncrement')) or (colPickMode==1 and !data.containsKey('deviceTotalIncrement'))">
                a.deviceTotal=ifnull(a.deviceTotal,0) + #{data.deviceTotalIncrement},
            </if>
            <if test="(colPickMode==0 and data.containsKey('onlineCount')) or (colPickMode==1 and !data.containsKey('onlineCount'))">
                a.onlineCount=#{data.onlineCount},
            </if>
            <if test="(colPickMode==0 and data.containsKey('onlineCountIncrement')) or (colPickMode==1 and !data.containsKey('onlineCountIncrement'))">
                a.onlineCount=ifnull(a.onlineCount,0) + #{data.onlineCountIncrement},
            </if>
            <if test="(colPickMode==0 and data.containsKey('offlineCount')) or (colPickMode==1 and !data.containsKey('offlineCount'))">
                a.offlineCount=#{data.offlineCount},
            </if>
            <if test="(colPickMode==0 and data.containsKey('offlineCountIncrement')) or (colPickMode==1 and !data.containsKey('offlineCountIncrement'))">
                a.offlineCount=ifnull(a.offlineCount,0) + #{data.offlineCountIncrement},
            </if>
            <if test="(colPickMode==0 and data.containsKey('stopCount')) or (colPickMode==1 and !data.containsKey('stopCount'))">
                a.stopCount=#{data.stopCount},
            </if>
            <if test="(colPickMode==0 and data.containsKey('stopCountIncrement')) or (colPickMode==1 and !data.containsKey('stopCountIncrement'))">
                a.stopCount=ifnull(a.stopCount,0) + #{data.stopCountIncrement},
            </if>
            <if test="(colPickMode==0 and data.containsKey('unActiveCount')) or (colPickMode==1 and !data.containsKey('unActiveCount'))">
                a.unActiveCount=#{data.unActiveCount},
            </if>
            <if test="(colPickMode==0 and data.containsKey('unActiveCountIncrement')) or (colPickMode==1 and !data.containsKey('unActiveCountIncrement'))">
                a.unActiveCount=ifnull(a.unActiveCount,0) + #{data.unActiveCountIncrement},
            </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('updateUserId')) or (colPickMode==1 and !data.containsKey('updateUserId'))">
                a.updateUserId=#{data.updateUserId},
            </if>
            <if test="(colPickMode==0 and data.containsKey('updateUserIdIncrement')) or (colPickMode==1 and !data.containsKey('updateUserIdIncrement'))">
                a.updateUserId=ifnull(a.updateUserId,0) + #{data.updateUserIdIncrement},
            </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_xhx_sitestat as a
        <trim prefix="set" suffixOverrides=",">
                        <trim prefix="siteId=(case" suffix="ELSE siteId end),">
                            <foreach collection="data.dataList" item="item" index="index" separator="" >
                                <choose>
                                    <when test="(colPickMode==0 and item.containsKey('siteId')) or (colPickMode==1 and !item.containsKey('siteId'))">
                                        when a.id=#{item.id} then #{item.siteId}
                                    </when>
                                    <when test="(colPickMode==0 and item.containsKey('siteIdIncrement')) or (colPickMode==1 and !item.containsKey('siteIdIncrement'))">
                                        when a.id=#{item.id} then ifnull(a.siteId,0) + #{item.siteIdIncrement}
                                    </when>
                                </choose>
                            </foreach>
                        </trim>
                <trim prefix="siteCode=(case" suffix="ELSE siteCode end),">
                    <foreach collection="data.dataList" item="item" index="index" separator="" >
                        <if test="(colPickMode==0 and item.containsKey('siteCode')) or (colPickMode==1 and !item.containsKey('siteCode'))">
                            when a.id=#{item.id} then #{item.siteCode}
                        </if>
                    </foreach>
                </trim>
                <trim prefix="siteName=(case" suffix="ELSE siteName end),">
                    <foreach collection="data.dataList" item="item" index="index" separator="" >
                        <if test="(colPickMode==0 and item.containsKey('siteName')) or (colPickMode==1 and !item.containsKey('siteName'))">
                            when a.id=#{item.id} then #{item.siteName}
                        </if>
                    </foreach>
                </trim>
                        <trim prefix="deviceTotal=(case" suffix="ELSE deviceTotal end),">
                            <foreach collection="data.dataList" item="item" index="index" separator="" >
                                <choose>
                                    <when test="(colPickMode==0 and item.containsKey('deviceTotal')) or (colPickMode==1 and !item.containsKey('deviceTotal'))">
                                        when a.id=#{item.id} then #{item.deviceTotal}
                                    </when>
                                    <when test="(colPickMode==0 and item.containsKey('deviceTotalIncrement')) or (colPickMode==1 and !item.containsKey('deviceTotalIncrement'))">
                                        when a.id=#{item.id} then ifnull(a.deviceTotal,0) + #{item.deviceTotalIncrement}
                                    </when>
                                </choose>
                            </foreach>
                        </trim>
                        <trim prefix="onlineCount=(case" suffix="ELSE onlineCount end),">
                            <foreach collection="data.dataList" item="item" index="index" separator="" >
                                <choose>
                                    <when test="(colPickMode==0 and item.containsKey('onlineCount')) or (colPickMode==1 and !item.containsKey('onlineCount'))">
                                        when a.id=#{item.id} then #{item.onlineCount}
                                    </when>
                                    <when test="(colPickMode==0 and item.containsKey('onlineCountIncrement')) or (colPickMode==1 and !item.containsKey('onlineCountIncrement'))">
                                        when a.id=#{item.id} then ifnull(a.onlineCount,0) + #{item.onlineCountIncrement}
                                    </when>
                                </choose>
                            </foreach>
                        </trim>
                        <trim prefix="offlineCount=(case" suffix="ELSE offlineCount end),">
                            <foreach collection="data.dataList" item="item" index="index" separator="" >
                                <choose>
                                    <when test="(colPickMode==0 and item.containsKey('offlineCount')) or (colPickMode==1 and !item.containsKey('offlineCount'))">
                                        when a.id=#{item.id} then #{item.offlineCount}
                                    </when>
                                    <when test="(colPickMode==0 and item.containsKey('offlineCountIncrement')) or (colPickMode==1 and !item.containsKey('offlineCountIncrement'))">
                                        when a.id=#{item.id} then ifnull(a.offlineCount,0) + #{item.offlineCountIncrement}
                                    </when>
                                </choose>
                            </foreach>
                        </trim>
                        <trim prefix="stopCount=(case" suffix="ELSE stopCount end),">
                            <foreach collection="data.dataList" item="item" index="index" separator="" >
                                <choose>
                                    <when test="(colPickMode==0 and item.containsKey('stopCount')) or (colPickMode==1 and !item.containsKey('stopCount'))">
                                        when a.id=#{item.id} then #{item.stopCount}
                                    </when>
                                    <when test="(colPickMode==0 and item.containsKey('stopCountIncrement')) or (colPickMode==1 and !item.containsKey('stopCountIncrement'))">
                                        when a.id=#{item.id} then ifnull(a.stopCount,0) + #{item.stopCountIncrement}
                                    </when>
                                </choose>
                            </foreach>
                        </trim>
                        <trim prefix="unActiveCount=(case" suffix="ELSE unActiveCount end),">
                            <foreach collection="data.dataList" item="item" index="index" separator="" >
                                <choose>
                                    <when test="(colPickMode==0 and item.containsKey('unActiveCount')) or (colPickMode==1 and !item.containsKey('unActiveCount'))">
                                        when a.id=#{item.id} then #{item.unActiveCount}
                                    </when>
                                    <when test="(colPickMode==0 and item.containsKey('unActiveCountIncrement')) or (colPickMode==1 and !item.containsKey('unActiveCountIncrement'))">
                                        when a.id=#{item.id} then ifnull(a.unActiveCount,0) + #{item.unActiveCountIncrement}
                                    </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="updateUserId=(case" suffix="ELSE updateUserId end),">
                            <foreach collection="data.dataList" item="item" index="index" separator="" >
                                <choose>
                                    <when test="(colPickMode==0 and item.containsKey('updateUserId')) or (colPickMode==1 and !item.containsKey('updateUserId'))">
                                        when a.id=#{item.id} then #{item.updateUserId}
                                    </when>
                                    <when test="(colPickMode==0 and item.containsKey('updateUserIdIncrement')) or (colPickMode==1 and !item.containsKey('updateUserIdIncrement'))">
                                        when a.id=#{item.id} then ifnull(a.updateUserId,0) + #{item.updateUserIdIncrement}
                                    </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="SitestatEntity-Map">
        select <include refid="_columns"/>
        from mortals_xhx_sitestat as a
        where a.id=#{condition.id}
    </select>
    <!-- 根据主健删除 -->
    <delete id="deleteByKey" parameterType="paramDto">
        delete a.* from mortals_xhx_sitestat as a where a.id=#{condition.id}
    </delete>
    <!-- 根据主健删除一批，针对单一主健有效 -->
    <delete id="deleteByKeys">
        delete from mortals_xhx_sitestat 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_xhx_sitestat as a
        <trim suffixOverrides="where" suffix="">
            where
            <trim prefixOverrides="and" prefix="">
                <include refid="_condition_"/>
            </trim>
        </trim>
    </delete>
    <!-- 获取列表 -->
    <select id="getList" parameterType="paramDto" resultMap="SitestatEntity-Map">
        select <include refid="_columns"/>
        from mortals_xhx_sitestat as a
        <trim suffixOverrides="where" suffix="">
            where
            <trim prefixOverrides="and" prefix="">
                <include refid="_condition_"/>
            </trim>
        </trim>
        <include refid="_orderCols_"/>
    </select>



    <!-- 获取 -->
    <select id="getListCount" parameterType="paramDto" resultType="int">
        select count(1)
        from mortals_xhx_sitestat 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('siteId')">
                <if test="conditionParamRef.siteId != null ">
                    ${_conditionType_} a.siteId = #{${_conditionParam_}.siteId}
                </if>
                <if test="conditionParamRef.siteId == null">
                    ${_conditionType_} a.siteId is null
                </if>
            </if>
            <if test="conditionParamRef.containsKey('siteIdList')">
                ${_conditionType_} a.siteId in
                <foreach collection="conditionParamRef.siteIdList" open="(" close=")" index="index" item="item" separator=",">
                    #{item}
                </foreach>
            </if>
            <if test="conditionParamRef.containsKey('siteIdStart') and conditionParamRef.siteIdStart != null">
                ${_conditionType_} a.siteId <![CDATA[ >= ]]> #{${_conditionParam_}.siteIdStart}
            </if>
            <if test="conditionParamRef.containsKey('siteIdEnd') and conditionParamRef.siteIdEnd != null">
                ${_conditionType_} a.siteId <![CDATA[ <= ]]> #{${_conditionParam_}.siteIdEnd}
            </if>


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

            <if test="conditionParamRef.containsKey('siteName')">
                <if test="conditionParamRef.siteName != null and conditionParamRef.siteName != ''">
                    ${_conditionType_} a.siteName like #{${_conditionParam_}.siteName}
                </if>
                <if test="conditionParamRef.siteName == null">
                    ${_conditionType_} a.siteName is null
                </if>
            </if>
            <if test="conditionParamRef.containsKey('siteNameList')">
                ${_conditionType_} a.siteName in
                <foreach collection="conditionParamRef.siteNameList" open="(" close=")" index="index" item="item" separator=",">
                    #{item}
                </foreach>
            </if>
            <if test="conditionParamRef.containsKey('deviceTotal')">
                <if test="conditionParamRef.deviceTotal != null ">
                    ${_conditionType_} a.deviceTotal = #{${_conditionParam_}.deviceTotal}
                </if>
                <if test="conditionParamRef.deviceTotal == null">
                    ${_conditionType_} a.deviceTotal is null
                </if>
            </if>
            <if test="conditionParamRef.containsKey('deviceTotalList')">
                ${_conditionType_} a.deviceTotal in
                <foreach collection="conditionParamRef.deviceTotalList" open="(" close=")" index="index" item="item" separator=",">
                    #{item}
                </foreach>
            </if>
            <if test="conditionParamRef.containsKey('deviceTotalStart') and conditionParamRef.deviceTotalStart != null">
                ${_conditionType_} a.deviceTotal <![CDATA[ >= ]]> #{${_conditionParam_}.deviceTotalStart}
            </if>
            <if test="conditionParamRef.containsKey('deviceTotalEnd') and conditionParamRef.deviceTotalEnd != null">
                ${_conditionType_} a.deviceTotal <![CDATA[ <= ]]> #{${_conditionParam_}.deviceTotalEnd}
            </if>

            <if test="conditionParamRef.containsKey('onlineCount')">
                <if test="conditionParamRef.onlineCount != null ">
                    ${_conditionType_} a.onlineCount = #{${_conditionParam_}.onlineCount}
                </if>
                <if test="conditionParamRef.onlineCount == null">
                    ${_conditionType_} a.onlineCount is null
                </if>
            </if>
            <if test="conditionParamRef.containsKey('onlineCountList')">
                ${_conditionType_} a.onlineCount in
                <foreach collection="conditionParamRef.onlineCountList" open="(" close=")" index="index" item="item" separator=",">
                    #{item}
                </foreach>
            </if>
            <if test="conditionParamRef.containsKey('onlineCountStart') and conditionParamRef.onlineCountStart != null">
                ${_conditionType_} a.onlineCount <![CDATA[ >= ]]> #{${_conditionParam_}.onlineCountStart}
            </if>
            <if test="conditionParamRef.containsKey('onlineCountEnd') and conditionParamRef.onlineCountEnd != null">
                ${_conditionType_} a.onlineCount <![CDATA[ <= ]]> #{${_conditionParam_}.onlineCountEnd}
            </if>

            <if test="conditionParamRef.containsKey('offlineCount')">
                <if test="conditionParamRef.offlineCount != null ">
                    ${_conditionType_} a.offlineCount = #{${_conditionParam_}.offlineCount}
                </if>
                <if test="conditionParamRef.offlineCount == null">
                    ${_conditionType_} a.offlineCount is null
                </if>
            </if>
            <if test="conditionParamRef.containsKey('offlineCountList')">
                ${_conditionType_} a.offlineCount in
                <foreach collection="conditionParamRef.offlineCountList" open="(" close=")" index="index" item="item" separator=",">
                    #{item}
                </foreach>
            </if>
            <if test="conditionParamRef.containsKey('offlineCountStart') and conditionParamRef.offlineCountStart != null">
                ${_conditionType_} a.offlineCount <![CDATA[ >= ]]> #{${_conditionParam_}.offlineCountStart}
            </if>
            <if test="conditionParamRef.containsKey('offlineCountEnd') and conditionParamRef.offlineCountEnd != null">
                ${_conditionType_} a.offlineCount <![CDATA[ <= ]]> #{${_conditionParam_}.offlineCountEnd}
            </if>

            <if test="conditionParamRef.containsKey('stopCount')">
                <if test="conditionParamRef.stopCount != null ">
                    ${_conditionType_} a.stopCount = #{${_conditionParam_}.stopCount}
                </if>
                <if test="conditionParamRef.stopCount == null">
                    ${_conditionType_} a.stopCount is null
                </if>
            </if>
            <if test="conditionParamRef.containsKey('stopCountList')">
                ${_conditionType_} a.stopCount in
                <foreach collection="conditionParamRef.stopCountList" open="(" close=")" index="index" item="item" separator=",">
                    #{item}
                </foreach>
            </if>
            <if test="conditionParamRef.containsKey('stopCountStart') and conditionParamRef.stopCountStart != null">
                ${_conditionType_} a.stopCount <![CDATA[ >= ]]> #{${_conditionParam_}.stopCountStart}
            </if>
            <if test="conditionParamRef.containsKey('stopCountEnd') and conditionParamRef.stopCountEnd != null">
                ${_conditionType_} a.stopCount <![CDATA[ <= ]]> #{${_conditionParam_}.stopCountEnd}
            </if>

            <if test="conditionParamRef.containsKey('unActiveCount')">
                <if test="conditionParamRef.unActiveCount != null ">
                    ${_conditionType_} a.unActiveCount = #{${_conditionParam_}.unActiveCount}
                </if>
                <if test="conditionParamRef.unActiveCount == null">
                    ${_conditionType_} a.unActiveCount is null
                </if>
            </if>
            <if test="conditionParamRef.containsKey('unActiveCountList')">
                ${_conditionType_} a.unActiveCount in
                <foreach collection="conditionParamRef.unActiveCountList" open="(" close=")" index="index" item="item" separator=",">
                    #{item}
                </foreach>
            </if>
            <if test="conditionParamRef.containsKey('unActiveCountStart') and conditionParamRef.unActiveCountStart != null">
                ${_conditionType_} a.unActiveCount <![CDATA[ >= ]]> #{${_conditionParam_}.unActiveCountStart}
            </if>
            <if test="conditionParamRef.containsKey('unActiveCountEnd') and conditionParamRef.unActiveCountEnd != null">
                ${_conditionType_} a.unActiveCount <![CDATA[ <= ]]> #{${_conditionParam_}.unActiveCountEnd}
            </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('updateUserId')">
                <if test="conditionParamRef.updateUserId != null ">
                    ${_conditionType_} a.updateUserId = #{${_conditionParam_}.updateUserId}
                </if>
                <if test="conditionParamRef.updateUserId == null">
                    ${_conditionType_} a.updateUserId is null
                </if>
            </if>
            <if test="conditionParamRef.containsKey('updateUserIdList')">
                ${_conditionType_} a.updateUserId in
                <foreach collection="conditionParamRef.updateUserIdList" open="(" close=")" index="index" item="item" separator=",">
                    #{item}
                </foreach>
            </if>
            <if test="conditionParamRef.containsKey('updateUserIdStart') and conditionParamRef.updateUserIdStart != null">
                ${_conditionType_} a.updateUserId <![CDATA[ >= ]]> #{${_conditionParam_}.updateUserIdStart}
            </if>
            <if test="conditionParamRef.containsKey('updateUserIdEnd') and conditionParamRef.updateUserIdEnd != null">
                ${_conditionType_} a.updateUserId <![CDATA[ <= ]]> #{${_conditionParam_}.updateUserIdEnd}
            </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('siteId')">
                        a.siteId
                        <if test='orderCol.siteId != null and "DESC".equalsIgnoreCase(orderCol.siteId)'>DESC</if>
                        ,
                    </if>
                    <if test="orderCol.containsKey('siteCode')">
                        a.siteCode
                        <if test='orderCol.siteCode != null and "DESC".equalsIgnoreCase(orderCol.siteCode)'>DESC</if>
                        ,
                    </if>
                    <if test="orderCol.containsKey('siteName')">
                        a.siteName
                        <if test='orderCol.siteName != null and "DESC".equalsIgnoreCase(orderCol.siteName)'>DESC</if>
                        ,
                    </if>
                    <if test="orderCol.containsKey('deviceTotal')">
                        a.deviceTotal
                        <if test='orderCol.deviceTotal != null and "DESC".equalsIgnoreCase(orderCol.deviceTotal)'>DESC</if>
                        ,
                    </if>
                    <if test="orderCol.containsKey('onlineCount')">
                        a.onlineCount
                        <if test='orderCol.onlineCount != null and "DESC".equalsIgnoreCase(orderCol.onlineCount)'>DESC</if>
                        ,
                    </if>
                    <if test="orderCol.containsKey('offlineCount')">
                        a.offlineCount
                        <if test='orderCol.offlineCount != null and "DESC".equalsIgnoreCase(orderCol.offlineCount)'>DESC</if>
                        ,
                    </if>
                    <if test="orderCol.containsKey('stopCount')">
                        a.stopCount
                        <if test='orderCol.stopCount != null and "DESC".equalsIgnoreCase(orderCol.stopCount)'>DESC</if>
                        ,
                    </if>
                    <if test="orderCol.containsKey('unActiveCount')">
                        a.unActiveCount
                        <if test='orderCol.unActiveCount != null and "DESC".equalsIgnoreCase(orderCol.unActiveCount)'>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('updateUserId')">
                        a.updateUserId
                        <if test='orderCol.updateUserId != null and "DESC".equalsIgnoreCase(orderCol.updateUserId)'>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>