<?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="cn.com.countrygarden.bi.main.dao.wcx.WcxReviewMapper">
    <resultMap id="BaseReviewMap" type="cn.com.countrygarden.bi.main.dto.wcx.WcxReviewDto">
        <id column="review_id" property="reviewId"/>
        <result column="review_content" property="reviewContent"/>
        <result column="user_id" property="userId"/>
        <result column="innovation_id" property="innovationId"/>
        <result column="status" property="status"/>
        <result column="create_date" property="createDate"/>
        <result column="employee_name" property="employeeName"/>
        <result column="head_pic_url" property="headPicUrl"/>
    </resultMap>


    <insert id="insert">
        INSERT INTO wcx_review
        (
        review_id,
        review_content,
        user_id,
        innovation_id,
        status,
        create_date
        )
        VALUES
        (
        #{reviewId},
        #{reviewContent},
        #{userId},
        #{innovationId},
        #{status},
        #{createDate}
        )
    </insert>

    <select id="selectPageData" resultMap="BaseReviewMap">
      SELECT
        r.review_id,
        r.review_content,
        r.user_id,
        r.innovation_id,
        r.status,
        r.create_date,
        u.employee_name,
        u.head_pic_url
      FROM wcx_review r
      JOIN wcx_user u on u.user_id = r.user_id
      WHERE r.innovation_id = #{innovationId}
      order by create_date desc, review_id
      limit #{pageOffset}, #{pageSize}
    </select>

    <select id="selectPageCount" resultType="int">
      SELECT count(review_id)
      FROM wcx_review r
      WHERE r.innovation_id = #{innovationId}
    </select>

    <delete id="deleteByPrimaryKey">
        DELETE FROM wcx_review WHERE review_id = #{reviewId}
    </delete>

    <delete id="deleteByInnovationId">
        DELETE FROM wcx_review WHERE innovation_id = #{innovationId}
    </delete>

    <select id="findFirstDto" resultMap="BaseReviewMap">
        SELECT
            r.review_id,
            r.review_content,
            r.user_id,
            r.innovation_id,
            r.status,
            r.create_date,
            u.employee_name
        FROM wcx_review r
        JOIN wcx_user u on u.user_id = r.user_id
        where r.review_id = #{reviewId}
    </select>
</mapper>