feat(制品库功能开发): 产品库增加打包下载产品库功能
异步处理文件打包逻辑: 1. 打包期间锁定产品库,防止产品库文件发生变化导致最终结果不一致 2. 由于产品库实际为Raw类型,且每个产品库下的制品都会在数据库存储一份,所以通过数据库获取该产品库下所有制品文件 3. 检查制品文件是否存在对应的文件标识,若不存在则从Nexus下载并上传至文件微服务并获取文件标识 4. 构建制品在产品库中的相对路径以及制品文件标识的Map对象,调用文件微服务打包文件接口对产品库进行打包
This commit is contained in:
parent
ba49299cb7
commit
6dbe90994c
|
|
@ -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<PmsProductLibraryComponent> pmsProductLibraryComponents) {
|
||||
|
|
@ -192,7 +201,44 @@ public class PmsProductLibraryAsyncServiceImpl implements IPmsProductLibraryAsyn
|
|||
CustomExecutorFactory.threadPoolExecutor.execute(() -> {
|
||||
pmsProductLibraryRepositoriesService.lockRepository(productRepo.getPmsEnterpriseIdentifier(), productRepo.getId());
|
||||
try {
|
||||
List<PmsProductLibraryComponent> componentList =
|
||||
pmsProductLibraryComponentService.selectPmsProductLibraryComponentListByDatabase(productRepo.getId());
|
||||
HashMap<String, String> 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());
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue