apzl_leasing/src_tenwa/com/tenwa/flow/Bigdata/BaiRongVerification.java
2021-03-19 09:51:11 +08:00

435 lines
17 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

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

package com.tenwa.flow.Bigdata;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import jbo.com.tenwa.lease.comm.LB_BAIRONG_BEFORELOAN;
import jbo.com.tenwa.lease.comm.LB_BAIRONG_LOG;
import jbo.com.tenwa.lease.comm.LB_BAIRONG_LOGIN;
import jbo.com.tenwa.lease.comm.LB_BAIRONG_VERIFICATION;
import jbo.ui.system.CODE_LIBRARY;
import net.sf.json.JSONObject;
import org.apache.commons.lang.StringUtils;
import com.amarsoft.are.jbo.BizObject;
import com.amarsoft.are.jbo.BizObjectManager;
import com.amarsoft.are.jbo.JBOFactory;
import com.amarsoft.are.jbo.JBOTransaction;
import com.amarsoft.context.ASUser;
import com.base.util.DateUtil;
import com.bfd.facade.MerchantServer;
import com.bfd.util.HttpConnectionManager4;
import com.bfd.util.MD5Utils;
import com.tenwa.comm.util.date.DateAssistant;
import com.tenwa.httpclient.resources.BaiRongPropertiesUtil;
import com.tenwa.reckon.util.UUIDUtil;
import com.tenwa.util.MultiSubjectUtil;
public class BaiRongVerification {
//深圳主体信息
private static String sz_userName=BaiRongPropertiesUtil.get("sz_userName");
private static String sz_password=BaiRongPropertiesUtil.get("sz_password");
private static String sz_apiCode=BaiRongPropertiesUtil.get("sz_apiCode");
private static String sz_dq_number=BaiRongPropertiesUtil.get("sz_dq_number");
private static String sz_yz_number=BaiRongPropertiesUtil.get("sz_yz_number");
private static String sz_loginName=BaiRongPropertiesUtil.get("sz_loginName");
private static String sz_apiName=BaiRongPropertiesUtil.get("sz_apiName");
private static String sz_verification=BaiRongPropertiesUtil.get("sz_verification");
private static String sz_downloadUrl=BaiRongPropertiesUtil.get("sz_downloadUrl");
private static String sz_downloadPath=BaiRongPropertiesUtil.get("sz_downloadPath");
//天津主体信息
private static String tj_userName=BaiRongPropertiesUtil.get("tj_userName");
private static String tj_password=BaiRongPropertiesUtil.get("tj_password");
private static String tj_apiCode=BaiRongPropertiesUtil.get("tj_apiCode");
private static String tj_dq_number=BaiRongPropertiesUtil.get("tj_dq_number");
private static String tj_yz_number=BaiRongPropertiesUtil.get("tj_yz_number");
private static String tj_loginName=BaiRongPropertiesUtil.get("tj_loginName");
private static String tj_apiName=BaiRongPropertiesUtil.get("tj_apiName");
private static String tj_verification=BaiRongPropertiesUtil.get("tj_verification");
private static String tj_downloadUrl=BaiRongPropertiesUtil.get("tj_downloadUrl");
private static String tj_downloadPath=BaiRongPropertiesUtil.get("tj_downloadPath");
private String subjectId;
private String flowUnid;
private String projectId;
private String contractId;
private String name;
private String certid;
private String phone;
private String userId;
private static MerchantServer ms = new MerchantServer();
public String getData(JBOTransaction tx){
String datePath = DateUtil.getSystemTimeByFormat("yyyy/MM/dd");
String apiCode = "";
String url = "";
String filePath = "";
String apiName = "";
String verification = "";
String strategy_id = "";
String conf_id = "";
if(MultiSubjectUtil.SZSUBJECTID.equals(subjectId)){//深圳主体
apiName= sz_apiName ;
apiCode= sz_apiCode ;
url = sz_downloadUrl;
filePath = sz_downloadPath+datePath+"/";
verification = sz_verification;
strategy_id = sz_dq_number;
conf_id = sz_yz_number;
}else if(MultiSubjectUtil.TJSUBJECTID.equals(subjectId)){//天津主体
apiName= tj_apiName ;
apiCode=tj_apiCode;
url = tj_downloadUrl;
filePath = tj_downloadPath+datePath+"/";
verification = tj_verification;
strategy_id = tj_dq_number;
conf_id = tj_yz_number;
}else{
System.out.println("主体id="+subjectId);
return "为找到对应的主体信息!!!";
}
ASUser user = new ASUser(userId);
String dMessage = this.doIdentityVerification(tx, apiName, apiCode, url, filePath,"0",user,strategy_id);
System.out.println("贷前信用数据:"+dMessage);
String yMessage = this.doIdentityVerification(tx, verification, apiCode, url, filePath,"1",user,conf_id);
System.out.println("验证信用数据:"+yMessage);
if(dMessage.equals("success") && yMessage.equals("success") ){
return "success";
}else {
return "获取数据失败!";
}
}
//获取贷前校验
public String doIdentityVerification(JBOTransaction tx,String apiName,String apiCode,String url,String filePath,String sign,ASUser user,String policyNumber){
String swiftNumber = "";
String fileName = "";
String code = "" ;
String messge= "" ;
String res = "";
try {
BizObjectManager manage = null ;
String logid = UUIDUtil.getUUID();
JSONObject jsonData = new JSONObject();
JSONObject reqData = new JSONObject();
jsonData.put("apiName",apiName);
//贷前的策略编号(请查看策略配置表)
if("0".equals(sign)){
manage = JBOFactory.getBizObjectManager(LB_BAIRONG_BEFORELOAN.CLASS_NAME,tx);
fileName = name+"的贷前校验";
reqData.put("strategy_id",policyNumber);
}else if ("1".equals(sign)){
manage = JBOFactory.getBizObjectManager(LB_BAIRONG_VERIFICATION.CLASS_NAME,tx);
fileName = name+"的验证报告";
reqData.put("conf_id",policyNumber);
}
BizObject bj= manage.createQuery(" flow_unid=:flow_unid and certid=:certid ").setParameter("flow_unid", flowUnid).setParameter("certid", certid).getSingleResult(true);
String codeStatus = bj == null ? "" : bj.getAttribute("code_status").toString();
if(!(codeStatus.equals("00")||codeStatus.equals("100002"))){
if(bj == null){
bj = manage.newObject();
}
String tokenid = this.getTokenid(tx , user);
if(tokenid.isEmpty()){
return "获取tokenid失败";
}
jsonData.put("tokenid",tokenid);
//请求参数 id cell name (如产品文档有其他必传参数按照文档为主)
reqData.put("id",certid);
reqData.put("cell",phone);
reqData.put("name",name);
jsonData.put("reqData",reqData);
System.out.println("请求参数:"+jsonData.toString());
res = ms.getApiData(jsonData.toString(),apiCode);
if(StringUtils.isNotBlank(res)){
JSONObject json = JSONObject.fromObject(res);
code = json.containsKey("code") ? json.getString("code") : "" ;
System.out.println("======================");
System.out.println("code:"+code);
System.out.println("======================");
if(code.equals("100007")){
tokenid = this.getTokenid(tx, user);
jsonData = JSONObject.fromObject(jsonData.toString());
jsonData.put("tokenid",tokenid);
res = ms.getApiData(jsonData.toString(),apiCode);
json = JSONObject.fromObject(res);
}else if(code.equals("00") || code.equals("100002") ||code.equals("s")){
swiftNumber = JSONObject.fromObject(res).getString("swift_number");
String download = this.download(tx, user, swiftNumber, apiCode, tokenid, url, filePath, bj ,fileName);
if(download.indexOf("下载成功")>=0){
messge = "success";
}else{
messge = "下载失败!";
System.out.println(sign+"类型下载pdf失败");
}
}else{
System.out.println("返回参数:"+res);
}
}
bj.setAttributeValue("certid", certid);
bj.setAttributeValue("name", name);
bj.setAttributeValue("code_status", code);
bj.setAttributeValue("swift_number", swiftNumber);
bj.setAttributeValue("log_id", logid);
bj.setAttributeValue("project_id", projectId);
bj.setAttributeValue("flow_unid", flowUnid);
bj.setAttributeValue("subjectId", subjectId);
bj.setAttributeValue("inputuserid", user.getUserID());
bj.setAttributeValue("inputorgid", user.getOrgID());
bj.setAttributeValue("inputtime", DateUtil.getSystemTimeByFormat("yyyy/MM/dd HH:mm:ss"));
manage.saveObject(bj);
}else if (!(bj.getAttribute("dcode_status").toString().equals("00"))){
String tokenid = this.getTokenid(tx , user);
if(tokenid.isEmpty()){
return "获取tokenid失败";
}
swiftNumber = bj.getAttribute("swift_number").toString();
String download = this.download(tx, user, swiftNumber, apiCode, tokenid, url, filePath, bj ,fileName);
manage.saveObject(bj);
if(download.indexOf("下载成功")>=0){
messge = "success";
}else{
messge = "下载失败!";
System.out.println(sign+"类型下载pdf失败");
}
}else{
return "success";
}
//保存日志信息
BizObjectManager lblManage = JBOFactory.getBizObjectManager(LB_BAIRONG_LOG.CLASS_NAME,tx);
BizObject lbl = lblManage.newObject();
lbl.setAttributeValue("id", logid);
lbl.setAttributeValue("request_content", reqData);
lbl.setAttributeValue("content_type", sign);
lbl.setAttributeValue("response_content", res);
lbl.setAttributeValue("project_id", projectId);
lbl.setAttributeValue("flow_unid", flowUnid);
lbl.setAttributeValue("subjectId", subjectId);
lbl.setAttributeValue("inputuserid", user.getUserID());
lbl.setAttributeValue("inputorgid", user.getOrgID());
lbl.setAttributeValue("inputtime", DateUtil.getSystemTimeByFormat("yyyy/MM/dd HH:mm:ss"));
lblManage.saveObject(lbl);
} catch (Exception e) {
e.printStackTrace();
messge = "false";
}
return messge;
}
public String download(JBOTransaction tx,ASUser user,String swiftNumber,String apiCode,String tokenid,String url,String filePath,BizObject bj,String fileName) throws Exception{
JSONObject jsonData = new JSONObject();
jsonData.put("swift_number", swiftNumber);
String checkCode = getCheckData(jsonData.toString(), apiCode, tokenid);
Map<String,Object> paramMap = new HashMap<String,Object>();
paramMap.put("tokenid", tokenid);
paramMap.put("apiCode",apiCode);
paramMap.put("jsonData",jsonData);
paramMap.put("checkCode",checkCode);
System.out.println("paramMap->"+paramMap.toString());
File file = new File(filePath);
if (!file.exists()) {
file.mkdirs();
}
BizObjectManager clManage = JBOFactory.getBizObjectManager(CODE_LIBRARY.CLASS_NAME,tx);
BizObject cl = clManage.createQuery(" codeno='baiRong' ").getSingleResult(false);
Thread.currentThread().sleep( Long.parseLong( cl.getAttribute("itemno").getString() ) );
String downFile = HttpConnectionManager4.downFile(url, paramMap,filePath+"/"+swiftNumber+".pdf");
String logid = UUIDUtil.getUUID();
if(downFile.indexOf("下载成功")>=0){
bj.setAttributeValue("dcode_status", "00");
bj.setAttributeValue("file_path", filePath+"/"+swiftNumber+".pdf");
bj.setAttributeValue("file_name", fileName);
}else{
bj.setAttributeValue("dcode_status", downFile);
System.out.println("下载返回参数:"+downFile);
}
bj.setAttributeValue("dlog_id", logid);
//保存日志信息
BizObjectManager lblManage = JBOFactory.getBizObjectManager(LB_BAIRONG_LOG.CLASS_NAME,tx);
BizObject lbl = lblManage.newObject();
lbl.setAttributeValue("id", logid);
lbl.setAttributeValue("request_content", paramMap);
lbl.setAttributeValue("content_type", "d");
lbl.setAttributeValue("response_content", downFile);
lbl.setAttributeValue("project_id", projectId);
lbl.setAttributeValue("flow_unid", flowUnid);
lbl.setAttributeValue("subjectId", subjectId);
lbl.setAttributeValue("inputuserid", user.getUserID());
lbl.setAttributeValue("inputorgid", user.getOrgID());
lbl.setAttributeValue("inputtime", DateUtil.getSystemTimeByFormat("yyyy/MM/dd HH:mm:ss"));
lblManage.saveObject(lbl);
return downFile;
}
private String getCheckData(String jsonData, String apiCode, String tokenId) {
return MD5Utils.genMd5(jsonData + MD5Utils.genMd5(apiCode + tokenId));
}
//获取tokenid的值
public String getTokenid(JBOTransaction tx,ASUser user){
String token="";
String codeStatus = "";
String login_res_str = "" ;
JSONObject reqData = new JSONObject();
try{
BizObjectManager lblManage = JBOFactory.getBizObjectManager(LB_BAIRONG_LOGIN.CLASS_NAME,tx);
BizObject lbl = lblManage.createQuery(" v.ROUND((v.UNIX_TIMESTAMP('"+DateUtil.getSystemTimeByFormat("yyyy/MM/dd HH:mm:ss")+"')-v.UNIX_TIMESTAMP(inputtime))/60)<28 ").getSingleResult(false);
if( lbl!=null && lbl.getAttribute("tokenid")!=null){
token = lbl.getAttribute("tokenid").getString();
}else{
BizObjectManager lbllManage = JBOFactory.getBizObjectManager(LB_BAIRONG_LOG.CLASS_NAME,tx);
lbl = lblManage.newObject();
BizObject lbll = lbllManage.newObject();
if(MultiSubjectUtil.SZSUBJECTID.equals(subjectId)){//深圳主体
reqData.put("userName", sz_userName);
reqData.put("password", sz_password);
reqData.put("loginName", sz_loginName);
reqData.put("apiCode", sz_apiCode);
login_res_str = ms.login(sz_userName,sz_password,sz_loginName,sz_apiCode);
}else if (MultiSubjectUtil.TJSUBJECTID.equals(subjectId)){//天津主体
reqData.put("userName", tj_userName);
reqData.put("password", tj_password);
reqData.put("loginName", tj_loginName);
reqData.put("apiCode", tj_apiCode);
login_res_str = ms.login(tj_userName,tj_password,tj_loginName,tj_apiCode);
}else{
System.out.println("主体id="+subjectId);
return "未找到对应的主体信息!!";
}
if(StringUtils.isNotBlank(login_res_str)){
JSONObject loginJson = JSONObject.fromObject(login_res_str);
codeStatus = loginJson.getString("code");
if(loginJson.containsKey("tokenid")){
token = loginJson.getString("tokenid");
}else {
System.out.println("返回结果异常无token!结果为:"+login_res_str);
}
}
String logid = UUIDUtil.getUUID();
//保存登录日志
lbl.setAttributeValue("code_status", codeStatus);
lbl.setAttributeValue("tokenid", token);
lbl.setAttributeValue("status_name", "");
lbl.setAttributeValue("log_id", logid);
lbl.setAttributeValue("project_id", projectId);
lbl.setAttributeValue("flow_unid", flowUnid);
lbl.setAttributeValue("subjectId", subjectId);
lbl.setAttributeValue("inputuserid", user.getUserID());
lbl.setAttributeValue("inputorgid", user.getOrgID());
lbl.setAttributeValue("inputtime", DateUtil.getSystemTimeByFormat("yyyy/MM/dd HH:mm:ss"));
lblManage.saveObject(lbl);
//保存日志信息
lbll.setAttributeValue("id", logid);
lbll.setAttributeValue("request_content", reqData);
lbll.setAttributeValue("content_type", "tokenid");
lbll.setAttributeValue("response_content", login_res_str);
lbll.setAttributeValue("project_id", projectId);
lbll.setAttributeValue("flow_unid", flowUnid);
lbll.setAttributeValue("subjectId", subjectId);
lbll.setAttributeValue("inputuserid", user.getUserID());
lbll.setAttributeValue("inputorgid", user.getOrgID());
lbll.setAttributeValue("inputtime", DateUtil.getSystemTimeByFormat("yyyy/MM/dd HH:mm:ss"));
lbllManage.saveObject(lbll);
}
}catch (Exception e){
e.printStackTrace();
}
return token;
}
public static void main(String[] arg ){
System.out.println(DateUtil.getSystemTimeByFormat("yyyy/MM/dd HH:mm:ss"));
System.out.println(DateAssistant.getToday());
}
public String getSubjectId() {
return subjectId;
}
public void setSubjectId(String subjectId) {
this.subjectId = subjectId;
}
public String getFlowUnid() {
return flowUnid;
}
public void setFlowUnid(String flowUnid) {
this.flowUnid = flowUnid;
}
public String getProjectId() {
return projectId;
}
public void setProjectId(String projectId) {
this.projectId = projectId;
}
public String getContractId() {
return contractId;
}
public void setContractId(String contractId) {
this.contractId = contractId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCertid() {
return certid;
}
public void setCertid(String certid) {
this.certid = certid;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
}