WeUserBehaviorDataMapper.xml
7.55 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<?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.linkwechat.wecom.mapper.WeUserBehaviorDataMapper">
<resultMap type="WeUserBehaviorData" id="WeUserBehaviorDataResult">
<result property="id" column="id"/>
<result property="userId" column="user_id"/>
<result property="statTime" column="stat_time"/>
<result property="newApplyCnt" column="new_apply_cnt"/>
<result property="newContactCnt" column="new_contact_cnt"/>
<result property="chatCnt" column="chat_cnt"/>
<result property="messageCnt" column="message_cnt"/>
<result property="replyPercentage" column="reply_percentage"/>
<result property="avgReplyTime" column="avg_reply_time"/>
<result property="negativeFeedbackCnt" column="negative_feedback_cnt"/>
</resultMap>
<select id="getCountDataByDay" resultType="com.linkwechat.wecom.domain.dto.WePageCountDto">
select
date_format(stat_time, '%Y-%m-%d') as x_time,
IFNULL(sum(new_apply_cnt),0) as new_apply_cnt,
IFNULL(sum(new_contact_cnt),0) as new_contact_cnt,
IFNULL(sum(chat_cnt),0) as chat_cnt,
IFNULL(sum(message_cnt),0) as message_cnt,
IFNULL(sum(reply_percentage),0) as reply_percentage,
IFNULL(sum(avg_reply_time),0) as avg_reply_time,
IFNULL(sum(negative_feedback_cnt),0) as negative_feedback_cnt
from we_user_behavior_data
<where>
<choose>
<when test="type !=null and type == 'day'">
date_format(stat_time, '%Y-%m-%d') = date_format(#{dateTime}, '%Y-%m-%d');
</when>
<when test="type !=null and type == 'week'">
YEARWEEK(date_format(stat_time,'%Y-%m-%d')) = YEARWEEK(date_format(#{dateTime}, '%Y-%m-%d'));
</when>
<when test="type !=null and type == 'month'">
DATE_FORMAT(stat_time,'%Y-%m') = DATE_FORMAT(#{dateTime}, '%Y-%m');
</when>
<!--查询今年-->
<otherwise>
YEAR(stat_time) = YEAR(#{dateTime});
</otherwise>
</choose>
</where>
</select>
<select id="getDayCountData" resultType="com.linkwechat.wecom.domain.dto.WePageCountDto">
SELECT
tbl._date AS x_time,
IFNULL(tbr.new_apply_cnt,0) as new_apply_cnt,
IFNULL(tbr.new_contact_cnt,0) as new_contact_cnt,
IFNULL(tbr.chat_cnt,0) as chat_cnt,
IFNULL(tbr.message_cnt,0) as message_cnt,
IFNULL(tbr.reply_percentage,0) as reply_percentage,
IFNULL(tbr.avg_reply_time,0) as avg_reply_time,
IFNULL(tbr.negative_feedback_cnt,0) as negative_feedback_cnt
FROM (SELECT (@s:=@s+1) AS _index,STR_TO_DATE(DATE(DATE_SUB(CURRENT_DATE,INTERVAL @s DAY)),'%Y-%m-%d') AS _date
FROM information_schema.CHARACTER_SETS,(SELECT @s:=-1) AS init WHERE
@s < #{few}
ORDER BY _date) AS tbl
LEFT JOIN(SELECT
sum(ifnull(wubd.new_apply_cnt, 0)) new_apply_cnt,
sum(ifnull(wubd.new_contact_cnt, 0)) new_contact_cnt,
sum(ifnull(wubd.chat_cnt, 0)) chat_cnt,
sum(ifnull(wubd.message_cnt, 0)) message_cnt,
sum(ifnull(wubd.reply_percentage, 0)) reply_percentage,
sum(ifnull(wubd.avg_reply_time, 0)) avg_reply_time,
sum(ifnull(wubd.negative_feedback_cnt, 0)) negative_feedback_cnt,
STR_TO_DATE(DATE_FORMAT(wubd.stat_time,'%Y-%m-%d'),'%Y-%m-%d') AS finish_date
FROM we_user_behavior_data wubd
where
STR_TO_DATE(DATE_FORMAT(wubd.stat_time,'%Y-%m-%d'),'%Y-%m-%d') >= #{startTime}
AND STR_TO_DATE(DATE_FORMAT(wubd.stat_time,'%Y-%m-%d'),'%Y-%m-%d') <= #{endTime}
GROUP BY finish_date
ORDER BY finish_date
) AS tbr ON tbl._date = tbr.finish_date GROUP BY tbl._date;
</select>
<select id="getWeekCountData" resultType="com.linkwechat.wecom.domain.dto.WePageCountDto">
select CONCAT(left(tbl._date,4),'年',right(tbl._date,2),'周') as x_time,
IFNULL(tbr.new_apply_cnt,0) as new_apply_cnt,
IFNULL(tbr.new_contact_cnt,0) as new_contact_cnt,
IFNULL(tbr.chat_cnt,0) as chat_cnt,
IFNULL(tbr.message_cnt,0) as message_cnt,
IFNULL(tbr.reply_percentage,0) as reply_percentage,
IFNULL(tbr.avg_reply_time,0) as avg_reply_time,
IFNULL(tbr.negative_feedback_cnt,0) as negative_feedback_cnt
from (select (@s := @s + 1) as _index,
yearweek(date(date_sub(date_format(current_date, '%Y-%m-%d'), interval @s week))) as _date
from information_schema.character_sets,
(select @s := -1) as init
where @s < #{few}
order by _date)
as tbl
left join(select
sum(ifnull(wubd.new_apply_cnt, 0)) new_apply_cnt,
sum(ifnull(wubd.new_contact_cnt, 0)) new_contact_cnt,
sum(ifnull(wubd.chat_cnt, 0)) chat_cnt,
sum(ifnull(wubd.message_cnt, 0)) message_cnt,
sum(ifnull(wubd.reply_percentage, 0)) reply_percentage,
sum(ifnull(wubd.avg_reply_time, 0)) avg_reply_time,
sum(ifnull(wubd.negative_feedback_cnt, 0)) negative_feedback_cnt,
yearweek(date_format(wubd.stat_time, '%Y-%m-%d')) as finish_date
from we_user_behavior_data wubd
where yearweek(date_format(wubd.stat_time, '%Y-%m-%d')) >=
yearweek(date(date_sub(date_format(current_date, '%Y-%m-%d'), interval #{few} week)))
and yearweek(date_format(wubd.stat_time, '%Y-%m-%d')) <=
yearweek(date_format(current_date, '%Y-%m-%d'))
group by finish_date
order by finish_date
) as tbr on tbl._date = tbr.finish_date
group by tbl._date;
</select>
<select id="getMonthCountData" resultType="com.linkwechat.wecom.domain.dto.WePageCountDto">
select tbl._date as x_time,
IFNULL(tbr.new_apply_cnt,0) as new_apply_cnt,
IFNULL(tbr.new_contact_cnt,0) as new_contact_cnt,
IFNULL(tbr.chat_cnt,0) as chat_cnt,
IFNULL(tbr.message_cnt,0) as message_cnt,
IFNULL(tbr.reply_percentage,0) as reply_percentage,
IFNULL(tbr.avg_reply_time,0) as avg_reply_time,
IFNULL(tbr.negative_feedback_cnt,0) as negative_feedback_cnt
from (select (@s := @s + 1) as _index, date_format(date_sub(current_date, interval @s month), '%Y-%m') as _date
from information_schema.character_sets,
(select @s := -1) as init
where @s < #{few}
order by _date) as tbl
left join(select
sum(ifnull(wubd.new_apply_cnt, 0)) new_apply_cnt,
sum(ifnull(wubd.new_contact_cnt, 0)) new_contact_cnt,
sum(ifnull(wubd.chat_cnt, 0)) chat_cnt,
sum(ifnull(wubd.message_cnt, 0)) message_cnt,
sum(ifnull(wubd.reply_percentage, 0)) reply_percentage,
sum(ifnull(wubd.avg_reply_time, 0)) avg_reply_time,
sum(ifnull(wubd.negative_feedback_cnt, 0)) negative_feedback_cnt,
date_format(wubd.stat_time, '%Y-%m') as finish_date
from we_user_behavior_data wubd
group by finish_date
order by finish_date
) as tbr on tbl._date = tbr.finish_date
group by tbl._date;
</select>
</mapper>