JsonShow jsCheck = init();
if (!jsCheck.isBoo()) {
jsonData.put("showText", jsCheck.getText());
jsonData.put("success", jsCheck.isBoo());
jsonResult.put("Data", jsonData);
output();
return;
}
List<Map> propertyList = PropertyManager.getInstance().select(null, null);
String[] fixObj = { "agent_code","agent_uuid", "agent_name", "agent_ip", "connect_time" };
String[] fixName = { "终端编号","终端标识", "终端名称", "IP地址", "最后心跳" };
List<Map> agentList = AgentConnectManager.getInstance().selectViewOnlyField(null, "", StringUtil.appendString(new String[] { "agent_id" }, fixObj));
Map<String, String[]> agentMap = new HashMap();
int fixSize = fixObj.length;
int num = fixSize + propertyList.size();
for (Map map : agentList) {
String[] str = new String[num];
for (int i = 0; i < str.length; i++) {
str[i] = "";
}
String agentId = StringUtil.getMapValue(map, "agent_id");
for (int i = 0; i < fixObj.length; i++) {
str[i] = StringUtil.getMapValue(map, fixObj[i]);
}
agentMap.put(agentId, str);
}
//
List<Map> propertyDetailList = PropertyDetailManager.getInstance().select(null, null);
Map<String, String> propertyDetailMap = new HashMap();
for (Map map : propertyDetailList) {
String pdId = StringUtil.getMapValue(map, "propdetail_id");
String value = StringUtil.getMapValue(map, "propdetail_name");
propertyDetailMap.put(pdId, value);
}
//
for (int i = 0; i < propertyList.size(); i++) {
Map map = propertyList.get(i);
String pId = StringUtil.getMapValue(map, "property_id");
boolean isInput = StringUtil.getMapValue(map, "property_ope_flag").equals("0");
List<Map> apList = AgentPropertyManager.getInstance().select(StringUtil.popMap("agent_property_id", pId), null);
for (Map apMap : apList) {
String agentId = StringUtil.getMapValue(apMap, "agent_id");
String value = "";
String pValue = StringUtil.getMapValue(apMap, "property_value");
if (isInput) {
value = pValue;
} else {
if (propertyDetailMap.containsKey(pValue)) {
value = propertyDetailMap.get(pValue);
}
}
if (agentMap.containsKey(agentId)) {
agentMap.get(agentId)[fixSize + i] = value;
}
}
}
//
List<String> pNameList = new ArrayList();
for (String str : fixName) {
pNameList.add(String.valueOf(str));
}
for (Map map : propertyList) {
pNameList.add(StringUtil.getMapValue(map, "property_name"));
}
//logger.info(StringUtil.getObjValue(pNameList.toArray()));
for (Map map : agentList) {
String agentId = StringUtil.getMapValue(map, "agent_id");
// logger.info(StringUtil.getObjValue(agentMap.get(agentId)));
}
//
StringBuilder table = new StringBuilder();
table.append("<meta http-equiv=\"content-type\" content=\"application/ms-excel; charset=UTF-8\"/>");
table.append("<table style='border-collapse: collapse;' border='1'>");
table.append("<tr>");
for (String fieldName : pNameList)
table.append("<td>" + fieldName + "</td>");
table.append("</tr>");
for (Map map : agentList) {
table.append("<tr>");
String agentId = StringUtil.getMapValue(map, "agent_id");
String[] fields = agentMap.get(agentId);
for (String value : fields) {
if (StringUtil.isNotDateyMdHms(value)) {
table.append("<td>" + value + "</td>");
} else {
table.append("<td>'" + value + "</td>");
}
}
table.append("</tr>");
}
table.append("</table>");
byte[] buffer = table.toString().getBytes();
// logger.info(table.toString());
HttpServletResponse response = ServletActionContext.getResponse();
// 清空response
response.reset();
// 设置response的Header
response.addHeader("Content-Disposition", "attachment;filename=" + java.net.URLEncoder.encode("终端属性", "UTF-8") + ".xls");
response.addHeader("Content-Length", "" + buffer.length);
OutputStream toClient = new BufferedOutputStream(response.getOutputStream());
response.setContentType("application/octet-stream");
toClient.write(buffer);
toClient.flush();
toClient.close();
导出excel代码和思路
最新推荐文章于 2024-05-22 22:49:25 发布