xlsx文件更新

This commit is contained in:
Mr-wang 2023-07-24 14:45:20 +08:00
parent fa859115ec
commit f760ba1b73
5 changed files with 102 additions and 235 deletions

View File

@ -232,61 +232,6 @@ public class CopyJob implements IJob {
SendOARead(jsonObject, processInstance, userIds,"批量推送");
} catch (DocumentException e) {
e.printStackTrace();
}finally {
if (finalM == list.size()-1){
List<RowMap> List = DBSql.getMaps("SELECT NAME FROM BO_EU_READ_COUNT WHERE PROCESSID = '"
+ processInstance.getId() + "' AND RESULT = '待处理'");
if (List.size() != 0) {
System.err.println(processInstance.getTitle() + "批量推送失败后执行二次推送=======>" + List.size());
for (RowMap rowMap : List) {
try {
ArrayList<String> secondUserList = new ArrayList<String>();
secondUserList.add(rowMap.getString("NAME"));
System.err.println(processInstance.getTitle() + "二次推送账号=======>" + secondUserList);
BO executiveTaskBO=SDK.getBOAPI().query("BO_ACT_EXECUTIVE_TASK").addQuery("TASKID=",processInstance.getId()).addQuery("TASKSTATUS=",2).detail();
if(executiveTaskBO!=null){
List<BO> recordFailLists = new ArrayList<BO>();
for(RowMap oneuserId:List){
BO bo = new BO();
bo.set("TITLE", processInstance.getTitle());
bo.set("NAME", oneuserId.getString("NAME"));
bo.set("TYPE", "批量推送");
bo.set("RESULT", "待处理");
bo.set("PROCESSID", processInstance.getId());
bo.set("DEPNAME", SDK.getORGAPI().getUser(oneuserId.getString("NAME")).getDepartmentId());
recordFailLists.add(bo);
}
SDK.getBOAPI().create("BO_EU_READ_COUNT", recordFailLists, processInstance.getId(), processInstance.getCreateUser());
return;
}
secondSendOARead(jsonObject, processInstance, secondUserList, "单个账号推送");
} catch (Exception e) { // TODO: handle exception
}
}
}
long endTimes = System.currentTimeMillis();
// 存入日志
createReadLog(processInstance, jsonObject, sendList, startTime, endTimes);
System.err.println(processInstance.getTitle() + "推送OA待阅执行完毕====>" + "用时:"
+ (endTimes - startTime) / 1000 / 60 + "分钟");
//发送消息通知
List<BO> readCountBO=SDK.getBOAPI().query("BO_EU_READ_COUNT").addQuery("PROCESSID=",processInstance.getId()).list();
if(readCountBO.size()>0){
SDK.getNotificationAPI().sendMessage("admin", "admin", "文件名称:"+processInstance.getTitle()+"文件有失败记录,请及时处理!!!");
}
//更新任务状态
int r1 = DBSql.update("UPDATE BO_ACT_EXECUTIVE_TASK SET ISTASKEND='2' WHERE TASKID ='" + processInstance.getId() + "'");
}
}
}
@ -297,104 +242,6 @@ public class CopyJob implements IJob {
}
public void secondSendOARead(JSONObject jsonObject, ProcessInstance processInstance, List<String> idList,String type)
throws DocumentException {
System.out.println("idList========="+idList.toString());
String processInstId = processInstance.getId();
// System.err.println(processInstance.getTitle() + "开始发送:" + userId);
/*
* if ("".equals(userId) || UtilString.isEmpty(userId)) { return; }
*/
if (idList.size() == 0) {
return;
}
String userIds = StringUtils.join(idList, ",");
jsonObject.put("userList", userIds);
String xmlStr = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:web=\"webservices.yili.weaver.com.cn\">\n"
+ " <soapenv:Header/>" + " <soapenv:Body>" + " <web:service>" + " <web:in0>"
+ "<![CDATA[" + jsonObject + "]]>" + " </web:in0>" + " </web:service>"
+ " </soapenv:Body>" + "</soapenv:Envelope>";
// System.out.println("xmlStr>>>>>>>>" + xmlStr);
String readurl = SDK.getAppAPI().getProperty("com.awspaas.user.apps.yili.integration", "readurl");
String postSoap = UtilUrl.doPostSoap(readurl, xmlStr, "");
Document document = DocumentHelper.parseText(postSoap);
Element rootElement = document.getRootElement();
Element result = rootElement.element("Body").element("serviceResponse").element("out");
String resultString = result.getData().toString();
JSONObject jsonObject1 = JSON.parseObject(resultString);
System.out.println("jsonObject1==============="+jsonObject1);
String datas = jsonObject1.getString("data");
System.out.println("data================="+datas);
String status = jsonObject1.getString("status");
System.out.println("推送》》》》》》》》》》》" + status);
if ("true".equals(status)) {
JSONArray resultArray = JSONObject.parseArray(datas);
System.out.println(processInstance.getTitle() + "待阅推送成功:" + idList.size()+"");
//批量入库操作
//加入时间戳
if(resultArray.size()>0){
List<BO> recordLists = new ArrayList<BO>();
long startTime2 = System.currentTimeMillis();
for (int j = 0; j < resultArray.size(); j++) {
JSONObject jsonObject2 = resultArray.getJSONObject(j);
String user = jsonObject2.get("user").toString();
String dataid = jsonObject2.get("dataid").toString();
BO bo = new BO();
bo.set("TITLE", processInstance.getTitle());
bo.set("PROCESSID", processInstance.getId());
bo.set("USER_ID", user);
bo.set("USERDEP", SDK.getORGAPI().getUser(user).getDepartmentId());
bo.set("DATAID", dataid);
bo.set("RESULT", status);
bo.set("SENDTYPE", "1");
bo.set("READSTATE", "未读");
bo.set("TYPE", type);
recordLists.add(bo);
BO oa_real_time=SDK.getBOAPI().query("BO_ACT_OA_REAL_TIME").addQuery("PROCESSID=",processInstance.getId()).detail();
String sqly = "SELECT ID FROM BO_ACT_DATAID WHERE PROCESSID = '" + processInstId + "' AND SENDTYPE = '1'";
List<RowMap> mapsy = DBSql.getMaps(sqly);
if(oa_real_time!=null){
int r1 = DBSql.update("UPDATE BO_ACT_OA_REAL_TIME SET SENDNUMSJ='" + mapsy.size() + "'WHERE PROCESSID ='" + processInstance.getId() + "'");
}else{
//插入实时更新人数表
BO realTimeBO=new BO();
realTimeBO.set("USREID", user);
realTimeBO.set("DEPID", SDK.getORGAPI().getUser(user).getDepartmentId());
realTimeBO.set("BUNAME",SDK.getORGAPI().getUser(user).getExt4());
realTimeBO.set("TITLE", processInstance.getTitle());
realTimeBO.set("PROCESSID", processInstance.getId());
realTimeBO.set("SENDNUMSJ", 1);
realTimeBO.set("SENDNUM",sendTotal);
SDK.getBOAPI().create("BO_ACT_OA_REAL_TIME", bo, processInstance.getId(), processInstance.getCreateUser());
}
}
SDK.getBOAPI().create("BO_ACT_DATAID",recordLists, processInstance.getId(), processInstance.getCreateUser());
long endTime2 = System.currentTimeMillis();
System.err.println(processInstance.getTitle() + "二次批量插入OA待阅数据====>" + "用时:"
+ (endTime2 - startTime2) / 1000 + "");
}
if("单个账号推送".equals(type)) {
DBSql.update("UPDATE BO_EU_READ_COUNT SET RESULT = '已重新推送' WHERE PROCESSID = '"+processInstId+"' AND NAME = '"+userIds+"'");
}
}
}
/**
* 发送OA待阅数据
*

View File

@ -331,13 +331,15 @@ public class Report2Gener {
for (RowMap rowMap :
nodeRowMaps_shape) {
String itsysval = rowMap.getString("ITSYSVAL");
SDK.getLogAPI().consoleInfo("这个进来了吗并且输出了系统名称了吗>>>>>>>>>>>>>"+itsysval);
if (!list_it_system.contains(itsysval)) {
list_it_system.add(itsysval);
}
}
SDK.getLogAPI().consoleInfo(list_it_system.toString());
int t = 1;
for (int r = 0; r < list_it_system.size(); r++) {
if (StringUtils.isEmpty(list_it_system.get(r))) {
if (!StringUtils.isEmpty(list_it_system.get(r))) {
JSONObject _tr_it_system = new JSONObject(new LinkedHashMap<>());
_tr_it_system.put("numbers", t);
_tr_it_system.put("it_name", list_it_system.get(r));
@ -376,6 +378,7 @@ public class Report2Gener {
//}
}
dataMap.put("position_table", positionTable);
SDK.getLogAPI().consoleInfo(dataMap.toString());
return dataMap;
}

View File

@ -32,7 +32,9 @@ public class OrReportComment {
public void getCommentContent(JSONObject dataMap, Map<String, Map<String, Object>> shapesMap, String shapeId,String userId) {
Map<String, Object> shapeMap = shapesMap.get(shapeId);
dataMap.put(OutputWordUtil.POSITION, UserContext.fromUID(userId).getUserModel().getPositionName()); //岗位名称
String position = UserContext.fromUID(userId).getUserModel().getPositionName();
//position.replace("\n", OutputWordUtil.WRAPSTRING);
dataMap.put(OutputWordUtil.POSITION, position); //岗位名称
//TODO 所属部门/公司
String messageJson = PALRepositoryQueryAPIManager.getInstance().getProcessDefinition(null, shapeMap.get("pid").toString());
JSONObject definition = JSONObject.parseObject(messageJson);

View File

@ -15,6 +15,7 @@ import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import com.actionsoft.exception.AWSDataAccessException;
import org.apache.commons.lang.StringUtils;
@ -546,7 +547,6 @@ public class ProcessEndAfterEvent_new extends ExecuteListener implements Execute
int m = 0;
for (String[] resrt:list
) {
int finalM = m;
service.execute(new Runnable() {
@Override
@ -559,61 +559,6 @@ public class ProcessEndAfterEvent_new extends ExecuteListener implements Execute
SendOARead(jsonObject, processExecutionContext.getProcessInstance(), userIds,"批量推送");
} catch (DocumentException e) {
e.printStackTrace();
}finally {
if (finalM == list.size()-1){
List<RowMap> List = DBSql.getMaps("SELECT NAME FROM BO_EU_READ_COUNT WHERE PROCESSID = '"
+ instanceById.getId() + "' AND RESULT = '待处理'");
if (List.size() != 0) {
System.err.println(instanceById.getTitle() + "批量推送失败后执行二次推送=======>" + List.size());
for (RowMap rowMap : List) {
try {
ArrayList<String> secondUserList = new ArrayList<String>();
secondUserList.add(rowMap.getString("NAME"));
System.err.println(instanceById.getTitle() + "二次推送账号=======>" + secondUserList);
BO executiveTaskBO=SDK.getBOAPI().query("BO_ACT_EXECUTIVE_TASK").addQuery("TASKID=",processExecutionContext.getProcessInstance().getId()).addQuery("TASKSTATUS=",2).detail();
if(executiveTaskBO!=null){
List<BO> recordFailLists = new ArrayList<BO>();
for(RowMap oneuserId:List){
BO bo = new BO();
bo.set("TITLE", processExecutionContext.getProcessInstance().getTitle());
bo.set("NAME", oneuserId.getString("NAME"));
bo.set("TYPE", "批量推送");
bo.set("RESULT", "待处理");
bo.set("PROCESSID", processExecutionContext.getProcessInstance().getId());
bo.set("DEPNAME", SDK.getORGAPI().getUser(oneuserId.getString("NAME")).getDepartmentId());
recordFailLists.add(bo);
}
SDK.getBOAPI().create("BO_EU_READ_COUNT", recordFailLists, processExecutionContext.getProcessInstance().getId(), processExecutionContext.getProcessInstance().getCreateUser());
return;
}
secondSendOARead(jsonObject, instanceById, secondUserList, "单个账号推送");
} catch (Exception e) { // TODO: handle exception
}
}
}
long endTimes = System.currentTimeMillis();
// 存入日志
createReadLog(processExecutionContext, jsonObject, sendList, startTime, endTimes);
System.err.println(instanceById.getTitle() + "推送OA待阅执行完毕====>" + "用时:"
+ (endTimes - startTime) / 1000 / 60 + "分钟");
//发送消息通知
List<BO> readCountBO=SDK.getBOAPI().query("BO_EU_READ_COUNT").addQuery("PROCESSID=",processExecutionContext.getProcessInstance().getId()).list();
if(readCountBO.size()>0){
SDK.getNotificationAPI().sendMessage("admin", "admin", "文件名称:"+processExecutionContext.getProcessInstance().getTitle()+"文件有失败记录,请及时处理!!!");
}
//更新任务状态
int r1 = DBSql.update("UPDATE BO_ACT_EXECUTIVE_TASK SET ISTASKEND='2' WHERE TASKID ='" + processExecutionContext.getProcessInstance().getId() + "'");
}
}
}
@ -621,6 +566,66 @@ public class ProcessEndAfterEvent_new extends ExecuteListener implements Execute
});
m++;
}
try {
// 等待所有的任务执行完毕最多等待1小时
if (service.awaitTermination(12, TimeUnit.HOURS)) {
List<RowMap> List = DBSql.getMaps("SELECT NAME FROM BO_EU_READ_COUNT WHERE PROCESSID = '"
+ instanceById.getId() + "' AND RESULT = '待处理'");
if (List.size() != 0) {
System.err.println(instanceById.getTitle() + "批量推送失败后执行二次推送=======>" + List.size());
for (RowMap rowMap : List) {
try {
ArrayList<String> secondUserList = new ArrayList<String>();
secondUserList.add(rowMap.getString("NAME"));
System.err.println(instanceById.getTitle() + "二次推送账号=======>" + secondUserList);
BO executiveTaskBO=SDK.getBOAPI().query("BO_ACT_EXECUTIVE_TASK").addQuery("TASKID=",processExecutionContext.getProcessInstance().getId()).addQuery("TASKSTATUS=",2).detail();
if(executiveTaskBO!=null){
List<BO> recordFailLists = new ArrayList<BO>();
for(RowMap oneuserId:List){
BO bo = new BO();
bo.set("TITLE", processExecutionContext.getProcessInstance().getTitle());
bo.set("NAME", oneuserId.getString("NAME"));
bo.set("TYPE", "批量推送");
bo.set("RESULT", "待处理");
bo.set("PROCESSID", processExecutionContext.getProcessInstance().getId());
bo.set("DEPNAME", SDK.getORGAPI().getUser(oneuserId.getString("NAME")).getDepartmentId());
recordFailLists.add(bo);
}
SDK.getBOAPI().create("BO_EU_READ_COUNT", recordFailLists, processExecutionContext.getProcessInstance().getId(), processExecutionContext.getProcessInstance().getCreateUser());
return;
}
secondSendOARead(jsonObject, instanceById, secondUserList, "单个账号推送");
} catch (Exception e) { // TODO: handle exception
}
}
}
long endTimes = System.currentTimeMillis();
// 存入日志
createReadLog(processExecutionContext, jsonObject, sendList, startTime, endTimes);
System.err.println(instanceById.getTitle() + "推送OA待阅执行完毕====>" + "用时:"
+ (endTimes - startTime) / 1000 / 60 + "分钟");
//发送消息通知
List<BO> readCountBO=SDK.getBOAPI().query("BO_EU_READ_COUNT").addQuery("PROCESSID=",processExecutionContext.getProcessInstance().getId()).list();
if(readCountBO.size()>0){
SDK.getNotificationAPI().sendMessage("admin", "admin", "文件名称:"+processExecutionContext.getProcessInstance().getTitle()+"文件有失败记录,请及时处理!!!");
}
//更新任务状态
int r1 = DBSql.update("UPDATE BO_ACT_EXECUTIVE_TASK SET ISTASKEND='2' WHERE TASKID ='" + processExecutionContext.getProcessInstance().getId() + "'");
} else {
System.out.println("超过等待时间,部分任务未执行完毕");
}
} catch (InterruptedException e) {
System.out.println("等待中断异常");
}
}
/**

View File

@ -19,15 +19,19 @@ import com.actionsoft.bpms.util.DBSql;
import com.actionsoft.bpms.util.UUIDGener;
import com.actionsoft.bpms.util.UtilDate;
import com.actionsoft.bpms.util.UtilString;
import com.actionsoft.exception.AWSDataAccessException;
import com.actionsoft.sdk.local.SDK;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.spire.presentation.*;
import com.spire.presentation.drawing.FillFormatType;
import org.apache.commons.text.StringEscapeUtils;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.openxml4j.exceptions.OLE2NotOfficeXmlFileException;
import org.apache.poi.poifs.filesystem.OfficeXmlFileException;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Color;
@ -38,10 +42,9 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.util.StringUtils;
import java.awt.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.*;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.LinkedList;
@ -51,14 +54,15 @@ import java.util.Map;
@Controller
public class UpFileExcelAndPptController {
@Mapping("com.awspaas.apps.coe.pal.output.zd.UpFileExcelAndPptController.upfile")
public JSONObject upfile(String sid,String pl_uuid,String shape_uuid,String file_data){
public JSONObject upfile(String sid,String pl_uuid,String shape_uuid,String file_data) throws UnsupportedEncodingException {
if (shape_uuid.contains("obj_")){
System.out.println("file_data>>>>>>>>>>>>>"+file_data);
JSONObject jsonObject = JSONObject.parseObject(file_data);
JSONObject jqXHR = jsonObject.getJSONObject("jqXHR");
JSONObject responseJSON = jqXHR.getJSONObject("responseJSON");
JSONObject files = responseJSON.getJSONObject("files");
String name = files.getString("name");
String name = URLDecoder.decode(files.getString("name"), StandardCharsets.UTF_8.toString());
System.out.println("filename>>>>>>>>>>>"+name);
UpfileModel model = new UpfileModel();
model.setUuid(UUIDGener.getUUID());
model.setPl_uuid(pl_uuid);
@ -96,13 +100,8 @@ public class UpFileExcelAndPptController {
String path = dcContext.getPath();
String fileName = name;
Utils.mergeExcel(list, path, fileName);
//Utils.mergeExcel(list,path+fileName);
//Open the first excel file.
// 读取上传的Excel文件
FileInputStream file = new FileInputStream(new File(dcContext.getFilePath()));
XSSFWorkbook workbook = new XSSFWorkbook(file);
// FileInputStream file2 = new FileInputStream(new File(dcContext.getFilePath()));
@ -139,20 +138,20 @@ public class UpFileExcelAndPptController {
}
//这个是替换生效日期
String file_date = DBSql.getString("select PROPERTYVALUE from APP_ACT_COE_PAL_PROP where PLID = '" + pl_uuid + "' and PROPERTYID = 'effective_date'");
if (UtilString.isNotEmpty(file_date)){
if (UtilString.isNotEmpty(file_date)){
replaceParameter(sheet, "{{file_date}}", file_date);
}else {
replaceParameter(sheet, "{{file_date}}", "");
}
replaceParameter(sheet, "{{file_date}}", file_date);
}else {
replaceParameter(sheet, "{{file_date}}", "");
}
//这个是替换适用范围
String fanwei = DBSql.getString("select PROPERTYVALUE from APP_ACT_COE_PAL_PROP where PLID = '" + pl_uuid + "' and PROPERTYID = 'application'");
if (UtilString.isNotEmpty(fanwei)){
if (UtilString.isNotEmpty(fanwei)){
replaceParameter(sheet, "{{fanwei}}", fanwei);
}else {
replaceParameter(sheet, "{{fanwei}}", "");
}
replaceParameter(sheet, "{{fanwei}}", fanwei);
}else {
replaceParameter(sheet, "{{fanwei}}", "");
}
//这个是替换L1-L4
String L1 = DBSql.getString("select PROPERTYVALUE from APP_ACT_COE_PAL_PROP where PLID = '" + pl_uuid + "' and PROPERTYID = 'Process_Architecture_L1'");
replaceParameter(sheet, "{{L1}}", L1);
@ -239,10 +238,21 @@ public class UpFileExcelAndPptController {
outputStream.close();
System.out.println("封面参数替换完成!");
} catch (IOException e) {
e.printStackTrace();
}catch (Exception e){
}
//Utils.mergeExcel(list,path+fileName);
//Open the first excel file.
// 读取上传的Excel文件
System.out.println("Excel文件修改成功");
} catch ( Exception e) {
e.printStackTrace();