|
@@ -1,6 +1,7 @@
|
|
|
package com.persagy.ibms.data.sdk.util;
|
|
|
|
|
|
import java.io.File;
|
|
|
+import java.io.FileOutputStream;
|
|
|
import java.net.URLEncoder;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.Date;
|
|
@@ -13,7 +14,10 @@ import java.util.concurrent.CopyOnWriteArrayList;
|
|
|
import javax.servlet.ServletOutputStream;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
+import org.apache.poi.ss.usermodel.Workbook;
|
|
|
import org.apache.poi.xssf.streaming.SXSSFSheet;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
import org.springframework.core.io.FileSystemResource;
|
|
|
import org.springframework.http.HttpHeaders;
|
|
|
import org.springframework.http.MediaType;
|
|
@@ -47,7 +51,7 @@ public class ExportUtil {
|
|
|
.body(new FileSystemResource(file));
|
|
|
}
|
|
|
|
|
|
- public static ResponseEntity<FileSystemResource> alarm_export(JSONObject result) throws Exception {
|
|
|
+ public static ResponseEntity<FileSystemResource> alarm_export_poi(JSONObject result) throws Exception {
|
|
|
JSONArray alarm_export_title = FastJsonReaderUtil.Instance().ReadJSONArray(FileUtil.file("alarm_export_title.json"));
|
|
|
List<String> codeList = new CopyOnWriteArrayList<String>();
|
|
|
List<String> titleList = new CopyOnWriteArrayList<String>();
|
|
@@ -75,7 +79,17 @@ public class ExportUtil {
|
|
|
sheetMap.put("Sheet1", sheet);
|
|
|
String filepath = UUID.randomUUID().toString() + ".xlsx";
|
|
|
try {
|
|
|
- ExcelCommonUtil.Write(filepath, sheetMap);
|
|
|
+ Workbook wb;
|
|
|
+ if (filepath.endsWith("xlsx")) {
|
|
|
+ wb = new XSSFWorkbook();
|
|
|
+ } else {
|
|
|
+ wb = new HSSFWorkbook();
|
|
|
+ }
|
|
|
+ ExcelCommonUtil.Write(sheetMap, wb);
|
|
|
+ FileOutputStream os = new FileOutputStream(filepath);
|
|
|
+ wb.write(os);
|
|
|
+ wb.close();
|
|
|
+ os.close();
|
|
|
} catch (Exception e) {
|
|
|
log.error(e.getMessage(), e);
|
|
|
}
|
|
@@ -83,6 +97,158 @@ public class ExportUtil {
|
|
|
}
|
|
|
|
|
|
public static void alarm_export(JSONObject result, HttpServletResponse response) throws Exception {
|
|
|
+ JSONArray content = result.getJSONArray("content");
|
|
|
+ ExcelSheet sheet = new ExcelSheet();
|
|
|
+ for (int i = 0; i < content.size(); i++) {
|
|
|
+ List<String> contentList = new CopyOnWriteArrayList<String>();
|
|
|
+ sheet.contentListList.add(contentList);
|
|
|
+ }
|
|
|
+ SimpleDateFormat sdf_T = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
|
|
|
+ SimpleDateFormat sdf_xie = new SimpleDateFormat("yyyy/MM/dd HH:mm");
|
|
|
+ {
|
|
|
+ sheet.titleColList.add("报警开始时间");
|
|
|
+ for (int i = 0; i < content.size(); i++) {
|
|
|
+ JSONObject contentItem = content.getJSONObject(i);
|
|
|
+ List<String> contentList = sheet.contentListList.get(i);
|
|
|
+ String cellValue = null;
|
|
|
+ if (contentItem.containsKey("triggerTime")) {
|
|
|
+ String triggerTime = contentItem.getString("triggerTime");
|
|
|
+ cellValue = sdf_xie.format(sdf_T.parse(triggerTime));
|
|
|
+ }
|
|
|
+ contentList.add(cellValue);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ {
|
|
|
+ sheet.titleColList.add("持续时间(分钟)");
|
|
|
+ for (int i = 0; i < content.size(); i++) {
|
|
|
+ JSONObject contentItem = content.getJSONObject(i);
|
|
|
+ List<String> contentList = sheet.contentListList.get(i);
|
|
|
+ String cellValue = null;
|
|
|
+ if (contentItem.containsKey("durationMilli")) {
|
|
|
+ long durationMilli = contentItem.getLong("durationMilli");
|
|
|
+ long minute = durationMilli / (1000L * 60);
|
|
|
+ cellValue = "" + minute;
|
|
|
+ }
|
|
|
+ contentList.add(cellValue);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ {
|
|
|
+ sheet.titleColList.add("报警处理状态");
|
|
|
+ for (int i = 0; i < content.size(); i++) {
|
|
|
+ JSONObject contentItem = content.getJSONObject(i);
|
|
|
+ List<String> contentList = sheet.contentListList.get(i);
|
|
|
+ String cellValue = null;
|
|
|
+ if (contentItem.containsKey("treatStateName")) {
|
|
|
+ cellValue = contentItem.getString("treatStateName");
|
|
|
+ }
|
|
|
+ contentList.add(cellValue);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ {
|
|
|
+ sheet.titleColList.add("报警級別");
|
|
|
+ for (int i = 0; i < content.size(); i++) {
|
|
|
+ JSONObject contentItem = content.getJSONObject(i);
|
|
|
+ List<String> contentList = sheet.contentListList.get(i);
|
|
|
+ String cellValue = null;
|
|
|
+ if (contentItem.containsKey("levelName")) {
|
|
|
+ cellValue = contentItem.getString("levelName");
|
|
|
+ }
|
|
|
+ contentList.add(cellValue);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ {
|
|
|
+ sheet.titleColList.add("报警对象名称");
|
|
|
+ for (int i = 0; i < content.size(); i++) {
|
|
|
+ JSONObject contentItem = content.getJSONObject(i);
|
|
|
+ List<String> contentList = sheet.contentListList.get(i);
|
|
|
+ String cellValue = null;
|
|
|
+ if (contentItem.containsKey("objName")) {
|
|
|
+ cellValue = contentItem.getString("objName");
|
|
|
+ }
|
|
|
+ contentList.add(cellValue);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ {
|
|
|
+ sheet.titleColList.add("报警对象编码");
|
|
|
+ for (int i = 0; i < content.size(); i++) {
|
|
|
+ JSONObject contentItem = content.getJSONObject(i);
|
|
|
+ List<String> contentList = sheet.contentListList.get(i);
|
|
|
+ String cellValue = null;
|
|
|
+ if (contentItem.containsKey("objId")) {
|
|
|
+ cellValue = contentItem.getString("objId");
|
|
|
+ }
|
|
|
+ contentList.add(cellValue);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ {
|
|
|
+ sheet.titleColList.add("报警描述");
|
|
|
+ for (int i = 0; i < content.size(); i++) {
|
|
|
+ JSONObject contentItem = content.getJSONObject(i);
|
|
|
+ List<String> contentList = sheet.contentListList.get(i);
|
|
|
+ String cellValue = null;
|
|
|
+ if (contentItem.containsKey("remark")) {
|
|
|
+ cellValue = contentItem.getString("remark");
|
|
|
+ }
|
|
|
+ contentList.add(cellValue);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ {
|
|
|
+ sheet.titleColList.add("报警类型");
|
|
|
+ for (int i = 0; i < content.size(); i++) {
|
|
|
+ JSONObject contentItem = content.getJSONObject(i);
|
|
|
+ List<String> contentList = sheet.contentListList.get(i);
|
|
|
+ String cellValue = null;
|
|
|
+ if (contentItem.containsKey("itemName")) {
|
|
|
+ cellValue = contentItem.getString("itemName");
|
|
|
+ }
|
|
|
+ contentList.add(cellValue);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ {
|
|
|
+ sheet.titleColList.add("批注类型");
|
|
|
+ for (int i = 0; i < content.size(); i++) {
|
|
|
+ JSONObject contentItem = content.getJSONObject(i);
|
|
|
+ List<String> contentList = sheet.contentListList.get(i);
|
|
|
+ String cellValue = null;
|
|
|
+ if (contentItem.containsKey("treatModeName")) {
|
|
|
+ cellValue = contentItem.getString("treatModeName");
|
|
|
+ }
|
|
|
+ contentList.add(cellValue);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ {
|
|
|
+ sheet.titleColList.add("是否重点关注");
|
|
|
+ for (int i = 0; i < content.size(); i++) {
|
|
|
+ JSONObject contentItem = content.getJSONObject(i);
|
|
|
+ List<String> contentList = sheet.contentListList.get(i);
|
|
|
+ String cellValue = null;
|
|
|
+ if (contentItem.containsKey("concern")) {
|
|
|
+ long durationMilli = contentItem.getLong("concern");
|
|
|
+ cellValue = durationMilli == 1 ? "是" : "否";
|
|
|
+ }
|
|
|
+ contentList.add(cellValue);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Map<String, ExcelSheet> sheetMap = new ConcurrentHashMap<String, ExcelSheet>();
|
|
|
+ sheetMap.put("Sheet1", sheet);
|
|
|
+ try {
|
|
|
+ Workbook wb = new XSSFWorkbook();
|
|
|
+ ExcelCommonUtil.Write(sheetMap, wb);
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH_mm_ss.SSS");
|
|
|
+ String xlsFileName = sdf.format(new Date()) + ".xlsx";
|
|
|
+ xlsFileName = URLEncoder.encode(xlsFileName, "UTF-8");
|
|
|
+ response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
|
|
|
+ response.setHeader("Content-Disposition", "attachment;filename=" + xlsFileName);
|
|
|
+ ServletOutputStream out = response.getOutputStream();
|
|
|
+ wb.write(out);
|
|
|
+ wb.close();
|
|
|
+ out.close();
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void alarm_export_hutool(JSONObject result, HttpServletResponse response) throws Exception {
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH_mm_ss.SSS");
|
|
|
JSONArray alarm_export_title = FastJsonReaderUtil.Instance().ReadJSONArray(FileUtil.file("alarm_export_title.json"));
|
|
|
JSONArray content = result.getJSONArray("content");
|
|
@@ -124,7 +290,7 @@ public class ExportUtil {
|
|
|
IoUtil.close(out);
|
|
|
}
|
|
|
|
|
|
- public static ResponseEntity<FileSystemResource> fjd_export(JSONArray parseArray) throws Exception {
|
|
|
+ public static ResponseEntity<FileSystemResource> fjd_export_poi(JSONArray parseArray) throws Exception {
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
SimpleDateFormat sdf_ = new SimpleDateFormat("yyyyMMddHHmmss");
|
|
|
Map<String, ExcelSheet> sheetMap = new ConcurrentHashMap<String, ExcelSheet>();
|
|
@@ -148,14 +314,24 @@ public class ExportUtil {
|
|
|
|
|
|
String filepath = UUID.randomUUID().toString() + ".xlsx";
|
|
|
try {
|
|
|
- ExcelCommonUtil.Write(filepath, sheetMap);
|
|
|
+ Workbook wb;
|
|
|
+ if (filepath.endsWith("xlsx")) {
|
|
|
+ wb = new XSSFWorkbook();
|
|
|
+ } else {
|
|
|
+ wb = new HSSFWorkbook();
|
|
|
+ }
|
|
|
+ ExcelCommonUtil.Write(sheetMap, wb);
|
|
|
+ FileOutputStream os = new FileOutputStream(filepath);
|
|
|
+ wb.write(os);
|
|
|
+ wb.close();
|
|
|
+ os.close();
|
|
|
} catch (Exception e) {
|
|
|
log.error(e.getMessage(), e);
|
|
|
}
|
|
|
return ExportUtil.export(new File(filepath));
|
|
|
}
|
|
|
|
|
|
- public static void fjd_export(JSONArray parseArray, HttpServletResponse response) throws Exception {
|
|
|
+ public static void fjd_export_hutool(JSONArray parseArray, HttpServletResponse response) throws Exception {
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
SimpleDateFormat sdf_ = new SimpleDateFormat("yyyyMMddHHmmss");
|
|
|
String xlsFileName = sdf.format(new Date()) + ".xlsx";
|