Files
TimiServerAPI/src/main/resources/mapper/timi-server/common/AttachmentMapper.xml
T
2026-08-12 16:11:08 +08:00

59 lines
1.8 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.AttachmentMapper">
<select id="selectByBizIdList" resultType="com.imyeyu.api.modules.common.entity.Attachment">
SELECT
*
FROM `attachment`
WHERE
`biz_type` = #{bizType}
<if test="bizIdList != null and !bizIdList.isEmpty()">
AND `biz_id` IN
<foreach collection="bizIdList" item="bizId" separator="," open="(" close=")">
#{bizId}
</foreach>
</if>
<if test="bizIdList == null or bizIdList.isEmpty()">
AND FALSE
</if>
AND `deleted_at` IS NULL
AND (`destroy_at` IS NULL OR UNIX_TIMESTAMP() &lt; `destroy_at`)
<if test="attachTypes != null and !attachTypes.isEmpty()">
AND `attach_type` IN
<foreach collection="attachTypes" item="attachType" separator="," open="(" close=")">
#{attachType}
</foreach>
</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 &lt; destroy_at
LIMIT 1
</select>
</mapper>