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

    <!-- 关联查询sql -->
    <sql id="selectSql">
        SELECT a.*
        FROM tower_accessory a
        <where>
            <if test="param.accessoryId != null">
                AND a.accessory_id = #{param.accessoryId}
            </if>
            <if test="param.accessoryName != null">
                AND a.accessory_name LIKE CONCAT('%', #{param.accessoryName}, '%')
            </if>
            <if test="param.accessoryCategory != null">
                AND a.accessory_category LIKE CONCAT('%', #{param.accessoryCategory}, '%')
            </if>
            <if test="param.accessoryModel != null">
                AND a.accessory_model LIKE CONCAT('%', #{param.accessoryModel}, '%')
            </if>
            <if test="param.accessorySpecs != null">
                AND a.accessory_specs LIKE CONCAT('%', #{param.accessorySpecs}, '%')
            </if>
            <if test="param.accessoryPrice != null">
                AND a.accessory_price = #{param.accessoryPrice}
            </if>
            <if test="param.accessoryUnit != null">
                AND a.accessory_unit LIKE CONCAT('%', #{param.accessoryUnit}, '%')
            </if>
            <if test="param.accessoryStock != null">
                AND a.accessory_stock LIKE CONCAT('%', #{param.accessoryStock}, '%')
            </if>
            <if test="param.companyName != null">
                AND a.company_name LIKE CONCAT('%', #{param.companyName}, '%')
            </if>
            <if test="param.manufactor != null">
                AND a.manufactor LIKE CONCAT('%', #{param.manufactor}, '%')
            </if>
            <if test="param.manufactorNo != null">
                AND a.manufactor_no LIKE CONCAT('%', #{param.manufactorNo}, '%')
            </if>
            <if test="param.lifeYear != null">
                AND a.life_year LIKE CONCAT('%', #{param.lifeYear}, '%')
            </if>
            <if test="param.factoryDate != null">
                AND a.factory_date LIKE CONCAT('%', #{param.factoryDate}, '%')
            </if>
            <if test="param.scrapDate != null">
                AND a.scrap_date LIKE CONCAT('%', #{param.scrapDate}, '%')
            </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>
          <if test="param.keywords != null">
            AND (
            a.accessory_name LIKE CONCAT('%', #{param.keywords}, '%')
            OR a.accessory_no LIKE CONCAT('%', #{param.keywords}, '%')
            OR a.company_name LIKE CONCAT('%', #{param.keywords}, '%')
            )
          </if>
        </where>
    </sql>

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

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

</mapper>
