<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.engine.hrmelog.mapper.LocalElogAopDaoMapper">

    <insert id="insertElogContext">
        insert into ${tableName} (id, uuid, log_date, tenant_key, modulename, functionName, operatetypename,
                                  log_operator, operatorname, targetid, targetname, interfacename, operatetype,
                                  operatedesc,
                                  params, clientIp, groupnamelabel, redoservice, redocontext, cancelservice,
                                  cancelcontext, device, groupid,
                                  belongMainId, requestUrl, requestUri, totalRunTime, mainRunTime, log_result,
                                  fromTerminal, resultDesc, old_content,
                                  link_type, link_id, old_link_id, create_time, update_time, delete_type, creator
                                      ${cusColumns})
        values (#{logContent.id}, #{logContent.uuid}, #{logContent.date},
                #{logContent.tenant_key}, #{logContent.moduleName}, #{logContent.functionName},
                #{logContent.operateTypeName}, #{logContent.logOperator}, #{logContent.operatorName},
                #{logContent.logTargetid}
                   , #{logContent.targetName}, #{logContent.interfaceName}, #{logContent.operateType},
                #{logContent.operatedesc},
                #{logContent.paramsStr}, #{logContent.clientIp}, #{logContent.groupNameLabel},
                #{logContent.redoService},
                #{logContent.redoContextStr}, #{logContent.cancelService}, #{logContent.cancelContextStr},
                #{logContent.device}, #{logContent.groupId},
                #{logContent.belongMainId}, #{logContent.requestUrl}, #{logContent.requestUri},
                #{logContent.totalRunTime}, #{logContent.mainRunTime}
                   , #{logContent.result}, #{logContent.fromTerminal}, #{logContent.resultDesc},
                #{logContent.old_content}, #{logContent.link_type}
                   , #{logContent.link_id}, #{logContent.old_link_id}, #{logContent.create_time},
                #{logContent.update_time}, #{logContent.delete_type}, #{logContent.logOperator}
         ${cusValus})
    </insert>

    <insert id="insertElogDetail">
        insert into ${detailTableName} (id, mainid, uuid, tablename, fieldname, newvalue, oldvalue,
                                        fielddesc, showorder, dataid, belongDataid, isDetail, tenant_key, creator,
                                        newRealValue, oldRealValue, tableNameDesc,
                                        tableNameLabelId, fieldNameLabelId, create_time, update_time
                                            ${cusColumns})
        values (#{detailContext.id}, #{mainid}, #{detailContext.uuid}, #{detailContext.tableName},
                #{detailContext.fieldName}, #{detailContext.newValue},
                #{detailContext.oldValue}, #{detailContext.fieldDesc}, #{detailContext.showorder},
                #{detailContext.dataid},
                #{detailContext.belongDataid}, #{detailContext.isDetail}, #{detailContext.tenant_key},
                #{detailContext.creator}, #{detailContext.newRealValue}
                   , #{detailContext.oldRealValue}, #{detailContext.tableNameDesc}, #{detailContext.tableNameLabelId},
                #{detailContext.fieldNameLabelId}, #{detailContext.create_time}, #{detailContext.update_time}
          ${cusValus})
    </insert>
    <insert id="batchInsertDetail">
        ${sql}
    </insert>


    <select id="queryElogContextById" resultType="java.lang.Integer">
        select 1
        from ${tableName}
        where id = #{id}
    </select>


    <insert id="insertElogDetailPrepared">
        insert into ${tablename} (id, mainid, uuid, tablename, fieldname, newvalue, oldvalue,
        fielddesc, showorder, dataid, belongDataid, isDetail, tenant_key,creator, newRealValue,
        oldRealValue,tableNameDesc,
        tableNameLabelId,fieldNameLabelId, create_time, update_time,delete_type)
        values
        <foreach collection="list" item="detailContext" separator=",">
            ( #{detailContext.id},#{mainid}, #{detailContext.uuid}, #{detailContext.tableName},
            #{detailContext.fieldName}, #{detailContext.newValue},
            #{detailContext.oldValue}, #{detailContext.fieldDesc}, #{detailContext.showorder}, #{detailContext.dataid},
            #{detailContext.belongDataid}, #{detailContext.isDetail},
            #{detailContext.tenant_key},#{detailContext.creator}, #{detailContext.newRealValue}
            , #{detailContext.oldRealValue}, #{detailContext.tableNameDesc}, #{detailContext.tableNameLabelId},
            #{detailContext.fieldNameLabelId}
            , #{detailContext.create_time}, #{detailContext.update_time}, #{detailContext.delete_type})
        </foreach>
    </insert>

    <insert id="insertElogDetailPrepared" databaseId="sqlserver">
        <foreach collection="list" item="detailContext" separator=";">
            insert into ${tablename} (id, mainid, uuid, tablename, fieldname, newvalue, oldvalue,
            fielddesc, showorder, dataid, belongDataid, isDetail, tenant_key,creator, newRealValue,
            oldRealValue,tableNameDesc,
            tableNameLabelId,fieldNameLabelId, create_time, update_time,delete_type)
            VALUES
            (
            #{detailContext.id},#{mainid}, #{detailContext.uuid}, #{detailContext.tableName},
            #{detailContext.fieldName}, #{detailContext.newValue},
            #{detailContext.oldValue}, #{detailContext.fieldDesc}, #{detailContext.showorder}, #{detailContext.dataid},
            #{detailContext.belongDataid}, #{detailContext.isDetail},
            #{detailContext.tenant_key},#{detailContext.creator}, #{detailContext.newRealValue}
            , #{detailContext.oldRealValue}, #{detailContext.tableNameDesc}, #{detailContext.tableNameLabelId},
            #{detailContext.fieldNameLabelId}
            , #{detailContext.create_time}, #{detailContext.update_time}, #{detailContext.delete_type}
            )
        </foreach>
    </insert>

    <insert id="insertElogDetailPreparedHasCustonInfo">
        insert into ${tablename} (id, mainid, uuid, tablename, fieldname, newvalue, oldvalue,
        fielddesc, showorder, dataid, belongDataid, isDetail, tenant_key,creator, newRealValue,
        oldRealValue,tableNameDesc,
        tableNameLabelId,fieldNameLabelId, create_time, update_time
        ${cusColumns})
        values
        <foreach collection="list" item="detailContext" separator=",">
            ( #{detailContext.id},#{mainid}, #{detailContext.uuid}, #{detailContext.tableName},
            #{detailContext.fieldName}, #{detailContext.newValue},
            #{detailContext.oldValue}, #{detailContext.fieldDesc}, #{detailContext.showorder}, #{detailContext.dataid},
            #{detailContext.belongDataid}, #{detailContext.isDetail},
            #{detailContext.tenant_key},#{detailContext.creator}, #{detailContext.newRealValue}
            , #{detailContext.oldRealValue}, #{detailContext.tableNameDesc}, #{detailContext.tableNameLabelId},
            #{detailContext.fieldNameLabelId}
            , #{detailContext.create_time}, #{detailContext.update_time}
            ${detailContext.cusValus})
        </foreach>
    </insert>

    <update id="rollBackElogById">
        update ${tableName}
        set delete_type = 3
        where id = #{id}
    </update>
    <update id="rollBackDetailElogByUUID">
        update ${tableName}
        set delete_type = 3
        where mainid = #{mainid}
    </update>

    <insert id="insertElogDetailPrepared" databaseId="oracle">
        insert into ${tablename} (id, mainid, uuid, tablename, fieldname, newvalue, oldvalue,
        fielddesc, showorder, dataid, belongDataid, isDetail, tenant_key,creator, newRealValue,
        oldRealValue,tableNameDesc,
        tableNameLabelId,fieldNameLabelId, create_time, update_time,delete_type)
        <foreach collection="list" item="detailContext" separator=" union all ">
            SELECT #{detailContext.id},#{mainid}, #{detailContext.uuid}, #{detailContext.tableName},
            #{detailContext.fieldName}, #{detailContext.newValue},
            #{detailContext.oldValue}, #{detailContext.fieldDesc}, #{detailContext.showorder}, #{detailContext.dataid},
            #{detailContext.belongDataid}, #{detailContext.isDetail},
            #{detailContext.tenant_key},#{detailContext.creator}, #{detailContext.newRealValue}
            , #{detailContext.oldRealValue}, #{detailContext.tableNameDesc}, #{detailContext.tableNameLabelId},
            #{detailContext.fieldNameLabelId}
            , #{detailContext.create_time}, #{detailContext.update_time}, #{detailContext.delete_type}
            FROM DUAL
        </foreach>
    </insert>

    <insert id="insertElogDetailPreparedHasCustonInfo" databaseId="oracle">
        insert into ${tablename} (id, mainid, uuid, tablename, fieldname, newvalue, oldvalue,
        fielddesc, showorder, dataid, belongDataid, isDetail, tenant_key,creator, newRealValue,
        oldRealValue,tableNameDesc,
        tableNameLabelId,fieldNameLabelId, create_time, update_time
        ${cusColumns})
        <foreach collection="list" item="detailContext" separator=" union all ">
            SELECT #{detailContext.id},#{mainid}, #{detailContext.uuid}, #{detailContext.tableName},
            #{detailContext.fieldName}, #{detailContext.newValue},
            #{detailContext.oldValue}, #{detailContext.fieldDesc}, #{detailContext.showorder}, #{detailContext.dataid},
            #{detailContext.belongDataid}, #{detailContext.isDetail},
            #{detailContext.tenant_key},#{detailContext.creator}, #{detailContext.newRealValue}
            , #{detailContext.oldRealValue}, #{detailContext.tableNameDesc}, #{detailContext.tableNameLabelId},
            #{detailContext.fieldNameLabelId}
            , #{detailContext.create_time}, #{detailContext.update_time}
            ${detailContext.cusValus}
            FROM DUAL
        </foreach>
    </insert>

</mapper>
