<?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.gxwebsoft.tower.mapper.TowerWarehouseMapper">

    <!-- 关联查询sql -->
    <sql id="selectSql">
        SELECT a.*
        FROM tower_warehouse a
        <where>
            <if test="param.warehouseId != null">
                AND a.warehouse_id = #{param.warehouseId}
            </if>
            <if test="param.warehouseName != null">
                AND a.warehouse_name LIKE CONCAT('%', #{param.warehouseName}, '%')
            </if>
            <if test="param.warehouseKeeper != null">
                AND a.warehouse_keeper LIKE CONCAT('%', #{param.warehouseKeeper}, '%')
            </if>
            <if test="param.warehousePhone != null">
                AND a.warehouse_phone LIKE CONCAT('%', #{param.warehousePhone}, '%')
            </if>
            <if test="param.longitude != null">
                AND a.longitude LIKE CONCAT('%', #{param.longitude}, '%')
            </if>
            <if test="param.latitude != null">
                AND a.latitude LIKE CONCAT('%', #{param.latitude}, '%')
            </if>
            <if test="param.country != null">
                AND a.country LIKE CONCAT('%', #{param.country}, '%')
            </if>
            <if test="param.province != null">
                AND a.province LIKE CONCAT('%', #{param.province}, '%')
            </if>
            <if test="param.city != null">
                AND a.city LIKE CONCAT('%', #{param.city}, '%')
            </if>
            <if test="param.region != null">
                AND a.region LIKE CONCAT('%', #{param.region}, '%')
            </if>
            <if test="param.address != null">
                AND a.address LIKE CONCAT('%', #{param.address}, '%')
            </if>
            <if test="param.regionName != null">
                AND a.region_name LIKE CONCAT('%', #{param.regionName}, '%')
            </if>
            <if test="param.status != null">
                AND a.status = #{param.status}
            </if>
            <if test="param.comments != null">
                AND a.comments LIKE CONCAT('%', #{param.comments}, '%')
            </if>
<!--            <if test="param.username != null">-->
<!--                AND a.username = #{param.username}-->
<!--            </if>-->
            <if test="param.deleted != null">
                AND a.deleted = #{param.deleted}
            </if>
            <if test="param.deleted == null">
                AND a.deleted = 0
            </if>
            <if test="param.createTimeStart != null">
                AND a.create_time &gt;= #{param.createTimeStart}
            </if>
            <if test="param.createTimeEnd != null">
                AND a.create_time &lt;= #{param.createTimeEnd}
            </if>
            <if test="param.keywords != null">
              AND (a.title LIKE CONCAT('%', #{param.keywords}, '%')
              OR a.warehouse_name = #{param.keywords
              OR a.warehouse_keeper = #{param.keywords}
              OR a.warehouse_phone = #{param.keywords}
              )
            </if>
        </where>
    </sql>

    <!-- 分页查询 -->
    <select id="selectPageRel" resultType="com.gxwebsoft.tower.entity.TowerWarehouse">
        <include refid="selectSql"></include>
    </select>

    <!-- 查询全部 -->
    <select id="selectListRel" resultType="com.gxwebsoft.tower.entity.TowerWarehouse">
        <include refid="selectSql"></include>
    </select>

</mapper>
