393 lines
16 KiB
Java
393 lines
16 KiB
Java
package com.tenwa.util;
|
||
|
||
import java.io.File;
|
||
import java.sql.Connection;
|
||
import java.sql.PreparedStatement;
|
||
import java.util.HashMap;
|
||
import java.util.List;
|
||
import java.util.Map;
|
||
|
||
import org.dom4j.Attribute;
|
||
import org.dom4j.Document;
|
||
import org.dom4j.DocumentException;
|
||
import org.dom4j.DocumentHelper;
|
||
import org.dom4j.Element;
|
||
import org.dom4j.io.SAXReader;
|
||
import org.dom4j.tree.DefaultAttribute;
|
||
|
||
import sun.misc.BASE64Decoder;
|
||
|
||
import com.alibaba.fastjson.JSONArray;
|
||
import com.alibaba.fastjson.JSONObject;
|
||
import com.amarsoft.are.jbo.JBOTransaction;
|
||
import com.amarsoft.are.util.StringFunction;
|
||
import com.amarsoft.awe.Configure;
|
||
import com.amarsoft.awe.util.SqlObject;
|
||
import com.amarsoft.awe.util.Transaction;
|
||
import com.amarsoft.context.ASUser;
|
||
import com.tenwa.comm.exception.BusinessException;
|
||
import com.tenwa.httpclient.HttpClientUtil;
|
||
import com.tenwa.httpclient.PyUtils;
|
||
import com.tenwa.httpclient.controller.BigDataController;
|
||
import com.tenwa.httpclient.resources.BigDataPropertiesUtil;
|
||
import com.tenwa.lease.flow.project.validate.NciicClient;
|
||
import com.tenwa.lease.flow.project.validate.SoapRequest;
|
||
import com.tenwa.lease.flow.project.validate.ValidatePropertiesUtil;
|
||
|
||
/**
|
||
* 预审批校验
|
||
* @author tang
|
||
*
|
||
*/
|
||
public class BeforeApplicationCheckUtil {
|
||
|
||
public static String checkCertid(String fullname,String fullcertid,String subjectid,String message) throws Exception{
|
||
String inConditions = SoapRequest.beforeApplication(fullname,fullcertid,subjectid);
|
||
String license = null;
|
||
if(MultiSubjectUtil.TJSUBJECTID.equals(subjectid)){
|
||
license =ValidatePropertiesUtil.get("t_key");
|
||
}else{
|
||
license =ValidatePropertiesUtil.get("key");
|
||
}
|
||
String decode = new String(new BASE64Decoder().decodeBuffer(license));
|
||
String result = NciicClient.executeClient("NciicServices",decode,inConditions,subjectid);
|
||
System.out.println("result:="+result);
|
||
//使用Document解析返回的响应XML
|
||
Document document = DocumentHelper.parseText(result);
|
||
Element rootElement = document.getRootElement();
|
||
String finalResult = "";
|
||
//判断根元素rootElement若为RESPONSE则调用出现问题
|
||
if("RESPONSE".equals(rootElement.getName())){
|
||
Element rowElement = rootElement.element("ROWS").element("ROW");
|
||
@SuppressWarnings("unchecked")
|
||
List<Element> elements = rowElement.elements();
|
||
String errormessage = elements.get(1).getText();
|
||
System.out.println("验证失败,错误原因:"+errormessage);
|
||
message = errormessage;
|
||
//若根元素是ROWS则调用成功
|
||
}else if("ROWS".equals(rootElement.getName())){
|
||
@SuppressWarnings("unchecked")
|
||
List<Element> rowElement = rootElement.elements("ROW");
|
||
for(int i=0;i<rowElement.size();i++){
|
||
//BizObject resultObject = bom4.newObject();
|
||
@SuppressWarnings("unchecked")
|
||
//获取响应XML中INPUT标签内的入参内容
|
||
List<Element> inputElements = rowElement.get(i).element("INPUT").elements();
|
||
String certid = inputElements.get(0).getText();
|
||
String name = inputElements.get(1).getText();
|
||
//向校验结果临时表存入数据
|
||
//resultObject.setAttributeValue("flowunid",FlowUnid);
|
||
//resultObject.setAttributeValue("name",name);
|
||
//resultObject.setAttributeValue("certid", certid);
|
||
//resultObject.setAttributeValue("inputuserid",UserName);
|
||
//resultObject.setAttributeValue("inputorgid", OrgName);
|
||
//resultObject.setAttributeValue("inputtime", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
|
||
//获取output中的所有item
|
||
@SuppressWarnings("unchecked")
|
||
List<Element> itemElements = rowElement.get(i).element("OUTPUT").elements("ITEM");
|
||
//获取第一个item
|
||
@SuppressWarnings("unchecked")
|
||
List<Element> outputCertIdElements= itemElements.get(0).elements();
|
||
//获取第二个item
|
||
@SuppressWarnings("unchecked")
|
||
List<Element> outputNameElements= itemElements.get(1).elements();
|
||
//判断第一个item中的第一个标签元素的名字
|
||
if("gmsfhm".equals(outputCertIdElements.get(0).getName())){
|
||
String certIdResult = outputCertIdElements.get(1).getText();
|
||
String nameResult = outputNameElements.get(1).getText();
|
||
System.out.println("身份证校验结果:"+certIdResult+",姓名校验结果:"+nameResult);
|
||
if(!"一致".equals(certIdResult)){
|
||
message = "身份证校验结果:"+certIdResult;
|
||
}else if(!"一致".equals(nameResult)){
|
||
message = "姓名校验结果::"+nameResult;
|
||
}
|
||
//resultObject.setAttributeValue("result",finalResult);
|
||
}else if("errormesage".equals(outputCertIdElements.get(0).getName())){
|
||
String errorResult = outputCertIdElements.get(0).getText();
|
||
System.out.println("错误原因为:"+errorResult);
|
||
message = errorResult;
|
||
//resultObject.setAttributeValue("result", finalResult);
|
||
}
|
||
}
|
||
}
|
||
return message;
|
||
}
|
||
|
||
public static String checkPengYuan(String fullname,String fullcertid,String fullPhone ,String subjectId,ASUser asUser,Map<String, String> id, Transaction Sqlca,JBOTransaction tx) throws Exception{
|
||
String applyId = SerialNumberUtil.getPengyuanNumber(tx);
|
||
Map<String,String> params = new HashMap<String,String>(); //初始化参数
|
||
params.put("queryType","25136");
|
||
params.put("name",fullname);
|
||
params.put("documentNo",fullcertid);
|
||
params.put("phone",fullPhone);
|
||
params.put("queryReasonID","101");
|
||
params.put("subreportIDs","96100");
|
||
params.put("refID","");
|
||
String type = "html";
|
||
String htmlFile = "";
|
||
System.out.println("------------------鹏元(pengyuan_af)拉取时间----------------------");
|
||
System.out.println("");
|
||
System.out.println("");
|
||
System.out.println("------------------"+StringFunction.getTodayNow()+"----------------------");
|
||
System.out.println("");
|
||
System.out.println("");
|
||
System.out.println("------------------鹏元(pengyuan_af)拉取时间----------------------");
|
||
|
||
System.out.println("==================pengyuan_af@" + type + "获取数据====================");
|
||
String result = getQueryReport(params, type,subjectId);
|
||
System.err.println(result);
|
||
System.out.println("==================pengyuan_af@" + type + "获取数据====================");
|
||
|
||
@SuppressWarnings("deprecation")
|
||
Configure configure = Configure.getInstance();
|
||
String fileSavePath = configure.getParameter("FileSavePath") + "/" + "pengyuan" + "/";
|
||
//String FlowNo = CurPage.getParameter("FlowNo");
|
||
//String fullcardNo = CurPage.getParameter("fullcardNo");
|
||
String fullcardNo="default";
|
||
String queryCondition = HttpClientUtil.getQueryCondition(params);
|
||
Connection conn = Sqlca.getConnection(Sqlca);
|
||
try{
|
||
htmlFile = HttpClientUtil.queryReport(result, type, fileSavePath, applyId);
|
||
if(id != null) {
|
||
id.put("applyId", applyId);
|
||
}
|
||
//在发起大数据请求前记录所有报文信息
|
||
PreparedStatement ps = null;
|
||
try {
|
||
ps = conn.prepareStatement("insert into bigdata_pengyuan_af_log (id, apply_id, type, html_url, html_param, inputuserid, inputorgid, inputtime,fullName,fullcertId,fullphone,fullcardNo)"
|
||
+ " values(REPLACE(UUID(),'-',''), ?, 'apply', ?, ?, ?, ?, ? ,?, ?, ?,? )");
|
||
ps.setString(1, applyId);
|
||
ps.setString(2, BigDataPropertiesUtil.get("pengyuanUrl"));
|
||
ps.setString(3, queryCondition + "," + BigDataPropertiesUtil.get("user") + "," + BigDataPropertiesUtil.get("password") + "," + type);
|
||
ps.setString(4, asUser.getUserID());
|
||
ps.setString(5, asUser.getOrgID());
|
||
ps.setString(6, StringFunction.getTodayNow());
|
||
ps.setString(7, fullname);
|
||
ps.setString(8, fullcertid);
|
||
ps.setString(9, fullPhone);
|
||
ps.setString(10, fullcardNo);
|
||
ps.execute();
|
||
} catch(Exception e) {
|
||
e.printStackTrace();
|
||
throw new BusinessException("数据存储失败");
|
||
} finally {
|
||
if(ps != null) ps.close();
|
||
}
|
||
String html_data = Sqlca.getString(new SqlObject("select html_data from bigdata_pengyuan_af where id = '" + applyId + "'"));
|
||
PreparedStatement ps1 = null;
|
||
/*if("ExceedTimLlimitApply".equals(FlowNo)&&html_data != null){//如果超期案件再次调用鹏元大数据,并且是save状态
|
||
ps1 = conn.prepareStatement("update bigdata_pengyuan_af set keyword3 = '"+FlowNo+"' where keyword1 = ? and keyword2 = ?");
|
||
ps1.setString(1, CurPage.getParameter("ProjectId"));
|
||
ps1.setString(2, CurPage.getParameter("CustId"));
|
||
ps1.execute();
|
||
htmlFile = html_data;
|
||
if(ps != null) ps1.close();
|
||
return htmlFile;
|
||
}*/
|
||
if(html_data != null) {
|
||
htmlFile = html_data;
|
||
return htmlFile;
|
||
}
|
||
|
||
} catch(Exception e) {
|
||
e.printStackTrace();
|
||
throw new BusinessException(e.getMessage());
|
||
}
|
||
type = "xml";
|
||
PreparedStatement ps = null;
|
||
try {
|
||
ps = conn.prepareStatement("update bigdata_pengyuan_af_log set " + type + "_url = ?, " + type + "_param = ? where apply_id = ?");
|
||
ps.setString(1, BigDataPropertiesUtil.get("pengyuanUrl"));
|
||
ps.setString(2, queryCondition + "," + BigDataPropertiesUtil.get("user") + "," + BigDataPropertiesUtil.get("password") + "," + type);
|
||
ps.setString(3, applyId);
|
||
ps.execute();
|
||
} catch(Exception e) {
|
||
e.printStackTrace();
|
||
throw new BusinessException("数据存储失败");
|
||
} finally {
|
||
if(ps != null) ps.close();
|
||
}
|
||
|
||
System.out.println("==================pengyuan_af@" + type + "获取数据====================");
|
||
String xmlResult = getQueryReport(params, type,subjectId);
|
||
System.out.println("==================pengyuan_af@" + type + "获取数据====================");
|
||
|
||
String xmlPath = HttpClientUtil.queryReport(xmlResult, type, fileSavePath + "xml" + File.separator + applyId + File.separator);
|
||
BigDataController.savePengyuanData(applyId, xmlPath, "pengyuan_af", conn);
|
||
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_pengyuan_af (id,keyword1,xml_data,html_data,"
|
||
+ "inputuserid,inputorgid,inputtime,fullName,fullcertId,fullphone,fullcardNo) values('" + applyId + "','','"
|
||
+ xmlResult + "','" + htmlFile.split("@")[1] + "','" +asUser.getUserID() + "','" + asUser.getOrgID()+ "','" + StringFunction.getTodayNow() +"','"
|
||
+fullname+"','"+fullcertid+"','"+fullPhone+"','"+fullcardNo+"')").replaceAll(":", "△"));
|
||
sql.setDebugSql(sql.getDebugSql().replaceAll("△", ":"));
|
||
sql.setOriginalSql(sql.getOriginalSql().replaceAll("△", ":"));
|
||
sql.setRunSql(sql.getRunSql().replaceAll("△", ":"));
|
||
|
||
|
||
System.err.println("****************************鹏元大数据************************");
|
||
String insertsql =sql.getOriginalSql();
|
||
System.err.println(insertsql);
|
||
System.err.println("****************************鹏元大数据************************");
|
||
Sqlca.executeSQL(sql);
|
||
return checkPengYuanValue(xmlPath);
|
||
}
|
||
|
||
public static String getQueryReport(Map<String, String> params, String type, String SubjectId) throws Exception {
|
||
System.out.println("========================鹏元请求参数==================");
|
||
System.out.println(params);
|
||
String queryCondition = HttpClientUtil.getQueryCondition(params);
|
||
System.out.println(queryCondition);
|
||
Object[] para =null;
|
||
if(MultiSubjectUtil.TJSUBJECTID.equals(SubjectId)){
|
||
System.out.println("天津公司调用接口:主体id=d989246c11c111eaaa0000163e0e11e6");
|
||
para = new Object[]{
|
||
BigDataPropertiesUtil.get("t_userId"),
|
||
BigDataPropertiesUtil.get("t_password"),
|
||
queryCondition,
|
||
type};
|
||
}else //if("aa740e4111c111eaaa0000163e0e11e6".equals(SubjectId))
|
||
{
|
||
System.out.println("深圳公司调用接口:主体id=aa740e4111c111eaaa0000163e0e11e6");
|
||
para = new Object[]{
|
||
BigDataPropertiesUtil.get("userId"),
|
||
BigDataPropertiesUtil.get("password"),
|
||
queryCondition,
|
||
type};
|
||
}
|
||
|
||
System.out.println(para);
|
||
System.out.println("========================鹏元请求参数==================");
|
||
String result = "";
|
||
try{
|
||
if(MultiSubjectUtil.TJSUBJECTID.equals(SubjectId)){
|
||
System.out.println("天津公司调用接口:主体id=d989246c11c111eaaa0000163e0e11e6");
|
||
result = PyUtils.requestApi(
|
||
BigDataPropertiesUtil.get("t_pengyuanUrl")+BigDataPropertiesUtil.get("t_pengyuanServer"),
|
||
BigDataPropertiesUtil.get("t_methodType"),
|
||
para);
|
||
}else //if("aa740e4111c111eaaa0000163e0e11e6".equals(SubjectId))
|
||
{
|
||
System.out.println("深圳公司调用接口:主体id=aa740e4111c111eaaa0000163e0e11e6");
|
||
result = PyUtils.requestApi(
|
||
BigDataPropertiesUtil.get("pengyuanUrl")+BigDataPropertiesUtil.get("pengyuanServer"),
|
||
BigDataPropertiesUtil.get("methodType"),
|
||
para);
|
||
}
|
||
System.out.println(result);
|
||
} catch(Exception e) {
|
||
e.printStackTrace();
|
||
throw new BusinessException("获取大数据失败");
|
||
}
|
||
return result;
|
||
}
|
||
|
||
public static String checkPengYuanValue(String xmlPath){
|
||
String message = null ;
|
||
System.out.println("执行");
|
||
SAXReader reader = new SAXReader();
|
||
File file = new File(xmlPath);
|
||
try {
|
||
Document document = reader.read(file);
|
||
Element root = document.getRootElement();
|
||
List<Element> cisReports = root.elements();
|
||
a:for (Element element : cisReports) {
|
||
List<Element> elements = element.elements();
|
||
for (Element element2 : elements) {
|
||
//Element queryCondition = element2.element("personRiskRosterInfo");
|
||
if("personRiskRosterInfo".equals(element2.getName())){
|
||
String values = element2.getStringValue().trim();
|
||
if(values.indexOf("301")>0){
|
||
message = "刑事被告";
|
||
}
|
||
if(values.indexOf("303")>0){
|
||
if(message == null ){
|
||
message = "司法被执行人";
|
||
}else{
|
||
message = ",司法被执行人";
|
||
}
|
||
|
||
}
|
||
if(values.indexOf("305")>0){
|
||
if(message == null ){
|
||
message = "司法失信人员";
|
||
}else{
|
||
message = ",司法失信人员";
|
||
}
|
||
}
|
||
if(message != null){
|
||
message = "命中风险名单:"+message+"!";
|
||
break a;
|
||
}
|
||
}
|
||
if("personJudicialRiskInfo".equals(element2.getName())){
|
||
List<Element> items = element2.elements("item");
|
||
Map<String,Map<String,String>> checkMap = new HashMap();
|
||
for(Element item : items) {
|
||
Map<String,String> valuesMap = new HashMap();
|
||
List<Element> ites2 = item.elements();
|
||
for (Element ites : ites2) {
|
||
valuesMap.put(ites.getName(), ites.getStringValue().trim()==null?"0":ites.getStringValue().trim());
|
||
}
|
||
checkMap.put(valuesMap.get("timePeriod"), valuesMap);
|
||
}
|
||
Map<String, String> map3 = checkMap.get("1");
|
||
if(map3.size()>0){
|
||
if(new Double(map3.get("judicialCount")) >0 ){
|
||
if(message == null ){
|
||
message = "近1年司法被执行人风险事件数量";
|
||
}else{
|
||
message = ",近1年司法被执行人风险事件数量";
|
||
}
|
||
}
|
||
}
|
||
Map<String, String> map4 = checkMap.get("4");
|
||
if(map4.size()>0){
|
||
if(new Double(map4.get("criminalCaseCount")) >0 ){
|
||
if(message == null ){
|
||
message = "历史刑事案件被告风险事件数量";
|
||
}else{
|
||
message = ",历史刑事案件被告风险事件数量";
|
||
}
|
||
}
|
||
if(new Double(map4.get("breakFaithCount")) >0 ){
|
||
if(message == null ){
|
||
message = "失信被执行人风险事件数量";
|
||
}else{
|
||
message = ",失信被执行人风险事件数量";
|
||
}
|
||
}
|
||
}
|
||
if(message != null){
|
||
message = message+"大于0!";
|
||
break a;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
} catch (DocumentException e) {
|
||
// TODO Auto-generated catch block
|
||
e.printStackTrace();
|
||
}
|
||
return message;
|
||
}
|
||
}
|