<?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.WeixinClockRewardDaoImpl">

    <resultMap id="BaseResultMap" type="com.pcloud.book.weixinclock.entity.WeixinClockReward">
        <id column="weixin_clock_reward_id" property="weixinClockRewardId" jdbcType="BIGINT"/>
        <result column="weixin_clock_id" property="weixinClockId" jdbcType="BIGINT"/>
        <result column="clock_days" property="clockDays" jdbcType="INTEGER"/>
        <result column="reward_num" property="rewardNum" jdbcType="INTEGER"/>
        <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
    </resultMap>

    <insert id="batchInsert" parameterType="weixinClockReward" useGeneratedKeys="true" keyProperty="weixinClockRewardId" flushCache="true">
        insert into weixin_clock_reward (
        weixin_clock_id,
        clock_days,
        reward_num,
        create_time
        ) values
        <foreach collection="list" item="item" index="index" separator=",">
            (
            #{item.weixinClockId,jdbcType=BIGINT},
            #{item.clockDays,jdbcType=INTEGER},
            #{item.rewardNum,jdbcType=INTEGER},
            NOW()
            )
        </foreach>
    </insert>

    <select id="listRewardDetail4Adviser" parameterType="long" resultMap="BaseResultMap">
        SELECT clock_days,reward_num
        FROM weixin_clock_reward
        WHERE weixin_clock_id = #{weixinClockId}
        ORDER BY clock_days asc
    </select>

    <!-- 删除书籍应用关联信息 -->
    <delete id="deleteById" parameterType="long" flushCache="true">
		DELETE FROM
			weixin_clock_reward
		WHERE
			weixin_clock_id = #{weixinClockId}
	</delete>

    <select id="getGrantNumFromReward" parameterType="map" resultType="Integer">
        select reward_num
        from weixin_clock_reward
        WHERE weixin_clock_id = #{weixinClockId}
        AND clock_days = #{clockDays}
        LIMIT 1
    </select>

</mapper>