<?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.tangguo.mapper.BbsUserPointsExchangeMapper">
	
	<select id="selectPointsUsers" resultType="com.tangguo.domain.vo.QwmhSysUserVO">
		SELECT
			uv.*,
			g.grade_name,
			IFNULL(p.current_points, 0) AS current_points,
			IFNULL(p.accumulated_points, 0) AS accumulated_points
		FROM
			qwmh_sys_user_view uv
		LEFT JOIN
			bbs_user_grade g ON g.user_name = uv.user_name
		LEFT JOIN
			bbs_user_points p ON p.user_name = uv.user_name
		<where>
			<if test="keyword != null and keyword != ''">
				nike_name LIKE CONCAT('%', #{keyword}, '%') OR user_name LIKE CONCAT('%', #{keyword}, '%')
			</if>
		</where>
		ORDER BY
			uv.user_id
	</select>
	
	
	<select id="selectBbsUserPointsExchangeList" resultType="com.tangguo.domain.BbsUserPointsExchange">
		SELECT
			e.*
		FROM
			bbs_user_points_exchange e
		<where>
			<if test="exchange.nikeName != null and exchange.nikeName != ''">
				e.nike_name LIKE CONCAT('%', #{exchange.nikeName}, '%')
			</if>
			<if test="exchange.userName != null and exchange.userName != ''">
				AND e.user_name LIKE CONCAT('%', #{exchange.userName}, '%')
			</if>
			<if test="exchange.goodsName != null and exchange.goodsName != ''">
				AND e.goods_name LIKE CONCAT('%', #{exchange.goodsName}, '%')
			</if>
			<if test="exchange.goodsCode != null and exchange.goodsCode != ''">
				AND e.goods_code LIKE CONCAT('%', #{exchange.goodsCode}, '%')
			</if>
			<if test="exchange.params.startTime != null and exchange.params.startTime != ''">
				AND DATE_FORMAT(create_time, '%Y-%m-%d') >= #{exchange.params.startTime}
			</if>
			<if test="exchange.params.endTime != null and exchange.params.endTime != ''">
				AND DATE_FORMAT(create_time, '%Y-%m-%d') &lt;= #{exchange.params.endTime}
			</if>
		</where>
		ORDER BY
			e.create_time DESC
	</select>
	
</mapper>
