From f2c7576cbd050824ec78233483e06fc375382bfb Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期四, 02 四月 2026 17:04:03 +0800
Subject: [PATCH] yys 1.客户档案导入-维护人,维护时间默认当前 2.销售报价审核非必填,产品选择方式也要改 3.销售产品增加物料号字段 4.产品维护增加录入时间,修改时间 6.发货审核不需要了 7.BI的生产核算分析不要了,增加生产订单当前工序 3.库存导入模板规格改成图纸编号,产品名称可以为空,加个库位 4.库存管理外购改为标准件 5.bom产品唯一 6.产品根据bom计算子项数量(只统计二级)
---
src/main/java/com/ruoyi/production/service/impl/ProductBomServiceImpl.java | 214 +++++++++++++++++++++++++++++++++++++----------------
1 files changed, 150 insertions(+), 64 deletions(-)
diff --git a/src/main/java/com/ruoyi/production/service/impl/ProductBomServiceImpl.java b/src/main/java/com/ruoyi/production/service/impl/ProductBomServiceImpl.java
index 2554b5e..b334365 100644
--- a/src/main/java/com/ruoyi/production/service/impl/ProductBomServiceImpl.java
+++ b/src/main/java/com/ruoyi/production/service/impl/ProductBomServiceImpl.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.CollectionUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.basic.pojo.Product;
@@ -13,6 +14,7 @@
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.production.dto.BomImportDto;
+import com.ruoyi.production.dto.BomImportErrorDto;
import com.ruoyi.production.dto.ProductBomDto;
import com.ruoyi.production.dto.ProductStructureDto;
import com.ruoyi.production.mapper.ProductBomMapper;
@@ -22,6 +24,7 @@
import com.ruoyi.production.service.ProductBomService;
import com.ruoyi.production.service.ProductProcessService;
import com.ruoyi.production.service.ProductStructureService;
+import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -59,14 +62,42 @@
@Autowired
private ProductProcessService productProcessService;
+
@Override
public IPage<ProductBomDto> listPage(Page page, ProductBomDto productBomDto) {
return productBomMapper.listPage(page, productBomDto);
}
+ /**
+ * 浜у搧鏍规嵁bom璁$畻瀛愰」鏁伴噺锛堝彧缁熻浜岀骇锛�
+ */
+ public Long countChild(Long productModelId) {
+ ProductBom productBom = productBomMapper.selectOne(new LambdaQueryWrapper<ProductBom>()
+ .eq(ProductBom::getProductModelId, productModelId));
+ if(productBom != null){
+ return productStructureService.countBybomId(productBom.getId());
+ }
+ return 0L;
+ }
+
+ /**
+ * 鍒ゆ柇浜у搧鏄惁瀛樺湪bom false涓嶅瓨鍦� true瀛樺湪
+ * @param productBom
+ * @return
+ */
+ public boolean checkBom(ProductBom productBom) {
+ ProductBom productBom1 = productBomMapper.selectOne(new LambdaQueryWrapper<ProductBom>()
+ .eq(ProductBom::getProductModelId, productBom.getProductModelId()));
+ return productBom1 == null ? false : true;
+ }
+
@Override
@Transactional(rollbackFor = Exception.class)
public AjaxResult add(ProductBom productBom) {
+ boolean b = checkBom(productBom);
+ if (b) {
+ return AjaxResult.error("浜у搧妯″瀷宸插瓨鍦˙OM");
+ }
boolean save = productBomMapper.insert(productBom) > 0;
if (save) {
String no = "BM." + String.format("%05d", productBom.getId());
@@ -97,18 +128,74 @@
return AjaxResult.error();
}
+ /**
+ * 閫掑綊淇濆瓨 BOM锛氬厛淇濆瓨鐖堕」 鈫� 淇濆瓨瀛愰」 鈫� 寤虹珛鍏崇郴 鈫� 閫掑綊瀛愰」鐨勫瓙椤�
+ * @param children 褰撳墠鐖堕」鐨勫瓙椤瑰垪琛�
+ * @return 淇濆瓨鍚庣殑鐖堕」浜у搧ID
+ */
+ private void saveBomRecursive(List<BomImportDto> children,
+ ProductBom bom,ProductModel rootModel,
+ Map<String, Long> processMap,
+ List<BomImportErrorDto> errorList ) {
+ // 1. 鑾峰彇children涓瓙椤逛骇鍝佺紪鍙蜂负绌虹殑鏁版嵁
+ List<BomImportDto> parentChildren = children
+ .stream()
+ .filter(child -> StringUtils.isEmpty(child.getChildCode()))
+ .collect(Collectors.toList());
+ if(CollectionUtils.isEmpty(parentChildren)){
+ return;
+ }
+ BomImportDto parentId = parentChildren.get(0); // 鐖剁骇鏁版嵁
+ ProductStructure rootNode = new ProductStructure();
+ rootNode.setBomId(bom.getId());
+ rootNode.setParentId(null); // 椤跺眰娌℃湁鐖惰妭鐐�
+ rootNode.setProductModelId(rootModel.getId());
+ rootNode.setUnitQuantity(BigDecimal.ONE);
+ rootNode.setUnit(rootModel.getUnit());
+ productStructureService.save(rootNode);
+
+ // 2. 閬嶅巻瀛愰」锛岄�愪釜澶勭悊
+ for (BomImportDto child : children) {
+ // 璺宠繃娌℃湁瀛愰」鐨勭埗椤�
+ if(StringUtils.isEmpty(child.getChildCode())){
+ continue;
+ }
+ // 鑾峰彇瀛愰」妯″瀷淇℃伅
+ ProductModel childModel = findModel(child.getChildName(), child.getChildSpec());
+ if(childModel.getId() == null){
+ BomImportErrorDto errorDto = new BomImportErrorDto();
+ BeanUtils.copyProperties(child, errorDto);
+ errorDto.setErrorMsg(childModel.getErrorMsg());
+ errorList.add(errorDto);
+ continue;
+ }
+ // 鎻掑叆缁撴瀯琛�
+ ProductStructure node = new ProductStructure();
+ node.setBomId(bom.getId());
+ node.setParentId(rootNode.getId()); // 鐖惰妭鐐笽D
+ node.setProductModelId(childModel.getId());
+ node.setUnitQuantity(child.getUnitQty());
+ node.setUnit(childModel.getUnit());
+ if (processMap.containsKey(child.getProcess())) {
+ node.setProcessId(processMap.get(child.getProcess()));
+ }
+ productStructureService.save(node);
+ }
+ }
+
+
@Override
@Transactional(rollbackFor = Exception.class)
- public AjaxResult uploadBom(MultipartFile file) {
+ public void uploadBom(MultipartFile file,HttpServletResponse response) {
ExcelUtil<BomImportDto> util = new ExcelUtil<>(BomImportDto.class);
List<BomImportDto> list;
try {
list = util.importExcel(file.getInputStream());
} catch (Exception e) {
- return AjaxResult.error("Excel瑙f瀽澶辫触");
+ throw new ServiceException("Excel瑙f瀽澶辫触");
}
- if (list == null || list.isEmpty()) return AjaxResult.error("鏁版嵁涓虹┖");
+ if (list == null || list.isEmpty()) throw new ServiceException("鏂囦欢涓虹┖");
// 澶勭悊宸ュ簭
list.forEach(dto -> {
@@ -120,68 +207,48 @@
handleProcess(list);
Map<String, Long> processMap = productProcessService.list().stream()
.collect(Collectors.toMap(ProductProcess::getName, ProductProcess::getId, (k1, k2) -> k1));
+ // 1. 鎸夌埗椤圭紪鐮佸垎缁�
+ Map<String, List<BomImportDto>> parentMap = list.stream()
+ .filter(bom -> StringUtils.isNotBlank(bom.getParentCode()))
+ .collect(Collectors.groupingBy(BomImportDto::getParentCode));
+ List<BomImportErrorDto> errorList = new ArrayList<>();
+ // 2. 閬嶅巻鎵�鏈夌埗椤癸紝閫掑綊淇濆瓨
+ for (Map.Entry<String, List<BomImportDto>> entry : parentMap.entrySet()) {
- // 鍒涘缓 BOM 鏁版嵁
- BomImportDto first = list.get(0);
- ProductModel rootModel = findModel(first.getParentName(), first.getParentSpec());
- ProductBom bom = new ProductBom();
- bom.setProductModelId(rootModel.getId());
- bom.setVersion("1.0");
- productBomMapper.insert(bom);
- bom.setBomNo("BM." + String.format("%05d", bom.getId()));
- productBomMapper.updateById(bom);
-
- // 璁板綍宸茬粡鎻掑叆缁撴瀯鐨勮妭鐐癸細Key = "鍚嶇О+瑙勬牸", Value = structure_id
- Map<String, Long> treePathMap = new HashMap<>();
-
- for (int i = 0; i < list.size(); i++) {
- BomImportDto dto = list.get(i);
- String parentKey = dto.getParentName() + "|" + dto.getParentSpec();
- String childKey = dto.getChildName() + "|" + dto.getChildSpec();
-
- //澶勭悊鏍硅妭鐐�,绗竴琛屼笖瀛愰」涓虹┖
- if (i == 0 && StringUtils.isBlank(dto.getChildName())) {
- ProductStructure rootNode = new ProductStructure();
- rootNode.setBomId(bom.getId());
- rootNode.setParentId(null); // 椤跺眰娌℃湁鐖惰妭鐐�
- rootNode.setProductModelId(rootModel.getId());
- rootNode.setUnitQuantity(BigDecimal.ONE);
- rootNode.setUnit(rootModel.getUnit());
- productStructureService.save(rootNode);
-
- treePathMap.put(parentKey, rootNode.getId());
+ // 鍒涘缓 BOM 鏁版嵁
+ BomImportDto first = entry.getValue().get(0);
+ ProductModel rootModel = findModel(first.getParentName(), first.getParentSpec());
+ if(rootModel.getId() == null){
+ BomImportErrorDto error = new BomImportErrorDto();
+ BeanUtils.copyProperties(first, error);
+ error.setErrorMsg(rootModel.getErrorMsg());
+ errorList.add(error);
continue;
}
- // 澶勭悊瀛愬眰绾ц妭鐐�
- // 鎵惧埌鐖惰妭鐐瑰湪鏁版嵁搴撻噷鐨� ID
- Long parentStructureId = treePathMap.get(parentKey);
- if (parentStructureId == null) {
- // 濡傛灉 Map 閲屾壘涓嶅埌锛岃鏄� Excel 椤哄簭涔变簡鎴栬�呮暟鎹湁璇�
- throw new ServiceException("瀵煎叆澶辫触: 鐖堕」[" + dto.getParentName() + "]蹇呴』鍦ㄥ叾瀛愰」涔嬪墠瀹氫箟");
+ ProductBom bom = new ProductBom();
+ bom.setProductModelId(rootModel.getId());
+ bom.setVersion("1.0");
+ boolean b = checkBom(bom);
+ if(b){
+ BomImportErrorDto error = new BomImportErrorDto();
+ BeanUtils.copyProperties(first, error);
+ error.setErrorMsg("浜у搧銆�"+ first.getParentSpec() + "銆態OM宸插瓨鍦�");
+ errorList.add(error);
+ continue;
}
-
- // 鑾峰彇瀛愰」妯″瀷淇℃伅
- ProductModel childModel = findModel(dto.getChildName(), dto.getChildSpec());
-
- // 鎻掑叆缁撴瀯琛�
- ProductStructure node = new ProductStructure();
- node.setBomId(bom.getId());
- node.setParentId(parentStructureId); // 鐖惰妭鐐笽D
- node.setProductModelId(childModel.getId());
- node.setUnitQuantity(dto.getUnitQty());
- node.setUnit(childModel.getUnit());
- if (processMap.containsKey(dto.getProcess())) {
- node.setProcessId(processMap.get(dto.getProcess()));
- }
- productStructureService.save(node);
-
- // 鎶婂綋鍓嶅瓙椤硅褰曞埌 Map,浣滀负浠ュ悗鏇存繁灞傜骇鐨勭埗椤规煡鎵句緷鎹�
- // 鍚屼竴鐖堕」涓嬬殑鍚屽悕瀛愰」涓嶉渶瑕侀噸澶嶈褰�
- treePathMap.put(childKey, node.getId());
+ productBomMapper.insert(bom);
+ bom.setBomNo("BM." + String.format("%05d", bom.getId()));
+ productBomMapper.updateById(bom);
+ // 澶勭悊bom瀛愯〃鏁版嵁
+ List<BomImportDto> children = entry.getValue();
+ saveBomRecursive(children,bom,rootModel,processMap,errorList);
}
-
- return AjaxResult.success("BOM瀵煎叆鎴愬姛");
+ // 鍒ゆ柇鏄惁鏈夐敊璇暟鎹紝鏈夊氨瀵煎嚭
+ if(CollectionUtils.isNotEmpty(errorList)){
+ ExcelUtil<BomImportErrorDto> utils = new ExcelUtil<>(BomImportErrorDto.class);
+ utils.exportExcel(response,errorList, "BOM閿欒鏁版嵁");
+ }
}
@@ -252,6 +319,22 @@
util.exportExcel(response, exportList, "BOM缁撴瀯瀵煎嚭");
}
+ @Override
+ public String updateBom(ProductBom productBom) {
+ ProductBom productBom1 = productBomMapper.selectById(productBom.getId());
+ if(productBom.getProductModelId().equals(productBom1.getProductModelId())){
+ productBomMapper.updateById(productBom);
+ }else{
+ boolean b = checkBom(productBom);
+ if(b){
+ throw new ServiceException("浜у搧BOM宸插瓨鍦�");
+ }else{
+ productBomMapper.updateById(productBom);
+ }
+ }
+ return "淇敼鎴愬姛";
+ }
+
private void populateMap(List<ProductStructureDto> nodes, Map<Long, ProductStructureDto> map) {
if (nodes == null || nodes.isEmpty()) {
return;
@@ -263,14 +346,17 @@
}
private ProductModel findModel(String name, String spec) {
- Product product = productService.getOne(new LambdaQueryWrapper<Product>()
- .eq(Product::getProductName, name).last("limit 1"));
- if (product == null) throw new ServiceException("浜у搧鏈淮鎶わ細" + name);
+// Product product = productService.getOne(new LambdaQueryWrapper<Product>()
+// .eq(Product::getProductName, name).last("limit 1"));
+// if (product == null) throw new ServiceException("浜у搧鏈淮鎶わ細" + name);
ProductModel model = productModelService.getOne(new LambdaQueryWrapper<ProductModel>()
- .eq(ProductModel::getProductId, product.getId())
+// .eq(ProductModel::getProductId, product.getId())
.eq(ProductModel::getModel, spec).last("limit 1"));
- if (model == null) throw new ServiceException("瑙勬牸鏈淮鎶わ細" + name + "[" + spec + "]");
+ if (model == null){
+ model = new ProductModel();
+ model.setErrorMsg("鍥剧焊缂栧彿鏈淮鎶わ細" + "[" + spec + "]");
+ }
return model;
}
--
Gitblit v1.9.3