pboc个人单笔查询代码初始化

This commit is contained in:
zhanglei 2023-02-06 11:52:26 +08:00 committed by stone
parent 893ddfebe7
commit f54916c975
18 changed files with 55411 additions and 2 deletions

View File

@ -204,7 +204,8 @@ public boolean validUserPassword(HttpServletRequest request, Transaction Sqlca,S
<%
String sPWDState = new UserMarkInfo(Sqlca,CurUser.getUserID()).getPasswordState();
// 开发模式不做首次登录/密码过期校验
if(sPWDState.equals(String.valueOf(SecurityAuditConstants.CODE_USER_FIRST_LOGON)) || sPWDState.equals(String.valueOf(SecurityAuditConstants.CODE_PWD_OVERDUE))){
// if(sPWDState.equals(String.valueOf(SecurityAuditConstants.CODE_USER_FIRST_LOGON)) || sPWDState.equals(String.valueOf(SecurityAuditConstants.CODE_PWD_OVERDUE))){
if(false){
%>
window.open("<%=CurConfig.getContextPath() %>/Redirector?ComponentURL=/AppMain/ModifyPassword.jsp", "_top");
<%

View File

@ -5,7 +5,7 @@
type="javax.sql.DataSource" maxActive="30" maxIdle="2" maxWait="10000"
username="apzl" password="apzl@2018"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://47.93.34.101:3306/apzl?rewriteBatchedStatements=true&amp;useUnicode=true&amp;characterEncoding=GBK&amp;autoReconnectForPools=true&amp;autoReconnect=true&amp;useSSL=false" />
url="jdbc:mysql://47.93.34.101:10323/apzl?rewriteBatchedStatements=true&amp;useUnicode=true&amp;characterEncoding=GBK&amp;autoReconnectForPools=true&amp;autoReconnect=true&amp;useSSL=false" />
<!-- 18测试环境 -->
<!-- <Resource name="jdbc/als" auth="Container" type="javax.sql.DataSource"
maxActive="30" maxIdle="2" maxWait="10000" username="apzl" password="apzl@2018"

View File

@ -0,0 +1,156 @@
<%@page import="com.itextpdf.text.log.SysoCounter"%>
<%@page import="java.util.Map.Entry"%>
<%@page import="com.alibaba.fastjson.JSONArray"%>
<%@page import="com.alibaba.fastjson.JSON"%>
<%@page import="com.alibaba.fastjson.JSONObject"%>
<%@page import="com.tenwa.httpclient.controller.BigDataController"%>
<%@page import="java.util.Date"%>
<%@page import="com.tenwa.util.SerialNumberUtil"%>
<%@ page import="com.tenwa.httpclient.controller.PbocDataController" %>
<%@ page contentType="text/html; charset=GBK"%>
<%@include file="/IncludeBegin.jsp"%><%
String flowunid = CurPage.getParameter("ObjectNo");
String projectId = CurPage.getParameter("ProjectId");//流程编号
String projectNo = CurPage.getParameter("ProjectNo");
String ReadyApprove = CurPage.getParameter("ReadyApprove");
String applyId = "";
String getType = CurPage.getParameter("GetType");
String type = "";
String count = "";
String reasonDesc = "";
PbocDataController bdc = new PbocDataController();
boolean flag = true;
String result = bdc.findDataApplyId(CurPage, "pboc_af", Sqlca);
if("GET".equals(getType)) {
if("false".equals(result)) {
%>
<%--<script type="text/javascript" src="<%=sWebRootPath %>/Frame/page/js/as_debug_message.js"></script>--%>
<%--<script type="text/javascript">--%>
<%--alert("该用户没有对应的详情信息!");--%>
<%--$(document).ready(function (){--%>
<%--AsControl.OpenView("/Tenwa/Lease/Flow/Comm/BigdataPboc/query_report/pbocdataList.jsp", "FlowUnid=<%=flowunid%>&ProjectId=<%=projectId%>","_self","");--%>
<%--})--%>
<%--</script>--%>
<%
// return ;
} else {
String[] res = result.split("@");
applyId = res[1];
count = res[2];
type = "GET";
}
} else {
if("false".equals(result)) {
JBOTransaction tx = JBOFactory.createJBOTransaction();
applyId = SerialNumberUtil.getPengyuanNumber(tx);
tx.commit();
type = "SAVE";
} else {
String[] res = result.split("@");
applyId = res[1];
count = res[2];
type = "GET";
}
}
// TODO: 2023/1/31 征信参数整理
Map<String,String> params = new HashMap<String,String>(); //初始化参数
params.put("queryType","25136");
params.put("name",CurPage.getParameter("fullName"));
params.put("documentNo",CurPage.getParameter("fullcertId"));
params.put("phone",CurPage.getParameter("fullphone"));
params.put("queryReasonID","101");
params.put("subreportIDs","96100");
params.put("refID","");
FileInputStream fr = null;
BufferedReader br = null;
try {
String htmlURL = bdc.findAndSavePbocData(params, "pboc_af", Sqlca, type, applyId, CurPage);
File file = new File(htmlURL);
fr = new FileInputStream(file);
br = new BufferedReader(new InputStreamReader(fr, "UTF-8"));
String str;
while((str = br.readLine()) != null) {
String html = str;
if(html.indexOf("viewReport_data") != -1) {
html = html.replaceAll("viewReport_data", "Tenwa/Lease/Flow/Comm/BigdataPboc/query_report/viewReport_data");
}
// if(html.indexOf(".png") != -1 || html.indexOf(".jpg") != -1) {
// html = html.replaceAll("image/image_\\d+[.]", "Tenwa/Lease/Flow/Comm/BigdataPboc/query_report/image/image.");
// }
// if(html.indexOf(".png") != -1 || html.indexOf(".jpg") != -1) {
// html = html.replaceAll("image/image_", "Tenwa/Lease/Flow/Comm/BigdataPboc/query_report/image/image_");
// }
// if(html.indexOf("width=\"95%\"") != -1) {
// html = html.replaceAll("width=\"95%\"", "");
// }
// if(html.indexOf("height=\"70\"") != -1) {
// html = html.replaceAll("height=\"70\"", "");
// }
// if(html.indexOf("width=\"103\"") != -1) {
// html = html.replaceAll("width=\"103\"", "");
// }
// if(html.indexOf("<td>个人反欺诈分析报告</td>") != -1) {
// html = html.replaceAll("<td>个人反欺诈分析报告</td>", "<td><a style=\"position:absolute;left:0;top:8%\" title=\"拉取鹏元数据\" onClick=\"returnList();\" class=\"inline_button \" hidefocus=\"\" href=\"#\"><span style=\"display:none;\"></span><span class=\"left\">&nbsp;</span><span class=\"center\"><span class=\"btn_icon btn_icon_edit\">&nbsp;</span><span class=\"btn_text\">返回</span></span><span class=\"right\">&nbsp;</span></a>个人信用报告</td>");
// }
if(html.indexOf("<body>") != -1) {
html = html.replaceAll("<body", "<body style=\"overflow:scroll;height:95%\" ");
}
// if(html.indexOf("<table class=\"report\" align=\"center\">") != -1) {
// html = html.replaceAll("<table class=\"report\" align=\"center\">", "<table class=\"report\" align=\"center\" style=\"width:99%\">");
// }
%>
<%=html%>
<%}
System.out.println("------------------鹏元-个人反欺诈解析结束时间----------------------");
System.out.println("");
System.out.println("");
System.out.println("------------------"+StringFunction.getTodayNow()+"----------------------");
System.out.println("");
System.out.println("");
System.out.println("------------------鹏元-个人反欺诈解析结束时间----------------------");
//查询获取数据次数
if("SAVE".equals(type)) {
String res = bdc.findDataApplyId(CurPage, "pengyuan_af", Sqlca);
if("false".equals(res)) {
count = "0";
} else {
count = res.split("@")[2];
}
}
} catch(Exception e) {
e.printStackTrace();
flag = false;
reasonDesc = e.getMessage();
Sqlca.rollback();
%>
<script type="text/javascript" src="<%=sWebRootPath %>/Frame/page/js/as_debug_message.js"></script>
<script type="text/javascript">
alert("获取数据失败");
$(document).ready(function (){
AsControl.OpenView("/Tenwa/Lease/Flow/Comm/BigdataPboc/query_report/pbocdataList.jsp", "FlowUnid=<%=flowunid%>&ProjectId=<%=projectId%>","_self","");
})
</script>
<%
} finally {
if(br != null) br.close();
if(fr != null) fr.close();
}
%>
<script type="text/javascript">
function getData() {
if('<%=ReadyApprove%>'=='ReadOnly'){
alert("查询页面不允许获取大数据");
return;
}
if("<%=count%>" == "done") {
alert("已达到获取数据次数上限");
} else {
location.href = location.href.indexOf("&GetType=GET") == -1 ? location.href + "&GetType=GET&Count=<%=count%>" : location.href.substring(0, location.href.indexOf("&GetType=GET")) + "&GetType=GET&Count=<%=count%>";
}
}
function returnList(){
AsControl.OpenView("/Tenwa/Lease/Flow/Comm/BigdataPboc/query_report/pbocdataList.jsp", "FlowUnid=<%=flowunid%>&ProjectId=<%=projectId%>","_self","");
}
</script>
<%@include file="/IncludeEnd.jsp"%>

View File

@ -0,0 +1,156 @@
<%@page import="com.itextpdf.text.log.SysoCounter"%>
<%@page import="java.util.Map.Entry"%>
<%@page import="com.alibaba.fastjson.JSONArray"%>
<%@page import="com.alibaba.fastjson.JSON"%>
<%@page import="com.alibaba.fastjson.JSONObject"%>
<%@page import="com.tenwa.httpclient.controller.BigDataController"%>
<%@page import="java.util.Date"%>
<%@page import="com.tenwa.util.SerialNumberUtil"%>
<%@ page import="com.tenwa.httpclient.controller.PbocDataController" %>
<%@ page contentType="text/html; charset=GBK"%>
<%@include file="/IncludeBegin.jsp"%><%
String flowunid = CurPage.getParameter("ObjectNo");
String projectId = CurPage.getParameter("ProjectId");//流程编号
String projectNo = CurPage.getParameter("ProjectNo");
String ReadyApprove = CurPage.getParameter("ReadyApprove");
String applyId = "";
String getType = CurPage.getParameter("GetType");
String type = "";
String count = "";
String reasonDesc = "";
PbocDataController bdc = new PbocDataController();
boolean flag = true;
String result = bdc.findDataApplyId(CurPage, "pboc_af", Sqlca);
if("GET".equals(getType)) {
if("false".equals(result)) {
%>
<%--<script type="text/javascript" src="<%=sWebRootPath %>/Frame/page/js/as_debug_message.js"></script>--%>
<%--<script type="text/javascript">--%>
<%--alert("该用户没有对应的详情信息!");--%>
<%--$(document).ready(function (){--%>
<%--AsControl.OpenView("/Tenwa/Lease/Flow/Comm/BigdataPboc/query_report/pbocdataList.jsp", "FlowUnid=<%=flowunid%>&ProjectId=<%=projectId%>","_self","");--%>
<%--})--%>
<%--</script>--%>
<%
// return ;
} else {
String[] res = result.split("@");
applyId = res[1];
count = res[2];
type = "GET";
}
} else {
if("false".equals(result)) {
JBOTransaction tx = JBOFactory.createJBOTransaction();
applyId = SerialNumberUtil.getPengyuanNumber(tx);
tx.commit();
type = "SAVE";
} else {
String[] res = result.split("@");
applyId = res[1];
count = res[2];
type = "GET";
}
}
// TODO: 2023/1/31 征信参数整理
Map<String,String> params = new HashMap<String,String>(); //初始化参数
params.put("queryType","25136");
params.put("name",CurPage.getParameter("fullName"));
params.put("documentNo",CurPage.getParameter("fullcertId"));
params.put("phone",CurPage.getParameter("fullphone"));
params.put("queryReasonID","101");
params.put("subreportIDs","96100");
params.put("refID","");
FileInputStream fr = null;
BufferedReader br = null;
try {
String htmlURL = bdc.findAndSavePbocData(params, "pboc_af", Sqlca, type, applyId, CurPage);
File file = new File(htmlURL);
fr = new FileInputStream(file);
br = new BufferedReader(new InputStreamReader(fr, "UTF-8"));
String str;
while((str = br.readLine()) != null) {
String html = str;
if(html.indexOf("viewReport_data") != -1) {
html = html.replaceAll("viewReport_data", "Tenwa/Lease/Flow/Comm/BigdataPboc/query_report/viewReport_data");
}
// if(html.indexOf(".png") != -1 || html.indexOf(".jpg") != -1) {
// html = html.replaceAll("image/image_\\d+[.]", "Tenwa/Lease/Flow/Comm/BigdataPboc/query_report/image/image.");
// }
// if(html.indexOf(".png") != -1 || html.indexOf(".jpg") != -1) {
// html = html.replaceAll("image/image_", "Tenwa/Lease/Flow/Comm/BigdataPboc/query_report/image/image_");
// }
// if(html.indexOf("width=\"95%\"") != -1) {
// html = html.replaceAll("width=\"95%\"", "");
// }
// if(html.indexOf("height=\"70\"") != -1) {
// html = html.replaceAll("height=\"70\"", "");
// }
// if(html.indexOf("width=\"103\"") != -1) {
// html = html.replaceAll("width=\"103\"", "");
// }
// if(html.indexOf("<td>个人反欺诈分析报告</td>") != -1) {
// html = html.replaceAll("<td>个人反欺诈分析报告</td>", "<td><a style=\"position:absolute;left:0;top:8%\" title=\"拉取鹏元数据\" onClick=\"returnList();\" class=\"inline_button \" hidefocus=\"\" href=\"#\"><span style=\"display:none;\"></span><span class=\"left\">&nbsp;</span><span class=\"center\"><span class=\"btn_icon btn_icon_edit\">&nbsp;</span><span class=\"btn_text\">返回</span></span><span class=\"right\">&nbsp;</span></a>个人信用报告</td>");
// }
if(html.indexOf("<body>") != -1) {
html = html.replaceAll("<body", "<body style=\"overflow:scroll;height:95%\" ");
}
// if(html.indexOf("<table class=\"report\" align=\"center\">") != -1) {
// html = html.replaceAll("<table class=\"report\" align=\"center\">", "<table class=\"report\" align=\"center\" style=\"width:99%\">");
// }
%>
<%=html%>
<%}
System.out.println("------------------鹏元-个人反欺诈解析结束时间----------------------");
System.out.println("");
System.out.println("");
System.out.println("------------------"+StringFunction.getTodayNow()+"----------------------");
System.out.println("");
System.out.println("");
System.out.println("------------------鹏元-个人反欺诈解析结束时间----------------------");
//查询获取数据次数
if("SAVE".equals(type)) {
String res = bdc.findDataApplyId(CurPage, "pengyuan_af", Sqlca);
if("false".equals(res)) {
count = "0";
} else {
count = res.split("@")[2];
}
}
} catch(Exception e) {
e.printStackTrace();
flag = false;
reasonDesc = e.getMessage();
Sqlca.rollback();
%>
<script type="text/javascript" src="<%=sWebRootPath %>/Frame/page/js/as_debug_message.js"></script>
<script type="text/javascript">
alert("获取数据失败");
$(document).ready(function (){
AsControl.OpenView("/Tenwa/Lease/Flow/Comm/BigdataPboc/query_report/pbocdataList.jsp", "FlowUnid=<%=flowunid%>&ProjectId=<%=projectId%>","_self","");
})
</script>
<%
} finally {
if(br != null) br.close();
if(fr != null) fr.close();
}
%>
<script type="text/javascript">
function getData() {
if('<%=ReadyApprove%>'=='ReadOnly'){
alert("查询页面不允许获取大数据");
return;
}
if("<%=count%>" == "done") {
alert("已达到获取数据次数上限");
} else {
location.href = location.href.indexOf("&GetType=GET") == -1 ? location.href + "&GetType=GET&Count=<%=count%>" : location.href.substring(0, location.href.indexOf("&GetType=GET")) + "&GetType=GET&Count=<%=count%>";
}
}
function returnList(){
AsControl.OpenView("/Tenwa/Lease/Flow/Comm/BigdataPboc/query_report/pbocdataList.jsp", "FlowUnid=<%=flowunid%>&ProjectId=<%=projectId%>","_self","");
}
</script>
<%@include file="/IncludeEnd.jsp"%>

View File

@ -0,0 +1,60 @@
<%@ page contentType="text/html; charset=GBK"%>
<%@ include file="/Frame/resources/include/include_begin_list.jspf"%><%
/*
Author: undefined 2019-06-14
Content:
History Log:
*/
String sFlowUnid = CurPage.getParameter("FlowUnid");//流程编号
String ProjectId = CurPage.getParameter("ProjectId");//流程编号
String SubjectId = CurPage.getParameter("SubjectId");//主体编号
String flag = "true";
/* String flowunid = CurPage.getParameter("ObjectNo");
String projectNo = CurPage.getParameter("ProjectNo");
String ReadyApprove = CurPage.getParameter("ReadyApprove");
String getType = CurPage.getParameter("GetType"); */
ASObjectModel doTemp = new ASObjectModel("VI_LB_IDENTITY_CHECK");
ASObjectWindow dwTemp = new ASObjectWindow(CurPage,doTemp,request);
dwTemp.Style="1"; //--设置为Grid风格--
dwTemp.ReadOnly = "1"; //只读模式
dwTemp.setPageSize(10);
dwTemp.genHTMLObjectWindow(sFlowUnid);
//0、是否展示 1、 权限控制 2、 展示类型 3、按钮显示名称 4、按钮解释文字 5、按钮触发事件代码 6、 7、 8、 9、图标CSS层叠样式 10、风格
String sButtons[][] = {
{"true","All","Button","拉取征信数据","拉取征信数据","newRecord()","","","","btn_icon_add",""},
{flag,"","Button","详情","查看详情","detail()","","","","btn_icon_detail",""},
// {"true","","Button","详情","详情","viewAndEdit()","","","","btn_icon_detail",""},
// {"true","","Button","删除","删除","if(confirm('确实要删除吗?'))as_delete(0,'alert(getRowCount(0))')","","","","btn_icon_delete",""},
};
%><%@include file="/Frame/resources/include/ui/include_list.jspf"%>
<script type="text/javascript">
$(function(){
var projectId = "<%=ProjectId%>";
/* if(null == projectId || "" == projectId || "null" == projectId){
location.reload();
} */
})
function request(getType){
var sUrl = "/Tenwa/Lease/Flow/Comm/BigdataPboc/query_report/pbocdata.jsp";
var fullName = getItemValue(0,getRow(0),'fullName');
var fullcertId = getItemValue(0,getRow(0),'certId');
var fullrelation = getItemValue(0,getRow(0),'relation');
var fullphone = getItemValue(0,getRow(0),'phone');
var params = 'ProjectId='+'<%=ProjectId%>'+'&fullName='+fullName+'&fullcertId='+fullcertId+'&fullrelation='+fullrelation+'&fullphone='+fullphone+'&GetType='+getType+'&SubjectId='+'<%=SubjectId%>';
AsControl.OpenView(sUrl,params,'_self','');
}
function newRecord(){
var getType = "SAVE";
request(getType);
}
function detail(){
var getType = "GET";
request(getType);
}
</script>
<%@ include file="/Frame/resources/include/include_end.jspf"%>

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

View File

@ -0,0 +1,51 @@
$(function(){
//pageInit();
});
function pageInit(){
var pPageWidth = 794; //打印时的A4完整宽度96dpi
var pPageHeight = $(document).height();
var pContentwidth = 720; //打印时的内容宽度96dpi,同步css
var A4Heigth = 1123; //A4纸的高度px96dip。固定值
var markBox = $('<div class="u-wmarkbox"/>').css("cssText","width:auto!important;width:".concat(pPageWidth,"px;min-width:",pPageWidth,"px")).css({
"display":"none",
"position": "absolute",
"top": 0,
"left": 0,
"height": pPageHeight.toString(10).concat("px"), //pPageHeight, 100%
"backgroundColor": "#FFF",
"overflow": "hidden",
"zIndex": 1
});
var wmimg = new Image();
wmimg.onload = function(){repeatwmimg(this);}
wmimg.src = '../../images/pbccrc_watermark2.gif';
function repeatwmimg(oimg){
var imgwidth = oimg.width;
var imgheight = oimg.height;
//获得水印图片高度后重置
//这里应该还要加上打印时每一页的上下边距4cm(同步css)≈72px(96dpi)
//var wmHeight = Math.ceil(pPageHeight / A4Heigth) * A4Heigth;
//var wmHeight = Math.ceil(pPageHeight / A4Heigth) * (A4Heigth + 145);
var wmHeight = Math.ceil(pPageHeight / A4Heigth) * A4Heigth;
markBox.css("height", wmHeight.toString(10).concat("px"));
var hi = Math.ceil(pPageWidth / imgwidth);
var vi = Math.ceil(wmHeight / imgheight);
for(var i = 0; i < vi; i++){
var vidiv = $('<div class="u-row"/>').css({
"width": (imgwidth * hi).toString(10).concat("px"),
"height": imgheight.toString(10).concat("px")
});
for(var j = 0; j < hi; j++){
vidiv.append($(oimg).clone(false).css({"display":"block","float":"left","border":"none"}));
}
vidiv.appendTo(markBox);
}
markBox.prependTo("body");
};
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,121 @@
package com.tenwa.reckon.executor;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;
import com.tenwa.app.manage.qiyuesuo.v2.ContractSignVtwoUtils;
import jbo.app.tenwa.calc.LC_CALC_CONDITION;
import jbo.app.tenwa.calc.LC_RENT_INCOME;
import jbo.app.tenwa.calc.LC_RENT_PLAN;
import jbo.com.tenwa.lease.comm.LC_CAR_DISPOSE;
import jbo.com.tenwa.lease.comm.LC_OCCUPY_RENT_LIST;
import com.amarsoft.app.awe.config.InitDBType;
import com.amarsoft.are.jbo.BizObject;
import com.amarsoft.are.jbo.BizObjectManager;
import com.amarsoft.are.jbo.BizObjectQuery;
import com.amarsoft.are.jbo.JBOException;
import com.amarsoft.are.jbo.JBOFactory;
import com.amarsoft.are.jbo.JBOTransaction;
import com.amarsoft.are.util.json.JSONEncoder;
import com.amarsoft.are.util.json.JSONObject;
import com.tenwa.reckon.util.Conn;
import com.tenwa.reckon.util.DateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* 合同测算校验
* @author tenwapc
*
*/
public class RentCalculateExecutor {
private static final Logger logger = LoggerFactory.getLogger(RentCalculateExecutor.class);
private String contractId;
private String startList;
private String paydayAdjust;
private String paymentnumber;
private String planId;
/**
* 校验中止日期是否合法
* @return
* @throws Exception
*/
public String checkPaydayAdjust() throws Exception {
JSONObject jsonObject = JSONObject.createObject();
JBOTransaction tx=null;
try{
tx=JBOFactory.createJBOTransaction();
String checkSql = " select min(plan_date) mindate from LC_RENT_PLAN where contract_id = ? and payment_number=?";
Conn conn = new Conn(tx);
List<Map<String, String>> results = conn.executeQuery(checkSql, this.contractId,this.getPaymentnumber());
String mindate = results.get(0).get("mindate");
logger.info("20211104 校验中止日期是否合法 mindate= " + mindate);
logger.info("20211104 校验中止日期是否合法 paydayAdjust= " + this.paydayAdjust);
//截取最后两位 字符串
String minDateStr = mindate.substring(mindate.lastIndexOf("/") + 1);
String paydayAdjustStr = this.paydayAdjust.substring(this.paydayAdjust.lastIndexOf("/") + 1);
logger.info("20211104 校验中止日期是否合法 minDateStr= " + minDateStr);
logger.info("20211104 校验中止日期是否合法 paydayAdjustStr= " + paydayAdjustStr);
if(minDateStr.equals(paydayAdjustStr)){
jsonObject.appendElement("result", "false");
jsonObject.appendElement("msg","约定终止日不能落在已汇款的租金计划的区间段!!!");
}else {
jsonObject.appendElement("result", "true");
}
}catch(Exception e){
tx.rollback();
e.printStackTrace();
jsonObject.appendElement("result", "false");
jsonObject.appendElement("msg","服务器正忙,请稍后再试!!!");
}finally{
tx.commit();
}
return JSONEncoder.encode(jsonObject);
}
public String getContractId() {
return contractId;
}
public void setContractId(String contractId) {
this.contractId = contractId;
}
public String getStartList() {
return startList;
}
public void setStartList(String startList) {
this.startList = startList;
}
public String getPaydayAdjust() {
return paydayAdjust;
}
public void setPaydayAdjust(String paydayAdjust) {
this.paydayAdjust = paydayAdjust;
}
public String getPaymentnumber() {
return paymentnumber;
}
public void setPaymentnumber(String paymentnumber) {
this.paymentnumber = paymentnumber;
}
public String getPlanId() {
return planId;
}
public void setPlanId(String planId) {
this.planId = planId;
}
}

View File

@ -0,0 +1,458 @@
package com.tenwa.httpclient.controller;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.amarsoft.are.ARE;
import com.amarsoft.are.util.StringFunction;
import com.amarsoft.awe.Configure;
import com.amarsoft.awe.control.model.Page;
import com.amarsoft.awe.util.ASResultSet;
import com.amarsoft.awe.util.SqlObject;
import com.amarsoft.awe.util.Transaction;
import com.tenwa.comm.exception.BusinessException;
import com.tenwa.httpclient.pboc.FileUtils;
import com.tenwa.httpclient.pboc.HttpUtils;
import com.tenwa.httpclient.pboc.PbocXmlUtils;
import com.tenwa.httpclient.resources.BigDataPropertiesUtil;
import com.tenwa.reckon.util.UUIDUtil;
import org.dom4j.Element;
import org.dom4j.tree.DefaultAttribute;
import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class PbocDataController {
/**
* 查询是否存在当前的用户的征信记录
* @param CurPage
* @param type
* @param Sqlca
* @return
* @throws Exception
*/
public String findDataApplyId(Page CurPage, String type, Transaction Sqlca) throws Exception {
String count = BigDataPropertiesUtil.get("count");
String sql = "select max(id) applyid, count(1) cou from bigdata_" + type + " where fullname='"+CurPage.getParameter("fullName")
+"' and fullcertId='"+CurPage.getParameter("fullcertId")+"' and fullphone='"+CurPage.getParameter("fullphone")+"' and {keyword} group by {gkeyword}";
StringBuffer keyword = new StringBuffer("");
StringBuffer gkeyword = new StringBuffer("");
String FlowNo = "";
for(int i = 1; i <= 5; i ++) {
String key = BigDataPropertiesUtil.get("keyword" + i);
String keyValue = CurPage.getParameter(key);
FlowNo = CurPage.getParameter("FlowNo");
if(key == null || keyValue == null) {
continue;
}
if(keyword.length() != 0) {
keyword.append(" and ");
gkeyword.append(",");
}
keyword.append("keyword").append(i).append("='").append(keyValue).append("'");
gkeyword.append("keyword").append(i);
}
// TODO: 2023/1/31 ExceedTimLlimitApply 这是啥玩意
if("ExceedTimLlimitApply".equals(FlowNo)&&keyword.length() != 0 ){
keyword.append(" and keyword3").append("='").append(FlowNo).append("'");
}else{
keyword.append(" and keyword3 is null");
}
sql = sql.replaceAll("\\{keyword\\}", keyword.length() == 0 ? "" : keyword.toString()).replaceAll("\\{gkeyword\\}", gkeyword.length() == 0 ? "" : gkeyword.toString());
ARE.getLog().info("======================sql========================================================");
ARE.getLog().info("======================"+sql+"========================================================");
ARE.getLog().info("======================sql========================================================");
ASResultSet rs = Sqlca.getASResultSet(new SqlObject(sql));
String result = "";
if(rs.next()) {
result = "true@" + rs.getString("applyid") + (rs.getString("cou").equals(count) ? "@done" : "@" + rs.getString("cou"));
} else {
result = "false";
}
ARE.getLog().info("======================result========================================================");
ARE.getLog().info("======================"+result+"========================================================");
ARE.getLog().info("======================result========================================================");
return result;
}
public String findAndSavePbocData(Map<String, String> params, String table, Transaction Sqlca, String actionType, String applyId, Page CurPage) throws Exception {
return this.getAndSavePengyuanData(params, table, Sqlca, actionType, applyId, CurPage, null);
}
public String getAndSavePengyuanData(Map<String, String> params, String table, Transaction Sqlca, String actionType, String applyId, Page CurPage, Map<String, String> id) throws Exception {
String type = "html";
ARE.getLog().info("------------------鹏元("+table+")拉取时间----------------------");
ARE.getLog().info("");
ARE.getLog().info("");
ARE.getLog().info("------------------"+ StringFunction.getTodayNow()+"----------------------");
ARE.getLog().info("");
ARE.getLog().info("");
ARE.getLog().info("------------------鹏元("+table+")拉取时间----------------------");
// if("GET".equals(actionType)) {
// if(id != null) {
// id.put("applyId", applyId);
// }
// htmlFile = Sqlca.getString(new SqlObject("select html_data from bigdata_" + table + " where id = '" + applyId + "'"));
// return htmlFile == null ? "" : htmlFile;
// }
Connection conn = Sqlca.getConnection(Sqlca);
// TODO: 2023/2/1 本地测试暂用
@SuppressWarnings("deprecation")
Configure configure = Configure.getInstance();
String fileSavePath = configure.getParameter("FileSavePath") + "/" + "pengyuan" + "/";
// String fileSavePath = "E:\\data";
String FlowNo = CurPage.getParameter("FlowNo");
String fullcardNo = CurPage.getParameter("fullcardNo");
if(fullcardNo==null||"".equals(fullcardNo)){fullcardNo="default";}
// TODO: 2023/2/1 生成pboc个人单笔查询请求参数
String personQueryParamStr = PbocXmlUtils.createPersonQueryParamStr(params, CurPage.getAttribute("SubjectId").toString());
type = "xml";
PreparedStatement ps = null;
try {
ps = conn.prepareStatement("update bigdata_" + table + "_log set " + type + "_url = ?, " + type + "_param = ? where apply_id = ?");
ps.setString(1, BigDataPropertiesUtil.get("pengyuanUrl"));
ps.setString(2, personQueryParamStr + "," + BigDataPropertiesUtil.get("user") + "," + BigDataPropertiesUtil.get("password") + "," + type);
ps.setString(3, applyId);
ps.execute();
} catch(Exception e) {
e.printStackTrace();
ARE.getLog().error("数据存储 bigdata_" + table + "_log 失败: ", e);
throw new BusinessException("数据存储失败");
} finally {
if(ps != null) ps.close();
}
ARE.getLog().info("==================" + table + "@" + type + "获取数据====================");
String resXMLReport = this.findQueryReport(personQueryParamStr, type, CurPage.getAttribute("SubjectId").toString());
ARE.getLog().info("==================" + table + "@" + type + "获取数据====================");
JSONObject resJson = PbocXmlUtils.toJson(resXMLReport);
JSONObject serviceDataJson = resJson.getJSONObject("service");
JSONObject msgHeadData = serviceDataJson.getJSONObject("msgHead");
JSONObject msgBodyData = serviceDataJson.getJSONObject("msgBody");
String reportId = msgHeadData.getString("resJnlId");
String htmlRptDataStr = msgBodyData.getString("htmlRpt");
String xmlFilePath = FileUtils.createXMLFile(fileSavePath, reportId, resXMLReport);
String htmlFilePath = FileUtils.createHtmlFile(fileSavePath,reportId, htmlRptDataStr);
ARE.getLog().info(htmlFilePath);
ARE.getLog().info(xmlFilePath);
StringBuffer keyword = new StringBuffer();
StringBuffer keywordValue = new StringBuffer();
for(int i = 1; i <= 5; i ++) {
String key = BigDataPropertiesUtil.get("keyword" + i);
String keyValue = CurPage.getParameter(key);
if(key == null || keyValue == null) {
continue;
}
if(keyword.length() != 0) {
keyword.append(",");
keywordValue.append(",");
}
keyword.append("keyword").append(i);
keywordValue.append("'").append(keyValue).append("'");
}
if("ExceedTimLlimitApply".equals(FlowNo)&&keyword.length() != 0){
keyword.append(",keyword3");
keywordValue.append(",'"+FlowNo+"'");
}
SqlObject sql = new SqlObject(("insert into bigdata_" + table + " (id," + keyword.toString() + ",xml_data,html_data,"
+ "inputuserid,inputorgid,inputtime,fullName,fullcertId,fullphone,fullcardNo) values('" + applyId + "'," + keywordValue.toString() + ",'"
+ xmlFilePath + "','" + htmlFilePath + "','" + CurPage.getUserId() + "','" + CurPage.getUser().getOrgID() + "','" + StringFunction.getTodayNow() +"','"
+CurPage.getParameter("fullName")+"','"+CurPage.getParameter("fullcertId")+"','"+CurPage.getParameter("fullphone")+"','"+fullcardNo+"')").replaceAll(":", ""));
sql.setDebugSql(sql.getDebugSql().replaceAll("", ":"));
sql.setOriginalSql(sql.getOriginalSql().replaceAll("", ":"));
sql.setRunSql(sql.getRunSql().replaceAll("", ":"));
ARE.getLog().error("****************************鹏元大数据************************");
String insertsql =sql.getOriginalSql();
ARE.getLog().error(insertsql);
ARE.getLog().error("****************************鹏元大数据************************");
Sqlca.executeSQL(sql);
return htmlFilePath;
}
public String findQueryReport(String params, String type, String SubjectId) throws Exception {
ARE.getLog().info("========================鹏元请求参数==================");
ARE.getLog().info(params);
ARE.getLog().info("========================鹏元请求参数==================");
String result = "";
try{
String url = "http://9.35.68.228:9090/pbcrs/api/msgDispatchController/postProcess";
result = HttpUtils.sendPost(url, params);
} catch(Exception e) {
e.printStackTrace();
throw new BusinessException("获取大数据失败");
}
return result;
}
@SuppressWarnings("unchecked")
public static void savePengyuanResultData(JSONObject dataType, Element parentElement, String elementName, Statement stat, Map<String, String> otherFields, Map<String, String> dateFields, List<String> stringFields) throws Exception {
Element element = parentElement.element(elementName);
if(element == null ){
return ;
}
JSONObject obj = new JSONObject();
List<DefaultAttribute> praAttributes = element.attributes();
for(DefaultAttribute praAttribute : praAttributes) {
obj.put(praAttribute.getName(), praAttribute.getStringValue().trim());
}
if(!obj.isEmpty()) {
stat.execute(getInsertSql(obj, "bigdata_py_result", null, otherFields, true, dateFields, stringFields));
otherFields.put("RESULT_ID", otherFields.remove("ID"));
}
savePengyuanResultSubTable(dataType, element, stat, otherFields, dateFields, stringFields);
otherFields.remove("RESULT_ID");
}
@SuppressWarnings("unchecked")
public static void savePengyuanResultSubTable(JSONObject dataType, Element parentElement, Statement stat, Map<String, String> otherFields, Map<String, String> dateFields, List<String> stringFields) throws SQLException {
if(dataType != null) {
JSONObject obj = null;
if("table".equals(dataType.get("type"))) {
List<String> fieldList = (List<String>)dataType.get("field");
obj = new JSONObject();
for(String field : fieldList) {
Element fieldElement = parentElement.element(field);
if(fieldElement != null) {
obj.put(fieldElement.getName(), fieldElement.getStringValue().trim());
}
}
if(!obj.isEmpty()) {
stat.execute(getInsertSql(obj, dataType.getString("tableName"), null, otherFields, true, dateFields, stringFields));
otherFields.remove("ID");
}
} else if("arrayTable".equals(dataType.get("type"))) {
List<String> fieldList = (List<String>)dataType.get("field");
List<Element> items = parentElement.elements("item");
if(items != null) {
for(Element el : items) {
obj = new JSONObject();
for(String field : fieldList) {
Element fieldElement = el.element(field);
if(fieldElement != null) {
obj.put(fieldElement.getName(), fieldElement.getStringValue().trim());
}
}
if(!obj.isEmpty()) {
stat.execute(getInsertSql(obj, dataType.getString("tableName"), null, otherFields, true, dateFields, stringFields));
otherFields.remove("ID");
}
}
}
} else {
JSONArray subTable = dataType.getJSONArray("subTable");
if(subTable != null) {
for(int i = 0; i < subTable.size(); i ++) {
JSONObject subObject = subTable.getJSONObject(i);
Element subElement = parentElement.element(subObject.getString("name"));
if(subElement != null) {
savePengyuanResultSubTable(subObject, subElement, stat, otherFields, dateFields, stringFields);
}
}
}
}
}
}
public static void saveDetail(JSONObject obj, String dataName, String tableName, String tableListName,
List<String> excludeFields, Map<String, String> detailOtherFields, Map<String, String> arrayOtherFields, Statement stat) throws SQLException {
excludeFields.clear();
excludeFields.add(dataName.toUpperCase());
stat.execute(getInsertSql(obj, tableName, excludeFields, detailOtherFields));
arrayOtherFields.put("PID", detailOtherFields.remove("ID"));
JSONArray array = obj.getJSONArray(dataName);
if(array != null) {
for(int k = 0; k < array.size(); k ++) {
stat.execute(getInsertSql(array.getJSONObject(k), tableListName, excludeFields, arrayOtherFields));
arrayOtherFields.remove("ID");
}
}
}
public static void saveDetailData(JSONObject obj, String dataName, String tableName, String tableListName,
List<String> excludeFields, Map<String, String> detailOtherFields, Map<String, String> arrayOtherFields, Statement stat) throws SQLException {
excludeFields.clear();
excludeFields.add(dataName.toUpperCase());
excludeFields.add("DATA");
stat.execute(getInsertSql(obj, tableName, excludeFields, detailOtherFields));
String pid = detailOtherFields.remove("ID");
JSONArray array = obj.getJSONArray(dataName);
List<String> dataExcludeField = new ArrayList<String>();
if(array != null) {
for(int k = 0; k < array.size(); k ++) {
arrayOtherFields.put("PID", pid);
JSONObject data = array.getJSONObject(k);
stat.execute(getInsertSql(data, tableListName, excludeFields, arrayOtherFields));
arrayOtherFields.put("PID", arrayOtherFields.remove("ID"));
JSONArray dataArray = data.getJSONArray("data");
if(dataArray == null) {
continue;
}
for(int i = 0; i < dataArray.size(); i ++) {
JSONObject daObj = new JSONObject();
daObj.put("data", dataArray.get(i));
stat.execute(getInsertSql(daObj, "bigdata_td_data", dataExcludeField, arrayOtherFields));
arrayOtherFields.remove("ID");
}
}
}
}
public static String getInsertSql(JSONObject obj, String tableName, List<String> excludeFields, Map<String, String> otherFields) {
return getInsertSql(obj, tableName, excludeFields, otherFields, true, null, null);
}
public static String getInsertSql(JSONObject obj, String tableName, List<String> excludeFields,
Map<String, String> otherFields, boolean isCheckNumber, Map<String, String> dateFields, List<String> stringFields) {
String sql = "INSERT INTO " + tableName.toUpperCase() + "({keys}) VALUES({values})";
String keys = "";
String values = "";
Set<Map.Entry<String, Object>> fields = obj.entrySet();
if(fields.size() == 0) {
return "";
}
boolean flag = false;
String id = "";
for(Map.Entry<String, Object> field : fields) {
String key = field.getKey();
if("ID".equals(key.toUpperCase())) {
id = (String)field.getValue();
flag = true;
}
Object value = field.getValue();
if(excludeFields != null && excludeFields.contains(key.toUpperCase())) {
continue;
}
if(keys.length() > 0) {
keys += ",";
values += ",";
}
keys += changeKey(key, true);;
if(value != null) {
String valueString = value + "";
if(isCheckNumber && isNumber(valueString)) {
if(stringFields != null && stringFields.contains(key)) {
values += changeStringToDate(key, valueString, dateFields);
} else {
values += valueString;
}
} else {
values += changeStringToDate(key, valueString, dateFields);
}
} else {
values += "''";
}
}
if(!otherFields.isEmpty()) {
for(Map.Entry<String, String> otherField : otherFields.entrySet()) {
if(keys.length() > 0) {
keys += ",";
values += ",";
}
keys += otherField.getKey().toUpperCase();
values += "'" + otherField.getValue() + "'";
}
}
if(!flag) {
id = UUIDUtil.getUUID();
keys += ",ID";
values += ",'" + id + "'";
}
otherFields.put("ID", id);
sql = sql.replaceAll("\\{keys\\}", keys).replaceAll("\\{values\\}", values);
ARE.getLog().info("[执行]" + sql);
return sql;
}
public static boolean isNumber(String value) {
try {
new BigDecimal(value);
} catch(Exception e) {
return false;
}
return true;
}
public static String changeStringToDate(String key, String value, Map<String, String> dateFields) {
if(dateFields != null) {
for(Map.Entry<String, String> dateField : dateFields.entrySet()) {
if(dateField.getKey().equals(key)) {
// return "DATE_FORMAT('" + value + "', '" + dateField.getValue() + "')";
return "'" + value + "'";
}
}
return "'" + value + "'";
}
return "'" + value + "'";
}
public static String changeKey(String key) {
return PbocDataController.changeKey(key, false);
}
public static String changeKey(String key, boolean toUpperCase) {
String[] keys = key.split("");
boolean flag = false;
if(flag) {
if(toUpperCase) {
return key.toUpperCase();
} else {
return key;
}
}
key = "";
int lockField = -1;
ot : for(int k = 0; k < keys.length; k ++) {
if("".equals(keys[k]) || keys[k] == null) {
continue;
}
if(lockField == k) {
key += keys[k].toLowerCase();
lockField = -1;
continue;
}
if(keys[k].matches("[0-9]") && lockField == -1) {
int i = k + 1;;
for(; i < keys.length; i ++) {
if("p".equals(keys[i])) {
break;
}
if(Character.isUpperCase(keys[i].charAt(0))) {
lockField = i;
key += "_" + keys[k];
continue ot;
}
}
}
if(k == keys.length -2 && "I".equals(keys[k]) && ("I".equals(keys[k + 1]) || "D".equals(keys[k + 1]))) {
key += keys[k].toLowerCase() + keys[k + 1].toLowerCase();
break;
} else if(Character.isUpperCase(keys[k].charAt(0))) {
key += "_" + keys[k].toLowerCase();
} else {
key += keys[k];
}
}
return toUpperCase ? key.toUpperCase() : key;
}
}

View File

@ -0,0 +1,48 @@
package com.tenwa.httpclient.pboc;
import org.apache.commons.codec.binary.Base64;
import java.io.File;
import java.io.FileOutputStream;
import java.io.PrintStream;
public class FileUtils {
/**
* xml信息读取并生成xml文件
* @param filePath
* @param reportId
* @param resXMLReportStr
* @return
*/
public static String createXMLFile(String filePath, String reportId, String resXMLReportStr) throws Exception {
// TODO: 2023/1/31 文件地址修改
// String xmlFilePath = filePath + "\\xmlHtml\\"+ reportId +".xml";
String xmlFilePath = filePath + "/xmlHtml/"+ reportId +".xml";
// TODO: 2023/1/31 写入xml文件
File xmlFile = new File(xmlFilePath);
xmlFile.createNewFile();
PrintStream printStream = new PrintStream(new FileOutputStream(xmlFile));
printStream.println(resXMLReportStr);//将字符串写入文件
return xmlFilePath;
}
/**
* xml信息读取并生成html文件
* @param filePath
* @param reportId
* @param htmlRptDataStr
* @return
*/
public static String createHtmlFile(String filePath, String reportId, String htmlRptDataStr) throws Exception {
byte[] byteData = new Base64().decode(htmlRptDataStr);
// TODO: 2023/1/31 文件地址修改
// String htmlFilePath = filePath + "\\xmlHtml\\"+ reportId +".html";
String htmlFilePath = filePath + "/xmlHtml/"+ reportId +".html";
// TODO: 2023/1/31 html内容写入html文件
File htmlFile = new File(htmlFilePath);
htmlFile.createNewFile();
PrintStream printStreamHtml = new PrintStream(new FileOutputStream(htmlFile));
printStreamHtml.println(new String(byteData));//将字符串写入文件
return htmlFilePath;
}
}

View File

@ -0,0 +1,179 @@
package com.tenwa.httpclient.pboc;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.net.ssl.*;
import java.io.*;
import java.net.ConnectException;
import java.net.SocketTimeoutException;
import java.net.URL;
import java.net.URLConnection;
import java.security.cert.X509Certificate;
/**
* 通用http发送方法
*
* @author zhanglei
*/
public class HttpUtils
{
private static final Logger log = LoggerFactory.getLogger(HttpUtils.class);
/**
* 向指定 URL 发送POST方法的请求
*
* @param url 发送请求的 URL
* @param param 请求参数请求参数应该是 name1=value1&name2=value2 的形式
* @return 所代表远程资源的响应结果
*/
public static String sendPost(String url, String param)
{
PrintWriter out = null;
BufferedReader in = null;
StringBuilder result = new StringBuilder();
try
{
String urlNameString = url;
// log.info("sendPost - {}", urlNameString);
URL realUrl = new URL(urlNameString);
URLConnection conn = realUrl.openConnection();
conn.setRequestProperty("accept", "*/*");
conn.setRequestProperty("connection", "Keep-Alive");
conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
conn.setRequestProperty("Accept-Charset", "utf-8");
conn.setRequestProperty("Content-Type", "application/xml;charset=utf-8");
conn.setRequestProperty("Content-Length", Integer.toString(param.length()));
conn.setDoOutput(true);
conn.setDoInput(true);
out = new PrintWriter(conn.getOutputStream());
out.print(param);
out.flush();
in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "utf-8"));
String line;
while ((line = in.readLine()) != null)
{
result.append(line);
}
// log.info("recv - {}", result);
}
catch (ConnectException e)
{
log.error("调用HttpUtils.sendPost ConnectException, url=" + url + ",param=" + param, e);
}
catch (SocketTimeoutException e)
{
log.error("调用HttpUtils.sendPost SocketTimeoutException, url=" + url + ",param=" + param, e);
}
catch (IOException e)
{
log.error("调用HttpUtils.sendPost IOException, url=" + url + ",param=" + param, e);
}
catch (Exception e)
{
log.error("调用HttpsUtil.sendPost Exception, url=" + url + ",param=" + param, e);
}
finally
{
try
{
if (out != null)
{
out.close();
}
if (in != null)
{
in.close();
}
}
catch (IOException ex)
{
log.error("调用in.close Exception, url=" + url + ",param=" + param, ex);
}
}
return result.toString();
}
public static String sendSSLPost(String url, String param)
{
StringBuilder result = new StringBuilder();
String urlNameString = url + "?" + param;
try
{
log.info("sendSSLPost - {}", urlNameString);
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, new TrustManager[] { new TrustAnyTrustManager() }, new java.security.SecureRandom());
URL console = new URL(urlNameString);
HttpsURLConnection conn = (HttpsURLConnection) console.openConnection();
conn.setRequestProperty("accept", "*/*");
conn.setRequestProperty("connection", "Keep-Alive");
conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
conn.setRequestProperty("Accept-Charset", "utf-8");
conn.setRequestProperty("contentType", "utf-8");
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setSSLSocketFactory(sc.getSocketFactory());
conn.setHostnameVerifier(new TrustAnyHostnameVerifier());
conn.connect();
InputStream is = conn.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String ret = "";
while ((ret = br.readLine()) != null)
{
if (ret != null && !ret.trim().equals(""))
{
result.append(new String(ret.getBytes("ISO-8859-1"), "utf-8"));
}
}
log.info("recv - {}", result);
conn.disconnect();
br.close();
}
catch (ConnectException e)
{
log.error("调用HttpUtils.sendSSLPost ConnectException, url=" + url + ",param=" + param, e);
}
catch (SocketTimeoutException e)
{
log.error("调用HttpUtils.sendSSLPost SocketTimeoutException, url=" + url + ",param=" + param, e);
}
catch (IOException e)
{
log.error("调用HttpUtils.sendSSLPost IOException, url=" + url + ",param=" + param, e);
}
catch (Exception e)
{
log.error("调用HttpsUtil.sendSSLPost Exception, url=" + url + ",param=" + param, e);
}
return result.toString();
}
private static class TrustAnyTrustManager implements X509TrustManager
{
@Override
public void checkClientTrusted(X509Certificate[] chain, String authType)
{
}
@Override
public void checkServerTrusted(X509Certificate[] chain, String authType)
{
}
@Override
public X509Certificate[] getAcceptedIssuers()
{
return new X509Certificate[] {};
}
}
private static class TrustAnyHostnameVerifier implements HostnameVerifier
{
@Override
public boolean verify(String hostname, SSLSession session)
{
return true;
}
}
}

View File

@ -0,0 +1,270 @@
package com.tenwa.httpclient.pboc;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.amarsoft.are.ARE;
import org.apache.commons.lang3.StringUtils;
import org.dom4j.*;
import java.util.*;
import java.util.regex.Pattern;
public class PbocXmlUtils {
/**
* 个人单笔查询的参数组装
* @param params
* @return
*/
public static String createPersonQueryParamStr(Map<String,String> params, String subjectId) {
/**
* String xmlParam = "<msgHead>" +
* "????<txCode>ZXCXA01</txCode>" +
* "????<reqSysCode>LOCAL</reqSysCode>" +
* "????<loginUserCode>system</loginUserCode>" +
* "????<loginPwd>123456</loginPwd>" +
* "????<finDept>a5adabc8ae00417bbe1b4f54423f4d03</finDept>" +
* "</msgHead>" +
* "<msgBody>" +
* "????<appType>01</appType>" +
* "????<rptUser>system</rptUser>" +
* "????<rptUserdept>777</rptUserdept>" +
* "????<custName>王小二</custName>" +
* "????<custCertype>10</custCertype>" +
* "????<custCertno>622926198501293785</custCertno>" +
* "????<qryReason>23</qryReason>" +
* "????<qryType>0</qryType>" +
* "????<qryFormat>01</qryFormat>" +
* "????<authStartDt>2021-03-25</authStartDt>" +
* "????<authEndDt>2023-03-24</authEndDt>" +
* "????<authArchFileNameList>爱啥啥</authArchFileNameList>" +
* "????<authArchUrl>www.baidu.com</authArchUrl>" +
* "????<certSrcUrl>www.sino.com</certSrcUrl>" +
* "????<certFileNameList>想啥啥</certFileNameList>" +
* "</msgBody>";
*/
try {
JSONObject param = new JSONObject();
JSONObject msgHead = new JSONObject();
JSONObject msgBody = new JSONObject();
msgHead.put("txCode", "ZXCXA01");
msgHead.put("reqSysCode", "LOCAL");
msgHead.put("loginUserCode", "system");
msgHead.put("loginPwd", "123456");
msgHead.put("finDept", "a5adabc8ae00417bbe1b4f54423f4d03");
param.put("msgHead", msgHead);
msgBody.put("appType", "01");
msgBody.put("rptUser", "system");
msgBody.put("rptUserdept", "777");
msgBody.put("custName", "王小二");
msgBody.put("custCertype", "10");
msgBody.put("custCertno", "622926198501293785");
msgBody.put("qryReason", "23");
msgBody.put("qryType", "0");
msgBody.put("qryFormat", "01");
msgBody.put("authStartDt", "2021-03-25");
msgBody.put("authEndDt", "2023-03-24");
msgBody.put("authArchFileNameList", "爱啥啥");
msgBody.put("authArchUrl", "www.baidu.com");
msgBody.put("certSrcUrl", "www.sino.com");
msgBody.put("certFileNameList", "想啥啥");
param.put("msgBody", msgBody);
ARE.getLog().info("xmlParamStr : " + param.toJSONString());
String xmlParamStr = toXml(param);
ARE.getLog().info("xmlParamStr : " + xmlParamStr);
return xmlParamStr;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
// 解决 CDATA 问题
private static Pattern pattern = Pattern.compile("[<>&\"',]");
public static String toXml(JSONObject obj) {
return jsonStr2Xml(obj.toJSONString());
}
private static String escape(String string) {
return pattern.matcher(string).find() ? "<![CDATA[" + string + "]]>" : string;
}
/**
* updateXml
* @param xmlStr
*/
private static String updateXml(String xmlStr) {
xmlStr = xmlStr.trim();
if (StringUtils.isBlank(xmlStr)) {
return xmlStr;
}
// 过滤非法字符
xmlStr = xmlStr.replaceAll("[\\x00-\\x08\\x0b-\\x0c\\x0e-\\x1f]", "");
StringBuilder xmlSb = new StringBuilder(xmlStr);
if (!xmlStr.startsWith("<?")) {
xmlSb.insert(0, "<?xml version=\"1.0\" encoding=\"utf-8\"?>");
}
int idx = xmlSb.indexOf("?>") + 2;
xmlSb.insert(idx, "<root_luxsun>").append("</root_luxsun>");
return xmlSb.toString();
}
/**
* xml2Json
* @param xmlStr
* @return
* @throws DocumentException
*/
public static JSONObject toJson(String xmlStr) throws DocumentException {
xmlStr = updateXml(xmlStr);
Document doc = DocumentHelper.parseText(xmlStr);
JSONObject json = new JSONObject();
dom4j2Json(doc.getRootElement(), json);
return json;
}
/**
* toJsonString
* @param xmlStr
*/
public static String toJsonString(String xmlStr) throws DocumentException {
JSONObject jsonObject = toJson(xmlStr);
String json = JSON.toJSONString(jsonObject);
return json;
}
/**
* toMap
* @param xmlStr
*/
public static Map<String, Object> toMap(String xmlStr) throws DocumentException {
String jsonStr = toJsonString(xmlStr);
Map<String, Object> xmlMap = JSON.parseObject(jsonStr, LinkedHashMap.class);
return xmlMap;
}
/**
* xml转json
* @param element
* @param json
*/
private static void dom4j2Json(Element element, JSONObject json){
// 如果是属性
for(Object o:element.attributes()){
Attribute attr=(Attribute)o;
if(!isEmpty(attr.getValue())){
json.put("@"+attr.getName(), attr.getValue());
}
}
List<Element> chdEl=element.elements();
if(chdEl.isEmpty()&&!isEmpty(element.getText())){ // 如果没有子元素,只有一个值
json.put(element.getName(), element.getText());
}
for(Element e:chdEl){ // 有子元素
if(!e.elements().isEmpty()){ // 子元素也有子元素
JSONObject chdjson=new JSONObject();
dom4j2Json(e,chdjson);
Object o=json.get(e.getName());
if(o!=null){
JSONArray jsona=null;
if(o instanceof JSONObject){ // 如果此元素已存在,则转为jsonArray
JSONObject jsono=(JSONObject)o;
json.remove(e.getName());
jsona=new JSONArray();
jsona.add(jsono);
jsona.add(chdjson);
}
if(o instanceof JSONArray){
jsona=(JSONArray)o;
jsona.add(chdjson);
}
json.put(e.getName(), jsona);
}else{
if(!chdjson.isEmpty()){
json.put(e.getName(), chdjson);
}
}
}else{ // 子元素没有子元素
for(Object o:element.attributes()){
Attribute attr=(Attribute)o;
if(!isEmpty(attr.getValue())){
json.put("@"+attr.getName(), attr.getValue());
}
}
if(!e.getText().isEmpty()){
json.put(e.getName(), e.getText());
}
}
}
}
public static boolean isEmpty(String str) {
if (str == null || str.trim().isEmpty() || "null".equals(str)) {
return true;
}
return false;
}
/**
* jsonStr2Xml
* @param json
* @return java.lang.String
*/
public static String jsonStr2Xml(String json){
try {
StringBuffer buffer = new StringBuffer();
buffer.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
JSONObject jObj = JSON.parseObject(json);
json2Xmlstr(jObj,buffer);
return buffer.toString();
}
catch (Exception e) {
e.printStackTrace();
return "";
}
}
/**
* Json to xmlstr string
*
* @param jObj the j obj
* @param buffer the buffer
* @return the string
*/
public static String json2Xmlstr(JSONObject jObj,StringBuffer buffer){
Set<Map.Entry<String, Object>> se = jObj.entrySet();
for(Iterator<Map.Entry<String, Object>> it = se.iterator(); it.hasNext(); )
{
Map.Entry<String, Object> en = it.next();
if(en.getValue().getClass().getName().equals("com.alibaba.fastjson.JSONObject")){
buffer.append("<"+en.getKey()+">");
JSONObject jo = jObj.getJSONObject(en.getKey());
json2Xmlstr(jo,buffer);
buffer.append("</"+en.getKey()+">");
}else if(en.getValue().getClass().getName().equals("com.alibaba.fastjson.JSONArray")){
JSONArray jarray = jObj.getJSONArray(en.getKey());
for (int i = 0; i < jarray.size(); i++) {
buffer.append("<"+en.getKey()+">");
JSONObject jsonobject = jarray.getJSONObject(i);
json2Xmlstr(jsonobject,buffer);
buffer.append("</"+en.getKey()+">");
}
}else if(en.getValue().getClass().getName().equals("java.lang.String")){
buffer.append("<"+en.getKey()+">" + escape((String) en.getValue()));
buffer.append("</"+en.getKey()+">");
}
}
return buffer.toString();
}
}