<?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.errand.dao.ErrandEvaluateDao">

    <insert id="userEvaluate">
        insert into errand_evaluate (user_id, rider_user_id, indent_number, evaluate_message, satisfaction_flag, create_time)
        values (#{userId},#{riderUserId},#{indentNumber},#{evaluateMessage},#{satisfactionFlag},#{createTime})
    </insert>

    <select id="selectEvaluateScoreByShopIdAndTime" resultType="Double">
        select avg(score) from evaluate where 1=1
        <if test="shopId!=null">
            and shop_id=#{shopId}
        </if>
        <if test="startTime!=null and startTime!=''">
            and date_format(create_time,'%Y-%m-%d')>=date_format(#{startTime},'%Y-%m-%d')
        </if>
        <if test="endTime!=null and endTime!=''">
            and date_format(create_time,'%Y-%m-%d')&lt;=date_format(#{endTime},'%Y-%m-%d')
        </if>
    </select>

    <select id="selectEvaluateList" resultType="com.sqx.modules.errand.entity.ErrandEvaluate">
        select s.* from errand_evaluate s
        left join tb_user u on u.user_id=s.user_id
        left join tb_user ru on ru.user_id=s.rider_user_id
        where 1=1
        <if test="nickName!=null and nickName!=''">
            and u.nick_name like concat('%',#{nickName},'%')
        </if>
        <if test="riderName!=null and riderName!=''">
            and ru.nick_name like concat('%',#{riderName},'%')
        </if>
        <if test="userId!=null">
            and u.user_id=#{userId}
        </if>
        <if test="riderUserId!=null">
            and ru.user_id=#{riderUserId}
        </if>
        <if test="satisfactionFlag!=null and satisfactionFlag!=''">
            and s.satisfaction_flag=#{satisfactionFlag}
        </if>
        <if test="indentNumber!=null and indentNumber!=''">
            and s.indent_number=#{indentNumber}
        </if>
        order by s.create_time desc
    </select>

</mapper>