FileMapper.xml 4.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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.persagy.dmp.file.dao.FileMapper">
  4. <resultMap id="FileMap" type="com.persagy.dmp.file.model.FileInfo">
  5. <result column="id" property="id"/>
  6. <result column="group_code" property="groupCode"/>
  7. <result column="file_name" property="fileName"/>
  8. <result column="business_id" property="businessId"/>
  9. <result column="file_md5" property="fileMd5"/>
  10. <result column="expire_date" property="expireDate"/>
  11. <result column="ts" property="ts"/>
  12. <result column="creator" property="creator"/>
  13. <result column="creation_time" property="creationTime"/>
  14. <result column="modifier" property="modifier"/>
  15. <result column="modified_time" property="modifiedTime"/>
  16. <result column="valid" property="valid"/>
  17. <result column="file_type" property="fileType"/>
  18. <result column="file_bucket" property="fileBucket"/>
  19. <result column="file_path" property="filePath"/>
  20. <result column="file_size" property="fileSize"/>
  21. <result column="upload_status" property="uploadStatus"/>
  22. </resultMap>
  23. <sql id="selectPart">
  24. SELECT dt_file_info.*,dt_file_md5.file_bucket,dt_file_md5.file_path,dt_file_md5.file_size,dt_file_md5.file_type,dt_file_md5.upload_status
  25. </sql>
  26. <sql id="fromPart">
  27. FROM dt_file_info INNER JOIN dt_file_md5 ON (dt_file_info.file_md5 = dt_file_md5.file_md5 AND dt_file_info.valid = TRUE AND dt_file_md5.valid = TRUE)
  28. </sql>
  29. <select id="getFileInfoById" resultMap="FileMap">
  30. <include refid="selectPart"/>
  31. <include refid="fromPart"/>
  32. WHERE dt_file_info.id = #{fileId};
  33. </select>
  34. <sql id="selectList">
  35. FROM dt_file_info INNER JOIN dt_file_md5 ON (dt_file_info.valid = TRUE AND dt_file_md5.valid = TRUE AND dt_file_info.file_md5 = dt_file_md5.file_md5
  36. AND dt_file_md5.upload_status = 0 AND dt_file_md5.file_bucket = #{bucket}
  37. <if test="null!=prefix and prefix.length>0">
  38. AND dt_file_md5.file_path LIKE CONCAT('%',#{prefix},'%')
  39. </if>) ORDER BY dt_file_info.creation_time DESC
  40. </sql>
  41. <select id="getPageSizeByPrefixAndFrom" resultType="java.lang.Integer">
  42. SET @rowNum = 0;
  43. SELECT FLOOR((@rowNum := @rowNum + 1)/ #{size}) AS rowNum FROM (SELECT dt_file_info.id AS id
  44. <include refid="selectList">
  45. <property name="bucket" value="#{bucket}"/>
  46. <property name="prefix" value="#{prefix}"/>
  47. </include>) AS df GROUP BY df.id HAVING df.id = #{from}
  48. </select>
  49. <select id="queryListByPrefixAndFrom" resultMap="FileMap">
  50. <include refid="selectPart"/>
  51. <include refid="selectList">
  52. <property name="bucket" value="#{bucket}"/>
  53. <property name="prefix" value="#{prefix}"/>
  54. </include>
  55. </select>
  56. <select id="getFileInfoByIds" resultMap="FileMap">
  57. <include refid="selectPart"/>
  58. <include refid="fromPart"/>
  59. <foreach collection="fileIds" separator="," open="WHERE dt_file_info.id IN(" close=")" item="fileId">
  60. #{fileId}
  61. </foreach>
  62. </select>
  63. <select id="queryFileKeysByInfos" resultType="java.lang.String">
  64. SELECT
  65. <choose>
  66. <when test="extractInfos!=null and extractInfos.size()>0">
  67. <foreach collection="extractInfos" item="item" open="JSON_EXTRACT(JSON_ARRAYAGG(JSON_EXTRACT(infos, '$.*.key'," close=")),'$[*][*]')" separator=",">
  68. CONCAT('$.',#{item})
  69. </foreach>
  70. </when>
  71. <otherwise>
  72. JSON_EXTRACT(JSON_ARRAYAGG(JSON_EXTRACT(infos, '$.*.key')),'$[*][*]')
  73. </otherwise>
  74. </choose> AS fileKeys
  75. FROM ${schema}_${groupCode}.dt_object WHERE
  76. <choose>
  77. <when test="extractInfos!=null and extractInfos.size()>0">
  78. <foreach collection="extractInfos" item="item" open="JSON_EXTRACT(infos, '$.*.key'," close=") IS NOT NULL" separator=",">
  79. CONCAT('$.',#{item})
  80. </foreach>
  81. </when>
  82. <otherwise>
  83. JSON_EXTRACT(infos, '$.*.key') IS NOT NULL
  84. </otherwise>
  85. </choose>;
  86. </select>
  87. </mapper>