From 83ab4c8eabb1d2f448079c03bbb2efa09d9d468a Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期四, 25 六月 2026 09:05:55 +0800
Subject: [PATCH] feat: 售后新增消息推送、数量自定义、分页查询

---
 src/main/java/com/ruoyi/aftersalesservice/service/impl/AfterSalesServiceServiceImpl.java |  127 ++++++++++++++++++++++++++++++++++++++---
 1 files changed, 116 insertions(+), 11 deletions(-)

diff --git a/src/main/java/com/ruoyi/aftersalesservice/service/impl/AfterSalesServiceServiceImpl.java b/src/main/java/com/ruoyi/aftersalesservice/service/impl/AfterSalesServiceServiceImpl.java
index 5f399ca..8f3cb12 100644
--- a/src/main/java/com/ruoyi/aftersalesservice/service/impl/AfterSalesServiceServiceImpl.java
+++ b/src/main/java/com/ruoyi/aftersalesservice/service/impl/AfterSalesServiceServiceImpl.java
@@ -1,33 +1,35 @@
 package com.ruoyi.aftersalesservice.service.impl;
 
+import com.alibaba.fastjson2.JSON;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.aftersalesservice.dto.AfterSalesProductDto;
 import com.ruoyi.aftersalesservice.dto.AfterSalesServiceNewDto;
+import com.ruoyi.aftersalesservice.dto.CountDto;
 import com.ruoyi.aftersalesservice.mapper.AfterSalesServiceMapper;
 import com.ruoyi.aftersalesservice.pojo.AfterSalesService;
 import com.ruoyi.aftersalesservice.service.AfterSalesServiceService;
+import com.ruoyi.common.utils.OrderUtils;
 import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.project.system.domain.SysDept;
 import com.ruoyi.project.system.domain.SysUser;
 import com.ruoyi.project.system.mapper.SysDeptMapper;
 import com.ruoyi.project.system.mapper.SysUserMapper;
+import com.ruoyi.project.system.service.ISysNoticeService;
 import com.ruoyi.sales.dto.SalesLedgerDto;
 import com.ruoyi.sales.pojo.SalesLedger;
 import com.ruoyi.sales.pojo.SalesLedgerProduct;
 import com.ruoyi.sales.service.ISalesLedgerProductService;
 import com.ruoyi.sales.service.ISalesLedgerService;
-import com.ruoyi.sales.service.impl.SalesLedgerProductServiceImpl;
-import com.ruoyi.sales.service.impl.SalesLedgerServiceImpl;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import java.util.Arrays;
-import java.util.List;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -50,14 +52,62 @@
     private ISalesLedgerProductService salesLedgerProductService;
     @Autowired
     private ISalesLedgerService salesLedgerService;
+    @Autowired
+    private ISysNoticeService sysNoticeService;
 
     @Override
-    public IPage<AfterSalesService> listPage(Page page, AfterSalesService afterSalesService) {
+    public IPage<AfterSalesServiceNewDto> listPage(Page page, AfterSalesServiceNewDto afterSalesService) {
         Long tenantId = SecurityUtils.getLoginUser().getTenantId();
         SysDept sysDept = sysDeptMapper.selectDeptById(tenantId);
-        IPage<AfterSalesService> afterSalesServiceIPage = afterSalesServiceMapper.listPage(page, afterSalesService);
+        IPage<AfterSalesServiceNewDto> afterSalesServiceIPage = afterSalesServiceMapper.listPage(page, afterSalesService);
+
+        List<Long> allSalesLedgerIds = afterSalesServiceIPage.getRecords().stream()
+                .map(AfterSalesServiceNewDto::getSalesLedgerId)
+                .filter(Objects::nonNull)
+                .distinct()
+                .collect(Collectors.toList());
+
+        Map<Long, List<SalesLedgerProduct>> salesLedgerProductsMap;
+        if (!allSalesLedgerIds.isEmpty()) {
+            List<SalesLedgerProduct> allProducts = salesLedgerProductService.list(
+                    new QueryWrapper<SalesLedgerProduct>().lambda()
+                            .in(SalesLedgerProduct::getSalesLedgerId, allSalesLedgerIds)
+            );
+            salesLedgerProductsMap = allProducts.stream()
+                    .collect(Collectors.groupingBy(SalesLedgerProduct::getSalesLedgerId));
+        } else {
+            salesLedgerProductsMap = new HashMap<>();
+        }
+
         afterSalesServiceIPage.getRecords().forEach(item -> {
             item.setDeptName(sysDept.getDeptName());
+
+            try {
+                if (org.apache.commons.lang3.StringUtils.isNotEmpty(item.getAfterSalesProducts())) {
+                    List<AfterSalesProductDto> afterSalesProductList = JSON.parseArray(item.getAfterSalesProducts(), AfterSalesProductDto.class);
+                    List<Long> selectedIds = afterSalesProductList.stream().map(AfterSalesProductDto::getId).collect(Collectors.toList());
+
+                    if (!selectedIds.isEmpty()) {
+                        List<SalesLedgerProduct> ledgerProducts = salesLedgerProductsMap.getOrDefault(item.getSalesLedgerId(), new java.util.ArrayList<>());
+                        List<SalesLedgerProduct> matchedProducts = ledgerProducts.stream()
+                                .filter(p -> selectedIds.contains(p.getId()))
+                                .collect(Collectors.toList());
+
+                        matchedProducts.forEach(p -> {
+                            afterSalesProductList.stream()
+                                    .filter(ap -> ap.getId().equals(p.getId()))
+                                    .findFirst()
+                                    .ifPresent(ap -> p.setAfterSalesQuantity(ap.getAfterSalesQuantity()));
+                        });
+
+                        SalesLedgerDto salesLedgerDto = new SalesLedgerDto();
+                        salesLedgerDto.setProductData(matchedProducts);
+                        item.setSalesLedgerDto(salesLedgerDto);
+                    }
+                }
+            } catch (Exception e) {
+                log.error("瑙f瀽鍞悗浜у搧澶辫触", e);
+            }
         });
         return afterSalesServiceIPage;
     }
@@ -65,16 +115,42 @@
     @Override
     public boolean addAfterSalesServiceDto(AfterSalesServiceNewDto afterSalesServiceNewDto) {
         afterSalesServiceNewDto.setStatus(1);
-        if (afterSalesServiceNewDto.getProductModelIdList() != null && afterSalesServiceNewDto.getProductModelIdList().isEmpty() ) {
+        if (afterSalesServiceNewDto.getProductModelIdList() != null && !afterSalesServiceNewDto.getProductModelIdList().isEmpty()) {
             String productModelIds = afterSalesServiceNewDto.getProductModelIdList().stream()
                     .map(String::valueOf)
                     .collect(Collectors.joining(","));
             afterSalesServiceNewDto.setProductModelIds(productModelIds);
         }
+        if (afterSalesServiceNewDto.getAfterSalesProductList() != null && !afterSalesServiceNewDto.getAfterSalesProductList().isEmpty()) {
+            afterSalesServiceNewDto.setAfterSalesProducts(JSON.toJSONString(afterSalesServiceNewDto.getAfterSalesProductList()));
+        }
         SysUser sysUser = sysUserMapper.selectUserById(afterSalesServiceNewDto.getCheckUserId());
-        if(sysUser == null) throw new RuntimeException("瀹℃牳浜轰笉瀛樺湪");
+        if (sysUser == null) throw new RuntimeException("瀹℃牳浜轰笉瀛樺湪");
         afterSalesServiceNewDto.setCheckNickName(sysUser.getNickName());
-        return this.save(afterSalesServiceNewDto);
+        if (StringUtils.isEmpty(afterSalesServiceNewDto.getAfterSalesServiceNo())) {
+            String string = OrderUtils.countAfterServiceTodayByCreateTime(afterSalesServiceMapper, "SH_");
+            afterSalesServiceNewDto.setAfterSalesServiceNo(string);
+        }
+        boolean saved = this.save(afterSalesServiceNewDto);
+
+        if (saved && afterSalesServiceNewDto.getSalesLedgerId() != null) {
+            try {
+                SalesLedger salesLedger = salesLedgerService.getById(afterSalesServiceNewDto.getSalesLedgerId());
+                if (salesLedger != null && StringUtils.isNotEmpty(salesLedger.getEntryPerson())) {
+                    Long entryUserId = Long.parseLong(salesLedger.getEntryPerson());
+                    String webPath = "/customerService/afterSalesHandling?afterSalesServiceNo=" + afterSalesServiceNewDto.getAfterSalesServiceNo();
+                    sysNoticeService.simpleNoticeByUser(
+                            "鏂板鍞悗鍗曢�氱煡",
+                            "鎮ㄥ綍鍏ョ殑閿�鍞鍗曟湁涓�鏉℃柊鐨勫敭鍚庤褰曪紝鍞悗鍗曞彿锛�" + afterSalesServiceNewDto.getAfterSalesServiceNo(),
+                            Collections.singletonList(entryUserId),
+                            webPath
+                    );
+                }
+            } catch (Exception e) {
+                log.error("鍙戦�佸敭鍚庢柊澧為�氱煡澶辫触: ", e);
+            }
+        }
+        return saved;
     }
 
     @Override
@@ -82,13 +158,42 @@
         AfterSalesService afterSalesService = afterSalesServiceMapper.selectById(id);
         SalesLedger byId = salesLedgerService.getById(afterSalesService.getSalesLedgerId());
         List<Long> collect = Arrays.stream(afterSalesService.getProductModelIds().split(",")).map(Long::valueOf).collect(Collectors.toList());
-        List<SalesLedgerProduct> list = salesLedgerProductService.list(new QueryWrapper<SalesLedgerProduct>().lambda().in(SalesLedgerProduct::getProductModelId, collect));
+        List<SalesLedgerProduct> list = salesLedgerProductService.list(new QueryWrapper<SalesLedgerProduct>().lambda().in(SalesLedgerProduct::getId, collect));
+
+        if (StringUtils.isNotEmpty(afterSalesService.getAfterSalesProducts())) {
+            List<com.ruoyi.aftersalesservice.dto.AfterSalesProductDto> afterSalesProductList = com.alibaba.fastjson2.JSON.parseArray(afterSalesService.getAfterSalesProducts(), com.ruoyi.aftersalesservice.dto.AfterSalesProductDto.class);
+            for (SalesLedgerProduct product : list) {
+                for (com.ruoyi.aftersalesservice.dto.AfterSalesProductDto productDto : afterSalesProductList) {
+                    if (product.getId().equals(productDto.getId())) {
+                        product.setAfterSalesQuantity(productDto.getAfterSalesQuantity());
+                        break;
+                    }
+                }
+            }
+        }
+
         AfterSalesServiceNewDto afterSalesServiceNewDto = new AfterSalesServiceNewDto();
         BeanUtils.copyProperties(afterSalesService, afterSalesServiceNewDto);
         SalesLedgerDto salesLedgerDto = new SalesLedgerDto();
         BeanUtils.copyProperties(byId, salesLedgerDto);
-        salesLedgerDto.setProductData( list);
+        salesLedgerDto.setProductData(list);
         afterSalesServiceNewDto.setSalesLedgerDto(salesLedgerDto);
         return afterSalesServiceNewDto;
     }
+
+    @Override
+    public List<CountDto> countAfterSalesService() {
+        List<CountDto> stringIntegerHashMap = afterSalesServiceMapper.countAfterSalesService();
+        Integer total = 0;
+        for (CountDto countDto : stringIntegerHashMap) {
+            total += countDto.getCount();
+        }
+        CountDto countDto = new CountDto();
+        countDto.setStatus(3);
+        countDto.setCount(total);
+        stringIntegerHashMap.add(countDto);
+
+        return stringIntegerHashMap;
+
+    }
 }

--
Gitblit v1.9.3