定时任务 判断多线程是否执行完毕,执行完毕执行二次推送
This commit is contained in:
parent
f760ba1b73
commit
4b05df7bc5
@ -29,6 +29,7 @@ import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class CopyJob implements IJob {
|
||||
|
||||
@ -239,6 +240,166 @@ public class CopyJob implements IJob {
|
||||
});
|
||||
m++;
|
||||
}
|
||||
|
||||
try {
|
||||
// 等待所有的任务执行完毕,最多等待1小时
|
||||
if (service.awaitTermination(12, TimeUnit.HOURS)) {
|
||||
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() + "'");
|
||||
|
||||
|
||||
} else {
|
||||
System.out.println("超过等待时间,部分任务未执行完毕");
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
System.out.println("等待中断异常");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
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+"'");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user