<?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.buy507.mall.mapper.DmsMemberMonthRewardRecordMapper">
  <resultMap id="BaseResultMap" type="com.buy507.mall.model.DmsMemberMonthRewardRecord">
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="member_id" jdbcType="BIGINT" property="memberId" />
    <result column="value" jdbcType="DECIMAL" property="value" />
    <result column="year" jdbcType="INTEGER" property="year" />
    <result column="month" jdbcType="INTEGER" property="month" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
  </resultMap>
  
  <insert id="insert" parameterType="com.buy507.mall.model.DmsMemberMonthRewardRecord">
    <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into dms_member_month_reward_record (member_id, value, year, month, create_time)
    values (#{memberId, jdbcType=BIGINT}, 
    		#{value, jdbcType=DECIMAL},
    		YEAR(NOW()),
    		#{month, jdbcType=INTEGER},
    		NOW()
    		)
  </insert>
  
  <select id="selectCountByMonth" resultType="java.lang.Integer">
    SELECT count(*) as count
      FROM
        dms_member_month_reward_record a
     WHERE
   		a.year = YEAR(NOW())
   	   AND
   	   	a.month = #{month}
  </select>
  
  
</mapper>