From e8d0bdce89ae0937763736f75868a43bd8690985 Mon Sep 17 00:00:00 2001
From: buhuazhen <hua100783@gmail.com>
Date: 星期五, 24 四月 2026 15:34:09 +0800
Subject: [PATCH] feat(production): 增加报工用户names支持
---
src/main/java/com/ruoyi/basic/service/impl/ProductModelServiceImpl.java | 96 ++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 89 insertions(+), 7 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 16a45b1..55bfdce 100644
--- a/src/main/java/com/ruoyi/basic/service/impl/ProductModelServiceImpl.java
+++ b/src/main/java/com/ruoyi/basic/service/impl/ProductModelServiceImpl.java
@@ -3,15 +3,20 @@
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.core.toolkit.CollectionUtils;
+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;
+import com.ruoyi.basic.dto.ProductModelAnticlockwiseDto;
import com.ruoyi.basic.dto.ProductModelDto;
import com.ruoyi.basic.mapper.ProductMapper;
import com.ruoyi.basic.mapper.ProductModelMapper;
import com.ruoyi.basic.pojo.Product;
import com.ruoyi.basic.pojo.ProductModel;
import com.ruoyi.basic.service.IProductModelService;
+import com.ruoyi.common.exception.ServiceException;
+import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.bean.BeanUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
@@ -23,9 +28,8 @@
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
+import javax.validation.constraints.NotNull;
+import java.util.*;
import java.util.stream.Collectors;
/**
@@ -70,7 +74,17 @@
public List<ProductModel> selectModelList(ProductDto productDto) {
LambdaQueryWrapper<ProductModel> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(ProductModel::getProductId, productDto.getId());
+ queryWrapper.eq(productDto.getCreateUser() != null, ProductModel::getCreateUser, productDto.getCreateUser());
+ queryWrapper.eq(productDto.getDeptId() != null, ProductModel::getDeptId, productDto.getDeptId());
+ if (ObjectUtils.isNotEmpty(productDto.getDeptIds())) {
+ queryWrapper.in( ProductModel::getDeptId, Arrays.asList(productDto.getDeptIds()));
+ }
return productModelMapper.selectList(queryWrapper);
+ }
+
+ @Override
+ public List<ProductModel> selectModelListByProductIds(@NotNull List<Long> ids) {
+ return productModelMapper.selectModelListByProductIds(ids);
}
/**
@@ -103,9 +117,16 @@
ExcelUtil<ProductModel> productModelExcelUtil = new ExcelUtil<>(ProductModel.class);
List<ProductModel> productModelList = productModelExcelUtil.importExcel(file.getInputStream());
- if (productModelList == null || productModelList.isEmpty()) {
+ if (CollectionUtils.isEmpty(productModelList)) {
return AjaxResult.error("瀵煎叆鏁版嵁涓嶈兘涓虹┖");
}
+
+ // 鑾峰彇褰撳墠浜у搧涓嬫墍鏈夌殑瑙勬牸鍨嬪彿鍚�
+ List<ProductModel> existingModels = list(new LambdaQueryWrapper<ProductModel>().eq(ProductModel::getProductId, productId));
+ Set<String> existingModelNames = existingModels.stream().map(ProductModel::getModel).collect(Collectors.toSet());
+
+ List<ProductModel> waitToSaveList = new ArrayList<>();
+ int skipCount = 0;
for (int i = 0; i < productModelList.size(); i++) {
ProductModel item = productModelList.get(i);
@@ -117,14 +138,75 @@
if (StringUtils.isEmpty(item.getUnit())) {
return AjaxResult.error("绗� " + rowNum + " 琛屽鍏ュけ璐�: [鍗曚綅] 涓嶈兘涓虹┖");
}
+
+ // 鍘婚噸,濡傛灉宸插寘鍚鍨嬪彿,鍒欒烦杩�
+ if (existingModelNames.contains(item.getModel())) {
+ skipCount++;
+ continue;
+ }
+
item.setProductId(product.getId());
+ waitToSaveList.add(item);
+
+ existingModelNames.add(item.getModel());
}
- saveOrUpdateBatch(productModelList);
- return AjaxResult.success("鎴愬姛瀵煎叆 " + productModelList.size() + " 鏉℃暟鎹�");
+ if (!waitToSaveList.isEmpty()) {
+ saveBatch(waitToSaveList);
+ }
+
+ if (skipCount == 0) {
+ return AjaxResult.success(String.format("鎴愬姛瀵煎叆 %d 鏉℃暟鎹�", waitToSaveList.size()));
+ } else {
+ return AjaxResult.success(String.format("鎴愬姛瀵煎叆 %d 鏉★紝璺宠繃宸插瓨鍦ㄦ暟鎹� %d 鏉�", waitToSaveList.size(), skipCount));
+ }
} catch (Exception e) {
log.error("瀵煎叆浜у搧瑙勬牸寮傚父", e);
- return AjaxResult.error("瀵煎叆澶辫触");
+ throw new ServiceException("瀵煎叆澶辫触");
+ }
+ }
+
+ //鍙嶅悜鏂板鎴愬搧浜у搧锛屽彧鏈夐攢鍞叧鑱旀柊澧炵殑鏃跺�欒皟鐢�
+ @Override
+ public Long productModelAnticlockwise(ProductModelAnticlockwiseDto productModelDto) {
+ ProductModel oldProductModel = productModelMapper.selectOldProductModel(productModelDto.getModel(), productModelDto.getProductName());
+ //瀛樺湪灏辨洿鏂�
+ if (oldProductModel != null) {
+ oldProductModel.setModel(productModelDto.getModel());
+ oldProductModel.setUnit(productModelDto.getUnit());
+ oldProductModel.setSubUnit(productModelDto.getSubUnit());
+ oldProductModel.setDeptId(SecurityUtils.getDeptId()[0]);
+ productModelMapper.updateById(oldProductModel);
+ Product product = productMapper.selectById(oldProductModel.getProductId());
+ product.setProductName(productModelDto.getProductName());
+ productMapper.updateById(product);
+ return oldProductModel.getId();
+ }else {
+ //鎵惧埌鐖惰妭鐐�
+ Product productParent = productMapper.selectOne(new QueryWrapper<Product>().lambda().eq(Product::getProductName, "鎴愬搧").last("limit 1"));
+ if (ObjectUtils.isEmpty(productParent)) {
+ Product product = new Product();
+ product.setProductName("鎴愬搧");
+ product.setDeptId(SecurityUtils.getDeptId()[0]);
+ productMapper.insert(product);
+ productParent.setId(product.getId());
+ }
+ //鏂板浜у搧澶х被
+ Product product = new Product();
+ product.setProductName(productModelDto.getProductName());
+ product.setParentId(productParent.getId());
+ product.setDeptId(SecurityUtils.getDeptId()[0]);
+ productMapper.insert( product);
+ //鏂板浜у搧瑙勬牸
+ ProductModel productModel = new ProductModel();
+ productModel.setProductId(product.getId());
+ productModel.setModel(productModelDto.getModel());
+ productModel.setUnit(productModelDto.getUnit());
+ productModel.setSubUnit(productModelDto.getSubUnit());
+ productModel.setDeptId(SecurityUtils.getDeptId()[0]);
+ productModelMapper.insert(productModel);
+ return productModel.getId();
+
}
}
}
--
Gitblit v1.9.3