创建线程执行发布

This commit is contained in:
Mr-wang 2023-07-10 10:50:53 +08:00
parent 8c894e7c51
commit eb6301781f

View File

@ -387,9 +387,61 @@ public class ProcessEndAfterEvent_new extends ExecuteListener implements Execute
* for (String user : sendList) { try { SendOARead(jsonObject, instanceById,
* user, "批量推送"); } catch (Exception e) { // TODO: handle exception } }
*/
if (StringUtils.isNotEmpty(new_uid
)) {
new_uid = new_uid.substring(0, new_uid.length() - 1);
}
long startTimes = System.currentTimeMillis();
System.out.println("new_userid ==========>>>>>>>>>"+new_uid);
String[] users = new_uid.split(",");
int length = 300;
int ys = users.length%length;
/**
* 这个是以300人作为一个发送单位去放到list中并发送待阅数据
*/
if (ys==0) {
int size = users.length/length;
int flag = 0;
List<String[]> list = new LinkedList();
for (int i=0;i<size;i++){
String[] results;
results = Arrays.copyOfRange(users, flag, flag+300);
list.add(results);
flag = flag+300;
}
/**
* 创建线程发送待阅数据
*/
course(list,startTime,jsonObject,processExecutionContext);
}else {
int size = users.length/length;
int flag = 0;
List<String[]> list = new LinkedList();
for (int i=0;i<size;i++){
String[] results;
results = Arrays.copyOfRange(users, flag, flag+300);
list.add(results);
flag = flag+300;
}
String[] redata;
redata = Arrays.copyOfRange(users, flag, flag+ys);
list.add(redata);
// 创建线程来实现为每300人为一个的线程跑待阅
/**
* 创建线程发送待阅数据
*/
course(list,startTime,jsonObject,processExecutionContext);
}
int toIndex = 200;
/*int toIndex = 200;
int listSize = sendList.size();
boolean shutdown = false;
@ -435,7 +487,7 @@ public class ProcessEndAfterEvent_new extends ExecuteListener implements Execute
System.err.println(instanceById.getTitle() + "单次300条推送单条====>" + "用时:"
+ (endTimes1 - startTime1) / 1000 + "");
/*
*//*
* ExecutorService cachedThreadPool = Executors.newFixedThreadPool(3); // 开启一个线程
* cachedThreadPool.execute(new Runnable() {
*
@ -443,16 +495,16 @@ public class ProcessEndAfterEvent_new extends ExecuteListener implements Execute
* Auto-generated catch block e.printStackTrace(); }
*
* } });
*/
*//*
// 以下是等线程池的全部线程执行结束后会自动执行
/*
*//*
* cachedThreadPool.shutdown(); while (true) { if
* (cachedThreadPool.isTerminated()) { long time = System.currentTimeMillis() -
* startTime; //System.out.println("程序结束了,总耗时:" + time + " ms(毫秒)\n"+toIndex);
* break; } }
*/
*//*
}
}*/
// 二次推送
List<RowMap> List = DBSql.getMaps("SELECT NAME FROM BO_EU_READ_COUNT WHERE PROCESSID = '"
@ -540,6 +592,45 @@ public class ProcessEndAfterEvent_new extends ExecuteListener implements Execute
}
}
/**
* 根据线程创建待阅日志
* @param list
* @param startTime
* @param jsonObject
* @param processExecutionContext
*/
public void course(List<String[]> list,long startTime,JSONObject jsonObject,ProcessExecutionContext processExecutionContext){
// 创建线程来实现为每300人为一个的线程跑待阅
ExecutorService service = Executors.newFixedThreadPool(4);
service.execute(new Runnable() {
@Override
public void run() {
int i=0;
for (String[] resrt:list
) {
if ((list.size()-1)==i){
long endTime = System.currentTimeMillis();
long time = endTime - startTime;
long itmes = time/1000/60/60;
BO bo_eu_pal_read_log = SDK.getBOAPI().query("BO_EU_PAL_READ_LOG", true).addQuery("PROCESSID = ", processExecutionContext.getProcessInstance().getId()).detail();
bo_eu_pal_read_log.set("ENDTIMES",endTime);
bo_eu_pal_read_log.set("TIMECOUNT",itmes);
SDK.getBOAPI().update("BO_EU_PAL_READ_LOG",bo_eu_pal_read_log);
}
try {
SendOARead(jsonObject, processExecutionContext.getProcessInstance(), resrt,"批量推送");
} catch (DocumentException e) {
e.printStackTrace();
}
i++;
}
}
});
}
/**
* 创建附件及文件
*
@ -872,24 +963,23 @@ public class ProcessEndAfterEvent_new extends ExecuteListener implements Execute
* @param results
* @throws DocumentException
*/
public void SendOARead(JSONObject jsonObject, ProcessInstance processInstance, List<String> idList,String type)
public void SendOARead(JSONObject jsonObject, ProcessInstance processInstance, String[] resrt,String type)
throws DocumentException {
String userIds = "";
userIds = StringUtils.join(resrt, ",");
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) {
if (userIds.length() == 0) {
return;
}
String userIds = StringUtils.join(idList, ",");
jsonObject.put("userList", userIds);
jsonObject.put("userList", resrt);
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>"
@ -911,7 +1001,7 @@ public class ProcessEndAfterEvent_new extends ExecuteListener implements Execute
if ("true".equals(status)) {
JSONArray resultArray = JSONObject.parseArray(datas);
System.out.println(processInstance.getTitle() + "待阅推送成功:" + idList.size()+"");
//System.out.println(processInstance.getTitle() + "待阅推送成功:" + idList.size()+"");
//批量入库操作
//加入时间戳
if(resultArray.size()>0){
@ -963,9 +1053,10 @@ public class ProcessEndAfterEvent_new extends ExecuteListener implements Execute
}
if("单个账号推送".equals(type)) {
DBSql.update("UPDATE BO_EU_READ_COUNT SET RESULT = '已重新推送' WHERE PROCESSID = '"+processInstId+"' AND NAME = '"+userIds+"'");
DBSql.update("UPDATE BO_EU_READ_COUNT SET RESULT = '已重新推送' WHERE PROCESSID = '"+processInstId+"' AND NAME = '"+resrt+"'");
}
} else {
List<String> idList = Arrays.asList(resrt);
BO bo = null;
List<BO> recordFailLists = new ArrayList<BO>();
if(idList.size()>0){