ObtainExcelData.jsp
16.4 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
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%@page import="com.api.voting.bean.TableHead"%>
<%@ page import="java.util.*" %>
<%@ page import="weaver.file.*" %>
<%@ page import="weaver.voting.bean.*"%>
<%@ include file="/systeminfo/init_wev8.jsp" %>
<jsp:useBean id="RecordSet" class="weaver.conn.RecordSet" scope="page" />
<jsp:useBean id="rs" class="weaver.conn.RecordSet" scope="page" />
<jsp:useBean id="ResourceComInfo" class="weaver.hrm.resource.ResourceComInfo" scope="page" />
<jsp:useBean id="DepartmentComInfo" class="weaver.hrm.company.DepartmentComInfo" scope="page" />
<jsp:useBean id="SubCompanyComInfo" class="weaver.hrm.company.SubCompanyComInfo" scope="page" />
<jsp:useBean id="JobTitlesComInfo" class="weaver.hrm.job.JobTitlesComInfo"></jsp:useBean>
<jsp:useBean id="VotingResultService" class="com.api.voting.service.VotingResultService"></jsp:useBean>
<jsp:useBean id="ExcelFile" class="weaver.file.ExcelFile" scope="session"/>
<%
String votingid = Util.null2String(request.getParameter("votingid"));
//统计信息
ExcelSheet esRate = new ExcelSheet() ;
ExcelRow erRate = null;
Map<String, Object> resultRate = VotingResultService.getVotingResult(user, Integer.parseInt(votingid), null);
List<Map<String, Object>> datas = (List<Map<String, Object>>)resultRate.get("datas");
for(int i=0;i<datas.size();i++){
Map<String, Object> dataMap = datas.get(i);
erRate = esRate.newExcelRow();
erRate.addStringValue((String)dataMap.get("label")+(String)dataMap.get("labelExt")) ;
esRate.addColumnwidth(6000);
erRate.addStringValue((String)dataMap.get("percent")) ;
esRate.addColumnwidth(6000);
String otherView = (String)dataMap.get("otherView");
if("0".equals(otherView) || "1".equals(otherView)){//单选,多选
List<Map<String, Object>> dataSource = (List<Map<String, Object>>)dataMap.get("dataSource");
for(int j=0;j<dataSource.size();j++){
Map<String, Object> sourceMap = dataSource.get(j);
erRate = esRate.newExcelRow () ;
erRate.addStringValue((String)sourceMap.get("oname")) ;
erRate.addStringValue((int)sourceMap.get("nums")+"("+Util.round(String.valueOf((float)sourceMap.get("percentdig")*100),2)+"%)") ;
}
}
if("2".equals(otherView)){//组合选择
List<TableHead> columns = (List<TableHead>)dataMap.get("columns");
erRate = esRate.newExcelRow () ;
for(int j=0;j<columns.size();j++){
TableHead tableHead = columns.get(j);
erRate.addStringValue(tableHead.getTitle()) ;
}
List<Map<String, Object>> dataSource = (List<Map<String, Object>>)dataMap.get("dataSource");
for(int j=0;j<dataSource.size();j++){
Map<String, Object> sourceMap = dataSource.get(j);
erRate = esRate.newExcelRow () ;
erRate.addStringValue((String)sourceMap.get("oname")) ;
int qnums = (int)sourceMap.get("qnums");
for(int k=1;k<columns.size();k++){//选项key不固定,遍历columns获取key oname_643,从1开始过滤oname
TableHead tableHead = columns.get(k);
int num = (int)sourceMap.get(tableHead.getKey());
if(qnums == 0){
erRate.addStringValue("0(0.0%)");
}else{
erRate.addStringValue(num + "("+Util.round(String.valueOf(((float)num/qnums)*100),2)+"%)");
}
}
}
}
erRate = esRate.newExcelRow();
}
//已投票人
ExcelSheet es = new ExcelSheet() ;
ExcelRow er = es.newExcelRow () ;
er.addStringValue(SystemEnv.getHtmlLabelName(15486, user.getLanguage())) ;
er.addStringValue(SystemEnv.getHtmlLabelName(413, user.getLanguage())) ;
er.addStringValue(SystemEnv.getHtmlLabelName(18939, user.getLanguage())) ;
er.addStringValue(SystemEnv.getHtmlLabelName(141, user.getLanguage())) ;
er.addStringValue(SystemEnv.getHtmlLabelName(6086, user.getLanguage())) ;
er.addStringValue(SystemEnv.getHtmlLabelName(683, user.getLanguage())) ;
String dismiss =SystemEnv.getHtmlLabelName(6091, user.getLanguage());//离职
List rsclist = new ArrayList();
Map rscinfomap=new HashMap();
RecordSet.executeSql("select a.useranony,b.id,b.lastname,b.departmentid,b.subcompanyid1,b.jobtitle,b.seclevel,b.status from VotingRemark a inner join HrmResource b on a.resourceid=b.id where a.votingid="+votingid+" and b.status in(0,1,2,3,5) order by a.operatedate asc,a.operatetime asc");
while(RecordSet.next()){
String tmpt_resourceid=Util.null2String(RecordSet.getString("id"));
String tmpt_status=Util.null2String(RecordSet.getString("status"));
rsclist.add(tmpt_resourceid);
List tmptRscInfoList=new ArrayList();
tmptRscInfoList.add(Util.null2String(RecordSet.getString("useranony")));
if("5".equals(tmpt_status)){
tmptRscInfoList.add(Util.null2String(RecordSet.getString("lastname"))+"("+dismiss+")");
}else{
tmptRscInfoList.add(Util.null2String(RecordSet.getString("lastname")));
}
tmptRscInfoList.add(Util.null2String(RecordSet.getString("departmentid")));
tmptRscInfoList.add(Util.null2String(RecordSet.getString("subcompanyid1")));
tmptRscInfoList.add(Util.null2String(RecordSet.getString("jobtitle")));
tmptRscInfoList.add(Util.null2String(RecordSet.getString("seclevel")));
rscinfomap.put(tmpt_resourceid,tmptRscInfoList);
}
Map selectdata=new HashMap();
RecordSet.executeSql("select resourceid,questionid,optionid from VotingResource where votingid="+votingid);
while(RecordSet.next()){
String tmpt_resourceid=Util.null2String(RecordSet.getString("resourceid"));
String tmpt_questionid=Util.null2String(RecordSet.getString("questionid"));
String tmpt_optionid=Util.null2String(RecordSet.getString("optionid"));
if(tmpt_optionid.indexOf("_")>-1){
String leftQuestionid = tmpt_optionid.substring(0,tmpt_optionid.indexOf("_"));
String rightOptionid = tmpt_optionid.substring(tmpt_optionid.indexOf("_")+1);
if(selectdata.containsKey(tmpt_resourceid+"_"+tmpt_questionid+"_"+leftQuestionid)){
List tmptlist=(List)selectdata.get(tmpt_resourceid+"_"+tmpt_questionid+"_"+leftQuestionid);
tmptlist.add(rightOptionid);
} else {
List tmptlist=new ArrayList();
tmptlist.add(rightOptionid);
selectdata.put(tmpt_resourceid+"_"+tmpt_questionid+"_"+leftQuestionid,tmptlist);
}
}else{
if(selectdata.containsKey(tmpt_resourceid+"_"+tmpt_questionid)){
List tmptlist=(List)selectdata.get(tmpt_resourceid+"_"+tmpt_questionid);
tmptlist.add(tmpt_optionid);
} else {
List tmptlist=new ArrayList();
tmptlist.add(tmpt_optionid);
selectdata.put(tmpt_resourceid+"_"+tmpt_questionid,tmptlist);
}
}
}
//处理多选排序问题。注意组合选择的optionid在VotingResource是个字符串,不能关联查询
Map<String,List<String>> selectdataMulti=new HashMap<String,List<String>>();
String multiSql = "select vv.resourceid,vv.questionid,vv.optionid,vp.showorder from"
+" (select vr.resourceid,vr.questionid,vr.optionid from VotingResource vr"
+" inner join VotingQuestion vq on vr.questionid=vq.id and vq.questiontype=0 and vq.ismulti=1 where vr.votingid="+votingid+") vv"
+" LEFT JOIN VotingOption vp on vv.optionid=vp.id order by vp.questionid,vp.showorder";
RecordSet.executeQuery(multiSql);
while(RecordSet.next()){
String tmpt_resourceid=Util.null2String(RecordSet.getString("resourceid"));
String tmpt_questionid=Util.null2String(RecordSet.getString("questionid"));
String tmpt_optionid=Util.null2String(RecordSet.getString("optionid"));
if(selectdataMulti.containsKey(tmpt_resourceid+"_"+tmpt_questionid)){
List tmptlist=(List)selectdataMulti.get(tmpt_resourceid+"_"+tmpt_questionid);
tmptlist.add(tmpt_optionid);
} else {
List tmptlist=new ArrayList();
tmptlist.add(tmpt_optionid);
selectdataMulti.put(tmpt_resourceid+"_"+tmpt_questionid,tmptlist);
}
}
if(!selectdataMulti.isEmpty()){
for(Map.Entry<String,List<String>> en: selectdataMulti.entrySet()){
if(selectdata.containsKey(en.getKey())){
selectdata.put(en.getKey(),en.getValue());
}
}
}
//组合选择中的多选问题 取出排序后的选项
Map<String,List<String>> selectdataMulti2=new HashMap<String,List<String>>();
String multiSql2 = "select vo.id optionid, vo.questionid, vo.showorder from VotingQuestion vq inner join VotingOption vo on vq.id=vo.questionid and vo.roworcolumn = 1"
+"where vq.questiontype=1 and vq.ismulti=1 and vq.votingid="+votingid+" order by vo.showorder";
RecordSet.executeQuery(multiSql2);
while(RecordSet.next()){
String tmpt_questionid=Util.null2String(RecordSet.getString("questionid"));
String tmpt_optionid=Util.null2String(RecordSet.getString("optionid"));
if(selectdataMulti2.containsKey(tmpt_questionid)){
List tmptlist=(List)selectdataMulti2.get(tmpt_questionid);
tmptlist.add(tmpt_optionid);
} else {
List tmptlist=new ArrayList();
tmptlist.add(tmpt_optionid);
selectdataMulti2.put(tmpt_questionid,tmptlist);
}
}
Map otherdata=new HashMap();
RecordSet.executeSql("select resourceid,questionid,otherinput from VotingResourceRemark where votingid="+votingid);
while(RecordSet.next()){
String tmpt_resourceid=Util.null2String(RecordSet.getString("resourceid"));
String tmpt_questionid=Util.null2String(RecordSet.getString("questionid"));
String tmpt_otherinput=Util.null2String(RecordSet.getString("otherinput"));
otherdata.put(tmpt_resourceid+"_"+tmpt_questionid,tmpt_otherinput);
}
Map optionmap=new HashMap();
RecordSet.executeSql("select id,description from VotingOption where votingid="+votingid);
while(RecordSet.next()){
optionmap.put(RecordSet.getString("id"),RecordSet.getString("description"));
}
List qstList=new ArrayList();
Map qstTypeMap = new HashMap();
Map subQstMap = new HashMap();
RecordSet.executeSql("select id,subject,questiontype from VotingQuestion where questiontype in(0,1,3) and votingid="+votingid+" and exists(select 1 from votingoption where questionid=VotingQuestion.id) order by pagenum asc ,showorder asc ");
while(RecordSet.next()){
String tmpt_qst_id=Util.null2String(RecordSet.getString("id"));
String tmpt_qst_subject=Util.null2String(RecordSet.getString("subject"));
int tmpt_qst_type=Util.getIntValue(RecordSet.getString("questiontype"));
qstList.add(tmpt_qst_id);
qstTypeMap.put(tmpt_qst_id,String.valueOf(tmpt_qst_type));
List subQstList=new ArrayList();
subQstMap.put(tmpt_qst_id,subQstList);
if(tmpt_qst_type==1){
int tmpt_count=0;
rs.executeSql("select id,description from VotingOption where questionid="+tmpt_qst_id+" and roworcolumn=0 order by showorder asc");
while(rs.next()){
String tmpt_opt_id=Util.null2String(rs.getString("id"));
subQstList.add(tmpt_opt_id);
String tmpt_opt_subject=Util.null2String(rs.getString("description"));
if(tmpt_count==0){
tmpt_opt_subject=SystemEnv.getHtmlLabelName(126294, user.getLanguage())+tmpt_qst_subject+SystemEnv.getHtmlLabelName(126295, user.getLanguage())+tmpt_opt_subject;
tmpt_count++;
}
er.addStringValue(tmpt_opt_subject) ;
}
continue;
}
er.addStringValue(tmpt_qst_subject) ;
}
//es.addExcelRow(er) ;
String anonymity =SystemEnv.getHtmlLabelName(18611, user.getLanguage());//匿名
for(int i=0;i<rsclist.size();i++){
er = es.newExcelRow();
String tmpt_resourceid=(String)rsclist.get(i);
List tmptRscInfoList=(List)rscinfomap.get(tmpt_resourceid);
String tmpt_useranony=(String)tmptRscInfoList.get(0);
String tmpt_lastname="";
String tmpt_dptmname="";
String tmpt_subcompanyname="";
String tmpt_jobtitle="";
String tmpt_seclevel="";
if(!"1".equals(tmpt_useranony)){
tmpt_lastname=(String)tmptRscInfoList.get(1);
tmpt_dptmname=DepartmentComInfo.getDepartmentname((String)tmptRscInfoList.get(2));
tmpt_subcompanyname=SubCompanyComInfo.getSubCompanyname((String)tmptRscInfoList.get(3));
tmpt_jobtitle=JobTitlesComInfo.getJobTitlesname((String)tmptRscInfoList.get(4));
tmpt_seclevel=(String)tmptRscInfoList.get(5);
}else{
tmpt_lastname=anonymity;
tmpt_dptmname=anonymity;
tmpt_subcompanyname=anonymity;
tmpt_jobtitle=anonymity;
tmpt_seclevel=anonymity;
}
er.addStringValue(String.valueOf(i+1)) ;
er.addStringValue(tmpt_lastname);
er.addStringValue(tmpt_dptmname);
er.addStringValue(tmpt_subcompanyname);
er.addStringValue(tmpt_jobtitle);
er.addStringValue(tmpt_seclevel);
for(int j=0;j<qstList.size();j++){
String tmpt_qst_id=(String)qstList.get(j);
String tmpt_qst_type=(String)qstTypeMap.get(tmpt_qst_id);
if("3".equals(tmpt_qst_type)){
er.addStringValue(Util.null2String(otherdata.get(tmpt_resourceid+"_"+tmpt_qst_id)));
} else if("0".equals(tmpt_qst_type)){
String tmptcellstr="";
List tmptselectlist=(List)selectdata.get(tmpt_resourceid+"_"+tmpt_qst_id);
if(tmptselectlist!=null){
for(int k=0;k<tmptselectlist.size();k++){
String tmpt_option_id=(String)tmptselectlist.get(k);
if(optionmap.containsKey(tmpt_option_id)){
String tmpt_option_desc=(String)optionmap.get(tmpt_option_id);
tmptcellstr +=tmpt_option_desc+";";
}
}
}
if(otherdata.containsKey(tmpt_resourceid+"_"+tmpt_qst_id)){
String tmpt_a=Util.null2String(otherdata.get(tmpt_resourceid+"_"+tmpt_qst_id));
if(!"".equals(tmpt_a)){
tmptcellstr +="["+SystemEnv.getHtmlLabelName(811, user.getLanguage())+"]"+tmpt_a+";";
}
}
er.addStringValue(tmptcellstr);
} else if("1".equals(tmpt_qst_type)){
List subQstList=(List)subQstMap.get(tmpt_qst_id);
if(subQstList==null) continue;
for(int m=0;m<subQstList.size();m++){
String tmptcellstr="";
String tmpt_subqst_id=(String)subQstList.get(m);
List tmptselectlist=(List)selectdata.get(tmpt_resourceid+"_"+tmpt_qst_id+"_"+tmpt_subqst_id);
List<String> multiList = new ArrayList<String>();
if(selectdataMulti2.get(tmpt_qst_id) != null){
multiList.addAll(selectdataMulti2.get(tmpt_qst_id));
}
if(tmptselectlist!=null){
if(multiList.isEmpty()){
for(int n=0;n<tmptselectlist.size();n++){
String tmpt_suboption_id=(String)tmptselectlist.get(n);
String tmpt_suboption_desc=(String)optionmap.get(tmpt_suboption_id);
tmptcellstr +=tmpt_suboption_desc+";";
}
}else{
List<String> multiList2 = new ArrayList<String>();
for(int n=0;n<multiList.size();n++){
String tmpt_suboption_id=(String)multiList.get(n);
//System.out.println("tmpt_suboption_id----:"+tmpt_suboption_id);
if(!tmptselectlist.contains(tmpt_suboption_id)){
//System.out.println("tmpt_suboption_id111111----:"+tmpt_suboption_id);
//multiList.remove(n);
continue;
}
multiList2.add(tmpt_suboption_id);
}
for(int n=0;n<multiList2.size();n++){
String tmpt_suboption_id=(String)multiList2.get(n);
//System.out.println("tmpt_suboption_id2222---:"+tmpt_suboption_id);
String tmpt_suboption_desc=(String)optionmap.get(tmpt_suboption_id);
tmptcellstr +=tmpt_suboption_desc+";";
}
}
}
er.addStringValue(tmptcellstr);
}
}
}
}
String excelfile="ExcelFile_"+votingid+"_"+user.getUID();
ExcelFile.init() ;
ExcelFile.setFilename(SystemEnv.getHtmlLabelName(20042, user.getLanguage())) ;
ExcelFile.addSheet(SystemEnv.getHtmlLabelName(25177, user.getLanguage()), esRate) ;
ExcelFile.addSheet(SystemEnv.getHtmlLabelName(21727, user.getLanguage()), es) ;
//未投票人
ExcelSheet esUn = new ExcelSheet();
ExcelRow erUn = esUn.newExcelRow();
erUn.addStringValue(SystemEnv.getHtmlLabelName(15486, user.getLanguage())) ;
erUn.addStringValue(SystemEnv.getHtmlLabelName(413, user.getLanguage())) ;
erUn.addStringValue(SystemEnv.getHtmlLabelName(18939, user.getLanguage())) ;
erUn.addStringValue(SystemEnv.getHtmlLabelName(141, user.getLanguage())) ;
erUn.addStringValue(SystemEnv.getHtmlLabelName(6086, user.getLanguage())) ;
erUn.addStringValue(SystemEnv.getHtmlLabelName(683, user.getLanguage())) ;
Set<String> hrmIdSet=new HashSet<String>();
rs.executeQuery("select resourceid from VotingShareDetail where votingid=?",votingid);
while(rs.next()){
String resourceid = Util.null2String(rs.getString("resourceid"));
if(!rsclist.contains(resourceid)){
hrmIdSet.add(resourceid);
}
}
int j=0;
for(Iterator iterator = hrmIdSet.iterator();iterator.hasNext();){
erUn = esUn.newExcelRow();
String tmpt_resourceid=(String)iterator.next();
erUn.addStringValue(String.valueOf(j+1)) ;
erUn.addStringValue(ResourceComInfo.getLastname(tmpt_resourceid));
erUn.addStringValue(DepartmentComInfo.getDepartmentname(ResourceComInfo.getDepartmentID(tmpt_resourceid)));
erUn.addStringValue(SubCompanyComInfo.getSubCompanyname(ResourceComInfo.getSubCompanyID(tmpt_resourceid)));
erUn.addStringValue(JobTitlesComInfo.getJobTitlesname(ResourceComInfo.getJobTitle(tmpt_resourceid)));
erUn.addStringValue(ResourceComInfo.getSeclevel(tmpt_resourceid));
j++;
}
ExcelFile.addSheet(SystemEnv.getHtmlLabelName(21728, user.getLanguage()), esUn) ;
session.setAttribute(excelfile,ExcelFile);
response.sendRedirect("/weaver/weaver.file.ExcelOut?excelfile="+excelfile);
%>