|
|
@@ -10,6 +10,11 @@
|
|
10
|
10
|
inner join biz_consult_session s on s.id = m.session_id and s.consult_type = 2
|
|
11
|
11
|
</sql>
|
|
12
|
12
|
|
|
|
13
|
+ <sql id="aiMessageFilter">
|
|
|
14
|
+ m.sender_role = 3
|
|
|
15
|
+ and m.sender_user_id = 0
|
|
|
16
|
+ </sql>
|
|
|
17
|
+
|
|
13
|
18
|
<select id="selectYearOverviewMetrics" resultType="com.ruoyi.web.modules.screen.domain.dto.LivestockResourceOverviewDto">
|
|
14
|
19
|
select
|
|
15
|
20
|
(select count(distinct asker_user_id)
|
|
|
@@ -25,38 +30,40 @@
|
|
25
|
30
|
(select count(*)
|
|
26
|
31
|
from biz_consult_message m
|
|
27
|
32
|
<include refid="aiMessageJoin"/>
|
|
28
|
|
- where m.sender_role = 3
|
|
29
|
|
- and m.sender_user_id = 0
|
|
30
|
|
- and m.send_time >= #{yearStart}
|
|
31
|
|
- and m.send_time <= #{yearEnd}) as totalQuestionCount,
|
|
|
33
|
+ where <include refid="aiMessageFilter"/>
|
|
|
34
|
+ and m.create_time >= #{yearStart}
|
|
|
35
|
+ and m.create_time <= #{yearEnd}) as totalQuestionCount,
|
|
32
|
36
|
(select avg(m.cost_time)
|
|
33
|
37
|
from biz_consult_message m
|
|
34
|
38
|
<include refid="aiMessageJoin"/>
|
|
35
|
|
- where m.sender_role = 3
|
|
36
|
|
- and m.sender_user_id = 0
|
|
|
39
|
+ where <include refid="aiMessageFilter"/>
|
|
37
|
40
|
and m.cost_time is not null
|
|
38
|
|
- and m.send_time >= #{yearStart}
|
|
39
|
|
- and m.send_time <= #{yearEnd}) as avgCostTimeMs
|
|
|
41
|
+ and m.create_time >= #{yearStart}
|
|
|
42
|
+ and m.create_time <= #{yearEnd}) as avgCostTimeMs
|
|
40
|
43
|
</select>
|
|
41
|
44
|
|
|
42
|
45
|
<select id="countTodayActiveUsers" resultType="long">
|
|
43
|
46
|
select count(distinct asker_user_id)
|
|
44
|
47
|
from biz_consult_session
|
|
45
|
48
|
where <include refid="aiSession"/>
|
|
46
|
|
- and last_message_time >= #{dayStart}
|
|
47
|
|
- and last_message_time <= #{dayEnd}
|
|
|
49
|
+ and update_time >= #{dayStart}
|
|
|
50
|
+ and update_time <= #{dayEnd}
|
|
48
|
51
|
</select>
|
|
49
|
52
|
|
|
50
|
53
|
<select id="countTodayNewUsers" resultType="long">
|
|
51
|
|
- select count(*)
|
|
52
|
|
- from (
|
|
53
|
|
- select asker_user_id
|
|
54
|
|
- from biz_consult_session
|
|
55
|
|
- where <include refid="aiSession"/>
|
|
56
|
|
- group by asker_user_id
|
|
57
|
|
- having min(create_time) >= #{dayStart}
|
|
58
|
|
- and min(create_time) <= #{dayEnd}
|
|
59
|
|
- ) t
|
|
|
54
|
+ select count(distinct asker_user_id)
|
|
|
55
|
+ from biz_consult_session
|
|
|
56
|
+ where <include refid="aiSession"/>
|
|
|
57
|
+ and create_time >= #{dayStart}
|
|
|
58
|
+ and create_time <= #{dayEnd}
|
|
|
59
|
+ and update_time >= #{dayStart}
|
|
|
60
|
+ and update_time <= #{dayEnd}
|
|
|
61
|
+ and asker_user_id not in (
|
|
|
62
|
+ select distinct asker_user_id
|
|
|
63
|
+ from biz_consult_session
|
|
|
64
|
+ where <include refid="aiSession"/>
|
|
|
65
|
+ and create_time < #{dayStart}
|
|
|
66
|
+ )
|
|
60
|
67
|
</select>
|
|
61
|
68
|
|
|
62
|
69
|
<select id="countTodaySessions" resultType="long">
|
|
|
@@ -71,10 +78,9 @@
|
|
71
|
78
|
select count(*)
|
|
72
|
79
|
from biz_consult_message m
|
|
73
|
80
|
<include refid="aiMessageJoin"/>
|
|
74
|
|
- where m.sender_role = 3
|
|
75
|
|
- and m.sender_user_id = 0
|
|
76
|
|
- and m.send_time >= #{dayStart}
|
|
77
|
|
- and m.send_time <= #{dayEnd}
|
|
|
81
|
+ where <include refid="aiMessageFilter"/>
|
|
|
82
|
+ and m.create_time >= #{dayStart}
|
|
|
83
|
+ and m.create_time <= #{dayEnd}
|
|
78
|
84
|
</select>
|
|
79
|
85
|
|
|
80
|
86
|
<select id="selectDailySessionCounts" resultType="com.ruoyi.web.modules.screen.domain.dto.LivestockResourceDateCountDto">
|
|
|
@@ -88,15 +94,14 @@
|
|
88
|
94
|
</select>
|
|
89
|
95
|
|
|
90
|
96
|
<select id="selectDailyAiReplyCounts" resultType="com.ruoyi.web.modules.screen.domain.dto.LivestockResourceDateCountDto">
|
|
91
|
|
- select date_format(m.send_time, '%Y-%m-%d') as bucketKey,
|
|
|
97
|
+ select date_format(m.create_time, '%Y-%m-%d') as bucketKey,
|
|
92
|
98
|
count(*) as count
|
|
93
|
99
|
from biz_consult_message m
|
|
94
|
100
|
<include refid="aiMessageJoin"/>
|
|
95
|
|
- where m.sender_role = 3
|
|
96
|
|
- and m.sender_user_id = 0
|
|
97
|
|
- and m.send_time >= #{rangeStart}
|
|
98
|
|
- and m.send_time <= #{rangeEnd}
|
|
99
|
|
- group by date_format(m.send_time, '%Y-%m-%d')
|
|
|
101
|
+ where <include refid="aiMessageFilter"/>
|
|
|
102
|
+ and m.create_time >= #{rangeStart}
|
|
|
103
|
+ and m.create_time <= #{rangeEnd}
|
|
|
104
|
+ group by date_format(m.create_time, '%Y-%m-%d')
|
|
100
|
105
|
</select>
|
|
101
|
106
|
|
|
102
|
107
|
<select id="selectUserStructure" resultType="com.ruoyi.web.modules.screen.domain.dto.LivestockResourceUserStructureDto">
|
|
|
@@ -109,48 +114,75 @@
|
|
109
|
114
|
select count(*)
|
|
110
|
115
|
from biz_consult_message m
|
|
111
|
116
|
<include refid="aiMessageJoin"/>
|
|
112
|
|
- where m.sender_role = 1
|
|
113
|
|
- and m.send_time >= #{yearStart}
|
|
114
|
|
- and m.send_time <= #{yearEnd}
|
|
|
117
|
+ where <include refid="aiMessageFilter"/>
|
|
|
118
|
+ and m.create_time >= #{yearStart}
|
|
|
119
|
+ and m.create_time <= #{yearEnd}
|
|
115
|
120
|
</select>
|
|
116
|
121
|
|
|
117
|
122
|
<select id="selectAskerCategoryCounts" resultType="com.ruoyi.web.modules.screen.domain.dto.LivestockResourceCategoryCountDto">
|
|
118
|
|
- select case
|
|
119
|
|
- when trim(m.ai_category) is null or trim(m.ai_category) = '' then 'UNCAT'
|
|
120
|
|
- else trim(m.ai_category)
|
|
121
|
|
- end as categoryCode,
|
|
122
|
|
- count(*) as count
|
|
123
|
|
- from biz_consult_message m
|
|
124
|
|
- <include refid="aiMessageJoin"/>
|
|
125
|
|
- where m.sender_role = 1
|
|
126
|
|
- and m.send_time >= #{yearStart}
|
|
127
|
|
- and m.send_time <= #{yearEnd}
|
|
128
|
|
- group by case
|
|
129
|
|
- when trim(m.ai_category) is null or trim(m.ai_category) = '' then 'UNCAT'
|
|
130
|
|
- else trim(m.ai_category)
|
|
131
|
|
- end
|
|
|
123
|
+ select category_code as categoryCode,
|
|
|
124
|
+ count(*) as count,
|
|
|
125
|
+ max(last_time) as lastEventTime
|
|
|
126
|
+ from (
|
|
|
127
|
+ select m.id,
|
|
|
128
|
+ case
|
|
|
129
|
+ when trim(coalesce((
|
|
|
130
|
+ select m2.ai_category
|
|
|
131
|
+ from biz_consult_message m2
|
|
|
132
|
+ where m2.session_id = m.session_id
|
|
|
133
|
+ and m2.sender_role = 1
|
|
|
134
|
+ and m2.send_time <= m.send_time
|
|
|
135
|
+ order by m2.send_time desc
|
|
|
136
|
+ limit 1
|
|
|
137
|
+ ), '')) is null
|
|
|
138
|
+ or trim(coalesce((
|
|
|
139
|
+ select m2.ai_category
|
|
|
140
|
+ from biz_consult_message m2
|
|
|
141
|
+ where m2.session_id = m.session_id
|
|
|
142
|
+ and m2.sender_role = 1
|
|
|
143
|
+ and m2.send_time <= m.send_time
|
|
|
144
|
+ order by m2.send_time desc
|
|
|
145
|
+ limit 1
|
|
|
146
|
+ ), '')) = '' then 'UNCAT'
|
|
|
147
|
+ else trim(coalesce((
|
|
|
148
|
+ select m2.ai_category
|
|
|
149
|
+ from biz_consult_message m2
|
|
|
150
|
+ where m2.session_id = m.session_id
|
|
|
151
|
+ and m2.sender_role = 1
|
|
|
152
|
+ and m2.send_time <= m.send_time
|
|
|
153
|
+ order by m2.send_time desc
|
|
|
154
|
+ limit 1
|
|
|
155
|
+ ), ''))
|
|
|
156
|
+ end as category_code,
|
|
|
157
|
+ m.create_time as last_time
|
|
|
158
|
+ from biz_consult_message m
|
|
|
159
|
+ <include refid="aiMessageJoin"/>
|
|
|
160
|
+ where <include refid="aiMessageFilter"/>
|
|
|
161
|
+ and m.create_time >= #{yearStart}
|
|
|
162
|
+ and m.create_time <= #{yearEnd}
|
|
|
163
|
+ ) t
|
|
|
164
|
+ group by category_code
|
|
132
|
165
|
</select>
|
|
133
|
166
|
|
|
134
|
167
|
<select id="selectHourlySessionCounts" resultType="com.ruoyi.web.modules.screen.domain.dto.LivestockResourceDateCountDto">
|
|
135
|
|
- select cast(floor(timestampdiff(minute, #{windowStart}, create_time) / 60) as char) as bucketKey,
|
|
|
168
|
+ select cast(hour(create_time) as char) as bucketKey,
|
|
136
|
169
|
count(*) as count
|
|
137
|
170
|
from biz_consult_session
|
|
138
|
171
|
where <include refid="aiSession"/>
|
|
139
|
|
- and create_time > #{windowStart}
|
|
140
|
|
- and create_time <= #{windowEnd}
|
|
141
|
|
- group by floor(timestampdiff(minute, #{windowStart}, create_time) / 60)
|
|
|
172
|
+ and create_time >= #{dayStart}
|
|
|
173
|
+ and create_time <= #{dayEnd}
|
|
|
174
|
+ group by hour(create_time)
|
|
142
|
175
|
</select>
|
|
143
|
176
|
|
|
144
|
177
|
<select id="selectHourlyAiReplyCounts" resultType="com.ruoyi.web.modules.screen.domain.dto.LivestockResourceDateCountDto">
|
|
145
|
|
- select cast(floor(timestampdiff(minute, #{windowStart}, m.send_time) / 60) as char) as bucketKey,
|
|
|
178
|
+ select cast(hour(m.create_time) as char) as bucketKey,
|
|
146
|
179
|
count(*) as count
|
|
147
|
180
|
from biz_consult_message m
|
|
148
|
181
|
<include refid="aiMessageJoin"/>
|
|
149
|
|
- where m.sender_role = 3
|
|
150
|
|
- and m.sender_user_id = 0
|
|
151
|
|
- and m.send_time > #{windowStart}
|
|
152
|
|
- and m.send_time <= #{windowEnd}
|
|
153
|
|
- group by floor(timestampdiff(minute, #{windowStart}, m.send_time) / 60)
|
|
|
182
|
+ where <include refid="aiMessageFilter"/>
|
|
|
183
|
+ and m.create_time >= #{dayStart}
|
|
|
184
|
+ and m.create_time <= #{dayEnd}
|
|
|
185
|
+ group by hour(m.create_time)
|
|
154
|
186
|
</select>
|
|
155
|
187
|
|
|
156
|
188
|
<select id="countYearSessions" resultType="long">
|
|
|
@@ -179,8 +211,8 @@
|
|
179
|
211
|
inner join biz_consult_session s2 on s2.id = m.session_id and s2.consult_type = 2
|
|
180
|
212
|
where m.sender_role = 3
|
|
181
|
213
|
and m.sender_user_id = 0
|
|
182
|
|
- and m.send_time >= #{yearStart}
|
|
183
|
|
- and m.send_time <= #{yearEnd}
|
|
|
214
|
+ and m.create_time >= #{yearStart}
|
|
|
215
|
+ and m.create_time <= #{yearEnd}
|
|
184
|
216
|
group by m.session_id
|
|
185
|
217
|
) r on r.session_id = s.id
|
|
186
|
218
|
where s.consult_type = 2
|
|
|
@@ -194,22 +226,20 @@
|
|
194
|
226
|
select count(*)
|
|
195
|
227
|
from biz_consult_message m
|
|
196
|
228
|
<include refid="aiMessageJoin"/>
|
|
197
|
|
- where m.sender_role = 3
|
|
198
|
|
- and m.sender_user_id = 0
|
|
|
229
|
+ where <include refid="aiMessageFilter"/>
|
|
199
|
230
|
and m.cost_time is not null
|
|
200
|
|
- and m.send_time >= #{yearStart}
|
|
201
|
|
- and m.send_time <= #{yearEnd}
|
|
|
231
|
+ and m.create_time >= #{yearStart}
|
|
|
232
|
+ and m.create_time <= #{yearEnd}
|
|
202
|
233
|
</select>
|
|
203
|
234
|
|
|
204
|
235
|
<select id="countAiRepliesFail" resultType="long">
|
|
205
|
236
|
select count(*)
|
|
206
|
237
|
from biz_consult_message m
|
|
207
|
238
|
<include refid="aiMessageJoin"/>
|
|
208
|
|
- where m.sender_role = 3
|
|
209
|
|
- and m.sender_user_id = 0
|
|
|
239
|
+ where <include refid="aiMessageFilter"/>
|
|
210
|
240
|
and m.cost_time is null
|
|
211
|
|
- and m.send_time >= #{yearStart}
|
|
212
|
|
- and m.send_time <= #{yearEnd}
|
|
|
241
|
+ and m.create_time >= #{yearStart}
|
|
|
242
|
+ and m.create_time <= #{yearEnd}
|
|
213
|
243
|
</select>
|
|
214
|
244
|
|
|
215
|
245
|
<select id="selectTextAskerContents" resultType="string">
|
|
|
@@ -217,6 +247,7 @@
|
|
217
|
247
|
from biz_consult_message m
|
|
218
|
248
|
<include refid="aiMessageJoin"/>
|
|
219
|
249
|
where m.sender_role = 1
|
|
|
250
|
+ and m.sender_user_id <> 0
|
|
220
|
251
|
and m.msg_type = 1
|
|
221
|
252
|
and m.content is not null
|
|
222
|
253
|
and trim(m.content) != ''
|