CouponViewMapper.xml
5.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?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}
<if test="useLimitType != null">
and use_limit_type = #{useLimitType}
</if>
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>