|
@@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.date.LocalDateTimeUtil;
|
|
|
import cn.hutool.core.util.ObjUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
|
|
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
@@ -17,8 +18,11 @@ import cn.iocoder.yudao.module.pms.controller.admin.iotmainworkorder.vo.IotMainW
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotmainworkorderbom.vo.IotMainWorkOrderBomPageReqVO;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotmainworkorderbom.vo.IotMainWorkOrderBomRespVO;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotmainworkorderbom.vo.IotMainWorkOrderBomSaveReqVO;
|
|
|
+import cn.iocoder.yudao.module.pms.controller.admin.iotmainworkorderbommaterial.vo.IotMainWorkOrderBomMaterialPageReqVO;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotmainworkorderbommaterial.vo.IotMainWorkOrderBomMaterialSaveReqVO;
|
|
|
+import cn.iocoder.yudao.module.pms.controller.admin.vo.IotDevicePageReqVO;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceRespVO;
|
|
|
+import cn.iocoder.yudao.module.pms.dal.dataobject.IotDeviceDO;
|
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.iotlockstock.IotLockStockDO;
|
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.iotmaintenancebom.IotMaintenanceBomDO;
|
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.iotmainworkorder.IotMainWorkOrderDO;
|
|
@@ -381,29 +385,6 @@ public class IotMainWorkOrderServiceImpl implements IotMainWorkOrderService {
|
|
|
* @return
|
|
|
*/
|
|
|
private List<Long> sortByNumericValue(Map<Long, String> map) {
|
|
|
- /* return map.entrySet().stream()
|
|
|
- // 转换数值并保留原始entry
|
|
|
- .map(entry -> {
|
|
|
- try {
|
|
|
- // 移除所有字母后缀并转换为double
|
|
|
- String cleanValue = entry.getValue()
|
|
|
- .replaceAll("[A-Za-z]+$", "");
|
|
|
- double numericValue = Double.parseDouble(cleanValue);
|
|
|
- return new AbstractMap.SimpleEntry<>(entry.getKey(), numericValue);
|
|
|
- } catch (NumberFormatException e) {
|
|
|
- // 数值转换失败处理(返回最大值确保排在最后)
|
|
|
- return new AbstractMap.SimpleEntry<>(entry.getKey(), Double.MAX_VALUE);
|
|
|
- }
|
|
|
- })
|
|
|
- // 双级排序:先按数值升序,数值相同再按key升序
|
|
|
- // 显式指定泛型类型
|
|
|
- .sorted(Comparator
|
|
|
- .<AbstractMap.SimpleEntry<Long, Double>>comparingDouble(AbstractMap.SimpleEntry::getValue)
|
|
|
- .thenComparingLong(AbstractMap.SimpleEntry::getKey)
|
|
|
- )
|
|
|
- // 提取排序后的key
|
|
|
- .map(AbstractMap.SimpleEntry::getKey)
|
|
|
- .collect(Collectors.toList()); */
|
|
|
return map.entrySet().stream()
|
|
|
.map(entry -> {
|
|
|
String[] parts = entry.getValue().split("\\s+");
|
|
@@ -902,17 +883,27 @@ public class IotMainWorkOrderServiceImpl implements IotMainWorkOrderService {
|
|
|
if (CollUtil.isEmpty(deviceIds) || CollUtil.isEmpty(personIds)) {
|
|
|
return;
|
|
|
}
|
|
|
+ // 查询设备集合修改前的部门
|
|
|
+ IotDevicePageReqVO deviceReqVO = new IotDevicePageReqVO();
|
|
|
+ deviceReqVO.setDeviceIds(deviceIds);
|
|
|
+ List<IotDeviceDO> devices = iotDeviceMapper.selectList(deviceReqVO);
|
|
|
+ Set<Long> deviceDeptIds = devices.stream()
|
|
|
+ .map(IotDeviceDO::getDeptId) // 提取deptId属性
|
|
|
+ .collect(Collectors.toSet()); // 收集为Set以保证唯一性
|
|
|
+
|
|
|
// 查询当前设备对应的 责任人 前端页面已经统一设置了相同的责任人(有可能多个 多个责任人时随机取1个)
|
|
|
Long personId = personIds.get(0);
|
|
|
// 查询当前设备集合的所有历史保养工单 如果历史工单明细中包含2个设备A,B,但是只调拨了1个设备A,此时 只复制设备A明细生成一个 执行完成的保养工单
|
|
|
IotMainWorkOrderBomPageReqVO reqVO = new IotMainWorkOrderBomPageReqVO();
|
|
|
reqVO.setDeviceIds(deviceIds);
|
|
|
reqVO.setStatus(1); // 查询已经保养完成的工单
|
|
|
- List<IotMainWorkOrderBomDO> workOrderBomS = iotMainWorkOrderBomMapper.selectList(reqVO);
|
|
|
+ // List<IotMainWorkOrderBomDO> workOrderBomS = iotMainWorkOrderBomMapper.selectList(reqVO);
|
|
|
+ List<IotMainWorkOrderBomDO> workOrderBomS = iotMainWorkOrderBomMapper.historyWorkOrderBomS(new ArrayList<>(deviceDeptIds), deviceIds);
|
|
|
// 以 工单id+设备id+设备负责人 为维度组成 工单BOM集合
|
|
|
Map<Long, List<IotMainWorkOrderBomDO>> workOrderBomPair = new HashMap<>();
|
|
|
Map<Long, IotMainWorkOrderDO> workOrderPair = new HashMap<>();
|
|
|
Set<Long> workOrderIds = new HashSet<>();
|
|
|
+ Set<Long> bomNodeIds = new HashSet<>();
|
|
|
// 需要新增的保养工单集合 (历史工单)
|
|
|
List<IotMainWorkOrderDO> tobeAddedOrders = new ArrayList<>();
|
|
|
// 需要新增的保养工单明细集合 (历史工单)
|
|
@@ -931,7 +922,28 @@ public class IotMainWorkOrderServiceImpl implements IotMainWorkOrderService {
|
|
|
workOrderBomPair.put(bom.getWorkOrderId(), tempBomS);
|
|
|
}
|
|
|
workOrderIds.add(bom.getWorkOrderId());
|
|
|
+ bomNodeIds.add(bom.getBomNodeId());
|
|
|
});
|
|
|
+ // 查询 指定保养工单集合内 bomNodeId集合内 的挂载的物料集合
|
|
|
+ Map<String, List<IotMainWorkOrderBomMaterialDO>> workOrderMaterialPair = new HashMap<>();
|
|
|
+ IotMainWorkOrderBomMaterialPageReqVO materialReqVO = new IotMainWorkOrderBomMaterialPageReqVO();
|
|
|
+ materialReqVO.setWorkOrderIds(new ArrayList<>(workOrderIds));
|
|
|
+ materialReqVO.setBomNodeIds(new ArrayList<>(bomNodeIds));
|
|
|
+ List<IotMainWorkOrderBomMaterialDO> historyBomMaterials = iotMainWorkOrderBomMaterialMapper.selectList(materialReqVO);
|
|
|
+ if (CollUtil.isNotEmpty(historyBomMaterials)) {
|
|
|
+ historyBomMaterials.forEach(material -> {
|
|
|
+ String uniqueKey = StrUtil.join("-", material.getWorkOrderId(), material.getBomNodeId());
|
|
|
+ if (workOrderMaterialPair.containsKey(uniqueKey)) {
|
|
|
+ List<IotMainWorkOrderBomMaterialDO> tempMaterials = workOrderMaterialPair.get(uniqueKey);
|
|
|
+ tempMaterials.add(material);
|
|
|
+ workOrderMaterialPair.put(uniqueKey, tempMaterials);
|
|
|
+ } else {
|
|
|
+ List<IotMainWorkOrderBomMaterialDO> tempMaterials = new ArrayList<>();
|
|
|
+ tempMaterials.add(material);
|
|
|
+ workOrderMaterialPair.put(uniqueKey, tempMaterials);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
// 查询所有保养工单明细对应的保养工单主表集合
|
|
|
IotMainWorkOrderPageReqVO orderReqVO = new IotMainWorkOrderPageReqVO();
|
|
|
orderReqVO.setWorkOrderIds(new ArrayList<>(workOrderIds));
|
|
@@ -952,7 +964,7 @@ public class IotMainWorkOrderServiceImpl implements IotMainWorkOrderService {
|
|
|
workOrder.setId(theMaxId.get());
|
|
|
workOrder.setDeptId(deptId);
|
|
|
if (workOrderPair.containsKey(k)) {
|
|
|
- workOrder.setName(workOrderPair.get(k).getName());
|
|
|
+ workOrder.setName(workOrderPair.get(k).getName() + " 历史");
|
|
|
workOrder.setPlanId(workOrderPair.get(k).getPlanId());
|
|
|
workOrder.setType(workOrderPair.get(k).getType());
|
|
|
workOrder.setCost(workOrderPair.get(k).getCost());
|
|
@@ -975,14 +987,28 @@ public class IotMainWorkOrderServiceImpl implements IotMainWorkOrderService {
|
|
|
tempBom.setId(null);
|
|
|
tempBom.setWorkOrderId(workOrderId);
|
|
|
tobeAddedOrderBomS.add(tempBom);
|
|
|
- System.out.println("当前保养明细名称:" + bom.getName());
|
|
|
+ // 3. 处理BOM明细关联的物料
|
|
|
+ String uniqueKey = StrUtil.join("-", k, bom.getBomNodeId());
|
|
|
+ if (workOrderMaterialPair.containsKey(uniqueKey)) {
|
|
|
+ List<IotMainWorkOrderBomMaterialDO> bomMaterials = workOrderMaterialPair.get(uniqueKey);
|
|
|
+ bomMaterials.forEach(material -> {
|
|
|
+ IotMainWorkOrderBomMaterialDO tempMaterial = new IotMainWorkOrderBomMaterialDO();
|
|
|
+ BeanUtils.copyProperties(material, tempMaterial);
|
|
|
+ tempMaterial.setId(null);
|
|
|
+ tempMaterial.setWorkOrderId(workOrderId);
|
|
|
+ tobeAddedOrderBomMaterialS.add(tempMaterial);
|
|
|
+ });
|
|
|
+ }
|
|
|
});
|
|
|
});
|
|
|
- // todo 还要处理保养项已经关联的物料
|
|
|
+ // 插入 保养工单 保养工单明细 保养工单明细关联的物料
|
|
|
if (CollUtil.isNotEmpty(tobeAddedOrders) && CollUtil.isNotEmpty(tobeAddedOrderBomS)) {
|
|
|
iotMainWorkOrderMapper.insertBatch(tobeAddedOrders);
|
|
|
iotMainWorkOrderBomMapper.insertBatch(tobeAddedOrderBomS);
|
|
|
- System.out.println("保养工单明细集合数量:" + tobeAddedOrderBomS.size());
|
|
|
+ }
|
|
|
+ // 插入 保养工单明细关联的物料
|
|
|
+ if (CollUtil.isNotEmpty(tobeAddedOrderBomMaterialS)) {
|
|
|
+ iotMainWorkOrderBomMaterialMapper.insertBatch(tobeAddedOrderBomMaterialS);
|
|
|
}
|
|
|
}
|
|
|
}
|