PaperBasicInfo

dev-tmp1
luotaiqian 2026-08-21 14:42:57 +08:00
parent 4817abfde5
commit d2bebf83a3
3 changed files with 70 additions and 3 deletions

View File

@ -10,6 +10,7 @@ import org.qinan.safetyeval.client.co.WpsDocOpenCO;
import org.qinan.safetyeval.infrastructure.dataobject.base.Req;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
@ -162,6 +163,14 @@ public class H5OpenController {
return SingleResponse.of(wpsApi.createBlank(data.getOrDefault("docxUrl", ""), Long.parseLong(data.getOrDefault("projectId", "0"))));
}
@ApiOperation("上传已有Word文件并创建文档返回可打开的WPS文档信息")
@PostMapping(value = "/doc/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public SingleResponse<WpsDocOpenCO> uploadDoc(@RequestPart("file") MultipartFile file,
@RequestParam("projectId") Long projectId) throws IOException {
log.info("wps upload doc, name={}, size={}, projectId={}", file.getOriginalFilename(), file.getSize(), projectId);
return SingleResponse.of(wpsApi.uploadDoc(file.getInputStream(), file.getOriginalFilename(), projectId));
}
@ApiOperation("模版文档(固定)")
@PostMapping(value = "/doc/template")
public SingleResponse<Map<String, Object>> template() {

View File

@ -2,6 +2,7 @@ package org.qinan.safetyeval.app.executor;
import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.jjb.saas.framework.auth.utils.AuthContext;
import lombok.extern.slf4j.Slf4j;
import org.dromara.x.file.storage.core.FileInfo;
import org.dromara.x.file.storage.core.FileStorageService;
@ -364,6 +365,38 @@ public class WpsExecutor implements WpsApi {
}
}
@Override
public WpsDocOpenCO uploadDoc(InputStream inputStream, String fileName, Long projectId) {
try {
Long userId = requireUserId();
if (Objects.isNull(projectId)) {
throw new BizException(ErrorCode.EVAL_PROJECT_ERROR);
}
String docName = StringUtils.hasText(fileName) ? fileName : "未命名文档.docx";
Long orgId = AuthContext.getOrgId();
FileStorage saved;
try {
FileInfo ossFileInfo = fileStorageService.of(inputStream, docName).upload();
FileStorage fileStorage = FileStorageHelper.buildResource(ossFileInfo, docName, true);
saved = fileStorageDomainService.saveResource(fileStorage);
} catch (BizException e) {
throw e;
} catch (Exception e) {
log.error("upload docx failed, name={}", docName, e);
throw new BizException(ErrorCode.FILE_UPLOAD_FAILED, e);
}
WpsDocEntity created = createInitialDoc(userId, orgId, docName, saved, projectId);
return toOpenCO(created, true);
} catch (BizException e) {
throw e;
} catch (Exception e) {
log.error("wps uploadDoc failed, name={}", fileName, e);
throw new BizException(ErrorCode.UNKNOWN_ERROR);
}
}
@Override
public WpsDocOpenCO getDocByProjectId(String projectId) {
LambdaQueryWrapper<WpsDocDO> wrapper = new LambdaQueryWrapper<>();
@ -388,10 +421,7 @@ public class WpsExecutor implements WpsApi {
throw new BizException(ErrorCode.WPS_BLANK_DOCX_URL_EMPTY);
}
Long orgId = requireOrgId();
String creatorId = String.valueOf(userId);
String fileId = generateFileId();
String docName = "未命名文档.docx";
long nowEpoch = System.currentTimeMillis() / 1000;
FileStorage saved;
try (InputStream inputStream = new URL(resDocxUrl).openStream()) {
@ -405,6 +435,24 @@ public class WpsExecutor implements WpsApi {
throw new BizException(ErrorCode.WPS_BLANK_DOCX_DOWNLOAD_FAILED, e);
}
return createInitialDoc(userId, orgId, docName, saved, projectId);
}
/**
*
*
* @param userId id
* @param orgId id
* @param docName
* @param saved
* @param projectId id
* @return
*/
private WpsDocEntity createInitialDoc(Long userId, Long orgId, String docName, FileStorage saved, Long projectId) {
String creatorId = String.valueOf(userId);
String fileId = generateFileId();
long nowEpoch = System.currentTimeMillis() / 1000;
WpsDocEntity doc = new WpsDocEntity();
doc.setFileId(fileId);
doc.setOrgId(orgId);

View File

@ -47,5 +47,15 @@ public interface WpsApi {
*/
WpsDocOpenCO createBlank(String docxUrl, Long projectId);
/**
* Word WPS
*
* @param inputStream
* @param fileName
* @param projectId id
* @return
*/
WpsDocOpenCO uploadDoc(InputStream inputStream, String fileName, Long projectId);
WpsDocOpenCO getDocByProjectId(String projectId);
}