|
|
|
|
@ -1,11 +1,23 @@
|
|
|
|
|
package cn.iocoder.yudao.module.mes.service.criticalcomponent;
|
|
|
|
|
|
|
|
|
|
import cn.iocoder.yudao.module.iot.dal.dataobject.deviceattributetype.DeviceAttributeTypeDO;
|
|
|
|
|
import cn.iocoder.yudao.module.iot.dal.dataobject.devicemodelattribute.DeviceModelAttributeDO;
|
|
|
|
|
import cn.iocoder.yudao.module.iot.dal.devicecontactmodel.DeviceContactModelDO;
|
|
|
|
|
import cn.iocoder.yudao.module.mes.dal.dataobject.deviceledger.DeviceLedgerDO;
|
|
|
|
|
import cn.iocoder.yudao.module.mes.dal.dataobject.repairtems.RepairTemsDO;
|
|
|
|
|
import cn.iocoder.yudao.module.mes.dal.mysql.deviceledger.DeviceLedgerMapper;
|
|
|
|
|
import cn.iocoder.yudao.module.mes.dal.mysql.repairtems.RepairTemsMapper;
|
|
|
|
|
import com.alibaba.excel.util.StringUtils;
|
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
import cn.iocoder.yudao.module.mes.controller.admin.criticalcomponent.vo.*;
|
|
|
|
|
import cn.iocoder.yudao.module.mes.dal.dataobject.criticalcomponent.CriticalComponentDO;
|
|
|
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
|
|
@ -15,6 +27,8 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
|
|
|
import cn.iocoder.yudao.module.mes.dal.mysql.criticalcomponent.CriticalComponentMapper;
|
|
|
|
|
|
|
|
|
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
|
|
|
import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.DEVICE_ATTRIBUTE_TYPE_NOT_EXISTS;
|
|
|
|
|
import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.DEVICE_ATTRIBUTE_TYPE_REFERENCES_EXISTS;
|
|
|
|
|
import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.*;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -29,6 +43,13 @@ public class CriticalComponentServiceImpl implements CriticalComponentService {
|
|
|
|
|
@Resource
|
|
|
|
|
private CriticalComponentMapper criticalComponentMapper;
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private DeviceLedgerMapper deviceLedgerMapper;
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private RepairTemsMapper repairTemsMapper;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Long createCriticalComponent(CriticalComponentSaveReqVO createReqVO) {
|
|
|
|
|
// 插入
|
|
|
|
|
@ -48,14 +69,75 @@ public class CriticalComponentServiceImpl implements CriticalComponentService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void deleteCriticalComponent(List<Long> idList) {
|
|
|
|
|
for (Long id : idList) {
|
|
|
|
|
// 校验存在
|
|
|
|
|
validateCriticalComponentExists(id);
|
|
|
|
|
public void deleteCriticalComponent(List<Long> ids) {
|
|
|
|
|
|
|
|
|
|
if (CollectionUtils.isEmpty(ids)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 批量校验存在性
|
|
|
|
|
List<CriticalComponentDO> existList = criticalComponentMapper.selectBatchIds(ids);
|
|
|
|
|
if (existList.size() != ids.size()) {
|
|
|
|
|
throw exception(CRITICAL_COMPONENT_NOT_EXISTS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 检验设备台账引用
|
|
|
|
|
validateDeviceLedgerBatchReferences(ids);
|
|
|
|
|
|
|
|
|
|
//检验项目维护引用
|
|
|
|
|
validateDvjectBatchReferences(ids);
|
|
|
|
|
|
|
|
|
|
// 删除
|
|
|
|
|
criticalComponentMapper.deleteByIds(idList);
|
|
|
|
|
criticalComponentMapper.deleteByIds(ids);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void validateDvjectBatchReferences(List<Long> ids) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
boolean isExists = repairTemsMapper.exists(
|
|
|
|
|
Wrappers.<RepairTemsDO>lambdaQuery()
|
|
|
|
|
.in(RepairTemsDO::getComponentId, ids));
|
|
|
|
|
|
|
|
|
|
if (isExists){
|
|
|
|
|
throw exception(CRITICAL_COMPONENT_REFERENCES);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void validateDeviceLedgerBatchReferences(List<Long> ids) {
|
|
|
|
|
// 查询所有包含这些ID的记录
|
|
|
|
|
List<DeviceLedgerDO> ledgers = deviceLedgerMapper.selectList(
|
|
|
|
|
Wrappers.<DeviceLedgerDO>lambdaQuery()
|
|
|
|
|
.isNotNull(DeviceLedgerDO::getComponentId)
|
|
|
|
|
.select(DeviceLedgerDO::getComponentId)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (CollectionUtils.isEmpty(ledgers)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 检查每个componentId字段是否包含目标ID
|
|
|
|
|
for (DeviceLedgerDO ledger : ledgers) {
|
|
|
|
|
if (StringUtils.isBlank(ledger.getComponentId())) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 将逗号分隔的ID转换为Set
|
|
|
|
|
Set<Long> componentIds = Arrays.stream(ledger.getComponentId().split(","))
|
|
|
|
|
.map(String::trim)
|
|
|
|
|
.filter(StringUtils::isNotBlank)
|
|
|
|
|
.map(Long::valueOf)
|
|
|
|
|
.collect(Collectors.toSet());
|
|
|
|
|
|
|
|
|
|
// 检查是否有交集
|
|
|
|
|
for (Long id : ids) {
|
|
|
|
|
if (componentIds.contains(id)) {
|
|
|
|
|
throw exception(CRITICAL_COMPONENT_REFERENCES);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void validateCriticalComponentExists(Long id) {
|
|
|
|
|
|