<?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.PcloudRobotWakeupMapper" >
  <resultMap id="BaseResultMap" type="com.pcloud.book.guide.entity.PcloudRobotWakeup" >
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="start_time" property="startTime" jdbcType="TIMESTAMP" />
    <result column="cycle" property="cycle" jdbcType="INTEGER" />
    <result column="last" property="last" jdbcType="INTEGER" />
    <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
    <result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
  </resultMap>

  <resultMap id="RobotWakeUpShowVOMap" type="com.pcloud.book.guide.vo.RobotWakeUpShowVO">
    <id column="id" property="wakeUpId" jdbcType="BIGINT"/>
    <result column="start_time" property="startTime" jdbcType="TIMESTAMP"/>
    <result column="last" property="lastDay" jdbcType="BIGINT"/>
    <collection property="classifyDTOList" column="id" select="com.pcloud.book.guide.mapper.PcloudRobotWakeupClassifyMapper.getRobotClassifyByWakeUpId"/>
    <collection property="msgList" column="id" select="com.pcloud.book.guide.mapper.PcloudWakeupMessageMapper.selectByWakeUpId"/>
  </resultMap>
  <sql id="Base_Column_List" >
    id, start_time, cycle, last, create_time, update_time
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
    select 
    <include refid="Base_Column_List" />
    from pcloud_robot_wakeup
    where id = #{id,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
    delete from pcloud_robot_wakeup
    where id = #{id,jdbcType=INTEGER}
  </delete>
    <insert id="insert" parameterType="com.pcloud.book.guide.entity.PcloudRobotWakeup" >
    insert into pcloud_robot_wakeup (id, start_time, cycle, 
      last, create_time, update_time
      )
    values (#{id,jdbcType=INTEGER}, #{startTime,jdbcType=TIMESTAMP}, #{cycle,jdbcType=INTEGER}, 
      #{last,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.pcloud.book.guide.entity.PcloudRobotWakeup" useGeneratedKeys="true" keyProperty="id" >
    insert into pcloud_robot_wakeup
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="startTime != null" >
        start_time,
      </if>
      <if test="cycle != null" >
        cycle,
      </if>
      <if test="last != null" >
        last,
      </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="startTime != null" >
        #{startTime,jdbcType=TIMESTAMP},
      </if>
      <if test="cycle != null" >
        #{cycle,jdbcType=INTEGER},
      </if>
      <if test="last != null" >
        #{last,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.PcloudRobotWakeup" >
    update pcloud_robot_wakeup
    <set >
      <if test="startTime != null" >
        start_time = #{startTime,jdbcType=TIMESTAMP},
      </if>
      <if test="cycle != null" >
        cycle = #{cycle,jdbcType=INTEGER},
      </if>
      <if test="last != null" >
        last = #{last,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.PcloudRobotWakeup" >
    update pcloud_robot_wakeup
    set start_time = #{startTime,jdbcType=TIMESTAMP},
      cycle = #{cycle,jdbcType=INTEGER},
      last = #{last,jdbcType=INTEGER},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      update_time = #{updateTime,jdbcType=TIMESTAMP}
    where id = #{id,jdbcType=INTEGER}
  </update>

  <delete id="deleteAll">
    delete from pcloud_robot_wakeup
  </delete>

  <select id="selectOne" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from pcloud_robot_wakeup
    limit 1
  </select>

  <select id="listAllRobot" resultType="java.lang.String">
    SELECT wx_id FROM pcloud_robot WHERE wake_up=1
  </select>
  <select id="listAllClassify"
          resultType="com.pcloud.book.pcloudkeyword.facade.response.PcloudRobotClassifyResponseVO">
    SELECT
    id,
    classify_name classifyName
    FROM pcloud_robot_classify WHERE id IN (SELECT DISTINCT robot_type FROM pcloud_robot )
    AND is_delete = 0
  </select>

  <select id="getRobotWakeUpConfigListCount" resultType="integer">
    select
    count(id)
    from
    pcloud_robot_wakeup
  </select>

  <select id="getRobotWakeUpConfigList" resultMap="RobotWakeUpShowVOMap">
    select
    id,
    start_time,
    last
    from pcloud_robot_wakeup
    order by create_time desc
    <if test="currentPage!=null">
      limit #{currentPage},#{numPerPage}
    </if>
  </select>

  <select id="getRobotWakeUpConfigById" parameterType="integer" resultMap="RobotWakeUpShowVOMap">
    select
    id,
    start_time,
    last
    from pcloud_robot_wakeup
    where id = #{wakeUpId}
  </select>

</mapper>