#coding=utf-8 from xml.dom import minidom import base64 import sys import os from customModel import CustomModel from ini_op import Config; base_dir = os.path.dirname(os.path.abspath(__file__)) config = Config(base_dir+"/config.ini"); productNumXy = config.get("baseconf", "productNumKcd") 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") 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 pboc.invokePboc import PBOC from mailUtil import MailUtil import datetime today=datetime.date.today() today = str(today) 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) # print(xmlData) #remove by chenqiwang 1105 xmlPath = xmlFile+".txt" # 生成xml格式报告 # with open(xmlPath, 'w', encoding='utf-8') as fp: # fp.write(xmlData) # 非小赢需要解析 productNum = getNodeData(request, "productNum") sqlMap = [] if productNum != productNumXy: if xmlData !="": if productNum == productNumHsz: result,sqlMap = parseHsz(xmlData) else: #跑数据的时候改为parseHsz result,sqlMap = parse(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 = "" 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 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_init,basePath,xml_path): startTime = str(startTime) productNum = businessInfo["productNum"] if productNumXy.find(productNum) >= 0: 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 + "')" dbController.execSql(sql) 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:#洽客 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); #上传审批结果 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) else: #走jar包逻辑 # print(businessInfo["result"]) txtPath = xml_path.replace(".xml",".txt") with open(txtPath, 'w', encoding='utf-8') as fp: fp.write(businessInfo["result"]) if productNum == productNumJz:#桔子 # 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_init + "execed_new/" + os.path.basename(xml_path) if not os.path.exists(basePath_init + "execed_new/"): os.mkdir(basePath_init + "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_init + "execed_new/" + os.path.basename(xml_path) if not os.path.exists(basePath_init + "execed_new/"): os.mkdir(basePath_init + "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_init + "execed_new/" + os.path.basename(xml_path) if not os.path.exists(basePath_init + "execed_new/"): os.mkdir(basePath_init + "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"]) # 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() jsonPath = txtPath.replace(".txt","_json.txt") #写入数据到文件 xyHttp.buildJyData(businessInfo,jsonPath) uploadJsonFile(businessInfo, jsonPath) # 移动xml文件 descXmlPath = basePath_init + "execed_new/" + os.path.basename(xml_path) if not os.path.exists(basePath_init + "execed_new/"): os.mkdir(basePath_init + "execed_new/") logger.info("移动文件 from " + xml_path + " to " + descXmlPath) if isPlt == "1": descTxtPath = basePath_init + "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_init + "execed_new/" + os.path.basename(xml_path) if not os.path.exists(basePath_init + "execed_new/"): os.mkdir(basePath_init + "execed_new/") logger.info("移动文件 from " + xml_path + " to " + descXmlPath) if isPlt == "1": move(xml_path, descXmlPath) elif productNumKn.find(productNum)>=0 :#快牛本地jar包,本地jar改为逗号配置 # 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.callLocal(businessInfo) uploadAudit(result,businessInfo["businessNum"],productNum) else: result = {"approveResult":"0","rule":"白户"} uploadAudit(result, businessInfo["businessNum"], productNum) # 移动xml文件 descXmlPath = basePath_init + "execed_new/" + os.path.basename(xml_path) if not os.path.exists(basePath_init + "execed_new/"): os.mkdir(basePath_init + "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_init + "execed_new/" + os.path.basename(xml_path) if not os.path.exists(basePath_init + "execed_new/"): os.mkdir(basePath_init + "execed_new/") logger.info("移动文件 from " + xml_path + " to " + descXmlPath) if isPlt == "1": move(xml_path, descXmlPath) else: #走新增的自定义模型 customModel=CustomModel(); res=customModel.doCustomModel(productNum,businessInfo,xml_path); 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_init + productNum): os.mkdir(basePath_init + 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 : descXmlPath = basePath_init + "execed_new/" + os.path.basename(xml_path) if not os.path.exists(basePath_init + "execed_new/"): os.mkdir(basePath_init + "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_init + "execed_txt/"): os.mkdir(basePath_init + "execed_txt/") descTxtPath = basePath_init + "execed_txt/" + os.path.basename(txtPath) shutil.move(txtPath, descTxtPath) #调用jar包 def move(xml_path, descXmlPath): try: shutil.move(xml_path, descXmlPath) # print(xml_path) if not os.path.exists(basePath_init + "execed_xml/"): os.mkdir(basePath_init + "execed_xml/") shutil.move(xml_path+".txt", descXmlPath.replace("execed_new","execed_xml")+".txt") # print("diaomeidiao") # os.remove(xml_path+".txt")#删除生成的xml.txt文件 except: logger.info("移动文件 from " + xml_path + " to " + descXmlPath +" error") def invokePboc(businessInfo,txtPath): # =================================== try: 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): 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" 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(); 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(); encryData = pboc.encrypt(jsonStr,key) encryData = encryData[0:len(encryData)-2] logger.info(encryData) response = requests.post(appoveApiUrl, data=encryData,headers=headers) text = response.text pboc = PBOC(); resultText = pboc.decrypt(text, config.get("baseconf", "AESKey")) logger.info(businessNum + "#" + "uploadAudit upload_result:" + 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(); 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,timeout=15) text = response.text logger.info("上传结果:"+text) pboc = PBOC(); resultText = pboc.decrypt(text,config.get("baseconf", "AESKey")) 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) def init_file_list(basePath): if not os.path.exists(basePath + "execed_txt/"): os.mkdir(basePath + "execed_txt/") if not os.path.exists(basePath + "execed_xml/"): os.mkdir(basePath + "execed_xml/") if not os.path.exists(basePath + "execed_new/"): os.mkdir(basePath + "execed_new/") # if not os.path.exists(basePath + "CPA0100657/"): # os.mkdir(basePath + "CPA0100657/") # if not os.path.exists(basePath + "CPA0100759/"): # os.mkdir(basePath + "CPA0100759/") # if not os.path.exists(basePath + "CPA0100775/"): # os.mkdir(basePath + "CPA0100775/") # if not os.path.exists(basePath + "CPA0100657/"): # os.mkdir(basePath + "CPA0100657/") # if not os.path.exists(basePath + "CPA0100841/"): # os.mkdir(basePath + "CPA0100841/") if __name__ == '__main__': basePath_init = "D:/jin_rong/todo/" init_file_list(basePath_init) file_name = sys.argv[1] # file_name = "樊术生_432924196512260092_525976302319050756-20221116100213782.xml" basePath = "D:/jin_rong/execed_xml/" xml_path = basePath + 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] # print("parseStarting") logger.info(xml_path+" 解析开始") startTime = datetime.now() #开始时间 businessInfo = getBusinessInfo(xml_path) # 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_init,basePath,xml_path) except: logger.error(traceback.print_exc()) logger.error(traceback.format_exc()) s = timeit.default_timer() - start; logger.info(str(s) + " 秒") logger.info(xml_path+" 解析完成") # 执行sql开始 logger.info(xml_path + " 执行sql解析开始") sqlMap = businessInfo["sqlMap"] # 执行sql完成 # logger.info(sqlMap) try: start = timeit.default_timer(); dbController.getConn() for sql in sqlMap: dbController.execSql(sql) 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解析完成")