Browse Source

优化导出、添加入库监控数据7-26

master
fkf 2 years ago
parent
commit
91a83425c1
  1. 1
      yxt-supervise-gf-api/src/main/java/com/yxt/supervise/gf/api/outstock/OutStock.java
  2. 59
      yxt-supervise-gf-api/src/main/java/com/yxt/supervise/gf/api/pushoutstockdata/PushOutStockData.java
  3. 555
      yxt-supervise-gf-biz/src/main/java/com/yxt/supervise/gf/biz/instock/InStockService.java
  4. 389
      yxt-supervise-gf-biz/src/main/java/com/yxt/supervise/gf/biz/outstock/OutStockService.java
  5. 13
      yxt-supervise-gf-biz/src/main/java/com/yxt/supervise/gf/biz/pushoutstockdata/PushOutStockDataMapper.java
  6. 17
      yxt-supervise-gf-biz/src/main/java/com/yxt/supervise/gf/biz/pushoutstockdata/PushOutStockDataRest.java
  7. 17
      yxt-supervise-gf-biz/src/main/java/com/yxt/supervise/gf/biz/pushoutstockdata/PushOutStockDataService.java
  8. 7
      yxt-supervise-gf-biz/src/main/java/com/yxt/supervise/gf/shanhai/ShRequester.java

1
yxt-supervise-gf-api/src/main/java/com/yxt/supervise/gf/api/outstock/OutStock.java

@ -55,4 +55,5 @@ public class OutStock {
private String source_name;
@ApiModelProperty("来源类型")
private String source_type;
private String time;
}

59
yxt-supervise-gf-api/src/main/java/com/yxt/supervise/gf/api/pushoutstockdata/PushOutStockData.java

@ -0,0 +1,59 @@
package com.yxt.supervise.gf.api.pushoutstockdata;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @author feikefei
* @create 2023-07-11-16:03
*/
@Data
@ApiModel(value = "监管出库数据表(推送出库数据表)")
@TableName("push_out_stock_data")
public class PushOutStockData {
@ApiModelProperty("id")
private Integer id;
@ApiModelProperty("物料名称")
private String materiel_name;
@ApiModelProperty("品牌")
private String brand_name;
@ApiModelProperty("物料编号")
private String materiel_no;
@ApiModelProperty("批次号")
private String batch_number;
@ApiModelProperty("物料组")
private String materiel_group_text;
@ApiModelProperty("本次操作数量")
private String num;
@ApiModelProperty("单价")
private Double price;
@ApiModelProperty("批次总金额")
private Double actual_price;
@ApiModelProperty("物料单位")
private String unit;
@ApiModelProperty("经办人")
private String admin_name;
@ApiModelProperty("仓库名称")
private String storehouse_name;
@ApiModelProperty("申请时间")
private String happen_time;
@ApiModelProperty("类型")
private String type;
@ApiModelProperty("类型明文")
private String type_text;
@ApiModelProperty("审核状态")
private String status;
@ApiModelProperty("原数量")
private Integer orig_num;
@ApiModelProperty("更新后的数量")
private Integer new_num;
@ApiModelProperty("创建时间")
private String create_time;
@ApiModelProperty("来源名称")
private String source_name;
@ApiModelProperty("来源类型")
private String source_type;
private String time;
}

555
yxt-supervise-gf-biz/src/main/java/com/yxt/supervise/gf/biz/instock/InStockService.java

@ -13,6 +13,7 @@ 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.pushinstockdata.PushInStockData;
import com.yxt.supervise.gf.biz.outstock.OutStockService;
import com.yxt.supervise.gf.biz.pushinstockdata.PushInStockDataService;
import com.yxt.supervise.gf.shanhai.ShRequester;
import com.yxt.supervise.gf.shanhai.req.In_stockGetRecordMaterielList;
@ -45,6 +46,8 @@ public class InStockService extends ServiceImpl<InStockMapper, InStock> {
private String filePath;
@Autowired
private PushInStockDataService pushInStockDataService;
@Autowired
private OutStockService outStockService;
public ResultBean save(In_stockGetRecordMaterielList reqParams){
ResultBean rb = ResultBean.fireFail();
@ -60,16 +63,16 @@ public class InStockService extends ServiceImpl<InStockMapper, 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<>();
Map<String, List<Object>> 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;
List<Object> 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);
for (InStockGetRecordMaterielList inStockGetRecordMaterielList : filterValue) {
for (Object inStockGetRecordMaterielList : filterValue) {
PushInStockData pushInStockData = new PushInStockData();
BeanUtil.copyProperties(inStockGetRecordMaterielList,pushInStockData,"id");
pushInStockData.setTime(DateUtil.format(new Date(), "yyyy-MM-dd"));
@ -79,285 +82,285 @@ public class InStockService extends ServiceImpl<InStockMapper, InStock> {
}
}
try {
exportExcel(map);
outStockService.exportExcel(map,0);
}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<>();//存储汇总数据
map1.forEach((k,v) -> {
HashMap<String, Object> mapCount = new HashMap<>();
Integer sumCount = v.stream().mapToInt(it -> Integer.parseInt(it.getNum())).sum();
Double priceCount = v.stream().mapToDouble(it -> Integer.parseInt(it.getNum()) * Double.parseDouble(it.getPrice())).sum();
mapCount.put("name",k);
mapCount.put("sumCount",sumCount);
mapCount.put("priceCount",priceCount);
listMap1.add(mapCount);
});
//汇总工作簿
String[] collectHead = {"序号","仓库名称","物料数量","核算的价值"};
Sheet stuSheet1 = wb.createSheet("货物入库质押汇总表");
Row headRow1 = stuSheet1.createRow(0); //第一行为头
Font head11 = wb.createFont();
head11.setFontHeightInPoints((short) 25);
CellStyle cellStylehz = wb.createCellStyle();
cellStylehz.setFont(head11);
cellStylehz.setAlignment(HorizontalAlignment.CENTER); //设置水平对齐方式
cellStylehz.setVerticalAlignment(VerticalAlignment.CENTER); //设置垂直对齐方式
CellRangeAddress callRangeAddress22 = new CellRangeAddress(0,0,0,collectHead.length-1);
CellRangeAddress callRangeAddress1g = new CellRangeAddress(1,1,0,collectHead.length-1);
CellRangeAddress callRangeAddress2 = new CellRangeAddress(2,2,0,collectHead.length-1);
Cell cell15 = headRow1.createCell(0);
cell15.setCellStyle(cellStylehz);
cell15.setCellValue("货物入库质押汇总表");
stuSheet1.addMergedRegion(callRangeAddress22);
Row headRowOnehz = stuSheet1.createRow(1);
Cell headCellhz = headRowOnehz.createCell(0);
headCellhz.setCellValue("编号:");
stuSheet1.addMergedRegion(callRangeAddress1g);
Row headRowTwohz = stuSheet1.createRow(2);
Cell headCellTwohz = headRowTwohz.createCell(0);
headCellTwohz.setCellValue("上报日期:" + sdf1.format(date));
stuSheet1.addMergedRegion(callRangeAddress2);
//获取表头行
Row titleRowhz = stuSheet1.createRow(3);
CellStyle stylehz = wb.createCellStyle();
Font font = wb.createFont();
font.setFontHeightInPoints((short) 16);
stylehz.setVerticalAlignment(VerticalAlignment.CENTER);
stylehz.setAlignment(HorizontalAlignment.CENTER);
stylehz.setBorderBottom(BorderStyle.THIN); //下边框
stylehz.setBorderLeft(BorderStyle.THIN);//左边框
stylehz.setBorderTop(BorderStyle.THIN);//上边框
stylehz.setBorderRight(BorderStyle.THIN);//右边框
stylehz.setShrinkToFit(true); //自动伸缩
stylehz.setFont(font);
Cell cellhz = null;
//把已经写好的标题行写入excel文件中
for (int i = 0; i < collectHead.length; i++) {
cellhz = titleRowhz.createCell(i);
cellhz.setCellValue(collectHead[i]);
cellhz.setCellStyle(stylehz);
}
//把从数据库中取得的数据一一写入excel文件中
Row rowh = null;
Cell cell2h = null;
CellStyle dataStyle1 = wb.createCellStyle();
dataStyle1.setBorderBottom(BorderStyle.THIN); //下边框
dataStyle1.setBorderLeft(BorderStyle.THIN);//左边框
dataStyle1.setBorderTop(BorderStyle.THIN);//上边框
dataStyle1.setBorderRight(BorderStyle.THIN);//右边框
dataStyle1.setVerticalAlignment(VerticalAlignment.CENTER); //设置垂直对齐方式
dataStyle1.setAlignment(HorizontalAlignment.CENTER); //设置水平对齐方式
Integer numSum = 0;
Double countSum = 0.0;
for (int i = 0; i < listMap1.size(); i++) {
//创建list.size()行数据
rowh = stuSheet1.createRow(i + 4);
//把值一一写进单元格里
//设置第一列为自动递增的序号
cell2h = rowh.createCell(0);
cell2h.setCellValue(i + 1);
cell2h.setCellStyle(dataStyle1);
cell2h = rowh.createCell(1);
cell2h.setCellValue(listMap1.get(i).get("name").toString());
cell2h.setCellStyle(dataStyle1);
cell2h = rowh.createCell(2);
cell2h.setCellValue(listMap1.get(i).get("sumCount").toString());
numSum+=Integer.parseInt(listMap1.get(i).get("sumCount").toString());
cell2h.setCellStyle(dataStyle1);
cell2h = rowh.createCell(3);
DecimalFormat df = new DecimalFormat("#0.00");
cell2h.setCellValue(df.format(listMap1.get(i).get("priceCount")));
countSum+=Double.parseDouble(df.format(listMap1.get(i).get("priceCount")));
cell2h.setCellStyle(dataStyle1);
}
font.setFontHeightInPoints((short) 14);
Row row1h = stuSheet1.createRow(listMap1.size()+4);
CellStyle style111 = wb.createCellStyle();
style111.setVerticalAlignment(VerticalAlignment.CENTER); //设置垂直对齐方式
style111.setAlignment(HorizontalAlignment.CENTER);
style111.setBorderBottom(BorderStyle.THIN); //下边框
style111.setBorderLeft(BorderStyle.THIN);//左边框
style111.setBorderTop(BorderStyle.THIN);//上边框
style111.setBorderRight(BorderStyle.THIN);//右边框
style111.setFont(font);
Cell cell11 = row1h.createCell(0);
cell11.setCellStyle(style111);
cell11.setCellValue("合计");
cell11 = row1h.createCell(1);
cell11.setCellStyle(style111);
cell11 = row1h.createCell(2);
cell11.setCellStyle(style111);
cell11.setCellValue(numSum);
cell11 = row1h.createCell(3);
cell11.setCellStyle(style111);
cell11.setCellValue(countSum);
//设置单元格宽度自适应,在此基础上把宽度调至1.5倍
for (int i = 0; i < collectHead.length; i++) {
stuSheet1.autoSizeColumn(i, true);
stuSheet1.setColumnWidth(i, stuSheet1.getColumnWidth(i) * 15 / 10);
}
for (Map.Entry<String, List<InStockGetRecordMaterielList>> stringListEntry : map1.entrySet()) {
//标题行抽出字段
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 fontq = wb.createFont();
fontq.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(fontq);
Cell cell11a = row1.createCell(0);
cell11a.setCellStyle(style11);
cell11a.setCellValue("合计");
cell11a = row1.createCell(3);
cell11a.setCellStyle(style11);
cell11a.setCellValue(numCount);
cell11a = row1.createCell(6);
cell11a.setCellStyle(style11);
cell11a.setCellValue(count);
cell11a = row1.createCell(1);
cell11a.setCellStyle(style11);
cell11a = row1.createCell(2);
cell11a.setCellStyle(style11);
cell11a = row1.createCell(4);
cell11a.setCellStyle(style11);
cell11a = row1.createCell(5);
cell11a.setCellStyle(style11);
cell11a = row1.createCell(7);
cell11a.setCellStyle(style11);
cell11a = row1.createCell(8);
cell11a.setCellStyle(style11);
//设置单元格宽度自适应,在此基础上把宽度调至1.5倍
for (int i = 0; i < head.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 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<>();//存储汇总数据
// map1.forEach((k,v) -> {
// HashMap<String, Object> mapCount = new HashMap<>();
// Integer sumCount = v.stream().mapToInt(it -> Integer.parseInt(it.getNum())).sum();
// Double priceCount = v.stream().mapToDouble(it -> Integer.parseInt(it.getNum()) * Double.parseDouble(it.getPrice())).sum();
// mapCount.put("name",k);
// mapCount.put("sumCount",sumCount);
// mapCount.put("priceCount",priceCount);
// listMap1.add(mapCount);
// });
// //汇总工作簿
// String[] collectHead = {"序号","仓库名称","物料数量","核算的价值"};
// Sheet stuSheet1 = wb.createSheet("货物入库质押汇总表");
// Row headRow1 = stuSheet1.createRow(0); //第一行为头
// Font head11 = wb.createFont();
// head11.setFontHeightInPoints((short) 25);
// CellStyle cellStylehz = wb.createCellStyle();
// cellStylehz.setFont(head11);
// cellStylehz.setAlignment(HorizontalAlignment.CENTER); //设置水平对齐方式
// cellStylehz.setVerticalAlignment(VerticalAlignment.CENTER); //设置垂直对齐方式
// CellRangeAddress callRangeAddress22 = new CellRangeAddress(0,0,0,collectHead.length-1);
// CellRangeAddress callRangeAddress1g = new CellRangeAddress(1,1,0,collectHead.length-1);
// CellRangeAddress callRangeAddress2 = new CellRangeAddress(2,2,0,collectHead.length-1);
// Cell cell15 = headRow1.createCell(0);
// cell15.setCellStyle(cellStylehz);
// cell15.setCellValue("货物入库质押汇总表");
// stuSheet1.addMergedRegion(callRangeAddress22);
//
// Row headRowOnehz = stuSheet1.createRow(1);
// Cell headCellhz = headRowOnehz.createCell(0);
// headCellhz.setCellValue("编号:");
// stuSheet1.addMergedRegion(callRangeAddress1g);
// Row headRowTwohz = stuSheet1.createRow(2);
// Cell headCellTwohz = headRowTwohz.createCell(0);
// headCellTwohz.setCellValue("上报日期:" + sdf1.format(date));
// stuSheet1.addMergedRegion(callRangeAddress2);
//
// //获取表头行
// Row titleRowhz = stuSheet1.createRow(3);
// CellStyle stylehz = wb.createCellStyle();
// Font font = wb.createFont();
// font.setFontHeightInPoints((short) 16);
// stylehz.setVerticalAlignment(VerticalAlignment.CENTER);
// stylehz.setAlignment(HorizontalAlignment.CENTER);
// stylehz.setBorderBottom(BorderStyle.THIN); //下边框
// stylehz.setBorderLeft(BorderStyle.THIN);//左边框
// stylehz.setBorderTop(BorderStyle.THIN);//上边框
// stylehz.setBorderRight(BorderStyle.THIN);//右边框
// stylehz.setShrinkToFit(true); //自动伸缩
// stylehz.setFont(font);
// Cell cellhz = null;
// //把已经写好的标题行写入excel文件中
// for (int i = 0; i < collectHead.length; i++) {
// cellhz = titleRowhz.createCell(i);
// cellhz.setCellValue(collectHead[i]);
// cellhz.setCellStyle(stylehz);
// }
// //把从数据库中取得的数据一一写入excel文件中
// Row rowh = null;
// Cell cell2h = null;
// CellStyle dataStyle1 = wb.createCellStyle();
// dataStyle1.setBorderBottom(BorderStyle.THIN); //下边框
// dataStyle1.setBorderLeft(BorderStyle.THIN);//左边框
// dataStyle1.setBorderTop(BorderStyle.THIN);//上边框
// dataStyle1.setBorderRight(BorderStyle.THIN);//右边框
// dataStyle1.setVerticalAlignment(VerticalAlignment.CENTER); //设置垂直对齐方式
// dataStyle1.setAlignment(HorizontalAlignment.CENTER); //设置水平对齐方式
// Integer numSum = 0;
// Double countSum = 0.0;
// for (int i = 0; i < listMap1.size(); i++) {
// //创建list.size()行数据
// rowh = stuSheet1.createRow(i + 4);
// //把值一一写进单元格里
// //设置第一列为自动递增的序号
// cell2h = rowh.createCell(0);
// cell2h.setCellValue(i + 1);
// cell2h.setCellStyle(dataStyle1);
// cell2h = rowh.createCell(1);
// cell2h.setCellValue(listMap1.get(i).get("name").toString());
// cell2h.setCellStyle(dataStyle1);
// cell2h = rowh.createCell(2);
// cell2h.setCellValue(listMap1.get(i).get("sumCount").toString());
// numSum+=Integer.parseInt(listMap1.get(i).get("sumCount").toString());
// cell2h.setCellStyle(dataStyle1);
// cell2h = rowh.createCell(3);
// DecimalFormat df = new DecimalFormat("#0.00");
// cell2h.setCellValue(df.format(listMap1.get(i).get("priceCount")));
// countSum+=Double.parseDouble(df.format(listMap1.get(i).get("priceCount")));
// cell2h.setCellStyle(dataStyle1);
// }
// font.setFontHeightInPoints((short) 14);
// Row row1h = stuSheet1.createRow(listMap1.size()+4);
// CellStyle style111 = wb.createCellStyle();
// style111.setVerticalAlignment(VerticalAlignment.CENTER); //设置垂直对齐方式
// style111.setAlignment(HorizontalAlignment.CENTER);
// style111.setBorderBottom(BorderStyle.THIN); //下边框
// style111.setBorderLeft(BorderStyle.THIN);//左边框
// style111.setBorderTop(BorderStyle.THIN);//上边框
// style111.setBorderRight(BorderStyle.THIN);//右边框
// style111.setFont(font);
// Cell cell11 = row1h.createCell(0);
// cell11.setCellStyle(style111);
// cell11.setCellValue("合计");
// cell11 = row1h.createCell(1);
// cell11.setCellStyle(style111);
// cell11 = row1h.createCell(2);
// cell11.setCellStyle(style111);
// cell11.setCellValue(numSum);
// cell11 = row1h.createCell(3);
// cell11.setCellStyle(style111);
// cell11.setCellValue(countSum);
// //设置单元格宽度自适应,在此基础上把宽度调至1.5倍
// for (int i = 0; i < collectHead.length; i++) {
// stuSheet1.autoSizeColumn(i, true);
// stuSheet1.setColumnWidth(i, stuSheet1.getColumnWidth(i) * 15 / 10);
// }
// for (Map.Entry<String, List<InStockGetRecordMaterielList>> stringListEntry : map1.entrySet()) {
// //标题行抽出字段
// 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 fontq = wb.createFont();
// fontq.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(fontq);
// Cell cell11a = row1.createCell(0);
// cell11a.setCellStyle(style11);
// cell11a.setCellValue("合计");
// cell11a = row1.createCell(3);
// cell11a.setCellStyle(style11);
// cell11a.setCellValue(numCount);
// cell11a = row1.createCell(6);
// cell11a.setCellStyle(style11);
// cell11a.setCellValue(count);
// cell11a = row1.createCell(1);
// cell11a.setCellStyle(style11);
// cell11a = row1.createCell(2);
// cell11a.setCellStyle(style11);
// cell11a = row1.createCell(4);
// cell11a.setCellStyle(style11);
// cell11a = row1.createCell(5);
// cell11a.setCellStyle(style11);
// cell11a = row1.createCell(7);
// cell11a.setCellStyle(style11);
// cell11a = row1.createCell(8);
// cell11a.setCellStyle(style11);
// //设置单元格宽度自适应,在此基础上把宽度调至1.5倍
// for (int i = 0; i < head.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();

389
yxt-supervise-gf-biz/src/main/java/com/yxt/supervise/gf/biz/outstock/OutStockService.java

@ -1,9 +1,11 @@
package com.yxt.supervise.gf.biz.outstock;
import cn.hutool.core.bean.BeanUtil;
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;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yxt.common.base.utils.PagerUtil;
import com.yxt.common.core.query.PagerQuery;
import com.yxt.common.core.result.ResultBean;
@ -11,14 +13,26 @@ import com.yxt.common.core.vo.PagerVo;
import com.yxt.supervise.gf.api.outstock.OutStock;
import com.yxt.supervise.gf.api.outstock.OutStockQuery;
import com.yxt.supervise.gf.api.outstock.OutStockVo;
import com.yxt.supervise.gf.api.pushoutstockdata.PushOutStockData;
import com.yxt.supervise.gf.biz.pushoutstockdata.PushOutStockDataService;
import com.yxt.supervise.gf.shanhai.ShRequester;
import com.yxt.supervise.gf.shanhai.req.Out_stockGetRecordMaterielList;
import com.yxt.supervise.gf.shanhai.resp.BaseResponse;
import com.yxt.supervise.gf.shanhai.resp.BaseResponseListObj;
import com.yxt.supervise.gf.shanhai.resp.*;
import com.yxt.supervise.gf.shanhai.resp.RecordMaterielList;
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.Autowired;
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
@ -27,18 +41,387 @@ import java.util.List;
@Service
public class OutStockService extends ServiceImpl<OutStockMapper, OutStock> {
@Value("${import.filePath}")
private String filePath;
@Autowired
private PushOutStockDataService pushOutStockDataService;
public ResultBean save(Out_stockGetRecordMaterielList reqParams){
ResultBean rb = ResultBean.fireFail();
String date = DateUtil.format(new Date(), "yyyy-MM-dd");
String currDay = DateUtil.format(DateUtil.offsetDay(new Date(), -1), "yyyy-MM-dd");
reqParams.setStart_happen_time(currDay);
reqParams.setEnd_happen_time(currDay);
BaseResponse<BaseResponseListObj<RecordMaterielList>> api$system$out_stock$get_record_materiel_list = ShRequester.getApi$system$out_stock$get_record_materiel_list(reqParams);
List<RecordMaterielList> list = api$system$out_stock$get_record_materiel_list.getData().getList();
for (RecordMaterielList recordMaterielList : list) {
OutStock outStock = new OutStock();
BeanUtil.copyProperties(recordMaterielList,outStock);
outStock.setTime(date);
baseMapper.insert(outStock);
}
Map<String, List<RecordMaterielList>> listMap = list.stream().collect(Collectors.groupingBy(it -> it.getStorehouse_name()));
Map<String, List<Object>> map = new HashMap<>();
for (Map.Entry<String, List<RecordMaterielList>> stringListEntry : listMap.entrySet()) {
String key = stringListEntry.getKey();
if (key.equals("江西余干库") || key.equals("庄河荣名库") || key.equals("安阳荣名库") || key.equals("藁城荣名库") || key.equals("曲阜荣名库")) {
List<RecordMaterielList> value = stringListEntry.getValue();
List<Object> 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);
for (Object recordMaterielList : filterValue) {
PushOutStockData pushOutStockData = new PushOutStockData();
BeanUtil.copyProperties(recordMaterielList,pushOutStockData,"id");
pushOutStockData.setTime(DateUtil.format(new Date(), "yyyy-MM-dd"));
pushOutStockDataService.saveOutStockData(pushOutStockData);
}
}
}
}
try {
exportExcel(map,1);
}catch (Exception e){
e.printStackTrace();
}
return rb.success().setMsg("添加成功");
}
/**
* @Description //描述: 出入库记录导出
* @Param [map1, state] state 0出库 1入库
* @return void
**/
public void exportExcel(Map<String, List<Object>> map1,int state) 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<>();//存储汇总数据
Map<String, List<RecordMaterielList>> listHashMap = new HashMap<>();
Map<String, List<InStockGetRecordMaterielList>> listMap = new HashMap<>();
for (Map.Entry<String, List<Object>> stringListEntry : map1.entrySet()) {
List<Object> value = stringListEntry.getValue();
List<RecordMaterielList> recordMaterielLists = new ArrayList<>();
List<InStockGetRecordMaterielList> inStockGetRecordMaterielLists = new ArrayList<>();
for (Object o : value) {
if (state == 0){
InStockGetRecordMaterielList inStockGetRecordMaterielList = new ObjectMapper().convertValue(o, InStockGetRecordMaterielList.class);
inStockGetRecordMaterielLists.add(inStockGetRecordMaterielList);
}else if(state == 1) {
RecordMaterielList recordMaterielList = new ObjectMapper().convertValue(o, RecordMaterielList.class);
recordMaterielLists.add(recordMaterielList);
}
}
listMap.put(stringListEntry.getKey(),inStockGetRecordMaterielLists);
listHashMap.put(stringListEntry.getKey(),recordMaterielLists);
}
if (state == 0){
listMap.forEach((k,v) -> {
HashMap<String, Object> mapCount = new HashMap<>();
Integer sumCount = v.stream().mapToInt(it -> Integer.parseInt(it.getNum())).sum();
Double priceCount = v.stream().mapToDouble(it -> Integer.parseInt(it.getNum()) * Double.parseDouble(it.getPrice())).sum();
mapCount.put("name",k);
mapCount.put("sumCount",sumCount);
mapCount.put("priceCount",priceCount);
listMap1.add(mapCount);
});
}else if(state == 1) {
listHashMap.forEach((k,v) -> {
HashMap<String, Object> mapCount = new HashMap<>();
Integer sumCount = v.stream().mapToInt(it -> Integer.parseInt(it.getNum())).sum();
Double priceCount = v.stream().mapToDouble(it -> Integer.parseInt(it.getNum()) * Double.parseDouble(it.getPrice())).sum();
mapCount.put("name",k);
mapCount.put("sumCount",sumCount);
mapCount.put("priceCount",priceCount);
listMap1.add(mapCount);
});
}
//汇总工作簿
Sheet stuSheet1 = null;
if (state == 0){
stuSheet1 = wb.createSheet("货物入库质押汇总表");
}else if(state == 1) {
stuSheet1 = wb.createSheet("货物出库质押汇总表");
}
String[] collectHead = {"序号","仓库名称","物料数量","核算的价值"};
Row headRow1 = stuSheet1.createRow(0); //第一行为头
Font head11 = wb.createFont();
head11.setFontHeightInPoints((short) 25);
CellStyle cellStylehz = wb.createCellStyle();
cellStylehz.setFont(head11);
cellStylehz.setAlignment(HorizontalAlignment.CENTER); //设置水平对齐方式
cellStylehz.setVerticalAlignment(VerticalAlignment.CENTER); //设置垂直对齐方式
CellRangeAddress callRangeAddress22 = new CellRangeAddress(0,0,0,collectHead.length-1);
CellRangeAddress callRangeAddress1g = new CellRangeAddress(1,1,0,collectHead.length-1);
CellRangeAddress callRangeAddress2 = new CellRangeAddress(2,2,0,collectHead.length-1);
Cell cell15 = headRow1.createCell(0);
cell15.setCellStyle(cellStylehz);
if (state == 0){
cell15.setCellValue("货物入库质押汇总表");
}else {
cell15.setCellValue("质物解除质押出库汇总表");
}
stuSheet1.addMergedRegion(callRangeAddress22);
Row headRowOnehz = stuSheet1.createRow(1);
Cell headCellhz = headRowOnehz.createCell(0);
headCellhz.setCellValue("编号:");
stuSheet1.addMergedRegion(callRangeAddress1g);
Row headRowTwohz = stuSheet1.createRow(2);
Cell headCellTwohz = headRowTwohz.createCell(0);
headCellTwohz.setCellValue("上报日期:" + sdf1.format(date));
stuSheet1.addMergedRegion(callRangeAddress2);
//获取表头行
Row titleRowhz = stuSheet1.createRow(3);
CellStyle stylehz = wb.createCellStyle();
Font font = wb.createFont();
font.setFontHeightInPoints((short) 16);
stylehz.setVerticalAlignment(VerticalAlignment.CENTER);
stylehz.setAlignment(HorizontalAlignment.CENTER);
stylehz.setBorderBottom(BorderStyle.THIN); //下边框
stylehz.setBorderLeft(BorderStyle.THIN);//左边框
stylehz.setBorderTop(BorderStyle.THIN);//上边框
stylehz.setBorderRight(BorderStyle.THIN);//右边框
stylehz.setShrinkToFit(true); //自动伸缩
stylehz.setFont(font);
Cell cellhz = null;
//把已经写好的标题行写入excel文件中
for (int i = 0; i < collectHead.length; i++) {
cellhz = titleRowhz.createCell(i);
cellhz.setCellValue(collectHead[i]);
cellhz.setCellStyle(stylehz);
}
//把从数据库中取得的数据一一写入excel文件中
Row rowh = null;
Cell cell2h = null;
CellStyle dataStyle1 = wb.createCellStyle();
dataStyle1.setBorderBottom(BorderStyle.THIN); //下边框
dataStyle1.setBorderLeft(BorderStyle.THIN);//左边框
dataStyle1.setBorderTop(BorderStyle.THIN);//上边框
dataStyle1.setBorderRight(BorderStyle.THIN);//右边框
dataStyle1.setVerticalAlignment(VerticalAlignment.CENTER); //设置垂直对齐方式
dataStyle1.setAlignment(HorizontalAlignment.CENTER); //设置水平对齐方式
Integer numSum = 0;
Double countSum = 0.0;
for (int i = 0; i < listMap1.size(); i++) {
//创建list.size()行数据
rowh = stuSheet1.createRow(i + 4);
//把值一一写进单元格里
//设置第一列为自动递增的序号
cell2h = rowh.createCell(0);
cell2h.setCellValue(i + 1);
cell2h.setCellStyle(dataStyle1);
cell2h = rowh.createCell(1);
cell2h.setCellValue(listMap1.get(i).get("name").toString());
cell2h.setCellStyle(dataStyle1);
cell2h = rowh.createCell(2);
cell2h.setCellValue(listMap1.get(i).get("sumCount").toString());
numSum+=Integer.parseInt(listMap1.get(i).get("sumCount").toString());
cell2h.setCellStyle(dataStyle1);
cell2h = rowh.createCell(3);
DecimalFormat df = new DecimalFormat("#0.00");
cell2h.setCellValue(df.format(listMap1.get(i).get("priceCount")));
countSum+=Double.parseDouble(df.format(listMap1.get(i).get("priceCount")));
cell2h.setCellStyle(dataStyle1);
}
font.setFontHeightInPoints((short) 14);
Row row1h = stuSheet1.createRow(listMap1.size()+4);
CellStyle style111 = wb.createCellStyle();
style111.setVerticalAlignment(VerticalAlignment.CENTER); //设置垂直对齐方式
style111.setAlignment(HorizontalAlignment.CENTER);
style111.setBorderBottom(BorderStyle.THIN); //下边框
style111.setBorderLeft(BorderStyle.THIN);//左边框
style111.setBorderTop(BorderStyle.THIN);//上边框
style111.setBorderRight(BorderStyle.THIN);//右边框
style111.setFont(font);
Cell cell11 = row1h.createCell(0);
cell11.setCellStyle(style111);
cell11.setCellValue("合计");
cell11 = row1h.createCell(1);
cell11.setCellStyle(style111);
cell11 = row1h.createCell(2);
cell11.setCellStyle(style111);
cell11.setCellValue(numSum);
cell11 = row1h.createCell(3);
cell11.setCellStyle(style111);
cell11.setCellValue(countSum);
//设置单元格宽度自适应,在此基础上把宽度调至1.5倍
for (int i = 0; i < collectHead.length; i++) {
stuSheet1.autoSizeColumn(i, true);
stuSheet1.setColumnWidth(i, stuSheet1.getColumnWidth(i) * 15 / 10);
}
for (Map.Entry<String, List<Object>> stringListEntry : map1.entrySet()) {
//标题行抽出字段
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);
if (state == 0){
cell1.setCellValue("货物入库质押表");
}else {
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++) {
RecordMaterielList recordMaterielList = null;
InStockGetRecordMaterielList inStockGetRecordMaterielList = null;
if (state == 0){
}else {
recordMaterielList = new ObjectMapper().convertValue(stringListEntry.getValue().get(i), RecordMaterielList.class);
}
//创建list.size()行数据
row = stuSheet.createRow(i + 4);
//把值一一写进单元格里
//设置第一列为自动递增的序号
cell2 = row.createCell(0);
cell2.setCellValue(recordMaterielList == null ? inStockGetRecordMaterielList.getMateriel_group_text() : recordMaterielList.getMateriel_group_text());
cell2.setCellStyle(dataStyle);
cell2 = row.createCell(1);
cell2.setCellValue(recordMaterielList == null ? inStockGetRecordMaterielList.getMateriel_name() : recordMaterielList.getMateriel_name());
numCount+=Integer.parseInt(recordMaterielList == null ? inStockGetRecordMaterielList.getNum() : recordMaterielList.getNum());
cell2.setCellStyle(dataStyle);
cell2 = row.createCell(2);
cell2.setCellValue(recordMaterielList == null ? inStockGetRecordMaterielList.getSource_name() : recordMaterielList.getSource_name());
cell2.setCellStyle(dataStyle);
cell2 = row.createCell(3);
cell2.setCellValue(recordMaterielList == null ? inStockGetRecordMaterielList.getNum() : recordMaterielList.getNum());
cell2.setCellStyle(dataStyle);
cell2 = row.createCell(4);
cell2.setCellValue("");
cell2.setCellStyle(dataStyle);
cell2 = row.createCell(5);
cell2.setCellValue(recordMaterielList == null ? inStockGetRecordMaterielList.getPrice() : recordMaterielList.getPrice());
cell2.setCellStyle(dataStyle);
cell2 = row.createCell(6);
Double price = Double.parseDouble(recordMaterielList == null ? inStockGetRecordMaterielList.getPrice() : recordMaterielList.getPrice()) * Integer.parseInt(recordMaterielList == null ? inStockGetRecordMaterielList.getNum() : recordMaterielList.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 fontq = wb.createFont();
fontq.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(fontq);
Cell cell11a = row1.createCell(0);
cell11a.setCellStyle(style11);
cell11a.setCellValue("合计");
cell11a = row1.createCell(3);
cell11a.setCellStyle(style11);
cell11a.setCellValue(numCount);
cell11a = row1.createCell(6);
cell11a.setCellStyle(style11);
cell11a.setCellValue(count);
cell11a = row1.createCell(1);
cell11a.setCellStyle(style11);
cell11a = row1.createCell(2);
cell11a.setCellStyle(style11);
cell11a = row1.createCell(4);
cell11a.setCellStyle(style11);
cell11a = row1.createCell(5);
cell11a.setCellStyle(style11);
cell11a = row1.createCell(7);
cell11a.setCellStyle(style11);
cell11a = row1.createCell(8);
cell11a.setCellStyle(style11);
//设置单元格宽度自适应,在此基础上把宽度调至1.5倍
for (int i = 0; i < head.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 = null;
if (state == 0) {
fileName = "货物入库质押表" + sdf.format(new Date()) + ".xlsx";
}else {
fileName = "质物解除质押出库表" + sdf.format(new Date()) + ".xlsx";
}
String savePath = filePath + File.separator + fileName;
//下载
OutputStream fileOut = new FileOutputStream(savePath);
wb.write(fileOut);
fileOut.close();
}
public PagerVo<OutStockVo> listPage(PagerQuery<OutStockQuery> pq){
OutStockQuery params = pq.getParams();
QueryWrapper<OutStock> wq = new QueryWrapper<>();

13
yxt-supervise-gf-biz/src/main/java/com/yxt/supervise/gf/biz/pushoutstockdata/PushOutStockDataMapper.java

@ -0,0 +1,13 @@
package com.yxt.supervise.gf.biz.pushoutstockdata;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yxt.supervise.gf.api.pushoutstockdata.PushOutStockData;
import org.apache.ibatis.annotations.Mapper;
/**
* @author feikefei
* @create 2023-07-25-17:12
*/
@Mapper
public interface PushOutStockDataMapper extends BaseMapper<PushOutStockData> {
}

17
yxt-supervise-gf-biz/src/main/java/com/yxt/supervise/gf/biz/pushoutstockdata/PushOutStockDataRest.java

@ -0,0 +1,17 @@
package com.yxt.supervise.gf.biz.pushoutstockdata;
/**
* @author feikefei
* @create 2023-07-25-17:11
*/
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@Api(value = "货物出库监管数据明细表(推送数据)")
@RestController
@RequestMapping("gf/pushInStockData")
public class PushOutStockDataRest {
}

17
yxt-supervise-gf-biz/src/main/java/com/yxt/supervise/gf/biz/pushoutstockdata/PushOutStockDataService.java

@ -0,0 +1,17 @@
package com.yxt.supervise.gf.biz.pushoutstockdata;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yxt.supervise.gf.api.pushoutstockdata.PushOutStockData;
import org.springframework.stereotype.Service;
/**
* @author feikefei
* @create 2023-07-25-17:12
*/
@Service
public class PushOutStockDataService extends ServiceImpl<PushOutStockDataMapper, PushOutStockData> {
public void saveOutStockData(PushOutStockData data){
baseMapper.insert(data);
}
}

7
yxt-supervise-gf-biz/src/main/java/com/yxt/supervise/gf/shanhai/ShRequester.java

@ -262,9 +262,12 @@ public class ShRequester {
public static BaseResponse<BaseResponseListObj<RecordMaterielList>> getApi$system$out_stock$get_record_materiel_list(Out_stockGetRecordMaterielList reqParams){
BaseResponse<BaseResponseListObj<RecordMaterielList>> req = new BaseResponse<>();
BaseResponseListObj<RecordMaterielList> reqObj = new BaseResponseListObj<>();
Map<String, Object> param = null;
if (reqParams != null)
Map<String, Object> param = new HashMap<>();
if (reqParams != null){
param = BeanUtil.beanToMap(reqParams);
}
param.put("page",1);
param.put("limit",2000);
String s = ShHttp.doGet(out_stock$get_record_materiel_list, param);
BaseResponse<BaseResponseListObj<JSONObject>> baseResponse = toBean(s, req, reqObj);
BeanUtil.copyProperties(baseResponse,req);

Loading…
Cancel
Save