物料老鼠图功能修改

This commit is contained in:
funny 2026-04-15 17:25:58 +08:00
parent a15ad691b6
commit aa81f6c3fc
6 changed files with 626 additions and 17 deletions

View File

@ -760,12 +760,16 @@ public class MaterialCodeController extends BaseController {
* 导出老鼠图PDF
*/
@PostMapping("exportPdf")
public ApiResult<String> exportPdf(HttpServletResponse response, @RequestBody @NotEmpty List<ShipmentMaterialCodeQRVO> list) throws Exception {
VUtil.trueThrowBusinessError(CollectionUtil.isEmpty(list)).throwMessage("没有需要导出的数据");
public ApiResult<String> exportPdf(HttpServletResponse response, @Valid @RequestBody MaterialPdfExportQO qo) throws Exception {
VUtil.trueThrowBusinessError(CollectionUtil.isEmpty(qo.getIds())).throwMessage("没有需要导出的数据");
// 每页数量校验
Integer perPage = qo.getPerPage() != null ? qo.getPerPage() : 6;
List<Integer> validPerPage = List.of(2, 4, 6, 8, 9);
VUtil.trueThrowBusinessError(!validPerPage.contains(perPage)).throwMessage("每页数量只能为2/4/6/8/9");
// list 中提取物料ID明细ID
List<Long> materialIds = list.stream()
.map(ShipmentMaterialCodeQRVO::getId)
List<Long> materialIds = qo.getIds().stream()
.filter(Objects::nonNull)
.toList();
VUtil.trueThrowBusinessError(materialIds.isEmpty()).throwMessage("物料ID不能为空");
@ -810,8 +814,8 @@ public class MaterialCodeController extends BaseController {
allWeight = allWeight.add(weight.multiply(num));
}
// list 中获取第一条数据
ShipmentMaterialCodeQRVO firstItem = list.get(0);
// materialIds 中获取第一条数据
WmsShipmentMaterialCodeItem firstItem = materialCodeItems.get(0);
// 根据物料码主表ID查询清单信息清单编号机台编号销售订单号客户名称下单日期
WmsShipmentMaterialCode materialCode = null;
@ -829,25 +833,28 @@ public class MaterialCodeController extends BaseController {
// 构建表头数据
MaterialPdfVO material = new MaterialPdfVO();
// 优先使用从数据库查询的清单信息如果没有则使用前端传入的数据
material.setNo(materialCode != null ? materialCode.getNo() : firstItem.getNo()); // 清单编号
material.setDeviceNo(materialCode != null ? materialCode.getDeviceNo() : firstItem.getDeviceNo()); // 机台编号
material.setMaterialNo(firstItem.getMaterialNo()); // 物料编号
material.setSoNo(materialCode != null ? materialCode.getSoNo() : firstItem.getSoNo()); // 销售订单号
material.setCustomerName(materialCode != null ? materialCode.getCustomerName() : firstItem.getCustomerName()); // 客户名称
material.setOrderDay(materialCode != null ? materialCode.getOrderDate() : firstItem.getOrderDate()); // 下单日期
material.setWeight(allWeight); // 总重量
material.setNo(materialCode != null ? materialCode.getNo() : firstItem.getMaterialCodeId().toString()); // 清单编号
material.setDeviceNo(materialCode != null ? materialCode.getDeviceNo() : null); // 机台编号
material.setMaterialNo(firstItem.getMaterialNo()); // 物料编号
material.setSoNo(materialCode != null ? materialCode.getSoNo() : null); // 销售订单号
material.setCustomerName(materialCode != null ? materialCode.getCustomerName() : null); // 客户名称
material.setOrderDay(materialCode != null ? materialCode.getOrderDate() : null); // 下单日期
material.setWeight(allWeight); // 总重量
// 用清单编号生成二维码放在红圈位置
String qrCodeNo = materialCode != null ? materialCode.getNo() : firstItem.getNo();
// 用清单编号生成二维码
String qrCodeNo = materialCode != null ? materialCode.getNo() : "";
material.setQrCode(QRCodeUtil.generateQRCodeBase64(qrCodeNo, 100, 100));
// 制作pdf
Map<String, Object> variables = new HashMap<>();
variables.put("info", material);
variables.put("pages", PdfPageDTO.create(items, 9, new MaterialPdfDTO()));
variables.put("pages", PdfPageDTO.create(items, perPage, new MaterialPdfDTO()));
// 根据每页数量选择对应模板
String templateName = "物料老鼠图" + perPage;
String html = ThymeleafUtil.generator(
"/template/",
"物料老鼠图",
templateName,
".html",
variables
);

View File

@ -0,0 +1,150 @@
<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>物料老鼠图</title>
<style>
@page {
size: A4;
margin: 0;
}
body {
font-family: SimSun, serif;
font-size: 9pt;
padding: 10px;
margin: 0 auto;
max-width: 100%;
}
.logo {
text-align: center;
}
.logo img {
height: 40px;
padding: 10px;
}
table {
width: 100%;
border-collapse: collapse;
border: 1px solid #000;
}
td {
border: 1px solid #000;
padding: 7px;
}
tr:first-child td {
border-top: none;
}
tr:last-child td {
border-bottom: none;
}
td:first-child {
border-left: none;
}
td:last-child {
border-right: none;
border-bottom: none;
}
.data-item {
width: 100%;
float: left;
border-right: 1px solid #000;
border-left: 1px solid #000;
box-sizing: border-box;
}
.cell-img {
display: table-cell;
vertical-align: middle;
text-align: center;
padding: 10px;
height: auto;
overflow: hidden;
}
.cell-img img {
vertical-align: middle; /* 防止图片底部留空隙 */
height: auto;
display: block;
margin: auto auto;
margin-left: 200px;
}
.cell {
border-bottom: 1px solid #000;
padding: 7px;
overflow: hidden;
}
.cell1 {
border-bottom: 1px solid #000;
padding: 7px;
height: 25px;
overflow: hidden;
}
.container {
page-break-after: always;
}
.container:last-child {
page-break-after: auto;
}
</style>
</head>
<body>
<div class="container" th:each="page,pageStat : ${pages}">
<div class="logo"><img alt="" src="../img/logo1.png"/></div>
<table>
<tr>
<td>清单编号:<span th:text="${info.no}">12255665451615</span></td>
<td>机台编号:<span th:text="${info.deviceNo}">1111</span></td>
<td>物料编号:<span th:text="${info.materialNo}">12255665451615</span></td>
<!-- 二维码:右侧固定 + 跨3行 -->
<td style="width: 120px; text-align: right; vertical-align: middle;" rowspan="3">
<img alt="二维码" style="width: 100px; height: 100px;" th:src="${info.qrCode}" src="../img/logo1.png"/>
</td>
</tr>
<tr>
<td>销售订单号:<span th:text="${info.soNo}">1</span></td>
<td>客户名称:<span th:text="${info.customerName}">12255665451615</span></td>
</tr>
<tr>
<td>下单日期:<span th:text="${info.orderDay}">1</span></td>
<td>总重:<span th:text="${info.weight}">348.41</span></td>
<td>页码:<span th:text="${pageStat.count}">1</span>/<span th:text="${pageStat.size}">2</span></td>
</tr>
</table>
<div class="data-item" th:each="item,itemStat : ${page.datas}">
<div class="cell" style="height: 300px;">
<div class="cell-img">
<img style="width: 340px;height: 280px;" alt=""
th:src="${!#strings.isEmpty(item.image)} ? ${item.image} : (${#strings.isEmpty(item.materialNo)} ? '' : 'http://192.168.163.83:9090/nflg-wms/template/none.png')"/>
</div>
</div>
<div class="cell">SAP编码<span th:text="${item.materialNo}">2222222222</span></div>
<div class="cell1">图号:<span
th:text="${item.drawingNo}">图号图号图号图号图号图号图号图号图号图号图号图号图号图号图号图号</span>
</div>
<div class="cell1">名称:<span
th:text="${item.materialDescribe}">名称名称名称名称名称名称名称名称名称名名称名名称名称名称称名称名称名称称名称名称名称</span>
</div>
<div class="cell">数量:<span th:text="${item.num}">1</span>&nbsp;&nbsp;&nbsp;&nbsp;重量:<span
th:text="${item.weight}">348.41</span></div>
</div>
</div>
</body>
</html>

View File

@ -0,0 +1,151 @@
<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>物料老鼠图</title>
<style>
@page {
size: A4;
margin: 0;
}
body {
font-family: SimSun, serif;
font-size: 9pt;
padding: 10px;
margin: 0 auto;
max-width: 100%;
}
.logo {
text-align: center;
}
.logo img {
height: 40px;
padding: 10px;
}
table {
width: 100%;
border-collapse: collapse;
border: 1px solid #000;
}
td {
border: 1px solid #000;
padding: 7px;
}
tr:first-child td {
border-top: none;
}
tr:last-child td {
border-bottom: none;
}
td:first-child {
border-left: none;
}
td:last-child {
border-right: none;
border-bottom: none;
}
.data-item {
width: 50%;
float: left;
border-right: 1px solid #000;
box-sizing: border-box;
}
.data-item:nth-child(2n+1) {
border-left: 1px solid #000;
clear: left;
}
.cell-img {
display: table-cell;
vertical-align: middle;
text-align: center;
padding: 10px;
height: auto;
overflow: hidden;
}
.cell-img img {
vertical-align: middle; /* 防止图片底部留空隙 */
height: auto;
}
.cell {
border-bottom: 1px solid #000;
padding: 7px;
overflow: hidden;
}
.cell1 {
border-bottom: 1px solid #000;
padding: 7px;
height: 25px;
overflow: hidden;
}
.container {
page-break-after: always;
}
.container:last-child {
page-break-after: auto;
}
</style>
</head>
<body>
<div class="container" th:each="page,pageStat : ${pages}">
<div class="logo"><img alt="" src="../img/logo1.png"/></div>
<table>
<tr>
<td>清单编号:<span th:text="${info.no}">12255665451615</span></td>
<td>机台编号:<span th:text="${info.deviceNo}">1111</span></td>
<td>物料编号:<span th:text="${info.materialNo}">12255665451615</span></td>
<!-- 二维码:右侧固定 + 跨3行 -->
<td style="width: 120px; text-align: right; vertical-align: middle;" rowspan="3">
<img alt="二维码" style="width: 100px; height: 100px;" th:src="${info.qrCode}" src="../img/logo1.png"/>
</td>
</tr>
<tr>
<td>销售订单号:<span th:text="${info.soNo}">1</span></td>
<td>客户名称:<span th:text="${info.customerName}">12255665451615</span></td>
</tr>
<tr>
<td>下单日期:<span th:text="${info.orderDay}">1</span></td>
<td>总重:<span th:text="${info.weight}">348.41</span></td>
<td>页码:<span th:text="${pageStat.count}">1</span>/<span th:text="${pageStat.size}">2</span></td>
</tr>
</table>
<div class="data-item" th:each="item,itemStat : ${page.datas}">
<div class="cell" style="height: 300px;">
<div class="cell-img">
<img style="width: 340px;height: 280px;" alt=""
th:src="${!#strings.isEmpty(item.image)} ? ${item.image} : (${#strings.isEmpty(item.materialNo)} ? '' : 'http://192.168.163.83:9090/nflg-wms/template/none.png')"/>
</div>
</div>
<div class="cell">SAP编码<span th:text="${item.materialNo}">2222222222</span></div>
<div class="cell1">图号:<span
th:text="${item.drawingNo}">图号图号图号图号图号图号图号图号图号图号图号图号图号图号图号图号</span>
</div>
<div class="cell1">名称:<span
th:text="${item.materialDescribe}">名称名称名称名称名称名称名称名称名称名名称名名称名称名称称名称名称名称称名称名称名称</span>
</div>
<div class="cell">数量:<span th:text="${item.num}">1</span>&nbsp;&nbsp;&nbsp;&nbsp;重量:<span
th:text="${item.weight}">348.41</span></div>
</div>
</div>
</body>
</html>

View File

@ -0,0 +1,150 @@
<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>物料老鼠图</title>
<style>
@page {
size: A4;
margin: 0;
}
body {
font-family: SimSun, serif;
font-size: 9pt;
padding: 10px;
margin: 0 auto;
max-width: 100%;
}
.logo {
text-align: center;
}
.logo img {
height: 40px;
padding: 10px;
}
table {
width: 100%;
border-collapse: collapse;
border: 1px solid #000;
}
td {
border: 1px solid #000;
padding: 7px;
}
tr:first-child td {
border-top: none;
}
tr:last-child td {
border-bottom: none;
}
td:first-child {
border-left: none;
}
td:last-child {
border-right: none;
border-bottom: none;
}
.data-item {
width: 33.16207%;
float: left;
border-right: 1px solid #000;
}
.data-item-row-first {
border-left: 1px solid #000;
}
.cell-img {
display: table-cell;
vertical-align: middle;
text-align: center;
padding: 10px;
height: auto;
overflow: hidden;
}
.cell-img img {
vertical-align: middle; /* 防止图片底部留空隙 */
height: auto;
}
.cell {
border-bottom: 1px solid #000;
padding: 7px;
overflow: hidden;
}
.cell1 {
border-bottom: 1px solid #000;
padding: 7px;
height: 25px;
overflow: hidden;
}
.container {
page-break-after: always;
}
.container:last-child {
page-break-after: auto;
}
</style>
</head>
<body>
<div class="container" th:each="page,pageStat : ${pages}">
<div class="logo"><img alt="" src="../img/logo1.png"/></div>
<table>
<tr>
<td>清单编号:<span th:text="${info.no}">12255665451615</span></td>
<td>机台编号:<span th:text="${info.deviceNo}">1111</span></td>
<td>物料编号:<span th:text="${info.materialNo}">12255665451615</span></td>
<!-- 二维码:右侧固定 + 跨3行 -->
<td style="width: 120px; text-align: right; vertical-align: middle;" rowspan="3">
<img alt="二维码" style="width: 100px; height: 100px;" th:src="${info.qrCode}" src="../img/logo1.png"/>
</td>
</tr>
<tr>
<td>销售订单号:<span th:text="${info.soNo}">1</span></td>
<td>客户名称:<span th:text="${info.customerName}">12255665451615</span></td>
</tr>
<tr>
<td>下单日期:<span th:text="${info.orderDay}">1</span></td>
<td>总重:<span th:text="${info.weight}">348.41</span></td>
<td>页码:<span th:text="${pageStat.count}">1</span>/<span th:text="${pageStat.size}">2</span></td>
</tr>
</table>
<div class="data-item" th:each="item,itemStat : ${page.datas}"
th:classappend="${itemStat.index % 3 == 0} ? 'data-item-row-first'">
<div class="cell" style="height: 300px;">
<div class="cell-img">
<img style="width: 200px;height: 280px;" alt=""
th:src="${!#strings.isEmpty(item.image)} ? ${item.image} : (${#strings.isEmpty(item.materialNo)} ? '' : 'http://192.168.163.83:9090/nflg-wms/template/none.png')"/>
</div>
</div>
<div class="cell">SAP编码<span th:text="${item.materialNo}">2222222222</span></div>
<div class="cell1">图号:<span
th:text="${item.drawingNo}">图号图号图号图号图号图号图号图号图号图号图号图号图号图号图号图号</span>
</div>
<div class="cell1">名称:<span
th:text="${item.materialDescribe}">名称名称名称名称名称名称名称名称名称名名称名名称名称名称称名称名称名称称名称名称名称</span>
</div>
<div class="cell">数量:<span th:text="${item.num}">1</span>&nbsp;&nbsp;&nbsp;&nbsp;重量:<span
th:text="${item.weight}">348.41</span></div>
</div>
</div>
</body>
</html>

View File

@ -0,0 +1,151 @@
<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>物料老鼠图</title>
<style>
@page {
size: A4;
margin: 0;
}
body {
font-family: SimSun, serif;
font-size: 9pt;
padding: 10px;
margin: 0 auto;
max-width: 100%;
}
.logo {
text-align: center;
}
.logo img {
height: 40px;
padding: 10px;
}
table {
width: 100%;
border-collapse: collapse;
border: 1px solid #000;
}
td {
border: 1px solid #000;
padding: 7px;
}
tr:first-child td {
border-top: none;
}
tr:last-child td {
border-bottom: none;
}
td:first-child {
border-left: none;
}
td:last-child {
border-right: none;
border-bottom: none;
}
.data-item {
width: 24.995%;
float: left;
border-right: 1px solid #000;
border-left: 1px solid #000;
box-sizing: border-box;
}
.data-item:nth-child(4n) {
border-right: none;
}
.cell-img {
display: table-cell;
vertical-align: middle;
text-align: center;
padding: 10px;
height: auto;
overflow: hidden;
}
.cell-img img {
vertical-align: middle; /* 防止图片底部留空隙 */
height: auto;
}
.cell {
border-bottom: 1px solid #000;
padding: 7px;
overflow: hidden;
}
.cell1 {
border-bottom: 1px solid #000;
padding: 7px;
height: 25px;
overflow: hidden;
}
.container {
page-break-after: always;
}
.container:last-child {
page-break-after: auto;
}
</style>
</head>
<body>
<div class="container" th:each="page,pageStat : ${pages}">
<div class="logo"><img alt="" src="../img/logo1.png"/></div>
<table>
<tr>
<td>清单编号:<span th:text="${info.no}">12255665451615</span></td>
<td>机台编号:<span th:text="${info.deviceNo}">1111</span></td>
<td>物料编号:<span th:text="${info.materialNo}">12255665451615</span></td>
<!-- 二维码:右侧固定 + 跨3行 -->
<td style="width: 120px; text-align: right; vertical-align: middle;" rowspan="3">
<img alt="二维码" style="width: 100px; height: 100px;" th:src="${info.qrCode}" src="../img/logo1.png"/>
</td>
</tr>
<tr>
<td>销售订单号:<span th:text="${info.soNo}">1</span></td>
<td>客户名称:<span th:text="${info.customerName}">12255665451615</span></td>
</tr>
<tr>
<td>下单日期:<span th:text="${info.orderDay}">1</span></td>
<td>总重:<span th:text="${info.weight}">348.41</span></td>
<td>页码:<span th:text="${pageStat.count}">1</span>/<span th:text="${pageStat.size}">2</span></td>
</tr>
</table>
<div class="data-item" th:each="item,itemStat : ${page.datas}">
<div class="cell" style="height: 300px;">
<div class="cell-img">
<img style="width: 140px;height: 280px;" alt=""
th:src="${!#strings.isEmpty(item.image)} ? ${item.image} : (${#strings.isEmpty(item.materialNo)} ? '' : 'http://192.168.163.83:9090/nflg-wms/template/none.png')"/>
</div>
</div>
<div class="cell">SAP编码<span th:text="${item.materialNo}">2222222222</span></div>
<div class="cell1">图号:<span
th:text="${item.drawingNo}">图号图号图号图号图号图号图号图号图号图号图号图号图号图号图号图号</span>
</div>
<div class="cell1">名称:<span
th:text="${item.materialDescribe}">名称名称名称名称名称名称名称名称名称名名称名名称名称名称称名称名称名称称名称名称名称</span>
</div>
<div class="cell">数量:<span th:text="${item.num}">1</span>&nbsp;&nbsp;&nbsp;&nbsp;重量:<span
th:text="${item.weight}">348.41</span></div>
</div>
</div>
</body>
</html>