<?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="shop.alien.mapper.StoreEvaluationMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="shop.alien.entity.store.StoreEvaluation">
        <id column="id" property="id" />
        <result column="user_order_id" property="userOrderId" />
        <result column="score" property="score" />
        <result column="other_score" property="otherScore" />
        <result column="evaluation_tags_type" property="evaluationTagsType" />
        <result column="evaluation_tags" property="evaluationTags" />
        <result column="evaluation_content" property="evaluationContent" />
        <result column="evaluation_image" property="evaluationImage" />
        <result column="is_anonymous" property="isAnonymous" />
        <result column="consumption_amount" property="consumptionAmount" />
        <result column="store_id" property="storeId" />
        <result column="user_id" property="userId" />
        <result column="delete_flag" property="deleteFlag" />
        <result column="created_time" property="createdTime" />
        <result column="updated_time" property="updatedTime" />
        <result column="created_user_id" property="createdUserId" />
        <result column="updated_user_id" property="updatedUserId" />
        <result column="levels" property="levels" />
        <result column="pid" property="pid" />
        <result column="likes" property="likes" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id,
        user_order_id,
        score,
        other_score,
        evaluation_tags_type,
        evaluation_tags,
        evaluation_content,
        evaluation_image,
        is_anonymous,
        consumption_amount,
        store_id,
        user_id,
        delete_flag,
        created_time,
        updated_time,
        created_user_id,
        updated_user_id,
        levels,
        pid,
        likes
    </sql>


    <select id="groupCount" parameterType="string" resultType="shop.alien.entity.store.dto.GroupRes">

        SELECT label,
               count(*) AS count
        FROM
            `evaluation_label`
        WHERE
            store_id = #{storeId}
        GROUP BY
            label

    </select>



    <select id="avgSource" parameterType="string" resultType="string">

        SELECT
            ROUND( SUM( score ) / NULLIF( COUNT(*), 0 ), 1 ) AS avg_score
        FROM
            `store_evaluation`
        WHERE
            store_id = #{storeId}
    </select>




</mapper>
