|
@@ -1,5 +1,6 @@
|
|
package cn.iocoder.yudao.module.pms.service.iotmainworkorder;
|
|
package cn.iocoder.yudao.module.pms.service.iotmainworkorder;
|
|
|
|
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.date.LocalDateTimeUtil;
|
|
import cn.hutool.core.date.LocalDateTimeUtil;
|
|
import cn.hutool.core.util.ObjUtil;
|
|
import cn.hutool.core.util.ObjUtil;
|
|
@@ -1298,72 +1299,98 @@ public class IotMainWorkOrderServiceImpl implements IotMainWorkOrderService {
|
|
Set<Long> mctDeviceIds = new HashSet<>();
|
|
Set<Long> mctDeviceIds = new HashSet<>();
|
|
// 需要更新 运行时长周期 的保养项id 集合
|
|
// 需要更新 运行时长周期 的保养项id 集合
|
|
Set<Long> mctBomNodeIds = new HashSet<>();
|
|
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 -> {
|
|
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());
|
|
tempMaterial.setWorkOrderId(mainWorkOrder.getId());
|
|
workOrderBomMaterialDOS.add(tempMaterial);
|
|
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);
|
|
iotMainWorkOrderBomMaterialMapper.insertBatch(workOrderBomMaterialDOS);
|
|
// key设备id-保养项BOM节点id value保养工单明细对象 用于更新关联的保养计划保养项
|
|
// key设备id-保养项BOM节点id value保养工单明细对象 用于更新关联的保养计划保养项
|
|
Map<String, IotMainWorkOrderBomSaveReqVO> deviceBomPair = new HashMap<>();
|
|
Map<String, IotMainWorkOrderBomSaveReqVO> deviceBomPair = new HashMap<>();
|
|
workOrderBOMs.forEach(bom -> {
|
|
workOrderBOMs.forEach(bom -> {
|
|
|
|
+ IotMainWorkOrderBomDO tempBom = BeanUtils.toBean(bom, IotMainWorkOrderBomDO.class);
|
|
if (ObjUtil.isNotEmpty(bom.getStatus()) && 0 == bom.getStatus()) {
|
|
if (ObjUtil.isNotEmpty(bom.getStatus()) && 0 == bom.getStatus()) {
|
|
// 兼容保养工单中部分保养项保养完成 部分保养项 延期保养的情况 这里只更新延期保养 或正常 保养的物料
|
|
// 兼容保养工单中部分保养项保养完成 部分保养项 延期保养的情况 这里只更新延期保养 或正常 保养的物料
|
|
- IotMainWorkOrderBomDO tempBom = BeanUtils.toBean(bom, IotMainWorkOrderBomDO.class);
|
|
|
|
// 如果工单明细中任何一个保养项设置了 任何一种推迟保养规则 工单结果 不能设置为 已执行
|
|
// 如果工单明细中任何一个保养项设置了 任何一种推迟保养规则 工单结果 不能设置为 已执行
|
|
- if (bom.getDelayKilometers().compareTo(BigDecimal.ZERO)>0
|
|
|
|
- || bom.getDelayDuration().compareTo(BigDecimal.ZERO)>0 || bom.getDelayNaturalDate().compareTo(BigDecimal.ZERO)>0) {
|
|
|
|
- tempBom.setStatus(0);
|
|
|
|
- mainCompleted.set(false);
|
|
|
|
- }
|
|
|
|
- if (bom.getDelayKilometers().compareTo(BigDecimal.ZERO)==0
|
|
|
|
|
|
+ /* if (bom.getDelayKilometers().compareTo(BigDecimal.ZERO)>0
|
|
|
|
+ || bom.getDelayDuration().compareTo(BigDecimal.ZERO)>0 || bom.getDelayNaturalDate().compareTo(BigDecimal.ZERO)>0) { */
|
|
|
|
+ tempBom.setStatus(0);
|
|
|
|
+ mainCompleted.set(false);
|
|
|
|
+ // }
|
|
|
|
+ /* if (bom.getDelayKilometers().compareTo(BigDecimal.ZERO)==0
|
|
&& bom.getDelayDuration().compareTo(BigDecimal.ZERO)==0 && bom.getDelayNaturalDate().compareTo(BigDecimal.ZERO)==0) {
|
|
&& bom.getDelayDuration().compareTo(BigDecimal.ZERO)==0 && bom.getDelayNaturalDate().compareTo(BigDecimal.ZERO)==0) {
|
|
// 如果保养项没有设置延时保养 则查询当前设备的 累计运行公里数 累计运行时间 当前时间日期 赋值到 关联保养计划 明细 的 对应保养规则数据上
|
|
// 如果保养项没有设置延时保养 则查询当前设备的 累计运行公里数 累计运行时间 当前时间日期 赋值到 关联保养计划 明细 的 对应保养规则数据上
|
|
deviceIds.add(bom.getDeviceId());
|
|
deviceIds.add(bom.getDeviceId());
|
|
// 保养项下如果已经添加了物料 说明该保养项已经保养完成
|
|
// 保养项下如果已经添加了物料 说明该保养项已经保养完成
|
|
bomNodeIds.add(bom.getBomNodeId());
|
|
bomNodeIds.add(bom.getBomNodeId());
|
|
tempBom.setStatus(1);
|
|
tempBom.setStatus(1);
|
|
- }
|
|
|
|
- workOrderBomDOS.add(tempBom);
|
|
|
|
|
|
+ } */
|
|
|
|
+ } else if (ObjUtil.isNotEmpty(bom.getStatus()) && 1 == bom.getStatus()) {
|
|
|
|
+ // 当前保养项已经保养完成 查询当前设备的 累计运行公里数 累计运行时间 当前时间日期 赋值到 关联保养计划 明细 的 对应保养规则数据上
|
|
|
|
+ deviceIds.add(bom.getDeviceId());
|
|
|
|
+ // 保养项下如果已经添加了物料 说明该保养项已经保养完成
|
|
|
|
+ bomNodeIds.add(bom.getBomNodeId());
|
|
|
|
+ tempBom.setStatus(1);
|
|
// 设置需要更新 关联保养计划 保养项 运行时间周期(H) 的设备id 保养项id 集合
|
|
// 设置需要更新 关联保养计划 保养项 运行时间周期(H) 的设备id 保养项id 集合
|
|
mctDeviceIds.add(bom.getDeviceId());
|
|
mctDeviceIds.add(bom.getDeviceId());
|
|
mctBomNodeIds.add(bom.getBomNodeId());
|
|
mctBomNodeIds.add(bom.getBomNodeId());
|
|
String uniqueKey = StrUtil.join("-", bom.getDeviceId(), bom.getBomNodeId());
|
|
String uniqueKey = StrUtil.join("-", bom.getDeviceId(), bom.getBomNodeId());
|
|
deviceBomPair.put(uniqueKey, bom);
|
|
deviceBomPair.put(uniqueKey, bom);
|
|
}
|
|
}
|
|
|
|
+ workOrderBomDOS.add(tempBom);
|
|
});
|
|
});
|
|
if (CollUtil.isNotEmpty(workOrderBOMs)) {
|
|
if (CollUtil.isNotEmpty(workOrderBOMs)) {
|
|
// 组装bom关联的设备信息
|
|
// 组装bom关联的设备信息
|
|
@@ -1463,16 +1490,16 @@ public class IotMainWorkOrderServiceImpl implements IotMainWorkOrderService {
|
|
if (2 == updateObj.getResult()) {
|
|
if (2 == updateObj.getResult()) {
|
|
if (CollUtil.isNotEmpty(filteredOrders)) {
|
|
if (CollUtil.isNotEmpty(filteredOrders)) {
|
|
// 将关联工单设置为 已执行 直接删除
|
|
// 将关联工单设置为 已执行 直接删除
|
|
- filteredOrders.forEach(order -> {order.setResult(2); order.setDeleted(true);});
|
|
|
|
|
|
+ filteredOrders.forEach(order -> { order.setResult(2); order.setDeleted(true); });
|
|
iotMainWorkOrderMapper.updateBatch(filteredOrders);
|
|
iotMainWorkOrderMapper.updateBatch(filteredOrders);
|
|
List<Long> workOrderIds = filteredOrders.stream()
|
|
List<Long> workOrderIds = filteredOrders.stream()
|
|
.map(IotMainWorkOrderDO::getId)
|
|
.map(IotMainWorkOrderDO::getId)
|
|
.collect(Collectors.toList());
|
|
.collect(Collectors.toList());
|
|
- // 将关联工单的明细 status 设置为 1
|
|
|
|
|
|
+ // 将关联工单的明细 status 设置为 1 直接删除
|
|
IotMainWorkOrderBomPageReqVO reqVO = new IotMainWorkOrderBomPageReqVO();
|
|
IotMainWorkOrderBomPageReqVO reqVO = new IotMainWorkOrderBomPageReqVO();
|
|
reqVO.setWorkOrderIds(workOrderIds);
|
|
reqVO.setWorkOrderIds(workOrderIds);
|
|
List<IotMainWorkOrderBomDO> associateOrderBomS = iotMainWorkOrderBomMapper.selectList(reqVO);
|
|
List<IotMainWorkOrderBomDO> associateOrderBomS = iotMainWorkOrderBomMapper.selectList(reqVO);
|
|
- associateOrderBomS.forEach(order -> order.setStatus(1));
|
|
|
|
|
|
+ associateOrderBomS.forEach(order -> { order.setStatus(1); order.setDeleted(true); });
|
|
iotMainWorkOrderBomMapper.updateBatch(associateOrderBomS);
|
|
iotMainWorkOrderBomMapper.updateBatch(associateOrderBomS);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -1488,10 +1515,10 @@ public class IotMainWorkOrderServiceImpl implements IotMainWorkOrderService {
|
|
order.setLaborCost(updateObj.getLaborCost());
|
|
order.setLaborCost(updateObj.getLaborCost());
|
|
order.setRemark(updateObj.getRemark());
|
|
order.setRemark(updateObj.getRemark());
|
|
});
|
|
});
|
|
|
|
+ // 更新 关联保养工单的相关数据
|
|
|
|
+ iotMainWorkOrderMapper.updateBatch(filteredOrders);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- // 如果在填报工单时 填写了 保养项 中的 ‘运行时间周期(H)’ 保存时需要同步到 保养工单 关联的 保养计划的 对应的保养项的 ‘运行时间周期(H)’
|
|
|
|
- // 包含 延时保养 的情况
|
|
|
|
// 只扣减本地库存 不处理SAP库存
|
|
// 只扣减本地库存 不处理SAP库存
|
|
// 保养基于单设备 出库时记录 单设备所属的部门id(即保养工单的部门id)
|
|
// 保养基于单设备 出库时记录 单设备所属的部门id(即保养工单的部门id)
|
|
if (CollUtil.isNotEmpty(factoryIds) && CollUtil.isNotEmpty(costCenterIds) && CollUtil.isNotEmpty(materialCodes)) {
|
|
if (CollUtil.isNotEmpty(factoryIds) && CollUtil.isNotEmpty(costCenterIds) && CollUtil.isNotEmpty(materialCodes)) {
|