user-level-record-mapper.xml
1.97 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
<?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 仝玉甫 -->
<mapper namespace="com.cjs.cms.dao.user.point.UserLevelRecordDao">
<sql id="user_level_record_field">
id, user_id, level, level_at, create_at, create_by
</sql>
<sql id="searchCondition">
where 1 = 1
<if test="userId != null and userId != ''"> and user_id = #{userId} </if>
<if test="startDate != null and startDate != ''"> <![CDATA[ and level_at >= #{startDate}]]> </if>
<if test="endDate != null and endDate != ''"> <![CDATA[ and level_at <= DATE_ADD(#{endDate}, INTERVAL +1 day)]]> </if>
</sql>
<!-- 新增 -->
<insert id="save" parameterType="UserLevelRecordInfo">
insert into user_level_record(user_id, level, level_at, create_at, create_by)
values (#{userId}, #{level}, now(), now(), #{createBy})
</insert>
<select id="search" parameterType="map" resultType="UserLevelRecordInfo">
select <include refid="user_level_record_field"/>
from user_level_record
<include refid="searchCondition" />
order by create_at desc
<include refid="common.pageLimit" />
</select>
<select id="searchTotal" parameterType="map" resultType="int">
select count(*)
from user_level_record
<include refid="searchCondition" />
</select>
<!-- 查询会员指定等级的升级记录 -->
<select id="queryForActive" parameterType="string" resultType="UserLevelRecordInfo">
select <include refid="user_level_record_field" />
from user_level_record
where level = #{level}
</select>
<!-- 查询指定会员升级最高等级记录 -->
<select id="queryForActiveByUserId" parameterType="string" resultType="UserLevelRecordInfo">
select <include refid="user_level_record_field" />
from user_level_record t where level >= 2 and user_id = #{userId}
and not exists
(select 1 from user_level_record where user_id = t.user_id and level > t.level)
</select>
</mapper>