<?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.iformall.mapper.WxDeviceMapper">
    <resultMap id="BaseResultMap" type="com.iformall.domain.po.WxDevice">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
        <result column="device_id" jdbcType="VARCHAR" property="deviceId"/>
        <result column="version" jdbcType="VARCHAR" property="version"/>
        <result column="location" jdbcType="VARCHAR" property="location"/>
        <result column="name" jdbcType="VARCHAR" property="name"/>
        <result column="type" jdbcType="INTEGER" property="type"/>
        <result column="status" jdbcType="INTEGER" property="status"/>
        <result column="create_date" jdbcType="TIMESTAMP" property="createDate"/>
        <result column="update_date" jdbcType="TIMESTAMP" property="updateDate"/>
        <result column="online_status" jdbcType="INTEGER" property="onlineStatus"/>
        <result column="first_hb_time" jdbcType="TIMESTAMP" property="firstHbTime"/>
        <result column="last_hb_time" jdbcType="TIMESTAMP" property="lastHbTime"/>
        <result column="hb_cmd" jdbcType="INTEGER" property="hbCmd"/>
        <result column="config" jdbcType="VARCHAR" property="config"/>
    </resultMap>

    <sql id="allColumns">
	    `id`, `tenant_id`, `device_id`, `type`, `status`, `location`, `name`, `version`, `create_date`, `update_date`, `online_status`, `first_hb_time`, `last_hb_time`, `hb_cmd`, `config`
	</sql>

    <sql id="dynamicWhereConditions">
        where 1 = 1

        <if test=" null != id ">
            and `id` = #{id}
        </if>

        <if test=" null != tenantId ">
            and `tenant_id` = #{tenantId}
        </if>

        <if test=" null != deviceId ">
            and `device_id` like concat('%', #{deviceId},'%')

        </if>
        <if test=" null != version ">
            and `version` like concat('%', #{version},'%')

        </if>
        <if test=" null != location ">
            and `location` like concat('%', #{location},'%')

        </if>
        <if test=" null != name ">
            and `name` like concat('%', #{name},'%')

        </if>

        <if test=" null != type ">
            and `type` = #{type}
        </if>

        <if test=" null != status ">
            and `status` = #{status}
        </if>

        <if test=" null != createDate ">
            and `create_date` = #{createDate}
        </if>

        <if test=" null != updateDate ">
            and `update_date` = #{updateDate}
        </if>

        <if test=" null != onlineStatus ">
            and `online_status` = #{onlineStatus}
        </if>

        <if test=" null != firstHbTime ">
            and `first_hb_time` = #{firstHbTime}
        </if>

        <if test=" null != lastHbTime ">
            and `last_hb_time` = #{lastHbTime}
        </if>

        <if test=" null != hbCmd ">
            and `hb_cmd` = #{hbCmd}
        </if>

        <if test=" null != config ">
            and `config` = #{config}
        </if>


        <if test=" null != ids ">
            and id in
            <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")">
                #{idItem}
            </foreach>
        </if>
        <if test=" null != sortColumns">order by ${sortColumns}</if>
    </sql>

    <select id="findList" parameterType="com.iformall.domain.po.WxDevice" resultMap="BaseResultMap">
        select
        <include refid="allColumns"/>
        from wx_device
        <include refid="dynamicWhereConditions"/>
    </select>


</mapper>
