HostInfoMapper.xml 7.58 KB
<?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.monitor.mysql.mapper.HostInfoMapper" >
  <resultMap id="BaseResultMap" type="com.model.HostInfo" >
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="alias" property="alias" jdbcType="VARCHAR" />
    <result column="host_ip" property="hostIp" jdbcType="VARCHAR" />
    <result column="group_id" property="groupId" jdbcType="INTEGER" />
    <result column="cloud_type" property="cloudType" jdbcType="BIT" />
    <result column="tags" property="tags" jdbcType="VARCHAR" />
    <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
    <result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
    <result column="group_name" property="groupName" jdbcType="VARCHAR" />
  </resultMap>
  <sql id="Base_Column_List" >
    id, alias, host_ip, group_id, cloud_type, tags, create_time, update_time
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
    select
    <include refid="Base_Column_List" />
    from host_info
    where id = #{id,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
    delete from host_info
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.model.HostInfo" >
    insert into host_info (id, alias, host_ip,
    group_id, cloud_type, tags,
    create_time, update_time)
    values (#{id,jdbcType=INTEGER}, #{alias,jdbcType=VARCHAR}, #{hostIp,jdbcType=VARCHAR},
    #{groupId,jdbcType=INTEGER}, #{cloudType,jdbcType=BIT}, #{tags,jdbcType=VARCHAR},
    now(), now())
  </insert>
  <insert id="insertSelective" parameterType="com.model.HostInfo" >
    insert into host_info
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="alias != null" >
        alias,
      </if>
      <if test="hostIp != null" >
        host_ip,
      </if>
      <if test="groupId != null" >
        group_id,
      </if>
      <if test="cloudType != null" >
        cloud_type,
      </if>
      <if test="tags != null" >
        tags,
      </if>
      <if test="createTime != null" >
        create_time,
      </if>
      <if test="updateTime != null" >
        update_time,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        #{id,jdbcType=INTEGER},
      </if>
      <if test="alias != null" >
        #{alias,jdbcType=VARCHAR},
      </if>
      <if test="hostIp != null" >
        #{hostIp,jdbcType=VARCHAR},
      </if>
      <if test="groupId != null" >
        #{groupId,jdbcType=INTEGER},
      </if>
      <if test="cloudType != null" >
        #{cloudType,jdbcType=BIT},
      </if>
      <if test="tags != null" >
        #{tags,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null" >
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateTime != null" >
        #{updateTime,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.model.HostInfo" >
    update host_info
    <set >
      <if test="alias != null" >
        alias = #{alias,jdbcType=VARCHAR},
      </if>
      <if test="hostIp != null" >
        host_ip = #{hostIp,jdbcType=VARCHAR},
      </if>
      <if test="groupId != null" >
        group_id = #{groupId,jdbcType=INTEGER},
      </if>
      <if test="cloudType != null" >
        cloud_type = #{cloudType,jdbcType=BIT},
      </if>
      <if test="tags != null" >
        tags = #{tags,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null" >
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateTime != null" >
        update_time = now(),
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.model.HostInfo" >
    update host_info
    set alias = #{alias,jdbcType=VARCHAR},
      host_ip = #{hostIp,jdbcType=VARCHAR},
      group_id = #{groupId,jdbcType=INTEGER},
      cloud_type = #{cloudType,jdbcType=BIT},
      tags = #{tags,jdbcType=VARCHAR},
      update_time = now()
    where id = #{id,jdbcType=INTEGER}
  </update>

  <select id="selectCountByCodition"  resultType="java.lang.Integer">
    select
      count(1)
    from host_info a left join host_group b on a.group_id=b.id
    where
    1=1
    <if test="params.alias != null &amp;&amp; params.alias != ''" >
      and instr(a.alias, #{params.alias}) &gt; 0
    </if>
    <if test="params.cloudType != null &amp;&amp; params.cloudType != 0" >
      and a.cloud_type = #{params.cloudType}
    </if>
    <if test="params.hostIp != null &amp;&amp; params.hostIp != ''" >
      and a.host_ip = #{params.hostIp}
    </if>
    <if test="params.tagsList != null &amp;&amp; params.tagsList != ''" >
      and
      <foreach collection="params.tagsList" index="index" item="item"  separator="and">
        instr(a.tags, #{item}) &gt; 0
      </foreach>
    </if>
  </select>

  <select id="selectHostInfosByCodition"   resultMap="BaseResultMap">
    select
     a.id, a.alias, a.host_ip, a.group_id, a.cloud_type, a.tags, a.create_time, a.update_time,b.group_name
    from host_info a left join host_group b on a.group_id=b.id
    where
    1=1
    <if test="params.alias != null &amp;&amp; params.alias != ''" >
      and instr(a.alias, #{params.alias}) &gt; 0
    </if>
    <if test="params.cloudType != null &amp;&amp; params.cloudType != 0" >
      and a.cloud_type = #{params.cloudType}
    </if>
    <if test="params.hostIp != null &amp;&amp; params.hostIp != ''" >
      and a.host_ip = #{params.hostIp}
    </if>
    <if test="params.tagsList != null &amp;&amp; params.tagsList != ''" >
      and
          <foreach collection="params.tagsList" index="index" item="item"   separator="and">
            instr(a.tags, #{item}) &gt; 0
          </foreach>
    </if>

    order by a.create_time desc
    limit #{startIndex},#{pageSize}
  </select>

  <select id="selectByHostIp" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from host_info
    where host_ip = #{hostIp}
  </select>

  <select id="selectHostInfosByTag" resultMap="BaseResultMap"  >
    select
    <include refid="Base_Column_List" />
    from host_info
    where instr(tags, LOWER(#{tag})) &gt; 0
  </select>

  <select id="selectHostInfosByTagAndCloudType" resultMap="BaseResultMap"  >
    select
    <include refid="Base_Column_List" />
    from host_info
    where instr(tags, LOWER(#{tag})) &gt; 0
    AND cloud_type = #{cloudType}
  </select>

  <select id="selectHostInfosByIps" resultMap="BaseResultMap">
    select host_ip, tags
    from host_info
    where host_ip in
    <foreach item="hostIp" index="index" collection="hostIps" open="("
             separator="," close=")">
      #{hostIp}
    </foreach>
  </select>

  <update id="updateTagByIps" >
    update host_info
    set  tags = ""
    where host_ip in
    <foreach item="hostIp" index="index" collection="hostIps" open="("
             separator="," close=")">
      #{hostIp}
    </foreach>
  </update>


  <update id="updateHostInfoByIp" parameterType="com.model.HostInfo" >
    update host_info
    set alias = #{alias,jdbcType=VARCHAR},
    cloud_type = #{cloudType,jdbcType=BIT},
    tags = #{tags,jdbcType=VARCHAR},
    update_time = now()
    where host_ip = #{hostIp,jdbcType=INTEGER}
  </update>


  <delete id="deleteByIp" parameterType="java.lang.String" >
    delete from host_info
    where host_ip = #{ip,jdbcType=VARCHAR}
  </delete>
</mapper>