新增excel表

product
杨世强 1 year ago
parent be1ee73ef7
commit 8080c40d15

@ -25,6 +25,7 @@ import java.util.List;
public interface PurchaseorderitemMapper extends BaseMapper<PurchaseorderitemEntity> { public interface PurchaseorderitemMapper extends BaseMapper<PurchaseorderitemEntity> {
// List<PurchaseOrderVO> getPurchorderItemMap(@Param("ew")Wrapper<PurchaseorderitemEntity> queryWrapper); // List<PurchaseOrderVO> getPurchorderItemMap(@Param("ew")Wrapper<PurchaseorderitemEntity> queryWrapper);
List<HashMap<String,Object>> getPdfInfo(@Param("ew")Wrapper<PurchaseorderitemEntity> queryWrapper); List<HashMap<String,Object>> getPdfInfo(@Param("ew")Wrapper<PurchaseorderitemEntity> queryWrapper);
List<HashMap<String,Object>> getOrderInfo(@Param("ew")Wrapper<PurchaseorderitemEntity> queryWrapper);
List<HashMap<String,Object>> getTitleInfo(@Param("ew")Wrapper<PurchaseorderitemEntity> queryWrapper); List<HashMap<String,Object>> getTitleInfo(@Param("ew")Wrapper<PurchaseorderitemEntity> queryWrapper);
List<HashMap<String,Object>> getWordExcelInfo(@Param("ew")Wrapper<PurchaseorderitemEntity> queryWrapper); List<HashMap<String,Object>> getWordExcelInfo(@Param("ew")Wrapper<PurchaseorderitemEntity> queryWrapper);
List<HashMap<String,Object>> getVehicleInfo(@Param("ew")Wrapper<PurchaseorderitemEntity> queryWrapper); List<HashMap<String,Object>> getVehicleInfo(@Param("ew")Wrapper<PurchaseorderitemEntity> queryWrapper);

@ -444,6 +444,291 @@ public class PurchaseorderitemServiceImpl extends ServiceImpl<PurchaseorderitemM
} }
public void getOrderInfoExcel(List<HashMap<String, Object>> list, String templateFilePath) throws Exception {
//声明要创建的文件名
String filename = templateFilePath + "\\订单信息表.xls";
//创建 HSSFWorkbook 类的实例
HSSFWorkbook workbook = new HSSFWorkbook();
FileOutputStream fileOut = new FileOutputStream(filename);
try {
//调用 creatSheet() 方法并传递要创建的工作表的名称
HSSFSheet sheet = workbook.createSheet("磅单信息");
HSSFCellStyle cellStyle = workbook.createCellStyle();
HSSFCellStyle headLineStyle = workbook.createCellStyle();
HSSFCellStyle headStyle = workbook.createCellStyle();
HSSFCellStyle headTitleStyle = workbook.createCellStyle();
HSSFCellStyle lineStyle = workbook.createCellStyle();
// 水平居中
cellStyle.setAlignment(org.apache.poi.ss.usermodel.HorizontalAlignment.CENTER);
// 垂直居中
cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
cellStyle.setHidden(true);
// 水平居左
headStyle.setAlignment(org.apache.poi.ss.usermodel.HorizontalAlignment.LEFT);
// 垂直居中
headStyle.setVerticalAlignment(VerticalAlignment.CENTER);
headStyle.setHidden(true);
// 水平居中
headLineStyle.setAlignment(org.apache.poi.ss.usermodel.HorizontalAlignment.CENTER);
// 垂直居中
headLineStyle.setVerticalAlignment(VerticalAlignment.CENTER);
// 边框
headLineStyle.setBorderBottom(BorderStyle.THIN);
headLineStyle.setBorderLeft(BorderStyle.THIN);
headLineStyle.setBorderTop(BorderStyle.THIN);
headLineStyle.setBorderRight(BorderStyle.THIN);
// 自动换行
// headLineStyle.setWrapText(true);
headLineStyle.setHidden(true);
// 水平居中
lineStyle.setAlignment(org.apache.poi.ss.usermodel.HorizontalAlignment.CENTER);
// 垂直居中
lineStyle.setVerticalAlignment(VerticalAlignment.CENTER);
// 边框
lineStyle.setBorderBottom(BorderStyle.THIN);
lineStyle.setBorderLeft(BorderStyle.THIN);
lineStyle.setBorderTop(BorderStyle.THIN);
lineStyle.setBorderRight(BorderStyle.THIN);
// 自动换行
// lineStyle.setWrapText(true);
lineStyle.setHidden(true);
HSSFFont font = workbook.createFont();
HSSFFont headFont = workbook.createFont();
HSSFFont tieleFont = workbook.createFont();
HSSFFont lineFont = workbook.createFont();
font.setFontName("宋体");
font.setFontHeightInPoints((short) 18);
font.setBold(true);
cellStyle.setFont(font);
headFont.setFontName("宋体");
headFont.setFontHeightInPoints((short) 11);
headFont.setBold(true);
headLineStyle.setFont(headFont);
tieleFont.setFontName("宋体");
tieleFont.setFontHeightInPoints((short) 11);
tieleFont.setBold(true);
headStyle.setFont(tieleFont);
lineFont.setFontName("宋体");
lineFont.setFontHeightInPoints((short) 12);
lineStyle.setFont(lineFont);
sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 10));
sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 10));
BigDecimal sum = BigDecimal.ZERO;
BigDecimal priceSum = BigDecimal.ZERO;
BigDecimal numSum = BigDecimal.ZERO;
if (list != null && list.size() > 0) {
for (int i = 0; i < list.size(); i++) {
HashMap<String, Object> map = list.get(i);
//创建第二行
HSSFRow row2 = sheet.createRow((short) i + 3 );
row2.setHeight((short) 500);
//在第二行插入数据
HSSFCell lineCell1 = row2.createCell(0);
HSSFCell lineCell2 = row2.createCell(1);
HSSFCell lineCell3 = row2.createCell(2);
HSSFCell lineCell4 = row2.createCell(3);
HSSFCell lineCell5 = row2.createCell(4);
HSSFCell lineCell6 = row2.createCell(5);
HSSFCell lineCell7 = row2.createCell(6);
HSSFCell lineCell8 = row2.createCell(7);
HSSFCell lineCell9 = row2.createCell(8);
HSSFCell lineCell10 = row2.createCell(9);
HSSFCell lineCell11 = row2.createCell(10);
lineCell1.setCellValue(i + 1);
lineCell1.setCellStyle(lineStyle);
lineCell2.setCellValue(String.valueOf(map.get("supplierName")).equals("null") ? "" : String.valueOf(map.get("supplierName")));
lineCell2.setCellStyle(lineStyle);
lineCell3.setCellValue(String.valueOf(map.get("documentNo")).equals("null") ? "" : String.valueOf(map.get("documentNo")));
lineCell3.setCellStyle(lineStyle);
lineCell4.setCellValue(String.valueOf(map.get("itemCode")).equals("null") ? "" : String.valueOf(map.get("itemCode")));
lineCell4.setCellStyle(lineStyle);
lineCell5.setCellValue(String.valueOf(map.get("itemName")).equals("null") ? "" : String.valueOf(map.get("itemName")));
lineCell5.setCellStyle(lineStyle);
lineCell6.setCellValue(String.valueOf(map.get("spec")).equals("null") ? "" : String.valueOf(map.get("spec")));
lineCell6.setCellStyle(lineStyle);
lineCell7.setCellValue(String.valueOf(map.get("settlement")).equals("null") ? "" : String.valueOf(map.get("settlement")));
lineCell7.setCellStyle(lineStyle);
lineCell8.setCellValue(String.valueOf(map.get("unit")).equals("null") ? "" : String.valueOf(map.get("unit")));
lineCell8.setCellStyle(lineStyle);
lineCell9.setCellValue(String.valueOf(map.get("price")).equals("null") ? "" : String.valueOf(map.get("price")));
lineCell9.setCellStyle(lineStyle);
lineCell10.setCellValue(String.valueOf(map.get("amount")).equals("null") ? "" : String.valueOf(map.get("amount")));
lineCell10.setCellStyle(lineStyle);
lineCell11.setCellValue(String.valueOf(map.get("rate")).equals("null") ? "" : String.valueOf(map.get("rate")));
lineCell11.setCellStyle(lineStyle);
String ss=String.valueOf(map.get("price")).equals("null") ? "" : String.valueOf(map.get("price"));
priceSum= priceSum.add(new BigDecimal(ss));
String s = String.valueOf(map.get("amount")).equals("null") ? "0" : String.valueOf(map.get("amount"));
sum = sum.add(new BigDecimal(s));
String num = String.valueOf(map.get("settlement")).equals("null") ? "" : String.valueOf(map.get("settlement"));
numSum = numSum.add(new BigDecimal(num));
if (i == list.size() - 1) {
//使用 createRow() 方法创建第 0 行
// HSSFRow rowhead = sheet.createRow((short) 0);
// rowhead.setHeight((short) 500);
//// 使用 createCell() 方法创建单元格,并使用 setCellValue() 方法为单元格设置值
//
// HSSFCell cell = rowhead.createCell(0);
// String s1 = String.valueOf(map.get("supplierNm")).equals("null") ? "" : String.valueOf(map.get("supplierNm"));
// if (s1.equals("")) {
// for (int i1 = 0; i1 < list.size(); i1++) {
// HashMap<String, Object> map1 = list.get(i1);
// if (!String.valueOf(map1.get("supplierNm")).equals("null")) {
// s1 = String.valueOf(map1.get("supplierNm"));
// }
// }
// }
// String s2 = String.valueOf(map.get("supplierName")).equals("null") ? "" : String.valueOf(map.get("supplierName"));
// if (s2.equals("")) {
// for (int i1 = 0; i1 < list.size(); i1++) {
// HashMap<String, Object> map1 = list.get(i1);
// if (!String.valueOf(map1.get("supplierName")).equals("null")) {
// s2 = String.valueOf(map1.get("supplierName"));
// }
// }
// }
// cell.setCellValue(s1 + "收货明细表");
// cell.setCellValue(111+ "收货明细表");
// cell.setCellStyle(cellStyle);
// //创建第一行
// HSSFRow row = sheet.createRow((short) 1);
// row.setHeight((short) 500);
////在第一行插入数据
// HSSFCell cell1 = row.createCell(0);
//
// cell1.setCellValue("供货单位:" + s2 + " 收货单位:");
// cell1.setCellStyle(headStyle);
//创建第二行
HSSFRow row1 = sheet.createRow((short) 2);
row1.setHeight((short) 500);
//在第二行插入数据
HSSFCell cell2 = row1.createCell(0);
HSSFCell cell3 = row1.createCell(1);
HSSFCell cell4 = row1.createCell(2);
HSSFCell cell5 = row1.createCell(3);
HSSFCell cell6 = row1.createCell(4);
HSSFCell cell7 = row1.createCell(5);
HSSFCell cell8 = row1.createCell(6);
HSSFCell cell9 = row1.createCell(7);
HSSFCell cell10 = row1.createCell(8);
HSSFCell cell11 = row1.createCell(9);
HSSFCell cell12 = row1.createCell(10);
cell2.setCellValue("序号");
cell2.setCellStyle(headLineStyle);
cell3.setCellValue("客户名称");
cell3.setCellStyle(headLineStyle);
cell4.setCellValue("订单号");
cell4.setCellStyle(headLineStyle);
cell5.setCellValue("物料编码");
cell5.setCellStyle(headLineStyle);
cell6.setCellValue("物料名称");
cell6.setCellStyle(headLineStyle);
cell7.setCellValue("规格");
cell7.setCellStyle(headLineStyle);
cell8.setCellValue("数量");
cell8.setCellStyle(headLineStyle);
cell9.setCellValue("单位");
cell9.setCellStyle(headLineStyle);
cell10.setCellValue("含税单价(元)");
cell10.setCellStyle(headLineStyle);
cell11.setCellValue("含税金额(元)");
cell11.setCellStyle(headLineStyle);
cell12.setCellValue("税率(%)");
cell12.setCellStyle(headLineStyle);
HSSFRow lowRow = sheet.createRow((short) i + 4);
lowRow.setHeight((short) 500);
HSSFCell lowCell1 = lowRow.createCell(0);
HSSFCell lowCell6 = lowRow.createCell(6);
HSSFCell lowCell8 = lowRow.createCell(8);
HSSFCell lowCell9 = lowRow.createCell(9);
lowCell1.setCellValue("合计");
lowCell1.setCellStyle(lineStyle);
sum.setScale(2, RoundingMode.HALF_UP);
priceSum.setScale(6, RoundingMode.HALF_UP);
lowCell6.setCellValue(numSum.toString());
lowCell6.setCellStyle(lineStyle);
// lowCell10.setCellValue(priceSum.toString());
// 合计
lowCell8.setCellValue(priceSum.toString());
lowCell8.setCellStyle(lineStyle);
lowCell9.setCellValue(sum.toString());
lowCell9.setCellStyle(lineStyle);
lowRow.createCell(1).setCellStyle(lineStyle);
lowRow.createCell(2).setCellStyle(lineStyle);
lowRow.createCell(3).setCellStyle(lineStyle);
lowRow.createCell(4).setCellStyle(lineStyle);
lowRow.createCell(5).setCellStyle(lineStyle);
lowRow.createCell(7).setCellStyle(lineStyle);
lowRow.createCell(10).setCellStyle(lineStyle);
}
}
}
for (int i = 0; i <= 10; i++) {
sheet.autoSizeColumn(i);
sheet.setColumnWidth(i, sheet.getColumnWidth(i) * 17 / 10);
}
sheet.setAutobreaks(true);//这个是sheet缩放设置默认打印一页要true
sheet.setMargin(Sheet.BottomMargin, 0.5);// 页边距(下)
sheet.setMargin(Sheet.LeftMargin, 0.1);// 页边距(左)
sheet.setMargin(Sheet.RightMargin, 0.1);// 页边距(右)
sheet.setMargin(Sheet.TopMargin, 0.5);// 页边距(上)
sheet.setHorizontallyCenter(true);//设置打印页面为水平居中
sheet.setVerticallyCenter(true);//设置打印页面为垂直居中
//使用POI输出Excel时打印页面
//启用“适合页面”打印选项的标志。(默认选择的是“将工作表调整为一页”)
sheet.setFitToPage(true);
HSSFPrintSetup printSetup = sheet.getPrintSetup();
printSetup.setLandscape(false); // 打印方向true横向false纵向
printSetup.setPaperSize(HSSFPrintSetup.A4_PAPERSIZE); //纸张大小自选A4 作者:大萌音音 https://www.bilibili.com/read/cv15053559 出处bilibili
workbook.write(fileOut);
} finally {
//关闭流
fileOut.close();
//关闭工作簿
workbook.close();
}
//在控制台打印消息
log.warn("订单信息Excel文件生成成功。");
}
/** /**
* @param wrapper * @param wrapper
* @param templateFilePath * @param templateFilePath
@ -689,8 +974,74 @@ public class PurchaseorderitemServiceImpl extends ServiceImpl<PurchaseorderitemM
// 任务集合 // 任务集合
if (StringUtil.isNotNull(userInfo.getOrganizeId()) && userInfo.getOrganizeId().equals("400882911877923205")) {
// 子线程计数器
CountDownLatch countDownLatch = new CountDownLatch(5);
// 创建线程池
ExecutorService executorService = Executors.newFixedThreadPool(5);
try {
executorService.execute(() -> {
try {
this.getPdf(wrapper, templateFilePath,settlementPdf);
} catch (Exception e) {
throw new RuntimeException(e);
}
// 关闭子线程
countDownLatch.countDown();
});
executorService.execute(() -> {
try {
this.getWord(info, templateFilePath,settlement);
} catch (Exception e) {
throw new RuntimeException(e);
}
// 关闭子线程
countDownLatch.countDown();
});
ArrayList<BigDecimal> bigDecimals = new ArrayList<>();
bigDecimals.add(amount);
executorService.execute(() -> {
try {
this.getExcel(info, templateFilePath,settlementExcel,bigDecimals);
} catch (Exception e) {
throw new RuntimeException(e);
}
// 关闭子线程
countDownLatch.countDown();
});
executorService.execute(() -> {
try {
this.getVehicle(vehicleInfo, templateFilePath,settlement);
} catch (Exception e) {
throw new RuntimeException(e);
}
// 关闭子线程
countDownLatch.countDown();
});
List<HashMap<String, Object>> orderInfo = purchaseorderitemMapper.getOrderInfo(wrapper);
executorService.execute(() -> {
try {
this.getOrderInfoExcel(orderInfo, templateFilePath);
} catch (Exception e) {
throw new RuntimeException(e);
}
// 关闭子线程
countDownLatch.countDown();
});
// 等待所有子线程执行完
countDownLatch.await();
} catch (Exception e) {
log.error("等待所有子线程执行完发生错误:" + e.getMessage());
e.printStackTrace();
} finally {
// 线程池不接受新任务
executorService.shutdown();
}
this.getZIP(templateFilePath, response,settlement);
}else{
// 子线程计数器 // 子线程计数器
CountDownLatch countDownLatch = new CountDownLatch(4); CountDownLatch countDownLatch = new CountDownLatch(4);
// 创建线程池 // 创建线程池
@ -737,7 +1088,6 @@ public class PurchaseorderitemServiceImpl extends ServiceImpl<PurchaseorderitemM
// 关闭子线程 // 关闭子线程
countDownLatch.countDown(); countDownLatch.countDown();
}); });
// 等待所有子线程执行完 // 等待所有子线程执行完
countDownLatch.await(); countDownLatch.await();
} catch (Exception e) { } catch (Exception e) {
@ -748,6 +1098,8 @@ public class PurchaseorderitemServiceImpl extends ServiceImpl<PurchaseorderitemM
executorService.shutdown(); executorService.shutdown();
} }
this.getZIP(templateFilePath, response,settlement); this.getZIP(templateFilePath, response,settlement);
}
} else { } else {
log.error("采购订单号出错!查不到该采购订单!"); log.error("采购订单号出错!查不到该采购订单!");
} }

@ -53,6 +53,7 @@
<result property="documentNo" column="documentNo"/> <result property="documentNo" column="documentNo"/>
<collection property="reportList" javaType="List" ofType="java.util.HashMap"> <collection property="reportList" javaType="List" ofType="java.util.HashMap">
<result property="itemCode" column="itemCode"/>
<!-- `物料名称、规格型号`--> <!-- `物料名称、规格型号`-->
<result property="itemName" column="itemName"/> <result property="itemName" column="itemName"/>
<!-- 税率--> <!-- 税率-->
@ -69,6 +70,35 @@
</resultMap> </resultMap>
<resultMap id="resultOrderInfoMap" type="java.util.HashMap" >
<!-- 制单人 -->
<result property="creatorUserName" column="creatorUserName"/>
<!-- 订单日期 -->
<result property="creatorTime" column="creatorTime"/>
<!-- 对方合同号-->
<result property="contractNo" column="contractNo"/>
<!-- 合同编码-->
<result property="contractCode" column="contractCode"/>
<!-- 供货 单位-->
<result property="supplierName" column="supplierName"/>
<!-- 订单号 -->
<result property="documentNo" column="documentNo"/>
<result property="itemCode" column="itemCode"/>
<!-- `物料名称、规格型号`-->
<result property="itemName" column="itemName"/>
<!-- 税率-->
<result property="rate" column="rate"/>
<!-- 单价-->
<result property="price" column="price"/>
<!-- 数量-->
<result property="settlement" column="settlement"/>
<!-- 单位-->
<result property="unit" column="unit"/>
<!-- 金额-->
<result property="amount" column="amount" />
</resultMap>
<select id="getPdfInfo" resultMap="resultPdfInfoMap"> <select id="getPdfInfo" resultMap="resultPdfInfoMap">
SELECT SELECT
@ -86,7 +116,7 @@
c.item_name AS `itemName`, c.item_name AS `itemName`,
( (
CASE CASE
a.rate d.rate
WHEN '0' THEN WHEN '0' THEN
13 13
WHEN '1' THEN WHEN '1' THEN
@ -118,7 +148,62 @@
GROUP BY GROUP BY
a.id, a.id,
b.material_id, b.material_id,
a.rate, d.rate,
b.unit,
a.document_no
) aaa ${ew.customSqlSegment}
</select>
<select id="getOrderInfo" resultMap="resultOrderInfoMap">
SELECT
*
FROM
(
SELECT
a.DOCUMENT_NO,
a.creator_user_name AS `creatorUserName`,
DATE_FORMAT( a.creator_time, '%Y-%m-%d' ) AS `creatorTime`,
a.contract_no AS `contractNo`,
e.contract_code AS `contractCode`,
a.supplier_name AS `supplierName`,
a.document_no AS `documentNo`,
c.item_code AS itemCode,
c.item_name AS `itemName`,
(
CASE
a.rate
WHEN '0' THEN
13
WHEN '1' THEN
9
WHEN '2' THEN
6
WHEN '3' THEN
5
WHEN '4' THEN
3 ELSE 13
END
) AS `rate`,
ROUND(IFNULL( SUM(d.amount)/SUM( CASE b.unit WHEN 0 THEN b.settlement ELSE b.settlement/1000 END ),0), 6 ) AS `price`,
ROUND( SUM( CASE b.unit WHEN 0 THEN b.settlement ELSE b.settlement/1000 END ), 2 ) AS `settlement`,
( CASE b.unit WHEN 0 THEN '吨' ELSE '千克' END ) AS `unit`,
ROUND( a.amount, 2 ) `amount`
FROM
jg_purchaseorder AS a
LEFT JOIN jg_purchaseorder_item0 d ON a.id = d.purchaseorder_id
AND d.delete_mark = '0'
LEFT JOIN jg_poundlist b ON b.id = d.poundlist_id
AND b.delete_mark = '0'
LEFT JOIN jg_material c ON b.material_id = c.id
AND c.delete_mark = '0'
LEFT JOIN jg_contract e ON a.contract_code = e.id
AND e.delete_mark = '0'
WHERE
a.delete_mark = '0'
GROUP BY
a.id,
b.material_id,
d.rate,
b.unit, b.unit,
a.document_no a.document_no
) aaa ${ew.customSqlSegment} ) aaa ${ew.customSqlSegment}

Loading…
Cancel
Save