<?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.yami.shop.user.comment.dao.UserLevelLogMapper">

  <resultMap id="userLevelLogMap" type="com.yami.shop.user.comment.model.UserLevelLog">
    <id column="level_log_id" property="levelLogId" />
    <result column="user_id" property="userId"/>
    <result column="level" property="level"/>
    <result column="level_type" property="levelType"/>
    <result column="create_time" property="createTime"/>
    <result column="state" property="state"/>
    <result column="gift_time" property="giftTime"/>
    <result column="dev_id" property="devId"/>
    <result column="dev_no" property="devNo"/>
    <result column="addr_order_id" property="addrOrderId"/>
  </resultMap>
  <select id="getPage" resultType="com.yami.shop.user.comment.model.UserLevelLog">
    SELECT ul.*,u.nick_name,d.dvy_name FROM tz_user_level_log ul
    JOIN tz_user u ON u.user_id = ul.user_id
    LEFT JOIN tz_delivery d ON d.dvy_id = ul.dev_id
    <where>
      <if test="userLevelLog.nickName != null">
        u.nick_name LIKE CONCAT("%",#{userLevelLog.nickName},"%")
      </if>
      <if test="userLevelLog.state != null">
        And ul.state = #{userLevelLog.state}
      </if>
    </where>
  </select>
    <select id="getMaxLevelByUserId" resultType="java.lang.Integer">
      SELECT MAX(`level`) FROM `tz_user_level_log` WHERE user_id = #{userId} and level_type=0
    </select>
</mapper>
