<?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.xxfc.platform.activity.mapper.IntegralUserRecordMapper" >
  <resultMap id="BaseResultMap" type="com.xxfc.platform.activity.entity.IntegralUserRecord" >
    <!--
      WARNING - @mbg.generated
    -->
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="user_id" property="userId" jdbcType="INTEGER" />
    <result column="type" property="type" jdbcType="INTEGER" />
    <result column="point" property="point" jdbcType="INTEGER" />
    <result column="integral_rule_code" property="integralRuleCode" jdbcType="VARCHAR" />
    <result column="crt_time" property="crtTime" jdbcType="BIGINT" />
    <result column="is_valid" property="isValid" jdbcType="BIT" />
    <result column="isdel" property="isdel" jdbcType="BIT" />
    <result column="channel_id" property="channelId" jdbcType="INTEGER" />
  </resultMap>

  <select id="selectByUserId" parameterType="java.lang.Integer" resultType="com.xxfc.platform.activity.entity.IntegralUserRecord">
    select * from integral_user_record
    <where>
      <if test="userId != null">
         and user_id = #{userId}
      </if>
    </where>
    order by crt_time DESC
  </select>
  <select id="selectByUserAndTime" resultType="com.xxfc.platform.activity.entity.IntegralUserRecord" parameterType="com.xxfc.platform.activity.vo.IntegralUserRecordDto">
    select * from integral_user_record
    where  user_id = #{userId} and crt_time between #{startTime} and #{endTime} and integral_rule_code = #{integralRuleCode}
  </select>

  <select id="countByUserAndCode" resultType="java.lang.Integer" parameterType="com.xxfc.platform.activity.vo.IntegralUserRecordDto">
    select count(*) from integral_user_record
    where  user_id = #{userId} and integral_rule_code = #{integralRuleCode}
      <if test="startTime != null">
        and crt_time between #{startTime} and #{endTime}
      </if>
  </select>

</mapper>