<?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.TowerFallMapper">

    <!-- 关联查询sql -->
    <sql id="selectSql">
        SELECT a.*,b.company_name as companyName
        FROM tower_fall a
        left join sys_company b on a.company_id = b.company_id
        <where>
            <if test="param.id != null">
                AND a.id = #{param.id}
            </if>
            <if test="param.keywords != null">
                AND (
                a.factory LIKE CONCAT('%', #{param.keywords}, '%') or
                a.code LIKE CONCAT('%', #{param.keywords}, '%') or
                a.model LIKE CONCAT('%', #{param.keywords}, '%')
                )
            </if>
            <if test="param.code != null">
                AND a.code LIKE CONCAT('%', #{param.code}, '%')
            </if>
            <if test="param.model != null">
                AND a.model LIKE CONCAT('%', #{param.model}, '%')
            </if>
            <if test="param.factory != null">
                AND a.factory LIKE CONCAT('%', #{param.factory}, '%')
            </if>
            <if test="param.companyId != null">
                AND a.company_id LIKE CONCAT('%', #{param.companyId}, '%')
            </if>
            <if test="param.factoryDate != null">
                AND a.factory_date LIKE CONCAT('%', #{param.factoryDate}, '%')
            </if>
            <if test="param.discardDate != null">
                AND a.discard_date LIKE CONCAT('%', #{param.discardDate}, '%')
            </if>
            <if test="param.file1 != null">
                AND a.file1 LIKE CONCAT('%', #{param.file1}, '%')
            </if>
            <if test="param.file2 != null">
                AND a.file2 LIKE CONCAT('%', #{param.file2}, '%')
            </if>
            <if test="param.file3 != null">
                AND a.file3 LIKE CONCAT('%', #{param.file3}, '%')
            </if>
            <if test="param.file4 != null">
                AND a.file4 LIKE CONCAT('%', #{param.file4}, '%')
            </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.sortNumber != null">
                AND a.sort_number = #{param.sortNumber}
            </if>
            <if test="param.userId != null">
                AND a.user_id = #{param.userId}
            </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>
        </where>
    </sql>

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

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

</mapper>
