select
a.id,
a.organization_id,
a.organization_name,
a.top_organization_id,
a.warehouse_id,
COALESCE(w.warehouse_name, a.warehouse_name) as warehouse_name,
a.shipper_id,
a.cargo_owner_name,
a.lease_type,
a.lease_area,
a.start_date,
a.end_date,
a.remark,
a.create_time,
a.create_by,
a.create_by_name,
a.update_time,
a.update_by,
a.update_by_name,
a.del_flag
from lease a
LEFT JOIN warehouse w ON a.warehouse_id = w.warehouse_id AND w.del_flag = 1
and a.organization_id = #{organizationId}
and a.top_organization_id = #{topOrganizationId}
and a.organization_name like concat('%', #{organizationName}, '%')
and a.warehouse_id = #{warehouseId}
and (w.warehouse_name like concat('%', #{warehouseName}, '%') or a.warehouse_name like concat('%', #{warehouseName}, '%'))
and a.cargo_owner_name like concat('%', #{cargoOwnerName}, '%')
and a.lease_type = #{leaseType}
and a.create_time = #{createTime}
and a.lease_area = #{leaseArea}
and a.remark like concat('%', #{remark}, '%')
and a.create_by_name like concat('%', #{createByName}, '%')
and a.update_by_name like concat('%', #{updateByName}, '%')
and date_format(a.create_time,'%Y-%m-%d') >= #{createTimeStart}
and date_format(a.create_time,'%Y-%m-%d') <= #{createTimeEnd}
and date_format(a.update_time,'%Y-%m-%d') >= #{updateTimeStart}
and date_format(a.update_time,'%Y-%m-%d') <= #{updateTimeEnd}
and a.start_date >= #{startDate} and a.start_date <= #{endDate}
AND a.start_date <= #{time}
AND a.end_date >= #{time}
and a.del_flag = #{delFlag} and a.del_flag = 1