<?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.erp.dao.InvoiceImgDao">

    <sql id="query_column_sql">
        id,
        image,
        image_path,
        uuid,
        scan_id
    </sql>

    <!-- 保存扫描发票图片；若已存在，则更新 -->
    <insert id="saveImg" parameterType="com.dxhy.erp.entity.InvoiceImgSavePo"
            useGeneratedKeys="true" keyProperty="id" databaseId="mysql">
        INSERT INTO t_dx_invoice_img
        (image,
        image_path,
        scan_id,
        valid,
        create_date,
        update_date)
        VALUES (
        #{image},
        #{imagePath},
        #{scanId},
        1,
        now(),
        now())
        <!-- ON DUPLICATE KEY UPDATE update_date = now(),image_path =#{imagePath} -->
    </insert>
    <insert id="saveImg" parameterType="com.dxhy.erp.entity.InvoiceImgSavePo"
            useGeneratedKeys="true" keyProperty="id" databaseId="oracle">
        INSERT INTO t_dx_invoice_img
        (image,
        image_path,
        scan_id,
        valid,
        create_date,
        update_date)
        VALUES (
        #{image},
        #{imagePath},
        #{scanId},
        1,
        sysdate,
        sysdate)
        <!-- ON DUPLICATE KEY UPDATE update_date = now(),image_path =#{imagePath} -->
    </insert>
    <!-- 根据scanId查询 -->
    <select id="getImg" parameterType="java.lang.String"
            resultType="com.dxhy.erp.entity.InvoiceImgQueryVo">
        SELECT
        <include refid="query_column_sql"/>
        FROM t_dx_invoice_img
        WHERE scan_id = #{scanId}
    </select>
    <!-- 无用逻辑删除一条 -->
    <update id="deleteImg" parameterType="java.lang.String" databaseId="mysql">
        UPDATE t_dx_invoice_img
        SET valid       = 1,
            update_date = NOW()
        WHERE scan_id = #{scanId}
    </update>


    <update id="deleteImg" parameterType="java.lang.String" databaseId="oracle">
        UPDATE t_dx_invoice_img
        SET valid       = 1,
            update_date = sysdate
        WHERE scan_id = #{scanId}
    </update>
    <!-- 物理删除图片 -->
    <delete id="deleteInvoiceImg" parameterType="java.lang.String">
        DELETE
        FROM t_dx_invoice_img
        WHERE scan_id = #{scanId}
    </delete>
    <!-- 无用方法修改图片 -->
    <update id="updateInvoiceImg" parameterType="java.lang.String" databaseId="mysql">
        UPDATE t_dx_invoice_img
        SET UUID        = #{uuId},
            update_date = NOW()
        WHERE UUID = #{scpz}
    </update>


    <update id="updateInvoiceImg" parameterType="java.lang.String" databaseId="oracle">
        UPDATE t_dx_invoice_img
        SET UUID        = #{uuId},
            update_date =sysdate
        WHERE UUID = #{scpz}
    </update>
</mapper>
