From 9083f2b399009c9c660462ea7806b76e189c67e6 Mon Sep 17 00:00:00 2001 From: lihongyu <504404568@qq.com> Date: Wed, 23 Nov 2022 00:31:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E6=AD=A3=E6=96=87=E7=94=9F?= =?UTF-8?q?=E6=88=90=E6=9D=A1=E6=AC=BE=E6=97=B6=E5=88=A0=E9=99=A4=E5=8E=9F?= =?UTF-8?q?=E6=AD=A3=E6=96=87=E6=96=87=E4=BB=B6=20=E6=AD=A3=E6=96=87?= =?UTF-8?q?=E7=94=9F=E6=88=90=E6=9D=A1=E6=AC=BE=E7=94=9F=E6=88=90=E8=A7=84?= =?UTF-8?q?=E5=88=99=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../util/readword/ReadWordUtil.java | 234 +++++++++++++----- 1 file changed, 167 insertions(+), 67 deletions(-) diff --git a/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/util/readword/ReadWordUtil.java b/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/util/readword/ReadWordUtil.java index ffb9f8b2..b55c07b5 100644 --- a/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/util/readword/ReadWordUtil.java +++ b/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/util/readword/ReadWordUtil.java @@ -1,8 +1,34 @@ package com.actionsoft.apps.coe.pal.datamigration.util.readword; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.sql.Timestamp; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.stream.Collectors; + +import org.apache.commons.lang.StringUtils; +import org.apache.poi.hwpf.HWPFDocument; +import org.apache.poi.hwpf.usermodel.CharacterRun; +import org.apache.poi.hwpf.usermodel.Paragraph; +import org.apache.poi.hwpf.usermodel.Range; +import org.apache.poi.hwpf.usermodel.Table; +import org.apache.poi.hwpf.usermodel.TableCell; +import org.apache.poi.hwpf.usermodel.TableRow; + import com.actionsoft.apps.coe.pal.constant.CoEConstant; import com.actionsoft.apps.coe.pal.datamigration.model.po.WordAttribute; import com.actionsoft.apps.coe.pal.datamigration.model.po.WordField; +import com.actionsoft.apps.coe.pal.log.CoEOpLogAPI; +import com.actionsoft.apps.coe.pal.log.CoEOpLogConst; import com.actionsoft.apps.coe.pal.pal.repository.cache.PALRepositoryCache; import com.actionsoft.apps.coe.pal.pal.repository.dao.CoeProcessLevelDaoFacotory; import com.actionsoft.apps.coe.pal.pal.repository.designer.manage.CoeDesignerAPIManager; @@ -15,12 +41,13 @@ import com.actionsoft.apps.coe.pal.pal.repository.upfile.model.UpfileModel; import com.actionsoft.apps.coe.pal.pal.repository.web.CoeProcessLevelWeb; import com.actionsoft.apps.resource.plugin.profile.DCPluginProfile; import com.actionsoft.bpms.bo.engine.BO; -import com.actionsoft.bpms.commons.database.RowMap; +import com.actionsoft.bpms.commons.mvc.view.ResponseObject; import com.actionsoft.bpms.server.UserContext; import com.actionsoft.bpms.server.fs.DCContext; import com.actionsoft.bpms.server.fs.dc.DCProfileManager; 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.JSON; @@ -28,14 +55,6 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.aspose.words.Document; import com.aspose.words.SaveFormat; -import org.apache.commons.lang.StringUtils; -import org.apache.poi.hwpf.HWPFDocument; -import org.apache.poi.hwpf.usermodel.*; - -import java.io.*; -import java.sql.Timestamp; -import java.util.*; -import java.util.stream.Collectors; @SuppressWarnings("all") public class ReadWordUtil { @@ -246,66 +265,147 @@ public class ReadWordUtil { } - public void translateDoc(UserContext userContext, String wsId, String groupValue, String fileValue, String fileName) { + public void translateDoc(UserContext userContext, String wsId, String groupValue, String fileValue, + String fileName) { - HashMap logMaps = new HashMap(); - - logMaps.put("FILENAME", fileName); - DCPluginProfile dcProfilepdf = DCProfileManager.getDCProfile("com.actionsoft.apps.coe.pal.datamigration", "migration"); - DCContext dcContextpdf = new DCContext(userContext, dcProfilepdf, "com.actionsoft.apps.coe.pal.datamigration", groupValue, fileValue, fileName); - //InputStream docfile = SDK.getDCAPI().read(dcContextpdf); - String filepath = dcContextpdf.getFilePath(); - String fileNewPath = dcContextpdf.getFilePath(); - String docname = ""; - String docxname = fileName; - boolean iscreatemap = true; - String name = ""; - if(fileName.endsWith(".doc")||fileName.endsWith(".docx")) { - docname = fileName.replace(".docx", ".doc"); - name = fileName.substring(0,fileName.lastIndexOf(".doc")); - }else if(fileName.endsWith(".xml")) { - name = fileName.substring(0,fileName.lastIndexOf(".xml")); - } - - - DCPluginProfile dcProfilepdfdoc = DCProfileManager.getDCProfile("com.actionsoft.apps.coe.pal.datamigration", "migration"); - - //将文件挂载到附件里面 - DCContext dcContextorigin = new DCContext(userContext, dcProfilepdfdoc, "com.actionsoft.apps.coe.pal.datamigration", groupValue, fileValue, fileName); - InputStream originfile = SDK.getDCAPI().read(dcContextorigin); - /* 上传附件到第一个形状,现在已改为每次重新生成第一个节点 - * try { PALRepositoryModel palRepositoryModel = - * PALRepositoryCache.getCache().get(fileValue); String id = - * palRepositoryModel.getId(); logMaps.put("PALID",id); //查询对应绩效模型中数据模型进行填充数据 - * BaseModel defineModel = CoeDesignerAPIManager.getInstance().getDefinition(id, - * 0); String shpId = ""; String define = defineModel.getDefinition(); - * JSONObject definition = JSONObject.parseObject(define); JSONObject elements = - * definition.getJSONObject("elements"); for (String key : elements.keySet()) { - * JSONObject shape1 = elements.getJSONObject(key); - * if("regulation".equals(shape1.getString("name"))||"I/O_L4".equals(shape1. - * getString("name"))) { shpId = key; break; } } //删除已有xml文件 StringBuffer sql = - * new StringBuffer(); - * sql.append("delete from ").append(UpfileModel.DATABASE_ENTITY). - * append(" WHERE SHAPEID = '" + shpId + "'"); int update = - * DBSql.update(sql.toString()); boolean writeFileTodisk = - * writeFileTodisk(userContext, shpId, fileName, originfile, - * palRepositoryModel.getId(), "s"); } catch (FileNotFoundException e) { // TODO - * Auto-generated catch block e.printStackTrace(); } - */ - //创建图形 - if (iscreatemap) { - DCContext dcContextpdf1 = new DCContext(userContext, dcProfilepdfdoc, "com.actionsoft.apps.coe.pal.datamigration", groupValue, fileValue, fileName); - InputStream docxfile = SDK.getDCAPI().read(dcContextpdf1); - if(new CreateMaps().updateMaps2(userContext, wsId, dcContextpdf1, name, groupValue, fileValue, fileName)) { - PALRepositoryModel model = PALRepositoryCache.getCache().get(fileValue); - RefreshNo(model); - logMaps.put("CREATESHAPE", "图形创建成功!"); - }else { - logMaps.put("CREATESHAPE", "图形创建失败!"); - } - } + HashMap logMaps = new HashMap(); + + logMaps.put("FILENAME", fileName); + DCPluginProfile dcProfilepdf = DCProfileManager.getDCProfile("com.actionsoft.apps.coe.pal.datamigration", + "migration"); + DCContext dcContextpdf = new DCContext(userContext, dcProfilepdf, "com.actionsoft.apps.coe.pal.datamigration", + groupValue, fileValue, fileName); + // InputStream docfile = SDK.getDCAPI().read(dcContextpdf); + String filepath = dcContextpdf.getFilePath(); + String fileNewPath = dcContextpdf.getFilePath(); + String docname = ""; + String docxname = fileName; + boolean iscreatemap = true; + String name = ""; + if (fileName.endsWith(".doc") || fileName.endsWith(".docx")) { + docname = fileName.replace(".docx", ".doc"); + name = fileName.substring(0, fileName.lastIndexOf(".doc")); + } else if (fileName.endsWith(".xml")) { + name = fileName.substring(0, fileName.lastIndexOf(".xml")); + } + + DCPluginProfile dcProfilepdfdoc = DCProfileManager.getDCProfile("com.actionsoft.apps.coe.pal.datamigration", + "migration"); + + // 将文件挂载到附件里面 + DCContext dcContextorigin = new DCContext(userContext, dcProfilepdfdoc, + "com.actionsoft.apps.coe.pal.datamigration", groupValue, fileValue, fileName); + InputStream originfile = SDK.getDCAPI().read(dcContextorigin); - } + try { + PALRepositoryModel palRepositoryModel = PALRepositoryCache.getCache().get(fileValue); + String id = palRepositoryModel.getId(); + logMaps.put("PALID", id); // 查询对应绩效模型中数据模型进行填充数据 + BaseModel defineModel = CoeDesignerAPIManager.getInstance().getDefinition(id, 0); + String shapeId = ""; + String define = defineModel.getDefinition(); + JSONObject definition = JSONObject.parseObject(define); + JSONObject elements = definition.getJSONObject("elements"); + for (String key : elements.keySet()) { + JSONObject shape1 = elements.getJSONObject(key); + if ("regulation".equals(shape1.getString("name")) || "I/O_L4".equals(shape1.getString("name"))) { + shapeId = key; + break; + } + } + //删除已上传的正文 + deleteShapeFile(id, shapeId); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + // 创建图形 + + if (iscreatemap) { + DCContext dcContextpdf1 = new DCContext(userContext, dcProfilepdfdoc, + "com.actionsoft.apps.coe.pal.datamigration", groupValue, fileValue, fileName); + InputStream docxfile = SDK.getDCAPI().read(dcContextpdf1); + if (new CreateMaps().updateMaps2(userContext, wsId, dcContextpdf1, name, groupValue, fileValue, fileName)) { + PALRepositoryModel model = PALRepositoryCache.getCache().get(fileValue); + RefreshNo(model); + logMaps.put("CREATESHAPE", "图形创建成功!"); + } else { + logMaps.put("CREATESHAPE", "图形创建失败!"); + } + } + + } + + + /** + * 删除附件 + * + * @param uuid + * @param messages + */ + public void deleteShapeFile(String uuid, String shapeId) { + StringBuffer sb = new StringBuffer(); + sb.append("'").append(shapeId).append("'").append(","); + if (sb.length() > 0) { + String shapes = sb.substring(0, sb.length() - 1); + UpFileDao dao = new UpFileDao(); + String sqlWhere = " and " + UpfileModel.FIELD_PL_UUID + "='" + uuid + "' and " + + UpfileModel.FIELD_SHAPE_UUID + " in (" + shapes + ")"; + List list = dao.search(sqlWhere); + if (!UtilString.isEmpty(list)) { + int delete = dao.deleteByShape(sqlWhere); + if (delete > 0) { + for (UpfileModel model : list) { + DCContext dcContext = getDCContext(model); + if (dcContext != null) { + try { + String path = dcContext.getPath(); + String fileName = model.getFileName(); + String dirName = fileName.substring(0, fileName.lastIndexOf(".")); + String postfix = fileName.substring(fileName.lastIndexOf(".")); + if (!postfix.equals(".pdf")) { + UtilFile pdfFile = new UtilFile(path + dirName + ".pdf"); + if (pdfFile.exists()) { + UtilFile.removeFile(pdfFile); + } + } + UtilFile dir = new UtilFile(path + dirName); + if (dir.exists() && dir.isDirectory()) { + UtilFile.removeFile(dir); + } + dcContext.delete(); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + } + } + } + } + + /** + * 获取dccontext + * + * @param model + * @return + */ + public DCContext getDCContext(UpfileModel model) { + DCContext dcContext = null; + DCPluginProfile dcProfile = DCProfileManager.getDCProfile(CoEConstant.APP_ID, CoeFileConstant.COE_UPFILE); + if (dcProfile != null) { + if ("f".equals(model.getType())) {// 文件 + dcContext = new DCContext(UserContext.fromUID("admin"), dcProfile, CoEConstant.APP_ID, "file", + model.getPl_uuid(), model.getFileName()); + } else {// 图形 + dcContext = new DCContext(UserContext.fromUID("admin"), dcProfile, CoEConstant.APP_ID, model.getPl_uuid(), + model.getShape_uuid(), model.getFileName()); + } + } + return dcContext; + } + public void translateDocTDocx(UserContext userContext, String wsId, String groupValue, String fileValue, String fileName) { HashMap logMaps = new HashMap();