From 91968cc6ee3fa8206201fd137f56a20ae4b6dff7 Mon Sep 17 00:00:00 2001
From: 吴羡 <16976746+Xian-TT3@user.noreply.gitee.com>
Date: 星期三, 23 九月 2026 15:19:46 +0800
Subject: [PATCH] feat: 销售台账手工录入品名/材质/规格型号自动注册产品层级,回退采购台账相关改动
---
src/main/java/com/ruoyi/basic/service/impl/ProductServiceImpl.java | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 105 insertions(+), 9 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 fdf2dd3..ba6b4d6 100644
--- a/src/main/java/com/ruoyi/basic/service/impl/ProductServiceImpl.java
+++ b/src/main/java/com/ruoyi/basic/service/impl/ProductServiceImpl.java
@@ -2,6 +2,7 @@
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.basic.dto.ProductDto;
@@ -11,12 +12,11 @@
import com.ruoyi.basic.pojo.Product;
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;
@@ -55,7 +55,7 @@
}
@Override
- public IPage<ProductModel> listPageProductModel(Page<ProductModel> page, ProductModel productModel) {
+ public IPage<ProductModelVo> listPageProductModel(Page<ProductModelVo> page, ProductModel productModel) {
return productModelMapper.listPageProductModel(page, productModel);
}
@@ -89,13 +89,23 @@
@Override
public int addOrEditProduct(ProductDto productDto) {
+ String productName = StringUtils.trim(productDto.getProductName());
+ if (StringUtils.isEmpty(productName)) {
+ throw new IllegalArgumentException("浜у搧鍚嶇О涓嶈兘涓虹┖");
+ }
+ // 鐖惰妭鐐逛负绌鸿〃绀烘柊澧炰竴绾уぇ绫�
+ if (ObjectUtils.isEmpty(productDto.getParentId())) {
+ if (productDto.getId() != null) {
+ throw new IllegalArgumentException("璇烽�夋嫨鐖惰妭鐐�");
+ }
+ productDto.setParentId(null);
+ }
+ productDto.setProductName(productName);
+ checkProductNameUnique(productDto.getParentId(), productName, productDto.getId());
if (productDto.getId() == null) {
// 鏂板浜у搧閫昏緫
- if (productDto.getParentId() == null) {
- // 鑻ユ湭鎸囧畾鐖惰妭鐐癸紝榛樿涓烘牴鑺傜偣锛坧arentId 璁句负 null锛�
- productDto.setParentId(null);
- } else {
- // 妫�鏌ョ埗鑺傜偣鏄惁瀛樺湪锛堝彲閫夛紝鏍规嵁涓氬姟闇�姹傦級
+ // 妫�鏌ョ埗鑺傜偣鏄惁瀛樺湪锛堜竴绾уぇ绫绘棤鐖惰妭鐐癸級
+ if (productDto.getParentId() != null) {
Product parent = productMapper.selectById(productDto.getParentId());
if (parent == null) {
throw new IllegalArgumentException("鐖惰妭鐐逛笉瀛樺湪锛屾棤娉曟坊鍔犲瓙浜у搧");
@@ -113,8 +123,44 @@
}
}
+ private void checkProductNameUnique(Long parentId, String productName, Long currentId) {
+ LambdaQueryWrapper<Product> queryWrapper = new LambdaQueryWrapper<>();
+ if (parentId == null) {
+ queryWrapper.isNull(Product::getParentId);
+ } else {
+ queryWrapper.eq(Product::getParentId, parentId);
+ }
+ queryWrapper.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) {
+ // 瀛樺湪瀛愮被鏃朵笉鍏佽鍒犻櫎
+ LambdaQueryWrapper<Product> childWrapper = new LambdaQueryWrapper<>();
+ childWrapper.in(Product::getParentId, ids).last("limit 1");
+ Product childProduct = productMapper.selectOne(childWrapper);
+ if (childProduct != null) {
+ throw new IllegalArgumentException("璇ュぇ绫讳笅瀛樺湪瀛愮被锛屼笉鑳藉垹闄�");
+ }
+
+ // 澶х被涓嬪瓨鍦ㄨ鏍煎瀷鍙锋暟鎹椂涓嶅厑璁稿垹闄�
+ for (Product product : productMapper.selectBatchIds(Arrays.asList(ids))) {
+ if (product.getParentId() != null) {
+ continue;
+ }
+ LambdaQueryWrapper<ProductModel> modelWrapper = new LambdaQueryWrapper<>();
+ modelWrapper.eq(ProductModel::getProductId, product.getId()).last("limit 1");
+ if (productModelMapper.selectOne(modelWrapper) != null) {
+ throw new IllegalArgumentException("璇ュぇ绫讳笅瀛樺湪鏁版嵁锛屼笉鑳藉垹闄�");
+ }
+ }
+
// 1. 鍒犻櫎瀛愯〃 product_model 涓叧鑱旂殑鏁版嵁
LambdaQueryWrapper<ProductModel> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.in(ProductModel::getProductId, ids);
@@ -126,4 +172,54 @@
return deleteCount;
}
+ @Override
+ public ProductModel ensureProductHierarchy(String productName, String material, String modelName, String unit) {
+ productName = StringUtils.trim(productName);
+ material = StringUtils.trim(material);
+ modelName = StringUtils.trim(modelName);
+ if (StringUtils.isEmpty(productName) || StringUtils.isEmpty(material) || StringUtils.isEmpty(modelName)) {
+ return null;
+ }
+
+ // 鍝佸悕锛氫竴绾уぇ绫伙紙parentId 涓虹┖锛�
+ LambdaQueryWrapper<Product> categoryWrapper = new LambdaQueryWrapper<>();
+ categoryWrapper.isNull(Product::getParentId)
+ .eq(Product::getProductName, productName)
+ .last("limit 1");
+ Product category = productMapper.selectOne(categoryWrapper);
+ if (category == null) {
+ category = new Product();
+ category.setProductName(productName);
+ productMapper.insert(category);
+ }
+
+ // 鏉愯川锛氬ぇ绫讳笅鐨勫瓙绫�
+ LambdaQueryWrapper<Product> materialWrapper = new LambdaQueryWrapper<>();
+ materialWrapper.eq(Product::getParentId, category.getId())
+ .eq(Product::getProductName, material)
+ .last("limit 1");
+ Product materialProduct = productMapper.selectOne(materialWrapper);
+ if (materialProduct == null) {
+ materialProduct = new Product();
+ materialProduct.setParentId(category.getId());
+ materialProduct.setProductName(material);
+ productMapper.insert(materialProduct);
+ }
+
+ // 瑙勬牸鍨嬪彿锛氬瓙绫讳笅鐨勮鏍�
+ LambdaQueryWrapper<ProductModel> modelWrapper = new LambdaQueryWrapper<>();
+ modelWrapper.eq(ProductModel::getProductId, materialProduct.getId())
+ .eq(ProductModel::getModel, modelName)
+ .last("limit 1");
+ ProductModel productModel = productModelMapper.selectOne(modelWrapper);
+ if (productModel == null) {
+ productModel = new ProductModel();
+ productModel.setProductId(materialProduct.getId());
+ productModel.setModel(modelName);
+ productModel.setUnit(unit);
+ productModelMapper.insert(productModel);
+ }
+ return productModel;
+ }
+
}
--
Gitblit v1.9.3