<?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="cn.iocoder.yudao.module.archives.mapper.ArchivesMapper">

    <resultMap id="BaseResultMap" type="cn.iocoder.yudao.module.archives.entity.Archives">
        <id property="id" column="id" jdbcType="VARCHAR"/>
        <result property="dataId" column="data_id" jdbcType="BIGINT"/>
        <result property="archivesName" column="archives_name" jdbcType="VARCHAR"/>
        <result property="archivesType" column="archives_type" jdbcType="VARCHAR"/>
        <result property="archivesPhysicsUrl" column="archives_physics_url" jdbcType="VARCHAR"/>
        <result property="archivesUrls" column="archives_urls" jdbcType="VARCHAR"/>
        <result property="archivesCode" column="archives_code" jdbcType="VARCHAR"/>
        <result property="signTime" column="sign_time" jdbcType="TIMESTAMP"/>
        <result property="expireTime" column="expire_time" jdbcType="TIMESTAMP"/>
        <result property="deptId" column="dept_id" jdbcType="BIGINT"/>
        <result property="remark" column="remark" jdbcType="VARCHAR"/>
    </resultMap>

    <sql id="Base_SQL">
        select id,
               data_id,
               archives_name,
               archives_type,
               archives_physics_url,
               archives_urls,
               archives_code,
               sign_time,
               expire_time,
               dept_id,
               remark
        from company_archives ca
        where deleted = '0'
    </sql>

    <select id="queryArchivesPage" resultMap="BaseResultMap">
        <include refid="Base_SQL" />
        and ca.data_id = #{map.dataId}
        <if test="map.archivesName != null and map.archivesName != ''">
            and (ca.archives_name like concat('%', #{map.archivesName}, '%'))
        </if>
        <if test="map.queryDateArray != null and map.queryDateArray.length > 0">
            and (ca.sign_time >= #{map.queryDateArray[0]} and ca.expire_time &lt;= #{map.queryDateArray[1]})
        </if>
        order by ca.expire_time, ca.create_time desc
    </select>
</mapper>