<?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.ruoyi.busi.mapper.BusiEvaluateMapper">

    <resultMap type="BusiEvaluate" id="BusiEvaluateResult">
        <result property="id" column="id"/>
        <result property="userId" column="user_id"/>
        <result property="userType" column="user_type"/>
        <result property="nickname" column="nickname"/>
        <result property="toUserId" column="to_user_id"/>
        <result property="toUserType" column="to_user_type"/>
        <result property="evaluateCode" column="evaluate_code"/>
        <result property="evaluate" column="evaluate"/>
        <result property="creator" column="creator"/>
        <result property="createTime" column="create_time"/>
        <result property="updater" column="updater"/>
        <result property="updateTime" column="update_time"/>
        <result property="delFlag" column="del_flag"/>
    </resultMap>

    <sql id="selectBusiEvaluateVo">
        select id,
               user_id,
               user_type,
               nickname,
               to_user_id,
               to_user_type,
               evaluate_code,
               evaluate,
               creator,
               create_time,
               updater,
               update_time,
               del_flag
        from dl_busi_evaluate
    </sql>

    <select id="queryListPage" parameterType="BusiEvaluate" resultMap="BusiEvaluateResult">
        <include refid="selectBusiEvaluateVo"/>
        <where>
            <if test="entity.userType != null  and entity.userType != ''">and user_type = #{entity.userType}</if>
            <if test="entity.nickname != null  and entity.nickname != ''">and nickname like concat('%',
                #{entity.nickname}, '%')
            </if>
            <if test="entity.toUserId != null ">and to_user_id like concat('%', #{entity.toUserId}, '%')</if>
            <if test="entity.toUserType != null  and entity.toUserType != ''">and to_user_type = #{entity.toUserType}
            </if>
        </where>
    </select>
    <select id="listByToUserId" resultType="com.ruoyi.busi.vo.BusiEvaluateVO">
        SELECT evaluate AS  evaluate,
               COUNT(id) AS num
        FROM dl_busi_evaluate
        WHERE del_flag = 0
          and to_user_id = #{userId}
        GROUP BY evaluate
        order by create_time desc
    </select>
</mapper>
