<?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.dxhy.core.dao.TDxExcelExportlogDao">

    <resultMap id="BaseResultMap" type="com.dxhy.api.model.excelExport.TDxExcelExportlog">
        <result column="id" property="id"/>
        <result column="conditions" property="conditions"/>
        <result column="service_type" property="serviceType"/>
        <result column="user_account" property="userAccount"/>
        <result column="db_name" property="dbName"/>
        <result column="create_date" property="createDate"/>
        <result column="gf_tax_no" property="gfTaxNo"/>
        <result column="user_name" property="userName"/>
    </resultMap>

    <delete id="deleteMessagecontrol" databaseId="mysql">
        delete
        from sys_messagecontrol
        where create_time &lt;= date_sub(curdate(), INTERVAL 2 MONTH)
    </delete>
    <delete id="deleteMessagecontrol" databaseId="oracle">
        delete
        from sys_messagecontrol
        where create_time &lt;= add_months(sysdate, -2)
    </delete>
    <select id="selectExportLogToDel" resultType="com.dxhy.api.model.excelExport.TDxExcelExportlog" databaseId="mysql">
        select *
        from t_dx_excel_exportlog
        where create_date &lt;= date_sub(curdate(), INTERVAL 2 MONTH)
    </select>
    <select id="selectExportLogToDel" resultType="com.dxhy.api.model.excelExport.TDxExcelExportlog" databaseId="oracle">
        select *
        from t_dx_excel_exportlog
        where create_date &lt;= add_months(sysdate, -2)
    </select>
    <select id="selectNeedExportLog" resultMap="BaseResultMap" databaseId="mysql">
        SELECT t.id,
               t.conditions,
               t.service_type,
               t.user_account,
               t.db_name,
               t.create_date,
               t.gf_tax_no,
               t.user_name
        FROM t_dx_excel_exportlog t
        WHERE t.export_status = 1 AND t.start_date is null and t.user_name = #{userName}
           or (t.export_status = 1 and TIMESTAMPDIFF(HOUR, NOW(), t.start_date) > 6)
    </select>
    <select id="selectNeedExportLog" resultMap="BaseResultMap" databaseId="oracle">
        SELECT t.id,
               t.conditions,
               t.service_type,
               t.user_account,
               t.db_name,
               t.create_date,
               t.gf_tax_no,
               t.user_name
        FROM t_dx_excel_exportlog t
        WHERE t.export_status = 1 AND t.start_date is null and t.user_name = #{userName}
           or (t.export_status = 1 and (sysdate - t.start_date) * 24 > 6)
    </select>

    <update id="lockExportlog">
        update t_dx_excel_exportlog t
        set t.export_status = 1
        where t.export_status = '0'
          and t.user_name = #{userName}
    </update>

    <update id="updateStart" databaseId="mysql">
        update t_dx_excel_exportlog t
        set t.start_date = now()
        where t.id = #{id}
    </update>
    <update id="updateStart" databaseId="oracle">
        update t_dx_excel_exportlog t
        set t.start_date = sysdate
        where t.id = #{id}
    </update>

    <update id="updateSucc" parameterType="java.util.Map" databaseId="mysql">
        update t_dx_excel_exportlog t
        set t.export_status = '2',
            t.end_date      = now(),
            t.filepath      = #{excelFile}
        where t.id = #{id}
    </update>
    <update id="updateSucc" parameterType="java.util.Map" databaseId="oracle">
        update t_dx_excel_exportlog t
        set t.export_status = '2',
            t.end_date      = sysdate,
            t.filepath      = #{excelFile}
        where t.id = #{id}
    </update>

    <update id="updateFail" parameterType="java.util.Map" databaseId="mysql">
        update t_dx_excel_exportlog t
        set t.export_status = '3',
            t.end_date      = now(),
            t.errmsg        = #{errmsg}
        where t.id = #{id}
    </update>
    <update id="updateFail" parameterType="java.util.Map" databaseId="oracle">
        update t_dx_excel_exportlog t
        set t.export_status = '3',
            t.end_date      = sysdate,
            t.errmsg        = #{errmsg}
        where t.id = #{id}
    </update>
</mapper>
