From 28849309cb2221d666d2424eb99f3ada5afac3be Mon Sep 17 00:00:00 2001 From: Mr-wang Date: Thu, 24 Aug 2023 10:55:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A8=E9=80=81EHSQ=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../coe/pal/datamigration/SendEHSQJob.java | 414 ++++++++++++++++++ 1 file changed, 414 insertions(+) create mode 100644 com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/SendEHSQJob.java diff --git a/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/SendEHSQJob.java b/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/SendEHSQJob.java new file mode 100644 index 00000000..27b1ef55 --- /dev/null +++ b/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/SendEHSQJob.java @@ -0,0 +1,414 @@ +package com.actionsoft.apps.coe.pal.datamigration; + +import com.actionsoft.apps.coe.pal.pal.output.dao.OutputTask; +import com.actionsoft.apps.coe.pal.pal.output.model.OutputTaskModel; +import com.actionsoft.apps.coe.pal.pal.repository.cache.PALRepositoryCache; +import com.actionsoft.apps.coe.pal.pal.repository.model.PALRepositoryModel; +import com.actionsoft.apps.coe.pal.publisher.pubEvent.AesUtil; +import com.actionsoft.apps.coe.pal.publisher.pubEvent.DownloadUtil; +import com.actionsoft.apps.coe.pal.publisher.pubEvent.HttpUtil; +import com.actionsoft.bpms.bo.engine.BO; +import com.actionsoft.bpms.bpmn.engine.core.delegate.ProcessExecutionContext; +import com.actionsoft.bpms.bpmn.engine.model.run.delegate.ProcessInstance; +import com.actionsoft.bpms.commons.database.RowMap; +import com.actionsoft.bpms.commons.login.constant.LoginConst; +import com.actionsoft.bpms.org.model.DepartmentModel; +import com.actionsoft.bpms.schedule.IJob; +import com.actionsoft.bpms.server.SSOUtil; +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.JSONArray; +import com.alibaba.fastjson.JSONObject; +import org.apache.commons.lang.StringUtils; +import org.quartz.JobExecutionContext; +import org.quartz.JobExecutionException; + +import java.sql.Connection; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Set; + +public class SendEHSQJob implements IJob{ + @Override + public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException { + String isSendEHSQ = SDK.getAppAPI().getProperty("com.actionsoft.apps.coe.pal.publisher", "isSendEHSQ"); + Connection open = DBSql.open(); + String jobParameter = SDK.getJobAPI().getJobParameter(jobExecutionContext); + ProcessInstance processInstance = SDK.getProcessAPI().getInstanceById(jobParameter); + /** + * 推送到EHSQ + */ + List bo_act_coe_publish_n = SDK.getBOAPI().query("BO_ACT_COE_PUBLISH_N", true).connection(open) + .addQuery("BINDID=", processInstance.getId()).list(); + List bo_act_coe_publish_c = SDK.getBOAPI().query("BO_ACT_COE_PUBLISH_C", true).connection(open) + .addQuery("BINDID=", processInstance.getId()).list(); + boolean sendEhqs = true; + String depId = UserContext.fromUID(processInstance.getCreateUser()).getDepartmentModel().getId(); + //获取EHSQ配置表判断是否发送 + String sql = "SELECT * FROM BO_ACT_ACT_ESQ_SEND"; + List maps = DBSql.getMaps(open,sql); + for (RowMap rowMap : maps) { + String dempet = rowMap.getString("DEMPET"); + String issend = rowMap.getString("ISSEND"); + DepartmentModel departmentById = SDK.getORGAPI().getDepartmentById(dempet); + if(departmentById!=null) { + String departemenId = departmentById.getId(); + if(departemenId.equals(depId)&&"是".equals(issend)) { + sendEhqs = true; + } /* + * else { List subDepartments = + * SDK.getORGAPI().getSubDepartments(departmentById.getId()); for + * (DepartmentModel departmentModel : subDepartments) { String subDeartmentId = + * departmentModel.getId(); if(subDeartmentId.equals(depId)&&"是".equals(issend)) + * { sendEhqs = true; } } + * + * } + */ + } + } + if(!sendEhqs) { + System.err.println("本次发文不推送EHSQ====>"+processInstance.getTitle()); + } + if ("true".equals(isSendEHSQ)&&sendEhqs) { + try { + // 推送EHSQ + if(bo_act_coe_publish_n.size()>0) { + sendEHSQ(processInstance, bo_act_coe_publish_n); + } + // 更新EHSQ + if(bo_act_coe_publish_c.size()>0) { + updateEHSQ(processInstance, bo_act_coe_publish_c); + } + } catch (Exception e) { + // TODO: handle exception + } + } + } + public void sendEHSQ(ProcessInstance processInstance, List bo_act_coe_publish_n) { + for (BO bo : bo_act_coe_publish_n) { + DownloadUtil downloadUtil = new DownloadUtil(); + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); + JSONArray jsonArray_EHSQ = new JSONArray(); + JSONObject jsonObject_ehsq = new JSONObject(new LinkedHashMap<>()); + OutputTaskModel model = new OutputTask().getTaskReportById(bo.getString("TASKID")); + String wsId = model.getWsId(); + String publishfileid = bo.getString("PUBLISHFILEID"); + LinkedHashMap downloadurl = downloadUtil.outputReportDownload( + UserContext.fromUID(processInstance.getCreateUser()), + bo.getString("TASKID"), publishfileid); + jsonObject_ehsq.put("fileid", bo.getString("TASKID")); + String plName = bo.getString("PUBLISHFILENAME"); + jsonObject_ehsq.put("filename", bo.getString("PUBLISHFILENAME")); + String plNumer = bo.getString("PUBLISH_NUMBER"); + jsonObject_ehsq.put("filecode",bo.getString("PUBLISH_NUMBER")); + //jsonObject_ehsq.put("filecode", "123456"); + String sql_n = "select * from APP_ACT_COE_PAL_REPOSITORY where id = '" + publishfileid + "'"; + RowMap map = DBSql.getMap(sql_n); + PALRepositoryModel palRepositoryModel = PALRepositoryCache.getCache().get(publishfileid); + jsonObject_ehsq.put("version", "V"+palRepositoryModel.getVersion()+""); + BO byProcess = SDK.getBOAPI().getByProcess("BO_ACT_COE_PUBLISH", processInstance.getId()); + String cdeDate = byProcess.getString("CHOICEEFFECTIVEDATE"); + if("1".equals(cdeDate)) { + jsonObject_ehsq.put("releasedate", byProcess.getString("EFFECTIVEDATE")); + jsonObject_ehsq.put("effectivedate", byProcess.getString("EFFECTIVEDATE")); + }else { + jsonObject_ehsq.put("releasedate", simpleDateFormat.format(new Date())); + jsonObject_ehsq.put("effectivedate", simpleDateFormat.format(new Date())); + } + jsonObject_ehsq.put("authorcode", processInstance.getCreateUser()); // jsonObject_ehsq.put("authorcode","00116465"); + jsonObject_ehsq.put("authorname", + UserContext.fromUID(processInstance.getCreateUser()).getUserName()); + // jsonObject_ehsq.put("authorname","毛鹏程"); + jsonObject_ehsq.put("companycode", UserContext + .fromUID(processInstance.getCreateUser()).getDepartmentModel().getNo()); + // jsonObject_ehsq.put("companycode","00000013"); + jsonObject_ehsq.put("authorcompany", UserContext + .fromUID(processInstance.getCreateUser()).getDepartmentModel().getName()); // jsonObject_ehsq.put("authorcompany","总部质量管理部"); + // // + BO bo1 = SDK.getBOAPI().query("BO_ACT_PUBLISH_PERM_SCOPE", true) + .addQuery("PALNAME=", bo.getString("PUBLISHFILENAME")).detail(); + if (bo1 != null) { + if (bo1.getString("PERMTYPE").equals("1")) { + jsonObject_ehsq.put("releasescope", "内蒙古伊利实业集团股份有限公司"); + } else { + + String departname = ""; + String orgperm = bo1.getString("ORGPERM"); + String dleass = ""; + String[] deptSplit = orgperm.split(","); + if (deptSplit.length == 1) { + dleass = "'" + deptSplit[0] + "'"; + } + dleass = "'" + StringUtils.join(deptSplit, "','") + "'"; + + List maps = DBSql + .getMaps("select DEPARTMENTNAME from ORGDEPARTMENT where ID in (" + dleass + ")"); + for (RowMap rowmas : maps) { + departname += rowmas.getString("DEPARTMENTNAME") + ";"; + } + if(UtilString.isNotEmpty(departname)&&departname.length()>500) { + String substring = departname.substring(0, 500); + departname = substring.substring(0,substring.lastIndexOf(";")); + } + jsonObject_ehsq.put("releasescope", departname); + + } + } + + //System.out.println("任务办理者>>>>>>>>>>>" + processExecutionContext.getTaskInstance().getTarget()); + String sessionId = new SSOUtil().registerClientSessionNoPassword( + processInstance.getCreateUser(), LoginConst.DEFAULT_LANG, "localhost", + LoginConst.DEVICE_PC); + + //System.out.println("办理者的sessionid>>>>>>>>>>>" + sessionId); + String downurl = downloadUtil.getzipURL(sessionId, bo.getString("TASKID"), bo.getString("PUBLISHFILENAME")); + // jsonObject_ehsq.put("downloadurl","http://bpm.yili.com:8088/portal/r"+downurl.toString().substring(1)); + String recordfiles = ""; + String recordurls = ""; + Set keys = downloadurl.keySet(); + for (String key : keys) { + recordfiles += key + ";"; + String cent_url = downloadurl.get(key).substring(downloadurl.get(key).indexOf("/df"), + downloadurl.get(key).length()); + String fileDownurl = "http://bpm.yili.com:8088/portal/r" + cent_url; + recordurls += fileDownurl + ";"; + } + String new_name = ""; + String[] split = recordfiles.split(";"); + if (split.length > 0) { + + for (int i = 1; i < split.length; i++) { + new_name += split[i] + ";"; + } + } + + String new_url = ""; + String[] urls = recordurls.split(";"); + if (urls.length > 0) { + String loadurl = urls[0].replaceAll("&sid=null", "&sid=" + sessionId); + System.out.println("下载的地址是<<<<<<<<<<<<<<<<<<" + loadurl); + jsonObject_ehsq.put("downloadurl", loadurl); + for (int i = 1; i < urls.length; i++) { + String data_url = urls[i].replaceAll("&sid=null", "&sid=" + sessionId); + new_url += data_url + ";"; + } + } + jsonObject_ehsq.put("recordfiles", new_name); + jsonObject_ehsq.put("recordurls", new_url); + jsonArray_EHSQ.add(jsonObject_ehsq); + + Date date = new Date(); + SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + UserContext uc = UserContext.fromUID(processInstance.getCreateUser()); + String userName = uc.getUserName(); + try { + String sql = "SELECT ID FROM BO_EU_PAL_SEND_EHSQ_JOB WHERE PLID = '"+publishfileid+"' AND USERNAMES = '"+userName+"'"; + String id = DBSql.getString(sql); + String sendEHSQFile = SendEHSQFile(plName,jsonArray_EHSQ); + System.err.println("EHSQ流程发布推送结果====>"+processInstance.getTitle()+"=========>"+sendEHSQFile); + if(UtilString.isNotEmpty(id)) { + BO bos = SDK.getBOAPI().get("BO_EU_PAL_SEND_EHSQ_JOB", id); + updateSendLog(bos,userName, uc.getDepartmentModel().getName(), publishfileid, plName, plNumer, dateFormat.format(date), "流程发布推送", sendEHSQFile); + }else { + createSendLog(userName, uc.getDepartmentModel().getName(), publishfileid, plName, plNumer, dateFormat.format(date), "流程发布推送", sendEHSQFile); + } + } catch (Exception e) { + String sql = "SELECT ID FROM BO_EU_PAL_SEND_EHSQ_JOB WHERE PLID = '"+publishfileid+"' AND USERNAMES = '"+userName+"'"; + String id = DBSql.getString(sql); + if(UtilString.isNotEmpty(id)) { + BO bos = SDK.getBOAPI().get("BO_EU_PAL_SEND_EHSQ_JOB", id); + updateSendLog(bos,userName, uc.getDepartmentModel().getName(), publishfileid, plName, plNumer, dateFormat.format(date), "流程发布推送", e.getMessage()); + }else { + createSendLog(userName, uc.getDepartmentModel().getName(), publishfileid, plName, plNumer, dateFormat.format(date), "流程发布推送", e.getMessage()); + } + } + } + } + + public void createSendLog(String username,String userDempet,String plId,String plName,String plNumer,String sendTime,String sendType,String sendResult) { + BO bo = new BO(); + bo.set("PLID", plId); + bo.set("PLNAME", plName); + bo.set("PLNUMER", plNumer); + bo.set("SENDTIME", sendTime); + bo.set("SENDTYPE", sendType); + bo.set("SENDRESULT", sendResult); + bo.set("USERNAMES", username); + bo.set("USERDEMPET", userDempet); + SDK.getBOAPI().createDataBO("BO_EU_PAL_SEND_EHSQ_JOB", bo, UserContext.fromUID("admin")); + } + public void updateSendLog(BO bo,String username,String userDempet,String plId,String plName,String plNumer,String sendTime,String sendType,String sendResult) { + bo.set("PLNUMER", plNumer); + bo.set("SENDTIME", sendTime); + bo.set("SENDTYPE", sendType); + bo.set("SENDRESULT", sendResult); + SDK.getBOAPI().update("BO_EU_PAL_SEND_EHSQ_JOB", bo); + } + + public void updateEHSQ(ProcessInstance processInstance, List bo_act_coe_publish_c) { + DownloadUtil downloadUtil = new DownloadUtil(); + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); + for (BO bo : bo_act_coe_publish_c) { + JSONArray jsonArray_EHSQ = new JSONArray(); + JSONObject jsonObject_ehsq = new JSONObject(new LinkedHashMap<>()); + OutputTaskModel model = new OutputTask().getTaskReportById(bo.getString("TASKID")); + String wsId = model.getWsId(); + String publishfileid = bo.getString("CHANGEDFILEIDNEW"); + LinkedHashMap downloadurl = downloadUtil.outputReportDownload( + UserContext.fromUID(processInstance.getCreateUser()), bo.getString("TASKID"), + publishfileid); + jsonObject_ehsq.put("fileid", bo.getString("TASKID")); + String plName = bo.getString("CHANGEDFILENAMENEW"); + String plNumer = bo.getString("CHANGE_NUMBER"); + jsonObject_ehsq.put("filename", plName); + jsonObject_ehsq.put("filecode",plNumer); + //jsonObject_ehsq.put("filecode", "123456"); + String sql_n = "select * from APP_ACT_COE_PAL_REPOSITORY where id = '" + publishfileid + "'"; + RowMap map = DBSql.getMap(sql_n); + PALRepositoryModel palRepositoryModel = PALRepositoryCache.getCache().get(publishfileid); + jsonObject_ehsq.put("version", "V"+palRepositoryModel.getVersion()+""); + BO byProcess = SDK.getBOAPI().getByProcess("BO_ACT_COE_PUBLISH", processInstance.getId()); + String cdeDate = byProcess.getString("CHOICEEFFECTIVEDATE"); + if("1".equals(cdeDate)) { + jsonObject_ehsq.put("releasedate", byProcess.getString("EFFECTIVEDATE")); + jsonObject_ehsq.put("effectivedate", byProcess.getString("EFFECTIVEDATE")); + }else { + jsonObject_ehsq.put("releasedate", simpleDateFormat.format(new Date())); + jsonObject_ehsq.put("effectivedate", simpleDateFormat.format(new Date())); + } + jsonObject_ehsq.put("authorcode", processInstance.getCreateUser()); + jsonObject_ehsq.put("authorname", + UserContext.fromUID(processInstance.getCreateUser()).getUserName()); + jsonObject_ehsq.put("companycode", UserContext + .fromUID(processInstance.getCreateUser()).getDepartmentModel().getNo()); + jsonObject_ehsq.put("authorcompany", UserContext + .fromUID(processInstance.getCreateUser()).getDepartmentModel().getName()); + BO bo1 = SDK.getBOAPI().query("BO_ACT_PUBLISH_PERM_SCOPE", true) + .addQuery("PALNAME=", bo.getString("CHANGEDFILENAMENEW")).detail(); + if (bo1 != null) { + if (bo1.getString("PERMTYPE").equals("1")) { + jsonObject_ehsq.put("releasescope", "内蒙古伊利实业集团股份有限公司"); + } else { + + String departname = ""; + String orgperm = bo1.getString("ORGPERM"); + String dleass = ""; + String[] deptSplit = orgperm.split(","); + if (deptSplit.length == 1) { + dleass = "'" + deptSplit[0] + "'"; + } + dleass = "'" + StringUtils.join(deptSplit, "','") + "'"; + + List maps = DBSql + .getMaps("select DEPARTMENTNAME from ORGDEPARTMENT where ID in (" + dleass + ")"); + for (RowMap rowmas : maps) { + departname += rowmas.getString("DEPARTMENTNAME") + ";"; + } + if(UtilString.isNotEmpty(departname)&&departname.length()>500) { + String substring = departname.substring(0, 500); + departname = substring.substring(0,substring.lastIndexOf(";")); + } + jsonObject_ehsq.put("releasescope", departname); + + } + } + + String sessionId = new SSOUtil().registerClientSessionNoPassword( + processInstance.getCreateUser(), LoginConst.DEFAULT_LANG, "localhost", + LoginConst.DEVICE_PC); + + String downurl = downloadUtil.getzipURL(sessionId, bo.getString("TASKID"), + bo.getString("CHANGEDFILENAMENEW")); + String recordfiles = ""; + String recordurls = ""; + Set keys = downloadurl.keySet(); + for (String key : keys) { + recordfiles += key + ";"; + String cent_url = downloadurl.get(key).substring(downloadurl.get(key).indexOf("/df"), + downloadurl.get(key).length()); + String fileDownurl = "http://bpm.yili.com:8088/portal/r" + cent_url; + recordurls += fileDownurl + ";"; + } + String new_name = ""; + String[] split = recordfiles.split(";"); + if (split.length > 0) { + + for (int i = 1; i < split.length; i++) { + new_name += split[i] + ";"; + } + } + + String new_url = ""; + String[] urls = recordurls.split(";"); + if (urls.length > 0) { + String loadurl = urls[0].replaceAll("&sid=null", "&sid=" + sessionId); + System.out.println("下载的地址是<<<<<<<<<<<<<<<<<<" + loadurl); + jsonObject_ehsq.put("downloadurl", loadurl); + for (int i = 1; i < urls.length; i++) { + String data_url = urls[i].replaceAll("&sid=null", "&sid=" + sessionId); + new_url += data_url + ";"; + } + } + jsonObject_ehsq.put("recordfiles", new_name); + jsonObject_ehsq.put("recordurls", new_url); + jsonArray_EHSQ.add(jsonObject_ehsq); + Date date = new Date(); + SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + UserContext uc = UserContext.fromUID(processInstance.getCreateUser()); + String userName = uc.getUserName(); + try { + String sql = "SELECT ID FROM BO_EU_PAL_SEND_EHSQ_JOB WHERE PLID = '"+publishfileid+"' AND USERNAMES = '"+userName+"'"; + String id = DBSql.getString(sql); + String sendEHSQFile = SendEHSQFile(plName,jsonArray_EHSQ); + System.err.println("EHSQ流程发布更新===>"+processInstance.getTitle()+"==========>"+sendEHSQFile); + if(UtilString.isNotEmpty(id)) { + BO bos = SDK.getBOAPI().get("BO_EU_PAL_SEND_EHSQ_JOB", id); + updateSendLog(bos,userName, uc.getDepartmentModel().getName(), publishfileid, plName, plNumer, dateFormat.format(date), "流程发布更新", sendEHSQFile); + }else { + createSendLog(userName, uc.getDepartmentModel().getName(), publishfileid, plName, plNumer, dateFormat.format(date), "流程发布更新", sendEHSQFile); + } + } catch (Exception e) { + String sql = "SELECT ID FROM BO_EU_PAL_SEND_EHSQ_JOB WHERE PLID = '"+publishfileid+"' AND USERNAMES = '"+userName+"'"; + String id = DBSql.getString(sql); + if(UtilString.isNotEmpty(id)) { + BO bos = SDK.getBOAPI().get("BO_EU_PAL_SEND_EHSQ_JOB", id); + updateSendLog(bos,userName, uc.getDepartmentModel().getName(), publishfileid, plName, plNumer, dateFormat.format(date), "流程发布更新", e.getMessage()); + }else { + createSendLog(userName, uc.getDepartmentModel().getName(), publishfileid, plName, plNumer, dateFormat.format(date), "流程发布更新", e.getMessage()); + } + } + } + } + + public String SendEHSQFile(String plName,JSONArray jsonArray) throws Exception { + /** + * 首先需要将传过来的参数进行加密操作,并设置 + */ + AesUtil aesUtil = new AesUtil(); + String system = SDK.getAppAPI().getProperty("com.awspaas.user.apps.yili.integration", "system"); + String AES = SDK.getAppAPI().getProperty("com.awspaas.user.apps.yili.integration", "AES"); + String EHSQUrl = SDK.getAppAPI().getProperty("com.awspaas.user.apps.yili.integration", "EHSQUrl"); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + String date = sdf.format(new Date()); + String s1 = date.replaceAll("-", "").replaceAll(" ", "").replaceAll(":", ""); + + //System.out.println("时间>>>>>>>>>>>>" + s1); + String data = system + "##" + s1; + String encrypt = aesUtil.encrypt(data, AES); // 获取加密之后的秘钥 + JSONObject jsonObject = new JSONObject(new LinkedHashMap<>()); + jsonObject.put("system", system); + jsonObject.put("token", encrypt); + jsonObject.put("infos", jsonArray); + HttpUtil httpUtil = new HttpUtil(); + //System.out.println(plName+"发送EHSQ参数>>>>>" + jsonObject); + String s = httpUtil.sendPost(jsonObject, EHSQUrl); + //System.out.println(plName+"发送EHSQ结果>>>>>" + s); + + return s; + } + +}