feat(制品库功能完善): 优化通过Feign远程请求文件服务逻辑
This commit is contained in:
parent
02fe6e7ec9
commit
2242cc6473
|
|
@ -20,9 +20,9 @@ import com.microservices.pms.productLibrary.mapper.PmsProductLibraryComponentMap
|
|||
import com.microservices.pms.productLibrary.service.*;
|
||||
import com.microservices.pms.utils.NexusRequestHelper;
|
||||
import com.microservices.pms.utils.NexusRequestUrl;
|
||||
import com.microservices.pms.utils.PmsUtils;
|
||||
import com.microservices.system.api.RemoteFileService;
|
||||
import com.microservices.system.api.domain.SysFileBytes;
|
||||
import feign.Response;
|
||||
import org.apache.http.entity.ContentType;
|
||||
import org.apache.http.entity.mime.MultipartEntityBuilder;
|
||||
import org.slf4j.Logger;
|
||||
|
|
@ -31,8 +31,11 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
|
@ -408,7 +411,7 @@ public class PmsProductLibraryComponentServiceImpl implements IPmsProductLibrary
|
|||
if (assetMavenInputVo.getFileBytes() != null) {
|
||||
fileBytes = assetMavenInputVo.getFileBytes();
|
||||
} else {
|
||||
fileBytes = PmsUtils.getFeignFile(fileService.getFileEntityByIdentifier(assetMavenInputVo.getFileIdentifier(), SecurityConstants.INNER));
|
||||
fileBytes = getFeignFile(assetMavenInputVo.getFileIdentifier());
|
||||
}
|
||||
if (fileBytes.getFileInputStream() == null) {
|
||||
throw new ServiceException("制品文件读取失败");
|
||||
|
|
@ -468,7 +471,7 @@ public class PmsProductLibraryComponentServiceImpl implements IPmsProductLibrary
|
|||
if (assetRawInputVo.getFileBytes() != null) {
|
||||
fileBytes = assetRawInputVo.getFileBytes();
|
||||
} else {
|
||||
fileBytes = PmsUtils.getFeignFile(fileService.getFileEntityByIdentifier(assetRawInputVo.getFileIdentifier(), SecurityConstants.INNER));
|
||||
fileBytes = getFeignFile(assetRawInputVo.getFileIdentifier());
|
||||
}
|
||||
if (fileBytes.getFileInputStream() == null) {
|
||||
throw new ServiceException("制品文件读取失败");
|
||||
|
|
@ -508,7 +511,7 @@ public class PmsProductLibraryComponentServiceImpl implements IPmsProductLibrary
|
|||
if (componentInputVo.getFileBytes() != null) {
|
||||
fileBytes = componentInputVo.getFileBytes();
|
||||
} else {
|
||||
fileBytes = PmsUtils.getFeignFile(fileService.getFileEntityByIdentifier(componentInputVo.getFileIdentifier(), SecurityConstants.INNER));
|
||||
fileBytes = getFeignFile(componentInputVo.getFileIdentifier());
|
||||
}
|
||||
if (fileBytes.getFileInputStream() == null) {
|
||||
throw new ServiceException("制品文件读取失败");
|
||||
|
|
@ -545,7 +548,7 @@ public class PmsProductLibraryComponentServiceImpl implements IPmsProductLibrary
|
|||
if (componentInputVo.getFileBytes() != null) {
|
||||
fileBytes = componentInputVo.getFileBytes();
|
||||
} else {
|
||||
fileBytes = PmsUtils.getFeignFile(fileService.getFileEntityByIdentifier(componentInputVo.getFileIdentifier(), SecurityConstants.INNER));
|
||||
fileBytes = getFeignFile(componentInputVo.getFileIdentifier());
|
||||
}
|
||||
if (fileBytes.getFileInputStream() == null) {
|
||||
throw new ServiceException("制品文件读取失败");
|
||||
|
|
@ -659,4 +662,25 @@ public class PmsProductLibraryComponentServiceImpl implements IPmsProductLibrary
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private SysFileBytes getFeignFile(String fileIdentifier) {
|
||||
try {
|
||||
Response response = fileService.getFileEntityByIdentifier(fileIdentifier, SecurityConstants.INNER);
|
||||
if (response == null) {
|
||||
throw new ServiceException("文件服务请求失败");
|
||||
}
|
||||
InputStream inputStream = response.body().asInputStream();
|
||||
Collection<String> fileNameCollection = response.headers().get("FileName");
|
||||
String fileName = null;
|
||||
if (fileNameCollection != null) {
|
||||
fileName = fileNameCollection.stream().findFirst().orElse(null);
|
||||
}
|
||||
SysFileBytes sysFileBytes = new SysFileBytes();
|
||||
sysFileBytes.setFileInputStream(inputStream);
|
||||
sysFileBytes.setFileName(fileName);
|
||||
return sysFileBytes;
|
||||
} catch (IOException e) {
|
||||
throw new ServiceException("获取文件失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,7 @@
|
|||
package com.microservices.pms.utils;
|
||||
|
||||
import com.microservices.common.core.exception.ServiceException;
|
||||
import com.microservices.system.api.domain.SysFileBytes;
|
||||
import feign.Response;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
|
@ -80,17 +76,4 @@ public class PmsUtils {
|
|||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public static SysFileBytes getFeignFile(Response response) {
|
||||
try {
|
||||
InputStream inputStream = response.body().asInputStream();
|
||||
String fileName = response.headers().get("FileName").stream().findFirst().orElse(null);
|
||||
SysFileBytes sysFileBytes = new SysFileBytes();
|
||||
sysFileBytes.setFileInputStream(inputStream);
|
||||
sysFileBytes.setFileName(fileName);
|
||||
return sysFileBytes;
|
||||
} catch (IOException e) {
|
||||
throw new ServiceException("获取文件失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue