DiskFileMapper.xml 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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="cn.reghao.tnb.content.app.disk.db.mapper.DiskFileMapper">
  4. <insert id="save" useGeneratedKeys="true" keyProperty="id">
  5. insert into disk_file
  6. (`channel_code`,`file_id`,`pid`,`path`,`filename`,`file_type`,`sha256sum`,`size`,`owner`)
  7. values
  8. (#{channelCode},#{fileId},#{pid},#{path},#{filename},#{fileType},#{sha256sum},#{size},#{owner})
  9. </insert>
  10. <insert id="saveAll" useGeneratedKeys="true" keyProperty="id">
  11. insert into disk_file
  12. (`channel_code`,`file_id`,`pid`,`path`,`filename`,`file_type`,`sha256sum`,`size`,`owner`)
  13. values
  14. <foreach collection="list" item="item" index="index" separator=",">
  15. (#{item.channelCode},#{item.fileId},#{item.pid},#{item.path},#{item.filename},#{item.fileType},#{item.sha256sum},#{item.size},#{item.owner})
  16. </foreach>
  17. </insert>
  18. <update id="updateMoveDiskFile">
  19. update disk_file
  20. set update_time=now(),pid=#{pid},`path`=#{path}
  21. where file_id=#{fileId}
  22. </update>
  23. <update id="updateDeleteDiskFiles">
  24. update disk_file
  25. set update_time=now(),deleted=1
  26. where file_id in
  27. <foreach collection="collection" item="id" index="index" open="(" close=")" separator=",">
  28. #{id}
  29. </foreach>
  30. </update>
  31. <update id="updateDeleteByPathPrefix">
  32. update disk_file
  33. set update_time=now(),deleted=1
  34. where `owner`=#{owner} and `path` like concat(#{pathPrefix},'%')
  35. </update>
  36. <delete id="deleteByAlbumIdAndPostId">
  37. delete from disk_file
  38. where album_id=#{albumId} and post_id=#{postId}
  39. </delete>
  40. <select id="countByDiskQuery" resultType="java.lang.Integer">
  41. select count(*)
  42. from disk_file
  43. <where>
  44. deleted=0
  45. <if test="fileType != null">
  46. and file_type=#{fileType}
  47. </if>
  48. <if test="owner != null">
  49. and owner=#{owner}
  50. </if>
  51. <if test="pid != null">
  52. and pid=#{pid}
  53. </if>
  54. <if test="fileId != null">
  55. and file_id=#{fileId}
  56. </if>
  57. <if test="path != null">
  58. and path=#{path}
  59. </if>
  60. <if test="sha256sum != null">
  61. and sha256sum=#{sha256sum}
  62. </if>
  63. </where>
  64. </select>
  65. <select id="findDiskQueryByPage" resultType="cn.reghao.tnb.content.app.disk.model.po.DiskFile">
  66. select *
  67. from disk_file
  68. <where>
  69. deleted=0
  70. <if test="diskQuery.fileType != null">
  71. and file_type=#{diskQuery.fileType}
  72. </if>
  73. <if test="diskQuery.owner != null">
  74. and `owner`=#{diskQuery.owner}
  75. </if>
  76. <if test="diskQuery.pid != null">
  77. and pid=#{diskQuery.pid}
  78. </if>
  79. <if test="diskQuery.fileId != null">
  80. and file_id=#{diskQuery.fileId}
  81. </if>
  82. <if test="diskQuery.path != null">
  83. and `path`=#{diskQuery.path}
  84. </if>
  85. <if test="diskQuery.sha256sum != null">
  86. and sha256sum=#{diskQuery.sha256sum}
  87. </if>
  88. <if test="diskQuery.pathPrefix != null">
  89. and `path` like concat(#{diskQuery.pathPrefix},'%')
  90. </if>
  91. </where>
  92. order by file_type,filename
  93. </select>
  94. <select id="findFileTypeCountByGroup" resultType="cn.reghao.tnb.content.app.disk.model.vo.DiskFileCount">
  95. select file,count(*) as total
  96. from disk_file
  97. group by file_type
  98. order by total desc
  99. </select>
  100. <select id="findByFileIds" resultType="cn.reghao.tnb.content.app.disk.model.po.DiskFile">
  101. select *
  102. from disk_file
  103. where deleted=0 and file_id in
  104. <foreach collection="list" item="id" index="index" open="(" close=")" separator=",">
  105. #{id}
  106. </foreach>
  107. </select>
  108. <select id="findByParentIds" resultType="cn.reghao.tnb.content.app.disk.model.po.DiskFile">
  109. select *
  110. from disk_file
  111. where deleted=0 and pid in
  112. <foreach collection="list" item="id" index="index" open="(" close=")" separator=",">
  113. #{id}
  114. </foreach>
  115. </select>
  116. <select id="findRoot" resultType="cn.reghao.tnb.content.app.disk.model.po.DiskFile">
  117. select *
  118. from disk_file
  119. where file_id='0'
  120. </select>
  121. <select id="findByPathPrefix" resultType="cn.reghao.tnb.content.app.disk.model.po.DiskFile">
  122. select *
  123. from disk_file
  124. where deleted=0 and file_id!=#{fileId} and `path` like concat(#{pathPrefix})
  125. </select>
  126. <select id="countSha256sumGroupByDiskQuery" resultType="java.lang.String">
  127. select sha256sum
  128. from disk_file
  129. where deleted=0 and `owner`=#{userId} and file_type=#{fileType} and sha256sum not in (
  130. select sha256sum
  131. from my_disk_album_file A
  132. where exists (
  133. select album_id
  134. from my_disk_album B
  135. where B.create_by=#{userId} and B.album_id=A.album_id
  136. )
  137. )
  138. group by sha256sum
  139. </select>
  140. <select id="findSha256sumGroupByPage" resultType="cn.reghao.tnb.content.app.disk.model.po.DiskFile">
  141. select *
  142. from disk_file
  143. where deleted=0 and `owner`=#{userId} and file_type=#{fileType} and sha256sum not in (
  144. select sha256sum
  145. from my_disk_album_file A
  146. where exists (
  147. select album_id
  148. from my_disk_album B
  149. where B.create_by=#{userId} and B.album_id=A.album_id
  150. )
  151. )
  152. group by sha256sum
  153. </select>
  154. <select id="findSha256sumGroup" resultType="cn.reghao.tnb.content.app.disk.model.po.DiskFile">
  155. select *
  156. from disk_file
  157. where deleted=0 and sha256sum in
  158. <foreach collection="list" item="id" index="index" open="(" close=")" separator=",">
  159. #{id}
  160. </foreach>
  161. group by sha256sum
  162. </select>
  163. </mapper>