<?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.ruoyi.basetyre.mapper.BaseDeviceMapper">
    
    <resultMap type="BaseDevice" id="BaseDeviceResult">
        <result property="id"    column="id"    />
        <result property="tyreFacCode"    column="tyre_fac_code"    />
        <result property="companyCode"    column="company_code"    />
        <result property="internetThingsNo"    column="internet_things_no"    />
        <result property="simCode"    column="sim_code"    />
        <result property="deviceType"    column="device_type"    />
        <result property="state"    column="state"    />
        <result property="activeTime"    column="active_time"    />
        <result property="lastRunTime"    column="last_run_time"    />
        <result property="isDelete"    column="is_delete"    />
        <result property="createTime"    column="create_time"    />
        <result property="createId"    column="create_id"    />
        <result property="createBy"    column="create_by"    />
        <result property="createName"    column="create_name"    />
        <result property="modifyTime"    column="modify_time"    />
        <result property="modifyId"    column="modify_id"    />
        <result property="modifyBy"    column="modify_by"    />
        <result property="modifyName"    column="modify__name"    />
    </resultMap>

    <sql id="selectBaseDeviceVo">
        select id, tyre_fac_code, company_code, internet_things_no, sim_code, device_type, state, active_time, last_run_time, is_delete, create_time, create_id, create_by, create_name, modify_time, modify_id, modify_by, modify__name from base_device
    </sql>

    <select id="selectBaseDeviceList" parameterType="BaseDevice" resultMap="BaseDeviceResult">
        <include refid="selectBaseDeviceVo"/>
        <where>  
            <if test="tyreFacCode != null  and tyreFacCode != ''"> and tyre_fac_code = #{tyreFacCode}</if>
            <if test="companyCode != null  and companyCode != ''"> and company_code = #{companyCode}</if>
            <if test="internetThingsNo != null  and internetThingsNo != ''"> and internet_things_no = #{internetThingsNo}</if>
            <if test="simCode != null  and simCode != ''"> and sim_code = #{simCode}</if>
            <if test="deviceType != null "> and device_type = #{deviceType}</if>
            <if test="state != null "> and state = #{state}</if>
            <if test="activeTime != null "> and active_time = #{activeTime}</if>
            <if test="lastRunTime != null "> and last_run_time = #{lastRunTime}</if>
            <if test="isDelete != null "> and is_delete = #{isDelete}</if>
            <if test="createId != null  and createId != ''"> and create_id = #{createId}</if>
            <if test="createName != null  and createName != ''"> and create_name like concat('%', #{createName}, '%')</if>
            <if test="modifyTime != null "> and modify_time = #{modifyTime}</if>
            <if test="modifyId != null  and modifyId != ''"> and modify_id = #{modifyId}</if>
            <if test="modifyBy != null  and modifyBy != ''"> and modify_by = #{modifyBy}</if>
            <if test="modifyName != null  and modifyName != ''"> and modify__name like concat('%', #{modifyName}, '%')</if>
        </where>
    </select>
    
    <select id="selectBaseDeviceById" parameterType="String" resultMap="BaseDeviceResult">
        <include refid="selectBaseDeviceVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertBaseDevice" parameterType="BaseDevice">
        insert into base_device
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="tyreFacCode != null">tyre_fac_code,</if>
            <if test="companyCode != null">company_code,</if>
            <if test="internetThingsNo != null">internet_things_no,</if>
            <if test="simCode != null">sim_code,</if>
            <if test="deviceType != null">device_type,</if>
            <if test="state != null">state,</if>
            <if test="activeTime != null">active_time,</if>
            <if test="lastRunTime != null">last_run_time,</if>
            <if test="isDelete != null">is_delete,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createId != null">create_id,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createName != null">create_name,</if>
            <if test="modifyTime != null">modify_time,</if>
            <if test="modifyId != null">modify_id,</if>
            <if test="modifyBy != null">modify_by,</if>
            <if test="modifyName != null">modify__name,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="tyreFacCode != null">#{tyreFacCode},</if>
            <if test="companyCode != null">#{companyCode},</if>
            <if test="internetThingsNo != null">#{internetThingsNo},</if>
            <if test="simCode != null">#{simCode},</if>
            <if test="deviceType != null">#{deviceType},</if>
            <if test="state != null">#{state},</if>
            <if test="activeTime != null">#{activeTime},</if>
            <if test="lastRunTime != null">#{lastRunTime},</if>
            <if test="isDelete != null">#{isDelete},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createId != null">#{createId},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createName != null">#{createName},</if>
            <if test="modifyTime != null">#{modifyTime},</if>
            <if test="modifyId != null">#{modifyId},</if>
            <if test="modifyBy != null">#{modifyBy},</if>
            <if test="modifyName != null">#{modifyName},</if>
         </trim>
    </insert>

    <update id="updateBaseDevice" parameterType="BaseDevice">
        update base_device
        <trim prefix="SET" suffixOverrides=",">
            <if test="tyreFacCode != null">tyre_fac_code = #{tyreFacCode},</if>
            <if test="companyCode != null">company_code = #{companyCode},</if>
            <if test="internetThingsNo != null">internet_things_no = #{internetThingsNo},</if>
            <if test="simCode != null">sim_code = #{simCode},</if>
            <if test="deviceType != null">device_type = #{deviceType},</if>
            <if test="state != null">state = #{state},</if>
            <if test="activeTime != null">active_time = #{activeTime},</if>
            <if test="lastRunTime != null">last_run_time = #{lastRunTime},</if>
            <if test="isDelete != null">is_delete = #{isDelete},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createId != null">create_id = #{createId},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createName != null">create_name = #{createName},</if>
            <if test="modifyTime != null">modify_time = #{modifyTime},</if>
            <if test="modifyId != null">modify_id = #{modifyId},</if>
            <if test="modifyBy != null">modify_by = #{modifyBy},</if>
            <if test="modifyName != null">modify__name = #{modifyName},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteBaseDeviceById" parameterType="String">
        delete from base_device where id = #{id}
    </delete>

    <delete id="deleteBaseDeviceByIds" parameterType="String">
        delete from base_device where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>