<?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="org.springblade.file.mapper.BusinessAttachmentMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="businessAttachmentResultMap" type="org.springblade.file.pojo.entity.BusinessAttachment">
        <result column="id" property="id"/>
        <result column="tenant_id" property="tenantId"/>
        <result column="biz_id" property="bizId"/>
        <result column="biz_code" property="bizCode"/>
        <result column="attachment_id" property="attachmentId"/>
        <result column="`desc`" property="desc"/>
        <result column="sort" property="sort"/>
        <result column="create_user" property="createUser"/>
        <result column="create_time" property="createTime"/>
        <result column="update_user" property="updateUser"/>
        <result column="update_time" property="updateTime"/>
        <result column="is_deleted" property="isDeleted"/>
    </resultMap>
    <select id="queryList" resultType="org.springblade.file.pojo.vo.BusinessAttachmentVO">
        select
            bba.id,
            bba.biz_id,
            bba.biz_code,
            bba.attachment_id,
            bba.`desc`,
            bba.sort,
            ba.dir,
            ba.attachment_name,
            ba.size,
            ba.object_key,
            ba.create_user uploadUserId,
            ba.create_user_name uploadUserName,
            ba.create_time,
            ba.create_user_name
        from blade_business_attachment bba
        left join blade_attachment ba on ba.id = bba.attachment_id
        where bba.is_deleted = 0 and ba.is_deleted = 0 and bba.biz_id in <foreach collection="bizIds" item="item" open="(" close=")" separator=",">#{item}</foreach>
        <if test="bizCode != null and bizCode != ''">
            and bba.biz_code = #{bizCode}
        </if>
        <if test="bizCodes != null and bizCodes.size() > 0">
            and bba.biz_code in <foreach collection="bizCodes" item="item" open="(" close=")" separator=",">#{item}</foreach>
        </if>
        order by bba.biz_id, bba.sort, bba.id
    </select>

</mapper>
