<?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.gyee.wisdom.alarm.sharding.mapper.DeviceModelMetricsMapper">


    <select id="getDeviceModelMetricsById" parameterType="java.util.Map" resultType="com.gyee.wisdom.alarm.sharding.entity.DeviceModelMetrics">
        select * from device_model_metrics a
        <where>
            1=1
            <if test="_parameter  !=null and _parameter  !=''">
                and a.metriccode=#{_parameter }
            </if>
        </where>
    </select>

    <select id="getAll" parameterType="java.util.Map" resultType="com.gyee.wisdom.alarm.sharding.entity.DeviceModelMetrics">
        select * from  device_model_metrics a
    </select>
    <select id="selectModelMetricsById" resultType="com.gyee.wisdom.alarm.sharding.entity.DeviceModelMetrics">
        select * from  device_model_metrics a where a.id=#{id}
    </select>
    <update id="updateModelMetricsById" parameterType="com.gyee.wisdom.alarm.sharding.entity.DeviceModelMetrics">
        update device_model_metrics
        <set >
            <if test="deviceid != null">deviceid = #{deviceid},</if>
            <if test="devicemodel != null">devicemodel = #{devicemodel},</if>
            <if test="metriccode != null">metriccode = #{metriccode},</if>
            <if test="uniformcode != null">uniformcode = #{uniformcode},</if>
            <if test="multiplier != null">multiplier = #{multiplier}</if>
        </set>
        where id = #{id}
    </update>

    <insert id="insertModelMetrics" parameterType="com.gyee.wisdom.alarm.sharding.entity.DeviceModelMetrics" useGeneratedKeys="true">
        insert into device_model_metrics(id, deviceid, devicemodel, metriccode, uniformcode,multiplier)
        values (#{id}, #{deviceid}, #{devicemodel},#{metriccode}, #{uniformcode},#{multiplier})
    </insert>

    <select id="getDeviceModelMetrics" parameterType="java.util.Map" resultType="com.gyee.wisdom.alarm.sharding.entity.DeviceModelMetrics">
        select * from device_model_metrics a
        <where>
            1=1
            <if test="modelId  !=null and modelId  !=''">
                and a.devicemodel =#{modelId}
            </if>
            <if test="metricCodeList !=null and metricCodeList.size > 0">
                and a.metriccode in
                <foreach collection="metricCodeList" item="metricCode" index="index" open="(" close=")" separator=",">
                    #{metricCode}
                </foreach>
            </if>
        </where>
    </select>
</mapper>
