From d7c69d76e9c81464c698199b90ec4a339a18b257 Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期五, 27 三月 2026 16:06:17 +0800
Subject: [PATCH] feat: 销售订单标签打印
---
src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java | 182 +++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 182 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..04f3a3a 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,188 @@
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;
+ }
+
+ @Override
+ public List<SalesLabelDto> salesLabel(Long salesLedgerId) {
+ if (salesLedgerId == null) {
+ throw new ServiceException("鎵撳嵃鏍囩澶辫触,鏁版嵁涓嶈兘涓虹┖");
+ }
+ SalesLedger salesLedger = baseMapper.selectById(salesLedgerId);
+ if (salesLedger == null) {
+ throw new ServiceException("鎵撳嵃澶辫触,閿�鍞鍗曚笉瀛樺湪");
+ }
+
+ // 鏌ヨ浜у搧鍒楄〃
+ List<SalesLedgerProduct> products = salesLedgerProductMapper.selectList(
+ new LambdaQueryWrapper<SalesLedgerProduct>().eq(SalesLedgerProduct::getSalesLedgerId, salesLedgerId));
+
+ // 鏌ヨ瀹㈡埛鍦板潃
+ String fullAddress = "";
+ if (salesLedger.getCustomerId() != null) {
+ Customer customer = customerMapper.selectById(salesLedger.getCustomerId());
+ if (customer != null) {
+ StringBuilder addressSb = new StringBuilder();
+ if (customer.getRegionsId() != null) {
+ CustomerRegions regions = customerRegionsService.getById(customer.getRegionsId());
+ if (regions != null) {
+ addressSb.append(regions.getRegionsName());
+ }
+ }
+ if (StringUtils.isNotEmpty(customer.getCompanyAddress())) {
+ addressSb.append(customer.getCompanyAddress());
+ }
+ fullAddress = addressSb.toString();
+ }
+ }
+
+ List<SalesLabelDto> list = new ArrayList<>();
+ if (CollectionUtils.isNotEmpty(products)) {
+ for (SalesLedgerProduct p : products) {
+ SalesLabelDto dto = new SalesLabelDto();
+ dto.setCustomerName(salesLedger.getCustomerName());
+ dto.setSalesContractNo(salesLedger.getSalesContractNo());
+ dto.setProductName(p.getProductCategory());
+
+ // 瀹�*楂�=鏁伴噺
+ String specification = (p.getWidth() != null ? p.getWidth().stripTrailingZeros().toPlainString() : "0") + "*" +
+ (p.getHeight() != null ? p.getHeight().stripTrailingZeros().toPlainString() : "0") + "=" +
+ (p.getQuantity() != null ? p.getQuantity().stripTrailingZeros().toPlainString() : "0");
+ dto.setSpecification(specification);
+
+ // 瀹㈡埛鍦板潃 + 妤煎眰缂栧彿
+ dto.setFloorCode(fullAddress + (StringUtils.isNotEmpty(p.getFloorCode()) ? " " + p.getFloorCode() : ""));
+ list.add(dto);
+ }
+ }
+
+ return list;
+ }
+
private int findFirstMissingSequence(List<Integer> sequences) {
if (sequences.isEmpty()) {
return 1;
--
Gitblit v1.9.3