From ac6db1c4fddcb89c9668e34a35f023817a59f838 Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期三, 01 四月 2026 17:54:44 +0800
Subject: [PATCH] yys 1.产品导入新增excel错误提示 2.bom导入新增excel错误提示 3.仓储物流增加库位字段 4.修改发货出库-新增库位 5.修改采购入库审核-新增库位 6.生产入库-新增库位,审核
---
src/main/java/com/ruoyi/basic/service/impl/ProductModelServiceImpl.java | 138 +++++++++++++++++++++++++++++-----------------
1 files changed, 87 insertions(+), 51 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 26715f3..b2918bd 100644
--- a/src/main/java/com/ruoyi/basic/service/impl/ProductModelServiceImpl.java
+++ b/src/main/java/com/ruoyi/basic/service/impl/ProductModelServiceImpl.java
@@ -11,25 +11,32 @@
import com.ruoyi.basic.pojo.Product;
import com.ruoyi.basic.pojo.ProductModel;
import com.ruoyi.basic.service.IProductModelService;
+import com.ruoyi.common.enums.FileNameType;
+import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.OrderUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.bean.BeanUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.utils.uuid.IdUtils;
+import com.ruoyi.other.mapper.TempFileMapper;
+import com.ruoyi.other.service.impl.TempFileServiceImpl;
+import com.ruoyi.production.mapper.ProductProcessMapper;
+import com.ruoyi.production.pojo.ProductProcess;
+import com.ruoyi.sales.mapper.CommonFileMapper;
import com.ruoyi.sales.mapper.SalesLedgerProductMapper;
import com.ruoyi.sales.pojo.SalesLedgerProduct;
+import com.ruoyi.sales.service.impl.CommonFileServiceImpl;
import lombok.AllArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
-import java.util.AbstractMap;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
import java.util.stream.Collectors;
/**
@@ -45,9 +52,13 @@
private final ProductMapper productMapper;
private final SalesLedgerProductMapper salesLedgerProductMapper;
private ProductModelMapper productModelMapper;
+ private final CommonFileServiceImpl commonFileService;
+ private final ProductProcessMapper productProcessMapper;
+
+ private final TempFileServiceImpl tempFileService;
@Override
- public int addOrEditProductModel(ProductModelDto productModelDto) {
+ public int addOrEditProductModel(ProductModelDto productModelDto) throws IOException {
if(StringUtils.isEmpty(productModelDto.getProductName())){
throw new RuntimeException("浜у搧鍚嶇О涓嶈兘涓虹┖");
}
@@ -63,16 +74,24 @@
ProductModel productModel = new ProductModel();
BeanUtils.copyProperties(productModelDto,productModel);
productModel.setProductId(product.getId());
- return productModelMapper.insert(productModel);
+ productModelMapper.insert(productModel);
+ if(CollectionUtils.isNotEmpty(productModelDto.getTempFileIds())){
+ commonFileService.migrateTempFilesToFormal(productModel.getId(), productModelDto.getTempFileIds());
+ }
+ return 1;
} else {
Product product1 = productMapper.selectById(productModelDto.getProductId());
if(product1 != null){
product1.setProductName(productModelDto.getProductName());
productMapper.updateById(product1);
}
-
+ commonFileService.deleteByBusinessIds(Collections.singletonList(productModelDto.getId()), FileNameType.PRODUCT_MODEL.getValue());
+ if(CollectionUtils.isNotEmpty(productModelDto.getTempFileIds())){
+ commonFileService.migrateTempFilesToFormal(productModelDto.getId(), productModelDto.getTempFileIds());
+ }
return productModelMapper.updateById(productModelDto);
}
+
}
@@ -112,51 +131,52 @@
@Override
@Transactional(rollbackFor = Exception.class)
- public Boolean importProduct(MultipartFile file) {
+ public void importProduct(MultipartFile file, HttpServletResponse response) {
+ ExcelUtil<ProductModelExcelCopyDto> productModelExcelUtil = new ExcelUtil<>(ProductModelExcelCopyDto.class);
+ List<ProductModelExcelCopyDto> productModelList = null;
try {
- ExcelUtil<ProductModelExcelCopyDto> productModelExcelUtil = new ExcelUtil<>(ProductModelExcelCopyDto.class);
- List<ProductModelExcelCopyDto> productModelList = productModelExcelUtil.importExcel(file.getInputStream());
-// List<Product> productList = productMapper.selectList(new LambdaQueryWrapper<Product>()
-// .isNull(Product::getParentId));
-// if(CollectionUtils.isEmpty(productList)) {
-// throw new RuntimeException("璇峰厛娣诲姞鐖剁骇浜у搧");
-// }
- if(CollectionUtils.isNotEmpty(productModelList)){
- // 2. 鎸変骇鍝佸悕绉�,鍥剧焊缂栧彿鍒嗙粍
- Map<Map.Entry<String, String>, List<ProductModelExcelCopyDto>> groupedByProductNameAndDrawingNumber =
- productModelList.stream()
- .collect(Collectors.groupingBy(
- dto -> new AbstractMap.SimpleEntry<>(
- dto.getProductName(),
- dto.getModel()
- )
- ));
- // 2. 閬嶅巻鍒嗙粍缁撴灉澶勭悊鏁版嵁
- for (Map.Entry<Map.Entry<String, String>, List<ProductModelExcelCopyDto>> entry : groupedByProductNameAndDrawingNumber.entrySet()) {
- Map.Entry<String, String> groupKey = entry.getKey();
- String productName = groupKey.getKey(); // 浜у搧鍚嶇О
- String drawingNumber = groupKey.getValue(); // 鍥剧焊缂栧彿
- List<ProductModelExcelCopyDto> dtoList = entry.getValue();
-
- // 绌哄垪琛ㄨ烦杩囷紝閬垮厤鍚庣画NPE
- if (CollectionUtils.isEmpty(dtoList)) {
- continue;
- }
- ProductModelExcelCopyDto firstDto = dtoList.get(0);
- String model = firstDto.getModel();
-
- // 3. 鏌ヨ/鏂板浜у搧锛堟寜浜у搧鍚嶇О+鍥剧焊缂栧彿锛屾洿绮惧噯锛�
- Product product = getOrCreateProduct(productName, drawingNumber);
-
- // 4. 鎵归噺澶勭悊浜у搧鍨嬪彿锛堟寜鍥剧焊缂栧彿+鍨嬪彿锛�
- processProductModel(dtoList, product.getId(), model, drawingNumber);
- }
- }
- return true;
+ productModelList = productModelExcelUtil.importExcel(file.getInputStream());
}catch (Exception e) {
- e.printStackTrace();
+ throw new ServiceException("鏂囦欢瑙f瀽澶辫触");
}
- return false;
+ if(CollectionUtils.isNotEmpty(productModelList)){
+ // 2. 鎸変骇鍝佸悕绉�,鍥剧焊缂栧彿鍒嗙粍
+ Map<Map.Entry<String, String>, List<ProductModelExcelCopyDto>> groupedByProductNameAndDrawingNumber =
+ productModelList.stream()
+ .collect(Collectors.groupingBy(
+ dto -> new AbstractMap.SimpleEntry<>(
+ dto.getProductName(),
+ dto.getModel()
+ )
+ ));
+ List<ProductModelExcelCopyErrorDto> errorList = new ArrayList<>();
+ // 2. 閬嶅巻鍒嗙粍缁撴灉澶勭悊鏁版嵁
+ for (Map.Entry<Map.Entry<String, String>, List<ProductModelExcelCopyDto>> entry : groupedByProductNameAndDrawingNumber.entrySet()) {
+ Map.Entry<String, String> groupKey = entry.getKey();
+ String productName = groupKey.getKey(); // 浜у搧鍚嶇О
+ String drawingNumber = groupKey.getValue(); // 鍥剧焊缂栧彿
+ List<ProductModelExcelCopyDto> dtoList = entry.getValue();
+
+ // 绌哄垪琛ㄨ烦杩囷紝閬垮厤鍚庣画NPE
+ if (CollectionUtils.isEmpty(dtoList)) {
+ continue;
+ }
+ ProductModelExcelCopyDto firstDto = dtoList.get(0);
+ String model = firstDto.getModel();
+
+ // 3. 鏌ヨ/鏂板浜у搧锛堟寜浜у搧鍚嶇О+鍥剧焊缂栧彿锛屾洿绮惧噯锛�
+ Product product = getOrCreateProduct(productName, drawingNumber);
+
+ // 4. 鎵归噺澶勭悊浜у搧鍨嬪彿锛堟寜鍥剧焊缂栧彿+鍨嬪彿锛�
+ processProductModel(dtoList, product.getId(), model, drawingNumber,errorList);
+ }
+ if(CollectionUtils.isNotEmpty(errorList)){
+ // 5. 鎵归噺澶勭悊閿欒鏁版嵁
+ ExcelUtil<ProductModelExcelCopyErrorDto> errorExcelUtil = new ExcelUtil<>(ProductModelExcelCopyErrorDto.class);
+ errorExcelUtil.exportExcel(response,errorList, "閿欒鏁版嵁");
+ }
+ }
+
}
/**
@@ -183,16 +203,31 @@
* 鎶藉彇閫氱敤鏂规硶锛氬鐞嗕骇鍝佸瀷鍙凤紙鏂板/鏇存柊锛�
*/
private void processProductModel(List<ProductModelExcelCopyDto> dtoList,
- Long productId, String model, String drawingNumber) {
+ Long productId,
+ String model,
+ String drawingNumber,
+ List<ProductModelExcelCopyErrorDto> errorList) {
+ // 鏌ヨ鎵�鏈夊伐鑹鸿矾绾�
+ List<ProductProcess> productRoutes = productProcessMapper.selectList(new QueryWrapper<ProductProcess>());
+ if(CollectionUtils.isEmpty(productRoutes)){
+ productRoutes = new ArrayList<>();
+ }
for (ProductModelExcelCopyDto dto : dtoList) {
// 鏌ヨ鏉′欢锛氬瀷鍙�+鍥剧焊缂栧彿锛堟洿绮惧噯锛岀鍚堝垎缁勯�昏緫锛�
ProductModel productModel = productModelMapper.selectOne(new LambdaQueryWrapper<ProductModel>()
.eq(ProductModel::getModel, model)
.last("limit 1"));
-
+ // 閫氳繃宸ヨ壓璺嚎鍚嶇О鍖归厤鏈�鏂颁竴鏉″伐鑹鸿矾绾�
+ ProductProcess productRoute = productRoutes.stream()
+ .filter(route -> route.getName().equals(dto.getProcessRoute()))
+ .max(Comparator.comparing(ProductProcess::getCreateTime))
+ .orElse(null);
if (productModel == null) {
productModel = new ProductModel();
BeanUtils.copyProperties(dto, productModel);
+ if (productRoute != null) {
+ productModel.setRouteId(productRoute.getId());
+ }
// 鍏滃簳榛樿鍊硷紝閬垮厤绌哄��
if (productModel.getProductType() == null) {
productModel.setProductType(1);
@@ -200,6 +235,7 @@
productModel.setProductId(productId);
productModelMapper.insert(productModel);
} else {
+ productModel.setRouteId(productRoute != null ? productRoute.getId() : null);
BeanUtils.copyProperties(dto, productModel);
productModel.setProductId(productId);
productModelMapper.updateById(productModel);
--
Gitblit v1.9.3