diff --git a/com/Client.java b/com/Client.java index 2d7ac57..22e3cf2 100644 --- a/com/Client.java +++ b/com/Client.java @@ -18,8 +18,8 @@ public class Client { // String str = "1010157060000081243025801570102311000120230905104426true500130004130157202309050600000812430todogetCountuserNum10913026任广鹏是个大刷币"; // String str = "0000066900000000000402580170951101017020230920195236true500120043010170202309200000000000040BTSQD-20230921001110110001测试审批人2驳回测试2"; // String str = "000005971010157000000001757025801570102311000120231018135840true500130004130157202310180000000017570todogetCount2userNum10110567"; - String str = "000005961010157000000001757025801570102311000120231018135840true500130004130157202310180000000017570todogetCountuserNum10110567"; - // ; + // String str = "000005961010157000000001757025801570102311000120231018135840true500130004130157202310180000000017570todogetCountuserNum10110567"; + String str = "0000066400000000000302580170951101017020240329082246true500120043010170202403290000000000030FHBTSQD-20240325000111010036赵圣熙0驳回测试"; // ; // System.out.println(XMLUtils.parseXMLToMap(str)); // Map stringStringMap = XMLUtils.parseXMLToMap(str); // System.out.println(stringStringMap); diff --git a/com/engine/custom/action/PushCWAction.java b/com/engine/custom/action/PushCWAction.java new file mode 100644 index 0000000..b161c58 --- /dev/null +++ b/com/engine/custom/action/PushCWAction.java @@ -0,0 +1,368 @@ +package com.engine.custom.action; + +import com.dcfs.fts.common.error.FtpException; +import com.engine.custom.hg.util.HgUtils; +import com.engine.custom.sl.entity.*; +import com.engine.util.SocketClientUtil; +import com.engine.util.XMLUtils; +import com.weaver.general.Util; +import org.jsoup.Jsoup; +import weaver.conn.RecordSet; +import weaver.file.ImageFileManager; +import weaver.general.BaseBean; +import weaver.general.StringUtil; +import weaver.hrm.User; +import weaver.interfaces.workflow.action.Action; +import weaver.soa.workflow.request.RequestInfo; + +import java.io.*; +import java.math.BigDecimal; +import java.text.SimpleDateFormat; +import java.util.*; + +/** + * 推送商旅节点后附加操作(推送商旅节点后附加操作 + * 测试环境 + */ +public class PushCWAction extends BaseBean implements Action { + /** + * After selecting aciton after the process path node, this method will be executed after the node is submitted. + */ + @Override + public String execute(RequestInfo request) { + writeLog("推送商旅节点后附加操作====>"); + // if(error) { + // request.getRequestManager().setMessageid("90001"); + // request.getRequestManager().setMessagecontent("System Abnormal Termination Process Submission!"); + // } + String requestId = request.getRequestid(); + String tablename = request.getRequestManager().getBillTableName(); + TravelToEsbBean toEsbBean = new TravelToEsbBean(); + //封装主表数据 + RecordSet rs = new RecordSet(); + String mainId = setMainForm(requestId, tablename, rs, toEsbBean); + writeLog("toEsbBean1====>"+toEsbBean); + writeLog("上传附件到ESB服务器====>"); + try { + fileToEsb(toEsbBean,requestId); + } catch (Exception e) { + request.getRequestManager().setMessageid("10001"); + request.getRequestManager().setMessagecontent(e.getMessage()); + return Action.FAILURE_AND_CONTINUE; + } + setFormDt1(mainId,tablename,rs,toEsbBean); + writeLog("toEsbBean2====>"+toEsbBean); + setFormDt2(mainId,tablename,rs,toEsbBean); + writeLog("toEsbBean3====>"+toEsbBean); + String Service_Body = ""+ toEsbBean.toXMLString()+"" ; + writeLog("toEsbBean4====>"+Service_Body); + try{ + EsbRequestHeader esbRequestHeader = new EsbRequestHeader(Util.getIntValue(mainId)); + writeLog("esbRequestHeader====>"+esbRequestHeader); + String Service_Header = TravelToEsbBean.convertObjectToXml(esbRequestHeader,"Service_Header"); + writeLog("esbRequestHeaderXML====>"+Service_Header); + String serviceXML = ""; + serviceXML = serviceXML + Service_Header + Service_Body; + serviceXML = serviceXML + ""; + writeLog("esbRequestHeaderXML====>"+serviceXML); + int byteArray = serviceXML.getBytes("UTF-8").length; + + // Calculate the length of the byte array + // int bytelength = byteArray.length; + String length = String.format("%08d", byteArray); + writeLog("XMLlength"+ length); + serviceXML = length + serviceXML; + writeLog("serviceXML==="+ serviceXML); + // serviceXML = new String(serviceXML.getBytes(StandardCharsets.UTF_8)); + writeLog("UTF_8_serviceXML==="+ serviceXML); + SocketClientUtil scketClient = new SocketClientUtil("14.1.78.197",10149); + String send = scketClient.send(serviceXML); + String substring = send.substring(0, 8); + String substring1 = send.substring(8); + Map map = XMLUtils.parseXMLToMap(substring1); + String retCd = map.get("retCd"); + String retCdDsc = map.get("retCdDsc"); + if ("9999".equals(retCd)){ + request.getRequestManager().setMessageid("9999"); + request.getRequestManager().setMessagecontent(retCdDsc); + return Action.FAILURE_AND_CONTINUE; + } + }catch (Exception e){ + e.printStackTrace(); + writeLog("构建XML异常"+e.getMessage()); + request.getRequestManager().setMessageid("10001"); + request.getRequestManager().setMessagecontent(e.getMessage()); + return Action.FAILURE_AND_CONTINUE; + } + // setFormDt1(); + return Action.SUCCESS; + } + + private void fileToEsb(TravelToEsbBean toEsbBean, String requestId) throws Exception { + // HashMap filePathMap = new HashMap<>(); + List acsryArray = toEsbBean.getAcsryArray(); + for (acsryItem acsryItem : acsryArray) { + String acsryNm = acsryItem.getAcsryNm(); + writeLog("acsryNm"+acsryNm); + ImageFileManager ifm = new ImageFileManager(); + ifm.getImageFileInfoById(Util.getIntValue(acsryNm,0)); + InputStream inputStream = ifm.getInputStream(); + String imageFileName = ifm.getImageFileName(); + writeLog("imageFileName"+imageFileName); + String[] filename = imageFileName.split("\\."); + int lastIndex = imageFileName.lastIndexOf('.'); + String part1 = ""; + String part2 = ""; + if (lastIndex != -1) { + part1 = imageFileName.substring(0, lastIndex); + part2 = imageFileName.substring(lastIndex + 1); + }else { + part1 = imageFileName; + } + String tempFilePath = ""; + try { + File tempFile = File.createTempFile(part1,part2.length() == 0 ? "" :part2); + + // 创建一个输出流,将数据写入临时文件 + OutputStream outputStream = new FileOutputStream(tempFile); + + // 将输入流中的数据复制到输出流(即临时文件) + byte[] buffer = new byte[2048]; + int bytesRead; + while ((bytesRead = inputStream.read(buffer)) != -1) { + outputStream.write(buffer, 0, bytesRead); + } + tempFilePath = tempFile.getAbsolutePath(); + writeLog( "临时文件位置"+tempFilePath); + // 关闭输入流和输出流 + inputStream.close(); + outputStream.close(); + }catch (Exception e){ + e.printStackTrace(); + writeLog( "创建本地文件异常"+e.getMessage()); + throw new Exception("创建"+imageFileName+"文件异常"+e.getMessage()); + } + //推送ESB服务器 + String ftpPath = ""; + try { + ftpPath = HgUtils.putFile(tempFilePath, requestId + File.separator + imageFileName); + + } catch (FtpException e) { + e.printStackTrace(); + writeLog( "传输ESBftp异常"+e.getMessage()); + throw new Exception("传输ESBftp异常"); + } catch (IOException e) { + e.printStackTrace(); + writeLog( "传输ESBIO异常"+e.getMessage()); + throw new Exception("传输ESBftp异常"); + } + acsryItem.setAcsryNm(imageFileName); + acsryItem.setSavePath(ftpPath); + } + + } + + private String setMainForm(String requestId, String tablename, RecordSet rs ,TravelToEsbBean toEsbBean) { + rs.execute("select * from " + tablename + " where requestid = " + requestId); + String mainid = ""; + String fj = ""; + String spdfj = ""; + String spwhscpdfwj = ""; + //表单数据 + if (rs.next()) { + mainid = rs.getString("id"); + //OA差旅报销单单据编号 + toEsbBean.setOaTrvlBnsExpnsAcctNo(rs.getString(Util.null2String("djbh"))); + //经办人工号 + toEsbBean.setOperatorNo(processString(Util.null2String(rs.getString("jbrgh")))); + //经办人姓名 id + toEsbBean.setOperatorName(Util.null2String(rs.getString("jbrxm"))); + String lastname = new User(Util.getIntValue(toEsbBean.getOperatorName())).getLastname(); + toEsbBean.setOperatorName(lastname); + + //附件张数 + toEsbBean.setAcsryNums(Util.null2String(rs.getString("fjzs"))); + //报销金额 + toEsbBean.setExpnsAmt(multiply100(Util.null2String(rs.getString("bxjedwf")))); + toEsbBean.setCostDeptCode((Util.null2String(rs.getString("cbzxbm")))); + toEsbBean.setCostDeptName((Util.null2String(rs.getString("cbzxmc")))); + //报销事由 Jsoup.parse(htmlContent).text() + String expnsRsn = Util.null2String(rs.getString("bxsy")); + String text = Jsoup.parse(expnsRsn).text(); + toEsbBean.setExpnsRsn(text); + //备注 + toEsbBean.setRemark(Util.null2String(rs.getString("bz"))); + fj = Util.null2String(rs.getString("fj")); + spdfj = Util.null2String(rs.getString("spdfj")); + // spwhscpdfwj = Util.null2String(rs.getString("clspdpdffj")); + spwhscpdfwj = Util.null2String(rs.getString("clspdpdffj")); + // String formData = rs.getString("formData"); + } + // 封装文件数组 + //现在是id + List fjids; + if(!StringUtil.isEmpty(fj)){ + fjids = new ArrayList<>( Arrays.asList(fj.split(","))); + }else { + fjids = new ArrayList<>(); + } + // + writeLog("fjids"+fjids); + try { + if (!StringUtil.isEmpty(spdfj)){ + fjids.add(spdfj); + } + if (!StringUtil.isEmpty(spwhscpdfwj)){ + fjids.add(spwhscpdfwj); + } + ArrayList acsryArray = new ArrayList<>(); + for (String fjid : fjids) { + acsryItem acsryItem = new acsryItem(); + acsryItem.setAcsryNm(getimgid(fjid,rs)); + acsryArray.add(acsryItem); + } + toEsbBean.setAcsryArray(acsryArray); + //重新设置下附件张数为数组长度 + toEsbBean.setAcsryNums(acsryArray.size()+""); + }catch (Exception e){ + e.printStackTrace(); + writeLog("fjidsException"+e); + } + + return mainid; + } + + + private void setFormDt1(String mainid, String tablename, RecordSet rs , TravelToEsbBean toEsbBean) { + rs.execute("select * from " + tablename + "_dt1 where mainid = " + mainid); + List expenseArray = new ArrayList<>(); + while (rs.next()) { + ExpenseItem expenseItem = new ExpenseItem(); + // 支出类型 + expenseItem.setExpndType(getpartyBuildCostCode(Util.getIntValue(rs.getString("zclx"),0))); + //不含税金额 + expenseItem.setExclsvTaxAmt(multiply100(Util.null2String(rs.getString("bhsjedwf")))); + // //不含税金额 + expenseItem.setTaxAmt(multiply100(Util.null2String(rs.getString("sedwf")))); + //价税合计金额 + expenseItem.setPrcTotAmt(multiply100(Util.null2String(rs.getString("jshjjedwf")))); + //记账摘要 Jsoup.parse(expnsRsn).text() + String jzzy = Util.null2String(rs.getString("jzzy")); + String text = Jsoup.parse(jzzy).text(); + expenseItem.setAcctingAbstct(text); + expenseArray.add(expenseItem); + } + toEsbBean.setExpndArray(expenseArray); + } + + + private void setFormDt2(String mainid, String tablename, RecordSet rs , TravelToEsbBean toEsbBean) { + rs.execute("select * from " + tablename + "_dt2 where mainid = " + mainid); + List jrnyInfoArray = new ArrayList<>(); + while (rs.next()) { + JourneyInfo journeyInfo = new JourneyInfo(); + // 开始日期 + journeyInfo.setStartDate(formatDate(Util.null2String(rs.getString("ksrq")))); + // 结束日期 + journeyInfo.setEndDate(formatDate(Util.null2String(rs.getString("jsrq")))); + // 出差天数 + journeyInfo.setBsnTrpDays(Util.null2String(rs.getString("ccts"))); + //行程路线 + journeyInfo.setJrnyPath(Util.null2String(rs.getString("hclx"))); + //行程说明 + journeyInfo.setJrnyExpln(Util.null2String(rs.getString("hcsm"))); + //记账摘要 + journeyInfo.setRemark(Util.null2String(rs.getString("bz"))); + jrnyInfoArray.add(journeyInfo); + } + toEsbBean.setJrnyInfoArray(jrnyInfoArray); + } + + //获取支出类型 + private String getpartyBuildCostCode(int index){ + if(index == 0){ + return "FEE_BUILD"; + }else if(index == 1){ + return "BIZ_FEE"; + }else if(index == 2){ + return "PARTY_BUILD_EXPENSE"; + } + return ""; + } + + public String getimgid(String docid, RecordSet rs){ + String sql = "select docid,df.imagefileid imgid from docimagefile df left join imagefile imf on df.imagefileid = imf.imagefileid where DOCID = ?"; + writeLog("getimgidsql"+sql+"===="+docid); + rs.executeQuery(sql,docid); + if (rs.next()){ + writeLog("imgid"+Util.null2String(rs.getString("imgid"))); + return Util.null2String(rs.getString("imgid")); + } + return ""; + }; + //生成流水号 + public static String generateTimestamp() { + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); + Date currentDate = new Date(); + return dateFormat.format(currentDate); + } + + public static String multiply100(String s) { + s = s.replace(",", ""); // 移除逗号 + if (StringUtil.isEmpty(s)){ + return "0"; + } + BigDecimal value = new BigDecimal(s); + BigDecimal multipliedValue = value.multiply(new BigDecimal("100")); + int result = multipliedValue.intValue(); + System.out.println(result); // 输出:123456 + return String.valueOf(result); // 输出:123456 + } + + public static String formatDate(String input) { + // String input = "2023-09-20 19:29"; + try { + SimpleDateFormat datetimeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm"); + // 使用SimpleDateFormat解析输入字符串 + if (!input.contains(" ")){ + datetimeFormat = new SimpleDateFormat("yyyy-MM-dd"); + } + + Date date = datetimeFormat.parse(input); + // 使用另一个SimpleDateFormat对象格式化Date为所需的输出格式 + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); + String output = dateFormat.format(date); + + return output; // 输出: 2023-09-20 + } catch (Exception e) { + e.printStackTrace(); + } + return ""; + } + + public static String processString(String input) { + // 检查字符串长度是否大于8 + if (input.length() > 8) { + // 如果是,截取前八位 + return input.substring(0, 8); + } else { + // 否则,返回原字符串 + return input; + } + } + + + public static void main(String[] args) { + String imageFileName = "11.16天津-成都去程机票 (1).jpg"; + int lastIndex = imageFileName.lastIndexOf('.'); + String part1 = imageFileName.substring(0, lastIndex); + String part2 = imageFileName.substring(lastIndex + 1); + System.out.println(part1); + System.out.println(part2); + } + + + + + +} diff --git a/com/engine/custom/archives/corn/PushArchivesCorn.java b/com/engine/custom/archives/corn/PushArchivesCorn.java index 9e2fb57..70561e0 100644 --- a/com/engine/custom/archives/corn/PushArchivesCorn.java +++ b/com/engine/custom/archives/corn/PushArchivesCorn.java @@ -4,10 +4,14 @@ import com.engine.custom.archives.service.PushArchivesCornService; import lombok.extern.slf4j.Slf4j; import weaver.interfaces.schedule.BaseCronJob; -import java.text.SimpleDateFormat; -import java.util.Date; + import java.util.HashMap; +/*** + * 推送档案系统定时任务 + * @author rengp + * @date 2024/4/7 + */ @Slf4j public class PushArchivesCorn extends BaseCronJob { public String filePath = "/opt/weaver/filesys/test"; diff --git a/com/engine/custom/archives/service/PushArchivesCornService.java b/com/engine/custom/archives/service/PushArchivesCornService.java index 4074656..4615ba5 100644 --- a/com/engine/custom/archives/service/PushArchivesCornService.java +++ b/com/engine/custom/archives/service/PushArchivesCornService.java @@ -16,6 +16,7 @@ import java.nio.charset.StandardCharsets; import java.io.*; import java.util.*; +import org.apache.commons.lang.StringUtils; import weaver.conn.RecordSet; import weaver.general.StringUtil; import weaver.general.Util; @@ -76,8 +77,10 @@ public class PushArchivesCornService { public void pushArchives(Map param) { log.info("PushArchivesCorn====Begin========{}", param); try { + ZipUtil zipUtil = new ZipUtil(); Date date = getDate(); + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd"); String format = dateFormat.format(date); SimpleDateFormat yyyyMMddHHmmss = new SimpleDateFormat("yyyy-MM-dd HH:mm"); @@ -215,13 +218,16 @@ public class PushArchivesCornService { }); //开始承办单 先获取主流程的承办单 List requestDocid = generaRequestFormPdf(requestid); - List subRequestDocid = generaSubRequestFormPdf(requestid); + // 1.去掉生成子流程承办单 + // List subRequestDocid = generaSubRequestFormPdf(requestid); Map reqDocMap = getFileIdByDocId(String.join(",", requestDocid)); - Map subReqDocMap = getFileIdByDocId(String.join(",", subRequestDocid)); + // 2.去掉生成子流程承办单 + // Map subReqDocMap = getFileIdByDocId(String.join(",", subRequestDocid)); log.error("reqDocMap:{}", JSONObject.toJSONString(reqDocMap)); - log.error("subReqDocMap:{}", JSONObject.toJSONString(subReqDocMap)); + //log.error("subReqDocMap:{}", JSONObject.toJSONString(subReqDocMap)); docids.addAll(requestDocid); - docids.addAll(subRequestDocid); + // 3.去掉生成子流程承办单 + // docids.addAll(subRequestDocid); //附件 reqDocMap.forEach((docid, imageid) -> { ImageFileManager imageFileManager = new ImageFileManager(); @@ -249,34 +255,36 @@ public class PushArchivesCornService { } }); //正文 + i[0] = 1; - subReqDocMap.forEach((docid, imageid) -> { - ImageFileManager imageFileManager = new ImageFileManager(); - imageFileManager.getImageFileInfoById(Util.getIntValue(imageid)); - InputStream inputStream = imageFileManager.getInputStream(); - //中文路径/中文文件名 - String imageFileName = filePath + File.separator + requestid + File.separator + zlcdir + File.separator + fjFile + i[0] + "_" + (imageFileManager.getImageFileName().contains("-")?imageFileManager.getImageFileName().split("\\-")[1]:imageFileManager.getImageFileName()); - imageFileName = codeUtf8(imageFileName); - log.info("子流程承办单路径:{}", imageFileName); - try { - File file = saveInputStreamToFile(inputStream, imageFileName); - String jsonStr = callApi(Url, file); - log.error("永中接口返回:{}", jsonStr); - JSONObject result = JSONObject.parseObject(jsonStr); - String errorcode = result.getString("errorcode"); - if ("0".equals(errorcode)) { - JSONObject data = result.getJSONObject("data"); - String destFileName = data.getString("destFileName"); - String viewUrl = data.getString("viewUrl"); - downloadFile(viewUrl, filePath + File.separator + requestid + File.separator + zlcdir + File.separator + fjFile + i[0] + "_" + (imageFileManager.getImageFileName().contains("-")?imageFileManager.getImageFileName().split("\\-")[1]:imageFileManager.getImageFileName() )+ ".pdf"); - } - i[0]++; - } catch (IOException e) { - e.printStackTrace(); - } - }); + // 4.去掉生成子流程承办单 + // subReqDocMap.forEach((docid, imageid) -> { + // ImageFileManager imageFileManager = new ImageFileManager(); + // imageFileManager.getImageFileInfoById(Util.getIntValue(imageid)); + // InputStream inputStream = imageFileManager.getInputStream(); + // //中文路径/中文文件名 + // String imageFileName = filePath + File.separator + requestid + File.separator + zlcdir + File.separator + fjFile + i[0] + "_" + (imageFileManager.getImageFileName().contains("-")?imageFileManager.getImageFileName().split("\\-")[1]:imageFileManager.getImageFileName()); + // imageFileName = codeUtf8(imageFileName); + // log.info("子流程承办单路径:{}", imageFileName); + // try { + // File file = saveInputStreamToFile(inputStream, imageFileName); + // String jsonStr = callApi(Url, file); + // log.error("永中接口返回:{}", jsonStr); + // JSONObject result = JSONObject.parseObject(jsonStr); + // String errorcode = result.getString("errorcode"); + // if ("0".equals(errorcode)) { + // JSONObject data = result.getJSONObject("data"); + // String destFileName = data.getString("destFileName"); + // String viewUrl = data.getString("viewUrl"); + // downloadFile(viewUrl, filePath + File.separator + requestid + File.separator + zlcdir + File.separator + fjFile + i[0] + "_" + (imageFileManager.getImageFileName().contains("-")?imageFileManager.getImageFileName().split("\\-")[1]:imageFileManager.getImageFileName() )+ ".pdf"); + // } + // i[0]++; + // } catch (IOException e) { + // e.printStackTrace(); + // } + // }); log.error(JSONObject.toJSONString(requestDocid)); - log.error(JSONObject.toJSONString(subRequestDocid)); + // log.error(JSONObject.toJSONString(subRequestDocid)); for (String docid : docids) { log.error("删除了" + docid); deleteDocByid(docid); @@ -474,7 +482,7 @@ public class PushArchivesCornService { context.append(lwdwmc).append("|"); String bgqx = Util.null2String(requesData.get("bgqx")); //6 保管期限 -> 保管期限 context.append(bgqx).append("|"); - String lwrq = Util.null2String(requesData.get("bgqx")); //7 日期 -> 原发文日期 + String lwrq = Util.null2String(requesData.get("lwrq")); //7 日期 -> 原发文日期 context.append(lwrq).append("|"); String ys = Util.null2String(requesData.get("ys")); //8 页数 -> 页数 context.append(ys).append("|"); @@ -857,11 +865,21 @@ public class PushArchivesCornService { public static String getSignLog(String requestid, String dirName, String requestName) { List subRequestIds = getSubRequestIds(requestid); ArrayList> lists = new ArrayList<>(); + List autoInitNodeIds = getAutoInitNodeIds(String.join(",", subRequestIds)); + RecordSet recordSet = new RecordSet(); + String getWFNameByReqId = "select WORKFLOWNAME from WORKFLOW_REQUESTBASE req " + + " left join WORKFLOW_BASE wf on req.WORKFLOWID = wf.ID " + + " where REQUESTID = ? "; for (String reqid : subRequestIds) { + recordSet.executeQuery(getWFNameByReqId,reqid); + String wfName = ""; + if (recordSet.next()){ + wfName = recordSet.getString("WORKFLOWNAME"); + } HashMap params = new HashMap<>(); params.put("requestid", reqid); params.put("desremark", "all"); - params.put("pageSize", "50"); + params.put("pageSize", "999"); params.put("isfirst", "true"); // params.put("request", request); Map data = getSignLogCmd(params, new User(1)); @@ -884,19 +902,49 @@ public class PushArchivesCornService { Map value = (Map) entry.getValue(); List> list = (List) value.get("list"); + String nodeid = Util.null2String(value.get("nodeid")) ; + if (autoInitNodeIds.contains(nodeid)){ + continue; + } for (Map item : list) { String operator = (String) item.get("operator"); String operatorid = (String) item.get("operatorid"); String operatortype = (String) item.get("operatortype"); String operatedate = (String) item.get("operatedate"); + String receivedate = (String) item.get("receivedate"); String nodename = (String) value.get("nodename"); + String statuscode = (String) item.get("statuscode"); HashMap itemMap = new HashMap<>(); itemMap.put("operator", operator); itemMap.put("operatorid", operatorid); itemMap.put("operatortype", operatortype); - itemMap.put("operatedate", operatedate); + itemMap.put("operatedate", StringUtil.isEmpty(operatedate) ? receivedate : operatedate); + itemMap.put("nodename", nodename); itemMap.put("nodename", nodename); itemMap.put("requestName", (String) value.get("requestName")); + //1:未查看, 2::以查看, 3:已提交, 4:暂停, 5:撤销, 6:启用 7:已查阅 8:退回 9:被撤回 + String action = ""; + if ("1".equals(statuscode)){ + action = "未查看"; + }else if("2".equals(statuscode)){ + action = "已查看"; + }else if("3".equals(statuscode)){ + action = "已提交"; + }else if("4".equals(statuscode)){ + action = "暂停"; + }else if("5".equals(statuscode)){ + action = "撤销"; + }else if("6".equals(statuscode)){ + action = "启用"; + }else if("7".equals(statuscode)){ + action = "已查阅"; + }else if("8".equals(statuscode)){ + action = "退回"; + }else if("9".equals(statuscode)){ + action = "被撤回"; + } + itemMap.put("statuscode", "3".equals(statuscode) ? "提交" : "查看" ); + itemMap.put("action", action ); results.add(itemMap); } @@ -905,7 +953,7 @@ public class PushArchivesCornService { HashMap records = new HashMap<>(); records.put("results",results); String requestName1 = (String) data.get("requestName"); - records.put("requestName",requestName1); + records.put("requestName","【"+wfName+"】-"+requestName1); log.error("requestName1:{}", requestName1); log.error("records:{}", JSONObject.toJSONString(records)); lists.add(records); @@ -1499,7 +1547,7 @@ public class PushArchivesCornService { if (!tmpisremark.equals("s") && !tmpisremark.equals("c") && !tmpisremark.equals("r")) { _receivedate = Util.toScreen(tmpreceivedate, user.getLanguage()) + " " + Util.toScreen(tmpreceivetime, user.getLanguage()); } - _operatedate = Util.toScreen(tmpreceivedate, user.getLanguage()) + " " + Util.toScreen(tmpreceivetime, user.getLanguage()); + _operatedate = Util.toScreen(tmpoperatedate, user.getLanguage()) + " " + Util.toScreen(tmpoperatetime, user.getLanguage()); _intervel = Util.toScreen(tmpIntervel, user.getLanguage()); @@ -1514,6 +1562,8 @@ public class PushArchivesCornService { _statusmap.put("beagentname", _beagentname); _statusmap.put("nodetype", nodetype); + + //所有节点 nodeallstatuslist.add(_statusmap); //查看状态 1:未查看, 2::以查看, 3:已提交, 4:暂停, 5:撤销, 6:启用 7:已查阅 @@ -1714,4 +1764,28 @@ public class PushArchivesCornService { System.out.println(s1); } } + + /** + * 获取流程自动发起的节点 + * @param mainAndSubRequestId + * @return + */ + private static ArrayList getAutoInitNodeIds(String mainAndSubRequestId) { + RecordSet recordSet = new RecordSet(); + ArrayList nodeids = new ArrayList<>(); + String sql = "select node.NODEID nodeid , nodegroup.GROUPNAME from workflow_flownode node " + + " left join workflow_nodegroup nodegroup " + + " on node.nodeid = nodegroup.nodeid " + + " left join workflow_groupdetail detail " + + "on nodegroup.id = detail.GROUPID " + + "where node.WORKFLOWID in (select distinct WORKFLOWID from WORKFLOW_REQUESTBASE where REQUESTID in ( "+ mainAndSubRequestId +" ) ) and detail.id is null"; + recordSet.executeQuery(sql); + while (recordSet.next()){ + String nodeid = recordSet.getString("nodeid"); + if (!StringUtils.isEmpty(nodeid)){ + nodeids.add(nodeid); + } + } + return nodeids; + } } diff --git a/com/engine/custom/archives/workflow/biz/requestLog/RequestLogCusBiz.java b/com/engine/custom/archives/workflow/biz/requestLog/RequestLogCusBiz.java index 31b8921..51576e8 100644 --- a/com/engine/custom/archives/workflow/biz/requestLog/RequestLogCusBiz.java +++ b/com/engine/custom/archives/workflow/biz/requestLog/RequestLogCusBiz.java @@ -140,6 +140,7 @@ public class RequestLogCusBiz { mssqlTopflg = " top 100 percent "; } String thisviewLogIds = getViewLogIds(viewLogIds, requestid, workflowid); + String autoInitNodeIds = getAutoInitNodeIds(mainAndSubRequestId); String robotNodeid = getRobotNodeid(thisviewLogIds); String selectfields = " nodeid,destnodeid,operatedate,operatetime,logtype,remark,isMobile,logid,operatortype,operator," + "agenttype,agentorbyagentid,receivedPersonids,requestLogId,annexdocids,operatorDept,signdocids," + @@ -155,8 +156,8 @@ public class RequestLogCusBiz { } String sql = "select " + mssqlTopflg + selectfields + " from workflow_requestlog t1 " + - " where t1.requestid in ( " + mainAndSubRequestId + ") and t1.logtype != '1' " ; - // " and " + Util.getSubINClause(thisviewLogIds, "t1.nodeid", "in"); + " where t1.requestid in ( " + mainAndSubRequestId + ") and t1.logtype != '1' " + + " and t1.nodeid not in (" + autoInitNodeIds + " )"; if (sqlwhere != null && !sqlwhere.equals("")) { sql = sql + sqlwhere; } @@ -172,6 +173,30 @@ public class RequestLogCusBiz { return sql; } + /** + * 获取流程自动发起的节点 + * @param mainAndSubRequestId + * @return + */ + private static String getAutoInitNodeIds(String mainAndSubRequestId) { + RecordSet recordSet = new RecordSet(); + ArrayList nodeids = new ArrayList<>(); + String sql = "select node.NODEID nodeid , nodegroup.GROUPNAME from workflow_flownode node " + + " left join workflow_nodegroup nodegroup " + + " on node.nodeid = nodegroup.nodeid " + + " left join workflow_groupdetail detail " + + "on nodegroup.id = detail.GROUPID " + + "where node.WORKFLOWID in (select distinct WORKFLOWID from WORKFLOW_REQUESTBASE where REQUESTID in ( "+ mainAndSubRequestId +" ) ) and detail.id is null"; + recordSet.executeQuery(sql); + while (recordSet.next()){ + String nodeid = recordSet.getString("nodeid"); + if (!StringUtils.isEmpty(nodeid)){ + nodeids.add(nodeid); + } + } + return String.join(",",nodeids); + } + private static String getMainOrSubRequest(int requestid, boolean isSubrequest) { if (isSubrequest){ // RecordSet rs = new RecordSet(); diff --git a/com/engine/custom/archives/workflow/cmd/requestLog/LoadRequestLogDataCusCmd.java b/com/engine/custom/archives/workflow/cmd/requestLog/LoadRequestLogDataCusCmd.java index 5a6eadf..272396f 100644 --- a/com/engine/custom/archives/workflow/cmd/requestLog/LoadRequestLogDataCusCmd.java +++ b/com/engine/custom/archives/workflow/cmd/requestLog/LoadRequestLogDataCusCmd.java @@ -275,12 +275,12 @@ public class LoadRequestLogDataCusCmd extends AbstractCommonCommand resultMap = null; + String tableName = ""; int userid = 0; try { - resultMap = getBeanByOAnum(oaTrvlBnsExpnsAcctNo, "formtable_main_281"); + if(oaTrvlBnsExpnsAcctNo.startsWith("BTSQD")){ + tableName = "formtable_main_281"; + // resultMap = getBeanByOAnum(oaTrvlBnsExpnsAcctNo, "formtable_main_281"); + }else if(oaTrvlBnsExpnsAcctNo.startsWith("FHBTSQD")) { + tableName = "formtable_main_420"; + // resultMap = getBeanByOAnum(oaTrvlBnsExpnsAcctNo, ""); + }else { + throw new Exception("未找到编号 '"+oaTrvlBnsExpnsAcctNo+"' 对应的表单"); + }; + resultMap = getBeanByOAnum(oaTrvlBnsExpnsAcctNo, tableName); } catch (Exception e) { e.printStackTrace(); return XMLUtils.CW2XML(paramMap, "1", e.getMessage()); @@ -48,9 +58,9 @@ public class CWGLSocketExecute extends BaseBean implements SocketExecute { if (requestid == 0) { return XMLUtils.CW2XML(paramMap, "1", "流程未找到"); } - if (userid == 0) { - return XMLUtils.CW2XML(paramMap, "1", "人员未找到"); - } + // if (userid == 0) { + // return XMLUtils.CW2XML(paramMap, "1", "人员未找到"); + // } RequestService requestService = new RequestService(); boolean istrue = false; if ("0".equals(flowStatus)) { @@ -69,7 +79,7 @@ public class CWGLSocketExecute extends BaseBean implements SocketExecute { if (istrue) { try { updateStatus(requestid, flowStatus); - String sqr = getsqrbyBH(oaTrvlBnsExpnsAcctNo, "formtable_main_281"); + String sqr = getsqrbyBH(oaTrvlBnsExpnsAcctNo, tableName); if("3".equals(flowStatus)){ sendMsgForSuccess(sqr,oaTrvlBnsExpnsAcctNo,requestid); } @@ -122,6 +132,7 @@ public class CWGLSocketExecute extends BaseBean implements SocketExecute { RecordSet recordSet = new RecordSet(); HashMap resultMap = new HashMap<>(); String sql = "select * from " + tableName + " where djbh = ?"; + writeLog("getBeanByOAnumSql"+sql); recordSet.executeQuery(sql, oaTrvlBnsExpnsAcctNo); if (recordSet.next()) { resultMap.put("id", Util.null2String(recordSet.getString("id"))); diff --git a/produce/23/transfer/mobile/ssoUrl.jsp b/produce/23/transfer/mobile/ssoUrl.jsp new file mode 100644 index 0000000..d5b44f2 --- /dev/null +++ b/produce/23/transfer/mobile/ssoUrl.jsp @@ -0,0 +1,809 @@ +<%@ page import="weaver.conn.RecordSet" %> +<%@ page import="weaver.general.BaseBean" %> +<%@ page import="weaver.general.Util" %> +<%@ page import="com.alibaba.fastjson.JSONObject" %> +<%@ page import="com.alibaba.fastjson.JSONArray" %> + +<%@ page import="java.io.*" %> +<%@ page import="weaver.hrm.User" %> +<%@ page import="java.text.SimpleDateFormat" %> +<%@ page import="java.util.*" %> +<%@ page language="java" contentType="text/html; charset=UTF-8" %> +<%@ page import="org.apache.http.impl.client.CloseableHttpClient" %> +<%@ page import="org.apache.http.impl.client.HttpClients" %> +<%@ page import="org.apache.http.client.methods.HttpPost" %> +<%@ page import="org.apache.http.entity.StringEntity" %> +<%@ page import="org.apache.http.client.methods.CloseableHttpResponse" %> +<%@ page import="org.apache.http.HttpStatus" %> +<%@ page import="org.apache.http.HttpEntity" %> +<%@ page import="org.apache.http.util.EntityUtils" %> +<%@ page import="org.apache.http.client.ClientProtocolException" %> +<%@ page import="weaver.hrm.HrmUserVarify" %> +<%@ page import="java.net.URL" %> +<%@ page import="java.net.HttpURLConnection" %> +<%@ page import="org.apache.http.NameValuePair" %> +<%@ page import="org.apache.http.message.BasicNameValuePair" %> +<%@ page import="org.apache.http.client.entity.UrlEncodedFormEntity" %> +<%@ page import="weaver.rsa.security.RSA" %> +<%@ page import="java.security.interfaces.RSAPublicKey" %> +<%@ page import="java.security.KeyFactory" %> +<%@ page import="java.security.spec.X509EncodedKeySpec" %> +<%@ page import="javax.crypto.Cipher" %> +<%@ page import="org.apache.commons.codec.binary.Base64" %> +<%@ page import="java.nio.charset.StandardCharsets" %> +<%@ page import="org.apache.http.impl.client.HttpClientBuilder" %> +<%@ page import="org.apache.http.client.methods.HttpGet" %> +<%@ page import="com.engine.common.util.ParamUtil" %> +<%@ page import="java.time.format.DateTimeFormatter" %> +<%@ page import="java.time.LocalDateTime" %> +<%@ page import="java.time.temporal.ChronoUnit" %> +<%@ page import="okhttp3.*" %> +<%@ page import="javax.servlet.http.Cookie" %> +<%@ page import="weaver.file.Prop" %> +<%@ page import="com.alibaba.fastjson.JSONException" %> +<%@ page import="com.wbi.util.StringUtil" %> +<%@ page import="java.net.URLDecoder" %> +<%! + public String httpPostRequest(String param, String url, String token) { + BaseBean baseBean = new BaseBean(); + String responseBody = ""; + try { + CloseableHttpClient httpClient = HttpClients.createDefault(); + HttpPost httpPost = new HttpPost(url); + + //设置请求体参数 + StringEntity entity = new StringEntity(param, "utf-8"); + baseBean.writeLog("entity-param->" + param); + baseBean.writeLog("entity-->" + entity); + entity.setContentEncoding("utf-8"); + baseBean.writeLog("entity-utf-8->" + entity); + httpPost.setEntity(entity); + //设置请求头部 + httpPost.setHeader("Content-Type", "application/json"); + if (token != null && !"".equals(token)) { + httpPost.setHeader("Authorization", token); + } + //执行请求,返回请求响应 + CloseableHttpResponse response = httpClient.execute(httpPost); + //请求返回状态码 + int statusCode = response.getStatusLine().getStatusCode(); + baseBean.writeLog("statusCode状态码->" + statusCode); + //请求成功 + if (statusCode == HttpStatus.SC_OK && statusCode <= HttpStatus.SC_TEMPORARY_REDIRECT) { + //取出响应体 + HttpEntity entity2 = response.getEntity(); + //从响应体中解析出token + responseBody = EntityUtils.toString(entity2, "utf-8"); +// jsonObject = JSONObject.parseObject(responseBody); + baseBean.writeLog("responseBody->" + responseBody); +// baseBean.writeLog("jsonObject->"+jsonObject); + //token = jsonObject.getString("access_token"); + } else { + //请求失败 + throw new ClientProtocolException("请求失败,响应码为:" + statusCode); + } + } catch (Exception e) { + e.printStackTrace(); + } + return responseBody; + } + + /** + * 发送http get请求 + */ + public static String httpGet(String url, Map headers, String encode) { + BaseBean bb = new BaseBean(); + if (encode == null) { + encode = "utf-8"; + } + CloseableHttpResponse httpResponse = null; + CloseableHttpClient closeableHttpClient = null; + String content = null; + //since 4.3 不再使用 DefaultHttpClient + try { + closeableHttpClient = HttpClientBuilder.create().build(); + HttpGet httpGet = new HttpGet(url); + //设置header + if (headers != null && headers.size() > 0) { + for (Map.Entry entry : headers.entrySet()) { + httpGet.setHeader(entry.getKey(), entry.getValue()); + } + } + + bb.writeLog("url=" + url + "header=" + headers + "encode=" + encode); + httpResponse = closeableHttpClient.execute(httpGet); + HttpEntity entity = httpResponse.getEntity(); + content = EntityUtils.toString(entity, encode); + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + httpResponse.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + try { //关闭连接、释放资源 + closeableHttpClient.close(); + } catch (IOException e) { + e.printStackTrace(); + } + return content; + } + + /** + * 向指定 URL 发送POST方法的请求 + * + * @param url 发送请求的 URL + * @param param 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。 + * @return 所代表远程资源的响应结果 + */ + public static String sendPost(String url, String param) { + BaseBean bb = new BaseBean(); + String result = ""; + PrintWriter out = null; + BufferedReader in = null; + HttpURLConnection connection = null; + try { + URL postUrl = new URL(url); + bb.writeLog("getUrl-->" + postUrl); + // 打开和URL之间的连接 + connection = (HttpURLConnection) postUrl.openConnection(); + + // 在connect之前,设置通用的请求属性 + connection.setRequestProperty("accept", "*/*"); + connection.setRequestProperty("connection", "Keep-Alive"); + connection.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"); + connection.setRequestProperty("Charsert", "UTF-8"); + + connection.setConnectTimeout(15000); + connection.setReadTimeout(60000); + // 发送POST请求必须设置如下两行,参数要放在http正文内 + connection.setDoOutput(true); + connection.setDoInput(true); + // 默认是 GET方式 + connection.setRequestMethod("POST"); + // Post 请求不使用缓存 + connection.setUseCaches(false); + // 配置本次连接的Content-type,form表单是"application/x-www-form-urlencoded",json是"application/json"等 + connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); + connection.connect(); + + // 参数要放在http正文内 + //1.获取URLConnection对象对应的输出流 + out = new PrintWriter(connection.getOutputStream()); + //2.中文有乱码的需要将PrintWriter改为如下 + //out=new OutputStreamWriter(conn.getOutputStream(),"UTF-8") + out.print(param); + out.flush(); + //也可以使用DataOutputStream +// DataOutputStream dos=new DataOutputStream(httpConn.getOutputStream()); +// dos.writeBytes(param); +// dos.flush(); +// dos.close(); + + // 定义BufferedReader输入流来读取URL的响应 + if (connection.getResponseCode() == 200) { + in = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8")); + String line; + while ((line = in.readLine()) != null) { + result += line; + } + } + } catch (Exception e) { + bb.writeLog("发送 POST 请求出现异常!" + e); + e.printStackTrace(); + } finally { + try { + if (out != null) { + out.close(); + } + if (in != null) { + in.close(); + } + if (connection != null) { + //关闭连接 + connection.disconnect(); + } + } catch (IOException ex) { + ex.printStackTrace(); + } + } + return result; + } + + + /** + * 发送 http post 请求,参数以form表单键值对的形式提交。 + */ + public static String httpPostForm(String url, Map params, Map headers, String encode) { + BaseBean bb = new BaseBean(); + if (encode == null) { + encode = "utf-8"; + } + + String content = null; + CloseableHttpResponse httpResponse = null; + CloseableHttpClient closeableHttpClient = null; + try { + + closeableHttpClient = HttpClients.createDefault(); + HttpPost httpost = new HttpPost(url); + + //设置header + if (headers != null && headers.size() > 0) { + for (Map.Entry entry : headers.entrySet()) { + httpost.setHeader(entry.getKey(), entry.getValue()); + } + } + bb.writeLog("url=" + url + "header=" + headers + "encode=" + encode); + bb.writeLog("params=" + params); + //组织请求参数 + List paramList = new ArrayList(); + if (params != null && params.size() > 0) { + Set keySet = params.keySet(); + for (String key : keySet) { + paramList.add(new BasicNameValuePair(key, params.get(key))); + } + } + httpost.setEntity(new UrlEncodedFormEntity(paramList, encode)); + + httpResponse = closeableHttpClient.execute(httpost); + HttpEntity entity = httpResponse.getEntity(); + content = EntityUtils.toString(entity, encode); + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + httpResponse.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + try { //关闭连接、释放资源 + closeableHttpClient.close(); + } catch (IOException e) { + e.printStackTrace(); + } + return content; + } + + /** + * 公钥加密 + * + * @param content 内容 + * @param publicKey 公钥 + * @return 加密后的密文 + * @throws Exception 异常信息 + */ + public static String encrypt(String content, String publicKey) throws Exception { + //base64编码的公钥 + byte[] decoded = org.apache.commons.codec.binary.Base64.decodeBase64(publicKey); + RSAPublicKey pubKey = (RSAPublicKey) KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(decoded)); + //RSA加密 + Cipher cipher = Cipher.getInstance("RSA"); + cipher.init(Cipher.ENCRYPT_MODE, pubKey); + return Base64.encodeBase64String(cipher.doFinal(content.getBytes(StandardCharsets.UTF_8))); + } + + public static String getPublicKey(Map MachInfo) { + BaseBean bb = new BaseBean(); + String publicKey = ""; + String API_KEY = Util.null2String(bb.getPropValue("tjbankEMobileSSO", "key")); + //请求获取publicKey接口 + Map headers = new HashMap<>(); + String url = Util.null2String(bb.getPropValue("tjbankEMobileSSO", "publicKeyUrl")); + headers.put("API_KEY", API_KEY); + headers.put("MACH_ID", MachInfo.get("deviceId")); + headers.put("MACH_TYPE", Util.null2String(MachInfo.get("clientType"), "0")); + headers.put("MACH_IP", MachInfo.get("param_ip")); + String msg = httpGet(url, headers, null); + bb.writeLog("===获取publickey返回值====" + msg); + try { + org.json.JSONObject resMsg = new org.json.JSONObject(msg); + bb.writeLog("===获取publickey返回值====" + resMsg); + if (resMsg.has("pubKey")) { + publicKey = Util.null2String(resMsg.get("pubKey").toString()); + } + } catch (Exception e) { + e.getMessage(); + } + return publicKey; + } + + //获取TG + public static String getST(String tgt, String emobileUrl, Map MachInfo) { + BaseBean bb = new BaseBean(); + String ST = ""; + String retMsg = ""; + Map params = new HashMap<>();//参数 + Map headers = new HashMap<>();//headers + String API_KEY = Util.null2String(bb.getPropValue("tjbankEMobileSSO", "key")); + //请求获取TG接口 + String url = Util.null2String(bb.getPropValue("tjbankEMobileSSO", "stUrl")); + bb.writeLog("==获取TG==" + url); + //移动端首页地址 + + bb.writeLog("==移动端首页地址==" + emobileUrl); + //获取TGT + params = new HashMap<>();//参数 + params.put("tgt", tgt); + params.put("service", emobileUrl); + bb.writeLog("==STparams==" + params); + + headers = new HashMap<>();//headers + headers.put("API_KEY", API_KEY); + headers.put("MACH_ID", MachInfo.get("deviceId")); + headers.put("MACH_TYPE", Util.null2String(MachInfo.get("clientType"), "0")); + headers.put("MACH_IP", MachInfo.get("param_ip")); + + try { + + retMsg = httpPostForm(url, params, headers, null); + bb.writeLog("===获取ST返回值====" + retMsg); + org.json.JSONObject resMsg = new org.json.JSONObject(retMsg); + bb.writeLog("===获取ST返回值resMsg====" + resMsg); + if (resMsg.has("ST")) { + ST = Util.null2String(resMsg.get("ST").toString()); + } + bb.writeLog("===获取ST====" + ST); + } catch (Exception e) { + throw new RuntimeException(e); + } + return retMsg; + + } + + public static String getSysUrl(String sysid) { + RecordSet rs = new RecordSet(); + String url = "-1"; + //查询建模 + rs.executeQuery("select * from uf_otherSysInfo where id = ?", sysid); + if (rs.next()) { + url = Util.null2String(rs.getString("xtdz")); + } else { + return "-1"; + } + url = url.trim(); + if (!StringUtil.isBlank(url)) { + //判断是否带?号 + if (url.indexOf("?") == -1) { + url = url + "?"; + } else { + url = url + "&"; + } + } + ; + return url; + } + + public static String getsysSSOurl(String sysid) { + RecordSet rs = new RecordSet(); + String url = "-1"; + //查询建模 + rs.executeQuery("select * from uf_otherSysInfo where id = ?", sysid); + if (rs.next()) { + url = Util.null2String(rs.getString("hqdddz")); + } else { + return "-1"; + } + new BaseBean().writeLog("hqdddz====" + url); + url = url.trim(); + return url; + } + + public static boolean isDifferenceGreaterThan(String timeStr2, int hours) { + // 定义日期时间格式 + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + + // 解析字符串为LocalDateTime对象 + // LocalDateTime time1 = LocalDateTime.parse(timeStr1, formatter); + LocalDateTime now = LocalDateTime.now(); + LocalDateTime time2 = LocalDateTime.parse(timeStr2, formatter); + + // 计算两个时间的差值(以小时为单位) + // long hoursDifference = ChronoUnit.HOURS.between(time1, time2); + long hoursDifference = ChronoUnit.SECONDS.between(now, time2); + System.out.println(hoursDifference); + // 检查差值是否大于给定的小时数 + return Math.abs(hoursDifference) > (long) hours * 60 * 60; + } + + public String getEMToken() { + try { + String sysurl = Prop.getPropValue("emsysinfo", "sysurl"); + String corpid = Prop.getPropValue("emsysinfo", "corpid"); + String corpsecret = Prop.getPropValue("emsysinfo", "corpsecret"); + OkHttpClient client = new OkHttpClient(); + Request request = new Request.Builder() + .url(sysurl + "/emp/api/gettoken?corpid=" + corpid + "&corpsecret=" + corpsecret) + .get() + .build(); + Response response = client.newCall(request).execute(); + String responseStr = response.body().string(); + JSONObject responseJson = JSONObject.parseObject(responseStr); + if ("0".equals(responseJson.get("errcode") + "")) { + return responseJson.getString("access_token"); + } else { + return responseJson.getString("errmsg"); + } + } catch (Exception e) { + return e.getMessage(); + } + } + + public String EMExt(String access_token, String jsonStr) { + OkHttpClient client = new OkHttpClient(); + String sysurl = Prop.getPropValue("emsysinfo", "sysurl"); + MediaType mediaType = MediaType.parse("application/json"); + RequestBody body = RequestBody.create(mediaType, jsonStr); + Request request = new Request.Builder() + .url(sysurl + "/emp/api/integrate/func/offline?access_token=" + access_token) + .post(body) + .addHeader("content-type", "application/json") + .build(); + try { + Response response = client.newCall(request).execute(); + String responseStr = response.body().string(); + JSONObject responseJson = JSONObject.parseObject(responseStr); + if ("0".equals(responseJson.get("errcode"))) { + return responseJson.getString("errmsg"); + } else { + return responseJson.getString("errmsg"); + } + } catch (Exception e) { + e.printStackTrace(); + return e.getMessage(); + } + } + +%> +<% + BaseBean bb = new BaseBean(); + bb.writeLog("进入消息单点跳转中中转页面jsp-->"); + // 权限认证 + User user = HrmUserVarify.getUser(request, response); + if (user == null) { + response.sendRedirect("/notice/noright.jsp"); + return; + } + RecordSet rs = new RecordSet(); + + RSA rsa = new RSA(); + Map params = new HashMap<>();//参数 + Map headers = new HashMap<>();//headers + JSONArray array = new JSONArray(); + List decriptList = new ArrayList<>(); + String ST = "";//获取ST + + Map paramsMap = ParamUtil.request2Map(request); + String deviceId = Util.null2String(paramsMap.get("deviceId")); + String clientType = Util.null2String(paramsMap.get("clientType")); + if ("2".equals(clientType)) { + clientType = "0"; + } else if ("3".equals(clientType)) { + clientType = "1"; + } + String param_ip = Util.null2String(paramsMap.get("param_ip")); + new BaseBean().writeLog("paramsMap===>" + paramsMap); + new BaseBean().writeLog("deviceId===>" + deviceId); + new BaseBean().writeLog("clientType===>" + clientType); + HashMap MachInfo = new HashMap<>(); + MachInfo.put("deviceId", deviceId.isEmpty() ? "123" : deviceId); + MachInfo.put("clientType", clientType.isEmpty() ? "1" : clientType); + MachInfo.put("param_ip", param_ip.isEmpty() ? "127.0.0.1" : param_ip); + String sysid = (String) paramsMap.get("sysid"); + if (StringUtil.isBlank(sysid)) { + out.print("sysid为空"); + return; + } + // String sysUrl = getSysUrl(sysid); + String sysUrl = (String) paramsMap.get("sysUrl"); + if ("-1".equals(sysUrl)) { + out.print("系统url为空"); + return; + } + sysUrl = URLDecoder.decode(sysUrl, StandardCharsets.UTF_8.toString()); + sysUrl = sysUrl.trim(); + if (!StringUtil.isBlank(sysUrl)) { + //判断是否带?号 + if (sysUrl.indexOf("?") == -1) { + sysUrl = sysUrl + "?"; + } else { + sysUrl = sysUrl + "&"; + } + } + + + + + String login_id = ""; + String user_password = ""; + + int uid = user.getUID(); + bb.writeLog("uid-->" + uid); + rs.executeQuery("select id,loginid,password,createtime from EmobileLoginDetail where id=?", uid); + if (rs.next()) { + login_id = Util.null2String(rs.getString("loginid")); + user_password = Util.null2String(rs.getString("password")); + } + bb.writeLog("login_id-->" + login_id); + bb.writeLog("user_password-->" + user_password); + //获取session + session = request.getSession(true); + String certified_token = Util.null2String(session.getAttribute("certified_token")); + String certified_token_expires = Util.null2String(session.getAttribute("certified_token_expires")); + bb.writeLog("获取sessionTGT==" + certified_token); + // //获取cookie + // Cookie[] cookies = request.getCookies(); + // bb.writeLog("获取cookies==" + cookies); + // String idd = ""; + // if (cookies != null) { + // for (Cookie cookie : cookies) { + // bb.writeLog("获取cookiesName==" + cookie.getName()); + // if (cookie.getName().equals("loginidweaver")) { + // idd = cookie.getValue(); + // bb.writeLog("获取idd==" + idd); + // } + // } + // } + //查询人员工号 + RecordSet recordSet = new RecordSet(); + String requestURI = request.getRequestURI(); + bb.writeLog("请求路径=" + requestURI); + // Map useridMap = ParamUtil.request2Map(request); + // bb.writeLog("人员id=" + useridMap.get("userid")); + // recordSet.executeQuery("select WORKCODE from HRMRESOURCE where id=?", Util.null2String(useridMap.get("userid"))); + // String workcode = ""; + // if (recordSet.next()) { + // workcode = Util.null2String(recordSet.getString("WORKCODE")); + // } + // bb.writeLog("人员workcode=" + useridMap.get("workcode")); + //查询 + String API_KEY = Util.null2String(bb.getPropValue("tjbankEMobileSSO", "key"));//publicKey + String url = Util.null2String(bb.getPropValue("tjbankEMobileSSO", "stUrl"));//获取ST的url + String cockpitUrl = getsysSSOurl(sysid); + String tgturl = Util.null2String(bb.getPropValue("tjbankEMobileSSO", "tgtUrl"));//请求获取TGT地址 + //获取ST,带着下游系统 + if (!StringUtil.isBlank(certified_token) && !isDifferenceGreaterThan(certified_token_expires, 4)) { + bb.writeLog("TGT未失效"); + String responseInfo = getST(certified_token, cockpitUrl, MachInfo); + bb.writeLog("进入responseInfo-->" + responseInfo); + if (StringUtil.isBlank(responseInfo)) { + out.print("单点系统接口返回值为null"); + return; + } else { + org.json.JSONObject stMsg = new org.json.JSONObject(responseInfo); + if (stMsg.has("ST")) { + ST = Util.null2String(stMsg.get("ST").toString()); + } else { + try { + if (stMsg.has("errorCode") && "2009".equals(stMsg.getString("errorCode"))) { + response.sendRedirect("https://office.bankoftianjin.com/interface/transfer/mobile/noPermissons2.html"); + } else if (stMsg.has("errorCode") && "2008".equals(stMsg.getString("errorCode"))) { + //----------------------------------TGT未找到--------------------------------------------- + bb.writeLog("TGT未找到"); + String TGT = ""; + String passWord = ""; + String retMsg = ""; + decriptList.add(login_id); + decriptList.add(user_password); + List resultList = rsa.decryptList(request, decriptList); + String loginId = resultList.get(0); + String userPassword = resultList.get(1); + String publicKey = getPublicKey(MachInfo); + passWord = encrypt(user_password, publicKey); + params = new HashMap<>();//参数 + params.put("username", loginId); + params.put("password", passWord); + bb.writeLog("==STparams==" + params); + + headers = new HashMap<>();//headers + headers.put("API_KEY", API_KEY); + headers.put("MACH_ID", MachInfo.get("deviceId")); + headers.put("MACH_TYPE", Util.null2String(MachInfo.get("clientType"), "0")); + headers.put("MACH_IP", MachInfo.get("param_ip")); + + + retMsg = httpPostForm(tgturl, params, headers, null); + bb.writeLog("===获取TGT返回值retMsg====" + retMsg); + org.json.JSONObject resMsg = new org.json.JSONObject(retMsg); + bb.writeLog("===获取TGT返回值====" + resMsg); + if (resMsg.has("TGT")) { + TGT = Util.null2String(resMsg.get("TGT").toString()); + } else { + //密码不正确,执行强制退出 + if ("2002".equals(resMsg.get("errorCode") + "")) { + out.print("

您的单点系统密码已修改,请重新登录,将在3秒后退出

"); + Thread thread = new Thread(new Runnable() { + @Override + public void run() { + try { + Thread.sleep(3000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + JSONObject postBody = new JSONObject(); + String sysid = Prop.getPropValue("emsysinfo", "sysid"); + postBody.put("sysid", sysid); + postBody.put("userids", user.getUID()); + postBody.put("offline_type", "1"); + postBody.put("client_type", "1,2,3"); + String errmsg = EMExt(getEMToken(), postBody.toJSONString()); + } + }); + thread.start(); + return; + } else { + out.print(resMsg.get("message")); + return; + } + } + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Date now = new Date(); + Date expiresDate = new Date(now.getTime() + (4 * 60 * 60 * 1000)); + request.getSession(true).setAttribute("certified_token_expires", sdf.format(expiresDate));//记录toekn失效日期时间 + request.getSession(true).setAttribute("certified_token", TGT);//记录toekn + + responseInfo = getST(TGT, cockpitUrl, MachInfo); + if (StringUtil.isBlank(responseInfo)) { + out.print("单点系统接口返回值为null"); + return; + } else { + org.json.JSONObject stMsgnew = new org.json.JSONObject(responseInfo); + if (stMsgnew.has("ST")) { + ST = Util.null2String(stMsgnew.get("ST").toString()); + } else { + try { + if (stMsgnew.has("errorCode") && "2009".equals(stMsgnew.getString("errorCode"))) { + response.sendRedirect("https://office.bankoftianjin.com/interface/transfer/mobile/noPermissons2.html"); + } + } catch (JSONException e) { + bb.writeLog(e); + } + out.print(Util.null2String(stMsgnew.getString("message"))); + return; + } + + String loginUrl = ""; + String remuseUrl = sysUrl; + + boolean isEm = Util.null2String(request.getHeader("user-agent")).indexOf("E-Mobile") > -1; + if (1 == 1) { + loginUrl = remuseUrl + "ticket=" + ST; + //loginUrl="http://123.151.115.199:8080/bi/PCFW?proc=1&action=viewer&hback=true&db=%E6%99%BA%E6%85%A7%E6%96%B9%E7%95%A5/%E5%89%8D%E7%BD%AE%E9%A1%B5.db&ticket="+ST; + } + + bb.writeLog("loginUrl-->" + loginUrl); + response.sendRedirect(loginUrl); + } + //----------------------------------TGT未找到--------------------------------------------- + } else { + try { + out.print(Util.null2String(stMsg.getString("message"))); + } catch (org.json.JSONException e) { + e.printStackTrace(); + } + } + } catch (JSONException e) { + bb.writeLog(e); + } + return; + } + + String loginUrl = ""; + // String remuseUrl = bb.getPropValue("tjbkremuse", "hbUrl"); + String remuseUrl = sysUrl; + boolean isEm = Util.null2String(request.getHeader("user-agent")).indexOf("E-Mobile") > -1; + if (1 == 1) { + loginUrl = remuseUrl + "ticket=" + ST; + } + + //loginUrl = "https://www.baidu.com/"; + bb.writeLog("loginUrl-->" + loginUrl); + out.print("跳转路径-->" + loginUrl); + //out.print(loginUrl); + response.sendRedirect(loginUrl); + // request.getRequestDispatcher("loginUrl").forward(request,response); +// return; + } + } else { + bb.writeLog("TGT已失效"); + String TGT = ""; + String passWord = ""; + String retMsg = ""; + decriptList.add(login_id); + decriptList.add(user_password); + List resultList = rsa.decryptList(request, decriptList); + String loginId = resultList.get(0); + String userPassword = resultList.get(1); + String publicKey = getPublicKey(MachInfo); + passWord = encrypt(user_password, publicKey); + params = new HashMap<>();//参数 + params.put("username", loginId); + params.put("password", passWord); + bb.writeLog("==STparams==" + params); + + headers = new HashMap<>();//headers + headers.put("API_KEY", API_KEY); + headers.put("MACH_ID", MachInfo.get("deviceId")); + headers.put("MACH_TYPE", Util.null2String(MachInfo.get("clientType"), "0")); + headers.put("MACH_IP", MachInfo.get("param_ip")); + + + retMsg = httpPostForm(tgturl, params, headers, null); + bb.writeLog("===获取TGT返回值retMsg====" + retMsg); + org.json.JSONObject resMsg = new org.json.JSONObject(retMsg); + bb.writeLog("===获取TGT返回值====" + resMsg); + if (resMsg.has("TGT")) { + TGT = Util.null2String(resMsg.get("TGT").toString()); + } else { + //密码不正确,执行强制退出 + if ("2002".equals(resMsg.get("errorCode") + "")) { + out.print("

您的单点系统密码已修改,请重新登录,将在3秒后退出

"); + Thread thread = new Thread(new Runnable() { + @Override + public void run() { + try { + Thread.sleep(3000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + JSONObject postBody = new JSONObject(); + String sysid = Prop.getPropValue("emsysinfo", "sysid"); + postBody.put("sysid", sysid); + postBody.put("userids", user.getUID()); + postBody.put("offline_type", "1"); + postBody.put("client_type", "1,2,3"); + String errmsg = EMExt(getEMToken(), postBody.toJSONString()); + } + }); + thread.start(); + return; + } else { + out.print(resMsg.get("message")); + return; + } + } + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Date now = new Date(); + Date expiresDate = new Date(now.getTime() + (4 * 60 * 60 * 1000)); + request.getSession(true).setAttribute("certified_token_expires", sdf.format(expiresDate));//记录toekn失效日期时间 + request.getSession(true).setAttribute("certified_token", TGT);//记录toekn + + String responseInfo = getST(TGT, cockpitUrl, MachInfo); + if (StringUtil.isBlank(responseInfo)) { + out.print("单点系统接口返回值为null"); + return; + } else { + org.json.JSONObject stMsg = new org.json.JSONObject(responseInfo); + if (stMsg.has("ST")) { + ST = Util.null2String(stMsg.get("ST").toString()); + } else { + try { + if (stMsg.has("errorCode") && "2009".equals(stMsg.getString("errorCode"))) { + response.sendRedirect("https://office.bankoftianjin.com/interface/transfer/mobile/noPermissons2.html"); + } + } catch (JSONException e) { + bb.writeLog(e); + } + out.print(Util.null2String(stMsg.getString("message"))); + return; + } + String loginUrl = ""; + String remuseUrl = sysUrl; + boolean isEm = Util.null2String(request.getHeader("user-agent")).indexOf("E-Mobile") > -1; + if (1 == 1) { + loginUrl = remuseUrl + "ticket=" + ST; + } + bb.writeLog("loginUrl-->" + loginUrl); + response.sendRedirect(loginUrl); + } + + + } + +%> + +  diff --git a/weaver/filter/LoginEMFilter.java b/weaver/filter/LoginEMFilter.java index 42c2158..32cc85f 100644 --- a/weaver/filter/LoginEMFilter.java +++ b/weaver/filter/LoginEMFilter.java @@ -110,7 +110,7 @@ public class LoginEMFilter implements Filter { Date currentDate = new Date(); long difference = currentDate.getTime() - parsedDate.getTime(); - if (difference > 2 * 60 * 1000) { // 10分钟 = 10 * 60 * 1000 毫秒 + if (difference > 5 * 60 * 1000) { // 10分钟 = 10 * 60 * 1000 毫秒 return true; } else { return false;