SearchSubDept.jsp
38.2 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
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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
<%@ page import="weaver.general.Util"%>
<%@ page import="java.util.Map.Entry"%>
<%@ page import="java.util.*"%>
<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="weaver.hrm.HrmUserVarify" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@ include file="GPUtil.jsp" %>
<%@ include file="/workrelate/comm/SubcpyDeptUtil.jsp" %>
<jsp:useBean id="rs" class="weaver.conn.RecordSet" scope="page" />
<!-- 展示列表 -->
<%
if(HrmUserVarify.getUser (request , response)==null){
return;
}
String year = Util.null2String(request.getParameter("year"));
String month = Util.null2String(request.getParameter("month"));
String type = Util.null2String(request.getParameter("type"));
int level = Util.getIntValue(request.getParameter("level"));
String subCpyId = Util.null2String(request.getParameter("subCpyId"));
String curCode = Util.null2String(request.getParameter("curCode"));
String curtype = Util.null2String(request.getParameter("curtype"));
int paddingSize = level * 23 + 12;
String subcompanyids = Util.null2String(request.getParameter("subcompanyids"));
//是否是sql server数据库
boolean isSqlServer = rs.getDBType().equals("sqlserver");
String sql = null;
LinkedHashMap<String,LinkedHashMap<String, String>> showMap = null;
if("subcpy".equals(curtype)){
sql = getSubcpySearchSql(year,month,isSqlServer);
rs.execute(sql);
//得到所有分部的数据
LinkedHashMap<String,LinkedHashMap<String, String>> subcpyDataMap = getWorkerResult(rs);
//查询分部树及对应的code,通过函数获得
rs.execute(getSubCpyTree(isSqlServer));
LinkedHashMap<String,LinkedHashMap<String, String>> subcpyTreeMap = getSubcpyTreeMapResult(rs);
//组合展示集合
showMap = getSubcpyShowMap(subcpyDataMap,subcpyTreeMap,subCpyId);
setIsContainSub(showMap);
}
//得到所有部门的数据
sql = getDeptSearchSql(year,month,isSqlServer);
rs.execute(sql);
LinkedHashMap<String,LinkedHashMap<String, String>> deptDataMap = getWorkerResult(rs);
//查询部门树及对应的code
rs.execute(getDeptTree(isSqlServer));
LinkedHashMap<String,LinkedHashMap<String, String>> deptTreeMap = getDeptTreeMapResult(rs);
//组合展示集合
LinkedHashMap<String,LinkedHashMap<String, String>> deptShowMap = getDeptShowMap(deptDataMap,deptTreeMap,subCpyId,curtype);
List<LinkedHashMap<String, String>> showList = new ArrayList<LinkedHashMap<String, String>>();
if(showMap != null){
showList.addAll(showMap.values());
}
showList.addAll(deptShowMap.values());
LinkedHashMap<String,String> curMap = null;
for (int i=0;i<showList.size();i++) {
curMap = showList.get(i);
%>
<tr style="text-align:center;" curCode='<%=curCode%>_<%=curMap.get("id")%>' subCpyId='<%=curMap.get("id")%>' opened="no" curtype="<%=curMap.get("curtype")%>">
<td style="text-align:left;padding-left:<%=paddingSize%>px;" level="<%=level+1%>">
<input type="checkbox"/>
<img onmouseover="imgOver(this)" onmouseout="imgOut(this)"
<%if("yes".equals(curMap.get("hasSub"))){%>
src="/workrelate/images/wropen.png"
onclick="loadSubDept()"
<%}else{%>
src="/workrelate/images/wrnormal.png"
<%}%>
style="margin-top:5px;margin-right:5px;cursor:pointer;">
</img>
<%if("subcpy".equals(curMap.get("curtype"))){%>
<img alt="" src="../images/sub.png"/>
<%}else{%>
<img alt="" src="../images/depat.png"/>
<%}%>
<label><%=curMap.get("showname") %></label>
</td>
<td><%=curMap.get("exist") %></td>
<td><%=curMap.get("without") %></td>
<td><%=curMap.get("scoring") %></td>
<td><%=curMap.get("assessing") %></td>
<td><%=curMap.get("back") %></td>
<td><%=curMap.get("finish") %></td>
<td><%=curMap.get("oscoring") %></td>
<td><%=curMap.get("oassessing") %></td>
<td><%=curMap.get("oback") %></td>
<%}%>
<%!
/**
* 把所有要展示的分部数据放到集合中
* @return
*/
private LinkedHashMap<String,LinkedHashMap<String, String>> getSubcpyShowMap(LinkedHashMap<String,LinkedHashMap<String, String>> dataMap,
LinkedHashMap<String,LinkedHashMap<String, String>> treeMap,
String subCpyId){
LinkedHashMap<String,LinkedHashMap<String, String>> resultMap = new LinkedHashMap<String,LinkedHashMap<String, String>>();
LinkedHashMap<String,String> curMap = null;
LinkedHashMap<String, String> tempCurDataMap = null;
LinkedHashMap<String, String> tempSupDataMap = null;
for (Entry<String,LinkedHashMap<String,String>> obj : treeMap.entrySet()) {
curMap = obj.getValue();
if(dataMap.get(obj.getKey()) == null){
continue;
}
if("1".equals(curMap.get("level"))){
continue;
}else{
tempCurDataMap = dataMap.get(curMap.get("id"));
tempSupDataMap = dataMap.get(curMap.get("supsubcomid"));
if(tempCurDataMap == null || tempSupDataMap == null){
continue;
}
tempSupDataMap.put("exist",(Integer.parseInt(tempCurDataMap.get("exist"))+Integer.parseInt(tempSupDataMap.get("exist")))+"");
tempSupDataMap.put("without",(Integer.parseInt(tempCurDataMap.get("without"))+Integer.parseInt(tempSupDataMap.get("without")))+"");
tempSupDataMap.put("scoring",(Integer.parseInt(tempCurDataMap.get("scoring"))+Integer.parseInt(tempSupDataMap.get("scoring")))+"");
tempSupDataMap.put("assessing",(Integer.parseInt(tempCurDataMap.get("assessing"))+Integer.parseInt(tempSupDataMap.get("assessing")))+"");
tempSupDataMap.put("back",(Integer.parseInt(tempCurDataMap.get("back"))+Integer.parseInt(tempSupDataMap.get("back")))+"");
tempSupDataMap.put("finish",(Integer.parseInt(tempCurDataMap.get("finish"))+Integer.parseInt(tempSupDataMap.get("finish")))+"");
tempSupDataMap.put("oscoring",(Integer.parseInt(tempCurDataMap.get("oscoring"))+Integer.parseInt(tempSupDataMap.get("oscoring")))+"");
tempSupDataMap.put("oassessing",(Integer.parseInt(tempCurDataMap.get("oassessing"))+Integer.parseInt(tempSupDataMap.get("oassessing")))+"");
tempSupDataMap.put("oback",(Integer.parseInt(tempCurDataMap.get("oback"))+Integer.parseInt(tempSupDataMap.get("oback")))+"");
tempSupDataMap.put("hasSub","yes");
//如果subCpyId是空或包含则添加
if(subCpyId.equals(curMap.get("supsubcomid"))){
tempCurDataMap.put("curtype","subcpy");
resultMap.put(curMap.get("id"),tempCurDataMap);
}
}
}
return resultMap;
}
/**
* 把所有要展示的部门数据放到集合中
* @return
*/
private LinkedHashMap<String,LinkedHashMap<String, String>> getDeptShowMap(LinkedHashMap<String,LinkedHashMap<String, String>> dataMap,
LinkedHashMap<String,LinkedHashMap<String, String>> treeMap,
String subCpyId,
String curtype){
LinkedHashMap<String,LinkedHashMap<String, String>> resultMap = new LinkedHashMap<String,LinkedHashMap<String, String>>();
LinkedHashMap<String,String> curMap = null;
LinkedHashMap<String, String> tempCurDataMap = null;
LinkedHashMap<String, String> tempSupDataMap = null;
for (Entry<String,LinkedHashMap<String,String>> obj : treeMap.entrySet()) {
curMap = obj.getValue();
if(dataMap.get(obj.getKey()) == null){
continue;
}
tempCurDataMap = dataMap.get(curMap.get("id"));
tempSupDataMap = dataMap.get(curMap.get("superid"));
if(tempCurDataMap == null && tempSupDataMap == null){
continue;
}else if(tempCurDataMap != null && tempSupDataMap == null){
if("subcpy".equals(curtype) && subCpyId.equals(curMap.get("subcompanyid1")) && "1".equals(curMap.get("level"))){
tempCurDataMap.put("curtype","dept");
resultMap.put(curMap.get("id"),tempCurDataMap);
}
continue;
}
tempSupDataMap.put("exist",(Integer.parseInt(tempCurDataMap.get("exist"))+Integer.parseInt(tempSupDataMap.get("exist")))+"");
tempSupDataMap.put("without",(Integer.parseInt(tempCurDataMap.get("without"))+Integer.parseInt(tempSupDataMap.get("without")))+"");
tempSupDataMap.put("scoring",(Integer.parseInt(tempCurDataMap.get("scoring"))+Integer.parseInt(tempSupDataMap.get("scoring")))+"");
tempSupDataMap.put("assessing",(Integer.parseInt(tempCurDataMap.get("assessing"))+Integer.parseInt(tempSupDataMap.get("assessing")))+"");
tempSupDataMap.put("back",(Integer.parseInt(tempCurDataMap.get("back"))+Integer.parseInt(tempSupDataMap.get("back")))+"");
tempSupDataMap.put("finish",(Integer.parseInt(tempCurDataMap.get("finish"))+Integer.parseInt(tempSupDataMap.get("finish")))+"");
tempSupDataMap.put("oscoring",(Integer.parseInt(tempCurDataMap.get("oscoring"))+Integer.parseInt(tempSupDataMap.get("oscoring")))+"");
tempSupDataMap.put("oassessing",(Integer.parseInt(tempCurDataMap.get("oassessing"))+Integer.parseInt(tempSupDataMap.get("oassessing")))+"");
tempSupDataMap.put("oback",(Integer.parseInt(tempCurDataMap.get("oback"))+Integer.parseInt(tempSupDataMap.get("oback")))+"");
tempSupDataMap.put("hasSub","yes");
//如果subCpyId是空或包含则添加
if("subcpy".equals(curtype)){
if(subCpyId.equals(curMap.get("subcompanyid1")) && "1".equals(curMap.get("level"))){
tempCurDataMap.put("curtype","dept");
resultMap.put(curMap.get("id"),tempCurDataMap);
}
}else{
if(subCpyId.equals(curMap.get("superid"))){
tempCurDataMap.put("curtype","dept");
resultMap.put(curMap.get("id"),tempCurDataMap);
}
}
}
return resultMap;
}
/**
* 把所有分部组合成的树放到集合中
* @return
*/
private LinkedHashMap<String,LinkedHashMap<String, String>> getSubcpyTreeMapResult(weaver.conn.RecordSet rs) {
LinkedHashMap<String,LinkedHashMap<String, String>> map = new LinkedHashMap<String,LinkedHashMap<String, String>>();
String id = null;
String subcompanyname = null;
String supsubcomid = null;
String code = null;
String level = null;
String s3 = null;
LinkedHashMap<String, String> curValues = null;
while(rs.next()){
id = null2String(rs.getString("id"));
subcompanyname = null2String(rs.getString("subcompanyname"));
supsubcomid = null2String(rs.getString("supsubcomid"));
code = null2String(rs.getString("code"));
level = null2String(rs.getString("level"));
curValues = new LinkedHashMap<String, String>();
curValues.put("id",id);
curValues.put("subcompanyname",subcompanyname);
curValues.put("supsubcomid",supsubcomid);
curValues.put("code",code);
curValues.put("level",level);
map.put(id,curValues);
}
return map;
}
/**
* 构建部门查询sql
*
* @param year 年
* @param month 月
* @param week 周
* @param type 查询类型(1:月;2:周)
* @return
*/
public String getDeptSearchSql(String year,String month,boolean isSqlServer){
year = "".equals(year)?""+Calendar.getInstance().get(Calendar.YEAR):year;
String type = "1";
String type2 = month;
String sql = null;
RecordSet rs= new RecordSet();
String dbType = rs.getDBType();
//如果是sql server数据库
if(dbType.equals("sqlserver")){
sql = "SELECT dept.id , "+
" dept.departmentname showname, "+
" ISNULL(A.exist, 0) exist , "+
" ISNULL(B.without, 0) without , "+
" ISNULL(C.scoring, 0) scoring , "+
" ISNULL(D.assessing, 0) assessing , "+
" ISNULL(BK.back, 0) back , "+
" ISNULL(E.finish, 0) finish, "+
" ISNULL(F.oscoring, 0) oscoring , "+
" ISNULL(G.oassessing, 0) oassessing, "+
" ISNULL(OBK.oback, 0) oback "+
"FROM HrmDepartment dept "+
" LEFT JOIN ( SELECT departmentid , "+
" COUNT(1) exist "+
" FROM HrmResource hrm "+
" WHERE hrm.status<=3 AND EXISTS ( SELECT 1 "+
" FROM GP_AccessProgram ap "+
" WHERE hrm.id = ap.userid "+
" AND ap.status = 3 ) "+
" GROUP BY departmentid "+
" ) A ON A.departmentid = dept.id "+
" LEFT JOIN ( SELECT departmentid , "+
" COUNT(1) without "+
" FROM HrmResource hrm "+
" WHERE hrm.status<=3 AND hrm.id NOT in ( SELECT ap.userid "+
" FROM GP_AccessProgram ap "+
" WHERE ap.status = 3 ) "+
" GROUP BY departmentid "+
" ) B ON B.departmentid = dept.id "+
" LEFT JOIN ( SELECT departmentid , "+
" COUNT(1) scoring "+
" FROM HrmResource hrm , "+
" GP_AccessScore score "+
" WHERE hrm.id = score.userid "+
" AND hrm.status<=3 "+
" AND score.status = 0 "+
" AND year = '"+year+"' "+
" AND type1 = '"+type+"' "+
" AND type2 = '"+type2+"' "+
" AND GETDATE()<Cast(score.enddate AS DATETIME) "+
" GROUP BY departmentid "+
" ) C ON C.departmentid = dept.id "+
" LEFT JOIN ( SELECT departmentid , "+
" COUNT(1) assessing "+
" FROM HrmResource hrm , "+
" GP_AccessScore score "+
" WHERE hrm.id = score.userid "+
" AND hrm.status<=3 "+
" AND score.status = 1 "+
" AND year = '"+year+"' "+
" AND type1 = '"+type+"' "+
" AND type2 = '"+type2+"' "+
" AND GETDATE()<SCORE.enddate "+
" GROUP BY departmentid "+
" ) D ON D.departmentid = dept.id "+
" LEFT JOIN ( SELECT departmentid , "+
" COUNT(1) back "+
" FROM HrmResource hrm , "+
" GP_AccessScore score "+
" WHERE hrm.id = score.userid "+
" AND hrm.status<=3 "+
" AND score.status = 2 "+
" AND year = '"+year+"' "+
" AND type1 = '"+type+"' "+
" AND type2 = '"+type2+"' "+
" AND GETDATE()<SCORE.enddate "+
" GROUP BY departmentid "+
" ) BK ON BK.departmentid = dept.id "+
" LEFT JOIN ( SELECT departmentid , "+
" COUNT(1) finish "+
" FROM HrmResource hrm , "+
" GP_AccessScore score "+
" WHERE hrm.id = score.userid "+
" AND hrm.status<=3 "+
" AND score.status = 3 "+
" AND year = '"+year+"' "+
" AND type1 = '"+type+"' "+
" AND type2 = '"+type2+"' "+
" GROUP BY departmentid "+
" ) E ON E.departmentid = dept.id "+
" LEFT JOIN ( SELECT departmentid , "+
" COUNT(1) oscoring "+
" FROM HrmResource hrm , "+
" GP_AccessScore score "+
" WHERE hrm.id = score.userid "+
" AND hrm.status<=3 "+
" AND score.status = 0 "+
" AND year = '"+year+"' "+
" AND type1 = '"+type+"' "+
" AND type2 = '"+type2+"' "+
" AND GETDATE()>CAST(score.enddate AS DATETIME) "+
" GROUP BY departmentid "+
" ) F ON F.departmentid = dept.id "+
" LEFT JOIN ( SELECT departmentid , "+
" COUNT(1) oassessing "+
" FROM HrmResource hrm , "+
" GP_AccessScore score "+
" WHERE hrm.id = score.userid "+
" AND hrm.status<=3 "+
" AND score.status = 1 "+
" AND year = '"+year+"' "+
" AND type1 = '"+type+"' "+
" AND type2 = '"+type2+"' "+
" AND GETDATE()>CAST(score.enddate AS DATETIME) "+
" GROUP BY departmentid "+
" ) G ON G.departmentid = dept.id "+
" LEFT JOIN ( SELECT departmentid , "+
" COUNT(1) oback "+
" FROM HrmResource hrm , "+
" GP_AccessScore score "+
" WHERE hrm.id = score.userid "+
" AND hrm.status<=3 "+
" AND score.status = 2 "+
" AND year = '"+year+"' "+
" AND type1 = '"+type+"' "+
" AND type2 = '"+type2+"' "+
" AND GETDATE()>CAST(score.enddate AS DATETIME) "+
" GROUP BY departmentid "+
" ) OBK ON OBK.departmentid = dept.id ";
}else if(dbType.equals("mysql")){
sql = "SELECT dept.id , "+
" dept.departmentname showname, "+
" IFNULL(A.exist, 0) exist , "+
" IFNULL(B.without, 0) without , "+
" IFNULL(C.scoring, 0) scoring , "+
" IFNULL(D.assessing, 0) assessing , "+
" IFNULL(BK.back, 0) back , "+
" IFNULL(E.finish, 0) finish, "+
" IFNULL(F.oscoring, 0) oscoring , "+
" IFNULL(G.oassessing, 0) oassessing, "+
" IFNULL(OBK.oback, 0) oback "+
"FROM HrmDepartment dept "+
" LEFT JOIN ( SELECT departmentid , "+
" COUNT(1) exist "+
" FROM HrmResource hrm "+
" WHERE hrm.status<=3 AND EXISTS ( SELECT 1 "+
" FROM GP_AccessProgram ap "+
" WHERE hrm.id = ap.userid "+
" AND ap.status = 3 ) "+
" GROUP BY departmentid "+
" ) A ON A.departmentid = dept.id "+
" LEFT JOIN ( SELECT departmentid , "+
" COUNT(1) without "+
" FROM HrmResource hrm "+
" WHERE hrm.status<=3 AND hrm.id NOT in ( SELECT ap.userid "+
" FROM GP_AccessProgram ap "+
" WHERE ap.status = 3 ) "+
" GROUP BY departmentid "+
" ) B ON B.departmentid = dept.id "+
" LEFT JOIN ( SELECT departmentid , "+
" COUNT(1) scoring "+
" FROM HrmResource hrm , "+
" GP_AccessScore score "+
" WHERE hrm.id = score.userid "+
" AND hrm.status<=3 "+
" AND score.status = 0 "+
" AND year = '"+year+"' "+
" AND type1 = '"+type+"' "+
" AND type2 = '"+type2+"' "+
" AND CURRENT_TIMESTAMP(3)<Cast(score.enddate AS DATETIME) "+
" GROUP BY departmentid "+
" ) C ON C.departmentid = dept.id "+
" LEFT JOIN ( SELECT departmentid , "+
" COUNT(1) assessing "+
" FROM HrmResource hrm , "+
" GP_AccessScore score "+
" WHERE hrm.id = score.userid "+
" AND hrm.status<=3 "+
" AND score.status = 1 "+
" AND year = '"+year+"' "+
" AND type1 = '"+type+"' "+
" AND type2 = '"+type2+"' "+
" AND CURRENT_TIMESTAMP(3)<SCORE.enddate "+
" GROUP BY departmentid "+
" ) D ON D.departmentid = dept.id "+
" LEFT JOIN ( SELECT departmentid , "+
" COUNT(1) back "+
" FROM HrmResource hrm , "+
" GP_AccessScore score "+
" WHERE hrm.id = score.userid "+
" AND hrm.status<=3 "+
" AND score.status = 2 "+
" AND year = '"+year+"' "+
" AND type1 = '"+type+"' "+
" AND type2 = '"+type2+"' "+
" AND CURRENT_TIMESTAMP(3)<SCORE.enddate "+
" GROUP BY departmentid "+
" ) BK ON BK.departmentid = dept.id "+
" LEFT JOIN ( SELECT departmentid , "+
" COUNT(1) finish "+
" FROM HrmResource hrm , "+
" GP_AccessScore score "+
" WHERE hrm.id = score.userid "+
" AND hrm.status<=3 "+
" AND score.status = 3 "+
" AND year = '"+year+"' "+
" AND type1 = '"+type+"' "+
" AND type2 = '"+type2+"' "+
" GROUP BY departmentid "+
" ) E ON E.departmentid = dept.id "+
" LEFT JOIN ( SELECT departmentid , "+
" COUNT(1) oscoring "+
" FROM HrmResource hrm , "+
" GP_AccessScore score "+
" WHERE hrm.id = score.userid "+
" AND hrm.status<=3 "+
" AND score.status = 0 "+
" AND year = '"+year+"' "+
" AND type1 = '"+type+"' "+
" AND type2 = '"+type2+"' "+
" AND CURRENT_TIMESTAMP(3)>CAST(score.enddate AS DATETIME) "+
" GROUP BY departmentid "+
" ) F ON F.departmentid = dept.id "+
" LEFT JOIN ( SELECT departmentid , "+
" COUNT(1) oassessing "+
" FROM HrmResource hrm , "+
" GP_AccessScore score "+
" WHERE hrm.id = score.userid "+
" AND hrm.status<=3 "+
" AND score.status = 1 "+
" AND year = '"+year+"' "+
" AND type1 = '"+type+"' "+
" AND type2 = '"+type2+"' "+
" AND CURRENT_TIMESTAMP(3)>CAST(score.enddate AS DATETIME) "+
" GROUP BY departmentid "+
" ) G ON G.departmentid = dept.id "+
" LEFT JOIN ( SELECT departmentid , "+
" COUNT(1) oback "+
" FROM HrmResource hrm , "+
" GP_AccessScore score "+
" WHERE hrm.id = score.userid "+
" AND hrm.status<=3 "+
" AND score.status = 2 "+
" AND year = '"+year+"' "+
" AND type1 = '"+type+"' "+
" AND type2 = '"+type2+"' "+
" AND CURRENT_TIMESTAMP(3)>CAST(score.enddate AS DATETIME) "+
" GROUP BY departmentid "+
" ) OBK ON OBK.departmentid = dept.id ";
}
else{
sql = "SELECT dept.id , "+
" dept.departmentname showname, "+
" NVL(A.exist, 0) exist , "+
" NVL(B.without, 0) without , "+
" NVL(C.scoring, 0) scoring , "+
" NVL(D.assessing, 0) assessing , "+
" NVL(BK.back, 0) back , "+
" NVL(E.finish, 0) finish, "+
" NVL(F.oscoring, 0) oscoring , "+
" NVL(G.oassessing, 0) oassessing, "+
" NVL(OBK.oback, 0) oback "+
"FROM HrmDepartment dept "+
" LEFT JOIN ( SELECT departmentid , "+
" COUNT(1) exist "+
" FROM HrmResource hrm "+
" WHERE hrm.status<=3 AND EXISTS ( SELECT 1 "+
" FROM GP_AccessProgram ap "+
" WHERE hrm.id = ap.userid "+
" AND ap.status = 3 ) "+
" GROUP BY departmentid "+
" ) A ON A.departmentid = dept.id "+
" LEFT JOIN ( SELECT departmentid , "+
" COUNT(1) without "+
" FROM HrmResource hrm "+
" WHERE hrm.status<=3 AND hrm.id NOT in ( SELECT ap.userid "+
" FROM GP_AccessProgram ap "+
" WHERE ap.status = 3 ) "+
" GROUP BY departmentid "+
" ) B ON B.departmentid = dept.id "+
" LEFT JOIN ( SELECT departmentid , "+
" COUNT(1) scoring "+
" FROM HrmResource hrm , "+
" GP_AccessScore score "+
" WHERE hrm.id = score.userid "+
" AND hrm.status<=3 "+
" AND score.status = 0 "+
" AND year = '"+year+"' "+
" AND type1 = '"+type+"' "+
" AND type2 = '"+type2+"' "+
" AND SYSDATE<=TO_DATE(score.enddate,'yyyy-mm-dd') "+
" GROUP BY departmentid "+
" ) C ON C.departmentid = dept.id "+
" LEFT JOIN ( SELECT departmentid , "+
" COUNT(1) assessing "+
" FROM HrmResource hrm , "+
" GP_AccessScore score "+
" WHERE hrm.id = score.userid "+
" AND hrm.status<=3 "+
" AND score.status = 1 "+
" AND year = '"+year+"' "+
" AND type1 = '"+type+"' "+
" AND type2 = '"+type2+"' "+
" AND SYSDATE<=TO_DATE(score.enddate,'yyyy-mm-dd') "+
" GROUP BY departmentid "+
" ) D ON D.departmentid = dept.id "+
" LEFT JOIN ( SELECT departmentid , "+
" COUNT(1) back "+
" FROM HrmResource hrm , "+
" GP_AccessScore score "+
" WHERE hrm.id = score.userid "+
" AND hrm.status<=3 "+
" AND score.status = 2 "+
" AND year = '"+year+"' "+
" AND type1 = '"+type+"' "+
" AND type2 = '"+type2+"' "+
" AND SYSDATE<=TO_DATE(score.enddate,'yyyy-mm-dd') "+
" GROUP BY departmentid "+
" ) BK ON BK.departmentid = dept.id "+
" LEFT JOIN ( SELECT departmentid , "+
" COUNT(1) finish "+
" FROM HrmResource hrm , "+
" GP_AccessScore score "+
" WHERE hrm.id = score.userid "+
" AND hrm.status<=3 "+
" AND score.status = 3 "+
" AND year = '"+year+"' "+
" AND type1 = '"+type+"' "+
" AND type2 = '"+type2+"' "+
" GROUP BY departmentid "+
" ) E ON E.departmentid = dept.id "+
" LEFT JOIN ( SELECT departmentid , "+
" COUNT(1) oscoring "+
" FROM HrmResource hrm , "+
" GP_AccessScore score "+
" WHERE hrm.id = score.userid "+
" AND hrm.status<=3 "+
" AND score.status = 0 "+
" AND year = '"+year+"' "+
" AND type1 = '"+type+"' "+
" AND type2 = '"+type2+"' "+
" AND SYSDATE>TO_DATE(score.enddate,'yyyy-mm-dd') "+
" GROUP BY departmentid "+
" ) F ON F.departmentid = dept.id "+
" LEFT JOIN ( SELECT departmentid , "+
" COUNT(1) oassessing "+
" FROM HrmResource hrm , "+
" GP_AccessScore score "+
" WHERE hrm.id = score.userid "+
" AND hrm.status<=3 "+
" AND score.status = 1 "+
" AND year = '"+year+"' "+
" AND type1 = '"+type+"' "+
" AND type2 = '"+type2+"' "+
" AND SYSDATE>TO_DATE(score.enddate,'yyyy-mm-dd') "+
" GROUP BY departmentid "+
" ) G ON G.departmentid = dept.id "+
" LEFT JOIN ( SELECT departmentid , "+
" COUNT(1) oback "+
" FROM HrmResource hrm , "+
" GP_AccessScore score "+
" WHERE hrm.id = score.userid "+
" AND hrm.status<=3 "+
" AND score.status = 2 "+
" AND year = '"+year+"' "+
" AND type1 = '"+type+"' "+
" AND type2 = '"+type2+"' "+
" AND SYSDATE>TO_DATE(score.enddate,'yyyy-mm-dd') "+
" GROUP BY departmentid "+
" ) OBK ON OBK.departmentid = dept.id ";
}
return sql;
}
%>