打印修改预览

This commit is contained in:
funny 2026-04-14 16:31:31 +08:00
parent ceb6c19a2e
commit c643d26632
4 changed files with 144 additions and 173 deletions

View File

@ -831,38 +831,36 @@ public class MaterialCodeController extends BaseController {
*/
@PostMapping("exportToPdf")
public void exportToPdf(HttpServletResponse response, @RequestBody @NotEmpty List<Long> ids) throws Exception {
// 根据物料主数据ID查询物料编号
List<WmsShipmentMaterial> materials = materialService.listByIds(ids);
VUtil.trueThrowBusinessError(CollectionUtil.isEmpty(materials)).throwMessage("物料数据不存在");
// 根据清单ID查询二维码数据
List<ShipmentMaterialCodeQRVO> datas = materialCodeItemQrService.getListVOByCodeIds(ids);
VUtil.trueThrowBusinessError(CollectionUtil.isEmpty(datas)).throwMessage("物料数据不存在");
Set<String> materialNos = materials.stream()
.map(WmsShipmentMaterial::getNo)
.collect(Collectors.toSet());
// 取第一条数据
ShipmentMaterialCodeQRVO data = datas.get(0);
// 根据物料编号查询物料图片
Map<String, String> images = materials.stream()
Map<String, String> images = materialService.lambdaQuery()
.select(WmsShipmentMaterial::getNo, WmsShipmentMaterial::getImage)
.in(WmsShipmentMaterial::getNo, datas.stream().map(ShipmentMaterialCodeQRVO::getMaterialNo).collect(Collectors.toSet()))
.list()
.stream()
.collect(Collectors.toMap(WmsShipmentMaterial::getNo, WmsShipmentMaterial::getImage));
// 根据物料编号查询清单明细二维码数据
List<ShipmentMaterialCodeQRVO> datas = materialCodeItemQrService.getListVOByMaterialNos(materialNos);
VUtil.trueThrowBusinessError(CollectionUtil.isEmpty(datas)).throwMessage("没有需要导出的数据");
// 构建打印数据
Map<String, Object> variables = new HashMap<>();
variables.put("list", datas.stream()
.map(data -> new MaterialCodePrintDTO()
.setNo(data.getNo())
.setQrCode(QRCodeUtil.generateQRCodeBase64(data.getNo(), 200, 200))
.setMaterialNo(data.getMaterialNo())
.setMaterialDescribe(data.getMaterialDescribe())
.setNum(data.getNum())
.setNumText(data.getNumText())
.setUnit(data.getUnit())
.setDeviceNo(data.getDeviceNo())
.setCustomerName(data.getCustomerName())
.setLst(images.get(data.getMaterialNo()))
).toList()
);
Map<String, Object> info = new HashMap<>();
info.put("no", data.getNo());
info.put("materialNo", data.getMaterialNo());
info.put("numText", data.getNumText());
info.put("customerName", data.getCustomerName());
Map<String, String> ext = new HashMap<>();
ext.put("qrCode", QRCodeUtil.generateQRCodeBase64(data.getNo(), 200, 200));
ext.put("lst", images.get(data.getMaterialNo()));
variables.put("info", info);
variables.put("ext", ext);
String html = ThymeleafUtil.generator("/template/label/", "material-pdf", ".html", variables);
URL baseUrl = new ClassPathResource("template/label/").getURL();
@ -878,79 +876,35 @@ public class MaterialCodeController extends BaseController {
@PostMapping("exportItemToPdf")
public void exportItemToPdf(HttpServletResponse response, @RequestBody @NotEmpty List<Long> ids) throws Exception {
// 根据明细ID查询数据
List<MaterialItemPrintVO> datas = materialCodeItemService.getListByItemIds(ids);
List<ShipmentMaterialCodeQRVO> datas = materialCodeItemQrService.getListVOByItemIds(ids);
VUtil.trueThrowBusinessError(CollectionUtil.isEmpty(datas)).throwMessage("没有需要导出的数据");
// 获取物料图片
// 取第一条数据
ShipmentMaterialCodeQRVO data = datas.get(0);
// 根据物料编号查询物料图片
Map<String, String> images = materialService.lambdaQuery()
.select(WmsShipmentMaterial::getNo, WmsShipmentMaterial::getImage)
.in(WmsShipmentMaterial::getNo, datas.stream().map(MaterialItemPrintVO::getMaterialNo).collect(Collectors.toSet()))
.in(WmsShipmentMaterial::getNo, datas.stream().map(ShipmentMaterialCodeQRVO::getMaterialNo).collect(Collectors.toSet()))
.list()
.stream()
.collect(Collectors.toMap(WmsShipmentMaterial::getNo, WmsShipmentMaterial::getImage));
// 构建打印数据
Map<String, Object> variables = new HashMap<>();
variables.put("list", datas.stream()
.map(data -> new MaterialCodePrintDTO()
.setNo(data.getMaterialNo() + "-" + data.getId())
.setQrCode(QRCodeUtil.generateQRCodeBase64(data.getMaterialNo() + "-" + data.getId(), 200, 200))
.setMaterialNo(data.getMaterialNo())
.setMaterialDescribe(data.getMaterialDescribe())
.setNum(data.getNum())
.setNumText(data.getNumText())
.setUnit(data.getUnit())
.setDeviceNo(data.getDeviceNo())
.setCustomerName(data.getCustomerName())
.setLst(images.get(data.getMaterialNo()))
).toList()
);
String html = ThymeleafUtil.generator("/template/label/", "material-pdf", ".html", variables);
URL baseUrl = new ClassPathResource("template/label/").getURL();
PdfGeneratorUtil.generatePdf("物料明细标签", html, baseUrl.toString(), response);
}
/**
* 根据物料主数据ID导出物料明细PDF打印预览
*
* @param response HTTP响应
* @param ids 物料主数据id列表wms_shipment_material.id
*/
@PostMapping("exportMaterialItemToPdf")
public void exportMaterialItemToPdf(HttpServletResponse response, @RequestBody @NotEmpty List<Long> ids) throws Exception {
// 根据物料主数据ID查询物料编号
List<WmsShipmentMaterial> materials = materialService.listByIds(ids);
VUtil.trueThrowBusinessError(CollectionUtil.isEmpty(materials)).throwMessage("物料数据不存在");
Map<String, Object> info = new HashMap<>();
info.put("no", data.getNo());
info.put("materialNo", data.getMaterialNo());
info.put("numText", data.getNumText());
info.put("customerName", data.getCustomerName());
Set<String> materialNos = materials.stream()
.map(WmsShipmentMaterial::getNo)
.collect(Collectors.toSet());
Map<String, String> ext = new HashMap<>();
ext.put("qrCode", QRCodeUtil.generateQRCodeBase64(data.getNo(), 200, 200));
ext.put("lst", images.get(data.getMaterialNo()));
// 根据物料编号查询物料图片
Map<String, String> images = materials.stream()
.collect(Collectors.toMap(WmsShipmentMaterial::getNo, WmsShipmentMaterial::getImage));
// 根据物料编号查询明细数据
List<MaterialItemPrintVO> datas = materialCodeItemService.getListByMaterialNos(materialNos);
VUtil.trueThrowBusinessError(CollectionUtil.isEmpty(datas)).throwMessage("没有需要导出的数据");
// 构建打印数据
Map<String, Object> variables = new HashMap<>();
variables.put("list", datas.stream()
.map(data -> new MaterialCodePrintDTO()
.setNo(data.getMaterialNo() + "-" + data.getId())
.setQrCode(QRCodeUtil.generateQRCodeBase64(data.getMaterialNo() + "-" + data.getId(), 200, 200))
.setMaterialNo(data.getMaterialNo())
.setMaterialDescribe(data.getMaterialDescribe())
.setNum(data.getNum())
.setNumText(data.getNumText())
.setUnit(data.getUnit())
.setDeviceNo(data.getDeviceNo())
.setCustomerName(data.getCustomerName())
.setLst(images.get(data.getMaterialNo()))
).toList()
);
variables.put("info", info);
variables.put("ext", ext);
String html = ThymeleafUtil.generator("/template/label/", "material-pdf", ".html", variables);
URL baseUrl = new ClassPathResource("template/label/").getURL();

View File

@ -421,15 +421,14 @@ public class PackagingCodeController extends BaseController {
Map<String, Object> variables = new HashMap<>();
variables.put("list", list.stream()
.map(data -> {
String typeName = types.stream()
.filter(type -> type.getId().equals(data.getType()))
.map(DictionaryItem::getName)
.findFirst()
.orElse("");
ShipmentPackagingCodeVO vo = new ShipmentPackagingCodeVO();
vo.setNo(data.getNo());
vo.setName(data.getName());
vo.setTypeName(typeName);
vo.setTypeName(types.stream()
.filter(type -> type.getId().equals(data.getType()))
.map(DictionaryItem::getName)
.findFirst()
.orElse(""));
vo.setQrCode(QRCodeUtil.generateQRCodeBase64(data.getNo(), 100, 100));
return vo;
}).toList()

View File

@ -2,26 +2,23 @@
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8"/>
<title>物料码标签</title>
<title>包装码</title>
<meta content="width=device-width, initial-scale=1.0" name="viewport"/>
<style>
@page {
size: 1200px 800px;
margin: 0;
}
body {
font-size: 10pt;
width: 1200px;
height: 800px;
font-size: 20pt;
font-family: SimSun, Arial, sans-serif;
margin: 0;
padding: 0;
}
.label-page {
width: 1200px;
height: 800px;
page-break-after: always;
}
.label-page:last-child {
page-break-after: auto;
}
table {
width: 1200px;
height: 800px;
@ -29,7 +26,7 @@
border-collapse: collapse;
table-layout: fixed;
}
th, td {
border: 3px solid #000;
padding: 10px;
@ -38,59 +35,56 @@
word-wrap: break-word;
overflow-wrap: break-word;
}
.qrcode {
width: 380px;
height: 380px;
}
.lst {
.lst{
width: 800px;
height: auto;
}
</style>
</head>
<body>
<div class="label-page" th:each="item, iterStat : ${list}" th:style="${iterStat.index == 0} ? 'page-break-before: auto;' : 'page-break-before: always;'">
<table>
<tr>
<td style="text-align: center; width: 400px" rowspan="3">
<img alt="" class="qrcode" th:src="${item.qrCode}"/>
<div style="font-size: 16pt" th:text="${item.no}">0PC7B724KV6FM</div>
</td>
<td style="width: 140px;">
机台编号
</td>
<td style="width: 200px;" th:text="${item.no}">
26LBZ4000L001
</td>
<td style="width: 140px;">
客户名称
</td>
<td style="text-align: left" th:text="${item.customerName}">
北京市京联鑫路用材料有限公司
</td>
</tr>
<tr>
<td>
物料编码
</td>
<td th:text="${item.materialNo}">
3100006701
</td>
<td>
数量
</td>
<td th:text="${item.numText}">
10
</td>
</tr>
<tr>
<td colspan="4">
<img style="width: 750px;" alt="" class="lst" th:src="${item.lst}"/>
</td>
</tr>
</table>
</div>
<table>
<tr>
<td style="text-align: center; width: 400px" rowspan="3">
<img alt="" class="qrcode" th:src="${ext.qrCode}"/>
<div style="font-size: 16pt" th:text="${info.no}">0PC7B724KV6FM</div>
</td>
<td style="width: 140px;">
机台编号
</td>
<td style="width: 200px;" th:text="${info.no}">
26LBZ4000L001
</td>
<td style="width: 140px;">
客户名称
</td>
<td style="text-align: left" th:text="${info.customerName}">
北京市京联鑫路用材料有限公司
</td>
</tr>
<tr>
<td>
物料编码
</td>
<td th:text="${info.materialNo}">
3100006701
</td>
<td>
数量
</td>
<td th:text="${info.numText}">
10
</td>
</tr>
<tr>
<td colspan="4">
<img style="width: 750px;" alt="" src="https://img-s.msn.cn/tenant/amp/entityid/AA1VWN3Q.img?w=768&h=333&m=6" class="lst" th:src="${ext.lst}"/>
</td>
</tr>
</table>
</body>
</html>
</html>

View File

@ -2,37 +2,57 @@
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8"/>
<title>包装码标签</title>
<title>包装码标签-A4打印版</title>
<meta content="width=device-width, initial-scale=1.0" name="viewport"/>
<style>
@page {
size: A4 portrait;
margin: 0;
}
body {
font-size: 10pt;
font-family: SimSun, Arial, sans-serif;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
}
.label-page {
width: 600px;
height: 400px;
width: 210mm;
height: 297mm;
display: flex;
align-items: center;
justify-content: center;
page-break-after: always;
position: relative;
}
.label-page:last-child {
page-break-after: auto;
}
.label-content {
width: 600px;
height: 400px;
transform-origin: center center;
transform: scale(calc(210mm / 600px));
}
table {
width: 600px;
height: 400px;
border: 3px solid #000;
border-collapse: collapse;
}
th, td {
border: 3px solid #000;
}
.div-with-border {
border-bottom: 3px solid #000;
padding: 18px;
@ -41,7 +61,7 @@
display: block;
vertical-align: middle
}
.qrcode {
width: 260px;
height: 260px;
@ -50,19 +70,23 @@
</style>
</head>
<body>
<div class="label-page" th:each="item, iterStat : ${list}" th:style="${iterStat.index == 0} ? 'page-break-before: auto;' : 'page-break-before: always;'">
<table>
<tr>
<td style="text-align: center;">
<img alt="" class="qrcode" th:src="${item.qrCode}"/>
<div style="font-size: 16pt" th:text="${item.no}">NFLG-QZ-002</div>
</td>
<td style="text-align: left;vertical-align: top">
<div class="div-with-border">包装名称: <span th:text="${item.name}">NFLG-QZ-002 测试包装名称</span></div>
<div class="div-with-border">包装类型: <span th:text="${item.typeName}">托盘</span></div>
</td>
</tr>
</table>
<div class="label-page" th:each="item, iterStat : ${list}">
<div class="label-content">
<table>
<tr>
<td style="text-align: center;">
<img alt="" class="qrcode" th:src="${item.qrCode}"/>
<div style="font-size: 16pt" th:text="${item.no}">NFLG-QZ-002</div>
</td>
<td style="text-align: left;vertical-align: top">
<div class="div-with-border">包装名称: <span th:text="${item.name}">NFLG-QZ-002 测试包装名称</span></div>
<div class="div-with-border">包装类型: <span th:text="${item.typeName}">托盘</span></div>
</td>
</tr>
</table>
</div>
</div>
</body>
</html>
</html>