/
test.cql
281 lines (274 loc) · 15.3 KB
/
test.cql
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
278
279
280
281
####################
#######################
[DATASOURCE]
impala jdbc:hive2://ip:21050/hnaudit;auth=noSasl org.apache.hive.jdbc.HiveDriver
[PARAM]
#################################################
## 常用输入参数
#################################################
@BeginDate TYPEAS string
@EndDate TYPEAS string
@BeginTime TYPEAS string
@EndTime TYPEAS string
@proctiomes TYPEAS int
@PkiIndustry TYPEAS int
@DeviceIndustry TYPEAS int
@WarnConfigId TYPEAS int
@WarnType TYPEAS int
@SmallType TYPEAS int
@WarnLevel TYPEAS int
@Flag TYPEAS int
@Value1 TYPEAS int
@Value2 TYPEAS int
@Value3 TYPEAS int
@Value4 TYPEAS int
@Value5 TYPEAS int
@Value6 TYPEAS int
@Value7 TYPEAS int
@Value8 TYPEAS int
@Value9 TYPEAS int
[ACTION]
###########################
# config
##############################
QUERY impala AS Card
SELECT executedate from Card WHERE id = 2
ENDQUERY
@BeginTime = Card.executedate
@EndDate = DATEADD(@BeginTime,-1)
QUERY impala AS ConfigValue1
SELECT configValue from APP_SystemConfigs WHERE ConfigName = 'PkiIndustry'
ENDQUERY
@PkiIndustry = ConfigValue1.configvalue
QUERY impala AS ConfigValue2
SELECT configValue from APP_SystemConfigs WHERE ConfigName = 'DeviceIndustry'
ENDQUERY
@DeviceIndustry =ConfigValue2.configvalue
@WarnType = 31
@WarnLevel = 1
QUERY impala AS mycursor
SELECT Id,Value1,Value2,Value3,Value4,Value5,Value6,Value7,Value8,Value9 from APP_WarnConfig WHERE WarnType = 31
ENDQUERY
#################
#
################
FOREACH mycursor @WarnConfigId,@Value1,@Value2,@Value3,@Value4,@Value5,@Value6,@Value7,@Value8,@Value9
IF @PkiIndustry == 1
IF @Value1 > 0
@BeginDate = @BeginTime
@SmallType = 1
QUERY impala
insert into App_WarnAudit(WarnConfigId,WarnType,SmallType,WarnLevel,
WarnContent,
KeyWord,WarnNumber,UniqueId,PkiUserId,TitleId,UpdateTime)
select @WarnConfigId,@WarnType,@SmallType,@WarnLevel,
concat('查询社会人员共<span class="Jcont">',cast(IDnum as string),'</span>个'),
'',IDnum,0,PkiUserId,0,UpdateTime
from App_PkiDay
where UpdateTime = @BeginDate and IDnum >= @Value1
ENDQUERY
ENDIF
IF @Value2 > 0
@SmallType = 2
QUERY impala
insert into App_WarnAudit(WarnConfigId,WarnType,SmallType,WarnLevel,
WarnContent,
KeyWord,WarnNumber,UniqueId,PkiUserId,TitleId,UpdateTime)
select @WarnConfigId,@WarnType,@SmallType,@WarnLevel,
concat('访问总次数共<span class="Jcont">',cast(LoginNum as string),'</span>次'),
'',LoginNum,0,PkiUserId,0,UpdateTime
from App_PkiDay
where UpdateTime = @BeginDate and LoginNum >= @Value2
ENDQUERY
ENDIF
IF @Value4 > 0
@BeginDate = DATEADD(@EndDate,-@Value3)
@SmallType = 3
QUERY impala
DELETE FROM App_WarnAudit WHERE WarnConfigId = @WarnConfigId and SmallType = @SmallType and UpdateTime = to_date(date_add(@EndDate,-1))
ENDQUERY
QUERY impala
insert into App_WarnAudit(WarnConfigId,WarnType,SmallType,WarnLevel,
WarnContent,
KeyWord,WarnNumber,UniqueId,PkiUserId,TitleId,UpdateTime)
select @WarnConfigId,@WarnType,@SmallType,@WarnLevel,
concat('持续<span class="Jcont">',cast(@Value3 as string),'</span>天查询社会人员超过',cast(@Value4 as string),'个'),
'',@Value3,0,PkiUserId,0,@EndDate
from (select PkiUserId,''
from
(select PkiUserId,UpdateTime
from App_PkiDay
where UpdateTime >= @BeginDate and UpdateTime <= @EndDate and IDnum >= @Value4) d
group by PkiUserId
having count(1) >= @Value3) u
where not exists(select * from App_WarnAudit w where w.WarnConfigId = @WarnConfigId and w.SmallType = @SmallType and w.UpdateTime = to_date(date_add(@EndDate,-1)) and w.PkiUserId = u.PkiUserId)
ENDQUERY
ENDIF
IF @Value5 > 0
@SmallType = 4
QUERY impala
DELETE FROM App_WarnAudit WHERE WarnConfigId = @WarnConfigId and SmallType = @SmallType and UpdateTime = to_date(date_add(@EndDate,-1))
ENDQUERY
QUERY impala
insert into App_WarnAudit(WarnConfigId,WarnType,SmallType,WarnLevel,
WarnContent,
KeyWord,WarnNumber,UniqueId,PkiUserId,TitleId,UpdateTime)
select @WarnConfigId,@WarnType,@SmallType,@WarnLevel,
concat('持续<span class="Jcont">',cast(@Value3 as string),'</span>天访问总数超过',cast(@Value5 as string),'次'),
'',@Value3,0,PkiUserId,0,@EndDate
from (select PkiUserId,''
from
(select PkiUserId,UpdateTime
from App_PkiDay
where UpdateTime >= @BeginDate and UpdateTime <= @EndDate and LoginNum >= @Value5) d
group by PkiUserId
having count(1) >= @Value3) u
where not exists(select * from App_WarnAudit w where w.WarnConfigId = @WarnConfigId and w.SmallType = @SmallType and w.UpdateTime = to_date(date_add(@EndDate,-1)) and w.PkiUserId = u.PkiUserId)
ENDQUERY
ENDIF
IF @Value8 > 0
@BeginDate = DATEADD(@EndDate,-@Value6)
@SmallType = 5
QUERY impala
insert into App_WarnAudit(WarnConfigId,WarnType,SmallType,WarnLevel,
WarnContent,
KeyWord,WarnNumber,UniqueId,PkiUserId,TitleId,UpdateTime)
select @WarnConfigId,@WarnType,@SmallType,@WarnLevel,
concat(cast(@Value6 as string),'天内累计<span class="Jcont">',cast(count(KeyWord) as string),'</span>天查询社会人员超过',cast(@Value8 as string),'个'),
group_concat(KeyWord,',') KeyWord ,
cast(count(KeyWord) as int),0,PkiUserId,0,@EndDate
from (select PkiUserId,cast(UpdateTime as string) as KeyWord
from App_PkiDay
where UpdateTime >= @BeginDate and UpdateTime <= @EndDate and IDnum >= @Value8) a
group by PkiUserId
having count(a.KeyWord) >= @Value7
ENDQUERY
ENDIF
IF @Value9 > 0
@SmallType = 6
QUERY impala
insert into App_WarnAudit(WarnConfigId,WarnType,SmallType,WarnLevel,
WarnContent,
KeyWord,WarnNumber,UniqueId,PkiUserId,TitleId,UpdateTime)
select @WarnConfigId,@WarnType,@SmallType,@WarnLevel,
concat(cast(@Value6 as string),'天内累计<span class="Jcont">',cast(count(KeyWord) as string),'</span>天访问总数超过',cast(@Value9 as string),'次'),
group_concat(KeyWord,',') KeyWord ,
cast(count(KeyWord) as int),0,PkiUserId,0,@EndDate
from (select PkiUserId,cast(UpdateTime as string) as KeyWord
from App_PkiDay
where UpdateTime >= @BeginDate and UpdateTime <= @EndDate and LoginNum >= @Value9) a
group by PkiUserId
having count(a.KeyWord) >= @Value7
ENDQUERY
ENDIF
ENDIF
IF @DeviceIndustry == 1
IF @Value1 > 0
@SmallType = 7
@BeginDate = @EndDate
QUERY impala
insert into App_WarnAudit(WarnConfigId,WarnType,SmallType,WarnLevel,
WarnContent,
KeyWord,WarnNumber,UniqueId,PkiUserId,TitleId,UpdateTime)
select @WarnConfigId,@WarnType,@SmallType,@WarnLevel,
concat('查询社会人员共<span class="Jcont">',cast(IDnum as string),'</span>个'),
'',IDnum,UniqueId,'',0,UpdateTime
from App_DeviceDay
where UpdateTime = @BeginDate and IDnum >= @Value1
ENDQUERY
ENDIF
IF @Value2 > 0
@SmallType = 8
QUERY impala
insert into App_WarnAudit(WarnConfigId,WarnType,SmallType,WarnLevel,
WarnContent,
KeyWord,WarnNumber,UniqueId,PkiUserId,TitleId,UpdateTime)
select @WarnConfigId,@WarnType,@SmallType,@WarnLevel,
concat('访问总次数共<span class="Jcont">',cast(LoginNum as string),'</span>次'),
'',LoginNum,UniqueId,'',0,UpdateTime
from App_DeviceDay
where UpdateTime = @BeginDate and LoginNum >= @Value2
ENDQUERY
ENDIF
IF @Value4 > 0
@SmallType = 9
@BeginDate = DATEADD(@EndDate,-@Value3)
QUERY impala
DELETE FROM App_WarnAudit WHERE WarnConfigId = @WarnConfigId and SmallType = @SmallType and UpdateTime = @BeginDate
ENDQUERY
QUERY impala
insert into App_WarnAudit(WarnConfigId,WarnType,SmallType,WarnLevel,
WarnContent,
KeyWord,WarnNumber,UniqueId,PkiUserId,TitleId,UpdateTime)
select @WarnConfigId,@WarnType,@SmallType,@WarnLevel,
concat('持续<span class="Jcont">',cast(@Value3 as string),'</span>天查询社会人员超过',cast(@Value4 as string),'个'),
'',@Value3,UniqueId,'',0,@EndDate
from (select UniqueId,''
from
(select UniqueId,UpdateTime
from App_DeviceDay
where UpdateTime >= @BeginDate and UpdateTime <= @EndDate and IDnum >= @Value4) d
group by UniqueId
having count(1) >= @Value3) u
where not exists(select * from App_WarnAudit w where w.WarnConfigId = @WarnConfigId and w.SmallType = @SmallType and w.UpdateTime = to_date(date_add(@EndDate,-1)) and w.UniqueId = u.UniqueId)
ENDQUERY
ENDIF
IF @Value5 > 0
@SmallType = 10
QUERY impala
DELETE FROM App_WarnAudit where WarnConfigId = @WarnConfigId and SmallType = @SmallType and UpdateTime = to_date(date_add(@EndDate,-1))
ENDQUERY
QUERY impala
insert into App_WarnAudit(WarnConfigId,WarnType,SmallType,WarnLevel,
WarnContent,
KeyWord,WarnNumber,UniqueId,PkiUserId,TitleId,UpdateTime)
select @WarnConfigId,@WarnType,@SmallType,@WarnLevel,
concat('持续<span class="Jcont">',cast(@Value3 as string),'</span>天访问总数超过',cast(@Value5 as string),'次'),
'',@Value3,UniqueId,'',0,@EndDate
from (select UniqueId,''
from
(select UniqueId,UpdateTime
from App_DeviceDay
where UpdateTime >= @BeginDate and UpdateTime <= @EndDate and LoginNum >= @Value5) d
group by UniqueId
having count(1) >= @Value3) u
where not exists(select * from App_WarnAudit w where w.WarnConfigId = @WarnConfigId and w.SmallType = @SmallType and w.UpdateTime =to_date(date_add(@EndDate,-1)) and w.UniqueId = u.UniqueId)
ENDQUERY
ENDIF
IF @Value8 > 0
@BeginDate = DATEADD(@EndDate,-@Value6)
@SmallType = 11
QUERY impala
insert into App_WarnAudit(WarnConfigId,WarnType,SmallType,WarnLevel,
WarnContent,
KeyWord,WarnNumber,UniqueId,PkiUserId,TitleId,UpdateTime)
select @WarnConfigId,@WarnType,@SmallType,@WarnLevel,
concat(cast(3 as string),'天内累计<span class="Jcont">',cast(count(KeyWord) as string),'</span>天查询社会人员超过',cast(3 as string),'个'),
group_concat(KeyWord,',') KeyWord ,
cast(count(KeyWord) as int),UniqueId,'',0,@EndDate
from (select UniqueId,cast(UpdateTime as string) as KeyWord
from App_DeviceDay
where UpdateTime >= @BeginDate and UpdateTime <= @EndDate and IDnum >= @Value8) a
group by UniqueId
having count(a.KeyWord) >= @Value7
ENDQUERY
ENDIF
IF @Value9 > 0
@SmallType = 12
QUERY impala
insert into App_WarnAudit(WarnConfigId,WarnType,SmallType,WarnLevel,
WarnContent,
KeyWord,WarnNumber,UniqueId,PkiUserId,TitleId,UpdateTime)
select @WarnConfigId,@WarnType,@SmallType,@WarnLevel,
concat(cast(@Value6 as string),'天内累计<span class="Jcont">',cast(count(KeyWord) as string),'</span>天访问总数超过',cast(@Value9 as string),'次'),
group_concat(KeyWord,',') KeyWord ,
cast(count(KeyWord) as int),UniqueId,'',0,@EndDate
from(select UniqueId,cast(UpdateTime as string) as KeyWord
from App_DeviceDay
where UpdateTime >= @BeginDate and UpdateTime <= @EndDate and LoginNum >= @Value9) a
group by UniqueId
having count(a.KeyWord) >= @Value7
ENDQUERY
ENDIF
ENDIF
ENDFOREACH