<?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.business.mapper.HwDeviceModeFunctionMapper">
    
    <resultMap type="HwDeviceModeFunction" id="HwDeviceModeFunctionResult">
        <result property="modeFunctionId"    column="mode_function_id"    />
        <result property="deviceModeId"    column="device_mode_id"    />
        <result property="functionMode"    column="function_mode"    />
        <result property="coordinate"    column="coordinate"    />
        <result property="functionName"    column="function_name"    />
        <result property="functionIdentifier"    column="function_identifier"    />
        <result property="functionType"    column="function_type"    />
        <result property="dataType"    column="data_type"    />
        <result property="dataDefinition"    column="data_definition"    />
        <result property="functionFormula"    column="function_formula"    />
        <result property="propertyUnit"    column="property_unit"    />
        <result property="displayFlag"    column="display_flag"    />
        <result property="rwFlag"    column="rw_flag"    />
        <result property="invokeMethod"    column="invoke_method"    />
        <result property="eventType"    column="event_type"    />
        <result property="remark"    column="remark"    />
        <result property="acquisitionFormula"    column="acquisition_formula"    />
        <result property="orderFlag"    column="order_flag"    />
        <result property="deviceRegister"    column="device_register"    />
        <result property="propertyStep"    column="property_step"    />
        <result property="propertyField"    column="property_field"    />
    </resultMap>

    <sql id="selectHwDeviceModeFunctionVo">
        select mode_function_id, device_mode_id, function_mode, coordinate, function_name, function_identifier, function_type, data_type, data_definition, function_formula, property_unit, display_flag, rw_flag, invoke_method, event_type, remark, acquisition_formula, order_flag, device_register, property_step, property_field from hw_device_mode_function
    </sql>

    <select id="selectHwDeviceModeFunctionList" parameterType="HwDeviceModeFunction" resultMap="HwDeviceModeFunctionResult">
        <include refid="selectHwDeviceModeFunctionVo"/>
        <where>  
            <if test="deviceModeId != null "> and device_mode_id = #{deviceModeId}</if>
            <if test="functionMode != null  and functionMode != ''"> and function_mode = #{functionMode}</if>
            <if test="coordinate != null  and coordinate != ''"> and coordinate = #{coordinate}</if>
            <if test="functionName != null  and functionName != ''"> and function_name like concat('%', #{functionName}, '%')</if>
            <if test="functionIdentifier != null  and functionIdentifier != ''"> and function_identifier = #{functionIdentifier}</if>
            <if test="functionType != null  and functionType != ''"> and function_type = #{functionType}</if>
            <if test="dataType != null "> and data_type = #{dataType}</if>
            <if test="dataDefinition != null  and dataDefinition != ''"> and data_definition = #{dataDefinition}</if>
            <if test="functionFormula != null  and functionFormula != ''"> and function_formula = #{functionFormula}</if>
            <if test="propertyUnit != null  and propertyUnit != ''"> and property_unit = #{propertyUnit}</if>
            <if test="displayFlag != null  and displayFlag != ''"> and display_flag = #{displayFlag}</if>
            <if test="rwFlag != null  and rwFlag != ''"> and rw_flag = #{rwFlag}</if>
            <if test="invokeMethod != null  and invokeMethod != ''"> and invoke_method = #{invokeMethod}</if>
            <if test="eventType != null  and eventType != ''"> and event_type = #{eventType}</if>
            <if test="acquisitionFormula != null  and acquisitionFormula != ''"> and acquisition_formula = #{acquisitionFormula}</if>
            <if test="orderFlag != null "> and order_flag = #{orderFlag}</if>
            <if test="deviceRegister != null  and deviceRegister != ''"> and device_register = #{deviceRegister}</if>
            <if test="propertyStep != null "> and property_step = #{propertyStep}</if>
            <if test="propertyField != null  and propertyField != ''"> and property_field = #{propertyField}</if>
        </where>
    </select>
    
    <select id="selectHwDeviceModeFunctionByModeFunctionId" parameterType="Long" resultMap="HwDeviceModeFunctionResult">
        <include refid="selectHwDeviceModeFunctionVo"/>
        where mode_function_id = #{modeFunctionId}
    </select>
        
    <insert id="insertHwDeviceModeFunction" parameterType="HwDeviceModeFunction" useGeneratedKeys="true" keyProperty="modeFunctionId">
        insert into hw_device_mode_function
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="deviceModeId != null">device_mode_id,</if>
            <if test="functionMode != null and functionMode != ''">function_mode,</if>
            <if test="coordinate != null">coordinate,</if>
            <if test="functionName != null and functionName != ''">function_name,</if>
            <if test="functionIdentifier != null and functionIdentifier != ''">function_identifier,</if>
            <if test="functionType != null">function_type,</if>
            <if test="dataType != null">data_type,</if>
            <if test="dataDefinition != null">data_definition,</if>
            <if test="functionFormula != null">function_formula,</if>
            <if test="propertyUnit != null">property_unit,</if>
            <if test="displayFlag != null">display_flag,</if>
            <if test="rwFlag != null">rw_flag,</if>
            <if test="invokeMethod != null">invoke_method,</if>
            <if test="eventType != null">event_type,</if>
            <if test="remark != null">remark,</if>
            <if test="acquisitionFormula != null">acquisition_formula,</if>
            <if test="orderFlag != null">order_flag,</if>
            <if test="deviceRegister != null">device_register,</if>
            <if test="propertyStep != null">property_step,</if>
            <if test="propertyField != null">property_field,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="deviceModeId != null">#{deviceModeId},</if>
            <if test="functionMode != null and functionMode != ''">#{functionMode},</if>
            <if test="coordinate != null">#{coordinate},</if>
            <if test="functionName != null and functionName != ''">#{functionName},</if>
            <if test="functionIdentifier != null and functionIdentifier != ''">#{functionIdentifier},</if>
            <if test="functionType != null">#{functionType},</if>
            <if test="dataType != null">#{dataType},</if>
            <if test="dataDefinition != null">#{dataDefinition},</if>
            <if test="functionFormula != null">#{functionFormula},</if>
            <if test="propertyUnit != null">#{propertyUnit},</if>
            <if test="displayFlag != null">#{displayFlag},</if>
            <if test="rwFlag != null">#{rwFlag},</if>
            <if test="invokeMethod != null">#{invokeMethod},</if>
            <if test="eventType != null">#{eventType},</if>
            <if test="remark != null">#{remark},</if>
            <if test="acquisitionFormula != null">#{acquisitionFormula},</if>
            <if test="orderFlag != null">#{orderFlag},</if>
            <if test="deviceRegister != null">#{deviceRegister},</if>
            <if test="propertyStep != null">#{propertyStep},</if>
            <if test="propertyField != null">#{propertyField},</if>
         </trim>
    </insert>

    <update id="updateHwDeviceModeFunction" parameterType="HwDeviceModeFunction">
        update hw_device_mode_function
        <trim prefix="SET" suffixOverrides=",">
            <if test="deviceModeId != null">device_mode_id = #{deviceModeId},</if>
            <if test="functionMode != null and functionMode != ''">function_mode = #{functionMode},</if>
            <if test="coordinate != null">coordinate = #{coordinate},</if>
            <if test="functionName != null and functionName != ''">function_name = #{functionName},</if>
            <if test="functionIdentifier != null and functionIdentifier != ''">function_identifier = #{functionIdentifier},</if>
            <if test="functionType != null">function_type = #{functionType},</if>
            <if test="dataType != null">data_type = #{dataType},</if>
            <if test="dataDefinition != null">data_definition = #{dataDefinition},</if>
            <if test="functionFormula != null">function_formula = #{functionFormula},</if>
            <if test="propertyUnit != null">property_unit = #{propertyUnit},</if>
            <if test="displayFlag != null">display_flag = #{displayFlag},</if>
            <if test="rwFlag != null">rw_flag = #{rwFlag},</if>
            <if test="invokeMethod != null">invoke_method = #{invokeMethod},</if>
            <if test="eventType != null">event_type = #{eventType},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="acquisitionFormula != null">acquisition_formula = #{acquisitionFormula},</if>
            <if test="orderFlag != null">order_flag = #{orderFlag},</if>
            <if test="deviceRegister != null">device_register = #{deviceRegister},</if>
            <if test="propertyStep != null">property_step = #{propertyStep},</if>
            <if test="propertyField != null">property_field = #{propertyField},</if>
        </trim>
        where mode_function_id = #{modeFunctionId}
    </update>

    <delete id="deleteHwDeviceModeFunctionByModeFunctionId" parameterType="Long">
        delete from hw_device_mode_function where mode_function_id = #{modeFunctionId}
    </delete>

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