<?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.TimeControlReplyMessageMapper" >
  <resultMap id="BaseResultMap" type="com.pcloud.book.timecontrol.entity.TimeControlReplyMessage" >
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="task_item_id" property="taskItemId" jdbcType="INTEGER" />
    <result column="task_id" property="taskId" jdbcType="INTEGER" />
    <result column="type" property="type" jdbcType="INTEGER" />
    <result column="reply_type" property="replyType" jdbcType="INTEGER" />
    <result column="content" property="content" jdbcType="VARCHAR" />
    <result column="serve_id" property="serveId" jdbcType="INTEGER" />
    <result column="resource_id" property="resourceId" jdbcType="INTEGER" />
    <result column="pic_url" property="picUrl" jdbcType="VARCHAR" />
    <result column="serve_type" property="serveType" jdbcType="VARCHAR" />
    <result column="description" property="description" jdbcType="VARCHAR" />
    <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
    <result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
    <result column="link_url" property="linkUrl" jdbcType="VARCHAR" />
  </resultMap>
  <sql id="Base_Column_List" >
    id, task_id, task_item_id, type, reply_type, content, serve_id, resource_id, pic_url, serve_type,
    description, create_time, update_time, link_url
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
    select 
    <include refid="Base_Column_List" />
    from time_control_reply_message
    where id = #{id,jdbcType=INTEGER}
  </select>

  <select id="list4TaskItem" resultMap="BaseResultMap">
    select task_id, task_item_id, type, reply_type, serve_id, resource_id, pic_url, serve_type,
    description, create_time, content, link_url
    from time_control_reply_message
    where task_item_id = #{taskItemId}
    <if test="type != null">
      and type = #{type}
    </if>
  </select>

  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
    delete from time_control_reply_message
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <delete id="deleteByItemId">
    delete from time_control_reply_message where task_item_id = #{taskItemId}
  </delete>
  <insert id="insert" parameterType="com.pcloud.book.timecontrol.entity.TimeControlReplyMessage" >
    insert into time_control_reply_message (id, task_item_id, type, 
      reply_type, serve_id, resource_id, 
      pic_url, serve_type, description, 
      create_time, update_time)
    values (#{id,jdbcType=INTEGER}, #{taskItemId,jdbcType=INTEGER}, #{type,jdbcType=INTEGER}, 
      #{replyType,jdbcType=VARCHAR}, #{serveId,jdbcType=INTEGER}, #{resourceId,jdbcType=INTEGER}, 
      #{picUrl,jdbcType=VARCHAR}, #{serveType,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR}, 
      #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP})
  </insert>

  <insert id="batchInsert">
    insert into time_control_reply_message (task_id, task_item_id, type,
      reply_type, content, serve_id, resource_id,
      pic_url, serve_type, description,
      create_time, update_time, link_url)
      values
      <foreach collection="list" separator="," item="item">
        (#{item.taskId}, #{item.taskItemId}, #{item.type}, #{item.replyType}, #{item.content}, #{item.serveId},
        #{item.resourceId}, #{item.picUrl}, #{item.serveType}, #{item.description}, now(), now(), #{item.linkUrl})
      </foreach>
  </insert>

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

  <select id="list4TaskItemList" resultType="com.pcloud.book.timecontrol.dto.ReplyMessageDto">
    select
    task_item_id taskItemId,
    serve_id serveId,
    resource_id resourceId,
    pic_url picUrl,
    serve_type serveType,
    description description,
    content content,
    link_url linkUrl,
    reply_type replyType
    from time_control_reply_message
    where  type = #{type}
    <if test="taskItemIds !=null and taskItemIds.size()>0">
      AND task_item_id IN
      <foreach collection="taskItemIds" open="(" close=")" separator="," item="item">
        #{item}
      </foreach>
    </if>
  </select>

</mapper>