ActPrizeProductMapper.xml 9.86 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.activity.dal.ActPrizeProductMapper">
  <resultMap id="BaseResultMap" type="com.yoho.activity.dal.model.ActPrizeProduct">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="act_id" jdbcType="INTEGER" property="actId" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="price" jdbcType="DECIMAL" property="price" />
    <result column="status" jdbcType="TINYINT" property="status" />
    <result column="start_time" jdbcType="INTEGER" property="startTime" />
    <result column="end_time" jdbcType="INTEGER" property="endTime" />
    <result column="limit" jdbcType="INTEGER" property="limit" />
    <result column="sort" jdbcType="INTEGER" property="sort" />
    <result column="cover_img" jdbcType="VARCHAR" property="coverImg" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="is_full" jdbcType="TINYINT" property="isFull" />
    <result column="channel" jdbcType="INTEGER" property="channel" />
    <result column="notice" jdbcType="VARCHAR" property="notice" />
    <result column="lottery_info" jdbcType="VARCHAR" property="lotteryInfo" />
    <result column="lottery_time" jdbcType="INTEGER" property="lotteryTime" />
    <result column="content" jdbcType="VARCHAR" property="content" />
  </resultMap>
  <sql id="Base_Column_List">
    id, act_id, name, price, status, start_time, end_time, limit, sort, cover_img, create_time, 
    is_full, channel, notice, lottery_info, lottery_time
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from act_prize_product
    where id = #{id,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from act_prize_product
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.yoho.activity.dal.model.ActPrizeProduct">
    insert into act_prize_product (id, act_id, name, 
      price, status, start_time, 
      end_time, limit, sort, 
      cover_img, create_time, is_full, 
      channel, notice, lottery_info, 
      lottery_time)
    values (#{id,jdbcType=INTEGER}, #{actId,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, 
      #{price,jdbcType=DECIMAL}, #{status,jdbcType=TINYINT}, #{startTime,jdbcType=INTEGER}, 
      #{endTime,jdbcType=INTEGER}, #{limit,jdbcType=INTEGER}, #{sort,jdbcType=INTEGER}, 
      #{coverImg,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, #{isFull,jdbcType=TINYINT}, 
      #{channel,jdbcType=INTEGER}, #{notice,jdbcType=VARCHAR}, #{lotteryInfo,jdbcType=VARCHAR}, 
      #{lotteryTime,jdbcType=INTEGER})
  </insert>
  <insert id="insertSelective" parameterType="com.yoho.activity.dal.model.ActPrizeProduct">
    insert into act_prize_product
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="actId != null">
        act_id,
      </if>
      <if test="name != null">
        name,
      </if>
      <if test="price != null">
        price,
      </if>
      <if test="status != null">
        status,
      </if>
      <if test="startTime != null">
        start_time,
      </if>
      <if test="endTime != null">
        end_time,
      </if>
      <if test="limit != null">
        limit,
      </if>
      <if test="sort != null">
        sort,
      </if>
      <if test="coverImg != null">
        cover_img,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
      <if test="isFull != null">
        is_full,
      </if>
      <if test="channel != null">
        channel,
      </if>
      <if test="notice != null">
        notice,
      </if>
      <if test="lotteryInfo != null">
        lottery_info,
      </if>
      <if test="lotteryTime != null">
        lottery_time,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=INTEGER},
      </if>
      <if test="actId != null">
        #{actId,jdbcType=INTEGER},
      </if>
      <if test="name != null">
        #{name,jdbcType=VARCHAR},
      </if>
      <if test="price != null">
        #{price,jdbcType=DECIMAL},
      </if>
      <if test="status != null">
        #{status,jdbcType=TINYINT},
      </if>
      <if test="startTime != null">
        #{startTime,jdbcType=INTEGER},
      </if>
      <if test="endTime != null">
        #{endTime,jdbcType=INTEGER},
      </if>
      <if test="limit != null">
        #{limit,jdbcType=INTEGER},
      </if>
      <if test="sort != null">
        #{sort,jdbcType=INTEGER},
      </if>
      <if test="coverImg != null">
        #{coverImg,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="isFull != null">
        #{isFull,jdbcType=TINYINT},
      </if>
      <if test="channel != null">
        #{channel,jdbcType=INTEGER},
      </if>
      <if test="notice != null">
        #{notice,jdbcType=VARCHAR},
      </if>
      <if test="lotteryInfo != null">
        #{lotteryInfo,jdbcType=VARCHAR},
      </if>
      <if test="lotteryTime != null">
        #{lotteryTime,jdbcType=INTEGER},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.yoho.activity.dal.model.ActPrizeProduct">
    update act_prize_product
    <set>
      <if test="actId != null">
        act_id = #{actId,jdbcType=INTEGER},
      </if>
      <if test="name != null">
        name = #{name,jdbcType=VARCHAR},
      </if>
      <if test="price != null">
        price = #{price,jdbcType=DECIMAL},
      </if>
      <if test="status != null">
        status = #{status,jdbcType=TINYINT},
      </if>
      <if test="startTime != null">
        start_time = #{startTime,jdbcType=INTEGER},
      </if>
      <if test="endTime != null">
        end_time = #{endTime,jdbcType=INTEGER},
      </if>
      <if test="limit != null">
        limit = #{limit,jdbcType=INTEGER},
      </if>
      <if test="sort != null">
        sort = #{sort,jdbcType=INTEGER},
      </if>
      <if test="coverImg != null">
        cover_img = #{coverImg,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="isFull != null">
        is_full = #{isFull,jdbcType=TINYINT},
      </if>
      <if test="channel != null">
        channel = #{channel,jdbcType=INTEGER},
      </if>
      <if test="notice != null">
        notice = #{notice,jdbcType=VARCHAR},
      </if>
      <if test="lotteryInfo != null">
        lottery_info = #{lotteryInfo,jdbcType=VARCHAR},
      </if>
      <if test="lotteryTime != null">
        lottery_time = #{lotteryTime,jdbcType=INTEGER},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.yoho.activity.dal.model.ActPrizeProduct">
    update act_prize_product
    set act_id = #{actId,jdbcType=INTEGER},
      name = #{name,jdbcType=VARCHAR},
      price = #{price,jdbcType=DECIMAL},
      status = #{status,jdbcType=TINYINT},
      start_time = #{startTime,jdbcType=INTEGER},
      end_time = #{endTime,jdbcType=INTEGER},
      limit = #{limit,jdbcType=INTEGER},
      sort = #{sort,jdbcType=INTEGER},
      cover_img = #{coverImg,jdbcType=VARCHAR},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      is_full = #{isFull,jdbcType=TINYINT},
      channel = #{channel,jdbcType=INTEGER},
      notice = #{notice,jdbcType=VARCHAR},
      lottery_info = #{lotteryInfo,jdbcType=VARCHAR},
      lottery_time = #{lotteryTime,jdbcType=INTEGER}
    where id = #{id,jdbcType=INTEGER}
  </update>

  <sql id="selectActListSQL">
    <if test="record.type == 1 and record.nowTime != null">
      and status > 0 and start_time > #{record.nowTime}
    </if>
    <if test="record.type == 2 and record.nowTime != null">
      and status > 1 or end_time &lt; #{record.nowTime} or is_full > 0
    </if>
    <if test="record.type == 0 and record.nowTime != null">
      and status = 1 and start_time &lt;= #{record.nowTime} and end_time >= #{record.nowTime} and is_full = 0
    </if>
    <if test="record.channel != null">
      and channel = #{record.channel}
    </if>
  </sql>
  <select id="selectActList" resultMap="BaseResultMap">
    select * from act_prize_product where 1=1
    <include refid="selectActListSQL" />
    order by sort desc
    limit #{page.startIndex}, #{page.pageSize}
  </select>

  <select id="selectJoinedActList" resultMap="BaseResultMap">
    select u.*, p.name, p.price, p.status, p.cover_img,
    p.start_time, p.end_time, p.is_full, p.lottery_info from
    act_prize_product_user u left join act_prize_product p on u.act_prize_id = p.id
    where 1=1
    <if test="record.channel != null">
      and u.uid = #{record.uid}
    </if>
    <if test="record.type != null and record.type > 0">
      and p.status = 2 or p.end_time &lt; #{record.nowTime}
    </if>
    <if test="record.type == null or record.type == 0">
      and p.status &lt; 2 and p.end_time > #{record.nowTime}
    </if>
    <if test="record.channel != null">
      and channel = #{record.channel}
    </if>
    order by u.create_time desc limit #{page.startIndex}, #{page.pageSize}
  </select>

    <select id="selectContentDetail" resultMap="BaseResultMap">
        select t1.*, t2.content from act_prize_product t1 left join act_prize_product_content_new t2 on t1.id=t2.act_prize_id
        where t1.id=#{id}
        limit 1
    </select>

  <select id="selectUserCodeCount" resultType="java.lang.Integer">
      select count(*) as code_num from act_prize_product_user
      where 1=1
      <if test="actPrizeId != null">
        act_prize_id = #{actPrizeId}
      </if>
      <if test="uid != null">
        uid = #{uid}
      </if>
  </select>


</mapper>