news 2026/5/11 9:26:17

泛微OA文档附件复制汇集

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
泛微OA文档附件复制汇集

实现场景:

目标:实现将流程相关资源中附件与文档内容复制到新字段中

使用泛微ESB实现复制相关资源文档,附件的docid到新字段中实现附件汇集

  • 附件1 字段存有a.txt,b.pdf; 附件2 字段存有 c.xls,d.ppt; 文档字段3 存有 d.doc在线文档
  • 在新增的自定义字段collectannex,通过esb接口实现将以上内容复制到该字段中

ESB思路:

最后更新表单要去除获取到的docid之间的空格!!!

实现思路:

  1. 通过 流程requestid 获取表名与流程创建者id
  2. 通过1中的内容获取流程相关资源的文件docid
  3. 复制所有相关资源中的docid生成复制后新的docid
  4. 执行更新SQL实现将以上新生成的docid复制到新字段(collectannex)中

完整代码:

package com.weaver.esb.package_20251215021826; import com.api.doc.detail.util.DecodeUtil; import com.engine.workflow.biz.workflowCore.RequestBaseBiz; import com.engine.workflow.entity.core.RequestInfoEntity; import weaver.conn.RecordSet; import weaver.docs.webservices.DocAttachment; import weaver.docs.webservices.DocInfo; import weaver.docs.webservices.DocServiceImpl; import weaver.file.ImageFileManager; import weaver.general.Util; import weaver.hrm.User; import weaver.hrm.resource.ResourceComInfo; import weaver.wechat.util.Utils; import weaver.workflow.request.RequestResources; import weaver.workflow.workflow.WorkflowComInfo; import java.io.ByteArrayOutputStream; import java.io.InputStream; import java.util.*; public class OperateWorkflowAnnex { /** * @param: param(Map collections) * 参数名称不能包含特殊字符+,.[]!"#$%&'()*:;<=>?@\^`{}|~/ 中文字符、标点 U+007F U+0000到U+001F */ public Map execute(Map<String,Object> params) { Map<String,Object> ret = new HashMap<>(); String requestid = Utils.null2String(params.get("requestid")); //1. obtain tablename by requestid String tableName= getWorkflowTablenameByRequestid(requestid); // 2. obtain creater by requestid String creater = getCreaterByRequestid(requestid); int useridInt = Integer.parseInt(creater) ; User user = new User(useridInt) ; // 3. obtain annex files ids by requestid,creater List<String> docidList = getAnnexfilesList( requestid , creater ); List<String> CollectAnnexDocidList = new ArrayList<>(); try { for(String docId : docidList){ Map<String, String> imageInfo = getImageFileidByDocid(docId); String decodeimagefileid = Util.null2String(DecodeUtil.decodeByImageFileIdByTianyu(Integer.parseInt(imageInfo.get("imagefileid")))); String imagefilename = imageInfo.get("imagefilename"); InputStream inputStream = ImageFileManager.getInputStreamById(Integer.parseInt(decodeimagefileid)); String relatedDocid= createDocument(inputStream,"/app/weaver/ecology/Archives",imagefilename,creater,user,imagefilename); CollectAnnexDocidList.add(relatedDocid); } } catch (Exception e) { ret.put("code","400"); ret.put("message","erro get files :"+e.toString()); throw new RuntimeException(e); } RecordSet updateAppendixRS = new RecordSet() ; String collectannex =String.join(", ", CollectAnnexDocidList); collectannex = collectannex.replaceAll("\\s", ""); String updateWorkflowSQL = "update "+tableName+" set collectannex ='"+collectannex+"' where requestid="+requestid; updateAppendixRS.execute(updateWorkflowSQL ) ; ret.put("code","200"); ret.put("message", tableName+"; creater:"+creater+" docidList:"+docidList+" CollectAnnexDocidList"+CollectAnnexDocidList+" ***"+updateWorkflowSQL); return ret; } public String createDocument(InputStream inputStream, String filePath, String fileName, String userid, User user, String wdmc) throws Exception { // System.out.println("+++++++++++++++++++++++++++++++++++++++++++进入生成文档方法+++++++++++++++++++++++++++++++++++++++++++"); String docid = ""; List<InputStream> inputStreams = new ArrayList<>(); byte[] content = new byte[102400]; // 上传附件,创建html文档 content = null; try { int byteread; byte data[] = new byte[1024]; // InputStreamReader reader = new InputStreamReader(input,"UTF-8"); ByteArrayOutputStream out = new ByteArrayOutputStream(); while ((byteread = inputStream.read(data)) != -1) { out.write(data, 0, byteread); out.flush(); } content = out.toByteArray(); inputStream.close(); out.close(); } catch (Exception e) { e.printStackTrace(); } DocAttachment da = new DocAttachment(); da.setDocid(0); da.setImagefileid(0); da.setFilecontent(org.apache.axis.encoding.Base64.encode(content)); da.setFilerealpath(filePath); da.setIszip(1); da.setFilename(fileName); da.setIsextfile("1"); da.setDocfiletype("3"); DocServiceImpl docService = new DocServiceImpl(); DocInfo doc = new DocInfo();//创建文档 doc.setDoccreaterid(Integer.parseInt(userid));// doc.setDoccreatertype(0); doc.setAccessorycount(1); doc.setMaincategory(Integer.parseInt("92"));//主目录id doc.setSeccategory(Integer.parseInt("92"));//子目录id doc.setOwnerid(Integer.parseInt(userid)); doc.setDocStatus(1); doc.setId(0); doc.setDocType(2); doc.setDocSubject(wdmc); doc.setDoccontent(""); doc.setAttachments(new DocAttachment[]{da}); int newDocid = docService.createDocByUser(doc, user); System.out.println("新文档id:" + newDocid); return newDocid + ""; } public static Map<String, String> getImageFileidByDocid(String docid) { String sql = "select imagefileid,imagefilename from docimagefile where docid='" + docid + "'"; RecordSet rs = new RecordSet(); rs.executeQuery(sql); Map<String, String> map = new HashMap<>(); if (rs.next()) { map.put("imagefileid", weaver.general.Util.null2String(rs.getString("imagefileid"))); map.put("imagefilename", (weaver.general.Util.null2String(rs.getString("imagefilename"))).replace("/","-")); } return map; } static List<String> getAnnexfilesList(String requestidStr,String creatoridStr){ List<String> docidList = new ArrayList<>() ; int requestid = Integer.parseInt(requestidStr) ; int useridInt = Integer.parseInt(creatoridStr) ; if(requestidStr.equals("")||requestidStr==null){ return null ; } User user = new User(useridInt) ; try { RequestInfoEntity infoEntity = RequestBaseBiz.loadRequestInfo(requestid); int workflowid = infoEntity.getWorkflowId(); WorkflowComInfo comInfo = new WorkflowComInfo(); int isbill = Util.getIntValue(comInfo.getIsBill(Util.null2String(workflowid))); int formid = Util.getIntValue(comInfo.getFormId(Util.null2String(workflowid))); RequestResources reqResources = new RequestResources(user, infoEntity.getWorkflowId(), requestid, isbill, formid, "", "", "", "0", 0, 0); // "type":资源类型 1:相关流程 2:相关文档 3:相关附件 String fromSql = reqResources.getReqResSqlByType(3); String querySQL = "select id, resname, restype, creator, creatortype, createdate, docid from " + fromSql + " order by id asc"; RecordSet rs = new RecordSet(); rs.executeQuery(querySQL); while (rs.next()) { int id = rs.getInt("id"); rs.getString("creator"); //文档类型的附件,查出来的是docid,还要根据docid去查询docImageFileId String docid = Util.null2String(rs.getInt("docid")); String imagefileid = getDocImageFileIdByDocid(docid).get("imagefileid").toString(); docidList.add( docid); } // "type":资源类型 1:相关流程 2:相关文档 3:相关附件 fromSql = reqResources.getReqResSqlByType(2); querySQL = "select id, resname, restype, creator, creatortype, createdate, docid from " + fromSql + " order by id asc"; rs.executeQuery(querySQL); while (rs.next()) { int id = rs.getInt("id"); rs.getString("creator"); //文档类型的附件,查出来的是docid,还要根据docid去查询docImageFileId String docid = Util.null2String(rs.getInt("docid")); String imagefileid = getDocImageFileIdByDocid(docid).get("imagefileid").toString(); // imagefileidList.add( imagefileid); docidList.add( docid); } }catch (Exception e) { // writeLog(e.getMessage(), e); } return docidList ; } /** * 根据docid获取最新一次的DocImageFileId * @param docid * @return */ static Map<String,Object> getDocImageFileIdByDocid(String docid){ Map<String,Object> map = new HashMap<>(); String zwflag="1"; int imagefileid=0; RecordSet rs = new RecordSet(); String sql="select * from docdetail where id="+docid; rs.executeSql(sql); sql="select * from DocImageFile where docid ="+docid; sql+=" order by id desc "; rs.executeSql(sql); if(rs.next()){ imagefileid= Util.getIntValue(rs.getString("imagefileid"),0); map.put("imagefilename",rs.getString("imagefilename")); } map.put("imagefileid",imagefileid); return map; } /** * obtain creater by requestid * @param requestid * @return */ static String getCreaterByRequestid(String requestid){ //get creater by requestid String queryCreaterSQL = " select creater from workflow_requestbase where requestid = ?"; RecordSet rs = new RecordSet(); rs.executeQuery(queryCreaterSQL,requestid) ; String creater ="28525" ; if(rs.next()){ creater=rs.getString("creater") ; } //get all annex files about requestid return creater ; } /** * obtain tablename by requestid * @param requestid * @return tablename */ static String getWorkflowTablenameByRequestid(String requestid){ String queryTableNameSQL = " SELECT b.tablename\n" + "FROM workflow_requestbase r\n" + "JOIN workflow_base w ON r.workflowid = w.id\n" + "JOIN workflow_bill b ON w.formid = b.id\n" + "WHERE r.requestid = ?" ; RecordSet rs = new RecordSet(); rs.executeQuery(queryTableNameSQL,requestid) ; String result ="" ; if(rs.next()){ result=rs.getString("tablename") ; } return result ; } }

代码解析:

  • 使用requestid获取流程对应的表名与创建人需要进行多个表的转换,queryTableNameSQL获取tablename(表名) 拆解来源如下:
select creater from workflow_requestbase where requestid = 80095263 -- workflowid 448621 select * from workflow_base where id = 448621 --- formid -4654 select tablename from workflow_bill where id = -4654 -- tablename
  • 获取相关资源,在之前的获取流程相关资源文章提到了获取相关流程requestid(参数为1),参数为2或者3即可获取相关资源的文档和附件docid;
    代码不同数字代表不同资源类型,其中 1:相关流程 2:相关文档 3:相关附件 ;

以下方法通过输入流程requestid与创建人id返回该流程相关资源中所有文档与附件的docid:

static List<String> getAnnexfilesList(String requestidStr,String creatoridStr){ List<String> docidList = new ArrayList<>() ; int requestid = Integer.parseInt(requestidStr) ; int useridInt = Integer.parseInt(creatoridStr) ; if(requestidStr.equals("")||requestidStr==null){ return null ; } User user = new User(useridInt) ; try { RequestInfoEntity infoEntity = RequestBaseBiz.loadRequestInfo(requestid); int workflowid = infoEntity.getWorkflowId(); WorkflowComInfo comInfo = new WorkflowComInfo(); int isbill = Util.getIntValue(comInfo.getIsBill(Util.null2String(workflowid))); int formid = Util.getIntValue(comInfo.getFormId(Util.null2String(workflowid))); RequestResources reqResources = new RequestResources(user, infoEntity.getWorkflowId(), requestid, isbill, formid, "", "", "", "0", 0, 0); // "type":资源类型 1:相关流程 2:相关文档 3:相关附件 String fromSql = reqResources.getReqResSqlByType(3); String querySQL = "select id, resname, restype, creator, creatortype, createdate, docid from " + fromSql + " order by id asc"; RecordSet rs = new RecordSet(); rs.executeQuery(querySQL); while (rs.next()) { int id = rs.getInt("id"); rs.getString("creator"); //文档类型的附件,查出来的是docid,还要根据docid去查询docImageFileId String docid = Util.null2String(rs.getInt("docid")); String imagefileid = getDocImageFileIdByDocid(docid).get("imagefileid").toString(); docidList.add( docid); } // "type":资源类型 1:相关流程 2:相关文档 3:相关附件 fromSql = reqResources.getReqResSqlByType(2); querySQL = "select id, resname, restype, creator, creatortype, createdate, docid from " + fromSql + " order by id asc"; rs.executeQuery(querySQL); while (rs.next()) { int id = rs.getInt("id"); rs.getString("creator"); //文档类型的附件,查出来的是docid,还要根据docid去查询docImageFileId String docid = Util.null2String(rs.getInt("docid")); String imagefileid = getDocImageFileIdByDocid(docid).get("imagefileid").toString(); // imagefileidList.add( imagefileid); docidList.add( docid); } }catch (Exception e) { // writeLog(e.getMessage(), e); } return docidList ; }
  • 将docid复制后存入新的字段(collectannex)中前需要复制生成新的文件docid
public String createDocument(InputStream inputStream, String filePath, String fileName, String userid, User user, String wdmc) throws Exception { // System.out.println("+++++++++++++++++++++++++++++++++++++++++++进入生成文档方法+++++++++++++++++++++++++++++++++++++++++++"); String docid = ""; List<InputStream> inputStreams = new ArrayList<>(); byte[] content = new byte[102400]; // 上传附件,创建html文档 content = null; try { int byteread; byte data[] = new byte[1024]; // InputStreamReader reader = new InputStreamReader(input,"UTF-8"); ByteArrayOutputStream out = new ByteArrayOutputStream(); while ((byteread = inputStream.read(data)) != -1) { out.write(data, 0, byteread); out.flush(); } content = out.toByteArray(); inputStream.close(); out.close(); } catch (Exception e) { e.printStackTrace(); } DocAttachment da = new DocAttachment(); da.setDocid(0); da.setImagefileid(0); da.setFilecontent(org.apache.axis.encoding.Base64.encode(content)); da.setFilerealpath(filePath); da.setIszip(1); da.setFilename(fileName); da.setIsextfile("1"); da.setDocfiletype("3"); DocServiceImpl docService = new DocServiceImpl(); DocInfo doc = new DocInfo();//创建文档 doc.setDoccreaterid(Integer.parseInt(userid));// doc.setDoccreatertype(0); doc.setAccessorycount(1); doc.setMaincategory(Integer.parseInt("92"));//主目录id doc.setSeccategory(Integer.parseInt("92"));//子目录id doc.setOwnerid(Integer.parseInt(userid)); doc.setDocStatus(1); doc.setId(0); doc.setDocType(2); doc.setDocSubject(wdmc); doc.setDoccontent(""); doc.setAttachments(new DocAttachment[]{da}); int newDocid = docService.createDocByUser(doc, user); System.out.println("新文档id:" + newDocid); return newDocid + ""; } public static Map<String, String> getImageFileidByDocid(String docid) { String sql = "select imagefileid,imagefilename from docimagefile where docid='" + docid + "'"; RecordSet rs = new RecordSet(); rs.executeQuery(sql); Map<String, String> map = new HashMap<>(); if (rs.next()) { map.put("imagefileid", weaver.general.Util.null2String(rs.getString("imagefileid"))); map.put("imagefilename", (weaver.general.Util.null2String(rs.getString("imagefilename"))).replace("/","-")); } return map; }

代码中方法getImageFileidByDocid 输入文件docid获取对应的imagefileid与imagefilename,作为获取新文档docid方法createDocument的参数,具体通过遍历上一步获取到所有资源docid的list循环生成,代码如下:

for(String docId : docidList){ Map<String, String> imageInfo = getImageFileidByDocid(docId); String decodeimagefileid = Util.null2String(DecodeUtil.decodeByImageFileIdByTianyu(Integer.parseInt(imageInfo.get("imagefileid")))); String imagefilename = imageInfo.get("imagefilename"); InputStream inputStream = ImageFileManager.getInputStreamById(Integer.parseInt(decodeimagefileid)); String relatedDocid= createDocument(inputStream,"/app/weaver/ecology/Archives",imagefilename,creater,user,imagefilename); CollectAnnexDocidList.add(relatedDocid); }

补充说明:

当一个

    版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
    网站建设 2026/5/9 9:46:52

    MinIO匿名访问安全配置终极指南:5分钟掌握企业级防护策略

    MinIO匿名访问安全配置终极指南&#xff1a;5分钟掌握企业级防护策略 【免费下载链接】minio minio/minio: 是 MinIO 的官方仓库&#xff0c;包括 MinIO 的源代码、文档和示例程序。MinIO 是一个分布式对象存储服务&#xff0c;提供高可用性、高性能和高扩展性。适合对分布式存…

    作者头像 李华
    网站建设 2026/5/3 10:05:48

    编程实战进阶指南:如何用100+开源项目创意提升开发技能

    还在为找不到合适的编程练习项目而烦恼吗&#xff1f;想要通过实战项目系统提升开发能力却无从下手&#xff1f;开源应用创意项目&#xff08;app-ideas&#xff09;为你提供了一条从新手到专家的完整成长路径。本文将带你探索这个汇集了100实战项目的宝库&#xff0c;掌握快速…

    作者头像 李华
    网站建设 2026/5/4 15:17:56

    即梦:当你的手机也能“画”出流动的梦境

    你有没有过这样的时刻&#xff1f; 看到一片晚霞&#xff0c;心里涌起一种说不清的情绪&#xff0c;想拍下来&#xff0c;却发现照片怎么也还原不了那一刻的氛围&#xff1b; 或者读到一句诗&#xff0c;“落花流水春去也”&#xff0c;脑子里浮现出画面&#xff0c;却不知道怎…

    作者头像 李华
    网站建设 2026/5/2 23:17:19

    为什么你的Flutter应用总是打包失败?5个终极解决方案

    为什么你的Flutter应用总是打包失败&#xff1f;5个终极解决方案 【免费下载链接】gsy_github_app_flutter Flutter 超完整的开源项目&#xff0c;功能丰富&#xff0c;适合学习和日常使用。GSYGithubApp系列的优势&#xff1a;我们目前已经拥有Flutter、Weex、ReactNative、ko…

    作者头像 李华
    网站建设 2026/5/6 3:59:14

    Whistle客户端终极使用指南:轻松掌握网络调试利器

    在网络开发和调试领域&#xff0c;Whistle客户端作为一款强大的跨平台网络抓包调试工具&#xff0c;已经成为众多开发者的首选。这款基于Node.js构建的图形化界面工具&#xff0c;不仅支持HTTP、HTTPS、HTTP2和Websocket等多种协议&#xff0c;还提供了直观的操作体验&#xff…

    作者头像 李华
    网站建设 2026/5/3 2:14:13

    pg数据库wal增长过快的处理

    1.关闭归档模式&#xff1a;需重启pg 2.非活跃的复制槽会阻止WAL日志清理。检查复制槽状态&#xff1a; 如果发现activefalse的复制槽且delay_size很大&#xff0c;说明该复制槽阻塞了WAL清理。根据业务需求决定是否删除&#xff1a; 处理过程如下&#xff1a; [rootpg pg_w…

    作者头像 李华