PromotionActivityMapper.xml 6.3 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.ufo.dal.PromotionActivityMapper" >
  <resultMap id="BaseResultMap" type="com.yoho.ufo.dal.model.PromotionActivity" >
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="activity_name" property="activityName" jdbcType="VARCHAR" />
    <result column="label" property="label" jdbcType="VARCHAR" />
    <result column="start_time" property="startTime" jdbcType="INTEGER" />
    <result column="end_time" property="endTime" jdbcType="INTEGER" />
    <result column="promotion_type" property="promotionType" jdbcType="TINYINT" />
    <result column="product_limit_type" property="productLimitType" jdbcType="VARCHAR" />
    <result column="status" property="status" jdbcType="TINYINT" />
    <result column="join_limit_type" property="joinLimitType" jdbcType="INTEGER" />
    <result column="join_limit_times" property="joinLimitTimes" jdbcType="INTEGER" />
    <result column="create_time" property="createTime" jdbcType="INTEGER" />
    <result column="update_time" property="updateTime" jdbcType="INTEGER" />
    <result column="business_client" property="businessClient" jdbcType="VARCHAR" />

  </resultMap>
  <sql id="Base_Column_List" >
    id, activity_name, start_time, end_time, promotion_type, product_scope_type,
    product_limit_type, is_coupon, all_times_limit, day_times_limit, status, create_time,
    update_time, create_user_id, update_user_id
  </sql>

  <select id="selectActivityWithinTime" resultMap="BaseResultMap">
    select id, business_client from promotion_activity
    where <![CDATA[ end_time > #{startTime, jdbcType=INTEGER}  ]]>
    and   <![CDATA[ start_time < #{endTime, jdbcType=INTEGER}  ]]>
    and   id != #{activityId, jdbcType=INTEGER}
    and   status = 1
  </select>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
    select 
    id, activity_name, label, start_time, end_time, promotion_type, product_limit_type, join_limit_type, join_limit_times, status, business_client
    from promotion_activity
    where id = #{id,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
    delete from promotion_activity
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.yoho.ufo.dal.model.PromotionActivity" keyProperty="id" useGeneratedKeys="true">
    insert into promotion_activity ( activity_name, label,  start_time,
      end_time, promotion_type,
      product_limit_type, join_limit_type, join_limit_times,
      status, create_time, update_time, business_client
      )
    values (#{activityName,jdbcType=VARCHAR},#{label,jdbcType=VARCHAR}, #{startTime,jdbcType=INTEGER},
      #{endTime,jdbcType=INTEGER}, #{promotionType,jdbcType=TINYINT},
      #{productLimitType,jdbcType=VARCHAR}, #{joinLimitType,jdbcType=TINYINT}, #{joinLimitTimes,jdbcType=INTEGER},
      #{status,jdbcType=TINYINT}, #{createTime,jdbcType=INTEGER},
      #{updateTime,jdbcType=INTEGER}, #{businessClient,jdbcType=VARCHAR}
      )
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.yoho.ufo.dal.model.PromotionActivity" >
    update promotion_activity
    <set >
      <if test="status != null" >
        status = #{status,jdbcType=TINYINT},
      </if>
      <if test="updateTime != null" >
        update_time = #{updateTime,jdbcType=INTEGER},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.yoho.ufo.dal.model.PromotionActivity" >
    update promotion_activity
    set activity_name = #{activityName,jdbcType=VARCHAR},
      label = #{label,jdbcType=VARCHAR},
      start_time = #{startTime, jdbcType=INTEGER},
      end_time = #{endTime,jdbcType=INTEGER},
      promotion_type = #{promotionType,jdbcType=TINYINT},
      product_limit_type = #{productLimitType,jdbcType=VARCHAR},
      join_limit_type = #{joinLimitType,jdbcType=TINYINT},
      join_limit_times = #{joinLimitTimes,jdbcType=INTEGER},
      status = #{status,jdbcType=TINYINT},
      update_time = #{updateTime,jdbcType=INTEGER},
      business_client = #{businessClient, jdbcType=VARCHAR}
    where id = #{id,jdbcType=INTEGER}
  </update>

  <select id="selectCountByCondition" resultType="java.lang.Integer" >
    select count(1)
    from promotion_activity
    where 1=1
    <if test="record.id != null" >
      and id = #{record.id,jdbcType=INTEGER}
    </if>
    <if test="record.activityName != null" >
      <![CDATA[ AND instr(activity_name ,#{record.activityName}) > 0 ]]>
    </if>
    <if test="record.status != null">
      <if test="record.status == 4">
        <!--已关闭-->
        and status= 2
      </if>
      <if test="record.status == 3">
        <!--已结束-->
        and end_time <![CDATA[< ]]> #{currentTime}
        and status != 2
      </if>
      <if test="record.status == 2">
        <!--进行中-->
        and start_time <![CDATA[<= ]]> #{currentTime}
        and end_time >= #{currentTime}
        and status != 2
      </if>
      <if test="record.status == 1">
        <!--未开始-->
        and start_time > #{currentTime}
        and status != 2
      </if>
    </if>
  </select>

  <select id="selectListByPage" resultMap="BaseResultMap" >
    select
    id, activity_name, label, promotion_type, start_time, end_time, status
    from promotion_activity
    where 1=1
    <if test="record.id != null" >
      and id = #{record.id,jdbcType=INTEGER}
    </if>
    <if test="record.activityName != null" >
      <![CDATA[ AND instr(activity_name ,#{record.activityName}) > 0 ]]>
    </if>
    <if test="record.status != null">
      <if test="record.status == 4">
        <!--已关闭-->
        and status= 2
      </if>
      <if test="record.status == 3">
        <!--已结束-->
        and end_time <![CDATA[< ]]> #{currentTime}
        and status != 2
      </if>
      <if test="record.status == 2">
        <!--进行中-->
        and start_time <![CDATA[<= ]]> #{currentTime}
        and end_time >= #{currentTime}
        and status != 2
      </if>
      <if test="record.status == 1">
        <!--未开始-->
        and start_time > #{currentTime}
        and status != 2
      </if>
    </if>
    order by id desc
    limit #{record.start},#{record.size}
  </select>

</mapper>