<?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.dao.OrderCommentCountDao">
    <resultMap id="ResultMap" type="com.zm.order.tool.server.model.OrderCommentCount">
		<id column="id" jdbcType="BIGINT" property="id"/>
		<result column="seller_id" jdbcType="BIGINT" property="sellerId"/>
		<result column="store_id" jdbcType="BIGINT" property="storeId"/>
		<result column="comment_count" jdbcType="INTEGER" property="commentCount"/>
		<result column="good_count" jdbcType="INTEGER" property="goodCount"/>
		<result column="bad_count" jdbcType="INTEGER" property="badCount"/>
		<result column="reply_count" jdbcType="INTEGER" property="replyCount"/>
		<result column="quality_count" jdbcType="INTEGER" property="qualityCount"/>
		<result column="image_count" jdbcType="INTEGER" property="imageCount"/>
		<result column="anonymous_count" jdbcType="INTEGER" property="anonymousCount"/>
		<result column="recommend_count" jdbcType="INTEGER" property="recommendCount"/>
		<result column="score_info" jdbcType="VARCHAR" property="scoreInfo"/>
		<result column="version" jdbcType="INTEGER" property="version"/>
		<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_count
    </sql>

    <sql id="cols_all">
        id,
		seller_id,
		store_id,
		comment_count,
		good_count,
		middle_count,
		bad_count,
		reply_count,
		quality_count,
		image_count,
		anonymous_count,
		recommend_count,
		score_info,
		version,
		created_at,
		updated_at,
		is_deleted
    </sql>

    <sql id="values">
    	#{id,jdbcType=BIGINT},
		#{sellerId,jdbcType=BIGINT},
		#{storeId,jdbcType=BIGINT},
		#{commentCount,jdbcType=INTEGER},
		#{goodCount,jdbcType=INTEGER},
		#{middleCount,jdbcType=INTEGER},
		#{badCount,jdbcType=INTEGER},
		#{replyCount,jdbcType=INTEGER},
		#{qualityCount,jdbcType=INTEGER},
		#{imageCount,jdbcType=INTEGER},
		#{anonymousCount,jdbcType=INTEGER},
		#{recommendCount,jdbcType=INTEGER},
		#{scoreInfo},
		0,
		now(),
		now(),
		0
    </sql>

    <insert id="insert" parameterType="com.zm.order.tool.server.model.OrderCommentCount"
                        keyColumn="id" keyProperty="id" useGeneratedKeys="true">
        insert into
        <include refid="tb"/>
        (<include refid="cols_all"/>)
        values
        (<include refid="values"/>)
    </insert>

    <select id="selectList" parameterType="map" resultMap="ResultMap">
        SELECT
        <include refid="cols_all"/>
        FROM
        <include refid="tb"/>
        <where>
			<if test="sellerId != null">
				sellerId = #{seller_id}
			</if>
			<if test="sellerIdList != null and sellerIdList.size > 0">
				AND seller_id in
				<foreach collection="sellerIdList" item="selleId" index="index" open="(" close=")" separator=",">
					#{selleId}
				</foreach>
			</if>
			<if test="storeIdList != null and storeIdList.size > 0">
				AND store_id in
				<foreach collection="storeIdList" item="storeId" index="index" open="(" close=")" separator=",">
					#{storeId}
				</foreach>
			</if>
			<if test="storeId != null">
				storeId = #{store_id}
			</if>
            is_deleted = 0
        </where>
        order by id desc
        <if test="start != null">
            limit ${start}, ${pageSize}
        </if>
    </select>

    <select id="selectOne" parameterType="map" resultMap="ResultMap">
        SELECT
        <include refid="cols_all"/>
        FROM
        <include refid="tb"/>
        <where>
			seller_id = #{sellerId} and store_id = #{storeId}
        </where>
        limit 1
    </select>

    <update id="update" parameterType="com.zm.order.tool.server.model.OrderCommentCount">
        UPDATE
        <include refid="tb"/>
        <set>
			<if test="commentCount != null">
				comment_count = #{commentCount,jdbcType=INTEGER},
			</if>
			<if test="goodCount != null">
				good_count = #{goodCount,jdbcType=INTEGER},
			</if>
			<if test="middleCount != null">
				middle_count = #{middleCount,jdbcType=INTEGER},
			</if>
			<if test="badCount != null">
				bad_count = #{badCount,jdbcType=INTEGER},
			</if>
			<if test="replyCount != null">
				reply_count = #{replyCount,jdbcType=INTEGER},
			</if>
			<if test="qualityCount != null">
				quality_count = #{qualityCount,jdbcType=INTEGER},
			</if>
			<if test="imageCount != null">
				image_count = #{imageCount,jdbcType=INTEGER},
			</if>
			<if test="anonymousCount != null">
				anonymous_count = #{anonymousCount,jdbcType=INTEGER},
			</if>
			<if test="recommendCount != null">
				recommend_count = #{recommendCount,jdbcType=INTEGER},
			</if>
			<if test="scoreInfo != null">
				score_info = #{scoreInfo},
			</if>
			updated_at = now(),
			version = version + 1
        </set>
        where id = #{id}
		<if test="version != null">
			AND version = #{version}
		</if>
    </update>

</mapper>