LotteryRecordMapper.xml 4.26 KB
<?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.yoho.lottery.dal.LotteryRecordMapper">
  <resultMap id="BaseResultMap" type="com.yoho.lottery.dal.model.LotteryRecord">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="lottery_id" jdbcType="INTEGER" property="lotteryId" />
    <result column="uid" jdbcType="INTEGER" property="uid" />
    <result column="status" jdbcType="TINYINT" property="status" />
    <result column="flag" jdbcType="VARCHAR" property="flag" />
    <result column="prize_id" jdbcType="INTEGER" property="prizeId" />
    <result column="mod_time" jdbcType="INTEGER" property="modTime" />
  </resultMap>
  
  <sql id="Base_Column_List" >
    id, lottery_id, uid, status, flag, prize_id, mod_time
  </sql>
  
  <delete id="deleteByPrimaryKey">
    delete from lottery_record_${shardFactor}
    where id = #{id,jdbcType=INTEGER}
  </delete>
  
  <insert id="insert">
    insert into lottery_record_${shardFactor} (id, lottery_id, uid, 
      status, flag, prize_id, 
      mod_time)
    values (#{record.id,jdbcType=INTEGER}, #{record.lotteryId,jdbcType=INTEGER}, #{record.uid,jdbcType=INTEGER}, 
      #{record.status,jdbcType=TINYINT}, #{record.flag,jdbcType=VARCHAR}, #{record.prizeId,jdbcType=INTEGER}, 
      #{record.modTime,jdbcType=INTEGER})
  </insert>
  
  <update id="updateByPrimaryKey">
    update lottery_record_${shardFactor}
    set lottery_id = #{record.lotteryId,jdbcType=INTEGER},
      uid = #{record.uid,jdbcType=INTEGER},
      status = #{record.status,jdbcType=TINYINT},
      flag = #{record.flag,jdbcType=VARCHAR},
      prize_id = #{record.prizeId,jdbcType=INTEGER},
      mod_time = #{record.modTime,jdbcType=INTEGER}
    where id = #{record.id,jdbcType=INTEGER}
  </update>
  
  <select id="selectByPrimaryKey" resultMap="BaseResultMap">
    select <include refid="Base_Column_List" />
    from lottery_record_${shardFactor}
    where id = #{id,jdbcType=INTEGER}
  </select>
  <select id="selectByIds" resultMap="BaseResultMap">
    select id, lottery_id, uid, status, flag, prize_id, mod_time
    from lottery_record_${shardFactor}
    where id in 
    <foreach collection="ids" item="id" index="index"
            open="(" close=")" separator=",">
        #{id}
    </foreach>
  </select>
  <select id="selectAll" resultMap="BaseResultMap">
    select <include refid="Base_Column_List" />
    from lottery_record_${shardFactor}
  </select>
  
  <select id="selectOrderRecords" resultMap="BaseResultMap">
    select <include refid="Base_Column_List" />
    from lottery_record_${shardFactor}
    where lottery_id = #{lotteryId,jdbcType=INTEGER}
    and uid = #{userId,jdbcType=INTEGER}
    <if test="orderCode != null and orderCode !=''">
    	and flag = #{orderCode,jdbcType=VARCHAR}
    </if>
    <if test="lotteryId != null">
    	and lottery_id = #{lotteryId,jdbcType=INTEGER}
    </if>
  </select>
  <select id="selectOrderRecordIds" resultType="java.lang.Integer">
    select id
    from lottery_record_${shardFactor}
    where uid = #{userId,jdbcType=INTEGER}
    <if test="lotteryId != null">
    	and lottery_id = #{lotteryId,jdbcType=INTEGER}
    </if>
    <if test="orderCode != null and orderCode !=''">
    	and flag = #{orderCode,jdbcType=INTEGER}
    </if>
  </select>
  
  <select id="selectUserLotteryPrizeCount" resultType="java.lang.Integer">
    select case when count(*) is null then 0 else count(*) end count
    from lottery_record_${shardFactor}
    where lottery_id = #{lotteryId,jdbcType=INTEGER}
    and uid = #{userId,jdbcType=INTEGER} and prize_id is not null
  </select>
  
  <select id="selectLotteryPrizeInfo" resultType="com.yoho.lottery.dal.model.LotteryPrizeInfo">
    select prize_id as prizeId , count(*) as count
    from lottery_record_${shardFactor}
    where lottery_id = #{lotteryId,jdbcType=INTEGER} and prize_id is not null
    group by prize_id
  </select>
  
  <select id="selectByUidAndOrderCodes" resultMap="BaseResultMap">
    select <include refid="Base_Column_List" /> 
    from lottery_record_${shardFactor}
    where uid = #{userId,jdbcType=INTEGER} and flag in 
    <foreach item="item" index="index" collection="orderCodes" open="(" separator="," close=")">
      #{item}
    </foreach>
  </select>
</mapper>