180 lines
9.7 KiB
Java
180 lines
9.7 KiB
Java
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查询并保存
|
||
*/
|
||
private void asyncReqHttpAndSave(String applyId, String personQueryParamStr, Page CurPage) throws Exception {
|
||
String type = "html";
|
||
String xmlFilePath = null;
|
||
String htmlFilePath = null;
|
||
String reportId = 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";
|
||
String resXMLReport = this.findQueryReport(personQueryParamStr, type, CurPage.getAttribute("subjectId").toString());
|
||
JSONObject resJson = PbocXmlUtils.toJson(resXMLReport);
|
||
JSONObject serviceDataJson = resJson.getJSONObject("service");
|
||
JSONObject msgHeadData = serviceDataJson.getJSONObject("msgHead");
|
||
JSONObject msgBodyData = serviceDataJson.getJSONObject("msgBody");
|
||
reportId = msgHeadData.getString("resJnlId");
|
||
String htmlRptDataStr = msgBodyData.getString("htmlRpt");
|
||
xmlFilePath = FileUtils.createXMLFile(fileSavePath, reportId, resXMLReport);
|
||
htmlFilePath = FileUtils.createHtmlFile(fileSavePath, reportId, htmlRptDataStr);
|
||
ARE.getLog().info(htmlFilePath);
|
||
ARE.getLog().info(xmlFilePath);
|
||
}catch (Exception e){
|
||
ARE.getLog().error("<<<<<<<<<<<<<<<<<<<<<<【PbocNewDataController】【asyncReqHttpAndSave】error>>>>>>01>>>>>>>>>>>>>>>>>", e);
|
||
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+"',"
|
||
+"html_data='"+htmlFilePath+"',"
|
||
+"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;
|
||
}
|
||
|
||
}
|
||
|