Files
TimiServerAPI/src/main/resources/mapper/timi-server/common/AttachmentVariantMapper.xml
T
2026-08-21 23:43:40 +08:00

106 lines
2.6 KiB
XML

<?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` &gt; #{now}
AND a.`mongo_id` = v.`source_mongo_id`
AND a.`is_destroyed` = FALSE
AND (a.`deleted_at` IS NULL OR #{now} &lt; a.`deleted_at`)
AND (a.`destroy_at` IS NULL OR #{now} &lt; 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` &lt;= #{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>