<?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.pcloud.book.weixinclock.dao.impl.WeixinClockPrizeRecordDaoImpl" >

    <resultMap id="BaseResultMap" type="com.pcloud.book.weixinclock.entity.WeixinClockPrizeRecord" >
        <id column="weixin_clock_prize_record_id" property="weixinClockPrizeRecordId" jdbcType="BIGINT" />
        <result column="wx_user_id" property="wxUserId" jdbcType="VARCHAR" />
        <result column="wechat_user_id" property="wechatUserId" jdbcType="BIGINT" />
        <result column="clock_prize_id" property="clockPrizeId" jdbcType="BIGINT" />
        <result column="prize_time" property="prizeTime" jdbcType="INTEGER" />
        <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
        <result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
    </resultMap>

    <sql id="Base_Column_List" >
    weixin_clock_prize_record_id, wx_user_id, wechat_user_id, clock_prize_id, prize_time,
    create_time, update_time
  </sql>

    <select id="selectByWxUserIdAndAppId" resultMap="BaseResultMap" parameterType="map" >
        select
        <include refid="Base_Column_List" />
        from weixin_clock_prize_record
        where wx_user_id = #{wxUserId,jdbcType=VARCHAR}
        and clock_prize_id = #{appId}
        LIMIT 1
    </select>

    <insert id="insert" parameterType="com.pcloud.book.weixinclock.entity.WeixinClockPrizeRecord" >
    insert into weixin_clock_prize_record (wx_user_id,wechat_user_id, clock_prize_id, prize_time,
      create_time, update_time)
    values ( #{wxUserId,jdbcType=VARCHAR},#{wechatUserId,jdbcType=BIGINT}, #{clockPrizeId,jdbcType=BIGINT}, #{prizeTime,jdbcType=INTEGER},
      NOW(), NOW())
  </insert>

    <update id="updatePrizeTime" parameterType="map">
      update weixin_clock_prize_record
      set prize_time = prize_time + #{prizeTime,jdbcType=INTEGER},
          update_time = NOW()
      where wx_user_id = #{wxUserId,jdbcType=VARCHAR}
      and clock_prize_id = #{appId}
    </update>

    <select id="getAllPrizeList" parameterType="map" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from weixin_clock_prize_record
        where wx_user_id = #{wxUserId,jdbcType=VARCHAR}
    </select>

    <delete id="deleteByWxUserId" parameterType="map" >
    delete from weixin_clock_prize_record
    where wx_user_id = #{wxUserId,jdbcType=VARCHAR}
  </delete>

</mapper>