quota-user-mapper.xml
3.63 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
108
109
110
111
112
113
114
115
116
117
118
119
<?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">
<!-- 用户权益 @author tongxiaochuan -->
<mapper namespace="com.cjs.cms.dao.quota.QuotaUserDao">
<sql id="quota_user_field">
id, user_id, otc_code, otc_name, quota,
create_at, create_by, update_at, update_by
</sql>
<sql id="searchCondition">
<if test="otcCode != null and otcCode != ''">
and u.otc_code = #{otcCode}
</if>
<if test="userId != null and userId != ''">
and u.user_id = #{userId}
</if>
<if test="quota == 1">
and u.quota = 0
</if>
<if test="quota == 2">
and u.quota > 0
</if>
<if test="endTime != null and endTime != ''">
and date(valid_end_date) = #{endTime}
</if>
</sql>
<sql id="searchQuotaCondition">
<if test="otcCode != null and otcCode != ''">
and otc_code like CONCAT('%',#{otcCode},'%')
</if>
<if test="otcName != null and otcName != ''">
and otc_name like CONCAT('%',#{otcName},'%')
</if>
<if test="userId != null and userId != ''">
and user_id like CONCAT('%',#{userId},'%')
</if>
</sql>
<!-- 查询用户权益 -->
<select id="searchQuota" parameterType="Map" resultType="map">
select <include refid="quota_user_field" /> from quota_user
where 1=1
<include refid="searchQuotaCondition"/>
<include refid="common.pageLimit" />
</select>
<select id="searchQuotaTotal" parameterType="map" resultType="int">
select count(*) from quota_user
where 1=1
<include refid="searchQuotaCondition"/>
</select>
<!-- 查询指定用户权益 -->
<select id="queryByUserId" parameterType="Map" resultType="QuotaUserInfo">
select <include refid="quota_user_field" />
from quota_user
where user_id = #{userId} and otc_code = #{otcCode}
</select>
<insert id="insert" parameterType="QuotaUserInfo" useGeneratedKeys="true" keyProperty="id">
insert into quota_user(user_id, otc_code, otc_name, create_at, create_by)
values(#{userId},#{otcCode},#{otcName},CURRENT_TIMESTAMP,#{createBy})
</insert>
<update id="updateQuota" parameterType="QuotaUserInfo">
update quota_user set quota = #{quota},
update_by = #{updateBy}, update_at = CURRENT_TIMESTAMP
where id = #{id}
</update>
<update id="updateQuotaByUserId" parameterType="map">
update quota_user set quota =quota+#{quota},
update_at = CURRENT_TIMESTAMP
where user_id = #{userId} and otc_code = #{otcCode}
</update>
<!-- 查询超过有效期时间的用户额度 -->
<select id="search" parameterType="map" resultType="QuotaUserInfo">
select u.id, u.user_id, u.otc_code, u.otc_name, u.quota,
u.update_at, u.update_by, valid_end_date
from quota_user u, quota_config c
where u.otc_code = c.otc_code
and <![CDATA[now() >= c.valid_end_date]]>
and c.allot = 1
<include refid="searchCondition" />
<include refid="common.pageLimit" />
</select>
<select id="searchTotal" parameterType="map"
resultType="int">
select count(1) from quota_user u, quota_config c
where u.otc_code = c.otc_code
and <![CDATA[now() >= c.valid_end_date]]>
and c.allot = 1
<include refid="searchCondition" />
</select>
<!-- 清除超过有效期时间的用户额度-->
<update id="emptyQuota" parameterType="map">
update quota_user set quota = 0 , update_by = #{updateBy} , update_at = now()
where otc_code = #{otcCode} and quota > 0
</update>
<select id="queryQuotaByotcCode" parameterType="String" resultType = "QuotaUserInfo">
select user_id, otc_code, otc_name, quota
from quota_user
where otc_code = #{otcCode} and quota>0
</select>
</mapper>