<?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.TimeControlSelfPlanFeedbackMapper" >
  <resultMap id="BaseResultMap" type="com.pcloud.book.timecontrol.entity.TimeControlSelfPlanFeedback" >
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="feedback_type" property="feedbackType" jdbcType="INTEGER" />
    <result column="self_plan_id" property="selfPlanId" jdbcType="INTEGER" />
    <result column="robot_wx_id" property="robotWxId" jdbcType="VARCHAR" />
    <result column="wx_id" property="wxId" jdbcType="VARCHAR" />
    <result column="plan_type" property="planType" jdbcType="INTEGER" />
    <result column="content" property="content" jdbcType="VARCHAR" />
    <result column="plan_score" property="planScore" jdbcType="INTEGER" />
    <result column="content_score" property="contentScore" 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, feedback_type, self_plan_id, robot_wx_id, wx_id, plan_type, content, plan_score, content_score, create_time, update_time
  </sql>

  <insert id="insert" parameterType="TimeControlSelfPlanFeedback" useGeneratedKeys="true" keyProperty="id">
    insert into time_control_self_plan_feedback (feedback_type, self_plan_id, robot_wx_id, wx_id,
      plan_type, content, plan_score, content_score, create_time, update_time)
    values (#{feedbackType,jdbcType=INTEGER}, #{selfPlanId,jdbcType=INTEGER}, #{robotWxId,jdbcType=VARCHAR}, #{wxId,jdbcType=VARCHAR},
      #{planType,jdbcType=INTEGER}, #{content,jdbcType=VARCHAR}, #{planScore,jdbcType=INTEGER},
      #{contentScore,jdbcType=INTEGER}, NOW(), NOW())
  </insert>

  <insert id="batchInsert" useGeneratedKeys="true" keyProperty="id">
    insert into time_control_self_plan_feedback (feedback_type, self_plan_id, robot_wx_id, wx_id,
      plan_type, content, plan_score, content_score, create_time, update_time)
    values
    <foreach collection="list" separator="," item="item">
    (#{item.feedbackType,jdbcType=INTEGER}, #{item.selfPlanId,jdbcType=INTEGER}, #{item.robotWxId,jdbcType=VARCHAR}, #{item.wxId,jdbcType=VARCHAR},
      #{item.planType,jdbcType=INTEGER}, #{item.content,jdbcType=VARCHAR}, #{item.planScore,jdbcType=INTEGER},
      #{item.contentScore,jdbcType=INTEGER}, NOW(), NOW())
    </foreach>
  </insert>

  <update id="update" parameterType="TimeControlSelfPlanFeedback">
    update time_control_self_plan_feedback
    <set>
      <if test="selfPlanId != null">
        self_plan_id = #{selfPlanId,jdbcType=INTEGER},
      </if>
      <if test="robotWxId != null">
        robot_wx_id = #{robotWxId,jdbcType=VARCHAR},
      </if>
      <if test="wxId != null">
        wx_id = #{wxId,jdbcType=VARCHAR},
      </if>
      <if test="planType != null">
        plan_type = #{planType,jdbcType=INTEGER},
      </if>
      <if test="content != null">
        content = #{content,jdbcType=VARCHAR},
      </if>
        update_time = NOW(),
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>

  <delete id="deleteByPlanId">
    delete from time_control_self_plan_feedback
    where self_plan_id = #{planId,jdbcType=INTEGER}
    and feedback_type = #{feedbackType,jdbcType=INTEGER}
  </delete>

  <select id="getFeedbackByPlan" resultMap="BaseResultMap">
    select
        <include refid="Base_Column_List" />
    from time_control_self_plan_feedback
    where self_plan_id = #{planId,jdbcType=INTEGER}
    and feedback_type = #{feedbackType,jdbcType=INTEGER}
  </select>

  <select id="listFeedback" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from time_control_self_plan_feedback
    where self_plan_id = #{planId,jdbcType=INTEGER}
    and feedback_type = 1
    ORDER BY
    create_time DESC
    LIMIT #{pageNum}, #{numPerPage}
  </select>

  <select id="listFeedbackCount" parameterType="integer" resultType="integer">
    select
    count(*)
    from
    time_control_self_plan_feedback
    where self_plan_id = #{planId,jdbcType=INTEGER}
    and feedback_type = 1
  </select>
</mapper>