<?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.custom.dao.impl.CustomReadPlanDaoImpl" >
  <resultMap id="BaseResultMap" type="com.pcloud.book.custom.entity.CustomReadPlan" >
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="robot_type" property="robotType" jdbcType="INTEGER" />
    <result column="name" property="name" jdbcType="VARCHAR" />
    <result column="detail" property="detail" jdbcType="VARCHAR" />
    <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
    <result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
    <result column="agent_id" property="agentId" jdbcType="BIGINT" />
  </resultMap>

  <sql id="Base_Column_List">
    id, robot_type,name,detail,create_time,update_time,agent_id
  </sql>

  <insert id="insert" parameterType="com.pcloud.book.custom.entity.CustomReadPlan" useGeneratedKeys="true" keyProperty="id">
    insert into custom_read_plan
    (robot_type,name,detail,create_time,update_time,agent_id)
    values
    (#{robotType},#{name},#{detail},now(),now(),#{agentId})
  </insert>

  <update id="update" parameterType="com.pcloud.book.custom.entity.CustomReadPlan">
    update custom_read_plan
    <set>
      <if test="robotType != null">
       robot_type = #{robotType},
      </if>
      <if test="name != null">
        name = #{name},
      </if>
      <if test="detail != null">
        detail = #{detail},
      </if>
        update_time = NOW()
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>

  <delete id="deleteById">
    delete from custom_read_plan
    where id = #{id,jdbcType=INTEGER}
  </delete>

  <select id="getById" resultMap="BaseResultMap">
    select
        <include refid="Base_Column_List" />
    from custom_read_plan
    where id = #{id,jdbcType=INTEGER}
  </select>

  <select id="getCustomReadPlanList" parameterType="map" resultMap="BaseResultMap">
    select
    t1.id,
    t1.robot_type,
    t1.name,
    t1.detail,
    t1.create_time,
    t1.update_time,
    t1.agent_id
    from custom_read_plan t1
    where 1=1
    <if test="robotType!=null">
      and t1.robot_type=#{robotType}
    </if>
    <if test="agentId != null">
      and t1.agent_id = #{agentId}
    </if>
    order by t1.create_time desc
  </select>

</mapper>