diff --git a/microservices-modules/microservices-modules-pms/src/main/java/com/microservices/pms/productLibrary/service/impl/PmsProductLibraryAsyncServiceImpl.java b/microservices-modules/microservices-modules-pms/src/main/java/com/microservices/pms/productLibrary/service/impl/PmsProductLibraryAsyncServiceImpl.java index d4237e301..f5fb6d434 100644 --- a/microservices-modules/microservices-modules-pms/src/main/java/com/microservices/pms/productLibrary/service/impl/PmsProductLibraryAsyncServiceImpl.java +++ b/microservices-modules/microservices-modules-pms/src/main/java/com/microservices/pms/productLibrary/service/impl/PmsProductLibraryAsyncServiceImpl.java @@ -1,6 +1,9 @@ package com.microservices.pms.productLibrary.service.impl; +import com.microservices.common.core.constant.SecurityConstants; +import com.microservices.common.core.exception.ServiceException; import com.microservices.common.core.utils.StringUtils; +import com.microservices.common.core.utils.file.FileUtils; import com.microservices.common.core.utils.html.EscapeUtil; import com.microservices.pms.productLibrary.domain.PmsProductLibraryComponent; import com.microservices.pms.productLibrary.domain.PmsProductLibraryRepositories; @@ -13,7 +16,10 @@ import com.microservices.pms.utils.CustomExecutorFactory; import com.microservices.pms.utils.NexusRequestHelper; import com.microservices.pms.utils.NexusRequestUrl; import com.microservices.pms.utils.PythonUtil; +import com.microservices.system.api.RemoteFileService; +import com.microservices.system.api.domain.SysFile; import com.microservices.system.api.domain.SysFileBytes; +import com.microservices.system.api.utils.FeignUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -23,6 +29,7 @@ import org.springframework.stereotype.Service; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.stream.Collectors; @@ -41,6 +48,8 @@ public class PmsProductLibraryAsyncServiceImpl implements IPmsProductLibraryAsyn @Autowired @Lazy private IPmsProductLibraryRepositoriesService pmsProductLibraryRepositoriesService; + @Autowired + private RemoteFileService remoteFileService; @Override public void syncNexusMavenRepoComponent(PmsProductLibraryRepositories repo, List pmsProductLibraryComponents) { @@ -192,7 +201,44 @@ public class PmsProductLibraryAsyncServiceImpl implements IPmsProductLibraryAsyn CustomExecutorFactory.threadPoolExecutor.execute(() -> { pmsProductLibraryRepositoriesService.lockRepository(productRepo.getPmsEnterpriseIdentifier(), productRepo.getId()); try { + List componentList = + pmsProductLibraryComponentService.selectPmsProductLibraryComponentListByDatabase(productRepo.getId()); + HashMap packagedStructure = new HashMap<>(); + for (PmsProductLibraryComponent component : componentList) { + String fileIdentifier = component.getFileIdentifier(); + if (StringUtils.isEmpty(fileIdentifier)) { + String nexusFileUrl = EscapeUtil.removeExtraSlashOfUrl(productRepo.getUrl() + "/" + component.getPath()); + SysFileBytes fileBytes = nexusRequestHelper.getFileBytes(nexusFileUrl); + if (fileBytes == null) { + throw new ServiceException("制品文件不存在(制品路径[%s])", component.getPath()); + } + try { + SysFile assetFile = + FeignUtils.getReturnData( + remoteFileService.upload( + FileUtils.createMultipartFile(fileBytes.getFileInputStream(), fileBytes.getFileName()), + "pms", + productRepo.getPmsEnterpriseIdentifier() + "/productLibrary", + SecurityConstants.INNER)); + if (assetFile == null) { + throw new ServiceException("制品文件不存在(制品路径[%s])", component.getPath()); + } + fileIdentifier = assetFile.getFileIdentifier(); + } catch (IOException e) { + throw new ServiceException("制品文件上传至文件微服务失败:%s", e.getMessage()); + } + + } + packagedStructure.put(component.getGroup(), fileIdentifier); + } + String fileIdentifier = FeignUtils.getReturnData( + remoteFileService.packagedFile( + packagedStructure, + "pms", + productRepo.getPmsEnterpriseIdentifier() + "/productLibrary", + SecurityConstants.INNER) + ); } finally { pmsProductLibraryRepositoriesService.unlockRepository(productRepo.getPmsEnterpriseIdentifier(), productRepo.getId()); }