diff --git a/archives/src/main/java/com/storeroom/modules/common/ExcelUtil.java b/archives/src/main/java/com/storeroom/modules/common/ExcelUtil.java index 6e807af..4e3c2d7 100644 --- a/archives/src/main/java/com/storeroom/modules/common/ExcelUtil.java +++ b/archives/src/main/java/com/storeroom/modules/common/ExcelUtil.java @@ -14,6 +14,7 @@ import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.xssf.usermodel.*; import javax.servlet.http.HttpServletResponse; +import java.awt.*; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.sql.Timestamp; @@ -90,13 +91,13 @@ public class ExcelUtil { // 设置表头字体格式 XSSFFont headersFont = workbook.createFont(); - headersFont.setColor(new XSSFColor(java.awt.Color.DARK_GRAY)); + headersFont.setColor(new XSSFColor((IndexedColorMap) Color.DARK_GRAY)); headersFont.setFontHeightInPoints((short) 14); headersFont.setBold(true); // 设置正文字体格式 XSSFFont dataSetFont = workbook.createFont(); - dataSetFont.setColor(new XSSFColor(java.awt.Color.BLACK)); + dataSetFont.setColor(new XSSFColor((IndexedColorMap) Color.BLACK)); dataSetFont.setBold(false); // 创建表头样式 @@ -227,13 +228,13 @@ public class ExcelUtil { // 设置表头字体格式 XSSFFont headersFont = workbook.createFont(); - headersFont.setColor(new XSSFColor(java.awt.Color.DARK_GRAY)); + headersFont.setColor(new XSSFColor((IndexedColorMap) Color.DARK_GRAY)); headersFont.setFontHeightInPoints((short) 14); headersFont.setBold(true); // 设置正文字体格式 XSSFFont dataSetFont = workbook.createFont(); - dataSetFont.setColor(new XSSFColor(java.awt.Color.BLACK)); + dataSetFont.setColor(new XSSFColor((IndexedColorMap) Color.BLACK)); dataSetFont.setBold(false); // 创建表头样式 diff --git a/common/src/main/java/com/storeroom/utils/CloseUtil.java b/common/src/main/java/com/storeroom/utils/CloseUtil.java new file mode 100644 index 0000000..62b9ebc --- /dev/null +++ b/common/src/main/java/com/storeroom/utils/CloseUtil.java @@ -0,0 +1,25 @@ +package com.storeroom.utils; + +import java.io.Closeable; + +public class CloseUtil { + public static void close(Closeable closeable) { + if (null != closeable) { + try { + closeable.close(); + } catch (Exception e) { + // 静默关闭 + } + } + } + + public static void close(AutoCloseable closeable) { + if (null != closeable) { + try { + closeable.close(); + } catch (Exception e) { + // 静默关闭 + } + } + } +} diff --git a/common/src/main/java/com/storeroom/utils/FileUtil.java b/common/src/main/java/com/storeroom/utils/FileUtil.java index f46e9ea..f05141e 100644 --- a/common/src/main/java/com/storeroom/utils/FileUtil.java +++ b/common/src/main/java/com/storeroom/utils/FileUtil.java @@ -77,7 +77,7 @@ public class FileUtil extends cn.hutool.core.io.FileUtil{ File file = null; try { // 用uuid作为文件名,防止生成的临时文件重复 - file = File.createTempFile(IdUtil.simpleUUID(), prefix); + file = new File(SYS_TEM_DIR + IdUtil.simpleUUID() + prefix); // MultipartFile to File multipartFile.transferTo(file); } catch (IOException e) { @@ -135,20 +135,26 @@ public class FileUtil extends cn.hutool.core.io.FileUtil{ /** * inputStream 转 File */ - static File inputStreamToFile(InputStream ins, String name) throws Exception { + static File inputStreamToFile(InputStream ins, String name){ File file = new File(SYS_TEM_DIR + name); if (file.exists()) { return file; } - OutputStream os = new FileOutputStream(file); - int bytesRead; - int len = 8192; - byte[] buffer = new byte[len]; - while ((bytesRead = ins.read(buffer, 0, len)) != -1) { - os.write(buffer, 0, bytesRead); + OutputStream os = null; + try { + os = new FileOutputStream(file); + int bytesRead; + int len = 8192; + byte[] buffer = new byte[len]; + while ((bytesRead = ins.read(buffer, 0, len)) != -1) { + os.write(buffer, 0, bytesRead); + } + } catch (Exception e) { + e.printStackTrace(); + } finally { + CloseUtil.close(os); + CloseUtil.close(ins); } - os.close(); - ins.close(); return file; } @@ -195,8 +201,6 @@ public class FileUtil extends cn.hutool.core.io.FileUtil{ sheet.trackAllColumnsForAutoSizing(); //列宽自适应 writer.autoSizeColumnAll(); - //列宽自适应支持中文单元格 - sizeChineseColumn(sheet, writer); //response为HttpServletResponse对象 response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8"); //test.xls是弹出下载对话框的文件名,不能为中文,中文请自行编码 @@ -209,33 +213,6 @@ public class FileUtil extends cn.hutool.core.io.FileUtil{ IoUtil.close(out); } - /** - * 自适应宽度(中文支持) - */ - private static void sizeChineseColumn(SXSSFSheet sheet, BigExcelWriter writer) { - for (int columnNum = 0; columnNum < writer.getColumnCount(); columnNum++) { - int columnWidth = sheet.getColumnWidth(columnNum) / 256; - for (int rowNum = 0; rowNum < sheet.getLastRowNum(); rowNum++) { - SXSSFRow currentRow; - if (sheet.getRow(rowNum) == null) { - currentRow = sheet.createRow(rowNum); - } else { - currentRow = sheet.getRow(rowNum); - } - if (currentRow.getCell(columnNum) != null) { - SXSSFCell currentCell = currentRow.getCell(columnNum); - if (currentCell.getCellTypeEnum() == CellType.STRING) { - int length = currentCell.getStringCellValue().getBytes().length; - if (columnWidth < length) { - columnWidth = length; - } - } - } - } - sheet.setColumnWidth(columnNum, columnWidth * 256); - } - } - public static String getFileType(String type) { String documents = "txt doc pdf ppt pps xlsx xls docx"; String music = "mp3 wav wma mpa ram ra aac aif m4a"; @@ -258,7 +235,7 @@ public class FileUtil extends cn.hutool.core.io.FileUtil{ // 1M int len = 1024 * 1024; if (size > (maxSize * len)) { - throw new BaseException("文件超出规定大小"); + throw new BaseException("文件超出规定大小:" + maxSize + "MB"); } } @@ -268,7 +245,10 @@ public class FileUtil extends cn.hutool.core.io.FileUtil{ public static boolean check(File file1, File file2) { String img1Md5 = getMd5(file1); String img2Md5 = getMd5(file2); - return img1Md5.equals(img2Md5); + if(img1Md5 != null){ + return img1Md5.equals(img2Md5); + } + return false; } /** @@ -281,16 +261,19 @@ public class FileUtil extends cn.hutool.core.io.FileUtil{ private static byte[] getByte(File file) { // 得到文件长度 byte[] b = new byte[(int) file.length()]; + InputStream in = null; try { - InputStream in = new FileInputStream(file); + in = new FileInputStream(file); try { System.out.println(in.read(b)); } catch (IOException e) { log.error(e.getMessage(), e); } - } catch (FileNotFoundException e) { + } catch (Exception e) { log.error(e.getMessage(), e); return null; + } finally { + CloseUtil.close(in); } return b; } diff --git a/pom.xml b/pom.xml index 3c872a2..e8b390f 100644 --- a/pom.xml +++ b/pom.xml @@ -164,17 +164,17 @@ org.apache.poi poi - 3.17 + 5.2.0 org.apache.poi poi-ooxml - 3.17 + 5.2.0 xerces xercesImpl - 2.12.0 + 2.12.2 diff --git a/storeroom/src/main/java/com/storeroom/modules/storeroom3d/service/impl/AlarmInfoServiceImpl.java b/storeroom/src/main/java/com/storeroom/modules/storeroom3d/service/impl/AlarmInfoServiceImpl.java index bf5ca33..3a13bb9 100644 --- a/storeroom/src/main/java/com/storeroom/modules/storeroom3d/service/impl/AlarmInfoServiceImpl.java +++ b/storeroom/src/main/java/com/storeroom/modules/storeroom3d/service/impl/AlarmInfoServiceImpl.java @@ -192,7 +192,7 @@ public class AlarmInfoServiceImpl implements AlarmInfoService { @Override public List queryAll(AlarmLogCriteria criteria) { - return null; + return alarmLogRepository.findAll((root, query, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)); } /**