根据正文生成条款时删除原正文文件
正文生成条款生成规则调整
This commit is contained in:
parent
772e3a6778
commit
9083f2b399
@ -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<String,Object> logMaps = new HashMap<String,Object>();
|
||||
|
||||
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<String, Object> logMaps = new HashMap<String, Object>();
|
||||
|
||||
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<UpfileModel> 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<String,Object> logMaps = new HashMap<String,Object>();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user