<?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.HintOrderCommentDao">
    <resultMap id="ResultMap" type="com.zm.order.tool.server.model.OrderComment">
		<id column="id" jdbcType="BIGINT" property="id"/>
		<result column="biz_type" jdbcType="INTEGER" property="bizType"/>
		<result column="order_no" jdbcType="VARCHAR" property="orderNo"/>
		<result column="user_id" jdbcType="BIGINT" property="userId"/>
		<result column="mobile" jdbcType="VARCHAR" property="mobile"/>
		<result column="order_type" jdbcType="INTEGER" property="orderType"/>
		<result column="comment_type" jdbcType="INTEGER" property="commentType"/>
		<result column="seller_id" jdbcType="BIGINT" property="sellerId"/>
		<result column="store_id" jdbcType="BIGINT" property="storeId"/>
		<result column="anonymous" jdbcType="INTEGER" property="anonymous"/>
		<result column="comment_info" jdbcType="VARCHAR" property="commentInfo"/>
		<result column="exist_recommend" jdbcType="INTEGER" property="existRecommend"/>
		<result column="recommend_item_info" jdbcType="VARCHAR" property="recommendItemInfo"/>
		<result column="buyer_remarks" jdbcType="VARCHAR" property="buyerRemarks"/>
		<result column="seller_reply" jdbcType="INTEGER" property="sellerReply"/>
		<result column="seller_reply_info" jdbcType="VARCHAR" property="sellerReplyInfo"/>
		<result column="exist_image" jdbcType="INTEGER" property="existImage"/>
		<result column="comment_image" jdbcType="VARCHAR" property="commentImage"/>
		<result column="hide" jdbcType="INTEGER" property="hide"/>
		<result column="quality" jdbcType="INTEGER" property="quality"/>
		<result column="delivery_comment" jdbcType="INTEGER" property="deliveryComment"/>
		<result column="comment_at" jdbcType="TIMESTAMP" property="commentAt"/>
		<result column="features" jdbcType="VARCHAR" property="features"/>
		<result column="created_at" jdbcType="TIMESTAMP" property="createdAt"/>
		<result column="updated_at" jdbcType="TIMESTAMP" property="updatedAt"/>
		<result column="is_deleted" jdbcType="INTEGER" property="isDeleted"/>
		<result column="version" jdbcType="INTEGER" property="version"/>
		<result column="append_comment_at" jdbcType="TIMESTAMP" property="appendCommentAt"/>
		<result column="append_comment_info" jdbcType="VARCHAR" property="appendCommentInfo"/>
		<result column="comment_feedback" jdbcType="INTEGER" property="commentFeedback"/>
		<result column="performance_type" jdbcType="INTEGER" property="performanceType"/>
		<result column="mobile_cipher" jdbcType="VARCHAR" property="mobileCipher"/>
	</resultMap>

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

    <sql id="cols_all">
        id,
		biz_type,
		order_no,
		user_id,
		mobile,
		order_type,
		comment_type,
		seller_id,
		store_id,
		anonymous,
		comment_info,
		exist_recommend,
		recommend_item_info,
		buyer_remarks,
		seller_reply,
		seller_reply_info,
		exist_image,
		comment_image,
		hide,
		quality,
		delivery_comment,
		comment_at,
		reply_at,
		features,
		created_at,
		updated_at,
		is_deleted,
		version,
		append_comment_at,
		append_comment_info,
		comment_feedback,
		performance_type, mobile_cipher,master_data_source
    </sql>


	<select id="selectOne" parameterType="map" resultMap="ResultMap">
		select
		<include refid="cols_all"/>
		from
		<include refid="tb"/>
		where order_no = #{orderNo} and seller_id = #{sellerId}
		limit 1
	</select>

    <select id="scan" parameterType="map" resultMap="ResultMap">
        SELECT
        <include refid="cols_all"/>
        FROM
        <include refid="tb"/>
        <where>
			<if test="sellerId != null">
				and seller_id = #{sellerId}
			</if>
			<if test="userId != null">
				and user_id = #{userId}
			</if>
			<if test="anonymous != null">
				and anonymous = #{anonymous}
			</if>
			<if test="quality != null">
				and quality = #{quality}
			</if>
			<if test="hide != null">
				and hide = #{hide}
			</if>
			<if test="existRecommend != null">
				and exist_recommend = #{existRecommend}
			</if>
			<if test="updatedAtStart != null">
				<![CDATA[ AND updated_at >= #{updatedAtStart} ]]>
			</if>
			<if test="updatedAtEnd != null">
				<![CDATA[ AND updated_at <= #{updatedAtEnd} ]]>
			</if>
			<if test="commentType != null">
				and comment_type = #{commentType}
			</if>
			<if test="storeId != null">
				and store_id = #{storeId}
			</if>
			<if test="mobile != null and mobile != ''">
				and mobile = #{mobile}
			</if>
			<if test="orderNo != null and orderNo != ''">
				and order_no = #{orderNo}
			</if>
			<if test="sellerReply != null">
				and seller_reply = #{sellerReply}
			</if>
			<if test="existImage != null">
				and exist_image = #{existImage}
			</if>
			<if test="commentAtStart != null">
				<![CDATA[ AND comment_at >= #{commentAtStart} ]]>
			</if>
			<if test="commentAtEnd != null">
				<![CDATA[ AND comment_at <= #{commentAtEnd} ]]>
			</if>
			<if test="replyAtStart != null">
				<![CDATA[ AND reply_at >= #{replyAtStart} ]]>
			</if>
			<if test="replyAtEnd != null">
				<![CDATA[ AND reply_at <= #{replyAtEnd} ]]>
			</if>
			<if test="orderTypeList != null">
				AND order_type in
				<foreach collection="orderTypeList" item="orderType" index="index" open="(" close=")" separator=",">
					#{orderType}
				</foreach>
			</if>
			<if test="storeIdList != null">
				AND store_id in
				<foreach collection="storeIdList" item="storeId" index="index" open="(" close=")" separator=",">
					#{storeId}
				</foreach>
			</if>
			<if test="lastId != null">
				and id > #{lastId}
			</if>
        </where>
		<choose>
			<when test="sortFlag == 1">
				order by updated_at, id
			</when>
			<otherwise>
				order by id
			</otherwise>
		</choose>
		<if test="start != null">
			limit ${start}, ${pageSize}
		</if>
		<if test="size != null">
			limit ${size}
		</if>
    </select>

	<select id="scanIdList" parameterType="map" resultMap="ResultMap">
		SELECT id FROM
		<include refid="tb"/>
		<where>
			seller_id = #{sellerId}
			<if test="userId != null">
				and user_id = #{userId}
			</if>
			<if test="anonymous != null">
				and anonymous = #{anonymous}
			</if>
			<if test="quality != null">
				and quality = #{quality}
			</if>
			<if test="hide != null">
				and hide = #{hide}
			</if>
			<if test="existRecommend != null">
				and exist_recommend = #{existRecommend}
			</if>
			<if test="commentType != null">
				and comment_type = #{commentType}
			</if>
			<if test="mobile != null and mobile != ''">
				and mobile = #{mobile}
			</if>
			<if test="storeId != null">
				and store_id = #{storeId}
			</if>
			<if test="orderNo != null and orderNo != ''">
				and order_no = #{orderNo}
			</if>
			<if test="sellerReply != null">
				and seller_reply = #{sellerReply}
			</if>
			<if test="existImage != null">
				and exist_image = #{existImage}
			</if>
			<if test="commentAtStart != null">
				<![CDATA[ AND comment_at >= #{commentAtStart} ]]>
			</if>
			<if test="commentAtEnd != null">
				<![CDATA[ AND comment_at <= #{commentAtEnd} ]]>
			</if>
			<if test="lastId != null">
				and id > #{lastId}
			</if>
			<if test="orderTypeList != null">
				AND order_type in
				<foreach collection="orderTypeList" item="orderType" index="index" open="(" close=")" separator=",">
					#{orderType}
				</foreach>
			</if>
			<if test="replyAtStart != null">
				<![CDATA[ AND reply_at >= #{replyAtStart} ]]>
			</if>
			<if test="replyAtEnd != null">
				<![CDATA[ AND reply_at <= #{replyAtEnd} ]]>
			</if>
			<if test="storeIdList != null">
				AND store_id in
				<foreach collection="storeIdList" item="storeId" index="index" open="(" close=")" separator=",">
					#{storeId}
				</foreach>
			</if>
			AND is_deleted = 0
		</where>
		<if test="start != null">
			order by comment_at desc
			<choose>
				<when test="fakePageSize != null">
					limit ${start}, ${fakePageSize}
				</when>
				<otherwise>
					limit ${start}, ${pageSize}
				</otherwise>
			</choose>
		</if>
		<if test="size != null">
			order by comment_at
			limit ${size}
		</if>
	</select>

    <update id="update" parameterType="com.zm.order.tool.server.model.OrderComment">
        UPDATE
        <include refid="tb"/>
        <set>
			<if test="anonymous != null">
				anonymous = #{anonymous,jdbcType=INTEGER},
			</if>
			<if test="commentInfo != null">
				comment_info = #{commentInfo,jdbcType=VARCHAR},
			</if>
			<if test="existRecommend != null">
				exist_recommend = #{existRecommend,jdbcType=INTEGER},
			</if>
			<if test="recommendItemInfo != null">
				recommend_item_info = #{recommendItemInfo,jdbcType=VARCHAR},
			</if>
			<if test="quality != null">
				quality = #{quality,jdbcType=INTEGER},
			</if>
			<if test="commentType != null">
				comment_type = #{commentType,jdbcType=INTEGER},
			</if>
			<if test="deliveryComment != null">
				delivery_comment = #{deliveryComment},
			</if>
			<if test="hide != null">
				hide = #{hide,jdbcType=INTEGER},
			</if>
			<if test="buyerRemarks != null">
				buyer_remarks = #{buyerRemarks,jdbcType=VARCHAR},
			</if>
			<if test="sellerReply != null">
				seller_reply = #{sellerReply,jdbcType=INTEGER},
			</if>
			<if test="sellerReplyInfo != null">
				seller_reply_info = #{sellerReplyInfo,jdbcType=VARCHAR},
			</if>
			<if test="existImage != null">
				exist_image = #{existImage,jdbcType=INTEGER},
			</if>
			<if test="commentImage != null">
				comment_image = #{commentImage,jdbcType=VARCHAR},
			</if>
			<if test="commentAt != null">
				comment_at = #{commentAt,jdbcType=TIMESTAMP},
			</if>
			<if test="replyAt != null">
				reply_at = #{replyAt},
			</if>
			<if test="features != null">
				features = #{features,jdbcType=VARCHAR},
			</if>
			updated_at = now()
        </set>
        where id = #{id}
    </update>

</mapper>