<?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.xunmei.system.mapper.SysDeviceMapper">

    <resultMap type="com.xunmei.system.api.domain.SysDevice" id="SysDeviceResult">
        <result property="id" column="id"/>
        <result property="orgId" column="org_id"/>
        <result property="orgName" column="org_name"/>
        <result property="deviceName" column="device_name"/>
        <result property="assetType" column="asset_type"/>
        <result property="deviceType" column="device_type"/>
        <result property="deviceBrand" column="device_brand"/>
        <result property="checkTime" column="check_time"/>
        <result property="maintenanceTerm" column="maintenance_term"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
        <result property="createBy" column="create_by"/>
        <result property="updateBy" column="update_by"/>
        <result property="delFlag" column="del_flag"/>
        <result property="hostId" column="host_id"/>
        <result property="channel" column="channel"/>
    </resultMap>

    <sql id="selectSysDeviceVo">
        select id,
               org_id,
               org_name,
               device_name,
               asset_type,
               device_type,
               device_brand,
               check_time,
               maintenance_term,
               create_time,
               update_time,
               create_by,
               update_by,
               del_flag,
               host_id,
               channel
        from sys_device
    </sql>

    <select id="selectSysDeviceList" parameterType="com.xunmei.system.api.domain.SysDevice"
            resultMap="SysDeviceResult">
        <include refid="selectSysDeviceVo"/>
        <where>
            <if test="orgId != null ">
                and org_id = #{orgId}
            </if>
            <if test="orgName != null  and orgName != ''">
                and org_name like concat('%', #{orgName}, '%')
            </if>
            <if test="deviceName != null  and deviceName != ''">
                and device_name like concat('%', #{deviceName}, '%')
            </if>
            <if test="assetType != null  and assetType != ''">
                and asset_type = #{assetType}
            </if>
            <if test="deviceType != null  and deviceType != ''">
                and device_type = #{deviceType}
            </if>
            <if test="deviceBrand != null  and deviceBrand != ''">
                and device_brand = #{deviceBrand}
            </if>
            <if test="checkTime != null ">
                and check_time = #{checkTime}
            </if>
            <if test="maintenanceTerm != null  and maintenanceTerm != ''">
                and maintenance_term = #{maintenanceTerm}
            </if>
            <if test="hostId != null ">
                and host_id = #{hostId}
            </if>
            <if test="channel != null ">
                and channel = #{channel}
            </if>
        </where>
    </select>

    <select id="selectSysDeviceById" parameterType="Long"
            resultMap="SysDeviceResult">
        <include refid="selectSysDeviceVo"/>
        where id = #{id}
    </select>
    <select id="getHostByOrgId" resultType="com.xunmei.system.api.domain.SysDevice">
        <include refid="selectSysDeviceVo"/>
        WHERE
        org_id =#{orgId} and del_flag='0' and device_type='0'
    </select>

    <insert id="insertSysDevice" parameterType="com.xunmei.system.api.domain.SysDevice">
        insert into sys_device
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,
            </if>
            <if test="orgId != null">org_id,
            </if>
            <if test="orgName != null">org_name,
            </if>
            <if test="deviceName != null">device_name,
            </if>
            <if test="assetType != null">asset_type,
            </if>
            <if test="deviceType != null">device_type,
            </if>
            <if test="deviceBrand != null">device_brand,
            </if>
            <if test="checkTime != null">check_time,
            </if>
            <if test="maintenanceTerm != null">maintenance_term,
            </if>
            <if test="createTime != null">create_time,
            </if>
            <if test="updateTime != null">update_time,
            </if>
            <if test="createBy != null">create_by,
            </if>
            <if test="updateBy != null">update_by,
            </if>
            <if test="delFlag != null">del_flag,
            </if>
            <if test="hostId != null">host_id,
            </if>
            <if test="channel != null">channel,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},
            </if>
            <if test="orgId != null">#{orgId},
            </if>
            <if test="orgName != null">#{orgName},
            </if>
            <if test="deviceName != null">#{deviceName},
            </if>
            <if test="assetType != null">#{assetType},
            </if>
            <if test="deviceType != null">#{deviceType},
            </if>
            <if test="deviceBrand != null">#{deviceBrand},
            </if>
            <if test="checkTime != null">#{checkTime},
            </if>
            <if test="maintenanceTerm != null">#{maintenanceTerm},
            </if>
            <if test="createTime != null">#{createTime},
            </if>
            <if test="updateTime != null">#{updateTime},
            </if>
            <if test="createBy != null">#{createBy},
            </if>
            <if test="updateBy != null">#{updateBy},
            </if>
            <if test="delFlag != null">#{delFlag},
            </if>
            <if test="hostId != null">#{hostId},
            </if>
            <if test="channel != null">#{channel},
            </if>
        </trim>
    </insert>

    <update id="updateSysDevice" parameterType="com.xunmei.system.api.domain.SysDevice">
        update sys_device
        <trim prefix="SET" suffixOverrides=",">
            <if test="orgId != null">org_id =
                #{orgId},
            </if>
            <if test="orgName != null">org_name =
                #{orgName},
            </if>
            <if test="deviceName != null">device_name =
                #{deviceName},
            </if>
            <if test="assetType != null">asset_type =
                #{assetType},
            </if>
            <if test="deviceType != null">device_type =
                #{deviceType},
            </if>
            <if test="deviceBrand != null">device_brand =
                #{deviceBrand},
            </if>
            <if test="checkTime != null">check_time =
                #{checkTime},
            </if>
            <if test="maintenanceTerm != null">maintenance_term =
                #{maintenanceTerm},
            </if>
            <if test="createTime != null">create_time =
                #{createTime},
            </if>
            <if test="updateTime != null">update_time =
                #{updateTime},
            </if>
            <if test="createBy != null">create_by =
                #{createBy},
            </if>
            <if test="updateBy != null">update_by =
                #{updateBy},
            </if>
            <if test="delFlag != null">del_flag =
                #{delFlag},
            </if>
            <if test="hostId != null">host_id =
                #{hostId},
            </if>
            <if test="channel != null">channel =
                #{channel},
            </if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSysDeviceById" parameterType="Long">
        delete
        from sys_device
        where id = #{id}
    </delete>

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