| | |
| | | package org.jeecg.modules.dnc.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import liquibase.pro.packaged.S; |
| | | 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.ComponentInfo; |
| | | import org.jeecg.modules.dnc.entity.DocFile; |
| | | import org.jeecg.modules.dnc.entity.*; |
| | | import org.jeecg.modules.dnc.exception.ExceptionCast; |
| | | import org.jeecg.modules.dnc.mapper.DocRelativeMapper; |
| | | import org.jeecg.modules.dnc.response.ActivitiCode; |
| | | import org.jeecg.modules.dnc.response.DocumentCode; |
| | | import org.jeecg.modules.dnc.service.IDocClassificationService; |
| | | import org.jeecg.modules.dnc.service.IDocFileService; |
| | | import org.jeecg.modules.dnc.service.IDocInfoService; |
| | | import org.jeecg.modules.dnc.service.IDocRelativeService; |
| | | import org.jeecg.modules.dnc.utils.CompressionUtils; |
| | | import org.jeecg.modules.dnc.utils.JsonUtils; |
| | | import org.jeecg.modules.dnc.utils.file.FileUtilS; |
| | | import org.jeecg.modules.dncFlow.service.IAssignFileStreamService; |
| | | 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; |
| | |
| | | @Service |
| | | public class FileFerryService { |
| | | |
| | | private final DataPackageService dataPackageService; |
| | | private final SecurityService securityService; |
| | | |
| | | private static final Logger logger = LoggerFactory.getLogger(FileFerryService.class); |
| | | |
| | | @Value("${deploy.secretFolder}") |
| | |
| | | @Value("${fileHomePath}") |
| | | private String fileHomePath; |
| | | |
| | | @Value("${jeecg.path.upload}") |
| | | private String upLoadPath; |
| | | |
| | | @Autowired |
| | | private MdcEquipmentMapper mdcEquipmentMapper; |
| | | |
| | |
| | | private IMdcProductionService mdcProductionService; |
| | | |
| | | @Autowired |
| | | private IDocInfoService docInfoService; |
| | | |
| | | @Autowired |
| | | private IDocClassificationService classificationService; |
| | | |
| | | @Autowired |
| | | private IDocRelativeService docRelativeService; |
| | | |
| | | @Autowired |
| | | private IDocInfoService docInfoService; |
| | | |
| | | @Autowired |
| | | public FileFerryService(DataPackageService dataPackageService, SecurityService securityService) { |
| | | this.dataPackageService = dataPackageService; |
| | | this.securityService = securityService; |
| | | } |
| | | private DataPackageService dataPackageService; |
| | | |
| | | public String exportData(TransferPackage.DataType type, String id,String fileName) { |
| | | // 1. 获取封装数据 |
| | |
| | | throw new RuntimeException("文件写入失败", e); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | public TransferPackage importData(String filePath) { |
| | | try { |
| | |
| | | |
| | | // 6. 获取文件复制目标路径 |
| | | DocFile docFile = pkg.getTraceChain().getDocFile(); |
| | | DocInfo docInfo = pkg.getTraceChain().getDocInfo(); |
| | | if (docFile == null) { |
| | | throw new IllegalStateException("传输包中缺少文档文件信息"); |
| | | } |
| | |
| | | Path source = Paths.get(ncFilePath); |
| | | Files.copy(source, Paths.get(targetPath), StandardCopyOption.REPLACE_EXISTING); |
| | | |
| | | // 10.删除临时NC文件与json文件 |
| | | // 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("文件传输路径获取失败"); |
| | | } |
| | | |
| | | // 计算后一个文件名 |
| | | long nextNumber = Long.parseLong(numericPart); |
| | | nextNumber++; |
| | | |
| | | //获取序列化的程序确认表数据 |
| | | GuideCardBatch guideCardBatch=pkg.getTraceChain().getGuideCardBatch(); |
| | | |
| | | //获取文件路径 |
| | | String pictureUrl=guideCardBatch.getPicture(); |
| | | |
| | | // 保持相同位数格式 |
| | | String nextNumeric = String.format("%0" + numericPart.length() + "d", nextNumber); |
| | | String nextFileName = prefix + nextNumeric + "_" + equipmentId+"."+pictureUrl.split("\\.")[1]; |
| | | String nextFilePath = path.getParent().resolve(nextFileName).toString(); |
| | | |
| | | //拼接现有路径 |
| | | String picturePtah=upLoadPath+"/"+pictureUrl; |
| | | |
| | | // 9. 复制文件并重命名 |
| | | logger.info("复制文件: {} → {}", nextFilePath,picturePtah); |
| | | Path PicSource= Paths.get(nextFilePath); |
| | | Files.copy(PicSource, Paths.get(picturePtah), StandardCopyOption.REPLACE_EXISTING); |
| | | |
| | | // 删除文件 |
| | | logger.info("删除临时文件: {}", ncFilePath); |
| | | Files.delete(source); |
| | | Files.delete(path); |
| | | Files.delete(PicSource); |
| | | |
| | | return JsonUtils.fromJson(json, TransferPackage.class); |
| | | |