|
|
@ -4,6 +4,7 @@ import cn.hutool.core.bean.BeanUtil; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
|
import com.sun.org.apache.bcel.internal.generic.NEW; |
|
|
|
import com.yxt.common.base.utils.PagerUtil; |
|
|
|
import com.yxt.common.core.query.PagerQuery; |
|
|
|
import com.yxt.common.core.result.ResultBean; |
|
|
@ -26,10 +27,12 @@ import javax.servlet.http.HttpServletResponse; |
|
|
|
import java.io.File; |
|
|
|
import java.io.FileOutputStream; |
|
|
|
import java.io.OutputStream; |
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.net.URLEncoder; |
|
|
|
import java.text.DecimalFormat; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.List; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
/** |
|
|
|
* @author feikefei |
|
|
@ -69,47 +72,215 @@ public class InventoryService extends ServiceImpl<InventoryMapper, Inventory> { |
|
|
|
* @throws Exception |
|
|
|
*/ |
|
|
|
public void exportExcel(HttpServletResponse response, List<com.yxt.supervise.gf.shanhai.resp.Inventory> list) throws Exception { |
|
|
|
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyyMMddHHmmss"); |
|
|
|
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd"); |
|
|
|
Date date = new Date(); |
|
|
|
XSSFWorkbook wb = new XSSFWorkbook(); |
|
|
|
//标题行抽出字段
|
|
|
|
String[] head = {"序号","库存数量","仓库编码", "物料id", "物料编码", "物料组id", "物料品牌", "物料名称", "物料单价(成本价)", "最后更新时间", "物料组明文", "最后更新时间明文", "仓库名称"}; |
|
|
|
|
|
|
|
//设置sheet名称,并创建新的sheet对象
|
|
|
|
Sheet stuSheet = wb.createSheet(); |
|
|
|
Map<String, List<com.yxt.supervise.gf.shanhai.resp.Inventory>> listMap = list.stream().collect(Collectors.groupingBy(it -> it.getStorehouse_name())); |
|
|
|
List<Map<String, Object>> listMap1 = new ArrayList<>();//存储汇总数据
|
|
|
|
for (Map.Entry<String, List<com.yxt.supervise.gf.shanhai.resp.Inventory>> stringListEntry : listMap.entrySet()) { |
|
|
|
Map<String, Object> map = new HashMap<>(); |
|
|
|
//标题行抽出字段
|
|
|
|
String[] head = {"序号","库存数量","仓库编码", "物料id", "物料编码", "物料组id", "物料品牌", "物料名称", "物料单价(成本价)", "最后更新时间", "物料组明文", "最后更新时间明文", "仓库名称","货值"}; |
|
|
|
//设置sheet名称,并创建新的sheet对象
|
|
|
|
Sheet stuSheet = wb.createSheet(stringListEntry.getKey()); |
|
|
|
//合并单元格
|
|
|
|
Row headRow = stuSheet.createRow(0); //第一行为头
|
|
|
|
Font head1 = wb.createFont(); |
|
|
|
head1.setFontHeightInPoints((short) 25); |
|
|
|
CellStyle cellStyle = wb.createCellStyle(); |
|
|
|
cellStyle.setFont(head1); |
|
|
|
cellStyle.setAlignment(HorizontalAlignment.CENTER); //设置水平对齐方式
|
|
|
|
cellStyle.setVerticalAlignment(VerticalAlignment.CENTER); //设置垂直对齐方式
|
|
|
|
CellRangeAddress callRangeAddress = new CellRangeAddress(0,0,0,head.length-1); |
|
|
|
Cell cell1 = headRow.createCell(0); |
|
|
|
cell1.setCellStyle(cellStyle); |
|
|
|
cell1.setCellValue(stringListEntry.getKey() + "("+ sdf1.format(date) +")"); |
|
|
|
stuSheet.addMergedRegion(callRangeAddress); |
|
|
|
//设置表头字体大小
|
|
|
|
Font font1 = wb.createFont(); |
|
|
|
font1.setFontHeightInPoints((short) 16); |
|
|
|
//获取表头行
|
|
|
|
Row titleRow = stuSheet.createRow(1); |
|
|
|
//创建单元格,设置style居中,字体,单元格大小等
|
|
|
|
CellStyle style = wb.createCellStyle(); |
|
|
|
style.setVerticalAlignment(VerticalAlignment.CENTER); //设置垂直对齐方式
|
|
|
|
style.setAlignment(HorizontalAlignment.CENTER); |
|
|
|
style.setShrinkToFit(true); //自动伸缩
|
|
|
|
style.setFont(font1); |
|
|
|
Cell cell = null; |
|
|
|
//把已经写好的标题行写入excel文件中
|
|
|
|
for (int i = 0; i < head.length; i++) { |
|
|
|
cell = titleRow.createCell(i); |
|
|
|
cell.setCellValue(head[i]); |
|
|
|
cell.setCellStyle(style); |
|
|
|
} |
|
|
|
//把从数据库中取得的数据一一写入excel文件中
|
|
|
|
Row row = null; |
|
|
|
Cell cell2 = null; |
|
|
|
Double count = 0.0; |
|
|
|
Integer numCount = 0; |
|
|
|
CellStyle dataStyle = wb.createCellStyle(); |
|
|
|
dataStyle.setVerticalAlignment(VerticalAlignment.CENTER); //设置垂直对齐方式
|
|
|
|
dataStyle.setAlignment(HorizontalAlignment.CENTER); //设置水平对齐方式
|
|
|
|
for (int i = 0; i < stringListEntry.getValue().size(); i++) { |
|
|
|
//创建list.size()行数据
|
|
|
|
row = stuSheet.createRow(i + 2); |
|
|
|
//把值一一写进单元格里
|
|
|
|
//设置第一列为自动递增的序号
|
|
|
|
cell2 = row.createCell(0); |
|
|
|
cell2.setCellValue(i + 1); |
|
|
|
cell2.setCellStyle(dataStyle); |
|
|
|
cell2 = row.createCell(1); |
|
|
|
cell2.setCellValue(stringListEntry.getValue().get(i).getNum()); |
|
|
|
numCount+=Integer.parseInt(stringListEntry.getValue().get(i).getNum()); |
|
|
|
cell2.setCellStyle(dataStyle); |
|
|
|
cell2 = row.createCell(2); |
|
|
|
cell2.setCellValue(stringListEntry.getValue().get(i).getStorehouse_code()); |
|
|
|
cell2.setCellStyle(dataStyle); |
|
|
|
cell2 = row.createCell(3); |
|
|
|
cell2.setCellValue(stringListEntry.getValue().get(i).getMateriel_id()); |
|
|
|
cell2.setCellStyle(dataStyle); |
|
|
|
cell2 = row.createCell(4); |
|
|
|
cell2.setCellValue(stringListEntry.getValue().get(i).getMateriel_no()); |
|
|
|
cell2.setCellStyle(dataStyle); |
|
|
|
cell2 = row.createCell(5); |
|
|
|
cell2.setCellValue(stringListEntry.getValue().get(i).getMateriel_group()); |
|
|
|
cell2.setCellStyle(dataStyle); |
|
|
|
cell2 = row.createCell(6); |
|
|
|
cell2.setCellValue(stringListEntry.getValue().get(i).getBrand_name()); |
|
|
|
cell2.setCellStyle(dataStyle); |
|
|
|
cell2 = row.createCell(7); |
|
|
|
cell2.setCellValue(stringListEntry.getValue().get(i).getMateriel_name()); |
|
|
|
cell2.setCellStyle(dataStyle); |
|
|
|
Double price = stringListEntry.getValue().get(i).getPrice(); |
|
|
|
if (price == null){ |
|
|
|
price = 0.0; |
|
|
|
} |
|
|
|
cell2 = row.createCell(8); |
|
|
|
cell2.setCellValue(price); |
|
|
|
cell2.setCellStyle(dataStyle); |
|
|
|
cell2 = row.createCell(9); |
|
|
|
cell2.setCellValue(stringListEntry.getValue().get(i).getUpdate_time()); |
|
|
|
cell2.setCellStyle(dataStyle); |
|
|
|
cell2 = row.createCell(10); |
|
|
|
cell2.setCellValue(stringListEntry.getValue().get(i).getMateriel_group_text()); |
|
|
|
cell2.setCellStyle(dataStyle); |
|
|
|
cell2 = row.createCell(11); |
|
|
|
cell2.setCellValue(stringListEntry.getValue().get(i).getUpdate_time_text()); |
|
|
|
cell2.setCellStyle(dataStyle); |
|
|
|
cell2 = row.createCell(12); |
|
|
|
cell2.setCellValue(stringListEntry.getValue().get(i).getStorehouse_name()); |
|
|
|
cell2.setCellStyle(dataStyle); |
|
|
|
Double i1 = Integer.parseInt(stringListEntry.getValue().get(i).getNum()) * price; |
|
|
|
cell2 = row.createCell(13); |
|
|
|
cell2.setCellValue(i1); |
|
|
|
cell2.setCellStyle(dataStyle); |
|
|
|
count+=i1; |
|
|
|
} |
|
|
|
Font font = wb.createFont(); |
|
|
|
font.setFontHeightInPoints((short) 14); |
|
|
|
Row row1 = stuSheet.createRow(stringListEntry.getValue().size()+2); |
|
|
|
CellStyle style11 = wb.createCellStyle(); |
|
|
|
style11.setVerticalAlignment(VerticalAlignment.CENTER); //设置垂直对齐方式
|
|
|
|
style11.setAlignment(HorizontalAlignment.CENTER); |
|
|
|
style11.setFont(font); |
|
|
|
Cell cell11 = row1.createCell(0); |
|
|
|
cell11.setCellStyle(style11); |
|
|
|
cell11.setCellValue("合计"); |
|
|
|
cell11 = row1.createCell(13); |
|
|
|
cell11.setCellStyle(style11); |
|
|
|
cell11.setCellValue(count); |
|
|
|
map.put("name",stringListEntry.getKey()); |
|
|
|
map.put("numCount",numCount); |
|
|
|
map.put("count",count); |
|
|
|
listMap1.add(map); |
|
|
|
//设置单元格宽度自适应,在此基础上把宽度调至1.5倍
|
|
|
|
for (int i = 0; i < head.length; i++) { |
|
|
|
stuSheet.autoSizeColumn(i, true); |
|
|
|
stuSheet.setColumnWidth(i, stuSheet.getColumnWidth(i) * 15 / 10); |
|
|
|
} |
|
|
|
} |
|
|
|
//汇总工作簿
|
|
|
|
String[] collectHead = {"序号","仓库名称","物料数量","货值"}; |
|
|
|
Sheet stuSheet = wb.createSheet("汇总"); |
|
|
|
Row headRow = stuSheet.createRow(0); //第一行为头
|
|
|
|
Font head1 = wb.createFont(); |
|
|
|
head1.setFontHeightInPoints((short) 25); |
|
|
|
CellStyle cellStyle = wb.createCellStyle(); |
|
|
|
cellStyle.setFont(head1); |
|
|
|
cellStyle.setAlignment(HorizontalAlignment.CENTER); //设置水平对齐方式
|
|
|
|
cellStyle.setVerticalAlignment(VerticalAlignment.CENTER); //设置垂直对齐方式
|
|
|
|
CellRangeAddress callRangeAddress = new CellRangeAddress(0,0,0,collectHead.length-1); |
|
|
|
Cell cell1 = headRow.createCell(0); |
|
|
|
cell1.setCellStyle(cellStyle); |
|
|
|
cell1.setCellValue("库存汇总"); |
|
|
|
stuSheet.addMergedRegion(callRangeAddress); |
|
|
|
//设置表头字体大小
|
|
|
|
Font font1 = wb.createFont(); |
|
|
|
font1.setFontHeightInPoints((short) 16); |
|
|
|
//获取表头行
|
|
|
|
Row titleRow = stuSheet.createRow(0); |
|
|
|
//创建单元格,设置style居中,字体,单元格大小等
|
|
|
|
Row titleRow = stuSheet.createRow(1); |
|
|
|
CellStyle style = wb.createCellStyle(); |
|
|
|
Font font = wb.createFont(); |
|
|
|
font.setFontHeightInPoints((short) 16); |
|
|
|
style.setVerticalAlignment(VerticalAlignment.CENTER); |
|
|
|
style.setAlignment(HorizontalAlignment.CENTER); |
|
|
|
style.setShrinkToFit(true); //自动伸缩
|
|
|
|
style.setFont(font); |
|
|
|
Cell cell = null; |
|
|
|
//把已经写好的标题行写入excel文件中
|
|
|
|
for (int i = 0; i < head.length; i++) { |
|
|
|
for (int i = 0; i < collectHead.length; i++) { |
|
|
|
cell = titleRow.createCell(i); |
|
|
|
cell.setCellValue(head[i]); |
|
|
|
cell.setCellValue(collectHead[i]); |
|
|
|
cell.setCellStyle(style); |
|
|
|
} |
|
|
|
//把从数据库中取得的数据一一写入excel文件中
|
|
|
|
Row row = null; |
|
|
|
for (int i = 0; i < list.size(); i++) { |
|
|
|
Cell cell2 = null; |
|
|
|
Double count = 0.0; |
|
|
|
CellStyle dataStyle = wb.createCellStyle(); |
|
|
|
dataStyle.setVerticalAlignment(VerticalAlignment.CENTER); //设置垂直对齐方式
|
|
|
|
dataStyle.setAlignment(HorizontalAlignment.CENTER); //设置水平对齐方式
|
|
|
|
Integer numSum = 0; |
|
|
|
Double countSum = 0.0; |
|
|
|
for (int i = 0; i < listMap1.size(); i++) { |
|
|
|
//创建list.size()行数据
|
|
|
|
row = stuSheet.createRow(i + 1); |
|
|
|
row = stuSheet.createRow(i + 2); |
|
|
|
//把值一一写进单元格里
|
|
|
|
//设置第一列为自动递增的序号
|
|
|
|
row.createCell(0).setCellValue(i + 1); |
|
|
|
row.createCell(1).setCellValue(list.get(i).getNum()); |
|
|
|
row.createCell(2).setCellValue(list.get(i).getStorehouse_code()); |
|
|
|
row.createCell(3).setCellValue(list.get(i).getMateriel_id()); |
|
|
|
row.createCell(4).setCellValue(list.get(i).getMateriel_no()); |
|
|
|
row.createCell(5).setCellValue(list.get(i).getMateriel_group()); |
|
|
|
row.createCell(6).setCellValue(list.get(i).getBrand_name()); |
|
|
|
row.createCell(7).setCellValue(list.get(i).getMateriel_name()); |
|
|
|
row.createCell(8).setCellValue(list.get(i).getPrice()); |
|
|
|
row.createCell(9).setCellValue(list.get(i).getUpdate_time()); |
|
|
|
row.createCell(10).setCellValue(list.get(i).getMateriel_group_text()); |
|
|
|
row.createCell(11).setCellValue(list.get(i).getUpdate_time_text()); |
|
|
|
row.createCell(12).setCellValue(list.get(i).getStorehouse_name()); |
|
|
|
cell2 = row.createCell(0); |
|
|
|
cell2.setCellValue(i + 1); |
|
|
|
cell2.setCellStyle(dataStyle); |
|
|
|
cell2 = row.createCell(1); |
|
|
|
cell2.setCellValue(listMap1.get(i).get("name").toString()); |
|
|
|
cell2.setCellStyle(dataStyle); |
|
|
|
cell2 = row.createCell(2); |
|
|
|
cell2.setCellValue(listMap1.get(i).get("numCount").toString()); |
|
|
|
numSum+=Integer.parseInt(listMap1.get(i).get("numCount").toString()); |
|
|
|
cell2.setCellStyle(dataStyle); |
|
|
|
cell2 = row.createCell(3); |
|
|
|
DecimalFormat df = new DecimalFormat("#0.00"); |
|
|
|
cell2.setCellValue(df.format(listMap1.get(i).get("count"))); |
|
|
|
countSum+=Double.parseDouble(df.format(listMap1.get(i).get("count"))); |
|
|
|
cell2.setCellStyle(dataStyle); |
|
|
|
} |
|
|
|
font.setFontHeightInPoints((short) 14); |
|
|
|
Row row1 = stuSheet.createRow(listMap1.size()+2); |
|
|
|
CellStyle style11 = wb.createCellStyle(); |
|
|
|
style11.setVerticalAlignment(VerticalAlignment.CENTER); //设置垂直对齐方式
|
|
|
|
style11.setAlignment(HorizontalAlignment.CENTER); |
|
|
|
style11.setFont(font); |
|
|
|
Cell cell11 = row1.createCell(0); |
|
|
|
cell11.setCellStyle(style11); |
|
|
|
cell11.setCellValue("合计"); |
|
|
|
cell11 = row1.createCell(2); |
|
|
|
cell11.setCellStyle(style11); |
|
|
|
cell11.setCellValue(numSum); |
|
|
|
cell11 = row1.createCell(3); |
|
|
|
cell11.setCellStyle(style11); |
|
|
|
cell11.setCellValue(countSum); |
|
|
|
//设置单元格宽度自适应,在此基础上把宽度调至1.5倍
|
|
|
|
for (int i = 0; i < head.length; i++) { |
|
|
|
for (int i = 0; i < collectHead.length; i++) { |
|
|
|
stuSheet.autoSizeColumn(i, true); |
|
|
|
stuSheet.setColumnWidth(i, stuSheet.getColumnWidth(i) * 15 / 10); |
|
|
|
} |
|
|
@ -117,7 +288,7 @@ public class InventoryService extends ServiceImpl<InventoryMapper, Inventory> { |
|
|
|
if (!file.exists()) { |
|
|
|
file.mkdirs(); |
|
|
|
} |
|
|
|
//设置文件名
|
|
|
|
//设置文件名
|
|
|
|
String fileName = sdf1.format(new Date()) + "库存记录" + ".xlsx"; |
|
|
|
String savePath = filePath + File.separator + fileName; |
|
|
|
//下载
|
|
|
|