From 3777b6430fe0ed70186cbbcdcf38c464e3adf47f Mon Sep 17 00:00:00 2001
From: liding <756868258@qq.com>
Date: 星期五, 27 三月 2026 17:57:59 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/dev_长治_健齿齿科器材' into dev_长治_健齿齿科器材
---
src/main/java/com/ruoyi/production/service/impl/ProductOrderServiceImpl.java | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 110 insertions(+), 4 deletions(-)
diff --git a/src/main/java/com/ruoyi/production/service/impl/ProductOrderServiceImpl.java b/src/main/java/com/ruoyi/production/service/impl/ProductOrderServiceImpl.java
index 65498fc..0ed4db6 100644
--- a/src/main/java/com/ruoyi/production/service/impl/ProductOrderServiceImpl.java
+++ b/src/main/java/com/ruoyi/production/service/impl/ProductOrderServiceImpl.java
@@ -4,27 +4,35 @@
import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
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.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.basic.dto.SelectOptionDTO;
+import com.ruoyi.common.enums.StockOutQualifiedRecordTypeEnum;
import com.ruoyi.common.exception.base.BaseException;
+import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.procurementrecord.utils.StockUtils;
+import com.ruoyi.production.dto.DrawMaterialDto;
import com.ruoyi.production.dto.ProductOrderDto;
import com.ruoyi.production.dto.ProductStructureDto;
import com.ruoyi.production.mapper.*;
import com.ruoyi.production.pojo.*;
import com.ruoyi.production.service.ProductOrderService;
import com.ruoyi.quality.mapper.QualityInspectMapper;
+import com.ruoyi.stock.dto.StockInventoryDto;
+import com.ruoyi.stock.mapper.StockInventoryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
import java.util.stream.Collectors;
@Service
@@ -65,6 +73,13 @@
@Autowired
private StockUtils stockUtils;
+
+ @Autowired
+ private ProductStructureMapper productStructureMapper;
+
+ @Autowired
+ private StockInventoryMapper stockInventoryMapper;
+
@Override
public IPage<ProductOrderDto> pageProductOrder(Page page, ProductOrderDto productOrder) {
@@ -160,11 +175,11 @@
//濡傛灉宸茬粡寮�濮嬬敓浜�,涓嶈兘鍒犻櫎
//鏌ヨ鐢熶骇璁㈠崟涓嬬殑宸ュ崟
List<ProductWorkOrder> productWorkOrders = productWorkOrderMapper.selectList(Wrappers.<ProductWorkOrder>lambdaQuery().in(ProductWorkOrder::getProductOrderId, ids));
- if (productWorkOrders.size()>0){
+ if (productWorkOrders.size() > 0) {
//鍒ゆ柇鏄惁鏈夋姤宸ユ暟鎹�
List<ProductionProductMain> productionProductMains = productionProductMainMapper.selectList(Wrappers.<ProductionProductMain>lambdaQuery()
.in(ProductionProductMain::getWorkOrderId, productWorkOrders.stream().map(ProductWorkOrder::getId).collect(Collectors.toList())));
- if (productionProductMains.size()>0){
+ if (productionProductMains.size() > 0) {
throw new RuntimeException("鐢熶骇璁㈠崟宸茬粡寮�濮嬬敓浜�,涓嶈兘鍒犻櫎");
}
//鍒犻櫎宸ュ崟
@@ -229,4 +244,95 @@
productOrder.setCleanRecord(JSON.toJSONString(cleanRecord));
return productOrderMapper.updateById(productOrder);
}
+
+ @Override
+ public List<SelectOptionDTO<String>> getProductOrderBatchNo() {
+ List<ProductOrder> productOrders = productOrderMapper.selectList(null);
+ return productOrders.stream().map(productOrder -> new SelectOptionDTO<>(productOrder.getBatchNo(), productOrder.getBatchNo())).collect(Collectors.toList());
+ }
+
+ @Override
+ public List<StockInventoryDto> getByBomId(Long bomId) {
+ List<ProductStructureDto> structureList = productStructureMapper.listBybomId(bomId);
+
+ if (CollectionUtils.isEmpty(structureList)) {
+ return Collections.emptyList();
+ }
+
+ Set<Long> allNodeIds = structureList.stream()
+ .map(ProductStructureDto::getId)
+ .collect(Collectors.toSet());
+
+ Set<Long> parentIds = structureList.stream()
+ .filter(node -> node.getParentId() != null && node.getParentId() != 0)
+ .map(ProductStructureDto::getParentId)
+ .collect(Collectors.toSet());
+
+ Set<Long> leafNodeIds = new HashSet<>(allNodeIds);
+ leafNodeIds.removeAll(parentIds);
+
+ // 鑾峰彇鍙跺瓙鑺傜偣鐨� productModelId
+ List<Long> productModelIds = structureList.stream()
+ .filter(node -> leafNodeIds.contains(node.getId()))
+ .map(ProductStructureDto::getProductModelId)
+ .filter(Objects::nonNull)
+ .distinct()
+ .collect(Collectors.toList());
+
+ if (productModelIds.isEmpty()) {
+ return Collections.emptyList();
+ }
+
+ return stockInventoryMapper.getStockInventory(productModelIds);
+ }
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public int drawMaterials(ProductOrderDto productOrderDto) {
+ if (productOrderDto == null || productOrderDto.getId() == null) {
+ throw new RuntimeException("鍙傛暟閿欒");
+ }
+
+ String jsonString = productOrderDto.getDrawMaterials();
+ if (StringUtils.isEmpty(jsonString)) {
+ throw new RuntimeException("棰嗘枡鏄庣粏涓嶈兘涓虹┖");
+ }
+
+ List<DrawMaterialDto> drawMaterialsList;
+ try {
+ drawMaterialsList = JSON.parseArray(jsonString, DrawMaterialDto.class);
+ } catch (Exception e) {
+ throw new RuntimeException("棰嗘枡鏄庣粏鏍煎紡閿欒");
+ }
+
+ if (CollectionUtils.isEmpty(drawMaterialsList)) {
+ throw new RuntimeException("棰嗘枡鏄庣粏涓嶈兘涓虹┖");
+ }
+
+ // 澶勭悊棰嗘枡锛堟墸鍑忓簱瀛橈級
+ try {
+ for (DrawMaterialDto drawMaterialDto : drawMaterialsList) {
+ if (drawMaterialDto.getProductModelId() == null) {
+ throw new RuntimeException("浜у搧鍨嬪彿ID涓嶈兘涓虹┖");
+ }
+ stockUtils.substractStock(drawMaterialDto.getProductModelId(), drawMaterialDto.getRequisitionQty(), StockOutQualifiedRecordTypeEnum.DRAW_MATERIALS_STOCK_OUT.getCode(), productOrderDto.getId());
+ }
+ } catch (Exception e) {
+ throw new RuntimeException("棰嗘枡澶辫触锛�" + e.getMessage());
+ }
+
+ // JSON瀛楃涓插瓨鍌�
+ String newJsonString = JSON.toJSONString(drawMaterialsList);
+ int update = productOrderMapper.update(null,
+ new LambdaUpdateWrapper<ProductOrder>()
+ .eq(ProductOrder::getId, productOrderDto.getId())
+ .set(ProductOrder::getDrawMaterials, newJsonString));
+
+ // 鏍¢獙鏇存柊缁撴灉
+ if (update == 0) {
+ throw new RuntimeException("鏇存柊璁㈠崟澶辫触");
+ }
+
+ return update;
+ }
}
--
Gitblit v1.9.3