diff --git a/WebContent/Tenwa/Lease/Flow/Comm/BigdataPengyuan/query_report/image/image.jpg b/WebContent/Tenwa/Lease/Flow/Comm/BigdataPengyuan/query_report/image/image.jpg new file mode 100644 index 000000000..b0e5c94d4 Binary files /dev/null and b/WebContent/Tenwa/Lease/Flow/Comm/BigdataPengyuan/query_report/image/image.jpg differ diff --git a/WebContent/Tenwa/Lease/Flow/Comm/BigdataPengyuan/query_report/image/image.png b/WebContent/Tenwa/Lease/Flow/Comm/BigdataPengyuan/query_report/image/image.png new file mode 100644 index 000000000..d8ff3cfd2 Binary files /dev/null and b/WebContent/Tenwa/Lease/Flow/Comm/BigdataPengyuan/query_report/image/image.png differ diff --git a/WebContent/Tenwa/Lease/Flow/Comm/BigdataPengyuan/query_report/pengyuandata.jsp b/WebContent/Tenwa/Lease/Flow/Comm/BigdataPengyuan/query_report/pengyuandata.jsp new file mode 100644 index 000000000..d80e31dc0 --- /dev/null +++ b/WebContent/Tenwa/Lease/Flow/Comm/BigdataPengyuan/query_report/pengyuandata.jsp @@ -0,0 +1,133 @@ +<%@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 contentType="text/html; charset=GBK"%> +<%@include file="/IncludeBegin.jsp"%><% + String flowunid = CurPage.getParameter("ObjectNo"); + String projectNo = CurPage.getParameter("ProjectNo"); + String ReadyApprove = CurPage.getParameter("ReadyApprove"); + String applyId = ""; + String getType ="GET"; + String type = ""; + String count = ""; + String reasonDesc = ""; + BigDataController bdc = new BigDataController(); + boolean flag = true; + + if("GET".equals(getType)) { + JBOTransaction tx = JBOFactory.createJBOTransaction(); + applyId = SerialNumberUtil.getPengyuanNumber(tx); + tx.commit(); + type = "SAVE"; + } else { + String result = bdc.getDataApplyId(CurPage, "pengyuan_af", Sqlca); + 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"; + } + } + Map params = new HashMap(); //初始化参数 + String resultals =bdc.getCustomerInfoPerson(flowunid, Sqlca); + if(!"false".equals(resultals)){ + String[] sReturn = resultals.split("@"); + params.put("queryType","25212"); + params.put("name","测试一"); + params.put("documentNo","110000199001011112"); + params.put("phone","13712345670"); + params.put("queryReasonID","101"); + params.put("subreportIDs","96040"); + params.put("refID",""); + } + FileInputStream fr = null; + BufferedReader br = null; + try { + String htmlURL = bdc.getAndSavePengyuanData(params, "pengyuan_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(".png") != -1 || html.indexOf(".jpg") != -1) { + html = html.replaceAll("image/image_\\d+[.]", "Tenwa/Lease/Flow/Comm/BigdataPengyuan/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("个人信息报告") != -1) { + html = html.replaceAll("个人信息报告", "  拉取鹏元数据 个人信用报告"); + } + if(html.indexOf("") != -1) { + html = html.replaceAll("", ""); + } + if(html.indexOf("") != -1) { + html = html.replaceAll("
", "
"); + } + %> + <%=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 result = bdc.getDataApplyId(CurPage, "pengyuan_af", Sqlca); + if("false".equals(result)) { + count = "0"; + } else { + count = result.split("@")[2]; + } + } + } catch(Exception e) { + e.printStackTrace(); + flag = false; + reasonDesc = e.getMessage(); + Sqlca.rollback(); + %> + + + <% + } finally { + if(br != null) br.close(); + if(fr != null) fr.close(); + } +%> + +<%@include file="/IncludeEnd.jsp"%> \ No newline at end of file diff --git a/WebContent/WEB-INF/lib/XmlSchema-1.1.jar b/WebContent/WEB-INF/lib/XmlSchema-1.1.jar new file mode 100644 index 000000000..a52c56211 Binary files /dev/null and b/WebContent/WEB-INF/lib/XmlSchema-1.1.jar differ diff --git a/WebContent/WEB-INF/lib/commons-logging.jar b/WebContent/WEB-INF/lib/commons-logging.jar index c4cef08d6..51036199f 100644 Binary files a/WebContent/WEB-INF/lib/commons-logging.jar and b/WebContent/WEB-INF/lib/commons-logging.jar differ diff --git a/WebContent/WEB-INF/lib/itextpdf-5.5.13.jar b/WebContent/WEB-INF/lib/itextpdf-5.5.13.jar new file mode 100644 index 000000000..fb2ecf1a6 Binary files /dev/null and b/WebContent/WEB-INF/lib/itextpdf-5.5.13.jar differ diff --git a/WebContent/WEB-INF/lib/wsdl4j.jar b/WebContent/WEB-INF/lib/wsdl4j.jar index 3e73b6332..67a35fcba 100644 Binary files a/WebContent/WEB-INF/lib/wsdl4j.jar and b/WebContent/WEB-INF/lib/wsdl4j.jar differ diff --git a/WebContent/WEB-INF/lib/xfire-aegis-1.2.6.jar b/WebContent/WEB-INF/lib/xfire-aegis-1.2.6.jar new file mode 100644 index 000000000..83e17f7f3 Binary files /dev/null and b/WebContent/WEB-INF/lib/xfire-aegis-1.2.6.jar differ diff --git a/WebContent/WEB-INF/lib/xfire-core-1.2.6.jar b/WebContent/WEB-INF/lib/xfire-core-1.2.6.jar new file mode 100644 index 000000000..0ff443aa7 Binary files /dev/null and b/WebContent/WEB-INF/lib/xfire-core-1.2.6.jar differ diff --git a/WebContent/WEB-INF/lib/xmlParserAPIs-2.6.2.jar b/WebContent/WEB-INF/lib/xmlParserAPIs-2.6.2.jar new file mode 100644 index 000000000..2dd837714 Binary files /dev/null and b/WebContent/WEB-INF/lib/xmlParserAPIs-2.6.2.jar differ diff --git a/config/bigdata.properties b/config/bigdata.properties new file mode 100644 index 000000000..7d65da2fe --- /dev/null +++ b/config/bigdata.properties @@ -0,0 +1,21 @@ +#bigdata config +count = 3 +keyword1 = ProjectId +keyword2 = CustId +keyword3 = +keyword4 = +keyword5 = + +#pengyuan +pengyuanUrl = https://test.pycredit.com:6443/services/WebServiceSingleQuery?wsdl +userId = apwsqueryn01 +password = {MD5}i3rx5Ta+2VL5Dj5T866giQ== +methodType = queryReport + + + + + + + + diff --git a/src_core/com/tenwa/util/SerialNumberUtil.java b/src_core/com/tenwa/util/SerialNumberUtil.java index d86b354c7..729a31a98 100644 --- a/src_core/com/tenwa/util/SerialNumberUtil.java +++ b/src_core/com/tenwa/util/SerialNumberUtil.java @@ -54,6 +54,10 @@ public class SerialNumberUtil { public static synchronized String getVoucherPCNumber(JBOTransaction tx) throws Exception{ return SerialNumberUtil.getSerialNumber("AP{year}{month}{day}-{maxOrderNumber}",3,null, "凭证接口批次", null, tx); } + //鹏元apply_id + public static synchronized String getPengyuanNumber(JBOTransaction tx) throws Exception{ + return SerialNumberUtil.getSerialNumber("{year}{month}{day}{maxOrderNumber}",9,null, "", null, tx); + } /** * 通联代扣流水号 * @param tx diff --git a/src_tenwa/com/tenwa/httpclient/HttpClientUtil.java b/src_tenwa/com/tenwa/httpclient/HttpClientUtil.java index e022f7050..37b4f76cc 100644 --- a/src_tenwa/com/tenwa/httpclient/HttpClientUtil.java +++ b/src_tenwa/com/tenwa/httpclient/HttpClientUtil.java @@ -1,6 +1,12 @@ package com.tenwa.httpclient; +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; import java.io.BufferedReader; +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; @@ -9,7 +15,10 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; +import org.apache.commons.codec.binary.Base64; import org.apache.commons.httpclient.ConnectTimeoutException; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpStatus; @@ -26,8 +35,12 @@ import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.message.BasicNameValuePair; import org.apache.http.util.EntityUtils; +import org.dom4j.Document; +import org.dom4j.DocumentHelper; +import org.dom4j.Element; import com.amarsoft.are.ARE; +import com.tenwa.comm.exception.BusinessException; import com.tenwa.httpclient.resources.GPSConfigure; public class HttpClientUtil { @@ -196,4 +209,147 @@ public class HttpClientUtil { } return resultString; } + public static String queryReport(String data, String type, String uploadPath) throws Exception { + return queryReport(data, type, uploadPath, null); + } + + public static String queryReport(String data, String type, String uploadPath, String applyId) throws Exception { + Document doc = DocumentHelper.parseText(data); + Element root = doc.getRootElement(); + Element returnValue = root.element("returnValue"); + byte[] byteData = new Base64().decode(returnValue.getText()); + + String filePath = "";//获取html页面的存储路径,并展示给用户 + + if("html".equals(type)) { + //输出文件 + filePath = writeByteData(byteData, uploadPath, applyId); + //解压文件 + String htmlFileName = unzipFile(filePath); + //找到html页面 + filePath = new File(new File(new File(htmlFileName).getParent()).getParent()).getName() + "@" + htmlFileName; + } else if("pdf".equals(type)) { + filePath = writeByteData(byteData, uploadPath); + } else { + filePath = writeByteData(byteData, uploadPath); + } + return filePath; + } + + //递归解压缩文件 + public static String unzipFile(String filePath) throws Exception { + if(filePath == null || !filePath.endsWith(".zip")) { + throw new BusinessException("not a zipfile"); + } + ZipInputStream zip = null; + FileOutputStream fos = null; + BufferedInputStream bis = null; + BufferedOutputStream bos = null; + String htmlFilePath = ""; + String zipPath = filePath; + try { + zip = new ZipInputStream(new FileInputStream(filePath)); + filePath = filePath.substring(0, filePath.indexOf("html") + 4); + bis = new BufferedInputStream(zip); + ZipEntry zipEntry = null; + while((zipEntry = zip.getNextEntry()) != null) { + String fileName = zipEntry.getName(); + fileName = filePath + File.separator + fileName; + if(fileName.endsWith(".zip")) {//是压缩文件就继续解压 + unzipFile(fileName); + } else { + File file = new File(fileName); + if(!file.exists()) { + new File(file.getParent()).mkdirs();//文件不存在,则先创建目录群 + } + if(fileName.endsWith(".html")) { + htmlFilePath = fileName; + } + bos = new BufferedOutputStream(new FileOutputStream(file)); + int n = -1; + while((n = bis.read()) != -1) { + bos.write(n); + } + bos.flush(); + } + } + } catch(Exception e) { + e.printStackTrace(); + throw new BusinessException("文件解压失败"); + } finally { + if(zip != null) zip.close(); + if(fos != null) fos.close(); + if(bis != null) bis.close(); + if(bos != null) bos.close(); + new File(zipPath).delete(); + } + return htmlFilePath; + } + + public static String writeByteData(byte[] byteData, String uploadPath) throws Exception { + return writeByteData(byteData, uploadPath, null); + } + + public static String writeByteData(byte[] byteData, String uploadPath, String applyId) throws Exception { + String filePath = ""; + ByteArrayInputStream bis = null; + FileOutputStream fos = null; + ZipInputStream zip = null; + File file = null; + try { + bis = new ByteArrayInputStream(byteData); + //首输出压缩文件 + zip = new ZipInputStream(bis);//读取zip流 + ZipEntry zipEntry = zip.getNextEntry(); + //filePath = uploadPath + zipEntry.getName(); + //为了避免并发导致读取文件冲突,为文件名加上时间戳 + String code = System.currentTimeMillis() + ""; + //增加applyId为存储名,确保并发情况下低概率出现时间戳一致的情况 + if(applyId != null && !"".equals(applyId)) { + code = applyId; + } + filePath = uploadPath + zipEntry.getName().replaceAll(".zip", code + ".zip"); + file = new File(filePath); + if(!file.exists()) { + new File(file.getParent()).mkdirs(); + } + fos = new FileOutputStream(file); + if(zipEntry != null) { + byte[] buf = new byte[1024]; + int n = -1; + while((n = zip.read(buf, 0, buf.length)) != -1) { + fos.write(buf, 0, n); + } + fos.flush(); + } + } catch(Exception e) { + e.printStackTrace(); + throw new BusinessException("读写文件失败"); + } finally { + if(bis != null) bis.close(); + if(fos != null) fos.close(); + } + return filePath; + } + + public static String getQueryCondition(Map params) { + try { + Document doc = DocumentHelper.createDocument(); + Element root = doc.addElement("conditions"); + Element condition = root.addElement("condition"); + condition.addAttribute("queryType",params.get("queryType")); + for(Entry param : params.entrySet()) { + if("queryType".equals(param.getKey())) { + continue; + } + Element item = condition.addElement("item"); + item.addElement("name").setText(param.getKey()); + item.addElement("value").setText(param.getValue()); + } + return doc.asXML(); + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } } diff --git a/src_tenwa/com/tenwa/httpclient/PyConfig.java b/src_tenwa/com/tenwa/httpclient/PyConfig.java new file mode 100644 index 000000000..c3af700f6 --- /dev/null +++ b/src_tenwa/com/tenwa/httpclient/PyConfig.java @@ -0,0 +1,38 @@ +package com.tenwa.httpclient; + +public class PyConfig { + + // API域名 + public final static String WEBSERVICE_HOST = ""; // 测试环境-http(具体以技术支持提供为准) +// public final static String WEBSERVICE_HOST = "https://test.pycredit.com:9443"; // 测试环境-https(具体以技术支持提供为准) +// public final static String WEBSERVICE_HOST = "http://www.pycredit.com:8001"; // 生产环境-http(具体以技术支持提供为准) +// public final static String WEBSERVICE_HOST = "https://www.pycredit.com:8443"; // 生产环境-https(具体以技术支持提供为准) + + // 返回报文压缩的URL + public final static String WSDL_PATH_ZIP = "/services/WebServiceSingleQuery?wsdl"; + + // 返回报文不压缩的URL + public final static String WSDL_PATH_UNZIP = "/services/WebServiceSingleQueryOfUnzip?wsdl"; + + // 认证信息 + public final static String USERID = ""; + public final static String PASSWORD = ""; + + // 返回格式 + public final static String FORMAT = "html"; +// public final static String FORMAT = "html"; +// public final static String FORMAT = "singlepdf"; + // 是否测试模式 + public final static boolean IS_TEST = true; + + // 请求内容样本文件,实际中可使用具体对象组装 + public final static String QUERY_XML_FILE = "d:/sample.xml"; + + public final static String KEYSTORE_FILE = "C:/Users/luojian/Desktop/安鹏/接口/01接口文档资料/鹏元测试证书/pytest.jks"; + public final static String KEYSTORE_PASSWORD = "123456"; + public final static String TRUSTSTORE_FILE = "C:/Users/luojian/Desktop/安鹏/接口/01接口文档资料/鹏元测试证书/pytest2.jks"; + public final static String TRUSTSTORE_PASSWORD = "123456"; + + public final static String AES_KEY = ""; + +} diff --git a/src_tenwa/com/tenwa/httpclient/PySSLContextUtil.java b/src_tenwa/com/tenwa/httpclient/PySSLContextUtil.java new file mode 100644 index 000000000..57d698981 --- /dev/null +++ b/src_tenwa/com/tenwa/httpclient/PySSLContextUtil.java @@ -0,0 +1,89 @@ +package com.tenwa.httpclient; + + + + + +import com.tenwa.httpclient.PyConfig; + +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.security.KeyManagementException; +import java.security.KeyStore; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.UnrecoverableKeyException; +import java.security.cert.CertificateException; + +import javax.net.ssl.KeyManager; +import javax.net.ssl.KeyManagerFactory; +import javax.net.ssl.SSLContext; +import javax.net.ssl.TrustManager; +import javax.net.ssl.TrustManagerFactory; +import javax.net.ssl.X509TrustManager; + +/** + * 鹏元征信 SSLContext 帮助类 + */ +public class PySSLContextUtil { + + /** + * 使用该SSLContext,证书如下 + * keystore : javax.net.ssl.keyStore 指定的证书 + * truststore : javax.net.ssl.trustStore 指定的证书 + * + * @return + * @throws NoSuchAlgorithmException + */ + public static SSLContext createDefaultSSLContext() throws NoSuchAlgorithmException { + return SSLContext.getDefault(); + } + + /** + * 使用该SSLContext, 证书可自定义 + * + * @return + * @throws NoSuchAlgorithmException + */ + public static SSLContext createCustomerSSLContext() throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException, IOException, CertificateException, UnrecoverableKeyException { + SSLContext context = SSLContext.getInstance("TLSv1.2"); + KeyStore keyStore = getKeyStore("JKS", new FileInputStream(PyConfig.KEYSTORE_FILE), PyConfig.KEYSTORE_PASSWORD); + KeyManager[] kms = createKeyManager(keyStore, PyConfig.KEYSTORE_PASSWORD); + KeyStore trustStore = getKeyStore("JKS", new FileInputStream(PyConfig.TRUSTSTORE_FILE), PyConfig.TRUSTSTORE_PASSWORD); + //带公钥证书 + // TrustManager[] tms = createTrustManager(trustStore); + // context.init(kms, tms, null); + //不带公钥证书 + context.init(kms,new TrustManager[]{new X509TrustManager(){ + public void checkClientTrusted(java.security.cert.X509Certificate[] arg0,String arg1) throws CertificateException{ + } + public void checkServerTrusted(java.security.cert.X509Certificate[] arg0,String arg1) throws CertificateException{ + } + public java.security.cert.X509Certificate[] getAcceptedIssuers(){ + return null; + } + }},null); + SSLContext.setDefault(context); + return context; + } + + private static KeyManager[] createKeyManager(KeyStore keyStore, String password) throws NoSuchAlgorithmException, UnrecoverableKeyException, KeyStoreException { + KeyManagerFactory factory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); + factory.init(keyStore, password.toCharArray()); + return factory.getKeyManagers(); + } + + private static TrustManager[] createTrustManager(KeyStore trustStore) throws NoSuchAlgorithmException, KeyStoreException { + TrustManagerFactory factory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); + factory.init(trustStore); + return factory.getTrustManagers(); + } + + + public static KeyStore getKeyStore(String keyStoreType, InputStream stream, String password) throws KeyStoreException, CertificateException, NoSuchAlgorithmException, IOException { + KeyStore keyStore = KeyStore.getInstance(keyStoreType); + keyStore.load(stream, password.toCharArray()); + return keyStore; + } +} diff --git a/src_tenwa/com/tenwa/httpclient/PyUtils.java b/src_tenwa/com/tenwa/httpclient/PyUtils.java new file mode 100644 index 000000000..feb311628 --- /dev/null +++ b/src_tenwa/com/tenwa/httpclient/PyUtils.java @@ -0,0 +1,123 @@ +package com.tenwa.httpclient; + + + +import org.apache.commons.httpclient.params.HttpClientParams; +import org.apache.commons.io.IOUtils; +import org.codehaus.xfire.client.Client; +import org.codehaus.xfire.transport.http.CommonsHttpMessageSender; +import org.w3c.dom.Document; + +import javax.net.ssl.HttpsURLConnection; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Unmarshaller; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.StringReader; +import java.net.URL; +import java.net.URLConnection; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; + +/** + * 鹏元工具类 + */ +public class PyUtils { + + /** + * 发起webservice请求 + * + * @param urlStr + * @return + * @throws Exception + */ + public static String requestApi(String urlStr, String method, Object[] params) throws Exception { + String result = ""; + try { + //调用webservice + URL url = new URL(urlStr); + Client client = null; + URLConnection conn = null; + if (urlStr.startsWith("https")) { + /** + * https 调用示例 + */ + conn = (HttpsURLConnection) url.openConnection(); + ((HttpsURLConnection) conn).setSSLSocketFactory(PySSLContextUtil.createCustomerSSLContext().getSocketFactory()); + + } else { + /** + * http 调用示例 + */ + conn = url.openConnection(); + + } + // 设置连接超时 + conn.setConnectTimeout(5000); + // 设置读取超时 + conn.setReadTimeout(5000); + client = new Client(conn.getInputStream(), null); + + // 设置 + HttpClientParams httpClientParams = new HttpClientParams(); + // 单位毫秒: 这个超时时间是 等待数据返回的时间 + httpClientParams.setSoTimeout(20000); + // 设置从 HTTP connection manager 获取一个HTTP connection 的超时时间 + httpClientParams.setConnectionManagerTimeout(10000L); + // xfire client支持 避免 'Expect: 100-continue' handshake + httpClientParams.setBooleanParameter(HttpClientParams.USE_EXPECT_CONTINUE, Boolean.FALSE); + client.setProperty(CommonsHttpMessageSender.HTTP_CLIENT_PARAMS, httpClientParams); + //xfire client支持 取消长连接 + client.setProperty(CommonsHttpMessageSender.DISABLE_KEEP_ALIVE, "true"); + + //得到子报告结果 + Object[] results = client.invoke(method, params); + + if (results[0] instanceof Document) { + Document doc = (Document) results[0]; + result = doc.getFirstChild().getFirstChild().getNodeValue(); + } else { + result = (String) results[0]; + } + } catch (Exception e) { + e.printStackTrace(); + } + return result; + } + + /** + * 解析报文(仅供参考) + * + * @param bodyStr + * @return + * @throws Exception + */ + public static WebServiceResult parseBody(String bodyStr) throws Exception { + JAXBContext context = JAXBContext.newInstance(WebServiceResult.class); + Unmarshaller unmarshaller = context.createUnmarshaller(); + WebServiceResult result = (WebServiceResult) unmarshaller.unmarshal(new StringReader(bodyStr)); + return result; + } + + /** + * 解压缩 + * + * @param data + * @return + * @throws Exception + */ + public static void decompress(byte[] data) throws Exception { + + ByteArrayInputStream bais = new ByteArrayInputStream(data); + ZipInputStream zis = new ZipInputStream(bais); + ZipEntry ze = null; + while ((ze = zis.getNextEntry()) != null) { + System.out.println("文件名:" + ze.getName()); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + IOUtils.copy(zis, baos); + zis.closeEntry(); + System.out.println("文件内容:" + new String(baos.toByteArray(), "GBK")); + } + } + +} diff --git a/src_tenwa/com/tenwa/httpclient/WebServiceResult.java b/src_tenwa/com/tenwa/httpclient/WebServiceResult.java new file mode 100644 index 000000000..f3841dcfa --- /dev/null +++ b/src_tenwa/com/tenwa/httpclient/WebServiceResult.java @@ -0,0 +1,53 @@ +package com.tenwa.httpclient; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * + */ +@XmlRootElement(name = "result") +@XmlAccessorType(value = XmlAccessType.FIELD) +public class WebServiceResult { + + private String status; + + private String returnValue; + + private String errorCode; + + private String errorMessage; + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getReturnValue() { + return returnValue; + } + + public void setReturnValue(String returnValue) { + this.returnValue = returnValue; + } + + public String getErrorCode() { + return errorCode; + } + + public void setErrorCode(String errorCode) { + this.errorCode = errorCode; + } + + public String getErrorMessage() { + return errorMessage; + } + + public void setErrorMessage(String errorMessage) { + this.errorMessage = errorMessage; + } +} diff --git a/src_tenwa/com/tenwa/httpclient/controller/BigDataController.java b/src_tenwa/com/tenwa/httpclient/controller/BigDataController.java new file mode 100644 index 000000000..f7a25af04 --- /dev/null +++ b/src_tenwa/com/tenwa/httpclient/controller/BigDataController.java @@ -0,0 +1,1030 @@ +package com.tenwa.httpclient.controller; + +import java.io.File; +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.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.regex.Pattern; + +import org.dom4j.Document; +import org.dom4j.Element; +import org.dom4j.io.SAXReader; +import org.dom4j.tree.DefaultAttribute; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.amarsoft.are.jbo.BizObject; +import com.amarsoft.are.jbo.JBOFactory; +import com.amarsoft.are.jbo.JBOTransaction; +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.amarsoft.dict.als.manage.CodeManager; +import com.amarsoft.dict.als.object.Item; +import com.tenwa.comm.exception.BusinessException; +import com.tenwa.httpclient.HttpClientUtil; +import com.tenwa.httpclient.PyUtils; +import com.tenwa.httpclient.resources.BigDataPropertiesUtil; +import com.tenwa.reckon.util.UUIDUtil; +import com.tenwa.util.SerialNumberUtil; + + +public class BigDataController { + + public String getDataApplyId(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 {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); + } + 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()); + System.out.println("======================sql========================================================"); + System.out.println("======================"+sql+"========================================================"); + System.out.println("======================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"; + } + System.out.println("======================result========================================================"); + System.out.println("======================"+result+"========================================================"); + System.out.println("======================result========================================================"); + + return result; + } + public String getAndSavePengyuanData(Map 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 params, String table, Transaction Sqlca, String actionType, String applyId, Page CurPage, Map id) throws Exception { + String type = "html"; + String htmlFile = ""; + System.out.println("------------------鹏元("+table+")拉取时间----------------------"); + System.out.println(""); + System.out.println(""); + System.out.println("------------------"+StringFunction.getTodayNow()+"----------------------"); + System.out.println(""); + System.out.println(""); + System.out.println("------------------鹏元("+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; + } + System.out.println("==================" + table + "@" + type + "获取数据===================="); + String result = this.getQueryReport(params, type); + System.err.println(result); + System.out.println("==================" + table + "@" + type + "获取数据===================="); + + @SuppressWarnings("deprecation") + Configure configure = Configure.getInstance(); + String fileSavePath = configure.getParameter("FileSavePath") + File.separator + "pengyuan" + File.separator; + String FlowNo = CurPage.getParameter("FlowNo"); + 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_" + table + "_log (id, apply_id, type, html_url, html_param, inputuserid, inputorgid, inputtime)" + + " 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, CurPage.getUser().getUserID()); + ps.setString(5, CurPage.getUser().getOrgID()); + ps.setString(6, StringFunction.getTodayNow()); + 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_" + table + " where id = '" + applyId + "'")); + PreparedStatement ps1 = null; + if("ExceedTimLlimitApply".equals(FlowNo)&&html_data != null){//如果超期案件再次调用鹏元大数据,并且是save状态 + ps1 = conn.prepareStatement("update bigdata_" + table + " 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_" + table + "_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("==================" + table + "@" + type + "获取数据===================="); + String xmlResult = this.getQueryReport(params, type); + System.out.println("==================" + table + "@" + type + "获取数据===================="); + + //String xmlPath = HttpClientUtil.queryReport(xmlResult, type, fileSavePath + "xml" + File.separator + applyId + File.separator); + //savePengyuanData(applyId, xmlPath, table, 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_" + table + " (id," + keyword.toString() + ",xml_data,html_data," + + "inputuserid,inputorgid,inputtime) values('" + applyId + "'," + keywordValue.toString() + ",'" + + xmlResult + "','" + htmlFile.split("@")[1] + "','" + CurPage.getUserId() + "','" + CurPage.getUser().getOrgID() + "','" + StringFunction.getTodayNow() + "')").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 htmlFile.split("@")[1]; + } + + @SuppressWarnings({ "unchecked"}) + public static void savePengyuanData(String applyId, String xmlPath, String type, Connection conn) throws Exception { + SAXReader reader = new SAXReader(); + File file = new File(xmlPath); + Document document = reader.read(file); + Element root = document.getRootElement(); + Map otherFields = new HashMap(); + otherFields.put("APPLY_ID", applyId); + Statement stat = null; + try { + stat = conn.createStatement(); + List rootAttribute = root.attributes(); + JSONObject obj = new JSONObject(); + String reportID = ""; + String batNo = ""; + List stringFields = new ArrayList(); + stringFields.add("batNo"); + stringFields.add("reportID"); + Map dateFields = new HashMap(); + dateFields.put("receiveTime", "yyyymmdd hh24:mi:ss"); + dateFields.put("buildEndTime", "yyyy-mm-dd hh24:mi:ss"); + for(DefaultAttribute el : rootAttribute) { + if("batNo".equals(el.getName())) { + batNo = el.getStringValue(); + } + obj.put(el.getName(), el.getStringValue()); + } + //存储cisReports + stat.execute(getInsertSql(obj, "bigdata_py_cis_report", null, otherFields, true, dateFields, stringFields)); + otherFields.remove("ID"); + otherFields.put("BAT_NO", batNo); + List cisReports = root.elements(); + for(Element cisReport : cisReports) { + //存储cisReport + obj = new JSONObject(); + List crAttributes = cisReport.attributes(); + for(DefaultAttribute crAttribute : crAttributes) { + if("reportID".equals(crAttribute.getName())) { + reportID = crAttribute.getStringValue(); + } + obj.put(crAttribute.getName(), crAttribute.getStringValue()); + } + stat.execute(getInsertSql(obj, "bigdata_py_cis_report_list", null, otherFields, true, dateFields, stringFields)); + otherFields.remove("ID"); + otherFields.put("REPORTID", reportID); + //存储queryConditions + Element queryCondition = cisReport.element("queryConditions"); + List items = queryCondition.elements("item"); + for(Element item : items) { + obj = new JSONObject(); + List subItem = item.elements(); + for(Element si : subItem) { + obj.put(si.getName(), si.getTextTrim()); + } + stat.execute(getInsertSql(obj, "bigdata_py_cis_query_condition", null, otherFields, true, dateFields, stringFields)); + otherFields.remove("ID"); + } + if("pengyuan_pr".equals(type)) {//个人风险评估 + JSONObject object = new JSONObject(); + object.put("type", "table"); + object.put("tableName", "bigdata_py_person_risk_assess"); + List fieldList = new ArrayList(); + fieldList.add("checkResult"); + fieldList.add("riskType"); + object.put("field", fieldList); + savePengyuanResultData(object, cisReport, "personRiskAssess", stat, otherFields, dateFields, stringFields); + } else if("pengyuan_af".equals(type)){//个人反欺诈 + //个人反欺诈风险综述信息 + JSONArray array = new JSONArray(); + JSONObject object = new JSONObject(); + object.put("type", "table"); + object.put("tableName", "bigdata_py_pe_an_sp_de_info"); + List fieldList = new ArrayList(); + fieldList.add("personAntiSpoofingDesc"); + object.put("field", fieldList); + savePengyuanResultData(object, cisReport, "personAntiSpoofingDescInfo", stat, otherFields, dateFields, stringFields); + + //个人反欺诈风险评分信息 + object.clear(); + object.put("type", "table"); + object.put("tableName", "bigdata_py_pe_an_sp_info"); + fieldList.clear(); + fieldList.add("riskScore"); + fieldList.add("riskLevel"); + fieldList.add("suggest"); + fieldList.add("hitTypes"); + object.put("field", fieldList); + savePengyuanResultData(object, cisReport, "personAntiSpoofingInfo", stat, otherFields, dateFields, stringFields); + + //是否命中羊毛党名单 + object.clear(); + object.put("type", "table"); + object.put("tableName", "bigdata_py_ec_info"); + fieldList.clear(); + fieldList.add("state"); + object.put("field", fieldList); + savePengyuanResultData(object, cisReport, "econnoisserurInfo", stat, otherFields, dateFields, stringFields); + + //是否命中欺诈风险名单 + object.clear(); + object.put("type", "table"); + object.put("tableName", "bigdata_py_fraud_risk_info"); + fieldList.clear(); + fieldList.add("state"); + object.put("field", fieldList); + savePengyuanResultData(object, cisReport, "fraudRiskInfo", stat, otherFields, dateFields, stringFields); + + //信贷行为信息 + object.clear(); + object.put("type", "table"); + object.put("tableName", "bigdata_py_credit_behavior_inf"); + fieldList.clear(); + fieldList.add("state"); + object.put("field", fieldList); + savePengyuanResultData(object, cisReport, "creditBehaviorInfo", stat, otherFields, dateFields, stringFields); + + //信贷逾期名单 + array.clear(); + object.clear(); + object.put("type", "tables"); + object.put("subTable", array); + fieldList.clear(); + + JSONObject subTable1 = new JSONObject(); + subTable1.put("name", "overdueStat"); + subTable1.put("type", "table"); + subTable1.put("tableName", "bigdata_py_overdue_state"); + fieldList.add("overdueAmount"); + fieldList.add("overdueTotal"); + fieldList.add("overdueNoClosedCnt"); + subTable1.put("field", fieldList); + JSONObject subTable2 = new JSONObject(); + subTable2.put("name", "overdueDetails"); + subTable2.put("type", "arrayTable"); + subTable2.put("tableName", "bigdata_py_overdue_detail"); + fieldList = new ArrayList(); + fieldList.add("overdueDays"); + fieldList.add("overdueAmount"); + fieldList.add("settlement"); + subTable2.put("field", fieldList); + array.add(subTable1); + array.add(subTable2); + savePengyuanResultData(object, cisReport, "overdueLoanInfo", stat, otherFields, dateFields, stringFields); + + //个人被机构查询概要信息 + array.clear(); + object.clear(); + object.put("type", "tables"); + object.put("subTable", array); + fieldList.clear(); + + subTable1 = new JSONObject(); + subTable1.put("name", "items"); + subTable1.put("type", "arrayTable"); + subTable1.put("tableName", "bigdata_py_his_que_info"); + fieldList.add("unitMember"); + fieldList.add("last1Month"); + fieldList.add("last3Month"); + fieldList.add("last6Month"); + fieldList.add("last12Month"); + fieldList.add("last18Month"); + fieldList.add("last24Month"); + subTable1.put("field", fieldList); + + subTable2 = new JSONObject(); + subTable2.put("name", "count"); + subTable2.put("type", "table"); + subTable2.put("tableName", "bigdata_py_his_que_info_count"); + fieldList = new ArrayList(); + fieldList.add("last1Month"); + fieldList.add("last3Month"); + fieldList.add("last6Month"); + fieldList.add("last12Month"); + fieldList.add("last18Month"); + fieldList.add("last24Month"); + subTable2.put("field", fieldList); + + JSONObject subTable3 = new JSONObject(); + subTable3.put("name", "suspectedBulllending"); + subTable3.put("type", "table"); + subTable3.put("tableName", "bigdata_py_his_que_info_sb"); + fieldList = new ArrayList(); + fieldList.add("appplyCnt"); + fieldList.add("applyNetLoanCnt"); + fieldList.add("applyFinclCnt"); + subTable3.put("field", fieldList); + + array.add(subTable1); + array.add(subTable2); + array.add(subTable3); + savePengyuanResultData(object, cisReport, "historySimpleQueryInfo", stat, otherFields, dateFields, stringFields); + + //风险信息 + array.clear(); + object.clear(); + object.put("type", "tables"); + object.put("subTable", array); + fieldList.clear(); + + subTable1 = new JSONObject(); + subTable1.put("name", "stat"); + subTable1.put("type", "table"); + subTable1.put("tableName", "bigdata_py_pr_stat"); + fieldList.add("totleCount"); + fieldList.add("alCount"); + fieldList.add("zxCount"); + fieldList.add("sxCount"); + fieldList.add("swCount"); + fieldList.add("cqggCount"); + fieldList.add("wdyqCount"); + subTable1.put("field", fieldList); + + subTable2 = new JSONObject(); + subTable2.put("name", "summary"); + subTable2.put("type", "tables"); + JSONArray subArray = new JSONArray(); + subTable2.put("subTable", subArray); + + subTable3 = new JSONObject(); + subTable3.put("name", "als"); + subTable3.put("type", "array"); + subTable3.put("tableName", "bigdata_py_pr_als"); + fieldList = new ArrayList(); + fieldList.add("recordId"); + fieldList.add("bt"); + fieldList.add("ajlx"); + fieldList.add("sjnf"); + fieldList.add("dsrlx"); + subTable3.put("field", fieldList); + subArray.add(subTable3); + + JSONObject subTable4 = new JSONObject(); + subTable4.put("name", "zxs"); + subTable4.put("type", "array"); + subTable4.put("tableName", "bigdata_py_pr_zxs"); + fieldList = new ArrayList(); + fieldList.add("recordId"); + fieldList.add("bt"); + fieldList.add("zxbd"); + fieldList.add("larq"); + subTable4.put("field", fieldList); + subArray.add(subTable4); + + JSONObject subTable5 = new JSONObject(); + subTable5.put("name", "sxs"); + subTable5.put("type", "array"); + subTable5.put("tableName", "bigdata_py_pr_sxs"); + fieldList = new ArrayList(); + fieldList.add("recordId"); + fieldList.add("bt"); + fieldList.add("larq"); + fieldList.add("fbrq"); + subTable5.put("field", fieldList); + subArray.add(subTable5); + + JSONObject subTable6 = new JSONObject(); + subTable6.put("name", "sws"); + subTable6.put("type", "array"); + subTable6.put("tableName", "bigdata_py_pr_sws"); + fieldList = new ArrayList(); + fieldList.add("recordId"); + fieldList.add("bt"); + fieldList.add("ggrq"); + subTable6.put("field", fieldList); + subArray.add(subTable6); + + JSONObject subTable7 = new JSONObject(); + subTable7.put("name", "cqs"); + subTable7.put("type", "array"); + subTable7.put("tableName", "bigdata_py_pr_cqs"); + fieldList = new ArrayList(); + fieldList.add("recordId"); + fieldList.add("bt"); + fieldList.add("fbrq"); + subTable7.put("field", fieldList); + subArray.add(subTable7); + + JSONObject subTable8 = new JSONObject(); + subTable8.put("name", "wdyqs"); + subTable8.put("type", "array"); + subTable8.put("tableName", "bigdata_py_pr_wdyqs"); + fieldList = new ArrayList(); + fieldList.add("recordId"); + fieldList.add("bt"); + fieldList.add("fbrq"); + subTable8.put("field", fieldList); + subArray.add(subTable8); + + array.add(subTable1); + array.add(subTable2); + savePengyuanResultData(object, cisReport, "personRiskInfo", stat, otherFields, dateFields, stringFields); + } + } + } catch(Exception e) { + e.printStackTrace(); + throw new BusinessException("鹏元数据明细存储失败"); + } finally { + if(stat != null) stat.close(); + } + } + + @SuppressWarnings("unchecked") + public static void savePengyuanResultData(JSONObject dataType, Element parentElement, String elementName, Statement stat, Map otherFields, Map dateFields, List stringFields) throws Exception { + Element element = parentElement.element(elementName); + JSONObject obj = new JSONObject(); + List 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 otherFields, Map dateFields, List stringFields) throws SQLException { + if(dataType != null) { + JSONObject obj = null; + if("table".equals(dataType.get("type"))) { + List fieldList = (List)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 fieldList = (List)dataType.get("field"); + List 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 excludeFields, Map detailOtherFields, Map 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 excludeFields, Map detailOtherFields, Map 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 dataExcludeField = new ArrayList(); + 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 excludeFields, Map otherFields) { + return getInsertSql(obj, tableName, excludeFields, otherFields, true, null, null); + } + + public static String getInsertSql(JSONObject obj, String tableName, List excludeFields, + Map otherFields, boolean isCheckNumber, Map dateFields, List stringFields) { + String sql = "INSERT INTO " + tableName.toUpperCase() + "({keys}) VALUES({values})"; + String keys = ""; + String values = ""; + Set> fields = obj.entrySet(); + if(fields.size() == 0) { + return ""; + } + boolean flag = false; + String id = ""; + for(Entry 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(Entry 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); + System.out.println("[执行]" + 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 dateFields) { + if(dateFields != null) { + for(Entry dateField : dateFields.entrySet()) { + if(dateField.getKey().equals(key)) { + return "TO_DATE('" + value + "', '" + dateField.getValue() + "')"; + } + } + return "'" + value + "'"; + } + return "'" + value + "'"; + } + + public static String changeKey(String key) { + return BigDataController.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; + } + + public String getQueryReport(Map params, String type) throws Exception { + System.out.println("========================鹏元请求参数=================="); + System.out.println(params); + String queryCondition = HttpClientUtil.getQueryCondition(params); + System.out.println(queryCondition); + Object[] para = new Object[]{ + BigDataPropertiesUtil.get("userId"), + BigDataPropertiesUtil.get("password"), + queryCondition, + type}; + System.out.println(para); + System.out.println("========================鹏元请求参数=================="); + String result = ""; + try{ + result = PyUtils.requestApi( + BigDataPropertiesUtil.get("pengyuanUrl"), + BigDataPropertiesUtil.get("methodType"), + para); + System.out.println(result); + } catch(Exception e) { + e.printStackTrace(); + throw new BusinessException("获取大数据失败"); + } + + return result; + } + + + public static Map getMapCustomerInfoPerson(String flowunid, Transaction Sqlca) throws Exception { + String sql = " select p.mobile, " + + " p.fullname, " + + " p.certid, " + + " ca.acc_number," + + " address.FULLADDRESS," + + " acl.itemname," + + " c.bankno " + + " from lb_union_lessee_temp lb " + + " left join CUSTOMER_PERSON_TEMP p " + + " on p.customerid = lb.customer_id " + + " and p.flowunid = lb.flowunid " + + " left join customer_address_temp address " + + " on address.customerid = p.customerid " + + " left join Customer_Account_Temp ca " + + " on lb.project_id = ca.project_id " + + " and ca.flowunid = lb.flowunid " + + " and ca.acc_info = 'Debit' " + + " left join customer_cert_temp cert on cert.customerid=p.customerid and cert.flowunid=p.flowunid " + + " left join code_library c on c.itemno=cert.certtype and c.codeno='CertType' " + + " left join code_library acl on acl.itemno = address.RESIDENTCITY and acl.codeno='AreaCode' " + + " where lb.flowunid = '"+flowunid+"' "; + ASResultSet rs = Sqlca.getASResultSet(new SqlObject(sql)); + Map MapParams = new HashMap(); + if(rs.next()) { + String fullname=rs.getString("fullname"); + String certid=rs.getString("certid"); + String mobile=rs.getString("mobile"); + String acc_number=rs.getString("acc_number"); + String bankno=rs.getString("bankno"); + String fullAddress=rs.getString("FULLADDRESS"); + String city = rs.getString("itemname"); + city = city == null ? "" : city; + String regexp = "^[\u4e00-\u9fa5]+省[\u4e00-\u9fa5]+市[\u4e00-\u9fa5]*$"; + if(Pattern.matches(regexp, city)) { + city = city.substring(city.indexOf("省") + 1, city.indexOf("市")); + } + MapParams.put("idNo", certid); + MapParams.put("idType", bankno == null ? "0" : bankno); + MapParams.put("name", fullname); + MapParams.put("mobileNo", mobile); + MapParams.put("address", fullAddress); + MapParams.put("cardNo", acc_number == null ? "0" : acc_number); + MapParams.put("cardNos", acc_number); + MapParams.put("email", "luojiankuaiyug@163.com"); + MapParams.put("city", city); + } + return MapParams; + } + public static Map getMapGuaranteeInfoPerson(String flowunid, String CustId, Transaction Sqlca) throws Exception { + String sql = " select lgut.assuror, cpt.mobile, cpt.fullname, cpt.certid, cat.fulladdress,acl.itemname " + + " from LB_GUARANTEE_UNIT_TEMP lgut " + + " left join CUSTOMER_PERSON_TEMP cpt " + + " on cpt.customerid = lgut.assuror " + + " and cpt.flowunid = lgut.flowunid " + + " left join CUSTOMER_ADDRESS_TEMP cat " + + " on cat.customerid = lgut.assuror " + + " and cat.flowunid = lgut.flowunid " + + " left join code_library acl on acl.itemno = cat.RESIDENTCITY and acl.codeno = 'AreaCode' " + + " where lgut.flowunid = '"+flowunid+"' " + + " and lgut.assuror = '"+CustId+"'"; + ASResultSet rs = Sqlca.getASResultSet(new SqlObject(sql)); + Map MapParams = new HashMap(); + if(rs.next()) { + String fullname=rs.getString("fullname"); + String certid=rs.getString("certid"); + String mobile=rs.getString("mobile"); + String fullAddress=rs.getString("fulladdress"); + String city = rs.getString("itemname"); + city = city == null ? "" : city; + String regexp = "^[\u4e00-\u9fa5]+省[\u4e00-\u9fa5]+市[\u4e00-\u9fa5]*$"; + if(Pattern.matches(regexp, city)) { + city = city.substring(city.indexOf("省") + 1, city.indexOf("市")); + } + MapParams.put("idNo", certid); + MapParams.put("idType", "0"); + MapParams.put("name", fullname); + MapParams.put("mobileNo", mobile); + MapParams.put("address", fullAddress); + MapParams.put("cardNo", "0");//担保人没有录入银行卡信息 + MapParams.put("cardNos", "0"); + MapParams.put("email", "luojiankuaiyug@163.com"); + MapParams.put("city", city); + } + return MapParams; + } + + public String getCustomerInfoPerson(String flowunid, Transaction Sqlca) throws Exception { + String sql = " select p.mobile, " + + " p.fullname, " + + " p.certid, " + + " ca.acc_number," + + " c.bankno " + + " from lb_union_lessee_temp lb " + + " left join CUSTOMER_PERSON_TEMP p " + + " on p.customerid = lb.customer_id " + + " and p.flowunid = lb.flowunid " + + " left join customer_address_temp address " + + " on address.customerid = p.customerid and address.flowunid = lb.flowunid " + + " left join Customer_Account_Temp ca " + + " on lb.project_id = ca.project_id " + + " and ca.flowunid = lb.flowunid " + + " and ca.acc_info = 'Debit' " + + " left join customer_cert_temp cert on cert.customerid=p.customerid and cert.flowunid=p.flowunid " + + " left join code_library c on c.itemno=cert.certtype and c.codeno='CertType' " + + " where lb.flowunid = '"+flowunid+"' "; + ASResultSet rs = Sqlca.getASResultSet(new SqlObject(sql)); + String result = ""; + if(rs.next()) { + String fullname=rs.getString("fullname") ; + String certid=rs.getString("certid") ; + String mobile=rs.getString("mobile") ; + String acc_number=rs.getString("acc_number") ; + result = "true@" + fullname +"@"+ certid+"@"+mobile+"@"+acc_number; + } else { + result = "false"; + } + return result; + } + + public boolean checkData(String applyId, BizObject rule, Transaction tran, JSONObject object) throws Exception { + String bigDataType = rule.getAttribute("BIGDATATYPE").toString(); + String ruleId = rule.getAttribute("ID").toString(); + String ruleNumber = rule.getAttribute("RULENUMBER").toString(); + String ruleFormula = rule.getAttribute("RULELOGIC").toString(); + String ruleCompare = rule.getAttribute("RETURNRESULT").toString(); + Item item = CodeManager.getItem("bigdata_rule", ruleNumber); + if(item == null) { + throw new BusinessException("未配置当前规则编号的数据字典"); + } + String itemDescribe = item.getItemDescribe(); + if(itemDescribe == null || "".equals(itemDescribe)) { + return false; + } + String tableName = itemDescribe.split("@")[0]; + String field = itemDescribe.split("@")[1]; + String value = ""; + if("tongdun".equals(bigDataType)){ + if("26221714".equals(ruleNumber)){ + value = tran.getString("select " + field + " from " + tableName + " where rownum = 1 and apply_id = '" + applyId + "' and description like '%3个月内申请人在多个平台申请借款%' "); + }else{ + value = tran.getString("select " + field + " from " + tableName + " where rownum = 1 and apply_id = '" + applyId + "' and rule_id = '"+ruleCompare+"' "); + } + }else if("pengyuan_af".equals(bigDataType)){ + if("subReportType(14227)".equals(ruleNumber)||"subReportType(14239)".equals(ruleNumber)){ + value = tran.getString("select case when " + field + " > 0 then '是' else '否' end from " + tableName + " where rownum = 1 and apply_id = '" + applyId + "'"); + }else{ + value = tran.getString("select " + field + " from " + tableName + " where rownum = 1 and apply_id = '" + applyId + "'"); + } + }else{ + value = tran.getString("select " + field + " from " + tableName + " where rownum = 1 and apply_id = '" + applyId + "'"); + } + object.put("APPLY_ID", applyId); + object.put("RULE_ID", ruleId); + object.put("OLDRESULT", ruleCompare); + object.put("NEWRESULT", value); + if(value == null || "".equals(value)) { + object.put("ISHIT", "0"); + return false; + } + if("".equals(ruleCompare) || ruleCompare == null) { + object.put("ISHIT", "0"); + return false; + } + switch(ruleFormula) { + case ">": + if(!isNumber(value) || !isNumber(ruleCompare)) { + throw new BusinessException("大数据规则比较类型错误"); + } + if(new BigDecimal(value).compareTo(new BigDecimal(ruleCompare)) > 0) { + return true; + } + break; + case "=": + if(value.equals(ruleCompare)) { + return true; + } + break; + case "<": + if(!isNumber(value) || !isNumber(ruleCompare)) { + throw new BusinessException("大数据规则比较类型错误"); + } + if(new BigDecimal(value).compareTo(new BigDecimal(ruleCompare)) < 0) { + return true; + } + break; + case "<>": + if(ruleCompare.split(",").length<2){ + throw new BusinessException("大数据规则返回值错误"); + } + if(!isNumber(value) || !isNumber(ruleCompare.split(",")[0]) || !isNumber(ruleCompare.split(",")[1])) { + throw new BusinessException("大数据规则比较类型错误"); + } + if(new BigDecimal(value).compareTo(new BigDecimal(ruleCompare.split(",")[0])) >= 0 && new BigDecimal(value).compareTo(new BigDecimal(ruleCompare.split(",")[1])) <= 0) { + return true; + } + break; + } + object.put("ISHIT", "0"); + return false; + } + + + public void getPengyuanAfData(Page CurPage, Transaction Sqlca, Map applyIds) throws Exception { + String type = ""; + String applyId = ""; + String flowunid = CurPage.getParameter("ObjectNo"); + String result = this.getDataApplyId(CurPage, "pengyuan_af", Sqlca); + if("false".equals(result)) { + JBOTransaction tx = JBOFactory.createJBOTransaction(); + applyId = SerialNumberUtil.getPengyuanNumber(tx); + tx.commit(); + type = "SAVE"; + } else { + String[] res = result.split("@"); + applyId = res[1]; + type = "GET"; + } + + Map params = new HashMap(); //初始化参数 + String resultals = this.getCustomerInfoPerson(flowunid, Sqlca) ; + if(!"false".equals(resultals)){ + String[] sReturn = resultals.split("@"); + params.put("queryType","25136"); + params.put("name",sReturn[1]); + params.put("documentNo",sReturn[2]); + params.put("phone",sReturn[3]); + params.put("queryReasonID","101"); + params.put("subreportIDs","96043"); + params.put("refID",""); + } + Map id = new HashMap(); + this.getAndSavePengyuanData(params, "pengyuan_af", Sqlca, type, applyId, CurPage, id); + applyIds.put("pengyuan_af", applyId); + } + +} \ No newline at end of file diff --git a/src_tenwa/com/tenwa/httpclient/resources/BigDataPropertiesUtil.java b/src_tenwa/com/tenwa/httpclient/resources/BigDataPropertiesUtil.java new file mode 100644 index 000000000..2bd2562ae --- /dev/null +++ b/src_tenwa/com/tenwa/httpclient/resources/BigDataPropertiesUtil.java @@ -0,0 +1,40 @@ +package com.tenwa.httpclient.resources; + +import java.io.IOException; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Properties; +import java.util.concurrent.ConcurrentHashMap; + +import com.amarsoft.are.ARE; + +public class BigDataPropertiesUtil { + private static Map attributes; + + public static void load() { + attributes = new ConcurrentHashMap(); + Properties prop = new Properties(); + try { + prop.load(BigDataPropertiesUtil.class.getResourceAsStream("/bigdata.properties")); + for(Entry entry : prop.entrySet()) { + if(entry.getKey() == null || entry.getValue() == null) { + continue; + } + attributes.put(entry.getKey().toString(), entry.getValue().toString()); + } + } catch (IOException e) { + e.printStackTrace(); + ARE.getLog().error("init BigDataPropertiesUtil info failed"); + } + ARE.getLog().info("init BigDataPropertiesUtil info success"); + } + + public static void destroy() { + if(attributes != null) attributes.clear(); + } + + public static String get(String propName) { + if(attributes == null) load(); + return attributes.get(propName); + } +}