<?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.yd.oss.service.dao.RelObjectMaterialMapper">
    <!-- 结果映射 -->
    <resultMap id="RelObjectMaterialResponseMap" type="com.yd.oss.feign.response.ApiRelObjectMaterialPageResponse">
        <id property="id" column="id"/>
        <result property="relObjectMaterialBizId" column="rel_object_material_biz_id"/>
        <result property="materialBizId" column="material_biz_id"/>
        <result property="status" column="status"/>
        <result property="dataPerson" column="data_person"/>
        <result property="dataType" column="data_type"/>
        <result property="precautions" column="precautions"/>
        <!-- 使用类型处理器将分号分隔的字符串转换为List -->
        <result property="fileUrlList" column="file_urls"
                typeHandler="com.yd.oss.service.handler.StringToListTypeHandler"/>
    </resultMap>

    <select id="page" resultMap="RelObjectMaterialResponseMap">
        SELECT
        rom.id,
        rom.rel_object_material_biz_id,
        rom.material_biz_id,
        rom.status,
        m.data_person,
        m.data_type,
        m.precautions,
        GROUP_CONCAT(
        CONCAT('https://', f.bucket_name, '.', p.endpoint, '/', f.file_key)
        SEPARATOR ';'
        ) as file_urls
        FROM rel_object_material rom
        LEFT JOIN material m ON m.material_biz_id = rom.material_biz_id AND m.is_deleted = 0
        LEFT JOIN oss_file f ON f.object_biz_id = rom.rel_object_material_biz_id
        AND f.object_table_name = 'rel_object_material'
        AND f.is_deleted = 0
        LEFT JOIN oss_provider p ON p.provider_biz_id = f.provider_biz_id
        AND p.is_active = 1
        AND p.is_deleted = 0
        <where>
            <if test="request.objectBizId != null and request.objectBizId != ''">
                AND rom.object_biz_id = #{request.objectBizId}
            </if>
            AND rom.is_deleted = 0
        </where>
        GROUP BY rom.id
    </select>


</mapper>
