附件批量上传
This commit is contained in:
parent
7b80f17144
commit
696794b294
@ -92,7 +92,8 @@ public class DataMigrationController {
|
||||
public void run() {
|
||||
String[] fileNameArr = fileName.split(",");
|
||||
for(String name : fileNameArr){
|
||||
new ReadTable().controlPolicyFile_import(me,wsId,groupValue,fileValue,name);
|
||||
//new ReadTable().controlPolicyFile_import(me,wsId,groupValue,fileValue,name);
|
||||
new ReadTable().dataFile_import(me,wsId,groupValue,fileValue,name);
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -103,6 +104,33 @@ public class DataMigrationController {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* by lhy 附件批量上传
|
||||
* @param me
|
||||
* @param wsId
|
||||
* @param groupValue
|
||||
* @param fileValue
|
||||
* @param fileName
|
||||
* @return
|
||||
*/
|
||||
@Mapping("com.actionsoft.apps.coe.pal.batchDataFile_import")
|
||||
public String dataFileImport(UserContext me,String wsId,String groupValue,String fileValue,String fileName){
|
||||
//new ReadTable().getTableInfo(me,wsId,groupValue,fileValue,fileName);
|
||||
Thread thread =new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
String[] fileNameArr = fileName.split(",");
|
||||
for(String name : fileNameArr){
|
||||
new ReadTable().dataFile_import(me,wsId,groupValue,fileValue,name);
|
||||
}
|
||||
}
|
||||
});
|
||||
thread.setPriority(8);
|
||||
thread.start();
|
||||
ResponseObject ro = ResponseObject.newOkResponse();
|
||||
return ro.toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* by bzp 表单属性文件上传 解析文件
|
||||
|
||||
@ -95,7 +95,151 @@ public class ReadTable {
|
||||
});
|
||||
}
|
||||
|
||||
public void controlPolicyFile_import(UserContext userContext, String wsId, String groupValue, String fileValue, String fileName) {
|
||||
|
||||
// 批量上传附件
|
||||
public void dataFile_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 name = fileName.substring(0, fileName.lastIndexOf("."));
|
||||
PALRepositoryModel palRepositoryModel = ReadWordUtil.getRepositoryByName(wsId, name);
|
||||
if (palRepositoryModel == null) {
|
||||
PALRepositoryModel palRepositoryModel_s = ReadWordUtil.getRepositoryByName(wsId, "酸奶" + name);
|
||||
if (palRepositoryModel_s != null) {
|
||||
palRepositoryModel = palRepositoryModel_s;
|
||||
}
|
||||
PALRepositoryModel palRepositoryModel_y = ReadWordUtil.getRepositoryByName(wsId, "液奶" + name);
|
||||
if (palRepositoryModel_y != null) {
|
||||
palRepositoryModel = palRepositoryModel_y;
|
||||
}
|
||||
PALRepositoryModel palRepositoryModel_l = ReadWordUtil.getRepositoryByName(wsId, "冷饮" + name);
|
||||
if (palRepositoryModel_l != null) {
|
||||
palRepositoryModel = palRepositoryModel_l;
|
||||
}
|
||||
PALRepositoryModel palRepositoryModel_n = ReadWordUtil.getRepositoryByName(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.getRepositoryByName(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);
|
||||
String shpId = "";
|
||||
String fileName_shap = "";
|
||||
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);
|
||||
// 删除已有文件
|
||||
StringBuffer sql = new StringBuffer();
|
||||
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();
|
||||
}
|
||||
|
||||
} else {
|
||||
logMaps.put("PALID", id);
|
||||
if (palRepositoryModel.getMethodId().contains("process")) {
|
||||
logMaps.put("MODLETYPE", "流程模型");
|
||||
} else {
|
||||
logMaps.put("MODLETYPE", "制度模型");
|
||||
}
|
||||
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();
|
||||
sql.append("delete from ").append(UpfileModel.DATABASE_ENTITY)
|
||||
.append(" WHERE FILENAME = '" + fileName + "' AND PALREPOSITORYID = '"+id+"'");
|
||||
int update = DBSql.update(sql.toString());
|
||||
InputStream originfile = SDK.getDCAPI().read(dcContextorigin);
|
||||
try {
|
||||
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 {
|
||||
@ -208,6 +352,7 @@ public class ReadTable {
|
||||
if(name.equals(fileName_shap)) {
|
||||
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);
|
||||
|
||||
@ -1,28 +1,5 @@
|
||||
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.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;
|
||||
@ -34,6 +11,7 @@ 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.server.UserContext;
|
||||
import com.actionsoft.bpms.server.fs.DCContext;
|
||||
import com.actionsoft.bpms.server.fs.dc.DCProfileManager;
|
||||
@ -46,6 +24,14 @@ 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 {
|
||||
@ -304,20 +290,30 @@ public class ReadWordUtil {
|
||||
DCContext dcContextpdfdoc = new DCContext(userContext, dcProfilepdfdoc, "com.actionsoft.apps.coe.pal.datamigration", groupValue, fileValue, docname);
|
||||
InputStream docfile = SDK.getDCAPI().read(dcContextpdfdoc);
|
||||
|
||||
boolean result = analysisWordTable(docfile);
|
||||
//ReadWordUtil tmp = new ReadWordUtil();
|
||||
boolean result = false;
|
||||
try {
|
||||
result = analysisWordTable(docfile);
|
||||
} catch (Exception e) {
|
||||
|
||||
|
||||
}
|
||||
writeAttrbute(logMaps,result,userContext, docfile, fileName, wsId);
|
||||
|
||||
if(!result) {
|
||||
logMaps.put("FILEATTRIBUTE", "文件属性解析失败,请检查或者手动复制!");
|
||||
}
|
||||
if (fileFieldMap.get("标题") == null) {
|
||||
return;
|
||||
}
|
||||
String title = fileFieldMap.get("标题").getData().toString();
|
||||
PALRepositoryModel palRepositoryModel = getRepositoryByName(wsId, title);
|
||||
if (palRepositoryModel != null) {
|
||||
logMaps.put("PALID", palRepositoryModel.getId());
|
||||
try {
|
||||
//上传附件
|
||||
if(writeFileTodisk(userContext, "", fileName, originfile, palRepositoryModel.getId(), "f")) {
|
||||
logMaps.put("UPFILESTATE", "文件附件上传成功!");
|
||||
|
||||
}else {
|
||||
logMaps.put("UPFILESTATE", "文件附件上传失败!");
|
||||
}
|
||||
@ -354,6 +350,7 @@ public class ReadWordUtil {
|
||||
|
||||
|
||||
public boolean analysisWordTable(InputStream file) {
|
||||
|
||||
fileFieldMap.clear();
|
||||
fieldMap.clear();
|
||||
try {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user