批量导入正文代码提交

This commit is contained in:
zhal 2023-07-17 17:54:46 +08:00
parent 1642c43f4d
commit b0bf1119ad
2 changed files with 383 additions and 392 deletions

View File

@ -1,29 +1,5 @@
package com.actionsoft.apps.coe.pal.datamigration.util.readtable; package com.actionsoft.apps.coe.pal.datamigration.util.readtable;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
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.datamigration.model.po.WordAttribute; 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.datamigration.model.po.WordField;
import com.actionsoft.apps.coe.pal.datamigration.util.ShapeUtil; import com.actionsoft.apps.coe.pal.datamigration.util.ShapeUtil;
@ -49,8 +25,13 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.aspose.words.Document; import com.aspose.words.Document;
import com.aspose.words.SaveFormat; import com.aspose.words.SaveFormat;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.usermodel.*;
import java.io.*;
import java.util.*;
/** /**
* @author baizp * @author baizp
@ -91,374 +72,386 @@ public class ReadTable {
idToNameMap.put(wordAttribute.getType(), wordAttribute.getTitle()); idToNameMap.put(wordAttribute.getType(), wordAttribute.getTitle());
}); });
} }
// 批量上传附件
public void dataFile_import(UserContext userContext, String wsId, String groupValue, String fileValue,
String fileName) {
fileName = fileName.trim();
String fileName2 = fileName;
HashMap<String, Object> logMaps = new HashMap<String, Object>();
if(fileName.substring(0, 4).contains("")) {
fileName2 = fileName2.substring(fileName2.indexOf("")+1);
}
if(fileName.substring(0, 4).contains(".")) {
fileName2 = fileName2.substring(fileName2.indexOf(".")+1);
}
logMaps.put("FILENAME", fileName);
try {
String name = "";
if(fileName2.contains("-附件")) {
name = fileName2.substring(0, fileName2.indexOf("-附件"));
}else if(fileName2.contains("+附件")){
name = fileName2.substring(0, fileName2.indexOf("+附件"));
}else {
name = fileName2.substring(0, fileName2.lastIndexOf("."));
}
PALRepositoryModel palRepositoryModel = null;
//String name = fileName.substring(0, fileName.lastIndexOf("."));
String sqlss = "select id from App_Act_Coe_Pal_Repository where plname = '"+name+"' and ISUSE = '1'";
String plid = DBSql.getString(sqlss);
if(UtilString.isNotEmpty(plid)) {
palRepositoryModel = PALRepositoryCache.getCache().get(plid);
}
//PALRepositoryModel palRepositoryModel = ReadWordUtil.getRepositoryByName2(wsId, name);
/*
* if (palRepositoryModel == null) { PALRepositoryModel palRepositoryModel_s =
* ReadWordUtil.getRepositoryByName2(wsId, "酸奶" + name); if
* (palRepositoryModel_s != null) { palRepositoryModel = palRepositoryModel_s; }
* PALRepositoryModel palRepositoryModel_y =
* ReadWordUtil.getRepositoryByName2(wsId, "液奶" + name); if
* (palRepositoryModel_y != null) { palRepositoryModel = palRepositoryModel_y; }
* PALRepositoryModel palRepositoryModel_l =
* ReadWordUtil.getRepositoryByName2(wsId, "冷饮" + name); if
* (palRepositoryModel_l != null) { palRepositoryModel = palRepositoryModel_l; }
* PALRepositoryModel palRepositoryModel_n =
* ReadWordUtil.getRepositoryByName2(wsId, "奶粉" + name); if
* (palRepositoryModel_n != null) { palRepositoryModel = palRepositoryModel_n; }
* if (palRepositoryModel == null) { if (name.startsWith("酸奶") ||
* name.startsWith("液奶") || name.startsWith("冷饮") || name.startsWith("奶粉")) {
* PALRepositoryModel palRepositoryModel_ss =
* ReadWordUtil.getRepositoryByName2(wsId, name.substring(2)); if
* (palRepositoryModel_ss != null) { palRepositoryModel = palRepositoryModel_ss;
* } } } }
*/
if (null == palRepositoryModel) {
logMaps.put("UPFILESTATE", "文件没有匹配到模型!");
} else {
String id = palRepositoryModel.getId();
logMaps.put("PALID", id);
logMaps.put("PALNAME", palRepositoryModel.getName());
String shpId = "";
if (palRepositoryModel.getMethodId().contains("form")) {
logMaps.put("MODLETYPE", "表单模型");
// 查询对应绩效模型中数据模型进行填充数据
BaseModel defineModel = CoeDesignerAPIManager.getInstance().getDefinition(id, 0);
if (null == defineModel) {
shpId = createOneMap2(wsId, name, userContext);
if ("".equals(shpId)) {
logMaps.put("UPFILESTATE", "表单图形创建失败!");
} // 批量上传附件
} else { public void dataFile_import(UserContext userContext, String wsId, String groupValue, String fileValue,
String define = defineModel.getDefinition(); String fileName) {
JSONObject definition = JSONObject.parseObject(define); fileName = fileName.trim();
JSONObject elements = definition.getJSONObject("elements"); String fileName2 = fileName;
for (String key : elements.keySet()) { HashMap<String, Object> logMaps = new HashMap<String, Object>();
JSONObject shape1 = elements.getJSONObject(key); if (fileName.substring(0, 4).contains("")) {
if ("form".equals(shape1.getString("name"))) { fileName2 = fileName2.substring(fileName2.indexOf("") + 1);
shpId = key; }
break; if (fileName.substring(0, 4).contains(".")) {
} fileName2 = fileName2.substring(fileName2.indexOf(".") + 1);
} }
} logMaps.put("FILENAME", fileName);
if ("".equals(shpId)) { try {
// 画一个图形 并返回图形ID String name = "";
shpId = createOneMap2(wsId, name, userContext); if (fileName2.contains("-附件")) {
if ("".equals(shpId)) { name = fileName2.substring(0, fileName2.indexOf("-附件"));
logMaps.put("UPFILESTATE", "表单图形创建失败!"); } else if (fileName2.contains("+附件")) {
name = fileName2.substring(0, fileName2.indexOf("+附件"));
} } else {
} name = fileName2.substring(0, fileName2.lastIndexOf("."));
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);
if(fileName.contains("-附件")) {
fileName = fileName.substring(fileName.indexOf("-附件")+1);
}
if(fileName.contains("+附件")) {
fileName = fileName.substring(fileName.indexOf("+附件")+1);
}
if(fileName.length()>4) {
if(fileName.substring(0, 4).contains("")) {
fileName = fileName.substring(fileName.indexOf("")+1);
}
if(fileName.substring(0, 4).contains(".")) {
fileName = fileName.substring(fileName.indexOf(".")+1);
}
}
// 删除已有文件
StringBuffer sql = new StringBuffer();
sql.append("delete from ").append(UpfileModel.DATABASE_ENTITY)
.append(" WHERE SHAPEID = '" + shpId + "'");
InputStream originfile = SDK.getDCAPI().read(dcContextorigin);
try {
logMaps.put("PLNAME", palRepositoryModel.getName());
PALRepositoryModel prmodel = PALRepositoryCache.getCache().get(palRepositoryModel.getParentId());
if (prmodel != null) {
logMaps.put("FRNAME", prmodel.getName());
}
boolean writeFileTodisk = new ReadWordUtil().writeFileTodisk(userContext, shpId, fileName,
originfile, id, "s");
if (writeFileTodisk) {
logMaps.put("UPFILESTATE", "上传成功!");
} else {
logMaps.put("UPFILESTATE", "上传失败!");
}
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
} else {
logMaps.put("PALID", id);
if (palRepositoryModel.getMethodId().contains("process")) {
logMaps.put("MODLETYPE", "流程模型");
logMaps.put("PLNAME", palRepositoryModel.getName());
} else {
logMaps.put("MODLETYPE", "制度模型");
logMaps.put("PLNAME", palRepositoryModel.getName());
}
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);
if(fileName.contains("-附件")) {
fileName = fileName.substring(fileName.indexOf("-附件")+1);
}
if(fileName.contains("+附件")) {
fileName = fileName.substring(fileName.indexOf("+附件")+1);
}
if(fileName.length()>4) {
if(fileName.substring(0, 4).contains("")) {
fileName = fileName.substring(fileName.indexOf("")+1);
}
if(fileName.substring(0, 4).contains(".")) {
fileName = fileName.substring(fileName.indexOf(".")+1);
}
}
StringBuffer sql = new StringBuffer();
sql.append("delete from ").append(UpfileModel.DATABASE_ENTITY)
.append(" WHERE FILENAME = '" + fileName + "' AND PALREPOSITORYID = '"+id+"'");
/*
* if(!fileName.contains("附件")) { // 删除已有文件 Date d = new Date(); StringBuffer
* sql = new StringBuffer(); SimpleDateFormat sdf = new
* SimpleDateFormat("yyyy/MM/dd"); String formatDate = sdf.format(d);
* sql.append("delete from ").append(UpfileModel.DATABASE_ENTITY).
* append(" WHERE CREATETIME < to_date ('"
* +formatDate+"','yyyy-mm-dd') and PALREPOSITORYID = '"+id+"'"); int update =
* DBSql.update(sql.toString());
*
* }
*/
/*
* if(!fileName.contains("附件")) { // 删除已有文件 Date d = new Date(); StringBuffer
* sql = new StringBuffer(); SimpleDateFormat sdf = new
* SimpleDateFormat("yyyy-MM-dd"); String formatDate = sdf.format(d);
* sql.append("delete from ").append(UpfileModel.DATABASE_ENTITY)
* .append(" WHERE CREATETIME < '"+formatDate+"' and PALREPOSITORYID = '"+id+"'"
* ); int update = DBSql.update(sql.toString());
*
* }
*/
InputStream originfile = SDK.getDCAPI().read(dcContextorigin);
try {
logMaps.put("PLNAME", palRepositoryModel.getName());
PALRepositoryModel prmodel = PALRepositoryCache.getCache().get(palRepositoryModel.getParentId());
if (prmodel != null) {
logMaps.put("FRNAME", prmodel.getName());
}
boolean writeFileTodisk = new ReadWordUtil().writeFileTodisk(userContext, "", fileName,
originfile, id, "f");
if (writeFileTodisk) {
logMaps.put("UPFILESTATE", "上传成功!");
} else {
logMaps.put("UPFILESTATE", "上传失败!");
}
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
}
}
} catch (Exception e) {
// TODO: handle exception
} finally {
SDK.getBOAPI().createDataBO("BO_ACT_FORMDATDFILE_LOG_ALL", new BO().setAll(logMaps), userContext);
}
}
@SuppressWarnings("deprecation")
public void controlPolicyFile_import(UserContext userContext, String wsId, String groupValue, String fileValue, String fileName) {
HashMap<String,Object> logMaps = new HashMap<String,Object>();
logMaps.put("FILENAME", fileName);
try {
String substring = fileName.substring(0,fileName.indexOf(".xml"));
PALRepositoryModel palRepositoryModel = ReadWordUtil.getRepositoryByName2(wsId, substring);
if(null==palRepositoryModel) {
logMaps.put("UPFILESTATE", "文件没有匹配到制度模型!");
}else {
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"))) {
shpId = key;
break;
}
}
if("".equals(shpId)) {
logMaps.put("UPFILESTATE", "模型中没有对应的形状!");
}else {
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);
StringBuffer sql = new StringBuffer();
//删除已有xml文件
sql.append("delete from ").append(UpfileModel.DATABASE_ENTITY).append(" WHERE SHAPEID = '" + shpId + "'");
int update = DBSql.update(sql.toString());
InputStream originfile = SDK.getDCAPI().read(dcContextorigin);
try {
boolean writeFileTodisk = new ReadWordUtil().writeFileTodisk(userContext, shpId, fileName, originfile, id, "s");
if(writeFileTodisk) {
logMaps.put("UPFILESTATE", "上传成功!");
}else {
logMaps.put("UPFILESTATE", "上传失败!");
}
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
}
} }
} catch (Exception e) { PALRepositoryModel palRepositoryModel = null;
// TODO: handle exception //String name = fileName.substring(0, fileName.lastIndexOf("."));
}finally { String sqlss = "select id from App_Act_Coe_Pal_Repository where plname = '" + name + "' and ISUSE = '1'";
SDK.getBOAPI().createDataBO("BO_ACT_DATAMIGRATION_LOG_T", new BO().setAll(logMaps), userContext); String plid = DBSql.getString(sqlss);
} if (UtilString.isNotEmpty(plid)) {
palRepositoryModel = PALRepositoryCache.getCache().get(plid);
}
//PALRepositoryModel palRepositoryModel = ReadWordUtil.getRepositoryByName2(wsId, name);
/*
* if (palRepositoryModel == null) { PALRepositoryModel palRepositoryModel_s =
* ReadWordUtil.getRepositoryByName2(wsId, "酸奶" + name); if
* (palRepositoryModel_s != null) { palRepositoryModel = palRepositoryModel_s; }
* PALRepositoryModel palRepositoryModel_y =
* ReadWordUtil.getRepositoryByName2(wsId, "液奶" + name); if
* (palRepositoryModel_y != null) { palRepositoryModel = palRepositoryModel_y; }
* PALRepositoryModel palRepositoryModel_l =
* ReadWordUtil.getRepositoryByName2(wsId, "冷饮" + name); if
* (palRepositoryModel_l != null) { palRepositoryModel = palRepositoryModel_l; }
* PALRepositoryModel palRepositoryModel_n =
* ReadWordUtil.getRepositoryByName2(wsId, "奶粉" + name); if
* (palRepositoryModel_n != null) { palRepositoryModel = palRepositoryModel_n; }
* if (palRepositoryModel == null) { if (name.startsWith("酸奶") ||
* name.startsWith("液奶") || name.startsWith("冷饮") || name.startsWith("奶粉")) {
* PALRepositoryModel palRepositoryModel_ss =
* ReadWordUtil.getRepositoryByName2(wsId, name.substring(2)); if
* (palRepositoryModel_ss != null) { palRepositoryModel = palRepositoryModel_ss;
* } } } }
*/
if (null == palRepositoryModel) {
logMaps.put("UPFILESTATE", "文件没有匹配到模型!");
} else {
String id = palRepositoryModel.getId();
logMaps.put("PALID", id);
logMaps.put("PALNAME", palRepositoryModel.getName());
String shpId = "";
if (palRepositoryModel.getMethodId().contains("form")) {
logMaps.put("MODLETYPE", "表单模型");
// 查询对应绩效模型中数据模型进行填充数据
BaseModel defineModel = CoeDesignerAPIManager.getInstance().getDefinition(id, 0);
if (null == defineModel) {
shpId = createOneMap2(wsId, name, userContext);
if ("".equals(shpId)) {
logMaps.put("UPFILESTATE", "表单图形创建失败!");
}
} else {
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 ("form".equals(shape1.getString("name"))) {
shpId = key;
break;
}
}
}
if ("".equals(shpId)) {
// 画一个图形 并返回图形ID
shpId = createOneMap2(wsId, name, userContext);
if ("".equals(shpId)) {
logMaps.put("UPFILESTATE", "表单图形创建失败!");
}
}
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);
if (fileName.contains("-附件")) {
fileName = fileName.substring(fileName.indexOf("-附件") + 1);
}
if (fileName.contains("+附件")) {
fileName = fileName.substring(fileName.indexOf("+附件") + 1);
}
if (fileName.length() > 4) {
if (fileName.substring(0, 4).contains("")) {
fileName = fileName.substring(fileName.indexOf("") + 1);
}
if (fileName.substring(0, 4).contains(".")) {
fileName = fileName.substring(fileName.indexOf(".") + 1);
}
}
// 删除已有文件
StringBuffer sql = new StringBuffer();
sql.append("delete from ").append(UpfileModel.DATABASE_ENTITY)
.append(" WHERE SHAPEID = '" + shpId + "'");
InputStream originfile = SDK.getDCAPI().read(dcContextorigin);
try {
logMaps.put("PLNAME", palRepositoryModel.getName());
PALRepositoryModel prmodel = PALRepositoryCache.getCache().get(palRepositoryModel.getParentId());
if (prmodel != null) {
logMaps.put("FRNAME", prmodel.getName());
}
boolean writeFileTodisk = new ReadWordUtil().writeFileTodisk(userContext, shpId, fileName,
originfile, id, "s");
if (writeFileTodisk) {
logMaps.put("UPFILESTATE", "上传成功!");
} else {
logMaps.put("UPFILESTATE", "上传失败!");
}
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
} else {
logMaps.put("PALID", id);
if (palRepositoryModel.getMethodId().contains("process")) {
logMaps.put("MODLETYPE", "流程模型");
logMaps.put("PLNAME", palRepositoryModel.getName());
} else {
logMaps.put("MODLETYPE", "制度模型");
logMaps.put("PLNAME", palRepositoryModel.getName());
}
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);
if (fileName.contains("-附件")) {
fileName = fileName.substring(fileName.indexOf("-附件") + 1);
}
if (fileName.contains("+附件")) {
fileName = fileName.substring(fileName.indexOf("+附件") + 1);
}
if (fileName.length() > 4) {
if (fileName.substring(0, 4).contains("")) {
fileName = fileName.substring(fileName.indexOf("") + 1);
}
if (fileName.substring(0, 4).contains(".")) {
fileName = fileName.substring(fileName.indexOf(".") + 1);
}
}
StringBuffer sql = new StringBuffer();
sql.append("delete from ").append(UpfileModel.DATABASE_ENTITY)
.append(" WHERE FILENAME = '" + fileName + "' AND PALREPOSITORYID = '" + id + "'");
/*
* if(!fileName.contains("附件")) { // 删除已有文件 Date d = new Date(); StringBuffer
* sql = new StringBuffer(); SimpleDateFormat sdf = new
* SimpleDateFormat("yyyy/MM/dd"); String formatDate = sdf.format(d);
* sql.append("delete from ").append(UpfileModel.DATABASE_ENTITY).
* append(" WHERE CREATETIME < to_date ('"
* +formatDate+"','yyyy-mm-dd') and PALREPOSITORYID = '"+id+"'"); int update =
* DBSql.update(sql.toString());
*
* }
*/
/*
* if(!fileName.contains("附件")) { // 删除已有文件 Date d = new Date(); StringBuffer
* sql = new StringBuffer(); SimpleDateFormat sdf = new
* SimpleDateFormat("yyyy-MM-dd"); String formatDate = sdf.format(d);
* sql.append("delete from ").append(UpfileModel.DATABASE_ENTITY)
* .append(" WHERE CREATETIME < '"+formatDate+"' and PALREPOSITORYID = '"+id+"'"
* ); int update = DBSql.update(sql.toString());
*
* }
*/
InputStream originfile = SDK.getDCAPI().read(dcContextorigin);
try {
logMaps.put("PLNAME", palRepositoryModel.getName());
PALRepositoryModel prmodel = PALRepositoryCache.getCache().get(palRepositoryModel.getParentId());
if (prmodel != null) {
logMaps.put("FRNAME", prmodel.getName());
}
boolean writeFileTodisk = new ReadWordUtil().writeFileTodisk(userContext, "", fileName,
originfile, id, "f");
if (writeFileTodisk) {
logMaps.put("UPFILESTATE", "上传成功!");
} else {
logMaps.put("UPFILESTATE", "上传失败!");
}
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
}
}
} catch (Exception e) {
// TODO: handle exception
} finally {
SDK.getBOAPI().createDataBO("BO_ACT_FORMDATDFILE_LOG_ALL", new BO().setAll(logMaps), userContext);
}
} }
@SuppressWarnings("deprecation")
public void controlPolicyFile_import(UserContext userContext, String wsId, String groupValue, String fileValue, String fileName) {
HashMap<String, Object> logMaps = new HashMap<String, Object>();
logMaps.put("FILENAME", fileName);
try {
//获取最后一个.的位置
int lastIndexOf = fileName.lastIndexOf(".");
//获取文件的后缀名
String suffix = fileName.substring(lastIndexOf);
String substring;
if (StringUtils.equals(suffix, ".xml")) {
substring = fileName.substring(0, fileName.indexOf(".xml"));
} else {
substring = fileName.substring(0, fileName.indexOf(".doc"));
}
PALRepositoryModel palRepositoryModel = ReadWordUtil.getRepositoryByName2(wsId, substring);
if (null == palRepositoryModel) {
logMaps.put("UPFILESTATE", "文件没有匹配到制度模型!");
} else {
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"))) {
shpId = key;
break;
}
}
if ("".equals(shpId)) {
logMaps.put("UPFILESTATE", "模型中没有对应的形状!");
} else {
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);
StringBuffer sql = new StringBuffer();
//删除已有xml文件
sql.append("delete from ").append(UpfileModel.DATABASE_ENTITY).append(" WHERE SHAPEID = '" + shpId + "'");
int update = DBSql.update(sql.toString());
InputStream originfile = SDK.getDCAPI().read(dcContextorigin);
try {
boolean writeFileTodisk = new ReadWordUtil().writeFileTodisk(userContext, shpId, fileName, originfile, id, "s");
if (writeFileTodisk) {
logMaps.put("UPFILESTATE", "上传成功!");
} else {
logMaps.put("UPFILESTATE", "上传失败!");
}
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
}
}
} catch (Exception e) {
// TODO: handle exception
} finally {
SDK.getBOAPI().createDataBO("BO_ACT_DATAMIGRATION_LOG_T", new BO().setAll(logMaps), userContext);
}
}
//导入表单附件 //导入表单附件
public void formDataFile_import(UserContext userContext, String wsId, String groupValue, String fileValue, String fileName) { public void formDataFile_import(UserContext userContext, String wsId, String groupValue, String fileValue, String fileName) {
HashMap<String,Object> logMaps = new HashMap<String,Object>(); HashMap<String, Object> logMaps = new HashMap<String, Object>();
logMaps.put("FILENAME", fileName); logMaps.put("FILENAME", fileName);
try { try {
String name = fileName.substring(0,fileName.lastIndexOf(".")); String name = fileName.substring(0, fileName.lastIndexOf("."));
PALRepositoryModel palRepositoryModel = ReadWordUtil.getRepositoryByName(wsId, name); PALRepositoryModel palRepositoryModel = ReadWordUtil.getRepositoryByName(wsId, name);
if(null==palRepositoryModel) { if (null == palRepositoryModel) {
logMaps.put("UPFILESTATE", "文件没有匹配到表单模型!"); logMaps.put("UPFILESTATE", "文件没有匹配到表单模型!");
}else { } else {
String shpId = ""; String shpId = "";
String id = palRepositoryModel.getId(); String id = palRepositoryModel.getId();
logMaps.put("PALID",id); logMaps.put("PALID", id);
//查询对应绩效模型中数据模型进行填充数据 //查询对应绩效模型中数据模型进行填充数据
BaseModel defineModel = CoeDesignerAPIManager.getInstance().getDefinition(id, 0); BaseModel defineModel = CoeDesignerAPIManager.getInstance().getDefinition(id, 0);
if(null==defineModel) { if (null == defineModel) {
shpId = createOneMap2(wsId, name, userContext); shpId = createOneMap2(wsId, name, userContext);
if("".equals(shpId)) { if ("".equals(shpId)) {
logMaps.put("UPFILESTATE", "表单图形创建失败!"); logMaps.put("UPFILESTATE", "表单图形创建失败!");
} }
}else { } else {
String define = defineModel.getDefinition(); String define = defineModel.getDefinition();
JSONObject definition = JSONObject.parseObject(define); JSONObject definition = JSONObject.parseObject(define);
JSONObject elements = definition.getJSONObject("elements"); JSONObject elements = definition.getJSONObject("elements");
for (String key : elements.keySet()) { for (String key : elements.keySet()) {
JSONObject shape1 = elements.getJSONObject(key); JSONObject shape1 = elements.getJSONObject(key);
if("form".equals(shape1.getString("name"))) { if ("form".equals(shape1.getString("name"))) {
shpId = key; shpId = key;
break; break;
} }
} }
} }
if("".equals(shpId)) { if ("".equals(shpId)) {
//画一个图形 并返回图形ID //画一个图形 并返回图形ID
shpId = createOneMap2(wsId, name, userContext); shpId = createOneMap2(wsId, name, userContext);
if("".equals(shpId)) { if ("".equals(shpId)) {
logMaps.put("UPFILESTATE", "表单图形创建失败!"); logMaps.put("UPFILESTATE", "表单图形创建失败!");
} }
} }
String fileName_shap = ""; String fileName_shap = "";
UpFileDao upFileDao = new UpFileDao(); UpFileDao upFileDao = new UpFileDao();
StringBuilder sqlWhere = new StringBuilder(); StringBuilder sqlWhere = new StringBuilder();
sqlWhere.append(" and PALREPOSITORYID ='").append(id).append("'"); sqlWhere.append(" and PALREPOSITORYID ='").append(id).append("'");
List<UpfileModel> fileList = upFileDao.search(sqlWhere.toString()); List<UpfileModel> fileList = upFileDao.search(sqlWhere.toString());
if (fileList != null && fileList.size() > 0) if (fileList != null && fileList.size() > 0)
for (UpfileModel upfileModel : fileList) { for (UpfileModel upfileModel : fileList) {
if ("s".equals(upfileModel.getType())) { if ("s".equals(upfileModel.getType())) {
String fileName_shaps= upfileModel.getFileName(); String fileName_shaps = upfileModel.getFileName();
if(UtilString.isNotEmpty(fileName_shaps)) { if (UtilString.isNotEmpty(fileName_shaps)) {
fileName_shap = fileName_shaps.substring(0,fileName_shaps.lastIndexOf(".")); fileName_shap = fileName_shaps.substring(0, fileName_shaps.lastIndexOf("."));
} }
} }
} }
if(name.equals(fileName_shap)) { if (name.equals(fileName_shap)) {
logMaps.put("UPFILESTATE", "此文件已存在,已忽略!"); logMaps.put("UPFILESTATE", "此文件已存在,已忽略!");
}else { } else {
DCPluginProfile dcProfilepdfdoc = DCProfileManager.getDCProfile("com.actionsoft.apps.coe.pal.datamigration", "migration"); 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); DCContext dcContextorigin = new DCContext(userContext, dcProfilepdfdoc, "com.actionsoft.apps.coe.pal.datamigration", groupValue, fileValue, fileName);
InputStream originfile = SDK.getDCAPI().read(dcContextorigin); InputStream originfile = SDK.getDCAPI().read(dcContextorigin);
try { try {
boolean writeFileTodisk = new ReadWordUtil().writeFileTodisk(userContext, shpId, fileName, originfile, id, "s"); boolean writeFileTodisk = new ReadWordUtil().writeFileTodisk(userContext, shpId, fileName, originfile, id, "s");
if(writeFileTodisk) { if (writeFileTodisk) {
logMaps.put("UPFILESTATE", "上传成功!"); logMaps.put("UPFILESTATE", "上传成功!");
}else { } else {
logMaps.put("UPFILESTATE", "上传失败!"); logMaps.put("UPFILESTATE", "上传失败!");
} }
} catch (FileNotFoundException e1) { } catch (FileNotFoundException e1) {
e1.printStackTrace(); e1.printStackTrace();
} }
} }
} }
} catch (Exception e) { } catch (Exception e) {
// TODO: handle exception // TODO: handle exception
}finally { } finally {
SDK.getBOAPI().createDataBO("BO_ACT_FORMDATDFILE_LOG_F", new BO().setAll(logMaps), userContext); SDK.getBOAPI().createDataBO("BO_ACT_FORMDATDFILE_LOG_F", new BO().setAll(logMaps), userContext);
} }
} }
//导入表单属性及附件 //导入表单属性及附件
public void getTableInfo(UserContext userContext, String wsId, String groupValue, String fileValue, String fileName) { public void getTableInfo(UserContext userContext, String wsId, String groupValue, String fileValue, String fileName) {
DCPluginProfile dcProfilepdf = DCProfileManager.getDCProfile("com.actionsoft.apps.coe.pal.datamigration", "migration"); DCPluginProfile dcProfilepdf = DCProfileManager.getDCProfile("com.actionsoft.apps.coe.pal.datamigration", "migration");
@ -564,9 +557,8 @@ public class ReadTable {
} }
}); });
} }
/** /**
* 创建表单图形,用于挂附件 * 创建表单图形,用于挂附件
* *
@ -604,7 +596,7 @@ public class ReadTable {
props1.put("zindex", 0); props1.put("zindex", 0);
elements.put(shapeIdz, shapeze); elements.put(shapeIdz, shapeze);
// Map<String, Map<String, JSONObject>> methodAttrsMap = new HashMap<>(); // Map<String, Map<String, JSONObject>> methodAttrsMap = new HashMap<>();
//handleShapeDefaultAttr("", palRepositoryModel, elements, methodAttrsMap, docfile); //handleShapeDefaultAttr("", palRepositoryModel, elements, methodAttrsMap, docfile);
// 设置画布大小 // 设置画布大小
defineModel.setDefinition(definition.toString()); defineModel.setDefinition(definition.toString());
@ -612,9 +604,8 @@ public class ReadTable {
CoeDesignerAPIManager.getInstance().storeDefinition(defineModel);// dao操作 CoeDesignerAPIManager.getInstance().storeDefinition(defineModel);// dao操作
return shapeIdz; return shapeIdz;
} }
/** /**
* 创建表单图形 * 创建表单图形
* *