相关表结构
表的关联关系
- 文档(doc_id)正文是文档详情表中的
content字段的值与文档附件表中的id相关联系的 - 文档(doc_id)对应的附件是与文档附件表中的
doc_id相关联的。
-- 根据文档id查询正文关联的附件ID
select content,form_data from document where id = '1183250141441179655'
-- 文档正文相关附件的信息
select * from fileobj where id = '1183250141441179653'
RPC接口远程下载附件
@Slf4j
@Service("com.weaver.seconddev.fdd.esb.action.impl.SignContractEsbActionImpl")
public class SignContractEsbActionImpl implements EsbServerlessRpcRemoteInterface {
/**
* 远程下载文件服务
*/
@Resource
private FileDownloadService fileDownloadService;
/**
* 获取文档详情
*/
@RpcReference
private DocClientService docClientService;
@Resource
private ApplicationContext applicationContext;
@Override
public WeaResult<Map<String, Object>> execute(Map<String, Object> params) {
log.error("合同签署传入的参数为:{}", JSON.toJSONString(params));
try {
// 获取文件ID(对应 document表中的 id 字段的值)
String imageId = String.valueOf(params.get("imageId"));
// 获取文档的详情
Document document = docClientService.getById(Long.parseLong(imageId));
log.error("签署合同的详细信息:{}", JSON.toJSONString(document));
// 获取正文的附件ID
String content = document.getContent();
// 远程获取文档流
FileData fileData = fileDownloadService.downloadFile(Long.parseLong(content));
String name = fileData.getFileObj().getName();
String[] nameArr = name.split("\\.");
String suffix = nameArr[nameArr.length - 1];
InputStream inputStream = fileData.getInputStream();
// 获取项目的路径
String applicationRootPath = applicationContext.getResource("/").getFile().getAbsolutePath() + File.separator
+ "weavernorth" + File.separator + "fdd" + File.separator + "temp" + File.separator + imageId + "." + suffix;
log.error("合同签署保存文件的路径:{}", applicationRootPath);
// TODO 其他的业务逻辑
} catch (Exception ex) {
log.error("合同签署异常:{}", ex.getMessage(), ex);
return WeaResult.fail(ex.getMessage());
}
return WeaResult.success();
}
}
RPC接口上传附件
代码实现
private Map<String, Object> uploadFile(String path) {
File file = new File(path);
// 3. 上传到知识目录
// 第三个参数的值可以参考:https://i18n-test-1301503941.cos.ap-shanghai.myqcloud.com/visitstatic/test/document/%E6%A8%A1%E5%9D%97%E6%A0%87%E8%AF%86.docx对应的地址去查看。或者直接查询表fileobj中的module字段
RemoteUploadParam uploadParam = new RemoteUploadParam("校验失败数据.xlsx", String.valueOf(System.currentTimeMillis()), "ebuilderform");
FileObj fileObj = fileUploadService.uploadLocalFile(
file,
Long.valueOf(TenantRpcContext.getCurrentEmployeeId()),
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
uploadParam
);
logger.error("上传文件结果为:{}", JSON.toJSONString(fileObj));
Long docId = fileObj.getDocId();
Long id = fileObj.getId();
if (docId != null && id != null) {
// 删除对应的文件
file.delete();
}
Map<String, Object> uploadResult = new HashMap<>();
uploadResult.put("docId", docId);
uploadResult.put("id", id);
return uploadResult;
}
返回结果
{
"ban": false,
"createTime": 1763445401460,
"doc": true,
"docId": 4746344540152656149,
"docType": "office",
"employeeId": 1191357605037350913,
"encryptId": "9AE465AF6DC57FDE57514F35AE14D66BF23F0E91771042D1FE90166AD60A27901",
"extName": "xlsx",
"fileVersionId": 1203644832285523971,
"fileid": 1203644832285523970,
"hasRef": false,
"id": 1203644832285523970,
"image": false,
"img": false,
"mainAccess": {
"canSetMainAccess": false,
"isMainAccess": false,
"mainAccessId": 0
},
"map": {
"signTip": ""
},
"module": "ebuilderform",
"name": "校验失败数据.xlsx",
"options": [
{
"content": "预览",
"icon": "Icon-custom34-o",
"id": "preview",
"moreType": true
},
{
"content": "下载",
"icon": "Icon-download02",
"id": "download",
"moreType": false
},
{
"content": "重命名",
"icon": "Icon-rename",
"id": "rename",
"moreType": true
},
{
"content": "替换附件",
"icon": "Icon-upload_again",
"id": "reupload",
"moreType": true
},
{
"content": "删除",
"icon": "Icon-delete",
"id": "delete",
"moreType": false
},
{
"content": "历史版本",
"icon": "Icon-Unfinished-business-o",
"id": "version",
"moreType": true
}
],
"qysFile": true,
"signTip": "",
"size": 3512,
"tenantKey": "t4815whorw",
"type": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"updateTime": 1763445402482,
"uploadEmployeeId": 1191357605037350913,
"uploadName": "sysadmin",
"uploadTime": 1763445401460,
"uploadUser": 1191357605037350913,
"uploadUserName": "sysadmin",
"url": "3b8734c3f19a4e619493e22a305fa2b1",
"version": 1
}
- 返回结果中的
docId值为表单document表中的ID id或者fileid为附件表中fileobj表中的ID
评论区