1.数据报表销量导出修改
2.开启关闭库存分组微信提醒 3.盘点出入库展示规格名称
This commit is contained in:
@@ -17,14 +17,19 @@ package cn.ysk.cashier.utils;
|
||||
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.poi.excel.BigExcelWriter;
|
||||
import cn.hutool.poi.excel.ExcelUtil;
|
||||
import cn.hutool.poi.excel.ExcelWriter;
|
||||
import cn.ysk.cashier.exception.BadRequestException;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.util.IOUtils;
|
||||
import org.apache.poi.xssf.streaming.SXSSFSheet;
|
||||
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
@@ -154,7 +159,7 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
|
||||
/**
|
||||
* inputStream 转 File
|
||||
*/
|
||||
static File inputStreamToFile(InputStream ins, String name){
|
||||
static File inputStreamToFile(InputStream ins, String name) {
|
||||
File file = new File(SYS_TEM_DIR + name);
|
||||
if (file.exists()) {
|
||||
return file;
|
||||
@@ -215,7 +220,7 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
|
||||
BigExcelWriter writer = ExcelUtil.getBigWriter(file);
|
||||
// 一次性写出内容,使用默认样式,强制输出标题
|
||||
writer.write(list, true);
|
||||
SXSSFSheet sheet = (SXSSFSheet)writer.getSheet();
|
||||
SXSSFSheet sheet = (SXSSFSheet) writer.getSheet();
|
||||
//上面需要强转SXSSFSheet 不然没有trackAllColumnsForAutoSizing方法
|
||||
sheet.trackAllColumnsForAutoSizing();
|
||||
//列宽自适应
|
||||
@@ -232,29 +237,71 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
|
||||
IoUtil.close(out);
|
||||
}
|
||||
|
||||
/**
|
||||
* 输入标题到excel
|
||||
*
|
||||
* @param writer excel对象
|
||||
* @param column 当前列位置
|
||||
* @param cellValue 标题内容
|
||||
* @param requiredFlag 是否标红
|
||||
*/
|
||||
private static void writeCell(ExcelWriter writer, int column, int row, String cellValue, boolean requiredFlag) {
|
||||
// 根据x,y轴设置单元格内容
|
||||
if (StrUtil.isNotBlank(cellValue)) {
|
||||
writer.writeCellValue(column, row, cellValue);
|
||||
}
|
||||
Font font = writer.createFont();
|
||||
font.setColor(Font.COLOR_RED);
|
||||
if (requiredFlag) {
|
||||
// 根据x,y轴获取当前单元格样式
|
||||
CellStyle cellStyle = writer.createCellStyle(column, row);
|
||||
// 内容水平居中
|
||||
cellStyle.setAlignment(HorizontalAlignment.CENTER);
|
||||
// 内容垂直居中
|
||||
cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||
// 设置边框
|
||||
cellStyle.setBorderBottom(BorderStyle.THIN);
|
||||
cellStyle.setBorderLeft(BorderStyle.THIN);
|
||||
cellStyle.setBorderRight(BorderStyle.THIN);
|
||||
// 字体颜色标红
|
||||
// cellStyle.setFont(font);
|
||||
cellStyle.setFillForegroundColor(IndexedColors.PALE_BLUE.getIndex());
|
||||
cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
||||
}
|
||||
}
|
||||
|
||||
public static void downloadExcelAndMerge(List<Map<String, Object>> list, int colSize, HttpServletResponse response, ArrayList<Integer> mergeRowIndex) throws IOException {
|
||||
String tempPath = SYS_TEM_DIR + IdUtil.fastSimpleUUID() + ".xlsx";
|
||||
File file = new File(tempPath);
|
||||
BigExcelWriter writer = ExcelUtil.getBigWriter(file);
|
||||
|
||||
// 合并单元格后的标题行,使用默认标题样式.
|
||||
ExcelWriter writer = ExcelUtil.getWriter(file);
|
||||
for (int i = 0; i < mergeRowIndex.size(); i++) {
|
||||
System.out.println(i);
|
||||
|
||||
int start = i == 0 ? 1 : mergeRowIndex.get(i - 1) + 1;
|
||||
for (int i1 = 0; i1 < colSize; i1++) {
|
||||
writer.merge(i == 0 ? 0 : mergeRowIndex.get(i - 1) + 1, mergeRowIndex.get(i), i1, i1, "", true);
|
||||
|
||||
if (start != mergeRowIndex.get(i)) {
|
||||
writer.merge(i == 0 ? 1 : mergeRowIndex.get(i - 1) + 1, mergeRowIndex.get(i), i1, i1, "", true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 一次性写出内容,使用默认样式,强制输出标题
|
||||
writer.write(list, true);
|
||||
SXSSFSheet sheet = (SXSSFSheet)writer.getSheet();
|
||||
|
||||
XSSFSheet sheet = (XSSFSheet) writer.getSheet();
|
||||
// 设置列宽
|
||||
for (int i = 0; i < colSize + 2; i++) {
|
||||
sheet.setColumnWidth(i, 4000); // 200个字符宽度
|
||||
}
|
||||
//上面需要强转SXSSFSheet 不然没有trackAllColumnsForAutoSizing方法
|
||||
sheet.trackAllColumnsForAutoSizing();
|
||||
// sheet.trackAllColumnsForAutoSizing();
|
||||
//列宽自适应
|
||||
writer.autoSizeColumnAll();
|
||||
// writer.autoSizeColumnAll();
|
||||
//response为HttpServletResponse对象
|
||||
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
|
||||
//test.xls是弹出下载对话框的文件名,不能为中文,中文请自行编码
|
||||
response.setHeader("Content-Disposition", "attachment;filename=file.xlsx");
|
||||
// 将写入的Excel作为文件流写出到response
|
||||
ServletOutputStream out = response.getOutputStream();
|
||||
// 终止后删除临时文件
|
||||
file.deleteOnExit();
|
||||
@@ -295,7 +342,7 @@ 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);
|
||||
if(img1Md5 != null){
|
||||
if (img1Md5 != null) {
|
||||
return img1Md5.equals(img2Md5);
|
||||
}
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user