<?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.inspect.metadata.bdconfig.mapper.BasedataBdConfigDeviceConvertMapper">

    <resultMap type="BasedataBdConfigDeviceConvert" id="BasedataBdConfigDeviceConvertResult">
        <result property="deviceConvertId" column="device_convert_id"/>
        <result property="mainSystemCode" column="main_system_code"/>
        <result property="mainSystemName" column="main_system_name"/>
        <result property="manufacturerCode" column="manufacturer_code"/>
        <result property="manufacturerName" column="manufacturer_name"/>
        <result property="deviceId" column="device_id"/>
        <result property="deviceCode" column="device_code"/>
        <result property="originalDeviceCode" column="original_device_code"/>
        <result property="delFlag" column="del_flag"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="deviceName" column="device_name"/>
        <result property="deviceLevel" column="device_level"/>
    </resultMap>

    <sql id="selectBasedataBdConfigDeviceConvertVo">
        select device_convert_id,
               main_system_code,
               main_system_name,
               manufacturer_code,
               manufacturer_name,
               device_id,
               device_code,
               original_device_code,
               del_flag,
               create_by,
               create_time,
               update_by,
               update_time,
               device_name,
               device_level
        from basedata_bdconfig_device_convert
    </sql>

    <select id="selectBasedataBdConfigDeviceConvertList" parameterType="BasedataBdConfigDeviceConvert"
            resultMap="BasedataBdConfigDeviceConvertResult">
        <include refid="selectBasedataBdConfigDeviceConvertVo"/>
        <where>
            <if test="mainSystemCode != null  and mainSystemCode != ''">and main_system_code = #{mainSystemCode}</if>
            <if test="mainSystemName != null  and mainSystemName != ''">and main_system_name like concat('%',
                #{mainSystemName}, '%')
            </if>
            <if test="manufacturerCode != null  and manufacturerCode != ''">and manufacturer_code =
                #{manufacturerCode}
            </if>
            <if test="manufacturerName != null  and manufacturerName != ''">and manufacturer_name like concat('%',
                #{manufacturerName}, '%')
            </if>
            <if test="deviceId != null ">and device_id = #{deviceId}</if>
            <if test="deviceCode != null  and deviceCode != ''">and device_code = #{deviceCode}</if>
            <if test="originalDeviceCode != null  and originalDeviceCode != ''">and original_device_code =
                #{originalDeviceCode}
            </if>
            <if test="deviceName != null  and deviceName != ''">and device_name like concat('%', #{deviceName}, '%')
            </if>
            <if test="deviceLevel != null  and deviceLevel != ''">and device_level = #{deviceLevel}</if>
        </where>
    </select>

    <select id="selectBasedataBdConfigDeviceConvertByDeviceConvertId" parameterType="Long"
            resultMap="BasedataBdConfigDeviceConvertResult">
        <include refid="selectBasedataBdConfigDeviceConvertVo"/>
        where device_convert_id = #{deviceConvertId}
    </select>

    <insert id="insertBasedataBdConfigDeviceConvert" parameterType="BasedataBdConfigDeviceConvert"
            useGeneratedKeys="true" keyProperty="deviceConvertId">
        insert into basedata_bdconfig_device_convert
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="mainSystemCode != null and mainSystemCode != ''">main_system_code,</if>
            <if test="mainSystemName != null">main_system_name,</if>
            <if test="manufacturerCode != null and manufacturerCode != ''">manufacturer_code,</if>
            <if test="manufacturerName != null">manufacturer_name,</if>
            <if test="deviceId != null">device_id,</if>
            <if test="deviceCode != null">device_code,</if>
            <if test="originalDeviceCode != null">original_device_code,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="deviceName != null">device_name,</if>
            <if test="deviceLevel != null">device_level,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="mainSystemCode != null and mainSystemCode != ''">#{mainSystemCode},</if>
            <if test="mainSystemName != null">#{mainSystemName},</if>
            <if test="manufacturerCode != null and manufacturerCode != ''">#{manufacturerCode},</if>
            <if test="manufacturerName != null">#{manufacturerName},</if>
            <if test="deviceId != null">#{deviceId},</if>
            <if test="deviceCode != null">#{deviceCode},</if>
            <if test="originalDeviceCode != null">#{originalDeviceCode},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="deviceName != null">#{deviceName},</if>
            <if test="deviceLevel != null">#{deviceLevel},</if>
        </trim>
    </insert>

    <update id="updateBasedataBdConfigDeviceConvert" parameterType="BasedataBdConfigDeviceConvert">
        update basedata_bdconfig_device_convert
        <trim prefix="SET" suffixOverrides=",">
            <if test="mainSystemCode != null and mainSystemCode != ''">main_system_code = #{mainSystemCode},</if>
            <if test="mainSystemName != null">main_system_name = #{mainSystemName},</if>
            <if test="manufacturerCode != null and manufacturerCode != ''">manufacturer_code = #{manufacturerCode},</if>
            <if test="manufacturerName != null">manufacturer_name = #{manufacturerName},</if>
            <if test="deviceId != null">device_id = #{deviceId},</if>
            <if test="deviceCode != null">device_code = #{deviceCode},</if>
            <if test="originalDeviceCode != null">original_device_code = #{originalDeviceCode},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="deviceName != null">device_name = #{deviceName},</if>
            <if test="deviceLevel != null">device_level = #{deviceLevel},</if>
        </trim>
        where device_convert_id = #{deviceConvertId}
    </update>

    <delete id="deleteBasedataBdConfigDeviceConvertByDeviceConvertId" parameterType="Long">
        delete
        from basedata_bdconfig_device_convert
        where device_convert_id = #{deviceConvertId}
    </delete>

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