打印修改预览

This commit is contained in:
funny 2026-04-15 15:34:19 +08:00
parent c643d26632
commit a15ad691b6
7 changed files with 337 additions and 149 deletions

View File

@ -4,6 +4,7 @@ import com.nflg.wms.common.util.NumberUtil;
import lombok.Data; import lombok.Data;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.List;
@Data @Data
public class ShipmentMaterialCodeQRVO { public class ShipmentMaterialCodeQRVO {
@ -69,4 +70,24 @@ public class ShipmentMaterialCodeQRVO {
*/ */
private String customerName; private String customerName;
/**
* 二维码编号列表用于打印
*/
private List<String> qrCodes;
/**
* 物料码主表ID用于查询客户信息
*/
private Long materialCodeId;
/**
* 销售订单号
*/
private String soNo;
/**
* 下单日期
*/
private String orderDate;
} }

View File

@ -22,7 +22,7 @@
</select> </select>
<select id="getListVOByCodeIds" resultType="com.nflg.wms.common.pojo.vo.ShipmentMaterialCodeQRVO"> <select id="getListVOByCodeIds" resultType="com.nflg.wms.common.pojo.vo.ShipmentMaterialCodeQRVO">
SELECT qr.id,qr.no,it.material_no,it.material_describe,qr.num,it.unit,qr.status,mc.device_no,mc.customer_name SELECT qr.id,qr.no,it.material_no,it.material_describe,qr.num,it.unit,qr.status,mc.device_no,mc.customer_name,it.material_code_id
FROM wms_shipment_material_code_item_qr qr FROM wms_shipment_material_code_item_qr qr
INNER JOIN wms_shipment_material_code_item it ON qr.item_id=it."id" INNER JOIN wms_shipment_material_code_item it ON qr.item_id=it."id"
INNER JOIN wms_shipment_material_code mc ON mc."id"=it.material_code_id INNER JOIN wms_shipment_material_code mc ON mc."id"=it.material_code_id

View File

@ -12,10 +12,7 @@ import com.nflg.wms.common.pojo.PageData;
import com.nflg.wms.common.pojo.dto.MaterialCodePrintDTO; import com.nflg.wms.common.pojo.dto.MaterialCodePrintDTO;
import com.nflg.wms.common.pojo.dto.MaterialPdfDTO; import com.nflg.wms.common.pojo.dto.MaterialPdfDTO;
import com.nflg.wms.common.pojo.qo.*; import com.nflg.wms.common.pojo.qo.*;
import com.nflg.wms.common.pojo.vo.MaterialPdfVO; import com.nflg.wms.common.pojo.vo.*;
import com.nflg.wms.common.pojo.vo.MaterialItemPrintVO;
import com.nflg.wms.common.pojo.vo.ShipmentMaterialCodeQRVO;
import com.nflg.wms.common.pojo.vo.ShipmentMaterialCodeItemVO;
import com.nflg.wms.common.util.EecExcelUtil; import com.nflg.wms.common.util.EecExcelUtil;
import com.nflg.wms.common.util.NumberUtil; import com.nflg.wms.common.util.NumberUtil;
import com.nflg.wms.common.util.UserUtil; import com.nflg.wms.common.util.UserUtil;
@ -763,21 +760,32 @@ public class MaterialCodeController extends BaseController {
* 导出老鼠图PDF * 导出老鼠图PDF
*/ */
@PostMapping("exportPdf") @PostMapping("exportPdf")
public ApiResult<String> exportPdf(HttpServletResponse response, @RequestBody MaterialPdfQO request) throws Exception { public ApiResult<String> exportPdf(HttpServletResponse response, @RequestBody @NotEmpty List<ShipmentMaterialCodeQRVO> list) throws Exception {
List<WmsShipmentMaterialCodeItem> materialCodeIts =materialCodeItemService.lambdaQuery() VUtil.trueThrowBusinessError(CollectionUtil.isEmpty(list)).throwMessage("没有需要导出的数据");
.in(WmsShipmentMaterialCodeItem::getId, request.getMaterialIds()).list();
//根据前端传入的物料ID查询对应的物料编号再查询物料主数据 // list 中提取物料ID明细ID
List<WmsShipmentMaterial> shipmentMaterials = materialService.lambdaQuery() List<Long> materialIds = list.stream()
.in(WmsShipmentMaterial::getNo, materialCodeIts .map(ShipmentMaterialCodeQRVO::getId)
.stream() .filter(Objects::nonNull)
.map(WmsShipmentMaterialCodeItem::getMaterialNo) .toList();
.toList()) VUtil.trueThrowBusinessError(materialIds.isEmpty()).throwMessage("物料ID不能为空");
.list();
//根据前端传入的物料ID查询物料明细 // 根据前端传入的物料ID查询对应的物料编号再查询物料主数据
List<WmsShipmentMaterialCodeItem> materialCodeItems = materialCodeItemService.lambdaQuery() List<WmsShipmentMaterialCodeItem> materialCodeItems = materialCodeItemService.lambdaQuery()
.in(WmsShipmentMaterialCodeItem::getId, request.getMaterialIds()).list(); .in(WmsShipmentMaterialCodeItem::getId, materialIds)
//将主数据转换成PDF需要的DTO列表 .list();
List<MaterialPdfDTO> items = Convert.toList(MaterialPdfDTO.class, materialCodeIts);
List<String> materialNos = materialCodeItems.stream()
.map(WmsShipmentMaterialCodeItem::getMaterialNo)
.distinct()
.toList();
List<WmsShipmentMaterial> shipmentMaterials = materialService.lambdaQuery()
.in(WmsShipmentMaterial::getNo, materialNos)
.list();
// 将主数据转换成PDF需要的DTO列表
List<MaterialPdfDTO> items = Convert.toList(MaterialPdfDTO.class, materialCodeItems);
Map<String, WmsShipmentMaterial> materialMap = shipmentMaterials.stream() Map<String, WmsShipmentMaterial> materialMap = shipmentMaterials.stream()
.collect(Collectors.toMap(WmsShipmentMaterial::getNo, m -> m)); .collect(Collectors.toMap(WmsShipmentMaterial::getNo, m -> m));
for (MaterialPdfDTO dto : items) { for (MaterialPdfDTO dto : items) {
@ -788,7 +796,8 @@ public class MaterialCodeController extends BaseController {
dto.setDrawingNo(mat.getDrawingNo()); dto.setDrawingNo(mat.getDrawingNo());
} }
} }
//计算总重量 = 单个重量 * 数量 累加
// 计算总重量 = 单个重量 * 数量 累加
BigDecimal allWeight = new BigDecimal(0); BigDecimal allWeight = new BigDecimal(0);
for (WmsShipmentMaterialCodeItem temp : materialCodeItems) { for (WmsShipmentMaterialCodeItem temp : materialCodeItems) {
WmsShipmentMaterial material = shipmentMaterials.stream() WmsShipmentMaterial material = shipmentMaterials.stream()
@ -800,10 +809,39 @@ public class MaterialCodeController extends BaseController {
BigDecimal num = temp.getActualNum() == null ? BigDecimal.ZERO : temp.getActualNum(); BigDecimal num = temp.getActualNum() == null ? BigDecimal.ZERO : temp.getActualNum();
allWeight = allWeight.add(weight.multiply(num)); allWeight = allWeight.add(weight.multiply(num));
} }
MaterialPdfVO material = Convert.convert(MaterialPdfVO.class, request);
material.setWeight(allWeight); // list 中获取第一条数据
material.setQrCode(QRCodeUtil.generateQRCodeBase64(request.getNo(), 100, 100)); ShipmentMaterialCodeQRVO firstItem = list.get(0);
//制作pdf
// 根据物料码主表ID查询清单信息清单编号机台编号销售订单号客户名称下单日期
WmsShipmentMaterialCode materialCode = null;
if (firstItem.getMaterialCodeId() != null) {
materialCode = materialCodeService.lambdaQuery()
.select(WmsShipmentMaterialCode::getNo,
WmsShipmentMaterialCode::getDeviceNo,
WmsShipmentMaterialCode::getSoNo,
WmsShipmentMaterialCode::getCustomerName,
WmsShipmentMaterialCode::getOrderDate)
.eq(WmsShipmentMaterialCode::getId, firstItem.getMaterialCodeId())
.one();
}
// 构建表头数据
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); // 总重量
// 用清单编号生成二维码放在红圈位置
String qrCodeNo = materialCode != null ? materialCode.getNo() : firstItem.getNo();
material.setQrCode(QRCodeUtil.generateQRCodeBase64(qrCodeNo, 100, 100));
// 制作pdf
Map<String, Object> variables = new HashMap<>(); Map<String, Object> variables = new HashMap<>();
variables.put("info", material); variables.put("info", material);
variables.put("pages", PdfPageDTO.create(items, 9, new MaterialPdfDTO())); variables.put("pages", PdfPageDTO.create(items, 9, new MaterialPdfDTO()));
@ -827,40 +865,68 @@ public class MaterialCodeController extends BaseController {
* 导出标签图片PDF打印预览 * 导出标签图片PDF打印预览
* *
* @param response HTTP响应 * @param response HTTP响应
* @param ids 物料主数据id列表wms_shipment_material.id * @param list 物料码主表列表
*/ */
@PostMapping("exportToPdf") @PostMapping("exportToPdf")
public void exportToPdf(HttpServletResponse response, @RequestBody @NotEmpty List<Long> ids) throws Exception { public void exportToPdf(HttpServletResponse response, @RequestBody @NotEmpty List<ShipmentMaterialCodeQRVO> list) throws Exception {
// 根据清单ID查询二维码数据 VUtil.trueThrowBusinessError(CollectionUtil.isEmpty(list)).throwMessage("物料数据不存在");
List<ShipmentMaterialCodeQRVO> datas = materialCodeItemQrService.getListVOByCodeIds(ids);
VUtil.trueThrowBusinessError(CollectionUtil.isEmpty(datas)).throwMessage("物料数据不存在");
// 取第一条数据 // 收集所有物料码主表ID
ShipmentMaterialCodeQRVO data = datas.get(0); List<Long> materialCodeIds = list.stream()
.map(ShipmentMaterialCodeQRVO::getId)
.filter(Objects::nonNull)
.toList();
VUtil.trueThrowBusinessError(materialCodeIds.isEmpty()).throwMessage("物料码ID不能为空");
// 根据物料码主表ID查询物料明细包含二维码信息和客户名称
List<ShipmentMaterialCodeQRVO> qrDatas = materialCodeItemQrService.getListVOByCodeIds(materialCodeIds);
VUtil.trueThrowBusinessError(CollectionUtil.isEmpty(qrDatas)).throwMessage("没有需要打印的二维码数据");
// 构建客户名称Map从传入的list中获取key为物料码主表ID
Map<Long, String> customerNameMap = list.stream()
.filter(item -> item.getId() != null && StrUtil.isNotBlank(item.getCustomerName()))
.collect(Collectors.toMap(
ShipmentMaterialCodeQRVO::getId,
ShipmentMaterialCodeQRVO::getCustomerName,
(v1, v2) -> v1
));
// 根据物料编号查询物料图片 // 根据物料编号查询物料图片
Map<String, String> images = materialService.lambdaQuery() Map<String, String> images = materialService.lambdaQuery()
.select(WmsShipmentMaterial::getNo, WmsShipmentMaterial::getImage) .select(WmsShipmentMaterial::getNo, WmsShipmentMaterial::getImage)
.in(WmsShipmentMaterial::getNo, datas.stream().map(ShipmentMaterialCodeQRVO::getMaterialNo).collect(Collectors.toSet())) .in(WmsShipmentMaterial::getNo, qrDatas.stream().map(ShipmentMaterialCodeQRVO::getMaterialNo).collect(Collectors.toSet()))
.list() .list()
.stream() .stream()
.collect(Collectors.toMap(WmsShipmentMaterial::getNo, WmsShipmentMaterial::getImage)); .collect(Collectors.toMap(WmsShipmentMaterial::getNo, WmsShipmentMaterial::getImage));
// 构建打印数据 // 构建打印数据
Map<String, Object> variables = new HashMap<>(); Map<String, Object> variables = new HashMap<>();
List<Map<String, Object>> printList = new ArrayList<>();
Map<String, Object> info = new HashMap<>(); for (ShipmentMaterialCodeQRVO item : qrDatas) {
info.put("no", data.getNo()); // 优先使用从list中获取的客户名称如果没有则使用SQL查询的customerName
info.put("materialNo", data.getMaterialNo()); String customerName = customerNameMap.get(item.getMaterialCodeId());
info.put("numText", data.getNumText()); if (StrUtil.isBlank(customerName)) {
info.put("customerName", data.getCustomerName()); customerName = item.getCustomerName();
}
Map<String, String> ext = new HashMap<>(); Map<String, Object> info = new HashMap<>();
ext.put("qrCode", QRCodeUtil.generateQRCodeBase64(data.getNo(), 200, 200)); info.put("no", item.getNo());
ext.put("lst", images.get(data.getMaterialNo())); info.put("materialNo", item.getMaterialNo());
info.put("numText", item.getNumText());
info.put("customerName", customerName);
variables.put("info", info); Map<String, String> ext = new HashMap<>();
variables.put("ext", ext); ext.put("qrCode", QRCodeUtil.generateQRCodeBase64(item.getNo(), 200, 200));
ext.put("lst", QRCodeUtil.imageUrlToBase64(images.get(item.getMaterialNo())));
Map<String, Object> printData = new HashMap<>();
printData.put("info", info);
printData.put("ext", ext);
printList.add(printData);
}
variables.put("list", printList);
String html = ThymeleafUtil.generator("/template/label/", "material-pdf", ".html", variables); String html = ThymeleafUtil.generator("/template/label/", "material-pdf", ".html", variables);
URL baseUrl = new ClassPathResource("template/label/").getURL(); URL baseUrl = new ClassPathResource("template/label/").getURL();
@ -871,43 +937,83 @@ public class MaterialCodeController extends BaseController {
* 根据明细ID导出物料明细PDF打印预览 * 根据明细ID导出物料明细PDF打印预览
* *
* @param response HTTP响应 * @param response HTTP响应
* @param ids 明细id列表wms_shipment_material_code_item.id * @param list 物料明细列表包含qrCodes二维码数组
*/ */
@PostMapping("exportItemToPdf") @PostMapping("exportItemToPdf")
public void exportItemToPdf(HttpServletResponse response, @RequestBody @NotEmpty List<Long> ids) throws Exception { public void exportItemToPdf(HttpServletResponse response, @RequestBody @NotEmpty List<ShipmentMaterialCodeQRVO> list) throws Exception {
// 根据明细ID查询数据 VUtil.trueThrowBusinessError(CollectionUtil.isEmpty(list)).throwMessage("没有需要导出的数据");
List<ShipmentMaterialCodeQRVO> datas = materialCodeItemQrService.getListVOByItemIds(ids);
VUtil.trueThrowBusinessError(CollectionUtil.isEmpty(datas)).throwMessage("没有需要导出的数据");
// 取第一条数据 // 收集所有二维码编号
ShipmentMaterialCodeQRVO data = datas.get(0); List<String> allQrCodes = new ArrayList<>();
for (ShipmentMaterialCodeQRVO item : list) {
if (item.getQrCodes() != null && !item.getQrCodes().isEmpty()) {
allQrCodes.addAll(item.getQrCodes());
}
}
VUtil.trueThrowBusinessError(allQrCodes.isEmpty()).throwMessage("没有需要打印的二维码");
// 根据物料码主表ID查询客户名称
Set<Long> materialCodeIds = list.stream()
.map(ShipmentMaterialCodeQRVO::getMaterialCodeId)
.filter(Objects::nonNull)
.collect(Collectors.toSet());
Map<Long, String> customerNameMap = new HashMap<>();
if (!materialCodeIds.isEmpty()) {
customerNameMap = materialCodeService.lambdaQuery()
.select(WmsShipmentMaterialCode::getId, WmsShipmentMaterialCode::getCustomerName)
.in(WmsShipmentMaterialCode::getId, materialCodeIds)
.list()
.stream()
.collect(Collectors.toMap(WmsShipmentMaterialCode::getId, WmsShipmentMaterialCode::getCustomerName));
}
// 根据物料编号查询物料图片 // 根据物料编号查询物料图片
Map<String, String> images = materialService.lambdaQuery() Map<String, String> images = materialService.lambdaQuery()
.select(WmsShipmentMaterial::getNo, WmsShipmentMaterial::getImage) .select(WmsShipmentMaterial::getNo, WmsShipmentMaterial::getImage)
.in(WmsShipmentMaterial::getNo, datas.stream().map(ShipmentMaterialCodeQRVO::getMaterialNo).collect(Collectors.toSet())) .in(WmsShipmentMaterial::getNo, list.stream().map(ShipmentMaterialCodeQRVO::getMaterialNo).collect(Collectors.toSet()))
.list() .list()
.stream() .stream()
.collect(Collectors.toMap(WmsShipmentMaterial::getNo, WmsShipmentMaterial::getImage)); .collect(Collectors.toMap(WmsShipmentMaterial::getNo, WmsShipmentMaterial::getImage));
// 构建打印数据 // 构建打印数据支持多个二维码生成多页
Map<String, Object> variables = new HashMap<>(); Map<String, Object> variables = new HashMap<>();
List<Map<String, Object>> printList = new ArrayList<>();
Map<String, Object> info = new HashMap<>(); for (ShipmentMaterialCodeQRVO item : list) {
info.put("no", data.getNo()); if (item.getQrCodes() == null || item.getQrCodes().isEmpty()) {
info.put("materialNo", data.getMaterialNo()); continue;
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)); String customerName = customerNameMap.get(item.getMaterialCodeId());
ext.put("lst", images.get(data.getMaterialNo()));
variables.put("info", info); for (String qrCode : item.getQrCodes()) {
variables.put("ext", ext); Map<String, Object> info = new HashMap<>();
info.put("no", qrCode);
info.put("materialNo", item.getMaterialNo());
info.put("numText", item.getNumText());
info.put("customerName", customerName);
Map<String, String> ext = new HashMap<>();
ext.put("qrCode", QRCodeUtil.generateQRCodeBase64(qrCode, 200, 200));
ext.put("lst", QRCodeUtil.imageUrlToBase64(images.get(item.getMaterialNo())));
Map<String, Object> printData = new HashMap<>();
printData.put("info", info);
printData.put("ext", ext);
printList.add(printData);
}
}
variables.put("list", printList);
// 生成 PDF
String html = ThymeleafUtil.generator("/template/label/", "material-pdf", ".html", variables); String html = ThymeleafUtil.generator("/template/label/", "material-pdf", ".html", variables);
URL baseUrl = new ClassPathResource("template/label/").getURL(); ClassPathResource resource = new ClassPathResource("template/label/");
PdfGeneratorUtil.generatePdf("物料明细标签", html, baseUrl.toString(), response); VUtil.trueThrowBusinessError(!resource.exists()).throwMessage("PDF模板不存在");
URL baseUrl = resource.getURL();
PdfGeneratorUtil.generatePdf("物料标签", html, baseUrl.toString(), response);
} }
} }

View File

@ -415,21 +415,34 @@ public class PackagingCodeController extends BaseController {
*/ */
@PostMapping("exportToPdf") @PostMapping("exportToPdf")
public void exportToPdf(HttpServletResponse response, @RequestBody @NotEmpty List<ShipmentPackagingCodeVO> list) throws Exception { public void exportToPdf(HttpServletResponse response, @RequestBody @NotEmpty List<ShipmentPackagingCodeVO> list) throws Exception {
List<Long> ids = list.stream()
.map(ShipmentPackagingCodeVO::getId)
.filter(Objects::nonNull)
.toList();
VUtil.trueThrowBusinessError(CollectionUtil.isEmpty(ids)).throwMessage("ID不能为空");
// 根据ID列表查询包装码数据
List<WmsShipmentPackagingCode> packagingCodes = packagingCodeService.lambdaQuery()
.in(WmsShipmentPackagingCode::getId,ids)
.list();
VUtil.trueThrowBusinessError(CollectionUtil.isEmpty(packagingCodes)).throwMessage("包装码数据不存在");
// 查询包装类型字典
List<DictionaryItem> types = dictionaryItemService.getListByDictionaryCode("PackagingType"); List<DictionaryItem> types = dictionaryItemService.getListByDictionaryCode("PackagingType");
Map<Long, String> typeMap = types.stream()
.collect(Collectors.toMap(DictionaryItem::getId, DictionaryItem::getName));
// 构建打印数据 // 构建打印数据
Map<String, Object> variables = new HashMap<>(); Map<String, Object> variables = new HashMap<>();
variables.put("list", list.stream() variables.put("list", packagingCodes.stream()
.map(data -> { .map(code -> {
ShipmentPackagingCodeVO vo = new ShipmentPackagingCodeVO(); ShipmentPackagingCodeVO vo = new ShipmentPackagingCodeVO();
vo.setNo(data.getNo()); vo.setNo(code.getNo());
vo.setName(data.getName()); vo.setName(code.getName());
vo.setTypeName(types.stream() vo.setTypeName(typeMap.getOrDefault(code.getType(), ""));
.filter(type -> type.getId().equals(data.getType())) vo.setQrCode(QRCodeUtil.generateQRCodeBase64(code.getNo(), 100, 100));
.map(DictionaryItem::getName)
.findFirst()
.orElse(""));
vo.setQrCode(QRCodeUtil.generateQRCodeBase64(data.getNo(), 100, 100));
return vo; return vo;
}).toList() }).toList()
); );

View File

@ -8,6 +8,8 @@ import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.net.URL;
import java.util.Base64; import java.util.Base64;
import java.util.Hashtable; import java.util.Hashtable;
@ -38,4 +40,22 @@ public class QRCodeUtil {
} }
} }
public static String imageUrlToBase64(String imageUrl) {
if (imageUrl == null || imageUrl.isBlank()) {
return null;
}
try (InputStream in = new URL(imageUrl).openStream();
ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
byte[] buf = new byte[4096];
int n;
while ((n = in.read(buf)) != -1) {
baos.write(buf, 0, n);
}
String ext = imageUrl.toLowerCase().contains(".png") ? "png" : "jpeg";
return "data:image/" + ext + ";base64," + Base64.getEncoder().encodeToString(baos.toByteArray());
} catch (Exception ignored) {
return null;
}
}
} }

View File

@ -6,30 +6,51 @@
<meta content="width=device-width, initial-scale=1.0" name="viewport"/> <meta content="width=device-width, initial-scale=1.0" name="viewport"/>
<style> <style>
@page { @page {
size: 1200px 800px; size: 1000px 500px;
margin: 0; margin: 0;
} }
body { body {
width: 1200px; font-size: 11pt;
height: 800px;
font-size: 20pt;
font-family: SimSun, Arial, sans-serif; font-family: SimSun, Arial, sans-serif;
margin: 0; margin: 0;
padding: 0; padding: 0;
} }
.label-page {
width: 1000px;
height: 500px;
display: table;
page-break-after: always;
}
.label-page:last-child {
page-break-after: auto;
}
.label-center {
display: table-cell;
width: 1000px;
vertical-align: middle;
text-align: center;
}
.label-content {
display: inline-block;
margin: 0 auto;
}
table { table {
width: 1200px; width: 900px;
height: 800px;
border: 3px solid #000; border: 3px solid #000;
border-collapse: collapse; border-collapse: collapse;
table-layout: fixed; table-layout: fixed;
margin: 0 auto;
} }
th, td { th, td {
border: 3px solid #000; border: 3px solid #000;
padding: 10px; padding: 4px;
text-align: center; text-align: center;
vertical-align: middle; vertical-align: middle;
word-wrap: break-word; word-wrap: break-word;
@ -37,54 +58,61 @@
} }
.qrcode { .qrcode {
width: 380px; width: 160px;
height: 380px; height: 160px;
} }
.lst{ .lst{
width: 800px; max-width: 480px;
height: auto; width: auto;
height: 220px;
} }
</style> </style>
</head> </head>
<body> <body>
<table> <div class="label-page" th:each="item, iterStat : ${list}">
<tr> <div class="label-center">
<td style="text-align: center; width: 400px" rowspan="3"> <div class="label-content">
<img alt="" class="qrcode" th:src="${ext.qrCode}"/> <table>
<div style="font-size: 16pt" th:text="${info.no}">0PC7B724KV6FM</div> <tr>
</td> <td style="text-align: center; width: 200px" rowspan="3">
<td style="width: 140px;"> <img alt="" class="qrcode" th:src="${item.ext.qrCode}"/>
机台编号 <div style="font-size: 16pt" th:text="${item.info.no}">0PC7B724KV6FM</div>
</td> </td>
<td style="width: 200px;" th:text="${info.no}"> <td style="width: 140px;">
26LBZ4000L001 机台编号
</td> </td>
<td style="width: 140px;"> <td style="width: 200px;" th:text="${item.info.no}">
客户名称 26LBZ4000L001
</td> </td>
<td style="text-align: left" th:text="${info.customerName}"> <td style="width: 140px;">
北京市京联鑫路用材料有限公司 客户名称
</td> </td>
</tr> <td style="text-align: center" th:text="${item.info.customerName}">
<tr> 北京市京联鑫路用材料有限公司
<td> </td>
物料编码 </tr>
</td> <tr>
<td th:text="${info.materialNo}"> <td>
3100006701 物料编码
</td> </td>
<td> <td th:text="${item.info.materialNo}">
数量 3100006701
</td> </td>
<td th:text="${info.numText}"> <td>
10 数量
</td> </td>
</tr> <td th:text="${item.info.numText}">
<tr> 10
<td colspan="4"> </td>
<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}"/> </tr>
</td> <tr>
</tr> <td colspan="4">
</table> <img alt="" class="lst" th:src="${item.ext.lst}"/>
</td>
</tr>
</table>
</div>
</div>
</div>
</body> </body>
</html> </html>

View File

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