78 lines
2.4 KiB
XML
78 lines
2.4 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="selectImageByBizIdList" resultType="com.imyeyu.api.modules.common.entity.Attachment">
|
|
SELECT
|
|
`ranked`.`id`,
|
|
`ranked`.`biz_type`,
|
|
`ranked`.`biz_id`,
|
|
`ranked`.`attach_type`,
|
|
`ranked`.`mongo_id`,
|
|
`ranked`.`title`,
|
|
`ranked`.`name`,
|
|
`ranked`.`mime_type`,
|
|
`ranked`.`metadata`,
|
|
`ranked`.`size`,
|
|
`ranked`.`md5`,
|
|
`ranked`.`uploader_ip`,
|
|
`ranked`.`is_destroyed`,
|
|
`ranked`.`created_at`,
|
|
`ranked`.`updated_at`,
|
|
`ranked`.`deleted_at`,
|
|
`ranked`.`destroy_at`
|
|
FROM (
|
|
SELECT
|
|
`attachment`.*,
|
|
ROW_NUMBER() OVER (
|
|
PARTITION BY `attachment`.`biz_id`
|
|
ORDER BY `attachment`.`created_at`, `attachment`.`id`
|
|
) AS `row_num`
|
|
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 `mime_type` LIKE "image/%"
|
|
AND `deleted_at` IS NULL
|
|
AND (`destroy_at` IS NULL OR UNIX_TIMESTAMP() < `destroy_at`)
|
|
<if test="attachType != null and !attachType.isEmpty()">
|
|
AND `attach_type` = #{attachType}
|
|
</if>
|
|
) `ranked`
|
|
WHERE `ranked`.`row_num` = 1
|
|
ORDER BY `ranked`.`created_at`, `ranked`.`id`
|
|
</select>
|
|
<select id="selectAllByBizIdList" 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() < `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>
|
|
</mapper>
|