<?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.zm.order.tool.server.hint.HintOrderCommentDetailsDao">
    <resultMap id="ResultMap" type="com.zm.order.tool.server.model.OrderCommentDetails">
		<id column="id" jdbcType="BIGINT" property="id"/>
		<result column="order_no" jdbcType="VARCHAR" property="orderNo"/>
		<result column="user_id" jdbcType="BIGINT" property="userId"/>
		<result column="seller_id" jdbcType="BIGINT" property="sellerId"/>
		<result column="store_id" jdbcType="BIGINT" property="storeId"/>
		<result column="comment_type" jdbcType="INTEGER" property="commentType"/>
		<result column="comment_score" jdbcType="INTEGER" property="commentScore"/>
		<result column="comment_name" jdbcType="INTEGER" property="commentName"/>
		<result column="created_at" jdbcType="TIMESTAMP" property="createdAt"/>
		<result column="updated_at" jdbcType="TIMESTAMP" property="updatedAt"/>
		<result column="is_deleted" jdbcType="INTEGER" property="isDeleted"/>
	</resultMap>

	<sql id="tb">
        order_comment_details
    </sql>

    <sql id="cols_all">
        id,
		order_no,
		user_id,
		seller_id,
		store_id,
		comment_type,
		comment_score,
		comment_name,
		created_at,
		updated_at,
		is_deleted
    </sql>

    <sql id="values">
    	#{id,jdbcType=BIGINT},
		#{orderNo,jdbcType=VARCHAR},
		#{userId,jdbcType=BIGINT},
		#{sellerId},
		#{storeId},
		#{commentType,jdbcType=INTEGER},
		#{commentScore,jdbcType=INTEGER},
		#{commentName},
		now(),
		now(),
		0
    </sql>

    <select id="selectByOrderNo" parameterType = "map" resultMap="ResultMap">
        SELECT
        <include refid="cols_all"/>
        FROM
        <include refid="tb"/>
        <where>
            seller_id = #{sellerId} and order_no = #{orderNo} and is_deleted = 0
        </where>
        limit 20
    </select>

    <update id="update" parameterType="map">
        UPDATE
        <include refid="tb"/>
        <set>
			<if test="commentType != null">
				comment_type = #{commentType,jdbcType=INTEGER},
			</if>
			<if test="commentScore != null">
				comment_score = #{commentScore,jdbcType=INTEGER},
			</if>
            updated_at = now()
        </set>
        where id = #{id}
    </update>

	<update id="batchUpdateDate" parameterType="list">
		update
		<include refid="tb"/>
		<set>
			updated_at = now()
		</set>
		where
		id in
		<foreach collection="list" item="id" index="index" open="(" close=")" separator=",">
			#{id}
		</foreach>
	</update>

</mapper>