监测平台系统导出功能新增util
parent
7d590ed05d
commit
0e2161fd0a
@ -0,0 +1,84 @@
|
|||||||
|
package com.ruoyi.business.utils;
|
||||||
|
|
||||||
|
import com.ruoyi.business.mapper.HwAlarmInfoMapper;
|
||||||
|
import com.ruoyi.common.core.utils.DateUtils;
|
||||||
|
import org.apache.poi.ss.usermodel.Row;
|
||||||
|
import org.apache.poi.ss.usermodel.Sheet;
|
||||||
|
import org.apache.poi.ss.usermodel.Workbook;
|
||||||
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class UnitExcelUtils {
|
||||||
|
@Autowired
|
||||||
|
private HwAlarmInfoMapper hwAlarmInfoMapper;
|
||||||
|
|
||||||
|
public void exportAlarmInfos(HttpServletResponse response, HashMap<Long, List<LinkedHashMap>> map) throws IOException {
|
||||||
|
Workbook bk = new XSSFWorkbook();
|
||||||
|
for (Long aLong : map.keySet()) {
|
||||||
|
List<LinkedHashMap> list3 = map.get(aLong);
|
||||||
|
Sheet unitId = bk.createSheet(aLong.toString());
|
||||||
|
int row = 0;
|
||||||
|
for (row = 0;row < list3.size();row++){
|
||||||
|
if (row == 0){
|
||||||
|
LinkedHashMap map1 = list3.get(row);
|
||||||
|
ArrayList list1 = new ArrayList<>(map1.keySet());
|
||||||
|
int size = map1.keySet().size();
|
||||||
|
int cellIndex = 0;
|
||||||
|
Row row1 = unitId.createRow(row);
|
||||||
|
Row row2 = unitId.createRow(row + 1);
|
||||||
|
for (cellIndex = 0;cellIndex < size;cellIndex++){
|
||||||
|
String key = list1.get(cellIndex).toString();
|
||||||
|
row1.createCell(cellIndex).setCellValue(key);
|
||||||
|
Object value = map1.get(key);
|
||||||
|
if (value instanceof String){
|
||||||
|
row2.createCell(cellIndex).setCellValue((String) map1.get(key));
|
||||||
|
}else if (value instanceof Long){
|
||||||
|
row2.createCell(cellIndex).setCellValue((Long) map1.get(key));
|
||||||
|
}else if(value instanceof Date){
|
||||||
|
row2.createCell(cellIndex).setCellValue((Date) map.get(key));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
LinkedHashMap map1 = list3.get(row);
|
||||||
|
ArrayList list1 = new ArrayList<>(map1.keySet());
|
||||||
|
int size = map1.keySet().size();
|
||||||
|
int cellIndex = 0;
|
||||||
|
Row row1 = unitId.createRow(row);
|
||||||
|
for (cellIndex = 0;cellIndex < size;cellIndex++){
|
||||||
|
String key = list1.get(cellIndex).toString();
|
||||||
|
Object value = map1.get(key);
|
||||||
|
if (value instanceof String){
|
||||||
|
row1.createCell(cellIndex).setCellValue((String) map1.get(key));
|
||||||
|
}else if (value instanceof Long){
|
||||||
|
row1.createCell(cellIndex).setCellValue((Long) map1.get(key));
|
||||||
|
}
|
||||||
|
else if(value instanceof Date){
|
||||||
|
row1.createCell(cellIndex).setCellValue((Date) map.get(key));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
// FileOutputStream stream = new FileOutputStream("告警信息");
|
||||||
|
bk.write(response.getOutputStream());
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
bk.close();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue