From 3fd61b2386021218909e0211b647cbd63f270f76 Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期五, 27 三月 2026 15:53:48 +0800
Subject: [PATCH] feat: 销售发货单打印
---
src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java | 126 ++++++++++++++++++++++++++++++++++++++++++
1 files changed, 126 insertions(+), 0 deletions(-)
diff --git a/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java b/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
index e5dd539..025fe60 100644
--- a/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
+++ b/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
@@ -1180,6 +1180,132 @@
return dto;
}
+ @Override
+ public SalesInvoicesDto salesInvoices(List<Long> salesLedgerIds) {
+ if (CollectionUtils.isEmpty(salesLedgerIds)) {
+ throw new ServiceException("閿�鍞彂璐у崟鎵撳嵃澶辫触,閿�鍞鍗曚笉鑳戒负绌�");
+ }
+
+ List<SalesLedger> ledgers = salesLedgerMapper.selectBatchIds(salesLedgerIds);
+ if (CollectionUtils.isEmpty(ledgers)) {
+ throw new ServiceException("閿�鍞彂璐у崟鎵撳嵃澶辫触,鏈壘鍒板搴斿彴璐﹁褰�");
+ }
+
+ Long customerId = ledgers.get(0).getCustomerId();
+ for (SalesLedger ledger : ledgers) {
+ if (!Objects.equals(customerId, ledger.getCustomerId())) {
+ throw new ServiceException("閿�鍞彂璐у崟鍚堝苟鎵撳嵃鍙兘鏄悓涓�涓鎴�");
+ }
+ }
+
+ SalesInvoicesDto dto = new SalesInvoicesDto();
+
+ Customer customer = customerMapper.selectById(customerId);
+ if (customer != null) {
+ dto.setCustomerName(customer.getCustomerName());
+ dto.setContactPerson(customer.getContactPerson());
+ dto.setContactPhone(customer.getContactPhone());
+
+ StringBuilder address = new StringBuilder();
+ if (customer.getRegionsId() != null) {
+ CustomerRegions regions = customerRegionsService.getById(customer.getRegionsId());
+ if (regions != null) {
+ address.append(regions.getRegionsName());
+ }
+ }
+ if (StringUtils.isNotEmpty(customer.getCompanyAddress())) {
+ address.append(customer.getCompanyAddress());
+ }
+ dto.setCompanyAddress(address.toString());
+ }
+
+ // 鍙戣揣鍗曞彿 (XF + 鏃ユ湡 + 搴忓垪)
+ String dateStr = LocalDate.now().format(DateTimeFormatter.ofPattern("yyMMdd"));
+ String redisKey = "sales:delivery:seq:" + dateStr;
+ Long seq = redisTemplate.opsForValue().increment(redisKey);
+ if (seq != null && seq == 1) {
+ redisTemplate.expire(redisKey, 48, TimeUnit.HOURS);
+ }
+ dto.setDeliveryNo("XF" + dateStr + String.format("%03d", seq != null ? seq : 1));
+
+ // 瀵规柟鍗曞彿
+// dto.setExternalOrderNo(ledgers.get(0).getCustomerContractNo());
+
+ // 鏌ヨ鎵�鏈変骇鍝�
+ List<SalesLedgerProduct> allProducts = salesLedgerProductMapper.selectList(
+ new LambdaQueryWrapper<SalesLedgerProduct>().in(SalesLedgerProduct::getSalesLedgerId, salesLedgerIds));
+
+ if (CollectionUtils.isNotEmpty(allProducts)) {
+ Map<Long, SalesLedger> ledgerMap = ledgers.stream()
+ .collect(Collectors.toMap(SalesLedger::getId, Function.identity()));
+
+ Map<Long, List<SalesLedgerProduct>> groupedData = new LinkedHashMap<>();
+ for (SalesLedgerProduct p : allProducts) {
+ groupedData.computeIfAbsent(p.getSalesLedgerId(), k -> new ArrayList<>()).add(p);
+ }
+
+ List<SalesInvoicesDto.InvoiceOrderGroupDto> groups = new ArrayList<>();
+ BigDecimal totalQty = BigDecimal.ZERO;
+ BigDecimal totalArea = BigDecimal.ZERO;
+
+ for (Map.Entry<Long, List<SalesLedgerProduct>> ledgerEntry : groupedData.entrySet()) {
+ SalesLedger ledger = ledgerMap.get(ledgerEntry.getKey());
+ String orderNo = ledger != null ? ledger.getSalesContractNo() : "";
+ List<SalesLedgerProduct> products = ledgerEntry.getValue();
+
+ SalesInvoicesDto.InvoiceOrderGroupDto group = new SalesInvoicesDto.InvoiceOrderGroupDto();
+ group.setSalesContractNo(orderNo);
+ if (CollectionUtils.isNotEmpty(products)) {
+ group.setProductName(products.get(0).getProductCategory());
+ }
+
+ List<SalesInvoicesDto.InvoiceItemDto> itemDtos = new ArrayList<>();
+ BigDecimal groupQty = BigDecimal.ZERO;
+ BigDecimal groupArea = BigDecimal.ZERO;
+
+ for (SalesLedgerProduct p : products) {
+ SalesInvoicesDto.InvoiceItemDto item = new SalesInvoicesDto.InvoiceItemDto();
+ item.setFloorCode(p.getFloorCode());
+ item.setWidthHeight((p.getWidth() != null ? p.getWidth().stripTrailingZeros().toPlainString() : "0") +
+ " * " + (p.getHeight() != null ? p.getHeight().stripTrailingZeros().toPlainString() : "0"));
+ item.setQuantity(p.getQuantity());
+
+ // 闈㈢Н
+ BigDecimal area = p.getSettleTotalArea() != null ? p.getSettleTotalArea() : p.getActualTotalArea();
+ if (area == null && p.getWidth() != null && p.getHeight() != null && p.getQuantity() != null) {
+ area = p.getWidth().multiply(p.getHeight()).multiply(p.getQuantity()).divide(new BigDecimal(1000000), 2, RoundingMode.HALF_UP);
+ }
+ item.setArea(area);
+ item.setRemark(p.getRemark());
+ item.setProcessRequirement(p.getProcessRequirement());
+
+ itemDtos.add(item);
+ groupQty = groupQty.add(p.getQuantity() != null ? p.getQuantity() : BigDecimal.ZERO);
+ groupArea = groupArea.add(area != null ? area : BigDecimal.ZERO);
+ }
+
+ group.setItems(itemDtos);
+ group.setGroupTotalQuantity(groupQty);
+ group.setGroupTotalArea(groupArea.setScale(2, RoundingMode.HALF_UP));
+ groups.add(group);
+
+ totalQty = totalQty.add(groupQty);
+ totalArea = totalArea.add(groupArea);
+ }
+ dto.setGroups(groups);
+ dto.setTotalQuantity(totalQty);
+ dto.setTotalArea(totalArea.setScale(2, RoundingMode.HALF_UP));
+ }
+
+ LoginUser loginUser = SecurityUtils.getLoginUser();
+ if (loginUser != null && loginUser.getUser() != null) {
+ dto.setOrderMaker(loginUser.getUser().getNickName());
+ }
+ dto.setExecutionDate(LocalDateTime.now());
+
+ return dto;
+ }
+
private int findFirstMissingSequence(List<Integer> sequences) {
if (sequences.isEmpty()) {
return 1;
--
Gitblit v1.9.3