|
@@ -2,15 +2,22 @@ package cn.iocoder.yudao.module.pms.service.iotdevicebom;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.util.ObjUtil;
|
|
import cn.hutool.core.util.ObjUtil;
|
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotdevicebom.vo.IotDeviceBomListReqVO;
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotdevicebom.vo.IotDeviceBomListReqVO;
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotdevicebom.vo.IotDeviceBomPageReqVO;
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotdevicebom.vo.IotDeviceBomPageReqVO;
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotdevicebom.vo.IotDeviceBomSaveReqVO;
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotdevicebom.vo.IotDeviceBomSaveReqVO;
|
|
|
|
+import cn.iocoder.yudao.module.pms.controller.admin.iotmaintenancebom.vo.IotMaintenanceBomPageReqVO;
|
|
|
|
+import cn.iocoder.yudao.module.pms.controller.admin.iotmainworkorderbom.vo.IotMainWorkOrderBomPageReqVO;
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.IotDeviceDO;
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.IotDeviceDO;
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicebom.IotDeviceBomDO;
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicebom.IotDeviceBomDO;
|
|
|
|
+import cn.iocoder.yudao.module.pms.dal.dataobject.iotmaintenancebom.IotMaintenanceBomDO;
|
|
|
|
+import cn.iocoder.yudao.module.pms.dal.dataobject.iotmainworkorderbom.IotMainWorkOrderBomDO;
|
|
import cn.iocoder.yudao.module.pms.dal.mysql.IotDeviceMapper;
|
|
import cn.iocoder.yudao.module.pms.dal.mysql.IotDeviceMapper;
|
|
import cn.iocoder.yudao.module.pms.dal.mysql.iotdevicebom.IotDeviceBomMapper;
|
|
import cn.iocoder.yudao.module.pms.dal.mysql.iotdevicebom.IotDeviceBomMapper;
|
|
|
|
+import cn.iocoder.yudao.module.pms.dal.mysql.iotmaintenancebom.IotMaintenanceBomMapper;
|
|
|
|
+import cn.iocoder.yudao.module.pms.dal.mysql.iotmainworkorderbom.IotMainWorkOrderBomMapper;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.validation.annotation.Validated;
|
|
@@ -20,6 +27,7 @@ import java.util.*;
|
|
|
|
|
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
import static cn.iocoder.yudao.module.pms.enums.ErrorCodeConstant.IOT_DEVICE_BOM_NOT_EXISTS;
|
|
import static cn.iocoder.yudao.module.pms.enums.ErrorCodeConstant.IOT_DEVICE_BOM_NOT_EXISTS;
|
|
|
|
+import static cn.iocoder.yudao.module.pms.enums.ErrorCodeConstant.IOT_MAIN_PLAN_ORDER_EXISTS;
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -35,6 +43,10 @@ public class IotDeviceBomServiceImpl implements IotDeviceBomService {
|
|
private IotDeviceBomMapper iotDeviceBomMapper;
|
|
private IotDeviceBomMapper iotDeviceBomMapper;
|
|
@Resource
|
|
@Resource
|
|
private IotDeviceMapper iotDeviceMapper;
|
|
private IotDeviceMapper iotDeviceMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ private IotMaintenanceBomMapper iotMaintenanceBomMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ private IotMainWorkOrderBomMapper iotMainWorkOrderBomMapper;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@@ -63,10 +75,58 @@ public class IotDeviceBomServiceImpl implements IotDeviceBomService {
|
|
@Override
|
|
@Override
|
|
public void updateIotDeviceBom(IotDeviceBomSaveReqVO updateReqVO) {
|
|
public void updateIotDeviceBom(IotDeviceBomSaveReqVO updateReqVO) {
|
|
// 校验存在
|
|
// 校验存在
|
|
- validateIotDeviceBomExists(updateReqVO.getId());
|
|
|
|
- // 更新
|
|
|
|
|
|
+ IotDeviceBomDO deviceBom = validateIotDeviceBomExists(updateReqVO.getId());
|
|
|
|
+ // 校验 如果当前保养项是否已经存在保养计划 保养工单 并且修改后的保养项 没有设置 保养 选项
|
|
|
|
+ // 提醒 先处理保养计划 或 保养工单 中的保养项
|
|
|
|
+ ValidateResult validateResult = validateExistPlanOrder(deviceBom);
|
|
|
|
+ Map<String, List<IotMaintenanceBomDO>> planBomsPair = validateResult.getPlanBomPair();
|
|
|
|
+ Map<String, List<IotMainWorkOrderBomDO>> orderBomsPair = validateResult.getWorkOrderBomPair();
|
|
|
|
+ if ((CollUtil.isNotEmpty(planBomsPair)
|
|
|
|
+ || CollUtil.isNotEmpty(orderBomsPair)) && !updateReqVO.getType().contains(2)) {
|
|
|
|
+ throw exception(IOT_MAIN_PLAN_ORDER_EXISTS);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 更新 保养项
|
|
IotDeviceBomDO updateObj = BeanUtils.toBean(updateReqVO, IotDeviceBomDO.class);
|
|
IotDeviceBomDO updateObj = BeanUtils.toBean(updateReqVO, IotDeviceBomDO.class);
|
|
iotDeviceBomMapper.updateById(updateObj);
|
|
iotDeviceBomMapper.updateById(updateObj);
|
|
|
|
+
|
|
|
|
+ // 如果修改了保养项名称 暂时覆盖 正在运行中的 保养计划 保养工单 明细中对应的 保养项名称
|
|
|
|
+ if (CollUtil.isNotEmpty(planBomsPair)) {
|
|
|
|
+ List<IotMaintenanceBomDO> planBoms = planBomsPair.get("planBoms");
|
|
|
|
+ if (CollUtil.isNotEmpty(planBoms)) {
|
|
|
|
+ // 查询 bomNodeIds 集合中每个bom节点的所有上级节点
|
|
|
|
+ // 查询所有 设备boms节点的所有上级节点名称 拼接出 全路径 的bom节点
|
|
|
|
+ List<Long> bomNodeIds = new ArrayList<>();
|
|
|
|
+ bomNodeIds.add(updateReqVO.getId());
|
|
|
|
+ Map<Long, String> bomFullPaths = buildBomFullPaths(bomNodeIds);
|
|
|
|
+ planBoms.forEach(bom -> {
|
|
|
|
+ if (bomFullPaths.containsKey(updateReqVO.getId())) {
|
|
|
|
+ if (StrUtil.isNotBlank(bomFullPaths.get(updateReqVO.getId())) && updateReqVO.getId().equals(bom.getBomNodeId())) {
|
|
|
|
+ bom.setName(bomFullPaths.get(updateReqVO.getId()));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ iotMaintenanceBomMapper.updateBatch(planBoms);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (CollUtil.isNotEmpty(orderBomsPair)) {
|
|
|
|
+ List<IotMainWorkOrderBomDO> orderBoms = orderBomsPair.get("orderBoms");
|
|
|
|
+ if (CollUtil.isNotEmpty(orderBoms)) {
|
|
|
|
+ // 查询 bomNodeIds 集合中每个bom节点的所有上级节点
|
|
|
|
+ // 查询所有 设备boms节点的所有上级节点名称 拼接出 全路径 的bom节点
|
|
|
|
+ List<Long> bomNodeIds = new ArrayList<>();
|
|
|
|
+ bomNodeIds.add(updateReqVO.getId());
|
|
|
|
+ Map<Long, String> bomFullPaths = buildBomFullPaths(bomNodeIds);
|
|
|
|
+ orderBoms.forEach(bom -> {
|
|
|
|
+ if (bomFullPaths.containsKey(updateReqVO.getId())) {
|
|
|
|
+ if (StrUtil.isNotBlank(bomFullPaths.get(updateReqVO.getId())) && updateReqVO.getId().equals(bom.getBomNodeId())) {
|
|
|
|
+ bom.setName(bomFullPaths.get(updateReqVO.getId()));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ iotMainWorkOrderBomMapper.updateBatch(orderBoms);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
// 设置设备BOM关联的设备的 bom_sync_status = 1
|
|
// 设置设备BOM关联的设备的 bom_sync_status = 1
|
|
iotDeviceMapper.updateBomSyncStatus(updateObj.getDeviceId());
|
|
iotDeviceMapper.updateBomSyncStatus(updateObj.getDeviceId());
|
|
}
|
|
}
|
|
@@ -75,9 +135,65 @@ public class IotDeviceBomServiceImpl implements IotDeviceBomService {
|
|
public void deleteIotDeviceBom(Long id) {
|
|
public void deleteIotDeviceBom(Long id) {
|
|
// 校验存在
|
|
// 校验存在
|
|
IotDeviceBomDO deviceBom = validateIotDeviceBomExists(id);
|
|
IotDeviceBomDO deviceBom = validateIotDeviceBomExists(id);
|
|
|
|
+ // 校验当前设备BOM保养项是否已经关联了保养计划 保养工单
|
|
|
|
+ ValidateResult validateResult = validateExistPlanOrder(deviceBom);
|
|
|
|
+ if (CollUtil.isNotEmpty(validateResult.getPlanBomPair())
|
|
|
|
+ || CollUtil.isNotEmpty(validateResult.getWorkOrderBomPair())) {
|
|
|
|
+ throw exception(IOT_MAIN_PLAN_ORDER_EXISTS);
|
|
|
|
+ }
|
|
// 删除
|
|
// 删除
|
|
iotDeviceBomMapper.deleteById(id);
|
|
iotDeviceBomMapper.deleteById(id);
|
|
iotDeviceMapper.updateBomSyncStatus(deviceBom.getDeviceId());
|
|
iotDeviceMapper.updateBomSyncStatus(deviceBom.getDeviceId());
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 校验当前保养项是否已经存在关联的保养计划 保养工单
|
|
|
|
+ * @param deviceBom
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ private ValidateResult validateExistPlanOrder(IotDeviceBomDO deviceBom){
|
|
|
|
+ Map<String, List<IotMaintenanceBomDO>> planBomPair = new HashMap<>();
|
|
|
|
+ Map<String, List<IotMainWorkOrderBomDO>> workOrderBomPair = new HashMap<>();
|
|
|
|
+ // 校验当前设备BOM保养项是否已经关联了保养计划 保养工单
|
|
|
|
+ IotMaintenanceBomPageReqVO bomReqVO = new IotMaintenanceBomPageReqVO();
|
|
|
|
+ bomReqVO.setDeviceId(deviceBom.getDeviceId());
|
|
|
|
+ bomReqVO.setBomNodeId(deviceBom.getId());
|
|
|
|
+ List<IotMaintenanceBomDO> planBoms = iotMaintenanceBomMapper.selectList(bomReqVO);
|
|
|
|
+ if (CollUtil.isNotEmpty(planBoms)) {
|
|
|
|
+ planBomPair.put("planBoms", planBoms);
|
|
|
|
+ }
|
|
|
|
+ // 查询当前设备bom保养项集合关联的 运行中(未保养完成) 的工单
|
|
|
|
+ IotMainWorkOrderBomPageReqVO orderBomReqVO = new IotMainWorkOrderBomPageReqVO();
|
|
|
|
+ orderBomReqVO.setDeviceId(deviceBom.getDeviceId());
|
|
|
|
+ orderBomReqVO.setBomNodeId(deviceBom.getId());
|
|
|
|
+ orderBomReqVO.setStatus(0);
|
|
|
|
+ List<IotMainWorkOrderBomDO> orderBoms = iotMainWorkOrderBomMapper.selectList(orderBomReqVO);
|
|
|
|
+ if (CollUtil.isNotEmpty(orderBoms)) {
|
|
|
|
+ workOrderBomPair.put("orderBoms", orderBoms);
|
|
|
|
+ }
|
|
|
|
+ return new ValidateResult(planBomPair, workOrderBomPair);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private class ValidateResult {
|
|
|
|
+ private Map<String, List<IotMaintenanceBomDO>> planBomPair;
|
|
|
|
+ private Map<String, List<IotMainWorkOrderBomDO>> workOrderBomPair;
|
|
|
|
+
|
|
|
|
+ // 构造方法
|
|
|
|
+ public ValidateResult(Map<String, List<IotMaintenanceBomDO>> planBomPair,
|
|
|
|
+ Map<String, List<IotMainWorkOrderBomDO>> workOrderBomPair) {
|
|
|
|
+ this.planBomPair = planBomPair;
|
|
|
|
+ this.workOrderBomPair = workOrderBomPair;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // getter
|
|
|
|
+ public Map<String, List<IotMaintenanceBomDO>> getPlanBomPair() {
|
|
|
|
+ return planBomPair;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Map<String, List<IotMainWorkOrderBomDO>> getWorkOrderBomPair() {
|
|
|
|
+ return workOrderBomPair;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
private IotDeviceBomDO validateIotDeviceBomExists(Long id) {
|
|
private IotDeviceBomDO validateIotDeviceBomExists(Long id) {
|