<?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.TaskPrizeItemMapper" >
  <resultMap id="BaseResultMap" type="com.pcloud.book.timecontrol.entity.TimeControlPrizeItem" >
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="task_id" property="taskId" jdbcType="INTEGER" />
    <result column="task_item_id" property="taskItemId" jdbcType="INTEGER" />
    <result column="prize_id" property="prizeId" jdbcType="INTEGER" />
    <result column="prize_type" property="prizeType" jdbcType="INTEGER" />
    <result column="coupon_url" property="couponUrl" jdbcType="VARCHAR" />
    <result column="coupon_title" property="couponTitle" jdbcType="VARCHAR" />
    <result column="content" property="content" jdbcType="VARCHAR" />
    <result column="pic_url" property="picUrl" jdbcType="VARCHAR" />
    <result column="serve_id" property="serveId" jdbcType="INTEGER" />
    <result column="serve_type" property="serveType" jdbcType="VARCHAR" />
    <result column="link_url" property="linkUrl" jdbcType="VARCHAR" />
    <result column="description" property="description" jdbcType="VARCHAR" />
    <result column="certificate_title" property="certificateTitle" jdbcType="VARCHAR" />
    <result column="certificate_user" property="certificateUser" jdbcType="VARCHAR" />
    <result column="certificate_base_url" property="certificateBaseUrl" jdbcType="VARCHAR" />
    <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
  </resultMap>

  <sql id="Base_Column_List" >
    id, task_id, task_item_id, prize_id, prize_type, coupon_url, coupon_title, content,
    pic_url, serve_id, serve_type, link_url, description, certificate_title, certificate_user,
    certificate_base_url, create_time
  </sql>

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

  <select id="getByPrizeId" resultMap="BaseResultMap" parameterType="map">
    SELECT
    <include refid="Base_Column_List" />
    from time_control_task_prize_item
    WHERE prize_id = #{prizeId,jdbcType=INTEGER} AND prize_type = #{prizeType,jdbcType=INTEGER}
    ORDER BY id DESC
    LIMIT 0,1
  </select>

  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
    delete from time_control_task_prize_item
    where id = #{id,jdbcType=INTEGER}
  </delete>

  <delete id="deleteByPrizeId">
    delete from time_control_task_prize_item
    where prize_id = #{prizeId,jdbcType=INTEGER}
  </delete>

  <insert id="insert" parameterType="com.pcloud.book.timecontrol.entity.TimeControlPrizeItem" useGeneratedKeys="true" keyProperty="id" >
    insert into time_control_task_prize_item (task_id, task_item_id,
      prize_id, prize_type, coupon_url,
      coupon_title, content, pic_url,
      serve_id, serve_type, link_url,
      description, certificate_title, certificate_user,
      certificate_base_url, create_time)
    values (#{taskId,jdbcType=INTEGER}, #{taskItemId,jdbcType=INTEGER},
      #{prizeId,jdbcType=INTEGER}, #{prizeType,jdbcType=INTEGER}, #{couponUrl,jdbcType=VARCHAR},
      #{couponTitle,jdbcType=VARCHAR}, #{content,jdbcType=VARCHAR}, #{picUrl,jdbcType=VARCHAR},
      #{serveId,jdbcType=INTEGER}, #{serveType,jdbcType=VARCHAR}, #{linkUrl,jdbcType=VARCHAR},
      #{description,jdbcType=VARCHAR}, #{certificateTitle,jdbcType=VARCHAR}, #{certificateUser,jdbcType=VARCHAR},
      #{certificateBaseUrl,jdbcType=VARCHAR}, NOW())
  </insert>

  <insert id="insertSelective" parameterType="com.pcloud.book.timecontrol.entity.TimeControlPrizeItem" >
    insert into time_control_task_prize_item
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="taskId != null" >
        task_id,
      </if>
      <if test="taskItemId != null" >
        task_item_id,
      </if>
      <if test="prizeId != null" >
        prize_id,
      </if>
      <if test="prizeType != null" >
        prize_type,
      </if>
      <if test="couponUrl != null" >
        coupon_url,
      </if>
      <if test="couponTitle != null" >
        coupon_title,
      </if>
      <if test="content != null" >
        content,
      </if>
      <if test="picUrl != null" >
        pic_url,
      </if>
      <if test="serveId != null" >
        serve_id,
      </if>
      <if test="serveType != null" >
        serve_type,
      </if>
      <if test="linkUrl != null" >
        link_url,
      </if>
      <if test="description != null" >
        description,
      </if>
      <if test="certificateTitle != null" >
        certificate_title,
      </if>
      <if test="certificateUser != null" >
        certificate_user,
      </if>
      <if test="certificateBaseUrl != null" >
        certificate_base_url,
      </if>
      <if test="createTime != null" >
        create_time,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        #{id,jdbcType=INTEGER},
      </if>
      <if test="taskId != null" >
        #{taskId,jdbcType=INTEGER},
      </if>
      <if test="taskItemId != null" >
        #{taskItemId,jdbcType=INTEGER},
      </if>
      <if test="prizeId != null" >
        #{prizeId,jdbcType=INTEGER},
      </if>
      <if test="prizeType != null" >
        #{prizeType,jdbcType=INTEGER},
      </if>
      <if test="couponUrl != null" >
        #{couponUrl,jdbcType=VARCHAR},
      </if>
      <if test="couponTitle != null" >
        #{couponTitle,jdbcType=VARCHAR},
      </if>
      <if test="content != null" >
        #{content,jdbcType=VARCHAR},
      </if>
      <if test="picUrl != null" >
        #{picUrl,jdbcType=VARCHAR},
      </if>
      <if test="serveId != null" >
        #{serveId,jdbcType=INTEGER},
      </if>
      <if test="serveType != null" >
        #{serveType,jdbcType=VARCHAR},
      </if>
      <if test="linkUrl != null" >
        #{linkUrl,jdbcType=VARCHAR},
      </if>
      <if test="description != null" >
        #{description,jdbcType=VARCHAR},
      </if>
      <if test="certificateTitle != null" >
        #{certificateTitle,jdbcType=VARCHAR},
      </if>
      <if test="certificateUser != null" >
        #{certificateUser,jdbcType=VARCHAR},
      </if>
      <if test="certificateBaseUrl != null" >
        #{certificateBaseUrl,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null" >
        #{createTime,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>

  <update id="updateByPrimaryKeySelective" parameterType="com.pcloud.book.timecontrol.entity.TimeControlPrizeItem" >
    update time_control_task_prize_item
    <set >
      <if test="taskId != null" >
        task_id = #{taskId,jdbcType=INTEGER},
      </if>
      <if test="taskItemId != null" >
        task_item_id = #{taskItemId,jdbcType=INTEGER},
      </if>
      <if test="prizeId != null" >
        prize_id = #{prizeId,jdbcType=INTEGER},
      </if>
      <if test="prizeType != null" >
        prize_type = #{prizeType,jdbcType=INTEGER},
      </if>
      <if test="couponUrl != null" >
        coupon_url = #{couponUrl,jdbcType=VARCHAR},
      </if>
      <if test="couponTitle != null" >
        coupon_title = #{couponTitle,jdbcType=VARCHAR},
      </if>
      <if test="content != null" >
        content = #{content,jdbcType=VARCHAR},
      </if>
      <if test="picUrl != null" >
        pic_url = #{picUrl,jdbcType=VARCHAR},
      </if>
      <if test="serveId != null" >
        serve_id = #{serveId,jdbcType=INTEGER},
      </if>
      <if test="serveType != null" >
        serve_type = #{serveType,jdbcType=VARCHAR},
      </if>
      <if test="linkUrl != null" >
        link_url = #{linkUrl,jdbcType=VARCHAR},
      </if>
      <if test="description != null" >
        description = #{description,jdbcType=VARCHAR},
      </if>
      <if test="certificateTitle != null" >
        certificate_title = #{certificateTitle,jdbcType=VARCHAR},
      </if>
      <if test="certificateUser != null" >
        certificate_user = #{certificateUser,jdbcType=VARCHAR},
      </if>
      <if test="certificateBaseUrl != null" >
        certificate_base_url = #{certificateBaseUrl,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null" >
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>

  <update id="updateByPrimaryKey" parameterType="com.pcloud.book.timecontrol.entity.TimeControlPrizeItem" >
    update time_control_task_prize_item
    set task_id = #{taskId,jdbcType=INTEGER},
      task_item_id = #{taskItemId,jdbcType=INTEGER},
      prize_id = #{prizeId,jdbcType=INTEGER},
      prize_type = #{prizeType,jdbcType=INTEGER},
      coupon_url = #{couponUrl,jdbcType=VARCHAR},
      coupon_title = #{couponTitle,jdbcType=VARCHAR},
      content = #{content,jdbcType=VARCHAR},
      pic_url = #{picUrl,jdbcType=VARCHAR},
      serve_id = #{serveId,jdbcType=INTEGER},
      serve_type = #{serveType,jdbcType=VARCHAR},
      link_url = #{linkUrl,jdbcType=VARCHAR},
      description = #{description,jdbcType=VARCHAR},
      certificate_title = #{certificateTitle,jdbcType=VARCHAR},
      certificate_user = #{certificateUser,jdbcType=VARCHAR},
      certificate_base_url = #{certificateBaseUrl,jdbcType=VARCHAR},
      create_time = #{createTime,jdbcType=TIMESTAMP}
    where id = #{id,jdbcType=INTEGER}
  </update>

  <insert id="batchInsert" parameterType="com.pcloud.book.timecontrol.entity.TimeControlPrizeItem">
    insert into time_control_task_prize_item (task_id, task_item_id,
      prize_id, prize_type, coupon_url,
      coupon_title, content, pic_url,
      serve_id, serve_type, link_url,
      description, certificate_title, certificate_user,
      certificate_base_url, create_time)
    values
    <foreach collection="prizeItemList" separator="," item="item">
      (#{item.taskId}, #{item.taskItemId}, #{item.prizeId}, #{item.prizeType}, #{item.couponUrl}, #{item.couponTitle},
      #{item.content}, #{item.picUrl}, #{item.serveId}, #{item.serveType}, #{item.linkUrl}, #{item.description},
      #{item.certificateTitle}, #{item.certificateUser}, #{item.certificateBaseUrl}, now())
    </foreach>
  </insert>

  <select id="listByPrizeId" parameterType="int" resultMap="BaseResultMap">
        select <include refid="Base_Column_List"/>
        from time_control_task_prize_item where prize_id = #{prizeId}
  </select>

  <select id="getByTaskId" parameterType="int" resultMap="BaseResultMap">
    select <include refid="Base_Column_List"/>
    from time_control_task_prize_item
    where task_id = #{taskId}
  </select>

  <delete id="deleteByTaskItemId" parameterType="map">
        delete from time_control_task_prize_item where task_item_id = #{taskItemId}
        <if test="deleteTypes != null and deleteTypes.size > 0">
            and prize_type in
            <foreach collection="deleteTypes" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
  </delete>
</mapper>
