parseCreditXmlAuto.py 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713
  1. #coding=utf-8
  2. from xml.dom import minidom
  3. import base64
  4. import sys
  5. import os
  6. from customModel import CustomModel
  7. from ini_op import Config;
  8. base_dir = os.path.dirname(os.path.abspath(__file__))
  9. config = Config(base_dir+"/config.ini");
  10. productNumXy = config.get("baseconf", "productNumKcd")
  11. productNumJz = config.get("baseconf","productNumJz")
  12. productNumXxw = config.get("baseconf","productNumXxw")
  13. productNumFb = config.get("baseconf", "productNumFb")
  14. productNumKcd = config.get("baseconf", "productNumKcd")
  15. productNumFd = config.get("baseconf", "productNumFd")
  16. productNumKn = config.get("baseconf", "productNumKn")
  17. productNumHst = config.get("baseconf", "productNumHst")
  18. productNumQk = config.get("baseconf", "productNumQk")
  19. productNumHc = config.get("baseconf", "productNumHc")
  20. productNum500 = config.get("baseconf", "productNum500")
  21. productNumHsz = config.get("baseconf", "productNumHsz")
  22. #简营
  23. productNumJy = config.get("baseconf", "productNumJy")
  24. #新版桔子
  25. productNumJzA = config.get("baseconf", "productNumJzA")
  26. #仁东
  27. productNumRd = config.get("baseconf", "productNumRd")
  28. #恒昌新
  29. productNumHcNew = config.get("baseconf", "productNumHcNew")
  30. isPlt = config.get("baseconf", "isPlt");
  31. import xyHttp
  32. import hst_rule_set
  33. import pboc_hc
  34. import log
  35. import shutil
  36. logger = log.logger
  37. import time
  38. from dbController import DbController
  39. dbController = DbController();
  40. import json
  41. import requests
  42. import timeit
  43. import traceback
  44. import gzip
  45. import io
  46. from xmlParser import XmlParser;
  47. from xmlParserHsz import XmlParserHsz;
  48. from pboc.invokePboc import PBOC
  49. from mailUtil import MailUtil
  50. import datetime
  51. today=datetime.date.today()
  52. today = str(today)
  53. def gzip_str(string_):
  54. out = io.BytesIO()
  55. with gzip.GzipFile(fileobj=out, mode='w') as fo:
  56. fo.write(string_.encode())
  57. bytes_obj = out.getvalue()
  58. return bytes_obj
  59. def gunzip_bytes_obj(bytes_obj):
  60. in_ = io.BytesIO()
  61. in_.write(bytes_obj)
  62. in_.seek(0)
  63. with gzip.GzipFile(fileobj=in_, mode='rb') as fo:
  64. gunzipped_bytes_obj = fo.read()
  65. return gunzipped_bytes_obj.decode()
  66. #解析xml数据
  67. def getBusinessInfo(xmlFile):
  68. doc = minidom.parse(xmlFile)
  69. request = doc.documentElement.getElementsByTagName("request")[0]
  70. responseBody = doc.documentElement.getElementsByTagName("responseBody")[0]
  71. responseHeader = doc.documentElement.getElementsByTagName("responseHeader")[0]
  72. result = ""
  73. xmlData = ""
  74. isBaihu = "0";
  75. if len(responseBody.childNodes)==0:
  76. mailUtil = MailUtil();
  77. webhook = 'https://oapi.dingtalk.com/robot/send?access_token=64d8b2c7fed4949e9433b807c7c5559939f1517af8f77c1dacb4de19c6910b56'
  78. resultMsg = getNodeData(responseHeader,"resultMsg")
  79. if resultMsg =="查询成功,无报告":
  80. isBaihu = "1"
  81. elif resultMsg == "输入的姓名与系统收录的姓名不一致":
  82. isBaihu = "3"
  83. else:
  84. isBaihu = "2"#查询失败
  85. mailUtil.dingtalk("号码:" + xmlFile.split("_")[0] + " 查询失败 ", webhook)
  86. else:
  87. responseBodyText = responseBody.childNodes[0].data
  88. decrpyt_bytes = base64.b64decode(responseBodyText)
  89. xmlData = gunzip_bytes_obj(decrpyt_bytes)
  90. # print(xmlData)
  91. #remove by chenqiwang 1105
  92. xmlPath = xmlFile+".txt"
  93. # 生成xml格式报告
  94. # with open(xmlPath, 'w', encoding='utf-8') as fp:
  95. # fp.write(xmlData)
  96. # 非小赢需要解析
  97. productNum = getNodeData(request, "productNum")
  98. sqlMap = []
  99. if productNum != productNumXy:
  100. if xmlData !="":
  101. if productNum == productNumHsz:
  102. result,sqlMap = parseHsz(xmlData)
  103. else:
  104. #跑数据的时候改为parseHsz
  105. result,sqlMap = parse(xmlData)
  106. data = {
  107. "businessNum":getNodeData(request,"businessNum"),
  108. "coopBusinessNum": getNodeData(request, "coopBusinessNum"),
  109. "customerNum":getNodeData(request,"customerNum"),
  110. "certificateNum": getNodeData(request, "certificateNum"),
  111. "productNum": productNum,
  112. "creditXml":xmlData,
  113. "extend": getNodeData(request, "extend"),
  114. "result":result,
  115. "isBaihu":isBaihu,
  116. "sqlMap":sqlMap
  117. }
  118. return data
  119. #解析xml报文
  120. def parse(xmlData):
  121. xmlParse = XmlParser()
  122. result = ""
  123. try:
  124. result,sqlMap = xmlParse.parse(xmlData)
  125. except:
  126. info = sys.exc_info()
  127. logger.error(info[0])
  128. logger.error(info[1])
  129. logger.error(traceback.extract_tb(info[2], 1))
  130. return result,sqlMap
  131. #解析xml报文 汇算帐
  132. def parseHsz(xmlData):
  133. xmlParseHsz = XmlParserHsz()
  134. result = ""
  135. try:
  136. result = xmlParseHsz.parse(xmlData)
  137. except:
  138. info = sys.exc_info()
  139. logger.error(info[0])
  140. logger.error(info[1])
  141. logger.error(traceback.extract_tb(info[2], 1))
  142. return result
  143. def getNodeData(request,key):
  144. data = request.getElementsByTagName(key)[0].childNodes[0].data
  145. return data;
  146. # if __name__ == '__main__':
  147. # businessInfo = getBusinessInfo('./test.xml')
  148. # print(businessInfo)
  149. # xml = ""
  150. # data = base64.b64encode(xml.encode("UTF-8"))
  151. # print(str(data))
  152. #调用http
  153. def process(startTime,businessInfo,basePath_init,basePath,xml_path):
  154. startTime = str(startTime)
  155. productNum = businessInfo["productNum"]
  156. if productNumXy.find(productNum) >= 0:
  157. try:
  158. result = xyHttp.call_credit(businessInfo)
  159. # result = json.loads(result);
  160. # logger.info(result)
  161. #上传审批结果
  162. jsonPath = basePath + businessInfo["certificateNum"] + ".txt"
  163. logger.info(jsonPath)
  164. with open(jsonPath, 'w', encoding='utf-8') as fp:
  165. fp.write(result)
  166. uploadJsonFile(businessInfo,jsonPath)
  167. #移动xml文件
  168. try:
  169. dayStrPath = basePath+productNum+"/"+time.strftime('%Y%m%d', time.localtime(time.time()))+"/";
  170. descXmlPath = dayStrPath +"xml/"+ os.path.basename(xml_path)
  171. descJsonPath = dayStrPath+"txt/" + os.path.basename(jsonPath)
  172. if not os.path.exists(basePath+productNum):
  173. os.mkdir(basePath+productNum)
  174. if not os.path.exists(dayStrPath):
  175. os.mkdir(dayStrPath)
  176. if not os.path.exists(dayStrPath+"xml/"):
  177. os.mkdir(dayStrPath + "xml/")
  178. if not os.path.exists(dayStrPath+"txt/"):
  179. os.mkdir(dayStrPath+"txt/")
  180. logger.info("移动文件 from " + xml_path + " to " + descXmlPath)
  181. if isPlt == "1":
  182. move(xml_path, descXmlPath)
  183. shutil.move(jsonPath, descJsonPath)
  184. except:
  185. logger.error(businessInfo["certificateNum"]+"#创建文件夹或者移动文件失败,不影响业务")
  186. logger.error(traceback.print_exc())
  187. logger.error(traceback.format_exc())
  188. except:
  189. logger.error(traceback.print_exc())
  190. logger.error(traceback.format_exc())
  191. mailUtil = MailUtil();
  192. webhook = 'https://oapi.dingtalk.com/robot/send?access_token=64d8b2c7fed4949e9433b807c7c5559939f1517af8f77c1dacb4de19c6910b56'
  193. mailUtil.dingtalk("号码:" + businessInfo["certificateNum"] + " 调用xy服务失败 ", webhook)
  194. endTime = str(datetime.now()) # 结束时间
  195. # yuan原有商户模型入库
  196. dbController.getConn()
  197. parse_info = str(businessInfo["result"])
  198. parse_info = parse_info.replace("'", "\\'")
  199. filter_info = str(result)
  200. filter_info = filter_info.replace("'", "\\'")
  201. sql = "INSERT INTO filter_result(report_name,filter_info,parse_info,start_time,end_time) VALUES ('" + file_name + "', '" + filter_info + "', '" + parse_info + "', '" + startTime + "', '" + endTime + "')"
  202. dbController.execSql(sql)
  203. dbController.commit()
  204. elif productNumQk.find(productNum) >= 0 or productNumHsz.find(productNum) >= 0 or productNumHc.find(productNum) >= 0 \
  205. or productNumJzA.find(productNum) >= 0 or productNumRd.find(productNum) >= 0 or productNumHcNew.find(productNum) >= 0:#洽客
  206. txtPath = xml_path.replace(".xml", ".txt")
  207. result = ""
  208. if businessInfo["isBaihu"] != "3":
  209. with open(txtPath, 'w', encoding='utf-8') as fp:
  210. fp.write(businessInfo["result"])
  211. if productNumQk.find(productNum) >= 0:
  212. result = xyHttp.callQk(businessInfo)
  213. if productNumHc.find(productNum) >= 0:
  214. result = xyHttp.callHc(businessInfo)
  215. elif productNumHsz.find(productNum) >= 0:
  216. result = xyHttp.callHsz(businessInfo)
  217. elif productNumJzA.find(productNum) >= 0:
  218. result = xyHttp.callJz(businessInfo)
  219. elif productNumRd.find(productNum) >= 0:
  220. result = xyHttp.callRd(businessInfo)
  221. elif productNumHcNew.find(productNum) >= 0:
  222. result = pboc_hc.renhang_rules(businessInfo)
  223. # result = json.loads(result);
  224. #上传审批结果
  225. jsonPath = basePath + businessInfo["certificateNum"] + ".txt"
  226. logger.info(jsonPath)
  227. if businessInfo["isBaihu"] == "3":
  228. result = "{'errCode':-1,errMsg:'输入的姓名与系统收录的姓名不一致'}"
  229. logger.info(result)
  230. with open(jsonPath, 'w', encoding='utf-8') as fp:
  231. fp.write(result)
  232. uploadJsonFile(businessInfo,jsonPath)
  233. endTime = str(datetime.now()) # 结束时间
  234. #yuan原有商户模型入库
  235. dbController.getConn()
  236. parse_info = str(businessInfo["result"])
  237. parse_info = parse_info.replace("'", "\\'")
  238. filter_info = str(result)
  239. filter_info = filter_info.replace("'", "\\'")
  240. 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 + "')"
  241. dbController.execSql(sql)
  242. dbController.commit()
  243. #移动xml文件
  244. dayStrPath = basePath+productNum+"/"+time.strftime('%Y%m%d', time.localtime(time.time()))+"/";
  245. descXmlPath = dayStrPath +"xml/"+ os.path.basename(xml_path)
  246. descJsonPath = dayStrPath+"txt/" + os.path.basename(jsonPath)
  247. descTxtPath = dayStrPath + "txt/" + os.path.basename(txtPath)
  248. if not os.path.exists(basePath+productNum):
  249. os.mkdir(basePath+productNum)
  250. if not os.path.exists(dayStrPath):
  251. os.mkdir(dayStrPath)
  252. if not os.path.exists(dayStrPath+"xml/"):
  253. os.mkdir(dayStrPath + "xml/")
  254. if not os.path.exists(dayStrPath+"txt/"):
  255. os.mkdir(dayStrPath+"txt/")
  256. logger.info("移动文件 from " + xml_path + " to " + descXmlPath)
  257. if isPlt == "1":
  258. move(xml_path, descXmlPath)
  259. shutil.move(jsonPath, descJsonPath)
  260. shutil.move(txtPath, descTxtPath)
  261. else:
  262. #走jar包逻辑
  263. # print(businessInfo["result"])
  264. txtPath = xml_path.replace(".xml",".txt")
  265. with open(txtPath, 'w', encoding='utf-8') as fp:
  266. fp.write(businessInfo["result"])
  267. if productNum == productNumJz:#桔子
  268. # yuan原有商户模型入库
  269. dbController.getConn()
  270. parse_info = str(businessInfo["result"])
  271. parse_info = parse_info.replace("'", "\\'")
  272. filter_info = "此模型不产生结果"
  273. sql = "INSERT INTO filter_result(report_name,filter_info,parse_info) VALUES ('" + file_name + "', '" + filter_info + "', '" + parse_info + "')"
  274. # print(sql)
  275. dbController.execSql(sql)
  276. # if i==1:
  277. # break
  278. dbController.commit()
  279. invokePboc(businessInfo, txtPath)
  280. #移动xml文件
  281. descXmlPath = basePath_init + "execed_new/" + os.path.basename(xml_path)
  282. if not os.path.exists(basePath_init + "execed_new/"):
  283. os.mkdir(basePath_init + "execed_new/")
  284. if isPlt == "1":
  285. move(xml_path, descXmlPath)
  286. elif productNum == productNumXxw:#新希望
  287. # yuan原有商户模型入库
  288. dbController.getConn()
  289. parse_info = str(businessInfo["result"])
  290. parse_info = parse_info.replace("'", "\\'")
  291. filter_info = "此模型不产生结果"
  292. sql = "INSERT INTO filter_result(report_name,filter_info,parse_info) VALUES ('" + file_name + "', '" + filter_info + "', '" + parse_info + "')"
  293. # print(sql)
  294. dbController.execSql(sql)
  295. # if i==1:
  296. # break
  297. dbController.commit()
  298. invokeXxw(businessInfo, txtPath);
  299. jsonPath = basePath + businessInfo["certificateNum"] + ".txt"
  300. #移动xml文件
  301. descXmlPath = basePath_init + "execed_new/" + os.path.basename(xml_path)
  302. if not os.path.exists(basePath_init + "execed_new/"):
  303. os.mkdir(basePath_init + "execed_new/")
  304. logger.info("移动文件 from " + xml_path + " to " + descXmlPath)
  305. if isPlt == "1":
  306. move(xml_path, descXmlPath)
  307. elif productNum == productNumFb or productNum== productNumKcd or productNum500.find(productNum)>=0:#没有java包 #快车道和风暴 上传500个字段
  308. logger.info(businessInfo["productNum"])
  309. # yuan原有商户模型入库
  310. dbController.getConn()
  311. parse_info = str(businessInfo["result"])
  312. parse_info = parse_info.replace("'", "\\'")
  313. filter_info = "此模型不产生结果"
  314. sql = "INSERT INTO filter_result(report_name,filter_info,parse_info) VALUES ('" + file_name + "', '" + filter_info + "', '" + parse_info + "')"
  315. # print(sql)
  316. dbController.execSql(sql)
  317. # if i==1:
  318. # break
  319. dbController.commit()
  320. uploadJsonFile(businessInfo,txtPath)
  321. # 移动xml文件
  322. descXmlPath = basePath_init + "execed_new/" + os.path.basename(xml_path)
  323. if not os.path.exists(basePath_init + "execed_new/"):
  324. os.mkdir(basePath_init + "execed_new/")
  325. logger.info("移动文件 from " + xml_path + " to " + descXmlPath)
  326. if isPlt == "1":
  327. move(xml_path, descXmlPath)
  328. elif productNumJy.find(productNum)>=0:#简营
  329. logger.info(businessInfo["productNum"])
  330. # yuan原有商户模型入库
  331. dbController.getConn()
  332. parse_info = str(businessInfo["result"])
  333. parse_info = parse_info.replace("'", "\\'")
  334. filter_info = "此模型不产生结果"
  335. sql = "INSERT INTO filter_result(report_name,filter_info,parse_info) VALUES ('" + file_name + "', '" + filter_info + "', '" + parse_info + "')"
  336. # print(sql)
  337. dbController.execSql(sql)
  338. # if i==1:
  339. # break
  340. dbController.commit()
  341. jsonPath = txtPath.replace(".txt","_json.txt")
  342. #写入数据到文件
  343. xyHttp.buildJyData(businessInfo,jsonPath)
  344. uploadJsonFile(businessInfo, jsonPath)
  345. # 移动xml文件
  346. descXmlPath = basePath_init + "execed_new/" + os.path.basename(xml_path)
  347. if not os.path.exists(basePath_init + "execed_new/"):
  348. os.mkdir(basePath_init + "execed_new/")
  349. logger.info("移动文件 from " + xml_path + " to " + descXmlPath)
  350. if isPlt == "1":
  351. descTxtPath = basePath_init + "execed_txt/" + os.path.basename(jsonPath)
  352. try:
  353. shutil.move(jsonPath, descTxtPath)
  354. except Exception:
  355. pass
  356. move(xml_path, descXmlPath)
  357. elif productNum == productNumFd:#分蛋 白户审批通过
  358. # yuan原有商户模型入库
  359. dbController.getConn()
  360. parse_info = str(businessInfo["result"])
  361. parse_info = parse_info.replace("'", "\\'")
  362. filter_info = "此模型不产生结果"
  363. sql = "INSERT INTO filter_result(report_name,filter_info,parse_info) VALUES ('" + file_name + "', '" + filter_info + "', '" + parse_info + "')"
  364. # print(sql)
  365. dbController.execSql(sql)
  366. # if i==1:
  367. # break
  368. dbController.commit()
  369. if businessInfo["result"]!="":
  370. result = xyHttp.callNewModel(businessInfo)
  371. uploadAudit(result,businessInfo["businessNum"],productNum)
  372. else:
  373. result = {"approveResult":"1","rule":"白户"}
  374. uploadAudit(result, businessInfo["businessNum"], productNum)
  375. # 移动xml文件
  376. descXmlPath = basePath_init + "execed_new/" + os.path.basename(xml_path)
  377. if not os.path.exists(basePath_init + "execed_new/"):
  378. os.mkdir(basePath_init + "execed_new/")
  379. logger.info("移动文件 from " + xml_path + " to " + descXmlPath)
  380. if isPlt == "1":
  381. move(xml_path, descXmlPath)
  382. elif productNumKn.find(productNum)>=0 :#快牛本地jar包,本地jar改为逗号配置
  383. # yuan原有商户模型入库
  384. dbController.getConn()
  385. parse_info = str(businessInfo["result"])
  386. parse_info = parse_info.replace("'", "\\'")
  387. filter_info = "此模型不产生结果"
  388. sql = "INSERT INTO filter_result(report_name,filter_info,parse_info) VALUES ('" + file_name + "', '" + filter_info + "', '" + parse_info + "')"
  389. # print(sql)
  390. dbController.execSql(sql)
  391. # if i==1:
  392. # break
  393. dbController.commit()
  394. if businessInfo["result"]!="":
  395. result = xyHttp.callLocal(businessInfo)
  396. uploadAudit(result,businessInfo["businessNum"],productNum)
  397. else:
  398. result = {"approveResult":"0","rule":"白户"}
  399. uploadAudit(result, businessInfo["businessNum"], productNum)
  400. # 移动xml文件
  401. descXmlPath = basePath_init + "execed_new/" + os.path.basename(xml_path)
  402. if not os.path.exists(basePath_init + "execed_new/"):
  403. os.mkdir(basePath_init + "execed_new/")
  404. logger.info("移动文件 from " + xml_path + " to " + descXmlPath)
  405. if isPlt == "1":
  406. move(xml_path, descXmlPath)
  407. elif productNum == productNumHst:#海盛通
  408. # yuan原有商户模型入库
  409. dbController.getConn()
  410. parse_info = str(businessInfo["result"])
  411. parse_info = parse_info.replace("'", "\\'")
  412. filter_info = "此模型不产生结果"
  413. sql = "INSERT INTO filter_result(report_name,filter_info,parse_info) VALUES ('" + file_name + "', '" + filter_info + "', '" + parse_info + "')"
  414. # print(sql)
  415. dbController.execSql(sql)
  416. # if i==1:
  417. # break
  418. dbController.commit()
  419. if businessInfo["result"]!="":
  420. result = hst_rule_set.callLocal(businessInfo)
  421. uploadAudit(result,businessInfo["businessNum"],productNum)
  422. else:
  423. result = {"approveResult":"0","rule":"白户"}
  424. uploadAudit(result, businessInfo["businessNum"], productNum)
  425. # 移动xml文件
  426. descXmlPath = basePath_init + "execed_new/" + os.path.basename(xml_path)
  427. if not os.path.exists(basePath_init + "execed_new/"):
  428. os.mkdir(basePath_init + "execed_new/")
  429. logger.info("移动文件 from " + xml_path + " to " + descXmlPath)
  430. if isPlt == "1":
  431. move(xml_path, descXmlPath)
  432. else:
  433. #走新增的自定义模型
  434. customModel=CustomModel();
  435. res=customModel.doCustomModel(productNum,businessInfo,xml_path);
  436. if res==3:
  437. jsonPath = xml_path.replace(".xml", "_json.txt")
  438. dayStrPath = basePath + productNum + "/" + time.strftime('%Y%m%d', time.localtime(time.time())) + "/";
  439. descXmlPath = dayStrPath + "xml/" + os.path.basename(xml_path)
  440. descJsonPath = dayStrPath + "txt/" + os.path.basename(jsonPath)
  441. descTxtPath = dayStrPath + "txt/" + os.path.basename(txtPath)
  442. if not os.path.exists(basePath_init + productNum):
  443. os.mkdir(basePath_init + productNum)
  444. if not os.path.exists(dayStrPath):
  445. os.mkdir(dayStrPath)
  446. if not os.path.exists(dayStrPath + "xml/"):
  447. os.mkdir(dayStrPath + "xml/")
  448. if not os.path.exists(dayStrPath + "txt/"):
  449. os.mkdir(dayStrPath + "txt/")
  450. logger.info("移动文件 from " + xml_path + " to " + descXmlPath)
  451. if isPlt == "1":
  452. move(xml_path, descXmlPath)
  453. shutil.move(jsonPath, descJsonPath)
  454. shutil.move(txtPath, descTxtPath)
  455. else :
  456. descXmlPath = basePath_init + "execed_new/" + os.path.basename(xml_path)
  457. if not os.path.exists(basePath_init + "execed_new/"):
  458. os.mkdir(basePath_init + "execed_new/")
  459. logger.info("移动文件 from " + xml_path + " to " + descXmlPath)
  460. if isPlt == "1":
  461. move(xml_path, descXmlPath)
  462. # if(res):
  463. # result["approveResult"]="1"
  464. #
  465. # print(result);
  466. # 结果返回
  467. # uploadAudit(res, businessInfo["businessNum"], productNum)
  468. # 这个地方嵌进去结果
  469. i=0
  470. #本地jar
  471. if isPlt == "1":
  472. if not os.path.exists(basePath_init + "execed_txt/"):
  473. os.mkdir(basePath_init + "execed_txt/")
  474. descTxtPath = basePath_init + "execed_txt/" + os.path.basename(txtPath)
  475. shutil.move(txtPath, descTxtPath)
  476. #调用jar包
  477. def move(xml_path, descXmlPath):
  478. try:
  479. shutil.move(xml_path, descXmlPath)
  480. # print(xml_path)
  481. if not os.path.exists(basePath_init + "execed_xml/"):
  482. os.mkdir(basePath_init + "execed_xml/")
  483. shutil.move(xml_path+".txt", descXmlPath.replace("execed_new","execed_xml")+".txt")
  484. # print("diaomeidiao")
  485. # os.remove(xml_path+".txt")#删除生成的xml.txt文件
  486. except:
  487. logger.info("移动文件 from " + xml_path + " to " + descXmlPath +" error")
  488. def invokePboc(businessInfo,txtPath):
  489. # ===================================
  490. try:
  491. businessNum = businessInfo["businessNum"]
  492. coopBusinessNum = businessInfo["coopBusinessNum"]
  493. pboc = PBOC()
  494. jarTxt = pboc.calc(txtPath,coopBusinessNum);
  495. result = json.loads(jarTxt)
  496. logger.info(result)
  497. if result.get("errcode")== None:
  498. uploadAudit(result,businessNum,businessInfo["productNum"])
  499. else:
  500. if businessInfo["isBaihu"]=="1":
  501. result = {"approveResult":"1"}
  502. uploadAudit(result, businessNum, businessInfo["productNum"])
  503. logger.error(result["errmsg"])
  504. except:
  505. logger.error("certificateNum=" + businessInfo["coopBusinessNum"])
  506. info = sys.exc_info()
  507. logger.error(info[0])
  508. logger.error(info[1])
  509. # logging.log(logging.ERROR, info[2])
  510. logger.error(traceback.extract_tb(info[2], 1))
  511. #调用xxwjar包
  512. def invokeXxw(businessInfo,txtPath):
  513. try:
  514. businessNum = businessInfo["businessNum"]
  515. coopBusinessNum = businessInfo["coopBusinessNum"]
  516. customerNum = businessInfo["customerNum"]
  517. certificateNum = businessInfo["certificateNum"]
  518. pboc = PBOC()
  519. jarTxt = pboc.calcXxw(coopBusinessNum,customerNum,txtPath);
  520. logger.info("jarTxt:"+jarTxt)
  521. result = json.loads(jarTxt)
  522. jsonPath = basePath+certificateNum+".txt"
  523. # logger.info(jsonPath)
  524. with open(jsonPath, 'w', encoding='utf-8') as fp:
  525. fp.write(jarTxt)
  526. uploadJsonFile(businessInfo,jsonPath)
  527. if not os.path.exists(basePath + "execed_txt/"):
  528. os.mkdir(basePath + "execed_txt/")
  529. descJsonPath = basePath + "execed_txt/" + os.path.basename(jsonPath)
  530. shutil.move(jsonPath, descJsonPath)
  531. except:
  532. logger.error("certificateNum=" + businessInfo["coopBusinessNum"])
  533. info = sys.exc_info()
  534. logger.error(info[0])
  535. logger.error(info[1])
  536. logger.error(traceback.extract_tb(info[2], 1))
  537. #上传审批结果
  538. def uploadAudit(result,businessNum,productNum):
  539. approvalType = result["approveResult"]
  540. if productNum == productNumJz:
  541. if approvalType=="1":
  542. approvalOpinion = "征信通过"
  543. approvalType = "4"
  544. else:
  545. approvalOpinion = "征信拒绝"
  546. approvalType = "3"
  547. elif productNumKn.find(productNum)>=0 or productNum == productNumHst or productNum == productNumFd:
  548. if approvalType=="1":
  549. approvalOpinion = "征信通过"
  550. approvalType = "4"
  551. else:#快牛 需要添加拒绝原因
  552. approvalOpinion = "征信拒绝" + "#" + result["rule"]
  553. approvalType = "3"
  554. taskKey = config.get("baseconf","taskKey")
  555. appoveApiUrl = config.get("baseconf","appoveApiUrl")
  556. key = config.get("baseconf", "AESKey")
  557. data = {"header":{
  558. "ticket": "2938123198320412343",
  559. "timestamp": int(int(round(time.time() * 1000+60*1000))),
  560. "nonce": config.get("baseconf", "nonce")
  561. },
  562. "body":{"approvalType": approvalType, "businessNum": businessNum,"taskKey":taskKey,"approvalOpinion":approvalOpinion}}
  563. access_token = dbController.getToken();
  564. if access_token == "":#获取token失败重新获取
  565. access_token = dbController.getToken();
  566. appoveApiUrl = appoveApiUrl+"?access_token="+access_token
  567. headers = {"Content-Type": "application/json"}
  568. jsonStr = json.dumps(data);
  569. jsonStr = jsonStr.replace('"',"\\\"")#必须替换才行
  570. logger.info(jsonStr)
  571. pboc = PBOC();
  572. encryData = pboc.encrypt(jsonStr,key)
  573. encryData = encryData[0:len(encryData)-2]
  574. logger.info(encryData)
  575. response = requests.post(appoveApiUrl, data=encryData,headers=headers)
  576. text = response.text
  577. pboc = PBOC();
  578. resultText = pboc.decrypt(text, config.get("baseconf", "AESKey"))
  579. logger.info(businessNum + "#" + "uploadAudit upload_result:" + resultText)
  580. #上传解析json
  581. def uploadJsonFile(businessInfo,json_path):
  582. # ===================================
  583. try:
  584. fileName = os.path.basename(json_path)
  585. #上传文件逻辑
  586. logger.info(json_path+"#"+"准备上传文件")
  587. uploadApiUrl = config.get("baseconf", "uploadApiUrl");
  588. token = dbController.getToken();
  589. if token == "":#如果获取失败,重新获取
  590. token = dbController.getToken();
  591. uploadApiUrl = uploadApiUrl + "?access_token=" + token
  592. files = {'file': open(json_path, 'rb')}
  593. logger.info(fileName+"#"+"businessNum:"+businessInfo["businessNum"])
  594. data = {'docType': "23", 'businessNum': businessInfo["businessNum"]}
  595. response = requests.post(uploadApiUrl, files=files, data=data,timeout=15)
  596. text = response.text
  597. logger.info("上传结果:"+text)
  598. pboc = PBOC();
  599. resultText = pboc.decrypt(text,config.get("baseconf", "AESKey"))
  600. logger.info(fileName+"#"+"uploadJsonFile:" + resultText)
  601. except:
  602. logger.error("certificateNum="+businessInfo["coopBusinessNum"])
  603. info = sys.exc_info()
  604. logger.error(info[0])
  605. logger.error(info[1])
  606. # logging.log(logging.ERROR, info[2])
  607. logger.error(traceback.extract_tb(info[2], 1))
  608. mailUtil = MailUtil();
  609. webhook = 'https://oapi.dingtalk.com/robot/send?access_token=64d8b2c7fed4949e9433b807c7c5559939f1517af8f77c1dacb4de19c6910b56'
  610. # mailUtil.dingtalk("号码:" + businessInfo["certificateNum"]+"-"+businessInfo["businessNum"] + " 上传文件失败 ", webhook)
  611. def init_file_list(basePath):
  612. if not os.path.exists(basePath + "execed_txt/"):
  613. os.mkdir(basePath + "execed_txt/")
  614. if not os.path.exists(basePath + "execed_xml/"):
  615. os.mkdir(basePath + "execed_xml/")
  616. if not os.path.exists(basePath + "execed_new/"):
  617. os.mkdir(basePath + "execed_new/")
  618. # if not os.path.exists(basePath + "CPA0100657/"):
  619. # os.mkdir(basePath + "CPA0100657/")
  620. # if not os.path.exists(basePath + "CPA0100759/"):
  621. # os.mkdir(basePath + "CPA0100759/")
  622. # if not os.path.exists(basePath + "CPA0100775/"):
  623. # os.mkdir(basePath + "CPA0100775/")
  624. # if not os.path.exists(basePath + "CPA0100657/"):
  625. # os.mkdir(basePath + "CPA0100657/")
  626. # if not os.path.exists(basePath + "CPA0100841/"):
  627. # os.mkdir(basePath + "CPA0100841/")
  628. if __name__ == '__main__':
  629. basePath_init = "D:/jin_rong/todo/"
  630. init_file_list(basePath_init)
  631. file_name = sys.argv[1]
  632. # file_name = "樊术生_432924196512260092_525976302319050756-20221116100213782.xml"
  633. basePath = "D:/jin_rong/execed_xml/"
  634. xml_path = basePath + file_name
  635. start = timeit.default_timer();
  636. # if len(sys.argv) > 1:
  637. # basePath = sys.argv[1]
  638. # xml_path = basePath + sys.argv[2]
  639. # file_name = sys.argv[2]
  640. # print("parseStarting")
  641. logger.info(xml_path+" 解析开始")
  642. startTime = datetime.now() #开始时间
  643. businessInfo = getBusinessInfo(xml_path)
  644. # with open('D:/jin_rong/test_data/朱传光_371425199305027971_256979050910728199.txt', 'r', encoding='utf-8')as fp:
  645. # businessInfo['result'] = fp.read();
  646. # logger.info(businessInfo)
  647. if businessInfo["isBaihu"]!="2":#白户不上传1211
  648. try:
  649. process(startTime,businessInfo,basePath_init,basePath,xml_path)
  650. except:
  651. logger.error(traceback.print_exc())
  652. logger.error(traceback.format_exc())
  653. s = timeit.default_timer() - start;
  654. logger.info(str(s) + " 秒")
  655. logger.info(xml_path+" 解析完成")
  656. # 执行sql开始
  657. logger.info(xml_path + " 执行sql解析开始")
  658. sqlMap = businessInfo["sqlMap"]
  659. # 执行sql完成
  660. # logger.info(sqlMap)
  661. try:
  662. start = timeit.default_timer();
  663. dbController.getConn()
  664. for sql in sqlMap:
  665. dbController.execSql(sql)
  666. dbController.commit()
  667. s = timeit.default_timer() - start;
  668. logger.info(xml_path+str(s) + " 秒")
  669. except:
  670. logger.error(traceback.print_exc())
  671. logger.error(traceback.format_exc())
  672. logger.info(xml_path + " 执行sql解析失败")
  673. logger.info(xml_path + " 执行sql解析完成")