<?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.prodevmnt.mapper.BasedataModelDeviceMapper">

    <resultMap type="BasedataModelDevice" id="BasedataModelDeviceResult">
        <result property="modelDeviceId" column="model_device_id"/>
        <result property="deviceId" column="device_id"/>
        <result property="deviceCode" column="device_code"/>
        <result property="deviceName" column="device_name"/>
        <result property="modelType" column="model_type"/>
        <result property="status" column="status"/>
        <result property="positionX" column="position_x"/>
        <result property="positionY" column="position_y"/>
        <result property="positionZ" column="position_z"/>
        <result property="deviceLength" column="device_length"/>
        <result property="deviceWidth" column="device_width"/>
        <result property="deviceHigh" column="device_high"/>
        <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"/>
    </resultMap>

    <sql id="selectBasedataModelDeviceVo">
        select model_device_id,
               device_id,
               device_code,
               device_name,
               model_type,
               status,
               position_x,
               position_y,
               position_z,
               device_length,
               device_width,
               device_high,
               del_flag,
               create_by,
               create_time,
               update_by,
               update_time
        from basedata_device_model
    </sql>

    <select id="selectBasedataModelDeviceList" parameterType="BasedataModelDevice"
            resultMap="BasedataModelDeviceResult">
        <include refid="selectBasedataModelDeviceVo"/>
        <where>
            <if test="deviceId != null">and device_id = #{deviceId}</if>
            <if test="deviceCode != null  and deviceCode != ''">and device_code = #{deviceCode}</if>
            <if test="deviceName != null  and deviceName != ''">and device_name like concat('%', #{deviceName}, '%')
            </if>
            <if test="modelType != null  and modelType != ''">and model_type = #{modelType}</if>
            <if test="status != null  and status != ''">and status = #{status}</if>
        </where>
    </select>

    <select id="selectBasedataModelDeviceByModelDeviceId" parameterType="String" resultMap="BasedataModelDeviceResult">
        <include refid="selectBasedataModelDeviceVo"/>
        where model_device_id = #{modelDeviceId}
    </select>

    <insert id="insertBasedataModelDevice" parameterType="BasedataModelDevice" useGeneratedKeys="true"
            keyProperty="modelDeviceId">
        insert into basedata_device_model
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="deviceId != null">device_id,</if>
            <if test="deviceCode != null">device_code,</if>
            <if test="deviceName != null">device_name,</if>
            <if test="modelType != null">model_type,</if>
            <if test="status != null">status,</if>
            <if test="positionX != null">position_x,</if>
            <if test="positionY != null">position_y,</if>
            <if test="positionZ != null">position_z,</if>
            <if test="deviceLength != null">device_length,</if>
            <if test="deviceWidth != null">device_width,</if>
            <if test="deviceHigh != null">device_high,</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>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="deviceId != null">#{deviceId},</if>
            <if test="deviceCode != null">#{deviceCode},</if>
            <if test="deviceName != null">#{deviceName},</if>
            <if test="modelType != null">#{modelType},</if>
            <if test="status != null">#{status},</if>
            <if test="positionX != null">#{positionX},</if>
            <if test="positionY != null">#{positionY},</if>
            <if test="positionZ != null">#{positionZ},</if>
            <if test="deviceLength != null">#{deviceLength},</if>
            <if test="deviceWidth != null">#{deviceWidth},</if>
            <if test="deviceHigh != null">#{deviceHigh},</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>
        </trim>
    </insert>

    <update id="updateBasedataModelDevice" parameterType="BasedataModelDevice">
        update basedata_device_model
        <trim prefix="SET" suffixOverrides=",">
            <if test="deviceId != null">device_id = #{deviceId},</if>
            <if test="deviceCode != null">device_code = #{deviceCode},</if>
            <if test="deviceName != null">device_name = #{deviceName},</if>
            <if test="modelType != null">model_type = #{modelType},</if>
            <if test="status != null">status = #{status},</if>
            <if test="positionX != null">position_x = #{positionX},</if>
            <if test="positionY != null">position_y = #{positionY},</if>
            <if test="positionZ != null">position_z = #{positionZ},</if>
            <if test="deviceLength != null">device_length = #{deviceLength},</if>
            <if test="deviceWidth != null">device_width = #{deviceWidth},</if>
            <if test="deviceHigh != null">device_high = #{deviceHigh},</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>
        </trim>
        where model_device_id = #{modelDeviceId}
    </update>

    <delete id="deleteBasedataModelDeviceByModelDeviceId" parameterType="String">
        delete
        from basedata_device_model
        where model_device_id = #{modelDeviceId}
    </delete>

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