<?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">
<!-- 命名，每一个映射对象不一样 namespace:必须与对应的接口全类名一致 -->
<mapper namespace="com.iamberry.wechat.service.mapper.IntegralMapper">

	<sql id="allField">
		integral_logs_id integralLogsId,
		integral_logs_openid
		integralLogsOpenid,
		integral_logs_num integralLogsNum,
		integral_logs_type integralLogsType,
		integral_logs_introduction
		integralLogsIntroduction,
		integral_logs_res_type integralLogsResType,
		integral_logs_create_date integralLogsCreateDate
	</sql>
<!-- 加载所有积分列表 -->
	<select id="getIntegralByPage" parameterType="Page" resultType="Integral">
		SELECT
		<include refid="allField" />
		FROM tb_iamberry_user_integral_logs 
		ORDER BY integral_logs_id DESC
		LIMIT #{pageNo},#{pageSize}
	</select>
	
	<!-- 分页显示当前用户的积分列表 -->
	<select id="getIntegralListByOpenId" parameterType="Member"
		resultType="Integral">
		SELECT
		i.integral_logs_id integralLogsId,
		i.integral_logs_openid integralLogsOpenid,
		i.integral_logs_num integralLogsNum,
		i.integral_logs_type integralLogsType,
		i.integral_logs_introduction integralLogsIntroduction,
		i.integral_logs_res_type integralLogsResType,
		i.integral_logs_create_date integralLogsCreateDate
		FROM TB_IAMBERRY_USER_INTEGRAL_LOGS i
		WHERE
		integral_logs_openid=#{userOpenid}
		ORDER BY integral_logs_create_date desc
		LIMIT #{page.pageNo},#{page.pageSize}
	</select>

	<select id="getCount" resultType="int" parameterType="Member">
		SELECT
			COUNT(integral_logs_id)
		FROM TB_IAMBERRY_USER_INTEGRAL_LOGS
		WHERE
		integral_logs_openid=#{userOpenid}
	</select>

	<!-- 添加一条积分变动记录 -->
	<insert id="insertIntegralLogs" parameterType="Integral">
		INSERT INTO
		TB_IAMBERRY_USER_INTEGRAL_LOGS
		(
		INTEGRAL_LOGS_OPENID,
		INTEGRAL_LOGS_NUM,
		INTEGRAL_LOGS_TYPE, INTEGRAL_LOGS_INTRODUCTION,
		INTEGRAL_LOGS_RES_TYPE, INTEGRAL_LOGS_CREATE_DATE
		)
		VALUES
		(
		#{integralLogsOpenid},
		#{integralLogsNum},
		#{integralLogsType},
		#{integralLogsIntroduction},
		#{integralLogsResType},
		#{integralLogsCreateDate}
		)
	</insert>
</mapper>