diff --git a/com.awspaas.user.apps.app20250109170254/src/com/awspaas/user/apps/app20250109170254/job/UpdateOAJob.java b/com.awspaas.user.apps.app20250109170254/src/com/awspaas/user/apps/app20250109170254/job/UpdateOAJob.java new file mode 100644 index 00000000..03e1937d --- /dev/null +++ b/com.awspaas.user.apps.app20250109170254/src/com/awspaas/user/apps/app20250109170254/job/UpdateOAJob.java @@ -0,0 +1,317 @@ +package com.awspaas.user.apps.app20250109170254.job; + +import com.actionsoft.bpms.bo.engine.BO; +import com.actionsoft.bpms.bpmn.engine.ProcessAPIManager; +import com.actionsoft.bpms.bpmn.engine.model.run.TaskCommentModel; +import com.actionsoft.bpms.bpmn.engine.model.run.delegate.HistoryTaskInstance; +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.login.constant.LoginConst; +import com.actionsoft.bpms.commons.mvc.view.ResponseObject; +import com.actionsoft.bpms.schedule.IJob; +import com.actionsoft.bpms.server.SSOUtil; +import com.actionsoft.bpms.server.UserContext; +import com.actionsoft.sdk.local.SDK; +import com.actionsoft.sdk.local.api.AppAPI; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.awspaas.user.apps.app20250109170254.utils.HttpClientUtils; +import com.awspaas.user.apps.app20250109170254.utils.XmlDatasUtil; +import org.apache.commons.lang3.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 javax.xml.soap.SOAPException; +import java.io.IOException; +import java.text.SimpleDateFormat; +import java.util.*; + +public class UpdateOAJob implements IJob { + @Override + public void execute(JobExecutionContext jobExecutionContext) { + + String jobParameter = SDK.getJobAPI().getJobParameter(jobExecutionContext); + + List list = SDK.getProcessAPI().query().addQuery("PROCESSDEFID IN ('"+jobParameter+"')", null).list(); + System.out.println("list=========="+list.size()); + for (ProcessInstance processInstance: + list) { + List list_history = SDK.getHistoryTaskQueryAPI().processInstId(processInstance.getId()).list(); + for (HistoryTaskInstance historyTaskInstance: + list_history) { + updatePending2(historyTaskInstance,processInstance); + } + + } + } + + private String getActionName(TaskInstance taskInstance) { + if (null == taskInstance) { + return ""; + } + String actionName = ""; + Iterator iterator = null; + if (StringUtils.isNotEmpty(taskInstance.getProcessInstId())){ + iterator= ProcessAPIManager.getInstance() + .getComments(taskInstance.getProcessInstId()).iterator(); + + + TaskCommentModel next; + + while (iterator.hasNext()) { + if ((next = iterator.next()).getTaskInstId().equals(taskInstance.getId())) { + actionName = next.getActionName(); + } + } + } + return actionName; + } + + public void updatePending2(TaskInstance taskInstance, ProcessInstance pec) { + try { + if("admin".equals(taskInstance.getTarget())) { + return; + } + XmlDatasUtil xmlDatasUtil = new XmlDatasUtil(); + xmlDatasUtil.setExternal_system_ID("LCZD"); + + xmlDatasUtil.setOther_system_to_do_ID(taskInstance.getId()); + //System.out.println("pec.getProcessInstance()>>>>>>>>"+pec.getProcessInstance()); + if(pec!=null){ + String actionName = getActionName(taskInstance); + if (actionName.equals("传阅")){ + BO bo_act_coe_publish = SDK.getBOAPI().query("BO_ACT_COE_PUBLISH", true).addQuery("BINDID=", pec.getId()).addQuery("PROCESS_TITLE is not null",null).detail(); + if (bo_act_coe_publish!=null){ + String title = bo_act_coe_publish.getString("PROCESS_TITLE"); + if(title.contains("&")) { + xmlDatasUtil.setProcess_title(" 您有一条传阅流程【"+title.replace("&", "-")+"】,点击进行处理"); + }else { + xmlDatasUtil.setProcess_title(" 您有一条传阅流程【"+title+"】,点击进行处理"); + } + }else { + xmlDatasUtil.setProcess_title(" 您有一条传阅流程【"+pec.getTitle()+"】,点击进行处理"); + } + }else { + BO bo_act_coe_publish = SDK.getBOAPI().query("BO_ACT_COE_PUBLISH", true).addQuery("BINDID=", pec.getId()).addQuery("PROCESS_TITLE is not null",null).detail(); + if (bo_act_coe_publish!=null){ + String title = bo_act_coe_publish.getString("PROCESS_TITLE"); + if(title.contains("&")) { + xmlDatasUtil.setProcess_title(" 您有一条待办流程【"+title.replace("&", "-")+"】,点击进行处理"); + }else { + xmlDatasUtil.setProcess_title(" 您有一条待办流程【"+title+"】,点击进行处理"); + } + }else { + xmlDatasUtil.setProcess_title(" 您有一条待办流程【"+pec.getTitle()+"】,点击进行处理"); + } + } + }else { + xmlDatasUtil.setProcess_title(" 您有一条发布流程被作废,点击进行处理"); + } + + //http://localhost:8089/portal/r/or?cmd=com.yili_form_page_open&processInstId=3505e654-9217-41cd-a31d-4971846b3219&taskInstId=8a71d75e-3ee0-43a2-a226-ecb01419319c&oauthName=oauthLogin&token=admin + String portalUrl = SDK.getPortalAPI().getPortalUrl(); + if (portalUrl.equals("http://10.114.11.135:8088/portal")){ + portalUrl = "https://bpm.yili.com:8088/portal/"; + } + if (pec!=null){ + xmlDatasUtil.setPcurl("https://bpm.yili.com:8088/portal"+"/r/or?cmd=com.yili_form_page_open&oauthName=oauthLogin&processInstId="+pec.getId()+"&taskInstId="+taskInstance.getId()+"&openState="+taskInstance.getState()); + xmlDatasUtil.setMobileurl("https://bpm.yili.com:8088/portal"+"/r/or?cmd=com.yili_form_page_open&corpid=wwb0ae23173b140618&appAgentId=1000014&oauthName=wechat&processInstId="+pec.getId()+"&taskInstId="+taskInstance.getId()+"&openState="+taskInstance.getState()); + }else { + xmlDatasUtil.setPcurl("https://bpm.yili.com:8088/portal"+"/r/or?cmd=CLIENT_BPM_FORM_TRACK_OPEN&oauthName=oauthLogin&processInstId="+taskInstance.getProcessInstId()+"&sourceApp=prm"); + xmlDatasUtil.setMobileurl("https://bpm.yili.com:8088/portal"+"/r/or?cmd=CLIENT_BPM_FORM_TRACK_OPEN&corpid=wwb0ae23173b140618&appAgentId=1000014&oauthName=wechat&processInstId="+taskInstance.getProcessInstId()+"&sourceApp=prm"); + } + + String target = taskInstance.getTarget(); + + //System.out.println("当前账户======》》》》"+target); + BO bo_eu_oa_reson = SDK.getBOAPI().query("BO_EU_OA_RESON", true).addQuery("WORKCODE=" , target).detail(); + //System.out.println("bo>>>>>>>>>>>>>>"+bo_eu_oa_reson); + if (bo_eu_oa_reson!=null){ + xmlDatasUtil.setTo_do_login_account(bo_eu_oa_reson.getString("LOGINID")); + } + SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//定义格式,不显示毫秒 + if (taskInstance.getBeginTime()!=null){ + String str = df.format(taskInstance.getBeginTime()); + String substring = str.substring(str.indexOf(" "), str.length()); + xmlDatasUtil.setTo_do_creation_time(substring); + xmlDatasUtil.setTo_do_completion_time(df.format(taskInstance.getBeginTime()).substring(df.format(taskInstance.getBeginTime()).indexOf(" "), df.format(taskInstance.getBeginTime()).length())); + xmlDatasUtil.setCreatedate(str.substring(0, str.indexOf(" "))); + xmlDatasUtil.setDonedate(df.format(taskInstance.getBeginTime()).substring(0, df.format(taskInstance.getBeginTime()).indexOf(" "))); + }else { + String str = df.format(new Date()); + String substring = str.substring(str.indexOf(" "), str.length()); + xmlDatasUtil.setTo_do_creation_time(substring); + xmlDatasUtil.setTo_do_completion_time(df.format(new Date()).substring(df.format(new Date()).indexOf(" "), df.format(new Date()).length())); + xmlDatasUtil.setCreatedate(str.substring(0, str.indexOf(" "))); + xmlDatasUtil.setDonedate(df.format(new Date()).substring(0, df.format(new Date()).indexOf(" "))); + } + + + //0待办,1已办 + xmlDatasUtil.setTo_do_status("1"); + //0:未读 -2:已读 + xmlDatasUtil.setViewtype("-2"); + //0:未归档 1:已归档 + xmlDatasUtil.setCurrentnodetype("1"); + + + xmlDatasUtil.setTo_do_official_type("0"); + String der = ""; + if (taskInstance.getReadTime()==null){ + der= df.format(new Date()); + }else { + der= df.format(taskInstance.getReadTime()); + } + + xmlDatasUtil.setReceivedate(der.substring(0, der.indexOf(" "))); + xmlDatasUtil.setReceivetime(der.substring(der.indexOf(" "),der.length())); + xmlDatasUtil.setCurrentnodetype("1"); + if (pec!=null) { + xmlDatasUtil.setRequestcode(pec.getId()); + xmlDatasUtil.setCurrentnodename(SDK.getRepositoryAPI().getProcessNode(pec.getProcessDefId(),taskInstance.getActivityDefId()).getName()); + // 调用App + String sourceAppId = pec.getAppId(); + // aslp服务地址 + String aslp = "aslp://com.actionsoft.apps.processtrends/processNodeInfoASLP"; + // 参数定义列表 + Map params = new HashMap(); + //流程实例id,必填 + params.put("processInstId", pec.getId()); + //,必填 + if (pec!=null){ + if(SDK.getORGAPI().getUser(pec.getCreateUser()).isClosed()==false){ + String sessionId = new SSOUtil().registerClientSessionNoPassword(pec.getCreateUser(), LoginConst.DEFAULT_LANG, "localhost", LoginConst.DEVICE_PC); + params.put("sid", sessionId); + } + }else { + if(SDK.getORGAPI().getUser(taskInstance.getTarget()).isClosed()==false) { + String sessionId = new SSOUtil().registerClientSessionNoPassword(taskInstance.getTarget(), LoginConst.DEFAULT_LANG, "127.0.0.1", LoginConst.DEVICE_PC); + params.put("sid", sessionId); + } + } + + AppAPI appAPI = SDK.getAppAPI(); + + + //流程节点数据 + ResponseObject ro = appAPI.callASLP(appAPI.getAppContext(sourceAppId), aslp, params); + String username = ""; + String userid = ""; + if (ro.isOk()){ + String data = ro.getData().toString(); + JSONObject jsonObject = JSONObject.parseObject(data); + JSONArray jsonArray = JSONArray.parseArray(jsonObject.getString("processBudgetModelList")); + if (!jsonArray.isEmpty()){ + for(int i=0;i"+pec.getTitle()+"===>"+"状态码============》》》》》》》》》》》"+s); + Document document = null; + try { + document = DocumentHelper.parseText(s); + } catch (DocumentException e) { + e.printStackTrace(); + } + Element rootElement = document.getRootElement(); + //System.out.println("rootElement>>>>>>"+rootElement); + Element result = rootElement.element("Body").element("InsertTodoCominfoResponse").element("out"); + String text = result.getText(); + document = DocumentHelper.parseText(text); + Element rootElement2 = document.getRootElement(); + Element statusElement = rootElement2.element("result"); + Element messageElement = rootElement2.element("message"); + String status = statusElement.getData().toString(); + String message = messageElement.getData().toString(); + if (status.equals("success")){ + //System.out.println("更新待办成功===>"+pec.getProcessInstance().getTitle()+"===>"+taskInstance.getTarget()+"====>"+status+"===>"+message); + }else { + System.out.println("更新待办失败===>"+pec.getTitle()+"===>"+taskInstance.getTarget()+"====>"+status+"===>"+message); + } + + if (s.contains("success")){ + //System.out.println("发送待办任务完成,请去OA系统上查看是否传输完成"); + }else { + //System.out.println("发送待办任务失败,请联系管理员查看是否出现错误"); + //System.out.println("错误提示>>>>>>>>>>>>"+s); + BO bo_eu_faid_data = SDK.getBOAPI().query("BO_EU_FAID_DATA").addQuery("TASK_ID=", taskInstance.getId()).detail(); + if (bo_eu_faid_data==null){ + ProcessInstance processInstance = SDK.getProcessAPI().createProcessInstance("obj_ef1918ca1f9c46948f56bd5f77f4e646", "admin", "admin" + "失败更新待办"); + BO bo_faid = new BO(); + bo_faid.set("CHANGED","2"); + bo_faid.set("TASK_ID",taskInstance.getId()); + if (pec!=null){ + bo_faid.set("PROCESS_ID",pec.getId()); + } + UserContext userContext = UserContext.fromUID("admin"); + SDK.getBOAPI().create("BO_EU_FAID_DATA",bo_faid,processInstance,userContext); + SDK.getProcessAPI().start(processInstance); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + + } +}