|
|
@@ -0,0 +1,146 @@
|
|
|
+<?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.jeeplus.modules.workinvoice.dao.WorkInvoiceDownloadRecordDao">
|
|
|
+
|
|
|
+ <sql id="downloadRecordColumns">
|
|
|
+ a.id AS "id",
|
|
|
+ a.user_id AS "userId",
|
|
|
+ a.invoice_id AS "invoiceId",
|
|
|
+ a.file_url AS "fileUrl",
|
|
|
+ a.download_time AS "downloadTime",
|
|
|
+ a.create_by AS "createBy.id",
|
|
|
+ a.create_date AS "createDate",
|
|
|
+ a.update_by AS "updateBy.id",
|
|
|
+ a.update_date AS "updateDate",
|
|
|
+ a.del_flag AS "delFlag"
|
|
|
+ </sql>
|
|
|
+
|
|
|
+ <sql id="downloadRecordJoins">
|
|
|
+ LEFT JOIN sys_user createBy ON createBy.id = a.create_by
|
|
|
+ LEFT JOIN sys_user updateBy ON updateBy.id = a.update_by
|
|
|
+ </sql>
|
|
|
+
|
|
|
+ <!-- 根据ID获取单条记录 -->
|
|
|
+ <select id="get" resultType="WorkInvoiceDownloadRecord">
|
|
|
+ SELECT
|
|
|
+ <include refid="downloadRecordColumns"/>
|
|
|
+ FROM work_invoice_download_record a
|
|
|
+ <include refid="downloadRecordJoins"/>
|
|
|
+ WHERE a.id = #{id} AND a.del_flag = '0'
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <!-- 查询列表 -->
|
|
|
+ <select id="findList" resultType="WorkInvoiceDownloadRecord">
|
|
|
+ SELECT
|
|
|
+ <include refid="downloadRecordColumns"/>
|
|
|
+ FROM work_invoice_download_record a
|
|
|
+ <include refid="downloadRecordJoins"/>
|
|
|
+ <where>
|
|
|
+ a.del_flag = '0'
|
|
|
+ <if test="userId != null and userId != ''">
|
|
|
+ AND a.user_id = #{userId}
|
|
|
+ </if>
|
|
|
+ <if test="invoiceId != null and invoiceId != ''">
|
|
|
+ AND a.invoice_id = #{invoiceId}
|
|
|
+ </if>
|
|
|
+ <if test="fileUrl != null and fileUrl != ''">
|
|
|
+ AND a.file_url = #{fileUrl}
|
|
|
+ </if>
|
|
|
+ </where>
|
|
|
+ ORDER BY a.download_time DESC
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <!-- 查询所有列表 -->
|
|
|
+ <select id="findAllList" resultType="WorkInvoiceDownloadRecord">
|
|
|
+ SELECT
|
|
|
+ <include refid="downloadRecordColumns"/>
|
|
|
+ FROM work_invoice_download_record a
|
|
|
+ <include refid="downloadRecordJoins"/>
|
|
|
+ WHERE a.del_flag = '0'
|
|
|
+ ORDER BY a.download_time DESC
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <!-- 插入记录 -->
|
|
|
+ <insert id="insert">
|
|
|
+ INSERT INTO work_invoice_download_record (
|
|
|
+ id,
|
|
|
+ user_id,
|
|
|
+ invoice_id,
|
|
|
+ file_url,
|
|
|
+ download_time,
|
|
|
+ create_by,
|
|
|
+ create_date,
|
|
|
+ update_by,
|
|
|
+ update_date,
|
|
|
+ del_flag
|
|
|
+ ) VALUES (
|
|
|
+ #{id},
|
|
|
+ #{userId},
|
|
|
+ #{invoiceId},
|
|
|
+ #{fileUrl},
|
|
|
+ #{downloadTime},
|
|
|
+ #{createBy.id},
|
|
|
+ #{createDate},
|
|
|
+ #{updateBy.id},
|
|
|
+ #{updateDate},
|
|
|
+ #{delFlag}
|
|
|
+ )
|
|
|
+ </insert>
|
|
|
+
|
|
|
+ <!-- 更新记录 -->
|
|
|
+ <update id="update">
|
|
|
+ UPDATE work_invoice_download_record SET
|
|
|
+ user_id = #{userId},
|
|
|
+ invoice_id = #{invoiceId},
|
|
|
+ file_url = #{fileUrl},
|
|
|
+ download_time = #{downloadTime},
|
|
|
+ update_by = #{updateBy.id},
|
|
|
+ update_date = #{updateDate}
|
|
|
+ WHERE id = #{id}
|
|
|
+ </update>
|
|
|
+
|
|
|
+ <!-- 删除记录(逻辑删除) -->
|
|
|
+ <update id="delete">
|
|
|
+ UPDATE work_invoice_download_record SET
|
|
|
+ del_flag = '1'
|
|
|
+ WHERE id = #{id}
|
|
|
+ </update>
|
|
|
+
|
|
|
+ <!-- 批量查询当前用户已下载的发票ID -->
|
|
|
+ <select id="findDownloadedInvoiceIds" resultType="java.lang.String">
|
|
|
+ SELECT DISTINCT a.invoice_id
|
|
|
+ FROM work_invoice_download_record a
|
|
|
+ WHERE a.user_id = #{userId}
|
|
|
+ AND a.del_flag = '0'
|
|
|
+ AND a.invoice_id IS NOT NULL
|
|
|
+ AND a.invoice_id IN
|
|
|
+ <foreach collection="invoiceIds" item="invoiceId" open="(" separator="," close=")">
|
|
|
+ #{invoiceId}
|
|
|
+ </foreach>
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <!-- 查询当前用户对某发票的下载记录数量 -->
|
|
|
+ <select id="countByUserIdAndInvoiceId" resultType="int">
|
|
|
+ SELECT COUNT(1)
|
|
|
+ FROM work_invoice_download_record a
|
|
|
+ WHERE a.user_id = #{userId}
|
|
|
+ AND a.invoice_id = #{invoiceId}
|
|
|
+ AND a.del_flag = '0'
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <!-- 分页查询总数 -->
|
|
|
+ <select id="queryCount" resultType="int">
|
|
|
+ SELECT COUNT(1)
|
|
|
+ FROM work_invoice_download_record a
|
|
|
+ <where>
|
|
|
+ a.del_flag = '0'
|
|
|
+ <if test="userId != null and userId != ''">
|
|
|
+ AND a.user_id = #{userId}
|
|
|
+ </if>
|
|
|
+ <if test="invoiceId != null and invoiceId != ''">
|
|
|
+ AND a.invoice_id = #{invoiceId}
|
|
|
+ </if>
|
|
|
+ </where>
|
|
|
+ </select>
|
|
|
+
|
|
|
+</mapper>
|