<?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="im.zhaojun.system.mapper.CodeMapper">

    <resultMap id="BaseResultMap" type="im.zhaojun.system.model.Code">
        <result column="key" jdbcType="VARCHAR" property="key" />
        <result column="name" jdbcType="VARCHAR" property="name" />
        <result column="type" jdbcType="CHAR" property="type" />
        <result column="alarmlevel" jdbcType="VARCHAR" property="alarmlevel" />
        <result column="rectifytime" jdbcType="INTEGER" property="rectifytime" />
        <result column="manualchecktime" jdbcType="INTEGER" property="manualchecktime" />
        <result column="pushchecktime" jdbcType="INTEGER" property="pushchecktime" />
        <result column="maxnumvalue" jdbcType="INTEGER" property="maxnumvalue" />
        <result column="alarmnum" jdbcType="INTEGER" property="alarmnum" />

    </resultMap>

    <update id="updatecode" parameterType="java.util.List">
        <foreach collection="list" item="item" index="index" open="" close="" separator=";">
            UPDATE t_code t
            <set>
                <if test="item.alarmlevel != null">
                    alarmlevel = #{item.alarmlevel,jdbcType=VARCHAR},
                </if>
                <if test="item.maxnumvalue != null">
                    maxnumvalue = #{item.maxnumvalue,jdbcType=INTEGER},
                </if>
                <if test="item.alarmnum != null">
                    alarmnum = #{item.alarmnum,jdbcType=INTEGER},
                </if>
            </set>
            where t.key = #{item.key,jdbcType=VARCHAR}
        </foreach>
    </update>

    <update id="updatetime" parameterType="java.util.List">
        <foreach collection="list" item="item" index="index" open="begin" close=";end;" separator=";">
            UPDATE t_code t
            <set>
                <if test="item.rectifytime != null">
                    rectifytime = #{item.rectifytime,jdbcType=INTEGER},
                </if>
                <if test="item.manualchecktime != null">
                    manualchecktime = #{item.manualchecktime,jdbcType=INTEGER},
                </if>
                <if test="item.pushchecktime != null">
                    pushchecktime = #{item.pushchecktime,jdbcType=INTEGER},
                </if>
            </set>
            where t.key = #{item.key,jdbcType=VARCHAR}
        </foreach>
    </update>

    <select id="selectAllWithKey" resultMap="BaseResultMap">
        select * from  t_code  t where t.type=2
    </select>


    <select id="selectAllWithType" resultMap="BaseResultMap">
        select * from  t_code   t where t.type=#{typeid,jdbcType=VARCHAR}
    </select>

    <update id="updateNameByCodeID">
        update  t_code t  set  name=#{envalue,jdbcType=VARCHAR} where t.key=#{codeid,jdbcType=VARCHAR}
    </update>

    <update id="updatemanualcode">
        update  t_code  t set  name=#{name ,jdbcType=VARCHAR},alarmlevel=#{alarmlevel,jdbcType=VARCHAR} where t.key='send'
    </update>
    <select id="selectalarmNum" resultMap="BaseResultMap">
        select * from  t_code t   where t.type=2 and  t.key=#{key,jdbcType=VARCHAR}
    </select>

</mapper>