<?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.testor.module.hire.dao.DepositoryManageBaseMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.testor.module.hire.entity.DepositoryManageBase">
        <id column="id" property="id"/>
        <result column="lessor_full_name" property="lessorFullName"/>
        <result column="lessor_short_name" property="lessorShortName"/>
        <result column="lessor_code" property="lessorCode"/>
        <result column="lessor_credit_code" property="lessorCreditCode"/>
        <result column="lessor_legal_person_code" property="lessorLegalPersonCode"/>
        <result column="lessor_tel" property="lessorTel"/>
        <result column="lessor_business_scope" property="lessorBusinessScope"/>
        <result column="lessor_org_id" property="lessorOrgId"/>
        <result column="lessor_org_name" property="lessorOrgName"/>
        <result column="lessor_parent_org_name" property="lessorParentOrgName"/>
        <result column="lessor_parent_org_id" property="lessorParentOrgId"/>
        <result column="status" property="status"/>
        <result column="create_by" property="createBy"/>
        <result column="create_date" property="createDate"/>
        <result column="update_by" property="updateBy"/>
        <result column="update_date" property="updateDate"/>
    </resultMap>
    <select id="findDepositoryList" resultType="com.testor.module.hire.entity.vo.HireDepositoryDto">
        SELECT
        a.id,
        a.lessor_org_id,
        a.lessor_org_name,
        a.lessor_parent_org_id,
        a.lessor_parent_org_name,
        a.lessor_short_name,
        b.depository_full_name,
        b.depository_address,
        c.access_lease_method_code,
        c.access_lease_method_name,
        c.access_lease_type_code,
        c.access_lease_type_name,
        c.access_lease_capacity,
        c.status AS access_status,
        c.access_hire_start_time,
        c.access_hire_end_time
        FROM
        t_hire_depository_manage_base a
        LEFT JOIN t_hire_depository_info b ON a.id = b.hire_depository_manage_base_id
        LEFT JOIN t_hire_depository_access_info c ON a.id = c.hire_depository_manage_base_id

        <where>
            <if test="param.orgCode!=null and param.orgCode!=''">
                AND a.lessor_org_id  = #{param.orgCode}
            </if>
            <if test="param.depositoryFullName!=null and param.depositoryFullName!=''">
                AND b.depository_full_name  like concat('%',#{param.depositoryFullName},'%')
            </if>
            <if test="param.depositoryAddress!=null and param.depositoryAddress!=''">
                AND b.depository_address   like concat('%', #{param.depositoryAddress},'%')
            </if>
            <if test="param.accessLeaseMethodCode!=null and param.accessLeaseMethodCode!=''">
                AND c.access_lease_method_code  = #{param.accessLeaseMethodCode}
            </if>
            <if test="param.accessLeaseTypeCode!=null and param.accessLeaseTypeCode!=''">
                AND  c.access_lease_type_code  = #{param.accessLeaseTypeCode}
            </if>
<!--            <if test="param.accessStatus!=null and param.accessStatus!=''">-->
<!--                AND c.status  = #{param.accessStatus}-->
<!--            </if>-->
            <if test="param.lessorShortName!=null and param.lessorShortName!=''">
                AND  a.lessor_short_name  like concat('%', #{param.lessorShortName},'%')
            </if>
            <if test="param.accessHireStartTime!=null and param.accessHireStartTime!=''">
                AND c.access_hire_end_time  &gt;= #{param.accessHireStartTime}
            </if>
            <if test="param.accessHireEndTime!=null and param.accessHireEndTime!=''">
                AND c.access_hire_end_time  &lt;=  #{param.accessHireEndTime}
            </if>

            <if test="param.accessStatus!=null and param.accessStatus!='' and param.accessStatus == 0 ">
                AND  c.access_hire_start_time  &lt;= NOW() AND c.access_hire_end_time  &gt;= NOW()
            </if>
            <if test="param.accessStatus!=null and param.accessStatus!='' and param.accessStatus == 2 ">
                AND ( c.access_hire_end_time  &lt;=  NOW() OR c.access_hire_end_time  IS NULL OR c.access_hire_start_time IS NULL )
            </if>
        </where>
    </select>

</mapper>
