From 469a106cf617efd2e9fbe02937c355fa392ae7bc Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期二, 10 二月 2026 17:53:07 +0800
Subject: [PATCH] feat: 消息通知添加APP跳转路由

---
 src/main/java/com/ruoyi/basic/service/impl/ProductModelServiceImpl.java |   64 ++++++++++++++++++++++++-------
 1 files changed, 49 insertions(+), 15 deletions(-)

diff --git a/src/main/java/com/ruoyi/basic/service/impl/ProductModelServiceImpl.java b/src/main/java/com/ruoyi/basic/service/impl/ProductModelServiceImpl.java
index eb9eedb..16a45b1 100644
--- a/src/main/java/com/ruoyi/basic/service/impl/ProductModelServiceImpl.java
+++ b/src/main/java/com/ruoyi/basic/service/impl/ProductModelServiceImpl.java
@@ -1,6 +1,7 @@
 package com.ruoyi.basic.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+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;
@@ -11,10 +12,15 @@
 import com.ruoyi.basic.pojo.Product;
 import com.ruoyi.basic.pojo.ProductModel;
 import com.ruoyi.basic.service.IProductModelService;
+import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.common.utils.bean.BeanUtils;
 import com.ruoyi.common.utils.poi.ExcelUtil;
+import com.ruoyi.framework.web.domain.AjaxResult;
+import com.ruoyi.sales.mapper.SalesLedgerProductMapper;
+import com.ruoyi.sales.pojo.SalesLedgerProduct;
 import lombok.AllArgsConstructor;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.multipart.MultipartFile;
 
 import java.util.Arrays;
@@ -33,6 +39,7 @@
 public class ProductModelServiceImpl extends ServiceImpl<ProductModelMapper, ProductModel> implements IProductModelService {
 
     private final ProductMapper productMapper;
+    private final SalesLedgerProductMapper salesLedgerProductMapper;
     private ProductModelMapper productModelMapper;
 
     @Override
@@ -40,15 +47,22 @@
 
         if (productModelDto.getId() == null) {
             ProductModel productModel = new ProductModel();
-            BeanUtils.copyProperties(productModelDto,productModel);
+            BeanUtils.copyProperties(productModelDto, productModel);
             return productModelMapper.insert(productModel);
         } else {
             return productModelMapper.updateById(productModelDto);
         }
     }
 
+
     @Override
     public int delProductModel(Long[] ids) {
+        List<SalesLedgerProduct> salesLedgerProducts = salesLedgerProductMapper.selectList(new QueryWrapper<SalesLedgerProduct>()
+                .lambda().in(SalesLedgerProduct::getProductModelId, ids));
+        if (salesLedgerProducts != null && salesLedgerProducts.size() > 0) {
+
+            throw new RuntimeException("宸茬粡瀛樺湪璇ヤ骇鍝佺殑閿�鍞彴璐﹀拰閲囪喘鍙拌处");
+        }
         return productModelMapper.deleteBatchIds(Arrays.asList(ids));
     }
 
@@ -61,6 +75,7 @@
 
     /**
      * 鏍规嵁id鏌ヨ浜у搧瑙勬牸鍒嗛〉鏌ヨ
+     *
      * @param page
      * @param productDto
      * @return
@@ -73,24 +88,43 @@
     }
 
     @Override
-    public Boolean importProduct(MultipartFile file) {
+    @Transactional(rollbackFor = Exception.class)
+    public AjaxResult importProductModel(MultipartFile file, Integer productId) {
+        if (productId == null) {
+            return AjaxResult.error("璇峰厛閫夋嫨浜у搧鍐嶅鍏ヨ鏍煎瀷鍙�");
+        }
+
+        Product product = productMapper.selectById(productId);
+        if (product == null) {
+            return AjaxResult.error("閫夋嫨鐨勪骇鍝佷笉瀛樺湪");
+        }
+
         try {
             ExcelUtil<ProductModel> productModelExcelUtil = new ExcelUtil<>(ProductModel.class);
             List<ProductModel> productModelList = productModelExcelUtil.importExcel(file.getInputStream());
-            Map<String, List<ProductModel>> collect = productModelList.stream().collect(Collectors.groupingBy(ProductModel::getProductName));
-            collect.forEach((k,v)->{
-                Product product = productMapper.selectOne(new LambdaQueryWrapper<Product>().eq(Product::getProductName, k).last("LIMIT 1"));
-                if (product != null) {
-                    v.forEach(productModel -> {
-                        productModel.setProductId(product.getId());
-                    });
-                    this.saveOrUpdateBatch(v);
+
+            if (productModelList == null || productModelList.isEmpty()) {
+                return AjaxResult.error("瀵煎叆鏁版嵁涓嶈兘涓虹┖");
+            }
+
+            for (int i = 0; i < productModelList.size(); i++) {
+                ProductModel item = productModelList.get(i);
+                int rowNum = i + 2;
+
+                if (StringUtils.isEmpty(item.getModel())) {
+                    return AjaxResult.error("绗� " + rowNum + " 琛屽鍏ュけ璐�: [瑙勬牸鍨嬪彿] 涓嶈兘涓虹┖");
                 }
-            });
-            return true;
-        }catch (Exception e) {
-            e.printStackTrace();
+                if (StringUtils.isEmpty(item.getUnit())) {
+                    return AjaxResult.error("绗� " + rowNum + " 琛屽鍏ュけ璐�: [鍗曚綅] 涓嶈兘涓虹┖");
+                }
+                item.setProductId(product.getId());
+            }
+
+            saveOrUpdateBatch(productModelList);
+            return AjaxResult.success("鎴愬姛瀵煎叆 " + productModelList.size() + " 鏉℃暟鎹�");
+        } catch (Exception e) {
+            log.error("瀵煎叆浜у搧瑙勬牸寮傚父", e);
+            return AjaxResult.error("瀵煎叆澶辫触");
         }
-        return false;
     }
 }

--
Gitblit v1.9.3