<?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.sqx.modules.order.dao.EvaluateDao">

    <select id="selectScoreByShopId" resultType="com.sqx.modules.order.entity.Evaluate">
        select ifnull(sum(score), 0) as allScore, count(*) as Evaluatecount
        from evaluate
        where shop_id = #{shopId}
    </select>
    <select id="getEvaluateList" resultType="com.sqx.modules.order.entity.Evaluate">
        SELECT e.*,
        gs.shop_name AS shopName,
        g.goods_name as goodsName,
        u.user_name as userName,
        gs.shop_cover as shopCover
        FROM evaluate e
        left join goods_shop gs on e.shop_id = gs.shop_id
        left join goods g on e.goods_id = g.goods_id
        left join tb_user u on e.user_id = u.user_id
        WHERE 1=1
        <if test="evaluate.evaluateMessage!=null and evaluate.evaluateMessage!=''">
            and e.evaluate_message like concat("%", #{evaluate.evaluateMessage},"%")
        </if>
        <if test="evaluate.orderNumber!=null and evaluate.orderNumber!=''">
            and e.order_number like concat("%",#{evaluate.orderNumber},"%")
        </if>
        <if test="evaluate.userId!=null and evaluate.userId!=''">
            and e.user_id = #{evaluate.userId}
        </if>
        <if test="evaluate.shopId!=null and evaluate.evaluate.shopId!=''">
            and e.shop_id = #{evaluate.shopId}
        </if>
        <if test="evaluate.goodsId!=null and evaluate.goodsId!=''">
            and e.goods_id = #{evaluate.goodsId}
        </if>

        <if test="evaluate.userName!=null and evaluate.userName!=''">
            and u.user_name like concat("%",#{evaluate.userName},"%")
        </if>
        <if test="evaluate.shopName!=null and evaluate.shopName!=''">
            and gs.shop_name like concat("%",#{evaluate.shopName},"%")
        </if>
        <if test="evaluate.goodsName!=null and evaluate.goodsName!=''">
            and g.goods_name like concat("%",#{evaluate.goodsName},"%")
        </if>
        order by create_time desc
    </select>

</mapper>