批量导入日志完善
This commit is contained in:
parent
7e7dbfbaca
commit
a94b875ddb
Binary file not shown.
@ -3,6 +3,7 @@ package com.actionsoft.apps.coe.pal.datamigration.util;
|
|||||||
import com.actionsoft.apps.coe.pal.datamigration.aris.constant.ArisConstant;
|
import com.actionsoft.apps.coe.pal.datamigration.aris.constant.ArisConstant;
|
||||||
import com.actionsoft.apps.coe.pal.datamigration.constant.Constant;
|
import com.actionsoft.apps.coe.pal.datamigration.constant.Constant;
|
||||||
import com.actionsoft.apps.coe.pal.datamigration.log.cache.LogRealTimeCountCache;
|
import com.actionsoft.apps.coe.pal.datamigration.log.cache.LogRealTimeCountCache;
|
||||||
|
import com.actionsoft.apps.coe.pal.datamigration.log.dao.LogDao;
|
||||||
import com.actionsoft.apps.coe.pal.datamigration.log.model.LogModel;
|
import com.actionsoft.apps.coe.pal.datamigration.log.model.LogModel;
|
||||||
import com.actionsoft.apps.resource.plugin.profile.DCPluginProfile;
|
import com.actionsoft.apps.resource.plugin.profile.DCPluginProfile;
|
||||||
import com.actionsoft.bpms.server.UserContext;
|
import com.actionsoft.bpms.server.UserContext;
|
||||||
@ -31,7 +32,7 @@ public class WordLogUtil {
|
|||||||
public WordLogUtil(UserContext _uc){
|
public WordLogUtil(UserContext _uc){
|
||||||
this.uc = _uc;
|
this.uc = _uc;
|
||||||
logId = UUIDGener.getUUID();// 记录缓存
|
logId = UUIDGener.getUUID();// 记录缓存
|
||||||
String fileValue = "AttrtibuteImported-" + new SimpleDateFormat("yyyy-MM-dd HH-mm-ss").format(new Date()) + "=" + _uc.getUID();
|
String fileValue = "AttrtibuteImported-" + new SimpleDateFormat("yyyy-MM-dd HH-mm-ss").format(new Date()) + "--" + _uc.getUID();
|
||||||
// 创建dc目录
|
// 创建dc目录
|
||||||
DCPluginProfile dcProfile = DCProfileManager.getDCProfile(Constant.APP_ID, Constant.UPFILE);
|
DCPluginProfile dcProfile = DCProfileManager.getDCProfile(Constant.APP_ID, Constant.UPFILE);
|
||||||
DCContext dc = new DCContext(_uc, dcProfile, Constant.APP_ID, "log", fileValue);
|
DCContext dc = new DCContext(_uc, dcProfile, Constant.APP_ID, "log", fileValue);
|
||||||
@ -142,6 +143,32 @@ public class WordLogUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新日志(日志操作行为,非具体日志信息)
|
||||||
|
* @param id
|
||||||
|
* @param endDate 结束时间
|
||||||
|
* @param resultType 结果状态
|
||||||
|
* @param mainInfo 主要信息
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public int updateLog(Timestamp endDate, int resultType, String mainInfo) {
|
||||||
|
return new LogDao().update(logId, endDate, resultType, mainInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String takeTime(long startTime,long endTime) {
|
||||||
|
long time = endTime - startTime;
|
||||||
|
String timeMsg = "";
|
||||||
|
if (time > 1000 * 60) {
|
||||||
|
timeMsg = "[" + (time / 1000 / 60) + "]分钟";
|
||||||
|
} else if (time > 1000) {
|
||||||
|
timeMsg = "[" + (time / 1000) + "]秒";
|
||||||
|
} else {
|
||||||
|
timeMsg = "[" + time + "]毫秒";
|
||||||
|
}
|
||||||
|
return timeMsg;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -12,6 +12,7 @@ import org.apache.poi.hwpf.HWPFDocument;
|
|||||||
import org.apache.poi.hwpf.usermodel.*;
|
import org.apache.poi.hwpf.usermodel.*;
|
||||||
|
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@ -72,64 +73,56 @@ public class WordUtil {
|
|||||||
|
|
||||||
public WordUtil() { }
|
public WordUtil() { }
|
||||||
|
|
||||||
public boolean analysisWordTable(String filePath){
|
public void analysisWordTable(String filePath) throws IOException ,RuntimeException {
|
||||||
try {
|
HWPFDocument doc = new HWPFDocument(new FileInputStream(filePath));
|
||||||
HWPFDocument doc = new HWPFDocument(new FileInputStream(filePath));
|
Range range = doc.getRange();
|
||||||
Range range = doc.getRange();
|
|
||||||
|
|
||||||
for (int i =0;i<range.numParagraphs();i++){
|
|
||||||
Paragraph paragraph = range.getParagraph(i);
|
|
||||||
String text = paragraph.text();
|
|
||||||
if (StringUtils.isEmpty(text)||"\r".equals(text)){
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
//获取文件编码
|
|
||||||
if (text.contains("文件编码") && fileFieldMap.get("文件编码") == null){
|
|
||||||
this.fileNo = this.getFileNo(text);
|
|
||||||
this.isOldVersion = this.isOldVersion(this.fileNo);
|
|
||||||
fileFieldMap.put("文件编码",new WordField<>(this.fileNo));
|
|
||||||
}
|
|
||||||
|
|
||||||
//获取文件名称
|
|
||||||
if (this.isTitle(paragraph)){
|
|
||||||
this.fileName += text.trim();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.isOldVersion){
|
|
||||||
//旧版本文档
|
|
||||||
AnalysisStrategyContext strategyContext = new AnalysisStrategyContext();
|
|
||||||
if (this.isTitle(paragraph)){
|
|
||||||
//文件标题下解析后续table
|
|
||||||
AnalysisStrategy titleField = strategyContext.getStrategy("VerticalFeild");
|
|
||||||
Map<String, WordField<Object>> analysis = titleField.analysis(doc, i);
|
|
||||||
fileFieldMap.putAll(analysis);
|
|
||||||
}
|
|
||||||
WordAttribute wordAttribute = oldWordAttributeMap.get(text.trim());
|
|
||||||
if (null == wordAttribute){
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
AnalysisStrategy strategy = strategyContext.getStrategy(wordAttribute.getType());
|
|
||||||
Map<String, WordField<Object>> analysis = strategy.analysis(doc, i);
|
|
||||||
fileFieldMap.putAll(analysis);
|
|
||||||
}else {
|
|
||||||
WordAttribute wordAttribute = wordAttributeMap.get(text.trim());
|
|
||||||
if (null == wordAttribute){
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
AnalysisStrategy strategy = new AnalysisStrategyContext().getStrategy(wordAttribute.getType());
|
|
||||||
Map<String, WordField<Object>> analysis = strategy.analysis(doc,i);
|
|
||||||
fileFieldMap.putAll(analysis);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
for (int i =0;i<range.numParagraphs();i++){
|
||||||
|
Paragraph paragraph = range.getParagraph(i);
|
||||||
|
String text = paragraph.text();
|
||||||
|
if (StringUtils.isEmpty(text)||"\r".equals(text)){
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (IOException e) {
|
//获取文件编码
|
||||||
e.printStackTrace();
|
if (text.contains("文件编码") && fileFieldMap.get("文件编码") == null){
|
||||||
return false;
|
this.fileNo = this.getFileNo(text);
|
||||||
}
|
this.isOldVersion = this.isOldVersion(this.fileNo);
|
||||||
|
fileFieldMap.put("文件编码",new WordField<>(this.fileNo));
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
//获取文件名称
|
||||||
|
if (this.isTitle(paragraph)){
|
||||||
|
this.fileName += text.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.isOldVersion){
|
||||||
|
//旧版本文档
|
||||||
|
AnalysisStrategyContext strategyContext = new AnalysisStrategyContext();
|
||||||
|
if (this.isTitle(paragraph)){
|
||||||
|
//文件标题下解析后续table
|
||||||
|
AnalysisStrategy titleField = strategyContext.getStrategy("VerticalFeild");
|
||||||
|
Map<String, WordField<Object>> analysis = titleField.analysis(doc, i);
|
||||||
|
fileFieldMap.putAll(analysis);
|
||||||
|
}
|
||||||
|
WordAttribute wordAttribute = oldWordAttributeMap.get(text.trim());
|
||||||
|
if (null == wordAttribute){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
AnalysisStrategy strategy = strategyContext.getStrategy(wordAttribute.getType());
|
||||||
|
Map<String, WordField<Object>> analysis = strategy.analysis(doc, i);
|
||||||
|
fileFieldMap.putAll(analysis);
|
||||||
|
}else {
|
||||||
|
WordAttribute wordAttribute = wordAttributeMap.get(text.trim());
|
||||||
|
if (null == wordAttribute){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
AnalysisStrategy strategy = new AnalysisStrategyContext().getStrategy(wordAttribute.getType());
|
||||||
|
Map<String, WordField<Object>> analysis = strategy.analysis(doc,i);
|
||||||
|
fileFieldMap.putAll(analysis);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getFileNo(String text){
|
private String getFileNo(String text){
|
||||||
|
|||||||
@ -140,8 +140,8 @@ public class DataMigrationWeb extends ActionWeb {
|
|||||||
String fileName = "";
|
String fileName = "";
|
||||||
for (int i = 0; i < fileArr.length; i++) {
|
for (int i = 0; i < fileArr.length; i++) {
|
||||||
File file = fileArr[i];
|
File file = fileArr[i];
|
||||||
fileName = StringUtils.isEmpty(fileName) ? fileName + file.getName() : ","+ fileName + file.getName();
|
fileName = StringUtils.isEmpty(fileName) ? fileName + file.getName() : fileName + ","+ file.getName();
|
||||||
if (i>=3){
|
if (i>=2){
|
||||||
fileName += "等";
|
fileName += "等";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -169,21 +169,32 @@ public class DataMigrationWeb extends ActionWeb {
|
|||||||
return ResponseObject.newErrResponse("资产库不存在或已停用").toString();
|
return ResponseObject.newErrResponse("资产库不存在或已停用").toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
new Thread(new Runnable() {
|
new Thread(()->{
|
||||||
@Override
|
int success = 0;
|
||||||
public void run() {
|
int error = 0;
|
||||||
for (File file : fileArr) {
|
for (File file : fileArr) {
|
||||||
wordLogUtil.appendAllLog("\n[信息]流程属性Word文件:" + file.getName());
|
wordLogUtil.appendAllLog("\n[信息]流程属性Word文件:" + file.getName());
|
||||||
wordLogUtil.appendAllLog("[信息]流程属性Word文件路径:"+ file.getPath());
|
wordLogUtil.appendAllLog("[信息]流程属性Word文件路径:"+ file.getPath());
|
||||||
wordLogUtil.appendAllLog("-----------流程属性Word文件 Begin " + UtilDate.datetimeFormat(startTime));
|
wordLogUtil.appendAllLog("-----------流程属性Word文件 Begin " + UtilDate.datetimeFormat(startTime));
|
||||||
ResponseObject res = new DataMigrationWeb().analysisWord(wsId, file.getPath(), wordLogUtil);
|
ResponseObject res = new DataMigrationWeb().analysisWord(wsId, file.getPath(), wordLogUtil);
|
||||||
if (res.isErr()){
|
if (res.isErr()){
|
||||||
wordLogUtil.appendAllAndErrorLog(Constant.LOG_ERROR + "word文件--"+file.getName()+" 解析异常:"+res.getMsg()+" 中断解析\n");
|
error++;
|
||||||
}
|
wordLogUtil.appendAllAndErrorLog(Constant.LOG_ERROR + "word文件--"+file.getName()+" 解析异常:"+res.getMsg()+" ,中断解析\n");
|
||||||
if (res.isOk()){
|
|
||||||
wordLogUtil.appendAllAndInfoLog(Constant.LOG_END+ "word文件--"+file.getName()+" :"+res.getMsg()+"\n");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if (res.isOk()){
|
||||||
|
success++;
|
||||||
|
wordLogUtil.appendAllAndInfoLog(Constant.LOG_END+ "word文件--"+file.getName()+" :"+res.getMsg()+"\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Timestamp endTime = new Timestamp(System.currentTimeMillis());
|
||||||
|
if (success > 0){
|
||||||
|
String resultMsg = "批量导入成功:总耗时" + wordLogUtil.takeTime(startTime.getTime(),endTime.getTime()) + ",总计文档["+fileArr.length+"]条,导入成功[" + success + "]条,导入失败[" + error + "]条";
|
||||||
|
wordLogUtil.updateLog(new Timestamp(System.currentTimeMillis()), Constant.LOG_RESULT_StATUS_SUCCESS, resultMsg);
|
||||||
|
wordLogUtil.appendAllAndInfoLog(resultMsg);
|
||||||
|
}else {
|
||||||
|
String resultMsg = "批量导入失败:总耗时" + wordLogUtil.takeTime(startTime.getTime(),endTime.getTime()) + ",总计文档["+fileArr.length+"]条,导入成功[" + success + "]条,导入失败[" + error + "]条";
|
||||||
|
wordLogUtil.updateLog(new Timestamp(System.currentTimeMillis()), Constant.LOG_RESULT_StATUS_ERROR, resultMsg);
|
||||||
|
wordLogUtil.appendAllAndInfoLog(resultMsg);
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
|
|
||||||
@ -418,9 +429,12 @@ public class DataMigrationWeb extends ActionWeb {
|
|||||||
private ResponseObject analysisWord(String wsId,String filePath,WordLogUtil logUtil){
|
private ResponseObject analysisWord(String wsId,String filePath,WordLogUtil logUtil){
|
||||||
//解析Word文档
|
//解析Word文档
|
||||||
WordUtil wordUtil = new WordUtil();
|
WordUtil wordUtil = new WordUtil();
|
||||||
boolean analysisFlag = wordUtil.analysisWordTable(filePath);
|
try {
|
||||||
if (!analysisFlag) {
|
wordUtil.analysisWordTable(filePath);
|
||||||
return ResponseObject.newErrResponse("文件解析异常");
|
} catch (IOException e) {
|
||||||
|
return ResponseObject.newErrResponse("word 文件解析异常: "+e.getMessage());
|
||||||
|
} catch (RuntimeException e){
|
||||||
|
return ResponseObject.newErrResponse("word 文件解析异常: "+e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取解析后的文件名称,同名策略匹配pal寻找对应文件
|
//获取解析后的文件名称,同名策略匹配pal寻找对应文件
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user