1463 WMS系统钢构包采购业务功能优化
This commit is contained in:
parent
ea971332cc
commit
03cda3e193
|
|
@ -211,12 +211,33 @@ public class StructuralPackageOrderController extends BaseController {
|
||||||
: supplierCode;
|
: supplierCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 构建托盘号前缀:S+供应商代码后4位+年后2位+月2位+日2位
|
||||||
|
String trayPrefix = "S" + supplierSuffix + datePart;
|
||||||
|
|
||||||
|
// 查询数据库中该前缀的最新托盘号,获取当前最大流水号
|
||||||
|
int startSeq = 1;
|
||||||
|
String lastTrayNo = structuralPackageOrderTrayService.getLast(trayPrefix);
|
||||||
|
if (StrUtil.isNotBlank(lastTrayNo)) {
|
||||||
|
// 从托盘号中提取流水号(格式:Sxxxxxx-序号)
|
||||||
|
int lastDashIndex = lastTrayNo.lastIndexOf('-');
|
||||||
|
if (lastDashIndex > 0 && lastDashIndex < lastTrayNo.length() - 1) {
|
||||||
|
try {
|
||||||
|
String seqStr = lastTrayNo.substring(lastDashIndex + 1);
|
||||||
|
startSeq = Integer.parseInt(seqStr) + 1;
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
// 如果解析失败,从1开始
|
||||||
|
startSeq = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
List<TrayVO> trays = new ArrayList<>();
|
List<TrayVO> trays = new ArrayList<>();
|
||||||
|
|
||||||
// 根据托盘数量生成托盘
|
// 根据托盘数量生成托盘,使用数据库最新流水号+1开始
|
||||||
for (int i = 1; i <= trayNum; i++) {
|
for (int i = 0; i < trayNum; i++) {
|
||||||
|
int currentSeq = startSeq + i;
|
||||||
// 生成托盘号:S+供应商代码后4位+年后2位+月2位+日2位-序号
|
// 生成托盘号:S+供应商代码后4位+年后2位+月2位+日2位-序号
|
||||||
String generatedTrayNo = "S" + supplierSuffix + datePart + "-" + i;
|
String generatedTrayNo = trayPrefix + "-" + currentSeq;
|
||||||
|
|
||||||
TrayVO tray = new TrayVO()
|
TrayVO tray = new TrayVO()
|
||||||
.setNo(generatedTrayNo)
|
.setNo(generatedTrayNo)
|
||||||
|
|
@ -684,8 +705,10 @@ public class StructuralPackageOrderController extends BaseController {
|
||||||
List<WmsStructuralPackageOrderTray> trays = structuralPackageOrderTrayService.getList(id);
|
List<WmsStructuralPackageOrderTray> trays = structuralPackageOrderTrayService.getList(id);
|
||||||
VUtil.trueThrowBusinessError(CollectionUtil.isEmpty(trays)).throwMessage("数据不存在");
|
VUtil.trueThrowBusinessError(CollectionUtil.isEmpty(trays)).throwMessage("数据不存在");
|
||||||
|
|
||||||
// 这里需要为订单下的所有托盘生成标签
|
// 收集所有托盘的HTML内容
|
||||||
// 由于原方法只处理单个托盘,现在需要遍历所有托盘
|
List<String> htmlList = new ArrayList<>();
|
||||||
|
|
||||||
|
// 遍历所有托盘,生成每个托盘的HTML内容
|
||||||
for (WmsStructuralPackageOrderTray tray : trays) {
|
for (WmsStructuralPackageOrderTray tray : trays) {
|
||||||
DeliverStructuralPackageOrderExtendVO trayVO = structuralPackageOrderTrayService.getInfo(tray.getId());
|
DeliverStructuralPackageOrderExtendVO trayVO = structuralPackageOrderTrayService.getInfo(tray.getId());
|
||||||
VUtil.trueThrowBusinessError(Objects.isNull(trayVO)).throwMessage("数据不存在");
|
VUtil.trueThrowBusinessError(Objects.isNull(trayVO)).throwMessage("数据不存在");
|
||||||
|
|
@ -693,10 +716,11 @@ public class StructuralPackageOrderController extends BaseController {
|
||||||
Map<String, Object> variables = new HashMap<>();
|
Map<String, Object> variables = new HashMap<>();
|
||||||
variables.put("info", trayVO);
|
variables.put("info", trayVO);
|
||||||
String html = ThymeleafUtil.generator("/template/qrcode/", "tray", ".html", variables);
|
String html = ThymeleafUtil.generator("/template/qrcode/", "tray", ".html", variables);
|
||||||
URL baseUrl = new ClassPathResource("template/qrcode/").getURL();
|
htmlList.add(html);
|
||||||
// 注意:这里会多次调用response,实际使用时可能需要合并PDF或返回ZIP
|
|
||||||
PdfGeneratorUtil.generatePdf("托盘标签" + trayVO.getTrayNo(), html, baseUrl.toString(), response);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 将所有托盘标签合并成一个PDF文件,每页一个标签
|
||||||
|
PdfGeneratorUtil.generatePdf("托盘标签", htmlList, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -726,7 +750,7 @@ public class StructuralPackageOrderController extends BaseController {
|
||||||
*/
|
*/
|
||||||
@GetMapping("exportQiTaoPdf")
|
@GetMapping("exportQiTaoPdf")
|
||||||
public void exportQiTaoPdf(HttpServletResponse response, @Valid @RequestParam @NotNull Long id) throws Exception {
|
public void exportQiTaoPdf(HttpServletResponse response, @Valid @RequestParam @NotNull Long id) throws Exception {
|
||||||
// 根据订单ID获取所有托盘,为每个托盘生成齐套标签
|
// 根据订单ID获取所有托盘
|
||||||
List<WmsStructuralPackageOrderTray> trays = structuralPackageOrderTrayService.getList(id);
|
List<WmsStructuralPackageOrderTray> trays = structuralPackageOrderTrayService.getList(id);
|
||||||
VUtil.trueThrowBusinessError(CollectionUtil.isEmpty(trays)).throwMessage("数据不存在");
|
VUtil.trueThrowBusinessError(CollectionUtil.isEmpty(trays)).throwMessage("数据不存在");
|
||||||
|
|
||||||
|
|
@ -737,18 +761,17 @@ public class StructuralPackageOrderController extends BaseController {
|
||||||
List<WmsQrCodeMaster> codes = qrCodeMasterService.getByExtendId(id);
|
List<WmsQrCodeMaster> codes = qrCodeMasterService.getByExtendId(id);
|
||||||
VUtil.trueThrowBusinessError(CollectionUtil.isEmpty(codes)).throwMessage("未找到二维码信息");
|
VUtil.trueThrowBusinessError(CollectionUtil.isEmpty(codes)).throwMessage("未找到二维码信息");
|
||||||
|
|
||||||
// 为每个托盘生成齐套标签
|
// 注意:齐套标签内容基于订单信息(外部订单号、行号、包号),同一订单下所有托盘的标签内容相同
|
||||||
for (WmsStructuralPackageOrderTray tray : trays) {
|
// 因此只需取第一个托盘生成一个标签即可
|
||||||
DeliverStructuralPackageOrderExtendVO trayVO = structuralPackageOrderTrayService.getInfo(tray.getId());
|
DeliverStructuralPackageOrderExtendVO trayVO = structuralPackageOrderTrayService.getInfo(trays.get(0).getId());
|
||||||
VUtil.trueThrowBusinessError(Objects.isNull(trayVO)).throwMessage("数据不存在");
|
VUtil.trueThrowBusinessError(Objects.isNull(trayVO)).throwMessage("数据不存在");
|
||||||
String temp = trayVO.getExternalOrderNo() + "$" + trayVO.getRowNo() + "$" + trayVO.getPackageNo();
|
String temp = trayVO.getExternalOrderNo() + "$" + trayVO.getRowNo() + "$" + trayVO.getPackageNo();
|
||||||
trayVO.setQrCode(QRCodeUtil.generateQRCodeBase64(codes.get(0).getBarcodeCode() + "$" + temp, 100, 100));
|
trayVO.setQrCode(QRCodeUtil.generateQRCodeBase64(codes.get(0).getBarcodeCode() + "$" + temp, 100, 100));
|
||||||
Map<String, Object> variables = new HashMap<>();
|
Map<String, Object> variables = new HashMap<>();
|
||||||
variables.put("info", trayVO);
|
variables.put("info", trayVO);
|
||||||
String html = ThymeleafUtil.generator("/template/qrcode/", "qitao", ".html", variables);
|
String html = ThymeleafUtil.generator("/template/qrcode/", "qitao", ".html", variables);
|
||||||
URL baseUrl = new ClassPathResource("template/qrcode/").getURL();
|
|
||||||
PdfGeneratorUtil.generatePdf("齐套标签" + trayVO.getTrayNo(), html, baseUrl.toString(), response);
|
PdfGeneratorUtil.generatePdf("齐套标签", html, response);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -1489,53 +1512,90 @@ public class StructuralPackageOrderController extends BaseController {
|
||||||
BigDecimal trayNumDecimal = request.getTrayNum();
|
BigDecimal trayNumDecimal = request.getTrayNum();
|
||||||
VUtil.trueThrowBusinessError(trayNumDecimal == null || trayNumDecimal.compareTo(BigDecimal.ZERO) <= 0)
|
VUtil.trueThrowBusinessError(trayNumDecimal == null || trayNumDecimal.compareTo(BigDecimal.ZERO) <= 0)
|
||||||
.throwMessage("托盘数量必须大于0");
|
.throwMessage("托盘数量必须大于0");
|
||||||
Integer trayNum = trayNumDecimal.intValue();
|
Integer newTrayNum = trayNumDecimal.intValue();
|
||||||
|
|
||||||
// 4. 获取钢构包信息
|
// 4. 获取数据库中当前的托盘列表
|
||||||
|
List<WmsStructuralPackageOrderTray> existingTrays = structuralPackageOrderTrayService.getList(order.getId());
|
||||||
|
int existingTrayCount = existingTrays.size();
|
||||||
|
|
||||||
|
// 5. 校验新传入的托盘数量必须比数据库中的大
|
||||||
|
VUtil.trueThrowBusinessError(newTrayNum <= existingTrayCount)
|
||||||
|
.throwMessage("新托盘数量必须大于当前托盘数量(" + existingTrayCount + ")");
|
||||||
|
|
||||||
|
// 6. 计算需要新增的托盘数量
|
||||||
|
int addTrayCount = newTrayNum - existingTrayCount;
|
||||||
|
|
||||||
|
// 7. 获取钢构包信息
|
||||||
PackageVO packageVO = structuralPackageService.getInfo(order.getPackageId());
|
PackageVO packageVO = structuralPackageService.getInfo(order.getPackageId());
|
||||||
VUtil.trueThrowBusinessError(Objects.isNull(packageVO)).throwMessage("钢构包不存在");
|
VUtil.trueThrowBusinessError(Objects.isNull(packageVO)).throwMessage("钢构包不存在");
|
||||||
|
|
||||||
// 5. 获取供应商代码
|
// 8. 获取供应商代码
|
||||||
UserSupplier supplier = userSupplierService.getById(order.getSupplierId());
|
UserSupplier supplier = userSupplierService.getById(order.getSupplierId());
|
||||||
VUtil.trueThrowBusinessError(Objects.isNull(supplier)).throwMessage("供应商不存在");
|
VUtil.trueThrowBusinessError(Objects.isNull(supplier)).throwMessage("供应商不存在");
|
||||||
String supplierCode = supplier.getSupplierCode();
|
String supplierCode = supplier.getSupplierCode();
|
||||||
|
|
||||||
// 6. 重新生成托盘信息(使用前端传入的托盘数量)
|
// 9. 生成日期部分:年后2位+月2位+日2位
|
||||||
GenerateTrayVO trayVO = generateTrayWithTrayNum(packageVO, supplierCode,
|
LocalDate now = LocalDate.now();
|
||||||
BigDecimal.valueOf(order.getNum()), order.getPlanNum(), trayNum);
|
String datePart = String.format("%02d%02d%02d",
|
||||||
|
now.getYear() % 100,
|
||||||
|
now.getMonthValue(),
|
||||||
|
now.getDayOfMonth());
|
||||||
|
|
||||||
// 7. 删除旧的托盘和托盘项
|
// 10. 供应商代码后4位
|
||||||
structuralPackageOrderTrayService.deleteByOrderId(order.getId());
|
String supplierSuffix = "";
|
||||||
structuralPackageOrderTrayItemService.deleteByOrderId(order.getId());
|
if (StrUtil.isNotBlank(supplierCode)) {
|
||||||
|
supplierSuffix = supplierCode.length() >= 4
|
||||||
|
? supplierCode.substring(supplierCode.length() - 4)
|
||||||
|
: supplierCode;
|
||||||
|
}
|
||||||
|
|
||||||
// 8. 保存新的托盘信息
|
// 11. 构建托盘号前缀:S+供应商代码后4位+年后2位+月2位+日2位
|
||||||
List<WmsStructuralPackageOrderTray> trays = trayVO.getTrays().stream().map(it -> new WmsStructuralPackageOrderTray()
|
String trayPrefix = "S" + supplierSuffix + datePart;
|
||||||
.setId(IdUtil.getSnowflakeNextId())
|
|
||||||
.setOrderId(order.getId())
|
|
||||||
.setNo(it.getNo())
|
|
||||||
.setWeight(BigDecimal.ZERO)
|
|
||||||
.setNum(BigDecimal.ZERO)
|
|
||||||
.setStation(it.getStation())
|
|
||||||
.setTray(it.getTray())).toList();
|
|
||||||
|
|
||||||
List<WmsStructuralPackageOrderTrayItem> items = new ArrayList<>();
|
// 12. 查询数据库中该前缀的最新托盘号,获取当前最大流水号
|
||||||
trays.forEach(tray -> {
|
int startSeq = 1;
|
||||||
List<TrayItemVO> itemVOS = trayVO.getItems().stream()
|
String lastTrayNo = structuralPackageOrderTrayService.getLast(trayPrefix);
|
||||||
.filter(it -> StrUtil.equals(it.getNo(), tray.getNo()))
|
if (StrUtil.isNotBlank(lastTrayNo)) {
|
||||||
.toList();
|
// 从托盘号中提取流水号(格式:Sxxxxxx-序号)
|
||||||
items.addAll(itemVOS.stream().map(it -> {
|
int lastDashIndex = lastTrayNo.lastIndexOf('-');
|
||||||
WmsStructuralPackageOrderTrayItem item = Convert.convert(WmsStructuralPackageOrderTrayItem.class, it);
|
if (lastDashIndex > 0 && lastDashIndex < lastTrayNo.length() - 1) {
|
||||||
item.setOrderId(order.getId());
|
try {
|
||||||
item.setTrayId(tray.getId());
|
String seqStr = lastTrayNo.substring(lastDashIndex + 1);
|
||||||
tray.setNum(tray.getNum().add(item.getShipmentNum()));
|
startSeq = Integer.parseInt(seqStr) + 1;
|
||||||
tray.setWeight(tray.getWeight().add(NumberUtil.mul(it.getWeight(), item.getShipmentNum())));
|
} catch (NumberFormatException e) {
|
||||||
return item;
|
// 如果解析失败,从1开始
|
||||||
}).toList()
|
startSeq = 1;
|
||||||
);
|
}
|
||||||
});
|
}
|
||||||
|
}
|
||||||
|
|
||||||
structuralPackageOrderTrayService.saveBatch(trays);
|
// 13. 保留原有托盘,只生成新增的托盘
|
||||||
structuralPackageOrderTrayItemService.saveBatch(items);
|
List<WmsStructuralPackageOrderTray> traysToKeep = new ArrayList<>(existingTrays);
|
||||||
|
List<WmsStructuralPackageOrderTray> traysToAdd = new ArrayList<>();
|
||||||
|
|
||||||
|
// 生成新增的托盘
|
||||||
|
for (int i = 0; i < addTrayCount; i++) {
|
||||||
|
int currentSeq = startSeq + i;
|
||||||
|
String generatedTrayNo = trayPrefix + "-" + currentSeq;
|
||||||
|
|
||||||
|
WmsStructuralPackageOrderTray newTray = new WmsStructuralPackageOrderTray()
|
||||||
|
.setId(IdUtil.getSnowflakeNextId())
|
||||||
|
.setOrderId(order.getId())
|
||||||
|
.setNo(generatedTrayNo)
|
||||||
|
.setWeight(BigDecimal.ZERO)
|
||||||
|
.setNum(BigDecimal.ZERO)
|
||||||
|
.setStation("")
|
||||||
|
.setTray("");
|
||||||
|
traysToAdd.add(newTray);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 14. 合并所有托盘(原有 + 新增)
|
||||||
|
List<WmsStructuralPackageOrderTray> allTrays = new ArrayList<>();
|
||||||
|
allTrays.addAll(traysToKeep);
|
||||||
|
allTrays.addAll(traysToAdd);
|
||||||
|
|
||||||
|
// 15. 保存所有托盘
|
||||||
|
structuralPackageOrderTrayService.saveOrUpdateBatch(allTrays);
|
||||||
|
|
||||||
return ApiResult.success();
|
return ApiResult.success();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue