<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper  PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "https://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.cpic.xim.mybatis.mapper.RewardsMapper">
    <select id="queryRewardProjects" statementType="STATEMENT" resultMap="RewardProjectMap" useCache="false" flushCache="true">
        select reward_index, reward_name from reward_projects order by reward_index desc
    </select>
    <resultMap id="RewardProjectMap" type="com.cpic.xim.mybatis.pojo.RewardProject">
        <id property="rewardCode" column="reward_index" />
        <result property="rewardName" column="reward_name" javaType="String"/>
    </resultMap>

    <select id="queryRewardTelsaler" statementType="STATEMENT" resultMap="RewardGainerMapper" useCache="false" flushCache="true">
        SELECT hjr.rec_id rec_id,
               hjr.telsaler_name telsaler_name,
               hjr.telsaler_code telsaler_code,
               xm.reward_name reward_name,
               xm.reward_index reward_index
               FROM telsaler_reward hjr,
                    reward_projects xm
         WHERE hjr.reward_index = xm.reward_index
         order by xm.reward_index desc
    </select>
    <resultMap id="RewardGainerMapper" type="com.cpic.xim.mybatis.pojo.RewardGainer">
        <id column="rec_id" property="recID" />
        <result column="telsaler_name" property="callerName" />
        <result column="telsaler_code" property="callerCode" />
        <result column="reward_name" property="rewardProjectName" />
        <result column="reward_index" property="rewardProjectCode" />
    </resultMap>

    <select id="addRewardTelSaler" statementType="CALLABLE" parameterType="java.util.HashMap" useCache="false" flushCache="true" >
        call telsaler_reward_pkg.add_telsaler_reward(
            #{a_reward_index,mode=IN,jdbcType=VARCHAR},
            #{a_telsaler_name,mode=IN,jdbcType=VARCHAR})
    </select>

    <!-- 删除获奖坐席记录 -->
    <select id="deleteRewardTelSaler" statementType="CALLABLE" parameterType="java.util.HashMap"  useCache="false" flushCache="true" >
        call telsaler_reward_pkg.delete_telsaler_reward(
             #{a_rec_id,mode=IN,jdbcType=INTEGER})
    </select>

    <!-- 更新获奖坐席 -->
    <select id="updateRewardTelSaler" statementType="CALLABLE" parameterType="java.util.HashMap"  useCache="false" flushCache="true" >
        call telsaler_reward_pkg.update_telsaler_reward(
            #{a_rec_id,mode=IN,jdbcType=INTEGER},
            #{a_telsaler_name,mode=IN,jdbcType=VARCHAR},
            #{a_reward_index,mode=IN,jdbcType=VARCHAR})
    </select>
</mapper>