| | |
| | | package org.jeecg.modules.dnc.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.jeecg.modules.dnc.dto.ComponentHierarchy; |
| | | import org.jeecg.modules.dnc.dto.TransferPackage; |
| | | import org.jeecg.modules.dnc.entity.*; |
| | | import org.jeecg.modules.dnc.exception.ExceptionCast; |
| | | import org.jeecg.modules.dnc.response.ActivitiCode; |
| | | import org.jeecg.modules.dnc.response.DocumentCode; |
| | | import org.jeecg.modules.dnc.entity.ComponentInfo; |
| | | import org.jeecg.modules.dnc.entity.DocFile; |
| | | import org.jeecg.modules.dnc.service.IDocClassificationService; |
| | | import org.jeecg.modules.dnc.service.IDocInfoService; |
| | | import org.jeecg.modules.dnc.service.IDocRelativeService; |
| | | import org.jeecg.modules.dnc.utils.JsonUtils; |
| | | import org.jeecg.modules.dnc.utils.file.FileUtilS; |
| | | import org.jeecg.modules.mdc.entity.MdcEquipment; |
| | | import org.jeecg.modules.mdc.mapper.MdcEquipmentMapper; |
| | | import org.jeecg.modules.system.service.IMdcProductionService; |
| | | import org.slf4j.Logger; |
| | |
| | | |
| | | // 6. 获取文件复制目标路径 |
| | | DocFile docFile = pkg.getTraceChain().getDocFile(); |
| | | DocInfo docInfo = pkg.getTraceChain().getDocInfo(); |
| | | if (docFile == null) { |
| | | throw new IllegalStateException("传输包中缺少文档文件信息"); |
| | | } |
| | |
| | | logger.info("复制文件: {} → {}", ncFilePath, targetPath); |
| | | Path source = Paths.get(ncFilePath); |
| | | Files.copy(source, Paths.get(targetPath), StandardCopyOption.REPLACE_EXISTING); |
| | | |
| | | // 8. 查询设备id |
| | | MdcEquipment mdcEquipment=mdcEquipmentMapper.selectOne(new QueryWrapper<MdcEquipment>().eq("equipment_id",equipmentId)); |
| | | if (mdcEquipment == null) { |
| | | throw new IllegalArgumentException("无效的设备ID: " + equipmentId); |
| | | } |
| | | |
| | | // 9.传输文件到设备下 |
| | | List<String> strings = mdcProductionService.findListParentTreeAll(mdcEquipment.getId()); |
| | | if (strings != null && !strings.isEmpty()) { |
| | | DocInfo deviceDoc = docInfoService.getByDocAttrAndDocId(docInfo.getDocId(), 7, mdcEquipment.getId()); |
| | | if (deviceDoc == null) { |
| | | DocClassification classification = classificationService.getByCode("send"); |
| | | if(classification == null) |
| | | ExceptionCast.cast(DocumentCode.DOC_CLASS_ERROR); |
| | | DocRelative docRelative = new DocRelative(); |
| | | docRelative.setDocId(docInfo.getDocId()); |
| | | docRelative.setClassificationId(classification.getClassificationId()); |
| | | docRelative.setAttributionType(7); |
| | | docRelative.setAttributionId(mdcEquipment.getId()); |
| | | docRelativeService.save(docRelative); |
| | | } |
| | | String sendPath = StringUtils.join(strings.toArray(), "/"); |
| | | boolean copyFileNc = FileUtilS.copyFileNc(docFile.getFilePath(), sendPath + "/" + mdcEquipment.getEquipmentId(), |
| | | docFile.getFileEncodeName(), |
| | | docFile.getFileName(), docFile.getFileSuffix()); |
| | | if (!copyFileNc) { |
| | | ExceptionCast.cast(ActivitiCode.ACT_FILE_ERROR); |
| | | } else { |
| | | FileUtilS.deleteZipFromToSend(sendPath + "/" + mdcEquipment.getEquipmentId(), |
| | | docFile.getFileName(), docFile.getFileSuffix()); |
| | | } |
| | | } else { |
| | | throw new RuntimeException("文件传输路径获取失败"); |
| | | } |
| | | |
| | | // 10.删除临时NC文件与json文件 |
| | | logger.info("删除临时文件: {}", ncFilePath); |