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 fullname='"+CurPage.getParameter("fullName") +"' and fullcertId='"+CurPage.getParameter("fullcertId")+"' and fullphone='"+CurPage.getParameter("fullphone")+"' and {keyword} group by {gkeyword}"; StringBuffer keyword = new StringBuffer(""); StringBuffer gkeyword = new StringBuffer(""); String FlowNo = ""; for(int i = 1; i <= 5; i ++) { String key = BigDataPropertiesUtil.get("keyword" + i); String keyValue = CurPage.getParameter(key); FlowNo = CurPage.getParameter("FlowNo"); if(key == null || keyValue == null) { continue; } if(keyword.length() != 0) { keyword.append(" and "); gkeyword.append(","); } keyword.append("keyword").append(i).append("='").append(keyValue).append("'"); gkeyword.append("keyword").append(i); } 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") + "/" + "pengyuan" + "/"; String FlowNo = CurPage.getParameter("FlowNo"); String fullcardNo = CurPage.getParameter("fullcardNo"); if(fullcardNo==null||"".equals(fullcardNo)){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_" + table + "_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, CurPage.getUser().getUserID()); ps.setString(5, CurPage.getUser().getOrgID()); ps.setString(6, StringFunction.getTodayNow()); ps.setString(7, CurPage.getParameter("fullName")); ps.setString(8, CurPage.getParameter("fullcertId")); ps.setString(9, CurPage.getParameter("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_" + 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+"'"); } //安鹏客户要求只保留最新数据 if("ebank_af".equals(table)){ SqlObject sql_d = new SqlObject("delete from bigdata_ebank_af where fullcertId='"+CurPage.getParameter("fullcertId")+"'"); Sqlca.executeSQL(sql_d); } SqlObject sql = new SqlObject(("insert into bigdata_" + table + " (id," + keyword.toString() + ",xml_data,html_data," + "inputuserid,inputorgid,inputtime,fullName,fullcertId,fullphone,fullcardNo) values('" + applyId + "'," + keywordValue.toString() + ",'" + xmlResult + "','" + htmlFile.split("@")[1] + "','" + CurPage.getUserId() + "','" + CurPage.getUser().getOrgID() + "','" + StringFunction.getTodayNow() +"','" +CurPage.getParameter("fullName")+"','"+CurPage.getParameter("fullcertId")+"','"+CurPage.getParameter("fullphone")+"','"+fullcardNo+"')").replaceAll(":", "△")); sql.setDebugSql(sql.getDebugSql().replaceAll("△", ":")); sql.setOriginalSql(sql.getOriginalSql().replaceAll("△", ":")); sql.setRunSql(sql.getRunSql().replaceAll("△", ":")); 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("pengyuanServer"), 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); } }