<?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.ruoyi.jarvis.mapper.TencentDocOperationLogMapper">
    
    <resultMap type="com.ruoyi.jarvis.domain.TencentDocOperationLog" id="TencentDocOperationLogResult">
        <id     property="id"                column="id"                />
        <result property="batchId"           column="batch_id"          />
        <result property="fileId"            column="file_id"           />
        <result property="sheetId"           column="sheet_id"          />
        <result property="operationType"     column="operation_type"    />
        <result property="orderNo"           column="order_no"          />
        <result property="targetRow"         column="target_row"        />
        <result property="logisticsLink"     column="logistics_link"    />
        <result property="operationStatus"   column="operation_status"  />
        <result property="errorMessage"      column="error_message"     />
        <result property="operator"          column="operator"          />
        <result property="createTime"        column="create_time"       />
        <result property="remark"            column="remark"            />
    </resultMap>

    <insert id="insertLog" parameterType="com.ruoyi.jarvis.domain.TencentDocOperationLog">
        insert into tencent_doc_operation_log
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="batchId != null">batch_id,</if>
            <if test="fileId != null">file_id,</if>
            <if test="sheetId != null">sheet_id,</if>
            <if test="operationType != null">operation_type,</if>
            <if test="orderNo != null">order_no,</if>
            <if test="targetRow != null">target_row,</if>
            <if test="logisticsLink != null">logistics_link,</if>
            <if test="operationStatus != null">operation_status,</if>
            <if test="errorMessage != null">error_message,</if>
            <if test="operator != null">operator,</if>
            <if test="remark != null">remark,</if>
            create_time
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="batchId != null">#{batchId},</if>
            <if test="fileId != null">#{fileId},</if>
            <if test="sheetId != null">#{sheetId},</if>
            <if test="operationType != null">#{operationType},</if>
            <if test="orderNo != null">#{orderNo},</if>
            <if test="targetRow != null">#{targetRow},</if>
            <if test="logisticsLink != null">#{logisticsLink},</if>
            <if test="operationStatus != null">#{operationStatus},</if>
            <if test="errorMessage != null">#{errorMessage},</if>
            <if test="operator != null">#{operator},</if>
            <if test="remark != null">#{remark},</if>
            now()
        </trim>
    </insert>

    <sql id="selectLogVo">
        select id, batch_id, file_id, sheet_id, operation_type, order_no, target_row, 
               logistics_link, operation_status, error_message, operator, 
               create_time, remark
        from tencent_doc_operation_log
    </sql>

    <select id="selectLogList" parameterType="com.ruoyi.jarvis.domain.TencentDocOperationLog" resultMap="TencentDocOperationLogResult">
        <include refid="selectLogVo"/>
        <where>
            <if test="fileId != null and fileId != ''">
                AND file_id = #{fileId}
            </if>
            <if test="sheetId != null and sheetId != ''">
                AND sheet_id = #{sheetId}
            </if>
            <if test="operationType != null and operationType != ''">
                AND operation_type = #{operationType}
            </if>
            <if test="orderNo != null and orderNo != ''">
                AND order_no = #{orderNo}
            </if>
            <if test="operationStatus != null and operationStatus != ''">
                AND operation_status = #{operationStatus}
            </if>
        </where>
        order by create_time desc
    </select>

    <select id="selectRecentLogs" resultMap="TencentDocOperationLogResult">
        <include refid="selectLogVo"/>
        <where>
            <if test="fileId != null and fileId != ''">
                AND file_id = #{fileId}
            </if>
        </where>
        order by create_time desc
        limit #{limit}
    </select>

    <select id="selectLogsByBatchId" resultMap="TencentDocOperationLogResult">
        <include refid="selectLogVo"/>
        WHERE batch_id = #{batchId}
        ORDER BY create_time ASC
    </select>

</mapper>

