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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
<?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="cn.chnmuseum.party.mapper.TBoardStatisticMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="cn.chnmuseum.party.model.TBoardStatistic">
<id column="id" property="id" />
<result column="board_id" property="boardId" />
<result column="board_name" property="boardName" />
<result column="organ_id" property="organId" />
<result column="area_id" property="areaId" />
<result column="play_number" property="playNumber" />
<result column="play_date" property="playDate" />
</resultMap>
<!-- 播放排行结果 -->
<resultMap id="rankMap" type="cn.chnmuseum.party.model.TBoardPlayRank">
<id column="id" property="id"/>
<result column="board_id" property="boardId"/>
<result column="board_name" property="boardName"/>
<result column="play_number" property="playNumber"/>
<result column="play_date" property="playDate"/>
</resultMap>
<resultMap id="trendMap" type="cn.chnmuseum.party.model.TBoardPlayTrend">
<result column="play_number" property="playNumber"/>
<result column="play_date" property="playDate"/>
</resultMap>
<!-- 地区看板统计 -->
<resultMap id="districtMap" type="cn.chnmuseum.party.model.TDistrictBoardStatistic">
<result column="area_name" property="areaName"/>
<result column="play_number" property="playNumber"/>
<result column="board_cnt" property="boardCnt"/>
</resultMap>
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
id, board_id, board_name, organ_id, area_id, play_number, play_date
</sql>
<!-- 展板播放量统计 -->
<select id="getBoardRankPageList" parameterType="cn.chnmuseum.party.model.TBoardPlayRank" resultMap="rankMap">
SELECT s.board_id,s.board_name,sum(s.play_number) play_number
from t_board_statistic s
left join t_organ o on o.id = s.organ_id
LEFT JOIN exhibition_board b ON b.id=s.board_id
<where>
b.is_deleted=0
<if test="rank.playDate != null">
and s.play_date like concat( #{rank.playDate}, '%')
</if>
<if test="rank.organId != null">
and s.organ_id = #{rank.organId}
</if>
<if test="rank.organCode != null">
and o.code LIKE concat(#{rank.organCode}, '%')
</if>
</where>
GROUP BY s.board_id,s.board_name
ORDER BY sum(s.play_number) desc
</select>
<!-- 播放趋势统计 -->
<select id="getBoardTrendPageList" parameterType="cn.chnmuseum.party.model.TBoardPlayTrend" resultMap="trendMap">
<if test="trend.playDate != null and trend.playDate.length() == 4">
SELECT sum(s.play_number) play_number,left(s.play_date,6) play_date
from t_board_statistic s
left join t_organ o on o.id = s.organ_id
where left(s.play_date,4) = ${trend.playDate}
<if test="trend.organCode != null">
and o.code LIKE concat(#{trend.organCode}, '%')
</if>
GROUP BY left(s.play_date,6)
ORDER BY left(s.play_date,6)
</if>
<if test="trend.playDate != null and trend.playDate.length() == 6">
SELECT sum(s.play_number) play_number,s.play_date
from t_board_statistic s
left join t_organ o on o.id = s.organ_id
where left(s.play_date,6) = ${trend.playDate}
<if test="trend.organCode != null">
and o.code LIKE concat(#{trend.organCode}, '%')
</if>
GROUP BY s.play_date
ORDER BY s.play_date
</if>
<if test="trend.playDate != null and trend.playDate.length() == 8">
SELECT sum(s.play_number) play_number,s.play_date
from t_board_statistic s
left join t_organ o on o.id = s.organ_id
where s.play_date = ${trend.playDate}
<if test="trend.organCode != null">
and o.code LIKE concat(#{trend.organCode}, '%')
</if>
GROUP BY s.play_date
ORDER BY s.play_date
</if>
</select>
<select id="getBoardPageList" parameterType="cn.chnmuseum.party.model.TBoardPlayTrend" resultMap="trendMap">
SELECT sum(s.play_number) play_number,left(s.play_date,6) play_date
from t_board_statistic s
left join t_organ o on o.id = s.organ_id
where
left(s.play_date,6) between ${trend.beginDate} and ${trend.endDate}
<if test="trend.organCode != null">
and o.code LIKE concat(#{trend.organCode}, '%')
</if>
GROUP BY left(s.play_date,6)
ORDER BY left(s.play_date,6)
</select>
<!-- 地区展板播放统计 -->
<select id="getBoardDistrictPageList" resultMap="districtMap">
SELECT a.name area_name,sum(s.play_number) play_number,count(s.board_id) board_cnt from t_board_statistic s
left join t_area a on s.area_id = a.id
left join t_organ o on o.id = s.organ_id
<where>
<if test="district.playDate != null and district.playDate.length() == 4">
and left(s.play_date,4) = ${district.playDate}
</if>
<if test="district.playDate != null and district.playDate.length() == 6">
and left(s.play_date,6) = ${district.playDate}
</if>
<if test="district.playDate != null and district.playDate.length() == 8">
and s.play_date = ${district.playDate}
</if>
<if test="district.organCode != null">
and o.code LIKE concat(#{district.organCode}, '%')
</if>
</where>
GROUP BY s.area_id
order by sum(s.play_number) desc,count(board_id) desc
</select>
<!-- 获取展板播放总量 -->
<select id="getBoardPlayTotal" parameterType="cn.chnmuseum.party.model.TBoardSurvey" resultType="java.lang.Integer">
SELECT sum(s.play_number) play_number
from t_board_statistic s
left join t_organ o on o.id = s.organ_id
<where>
<if test="statisticDate != null and statisticDate.length() == 4">
and left(s.play_date,4) = ${statisticDate}
</if>
<if test="statisticDate != null and statisticDate.length() == 6">
and left(s.play_date,6) = ${statisticDate}
</if>
<if test="statisticDate != null and statisticDate.length() == 8">
and s.play_date = ${statisticDate}
</if>
<if test="areaId != null">
and s.area_id like concat(#{areaId}, '%')
</if>
<if test="organId != null">
and s.organ_id = #{organId}
</if>
<if test="organCode != null">
and o.code LIKE concat(#{organCode}, '%')
</if>
</where>
</select>
<!-- 获取展板总量 -->
<select id="getBoardTotal" resultType="java.lang.Integer">
SELECT count( a.board_id )
FROM
( SELECT s.board_id
FROM t_board_statistic s
left join t_organ o on o.id = s.organ_id
<where>
<if test="statisticDate != null and statisticDate.length() == 4">
left(s.play_date,4) = ${statisticDate}
</if>
<if test="statisticDate != null and statisticDate.length() == 6">
left(s.play_date,6) = ${statisticDate}
</if>
<if test="statisticDate != null and statisticDate.length() == 8">
s.play_date = ${statisticDate}
</if>
<if test="organCode != null">
and o.code LIKE concat(#{organCode}, '%')
</if>
</where>
GROUP BY s.board_id ) a
</select>
<!-- 获取播放展板的机构总量 -->
<select id="getOrganTotal" resultType="java.lang.Integer">
SELECT
count( a.organ_id )
FROM
( SELECT s.organ_id FROM t_board_statistic s
left join t_organ o on o.id = s.organ_id
<where>
<if test="statisticDate != null and statisticDate.length() == 4">
left(s.play_date,4) = ${statisticDate}
</if>
<if test="statisticDate != null and statisticDate.length() == 6">
left(s.play_date,6) = ${statisticDate}
</if>
<if test="statisticDate != null and statisticDate.length() == 8">
s.play_date = ${statisticDate}
</if>
<if test="organCode != null">
and o.code LIKE concat(#{organCode}, '%')
</if>
</where>
GROUP BY s.organ_id ) a
</select>
<!-- 获取互动总量 -->
<select id="getInteractionTotal" resultType="java.lang.Integer">
select count(i.id) from t_interaction i
left join t_organ o on o.id = i.organ_id
<where>
<if test="statisticDate != null and statisticDate.length() == 4">
DATE_FORMAT(i.create_time,'%Y') = ${statisticDate}
</if>
<if test="statisticDate != null and statisticDate.length() == 6">
DATE_FORMAT(i.create_time,'%Y%m') = ${statisticDate}
</if>
<if test="statisticDate != null and statisticDate.length() == 8">
DATE_FORMAT(i.create_time,'%Y%m%d') = ${statisticDate}
</if>
<if test="organCode != null">
and o.code LIKE concat(#{organCode}, '%')
</if>
</where>
</select>
<!-- 互动频次统计 -->
<select id="getInteractionFrequency" resultType="java.util.HashMap">
<if test="frequencyDate != null and frequencyDate.length() == 4">
SELECT o.name organName,count(i.organ_id) frequencyCnt
from t_interaction i
left join t_organ o on i.organ_id = o.id
<where>
DATE_FORMAT(i.create_time,'%Y') = ${frequencyDate}
<if test="orgCode != null">
and o.code LIKE concat(#{orgCode}, '%')
</if>
</where>
group by i.organ_id
order by count(i.organ_id) desc
</if>
<if test="frequencyDate != null and frequencyDate.length() == 6">
SELECT o.name organName,count(i.organ_id) frequencyCnt
from t_interaction i
left join t_organ o on i.organ_id = o.id
<where>
DATE_FORMAT(i.create_time,'%Y%m') = ${frequencyDate}
<if test="orgCode != null">
and o.code LIKE concat(#{orgCode}, '%')
</if>
</where>
group by i.organ_id
order by count(i.organ_id) desc
</if>
<if test="frequencyDate != null and frequencyDate.length() == 8">
SELECT o.name organName,count(i.organ_id) frequencyCnt
from t_interaction i
left join t_organ o on i.organ_id = o.id
<where>
DATE_FORMAT(i.create_time,'%Y%m%d') = ${frequencyDate}
<if test="orgCode != null">
and o.code LIKE concat(#{orgCode}, '%')
</if>
</where>
group by i.organ_id
order by count(i.organ_id) desc
</if>
</select>
</mapper>