feat(order): 根据订单ID导出零件标签图片ZIP文件
- 新增接口根据订单id导出零件标签图片的ZIP压缩包 - 直接通过订单ID获取物料项列表,简化标签生成流程 - 生成每个物料项对应的二维码及二维码图片 - 支持物料项数量的分批标签生成,包括小数部分拆分 - 使用Base62编码生成二维码ID,保证唯一性 - 设置响应头返回ZIP格式文件,提高前端下载体验 - readme文档补充wkhtmltoimage在不同系统上的安装方法
This commit is contained in:
parent
8b75fb3a27
commit
25a88cbeb7
|
|
@ -2136,4 +2136,51 @@ public class StructuralPackageOrderController extends BaseController {
|
||||||
URL baseUrl = new ClassPathResource("template/").getURL();
|
URL baseUrl = new ClassPathResource("template/").getURL();
|
||||||
PdfGeneratorUtil.generatePdf("钢构件老鼠图", html, baseUrl.toString(), response);
|
PdfGeneratorUtil.generatePdf("钢构件老鼠图", html, baseUrl.toString(), response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据订单id导出零件标签图片ZIP
|
||||||
|
* @param id 订单id
|
||||||
|
*/
|
||||||
|
@GetMapping(value = "exportItemImageZipByOrderId", produces = "application/zip")
|
||||||
|
public ResponseEntity<byte[]> exportItemImageZipByOrderId(@Valid @RequestParam @NotNull Long id) throws Exception {
|
||||||
|
// 获取订单信息
|
||||||
|
DeliverStructuralPackageOrderVO orderVO = structuralPackageOrderService.getInfo(id);
|
||||||
|
VUtil.trueThrowBusinessError(Objects.isNull(orderVO)).throwMessage("数据不存在");
|
||||||
|
|
||||||
|
// 获取第一个托盘信息用于生成标签
|
||||||
|
List<WmsStructuralPackageOrderTray> trays = structuralPackageOrderTrayService.getList(id);
|
||||||
|
VUtil.trueThrowBusinessError(CollectionUtil.isEmpty(trays)).throwMessage("数据不存在");
|
||||||
|
DeliverStructuralPackageOrderExtendVO trayVO = structuralPackageOrderTrayService.getInfo(trays.get(0).getId());
|
||||||
|
|
||||||
|
// 直接根据订单ID获取物料项列表,不再依赖托盘关联
|
||||||
|
List<DeliverStructuralPackageOrderTrayItemVO> list = structuralPackageOrderTrayItemService.getListVOByOrderId(id);
|
||||||
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
|
try (ZipOutputStream zos = new ZipOutputStream(baos)) {
|
||||||
|
int index = 0;
|
||||||
|
for (DeliverStructuralPackageOrderTrayItemVO it : list) {
|
||||||
|
it.setSupplierCode(trayVO.getSupplierCode());
|
||||||
|
index++;
|
||||||
|
String code = Base62Util.encode(it.getId());
|
||||||
|
for (int i = 0, count = it.getShipmentNum().intValue(); i < count; i++) {
|
||||||
|
DeliverStructuralPackageOrderTrayItemVO vo = BeanUtil.copy(it, DeliverStructuralPackageOrderTrayItemVO.class);
|
||||||
|
vo.setQrCodeId(code + "-" + (i + 1));
|
||||||
|
vo.setQrCode(vo.getQrCodeId() + "^" + it.getMaterialNo() + "_1");
|
||||||
|
vo.setQrCodeImage(QRCodeUtil.generateQRCodeBase64(vo.getQrCode(), 200, 200));
|
||||||
|
addEntry(zos, index, vo);
|
||||||
|
}
|
||||||
|
if (it.getShipmentNum().remainder(BigDecimal.ONE).compareTo(BigDecimal.ZERO) > 0) {
|
||||||
|
DeliverStructuralPackageOrderTrayItemVO vo = BeanUtil.copy(it, DeliverStructuralPackageOrderTrayItemVO.class);
|
||||||
|
vo.setQrCodeId(code + "-" + (it.getShipmentNum().intValue() + 1));
|
||||||
|
vo.setQrCode(vo.getQrCodeId() + "^" + it.getMaterialNo() + "_" + it.getShipmentNum().remainder(BigDecimal.ONE));
|
||||||
|
vo.setQrCodeImage(QRCodeUtil.generateQRCodeBase64(vo.getQrCode(), 200, 200));
|
||||||
|
addEntry(zos, index, vo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
byte[] zipBytes = baos.toByteArray();
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.setContentType(MediaType.valueOf("application/zip"));
|
||||||
|
headers.setContentLength(zipBytes.length);
|
||||||
|
return new ResponseEntity<>(zipBytes, headers, HttpStatus.OK);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
11
readme.md
11
readme.md
|
|
@ -1,10 +1,19 @@
|
||||||
## 需要安装的软件
|
## 需要安装的软件
|
||||||
|
|
||||||
- wkhtmltoimage
|
### wkhtmltoimage
|
||||||
|
|
||||||
> 用于将HTML转为图片,打印标签需要
|
> 用于将HTML转为图片,打印标签需要
|
||||||
|
|
||||||
|
- CentOS 7
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox-0.12.6-1.centos7.x86_64.rpm
|
wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox-0.12.6-1.centos7.x86_64.rpm
|
||||||
yum localinstall wkhtmltox-0.12.6-1.centos7.x86_64.rpm
|
yum localinstall wkhtmltox-0.12.6-1.centos7.x86_64.rpm
|
||||||
|
```
|
||||||
|
|
||||||
|
- AlmaLinux 9
|
||||||
|
|
||||||
|
```bash
|
||||||
|
wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6.1-2/wkhtmltox-0.12.6.1-2.almalinux9.x86_64.rpm
|
||||||
|
yum localinstall wkhtmltox-0.12.6.1-2.almalinux9.x86_64.rpm
|
||||||
```
|
```
|
||||||
Loading…
Reference in New Issue