<?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.pcloud.book.guide.mapper.PcloudRobotSilenceMapper" >
  <resultMap id="BaseResultMap" type="com.pcloud.book.guide.entity.PcloudRobotSilence" >
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="robot_wx_id" property="robotWxId" jdbcType="VARCHAR" />
    <result column="silence_duration" property="silenceDuration" jdbcType="INTEGER" />
    <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
    <result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
  </resultMap>
  <sql id="Base_Column_List" >
    id, robot_wx_id, silence_duration, create_time, update_time
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
    select 
    <include refid="Base_Column_List" />
    from pcloud_robot_silence
    where id = #{id,jdbcType=INTEGER}
  </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
    delete from pcloud_robot_silence
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.pcloud.book.guide.entity.PcloudRobotSilence" >
    insert into pcloud_robot_silence (id, robot_wx_id, silence_duration, 
      create_time, update_time)
    values (#{id,jdbcType=INTEGER}, #{robotWxId,jdbcType=VARCHAR}, #{silenceDuration,jdbcType=INTEGER}, 
      #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP})
  </insert>
  <insert id="insertSelective" parameterType="com.pcloud.book.guide.entity.PcloudRobotSilence" >
    insert into pcloud_robot_silence
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="robotWxId != null" >
        robot_wx_id,
      </if>
      <if test="silenceDuration != null" >
        silence_duration,
      </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="robotWxId != null" >
        #{robotWxId,jdbcType=VARCHAR},
      </if>
      <if test="silenceDuration != null" >
        #{silenceDuration,jdbcType=INTEGER},
      </if>
      <if test="createTime != null" >
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateTime != null" >
        #{updateTime,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.pcloud.book.guide.entity.PcloudRobotSilence" >
    update pcloud_robot_silence
    <set >
      <if test="robotWxId != null" >
        robot_wx_id = #{robotWxId,jdbcType=VARCHAR},
      </if>
      <if test="silenceDuration != null" >
        silence_duration = #{silenceDuration,jdbcType=INTEGER},
      </if>
      <if test="createTime != null" >
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateTime != null" >
        update_time = #{updateTime,jdbcType=TIMESTAMP},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.pcloud.book.guide.entity.PcloudRobotSilence" >
    update pcloud_robot_silence
    set robot_wx_id = #{robotWxId,jdbcType=VARCHAR},
      silence_duration = #{silenceDuration,jdbcType=INTEGER},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      update_time = #{updateTime,jdbcType=TIMESTAMP}
    where id = #{id,jdbcType=INTEGER}
  </update>

  <!--查询所有平台端 引导语 缄默设置相关的机器人-->
  <select id="listRobots" resultType="java.lang.String">
    SELECT robot_wx_id FROM pcloud_robot_silence UNION SELECT robot_wx_id FROM pcloud_guide
  </select>

  <!--根据机器人wxid获取缄默时长-->
  <select id="getSilenceDurationByRobotWxId" resultType="java.lang.Integer">
    SELECT silence_duration FROM pcloud_robot_silence WHERE robot_wx_id = #{wxId}
  </select>

  <!--设置机器人缄默时长-->
  <update id="setSilenceDuration">
    INSERT INTO pcloud_robot_silence (robot_wx_id,silence_duration,create_time) VALUE(#{robotWxId},#{silenceDuration},NOW())
    ON DUPLICATE KEY UPDATE robot_wx_id=#{robotWxId},silence_duration=#{silenceDuration},update_time=NOW()
  </update>


</mapper>