<?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="${domain}module.wsys.mpr.LogErrMapper">

    <sql id="table">"SYS_LOG_ERR"</sql>

    <sql id="entityColumnList">
        "ID","LOG_ERR_TYPE","LOG_TITLE","LOG_NOTE","LOG_ERR_RESULT","LOG_ATTR1","LOG_ATTR2","LOG_ATTR3","ROW_VERSION","IS_DELETED","CREATE_BY","CREATE_TIME","LAST_UPDATE_BY","LAST_UPDATE_TIME"
    </sql>

    <resultMap id="logErr" type="${domain}.module.wsys.ent.LogErr">
        <result column="ID" jdbcType="BIGINT" property="id"/>
        <result column="LOG_ERR_TYPE" jdbcType="VARCHAR" property="logErrType"/>
        <result column="LOG_TITLE" jdbcType="VARCHAR" property="logTitle"/>
        <result column="LOG_NOTE" jdbcType="VARCHAR" property="logNote"/>
        <result column="LOG_ERR_RESULT" jdbcType="VARCHAR" property="logErrResult"/>
        <result column="LOG_ATTR1" jdbcType="VARCHAR" property="logAttr1"/>
        <result column="LOG_ATTR2" jdbcType="VARCHAR" property="logAttr2"/>
        <result column="LOG_ATTR3" jdbcType="VARCHAR" property="logAttr3"/>
        <result column="ROW_VERSION" jdbcType="BIGINT" property="rowVersion"/>
        <result column="IS_DELETED" jdbcType="BIT" property="isDeleted"/>
        <result column="CREATE_BY" jdbcType="BIGINT" property="createBy"/>
        <result column="CREATE_TIME" jdbcType="TIMESTAMP" property="createTime"/>
        <result column="LAST_UPDATE_BY" jdbcType="BIGINT" property="lastUpdateBy"/>
        <result column="LAST_UPDATE_TIME" jdbcType="TIMESTAMP" property="lastUpdateTime"/>
    </resultMap>

    <insert id="insert">
        INSERT INTO
        <include refid="table"/>
        (
        <include refid="entityColumnList"/>
        )
        VALUES
        (
        ${r'#'}{request.id},
        ${r'#'}{request.logErrType,jdbcType=VARCHAR},
        ${r'#'}{request.logTitle,jdbcType=VARCHAR},
        ${r'#'}{request.logNote,jdbcType=VARCHAR},
        ${r'#'}{request.logErrResult,jdbcType=VARCHAR},
        ${r'#'}{request.logAttr1,jdbcType=VARCHAR},
        ${r'#'}{request.logAttr2,jdbcType=VARCHAR},
        ${r'#'}{request.logAttr3,jdbcType=VARCHAR},
        0,
        0,
        ${r'#'}{token.userId,jdbcType=NUMERIC},
        sysdate,
        NULL,
        NULL
        )
    </insert>

    <insert id="insertBatch">
        INSERT INTO
        <include refid="table"/>
        (
        <include refid="entityColumnList"/>
        )
        VALUES
        <foreach collection="list" item="item" index="index" separator="," open="(" close=")">
            ${r'#'}{item.id},
            ${r'#'}{item.logErrType,jdbcType=VARCHAR},
            ${r'#'}{item.logTitle,jdbcType=VARCHAR},
            ${r'#'}{item.logNote,jdbcType=VARCHAR},
            ${r'#'}{item.logErrResult,jdbcType=VARCHAR},
            ${r'#'}{item.logAttr1,jdbcType=VARCHAR},
            ${r'#'}{item.logAttr2,jdbcType=VARCHAR},
            ${r'#'}{item.logAttr3,jdbcType=VARCHAR},
            0,
            0,
            ${r'#'}{token.userId,jdbcType=NUMERIC},
            sysdate,
            NULL,
            NULL
        </foreach >
    </insert>

    <update id="delete">
        UPDATE
        <include refid="table"/>
        SET "IS_DELETED" = 1
        WHERE "IS_DELETED" = 0
        AND "ID" = ${r'#'}{id}
    </update>

    <update id="deleteBatch">
        UPDATE
        <include refid="table"/>
        SET "IS_DELETED" = 1
        WHERE "IS_DELETED" = 0
        AND "ID" IN
        <foreach collection="list" item="item" index="index" separator="," open="(" close=")">
            ${r'#'}{item}
        </foreach>
    </update>

    <update id="update">
        UPDATE
        <include refid="table"/>
        SET
        "LOG_ERR_TYPE" = ${r'#'}{request.logErrType,jdbcType=VARCHAR},
        "LOG_TITLE" = ${r'#'}{request.logTitle,jdbcType=VARCHAR},
        "LOG_NOTE" = ${r'#'}{request.logNote,jdbcType=VARCHAR},
        "LOG_ERR_RESULT" = ${r'#'}{request.logErrResult,jdbcType=VARCHAR},
        "LOG_ATTR1" = ${r'#'}{request.logAttr1,jdbcType=VARCHAR},
        "LOG_ATTR2" = ${r'#'}{request.logAttr2,jdbcType=VARCHAR},
        "LOG_ATTR3" = ${r'#'}{request.logAttr3,jdbcType=VARCHAR},
        "ROW_VERSION" = "ROW_VERSION" + 1,
        "LAST_UPDATE_BY" = ${r'#'}{token.userId},
        "LAST_UPDATE_TIME" = sysdate
        WHERE "IS_DELETED" = 0
        AND "ID" = ${r'#'}{request.id}
        AND "ROW_VERSION" = ${r'#'}{request.rowVersion}
    </update>

    <select id="find" resultMap="logErr">
        SELECT
        <include refid="entityColumnList"/>
        FROM
        <include refid="table"/>
        WHERE
        "IS_DELETED" = 0
        <if test="request.logErrType != null and request.logErrType != ''">
            AND "LOG_ERR_TYPE" = ${r'#'}{request.logErrType}
        </if>
        <if test="request.logTitle != null and request.logTitle != ''">
            AND "LOG_TITLE" = ${r'#'}{request.logTitle}
        </if>
        <if test="request.logErrResult != null and request.logErrResult != ''">
            AND "LOG_ERR_RESULT" = ${r'#'}{request.logErrResult}
        </if>
        <if test="request.startDate != null">
            AND "CREATE_TIME" &gt;= ${r"#"}{request.startDate}
        </if>
        <if test="request.endDate != null">
            AND "CREATE_TIME" &lt;= ${r"#"}{request.endDate}
        </if>
    </select>

    <select id="search" resultMap="logErr">
        SELECT
        <include refid="entityColumnList"/>
        FROM
        <include refid="table"/>
        WHERE
        "IS_DELETED" = 0
    </select>

    <select id="getById" resultMap="logErr">
        SELECT
        <include refid="entityColumnList"/>
        FROM
        <include refid="table"/>
        WHERE "IS_DELETED" = 0
        AND "ID" = ${r'#'}{id}
    </select>

    <select id="getByIds" resultMap="logErr">
        SELECT
        <include refid="entityColumnList"/>
        FROM
        <include refid="table"/>
        WHERE "IS_DELETED" = 0
        AND "ID" IN
        <foreach collection="list" item="item" index="index" separator="," open="(" close=")">
            ${r'#'}{item}
        </foreach>
    </select>
</mapper>