CompareEnvironmentExcel.jsp
6.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
<%@ page import="java.util.*" %><%@
page import="wscheck.CheckEnvironment" %><%@
page language="java" contentType="text/html; charset=UTF-8" %><%@
page import="weaver.hrm.*" %><%@
page import="weaver.file.*,wscheck.*,weaver.general.*,java.io.*,java.util.zip.*" %><%@
page import="weaver.file.Prop" %>
<jsp:useBean id="ExcelFile" class="weaver.file.ExcelFile" scope="session"/>
<jsp:useBean id="RecordSet" class="weaver.conn.RecordSet" scope="page" />
<head>
</head>
<%
User user = HrmUserVarify.getUser (request , response) ;
if(user == null) return ;
CheckEnvironment ce = new CheckEnvironment();
Map fileMap = (Map)session.getAttribute("CompareEnvironmentMap");
String sourcePath = Util.null2String(request.getParameter("sourcePath"));
String targetPath = Util.null2String(request.getParameter("targetPath"));
String systemInfo = "源路径:"+sourcePath+" 目标路径:"+targetPath;
// create Excel
ExcelSheet es = new ExcelSheet();
ExcelRow topHead = es.newExcelRow();
ExcelRow erHead = es.newExcelRow();
ExcelFile.init();
es.addColumnwidth(1500);
es.addColumnwidth(10000);
es.addColumnwidth(5500);
es.addColumnwidth(4500);
es.addColumnwidth(4900);
String excelName ="环境对比结果";
ExcelStyle estTop = ExcelFile.newExcelStyle("TopInfo");
estTop.setGroundcolor(ExcelStyle.WeaverLightGroundcolor);
estTop.setFontcolor(ExcelStyle.WeaverHeaderFontcolor);
estTop.setFontbold(ExcelStyle.WeaverHeaderFontbold);
estTop.setAlign(ExcelStyle.ALIGN_LEFT);
ExcelStyle est = ExcelFile.newExcelStyle("Header");
est.setGroundcolor(ExcelStyle.WeaverHeaderGroundcolor1);
est.setFontcolor(ExcelStyle.WeaverHeaderFontcolor);
est.setFontbold(ExcelStyle.WeaverHeaderFontbold);
est.setAlign(ExcelStyle.ALIGN_LEFT);
ExcelStyle estDark = ExcelFile.newExcelStyle("dark");
estDark.setGroundcolor(ExcelStyle.WeaverDarkGroundcolor);
estDark.setFontcolor(ExcelStyle.WeaverHeaderFontcolor);
estDark.setAlign(ExcelStyle.ALIGN_LEFT);
ExcelStyle estLight = ExcelFile.newExcelStyle("light");
estLight.setGroundcolor(ExcelStyle.WeaverLightGroundcolor);
estLight.setFontcolor(ExcelStyle.WeaverHeaderFontbold);
estLight.setAlign(ExcelStyle.ALIGN_LEFT);
ExcelStyle estRed = ExcelFile.newExcelStyle("red");
estRed.setGroundcolor(ExcelStyle.WeaverLightGroundcolor);
estRed.setFontcolor(ExcelStyle.RED_Color);
estRed.setAlign(ExcelStyle.ALIGN_LEFT);
ExcelStyle estGreen = ExcelFile.newExcelStyle("green");
estGreen.setGroundcolor(ExcelStyle.WeaverLightGroundcolor);
estGreen.setFontcolor(ExcelStyle.GREEN_Color);
estGreen.setAlign(ExcelStyle.ALIGN_LEFT);
ExcelStyle estBlue = ExcelFile.newExcelStyle("blue");
estBlue.setGroundcolor(ExcelStyle.WeaverLightGroundcolor);
estBlue.setFontcolor(ExcelStyle.BLUE_Color);
estBlue.setAlign(ExcelStyle.ALIGN_LEFT);
String styleName = "";
topHead.addStringValue(systemInfo, "TopInfo", 5);
erHead.addStringValue("序号", "Header");
erHead.addStringValue("文件路径", "Header");
erHead.addStringValue("对比结果说明", "Header");
erHead.addStringValue("源环境最后修改日期", "Header");
erHead.addStringValue("目标环境最后修改日期", "Header");
es.addExcelRow(erHead);
int rowindex = 1;
if (null != fileMap && fileMap.size() > 0) {
Set keyset = fileMap.keySet();
for (Iterator it = keyset.iterator(); it.hasNext();) {
// if (rowindex % 2 == 0) {
// styleName = "light";
// } else {
// styleName = "dark";
// }
String realfilepath = "";
String filename = Util.null2String((String)it.next()).trim();
String[] values = Util.null2String((String)fileMap.get(filename)).trim().split("[+]");
String lastModifieddate_source="";
String lastModifieddate_target="";
String operatetype="";
if(values.length==3){
operatetype=values[0];
lastModifieddate_source = values[1];
lastModifieddate_target = values[2];
}else{continue;}
if(filename.startsWith("/")) {
filename = filename.substring(1,filename.length());
}
styleName = operatetype.equals("2")?"red":operatetype.equals("1")?"green":"blue";
if(operatetype.equals("1")||operatetype.equals("2")){
realfilepath = ("\\".equals(""+File.separatorChar))?sourcePath+(filename.replaceAll("/","\\\\")):sourcePath+filename;
}else if(operatetype.equals("0")){
realfilepath =("\\".equals(""+File.separatorChar))? targetPath+(filename.replaceAll("/","\\\\")):targetPath+filename;
}
ExcelRow er = es.newExcelRow();
er.addStringValue(String.valueOf(rowindex), "light");
er.addStringValue(realfilepath, styleName);
if (operatetype.equals("0")) {
er.addStringValue("源环境不存在该文件", styleName);
} else if (operatetype.equals("1")) {
er.addStringValue("目标环境不存在该文件", styleName);
} else if (operatetype.equals("2")) {
er.addStringValue("目标与源环境文件不一致", styleName);
}
er.addStringValue(lastModifieddate_source, styleName);
er.addStringValue(lastModifieddate_target, styleName);
es.addExcelRow(er);
rowindex++;
}
ExcelFile.setFilename(excelName);
ExcelFile.addSheet("对比结果", es);
//114环境必须使用一下注释的这种写文件到本地,然后流下载,ecology环境用src="/weaver/weaver.file.ExcelOut" 这种方式,
//本来希望两个环境代码同步,但是一直报编码问题,暂时先这样解决
// String filepath="";
// try {
// filepath = ce.toFile(ExcelFile, excelName);
// } catch (Exception ex) {
// ex.printStackTrace();
// }
// File excelfile = new File(filepath);
// if (excelfile.exists()) {
// // 检查文件是否存在
// File obj = new File(filepath);
// response.reset();
// String fileName = excelfile.getName();
// // 写流文件到前端浏览器
// ServletOutputStream outs = response.getOutputStream();
// response.setHeader("Content-disposition", "attachment;filename=" + java.net.URLEncoder.encode(fileName, "GBK"));
// response.setContentType("application/x-download");
// BufferedInputStream bis = null;
// BufferedOutputStream bos = null;
// try {
// bis = new BufferedInputStream(new FileInputStream(filepath));
// bos = new BufferedOutputStream(outs);
// byte[] buff = new byte[2048];
// int bytesRead;
// while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
// bos.write(buff, 0, bytesRead);
// }
// bos.flush();
// } catch (IOException e) {
// throw e;
// } finally {
// if (bis != null)
// bis.close();
// if (bos != null)
// bos.close();
// }
// }
}
%>
<iframe name="ExcelOut" id="ExcelOut" src="/weaver/weaver.file.ExcelOut" style="display:none" ></iframe>
</html>