123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833 |
- #coding=utf-8
- import fileinput
- from xml.dom import minidom
- import base64
- import sys
- import os
- # import xmlSelfParser
- from customModel import CustomModel
- from datetime import datetime
- from ini_op import Config;
- base_dir = os.path.dirname(os.path.abspath(__file__)) #当前文件上一层目录的绝对路径
- config = Config(base_dir+"/config.ini");
- productNumXy = config.get("baseconf", "productNumXy")
- productNumJz = config.get("baseconf","productNumJz")
- productNumXxw = config.get("baseconf","productNumXxw")
- productNumFb = config.get("baseconf", "productNumFb")
- productNumKcd = config.get("baseconf", "productNumKcd")
- productNumFd = config.get("baseconf", "productNumFd")
- productNumKn = config.get("baseconf", "productNumKn")
- productNumHst = config.get("baseconf", "productNumHst")
- productNumQk = config.get("baseconf", "productNumQk")
- productNumHc = config.get("baseconf", "productNumHc")
- productNum500 = config.get("baseconf", "productNum500")
- productNumHsz = config.get("baseconf", "productNumHsz")
- #简营
- productNumJy = config.get("baseconf", "productNumJy")
- #新版桔子
- productNumJzA = config.get("baseconf", "productNumJzA")
- #仁东
- productNumRd = config.get("baseconf", "productNumRd")
- #恒昌新
- productNumHcNew = config.get("baseconf", "productNumHcNew")
- #非自定义列表
- busiNum = [productNumJz,productNumXxw,productNumFb,productNumKcd,productNumFd,productNumKn,productNumHst,productNumQk,productNumHc,productNum500,
- productNumJy,productNumJzA,productNumRd,productNumHcNew]
- isPlt = config.get("baseconf", "isPlt");
- import xyHttp
- import hst_rule_set
- import pboc_hc
- import log
- import shutil
- logger = log.logger
- import time
- from dbController import DbController
- dbController = DbController();
- import json
- import requests
- import timeit
- import traceback
- import gzip
- import io
- from xmlParser import XmlParser;
- from xmlParserHsz import XmlParserHsz;
- # from xmlSelfParser import XmlSelfParser;
- from pboc.invokePboc import PBOC
- from mailUtil import MailUtil
- approResult=0
- def gzip_str(string_):
- out = io.BytesIO()
- with gzip.GzipFile(fileobj=out, mode='w') as fo:
- fo.write(string_.encode())
- bytes_obj = out.getvalue()
- return bytes_obj
- def gunzip_bytes_obj(bytes_obj):
- in_ = io.BytesIO()
- in_.write(bytes_obj)
- in_.seek(0)
- with gzip.GzipFile(fileobj=in_, mode='rb') as fo:
- gunzipped_bytes_obj = fo.read()
- return gunzipped_bytes_obj.decode()
- #解析xml数据
- def getBusinessInfo(xmlFile):
- doc = minidom.parse(xmlFile)
- request = doc.documentElement.getElementsByTagName("request")[0]
- responseBody = doc.documentElement.getElementsByTagName("responseBody")[0]
- responseHeader = doc.documentElement.getElementsByTagName("responseHeader")[0]
- result = ""
- xmlData = ""
- isBaihu = "0";
- if len(responseBody.childNodes)==0:
- mailUtil = MailUtil();
- webhook = 'https://oapi.dingtalk.com/robot/send?access_token=64d8b2c7fed4949e9433b807c7c5559939f1517af8f77c1dacb4de19c6910b56'
- resultMsg = getNodeData(responseHeader,"resultMsg")
- if resultMsg =="查询成功,无报告":
- isBaihu = "1"
- elif resultMsg == "输入的姓名与系统收录的姓名不一致":
- isBaihu = "3"
- else:
- isBaihu = "2"#查询失败
- mailUtil.dingtalk("号码:" + xmlFile.split("_")[0] + " 查询失败 ", webhook)
- else:
- responseBodyText = responseBody.childNodes[0].data
- decrpyt_bytes = base64.b64decode(responseBodyText)
- xmlData = gunzip_bytes_obj(decrpyt_bytes)
- #remove by chenqiwang 1105
- xmlPath = xmlFile+".txt"
- # 生成xml格式报告
- with open(xmlPath, 'w', encoding='utf-8') as fp:
- fp.write(xmlData)
- # 非小赢需要解析
- productNum = getNodeData(request, "productNum")
- # print("a")
- # print(productNum + "cc")
- # print("b")
- sqlMap = []
- if productNum != productNumXy:
- if xmlData !="":
- if productNum == productNumHsz:
- result,sqlMap = parseHsz(xmlData)
- # print("HSZ")
- else:
- #跑数据的时候改为parseHsz
- result, sqlMap = parse(xmlData)
- # elif productNum in busiNum:
- # #跑数据的时候改为parseHsz
- # result, sqlMap = parse(xmlData)
- # else :
- # result, sqlMap = parseSelf(xmlData)
- data = {
- "businessNum":getNodeData(request,"businessNum"),
- "coopBusinessNum": getNodeData(request, "coopBusinessNum"),
- "customerNum":getNodeData(request,"customerNum"),
- "certificateNum": getNodeData(request, "certificateNum"),
- "productNum": productNum,
- "creditXml":xmlData,
- "extend": getNodeData(request, "extend"),
- "result":result,
- "isBaihu":isBaihu,
- "sqlMap":sqlMap
- }
- return data
- #解析xml报文
- def parse(xmlData):
- xmlParse = XmlParser()
- result = ""
- sqlMap = []
- try:
- result,sqlMap = xmlParse.parse(xmlData)
- except:
- info = sys.exc_info()
- logger.error(info[0])
- logger.error(info[1])
- logger.error(traceback.extract_tb(info[2], 1))
- return result,sqlMap
- #解析xml报文 汇算帐
- def parseHsz(xmlData):
- xmlParseHsz = XmlParserHsz()
- result = ""
- try:
- result = xmlParseHsz.parse(xmlData)
- except:
- info = sys.exc_info()
- logger.error(info[0])
- logger.error(info[1])
- logger.error(traceback.extract_tb(info[2], 1))
- return result
- # #解析xml报文 自定义
- # def parseSelf(xmlData):
- # xmlParseSelf = XmlSelfParser()
- # result = ""
- # sqlMap = []
- #
- # try:
- # result,sqlMap = xmlParseSelf.parse(xmlData)
- # except:
- # info = sys.exc_info()
- # logger.error(info[0])
- # logger.error(info[1])
- # logger.error(traceback.extract_tb(info[2], 1))
- # return result,sqlMap
- def getNodeData(request,key):
- data = request.getElementsByTagName(key)[0].childNodes[0].data
- return data;
- # if __name__ == '__main__':
- # businessInfo = getBusinessInfo('./test.xml')
- # print(businessInfo)
- # xml = ""
- # data = base64.b64encode(xml.encode("UTF-8"))
- # print(str(data))
- #调用http
- def process(startTime,businessInfo,basePath,xml_path,file_name):
- startTime = str(startTime)
- businessInfo = businessInfo
- file_name = file_name
- xml_path = xml_path
- productNum = businessInfo["productNum"]
- # parse_result = businessInfo["result"]
- # print(businessInfo)
- # print("产品号:"+productNum)
- if productNumXy.find(productNum) >= 0:
- print("操作1")
- try:
- result = xyHttp.call_credit(businessInfo)
- # result = json.loads(result);
- # logger.info(result)
- #上传审批结果
- jsonPath = basePath + businessInfo["certificateNum"] + ".txt"
- logger.info(jsonPath)
- with open(jsonPath, 'w', encoding='utf-8') as fp:
- fp.write(result)
- uploadJsonFile(businessInfo,jsonPath)
- #移动xml文件
- try:
- dayStrPath = basePath+productNum+"/"+time.strftime('%Y%m%d', time.localtime(time.time()))+"/";
- descXmlPath = dayStrPath +"xml/"+ os.path.basename(xml_path)
- descJsonPath = dayStrPath+"txt/" + os.path.basename(jsonPath)
- if not os.path.exists(basePath+productNum):
- os.mkdir(basePath+productNum)
- if not os.path.exists(dayStrPath):
- os.mkdir(dayStrPath)
- if not os.path.exists(dayStrPath+"xml/"):
- os.mkdir(dayStrPath + "xml/")
- if not os.path.exists(dayStrPath+"txt/"):
- os.mkdir(dayStrPath+"txt/")
- logger.info("移动文件 from " + xml_path + " to " + descXmlPath)
- if isPlt == "1":
- move(xml_path, descXmlPath)
- shutil.move(jsonPath, descJsonPath)
- except:
- logger.error(businessInfo["certificateNum"]+"#创建文件夹或者移动文件失败,不影响业务")
- logger.error(traceback.print_exc())
- logger.error(traceback.format_exc())
- except:
- logger.error(traceback.print_exc())
- logger.error(traceback.format_exc())
- mailUtil = MailUtil();
- webhook = 'https://oapi.dingtalk.com/robot/send?access_token=64d8b2c7fed4949e9433b807c7c5559939f1517af8f77c1dacb4de19c6910b56'
- mailUtil.dingtalk("号码:" + businessInfo["certificateNum"] + " 调用xy服务失败 ", webhook)
- endTime = str(datetime.now()) # 结束时间
- # yuan原有商户模型入库
- dbController.getConn()
- parse_info = str(businessInfo["result"])
- parse_info = parse_info.replace("'", "\\'")
- filter_info = str(result)
- filter_info = filter_info.replace("'", "\\'")
- sql = "INSERT INTO filter_result(report_name,filter_info,parse_info,start_time,end_time) VALUES ('" + file_name + "', '" + filter_info + "', '" + parse_info + "', '" + startTime + "', '" + endTime + "')"
- # print(sql)
- dbController.execSql(sql)
- # if i==1:
- # break
- dbController.commit()
- elif productNumQk.find(productNum) >= 0 or productNumHsz.find(productNum) >= 0 or productNumHc.find(productNum) >= 0 \
- or productNumJzA.find(productNum) >= 0 or productNumRd.find(productNum) >= 0 or productNumHcNew.find(productNum) >= 0:#洽客
- # print("操作2")
- txtPath = xml_path.replace(".xml", ".txt")
- result = ""
- if businessInfo["isBaihu"] != "3":
- with open(txtPath, 'w', encoding='utf-8') as fp:
- fp.write(businessInfo["result"])
- if productNumQk.find(productNum) >= 0:
- result = xyHttp.callQk(businessInfo)
- if productNumHc.find(productNum) >= 0:
- result = xyHttp.callHc(businessInfo)
- elif productNumHsz.find(productNum) >= 0:
- result = xyHttp.callHsz(businessInfo)
- elif productNumJzA.find(productNum) >= 0:
- result = xyHttp.callJz(businessInfo)
- elif productNumRd.find(productNum) >= 0:
- result = xyHttp.callRd(businessInfo)
- elif productNumHcNew.find(productNum) >= 0:
- result = pboc_hc.renhang_rules(businessInfo)
- # result = json.loads(result);
- # print(result)
- #上传审批结果
- # print(businessInfo["certificateNum"])
- jsonPath = basePath + businessInfo["certificateNum"] + ".txt"
- logger.info(jsonPath)
- if businessInfo["isBaihu"] == "3":
- result = "{'errCode':-1,errMsg:'输入的姓名与系统收录的姓名不一致'}"
- logger.info(result)
- with open(jsonPath, 'w', encoding='utf-8') as fp:
- fp.write(result)
- uploadJsonFile(businessInfo,jsonPath)
- endTime = str(datetime.now()) # 结束时间
- #yuan原有商户模型入库
- dbController.getConn()
- parse_info = str(businessInfo["result"])
- parse_info = parse_info.replace("'", "\\'")
- filter_info = str(result)
- filter_info = filter_info.replace("'", "\\'")
- sql = "INSERT INTO filter_result(report_name,product_num,filter_info,parse_info,start_time,end_time) VALUES ('" + file_name + "', '" +productNum + "', '" + filter_info + "', '" + parse_info + "', '" + startTime + "', '" + endTime + "')"
- dbController.execSql(sql)
- dbController.commit()
- #移动xml文件
- dayStrPath = basePath+productNum+"/"+time.strftime('%Y%m%d', time.localtime(time.time()))+"/";
- descXmlPath = dayStrPath +"xml/"+ os.path.basename(xml_path) #源文件
- descJsonPath = dayStrPath+"txt/" + os.path.basename(jsonPath) #解析文件
- descTxtPath = dayStrPath + "txt/" + os.path.basename(txtPath) #征信信息
- if not os.path.exists(basePath+productNum):
- os.mkdir(basePath+productNum)
- if not os.path.exists(dayStrPath):
- os.mkdir(dayStrPath)
- if not os.path.exists(dayStrPath+"xml/"):
- os.mkdir(dayStrPath + "xml/")
- if not os.path.exists(dayStrPath+"txt/"):
- os.mkdir(dayStrPath+"txt/")
- logger.info("移动文件 from " + xml_path + " to " + descXmlPath)
- if isPlt == "1":
- move(xml_path, descXmlPath)
- shutil.move(jsonPath, descJsonPath)
- shutil.move(txtPath, descTxtPath)
- # if i==1:
- # break
- # dbController.commit()
- else:
- # print("产品号:"+productNum)
- #走jar包逻辑
- # print(businessInfo["result"])
- txtPath = xml_path.replace(".xml",".txt")
- # print("txt路径"+txtPath)
- with open(txtPath, 'w', encoding='utf-8') as fp:
- fp.write(businessInfo["result"])
- if productNum == productNumJz:#桔子
- print("桔子")
- # yuan原有商户模型入库
- dbController.getConn()
- parse_info = str(businessInfo["result"])
- parse_info = parse_info.replace("'", "\\'")
- filter_info = "此模型不产生结果"
- sql = "INSERT INTO filter_result(report_name,filter_info,parse_info) VALUES ('" + file_name + "', '" + filter_info + "', '" + parse_info + "')"
- # print(sql)
- dbController.execSql(sql)
- # if i==1:
- # break
- dbController.commit()
- invokePboc(businessInfo, txtPath)
- #移动xml文件
- descXmlPath = basePath + "execed_new/" + os.path.basename(xml_path)
- if not os.path.exists(basePath + "execed_new/"):
- os.mkdir(basePath + "execed_new/")
- if isPlt == "1":
- move(xml_path, descXmlPath)
- elif productNum == productNumXxw:#新希望
- # yuan原有商户模型入库
- dbController.getConn()
- parse_info = str(businessInfo["result"])
- parse_info = parse_info.replace("'", "\\'")
- filter_info = "此模型不产生结果"
- sql = "INSERT INTO filter_result(report_name,filter_info,parse_info) VALUES ('" + file_name + "', '" + filter_info + "', '" + parse_info + "')"
- # print(sql)
- dbController.execSql(sql)
- # if i==1:
- # break
- dbController.commit()
- invokeXxw(businessInfo, txtPath);
- jsonPath = basePath + businessInfo["certificateNum"] + ".txt"
- #移动xml文件
- descXmlPath = basePath + "execed_new/" + os.path.basename(xml_path)
- if not os.path.exists(basePath + "execed_new/"):
- os.mkdir(basePath + "execed_new/")
- logger.info("移动文件 from " + xml_path + " to " + descXmlPath)
- if isPlt == "1":
- move(xml_path, descXmlPath)
- elif productNum == productNumFb or productNum== productNumKcd or productNum500.find(productNum)>=0:#没有java包 #快车道和风暴 上传500个字段
- logger.info(businessInfo["productNum"])
- # yuan原有商户模型入库
- dbController.getConn()
- parse_info = str(businessInfo["result"])
- parse_info = parse_info.replace("'", "\\'")
- filter_info = "此模型不产生结果"
- sql = "INSERT INTO filter_result(report_name,filter_info,parse_info) VALUES ('" + file_name + "', '" + filter_info + "', '" + parse_info + "')"
- # print(sql)
- dbController.execSql(sql)
- # if i==1:
- # break
- dbController.commit()
- uploadJsonFile(businessInfo,txtPath)
- # 移动xml文件
- descXmlPath = basePath + "execed_new/" + os.path.basename(xml_path)
- if not os.path.exists(basePath + "execed_new/"):
- os.mkdir(basePath + "execed_new/")
- logger.info("移动文件 from " + xml_path + " to " + descXmlPath)
- if isPlt == "1":
- move(xml_path, descXmlPath)
- elif productNumJy.find(productNum)>=0:#简营
- logger.info(businessInfo["productNum"])
- jsonPath = txtPath.replace(".txt","_json.txt")
- # yuan原有商户模型入库
- dbController.getConn()
- parse_info = str(businessInfo["result"])
- parse_info = parse_info.replace("'", "\\'")
- filter_info = "此模型不产生结果"
- sql = "INSERT INTO filter_result(report_name,filter_info,parse_info) VALUES ('" + file_name + "', '" + filter_info + "', '" + parse_info + "')"
- # print(sql)
- dbController.execSql(sql)
- # if i==1:
- # break
- dbController.commit()
- #写入数据到文件
- xyHttp.buildJyData(businessInfo,jsonPath)
- uploadJsonFile(businessInfo, jsonPath)
- # 移动xml文件
- descXmlPath = basePath + "execed_new/" + os.path.basename(xml_path)
- if not os.path.exists(basePath + "execed_new/"):
- os.mkdir(basePath + "execed_new/")
- logger.info("移动文件 from " + xml_path + " to " + descXmlPath)
- if isPlt == "1":
- descTxtPath = basePath + "execed_txt/" + os.path.basename(jsonPath)
- try:
- shutil.move(jsonPath, descTxtPath)
- except Exception:
- pass
- move(xml_path, descXmlPath)
- elif productNum == productNumFd:#分蛋 白户审批通过
- # yuan原有商户模型入库
- dbController.getConn()
- parse_info = str(businessInfo["result"])
- parse_info = parse_info.replace("'", "\\'")
- filter_info = "此模型不产生结果"
- sql = "INSERT INTO filter_result(report_name,filter_info,parse_info) VALUES ('" + file_name + "', '" + filter_info + "', '" + parse_info + "')"
- # print(sql)
- dbController.execSql(sql)
- # if i==1:
- # break
- dbController.commit()
- if businessInfo["result"]!="":
- result = xyHttp.callNewModel(businessInfo)
- uploadAudit(result,businessInfo["businessNum"],productNum)
- else:
- result = {"approveResult":"1","rule":"白户"}
- uploadAudit(result, businessInfo["businessNum"], productNum)
- # 移动xml文件
- descXmlPath = basePath + "execed_new/" + os.path.basename(xml_path)
- if not os.path.exists(basePath + "execed_new/"):
- os.mkdir(basePath + "execed_new/")
- logger.info("移动文件 from " + xml_path + " to " + descXmlPath)
- if isPlt == "1":
- move(xml_path, descXmlPath)
- elif productNumKn.find(productNum)>=0 :#快牛 是本地jar包,本地jar改为逗号配置
- if businessInfo["result"]!="":
- result = xyHttp.callLocal(businessInfo)
- filter_info = uploadAudit(result,businessInfo["businessNum"],productNum)
- endTime = str(datetime.now()) # 结束时间
- # yuan原有商户模型入库
- dbController.getConn()
- parse_info = str(businessInfo["result"])
- parse_info = parse_info.replace("'", "\\'")
- sql = "INSERT INTO filter_result(report_name,product_num,filter_info,parse_info,start_time,end_time) VALUES ('" + file_name + "', '" + productNum + "', '" + filter_info + "', '" + parse_info + "', '" + startTime + "', '" + endTime + "')"
- # print(sql)
- dbController.execSql(sql)
- # if i==1:
- # break
- dbController.commit()
- else:
- result = {"approveResult":"0","rule":"白户"}
- uploadAudit(result, businessInfo["businessNum"], productNum)
- # 移动xml文件
- descXmlPath = basePath + "execed_new/" + os.path.basename(xml_path)
- if not os.path.exists(basePath + "execed_new/"):
- os.mkdir(basePath + "execed_new/")
- logger.info("移动文件 from " + xml_path + " to " + descXmlPath)
- if isPlt == "1":
- move(xml_path, descXmlPath)
- elif productNum == productNumHst:#海盛通
- # yuan原有商户模型入库
- dbController.getConn()
- parse_info = str(businessInfo["result"])
- parse_info = parse_info.replace("'", "\\'")
- filter_info = "此模型不产生结果"
- sql = "INSERT INTO filter_result(report_name,filter_info,parse_info) VALUES ('" + file_name + "', '" + filter_info + "', '" + parse_info + "')"
- # print(sql)
- dbController.execSql(sql)
- # if i==1:
- # break
- dbController.commit()
- if businessInfo["result"]!="":
- result = hst_rule_set.callLocal(businessInfo)
- uploadAudit(result,businessInfo["businessNum"],productNum)
- else:
- result = {"approveResult":"0","rule":"白户"}
- uploadAudit(result, businessInfo["businessNum"], productNum)
- # 移动xml文件
- descXmlPath = basePath + "execed_new/" + os.path.basename(xml_path)
- if not os.path.exists(basePath + "execed_new/"):
- os.mkdir(basePath + "execed_new/")
- logger.info("移动文件 from " + xml_path + " to " + descXmlPath)
- if isPlt == "1":
- move(xml_path, descXmlPath)
- else:
- # 走新增的自定义模型
- print("go selfdesign")
- customModel= CustomModel();
- res=customModel.doCustomModel(productNum,businessInfo,xml_path,file_name,startTime);
- print(res)
- if res==3:
- jsonPath = xml_path.replace(".xml", "_json.txt")
- dayStrPath = basePath + productNum + "/" + time.strftime('%Y%m%d', time.localtime(time.time())) + "/";
- descXmlPath = dayStrPath + "xml/" + os.path.basename(xml_path)
- descJsonPath = dayStrPath + "txt/" + os.path.basename(jsonPath)
- descTxtPath = dayStrPath + "txt/" + os.path.basename(txtPath)
- if not os.path.exists(basePath + productNum):
- os.mkdir(basePath + productNum)
- if not os.path.exists(dayStrPath):
- os.mkdir(dayStrPath)
- if not os.path.exists(dayStrPath + "xml/"):
- os.mkdir(dayStrPath + "xml/")
- if not os.path.exists(dayStrPath + "txt/"):
- os.mkdir(dayStrPath + "txt/")
- logger.info("移动文件 from " + xml_path + " to " + descXmlPath)
- if isPlt == "1":
- move(xml_path, descXmlPath)
- shutil.move(jsonPath, descJsonPath)
- shutil.move(txtPath, descTxtPath)
- else :
- print("移动文件")
- descXmlPath = basePath + "execed_new/" + os.path.basename(xml_path)
- # print("descXmlPath是"+str(businessInfo))
- if not os.path.exists(basePath + "execed_new/"):
- os.mkdir(basePath + "execed_new/")
- logger.info("移动文件 from " + xml_path + " to " + descXmlPath)
- if isPlt == "1":
- move(xml_path, descXmlPath)
- # if(res):
- # result["approveResult"]="1"
- #
- # print(result);
- # 结果返回
- # uploadAudit(res, businessInfo["businessNum"], productNum)
- # 这个地方嵌进去结果
- i=0
- #本地jar
- if isPlt == "1":
- if not os.path.exists(basePath + "execed_txt/"):
- os.mkdir(basePath + "execed_txt/")
- descTxtPath = basePath + "execed_txt/" + os.path.basename(txtPath)
- shutil.move(txtPath, descTxtPath)
- #调用jar包
- def move(xml_path, descXmlPath):
- try:
- shutil.move(xml_path, descXmlPath)
- if not os.path.exists(basePath + "execed_xml/"):
- os.mkdir(basePath + "execed_xml/")
- shutil.move(xml_path+".txt", descXmlPath.replace("execed_new","execed_xml")+".txt")
- # os.remove(xml_path+".txt")#删除生成的xml.txt文件
- except:
- logger.info("移动文件 from " + xml_path + " to " + descXmlPath +" error")
- # #调用jar包
- # def move1(xml_path, descXmlPath):
- # try:
- # shutil.move(xml_path, descXmlPath)
- # # os.remove(xml_path+".txt")#删除生成的xml.txt文件
- # except:
- # logger.info("移动文件 from " + xml_path + " to " + descXmlPath +" error")
- def invokePboc(businessInfo,txtPath):
- # ===================================
- try:
- # print(businessInfo)
- businessNum = businessInfo["businessNum"]
- coopBusinessNum = businessInfo["coopBusinessNum"]
- pboc = PBOC()
- jarTxt = pboc.calc(txtPath,coopBusinessNum);
- result = json.loads(jarTxt)
- logger.info(result)
- if result.get("errcode")== None:
- uploadAudit(result,businessNum,businessInfo["productNum"])
- else:
- if businessInfo["isBaihu"]=="1":
- result = {"approveResult":"1"}
- uploadAudit(result, businessNum, businessInfo["productNum"])
- logger.error(result["errmsg"])
- except:
- logger.error("certificateNum=" + businessInfo["coopBusinessNum"])
- info = sys.exc_info()
- logger.error(info[0])
- logger.error(info[1])
- # logging.log(logging.ERROR, info[2])
- logger.error(traceback.extract_tb(info[2], 1))
- #调用xxwjar包
- def invokeXxw(businessInfo,txtPath):
- try:
- businessNum = businessInfo["businessNum"]
- coopBusinessNum = businessInfo["coopBusinessNum"]
- customerNum = businessInfo["customerNum"]
- certificateNum = businessInfo["certificateNum"]
- pboc = PBOC()
- jarTxt = pboc.calcXxw(coopBusinessNum,customerNum,txtPath);
- logger.info("jarTxt:"+jarTxt)
- result = json.loads(jarTxt)
- jsonPath = basePath+certificateNum+".txt"
- # logger.info(jsonPath)
- with open(jsonPath, 'w', encoding='utf-8') as fp:
- fp.write(jarTxt)
- uploadJsonFile(businessInfo,jsonPath)
- if not os.path.exists(basePath + "execed_txt/"):
- os.mkdir(basePath + "execed_txt/")
- descJsonPath = basePath + "execed_txt/" + os.path.basename(jsonPath)
- shutil.move(jsonPath, descJsonPath)
- except:
- logger.error("certificateNum=" + businessInfo["coopBusinessNum"])
- info = sys.exc_info()
- logger.error(info[0])
- logger.error(info[1])
- logger.error(traceback.extract_tb(info[2], 1))
- #上传审批结果
- def uploadAudit(result,businessNum,productNum):
- global approResult
- approvalType = result["approveResult"]
- if productNum == productNumJz:
- if approvalType=="1":
- approvalOpinion = "征通信过"
- approvalType = "4"
- else:
- approvalOpinion = "征信拒绝"
- approvalType = "3"
- elif productNumKn.find(productNum)>=0 or productNum == productNumHst or productNum == productNumFd:
- if approvalType=="1":
- approvalOpinion = "征信通过"
- approvalType = "4"
- else:#快牛 需要添加拒绝原因
- approvalOpinion = "征信拒绝" + "#" + result["rule"]
- approvalType = "3"
- else:#自定义模型情况yuan
- if approvalType == "1":
- approvalOpinion = "征信通过"
- # print("yuan上传审批征信通过")
- approvalType = "4"
- else:
- approvalOpinion = "征信拒绝"
- approvalType = "3"
- taskKey = config.get("baseconf","taskKey")
- appoveApiUrl = config.get("baseconf","appoveApiUrl")
- key = config.get("baseconf", "AESKey")
- data = {"header":{
- "ticket": "2938123198320412343",
- "timestamp": int(int(round(time.time() * 1000+60*1000))),
- "nonce": config.get("baseconf", "nonce")
- },
- "body":{"approvalType": approvalType, "businessNum": businessNum,"taskKey":taskKey,"approvalOpinion":approvalOpinion}}
- access_token = dbController.getToken();
- # access_token = "3BWvQEAzX7W53UuX"
- if access_token == "":#获取token失败重新获取
- access_token = dbController.getToken();
- appoveApiUrl = appoveApiUrl+"?access_token="+access_token
- headers = {"Content-Type": "application/json"}
- jsonStr = json.dumps(data);
- jsonStr = jsonStr.replace('"',"\\\"")#必须替换才行
- logger.info(jsonStr)
- pboc = PBOC();
- # print("if encty")response是
- encryData = pboc.encrypt(jsonStr,key)
- # print("if encty11")
- encryData = encryData[0:len(encryData)-2]
- # print("had encry")
- logger.info(encryData)
- # print("if response")
- print("appoveApiUrl是: " + str(appoveApiUrl))
- print("encryData是: " + str(encryData))
- print("headers是: " + str(headers))
- response = requests.post(appoveApiUrl, data=encryData,headers=headers)
- text = response.text
- print("response是: " + str(response))
- print("text: " + str(text))
- pboc = PBOC();
- resultText = pboc.decrypt(text, config.get("baseconf", "AESKey"))
- print("resultText是: " + str(resultText))
- logger.info(businessNum + "#" + "uploadAudit upload_result:" + resultText)
- return str(resultText)
- #上传解析json 文件上传
- def uploadJsonFile(businessInfo,json_path):
- # ===================================
- try:
- fileName = os.path.basename(json_path)
- #上传文件逻辑
- logger.info(json_path+"#"+"准备上传文件")
- uploadApiUrl = config.get("baseconf", "uploadApiUrl");
- token = dbController.getToken();
- # token = "3BWvQEAzX7W53UuX"
- if token == "":#如果获取失败,重新获取
- token = dbController.getToken();
- uploadApiUrl = uploadApiUrl + "?access_token=" + token
- files = {'file': open(json_path, 'rb')}
- logger.info(fileName+"#"+"businessNum:"+businessInfo["businessNum"])
- data = {'docType': "23", 'businessNum': businessInfo["businessNum"]}
- response = requests.post(uploadApiUrl, files=files, data=data)
- text = response.text
- print("response是: " + str(response))
- print("text: " + str(text))
- logger.info("上传结果:"+text)
- pboc = PBOC();
- resultText = pboc.decrypt(text, config.get("baseconf", "AESKey"))
- print("resultText是: "+ str(resultText))
- logger.info(fileName+"#"+"uploadJsonFile:" + resultText)
- except:
- logger.error("certificateNum="+businessInfo["coopBusinessNum"])
- info = sys.exc_info()
- logger.error(info[0])
- logger.error(info[1])
- # logging.log(logging.ERROR, info[2])
- logger.error(traceback.extract_tb(info[2], 1))
- mailUtil = MailUtil();
- webhook = 'https://oapi.dingtalk.com/robot/send?access_token=64d8b2c7fed4949e9433b807c7c5559939f1517af8f77c1dacb4de19c6910b56'
- # mailUtil.dingtalk("号码:" + businessInfo["certificateNum"]+"-"+businessInfo["businessNum"] + " 上传文件失败 ", webhook)
- if __name__ == '__main__':
- basePath = "D:/jin_rong/todo/"
- init_path = "test_data/"
- # basePath = "D:/mydocument/myprojects/creditreport/parse/"
- # file_name = sys.argv[1]
- # file_name = "周绍政_512925196801187190_523465671363788806-20221109114553780.xml"
- #
- file_name = "段国钊_432924196512260092_525976302319050756-20221116100213782.xml"
- # logger.info("Made request to REST API. [file_name={}]", file_name)
- # file_name = "侬志雪_532627199808160322_525990479343394824-202211161058332446.xml"
- # # file_name="dqy_320821199205184730_255559091387119623.xml"
- # file_name='zl_342425199204087911_255220233202055177.xml'
- # file_name="sxg_330719197909242017_257564808331673603.xml"
- # file_name="pxy_522401199510147022_258623031256039426.xml"
- # file_name = "任赞_130185199601221319_257538384191307779.xml"
- # file_name="朱宏辉_430521199607210734_256254065317527560.xml"
- # file_name="杨同山_340406197907213451_236806485030479874.xml"
- # # file_name = "1_210303197510273014_269873665141647369-202012091702117200.xml"
- # # file_name="任赞_130185199601221319_257538384191307779"
- # file_name="艾红平_520202198707150427_384652376306363396-202110221031275368.xml"
- # # file_name = "王彬彬_150429198902200911_5.xml"
- # file_name="裴增计_140522196602121517_331131028938695682-202105271756329018.xml"
- # file_name = "胡龙德_370829197506094916_389014816133485574-202111031126048397.xml"
- # file_name="周子彪_533024199501184513_257703742621630467.xml"
- xml_path = basePath + init_path + file_name
- start = timeit.default_timer();
- # if len(sys.argv) > 1:
- # basePath = sys.argv[1]
- # xml_path = basePath + sys.argv[2]
- # file_name = sys.argv[2]
- logger.info(xml_path+" 解析开始")
- startTime = datetime.now() #开始时间
- # print(xml_path+ " 解析开始")
- businessInfo = getBusinessInfo(xml_path)
- # uploadJsonFile(businessInfo,"D:/jin_rong/test_data/朱家铎_410922199111210030_255632073002334212.txt")
- # with open('D:/jin_rong/test_data/朱传光_371425199305027971_256979050910728199.txt', 'r', encoding='utf-8')as fp:
- # businessInfo['result'] = fp.read();
- # logger.info(businessInfo)
- if businessInfo["isBaihu"]!="2":#白户不上传1211
- try:
- process(startTime,businessInfo, basePath, xml_path, file_name)
- except:
- logger.error(traceback.print_exc())
- logger.error(traceback.format_exc())
- # if approResult==0:
- # print("征信通过")
- # dbController.getConn()
- # # print(len(sqlMap))
- # sql = "INSERT INTO credit_approval(approval_result,credit_name) VALUES ('征信通过', '" + file_name + "')"
- # print(sql)
- # dbController.execSql(sql)
- # # if i==1:
- # # break
- # dbController.commit()
- s = timeit.default_timer() - start;
- logger.info(str(s) + " 秒")
- logger.info(xml_path+" 解析完成")
- # 执行sql开始
- logger.info(xml_path + " 执行sql解析开始")
- # print("this is a result")
- sqlMap = businessInfo["sqlMap"]
- # 执行sql完成
- # logger.info(sqlMap)
- try:
- start = timeit.default_timer();
- dbController.getConn()
- # print(len(sqlMap))
- for sql in sqlMap:
- # i +=1
- dbController.execSql(sql)
- # if i==1:
- # break
- dbController.commit()
- s = timeit.default_timer() - start;
- logger.info(xml_path+str(s) + " 秒")
- except:
- logger.error(traceback.print_exc())
- logger.error(traceback.format_exc())
- logger.info(xml_path + " 执行sql解析失败")
- logger.info(xml_path + " 执行sql解析完成")
|