<?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.timecontrol.mapper.TimeControlSelfPlanItemMapper" >
  <resultMap id="BaseResultMap" type="com.pcloud.book.timecontrol.entity.TimeControlSelfPlanItem" >
    <id column="id" property="id"  jdbcType="INTEGER"/>
    <result column="self_plan_id" property="selfPlanId" jdbcType="INTEGER" />
    <result column="type" property="type" jdbcType="INTEGER" />
    <result column="title" property="title" jdbcType="VARCHAR" />
    <result column="content" property="content" jdbcType="VARCHAR" />
    <result column="description" property="description" jdbcType="VARCHAR" />
    <result column="pic_url" property="picUrl" jdbcType="VARCHAR" />
    <result column="open_feedback" property="openFeedback" 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, self_plan_id, type, title, content, description, pic_url, open_feedback, create_time, update_time
  </sql>

  <insert id="batchInsert">
    insert into time_control_self_plan_item (self_plan_id, type, title,
      content, description, pic_url, open_feedback, create_time, update_time)
    values
    <foreach collection="list" separator="," item="item">
     (#{item.selfPlanId,jdbcType=INTEGER}, #{item.type,jdbcType=INTEGER}, #{item.title,jdbcType=VARCHAR},
      #{item.content,jdbcType=VARCHAR}, #{item.description,jdbcType=VARCHAR},#{item.picUrl,jdbcType=VARCHAR},
      #{item.openFeedback,jdbcType=INTEGER}, NOW(), NOW())
    </foreach>
  </insert>

  <update id="update" parameterType="TimeControlSelfPlanItem">
    update time_control_self_plan_item
    <set>
      <if test="selfPlanId != null">
        self_plan_id = #{selfPlanId,jdbcType=INTEGER},
      </if>
      <if test="type != null">
        type = #{type,jdbcType=INTEGER},
      </if>
      <if test="title != null">
        title = #{title,jdbcType=VARCHAR},
      </if>
      <if test="content != null">
        content = #{content,jdbcType=VARCHAR},
      </if>
      <if test="description != null">
        description = #{description,jdbcType=VARCHAR},
      </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>

  <select id="getByPlanId" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select
        <include refid="Base_Column_List" />
    from time_control_self_plan_item
    where self_plan_id = #{planId,jdbcType=INTEGER}
  </select>

  <delete id="deleteByPlanId" parameterType="java.lang.Integer">
    delete from time_control_self_plan_item
    where self_plan_id = #{planId,jdbcType=INTEGER}
  </delete>
</mapper>