From fe1b02a121c173e9b2d56bbe5a1982e0e69e0548 Mon Sep 17 00:00:00 2001
From: liding <756868258@qq.com>
Date: 星期二, 28 四月 2026 18:06:08 +0800
Subject: [PATCH] feat(production): 新增生产工单管理功能 - 创建 ProductionOperationTask 实体类定义工单数据结构 - 实现 ProductionOperationTaskController 提供工单的增删改查接口 - 开发 ProductionOperationTaskService 和实现类处理业务逻辑 - 配置 ProductionOperationTaskMapper 及 XML 文件实现数据库操作 - 添加 ProductionOperationTaskVo 视图对象用于数据展示 - 扩展 ProductionOrder 实体类增加生产订单相关属性 - 更新 ProductionOrderMapper.xml 完善订单查询映射配置 - 优化 ProductionOrderPickRecordMapper.xml 记录物料领取明细 - 新增 ProductionOrderRoutingOperationParam 参数配置实体 - 完善 工序参数处理逻辑
---
src/main/java/com/ruoyi/production/service/impl/ProductionOrderServiceImpl.java | 140 +++++++++++++++++++++++++++++++---------------
1 files changed, 93 insertions(+), 47 deletions(-)
diff --git a/src/main/java/com/ruoyi/production/service/impl/ProductionOrderServiceImpl.java b/src/main/java/com/ruoyi/production/service/impl/ProductionOrderServiceImpl.java
index f1ea57d..f994bb6 100644
--- a/src/main/java/com/ruoyi/production/service/impl/ProductionOrderServiceImpl.java
+++ b/src/main/java/com/ruoyi/production/service/impl/ProductionOrderServiceImpl.java
@@ -15,6 +15,8 @@
import com.ruoyi.common.constant.StorageAttachmentConstants;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.production.bean.dto.ProductionOrderDto;
+import com.ruoyi.production.bean.vo.ProductionBomStructureVo;
+import com.ruoyi.production.bean.vo.ProductionOrderPickVo;
import com.ruoyi.production.bean.vo.ProductionOrderVo;
import com.ruoyi.production.bean.vo.ProductionPlanVo;
import com.ruoyi.production.enums.ProductOrderStatusEnum;
@@ -23,6 +25,8 @@
import com.ruoyi.production.service.ProductionOrderService;
import com.ruoyi.sales.mapper.SalesLedgerMapper;
import com.ruoyi.sales.mapper.SalesLedgerProductMapper;
+import com.ruoyi.stock.mapper.StockInventoryMapper;
+import com.ruoyi.stock.pojo.StockInventory;
import com.ruoyi.technology.mapper.*;
import com.ruoyi.technology.pojo.*;
import lombok.RequiredArgsConstructor;
@@ -50,6 +54,7 @@
private final ProductionOrderPickMapper productionOrderPickMapper;
private final ProductionOrderPickRecordMapper productionOrderPickRecordMapper;
private final ProductionPlanMapper productionPlanMapper;
+ private final StockInventoryMapper stockInventoryMapper;
private final StorageAttachmentMapper storageAttachmentMapper;
private final StorageBlobMapper storageBlobMapper;
private final SalesLedgerMapper salesLedgerMapper;
@@ -112,11 +117,7 @@
|| productionOrderRoutingMapper.selectCount(Wrappers.<ProductionOrderRouting>lambdaQuery()
.eq(ProductionOrderRouting::getProductionOrderId, productionOrder.getId())) == 0);
if (needSync) {
- // 宸ヨ壓銆佷骇鍝佹垨鏁伴噺鍙樺寲鍚庯紝璁㈠崟蹇収蹇呴』鍜屽綋鍓嶄笅鍗曟暟鎹噸鏂板榻愩��
syncProductionOrderSnapshot(productionOrder.getId());
- } else {
- // 鏈噸寤哄揩鐓ф椂锛屼篃瑕佺‘淇濆鏂欎富鍗曞拰璁㈠崟鏁伴噺淇濇寔鍚屾銆�
- upsertOrderPick(productionOrder);
}
return true;
}
@@ -237,10 +238,11 @@
targetOperation.setDragSort(sourceOperation.getDragSort());
targetOperation.setIsQuality(sourceOperation.getIsQuality());
targetOperation.setOperationName(operationNameMap.get(sourceOperation.getTechnologyOperationId()));
+ targetOperation.setTechnologyOperationId(sourceOperation.getTechnologyOperationId());
productionOrderRoutingOperationMapper.insert(targetOperation);
ProductionOperationTask task = new ProductionOperationTask();
- task.setTechnologyRoutingOperationId(targetOperation.getId());
+ task.setProductionOrderRoutingOperationId(targetOperation.getId());
task.setProductionOrderId(productionOrder.getId());
task.setPlanQuantity(defaultDecimal(productionOrder.getQuantity()));
task.setCompleteQuantity(BigDecimal.ZERO);
@@ -256,7 +258,7 @@
// 宸ュ簭鎵ц鍙傛暟鍚屾牱鍋氬揩鐓э紝閬垮厤宸ヨ壓鍙傛暟璋冩暣褰卞搷宸蹭笅杈捐鍗曘��
ProductionOrderRoutingOperationParam targetParam = new ProductionOrderRoutingOperationParam();
targetParam.setProductionOrderId(productionOrder.getId());
- targetParam.setTechnologyRoutingOperationId(targetOperation.getId());
+ targetParam.setProductionOrderRoutingOperationId(targetOperation.getId());
targetParam.setTechnologyRoutingOperationParamId(sourceParam.getId());
targetParam.setParamId(sourceParam.getParamId());
targetParam.setTechnologyOperationId(sourceParam.getTechnologyOperationId());
@@ -273,8 +275,6 @@
syncedParamCount++;
}
}
-
- upsertOrderPick(productionOrder);
return syncedParamCount;
}
@@ -297,10 +297,9 @@
orderBom.setProductionOrderId(productionOrder.getId());
orderBom.setBomId(Long.valueOf(technologyBom.getId()));
orderBom.setProductModelId(root != null ? root.getProductModelId() : productionOrder.getProductModelId());
- orderBom.setTechnologyOperationId(root == null ? null : root.getOperationId());
- orderBom.setUnitQuantity(root != null && root.getUnitQuantity() != null ? root.getUnitQuantity() : BigDecimal.ONE);
- orderBom.setDemandedQuantity(orderQuantity);
- orderBom.setUnit(root == null ? null : root.getUnit());
+ orderBom.setRemark(technologyBom.getRemark());
+ orderBom.setBomNo(technologyBom.getBomNo());
+ orderBom.setVersion(technologyBom.getVersion());
productionOrderBomMapper.insert(orderBom);
Map<Long, Long> idMap = new HashMap<>();
@@ -313,7 +312,7 @@
target.setProductModelId(source.getProductModelId());
target.setTechnologyOperationId(source.getOperationId());
target.setUnitQuantity(source.getUnitQuantity());
- target.setDemandedQuantity(resolveBomDemandQuantity(source, orderQuantity));
+ target.setDemandedQuantity(source.getUnitQuantity().multiply(orderQuantity));
target.setUnit(source.getUnit());
productionBomStructureMapper.insert(target);
idMap.put(source.getId(), target.getId());
@@ -451,6 +450,12 @@
if (productionPlans.size() != planIds.size()) {
throw new ServiceException("閮ㄥ垎鐢熶骇璁″垝涓嶅瓨鍦�");
}
+ Map<Long, ProductionPlan> planMap = productionPlans.stream()
+ .collect(Collectors.toMap(ProductionPlan::getId, item -> item, (left, right) -> left));
+ ProductionPlan mainPlan = planMap.get(planIds.get(0));
+ if (mainPlan == null) {
+ throw new ServiceException("涓荤敓浜ц鍒掍笉瀛樺湪");
+ }
Set<Long> productModelIds = productionPlans.stream()
.map(ProductionPlan::getProductModelId)
.collect(Collectors.toSet());
@@ -460,7 +465,7 @@
if (productionPlans.stream().anyMatch(item -> item.getStatus() != null && item.getStatus() == 2)) {
throw new ServiceException("鎵�閫夌敓浜ц鍒掑凡涓嬪彂");
}
- ProductionPlan firstPlan = productionPlans.get(0);
+ ProductionPlan firstPlan = mainPlan;
if (productionOrder.getProductModelId() == null) {
productionOrder.setProductModelId(firstPlan.getProductModelId());
} else if (!Objects.equals(productionOrder.getProductModelId(), firstPlan.getProductModelId())) {
@@ -549,39 +554,6 @@
return 0;
}
return issuedQuantity.compareTo(requiredQuantity) < 0 ? 1 : 2;
- }
-
- private void upsertOrderPick(ProductionOrder productionOrder) {
- if (productionOrder == null || productionOrder.getId() == null) {
- return;
- }
- // 璁㈠崟涓嬭揪鍚庤嚜鍔ㄧ敓鎴愪竴寮犲鏂欎富鍗曪紝鍚庣画棰嗘枡璁板綍閮芥寕鍦ㄨ繖寮犲崟涓娿��
- ProductionOrderPick orderPick = productionOrderPickMapper.selectOne(
- Wrappers.<ProductionOrderPick>lambdaQuery()
- .eq(ProductionOrderPick::getProductionOrderId, productionOrder.getId())
- .last("limit 1"));
- if (orderPick == null) {
- orderPick = new ProductionOrderPick();
- orderPick.setProductionOrderId(productionOrder.getId());
- }
- orderPick.setProductModelId(productionOrder.getProductModelId() == null ? null : Math.toIntExact(productionOrder.getProductModelId()));
- orderPick.setQuantity(defaultDecimal(productionOrder.getQuantity()));
- orderPick.setRemark("涓嬪崟鑷姩鐢熸垚");
- if (orderPick.getId() == null) {
- productionOrderPickMapper.insert(orderPick);
- } else {
- productionOrderPickMapper.updateById(orderPick);
- }
- }
-
- private BigDecimal resolveBomDemandQuantity(TechnologyBomStructure source, BigDecimal orderQuantity) {
- // 宸ヨ壓 BOM 涓殑闇�姹傞噺鎸夆�滃崟浠堕渶姹� * 璁㈠崟鏁伴噺鈥濆睍寮�鎴愯鍗曠骇闇�姹傘��
- BigDecimal baseQuantity = source.getDemandedQuantity() != null ? source.getDemandedQuantity() : source.getUnitQuantity();
- baseQuantity = baseQuantity == null ? BigDecimal.ZERO : baseQuantity;
- if (baseQuantity.compareTo(BigDecimal.ZERO) <= 0) {
- return BigDecimal.ZERO;
- }
- return baseQuantity.multiply(orderQuantity);
}
private List<Long> parsePlanIds(String productionPlanIds) {
@@ -687,4 +659,78 @@
vo.setDownloadURL(fileUtil.buildSignedDownloadUrl(vo));
return vo;
}
+
+ @Override
+ public List<ProductionOrderPickVo> pick(Long productionOrderId) {
+ if (productionOrderId == null) {
+ return Collections.emptyList();
+ }
+
+ ProductionOrderBom orderBom = productionOrderBomMapper.selectOne(
+ Wrappers.<ProductionOrderBom>lambdaQuery()
+ .eq(ProductionOrderBom::getProductionOrderId, productionOrderId)
+ .orderByDesc(ProductionOrderBom::getId)
+ .last("limit 1"));
+ if (orderBom == null || orderBom.getId() == null) {
+ return Collections.emptyList();
+ }
+
+ List<ProductionBomStructureVo> bomStructureList = productionBomStructureMapper.pickByBomId(orderBom.getId());
+ if (bomStructureList == null || bomStructureList.isEmpty()) {
+ return Collections.emptyList();
+ }
+
+ List<Long> productModelIds = bomStructureList.stream()
+ .map(ProductionBomStructureVo::getProductModelId)
+ .filter(Objects::nonNull)
+ .distinct()
+ .collect(Collectors.toList());
+ Map<Long, BigDecimal> stockQuantityMap = new HashMap<>();
+ Map<Long, LinkedHashSet<String>> stockBatchNoMap = new HashMap<>();
+ if (!productModelIds.isEmpty()) {
+ List<StockInventory> stockList = stockInventoryMapper.selectList(
+ Wrappers.<StockInventory>lambdaQuery()
+ .in(StockInventory::getProductModelId, productModelIds));
+ for (StockInventory stockItem : stockList) {
+ if (stockItem == null || stockItem.getProductModelId() == null) {
+ continue;
+ }
+ Long productModelId = stockItem.getProductModelId();
+ stockQuantityMap.merge(productModelId, defaultDecimal(stockItem.getQualitity()), BigDecimal::add);
+ String batchNo = stockItem.getBatchNo();
+ if (batchNo != null && !batchNo.trim().isEmpty()) {
+ stockBatchNoMap.computeIfAbsent(productModelId, key -> new LinkedHashSet<>()).add(batchNo);
+ }
+ }
+ }
+
+ Map<String, ProductionOrderPickVo> mergedPickMap = new LinkedHashMap<>();
+ for (ProductionBomStructureVo structure : bomStructureList) {
+ if (structure == null || structure.getProductModelId() == null) {
+ continue;
+ }
+ Long productModelId = structure.getProductModelId();
+ String mergeKey = String.valueOf(structure.getTechnologyOperationId()) + "#" + productModelId;
+ ProductionOrderPickVo vo = mergedPickMap.get(mergeKey);
+ if (vo == null) {
+ vo = new ProductionOrderPickVo();
+ vo.setProductModelId(productModelId);
+ vo.setOperationName(structure.getOperationName());
+ vo.setTechnologyOperationId(structure.getTechnologyOperationId());
+ vo.setProductName(structure.getProductName());
+ vo.setModel(structure.getModel());
+ vo.setDemandedQuantity(BigDecimal.ZERO);
+ vo.setUnit(structure.getUnit());
+ List<String> batchNoList = stockBatchNoMap.get(productModelId) == null
+ ? Collections.emptyList()
+ : new ArrayList<>(stockBatchNoMap.get(productModelId));
+ vo.setBatchNoList(batchNoList);
+ vo.setStockQuantity(stockQuantityMap.getOrDefault(productModelId, BigDecimal.ZERO));
+ vo.setBom(true);
+ mergedPickMap.put(mergeKey, vo);
+ }
+ vo.setDemandedQuantity(defaultDecimal(vo.getDemandedQuantity()).add(defaultDecimal(structure.getDemandedQuantity())));
+ }
+ return new ArrayList<>(mergedPickMap.values());
+ }
}
--
Gitblit v1.9.3