MatrixExportOperation.jsp
11.7 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
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.util.*" %>
<%@ page import="weaver.general.Util" %>
<%@page import="weaver.hrm.User"%>
<%@page import="weaver.hrm.HrmUserVarify"%>
<%@page import="java.io.OutputStream"%>
<%@page import="weaver.matrix.MatrixUtil"%>
<%@page import="weaver.workflow.workflow.GetShowCondition"%>
<%@page import="org.apache.poi.hssf.usermodel.HSSFWorkbook"%>
<%@page import="org.apache.poi.hssf.usermodel.HSSFSheet"%>
<%@page import="org.apache.poi.hssf.usermodel.HSSFRow"%>
<%@page import="org.apache.poi.hssf.usermodel.HSSFCellStyle"%>
<%@page import="org.apache.poi.hssf.usermodel.HSSFCell"%>
<%@page import="org.apache.poi.hssf.usermodel.HSSFFont"%>
<%@page import="org.apache.poi.hssf.util.HSSFColor"%>
<%@page import="weaver.systeminfo.SystemEnv"%>
<%@page import="weaver.hrm.common.database.dialect.DialectUtil"%>
<jsp:useBean id="RecordSet" class="weaver.conn.RecordSet" scope="page" />
<jsp:useBean id="MatrixManager" class="weaver.matrix.MatrixManager" scope="page" />
<jsp:useBean id="SubCompanyComInfo" class="weaver.hrm.company.SubCompanyComInfo" scope="page" />
<jsp:useBean id="RecordSet1" class="weaver.conn.RecordSet" scope="page" />
<%
User user = HrmUserVarify.getUser (request , response) ;
if(user==null) {
response.sendRedirect("/login/Login.jsp");
return;
}
//request.setCharacterEncoding("UTF-8");
String matrixid = Util.null2String(request.getParameter("matrixid"));
String method = Util.null2String(request.getParameter("method"));
//System.out.println("olduserid="+matrixid+"====newuserid="+method);
//处理模板导出
try{
//查询在当前矩阵id下的所有字段
List<String> backfiledlist = new ArrayList<String>();
List<String> displaynamelist = new ArrayList<String>();
List<String> fieldType = new ArrayList<String>();
String sql ="select * from MatrixFieldInfo where matrixid="+matrixid+" order by fieldtype asc, priority";
RecordSet.execute(sql);
//获取当前表的所有字段,不包括id
while(RecordSet.next()){
backfiledlist.add(RecordSet.getString("fieldname"));
displaynamelist.add(RecordSet.getString("displayname"));
fieldType.add(RecordSet.getString("browsertypeid"));
}
HSSFWorkbook wb = new HSSFWorkbook();
int sheetNum = 0;
if(!"exportDataNoSQ".equals(method)){
HSSFSheet sheet0 = wb.createSheet(""+SystemEnv.getHtmlLabelName(84453,user.getLanguage())); //TODO 84453 矩阵导入说明
sheet0.setColumnWidth((short)1, (short)(1000 * 256));
wb.setSheetName(0,""+SystemEnv.getHtmlLabelName(84453,user.getLanguage()));
HSSFCell cell_;
//第一行
HSSFRow row0 = sheet0.createRow((int) 0);
HSSFCellStyle style0 = wb.createCellStyle();
style0.setAlignment(HSSFCellStyle.ALIGN_CENTER);
HSSFCellStyle style_ = wb.createCellStyle();
style_.setAlignment(HSSFCellStyle.ALIGN_LEFT);
cell_ = row0.createCell((short) 0);
//cell_.setEncoding(HSSFCell.ENCODING_UTF_16);
cell_.setCellValue(""+SystemEnv.getHtmlLabelName(15486,user.getLanguage())); //序号
cell_.setCellStyle(style0);
cell_ = row0.createCell((short) 1);
//cell_.setEncoding(HSSFCell.ENCODING_UTF_16);
cell_.setCellValue(""+SystemEnv.getHtmlLabelName(25734,user.getLanguage())); //说明
cell_.setCellStyle(style_);
//第二行
row0 = sheet0.createRow((int) 1);
cell_ = row0.createCell((short) 0);
//cell_.setEncoding(HSSFCell.ENCODING_UTF_16);
cell_.setCellValue(1); //序号
cell_.setCellStyle(style0);
cell_ = row0.createCell((short) 1);
//cell_.setEncoding(HSSFCell.ENCODING_UTF_16);
cell_.setCellValue(""+SystemEnv.getHtmlLabelName(84454,user.getLanguage())); //说明
cell_.setCellStyle(style_);
//第三行
row0 = sheet0.createRow((int) 2);
cell_ = row0.createCell((short) 0);
//cell_.setEncoding(HSSFCell.ENCODING_UTF_16);
cell_.setCellValue(2); //序号
cell_.setCellStyle(style0);
cell_ = row0.createCell((short) 1);
//cell_.setEncoding(HSSFCell.ENCODING_UTF_16);
cell_.setCellValue(""+SystemEnv.getHtmlLabelName(84455,user.getLanguage())); //说明
cell_.setCellStyle(style_);
//第四行
row0 = sheet0.createRow((int) 3);
cell_ = row0.createCell((short) 0);
//cell_.setEncoding(HSSFCell.ENCODING_UTF_16);
cell_.setCellValue(3); //序号
cell_.setCellStyle(style0);
cell_ = row0.createCell((short) 1);
//cell_.setEncoding(HSSFCell.ENCODING_UTF_16);
cell_.setCellValue(""+SystemEnv.getHtmlLabelName(84456,user.getLanguage())); //说明
cell_.setCellStyle(style_);
//第五行
row0 = sheet0.createRow((int) 4);
cell_ = row0.createCell((short) 0);
//cell_.setEncoding(HSSFCell.ENCODING_UTF_16);
cell_.setCellValue(4); //序号
cell_.setCellStyle(style0);
cell_ = row0.createCell((short) 1);
//cell_.setEncoding(HSSFCell.ENCODING_UTF_16);
cell_.setCellValue(""+SystemEnv.getHtmlLabelName(84457,user.getLanguage())); //说明
cell_.setCellStyle(style_);
//第六行
row0 = sheet0.createRow((int) 5);
cell_ = row0.createCell((short) 0);
//cell_.setEncoding(HSSFCell.ENCODING_UTF_16);
cell_.setCellValue(5); //序号
cell_.setCellStyle(style0);
cell_ = row0.createCell((short) 1);
//cell_.setEncoding(HSSFCell.ENCODING_UTF_16);
cell_.setCellValue(""+SystemEnv.getHtmlLabelName(84458,user.getLanguage())); //说明
cell_.setCellStyle(style_);
//第七行
row0 = sheet0.createRow((int) 6);
cell_ = row0.createCell((short) 0);
//cell_.setEncoding(HSSFCell.ENCODING_UTF_16);
cell_.setCellValue(6); //序号
cell_.setCellStyle(style0);
cell_ = row0.createCell((short) 1);
//cell_.setEncoding(HSSFCell.ENCODING_UTF_16);
cell_.setCellValue(""+SystemEnv.getHtmlLabelName(84580,user.getLanguage())); //说明
cell_.setCellStyle(style_);
sheetNum++;
}
HSSFSheet sheet = wb.createSheet(""+SystemEnv.getHtmlLabelName(84452,user.getLanguage())); //TODO 84452 矩阵导入模板
sheet.setDefaultColumnWidth( (short)15);
wb.setSheetName(sheetNum,""+SystemEnv.getHtmlLabelName(84452,user.getLanguage()));
HSSFRow row = sheet.createRow((int) 0);
HSSFCellStyle style = wb.createCellStyle();
style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
HSSFCellStyle style1 = wb.createCellStyle();
HSSFFont font = wb.createFont();
font.setColor(HSSFColor.GREY_50_PERCENT.index);
style1.setFont(font);
HSSFCell cell;
int cellNum = 0;
if("exportData".equals(method)){
cell = row.createCell((short) 0);
//cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("UUID("+SystemEnv.getHtmlLabelName(129277, user.getLanguage())+")");
cell.setCellStyle(style1);
cellNum++;
}
HSSFCellStyle style2 = wb.createCellStyle();
HSSFFont font2 = wb.createFont();
font2.setColor(HSSFColor.ORANGE.index);
font2.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
style2.setFont(font2);
style2.setAlignment(HSSFCellStyle.ALIGN_CENTER);
for (int i = cellNum; i < displaynamelist.size()+cellNum; i++)
{
cell = row.createCell((short) (i));
//cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(displaynamelist.get("exportData".equals(method)?i-1:i));
cell.setCellStyle(style2);
}
if("exportData".equals(method)||"exportDataNoSQ".equals(method)){
Map<String, Map<String, String>> fieldinfos=MatrixUtil.getFieldDetail(matrixid);
//根据id值获取具体的名称
GetShowCondition conditions=new GetShowCondition();
String dbType = RecordSet1.getDBType();
String dataorder = "dataorder";
if("oracle".equalsIgnoreCase(dbType)){
if(Util.null2String(RecordSet1.getOrgindbtype()).equals("jc"))
dataorder="cast(dataorder AS float)-1";
else
dataorder = "dataorder-1";
}else if("sqlserver".equalsIgnoreCase(dbType)){
dataorder = "cast(dataorder as float)";
}else if(DialectUtil.isMySql(dbType)){
dataorder = "cast(dataorder as decimal)";
}
sql ="select * from "+MatrixUtil.MATRIXPREFIX+matrixid +" order by "+dataorder;
RecordSet1.execute(sql);
int rowNum =1;
while(RecordSet1.next())
{
row = sheet.createRow((int) rowNum);
if(!"exportDataNoSQ".equals(method)){
cell = row.createCell((short) 0);
cell.setCellValue(RecordSet1.getString("UUID"));
cell.setCellStyle(style1);
}
//添加列值
for(int i=0;i<backfiledlist.size();i++){
String filedValue = RecordSet1.getString(backfiledlist.get(i));
String showName = "";
if(!"".equals(filedValue)){
if("exportDataNoSQ".equals(method)){
showName = MatrixUtil.getSpanValueByIds(fieldinfos.get(backfiledlist.get(i).toLowerCase()),conditions,filedValue);
if("162".equals(fieldType.get(i))||"17".equals(fieldType.get(i))){ //自定义多选
showName = showName.replace(",",";");
}
}else{
if("1".equals(fieldType.get(i))||"17".equals(fieldType.get(i))){//人员
showName =MatrixManager.getResource(filedValue);
}else if("164".equals(fieldType.get(i))){ // 分部类型
showName =MatrixManager.getSubcompany(filedValue);
}else if("4".equals(fieldType.get(i))){ // 部门类型
showName =MatrixManager.getDepartment(filedValue);
}else if("24".equals(fieldType.get(i))){ // 岗位类型
showName =MatrixManager.getJobTitleName(filedValue);
}else{
showName = MatrixUtil.getSpanValueByIds(fieldinfos.get(backfiledlist.get(i)),conditions,filedValue);
}
if("162".equals(fieldType.get(i))){ //自定义多选
showName = showName.replace(",",";");
}
}
}
cell = row.createCell((short) (i+sheetNum));
//cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(showName);
cell.setCellStyle(style);
}
rowNum++;
}
}
String name = "";
RecordSet1.executeSql("select issystem,name from MatrixInfo where id =" +matrixid);
if(RecordSet1.next()){
name = RecordSet1.getString("name");
}
name += SystemEnv.getHtmlLabelName(84477,user.getLanguage());
name = new String(name.getBytes(),"ISO8859-1");
OutputStream os = response.getOutputStream();// 取得输出流
response.reset();// 清空输出流
response.setHeader("Content-disposition", "attachment; filename="+name+".xls");// 设定输出文件头
response.setContentType("application/msexcel;charset=utf-8");// 定义输出类型
response.setCharacterEncoding("utf-8");
wb.write(os);
os.close();
return;
}catch(Exception e){
}
%>