PrizeMapper.xml 3.01 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.PrizeMapper">
  <resultMap id="BaseResultMap" type="com.yoho.lottery.dal.model.Prize">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="lottery_id" jdbcType="INTEGER" property="lotteryId" />
    <result column="gift_id" jdbcType="INTEGER" property="giftId" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="prize_type" jdbcType="VARCHAR" property="prizeType" />
    <result column="prize_value" jdbcType="VARCHAR" property="prizeValue" />
    <result column="total" jdbcType="INTEGER" property="total" />
    <result column="remain" jdbcType="INTEGER" property="remain" />
    <result column="remark" jdbcType="VARCHAR" property="remark" />
    <result column="image" jdbcType="VARCHAR" property="image" />
  </resultMap>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from prize
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.yoho.lottery.dal.model.Prize">
    insert into prize (id, lottery_id, gift_id, 
      name, prize_type, prize_value, 
      total, remark, remain, image
      )
    values (#{id,jdbcType=INTEGER}, #{lotteryId,jdbcType=INTEGER}, #{giftId,jdbcType=INTEGER}, 
      #{name,jdbcType=VARCHAR}, #{prizeType,jdbcType=VARCHAR}, #{prizeValue,jdbcType=VARCHAR}, 
      #{total,jdbcType=INTEGER}, #{remark,jdbcType=VARCHAR}, #{remain,jdbcType=INTEGER}, #{image,jdbcType=VARCHAR}
      )
  </insert>
  <update id="updateByPrimaryKey" parameterType="com.yoho.lottery.dal.model.Prize">
    update prize
    set lottery_id = #{lotteryId,jdbcType=INTEGER},
      gift_id = #{giftId,jdbcType=INTEGER},
      name = #{name,jdbcType=VARCHAR},
      prize_type = #{prizeType,jdbcType=VARCHAR},
      prize_value = #{prizeValue,jdbcType=VARCHAR},
      total = #{total,jdbcType=INTEGER},
      remark = #{remark,jdbcType=VARCHAR},
      remain = #{remain,jdbcType=INTEGER},
      image = #{image,jdbcType=VARCHAR}
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="subtractPrize" parameterType="java.lang.Integer">
    update prize
    set remain = remain - 1
    where id = #{id,jdbcType=INTEGER} and remain &gt; 0
  </update>
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select id, lottery_id, gift_id, name, prize_type, prize_value, total, remark, remain, image
    from prize
    where id = #{id,jdbcType=INTEGER}
  </select>
  <select id="selectByLotteryId" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select id, lottery_id, gift_id, name, prize_type, prize_value, total, remark, remain, image
    from prize
    where lottery_id = #{lotteryId,jdbcType=INTEGER}
  </select>
  <select id="selectAll" resultMap="BaseResultMap">
    select id, lottery_id, gift_id, name, prize_type, prize_value, total, remark, remain, image
    from prize
  </select>
</mapper>