<?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.vctgo.file.mapper.FileAshInfoMapper">

    <resultMap type="com.vctgo.file.domain.FileAshInfo" id="FileAshInfoResult">
        <result property="id" column="id"/>
        <result property="tenantId" column="tenant_id"/>
        <result property="fileId" column="file_id"/>
        <result property="fileType" column="file_type"/>
        <result property="fileExtension" column="file_extension"/>
        <result property="fileName" column="file_name"/>
        <result property="fileFullName" column="file_full_name"/>
        <result property="fileSize" column="file_size"/>
        <result property="fileUrl" column="file_url"/>
        <result property="fileIsDirectory" column="file_is_directory"/>
        <result property="remark" column="remark"/>
        <result property="isDeleted" column="is_deleted"/>
        <result property="createById" column="create_by_id"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateById" column="update_by_id"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="selectFileAshInfoVo">
        select id, tenant_id, file_id,file_type, file_extension,file_name,file_full_name,file_size,file_is_directory,file_url, remark, is_deleted, create_by_id, create_by, create_time, update_by_id, update_by, update_time from file_ash_info
    </sql>

    <sql id="defaultDeleteCondition">
        is_deleted = '0'
    </sql>

    <select id="selectFileAshInfoList" resultMap="FileAshInfoResult">
        <include refid="selectFileAshInfoVo"/>
        <where>
            <include refid="defaultDeleteCondition"/>
            <if test="query.tenantId != null  and query.tenantId != ''">
                and tenant_id = #{query.tenantId}
            </if>
            <if test="query.fileId != null  and query.fileId != ''">
                and file_id = #{query.fileId}
            </if>
            <if test="query.fileName != null  and query.fileName != ''">
                and file_name like concat('%',#{query.fileName}, '%')
            </if>
            <if test="query.isDeleted != null  and query.isDeleted != ''">
                and is_deleted = #{query.isDeleted}
            </if>
            <if test="query.updateById != null ">
                AND update_by_id = #{query.updateById}
            </if>
            <if test="query.updateStartTime != null and query.updateStartTime != ''">
                <![CDATA[
                    AND	DATE_FORMAT(update_time, '%Y-%m-%d')>= DATE_FORMAT(#{query.updateStartTime}, '%Y-%m-%d')
                ]]>
            </if>
            <if test="query.updateEndTime != null and query.updateEndTime != ''">
                <![CDATA[
                    AND	DATE_FORMAT(update_time, '%Y-%m-%d')<= DATE_FORMAT(#{query.updateEndTime}, '%Y-%m-%d')
                ]]>
            </if>
            <if test="query.userIdList !=null and query.userIdList.size() > 0">
                AND update_by_id in
                <foreach collection="query.userIdList" item="item" index="index" separator="," open="(" close=")">
                    #{item}
                </foreach>
            </if>
        </where>
        <if test="query.params.orderNumber == 1">
            order by update_time desc
        </if>
        <if test="query.params.orderNumber != 1">
            order by file_is_directory desc, update_time desc
        </if>
    </select>

    <update id="logicalDeleteFileAshInfoByIds" parameterType="String">
        update
        file_ash_info
        set is_deleted = #{query.isDeleted},
        update_by_id = #{query.updateById},
        update_by = #{query.updateBy},
        update_time = #{query.updateTime}
        where id in
        <foreach item="id" collection="ids" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>

    <delete id="deleteFileAshInfoByIds" parameterType="String">
        delete from file_ash_info where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>
