<?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.push.dao.impl.SelfPushDaoImpl" >
  <resultMap id="BaseResultMap" type="com.pcloud.book.push.entity.SelfPush" >
    <id column="id" property="id" jdbcType="BIGINT" />
    <result column="alt_id" property="altId" jdbcType="VARCHAR" />
    <result column="create_user" property="createUser" jdbcType="BIGINT" />
    <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
    <result column="update_user" property="updateUser" jdbcType="BIGINT" />
    <result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
    <result column="send_now" property="sendNow" jdbcType="BIT" />
    <result column="send_time" property="sendTime" jdbcType="TIMESTAMP" />
    <result column="book_group_id" property="bookGroupId" jdbcType="BIGINT" />
    <result column="send_all" property="sendAll" jdbcType="BIT" />
    <result column="start_time" property="startTime" jdbcType="TIMESTAMP" />
    <result column="end_time" property="endTime" jdbcType="TIMESTAMP" />
    <result column="push_type" property="pushType" jdbcType="BIT" />
    <result column="week_days" property="weekDays" jdbcType="VARCHAR" />
    <result column="push_send_time" property="pushSendTime" jdbcType="VARCHAR" />

  </resultMap>

  <sql id="Base_Column_List" >
    id, alt_id, create_user, create_time, update_user, update_time, send_now, send_time, book_group_id, send_all,start_time,end_time,
    push_type,week_days,push_send_time
  </sql>


  <insert id="insert" parameterType="com.pcloud.book.push.entity.SelfPush" useGeneratedKeys="true" keyProperty="id">
    insert into self_push (id, alt_id, create_user,
    create_time, update_user, update_time, send_now, send_time, book_group_id, send_all,start_time,end_time,
    push_type,week_days,push_send_time
    )
    values (#{id,jdbcType=BIGINT}, #{altId,jdbcType=VARCHAR}, #{createUser,jdbcType=BIGINT},
    now(), #{updateUser,jdbcType=BIGINT}, now(), #{sendNow}, #{sendTime}, #{bookGroupId}, #{sendAll},#{startTime},
    #{endTime},#{pushType},#{weekDays},#{pushSendTime}
    )
  </insert>


  <select id="getById" parameterType="long" resultMap="BaseResultMap">
    SELECT <include refid="Base_Column_List"/>
    FROM self_push
    WHERE id= #{id}
  </select>

  <delete id="deleteById" parameterType="long">
    delete from
    self_push
    WHERE id= #{id}
  </delete>

  <select id="getUnclosedByRobot" parameterType="string" resultMap="BaseResultMap">
    SELECT
	<include refid="Base_Column_List"/>
    FROM
        self_push
    WHERE
        send_all = 1
    AND send_now = 0
    AND (
        send_time > CURTIME()
        OR CURTIME() BETWEEN start_time
        AND end_time
    )
    AND alt_id = #{altId}
  </select>
</mapper>