From 72a32c227fdf10f34fe563a7de35169da5729eea Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期二, 07 七月 2026 15:50:31 +0800
Subject: [PATCH] Merge branch 'dev_New_pro' into dev_平遥县盛达铸造厂
---
src/main/java/com/ruoyi/basic/service/impl/ProductServiceImpl.java | 41 +++++++++++++++++++++++++++++------------
1 files changed, 29 insertions(+), 12 deletions(-)
diff --git a/src/main/java/com/ruoyi/basic/service/impl/ProductServiceImpl.java b/src/main/java/com/ruoyi/basic/service/impl/ProductServiceImpl.java
index 5a7f679..2b9b26e 100644
--- a/src/main/java/com/ruoyi/basic/service/impl/ProductServiceImpl.java
+++ b/src/main/java/com/ruoyi/basic/service/impl/ProductServiceImpl.java
@@ -13,12 +13,10 @@
import com.ruoyi.basic.pojo.ProductModel;
import com.ruoyi.basic.service.IProductService;
import com.ruoyi.basic.vo.ProductModelVo;
+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 lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
-import org.springframework.web.multipart.MultipartFile;
import java.util.ArrayList;
import java.util.Arrays;
@@ -61,6 +59,12 @@
return productModelMapper.listPageProductModel(page, productModel);
}
+ @Override
+ public IPage<ProductModelVo> listPageProductModelByType(Page<ProductModelVo> page, ProductModel productModel, Long topProductParentId) {
+ productModel.setTopProductParentId(topProductParentId);
+ return productModelMapper.listPageProductModel(page, productModel);
+ }
+
// 閫掑綊鏋勫缓瀛愯妭鐐�
private List<ProductTreeDto> buildChildrenNodes(Long parentId) {
@@ -94,17 +98,18 @@
if (ObjectUtils.isEmpty(productDto.getParentId())) {
throw new IllegalArgumentException("璇烽�夋嫨鐖惰妭鐐�");
}
+ String productName = StringUtils.trim(productDto.getProductName());
+ if (StringUtils.isEmpty(productName)) {
+ throw new IllegalArgumentException("浜у搧鍚嶇О涓嶈兘涓虹┖");
+ }
+ productDto.setProductName(productName);
+ checkProductNameUnique(productDto.getParentId(), productName, productDto.getId());
if (productDto.getId() == null) {
// 鏂板浜у搧閫昏緫
- if (productDto.getParentId() == null) {
- // 鑻ユ湭鎸囧畾鐖惰妭鐐癸紝榛樿涓烘牴鑺傜偣锛坧arentId 璁句负 null锛�
- productDto.setParentId(null);
- } else {
- // 妫�鏌ョ埗鑺傜偣鏄惁瀛樺湪锛堝彲閫夛紝鏍规嵁涓氬姟闇�姹傦級
- Product parent = productMapper.selectById(productDto.getParentId());
- if (parent == null) {
- throw new IllegalArgumentException("鐖惰妭鐐逛笉瀛樺湪锛屾棤娉曟坊鍔犲瓙浜у搧");
- }
+ // 妫�鏌ョ埗鑺傜偣鏄惁瀛樺湪锛堝彲閫夛紝鏍规嵁涓氬姟闇�姹傦級
+ Product parent = productMapper.selectById(productDto.getParentId());
+ if (parent == null) {
+ throw new IllegalArgumentException("鐖惰妭鐐逛笉瀛樺湪锛屾棤娉曟坊鍔犲瓙浜у搧");
}
return productMapper.insert(productDto);
} else {
@@ -118,6 +123,18 @@
}
}
+ private void checkProductNameUnique(Long parentId, String productName, Long currentId) {
+ LambdaQueryWrapper<Product> queryWrapper = new LambdaQueryWrapper<>();
+ queryWrapper.eq(Product::getParentId, parentId)
+ .eq(Product::getProductName, productName)
+ .ne(currentId != null, Product::getId, currentId)
+ .last("limit 1");
+ Product duplicateProduct = productMapper.selectOne(queryWrapper);
+ if (duplicateProduct != null) {
+ throw new IllegalArgumentException("瀵瑰簲鐨�" + productName + "宸茬粡瀛樺湪");
+ }
+ }
+
@Override
public int delProductByIds(Long[] ids) {
// 1. 鍒犻櫎瀛愯〃 product_model 涓叧鑱旂殑鏁版嵁
--
Gitblit v1.9.3