From 1b377a868230a66d8b1dfb1c80a0127a4cd587ec Mon Sep 17 00:00:00 2001 From: Mr-wang Date: Mon, 23 Oct 2023 10:35:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=B6=E5=BA=A6=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pal/output/zd/InstitutionalTextWeb.java | 1328 +++++++++++++++++ 1 file changed, 1328 insertions(+) create mode 100644 com.awspaas.user.apps.coe.pal.output.zd/src/com/awspaas/apps/coe/pal/output/zd/InstitutionalTextWeb.java diff --git a/com.awspaas.user.apps.coe.pal.output.zd/src/com/awspaas/apps/coe/pal/output/zd/InstitutionalTextWeb.java b/com.awspaas.user.apps.coe.pal.output.zd/src/com/awspaas/apps/coe/pal/output/zd/InstitutionalTextWeb.java new file mode 100644 index 00000000..f1717658 --- /dev/null +++ b/com.awspaas.user.apps.coe.pal.output.zd/src/com/awspaas/apps/coe/pal/output/zd/InstitutionalTextWeb.java @@ -0,0 +1,1328 @@ +package com.awspaas.apps.coe.pal.output.zd; + +import com.actionsoft.apps.coe.pal.constant.CoEConstant; +import com.actionsoft.apps.coe.pal.pal.output.extend.GenerLogExd; +import com.actionsoft.apps.coe.pal.pal.output.extend.OutputAppManager; +import com.actionsoft.apps.coe.pal.pal.output.util.OutputExcelUtil; +import com.actionsoft.apps.coe.pal.pal.output.util.OutputWordUtil; +import com.actionsoft.apps.coe.pal.pal.repository.PALRepositoryQueryAPIManager; +import com.actionsoft.apps.coe.pal.pal.repository.cache.PALRepositoryPropertyCache; +import com.actionsoft.apps.coe.pal.pal.repository.designer.util.CoeDesignerUtil; +import com.actionsoft.apps.coe.pal.pal.repository.model.PALRepositoryModel; +import com.actionsoft.apps.coe.pal.pal.repository.model.PALRepositoryPropertyModel; +import com.actionsoft.apps.coe.pal.pal.repository.upfile.constant.CoeFileConstant; +import com.actionsoft.apps.coe.pal.pal.repository.upfile.dao.UpFileDao; +import com.actionsoft.apps.coe.pal.pal.repository.upfile.model.UpfileModel; +import com.actionsoft.apps.coe.pal.system.property.CoePropertyUtil; +import com.actionsoft.apps.resource.plugin.profile.DCPluginProfile; +import com.actionsoft.bpms.bo.engine.BO; +import com.actionsoft.bpms.bpmn.engine.model.run.delegate.ProcessInstance; +import com.actionsoft.bpms.commons.database.RowMap; +import com.actionsoft.bpms.commons.mvc.view.ActionWeb; +import com.actionsoft.bpms.server.DispatcherRequest; +import com.actionsoft.bpms.server.UserContext; +import com.actionsoft.bpms.server.conf.server.AWSServerConf; +import com.actionsoft.bpms.server.fs.DCContext; +import com.actionsoft.bpms.server.fs.dc.DCProfileManager; +import com.actionsoft.bpms.server.fs.dc.DCUtil; +import com.actionsoft.bpms.util.DBSql; +import com.actionsoft.bpms.util.UUIDGener; +import com.actionsoft.bpms.util.UtilFile; +import com.actionsoft.bpms.util.UtilString; +import com.actionsoft.sdk.local.SDK; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.awspaas.apps.coe.pal.output.zd.util.PrReportComment; +import com.awspaas.apps.coe.pal.output.zd.util.ReportRepositoryCompare; +import com.sini.com.spire.doc.*; +import com.sini.com.spire.doc.collections.SectionCollection; +import com.sini.com.spire.doc.documents.*; +import com.sini.com.spire.doc.fields.TextRange; +import com.sini.com.spire.doc.formatting.CharacterFormat; +import com.sini.com.spire.doc.formatting.ParagraphFormat; +import freemarker.template.Configuration; +import freemarker.template.Template; +import org.apache.commons.compress.utils.IOUtils; + +import java.awt.*; +import java.io.*; +import java.nio.file.Files; +import java.text.SimpleDateFormat; +import java.util.List; +import java.util.*; + +/** + * 生成流程手册-步骤横表横表的入口 + * + * @author zhangming + */ +public class InstitutionalTextWeb extends ActionWeb { + UserContext _uc; + GenerLogExd log = new GenerLogExd(); + + + public InstitutionalTextWeb(UserContext uc) { + super(uc); + _uc = uc; + } + + //word换行符 + private final String WRAPSTRING = ""; + + + /** + * 制度批量导出正文 + * + * @param wsId + * @param teamId + * @return + */ + public String systemManualTextExport() { + List listIds = OutputAppManager.getProfileName(""); + + //查询制度流程文件 + List policyMap = DBSql.getMaps("SELECT * FROM APP_ACT_COE_PAL_REPOSITORY WHERE PLMETHODID='control.policy' "); + + String downUrl = ""; + + Date date = new Date(); + SimpleDateFormat dateFormat = new + SimpleDateFormat("yyyyMMddhhmmss"); + + long times = System.currentTimeMillis(); + final String zipName = "批量下载正文导出" + dateFormat.format(date) + ".zip"; + String targetDir = AWSServerConf.getProperty("dc.path") + File.separator + "com.awspaas.user.apps.coe.pal.output.zd" + File.separator + "tmp/grouppackage/zip" + times + "/"; + + File targetFileDir = new File(targetDir); + if (!targetFileDir.exists()) { + targetFileDir.mkdirs(); + } + + for (int i = 0; i < policyMap.size(); i++) { + exportText(policyMap.get(i).getString("ID"), policyMap.get(i).getString("WSID"), policyMap.get(i).getString("PLNAME"), policyMap.get(i).getString("PLVER"), zipName, times, targetDir, targetFileDir); + } + + try { + UtilFile.zipCompress(targetDir, new File(targetDir + zipName)); + + File[] files = targetFileDir.listFiles(new FilenameFilter() { + @Override + public boolean accept(File dir, String name) { + if (name.equals(zipName)) { + return false; + } + return true; + } + }); + for (File file : files) { + try { + file.delete(); + } catch (Exception exception) { + } + } + } catch (Exception e) { + e.printStackTrace(); + } + + DCContext zipDcContext = new DCContext(getContext(), DCProfileManager.getDCProfile("com.awspaas.user.apps.coe.pal.output.zd", "tmp"), "com.awspaas.user.apps.coe.pal.output.zd", "grouppackage", "zip" + times, zipName); + + downUrl = SDK.getConfAPI().getPortalUrl() + "/r/" + zipDcContext.getDownloadURL().replace("./", ""); + + + return downUrl; + + } + + + /** + * 制度正文单条导出 + * + * @param targetFileId + * @return + */ + public String systemManualTextExportoOnce(String targetFileId) { + List listIds = OutputAppManager.getProfileName(""); + String downUrl = ""; + + Date date = new Date(); + SimpleDateFormat dateFormat = new + SimpleDateFormat("yyyyMMddhhmmss"); + + long times = System.currentTimeMillis(); + final String zipName = "批量下载正文导出" + dateFormat.format(date) + ".zip"; + String targetDir = AWSServerConf.getProperty("dc.path") + File.separator + "com.awspaas.user.apps.coe.pal.output.zd" + File.separator + "tmp/grouppackage/zip" + times + "/"; + + File targetFileDir = new File(targetDir); + if (!targetFileDir.exists()) { + targetFileDir.mkdirs(); + } + + if (targetFileId != null) { + + String[] targetFileIdArray = targetFileId.split(","); + + for (int i = 0; i < targetFileIdArray.length; i++) { + //查询制度流程文件 + RowMap policyMap = DBSql.getMap("SELECT * FROM APP_ACT_COE_PAL_REPOSITORY WHERE PLMETHODID='control.policy' AND ID='" + targetFileIdArray[i] + "' "); + + if (policyMap != null) { + exportOnceText(policyMap.getString("ID"), policyMap.getString("WSID"), policyMap.getString("PLNAME"), policyMap.getString("PLVER"), zipName, times, targetDir, targetFileDir); + } + + } + try { + UtilFile.zipCompress(targetDir, new File(targetDir + zipName)); + } catch (Exception e) { + e.printStackTrace(); + } + + DCContext zipDcContext = new DCContext(getContext(), DCProfileManager.getDCProfile("com.awspaas.user.apps.coe.pal.output.zd", "tmp"), "com.awspaas.user.apps.coe.pal.output.zd", "grouppackage", "zip" + times, zipName); + downUrl = SDK.getConfAPI().getPortalUrl() + "/r/" + zipDcContext.getDownloadURL().replace("./", ""); + } + + return downUrl; + + } + + + @SuppressWarnings("deprecation") + public void exportText(String targetFileId, String wsId, String plname, String versionNumer, String zipName, long times, String targetDir, File targetFileDir) { + ProcessInstance boProcessInstance = SDK.getProcessAPI() + .createBOProcessInstance("obj_c0fd5262f1c64df9ab5e725aae3eff2e", "admin", "正文导出"); + + String fileName = null; + try { + String tempName = "制度-手册7.xml"; + String tempPath = "../apps/install/com.awspaas.user.apps.coe.pal.output.zd/"; + String fileValue = UUIDGener.getUUID() + "_outputText"; + String sourceAppId = "com.awspaas.user.apps.coe.pal.output.zd"; + String filename = plname; + DCContext sourceDc = new DCContext(_uc, DCProfileManager.getDCProfile(sourceAppId, "output"), sourceAppId, wsId, fileValue, filename); + String docPath = sourceDc.getPath(); + UtilFile upfileDir = new UtilFile(docPath); + if (!upfileDir.exists()) { + upfileDir.mkdirs(); + } + //{"orderNuberFirst":true,"targetShape":"","targetFileId":"ca45dc6a-0f77-44ee-adfe-f36b014586f3", + // "orderNametwo":false,"reportNameIsItName":"%fileName%_%fileVersion%","relationFileId":"","isItReport":true} + + JSONObject wizardJsonData = new JSONObject(); + wizardJsonData.put("orderNuberFirst", true); + wizardJsonData.put("targetShape", ""); + wizardJsonData.put("targetFileId", targetFileId); + wizardJsonData.put("orderNametwo", false); + wizardJsonData.put("reportNameIsItName", "%fileName%_%fileVersion%"); + wizardJsonData.put("relationFileId", ""); + wizardJsonData.put("isItReport", true); + + + String reportName = wizardJsonData.getString("reportNameIsItName"); //页面上设计的文件命名规则 + Map indexMap = new HashMap(); + + PALRepositoryModel model = PALRepositoryQueryAPIManager.getInstance().queryPalRepositoryModelByPalId(targetFileId); + if (model != null) { + //获取文件扩展属性 + String json = CoePropertyUtil.getPropertyValue(model.getId() + "_attr"); + JSONObject extendAttr = new JSONObject(); + if (json != null && !"".equals(json) && !"null".equals(json)) { + JSONArray jsonArray = JSONArray.parseArray(json); + for (int j = 0; j < jsonArray.size(); j++) { + JSONObject object = jsonArray.getJSONObject(j); + extendAttr.put(object.getString("id"), object.get("value")); + } + } + //文件的扩展属性 + List repositoryPropertyList = PALRepositoryPropertyCache.getPropertyByPlId(model.getId()); + if (repositoryPropertyList != null && repositoryPropertyList.size() > 0) { + for (PALRepositoryPropertyModel repositoryPropertyModel : repositoryPropertyList) { + if ("P_versions".equals(repositoryPropertyModel.getPropertyId())) { + String plvers = model.getVersion() + ""; + String plver = ""; + if (!"".equals(plvers)) { + if (plvers.length() > 1) { + plver = plvers.substring(0, 1) + "." + + plvers.substring(plvers.length() - 1, plvers.length()); + } else { + plver = plvers.substring(0, 1) + ".0"; + } + } + extendAttr.put(repositoryPropertyModel.getPropertyId(), "V" + plver); + } else { + extendAttr.put(repositoryPropertyModel.getPropertyId(), repositoryPropertyModel.getPropertyValue()); + } + } + } + List reportNameLabels = OutputExcelUtil.string2label(reportName); + String reportNameValue = reportName; + if (reportNameLabels.size() > 0) { + reportNameValue = OutputExcelUtil.label2value(model, extendAttr, null, reportName); + + } + reportNameValue = reportNameValue.replaceAll(OutputExcelUtil.FILENAMEREGX, ""); + if (reportNameValue.length() > 255) { + reportNameValue = reportNameValue.substring(0, 255); + } + String docName = ""; + if (indexMap.containsKey(reportNameValue)) { + int index = indexMap.get(reportNameValue); + index++; + fileName = reportNameValue + "(" + index + ")"; + log.info("得到word名称为:" + fileName); + docName = docPath + fileName + ".doc"; + indexMap.put(reportNameValue, index); + } else { + fileName = reportNameValue; + log.info("得到word名称为:" + fileName); + docName = docPath + fileName + ".doc"; + indexMap.put(fileName, 1); + } + + + JSONObject dataMap = getData2(targetFileId, wizardJsonData, docPath, fileName); + System.out.println("dpcpath=======" + docPath); + + if (dataMap != null) { + + String filePath = createDoc2(dataMap, tempPath, tempName, docName, wizardJsonData, targetFileId, docPath); + DCContext sourceDc2 = new DCContext(_uc, DCProfileManager.getDCProfile(sourceAppId, "output"), sourceAppId, wsId, fileValue, fileName + ".doc"); + String downUrl = SDK.getConfAPI().getPortalUrl() + "/r/" + + sourceDc2.getDownloadURL().replace("./", ""); + + + File targetFile = new File(targetDir + fileName + ".doc"); + if (!targetFile.exists()) { + targetFile.createNewFile(); + } + OutputStream out = new FileOutputStream(targetFile); + InputStream in = DCUtil.decryptFile(sourceDc2); + if (in == null) { + String msg = "+ dcContext.getFileName() + "; + if (sourceDc.getDCMessage() != null) { + msg = sourceDc.getDCMessage().getMessage(); + } + } + IOUtils.copy(in, out); + in.close(); + out.close(); + + + if (filePath != null) { + + BO actTextDerivation = SDK.getBOAPI().query("BO_ACT_TEXT_DERIVATION").addQuery("PALID=", targetFileId).addQuery("UPFILESTATE=", "上传成功").detail(); + if (actTextDerivation == null) { + BO bo = new BO(); + bo.set("PALID", targetFileId); + bo.set("FILENAME", fileName); + bo.set("VERSIONNUMBER", versionNumer); + bo.set("UPFILESTATE", "下载成功"); + bo.set("PALNAME", plname); + SDK.getBOAPI().create("BO_ACT_TEXT_DERIVATION", bo, boProcessInstance.getId(), ""); + } else { + BO bo = SDK.getBOAPI().query("BO_ACT_TEXT_DERIVATION").addQuery("PALID=", targetFileId).addQuery("UPFILESTATE=", "下载失败").detail(); + if (bo != null) { + bo.set("ID", bo.getId()); + bo.set("UPFILESTATE", "下载成功"); + SDK.getBOAPI().update("BO_ACT_TEXT_DERIVATION", bo); + } + + } + + } + } + + + } + } catch (Exception e) { + e.printStackTrace(); + BO actTextDerivation = SDK.getBOAPI().query("BO_ACT_TEXT_DERIVATION").addQuery("PALID=", targetFileId).addQuery("UPFILESTATE=", "下载失败").detail(); + if (actTextDerivation == null) { + BO bo = new BO(); + bo.set("PALID", targetFileId); + bo.set("FILENAME", fileName); + bo.set("VERSIONNUMBER", versionNumer); + bo.set("UPFILESTATE", "下载失败"); + bo.set("PALNAME", plname); + bo.set("REASONSPROBLEM", e.getMessage()); + SDK.getBOAPI().create("BO_ACT_TEXT_DERIVATION", bo, boProcessInstance.getId(), ""); + } + + } + + } + + + public void exportOnceText(String targetFileId, String wsId, String plname, String versionNumer, String zipName, long times, String targetDir, File targetFileDir) { + ProcessInstance boProcessInstance = SDK.getProcessAPI() + .createBOProcessInstance("obj_c0fd5262f1c64df9ab5e725aae3eff2e", "admin", "正文导出"); + + String fileName = null; + try { + String tempName = "制度-手册7.xml"; + String tempPath = "../apps/install/com.awspaas.user.apps.coe.pal.output.zd/"; + String fileValue = UUIDGener.getUUID() + "_outputText"; + String sourceAppId = "com.awspaas.user.apps.coe.pal.output.zd"; + String filename = plname; + DCContext sourceDc = new DCContext(_uc, DCProfileManager.getDCProfile(sourceAppId, "output"), sourceAppId, wsId, fileValue, filename); + String docPath = sourceDc.getPath(); + UtilFile upfileDir = new UtilFile(docPath); + if (!upfileDir.exists()) { + upfileDir.mkdirs(); + } + //{"orderNuberFirst":true,"targetShape":"","targetFileId":"ca45dc6a-0f77-44ee-adfe-f36b014586f3", + // "orderNametwo":false,"reportNameIsItName":"%fileName%_%fileVersion%","relationFileId":"","isItReport":true} + + JSONObject wizardJsonData = new JSONObject(); + wizardJsonData.put("orderNuberFirst", true); + wizardJsonData.put("targetShape", ""); + wizardJsonData.put("targetFileId", targetFileId); + wizardJsonData.put("orderNametwo", false); + wizardJsonData.put("reportNameIsItName", "%fileName%_%fileVersion%"); + wizardJsonData.put("relationFileId", ""); + wizardJsonData.put("isItReport", true); + + + String reportName = wizardJsonData.getString("reportNameIsItName"); //页面上设计的文件命名规则 + Map indexMap = new HashMap(); + + PALRepositoryModel model = PALRepositoryQueryAPIManager.getInstance().queryPalRepositoryModelByPalId(targetFileId); + if (model != null) { + //获取文件扩展属性 + String json = CoePropertyUtil.getPropertyValue(model.getId() + "_attr"); + JSONObject extendAttr = new JSONObject(); + if (json != null && !"".equals(json) && !"null".equals(json)) { + JSONArray jsonArray = JSONArray.parseArray(json); + for (int j = 0; j < jsonArray.size(); j++) { + JSONObject object = jsonArray.getJSONObject(j); + extendAttr.put(object.getString("id"), object.get("value")); + } + } + //文件的扩展属性 + List repositoryPropertyList = PALRepositoryPropertyCache.getPropertyByPlId(model.getId()); + if (repositoryPropertyList != null && repositoryPropertyList.size() > 0) { + for (PALRepositoryPropertyModel repositoryPropertyModel : repositoryPropertyList) { + if ("P_versions".equals(repositoryPropertyModel.getPropertyId())) { + String plvers = model.getVersion() + ""; + String plver = ""; + if (!"".equals(plvers)) { + if (plvers.length() > 1) { + plver = plvers.substring(0, 1) + "." + + plvers.substring(plvers.length() - 1, plvers.length()); + } else { + plver = plvers.substring(0, 1) + ".0"; + } + } + extendAttr.put(repositoryPropertyModel.getPropertyId(), "V" + plver); + } else { + extendAttr.put(repositoryPropertyModel.getPropertyId(), repositoryPropertyModel.getPropertyValue()); + } + } + } + List reportNameLabels = OutputExcelUtil.string2label(reportName); + String reportNameValue = reportName; + if (reportNameLabels.size() > 0) { + reportNameValue = OutputExcelUtil.label2value(model, extendAttr, null, reportName); + + } + reportNameValue = reportNameValue.replaceAll(OutputExcelUtil.FILENAMEREGX, ""); + if (reportNameValue.length() > 255) { + reportNameValue = reportNameValue.substring(0, 255); + } + String docName = ""; + if (indexMap.containsKey(reportNameValue)) { + int index = indexMap.get(reportNameValue); + index++; + fileName = reportNameValue + "(" + index + ")"; + log.info("得到word名称为:" + fileName); + docName = docPath + fileName + ".doc"; + indexMap.put(reportNameValue, index); + } else { + fileName = reportNameValue; + log.info("得到word名称为:" + fileName); + docName = docPath + fileName + ".doc"; + indexMap.put(fileName, 1); + } + + + JSONObject dataMap = getData2(targetFileId, wizardJsonData, docPath, fileName); + System.out.println("dpcpath=======" + docPath); + + if (dataMap != null) { + + String filePath = createDoc2(dataMap, tempPath, tempName, docName, wizardJsonData, targetFileId, docPath); + DCContext sourceDc2 = new DCContext(_uc, DCProfileManager.getDCProfile(sourceAppId, "output"), sourceAppId, wsId, fileValue, fileName + ".doc"); + String downUrl = SDK.getConfAPI().getPortalUrl() + "/r/" + + sourceDc2.getDownloadURL().replace("./", ""); + + + File targetFile = new File(targetDir + fileName + ".doc"); + if (!targetFile.exists()) { + targetFile.createNewFile(); + } + OutputStream out = new FileOutputStream(targetFile); + InputStream in = DCUtil.decryptFile(sourceDc2); + if (in == null) { + String msg = "+ dcContext.getFileName() + "; + if (sourceDc.getDCMessage() != null) { + msg = sourceDc.getDCMessage().getMessage(); + } + } + IOUtils.copy(in, out); + in.close(); + out.close(); + + + } + + + } + } catch (Exception e) { + e.printStackTrace(); + + + } + + } + + /** + * 生成word文件 + * + * @param dataMap + * @param tempPath + * @param tempName + * @param docName + */ + public static String createDoc2(com.alibaba.fastjson.JSONObject dataMap, String tempPath, String tempName, String docName, JSONObject wizardJsonData, String repositoryId, String docPath) throws Exception { + Configuration configuration = new Configuration(); + configuration.setDefaultEncoding("UTF-8"); + + + // 设置模本装置方法和路径 + UtilFile temps = new UtilFile(tempPath); + configuration.setDirectoryForTemplateLoading(temps); + + + Template t = null; + t = configuration.getTemplate(tempName, "UTF-8"); + + // 输出文档路径及名称 + File outFile = new File(docName); + Writer out = null; + out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile), "UTF-8")); + + + if (t != null && out != null) { + t.process(dataMap, out); + out.flush(); + out.close(); + } + + + //***********************************************************使用spire 生成模板后复制文件****************************************************/ + List> repositoryFileElements = CoeDesignerUtil.getShapeMessageJson4(repositoryId); //流程文件内容 + if (wizardJsonData.getBoolean("orderNuberFirst")) { // 根据页面选择进行排序 + OutputWordUtil.orderByNumber(repositoryFileElements); + } + + String controlShapeId = ""; + if (repositoryFileElements != null) { + int index = 1;// 流程步骤序号 + int dangerIndex = 1;// 风险序号 + int regulateIndex = 1;// 控制序号 + for (Map shape : repositoryFileElements) { + String type = shape.get("type").toString(); + if ("regulation".equals(type)) { + controlShapeId = shape.get("id").toString(); + } else if ("I/O_L4".equals(type)) { + controlShapeId = shape.get("id").toString(); + } + } + } + + + UserContext userContext = DispatcherRequest.getUserContext(); + + Map result = new HashMap<>(); + result.put("listDef", ""); + result.put("content", ""); + if (UtilString.isEmpty(controlShapeId)) { + + } + PALRepositoryModel repositoryModel = PALRepositoryQueryAPIManager.getInstance().queryPalRepositoryModelByPalId(repositoryId); + if (repositoryModel == null) { + + } + String content = ""; + StringBuilder listStr = new StringBuilder(); + // 读取附件 + // 流程附件列表 + UpFileDao upFileDao = new UpFileDao(); + List search = upFileDao.search(repositoryModel.getId(), controlShapeId, null); + + DCContext dcContextpdf = null; + File file = null; + + + if (search != null && search.size() > 0) { + long b1 = System.currentTimeMillis(); + // 复制附件 + for (UpfileModel upfileModel : search) { + DCPluginProfile dcProfile = DCProfileManager.getDCProfile(CoEConstant.APP_ID, CoeFileConstant.COE_UPFILE); + + if (dcProfile != null) { + dcContextpdf = new DCContext(userContext, dcProfile, CoEConstant.APP_ID, upfileModel.getPl_uuid(), upfileModel.getShape_uuid(), upfileModel.getFileName()); + String path = dcContextpdf.getPath(); + String fileName = dcContextpdf.getFileName(); + + + String suffix = fileName.substring(fileName.lastIndexOf(".") + 1); + + System.out.println("文件名称为================" + fileName); + if (suffix.equals("xml")) { + // 输出文档路径及名称 + File sourceFile = new UtilFile(path + fileName); + File targetFile = new UtilFile(docPath + fileName); + try { + UtilFile.copyFile(sourceFile, targetFile); + } catch (Exception e) { + System.out.println(e); + e.printStackTrace(); + } + + //创建实例,加载xml测试文档 + com.sini.com.spire.doc.Document doc = new com.sini.com.spire.doc.Document(); + doc.loadFromFile(docPath + fileName); + + //保存为xml格式 + String substring = fileName.substring(0, fileName.lastIndexOf(".xml")); + //保存为Word + doc.saveToFile(docPath + substring + ".docx", FileFormat.Docx);//支持.doc + + } + + + //创建 Document 类的对象并从磁盘加载 Word 文档 + com.sini.com.spire.doc.Document document = new com.sini.com.spire.doc.Document(outFile.getPath()); + + Section section = document.getLastSection(); + // 删除第一页 + Section section2 = document.getSections().get(0); + document.getSections().remove(section2); + + + //添加段落 + Paragraph paragraph = section.addParagraph(); + + + ParagraphFormat paragraphFormat = paragraph.getFormat(); + paragraphFormat.setHorizontalAlignment(HorizontalAlignment.Left); + + TextRange tr = paragraph.appendText("1.目的"); + tr.getCharacterFormat().setBold(true); + tr.getCharacterFormat().setFontName("宋体"); + tr.getCharacterFormat().setFontSize(12); + paragraph.applyStyle(BuiltinStyle.Body_Text); //应用标题1样式 + + + CharacterFormat format = new CharacterFormat(document); + format.setFontName("宋体"); + format.setFontSize(12); + + + //添加段落 + Paragraph Purposeparagraph = section.addParagraph(); + if (UtilString.isNotEmpty(dataMap.getString("pl_Purpose"))) { + Purposeparagraph.appendText(dataMap.getString("pl_Purpose")); + } else { + Purposeparagraph.appendText("无").applyCharacterFormat(format); + } + + //添加段落 + Paragraph paragraph1 = section.addParagraph(); + + ParagraphFormat paragraphFormat1 = paragraph1.getFormat(); + paragraphFormat1.setHorizontalAlignment(HorizontalAlignment.Left); + + TextRange tr1 = paragraph1.appendText("2.术语"); + + + tr1.getCharacterFormat().setBold(true); + tr1.getCharacterFormat().setFontName("宋体"); + tr1.getCharacterFormat().setFontSize(12); + paragraph1.applyStyle(BuiltinStyle.Body_Text); //应用标题1样式 + + + PALRepositoryPropertyModel term = PALRepositoryPropertyCache.getPropertyByPropertyId(repositoryModel.getId(), "term"); + JSONArray termTable = new JSONArray(); //术语定义Table + // 属性特征 属性代码KEY + String termVal = term.getPropertyValue(); + JSONObject termObj = JSONObject.parseObject(termVal); + if (termObj != null && !termObj.isEmpty()) { + JSONArray tableArr = termObj.getJSONArray("table"); + if (tableArr != null && !tableArr.isEmpty()) { + for (Object obj : tableArr) { + JSONObject obj2 = (JSONObject) obj; + if (!"table_head".equals(obj2.getString("id"))) { + String name = obj2.getString("name"); + String desc = obj2.getString("desc"); + JSONObject tmp = new JSONObject(); + tmp.put("name", name); + tmp.put("desc", desc); + termTable.add(tmp); + } + } + } + } + + + //定义表格数据 + String[] header = {"术语", "定义"}; + if (termTable != null && !termTable.isEmpty()) { + String[][] strArray2 = new String[termTable.size()][]; + + List list = new LinkedList<>(); + for (int i = 0; i < termTable.size(); i++) { + JSONObject obj2 = (JSONObject) termTable.get(i); + String[] strArray = new String[2]; + strArray[0] = obj2.getString("name"); + strArray[1] = obj2.getString("desc"); + list.add(strArray); + strArray2[i] = strArray; + } + String[][] data = strArray2; + + //添加表格 + Table table = section.addTable(true); + + + table.resetCells(data.length + 1, header.length); + + + TableRow row = table.getRows().get(0); + row.isHeader(true); + row.setHeight(20); + row.setHeightType(TableRowHeightType.Auto); + //循环表头 + for (int i = 0; i < header.length; i++) { + row.getCells().get(i).getCellFormat().setVerticalAlignment(VerticalAlignment.Middle); + //设置固定列宽 + row.getCells().get(0).setWidth(150); + row.getCells().get(1).setWidth(500); + Paragraph p = row.getCells().get(i).addParagraph(); + p.getFormat().setHorizontalAlignment(HorizontalAlignment.Center); + TextRange txtRange = p.appendText(header[i]); + + txtRange.getCharacterFormat().setBold(true); + + + } + + + //将数据添加到其余行 + for (int r = 0; r < data.length; r++) { + TableRow dataRow = table.getRows().get(r + 1); + dataRow.setHeight(25); + dataRow.setHeightType(TableRowHeightType.Auto); + dataRow.getRowFormat().setBackColor(Color.white); + for (int c = 0; c < data[r].length; c++) { + dataRow.getCells().get(c).getCellFormat().setVerticalAlignment(VerticalAlignment.Middle); + dataRow.getCells().get(0).setWidth(150); + dataRow.getCells().get(1).setWidth(500); + dataRow.getCells().get(c).addParagraph().appendText(data[r][c]); + + } + + } + } else { + Paragraph orgparagraph = section.addParagraph(); + orgparagraph.appendText("无").applyCharacterFormat(format); + } + + + //添加段落 + Paragraph paragraph2 = section.addParagraph(); + + ParagraphFormat paragraphFormat2 = paragraph2.getFormat(); + paragraphFormat2.setHorizontalAlignment(HorizontalAlignment.Left); + + TextRange tr2 = paragraph2.appendText("3.组织/角色与职责"); + + + tr2.getCharacterFormat().setBold(true); + tr2.getCharacterFormat().setFontName("宋体"); + tr2.getCharacterFormat().setFontSize(12); + paragraph2.applyStyle(BuiltinStyle.Body_Text); //应用标题1样式 + + + JSONArray organizationTable = new JSONArray(); //组织职责Table + // 属性特征 属性代码KEY + + PALRepositoryPropertyModel Organizational = PALRepositoryPropertyCache.getPropertyByPropertyId(repositoryModel.getId(), "Organizational_role"); + String OrganizationalVal = Organizational.getPropertyValue(); + + JSONObject OrganizationalObj = JSONObject.parseObject(OrganizationalVal); + if (OrganizationalObj != null && !OrganizationalObj.isEmpty()) { + JSONArray tableArr = OrganizationalObj.getJSONArray("table"); + if (tableArr != null && !tableArr.isEmpty()) { + for (Object obj : tableArr) { + JSONObject obj2 = (JSONObject) obj; + if (!"table_head".equals(obj2.getString("id"))) { + String name = obj2.getString("name"); + String desc = obj2.getString("desc"); + JSONObject tmp = new JSONObject(); + tmp.put("name", name); + tmp.put("desc", desc); + organizationTable.add(tmp); + } + } + } + } + + + //定义表格数据 + String[] orgheader = {"组织/角色与名称", "职责"}; + if (organizationTable != null && !organizationTable.isEmpty()) { + String[][] strArray2 = new String[organizationTable.size()][]; + + List list = new LinkedList<>(); + for (int i = 0; i < organizationTable.size(); i++) { + JSONObject obj2 = (JSONObject) organizationTable.get(i); + String[] strArray = new String[2]; + strArray[0] = obj2.getString("name"); + strArray[1] = obj2.getString("desc"); + list.add(strArray); + strArray2[i] = strArray; + + } + String[][] data = strArray2; + + //添加表格 + Table table = section.addTable(true); + + table.resetCells(data.length + 1, orgheader.length); + + + TableRow row = table.getRows().get(0); + row.isHeader(true); + row.setHeight(20); + row.setHeightType(TableRowHeightType.Auto); + for (int i = 0; i < orgheader.length; i++) { + row.getCells().get(i).getCellFormat().setVerticalAlignment(VerticalAlignment.Middle); + //设置固定列宽 + row.getCells().get(0).setWidth(150); + row.getCells().get(1).setWidth(500); + Paragraph p = row.getCells().get(i).addParagraph(); + p.getFormat().setHorizontalAlignment(HorizontalAlignment.Center); + TextRange txtRange = p.appendText(orgheader[i]); + txtRange.getCharacterFormat().setBold(true); + } + + //将数据添加到其余行 + for (int r = 0; r < data.length; r++) { + TableRow dataRow = table.getRows().get(r + 1); + dataRow.setHeight(25); + dataRow.setHeightType(TableRowHeightType.Auto); + dataRow.getRowFormat().setBackColor(Color.white); + for (int c = 0; c < data[r].length; c++) { + dataRow.getCells().get(c).getCellFormat().setVerticalAlignment(VerticalAlignment.Middle); + //设置固定列宽 + dataRow.getCells().get(0).setWidth(150); + dataRow.getCells().get(1).setWidth(500); + dataRow.getCells().get(c).addParagraph().appendText(data[r][c]); + } + } + } else { + Paragraph orgparagraph = section.addParagraph(); + orgparagraph.appendText("无").applyCharacterFormat(format); + } + + + //添加段落 + Paragraph paragraph3 = section.addParagraph(); + + ParagraphFormat paragraphFormat3 = paragraph3.getFormat(); + paragraphFormat3.setHorizontalAlignment(HorizontalAlignment.Left); + + TextRange tr3 = paragraph3.appendText("4.内容"); + + + tr3.getCharacterFormat().setBold(true); + tr3.getCharacterFormat().setFontName("宋体"); + tr3.getCharacterFormat().setFontSize(12); + paragraph3.applyStyle(BuiltinStyle.Body_Text); //应用标题1样式 + + + // 删除第一段落 + if (document.getSections().getCount() > 0) { + Section section4 = document.getSections().get(0); + if (section4.getParagraphs().getCount() > 0) { + section4.getParagraphs().removeAt(0); + } + } + //保存结果文档 + document.saveToFile(outFile.getPath(), FileFormat.Docx_2013); + + + String appendUrl = null; + if (suffix.equals("xml")) { + //保存为xml格式 + String substring = fileName.substring(0, fileName.lastIndexOf(".xml")); + appendUrl = docPath + substring + ".docx"; + } else { + appendUrl = path + fileName; + } + + com.sini.com.spire.doc.Document document2 = new com.sini.com.spire.doc.Document(appendUrl); + + int sectionCount = document2.getSections().getCount(); + ProcessInstance boProcessInstance = SDK.getProcessAPI() + .createBOProcessInstance("obj_70c7c5eb0e8f425fa1b57a94038089a8", "admin", "页面方向"); + + // 判断文档中是否存在横向页面方向 + boolean isLandscape = false; + // 循环遍历每个节(Section) + for (int i = 0; i < sectionCount; i++) { + Section souresection = document2.getSections().get(i); + + // 获取当前节的页面方向 + PageSetup pageSetup = souresection.getPageSetup(); + PageOrientation pageOrientation = pageSetup.getOrientation(); + + if (pageSetup.getOrientation() == PageOrientation.Landscape) { + isLandscape = true; + break; // 如果存在横向页面方向,则跳出循环 + } + } + + if (isLandscape) { + System.out.println("文档存在横向页面方向"); + + if (suffix.equals("xml")) { + //保存为xml格式 + String substring = fileName.substring(0, fileName.lastIndexOf(".xml")); + //保存为Word + document.insertTextFromFile(docPath + substring + ".docx", FileFormat.Docx_2013); + } else { + document.insertTextFromFile(path + fileName, FileFormat.Docx_2013); + } + //保存结果文档 + document.saveToFile(outFile.getPath(), FileFormat.Docx_2013); + + /*BO bo = new BO(); + bo.set("FILENAME", fileName); + bo.set("PALID", repositoryId); + bo.set("PAGE_ORIENTATION", "横向"); + SDK.getBOAPI().create("BO_ACT_PAGE_ORIENTATION", bo, boProcessInstance.getId(), "");*/ + + } else { + + System.out.println("文档存在纵向页面方向"); + //在第二个文档中循环获取所有节 + for (Object sectionObj : (Iterable) document2.getSections()) { + Section sec = (Section) sectionObj; + //在所有节中循环获取所有子对象 + for (Object docObj : (Iterable) sec.getBody().getChildObjects()) { + DocumentObject obj = (DocumentObject) docObj; + + //获取第一个文档的最后一节 + Section lastSection = document.getLastSection(); + + //将所有子对象添加到第一个文档的最后一节中 + Body body = lastSection.getBody(); + body.getChildObjects().add(obj.deepClone()); + } + } + //保存结果文档 + document.saveToFile(outFile.getPath(), FileFormat.Docx_2013); + + /*BO bo = new BO(); + bo.set("FILENAME", fileName); + bo.set("PALID", repositoryId); + bo.set("PAGE_ORIENTATION", "纵向"); + SDK.getBOAPI().create("BO_ACT_PAGE_ORIENTATION", bo, boProcessInstance.getId(), "");*/ + + } + } + } + long b2 = System.currentTimeMillis(); + + System.err.println("复制附件用时:" + + (b2 - b1) / 1000 + "秒"); + } + + + //创建 Document 类的对象并从磁盘加载 Word 文档 + com.sini.com.spire.doc.Document document = new com.sini.com.spire.doc.Document(outFile.getPath()); + + Section section = document.getLastSection(); + + + //添加段落 + Paragraph paragraph3 = section.addParagraph(); + + ParagraphFormat paragraphFormat3 = paragraph3.getFormat(); + paragraphFormat3.setHorizontalAlignment(HorizontalAlignment.Left); + + TextRange tr3 = paragraph3.appendText("5.附则"); + + + tr3.getCharacterFormat().setBold(true); + tr3.getCharacterFormat().setFontName("宋体"); + tr3.getCharacterFormat().setFontSize(12); + paragraph3.applyStyle(BuiltinStyle.Body_Text); //应用标题1样式 + + + CharacterFormat format = new CharacterFormat(document); + format.setFontName("宋体"); + format.setFontSize(12); + + + //添加段落 + Paragraph articlesparagraph = section.addParagraph(); + if (UtilString.isNotEmpty(dataMap.getString("pl_T_supplementary_articles"))) { + articlesparagraph.appendText(dataMap.getString("pl_T_supplementary_articles")); + } else { + articlesparagraph.appendText("无").applyCharacterFormat(format); + } + + + document.saveToFile(outFile.getPath(), FileFormat.Docx_2013); + + + //加载文档1 + com.sini.com.spire.doc.Document doc1 = new com.sini.com.spire.doc.Document(); + doc1.loadFromFile(tempPath + "制度-手册5.doc"); + + + //获取section + Section section1 = doc1.getSections().get(0); + + //获取文档1的页眉页脚 + HeaderFooter headerword = section1.getHeadersFooters().getHeader(); + HeaderFooter footerword = section1.getHeadersFooters().getFooter(); + + //加载文档2 + com.sini.com.spire.doc.Document doc2 = new com.sini.com.spire.doc.Document(); + doc2.loadFromFile(outFile.getPath()); + + SectionCollection sections = doc2.getSections(); + + + //加载文档1 + com.sini.com.spire.doc.Document doc3 = new com.sini.com.spire.doc.Document(); + doc3.loadFromFile(tempPath + "横板页眉页脚模板.doc"); + + + // 将页眉复制到目标文档的第一节以及后续节 + for (int i = 0; i < doc2.getSections().getCount(); i++) { + Section targetSection = doc2.getSections().get(i); + + PageSetup pageSetup = targetSection.getPageSetup(); + PageOrientation orientation = pageSetup.getOrientation(); + + + // 根据合并文档节的页面方向选择模板 + PageOrientation mergeOrientation = pageSetup.getOrientation(); + com.sini.com.spire.doc.Document templateDoc = (mergeOrientation == PageOrientation.Landscape) ? doc3 : doc1; + + // 复制模板文档的页眉和页脚到新文档 + HeaderFooter sourceHeader = templateDoc.getSections().get(0).getHeadersFooters().getHeader(); + + HeaderFooter targetHeader = targetSection.getHeadersFooters().getHeader(); + targetHeader.getChildObjects().clear(); + + for (int j = 0; j < sourceHeader.getChildObjects().getCount(); j++) { + + DocumentObject obj = sourceHeader.getChildObjects().get(j).deepClone(); + targetHeader.getChildObjects().add(obj); + } + } + // 将页脚复制到目标文档的第一节以及后续节 + for (int i = 0; i < doc2.getSections().getCount(); i++) { + Section targetSection = doc2.getSections().get(i); + HeaderFooter targetFooter = targetSection.getHeadersFooters().getFooter(); + + PageSetup pageSetup = targetSection.getPageSetup(); + + PageOrientation mergeOrientation = pageSetup.getOrientation(); + com.sini.com.spire.doc.Document templateDoc = (mergeOrientation == PageOrientation.Landscape) ? doc3 : doc1; + HeaderFooter sourceFooter = templateDoc.getSections().get(0).getHeadersFooters().getFooter(); + + targetFooter.getChildObjects().clear(); + for (int j = 0; j < sourceFooter.getChildObjects().getCount(); j++) { + DocumentObject obj = sourceFooter.getChildObjects().get(j).deepClone(); + targetFooter.getChildObjects().add(obj); + } + } + + + doc2.saveToFile(outFile.getPath(), FileFormat.Docx_2013); + + + return outFile.getPath(); + } + + + /** + * 获取文档数据 + * + * @param repositoryId + * @param wizardJsonData + * @return + */ + private JSONObject getData2(String repositoryId, JSONObject wizardJsonData, String docPath, String + fileName) throws Exception { + JSONObject dataMap = new JSONObject(); + dataMap.put("organizationType", "涉及部门及岗位\\角色"); + boolean raciRelationType = SDK.getAppAPI().getPropertyBooleanValue("com.awspaas.user.apps.coe.pal.output.zd", "DETY_POSITION_ROLE_RELATION_TYPE", false); + + // 记录关联属性的流程节点,防止多次查询重复文件信息耗费时间 + Set relationFileIds = new HashSet<>(); + Map> relationFileMap = new HashMap<>(); + + PrReportComment prReportComment = new PrReportComment(); + PALRepositoryModel repositoryModel = PALRepositoryQueryAPIManager.getInstance().queryPalRepositoryModelByPalId(repositoryId); + if (repositoryModel == null) { + return null; + } + + prReportComment.getCommentContent(dataMap, repositoryModel); // 获取一些公共的数据(手册首页的手册岗位名称、部门、时间等) + + JSONArray repositoryShapeTable = new JSONArray(); //流程步骤Table + JSONArray fileTable = new JSONArray(); //流程附件Table + JSONArray dangerTable = new JSONArray(); //风险Table + JSONArray regulateTable = new JSONArray(); //控制Table + JSONArray KPITable = new JSONArray(); //相关绩效考核Table + + Set dangerSet = new HashSet();// 风险 + Set regulateSet = new HashSet();// 控制 + Set KPISet = new HashSet();// kpi + + /*List> repositoryFileElements = CoeDesignerUtil.getShapeMessageJson4(repositoryId); //流程文件内容 + if (wizardJsonData.getBoolean("orderNuberFirst")) { // 根据页面选择进行排序 + OutputWordUtil.orderByNumber(repositoryFileElements); + }*/ + + + //组织和职责 + /*dataMap.put("organization_table", organizationTable);//table5 + dataMap.put("organization_table_count", organizationTable.size());//table5*/ + + + /* dataMap.put(OutputWordUtil.TABLE_REPOSITORY_SHAPE, repositoryShapeTable); + boolean contains = isNumberAscArray.contains("false"); + if (contains) { + fileTable.sort(Comparator.comparing(obj -> ((JSONObject) obj).getString("file_name"))); + } else { + try { + fileTable.sort(Comparator.comparing(obj -> ((JSONObject) obj).getInteger("file_number"))); + } catch (Exception e) { + throw new AWSQuotaException("附件格式请以:《附件1:XXXXXX》格式命名"); + } + }*/ + ReportRepositoryCompare compare = new ReportRepositoryCompare(); + JSONArray historyVersionModify = compare.getModifyVersionHistory(repositoryId); + dataMap.put("history_table", historyVersionModify); + + + return dataMap; + } + + + public String systemManualTextTextOriginal() { + + List listIds = OutputAppManager.getProfileName(""); + + //查询制度流程文件 + List policyMap = DBSql.getMaps("SELECT * FROM APP_ACT_COE_PAL_REPOSITORY WHERE PLMETHODID='control.policy' "); + + String downUrl = ""; + + Date date = new Date(); + SimpleDateFormat dateFormat = new + SimpleDateFormat("yyyyMMddhhmmss"); + + long times = System.currentTimeMillis(); + final String zipName = "批量下载正文原文导出" + dateFormat.format(date) + ".zip"; + String targetDir = AWSServerConf.getProperty("dc.path") + File.separator + "com.awspaas.user.apps.coe.pal.output.zd" + File.separator + "tmp/grouppackage/zip" + times + "/"; + + File targetFileDir = new File(targetDir); + if (!targetFileDir.exists()) { + targetFileDir.mkdirs(); + } + + for (int i = 0; i < policyMap.size(); i++) { + vvvv(policyMap.get(i).getString("ID"), policyMap.get(i).getString("WSID"), policyMap.get(i).getString("PLNAME"), policyMap.get(i).getString("PLVER"), zipName, times, targetDir, targetFileDir); + } + + try { + UtilFile.zipCompress(targetDir, new File(targetDir + zipName)); + + File[] files = targetFileDir.listFiles(new FilenameFilter() { + @Override + public boolean accept(File dir, String name) { + if (name.equals(zipName)) { + return false; + } + return true; + } + }); + + } catch (Exception e) { + e.printStackTrace(); + } + + DCContext zipDcContext = new DCContext(getContext(), DCProfileManager.getDCProfile("com.awspaas.user.apps.coe.pal.output.zd", "tmp"), "com.awspaas.user.apps.coe.pal.output.zd", "grouppackage", "zip" + times, zipName); + + downUrl = SDK.getConfAPI().getPortalUrl() + "/r/" + zipDcContext.getDownloadURL().replace("./", ""); + + + return downUrl; + + + } + + public void vvvv(String targetFileId, String wsId, String plname, String versionNumer, String zipName, long times, String targetDir, File targetFileDir) { + + ProcessInstance boProcessInstance = SDK.getProcessAPI() + .createBOProcessInstance("obj_ddbc1403613b42279439eb35069be0f0", "admin", "正文原文导出"); + + PALRepositoryModel model = PALRepositoryQueryAPIManager.getInstance().queryPalRepositoryModelByPalId(targetFileId); + + String fileName = null; + try { + String tempName = "制度-手册7.xml"; + String tempPath = "../apps/install/com.awspaas.user.apps.coe.pal.output.zd/"; + String fileValue = UUIDGener.getUUID() + "_outputText"; + String sourceAppId = "com.awspaas.user.apps.coe.pal.output.zd"; + String filename = plname; + DCContext sourceDc = new DCContext(_uc, DCProfileManager.getDCProfile(sourceAppId, "output"), sourceAppId, wsId, fileValue, filename); + String docPath = sourceDc.getPath(); + UtilFile upfileDir = new UtilFile(docPath); + if (!upfileDir.exists()) { + upfileDir.mkdirs(); + } + //{"orderNuberFirst":true,"targetShape":"","targetFileId":"ca45dc6a-0f77-44ee-adfe-f36b014586f3", + // "orderNametwo":false,"reportNameIsItName":"%fileName%_%fileVersion%","relationFileId":"","isItReport":true} + + JSONObject wizardJsonData = new JSONObject(); + wizardJsonData.put("orderNuberFirst", true); + wizardJsonData.put("targetShape", ""); + wizardJsonData.put("targetFileId", targetFileId); + wizardJsonData.put("orderNametwo", false); + wizardJsonData.put("reportNameIsItName", "%fileName%_%fileVersion%"); + wizardJsonData.put("relationFileId", ""); + wizardJsonData.put("isItReport", true); + + + String reportName = wizardJsonData.getString("reportNameIsItName"); //页面上设计的文件命名规则 + Map indexMap = new HashMap(); + + + if (model != null) { + + String filePath1 = upfileText(targetFileId); + + if (filePath1 != null) { + + File oldpaths = new File(filePath1); + File newpaths = new File(targetDir + filePath1.substring(filePath1.lastIndexOf("/") + 1)); + if (!newpaths.exists()) { + Files.copy(oldpaths.toPath(), newpaths.toPath()); + } else { + newpaths.delete(); + Files.copy(oldpaths.toPath(), newpaths.toPath()); + + } + + BO bo = new BO(); + bo.set("PALID", targetFileId); + bo.set("FILENAME", filePath1.substring(filePath1.lastIndexOf("/") + 1)); + bo.set("VERSIONNUMBER", versionNumer); + bo.set("UPFILESTATE", "下载成功"); + bo.set("PALNAME", model.getName()); + SDK.getBOAPI().create("BO_ACT_TEXT_ORIGIN_EXPORT", bo, boProcessInstance.getId(), ""); + + } + + + } + } catch (Exception e) { + e.printStackTrace(); + BO bo = new BO(); + bo.set("PALID", targetFileId); + bo.set("FILENAME", model.getName()); + bo.set("VERSIONNUMBER", versionNumer); + bo.set("UPFILESTATE", "下载失败"); + bo.set("PALNAME", model.getName()); + bo.set("REASONSPROBLEM", e.getMessage()); + SDK.getBOAPI().create("BO_ACT_TEXT_DERIVATION", bo, boProcessInstance.getId(), ""); + + } + } + + + public String upfileText(String repositoryId) { + + //***********************************************************使用spire 生成模板后复制文件****************************************************/ + List> repositoryFileElements = CoeDesignerUtil.getShapeMessageJson4(repositoryId); //流程文件内容 + + String controlShapeId = ""; + if (repositoryFileElements != null) { + int index = 1;// 流程步骤序号 + int dangerIndex = 1;// 风险序号 + int regulateIndex = 1;// 控制序号 + for (Map shape : repositoryFileElements) { + String type = shape.get("type").toString(); + if ("regulation".equals(type)) { + controlShapeId = shape.get("id").toString(); + } else if ("I/O_L4".equals(type)) { + controlShapeId = shape.get("id").toString(); + } + } + } + + + UserContext userContext = DispatcherRequest.getUserContext(); + + Map result = new HashMap<>(); + result.put("listDef", ""); + result.put("content", ""); + if (UtilString.isEmpty(controlShapeId)) { + + } + PALRepositoryModel repositoryModel = PALRepositoryQueryAPIManager.getInstance().queryPalRepositoryModelByPalId(repositoryId); + if (repositoryModel == null) { + + } + String content = ""; + StringBuilder listStr = new StringBuilder(); + // 读取附件 + // 流程附件列表 + UpFileDao upFileDao = new UpFileDao(); + List search = upFileDao.search(repositoryModel.getId(), controlShapeId, null); + + DCContext dcContextpdf = null; + File file = null; + + String fileUrl = null; + if (search != null && search.size() > 0) { + long b1 = System.currentTimeMillis(); + // 复制附件 + for (UpfileModel upfileModel : search) { + DCPluginProfile dcProfile = DCProfileManager.getDCProfile(CoEConstant.APP_ID, CoeFileConstant.COE_UPFILE); + + if (dcProfile != null) { + dcContextpdf = new DCContext(userContext, dcProfile, CoEConstant.APP_ID, upfileModel.getPl_uuid(), upfileModel.getShape_uuid(), upfileModel.getFileName()); + String path = dcContextpdf.getPath(); + String fileName = dcContextpdf.getFileName(); + + String suffix = fileName.substring(fileName.lastIndexOf(".") + 1); + + fileUrl = path + fileName; + } + } + } + return fileUrl; + } +} +