feat(制品库功能完善): 产品库不提供直接上传产品操作,文档需要从知识库中选取
产品库上传文档逻辑优化:支持选择文档类型的文档 1. 创建临时文件,文件名为文档名称并添加后缀.md,并将文档内容输入到文件中 2. 获取文件流作为产品库制品上传 3. 删除临时文件
This commit is contained in:
parent
7bd025970e
commit
9b2a323674
|
|
@ -28,6 +28,7 @@ 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 com.microservices.system.api.domain.SysFileInfo;
|
||||
import com.microservices.system.api.utils.FeignUtils;
|
||||
import org.slf4j.Logger;
|
||||
|
|
@ -36,6 +37,10 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
|
@ -176,7 +181,7 @@ public class PmsProductLibraryServiceImpl implements IPmsProductLibraryService {
|
|||
PmsEnterprise pmsEnterprise = pmsEnterpriseService.selectPmsEnterpriseByIdentifier(productComponentInputVo.getEnterpriseIdentifier());
|
||||
for (Long docId : productComponentInputVo.getDocList()) {
|
||||
PmsDocumentDetailVo pmsDocument = pmsDocumentService.selectPmsDocumentDetailVoByIdAndEnterpriseId(docId, pmsEnterprise.getId());
|
||||
if (Objects.equals(pmsDocument.getDocType(), 1) || Objects.equals(pmsDocument.getDocType(), 4)) {
|
||||
if (!Objects.equals(pmsDocument.getDocType(), 2) && !Objects.equals(pmsDocument.getDocType(), 3)) {
|
||||
throw new ServiceException("产品库文档类型仅允许为文档类型或附件类型(文档Id[%s])", pmsDocument.getId());
|
||||
}
|
||||
PmsProductLibraryComponent pmsProductLibraryComponent =
|
||||
|
|
@ -185,9 +190,36 @@ public class PmsProductLibraryServiceImpl implements IPmsProductLibraryService {
|
|||
throw new ServiceException("产品库已存在该文档,请勿重复上传(文档文件名称[%s])", pmsDocument.getName());
|
||||
}
|
||||
AssetRawInputVo assetRawInputVo = new AssetRawInputVo();
|
||||
assetRawInputVo.setFilename(pmsDocument.getName());
|
||||
assetRawInputVo.setAssetIdentifier(String.valueOf(pmsDocument.getId()));
|
||||
assetRawInputVo.setFileIdentifier(pmsDocument.getAttachmentIdentifier());
|
||||
if (Objects.equals(pmsDocument.getDocType(), 3)) {
|
||||
assetRawInputVo.setFilename(pmsDocument.getName());
|
||||
assetRawInputVo.setFileIdentifier(pmsDocument.getAttachmentIdentifier());
|
||||
} else if (Objects.equals(pmsDocument.getDocType(), 2)) {
|
||||
Path tempFilePath = null;
|
||||
try {
|
||||
String docFileName = pmsDocument.getName() + ".md";
|
||||
assetRawInputVo.setFilename(docFileName);
|
||||
// 创建临时文件
|
||||
tempFilePath = Files.createTempFile(pmsDocument.getName(), ".md");
|
||||
Files.write(tempFilePath, pmsDocument.getContent().getBytes(StandardCharsets.UTF_8));
|
||||
SysFileBytes sysFileBytes = new SysFileBytes();
|
||||
sysFileBytes.setFileName(docFileName);
|
||||
sysFileBytes.setFileInputStream(Files.newInputStream(tempFilePath));
|
||||
assetRawInputVo.setFileBytes(sysFileBytes);
|
||||
} catch (IOException e) {
|
||||
log.error("文档上传失败:{}", e.getMessage());
|
||||
throw new ServiceException("文档上传失败");
|
||||
} finally {
|
||||
if (tempFilePath != null) {
|
||||
try {
|
||||
Files.deleteIfExists(tempFilePath);
|
||||
} catch (IOException e) {
|
||||
log.error("删除临时文件失败:{}", e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assetList.add(assetRawInputVo);
|
||||
}
|
||||
return pmsProductLibraryComponentService.insertRawComponent(productComponentInputVo.toComponentRawInputVo(assetList));
|
||||
|
|
|
|||
Loading…
Reference in New Issue