<?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.LifeAppealManageMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="shop.alien.entity.store.EssentialHolidayComparison">
        <id column="id" property="id" />
        <result column="festival_name" property="festivalName" />
        <result column="festival_date" property="festivalDate" />
        <result column="particular_year" property="particularYear" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, festival_name, festival_date, particular_year
    </sql>

    <select id="getAppealManagement" resultType="shop.alien.entity.store.vo.LifeAppealManageVo">
        SELECT
        appeal.id,
        appeal.store_id,
        store.store_name,
        su.`name` AS store_contact,
        lu.user_phone AS user_phone,
        store.store_tel AS store_phone,
        `comment`.comment_content AS customer_report,
        appeal.appeal_reason,
        appeal.appeal_status AS appeal_type,
        si.img_url as appeal_image,
        sg.img_url AS commentImage,
        CASE
        appeal.appeal_status
        WHEN 0 THEN
        "待处理"
        WHEN 1 THEN
        "成功"
        WHEN 2 THEN
        "失败"
        END AS appeal_type_name,
        `comment`.business_type,
        CASE
        `comment`.business_type
        WHEN 1 THEN
        "订单评论"
        WHEN 2 THEN
        "动态社区评论"
        WHEN 3 THEN
        "活动评论"
        END AS business_type_name,
        appeal.created_time AS appeal_time
        FROM
        store_comment_appeal appeal
        LEFT JOIN store_info store ON appeal.store_id = store.id
        LEFT JOIN store_user su ON su.store_id = store.id and su.delete_flag = 0
        LEFT JOIN store_comment `comment` ON `comment`.id = appeal.comment_id
        LEFT JOIN life_user lu ON `comment`.user_id = lu.id
        LEFT JOIN store_img si ON appeal.img_id = si.id
        LEFT JOIN store_img sg ON sg.id = `comment`.img_id
        WHERE
        1 = 1
        <if test="storeName != null and storeName != ''">
            AND store.store_name LIKE CONCAT('%', #{storeName}, '%')
        </if>
        <if test="storeContact != null and storeContact != ''">
            AND `comment`.comment_content LIKE CONCAT('%', #{storeContact}, '%')
        </if>
        <if test="storePhone != null and storePhone != ''">
            AND lu.user_phone LIKE CONCAT('%', #{storePhone}, '%')
        </if>
        <if test="appealType != null and appealType != ''">
            AND appeal.appeal_status = #{appealType}
        </if>
        ORDER BY
        appeal.created_time DESC
    </select>

</mapper>
