point-record-mapper.xml
4.02 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
<?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.user.point.PointRecordDao">
<sql id="point_record_field">
id, active_id, user_id, otc_code,otc_name,occur_count, remain_count, post_count,
expired_date, business_type, remark, gift_by, create_at, create_by
</sql>
<sql id="searchCondition">
where 1=1
<if test="userId != null and userId != ''"> and user_id=#{userId} </if>
<if test="otcCode != null and otcCode != ''"> and otc_code=#{otcCode} </if>
<if test="appendType != null and appendType !=''">
and business_type in
<foreach collection="appendType" item="item" index="index" open="(" separator="," close=")">#{item}</foreach>
</if>
<if test="activeId != null and activeId != ''"> and active_id=#{activeId} </if>
<if test="businessType != null and businessType != ''"> and business_type=#{businessType} </if>
<if test="startDate != null and startDate != ''"> <![CDATA[ and create_at >= #{startDate}]]> </if>
<if test="endDate != null and endDate != ''"> <![CDATA[ and create_at <= DATE_ADD(#{endDate}, INTERVAL 1 day)]]> </if>
</sql>
<insert id="insert" parameterType="PointRecordInfo">
insert into point_record(active_id, user_id, occur_count, remain_count, post_count, expired_date, otc_code,otc_name,
business_type, remark, gift_by, create_at, create_by)
values(#{activeId}, #{userId}, #{occurCount}, #{remainCount}, #{postCount}, #{expiredDate}, #{otcCode}, #{otcName},
#{businessType}, #{remark}, #{giftBy}, CURRENT_TIMESTAMP, #{createBy})
</insert>
<update id="update" parameterType="PointRecordInfo">
update point_record set
occur_count = #{occurCount}, remain_count = #{remainCount}, post_count = #{postCount},
remark = #{remark}
where id = #{id}
</update>
<!-- 查询过期待作废积分 -->
<select id="queryExpired" resultType="PointRecordInfo">
select <include refid="point_record_field" />
from point_record
<![CDATA[where expired_date < now() and remain_count > 0 and expired_date is not null]]>
order by user_id
</select>
<sql id="queryCondition">
<if test="businessType != null and businessType != ''">
and business_type = #{businessType}
</if>
<if test="startDate != null and startDate != ''">
<![CDATA[and create_at >= #{startDate} ]]>
</if>
<if test="endDate != null and endDate != ''">
<![CDATA[and create_at <= #{endDate} ]]>
</if>
<if test="flag != null and flag != ''">
<![CDATA[and instr(gift_by, #{flag}) > 0 ]]>
</if>
</sql>
<select id="search" parameterType="map" resultType="PointRecordInfo">
select <include refid="point_record_field" />
from point_record
<include refid="searchCondition" />
order by id desc
<include refid="common.pageLimit" />
</select>
<select id="searchTotal" parameterType="map" resultType="int">
select count(*)
from point_record
<include refid="searchCondition" />
</select>
<select id="searchOccurCount" parameterType="map" resultType="double">
select IFNULL(sum(occur_count),0)
from point_record
<include refid="searchCondition" />
</select>
<select id="queryRecordByCondition" parameterType="map" resultType="PointRecordInfo">
select <include refid="point_record_field" />
from point_record
where user_id = #{userId} and active_id = #{activeId}
<include refid="queryCondition" />
</select>
<!-- 查询新开户用户配额发放记录 -->
<select id="queryRecordByConditions" parameterType="map" resultType="PointRecordInfo">
select <include refid="point_record_field" />
from point_record
<include refid="queryRecordConditions" />
</select>
<sql id="queryRecordConditions">
where occur_count = 20
<if test="userId != null and userId != ''">
and user_id = #{userId}
</if>
<if test="activeId != null and activeId != ''">
and active_id = #{activeId}
</if>
<if test="businessType != null and businessType != ''">
and business_type = #{businessType}
</if>
</sql>
</mapper>