苍穹通过文件服务生成文件,下载文件原创
金蝶云社区-yauayau
yauayau
27人赞赏了该文章 3,677次浏览 未经作者许可,禁止转载编辑于2021年04月02日 19:46:11

生成文件时,保存在临时文件,或使用文件服务保存到单据的附件钟,用IFormView.download(url)下载文件

// 生成文件
// 生成临时文件
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        book.write(out);
        ByteArrayInputStream bin = new ByteArrayInputStream(out.toByteArray());
        out.close();
        TempFileCache tfc = CacheFactory.getCommonCacheFactory().getTempFileCache();
        // 设置临时文件有效时间
        String url = tfc.saveAsUrl(name, bin, 60 * 60 * 2);
        // 下载
        getView().download(url);
        
// 使用文件服务,保存到附件
        FileService fileService = FileServiceFactory.getAttachmentFileService();
        RequestContext requestContext = RequestContext.get();
        String pathParam = FileNameUtils.getAttachmentFileName(requestContext.getTenantId(),
            requestContext.getAccountId(), "attachmentImport", names);
        FileItem item = new FileItem(names, pathParam, bin);
        String path = fileService.upload(item);
        
        ORM orm = ORM.create();
        DynamicObject dynamicObject = orm.newDynamicObject("bos_attachment");
        long id = orm.genLongId("bos_attachment");
        dynamicObject.set("id", Long.valueOf(id));
        dynamicObject.set("FNUMBER", attach.get("uid"));
        dynamicObject.set("FBillType", formId);
        dynamicObject.set("FInterID", pkId);
        dynamicObject.set("FModifyTime", today);
        dynamicObject.set("fcreatetime", today);
        dynamicObject.set("FaliasFileName", name);
        dynamicObject.set("FAttachmentName", name);
        dynamicObject.set("FExtName", extName);
        dynamicObject.set("FATTACHMENTSIZE", size); // out.size();
        dynamicObject.set("FCREATEMEN", RequestContext.get().getUserId());
        dynamicObject.set("fattachmentpanel", attachKey);
        dynamicObject.set("fdescription", desc);
        dynamicObject.set("FFileId", path);
        attDynColls.add(dynamicObject);
        SaveServiceHelper.save((DynamicObject[]) attDynColls.toArray(new DynamicObject[attDynColls.size()]));
        
// 查询附件中文件        
        List<Map<String, Object>> comAttachments = AttachmentServiceHelper.getAttachments("xx_bill", this.getModel().getValue("id"), "inventoryaccessory");
        for (int i = 0; i < comAttachments.size(); i++) {
            Map<String, Object> map = comAttachments.get(i);
            this.getView().download(map.get("url").toString());   //下载附件
        }
        
// 如果是在操作插件中生成文件,将url设置在InteractionContext  中
                OperationResult operationResult = getOperationResult();
                InteractionContext interactionContext = new InteractionContext();
                Map<String, String> urlMap = Maps.newHashMap();
                urlMap.put("url", url);
                interactionContext.setCustShowParameter(urlMap);
                operationResult.setInteractionContext(interactionContext);
图标赞 27
27人点赞
还没有人点赞,快来当第一个点赞的人吧!
图标打赏
0人打赏
还没有人打赏,快来当第一个打赏的人吧!