<?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" />
    <result column="pcloud_classify_id" property="pcloudClassifyId" jdbcType="INTEGER" />
  </resultMap>
  <sql id="Base_Column_List" >
    id, robot_wx_id, silence_duration, create_time, update_time, pcloud_classify_id
  </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, pcloud_classify_id)
    values (#{id,jdbcType=INTEGER}, #{robotWxId,jdbcType=VARCHAR}, #{silenceDuration,jdbcType=INTEGER}, 
      #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}, #{pcloudClassifyId})
  </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 silence_duration = #{silenceDuration,jdbcType=INTEGER},
      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 1=1
    <if test="wxId != null">
      and robot_wx_id = #{wxId}
    </if>
    <if test="pcloudClassifyId != null">
      and pcloud_classify_id = #{pcloudClassifyId}
    </if>
  </select>

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

  <select id="get" resultMap="BaseResultMap">
    SELECT id, robot_wx_id, silence_duration, create_time, update_time, pcloud_classify_id FROM pcloud_robot_silence WHERE 1=1
    <if test="wxId != null">
      and robot_wx_id = #{wxId}
    </if>
    <if test="pcloudClassifyId != null">
      and pcloud_classify_id = #{pcloudClassifyId}
    </if>
  </select>

</mapper>