From 6e411c48a99544e70993d97d41115ea9f2a328e2 Mon Sep 17 00:00:00 2001 From: Mr-wang Date: Wed, 30 Aug 2023 16:46:59 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=89=8B=E5=8A=A8=E6=8E=A8?= =?UTF-8?q?=E9=80=81OA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../coe/pal/datamigration/InsertOAJob.java | 974 ++++++++++++++++++ 1 file changed, 974 insertions(+) create mode 100644 com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/InsertOAJob.java diff --git a/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/InsertOAJob.java b/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/InsertOAJob.java new file mode 100644 index 00000000..f6f2d2d4 --- /dev/null +++ b/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/InsertOAJob.java @@ -0,0 +1,974 @@ +package com.actionsoft.apps.coe.pal.datamigration; + +import com.actionsoft.apps.coe.pal.datamigration.Utils.UtilUrl; +import com.actionsoft.bpms.bo.engine.BO; +import com.actionsoft.bpms.bpmn.engine.model.run.delegate.ProcessInstance; +import com.actionsoft.bpms.bpmn.engine.model.run.delegate.TaskInstance; +import com.actionsoft.bpms.commons.database.RowMap; +import com.actionsoft.bpms.org.model.DepartmentModel; +import com.actionsoft.bpms.org.model.UserModel; +import com.actionsoft.bpms.schedule.IJob; +import com.actionsoft.bpms.server.UserContext; +import com.actionsoft.bpms.util.DBSql; +import com.actionsoft.bpms.util.UtilString; +import com.actionsoft.sdk.local.SDK; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import lombok.SneakyThrows; +import org.apache.commons.lang.StringUtils; +import org.dom4j.Document; +import org.dom4j.DocumentException; +import org.dom4j.DocumentHelper; +import org.dom4j.Element; +import org.quartz.JobExecutionContext; +import org.quartz.JobExecutionException; + +import java.sql.Timestamp; +import java.text.SimpleDateFormat; +import java.util.*; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +public class InsertOAJob implements IJob { + + private int sendTotal; + @SneakyThrows + @Override + public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException { + + String cc = SDK.getJobAPI().getJobParameter(jobExecutionContext); + System.err.println("推送OA待阅执行开始====>"); + long startTime = System.currentTimeMillis(); + ArrayList sendList = new ArrayList(); + String new_uid = ""; + ProcessInstance pc = SDK.getProcessAPI().getInstanceById(cc); + BO bo_act_coe_publish1 = SDK.getBOAPI().query("BO_ACT_COE_PUBLISH", true) + .addQuery("BINDID=", pc.getId()) + .addQuery("OPTIONTYPE IS NOT NULL", null).detail(); + + String sql = "SELECT ID FROM WFH_TASK WHERE PROCESSINSTID = '" + pc.getId() + + "' AND ACTIVITYDEFID = 'obj_c9e5a3144b200001b68cffa01ed0153e' "; + String taskInd = DBSql.getString(sql); + TaskInstance taskInstance = SDK.getTaskAPI().getInstanceById(taskInd); + String sql_date = "SELECT ENDTIME FROM WFH_TASK WHERE PROCESSINSTID = '" + pc.getId() + + "' AND ACTIVITYDEFID = 'obj_c9e5a3144b200001b68cffa01ed0153e' "; + String end_date = DBSql.getString(sql_date); + TaskInstance ta = SDK.getTaskAPI().getInstanceById(taskInd); + String portalUrl = SDK.getPortalAPI().getPortalUrl(); + + String url = portalUrl + "/r/or?cmd=com.yili_process_page&oauthName=oauthLogin&processInstId=" + + pc.getId() + "&taskInstId=" + + taskInd+"&usercode="; + String mobileurl = "https://bpm.yili.com:8088/portal" + + "/r/or?cmd=com.yili_process_page_phone&corpid=wwb0ae23173b140618&appAgentId=1000014&oauthName=wechat&processInstId=" + + pc.getId() + "&taskInstId=" + + taskInd; + + + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + //Timestamp endTime = processExecutionContext.getTaskInstance().getBeginTime(); + //Timestamp endTime = new Timestamp(System.currentTimeMillis()); + + JSONObject jsonObject = new JSONObject(new LinkedHashMap()); + jsonObject.put("action", "read"); + jsonObject.put("title", " " + "" + bo_act_coe_publish1.getString("PROCESS_TITLE") + ""); + jsonObject.put("deptname",SDK.getORGAPI() + .getDepartmentByUser(ta.getTarget()).getName()); + jsonObject.put("dept", SDK.getORGAPI() + .getDepartmentByUser(ta.getTarget()).getNo());// SDK.getORGAPI().getDepartmentByUser(processExecutionContext.getProcessInstance().getCreateUser()).getNo() + String target = ta.getTarget(); + + jsonObject.put("user", target); + // jsonObject.put("user",);//processExecutionContext.getProcessInstance().getCreateUser() + jsonObject.put("date", sdf.format(end_date)); + jsonObject.put("remark", bo_act_coe_publish1.getString("PROCESS_TITLE")); + jsonObject.put("status", "0"); + jsonObject.put("dataid", pc.getId()); + jsonObject.put("pcurl", url); + jsonObject.put("mobileurl", mobileurl); + + int count = 1; + int count2 = 1; + int count3 = 1; + // 发送组织岗位职级 + sendList = getSendList(pc, bo_act_coe_publish1, jsonObject); + ArrayList finalList = new ArrayList(); + System.out.println("titile==============" + pc.getTitle()); + System.out.println("sendList==============" + sendList.toString()); + System.out.println("sendList.size()==============" + sendList.size()); + + List finalLists = new ArrayList<>(); + ProcessInstance boProcessInstance = SDK.getProcessAPI() + .createBOProcessInstance("obj_c14a0187c4d0463baa22752711f65947", "admin", "OA补充发送手动清单"); + + /* for (String oneid : sendList) { + + BO actDataid = SDK.getBOAPI().query("BO_ACT_DATAID").addQuery("USER_ID=", oneid).addQuery("PROCESSID=", pc.getId()).detail(); + + BO actAlreadyDataid = SDK.getBOAPI().query("BO_ACT_ALREADY_DATAID").addQuery("USER_ID=", oneid).addQuery("PROCESSID=", pc.getId()).detail(); + *//*if(actDataid==null && actAlreadyDataid==null){*//* + + BO bo = new BO(); + bo.set("PROCESSTITLE", pc.getTitle()); + bo.set("JSRCODE", oneid); + bo.set("FBJG", "总部企业事务部"); + bo.set("FFRCODE", "10039924"); + bo.set("FBRQ", "2023-07-11"); + bo.set("ZT", "未读"); + String pcurl = "https://bpm.yili.com:8088/portal/r/or?cmd=com.yili_process_page&oauthName=oauthLogin&processInstId=" + pc.getId() + "&taskInstId=69bc4788-071b-41e0-a07c-b28ac6574a78&usercode=" + oneid; + bo.set("PCURL", pcurl); + String wqurl = "https://bpm.yili.com:8088/portal/r/or?cmd=com.yili_process_page_phone&corpid=wwb0ae23173b140618&appAgentId=1000014&oauthName=wechat&processInstId=" + pc.getId() + "&taskInstId=69bc4788-071b-41e0-a07c-b28ac6574a78"; + bo.set("QWURL", wqurl); + SDK.getBOAPI().create("BO_ACT_OA_SUPP_SENDING", bo, boProcessInstance.getId(), ""); + *//*}*//* + }*/ + + ArrayList list = new ArrayList<>(); + + for (String user_id:sendList){ + + BO bo_eu_require_data = SDK.getBOAPI().query("BO_EU_REQUIRE_DATA", true).addQuery("PROCESS_ID = ", cc).addQuery("USER_ID=",user_id).detail(); + if (bo_eu_require_data!=null){ + + }else { + /* BO bo_eu_Read = SDK.getBOAPI().query("BO_ACT_ALREADY_DATAID", true).addQuery("PROCESSID = ", cc).addQuery("USER_ID=",user_id).detail(); + if (bo_eu_Read!=null){ + + }else { + list.add(user_id); + }*/ + list.add(user_id); + } + } + // list.add("10036614"); + // list.add("10056870"); + + new_uid = new_uid.join(",",list); + long startTimes = System.currentTimeMillis(); + String[] users = new_uid.split(","); + System.out.println("new_uid>>>>>>>>>>>>>>"+users.length); + System.out.println("new_uids>>>>>>>>>>>>>>"+users); + int length = 100; + int ys = users.length%length; + /** + * 这个是以300人作为一个发送单位去放到list中并发送待阅数据 + */ + if (ys==0) { + int size = users.length/length; + int flag = 0; + + List lists = new LinkedList(); + + for (int i=0;i>>>>>>>>>>>>>"+list); + }else { + int size = users.length/length; + int flag = 0; + List lists = new LinkedList(); + + for (int i=0;i>>>>>>>>>>>>>"+list); + } + + + /*System.out.println("新list>>>>>>"+list.size()); + for (String user : lists) { + try { + SendOARead(jsonObject, pc, user, "批量推送"); + } catch (Exception e) { // TODO: handle exception +//2023-07-12 14:51:03--job worker-9d60ecf3-d70c-4b15-a271-6cfce754ff25,ijob--sendList.size()==============20393 + } + } + + + long endTimes = System.currentTimeMillis(); + // 存入日志 + createReadLog(pc, jsonObject, sendList, startTime, endTimes); + System.err.println(pc.getTitle() + "推送OA待阅执行完毕====>" + "用时:" + + (endTimes - startTime) / 1000 / 60 + "分钟");*/ + + } + + + + public void course(List list, long startTime, JSONObject jsonObject, ProcessInstance processInstance,TaskInstance taskInstance,ArrayList sendList) throws Exception { + final boolean[] flag = {false}; + // 创建线程来实现为每100人为一个的线程跑待阅 + CountDownLatch countDownLatch = new CountDownLatch(list.size()); + ExecutorService service = Executors.newFixedThreadPool(5); + int m = 0; + for (int i=0;i>>>>>>"+Arrays.asList(list.get(finalI)).size()); + String userIds = ""; + userIds = StringUtils.join(list.get(finalI), ","); + System.out.println("userIDs>>>>>>>>>>>>>>>"+userIds); + /*try { + SendOARead(jsonObject, processInstance, userIds,"批量推送"); + } catch (DocumentException e) { + e.printStackTrace(); + }*/ + /*try { + SendOARead(jsonObject, processInstance, userIds,"批量推送"); + countDownLatch.countDown(); + } catch (DocumentException e) { + e.printStackTrace(); + }*/ + InsertBO(jsonObject, processInstance,taskInstance, userIds,"批量推送"); + countDownLatch.countDown(); + } + }); + m++; + } + countDownLatch.await(); + /*if (countDownLatch.getCount()==0){ + + try { + // 等待所有的任务执行完毕,最多等待1小时 + + List 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 secondUserList = new ArrayList(); + 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 recordFailLists = new ArrayList(); + 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 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() + "'"); + + } catch (Exception e) { + System.out.println("等待中断异常"); + } + } else { + System.out.println("超过等待时间,部分任务未执行完毕"); + }*/ + } + + + public void InsertBO(JSONObject jsonObject, ProcessInstance processInstance,TaskInstance taskInstance, String userIds,String type){ + BO bo = new BO(); + bo.set("PROCESSID",processInstance.getId()); + bo.set("USERIDS",userIds); + SDK.getBOAPI().create("BO_EU_JSIS_DATA",bo,processInstance.getId(),processInstance.getCreateUser()); + + if (userIds.contains(",")){ + String[] split = userIds.split(","); + for (String user_id: + split) { + BO bos = new BO(); + bos.set("PROCESSTITLE", processInstance.getTitle()); + bos.set("JSRCODE", jsonObject.getString("user")); + bos.set("FBJG",jsonObject.getString("deptname")); + bos.set("FFRCODE", jsonObject.getString("dept")); + bos.set("FBRQ", jsonObject.getString("date")); + bos.set("ZT", "未读"); + String pcurl = "https://bpm.yili.com:8088/portal/r/or?cmd=com.yili_process_page&oauthName=oauthLogin&processInstId=" + processInstance.getId() + "&taskInstId="+taskInstance.getId()+"&usercode=" + user_id; + bos.set("PCURL", pcurl); + String wqurl = "https://bpm.yili.com:8088/portal/r/or?cmd=com.yili_process_page_phone&corpid=wwb0ae23173b140618&appAgentId=1000014&oauthName=wechat&processInstId=" + processInstance.getId() + "&taskInstId="+taskInstance.getId()+""; + bos.set("QWURL", wqurl); + SDK.getBOAPI().create("BO_ACT_OA_SUPP_SENDING", bo, processInstance.getId(),processInstance.getCreateUser()); + } + }else { + BO bos = new BO(); + bos.set("PROCESSTITLE", processInstance.getTitle()); + bos.set("JSRCODE", jsonObject.getString("user")); + bos.set("FBJG",jsonObject.getString("deptname")); + bos.set("FFRCODE", jsonObject.getString("dept")); + bos.set("FBRQ", jsonObject.getString("date")); + bos.set("ZT", "未读"); + String pcurl = "https://bpm.yili.com:8088/portal/r/or?cmd=com.yili_process_page&oauthName=oauthLogin&processInstId=" + processInstance.getId() + "&taskInstId="+taskInstance.getId()+"&usercode=" + userIds; + bos.set("PCURL", pcurl); + String wqurl = "https://bpm.yili.com:8088/portal/r/or?cmd=com.yili_process_page_phone&corpid=wwb0ae23173b140618&appAgentId=1000014&oauthName=wechat&processInstId=" + processInstance.getId() + "&taskInstId="+taskInstance.getId()+""; + bos.set("QWURL", wqurl); + SDK.getBOAPI().create("BO_ACT_OA_SUPP_SENDING", bo, processInstance.getId(),processInstance.getCreateUser()); + } + + + } + + + + public void secondSendOARead(JSONObject jsonObject, ProcessInstance processInstance, List 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 = "\n" + + " " + " " + " " + " " + + "" + " " + " " + + " " + ""; + // 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 recordLists = new ArrayList(); + 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 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待阅数据 + * + * @param jsonObject + * @param processInstance + * @param results + * @throws DocumentException + */ + public void SendOARead(JSONObject jsonObject, ProcessInstance processInstance, String userIds,String type) + throws DocumentException { + + + String processInstId = processInstance.getId(); + // System.err.println(processInstance.getTitle() + "开始发送:" + userId); + + /* + * if ("".equals(userId) || UtilString.isEmpty(userId)) { return; } + */ + long start_time = System.currentTimeMillis(); + System.out.println("待阅推送开始时间>>>>>>>>>>>>"+start_time); + BO bo_OA_read = new BO(); + String[] resrt = userIds.split(","); + bo_OA_read.set("FIR_NUMS",resrt.length); + bo_OA_read.set("START_TIME",start_time); + jsonObject.put("userList", userIds); + String xmlStr = "\n" + + " " + " " + " " + " " + + "" + " " + " " + + " " + ""; + // System.out.println("xmlStr>>>>>>>>" + xmlStr); + String readurl = SDK.getAppAPI().getProperty("com.awspaas.user.apps.yili.integration", "readurl"); + SDK.getLogAPI().consoleInfo(xmlStr); + 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"); + long have_time = System.currentTimeMillis(); + System.out.println("接收到返回的待阅ID时间>>>>>>>>>>>>>>>>"+have_time); + bo_OA_read.set("HAVE_TIME",have_time); + System.out.println("接收到返回的待阅耗时时间>>>>>>>>>>>>"+(have_time-start_time)); + bo_OA_read.set("SUM_TIME",(have_time-start_time)); + 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()+"人"); + //批量入库操作 + //加入时间戳 + long set_start_time = System.currentTimeMillis(); + bo_OA_read.set("SET_TIME",set_start_time); + if(resultArray.size()>0){ + List recordLists = new ArrayList(); + 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 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, UserContext.fromUID(processInstance.getCreateUser())); + } + + } + SDK.getBOAPI().create("BO_ACT_DATAID",recordLists, processInstance, UserContext.fromUID(processInstance.getCreateUser())); + + long endTime2 = System.currentTimeMillis(); + System.err.println(processInstance.getTitle() + "批量插入OA待阅数据====>" + "用时:" + + (endTime2 - startTime2) / 1000 + "秒"); + } + long set_end_time = System.currentTimeMillis(); + bo_OA_read.set("SET_END_TIME",set_end_time); + bo_OA_read.set("SET_SUM_TIME",(set_end_time-set_start_time)); + bo_OA_read.set("PROCESS_ID",processInstance.getId()); + SDK.getBOAPI().create("BO_EU_OA_READ_LOG", bo_OA_read, processInstance, UserContext.fromUID(processInstance.getCreateUser())); + if("单个账号推送".equals(type)) { + DBSql.update("UPDATE BO_EU_READ_COUNT SET RESULT = '已重新推送' WHERE PROCESSID = '"+processInstId+"' AND NAME = '"+resrt+"'"); + } + } else { + List idList = Arrays.asList(resrt); + BO bo = null; + List recordFailLists = new ArrayList(); + if(idList.size()>0){ + for (String userId : idList) { + System.out.println(processInstance.getTitle() + "待阅推送失败:" + userId); + try { + bo= new BO(); + bo.set("TITLE", processInstance.getTitle()); + bo.set("NAME", userId); + bo.set("TYPE", type); + bo.set("RESULT", "待处理"); + bo.set("PROCESSID", processInstId); + bo.set("DEPNAME", SDK.getORGAPI().getUser(userId).getDepartmentId()); + //SDK.getBOAPI().create("BO_EU_READ_COUNT", bo, processInstance.getId(), processInstance.getCreateUser()); + recordFailLists.add(bo); + } catch (Exception e) { + bo= new BO(); + bo.set("TITLE", processInstance.getTitle()); + bo.set("NAME", userIds); + bo.set("TYPE", type); + bo.set("RESULT", "待处理"); + bo.set("PROCESSID", processInstId); + bo.set("DEPNAME", SDK.getORGAPI().getUser(userIds).getDepartmentId()); + //SDK.getBOAPI().create("BO_EU_READ_COUNT", bo, processInstance.getId(), processInstance.getCreateUser()); + recordFailLists.add(bo); + } + } + System.out.println("recordFailLists========="+recordFailLists.size()); + SDK.getBOAPI().create("BO_EU_READ_COUNT", recordFailLists, processInstance, UserContext.fromUID(processInstance.getCreateUser())); + } + + + + + + + } + + } + + public ArrayList getSendList(ProcessInstance instanceById, BO bo_act_coe_publish1, JSONObject jsonObject) { + String sendType = bo_act_coe_publish1.getString("SEND_SCOP"); + String org = bo_act_coe_publish1.getString("SEND_SCOPE_ORG"); + String post = bo_act_coe_publish1.getString("SEND_SCOPE_POST"); + String level = bo_act_coe_publish1.getString("SEND_SCOPE_LEVEL"); + ArrayList userList = new ArrayList<>(); + if ("1".equals(sendType)) { + //System.err.println("发送全集团=====>" + instanceById.getTitle()); + userList = sendOrg(org, userList, instanceById, bo_act_coe_publish1, jsonObject, sendType); + + } else { + /** + * 先组织和职级取交集,然后再和岗位取并集 + */ + if (UtilString.isNotEmpty(org) && UtilString.isNotEmpty(post) && UtilString.isNotEmpty(level)) { + //System.err.println("发送组织/岗位/职级=====>" + instanceById.getTitle()); + ArrayList sendOrgList = sendOrg(org, userList, instanceById, bo_act_coe_publish1, jsonObject, + sendType); + ArrayList sendLevel = sendLevel(level, sendOrgList, instanceById, bo_act_coe_publish1, jsonObject); + userList = sendPost(post, sendLevel, instanceById, bo_act_coe_publish1, + jsonObject); + } + // 如果职级为空,组织/岗位取并集 + if (UtilString.isNotEmpty(org) && UtilString.isNotEmpty(post) && UtilString.isEmpty(level)) { + //System.err.println("发送组织/岗位=====>" + instanceById.getTitle()); + ArrayList sendOrgList = sendOrg(org, userList, instanceById, bo_act_coe_publish1, jsonObject, + sendType); + userList = sendPost(post, sendOrgList, instanceById, bo_act_coe_publish1, jsonObject); + } + // 如果岗位为空,组织/职级取交集 + if (UtilString.isNotEmpty(org) && UtilString.isEmpty(post) && UtilString.isNotEmpty(level)) { + //System.err.println("发送组织/职级=====>" + instanceById.getTitle()); + ArrayList sendOrgList = sendOrg(org, userList, instanceById, bo_act_coe_publish1, jsonObject, + sendType); + userList = sendLevel(level, sendOrgList, instanceById, bo_act_coe_publish1, jsonObject); + } + + /** + * 组织为空 岗位和职级取并集 + */ + if (UtilString.isEmpty(org) && UtilString.isNotEmpty(post) && UtilString.isNotEmpty(level)) { + //System.err.println("发送岗位/职级=====>" + instanceById.getTitle()); + ArrayList sendLevel2 = sendLevel2(level, userList, instanceById, bo_act_coe_publish1, jsonObject); + userList = sendPost(post, sendLevel2, instanceById, bo_act_coe_publish1, + jsonObject); + } + // 如果只有组织不为空 + if (UtilString.isNotEmpty(org) && UtilString.isEmpty(post) && UtilString.isEmpty(level)) { + //System.err.println("发送组织=====>" + instanceById.getTitle()); + userList = sendOrg(org, userList, instanceById, bo_act_coe_publish1, jsonObject, sendType); + } + // 如果只有岗位不为空 + if (UtilString.isEmpty(org) && UtilString.isNotEmpty(post) && UtilString.isEmpty(level)) { + //System.err.println("发送岗位=====>" + instanceById.getTitle()); + userList = sendPost(post, userList, instanceById, bo_act_coe_publish1, jsonObject); + } + // 如果只有职级不为空 + if (UtilString.isEmpty(org) && UtilString.isEmpty(post) && UtilString.isNotEmpty(level)) { + //System.err.println("发送职级=====>" + instanceById.getTitle()); + userList = sendLevel2(level, userList, instanceById, bo_act_coe_publish1, jsonObject); + } + + } + + return userList; + + } + + + // 只发送职级 + public ArrayList sendLevel2(String level, ArrayList userList, ProcessInstance instanceById, + BO bo_act_coe_publish1, JSONObject jsonObject) { + String processid = instanceById.getId(); + ArrayList userList_level = new ArrayList(); + // 获取职级 + if (StringUtils.isNotEmpty(level)) { + String ranks[] = level.split(","); + String rankss = ""; + if (ranks.length == 1) { + // DBSql.getMap("select USERID from ORGUSER WHERE POSITION_NO IN "); + rankss = "'" + ranks[0] + "'"; + } else { + rankss = "'" + StringUtils.join(ranks, "','") + "'"; + } + // 取交集 + String sql2 = "select * from ORGUSER where EXT2 in (" + rankss + ") and userno is not null"; + List maps2 = DBSql.getMaps(sql2); + for (RowMap rowMap : maps2) { + String userId = rowMap.getString("USERID"); + boolean closed = SDK.getORGAPI().getUser(userId).isClosed(); + if (!closed) { + userList_level.add(userId); + } + } + } + return userList_level; + } + + + // 发送岗位 + public ArrayList sendPost(String post, ArrayList userList, ProcessInstance instanceById, + BO bo_act_coe_publish1, JSONObject jsonObject) { + String processid = instanceById.getId(); + // 获取岗位 + if (StringUtils.isNotEmpty(post)) { + String posts[] = post.split(","); + // 取并集 + String postss = ""; + if (posts.length == 1) { + // DBSql.getMap("select USERID from ORGUSER WHERE POSITION_NO IN "); + postss = "'" + posts[0] + "'"; + } else { + postss = "'" + StringUtils.join(posts, "','") + "'"; + } + String sql = "select * from ORGUSER where POSITION_NO in (" + postss + ") and userno is not null"; + List maps1 = DBSql.getMaps(sql); + for (RowMap rowMap : maps1) { + String userId = rowMap.getString("USERID"); + if (!userList.contains(userId)) { + boolean closed = SDK.getORGAPI().getUser(userId).isClosed(); + if (!closed) { + userList.add(userId); + } + } + + } + } + + return userList; + } + + + // 发送组织 + public ArrayList sendOrg(String org, ArrayList userList, ProcessInstance instanceById, + BO bo_act_coe_publish1, JSONObject jsonObject, String sendType) { + String processid = instanceById.getId(); + // 获取组织 + if (StringUtils.isNotEmpty(org) || "1".equals(sendType)) { + long startTime = System.currentTimeMillis(); + userList = getUser(jsonObject, org, sendType, processid); + long endTimes = System.currentTimeMillis(); + // System.out.println(instanceById.getTitle()+"_根据部门获取人员用时===>"+(endTimes-startTime)/1000); + } + + return userList; + } + + + // 发送职级 + public ArrayList sendLevel(String level, ArrayList userList, ProcessInstance instanceById, + BO bo_act_coe_publish1, JSONObject jsonObject) { + String processid = instanceById.getId(); + ArrayList userList_level = new ArrayList(); + // 获取职级 + if (StringUtils.isNotEmpty(level)) { + String ranks[] = level.split(","); + String rankss = ""; + if (ranks.length == 1) { + // DBSql.getMap("select USERID from ORGUSER WHERE POSITION_NO IN "); + rankss = "'" + ranks[0] + "'"; + } else { + rankss = "'" + StringUtils.join(ranks, "','") + "'"; + } + // 取交集 + String sql2 = "select * from ORGUSER where EXT2 in (" + rankss + ") and userno is not null"; + List maps2 = DBSql.getMaps(sql2); + for (RowMap rowMap : maps2) { + String userId = rowMap.getString("USERID"); + if (userList.contains(userId)) { + boolean closed = SDK.getORGAPI().getUser(userId).isClosed(); + if (!closed) { + userList_level.add(userId); + } + } + + } + } + + return userList_level; + } + + + /** + * 根据部门id获取当前部门以及下级部门的人员信息 + * + * @param processid + * @return + */ + + public ArrayList getUser(JSONObject jsonObject, String depIds, String sendType, String processid) { + ArrayList arr = new ArrayList(); + ArrayList arr_test = new ArrayList(); + // 全集团 + if ("1".equals(sendType)) { + List departmentsByCompanyId = SDK.getORGAPI().getDepartmentsByCompanyId(1, + "8911e732-b42a-4556-853f-ad32761bcbee"); + for (DepartmentModel departmentModel : departmentsByCompanyId) { + String id = departmentModel.getId(); + // 查询未注销的部门并且去掉系统部门 + if (!departmentModel.isClosed() && !"5bc3a2dc-3bd2-4376-bcc3-5612e28e55fe".equals(id) + && !"e79281b1-2f81-4895-b30e-9f96e9ad0e2c".equals(id) + && !"65048aee-157f-49f2-a2dc-5903dd26f519".equals(id)) { + getUserList(jsonObject, arr_test, arr, id, processid); + + } + } + } else { + if (UtilString.isNotEmpty(depIds)) { + String[] split = depIds.split(","); + for (String depId : split) { + getUserList(jsonObject, arr_test, arr, depId, processid); + } + } + } + + // System.err.println(SDK.getProcessAPI().getInstanceById(processid) + + // "_得到的总人数为:" + arr_test.size()); + // System.err.println(SDK.getProcessAPI().getInstanceById(processid) + + // "_得到的过滤后的人数为:" + arr.size()); + return arr; + } + + + public void getUserList(JSONObject jsonObject, ArrayList arr_test, ArrayList arr, + String departmentId, String processid) { + // 获取当前部门下人员 + List userModelList = SDK.getORGAPI().getAllUsersByDepartment(departmentId); + for (UserModel userModel : userModelList) { + if (!userModel.isClosed()) { + String uid = userModel.getUID(); + if (!arr.contains(uid)) { + if (!"10033643".equals(uid)) { + // System.err.println("发送人员======>" + uid); } + arr.add(uid); + + } + /* + * RowMap map = DBSql.getMap("SELECT ID FROM BO_ACT_DATAID WHERE PROCESSID = '" + * + processid + "' AND USER_ID = '" + uid + "'"); if (map == null) { + * //System.err.println("发送人员======>" + uid); } + */ + } + } + } + // 获取当前部门的子部门人员 + DepartmentModel departmentById = SDK.getORGAPI().getDepartmentById(departmentId); + if (departmentById.isExistSubModelOfCache()) { + getSubDepartments(jsonObject, arr_test, arr, departmentById, processid); + } + + } + + + // 获取子部门人员 + public void getSubDepartments(JSONObject jsonObject, ArrayList arr_test, ArrayList arr, + DepartmentModel departmentById, String processid) { + if (!departmentById.isClosed()) { + List subDepartments = SDK.getORGAPI().getSubDepartments(departmentById.getId()); + for (DepartmentModel departmentModel : subDepartments) { + if (!departmentModel.isClosed()) { + String id = departmentModel.getId(); + List userModelList = SDK.getORGAPI().getAllUsersByDepartment(id); + for (UserModel userModel : userModelList) { + if (!userModel.isClosed()) { + String uid = userModel.getUID(); + if (!arr.contains(uid)) { + if (!"10033643".equals(uid)) { + // System.err.println("发送人员======>" + uid); } + arr.add(uid); + } + // System.err.println(SDK.getProcessAPI().getInstanceById(processid) + + // "_发送人员======>" + uid); + + } + } + } + // 递归获取子部门下的子部门 + if (SDK.getORGAPI().isExistSubDepartment(id)) { + getSubDepartments(jsonObject, arr_test, arr, SDK.getORGAPI().getDepartmentById(id), processid); + } + + } + + } + } + } + + + /** + * 创建待阅日志 + * + * @param jsonObject + * @param startTime + */ + + public void createReadLog(ProcessInstance pc, JSONObject jsonObject, + ArrayList arr, long startTime, long endTimes) { + BO bo_Read_log = new BO(); + String processInstId = pc.getId(); + bo_Read_log.set("USREID", pc.getCreateUser()); + bo_Read_log.set("DEPID", pc.getCreateUserDeptId()); + bo_Read_log.set("BUNAME", UserContext.fromUID(pc.getCreateUser()).getUserModel().getExt4()); + bo_Read_log.set("TITLE", jsonObject.get("title")); + bo_Read_log.set("PROCESSID", processInstId); + bo_Read_log.set("SENDNUM", arr.size()); + String sqly = "SELECT ID FROM BO_ACT_DATAID WHERE PROCESSID = '" + processInstId + "' AND SENDTYPE = '1'"; + List mapsy = DBSql.getMaps(sqly); + String alsqly = "SELECT ID FROM BO_ACT_ALREADY_DATAID WHERE PROCESSID = '" + processInstId + "' AND SENDTYPE = '1'"; + List almapsy = DBSql.getMaps(alsqly); + bo_Read_log.set("SENDNUMSJ", mapsy.size() + almapsy.size()); + + BO bo_act_coe_publishs = SDK.getBOAPI().query("BO_ACT_COE_PUBLISH", true).addQuery("BINDID=", processInstId) + .addQuery("OPTIONTYPE IS NOT NULL", null).detail(); + String send_scop = bo_act_coe_publishs.getString("SEND_SCOP"); + bo_Read_log.set("SEND_SCOP", send_scop); + String SEND_SCOPE_ORG = bo_act_coe_publishs.getString("SEND_SCOPE_ORG"); + if (UtilString.isNotEmpty(SEND_SCOPE_ORG)) { + String[] resulr = SEND_SCOPE_ORG.split(","); + bo_Read_log.set("SEND_SCOPE_ORGNUM", resulr.length); + } + String SEND_SCOPE_POST = bo_act_coe_publishs.getString("SEND_SCOPE_POST"); + if (UtilString.isNotEmpty(SEND_SCOPE_POST)) { + String[] resulr = SEND_SCOPE_POST.split(","); + bo_Read_log.set("SEND_SCOPE_POST_NUM", resulr.length); + } + String SEND_SCOPE_LEVEL = bo_act_coe_publishs.getString("SEND_SCOPE_LEVEL"); + if (UtilString.isNotEmpty(SEND_SCOPE_LEVEL)) { + String[] resulr = SEND_SCOPE_LEVEL.split(","); + bo_Read_log.set("SEND_SCOPE_LEVEL_NUM", resulr.length); + } + + bo_Read_log.set("STARTTIMES", startTime); + bo_Read_log.set("ENDTIMES", endTimes); + long time = endTimes - startTime; + long diffSeconds = time / 1000 % 60; + long diffMinutes = time / (60 * 1000) % 60; + long diffHours = time / (60 * 60 * 1000) % 24; + long diffDays = time / (24 * 60 * 60 * 1000); + String remainTime = ""; + if (diffDays != 0 && diffHours != 0) { + remainTime = diffDays + "天" + diffHours + "小时" + diffMinutes + "分钟" + diffSeconds + "秒"; + } else if (diffDays == 0 && diffHours != 0 && diffMinutes != 0) { + remainTime = diffHours + "小时" + diffMinutes + "分钟" + diffSeconds + "秒"; + } else if (diffDays == 0 && diffHours == 0 && diffMinutes != 0) { + remainTime = diffMinutes + "分钟" + diffSeconds + "秒"; + } else if (diffDays == 0 && diffHours == 0 && diffMinutes == 0) { + remainTime = diffSeconds + "秒"; + } + bo_Read_log.set("TIMECOUNT", remainTime); + // 文件发布成功回执流程 + ProcessInstance processInst = SDK.getProcessAPI().createProcessInstance("obj_b4700f89a7a144c086d047de0cfe9531", + "admin", jsonObject.get("title") + "成功发布回执单"); + SDK.getBOAPI().create("BO_EU_PAL_PULBISH_SUCCESS", bo_Read_log, processInst, UserContext.fromUID("admin")); + TaskInstance taskInst = SDK.getProcessAPI().start(processInst).fetchActiveTasks().get(0); + SDK.getTaskAPI().completeTask(taskInst.getId(), "admin"); + + } +}