<?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.access.dao.ibatis.AccessLogDaoImpl">

    <!-- 字段和属性映射 -->
    <resultMap type="AccessLogEntity" id="AccessLogEntity-Map">
        <id  property="id" column="id" />
        <result property="traceID" column="traceID" />
        <result property="pspanId" column="pspanId" />
        <result property="spanId" column="spanId" />
        <result property="appName" column="appName" />
        <result property="hostName" column="hostName" />
        <result property="targetServer" column="targetServer" />
        <result property="logLevel" column="logLevel" />
        <result property="requestIp" column="requestIp" />
        <result property="method" column="method" />
        <result property="ua" column="ua" />
        <result property="uri" column="uri" />
        <result property="requestData" column="requestData" />
        <result property="responseData" column="responseData" />
        <result property="logTime" column="logTime" />
        <result property="requestTime" column="requestTime" />
        <result property="responseTime" column="responseTime" />
        <result property="duration" column="duration" />
        <result property="createUserId" column="createUserId" />
        <result property="createTime" column="createTime" />
        <result property="schemaData" column="schemaData" />

    </resultMap>

    <update id="createTable" parameterType="paramDto">
        CREATE TABLE `${tableName}`(
        `id` bigint(20) NOT NULL    COMMENT '主键ID',
        `traceID` varchar(64)     COMMENT 'TraceId',
        `pspanId` int(9)     COMMENT '父服务调用id',
        `spanId` int(9)     COMMENT '当前服务跨度Id',
        `appName` varchar(64)     COMMENT '应用名称',
        `hostName` varchar(64)     COMMENT '实例IP',
        `targetServer` varchar(64)     COMMENT '目标服务',
        `logLevel` varchar(64)     COMMENT '日志等级',
        `requestIp` varchar(256)     COMMENT '请求者IP',
        `method` varchar(256)     COMMENT '请求方式',
        `ua` varchar(2048)     COMMENT '用户浏览器UA',
        `uri` varchar(64)     COMMENT '请求URI',
        `requestData` mediumtext     COMMENT '请求参数，json序列化',
        `responseData` mediumtext     COMMENT '响应结果,',
        `logTime` datetime NOT NULL    COMMENT '日志产生时间',
        `requestTime` datetime     COMMENT '请求时间',
        `responseTime` datetime     COMMENT '响应时间',
        `duration` bigint(20)     COMMENT '持续时间，单位毫秒',
        `createUserId` bigint(20) NOT NULL    COMMENT '创建用户',
        `createTime` datetime NOT NULL    COMMENT '创建时间',
        `schemaData` varchar(64)     COMMENT '协议',
        PRIMARY KEY  (`id`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='访问日志';
    </update>

    <!-- 表所有列 -->
    <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('traceID') or colPickMode == 1 and data.containsKey('traceID')))">
                a.traceID,
            </if>
            <if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('pspanId') or colPickMode == 1 and data.containsKey('pspanId')))">
                a.pspanId,
            </if>
            <if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('spanId') or colPickMode == 1 and data.containsKey('spanId')))">
                a.spanId,
            </if>
            <if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('appName') or colPickMode == 1 and data.containsKey('appName')))">
                a.appName,
            </if>
            <if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('hostName') or colPickMode == 1 and data.containsKey('hostName')))">
                a.hostName,
            </if>
            <if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('targetServer') or colPickMode == 1 and data.containsKey('targetServer')))">
                a.targetServer,
            </if>
            <if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('logLevel') or colPickMode == 1 and data.containsKey('logLevel')))">
                a.logLevel,
            </if>
            <if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('requestIp') or colPickMode == 1 and data.containsKey('requestIp')))">
                a.requestIp,
            </if>
            <if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('method') or colPickMode == 1 and data.containsKey('method')))">
                a.method,
            </if>
            <if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('ua') or colPickMode == 1 and data.containsKey('ua')))">
                a.ua,
            </if>
            <if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('uri') or colPickMode == 1 and data.containsKey('uri')))">
                a.uri,
            </if>
            <if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('requestData') or colPickMode == 1 and data.containsKey('requestData')))">
                a.requestData,
            </if>
            <if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('responseData') or colPickMode == 1 and data.containsKey('responseData')))">
                a.responseData,
            </if>
            <if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('logTime') or colPickMode == 1 and data.containsKey('logTime')))">
                a.logTime,
            </if>
            <if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('requestTime') or colPickMode == 1 and data.containsKey('requestTime')))">
                a.requestTime,
            </if>
            <if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('responseTime') or colPickMode == 1 and data.containsKey('responseTime')))">
                a.responseTime,
            </if>
            <if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('duration') or colPickMode == 1 and data.containsKey('duration')))">
                a.duration,
            </if>
            <if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('createUserId') or colPickMode == 1 and data.containsKey('createUserId')))">
                a.createUserId,
            </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('schemaData') or colPickMode == 1 and data.containsKey('schemaData')))">
                a.schemaData,
            </if>
        </trim>
    </sql>
    <!-- 新增 区分主键自增加还是业务插入 -->
    <insert id="insert" parameterType="AccessLogEntity" >
        insert into `${tableName}`
        (id,traceID,pspanId,spanId,appName,hostName,targetServer,logLevel,requestIp,method,ua,uri,requestData,responseData,logTime,requestTime,responseTime,duration,createUserId,createTime,schemaData)
        VALUES
        (#{id},#{traceID},#{pspanId},#{spanId},#{appName},#{hostName},#{targetServer},#{logLevel},#{requestIp},#{method},#{ua},#{uri},#{requestData},#{responseData},#{logTime},#{requestTime},#{responseTime},#{duration},#{createUserId},#{createTime},#{schemaData})
    </insert>

    <!-- 批量新增 -->
    <insert id="insertBatch" parameterType="paramDto">
        insert into `${tableName}`
        (id,traceID,pspanId,spanId,appName,hostName,targetServer,logLevel,requestIp,method,ua,uri,requestData,responseData,logTime,requestTime,responseTime,duration,createUserId,createTime,schemaData)
        VALUES
        <foreach collection="data.dataList" item="item" index="index" separator="," >
            (#{item.id},#{item.traceID},#{item.pspanId},#{item.spanId},#{item.appName},#{item.hostName},#{item.targetServer},#{item.logLevel},#{item.requestIp},#{item.method},#{item.ua},#{item.uri},#{item.requestData},#{item.responseData},#{item.logTime},#{item.requestTime},#{item.responseTime},#{item.duration},#{item.createUserId},#{item.createTime},#{item.schemaData})
        </foreach>
    </insert>


    <!-- 根据ParamDto更新 -->
    <update id="update" parameterType="paramDto">
        update `${tableName}` as a
        set
        <trim suffixOverrides="," suffix="">
            <if test="(colPickMode==0 and data.containsKey('traceID')) or (colPickMode==1 and !data.containsKey('traceID'))">
                a.traceID=#{data.traceID},
            </if>
            <if test="(colPickMode==0 and data.containsKey('pspanId')) or (colPickMode==1 and !data.containsKey('pspanId'))">
                a.pspanId=#{data.pspanId},
            </if>
            <if test="(colPickMode==0 and data.containsKey('pspanIdIncrement')) or (colPickMode==1 and !data.containsKey('pspanIdIncrement'))">
                a.pspanId=ifnull(a.pspanId,0) + #{data.pspanIdIncrement},
            </if>
            <if test="(colPickMode==0 and data.containsKey('spanId')) or (colPickMode==1 and !data.containsKey('spanId'))">
                a.spanId=#{data.spanId},
            </if>
            <if test="(colPickMode==0 and data.containsKey('spanIdIncrement')) or (colPickMode==1 and !data.containsKey('spanIdIncrement'))">
                a.spanId=ifnull(a.spanId,0) + #{data.spanIdIncrement},
            </if>
            <if test="(colPickMode==0 and data.containsKey('appName')) or (colPickMode==1 and !data.containsKey('appName'))">
                a.appName=#{data.appName},
            </if>
            <if test="(colPickMode==0 and data.containsKey('hostName')) or (colPickMode==1 and !data.containsKey('hostName'))">
                a.hostName=#{data.hostName},
            </if>
            <if test="(colPickMode==0 and data.containsKey('targetServer')) or (colPickMode==1 and !data.containsKey('targetServer'))">
                a.targetServer=#{data.targetServer},
            </if>
            <if test="(colPickMode==0 and data.containsKey('logLevel')) or (colPickMode==1 and !data.containsKey('logLevel'))">
                a.logLevel=#{data.logLevel},
            </if>
            <if test="(colPickMode==0 and data.containsKey('requestIp')) or (colPickMode==1 and !data.containsKey('requestIp'))">
                a.requestIp=#{data.requestIp},
            </if>
            <if test="(colPickMode==0 and data.containsKey('method')) or (colPickMode==1 and !data.containsKey('method'))">
                a.method=#{data.method},
            </if>
            <if test="(colPickMode==0 and data.containsKey('ua')) or (colPickMode==1 and !data.containsKey('ua'))">
                a.ua=#{data.ua},
            </if>
            <if test="(colPickMode==0 and data.containsKey('uri')) or (colPickMode==1 and !data.containsKey('uri'))">
                a.uri=#{data.uri},
            </if>
            <if test="(colPickMode==0 and data.containsKey('requestData')) or (colPickMode==1 and !data.containsKey('requestData'))">
                a.requestData=#{data.requestData},
            </if>
            <if test="(colPickMode==0 and data.containsKey('responseData')) or (colPickMode==1 and !data.containsKey('responseData'))">
                a.responseData=#{data.responseData},
            </if>
            <if test="(colPickMode==0 and data.containsKey('logTime')) or (colPickMode==1 and !data.containsKey('logTime'))">
                a.logTime=#{data.logTime},
            </if>
            <if test="(colPickMode==0 and data.containsKey('requestTime')) or (colPickMode==1 and !data.containsKey('requestTime'))">
                a.requestTime=#{data.requestTime},
            </if>
            <if test="(colPickMode==0 and data.containsKey('responseTime')) or (colPickMode==1 and !data.containsKey('responseTime'))">
                a.responseTime=#{data.responseTime},
            </if>
            <if test="(colPickMode==0 and data.containsKey('duration')) or (colPickMode==1 and !data.containsKey('duration'))">
                a.duration=#{data.duration},
            </if>
            <if test="(colPickMode==0 and data.containsKey('durationIncrement')) or (colPickMode==1 and !data.containsKey('durationIncrement'))">
                a.duration=ifnull(a.duration,0) + #{data.durationIncrement},
            </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('createTime')) or (colPickMode==1 and !data.containsKey('createTime'))">
                a.createTime=#{data.createTime},
            </if>
            <if test="(colPickMode==0 and data.containsKey('schemaData')) or (colPickMode==1 and !data.containsKey('schemaData'))">
                a.schemaData=#{data.schemaData},
            </if>
        </trim>
        <trim suffixOverrides="where" suffix="">
            where
            <trim prefixOverrides="and" prefix="">
                <include refid="_condition_"/>
            </trim>
        </trim>
    </update>
    <!-- 批量更新 -->
    <update id="updateBatch" parameterType="paramDto">
        update `${tableName}` as a
        <trim prefix="set" suffixOverrides=",">
            <trim prefix="traceID=(case" suffix="ELSE traceID end),">
                <foreach collection="data.dataList" item="item" index="index" separator="" >
                    <if test="(colPickMode==0 and item.containsKey('traceID')) or (colPickMode==1 and !item.containsKey('traceID'))">
                        when a.id=#{item.id} then #{item.traceID}
                    </if>
                </foreach>
            </trim>
            <trim prefix="pspanId=(case" suffix="ELSE pspanId end),">
                <foreach collection="data.dataList" item="item" index="index" separator="" >
                    <choose>
                        <when test="(colPickMode==0 and item.containsKey('pspanId')) or (colPickMode==1 and !item.containsKey('pspanId'))">
                            when a.id=#{item.id} then #{item.pspanId}
                        </when>
                        <when test="(colPickMode==0 and item.containsKey('pspanIdIncrement')) or (colPickMode==1 and !item.containsKey('pspanIdIncrement'))">
                            when a.id=#{item.id} then ifnull(a.pspanId,0) + #{item.pspanIdIncrement}
                        </when>
                    </choose>
                </foreach>
            </trim>
            <trim prefix="spanId=(case" suffix="ELSE spanId end),">
                <foreach collection="data.dataList" item="item" index="index" separator="" >
                    <choose>
                        <when test="(colPickMode==0 and item.containsKey('spanId')) or (colPickMode==1 and !item.containsKey('spanId'))">
                            when a.id=#{item.id} then #{item.spanId}
                        </when>
                        <when test="(colPickMode==0 and item.containsKey('spanIdIncrement')) or (colPickMode==1 and !item.containsKey('spanIdIncrement'))">
                            when a.id=#{item.id} then ifnull(a.spanId,0) + #{item.spanIdIncrement}
                        </when>
                    </choose>
                </foreach>
            </trim>
            <trim prefix="appName=(case" suffix="ELSE appName end),">
                <foreach collection="data.dataList" item="item" index="index" separator="" >
                    <if test="(colPickMode==0 and item.containsKey('appName')) or (colPickMode==1 and !item.containsKey('appName'))">
                        when a.id=#{item.id} then #{item.appName}
                    </if>
                </foreach>
            </trim>
            <trim prefix="hostName=(case" suffix="ELSE hostName end),">
                <foreach collection="data.dataList" item="item" index="index" separator="" >
                    <if test="(colPickMode==0 and item.containsKey('hostName')) or (colPickMode==1 and !item.containsKey('hostName'))">
                        when a.id=#{item.id} then #{item.hostName}
                    </if>
                </foreach>
            </trim>
            <trim prefix="targetServer=(case" suffix="ELSE targetServer end),">
                <foreach collection="data.dataList" item="item" index="index" separator="" >
                    <if test="(colPickMode==0 and item.containsKey('targetServer')) or (colPickMode==1 and !item.containsKey('targetServer'))">
                        when a.id=#{item.id} then #{item.targetServer}
                    </if>
                </foreach>
            </trim>
            <trim prefix="logLevel=(case" suffix="ELSE logLevel end),">
                <foreach collection="data.dataList" item="item" index="index" separator="" >
                    <if test="(colPickMode==0 and item.containsKey('logLevel')) or (colPickMode==1 and !item.containsKey('logLevel'))">
                        when a.id=#{item.id} then #{item.logLevel}
                    </if>
                </foreach>
            </trim>
            <trim prefix="requestIp=(case" suffix="ELSE requestIp end),">
                <foreach collection="data.dataList" item="item" index="index" separator="" >
                    <if test="(colPickMode==0 and item.containsKey('requestIp')) or (colPickMode==1 and !item.containsKey('requestIp'))">
                        when a.id=#{item.id} then #{item.requestIp}
                    </if>
                </foreach>
            </trim>
            <trim prefix="method=(case" suffix="ELSE method end),">
                <foreach collection="data.dataList" item="item" index="index" separator="" >
                    <if test="(colPickMode==0 and item.containsKey('method')) or (colPickMode==1 and !item.containsKey('method'))">
                        when a.id=#{item.id} then #{item.method}
                    </if>
                </foreach>
            </trim>
            <trim prefix="ua=(case" suffix="ELSE ua end),">
                <foreach collection="data.dataList" item="item" index="index" separator="" >
                    <if test="(colPickMode==0 and item.containsKey('ua')) or (colPickMode==1 and !item.containsKey('ua'))">
                        when a.id=#{item.id} then #{item.ua}
                    </if>
                </foreach>
            </trim>
            <trim prefix="uri=(case" suffix="ELSE uri end),">
                <foreach collection="data.dataList" item="item" index="index" separator="" >
                    <if test="(colPickMode==0 and item.containsKey('uri')) or (colPickMode==1 and !item.containsKey('uri'))">
                        when a.id=#{item.id} then #{item.uri}
                    </if>
                </foreach>
            </trim>
            <trim prefix="requestData=(case" suffix="ELSE requestData end),">
                <foreach collection="data.dataList" item="item" index="index" separator="" >
                    <if test="(colPickMode==0 and item.containsKey('requestData')) or (colPickMode==1 and !item.containsKey('requestData'))">
                        when a.id=#{item.id} then #{item.requestData}
                    </if>
                </foreach>
            </trim>
            <trim prefix="responseData=(case" suffix="ELSE responseData end),">
                <foreach collection="data.dataList" item="item" index="index" separator="" >
                    <if test="(colPickMode==0 and item.containsKey('responseData')) or (colPickMode==1 and !item.containsKey('responseData'))">
                        when a.id=#{item.id} then #{item.responseData}
                    </if>
                </foreach>
            </trim>
            <trim prefix="logTime=(case" suffix="ELSE logTime end),">
                <foreach collection="data.dataList" item="item" index="index" separator="" >
                    <if test="(colPickMode==0 and item.containsKey('logTime')) or (colPickMode==1 and !item.containsKey('logTime'))">
                        when a.id=#{item.id} then #{item.logTime}
                    </if>
                </foreach>
            </trim>
            <trim prefix="requestTime=(case" suffix="ELSE requestTime end),">
                <foreach collection="data.dataList" item="item" index="index" separator="" >
                    <if test="(colPickMode==0 and item.containsKey('requestTime')) or (colPickMode==1 and !item.containsKey('requestTime'))">
                        when a.id=#{item.id} then #{item.requestTime}
                    </if>
                </foreach>
            </trim>
            <trim prefix="responseTime=(case" suffix="ELSE responseTime end),">
                <foreach collection="data.dataList" item="item" index="index" separator="" >
                    <if test="(colPickMode==0 and item.containsKey('responseTime')) or (colPickMode==1 and !item.containsKey('responseTime'))">
                        when a.id=#{item.id} then #{item.responseTime}
                    </if>
                </foreach>
            </trim>
            <trim prefix="duration=(case" suffix="ELSE duration end),">
                <foreach collection="data.dataList" item="item" index="index" separator="" >
                    <choose>
                        <when test="(colPickMode==0 and item.containsKey('duration')) or (colPickMode==1 and !item.containsKey('duration'))">
                            when a.id=#{item.id} then #{item.duration}
                        </when>
                        <when test="(colPickMode==0 and item.containsKey('durationIncrement')) or (colPickMode==1 and !item.containsKey('durationIncrement'))">
                            when a.id=#{item.id} then ifnull(a.duration,0) + #{item.durationIncrement}
                        </when>
                    </choose>
                </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="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="schemaData=(case" suffix="ELSE schemaData end),">
                <foreach collection="data.dataList" item="item" index="index" separator="" >
                    <if test="(colPickMode==0 and item.containsKey('schemaData')) or (colPickMode==1 and !item.containsKey('schemaData'))">
                        when a.id=#{item.id} then #{item.schemaData}
                    </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="AccessLogEntity-Map">
        select <include refid="_columns"/>
        from `${tableName}` as a
        where a.id=#{condition.id}
    </select>
    <!-- 根据主健删除 -->
    <delete id="deleteByKey" parameterType="paramDto">
        delete a.* from `${tableName}` as a where a.id=#{condition.id}
    </delete>
    <!-- 根据主健删除一批，针对单一主健有效 -->
    <delete id="deleteByKeys">
        delete from `${tableName}` 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 `${tableName}` as a
        <trim suffixOverrides="where" suffix="">
            where
            <trim prefixOverrides="and" prefix="">
                <include refid="_condition_"/>
            </trim>
        </trim>
    </delete>
    <!-- 获取列表 -->
    <select id="getList" parameterType="paramDto" resultMap="AccessLogEntity-Map">
        select <include refid="_columns"/>
        from `${tableName}` 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 `${tableName}` 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('traceID')">
            <if test="conditionParamRef.traceID != null and conditionParamRef.traceID != ''">
                ${_conditionType_} a.traceID like #{${_conditionParam_}.traceID}
            </if>
            <if test="conditionParamRef.traceID == null">
                ${_conditionType_} a.traceID is null
            </if>
        </if>
        <if test="conditionParamRef.containsKey('traceIDList')">
            ${_conditionType_} a.traceID in
            <foreach collection="conditionParamRef.traceIDList" open="(" close=")" index="index" item="item" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="conditionParamRef.containsKey('pspanId')">
            <if test="conditionParamRef.pspanId != null ">
                ${_conditionType_} a.pspanId = #{${_conditionParam_}.pspanId}
            </if>
            <if test="conditionParamRef.pspanId == null">
                ${_conditionType_} a.pspanId is null
            </if>
        </if>
        <if test="conditionParamRef.containsKey('pspanIdList')">
            ${_conditionType_} a.pspanId in
            <foreach collection="conditionParamRef.pspanIdList" open="(" close=")" index="index" item="item" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="conditionParamRef.containsKey('pspanIdStart') and conditionParamRef.pspanIdStart != null">
            ${_conditionType_} a.pspanId <![CDATA[ >= ]]> #{${_conditionParam_}.pspanIdStart}
        </if>
        <if test="conditionParamRef.containsKey('pspanIdEnd') and conditionParamRef.pspanIdEnd != null">
            ${_conditionType_} a.pspanId <![CDATA[ <= ]]> #{${_conditionParam_}.pspanIdEnd}
        </if>

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


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

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

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

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

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

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

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

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

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

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

        <if test="conditionParamRef.containsKey('logTime')">
            <if test="conditionParamRef.logTime != null ">
                ${_conditionType_} a.logTime = #{${_conditionParam_}.logTime}
            </if>
            <if test="conditionParamRef.logTime == null">
                ${_conditionType_} a.logTime is null
            </if>
        </if>
        <if test="conditionParamRef.containsKey('logTimeStart') and conditionParamRef.logTimeStart != null and conditionParamRef.logTimeStart!=''">
            ${_conditionType_} a.logTime <![CDATA[ >= ]]> STR_TO_DATE(left(concat(#{${_conditionParam_}.logTimeStart},' 00:00:00'),19),'%Y-%m-%d %k:%i:%s')
        </if>
        <if test="conditionParamRef.containsKey('logTimeEnd') and conditionParamRef.logTimeEnd != null and conditionParamRef.logTimeEnd!=''">
            ${_conditionType_} a.logTime <![CDATA[ <= ]]> STR_TO_DATE(left(concat(#{${_conditionParam_}.logTimeEnd},' 23:59:59'),19),'%Y-%m-%d %k:%i:%s')
        </if>

        <if test="conditionParamRef.containsKey('requestTime')">
            <if test="conditionParamRef.requestTime != null ">
                ${_conditionType_} a.requestTime = #{${_conditionParam_}.requestTime}
            </if>
            <if test="conditionParamRef.requestTime == null">
                ${_conditionType_} a.requestTime is null
            </if>
        </if>
        <if test="conditionParamRef.containsKey('requestTimeStart') and conditionParamRef.requestTimeStart != null and conditionParamRef.requestTimeStart!=''">
            ${_conditionType_} a.requestTime <![CDATA[ >= ]]> STR_TO_DATE(left(concat(#{${_conditionParam_}.requestTimeStart},' 00:00:00'),19),'%Y-%m-%d %k:%i:%s')
        </if>
        <if test="conditionParamRef.containsKey('requestTimeEnd') and conditionParamRef.requestTimeEnd != null and conditionParamRef.requestTimeEnd!=''">
            ${_conditionType_} a.requestTime <![CDATA[ <= ]]> STR_TO_DATE(left(concat(#{${_conditionParam_}.requestTimeEnd},' 23:59:59'),19),'%Y-%m-%d %k:%i:%s')
        </if>

        <if test="conditionParamRef.containsKey('responseTime')">
            <if test="conditionParamRef.responseTime != null ">
                ${_conditionType_} a.responseTime = #{${_conditionParam_}.responseTime}
            </if>
            <if test="conditionParamRef.responseTime == null">
                ${_conditionType_} a.responseTime is null
            </if>
        </if>
        <if test="conditionParamRef.containsKey('responseTimeStart') and conditionParamRef.responseTimeStart != null and conditionParamRef.responseTimeStart!=''">
            ${_conditionType_} a.responseTime <![CDATA[ >= ]]> STR_TO_DATE(left(concat(#{${_conditionParam_}.responseTimeStart},' 00:00:00'),19),'%Y-%m-%d %k:%i:%s')
        </if>
        <if test="conditionParamRef.containsKey('responseTimeEnd') and conditionParamRef.responseTimeEnd != null and conditionParamRef.responseTimeEnd!=''">
            ${_conditionType_} a.responseTime <![CDATA[ <= ]]> STR_TO_DATE(left(concat(#{${_conditionParam_}.responseTimeEnd},' 23:59:59'),19),'%Y-%m-%d %k:%i:%s')
        </if>
        <if test="conditionParamRef.containsKey('duration')">
            <if test="conditionParamRef.duration != null ">
                ${_conditionType_} a.duration = #{${_conditionParam_}.duration}
            </if>
            <if test="conditionParamRef.duration == null">
                ${_conditionType_} a.duration is null
            </if>
        </if>
        <if test="conditionParamRef.containsKey('durationList')">
            ${_conditionType_} a.duration in
            <foreach collection="conditionParamRef.durationList" open="(" close=")" index="index" item="item" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="conditionParamRef.containsKey('durationStart') and conditionParamRef.durationStart != null">
            ${_conditionType_} a.duration <![CDATA[ >= ]]> #{${_conditionParam_}.durationStart}
        </if>
        <if test="conditionParamRef.containsKey('durationEnd') and conditionParamRef.durationEnd != null">
            ${_conditionType_} a.duration <![CDATA[ <= ]]> #{${_conditionParam_}.durationEnd}
        </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('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('schemaData')">
            <if test="conditionParamRef.schemaData != null and conditionParamRef.schemaData != ''">
                ${_conditionType_} a.schemaData like #{${_conditionParam_}.schemaData}
            </if>
            <if test="conditionParamRef.schemaData == null">
                ${_conditionType_} a.schemaData is null
            </if>
        </if>
        <if test="conditionParamRef.containsKey('schemaDataList')">
            ${_conditionType_} a.schemaData in
            <foreach collection="conditionParamRef.schemaDataList" open="(" close=")" index="index" item="item" separator=",">
                #{item}
            </foreach>
        </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('traceID')">
                    a.traceID
                    <if test='orderCol.traceID != null and "DESC".equalsIgnoreCase(orderCol.traceID)'>DESC</if>
                    ,
                </if>
                <if test="orderCol.containsKey('pspanId')">
                    a.pspanId
                    <if test='orderCol.pspanId != null and "DESC".equalsIgnoreCase(orderCol.pspanId)'>DESC</if>
                    ,
                </if>
                <if test="orderCol.containsKey('spanId')">
                    a.spanId
                    <if test='orderCol.spanId != null and "DESC".equalsIgnoreCase(orderCol.spanId)'>DESC</if>
                    ,
                </if>
                <if test="orderCol.containsKey('appName')">
                    a.appName
                    <if test='orderCol.appName != null and "DESC".equalsIgnoreCase(orderCol.appName)'>DESC</if>
                    ,
                </if>
                <if test="orderCol.containsKey('hostName')">
                    a.hostName
                    <if test='orderCol.hostName != null and "DESC".equalsIgnoreCase(orderCol.hostName)'>DESC</if>
                    ,
                </if>
                <if test="orderCol.containsKey('targetServer')">
                    a.targetServer
                    <if test='orderCol.targetServer != null and "DESC".equalsIgnoreCase(orderCol.targetServer)'>DESC</if>
                    ,
                </if>
                <if test="orderCol.containsKey('logLevel')">
                    a.logLevel
                    <if test='orderCol.logLevel != null and "DESC".equalsIgnoreCase(orderCol.logLevel)'>DESC</if>
                    ,
                </if>
                <if test="orderCol.containsKey('requestIp')">
                    a.requestIp
                    <if test='orderCol.requestIp != null and "DESC".equalsIgnoreCase(orderCol.requestIp)'>DESC</if>
                    ,
                </if>
                <if test="orderCol.containsKey('method')">
                    a.method
                    <if test='orderCol.method != null and "DESC".equalsIgnoreCase(orderCol.method)'>DESC</if>
                    ,
                </if>
                <if test="orderCol.containsKey('ua')">
                    a.ua
                    <if test='orderCol.ua != null and "DESC".equalsIgnoreCase(orderCol.ua)'>DESC</if>
                    ,
                </if>
                <if test="orderCol.containsKey('uri')">
                    a.uri
                    <if test='orderCol.uri != null and "DESC".equalsIgnoreCase(orderCol.uri)'>DESC</if>
                    ,
                </if>
                <if test="orderCol.containsKey('requestData')">
                    a.requestData
                    <if test='orderCol.requestData != null and "DESC".equalsIgnoreCase(orderCol.requestData)'>DESC</if>
                    ,
                </if>
                <if test="orderCol.containsKey('responseData')">
                    a.responseData
                    <if test='orderCol.responseData != null and "DESC".equalsIgnoreCase(orderCol.responseData)'>DESC</if>
                    ,
                </if>
                <if test="orderCol.containsKey('logTime')">
                    a.logTime
                    <if test='orderCol.logTime != null and "DESC".equalsIgnoreCase(orderCol.logTime)'>DESC</if>
                    ,
                </if>
                <if test="orderCol.containsKey('requestTime')">
                    a.requestTime
                    <if test='orderCol.requestTime != null and "DESC".equalsIgnoreCase(orderCol.requestTime)'>DESC</if>
                    ,
                </if>
                <if test="orderCol.containsKey('responseTime')">
                    a.responseTime
                    <if test='orderCol.responseTime != null and "DESC".equalsIgnoreCase(orderCol.responseTime)'>DESC</if>
                    ,
                </if>
                <if test="orderCol.containsKey('duration')">
                    a.duration
                    <if test='orderCol.duration != null and "DESC".equalsIgnoreCase(orderCol.duration)'>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('createTime')">
                    a.createTime
                    <if test='orderCol.createTime != null and "DESC".equalsIgnoreCase(orderCol.createTime)'>DESC</if>
                    ,
                </if>
                <if test="orderCol.containsKey('schemaData')">
                    a.schemaData
                    <if test='orderCol.schemaData != null and "DESC".equalsIgnoreCase(orderCol.schemaData)'>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>