apzl_leasing/src_tenwa/com/tenwa/httpclient/pboc/PbocNewDataController.java

235 lines
13 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.tenwa.httpclient.pboc;
import com.alibaba.fastjson.JSONObject;
import com.amarsoft.are.ARE;
import com.amarsoft.are.jbo.JBOException;
import com.amarsoft.are.util.StringFunction;
import com.amarsoft.awe.Configure;
import com.amarsoft.awe.control.model.Page;
import com.amarsoft.awe.util.SqlObject;
import com.amarsoft.awe.util.Transaction;
import com.tenwa.comm.exception.BusinessException;
import com.tenwa.httpclient.resources.BigDataPropertiesUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import java.util.Map;
public class PbocNewDataController {
/**
* pboc查询或者查询缓存
* @param params
* @param table
* @param Sqlca
* @param actionType
* @param applyId
* @param CurPage
* @return
* @throws Exception
*/
public String findAndSavePbocData(Map<String, String> params, String table, Transaction Sqlca, String actionType, String applyId, Page CurPage) throws Exception {
String type = "html";
ARE.getLog().info("PbocNewDataController.findAndSavePbocData====applyid="+applyId);
String htmlFilePath = Sqlca.getString(new SqlObject("select html_data from bigdata_pboc_af where id = '" + applyId + "'"));
if(null != htmlFilePath && !"null".equals(htmlFilePath.toLowerCase())){
return htmlFilePath;
}
// TODO: 2023-5-5 新增记录,状态为进行中。 新增访问日志。
// TODO: 2023/2/1 生成pboc个人单笔查询请求参数 主体id
String flowId = CurPage.getParameter("flowId");//流程编号
String projectNo = CurPage.getParameter("projectNo");//业务编号
String personQueryParamStr = PbocXmlUtils.createPersonQueryParamStr(params, CurPage.getAttribute("subjectId").toString());
ARE.getLog().info("pboc请求参数===============fullName==="+CurPage.getParameter("fullName"));
ARE.getLog().info("pboc请求参数===============fullCertId==="+CurPage.getParameter("fullCertId"));
ARE.getLog().info("pboc请求参数===============fullPhone==="+CurPage.getParameter("fullPhone"));
SqlObject sql = new SqlObject(("insert into bigdata_pboc_af (id,req_sts,begin_time,inputuserid,inputorgid,inputtime,flow_id,project_no,fullName,fullcertId,fullphone) values('" +
applyId+ "','0','" + System.currentTimeMillis() + "','" + CurPage.getUserId() + "','" + CurPage.getUser().getOrgID() + "','" + StringFunction.getTodayNow() +"','"
+ flowId +"','" + projectNo +"','"
+CurPage.getParameter("fullName")+"','"+CurPage.getParameter("fullCertId")+"','"+CurPage.getParameter("fullPhone")+"')").replaceAll(":", ""));
sql.setDebugSql(sql.getDebugSql().replaceAll("", ":"));
sql.setOriginalSql(sql.getOriginalSql().replaceAll("", ":"));
sql.setRunSql(sql.getRunSql().replaceAll("", ":"));
Sqlca.executeSQL(sql);
//新增log
SqlObject sqlLog = new SqlObject(("insert into bigdata_pboc_af_log (pboc_id,req_sts,req_time,http_url,http_param,inputuserid,inputorgid,inputtime,flow_id,project_no,fullName,fullcertId,fullphone) values('" +
applyId+ "','0','" + System.currentTimeMillis()+ "','" + BigDataPropertiesUtil.get("pboc_url") + "','" + personQueryParamStr
+ "','" + CurPage.getUserId() + "','" + CurPage.getUser().getOrgID() + "','" + StringFunction.getTodayNow()
+"','"+ flowId +"','" + projectNo
+"','" +CurPage.getParameter("fullName")+"','"+CurPage.getParameter("fullCertId")
+"','"+CurPage.getParameter("fullPhone")+"')").replaceAll(":", ""));
sqlLog.setDebugSql(sqlLog.getDebugSql().replaceAll("", ":"));
sqlLog.setOriginalSql(sqlLog.getOriginalSql().replaceAll("", ":"));
sqlLog.setRunSql(sqlLog.getRunSql().replaceAll("", ":"));
Sqlca.executeSQL(sqlLog);
// TODO: 2023-5-5 异步调用接口请求,更改记录 。新增访问日志。
asyncReqHttp(applyId,personQueryParamStr,CurPage);
return "false@征信数据拉取中,请稍后再进行查询!";
}
private void asyncReqHttp(String applyId, String personQueryParamStr, Page curPage) {
ThreadPoolTaskExecutor threadPool = PbocThreadPool.getInstance();
threadPool.execute(()->{
try {
asyncReqHttpAndSave(applyId, personQueryParamStr, curPage);
} catch (Exception e) {
throw new RuntimeException(e);
}
});
}
/**
* pboc查询配偶信息
* @param params
* @param applyId
* @return
* @throws Exception
*/
public String queryPbocData(Map<String, String> params, Transaction Sqlca, String applyId) throws Exception {
String type = "html";
ARE.getLog().info("PbocNewDataController.findAndSavePbocData====applyid=" + applyId);
String xmlDataContent = Sqlca.getString(new SqlObject("select xml_data_content from bigdata_pboc_af where id = '" + applyId + "'"));
if(null != xmlDataContent){
JSONObject resJson = PbocXmlUtils.toJson(xmlDataContent);
JSONObject serviceDataJson = resJson.getJSONObject("service");
JSONObject msgBodyData = serviceDataJson.getJSONObject("msgBody");
JSONObject xmlRptData = msgBodyData.getJSONObject("xmlRpt");
JSONObject DocumentData = xmlRptData.getJSONObject("Document");
JSONObject PMMData = DocumentData.getJSONObject("PMM");
JSONObject PB02Data = PMMData.getJSONObject("PB02");
String poName = PB02Data.getString("PB020Q01");
if(null == poName){
return null;
}
String poCertId = PB02Data.getString("PB020I01") == null ? "0" : PB02Data.getString("PB020I01");
return poName+"@"+poCertId;
}
return null;
}
/**
* 异步执行访问pboc查询并保存
*/
private void asyncReqHttpAndSave(String applyId, String personQueryParamStr, Page CurPage) throws Exception {
String type = "html";
String xmlFilePath = null;
String htmlFilePath = null;
String resXMLReport = null;
String reportId = null;
JSONObject resJson = null;
String resSts = "1";//req_sts : 0,进行中,-1 失败1 成功
try{
// : 2023/2/1 本地测试暂用
@SuppressWarnings("deprecation")
Configure configure = Configure.getInstance();
String fileSavePath = configure.getParameter("FileSavePath") + "/" + "pboc";
resXMLReport = this.findQueryReport(personQueryParamStr, type, CurPage.getAttribute("subjectId").toString());
resJson = PbocXmlUtils.toJson(resXMLReport);
JSONObject serviceDataJson = resJson.getJSONObject("service");
JSONObject msgHeadData = serviceDataJson.getJSONObject("msgHead");
ARE.getLog().info("========================pboc返回==================");
ARE.getLog().info("<<<<<<<<<<<<<<<<<<<<<<【PbocNewDataController】【asyncReqHttpAndSave】info>>>>>>20230816 querypbocressuccess >>>>>>>>>>>>>>>>>"+ msgHeadData.toJSONString());
ARE.getLog().info("========================pboc返回==================");
String resCode = msgHeadData.getString("resCode");
if("000".equals(resCode)){
reportId = msgHeadData.getString("resJnlId");
JSONObject msgBodyData = serviceDataJson.getJSONObject("msgBody");
ARE.getLog().info("========================pboc返回成功==================");
ARE.getLog().info("<<<<<<<<<<<<<<<<<<<<<<【PbocNewDataController】【asyncReqHttpAndSave】success>>>>>>20230816 querypbocressuccess >>>>>>>>>>>>>>>>>"+ resCode);
ARE.getLog().info("========================pboc返回成功==================");
String htmlRptDataStr = msgBodyData.getString("htmlRpt");
// : 2023-5-24 删除html内容存储
//msgBodyData.remove("htmlRpt");
// : 2023-5-24 删除html内容存储
xmlFilePath = FileUtils.createXMLFile(fileSavePath, reportId, resXMLReport);
htmlFilePath = FileUtils.createHtmlFile(fileSavePath, reportId, htmlRptDataStr);
ARE.getLog().info(htmlFilePath);
ARE.getLog().info(xmlFilePath);
}else {//返回状态异常
resSts = "-1";//req_sts : 0,进行中,-1 失败1 成功
ARE.getLog().info("========================pboc返回异常==================");
ARE.getLog().error("<<<<<<<<<<<<<<<<<<<<<<【PbocNewDataController】【asyncReqHttpAndSave】error>>>>>>20230816 querypbocreserror >>>>>>>>>>>>>>>>>"+ resCode);
ARE.getLog().info("========================pboc返回异常==================");
}
}catch (Exception e){
ARE.getLog().info("========================pboc返回异常==================");
ARE.getLog().error("<<<<<<<<<<<<<<<<<<<<<<【PbocNewDataController】【asyncReqHttpAndSave】error>>>>>>01>>>>>>>>>>>>>>>>>", e);
ARE.getLog().info("========================pboc返回异常==================");
resSts = "-1";//req_sts : 0,进行中,-1 失败1 成功
}
Transaction Sqlca=null;
try{
Sqlca = Transaction.createTransaction("als");
// TODO: 2023-5-5 异步调用接口请求,更改记录 。新增访问日志。
SqlObject sql = new SqlObject(("update bigdata_pboc_af set pboc_report_id='"+reportId+"',"
+"xml_data='"+xmlFilePath+"',"
// +"xml_data_content='"+resXMLReport+"',"
// TODO: 2023-5-24 删除html内容存储
// +"xml_data_content='"+PbocXmlUtils.jsonStr2Xml(resJson.toJSONString())+"',"
+"xml_data_content='"+resXMLReport+"',"
// TODO: 2023-5-24 删除html内容存储
+"html_data='"+htmlFilePath+"',"
+"req_sts='"+resSts+"',"
+"end_time='"+ System.currentTimeMillis() +"'"
+" where id='"+ applyId +"'").replaceAll(":", ""));
sql.setDebugSql(sql.getDebugSql().replaceAll("", ":"));
sql.setOriginalSql(sql.getOriginalSql().replaceAll("", ":"));
sql.setRunSql(sql.getRunSql().replaceAll("", ":"));
Sqlca.executeSQL(sql);
//新增log
SqlObject sqlLog = new SqlObject(("insert into bigdata_pboc_af_log (pboc_id,req_sts,req_time,http_url,http_param,http_res,inputuserid,inputorgid,inputtime,fullName,fullcertId,fullphone) values('" +
applyId+ "','"+resSts+"','" + System.currentTimeMillis()+ "','" + BigDataPropertiesUtil.get("pboc_url") + "','" + personQueryParamStr
+ "','" + reportId
+ "','" + CurPage.getUserId() + "','" + CurPage.getUser().getOrgID() + "','" + StringFunction.getTodayNow()
+"','" +CurPage.getParameter("fullName")+"','"+CurPage.getParameter("fullCertId")
+"','"+CurPage.getParameter("fullPhone")+"')").replaceAll(":", ""));
sqlLog.setDebugSql(sqlLog.getDebugSql().replaceAll("", ":"));
sqlLog.setOriginalSql(sqlLog.getOriginalSql().replaceAll("", ":"));
sqlLog.setRunSql(sqlLog.getRunSql().replaceAll("", ":"));
Sqlca.executeSQL(sqlLog);
}catch(Exception e){
e.printStackTrace();
ARE.getLog().error("<<<<<<<<<<<<<<<<<<<<<<【PbocNewDataController】【asyncReqHttpAndSave】error>>>>>>1>>>>>>>>>>>>>>>>>", e);
try {
Sqlca.rollback();
} catch (JBOException e1) {
e1.printStackTrace();
ARE.getLog().error("<<<<<<<<<<<<<<<<<<<<<<【PbocNewDataController】【asyncReqHttpAndSave】error>>>>>>2>>>>>>>>>>>>>>>>>", e1);
}
}finally {
if(Sqlca!=null) {
try {
Sqlca.commit();
} catch (JBOException e) {
e.printStackTrace();
ARE.getLog().error("<<<<<<<<<<<<<<<<<<<<<<【PbocNewDataController】【asyncReqHttpAndSave】error>>>>>>3>>>>>>>>>>>>>>>>>", e);
}
}
}
}
public String findQueryReport(String params, String type, String SubjectId) throws Exception {
ARE.getLog().info("========================pboc请求参数==================");
ARE.getLog().info(params);
ARE.getLog().info("========================pboc请求参数==================");
String result = "";
try{
String url = BigDataPropertiesUtil.get("pboc_url");
result = HttpUtils.sendPost(url, params);
if(StringUtils.isEmpty(result)){
ARE.getLog().info("==================返回值为空====================" );
throw new RuntimeException("获取大数据失败");
}else if(result.length() < 2000){
ARE.getLog().info("==================result====================" + result);
}
} catch(Exception e) {
e.printStackTrace();
throw new BusinessException("获取大数据失败");
}
return result;
}
}