<?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="maxnum" jdbcType="INTEGER" property="maxnum" />
        <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
            <set>
                <if test="item.alarmlevel != null">
                    alarmlevel = #{item.alarmlevel,jdbcType=VARCHAR},
                </if>
            </set>
            where 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
            <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 key = #{item.key,jdbcType=VARCHAR}
        </foreach>
    </update>

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


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

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

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

</mapper>