|
@@ -1,5 +1,6 @@
|
|
|
package cn.iocoder.yudao.module.pms.service.iotmainworkorder;
|
|
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.date.LocalDateTimeUtil;
|
|
|
import cn.hutool.core.util.ObjUtil;
|
|
@@ -1298,43 +1299,63 @@ public class IotMainWorkOrderServiceImpl implements IotMainWorkOrderService {
|
|
|
Set<Long> mctDeviceIds = new HashSet<>();
|
|
|
// 需要更新 运行时长周期 的保养项id 集合
|
|
|
Set<Long> mctBomNodeIds = new HashSet<>();
|
|
|
+ // 需要消耗物料的保养项id集合
|
|
|
+ Set<Long> materialBomNodeIds = new HashSet<>();
|
|
|
+ // 保养完成的保养项id集合
|
|
|
+ Set<Long> completedBomNodeIds = new HashSet<>();
|
|
|
+ // 统计保养项信息 是否保养完成 是否需要消耗物料
|
|
|
+ workOrderBOMs.forEach(bom -> {
|
|
|
+ if ("0".equals(bom.getRule())) {
|
|
|
+ // 需要消耗物料
|
|
|
+ materialBomNodeIds.add(bom.getBomNodeId());
|
|
|
+ }
|
|
|
+ if (1 == bom.getStatus()) {
|
|
|
+ // 保养完成
|
|
|
+ completedBomNodeIds.add(bom.getBomNodeId());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ // 只有保养完成的保养项关联的物料才会被统计出库(如果物料来源是 本地库存)
|
|
|
workOrderMaterials.forEach(material -> {
|
|
|
- if (ObjUtil.isEmpty(material.getId())) {
|
|
|
- // 兼容保养工单中部分保养项保养完成 部分保养项延期保养的情况 这里只新增延期保养 或 正常保养的物料
|
|
|
- IotMainWorkOrderBomMaterialDO tempMaterial = BeanUtils.toBean(material, IotMainWorkOrderBomMaterialDO.class);
|
|
|
+ // 兼容保养工单中部分保养项保养完成 部分保养项延期保养的情况 这里只新增延期保养 或 正常保养的物料
|
|
|
+ if (materialBomNodeIds.contains(material.getBomNodeId())) {
|
|
|
+ IotMainWorkOrderBomMaterialDO tempMaterial = BeanUtil.copyProperties(material, IotMainWorkOrderBomMaterialDO.class, "id");
|
|
|
tempMaterial.setWorkOrderId(mainWorkOrder.getId());
|
|
|
workOrderBomMaterialDOS.add(tempMaterial);
|
|
|
+ }
|
|
|
|
|
|
- if ("本地库存".equals(material.getMaterialSource())) {
|
|
|
- if (ObjUtil.isNotEmpty(material.getFactoryId())) {
|
|
|
- factoryIds.add(material.getFactoryId());
|
|
|
- }
|
|
|
- if (ObjUtil.isNotEmpty(material.getCostCenterId())) {
|
|
|
- costCenterIds.add(material.getCostCenterId());
|
|
|
- }
|
|
|
- if (ObjUtil.isNotEmpty(material.getStorageLocationId())) {
|
|
|
- storageLocationIds.add(material.getStorageLocationId());
|
|
|
- }
|
|
|
- if (ObjUtil.isNotEmpty(material.getMaterialCode())) {
|
|
|
- materialCodes.add(material.getMaterialCode());
|
|
|
- }
|
|
|
- String uniqueKey = StrUtil.join("-", material.getFactoryId(),
|
|
|
- material.getCostCenterId(), material.getMaterialCode(), material.getBomNodeId());
|
|
|
- String tempKey = material.getFactoryId() + String.valueOf(material.getCostCenterId())
|
|
|
- + material.getMaterialCode();
|
|
|
- // 扣减库存使用 合并不同保养项下的相同物料
|
|
|
- if (lockStockPair.containsKey(tempKey)) {
|
|
|
- BigDecimal tempQuantity = lockStockPair.get(tempKey);
|
|
|
- BigDecimal totalQuantity = tempQuantity.add(material.getQuantity());
|
|
|
- lockStockPair.put(tempKey, totalQuantity);
|
|
|
- } else {
|
|
|
- lockStockPair.put(tempKey, material.getQuantity());
|
|
|
- }
|
|
|
- // 记录出库使用 记录保养项id
|
|
|
- bomMaterialPair.put(uniqueKey, material);
|
|
|
+ if (completedBomNodeIds.contains(material.getBomNodeId()) && "本地库存".equals(material.getMaterialSource())) {
|
|
|
+ if (ObjUtil.isNotEmpty(material.getFactoryId())) {
|
|
|
+ factoryIds.add(material.getFactoryId());
|
|
|
+ }
|
|
|
+ if (ObjUtil.isNotEmpty(material.getCostCenterId())) {
|
|
|
+ costCenterIds.add(material.getCostCenterId());
|
|
|
+ }
|
|
|
+ if (ObjUtil.isNotEmpty(material.getStorageLocationId())) {
|
|
|
+ storageLocationIds.add(material.getStorageLocationId());
|
|
|
+ }
|
|
|
+ if (ObjUtil.isNotEmpty(material.getMaterialCode())) {
|
|
|
+ materialCodes.add(material.getMaterialCode());
|
|
|
}
|
|
|
+ String uniqueKey = StrUtil.join("-", material.getFactoryId(),
|
|
|
+ material.getCostCenterId(), material.getMaterialCode(), material.getBomNodeId());
|
|
|
+ String tempKey = material.getFactoryId() + String.valueOf(material.getCostCenterId())
|
|
|
+ + material.getMaterialCode();
|
|
|
+ // 扣减库存使用 合并不同保养项下的相同物料
|
|
|
+ if (lockStockPair.containsKey(tempKey)) {
|
|
|
+ BigDecimal tempQuantity = lockStockPair.get(tempKey);
|
|
|
+ BigDecimal totalQuantity = tempQuantity.add(material.getQuantity());
|
|
|
+ lockStockPair.put(tempKey, totalQuantity);
|
|
|
+ } else {
|
|
|
+ lockStockPair.put(tempKey, material.getQuantity());
|
|
|
+ }
|
|
|
+ // 记录出库使用 记录保养项id
|
|
|
+ bomMaterialPair.put(uniqueKey, material);
|
|
|
}
|
|
|
});
|
|
|
+ // 删除当前工单已有的保养项物料 再新增
|
|
|
+ if (ObjUtil.isNotEmpty(updateObj.getId())) {
|
|
|
+ iotMainWorkOrderBomMaterialMapper.updateToDelete(updateObj.getId(), LocalDateTime.now());
|
|
|
+ }
|
|
|
// 添加 工单消耗的物料记录
|
|
|
iotMainWorkOrderBomMaterialMapper.insertBatch(workOrderBomMaterialDOS);
|
|
|
// key设备id-保养项BOM节点id value保养工单明细对象 用于更新关联的保养计划保养项
|