SysFileDao.xml 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
  3. <mapper namespace="com.backendsys.modules.upload.dao.SysFileDao">
  4. <sql id="includeFileSimple">
  5. f.id,
  6. COALESCE(f.category_id, '') category_id,
  7. COALESCE(fc.category_name, '') category_name,
  8. f.upload_id,
  9. f.name,
  10. f.object_key,
  11. f.md5,
  12. f.url,
  13. f.upload_time,
  14. f.create_time,
  15. f.update_time
  16. </sql>
  17. <sql id="includeFile">
  18. f.id,
  19. COALESCE(f.category_id, '') category_id,
  20. COALESCE(fc.category_name, '') category_name,
  21. COALESCE(f.request_id, '') request_id,
  22. COALESCE(f.upload_id, '') upload_id,
  23. COALESCE(f.upload_chunk_count, '') upload_chunk_count,
  24. COALESCE(f.upload_chunk_index, '') upload_chunk_index,
  25. f.user_id,
  26. fu.username,
  27. f.name,
  28. f.content_type,
  29. f.url,
  30. COALESCE(f.url_thumb, '') url_thumb,
  31. COALESCE(f.object_key, '') object_key,
  32. f.size,
  33. f.md5,
  34. f.target,
  35. f.upload_time,
  36. f.create_time,
  37. f.update_time
  38. </sql>
  39. <resultMap id="resultMapFileSimple" type="java.util.LinkedHashMap">
  40. <id property="id" column="id" jdbcType="BIGINT" />
  41. <result property="category_id" column="category_id" javaType="java.lang.Long" />
  42. <result property="category_name" column="category_name" />
  43. <result property="upload_id" column="upload_id" />
  44. <result property="name" column="name" />
  45. <result property="object_key" column="object_key" />
  46. <result property="url" column="url" />
  47. <result property="md5" column="md5" />
  48. <result property="upload_time" column="upload_time" />
  49. <result property="create_time" column="create_time" />
  50. <result property="update_time" column="update_time" />
  51. </resultMap>
  52. <resultMap id="resultMapFileList" type="com.backendsys.modules.upload.entity.SysFile">
  53. <id property="id" column="id" jdbcType="BIGINT" />
  54. <result property="category_id" column="category_id" javaType="java.lang.Long" />
  55. <result property="category_name" column="category_name" />
  56. <result property="request_id" column="request_id" />
  57. <result property="upload_id" column="upload_id" />
  58. <result property="upload_chunk_count" column="upload_chunk_count" javaType="java.lang.Integer" />
  59. <result property="upload_chunk_index" column="upload_chunk_index" javaType="java.lang.Integer" />
  60. <result property="user_id" column="user_id" javaType="java.lang.Long" />
  61. <result property="username" column="username" />
  62. <result property="name" column="name" />
  63. <result property="content_type" column="content_type" />
  64. <result property="url" column="url" />
  65. <result property="url_thumb" column="url_thumb" />
  66. <result property="object_key" column="object_key" />
  67. <result property="size" column="size" javaType="java.lang.Long" />
  68. <result property="md5" column="md5" />
  69. <result property="target" column="target" javaType="java.lang.Integer" />
  70. <result property="upload_time" column="upload_time" typeHandler="com.backendsys.config.Mybatis.handler.timezone.LocalDateTimeHandler" />
  71. <result property="create_time" column="create_time" typeHandler="com.backendsys.config.Mybatis.handler.timezone.LocalDateTimeHandler" />
  72. <result property="update_time" column="update_time" typeHandler="com.backendsys.config.Mybatis.handler.timezone.LocalDateTimeHandler" />
  73. <!-- <result property="upload_time" column="upload_time" typeHandler="com.backendsys.config.Mybatis.handler.timezone.LocalDateTimeHandler" />-->
  74. <!-- <result property="create_time" column="create_time" typeHandler="com.backendsys.config.Mybatis.handler.timezone.LocalDateTimeHandler" />-->
  75. <!-- <result property="update_time" column="update_time" typeHandler="com.backendsys.config.Mybatis.handler.timezone.LocalDateTimeHandler" />-->
  76. </resultMap>
  77. <select id="selectUploadFileSimple" resultMap="resultMapFileSimple">
  78. SELECT <include refid="includeFileSimple" />
  79. FROM sys_file f
  80. LEFT JOIN sys_file_category fc ON f.category_id = fc.id
  81. <where>
  82. AND (f.upload_id IS NULL OR f.upload_id = '')
  83. <if test="user_id != null and user_id != ''">
  84. AND f.user_id = #{user_id}
  85. </if>
  86. <if test="object_key != null and object_key != ''">
  87. AND f.object_key = #{object_key}
  88. </if>
  89. <if test="md5 != null and md5 != ''">
  90. AND f.md5 = #{md5}
  91. </if>
  92. </where>
  93. ORDER BY f.upload_time DESC
  94. </select>
  95. <select id="selectUploadFileList" resultMap="resultMapFileList">
  96. SELECT <include refid="includeFile" />
  97. FROM sys_file f
  98. LEFT JOIN sys_file_category fc ON f.category_id = fc.id
  99. LEFT JOIN sys_user fu ON f.user_id = fu.id
  100. <where>
  101. <if test="name != null and name != ''">
  102. AND f.name LIKE CONCAT('%', #{name}, '%')
  103. </if>
  104. <if test="category_id != null and category_id != ''">
  105. AND f.category_id = #{category_id}
  106. </if>
  107. <if test="user_id != null and user_id != ''">
  108. AND f.user_id = #{user_id}
  109. </if>
  110. <if test="upload_id != null and upload_id != ''">
  111. AND f.upload_id = #{upload_id}
  112. </if>
  113. <if test="object_key != null and object_key != ''">
  114. AND f.object_key = #{object_key}
  115. </if>
  116. <if test="target != null and target != ''">
  117. AND f.target = #{target}
  118. </if>
  119. </where>
  120. ORDER BY f.upload_time DESC
  121. </select>
  122. <update id="updateFile" parameterType="com.backendsys.modules.upload.entity.SysFile"
  123. useGeneratedKeys="true" keyProperty="id">
  124. UPDATE sys_file
  125. <set>
  126. <trim suffixOverrides="," suffix=" ">
  127. name = #{name},
  128. category_id = #{category_id},
  129. </trim>
  130. </set>
  131. WHERE id = #{id}
  132. </update>
  133. <update id="updateCompleteFile" parameterType="com.backendsys.modules.upload.entity.SysFile"
  134. useGeneratedKeys="true" keyProperty="id">
  135. UPDATE sys_file
  136. SET upload_id = null, upload_chunk_count = null, upload_chunk_index = null
  137. <if test="request_id != null and request_id != ''">, request_id = #{request_id}</if>
  138. <if test="url != null and url != ''">, url = #{url}</if>
  139. <if test="url_thumb != null and url_thumb != ''">, url_thumb = #{url_thumb}</if>
  140. WHERE id = #{id}
  141. </update>
  142. </mapper>