CouponViewMapper.xml 5.74 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.yohoufo.dal.promotion.CouponViewMapper">
  <resultMap id="BaseResultMap" type="com.yohoufo.dal.promotion.model.Coupon">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="coupon_token" jdbcType="VARCHAR" property="couponToken" />
    <result column="coupon_name" jdbcType="VARCHAR" property="couponName" />
    <result column="coupon_amount" jdbcType="DECIMAL" property="couponAmount" />
      <result column="coupon_type" jdbcType="INTEGER" property="couponType" />
    <result column="coupon_num" jdbcType="INTEGER" property="couponNum" />
    <result column="use_num" jdbcType="SMALLINT" property="useNum" />
    <result column="send_num" jdbcType="INTEGER" property="sendNum" />
    <result column="use_limit_type" jdbcType="TINYINT" property="useLimitType" />
    <result column="use_limit_value" jdbcType="SMALLINT" property="useLimitValue" />
    <result column="product_limit_type" jdbcType="TINYINT" property="productLimitType" />
    <result column="product_limit_value" jdbcType="VARCHAR" property="productLimitValue" />
    <result column="start_time" jdbcType="INTEGER" property="startTime" />
    <result column="end_time" jdbcType="INTEGER" property="endTime" />
    <result column="status" jdbcType="TINYINT" property="status" />
    <result column="create_time" jdbcType="INTEGER" property="createTime" />
    <result column="pid" jdbcType="INTEGER" property="pid" />
    <result column="remark" jdbcType="VARCHAR" property="remark" />
    <result column="skup_forbid_type" jdbcType="VARCHAR" property="skupForbidType" />
    <result column="skup_allow_type" jdbcType="VARCHAR" property="skupAllowType" />
    <result column="business_client" jdbcType="VARCHAR" property="businessClient" />
    <result column="receive_start_time" property="receiveStartTime" jdbcType="INTEGER" />
    <result column="receive_end_time" property="receiveEndTime" jdbcType="INTEGER" />
    <result column="check_required" property="checkRequired" jdbcType="INTEGER" />
  </resultMap>
  <sql id="Base_Column_List">
    id, coupon_token, coupon_name, coupon_amount, coupon_type, coupon_num, use_num, send_num, 
    use_limit_type, use_limit_value, product_limit_type, product_limit_value, start_time,
    end_time, status, create_time, pid, remark,skup_forbid_type,skup_allow_type,business_client,
    receive_start_time,receive_end_time,check_required
  </sql>

  <sql id="Base_Column_List_With_Alias">
    cpn.id, coupon_token, coupon_name, coupon_amount, coupon_type, coupon_num, use_num, send_num,
    use_limit_type, use_limit_value, product_limit_type, product_limit_value, start_time,
    end_time, status, create_time, pid, remark,skup_forbid_type,skup_allow_type,business_client,
    receive_start_time,receive_end_time,check_required
  </sql>

  <select id="selectByAssociatedPrd" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List_With_Alias" />
    from coupon cpn
    LEFT JOIN `coupon_display` cdp  ON cpn.`id` = cdp.coupon_id
    WHERE cpn.status = 1
    AND cpn.id IN
    (<include refid="query_prd_limit"/> )
    AND cpn.`coupon_num` > cpn.`send_num`
    AND cdp.position_type= #{positionType} AND cdp.`visibility`=1
    AND (#{currentTime} <![CDATA[ < ]]> `end_time` OR #{currentTime} <![CDATA[ < ]]> `receive_end_time`)
    and receive_start_time <![CDATA[ <= ]]> #{currentTime}
    AND `business_client` LIKE CONCAT('%',#{businessClient},'%')
    ORDER BY coupon_type,use_limit_type,`use_limit_value` DESC
    limit #{offset},#{limit}
  </select>

  <select id="selectCntByAssociatedPrd" resultType="int">
    SELECT COUNT(*) cnt FROM coupon cpn
    LEFT JOIN `coupon_display` cdp  ON cpn.`id` = cdp.coupon_id
    WHERE cpn.status = 1
    AND cpn.id IN
    (<include refid="query_prd_limit"/> )
    AND cpn.`coupon_num` > cpn.`send_num`
    AND cdp.position_type= #{positionType} AND cdp.`visibility`=1
    AND (#{currentTime} <![CDATA[ < ]]> `end_time` OR #{currentTime} <![CDATA[ < ]]> `receive_end_time`)
    and receive_start_time <![CDATA[ <= ]]> #{currentTime}
    AND `business_client` LIKE CONCAT('%',#{businessClient},'%')
  </select>

  <sql id="query_prd_limit">
    SELECT DISTINCT cpn.id FROM coupon cpn
    LEFT JOIN `coupon_product_limit` cpl ON cpl.`coupon_id` = cpn.id
    WHERE   ((cpn.`product_limit_type` = 1 AND cpl.`product_id` = #{productId}) OR (cpn.`product_limit_type` = 3 AND cpl.`product_id` != #{productId}) OR cpn.`product_limit_type` =2)
  </sql>

  <select id="selectByAssociatedPrdNCouponType" parameterType="com.yohoufo.dal.promotion.model.CouponQueryParamOfUseLimitType" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List_With_Alias" />
    from coupon cpn
    LEFT JOIN `coupon_display` cdp  ON cpn.`id` = cdp.coupon_id
    WHERE cpn.status = 1
    AND cpn.id IN
    (<include refid="query_prd_limit_coupon_use_limit_type"/> )
    AND cpn.`coupon_num` > cpn.`send_num`
    AND cdp.position_type= #{positionType} AND cdp.`visibility`=1
    AND (#{currentTime} <![CDATA[ < ]]> `end_time` OR #{currentTime} <![CDATA[ < ]]> `receive_end_time`)
    and receive_start_time <![CDATA[ <= ]]> #{currentTime}
    AND `business_client` LIKE CONCAT('%',#{businessClient},'%')
    ORDER BY `use_limit_value` DESC
    limit #{offset},#{limit}
  </select>

  <sql id="query_prd_limit_coupon_use_limit_type">
    SELECT DISTINCT cpn.id FROM coupon cpn
    LEFT JOIN `coupon_product_limit` cpl ON cpl.`coupon_id` = cpn.id
    WHERE   coupon_type = #{couponType}
    and use_limit_type =  #{useLimitType}
    and ((cpn.`product_limit_type` = 1 AND cpl.`product_id` = #{productId}) OR (cpn.`product_limit_type` = 3 AND cpl.`product_id` != #{productId}) OR cpn.`product_limit_type` =2)
  </sql>

</mapper>