add AttachmentVariant
This commit is contained in:
@@ -26,33 +26,4 @@
|
||||
</if>
|
||||
ORDER BY `created_at`
|
||||
</select>
|
||||
<select id="selectThumb" resultType="com.imyeyu.api.modules.common.entity.Attachment">
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
`attachment`
|
||||
WHERE
|
||||
biz_type = #{bizType}
|
||||
AND biz_id = #{sourceId}
|
||||
AND attach_type = 'THUMB'
|
||||
<choose>
|
||||
<when test="requestWidth != null">
|
||||
AND JSON_EXTRACT(metadata, '$.requestWidth') = #{requestWidth}
|
||||
</when>
|
||||
<otherwise>
|
||||
AND JSON_EXTRACT(metadata, '$.requestWidth') IS NULL
|
||||
</otherwise>
|
||||
</choose>
|
||||
<choose>
|
||||
<when test="requestHeight != null">
|
||||
AND JSON_EXTRACT(metadata, '$.requestHeight') = #{requestHeight}
|
||||
</when>
|
||||
<otherwise>
|
||||
AND JSON_EXTRACT(metadata, '$.requestHeight') IS NULL
|
||||
</otherwise>
|
||||
</choose>
|
||||
AND is_destroyed = FALSE
|
||||
AND UNIX_TIMESTAMP() * 1000 < destroy_at
|
||||
LIMIT 1
|
||||
</select>
|
||||
</mapper>
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
<?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.imyeyu.api.modules.common.mapper.AttachmentVariantMapper">
|
||||
<sql id="variantKey">
|
||||
`source_attachment_id` = #{sourceAttachmentId}
|
||||
AND `source_mongo_id` = #{sourceMongoId}
|
||||
AND `request_width` = #{requestWidth}
|
||||
AND `request_height` = #{requestHeight}
|
||||
AND `fit_mode` = #{fitMode}
|
||||
AND `output_format` = #{outputFormat}
|
||||
AND `algorithm_version` = #{algorithmVersion}
|
||||
</sql>
|
||||
|
||||
<select id="selectValidAttachment" resultType="com.imyeyu.api.modules.common.entity.Attachment">
|
||||
SELECT
|
||||
v.`id`,
|
||||
a.`biz_type`,
|
||||
v.`source_attachment_id` AS `biz_id`,
|
||||
'THUMB' AS `attach_type`,
|
||||
v.`mongo_id`,
|
||||
v.`name`,
|
||||
v.`mime_type`,
|
||||
v.`metadata`,
|
||||
v.`size`,
|
||||
v.`md5`,
|
||||
FALSE AS `is_destroyed`,
|
||||
v.`created_at`,
|
||||
v.`expire_at` AS `destroy_at`
|
||||
FROM `attachment_variant` v
|
||||
INNER JOIN `attachment` a ON a.`id` = v.`source_attachment_id`
|
||||
WHERE
|
||||
<include refid="variantKey" />
|
||||
AND v.`expire_at` > #{now}
|
||||
AND a.`mongo_id` = v.`source_mongo_id`
|
||||
AND a.`is_destroyed` = FALSE
|
||||
AND (a.`deleted_at` IS NULL OR #{now} < a.`deleted_at`)
|
||||
AND (a.`destroy_at` IS NULL OR #{now} < a.`destroy_at`)
|
||||
LIMIT 1
|
||||
</select>
|
||||
|
||||
<select id="selectByKey" resultType="com.imyeyu.api.modules.common.entity.AttachmentVariant">
|
||||
SELECT *
|
||||
FROM `attachment_variant`
|
||||
WHERE
|
||||
<include refid="variantKey" />
|
||||
LIMIT 1
|
||||
</select>
|
||||
|
||||
<select id="selectBySourceAttachmentId" resultType="com.imyeyu.api.modules.common.entity.AttachmentVariant">
|
||||
SELECT *
|
||||
FROM `attachment_variant`
|
||||
WHERE `source_attachment_id` = #{sourceAttachmentId}
|
||||
</select>
|
||||
|
||||
<select id="selectExpired" resultType="com.imyeyu.api.modules.common.entity.AttachmentVariant">
|
||||
SELECT *
|
||||
FROM `attachment_variant`
|
||||
WHERE `expire_at` <= #{now}
|
||||
</select>
|
||||
|
||||
<insert id="insert">
|
||||
INSERT INTO `attachment_variant` (
|
||||
`id`,
|
||||
`source_attachment_id`,
|
||||
`source_mongo_id`,
|
||||
`source_md5`,
|
||||
`request_width`,
|
||||
`request_height`,
|
||||
`fit_mode`,
|
||||
`output_format`,
|
||||
`algorithm_version`,
|
||||
`mongo_id`,
|
||||
`name`,
|
||||
`mime_type`,
|
||||
`metadata`,
|
||||
`size`,
|
||||
`md5`,
|
||||
`created_at`,
|
||||
`expire_at`
|
||||
) VALUES (
|
||||
#{id},
|
||||
#{sourceAttachmentId},
|
||||
#{sourceMongoId},
|
||||
#{sourceMd5},
|
||||
#{requestWidth},
|
||||
#{requestHeight},
|
||||
#{fitMode},
|
||||
#{outputFormat},
|
||||
#{algorithmVersion},
|
||||
#{mongoId},
|
||||
#{name},
|
||||
#{mimeType},
|
||||
#{metadata},
|
||||
#{size},
|
||||
#{md5},
|
||||
#{createdAt},
|
||||
#{expireAt}
|
||||
)
|
||||
</insert>
|
||||
|
||||
<delete id="delete">
|
||||
DELETE FROM `attachment_variant`
|
||||
WHERE `id` = #{id}
|
||||
</delete>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user