|
|
@ -1,8 +1,7 @@ |
|
|
|
package com.yxt.supervise.gf.biz.instock; |
|
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil; |
|
|
|
import cn.hutool.json.JSONObject; |
|
|
|
import cn.hutool.json.JSONUtil; |
|
|
|
import cn.hutool.core.date.DateUtil; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
@ -13,14 +12,26 @@ import com.yxt.common.core.vo.PagerVo; |
|
|
|
import com.yxt.supervise.gf.api.instock.InStock; |
|
|
|
import com.yxt.supervise.gf.api.instock.InStockQuery; |
|
|
|
import com.yxt.supervise.gf.api.instock.InStockVo; |
|
|
|
import com.yxt.supervise.gf.api.pushinventorydata.PushInventoryData; |
|
|
|
import com.yxt.supervise.gf.shanhai.ShRequester; |
|
|
|
import com.yxt.supervise.gf.shanhai.req.In_stockGetRecordMaterielList; |
|
|
|
import com.yxt.supervise.gf.shanhai.resp.BaseResponse; |
|
|
|
import com.yxt.supervise.gf.shanhai.resp.BaseResponseListObj; |
|
|
|
import com.yxt.supervise.gf.shanhai.resp.InStockGetRecordMaterielList; |
|
|
|
import org.apache.poi.hssf.usermodel.HSSFCellStyle; |
|
|
|
import org.apache.poi.ss.usermodel.*; |
|
|
|
import org.apache.poi.ss.util.CellRangeAddress; |
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
import java.io.File; |
|
|
|
import java.io.FileOutputStream; |
|
|
|
import java.io.OutputStream; |
|
|
|
import java.text.DecimalFormat; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
/** |
|
|
|
* @author feikefei |
|
|
@ -29,8 +40,14 @@ import java.util.List; |
|
|
|
@Service |
|
|
|
public class InStockService extends ServiceImpl<InStockMapper, InStock> { |
|
|
|
|
|
|
|
@Value("${import.filePath}") |
|
|
|
private String filePath; |
|
|
|
|
|
|
|
public ResultBean save(In_stockGetRecordMaterielList reqParams){ |
|
|
|
ResultBean rb = ResultBean.fireFail(); |
|
|
|
String currDay = DateUtil.format(DateUtil.offsetDay(new Date(), -1), "yyyy-MM-dd"); |
|
|
|
reqParams.setStart_happen_time(currDay); |
|
|
|
reqParams.setEnd_happen_time(currDay); |
|
|
|
BaseResponse<BaseResponseListObj<InStockGetRecordMaterielList>> api$system$in_stock$get_record_materiel_list = ShRequester.getApi$system$in_stock$get_record_materiel_list(reqParams); |
|
|
|
List<InStockGetRecordMaterielList> list = api$system$in_stock$get_record_materiel_list.getData().getList(); |
|
|
|
for (InStockGetRecordMaterielList inStockGetRecordMaterielList : list) { |
|
|
@ -38,9 +55,300 @@ public class InStockService extends ServiceImpl<InStockMapper, InStock> { |
|
|
|
BeanUtil.copyProperties(inStockGetRecordMaterielList,inStock); |
|
|
|
baseMapper.insert(inStock); |
|
|
|
} |
|
|
|
Map<String, List<InStockGetRecordMaterielList>> listMap = list.stream().collect(Collectors.groupingBy(it -> it.getStorehouse_name())); |
|
|
|
Map<String, List<InStockGetRecordMaterielList>> map = new HashMap<>(); |
|
|
|
for (Map.Entry<String, List<InStockGetRecordMaterielList>> stringListEntry : listMap.entrySet()) { |
|
|
|
String key = stringListEntry.getKey(); |
|
|
|
if (key.equals("江西余干库") || key.equals("庄河荣名库") || key.equals("安阳荣名库") || key.equals("藁城荣名库") || key.equals("曲阜荣名库")) { |
|
|
|
List<InStockGetRecordMaterielList> value = stringListEntry.getValue(); |
|
|
|
List<InStockGetRecordMaterielList> filterValue = null; |
|
|
|
filterValue = value.stream().filter(t -> t.getMateriel_group_text().equals("组件") || t.getMateriel_group_text().equals("逆变器")).collect(Collectors.toList()); |
|
|
|
if (filterValue.size() != 0){ |
|
|
|
map.put(stringListEntry.getKey(),filterValue); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
try { |
|
|
|
exportExcel(map); |
|
|
|
}catch (Exception e){ |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
return rb.success().setMsg("新增成功"); |
|
|
|
} |
|
|
|
|
|
|
|
public void exportExcel(Map<String, List<InStockGetRecordMaterielList>> map1) throws Exception{ |
|
|
|
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy/MM/dd"); |
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
|
|
|
Date date = new Date(); |
|
|
|
XSSFWorkbook wb = new XSSFWorkbook(); |
|
|
|
List<Map<String, Object>> listMap1 = new ArrayList<>();//存储汇总数据
|
|
|
|
for (Map.Entry<String, List<InStockGetRecordMaterielList>> stringListEntry : map1.entrySet()) { |
|
|
|
Map<String, Object> map = new HashMap<>(); |
|
|
|
//标题行抽出字段
|
|
|
|
String[] head = {"质物名称","规格(型号)","生产厂家(产地)","数量","重量","质权人确认的单价","核算的价值","货位号","备注"}; |
|
|
|
//设置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("货物入库质押表"); |
|
|
|
stuSheet.addMergedRegion(callRangeAddress); |
|
|
|
Row headRowOne = stuSheet.createRow(1); |
|
|
|
Cell headCell = headRowOne.createCell(0); |
|
|
|
headCell.setCellValue("编号:"); |
|
|
|
Cell headCell1 = headRowOne.createCell(8); |
|
|
|
headCell1.setCellValue("仓库名称:" + stringListEntry.getKey()); |
|
|
|
CellRangeAddress callRangeAddress1 = new CellRangeAddress(2,2,0,head.length-1); |
|
|
|
Row headRowTwo = stuSheet.createRow(2); |
|
|
|
Cell headCellTwo = headRowTwo.createCell(0); |
|
|
|
headCellTwo.setCellValue("上报日期:" + sdf1.format(date)); |
|
|
|
stuSheet.addMergedRegion(callRangeAddress1); |
|
|
|
//设置表头字体大小
|
|
|
|
Font font1 = wb.createFont(); |
|
|
|
font1.setFontHeightInPoints((short) 16); |
|
|
|
//获取表头行
|
|
|
|
Row titleRow = stuSheet.createRow(3); |
|
|
|
//创建单元格,设置style居中,字体,单元格大小等
|
|
|
|
CellStyle style = wb.createCellStyle(); |
|
|
|
style.setVerticalAlignment(VerticalAlignment.CENTER); //设置垂直对齐方式
|
|
|
|
style.setAlignment(HorizontalAlignment.CENTER); |
|
|
|
style.setBorderBottom(BorderStyle.THIN); //下边框
|
|
|
|
style.setBorderLeft(BorderStyle.THIN);//左边框
|
|
|
|
style.setBorderTop(BorderStyle.THIN);//上边框
|
|
|
|
style.setBorderRight(BorderStyle.THIN);//右边框
|
|
|
|
style.setShrinkToFit(true); //自动伸缩
|
|
|
|
style.setFont(font1); |
|
|
|
//把已经写好的标题行写入excel文件中
|
|
|
|
for (int i = 0; i < head.length; i++) { |
|
|
|
Cell 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); //设置水平对齐方式
|
|
|
|
dataStyle.setBorderBottom(BorderStyle.THIN); //下边框
|
|
|
|
dataStyle.setBorderLeft(BorderStyle.THIN);//左边框
|
|
|
|
dataStyle.setBorderTop(BorderStyle.THIN);//上边框
|
|
|
|
dataStyle.setBorderRight(BorderStyle.THIN);//右边框
|
|
|
|
for (int i = 0; i < stringListEntry.getValue().size(); i++) { |
|
|
|
//创建list.size()行数据
|
|
|
|
row = stuSheet.createRow(i + 4); |
|
|
|
//把值一一写进单元格里
|
|
|
|
//设置第一列为自动递增的序号
|
|
|
|
cell2 = row.createCell(0); |
|
|
|
cell2.setCellValue(stringListEntry.getValue().get(i).getMateriel_group_text()); |
|
|
|
cell2.setCellStyle(dataStyle); |
|
|
|
cell2 = row.createCell(1); |
|
|
|
cell2.setCellValue(stringListEntry.getValue().get(i).getMateriel_name()); |
|
|
|
numCount+=Integer.parseInt(stringListEntry.getValue().get(i).getNum()); |
|
|
|
cell2.setCellStyle(dataStyle); |
|
|
|
cell2 = row.createCell(2); |
|
|
|
cell2.setCellValue(stringListEntry.getValue().get(i).getSource_name()); |
|
|
|
cell2.setCellStyle(dataStyle); |
|
|
|
cell2 = row.createCell(3); |
|
|
|
cell2.setCellValue(stringListEntry.getValue().get(i).getNum()); |
|
|
|
cell2.setCellStyle(dataStyle); |
|
|
|
cell2 = row.createCell(4); |
|
|
|
cell2.setCellValue(""); |
|
|
|
cell2.setCellStyle(dataStyle); |
|
|
|
cell2 = row.createCell(5); |
|
|
|
cell2.setCellValue(stringListEntry.getValue().get(i).getPrice()); |
|
|
|
cell2.setCellStyle(dataStyle); |
|
|
|
cell2 = row.createCell(6); |
|
|
|
Double price = Double.parseDouble(stringListEntry.getValue().get(i).getPrice()) * Integer.parseInt(stringListEntry.getValue().get(i).getNum()); |
|
|
|
if (price == null){ |
|
|
|
price = 0.0; |
|
|
|
} |
|
|
|
cell2.setCellValue(price); |
|
|
|
cell2.setCellStyle(dataStyle); |
|
|
|
cell2 = row.createCell(7); |
|
|
|
cell2.setCellValue(""); |
|
|
|
cell2.setCellStyle(dataStyle); |
|
|
|
cell2 = row.createCell(8); |
|
|
|
cell2.setCellValue(""); |
|
|
|
cell2.setCellStyle(dataStyle); |
|
|
|
count+=price; |
|
|
|
} |
|
|
|
|
|
|
|
Font font = wb.createFont(); |
|
|
|
font.setFontHeightInPoints((short) 14); |
|
|
|
Row row1 = stuSheet.createRow(stringListEntry.getValue().size()+4); |
|
|
|
CellStyle style11 = wb.createCellStyle(); |
|
|
|
style11.setVerticalAlignment(VerticalAlignment.CENTER); //设置垂直对齐方式
|
|
|
|
style11.setAlignment(HorizontalAlignment.CENTER); |
|
|
|
style11.setBorderBottom(BorderStyle.THIN); //下边框
|
|
|
|
style11.setBorderLeft(BorderStyle.THIN);//左边框
|
|
|
|
style11.setBorderTop(BorderStyle.THIN);//上边框
|
|
|
|
style11.setBorderRight(BorderStyle.THIN);//右边框
|
|
|
|
style11.setFont(font); |
|
|
|
Cell cell11 = row1.createCell(0); |
|
|
|
cell11.setCellStyle(style11); |
|
|
|
cell11.setCellValue("合计"); |
|
|
|
cell11 = row1.createCell(3); |
|
|
|
cell11.setCellStyle(style11); |
|
|
|
cell11.setCellValue(numCount); |
|
|
|
cell11 = row1.createCell(6); |
|
|
|
cell11.setCellStyle(style11); |
|
|
|
cell11.setCellValue(count); |
|
|
|
cell11 = row1.createCell(1); |
|
|
|
cell11.setCellStyle(style11); |
|
|
|
cell11 = row1.createCell(2); |
|
|
|
cell11.setCellStyle(style11); |
|
|
|
cell11 = row1.createCell(4); |
|
|
|
cell11.setCellStyle(style11); |
|
|
|
cell11 = row1.createCell(5); |
|
|
|
cell11.setCellStyle(style11); |
|
|
|
cell11 = row1.createCell(7); |
|
|
|
cell11.setCellStyle(style11); |
|
|
|
cell11 = row1.createCell(8); |
|
|
|
cell11.setCellStyle(style11); |
|
|
|
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); |
|
|
|
CellRangeAddress callRangeAddress1 = new CellRangeAddress(1,1,0,collectHead.length-1); |
|
|
|
CellRangeAddress callRangeAddress2 = new CellRangeAddress(2,2,0,collectHead.length-1); |
|
|
|
Cell cell1 = headRow.createCell(0); |
|
|
|
cell1.setCellStyle(cellStyle); |
|
|
|
cell1.setCellValue("货物入库质押汇总表"); |
|
|
|
stuSheet.addMergedRegion(callRangeAddress); |
|
|
|
|
|
|
|
Row headRowOne = stuSheet.createRow(1); |
|
|
|
Cell headCell = headRowOne.createCell(0); |
|
|
|
headCell.setCellValue("编号:"); |
|
|
|
stuSheet.addMergedRegion(callRangeAddress1); |
|
|
|
Row headRowTwo = stuSheet.createRow(2); |
|
|
|
Cell headCellTwo = headRowTwo.createCell(0); |
|
|
|
headCellTwo.setCellValue("上报日期:" + sdf1.format(date)); |
|
|
|
stuSheet.addMergedRegion(callRangeAddress2); |
|
|
|
|
|
|
|
//设置表头字体大小
|
|
|
|
Font font1 = wb.createFont(); |
|
|
|
font1.setFontHeightInPoints((short) 16); |
|
|
|
//获取表头行
|
|
|
|
Row titleRow = stuSheet.createRow(3); |
|
|
|
CellStyle style = wb.createCellStyle(); |
|
|
|
Font font = wb.createFont(); |
|
|
|
font.setFontHeightInPoints((short) 16); |
|
|
|
style.setVerticalAlignment(VerticalAlignment.CENTER); |
|
|
|
style.setAlignment(HorizontalAlignment.CENTER); |
|
|
|
style.setBorderBottom(BorderStyle.THIN); //下边框
|
|
|
|
style.setBorderLeft(BorderStyle.THIN);//左边框
|
|
|
|
style.setBorderTop(BorderStyle.THIN);//上边框
|
|
|
|
style.setBorderRight(BorderStyle.THIN);//右边框
|
|
|
|
style.setShrinkToFit(true); //自动伸缩
|
|
|
|
style.setFont(font); |
|
|
|
Cell cell = null; |
|
|
|
//把已经写好的标题行写入excel文件中
|
|
|
|
for (int i = 0; i < collectHead.length; i++) { |
|
|
|
cell = titleRow.createCell(i); |
|
|
|
cell.setCellValue(collectHead[i]); |
|
|
|
cell.setCellStyle(style); |
|
|
|
} |
|
|
|
//把从数据库中取得的数据一一写入excel文件中
|
|
|
|
Row row = null; |
|
|
|
Cell cell2 = null; |
|
|
|
Double count = 0.0; |
|
|
|
CellStyle dataStyle = wb.createCellStyle(); |
|
|
|
dataStyle.setBorderBottom(BorderStyle.THIN); //下边框
|
|
|
|
dataStyle.setBorderLeft(BorderStyle.THIN);//左边框
|
|
|
|
dataStyle.setBorderTop(BorderStyle.THIN);//上边框
|
|
|
|
dataStyle.setBorderRight(BorderStyle.THIN);//右边框
|
|
|
|
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 + 4); |
|
|
|
//把值一一写进单元格里
|
|
|
|
//设置第一列为自动递增的序号
|
|
|
|
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()+4); |
|
|
|
CellStyle style11 = wb.createCellStyle(); |
|
|
|
style11.setVerticalAlignment(VerticalAlignment.CENTER); //设置垂直对齐方式
|
|
|
|
style11.setAlignment(HorizontalAlignment.CENTER); |
|
|
|
style11.setBorderBottom(BorderStyle.THIN); //下边框
|
|
|
|
style11.setBorderLeft(BorderStyle.THIN);//左边框
|
|
|
|
style11.setBorderTop(BorderStyle.THIN);//上边框
|
|
|
|
style11.setBorderRight(BorderStyle.THIN);//右边框
|
|
|
|
style11.setFont(font); |
|
|
|
Cell cell11 = row1.createCell(0); |
|
|
|
cell11.setCellStyle(style11); |
|
|
|
cell11.setCellValue("合计"); |
|
|
|
cell11 = row1.createCell(1); |
|
|
|
cell11.setCellStyle(style11); |
|
|
|
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 < collectHead.length; i++) { |
|
|
|
stuSheet.autoSizeColumn(i, true); |
|
|
|
stuSheet.setColumnWidth(i, stuSheet.getColumnWidth(i) * 15 / 10); |
|
|
|
} |
|
|
|
File file = new File(filePath); |
|
|
|
if (!file.exists()) { |
|
|
|
file.mkdirs(); |
|
|
|
} |
|
|
|
//设置文件名
|
|
|
|
String fileName = "货物入库质押表" + sdf.format(new Date()) + ".xlsx"; |
|
|
|
String savePath = filePath + File.separator + fileName; |
|
|
|
//下载
|
|
|
|
OutputStream fileOut = new FileOutputStream(savePath); |
|
|
|
wb.write(fileOut); |
|
|
|
fileOut.close(); |
|
|
|
} |
|
|
|
|
|
|
|
public PagerVo<InStockVo> listPage(PagerQuery<InStockQuery> pq){ |
|
|
|
InStockQuery params = pq.getParams(); |
|
|
|
QueryWrapper<InStock> wq = new QueryWrapper<>(); |
|
|
|