<?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.BusinessUnzipTaskMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="org.springblade.file.pojo.entity.BusinessUnzipTask">
        <id column="id" property="id" />
        <result column="biz_id" property="bizId" />
        <result column="department_id" property="departmentId" />
        <result column="biz_code" property="bizCode" />
        <result column="doc_code" property="docCode" />
        <result column="relate_type" property="relateType" />
        <result column="relate_id" property="relateId" />
        <result column="status" property="status" />
        <result column="tenant_id" property="tenantId" />
        <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>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, biz_id, department_id, biz_code, doc_code, relate_type, relate_id, status, tenant_id, create_user, create_time, update_user, update_time, is_deleted
    </sql>
    <select id="selectTaskList" resultType="org.springblade.file.pojo.vo.BusinessUnzipTaskListVO">
        select
            but.id,
            but.biz_id,
            but.biz_code,
            but.doc_code,
            but.relate_type,
            but.relate_id,
            but.department_id,
            but.create_user b_create_user,
            ft.md5,
            ft.object_key,
            ft.attachment_name,
            ft.suffix,
            ft.size,
            ft.chunk_size,
            ft.chunk_total,
            ft.current_index,
            ft.upload_id,
            ft.status,
            ft.create_user,
            ft.create_user_name,
            ft.create_time,
            ft.update_user,
            ft.update_user_name,
            ft.update_time
        from blade_business_unzip_task but
        left join blade_file_task ft on ft.id = but.relate_id
        where but.is_deleted = 0 and ft.is_deleted = 0
        <if test="param.bizIds != null and param.bizIds.size() > 0">
            and but.biz_id in <foreach collection="param.bizIds" item="item" open="(" close=")" separator=",">#{item}</foreach>
        </if>
        <if test="param.docCode != null and param.docCode != ''">
            and but.doc_code like concat('%',#{param.docCode},'%')
        </if>
        <if test="param.relateType != null and param.relateType != ''">
            and but.relate_type = #{param.relateType}
        </if>
        <if test="param.currentUserId != null">
            and but.create_user = #{param.currentUserId}
        </if>
        <if test="param.attachmentName != null and param.attachmentName != ''">
            and ft.attachment_name like concat('%',#{param.attachmentName},'%')
        </if>
        <if test="param.status != null and param.status != ''">
            and ft.status = #{param.status}
        </if>
        order by Field(ft.status, 'uploading','failed', 'completed'), but.id desc
    </select>
    <select id="queryBusinessUnzipDetail" resultType="org.springblade.file.pojo.vo.BusinessUnzipDetailListVO">
        select
            bbud.id,
            bbud.attachment_id,
            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_unzip_task bbut
        left join blade_business_unzip_detail bbud on bbud.business_unzip_task_id = bbut.id
        left join blade_attachment ba on bbud.attachment_id = ba.id
        where bbut.is_deleted = 0 and bbud.is_deleted = 0 and ba.is_deleted = 0
        and bbut.biz_id = #{bizId}
    </select>

</mapper>
