xmlParser.py0123 203 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428
  1. #!/usr/bin/env Python
  2. # coding=utf-8
  3. import json
  4. from xml.dom import minidom
  5. import consts;
  6. import pandas as pd
  7. import numpy as np;
  8. import time
  9. import log
  10. logger = log.logger
  11. import utils
  12. import loanIndexParser as lip;
  13. import payRcdIndexParser as prp;
  14. import creditCardIndexParser as cip
  15. import queryInfoIndexParser as qip
  16. import requests
  17. import dfParser
  18. import sys
  19. import traceback
  20. import timeit
  21. from mailUtil import MailUtil
  22. #身份信息
  23. identityInfoIndex = '身份信息'
  24. identityInfoDf = pd.DataFrame(columns=consts.identityInfoHeader,index=[identityInfoIndex])
  25. #配偶信息
  26. mateInfoIndex = '配偶信息'
  27. mateInfoDf = pd.DataFrame(columns=consts.mateInfoHeader,index=[mateInfoIndex])
  28. #居住信息
  29. liveInfoIndex = '居住信息'
  30. liveInfoDf = pd.DataFrame(columns=consts.liveInfoHeader,index=[liveInfoIndex])
  31. #职业信息
  32. occupationInfoIndex = '职业信息'
  33. occupationInfoDf = pd.DataFrame(columns=consts.occupationInfoHeader,index=[occupationInfoIndex])
  34. #信贷交易信息提示
  35. loanTradeInfoIndex = '信贷交易信息提示'
  36. briefInfoDf_loanTradeInfo = pd.DataFrame(columns=consts.briefInfoHeader_loanTradeInfo,index=[loanTradeInfoIndex])
  37. #被追偿信息汇总及呆账信息汇总
  38. recoveryInfoSumIndex = '信贷交易违约信息概要'
  39. briefInfoDf_recoveryInfoSum = pd.DataFrame(columns=consts.briefInfoHeader_recoveryInfo,index=[recoveryInfoSumIndex])
  40. #呆账信息汇总
  41. badDebtsInfoIndex = '呆账信息汇总'
  42. briefInfoDf_badDebtsInfoSum = pd.DataFrame(columns=consts.briefInfoHeader_badDebtsInfoSum,index=[badDebtsInfoIndex])
  43. #逾期(透支)信息汇总
  44. overdueInfoSumIndex='逾期(透支)信息汇总'
  45. briefInfoDf_overdueInfoSum = pd.DataFrame(columns=consts.briefInfoHeader_overdueInfoSum,index=[overdueInfoSumIndex])
  46. #信贷交易授信及负债信息概要
  47. loanTradeCreditInfoIndex='信贷交易授信及负债信息概要'
  48. briefInfoDf_loanTradeCreditInfo = pd.DataFrame(columns=consts.briefInfoHeader_loanTradeCreditInfo,index=[loanTradeCreditInfoIndex]).fillna(0.0)
  49. #公共信息概要
  50. publicInfoBriefIndex = '公共信息概要'
  51. publicInfoBriefDf = pd.DataFrame(columns=consts.publicInfoBriefHeader,index=[publicInfoBriefIndex])
  52. #查询记录汇总
  53. queryRecordSumIndex = '查询记录汇总'
  54. queryRecordSumDf = pd.DataFrame(columns=consts.queryRecordSumHeader,index=[queryRecordSumIndex])
  55. #信贷交易明细-被追偿信息
  56. recoveryInfoIndex='被追偿信息'
  57. creditTradeDetailDf_recoveryInfo = pd.DataFrame(columns=consts.creditTradeDetailHeader_recoveryInfo,index=[recoveryInfoIndex])
  58. #信贷交易明细-特殊交易
  59. specialTradeIndex='特殊交易'
  60. creditTradeDetailHeader_specialTrade = pd.DataFrame(columns=consts.creditTradeDetailHeader_specialTrade,index=[specialTradeIndex])
  61. #信贷交易明细
  62. #非循环贷账户
  63. loanInfoIndex='非循环贷账户'
  64. creditTradeDetailDf_loanAccountInfo = pd.DataFrame(columns=consts.creditTradeDetailHeader_loanAccountInfo,index=[loanInfoIndex])
  65. #循环额度下分账户
  66. cycleCreditAccountInfoIndex='循环额度下分账户'
  67. creditTradeDetailDf_cycleCreditAccountInfo = pd.DataFrame(columns=consts.creditTradeDetailHeader_cycleCreditAccountInfo,index=[cycleCreditAccountInfoIndex])
  68. #循环贷账户
  69. cycleLoanAccountInfoIndex='循环贷账户'
  70. creditTradeDetailDf_cycleLoanAccountInfo = pd.DataFrame(columns=consts.creditTradeDetailHeader_cycleLoanAccountInfo,index=[cycleLoanAccountInfoIndex])
  71. #贷款信息
  72. loanAccountInfoIndex='贷款信息'
  73. loanAccountInfoDf = pd.DataFrame(columns=consts.loanAccountInfoHeader,index=[loanAccountInfoIndex])
  74. #贷记卡信息
  75. creditCardAccountInfoIndex = '贷记卡账户'
  76. creditCardAccountInfoDf = pd.DataFrame(columns=consts.creditCardAccountInfoHeader,index=[creditCardAccountInfoIndex])
  77. #准贷记卡
  78. creditCardAccountInfoIndexZ = '准贷记卡账户'
  79. creditCardAccountInfoDfZ = pd.DataFrame(columns=consts.creditCardAccountInfoHeaderZ,index=[creditCardAccountInfoIndexZ])
  80. useRateIndex = '使用率'
  81. useRateDf = pd.DataFrame(columns=consts.creditTradeDetailHeader_useRate,index=[useRateIndex])
  82. openAccountIndex = '开户数'
  83. openAccountDf = pd.DataFrame(columns=consts.creditTradeDetailHeader_openAccount,index=[openAccountIndex])
  84. payRcdStatusIndex = '24期还款状态'
  85. payRcdStatusDf = pd.DataFrame(columns=consts.creditTradeDetailHeader_payRcdStatus,index=[payRcdStatusIndex])
  86. #查询记录明细指标
  87. queryRecordDetailIndex = '信贷审批查询记录明细'
  88. queryRecordDetailDf = pd.DataFrame(columns=consts.queryRecordDetailHeader,index=[queryRecordDetailIndex])
  89. #住房公积金
  90. housingFundRcdIndex = '住房公积金参缴记录'
  91. housingFundRcdDf = pd.DataFrame(columns=consts.housingFundRcdHeader,index=[housingFundRcdIndex])
  92. #汇算-其他
  93. otherIndex = '慧算账新增'
  94. otherDf = pd.DataFrame(columns=consts.otherHeader,index=[otherIndex])
  95. sanshouIndex = '恒昌新增'
  96. sanshouDf = pd.DataFrame(columns=consts.sanShouHeader,index=[sanshouIndex])
  97. class XmlParser(object):
  98. def getNodeData(self,node, key):
  99. data = ""
  100. try:
  101. if len(node.getElementsByTagName(key)) > 0:
  102. nodeValue = node.getElementsByTagName(key)[0].childNodes
  103. if len(nodeValue)>0:
  104. data = nodeValue[0].data
  105. except Exception:
  106. logger.error("getNodeData error")
  107. info = sys.exc_info()
  108. logger.error(info[0])
  109. logger.error(info[1])
  110. logger.error(traceback.extract_tb(info[2], 1))
  111. return data;
  112. def parse(self, xmlData):
  113. result = "{"
  114. try:
  115. docXml = minidom.parseString(xmlData)
  116. queryInfo = self.parseQueryInfo(docXml)
  117. reportTime = queryInfo["reportTime"];
  118. self.parseIdentity(reportTime,docXml)
  119. self.parseLiveInfo(docXml)
  120. self.parseOccupationInfoDf(reportTime,docXml)
  121. self.parseLoanTradeInfo(docXml)
  122. self.parseRecoveryInfoSum(docXml)
  123. self.parseBadDebtsInfoSumDf(docXml)
  124. self.parseOverdueInfoSum(docXml)
  125. self.parseLoanAccountInfoSum(docXml)
  126. self.parseCycleCreditAccountInfoSum(docXml);
  127. self.parseCyleLoanAccountInfoSum(docXml);
  128. self.parseCreditCardInfoSum(docXml)
  129. self.parseCreditCardInfoSumZ(docXml)
  130. self.parseRepaymentSum(docXml)
  131. self.parsePublicInfoBrief(docXml)
  132. self.parseQueryRecordSum(docXml)
  133. self.parseQueryInfoDetail(reportTime,docXml)
  134. self.parseHousingFundRcd(reportTime,docXml)
  135. loanAccountDfs = []
  136. start = timeit.default_timer();
  137. logger.info(queryInfo["queryInfoCardId"]+"贷款解析开始")
  138. # 非循环
  139. noloopcreditaccountbols = self.mergeLoanDf(reportTime, docXml, "NOLOOPCREDITACCOUNTBOLS")
  140. # 循环额度
  141. loopquotaaccountbols = self.mergeLoanDf(reportTime, docXml, "LOOPQUOTAACCOUNTBOLS")
  142. # 循环贷账户
  143. loopcreditaccountbols = self.mergeLoanDf(reportTime, docXml, "LOOPCREDITACCOUNTBOLS")
  144. loanAccountDfs = noloopcreditaccountbols + loopquotaaccountbols + loopcreditaccountbols
  145. print(len(loanAccountDfs))
  146. s = timeit.default_timer() - start
  147. logger.info(str(s) + " 秒")
  148. logger.info(queryInfo["queryInfoCardId"] + "贷款解析完成")
  149. start = timeit.default_timer();
  150. logger.info(queryInfo["queryInfoCardId"] + "信用卡解析开始")
  151. creditCardAccountDfs = self.mergeCreditCardDf(reportTime, docXml)
  152. print(len(creditCardAccountDfs))
  153. creditCardAccountDfsZ = self.mergeCreditCardDfZ(reportTime, docXml)
  154. print(len(creditCardAccountDfsZ))
  155. # 合并贷款
  156. loanMergeDf = pd.DataFrame(columns=dfParser.dfHeaderLoan)
  157. loanPayRecordMergeDf = pd.DataFrame(columns=dfParser.dfHeaderLoanPayRecord)
  158. loanSpecialTradeMergeDf = pd.DataFrame(columns=dfParser.dfHeaderLoanSpecialTrade) # 特殊交易
  159. loanMergeDfDs = []
  160. loanPayRecordMergeDfDs = []
  161. # for loanDfObj in loanAccountDfs:
  162. # loanMergeDf = pd.concat([loanMergeDf, loanDfObj["loanDf"]], axis=0, ignore_index=True);
  163. # loanPayRecordMergeDf = pd.concat([loanPayRecordMergeDf, loanDfObj["loanPayRecordDf"]], axis=0,ignore_index=True);
  164. # loanSpecialTradeMergeDf = pd.concat([loanSpecialTradeMergeDf, loanDfObj["specialTradeDf"]], axis=0,ignore_index=True);
  165. for loanDfObj in loanAccountDfs:
  166. loanMergeDfDs.append(loanDfObj["loanDf"])
  167. loanPayRecordMergeDfDs.extend(loanDfObj["loanPayRecordDf"])
  168. loanSpecialTradeMergeDf = pd.concat([loanSpecialTradeMergeDf, loanDfObj["specialTradeDf"]], axis=0,ignore_index=True);
  169. loanMergeDf = pd.DataFrame(loanMergeDfDs)
  170. loanPayRecordMergeDf = pd.DataFrame(loanPayRecordMergeDfDs)
  171. # 合并贷记卡
  172. creditCardMergeDf = pd.DataFrame(columns=dfParser.dfHeaderCreditCard)
  173. creditCardPayRecordMergeDf = pd.DataFrame(columns=dfParser.dfHeaderCreditCardPayRecord)
  174. for creditCardDfObj in creditCardAccountDfs:
  175. creditCardMergeDf = pd.concat([creditCardMergeDf, creditCardDfObj["creditCardDf"]], axis=0,ignore_index=True);
  176. creditCardPayRecordMergeDf = pd.concat([creditCardPayRecordMergeDf, creditCardDfObj["creditCardPayRecordDf"]], axis=0, ignore_index=True);
  177. # 准贷记卡合并df
  178. creditCardMergeDfZ = pd.DataFrame(columns=dfParser.dfHeaderCreditCardZ)
  179. creditCardPayRecordMergeDfZ = pd.DataFrame(columns=dfParser.dfHeaderCreditCardPayRecordZ)
  180. for creditCardDfObj in creditCardAccountDfsZ:
  181. creditCardMergeDfZ = pd.concat([creditCardMergeDfZ, creditCardDfObj["creditCardDfZ"]], axis=0,ignore_index=True);
  182. creditCardPayRecordMergeDfZ = pd.concat([creditCardPayRecordMergeDfZ, creditCardDfObj["creditCardPayRecordDfZ"]], axis=0,ignore_index=True);
  183. s = timeit.default_timer() - start
  184. logger.info(str(s) + " 秒")
  185. logger.info(queryInfo["queryInfoCardId"] + "信用卡解析完成")
  186. result += utils.toJson(identityInfoDf) + ","
  187. result += utils.toJson(mateInfoDf) + ","
  188. result += utils.toJson(liveInfoDf) + ","
  189. result += utils.toJson(occupationInfoDf) + ","
  190. result += "briefInfoDf_loanTradeInfo" + "," # 占位符
  191. result += "briefInfoDf_recoveryInfoSum" + "," # 占位符
  192. result += "briefInfoDf_overdueInfoSum" + ","
  193. result += utils.toJson(briefInfoDf_badDebtsInfoSum) + ","
  194. result += utils.toJson(briefInfoDf_loanTradeCreditInfo) + ","
  195. result += utils.toJson(publicInfoBriefDf) + ","
  196. result += utils.toJson(queryRecordSumDf) + ","
  197. # 合并被追偿信息DF
  198. recoveryInfoMergeDf = self.mergeRecoveryInfoDf(reportTime, docXml)
  199. self.parseRecoveryInfoMergeDf(recoveryInfoMergeDf)
  200. result = result.replace("briefInfoDf_recoveryInfoSum", utils.toJson(briefInfoDf_recoveryInfoSum)) # 替换汇总中的指标
  201. result += utils.toJson(creditTradeDetailDf_recoveryInfo) + "," # 设置占位符,由于存在概要的指标在明细中计算
  202. # 特殊交易
  203. self.parseSpecialTrade(loanSpecialTradeMergeDf)
  204. result += utils.toJson(creditTradeDetailHeader_specialTrade) + ","
  205. # 信贷交易明细-解析非循环贷账户
  206. self.parseLoanAccountInfo(loanMergeDf);
  207. result += utils.toJson(creditTradeDetailDf_loanAccountInfo) + ","
  208. # 循环额度分账户
  209. self.parseCycleCreditAccountInfo(loanMergeDf);
  210. result += utils.toJson(creditTradeDetailDf_cycleCreditAccountInfo) + ","
  211. # 循环贷
  212. self.parseCycleLoanAccountInfo(loanMergeDf);
  213. result += utils.toJson(creditTradeDetailDf_cycleLoanAccountInfo) + ","
  214. # 解析贷款账户指标
  215. start = timeit.default_timer();
  216. self.parseLoanMergeDf(loanMergeDf,reportTime);
  217. s = timeit.default_timer() - start
  218. logger.info("解析贷款账户指标 " + str(s) + " 秒")
  219. # 解析还款记录相关指标
  220. start = timeit.default_timer();
  221. self.parseLoanMergeAndPayRecordDf(loanMergeDf, loanPayRecordMergeDf,reportTime);
  222. s = timeit.default_timer() - start
  223. logger.info("解析还款记录相关指标 " + str(s) + " 秒")
  224. result += utils.toJson(loanAccountInfoDf) + ","
  225. # 解析贷记卡账户指标
  226. self.parseCreditCardMergeDf(creditCardMergeDf,reportTime);
  227. self.parseCreditCardMergeAndPayRecordDf(creditCardMergeDf, creditCardPayRecordMergeDf,reportTime)
  228. # 解析准贷记卡相关指标
  229. self.parseCreditCardMergeDfZ(creditCardMergeDfZ, creditCardPayRecordMergeDfZ);
  230. result += utils.toJson(creditCardAccountInfoDf) + ","
  231. result += utils.toJson(creditCardAccountInfoDfZ) + ","
  232. # 使用率
  233. self.parseUseRate()
  234. result += utils.toJson(useRateDf) + ","
  235. # 开户数
  236. self.parseOpenAccount(loanMergeDf, creditCardMergeDf, creditCardMergeDfZ, recoveryInfoMergeDf, loanPayRecordMergeDf,creditCardPayRecordMergeDf, creditCardPayRecordMergeDfZ,reportTime)
  237. result += utils.toJson(openAccountDf) + ","
  238. # 24期还款状态
  239. start = timeit.default_timer();
  240. self.parsePayRcdStatus(loanMergeDf, creditCardMergeDf, creditCardMergeDfZ, loanPayRecordMergeDf,creditCardPayRecordMergeDf, creditCardPayRecordMergeDfZ,reportTime)
  241. s = timeit.default_timer() - start
  242. logger.info("24期还款状态 " + str(s) + " 秒")
  243. result += utils.toJson(payRcdStatusDf) + ","
  244. # 由于逾期汇总的指标再还款状态之后需要替换占位 TODO
  245. result = result.replace("briefInfoDf_overdueInfoSum", utils.toJson(briefInfoDf_overdueInfoSum))
  246. # 0525 由于在开户数后,统计信贷信息概要的指标,替换占位符
  247. result = result.replace("briefInfoDf_loanTradeInfo", utils.toJson(briefInfoDf_loanTradeInfo))
  248. # 公积金
  249. result += utils.toJson(housingFundRcdDf) + ","
  250. result += utils.toJson(queryRecordDetailDf) + ","
  251. #1112修改慧算账需求
  252. # otherDf.loc[otherIndex, "贷款当前逾期金额"] = utils.null2Zero(
  253. # creditTradeDetailDf_loanAccountInfo.loc[loanInfoIndex, '当前一共逾期总额']) + \
  254. # utils.null2Zero(creditTradeDetailDf_cycleCreditAccountInfo.loc[
  255. # cycleCreditAccountInfoIndex, '当前一共逾期总额']) \
  256. # + utils.null2Zero(
  257. # creditTradeDetailDf_cycleLoanAccountInfo.loc[cycleLoanAccountInfoIndex, '当前一共逾期总额'])
  258. # otherDf.loc[otherIndex,"当前逾期金额"] = utils.null2Zero( otherDf.loc[otherIndex, "贷款当前逾期金额"])+\
  259. # utils.null2Zero(otherDf.loc[otherIndex, '贷记卡当前逾期金额'])
  260. #
  261. # otherDf.loc[otherIndex, "历史最大逾期金额"] = np.max([ utils.null2Zero(briefInfoDf_overdueInfoSum.loc[overdueInfoSumIndex, '非循环贷帐户单月最高逾期总额']),
  262. # utils.null2Zero(briefInfoDf_overdueInfoSum.loc[overdueInfoSumIndex, '循环额度下分账户单月最高逾期总额']),
  263. # utils.null2Zero(briefInfoDf_overdueInfoSum.loc[overdueInfoSumIndex, '贷记卡账户单月逾期总额']) ])
  264. # otherDf.loc[otherIndex, "贷款历史最大逾期期数"] = utils.null2Zero(briefInfoDf_overdueInfoSum.loc[overdueInfoSumIndex, '非循环贷帐户最长逾期月数'])+\
  265. # utils.null2Zero(briefInfoDf_overdueInfoSum.loc[overdueInfoSumIndex, '循环额度下分账户最长逾期月数'])+ \
  266. # utils.null2Zero(briefInfoDf_overdueInfoSum.loc[
  267. # overdueInfoSumIndex, '循环贷账户最长逾期月数'])
  268. # otherDf.loc[otherIndex, "近3个月M1及以上次数"] = utils.null2Zero(payRcdStatusDf.loc[payRcdStatusIndex, '贷款账户近3月逾期期数大于或等于“1”的次数'])+\
  269. # utils.null2Zero(payRcdStatusDf.loc[payRcdStatusIndex, '贷记卡账户近3月逾期期数大于或等于“1”的次数'])
  270. # otherDf.loc[otherIndex, "近6个月M1及以上次数"] = utils.null2Zero(
  271. # payRcdStatusDf.loc[payRcdStatusIndex, '贷款账户近6月逾期期数大于或等于“1”的次数']) + \
  272. # utils.null2Zero(payRcdStatusDf.loc[
  273. # payRcdStatusIndex, '贷记卡账户近6月逾期期数大于或等于“1”的次数'])
  274. # otherDf.loc[otherIndex, "近12个月M1及以上次数"] = utils.null2Zero(
  275. # payRcdStatusDf.loc[payRcdStatusIndex, '贷款账户近12月逾期期数大于或等于“1”的次数']) + \
  276. # utils.null2Zero(payRcdStatusDf.loc[
  277. # payRcdStatusIndex, '贷记卡账户近12月逾期期数大于或等于“1”的次数'])
  278. # otherDf.loc[otherIndex, "近24个月M1及以上次数"] = utils.null2Zero(
  279. # payRcdStatusDf.loc[payRcdStatusIndex, '贷款账户近24月逾期期数大于或等于“1”的次数']) + \
  280. # utils.null2Zero(payRcdStatusDf.loc[
  281. # payRcdStatusIndex, '贷记卡账户近24月逾期期数大于或等于“1”的次数'])
  282. # otherDf.loc[otherIndex, "近6个月M2及以上次数"] = utils.null2Zero(
  283. # payRcdStatusDf.loc[payRcdStatusIndex, '贷款账户近6月逾期期数大于或等于“2”的次数']) + \
  284. # utils.null2Zero(payRcdStatusDf.loc[
  285. # payRcdStatusIndex, '贷记卡账户近6月逾期期数大于或等于“2”的次数'])
  286. # otherDf.loc[otherIndex, "近12个月M2及以上次数"] = utils.null2Zero(
  287. # payRcdStatusDf.loc[payRcdStatusIndex, '贷款账户近12月逾期期数大于或等于“2”的次数']) + \
  288. # utils.null2Zero(payRcdStatusDf.loc[
  289. # payRcdStatusIndex, '贷记卡账户近12月逾期期数大于或等于“2”的次数'])
  290. # otherDf.loc[otherIndex, "近12个月M3及以上次数"] = utils.null2Zero(
  291. # payRcdStatusDf.loc[payRcdStatusIndex, '贷款账户近12月逾期期数大于或等于“3”的次数']) + \
  292. # utils.null2Zero(payRcdStatusDf.loc[
  293. # payRcdStatusIndex, '贷记卡账户近12月逾期期数大于或等于“3”的次数'])
  294. #
  295. # otherDf.loc[otherIndex, "近24个月M4及以上次数"] = utils.null2Zero(
  296. # payRcdStatusDf.loc[payRcdStatusIndex, '贷款账户近24月逾期期数大于或等于“4”的次数']) + \
  297. # utils.null2Zero(payRcdStatusDf.loc[
  298. # payRcdStatusIndex, '贷记卡账户近24月逾期期数大于或等于“4”的次数'])
  299. # otherDf.loc[otherIndex, "贷款发放笔数"] = utils.null2Zero(briefInfoDf_loanTradeInfo.loc[loanTradeInfoIndex, '个人住房贷款账户数'])+ \
  300. # utils.null2Zero(
  301. # briefInfoDf_loanTradeInfo.loc[loanTradeInfoIndex, '个人商用房贷款(包括商住两用)账户数']) + \
  302. # utils.null2Zero(
  303. # briefInfoDf_loanTradeInfo.loc[loanTradeInfoIndex, '其他类贷款账户数'])
  304. # otherDf.loc[otherIndex, "贷款授信总额"] = utils.null2Zero(briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '非循环贷账户授信总额'])+\
  305. # briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '循环额度下分账户授信总额']\
  306. # +briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '循环贷账户授信总额']
  307. # otherDf.loc[otherIndex, "未结清贷款最近6个月平均应还款"]=utils.null2Zero(briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '非循环贷账户6月平均应还款'])+\
  308. # utils.null2Zero(briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '循环额度下分账户6月平均应还款'])+\
  309. # utils.null2Zero(briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '循环贷账户6月平均应还款'])
  310. # otherDf.loc[otherIndex, "房贷发放笔数"] = utils.null2Zero(briefInfoDf_loanTradeInfo.loc[loanTradeInfoIndex, '个人住房贷款账户数'])+ \
  311. # utils.null2Zero(
  312. # briefInfoDf_loanTradeInfo.loc[loanTradeInfoIndex, '个人商用房贷款(包括商住两用)账户数'])
  313. # otherDf.loc[otherIndex, "近3个月新增贷款授信总额"] = utils.null2Zero(openAccountDf.loc[openAccountIndex, '近3个月贷款账户开户数'])\
  314. # *utils.null2Zero(loanAccountInfoDf.loc[loanAccountInfoIndex, '近3月开户平均贷款本金'])
  315. # otherDf.loc[otherIndex, "近6个月新增贷款授信总额"] = utils.null2Zero(
  316. # openAccountDf.loc[openAccountIndex, '近6个月贷款账户开户数']) * utils.null2Zero(
  317. # loanAccountInfoDf.loc[loanAccountInfoIndex, '近6月开户平均贷款本金'])
  318. # otherDf.loc[otherIndex, "近12个月新增贷款授信总额"] = utils.null2Zero(
  319. # openAccountDf.loc[openAccountIndex, '近12个月贷款账户开户数']) * utils.null2Zero(
  320. # loanAccountInfoDf.loc[loanAccountInfoIndex, '近12月开户平均贷款本金'])
  321. # otherDf.loc[otherIndex, "近3个月新授信贷记卡总额度"] = utils.null2Zero(openAccountDf.loc[openAccountIndex, '近3个月贷记卡账户开户数'])*\
  322. # utils.null2Zero(creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '近3月开卡平均额度'])
  323. # otherDf.loc[otherIndex, "近1个月贷款和信用卡审批查询次数"] = utils.null2Zero(queryRecordSumDf.loc[queryRecordSumIndex, '近1月内的查询次数-贷款审批'])+ \
  324. # utils.null2Zero(queryRecordSumDf.loc[
  325. # queryRecordSumIndex, '近1月内的查询次数-信用卡审批'])
  326. # otherDf.loc[otherIndex, "近3个月贷款和信用卡审批查询次数"] = utils.null2Zero(
  327. # queryRecordDetailDf.loc[queryRecordDetailIndex, '近3月查询次数贷款审批']) + \
  328. # utils.null2Zero(queryRecordDetailDf.loc[
  329. # queryRecordDetailIndex, '近3月查询次数信用卡审批'])
  330. # otherDf.loc[otherIndex, "近6个月贷款和信用卡审批查询次数"]= utils.null2Zero(
  331. # queryRecordDetailDf.loc[queryRecordDetailIndex, '近6月查询次数贷款审批']) + \
  332. # utils.null2Zero(queryRecordDetailDf.loc[
  333. # queryRecordDetailIndex, '近6月查询次数信用卡审批'])
  334. # otherDf.loc[otherIndex, "近12个月贷款和信用卡审批查询次数"] = utils.null2Zero(
  335. # queryRecordDetailDf.loc[queryRecordDetailIndex, '近12月查询次数贷款审批']) + \
  336. # utils.null2Zero(queryRecordDetailDf.loc[
  337. # queryRecordDetailIndex, '近12月查询次数信用卡审批'])
  338. # otherDf.loc[otherIndex, "未来12个月负债总计"] = round(np.sum(loanMergeDf["贷款负债"]),2)+creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '大额专项分期额度(合计)']
  339. #1112end 慧算账
  340. # try:
  341. # # self.getLastOverdueMonth(loanMergeDf,creditCardMergeDf,loanPayRecordMergeDf,creditCardPayRecordMergeDf,reportTime)
  342. # # self.calcPayRcdStatus(loanPayRecordMergeDf,creditCardPayRecordMergeDf,reportTime)
  343. # # except Exception:
  344. # # logger.error(traceback.print_exc())
  345. # # logger.error(traceback.format_exc())
  346. result += utils.toJson(otherDf) + ","
  347. #三寿新增
  348. result += utils.toJson(sanshouDf) + ""
  349. result += "}"
  350. except Exception:
  351. info = sys.exc_info()
  352. # logger.error(str(Exception))
  353. logger.error(queryInfo["queryInfoCardId"]+" error")
  354. logger.error(info[0])
  355. logger.error(info[1])
  356. logger.error(traceback.extract_tb(info[2], 1))
  357. # logger.error( 'str(Exception):\t', str(Exception))
  358. # logger.error('str(e):\t\t', str(e))
  359. # logger.error('repr(e):\t', repr(e))
  360. # logger.error('e.message:\t', e.message)
  361. logger.error(traceback.print_exc())
  362. logger.error(traceback.format_exc())
  363. mailUtil = MailUtil();
  364. webhook = 'https://oapi.dingtalk.com/robot/send?access_token=64d8b2c7fed4949e9433b807c7c5559939f1517af8f77c1dacb4de19c6910b56'
  365. mailUtil.dingtalk("号码:"+queryInfo["queryInfoCardId"]+" 解析错误 "+traceback.format_exc(),webhook)
  366. return result;
  367. # 解析被查询信息指标
  368. def parseQueryInfo(self,docXml):
  369. headbo = docXml.documentElement.getElementsByTagName("HEADBO")[0]
  370. reportTime= self.getNodeData(headbo,"RPTTIME")
  371. queryInfo = {};
  372. queryInfoCardId = self.getNodeData(headbo,"CRENUMBER")
  373. queryInfo["reportTime"] = reportTime.replace("T"," ")
  374. queryInfo["queryInfoCardId"] = queryInfoCardId; # 被查询者证件号码
  375. otherDf.loc[otherIndex, '报告查询日期'] = queryInfo["reportTime"];
  376. sanshouDf.loc[sanshouIndex,"身份证号前两位"]=queryInfoCardId[0:2]
  377. print(queryInfo)
  378. return queryInfo;
  379. def parseIdentity(self,reportTime,docXml):
  380. tmpNode =docXml.documentElement.getElementsByTagName("BASEINFO")
  381. if len(tmpNode)>0:
  382. baseInfo = docXml.documentElement.getElementsByTagName("BASEINFO")[0]
  383. tmpNode = docXml.documentElement.getElementsByTagName("MARRIAGEINFOSG")
  384. identityInfoDf.loc[identityInfoIndex, '性别'] = self.getNodeData(baseInfo,"SEXDESC")
  385. identityInfoDf.loc[identityInfoIndex, '出生日期'] = self.getNodeData(baseInfo,"BIRTHDAY")
  386. identityInfoDf.loc[identityInfoIndex, '国籍'] = self.getNodeData(baseInfo,"NATIONDESC")
  387. identityInfoDf.loc[identityInfoIndex, '户籍地址'] = self.getNodeData(baseInfo,"ADDRESS")
  388. if len(tmpNode)>0:
  389. marriageinfosg = docXml.documentElement.getElementsByTagName("MARRIAGEINFOSG")[0]
  390. self.parseMate(marriageinfosg)
  391. identityInfoDf.loc[identityInfoIndex, '婚姻状况'] = self.getNodeData(marriageinfosg,"MARSTATUDESC")
  392. identityInfoDf.loc[identityInfoIndex, '学历'] = self.getNodeData(baseInfo,"DEGREEDESC")
  393. identityInfoDf.loc[identityInfoIndex, '学位'] = self.getNodeData(baseInfo,"DEGREEDESC")
  394. identityInfoDf.loc[identityInfoIndex, '通讯地址'] = self.getNodeData(baseInfo,"COMMUADDRESS")
  395. identityInfoDf.loc[identityInfoIndex, '就业状况'] = self.getNodeData(baseInfo,"WORKSTATUSDESC")
  396. mobiles = docXml.documentElement.getElementsByTagName("TELEPHONEINFOSGLS")
  397. if len(mobiles)>0:
  398. telephoneinfosgls = docXml.documentElement.getElementsByTagName("TELEPHONEINFOSGLS")[0]
  399. telephoneinfosg = telephoneinfosgls.getElementsByTagName("TELEPHONEINFOSG");
  400. identityInfoDf.loc[identityInfoIndex, '历史手机号码数'] = len(telephoneinfosg)
  401. identityInfoDf.loc[identityInfoIndex, '近3个月手机号码数'] = self.getLastMonthMobileCount(telephoneinfosg, 3, reportTime)
  402. identityInfoDf.loc[identityInfoIndex, '近6个月手机号码数'] = self.getLastMonthMobileCount(telephoneinfosg, 6, reportTime)
  403. identityInfoDf.loc[identityInfoIndex, '近12个月手机号码数'] = self.getLastMonthMobileCount(telephoneinfosg, 12, reportTime)
  404. identityInfoDf.loc[identityInfoIndex, '近24个月手机号码数'] = self.getLastMonthMobileCount(telephoneinfosg, 24, reportTime)
  405. # print(identityInfoDf.to_json(orient="index",force_ascii=False))
  406. def getLastMonthMobileCount(self,telephoneinfosg, month, reportTime):
  407. df = pd.DataFrame()
  408. for i in range(0,len(telephoneinfosg)):
  409. telephone = self.getNodeData(telephoneinfosg[i],"TELEPHONE")
  410. updatedateinfo= self.getNodeData(telephoneinfosg[i],"UPDATEDATEINFO")
  411. df.loc[i,0] = telephone
  412. df.loc[i,1] = updatedateinfo
  413. # 当前日期
  414. last1MonthDateStr = reportTime
  415. # 最近一个月
  416. lastMonthDate = np.datetime64(last1MonthDateStr, "D") - np.timedelta64(30 * month, 'D')
  417. lastMonthMobileDf = df[df[1] >= str(lastMonthDate)]
  418. return lastMonthMobileDf.shape[0];
  419. def parseMate(self,marriageinfosg):
  420. mateInfoDf.loc[mateInfoIndex, '姓名'] = self.getNodeData(marriageinfosg,"SPUOSENAME")
  421. mateInfoDf.loc[mateInfoIndex, '证件号码'] = self.getNodeData(marriageinfosg,"CERTNUM")
  422. mateInfoDf.loc[mateInfoIndex, '工作单位'] = self.getNodeData(marriageinfosg,"COMPANY")
  423. mateInfoDf.loc[mateInfoIndex, '联系电话'] = self.getNodeData(marriageinfosg,"TELNUM")
  424. # print(mateInfoDf.to_json(orient="index", force_ascii=False))
  425. # 解析居住信息
  426. def parseLiveInfo(self,docXml):
  427. # residenceinfosgls = docXml.documentElement.getElementsByTagName("RESIDENCEINFOSGLS")
  428. residenceinfosg = docXml.documentElement.getElementsByTagName("RESIDENCEINFOSG");
  429. df = pd.DataFrame()
  430. for i in range(0, len(residenceinfosg)):
  431. resistatusdesc = self.getNodeData(residenceinfosg[i], "RESISTATUSDESC")
  432. address = self.getNodeData(residenceinfosg[i], "ADDRESS")
  433. telnum = self.getNodeData(residenceinfosg[i], "TELNUM")
  434. updatedateinfo = self.getNodeData(residenceinfosg[i], "UPDATEDATEINFO")
  435. df.loc[i, 0] = resistatusdesc
  436. df.loc[i, 1] = address
  437. df.loc[i, 2] = telnum
  438. df.loc[i, 3] = updatedateinfo
  439. if len(residenceinfosg)>0:
  440. liveInfoDf.loc[liveInfoIndex, '居住地址'] = self.getNodeData(residenceinfosg[0],"ADDRESS")
  441. liveInfoDf.loc[liveInfoIndex, '住宅电话'] = self.getNodeData(residenceinfosg[0],"TELNUM")
  442. liveInfoDf.loc[liveInfoIndex, '历史居住地址个数'] = len(residenceinfosg);
  443. curDate = np.datetime64(time.strftime("%Y-%m-%d"));
  444. last3year = str(curDate)[0:4]
  445. last3yearDate = str(int(last3year) - 3) + str(curDate)[4:10]
  446. lastLiveDf = df[df[3] >= last3yearDate];
  447. liveInfoDf.loc[liveInfoIndex, '最近3年内居住地址个数'] = lastLiveDf.index.size ;
  448. houseIndex = df[df[0] == '自置'].index.size > 0
  449. if (houseIndex):
  450. houseStr = '是'
  451. else:
  452. houseStr = '否'
  453. liveInfoDf.loc[liveInfoIndex, '当前居住状况-是否具有自有住房'] = houseStr;
  454. liveInfoDf.loc[liveInfoIndex, '居住状况'] = self.getNodeData(residenceinfosg[0],"RESISTATUSDESC")
  455. liveInfoDf.loc[liveInfoIndex, '信息更新日期'] = self.getNodeData(residenceinfosg[0],"UPDATEDATEINFO")
  456. # print(liveInfoDf.to_json(orient="index", force_ascii=False))
  457. # 解析职业信息
  458. def parseOccupationInfoDf(self,reportTime,docXml):
  459. vocationinfosg = docXml.documentElement.getElementsByTagName("VOCATIONINFOSG");
  460. df = pd.DataFrame()
  461. if len(vocationinfosg)>0:
  462. for i in range(0, len(vocationinfosg)):
  463. # df.loc[i, 0] = self.getNodeData(vocationinfosg[i], "WORDSTATUSDESC")
  464. df.loc[i, 0] = self.getNodeData(vocationinfosg[i], "CPNTYPEDESC")
  465. df.loc[i, 1] = self.getNodeData(vocationinfosg[i], "TRADEDESC")
  466. df.loc[i, 2] = self.getNodeData(vocationinfosg[i], "VOCATIONDESC")
  467. df.loc[i, 3] = self.getNodeData(vocationinfosg[i], "VOCATIONTITLEDESC")
  468. df.loc[i, 4] = self.getNodeData(vocationinfosg[i], "COMPANY")
  469. df.loc[i, 5] = self.getNodeData(vocationinfosg[i], "CPNADDRESS")
  470. df.loc[i, 6] = self.getNodeData(vocationinfosg[i], "CPNTELNUM")
  471. df.loc[i, 7] = self.getNodeData(vocationinfosg[i], "BEGINYEAR")
  472. df.loc[i, 8] = self.getNodeData(vocationinfosg[i], "INFOUPDATEDATE")
  473. occupationInfoDf.loc[occupationInfoIndex, '工作单位'] = self.getNodeData(vocationinfosg[0], "COMPANY")
  474. last3yearDate = utils.getLastMonthDate(reportTime, 12 * 3)
  475. last3yearOccDf = df[df[8] >= last3yearDate]
  476. occupationInfoDf.loc[occupationInfoIndex, '最近3年内工作单位数'] = last3yearOccDf.index.size;
  477. occupationInfoDf.loc[occupationInfoIndex, '单位电话'] = self.getNodeData(vocationinfosg[0], "CPNTELNUM")
  478. try:
  479. minDateIndex = np.argmin(df[7]);
  480. maxDateIndex = np.argmax(df[7]);
  481. rowYearMin = df.loc[minDateIndex, :].dropna()
  482. rowYearMax = df.loc[maxDateIndex, :].dropna()
  483. if rowYearMin[7] != "":
  484. occupationInfoDf.loc[occupationInfoIndex, '最早进入本单位年份距报告日期时长'] = int(
  485. str(np.datetime64(reportTime, "Y"))) - int(rowYearMin[7])
  486. if rowYearMax[7] != "":
  487. occupationInfoDf.loc[occupationInfoIndex, '最新进入本单位年份距报告日期时长'] = int(
  488. str(np.datetime64(reportTime, "Y"))) - int(rowYearMax[7])
  489. except:
  490. logger.error("最早进入本单位年份距报告日期时长解析异常")
  491. occupationInfoDf.loc[occupationInfoIndex, '单位性质'] = self.getNodeData(vocationinfosg[0], "CPNTYPEDESC")
  492. occupationInfoDf.loc[occupationInfoIndex, '单位地址'] = self.getNodeData(vocationinfosg[0], "CPNADDRESS")
  493. occupationInfoDf.loc[occupationInfoIndex, '职业'] = self.getNodeData(vocationinfosg[0], "VOCATIONDESC")
  494. occupationInfoDf.loc[occupationInfoIndex, '行业'] = self.getNodeData(vocationinfosg[0], "TRADEDESC")
  495. occupationInfoDf.loc[occupationInfoIndex, '职务'] = self.getNodeData(vocationinfosg[0], "TITLEDESC")
  496. occupationInfoDf.loc[occupationInfoIndex, '职称'] = self.getNodeData(vocationinfosg[0], "VOCATIONTITLEDESC")
  497. occupationInfoDf.loc[occupationInfoIndex, '进入本单位年份'] =self.getNodeData(vocationinfosg[0], "BEGINYEAR")
  498. occupationInfoDf.loc[occupationInfoIndex, '信息更新日期'] = self.getNodeData(vocationinfosg[0], "INFOUPDATEDATE")
  499. occupationInfoDf.loc[occupationInfoIndex, '历史工作单位数'] = len(vocationinfosg)
  500. # print(occupationInfoDf.to_json(orient="index", force_ascii=False))
  501. # 信贷交易明细汇总
  502. def parseLoanTradeInfo(self,docXml):
  503. credittipsinfo = docXml.documentElement.getElementsByTagName("CREDITTIPSINFO");
  504. if len(credittipsinfo)>0:
  505. briefInfoDf_loanTradeInfo.loc[loanTradeInfoIndex, '个人住房贷款账户数'] = utils.toInt(self.getNodeData(credittipsinfo[0],"ACCOUNTNUM"))
  506. briefInfoDf_loanTradeInfo.loc[loanTradeInfoIndex, '个人商用房贷款(包括商住两用)账户数'] = utils.toInt(self.getNodeData(credittipsinfo[1],"ACCOUNTNUM"))
  507. briefInfoDf_loanTradeInfo.loc[loanTradeInfoIndex, '其他类贷款账户数'] = utils.toInt(self.getNodeData(credittipsinfo[2],"ACCOUNTNUM"))
  508. briefInfoDf_loanTradeInfo.loc[loanTradeInfoIndex, '贷记卡账户数'] = utils.toInt(self.getNodeData(credittipsinfo[3],"ACCOUNTNUM"))
  509. briefInfoDf_loanTradeInfo.loc[loanTradeInfoIndex, '准贷记卡账户数'] = utils.toInt(self.getNodeData(credittipsinfo[4],"ACCOUNTNUM"))
  510. #汇算
  511. moths = [self.getNodeData(credittipsinfo[0], "FIRSTBUSMONTH"),
  512. self.getNodeData(credittipsinfo[1], "FIRSTBUSMONTH"),self.getNodeData(credittipsinfo[2], "FIRSTBUSMONTH")]
  513. moths=utils.get_real_arr(moths)
  514. if len(moths)>0:
  515. otherDf.loc[otherIndex, '首笔贷款发放月份'] = min(moths)
  516. otherDf.loc[otherIndex, '首张贷记卡发卡月份'] = self.getNodeData(credittipsinfo[3], "FIRSTBUSMONTH")
  517. # print(briefInfoDf_loanTradeInfo.to_json(orient="index", force_ascii=False))
  518. # 解析被追偿信息汇总
  519. def parseRecoveryInfoSum(self,docXml):
  520. recoveredinfosumsmry = docXml.documentElement.getElementsByTagName("RECOVEREDINFOSUMSMRY");
  521. recorinfosumsg = docXml.documentElement.getElementsByTagName("RECORINFOSUMSG")
  522. if len(recoveredinfosumsmry)>0:
  523. if len(recorinfosumsg)>0:
  524. briefInfoDf_recoveryInfoSum.loc[recoveryInfoSumIndex, '资产处置业务账户数'] = utils.toInt(self.getNodeData(recorinfosumsg[0],"ACCOUNTNUM"))
  525. briefInfoDf_recoveryInfoSum.loc[recoveryInfoSumIndex, '资产处置业务余额'] = utils.replaceAmt(self.getNodeData(recorinfosumsg[0],"BALANCE"))
  526. briefInfoDf_recoveryInfoSum.loc[recoveryInfoSumIndex, '垫款业务账户数'] = utils.toInt(self.getNodeData(recorinfosumsg[1],"ACCOUNTNUM"))
  527. briefInfoDf_recoveryInfoSum.loc[recoveryInfoSumIndex, '垫款业务余额'] = utils.replaceAmt(self.getNodeData(recorinfosumsg[1],"BALANCE"))
  528. briefInfoDf_recoveryInfoSum.loc[recoveryInfoSumIndex, '合计总账户数'] = utils.toInt(self.getNodeData(recoveredinfosumsmry[0],"ACCOUNTNUMSUM"))
  529. briefInfoDf_recoveryInfoSum.loc[recoveryInfoSumIndex, '合计总余额'] = utils.replaceAmt(self.getNodeData(recoveredinfosumsmry[0],"BALANCESUM"))
  530. # print(briefInfoDf_recoveryInfoSum.to_json(orient="index", force_ascii=False))
  531. # 解析呆账信息汇总
  532. def parseBadDebtsInfoSumDf(self,docXml):
  533. baddebtssmry = docXml.documentElement.getElementsByTagName("BADDEBTSSMRY");
  534. if len(baddebtssmry)>0:
  535. briefInfoDf_badDebtsInfoSum.loc[badDebtsInfoIndex, '账户数'] = utils.toInt(self.getNodeData(baddebtssmry[0],"ACCOUNTNUM"))
  536. briefInfoDf_badDebtsInfoSum.loc[badDebtsInfoIndex, '余额'] = utils.replaceAmt(self.getNodeData(baddebtssmry[0],"BALANCE"));
  537. # print(briefInfoDf_badDebtsInfoSum.to_json(orient="index", force_ascii=False))
  538. #透支及逾期信息汇总
  539. def parseOverdueInfoSum(self,docXml):
  540. overdraftsumsg = docXml.documentElement.getElementsByTagName("OVERDRAFTSUMSG");
  541. df = pd.DataFrame()
  542. if len(overdraftsumsg)>0:
  543. for i in range(0, len(overdraftsumsg)):
  544. df.loc[i, 0] = self.getNodeData(overdraftsumsg[i], "ACCTYPEDESC")
  545. df.loc[i, 1] = self.getNodeData(overdraftsumsg[i], "ACCSUM")
  546. df.loc[i, 2] = self.getNodeData(overdraftsumsg[i], "MONTHSUM")
  547. df.loc[i, 3] = self.getNodeData(overdraftsumsg[i], "OVERDRAFTMAX")
  548. df.loc[i, 4] = self.getNodeData(overdraftsumsg[i], "OVERMONTH")
  549. if len(overdraftsumsg)>0:
  550. briefInfoDf_overdueInfoSum.loc[overdueInfoSumIndex, '非循环贷帐户账户数'] = utils.toInt(self.getNodeData(overdraftsumsg[0],"ACCSUM"));
  551. briefInfoDf_overdueInfoSum.loc[overdueInfoSumIndex, '非循环贷帐户月份数'] = utils.toInt(self.getNodeData(overdraftsumsg[0],"MONTHSUM"));
  552. briefInfoDf_overdueInfoSum.loc[overdueInfoSumIndex, '非循环贷帐户单月最高逾期总额'] = utils.replaceAmt(self.getNodeData(overdraftsumsg[0],"OVERDRAFTMAX"));
  553. briefInfoDf_overdueInfoSum.loc[overdueInfoSumIndex, '非循环贷帐户最长逾期月数'] = utils.toInt(self.getNodeData(overdraftsumsg[0],"OVERMONTH"));
  554. briefInfoDf_overdueInfoSum.loc[overdueInfoSumIndex, '循环额度下分账户账户数'] = utils.toInt(self.getNodeData(overdraftsumsg[1],"ACCSUM"));
  555. briefInfoDf_overdueInfoSum.loc[overdueInfoSumIndex, '循环额度下分账户月份数'] = utils.toInt(self.getNodeData(overdraftsumsg[1],"MONTHSUM"));
  556. briefInfoDf_overdueInfoSum.loc[overdueInfoSumIndex, '循环额度下分账户单月最高逾期总额'] = utils.replaceAmt(self.getNodeData(overdraftsumsg[1],"OVERDRAFTMAX"));
  557. briefInfoDf_overdueInfoSum.loc[overdueInfoSumIndex, '循环额度下分账户最长逾期月数'] = utils.toInt(self.getNodeData(overdraftsumsg[1],"OVERMONTH"));
  558. briefInfoDf_overdueInfoSum.loc[overdueInfoSumIndex, '循环贷账户账户数'] = utils.toInt(self.getNodeData(overdraftsumsg[2],"ACCSUM"));
  559. briefInfoDf_overdueInfoSum.loc[overdueInfoSumIndex, '循环贷账户月份数'] = utils.toInt(self.getNodeData(overdraftsumsg[2],"MONTHSUM"));
  560. briefInfoDf_overdueInfoSum.loc[overdueInfoSumIndex, '循环贷账户单月最高逾期总额'] = utils.replaceAmt(self.getNodeData(overdraftsumsg[2],"OVERDRAFTMAX"));
  561. briefInfoDf_overdueInfoSum.loc[overdueInfoSumIndex, '循环贷账户最长逾期月数'] = utils.toInt(self.getNodeData(overdraftsumsg[2],"OVERMONTH"));
  562. briefInfoDf_overdueInfoSum.loc[overdueInfoSumIndex, '贷记卡账户账户数'] = utils.toInt(self.getNodeData(overdraftsumsg[3],"ACCSUM"));
  563. briefInfoDf_overdueInfoSum.loc[overdueInfoSumIndex, '贷记卡账户月份数'] = utils.toInt(self.getNodeData(overdraftsumsg[3],"MONTHSUM"));
  564. briefInfoDf_overdueInfoSum.loc[overdueInfoSumIndex, '贷记卡账户单月逾期总额'] = utils.replaceAmt(self.getNodeData(overdraftsumsg[3],"OVERDRAFTMAX"));
  565. briefInfoDf_overdueInfoSum.loc[overdueInfoSumIndex, '贷记卡账户最长逾期月数'] = utils.toInt(self.getNodeData(overdraftsumsg[3],"OVERMONTH"));
  566. briefInfoDf_overdueInfoSum.loc[overdueInfoSumIndex, '准贷记卡账户账户数'] = utils.toInt(self.getNodeData(overdraftsumsg[4],"ACCSUM"));
  567. briefInfoDf_overdueInfoSum.loc[overdueInfoSumIndex, '准贷记卡账户月份数'] = utils.toInt(self.getNodeData(overdraftsumsg[4],"MONTHSUM"));
  568. briefInfoDf_overdueInfoSum.loc[overdueInfoSumIndex, '准贷记卡账户单月透支总额'] = utils.replaceAmt(self.getNodeData(overdraftsumsg[4],"OVERDRAFTMAX"));
  569. briefInfoDf_overdueInfoSum.loc[overdueInfoSumIndex, '准贷记卡账户最长透支月数'] = utils.toInt(self.getNodeData(overdraftsumsg[4],"OVERMONTH"));
  570. overdueInfoAccountDf = df[df[1] != ''];
  571. briefInfoDf_overdueInfoSum.loc[overdueInfoSumIndex, '该用户所有逾期账户最长逾期/透支月数最大值'] = np.max(overdueInfoAccountDf[4].astype('int'))
  572. briefInfoDf_overdueInfoSum.loc[overdueInfoSumIndex, '该用户所有逾期账户数加总'] = np.sum(overdueInfoAccountDf[1].astype('int')) # TODO
  573. # briefInfoDf_overdueInfoSum.loc[overdueInfoSumIndex, '该用户过去5年出现逾期的所有账户数目']=None# TODO
  574. # print(briefInfoDf_overdueInfoSum.to_json(orient="index", force_ascii=False))
  575. # 非循环贷账户信息汇总
  576. def parseLoanAccountInfoSum(self,docXml):
  577. noncyclicalsmry = docXml.documentElement.getElementsByTagName("NONCYCLICALSMRY");
  578. if len(noncyclicalsmry)>0:
  579. # loanAccountInfoSumDf = doFilterCalc(loanAccountInfoSumDf); # 替换为0
  580. #TODO 需要检查是否都有值
  581. # loanAccountInfoSumDf = loanAccountInfoSumDf.reset_index(drop=True)
  582. # row0 = loanAccountInfoSumDf.loc[0, :]
  583. briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '非循环贷账户管理机构数'] = int(self.getNodeData(noncyclicalsmry[0],"MANAGEORGNUM"))
  584. briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '非循环贷账户账户数'] = int(self.getNodeData(noncyclicalsmry[0],"ACCSUM"))
  585. briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '非循环贷账户授信总额'] = utils.replaceAmt(self.getNodeData(noncyclicalsmry[0],"CREDITSUM"))
  586. briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '非循环贷账户余额'] = utils.replaceAmt(self.getNodeData(noncyclicalsmry[0],"BALANCE"))
  587. briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '非循环贷账户6月平均应还款'] = utils.replaceAmt(self.getNodeData(noncyclicalsmry[0],"LATELY6MON"))
  588. # print(briefInfoDf_loanTradeCreditInfo.to_json(orient="index", force_ascii=False))
  589. # 循环额度下分账户
  590. def parseCycleCreditAccountInfoSum(self,docXml):
  591. cybranchaccsmry = docXml.documentElement.getElementsByTagName("CYBRANCHACCSMRY");
  592. if len(cybranchaccsmry) > 0:
  593. briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '循环额度下分账户管理机构数'] = int(self.getNodeData(cybranchaccsmry[0],"MANAGEORGNUM"))
  594. briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '循环额度下分账户账户数'] = int(self.getNodeData(cybranchaccsmry[0],"ACCSUM"))
  595. briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '循环额度下分账户授信总额'] = utils.replaceAmt(self.getNodeData(cybranchaccsmry[0],"CREDITSUM"))
  596. briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '循环额度下分账户余额'] = utils.replaceAmt(self.getNodeData(cybranchaccsmry[0],"BALANCE"))
  597. briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '循环额度下分账户6月平均应还款'] = utils.replaceAmt(self.getNodeData(cybranchaccsmry[0],"LATELY6MON"))
  598. # print(briefInfoDf_loanTradeCreditInfo.to_json(orient="index", force_ascii=False))
  599. # 循环贷账户信息
  600. def parseCyleLoanAccountInfoSum(self,docXml):
  601. cyclicalloansmry = docXml.documentElement.getElementsByTagName("CYCLICALLOANSMRY");
  602. if len(cyclicalloansmry) > 0:
  603. briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '循环贷账户管理机构数'] = int(self.getNodeData(cyclicalloansmry[0],"MANAGEORGNUM"))
  604. briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '循环贷账户账户数'] = int(self.getNodeData(cyclicalloansmry[0],"ACCSUM"))
  605. briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '循环贷账户授信总额'] = utils.replaceAmt(self.getNodeData(cyclicalloansmry[0],"CREDITSUM"))
  606. briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '循环贷账户余额'] = utils.replaceAmt(self.getNodeData(cyclicalloansmry[0],"BALANCE"))
  607. briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '循环贷账户6月平均应还款'] = utils.replaceAmt(self.getNodeData(cyclicalloansmry[0],"LATELY6MON"))
  608. # 解析贷记卡信息汇总,包含准贷记卡
  609. def parseCreditCardInfoSum(self,docXml):
  610. debitcardaccsmry = docXml.documentElement.getElementsByTagName("DEBITCARDACCSMRY");
  611. if len(debitcardaccsmry) > 0:
  612. briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '贷记卡发卡机构数'] = int(self.getNodeData(debitcardaccsmry[0],"CARDISSUERNUM"))
  613. briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '贷记卡账户数'] =int(self.getNodeData(debitcardaccsmry[0],"ACCSUM"))
  614. briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '贷记卡授信总额'] = utils.replaceAmt(self.getNodeData(debitcardaccsmry[0],"CREDITSUM"))
  615. briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '贷记卡单家机构最高授信额'] = utils.replaceAmt(self.getNodeData(debitcardaccsmry[0],"CRAMOUNTMAX"))
  616. briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '贷记卡单家机构最低授信额'] =utils.replaceAmt(self.getNodeData(debitcardaccsmry[0],"CRAMOUNTMIN"))
  617. briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '贷记卡已用额度'] = utils.replaceAmt(self.getNodeData(debitcardaccsmry[0],"ALREADYUSED"))
  618. briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '贷记卡最近6个月平均使用额度'] = utils.replaceAmt(self.getNodeData(debitcardaccsmry[0],"LATELY6MONUSE"))
  619. # 解析贷记卡信息汇总,包含准贷记卡
  620. def parseCreditCardInfoSumZ(self,docXml):
  621. zdebitcardaccsmry = docXml.documentElement.getElementsByTagName("ZDEBITCARDACCSMRY");
  622. if len(zdebitcardaccsmry) > 0:
  623. briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '准贷记卡发卡机构数'] = int(self.getNodeData(zdebitcardaccsmry[0],"CARDISSUERNUM"))
  624. briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '准贷记卡账户数'] =int(self.getNodeData(zdebitcardaccsmry[0],"ACCSUM"))
  625. briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '准贷记卡授信总额'] = utils.replaceAmt(self.getNodeData(zdebitcardaccsmry[0],"CREDITSUM"))
  626. briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '准贷记卡单家机构最高授信额'] = utils.replaceAmt(self.getNodeData(zdebitcardaccsmry[0],"CRAMOUNTMAX"))
  627. briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '准贷记卡单家机构最低授信额'] = utils.replaceAmt(self.getNodeData(zdebitcardaccsmry[0],"CRAMOUNTMIN"))
  628. briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '准贷记卡已用额度'] = utils.replaceAmt(self.getNodeData(zdebitcardaccsmry[0],"OVERDRAFT"))
  629. briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '准贷记卡最近6个月平均使用额度'] = utils.replaceAmt(self.getNodeData(zdebitcardaccsmry[0],"LATELY6MONDRAFT"))
  630. # 相关还款责任
  631. def parseRepaymentSum(self,docXml):
  632. repaymentinfosmry = docXml.documentElement.getElementsByTagName("REPAYMENTINFOSMRY");
  633. if len(repaymentinfosmry)>0:
  634. perAccountNum = 0; # 个人账户数
  635. orgAccountNum = 0; # 企业账户数
  636. totalAccountNum = 0; # 总账户数
  637. guaranteeAccountNum = 0; # 相关还款责任总账户数-担保责任
  638. otherAccountNum = 0; # 相关还款责任总账户数-其他
  639. perGuaranteeAmt = 0 # 个人担保金额及其他
  640. orgGuaranteeAmt = 0 # 企业担保金额及其他
  641. totalGuaranteeAmt = 0; # 总担保金额
  642. guaranteeAmt = 0; # 相关还款责任总担保金额
  643. otherPaymentAmt = 0; # 其他还款责任金额
  644. perGuaranteeBalance = 0 # 个人担保余额及其他
  645. orgGuaranteeBalance = 0 # 企业担保余额及其他
  646. totalGuaranteeBalance = 0; # 总担保余额
  647. guaranteeBalance = 0; # 相关还款责任总担保余额
  648. otherPaymentBalance = 0; # 其他还款责任余额
  649. perGuaranteeNum = self.getNodeData(repaymentinfosmry[0],"ACCSUM")
  650. perGuaranteeAmtStr = self.getNodeData(repaymentinfosmry[0], "RELPAYRESPSUM")
  651. perGuaranteeBalanceStr = self.getNodeData(repaymentinfosmry[0], "BALANCE")
  652. perOtherNum = self.getNodeData(repaymentinfosmry[1], "ACCSUM")
  653. perOtherAmt = self.getNodeData(repaymentinfosmry[1], "RELPAYRESPSUM")
  654. perOtherBalance = self.getNodeData(repaymentinfosmry[1], "BALANCE")
  655. enGuaranteeNum = ""
  656. enGuaranteeAmt = ""
  657. enGuaranBalance = ""
  658. enOtherNum = ""
  659. enOtherAmt = ""
  660. enOtherBalance= ""
  661. if len(repaymentinfosmry)>=3:
  662. enGuaranteeNum = self.getNodeData(repaymentinfosmry[2], "ACCSUM")
  663. enGuaranteeAmt = self.getNodeData(repaymentinfosmry[2], "RELPAYRESPSUM")
  664. enGuaranBalance = self.getNodeData(repaymentinfosmry[2], "BALANCE")
  665. if len(repaymentinfosmry) >= 4:
  666. enOtherNum = self.getNodeData(repaymentinfosmry[3], "ACCSUM")
  667. enOtherAmt = self.getNodeData(repaymentinfosmry[3], "RELPAYRESPSUM")
  668. enOtherBalance = self.getNodeData(repaymentinfosmry[3], "BALANCE")
  669. # 计算总账户数
  670. if perGuaranteeNum != "":
  671. perAccountNum = perAccountNum + utils.toInt(perGuaranteeNum)
  672. guaranteeAccountNum = guaranteeAccountNum + utils.toInt(perGuaranteeNum) # 个人担保责任账户数
  673. if perOtherNum != "":
  674. perAccountNum = perAccountNum + utils.toInt(perOtherNum) # 其他
  675. otherAccountNum = otherAccountNum + utils.toInt(perOtherNum) # 其他
  676. if enGuaranteeNum != None:
  677. if enGuaranteeNum != "":
  678. orgAccountNum = orgAccountNum + utils.toInt(enGuaranteeNum)
  679. guaranteeAccountNum = guaranteeAccountNum + utils.toInt(enGuaranteeNum) # 企业担保责任账户数
  680. if enOtherNum != "":
  681. orgAccountNum = orgAccountNum + utils.toInt(enOtherNum) # 其他
  682. otherAccountNum = otherAccountNum + utils.toInt(enOtherNum) # 其他
  683. totalAccountNum = perAccountNum + orgAccountNum
  684. # 计算担保金额
  685. if perGuaranteeAmtStr != "":
  686. perGuaranteeAmt = perGuaranteeAmt + utils.replaceAmt(perGuaranteeAmtStr) # 担保
  687. guaranteeAmt = guaranteeAmt + utils.replaceAmt(perGuaranteeAmtStr) # 担保
  688. if perOtherAmt != "":
  689. perGuaranteeAmt = perGuaranteeAmt + utils.replaceAmt(perOtherAmt) # 其他
  690. otherPaymentAmt = otherPaymentAmt + utils.replaceAmt(perOtherAmt) # 其他
  691. if enGuaranteeAmt != None:
  692. if enGuaranteeAmt != "":
  693. orgGuaranteeAmt = orgGuaranteeAmt + utils.replaceAmt(enGuaranteeAmt) # 担保
  694. guaranteeAmt = guaranteeAmt + utils.replaceAmt(enGuaranteeAmt) # 担保
  695. if enOtherAmt != "":
  696. orgGuaranteeAmt = orgGuaranteeAmt + utils.replaceAmt(enOtherAmt) # 其他
  697. otherPaymentAmt = otherPaymentAmt + utils.replaceAmt(enOtherAmt) # 其他
  698. totalGuaranteeAmt = perGuaranteeAmt + orgGuaranteeAmt
  699. # 计算余额
  700. if perGuaranteeBalanceStr != "":
  701. perGuaranteeBalance = perGuaranteeBalance + utils.replaceAmt(perGuaranteeBalanceStr)
  702. guaranteeBalance = guaranteeBalance + utils.replaceAmt(perGuaranteeBalanceStr) # 个人担保余额
  703. if perOtherBalance != "":
  704. perGuaranteeBalance = perGuaranteeBalance + utils.replaceAmt(perOtherBalance) # 其他
  705. otherPaymentBalance = otherPaymentBalance + utils.replaceAmt(perOtherBalance) # 其他
  706. if enGuaranBalance != None:
  707. if enGuaranBalance != "":
  708. orgGuaranteeBalance = orgGuaranteeBalance + utils.replaceAmt(enGuaranBalance)
  709. guaranteeBalance = guaranteeBalance + utils.replaceAmt(enGuaranBalance) # 企业担保余额
  710. if enOtherBalance != "":
  711. orgGuaranteeBalance = orgGuaranteeBalance + utils.replaceAmt(enOtherBalance)
  712. otherPaymentBalance = otherPaymentBalance + utils.replaceAmt(enOtherBalance) # 其他
  713. totalGuaranteeBalance = perGuaranteeBalance + orgGuaranteeBalance
  714. briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '相关还款责任总账户数(担保+其他+个人+企业)'] = totalAccountNum
  715. briefInfoDf_loanTradeCreditInfo.loc[
  716. loanTradeCreditInfoIndex, '相关还款责任总担保金额+总还款责任金额(个人+企业)'] = totalGuaranteeAmt
  717. briefInfoDf_loanTradeCreditInfo.loc[
  718. loanTradeCreditInfoIndex, '相关还款责任账户总担保余额+总其他余额(个人+企业)'] = totalGuaranteeBalance
  719. if totalGuaranteeAmt != 0:
  720. briefInfoDf_loanTradeCreditInfo.loc[
  721. loanTradeCreditInfoIndex, '相关还款责任账户总担保余额+总其他余额(个人+企业)/相关还款责任账户总担保金额+总其他金额(个人+企业)'] = \
  722. round(totalGuaranteeBalance / totalGuaranteeAmt, 2)
  723. briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '相关还款责任担保总账户数-个人'] = perAccountNum
  724. briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '相关还款责任总担保金额-个人'] = perGuaranteeAmt
  725. briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '相关还款责任总担保余额-个人'] = perGuaranteeBalance
  726. if perGuaranteeBalance != 0:
  727. briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '相关还款责任总担保余额-个人/相关还款责任总担保金额-个人'] = round(
  728. perGuaranteeBalance / perGuaranteeBalance, 2)
  729. briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '相关还款责任总账户数-企业'] = orgAccountNum
  730. briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '相关还款责任总担保金额-企业'] = orgGuaranteeAmt
  731. briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '相关还款责任总担保余额-企业'] = orgGuaranteeBalance
  732. if orgGuaranteeAmt != 0:
  733. briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '相关还款责任总担保余额-企业/相关还款责任总担保金额-企业'] = round(
  734. orgGuaranteeBalance / orgGuaranteeAmt, 2)
  735. briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '相关还款责任总账户数-担保责任'] = guaranteeAccountNum
  736. briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '相关还款责任总担保金额-担保责任'] = guaranteeAmt
  737. briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '相关还款责任账户总担保余额-担保责任'] = guaranteeBalance
  738. if guaranteeAmt != 0:
  739. briefInfoDf_loanTradeCreditInfo.loc[
  740. loanTradeCreditInfoIndex, '相关还款责任总担保余额-担保责任/相关还款责任总担保金额-担保责任'] = round(
  741. guaranteeBalance / guaranteeAmt, 2)
  742. briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '相关还款责任总账户数-其他'] = otherAccountNum
  743. briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '相关还款责任总担保金额-其他'] = otherPaymentAmt
  744. briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '相关还款责任总担保余额-其他'] = otherPaymentBalance
  745. if otherPaymentAmt != 0:
  746. briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '相关还款责任账户总担保余额-其他/相关还款责任账户总担保金额-其他'] = round(otherPaymentBalance / otherPaymentAmt, 2)
  747. # print(briefInfoDf_loanTradeCreditInfo.to_json(orient="index", force_ascii=False))
  748. #解析公共信息汇总
  749. def parsePublicInfoBrief(self,docXml):
  750. comminfosmry = docXml.documentElement.getElementsByTagName("COMMINFOSMRY")
  751. if len(comminfosmry)>0:
  752. publicInfoBriefDf.loc[publicInfoBriefIndex, '欠税信息-记录数'] = utils.toInt(self.getNodeData(comminfosmry[0],"RECORDNUM"))
  753. publicInfoBriefDf.loc[publicInfoBriefIndex, '欠税信息-涉及金额'] = utils.replaceAmt(self.getNodeData(comminfosmry[0],"INVOLVEMONEY"))
  754. publicInfoBriefDf.loc[publicInfoBriefIndex, '民事判决信息-记录数'] = utils.toInt(self.getNodeData(comminfosmry[1],"RECORDNUM"))
  755. publicInfoBriefDf.loc[publicInfoBriefIndex, '民事判决信息-涉及金额'] = utils.replaceAmt(self.getNodeData(comminfosmry[1],"INVOLVEMONEY"))
  756. publicInfoBriefDf.loc[publicInfoBriefIndex, '强制执行信息-记录数'] = utils.toInt(self.getNodeData(comminfosmry[2],"RECORDNUM"))
  757. publicInfoBriefDf.loc[publicInfoBriefIndex, '强制执行信息-涉及金额'] = utils.replaceAmt(self.getNodeData(comminfosmry[2],"INVOLVEMONEY"))
  758. publicInfoBriefDf.loc[publicInfoBriefIndex, '行政处罚信息-记录数'] = utils.toInt(self.getNodeData(comminfosmry[3],"RECORDNUM"))
  759. publicInfoBriefDf.loc[publicInfoBriefIndex, '行政处罚信息-涉及金额'] = utils.replaceAmt(self.getNodeData(comminfosmry[3],"INVOLVEMONEY"))
  760. # 解析查询信息汇总
  761. def parseQueryRecordSum(self,docXml):
  762. queryrecordsumsg = docXml.documentElement.getElementsByTagName("QUERYRECORDSUMSG")
  763. if len(queryrecordsumsg) > 0:
  764. queryRecordSumDf.loc[queryRecordSumIndex, '近1月内的查询机构数-贷款审批'] = int(self.getNodeData(queryrecordsumsg[0],"LAST1ORGSP"))
  765. queryRecordSumDf.loc[queryRecordSumIndex, '近1月内的查询机构数-信用卡审批'] = int(self.getNodeData(queryrecordsumsg[0],"LAST1CREDITSP"))
  766. queryRecordSumDf.loc[queryRecordSumIndex, '近1月内的查询次数-贷款审批'] = int(self.getNodeData(queryrecordsumsg[0],"NUMSP"))
  767. queryRecordSumDf.loc[queryRecordSumIndex, '近1月内的查询次数-信用卡审批'] = int(self.getNodeData(queryrecordsumsg[0],"NUMCREDITSP"))
  768. queryRecordSumDf.loc[queryRecordSumIndex, '近1月内的查询次数-本人查询'] = int(self.getNodeData(queryrecordsumsg[0],"LAST1NUMSELF"))
  769. queryRecordSumDf.loc[queryRecordSumIndex, '近2年内的查询次数-贷后管理'] = int(self.getNodeData(queryrecordsumsg[0],"L2YNUMDH"))
  770. queryRecordSumDf.loc[queryRecordSumIndex, '近2年内的查询次数-担保资格审查'] = int(self.getNodeData(queryrecordsumsg[0],"L2YNUMDBZG"))
  771. # print(queryRecordSumDf.to_json(orient="index", force_ascii=False))
  772. # 解析查询记录明细
  773. def parseQueryInfoDetail(self,reportTime,docXml):
  774. queryRecordsg = docXml.documentElement.getElementsByTagName("QUERYRECORDSG");
  775. if len(queryRecordsg)>0:
  776. df = pd.DataFrame()
  777. for i in range(0, len(queryRecordsg)):
  778. df.loc[i, 1] = self.getNodeData(queryRecordsg[i], "QUERYDATE")
  779. df.loc[i, 2] = self.getNodeData(queryRecordsg[i], "QUERYORG")
  780. queryReson = self.getNodeData(queryRecordsg[i], "QUERYREASONDESC")
  781. df.loc[i, 3] = queryReson
  782. queryRecordDetailDf.loc[queryRecordDetailIndex, '近1月查询次数'] =qip.getLastMonthQueryTimes(df, 1, "",reportTime)
  783. queryRecordDetailDf.loc[queryRecordDetailIndex, '近3月查询次数'] =qip.getLastMonthQueryTimes(df, 3, "",reportTime)
  784. queryRecordDetailDf.loc[queryRecordDetailIndex, '近6月查询次数'] =qip.getLastMonthQueryTimes(df, 6, "",reportTime)
  785. queryRecordDetailDf.loc[queryRecordDetailIndex, '近12月查询次数'] =qip.getLastMonthQueryTimes(df, 12, "",reportTime)
  786. queryRecordDetailDf.loc[queryRecordDetailIndex, '最近1个月查询机构数'] =qip.getLastMonthQueryOrgTimes(df, 1, "", reportTime)
  787. queryRecordDetailDf.loc[queryRecordDetailIndex, '最近3个月查询机构数'] =qip.getLastMonthQueryOrgTimes(df, 3, "", reportTime)
  788. queryRecordDetailDf.loc[queryRecordDetailIndex, '最近6个月查询机构数'] =qip.getLastMonthQueryOrgTimes(df, 6, "", reportTime)
  789. queryRecordDetailDf.loc[queryRecordDetailIndex, '最近12个月查询机构数'] =qip.getLastMonthQueryOrgTimes(df, 12, "", reportTime)
  790. queryRecordDetailDf.loc[queryRecordDetailIndex, '最近24个月查询机构数'] =qip.getLastMonthQueryOrgTimes(df, 24, "", reportTime)
  791. queryRecordDetailDf.loc[queryRecordDetailIndex, '近3月查询次数贷款审批'] =qip.getLastMonthQueryTimes(df, 3, consts.loanApprove, reportTime)
  792. queryRecordDetailDf.loc[queryRecordDetailIndex, '近3月查询次数信用卡审批'] =qip.getLastMonthQueryTimes(df, 3, consts.creditCard, reportTime)
  793. queryRecordDetailDf.loc[queryRecordDetailIndex, '近6月查询次数贷款审批'] =qip.getLastMonthQueryTimes(df, 6, consts.loanApprove, reportTime)
  794. queryRecordDetailDf.loc[queryRecordDetailIndex, '近6月查询次数信用卡审批'] = qip.getLastMonthQueryTimes(df, 6, consts.creditCard, reportTime)
  795. queryRecordDetailDf.loc[queryRecordDetailIndex, '近12月查询次数贷款审批'] = qip.getLastMonthQueryTimes(df, 12, consts.loanApprove, reportTime)
  796. queryRecordDetailDf.loc[queryRecordDetailIndex, '近12月查询次数信用卡审批'] =qip.getLastMonthQueryTimes(df, 12, consts.creditCard, reportTime)
  797. queryRecordDetailDf.loc[queryRecordDetailIndex, '近3月查询机构数贷款审批'] =qip.getLastMonthQueryOrgTimes(df, 3, consts.loanApprove, reportTime)
  798. queryRecordDetailDf.loc[queryRecordDetailIndex, '近3月查询机构数信用卡审批'] =qip.getLastMonthQueryOrgTimes(df, 3, consts.creditCard, reportTime)
  799. queryRecordDetailDf.loc[queryRecordDetailIndex, '近6月查询机构数贷款审批'] =qip.getLastMonthQueryOrgTimes(df, 6, consts.loanApprove, reportTime)
  800. queryRecordDetailDf.loc[queryRecordDetailIndex, '近6月查询机构数信用卡审批'] = qip.getLastMonthQueryOrgTimes(df, 6, consts.creditCard,reportTime)
  801. queryRecordDetailDf.loc[queryRecordDetailIndex, '近12月查询机构数贷款审批'] = qip.getLastMonthQueryOrgTimes(df, 12, consts.loanApprove, reportTime)
  802. queryRecordDetailDf.loc[queryRecordDetailIndex, '近12月查询机构数信用卡审批'] = qip.getLastMonthQueryOrgTimes(df, 12, consts.creditCard,reportTime)
  803. queryRecordDetailDf.loc[queryRecordDetailIndex, '最近3个月担保资格审查查询次数'] = qip.getLastMonthQueryTimes(df, 3, consts.insuranceAprove,reportTime)
  804. queryRecordDetailDf.loc[queryRecordDetailIndex, '最近6个月担保资格审查查询次数'] = qip.getLastMonthQueryTimes(df, 6, consts.insuranceAprove,reportTime)
  805. queryRecordDetailDf.loc[queryRecordDetailIndex, '近12个月担保资格审查查询次数'] = qip.getLastMonthQueryTimes(df, 12, consts.insuranceAprove,reportTime)
  806. queryRecordDetailDf.loc[queryRecordDetailIndex, '最近6个月贷后管理查询次数'] = qip.getLastMonthQueryTimes(df, 6, consts.loanAfterMgr,reportTime)
  807. queryRecordDetailDf.loc[queryRecordDetailIndex, '最近12个月贷后管理查询次数'] = qip.getLastMonthQueryTimes(df, 12, consts.loanAfterMgr,reportTime)
  808. queryRecordDetailDf.loc[queryRecordDetailIndex, '最后一次查询距离现在的月数贷款审批'] = qip.getLastTimeQueryMonth(df, consts.loanApprove,reportTime)
  809. queryRecordDetailDf.loc[queryRecordDetailIndex, '最近24个月贷后管理查询次数'] = qip.getLastMonthQueryTimes(df, 24, consts.loanAfterMgr, reportTime)
  810. queryRecordDetailDf.loc[queryRecordDetailIndex, '最近24个月贷款审批审批次数'] = qip.getLastMonthQueryTimes(df, 24, consts.loanApprove, reportTime)
  811. queryRecordDetailDf.loc[queryRecordDetailIndex, '最近24个月信用卡审批查询次数'] = qip.getLastMonthQueryTimes(df, 24, consts.creditCard,reportTime)
  812. queryRecordDetailDf.loc[queryRecordDetailIndex, '最近24个月担保资格审查查询次数'] = qip.getLastMonthQueryTimes(df, 24, consts.insuranceAprove,reportTime)
  813. #三寿 100年所有信用卡审批
  814. sanshouDf.loc[sanshouIndex, '贷后管理最近3个月内的机构查询次数'] = qip.getLastMonthQueryTimes(df, 3, consts.loanAfterMgr,reportTime)
  815. sanshouDf.loc[sanshouIndex, '信用卡审批所有机构查询次数'] =qip.getLastMonthQueryTimes(df, 12*100, consts.creditCard, reportTime)
  816. sanshouDf.loc[sanshouIndex, '所有本人查询次数'] = qip.getSelfLastMonthQueryTimes(df, 12 * 100,reportTime)
  817. sanshouDf.loc[sanshouIndex, '最近1年内本人查询次数'] = qip.getSelfLastMonthQueryTimes(df, 12, reportTime)
  818. sanshouDf.loc[sanshouIndex, '最近2年内本人查询次数'] = qip.getSelfLastMonthQueryTimes(df, 24, reportTime)
  819. # print(queryRecordDetailDf.to_json(orient="index", force_ascii=False))
  820. def parseHousingFundRcd(self,reportTime,docXml):
  821. housingfund = docXml.documentElement.getElementsByTagName("HOUSINGFUND");
  822. if len(housingfund) >0 :
  823. df = pd.DataFrame()
  824. for i in range(0, len(housingfund)):
  825. df.loc[i, 0] = self.getNodeData(housingfund[i], "ADDRESSDESC")#参缴地
  826. df.loc[i, 1] = self.getNodeData(housingfund[i], "PAYDATE")#参缴日期
  827. df.loc[i, 2] = self.getNodeData(housingfund[i], "STATUSDESC")#缴费状态
  828. df.loc[i, 3] = self.getNodeData(housingfund[i], "BEGINMONTH")#初缴月份
  829. df.loc[i, 4] = self.getNodeData(housingfund[i], "ENDMONTH")#缴至月份
  830. df.loc[i, 5] = self.getNodeData(housingfund[i], "COMPROPORTION")#个人存缴比例
  831. df.loc[i, 6] = self.getNodeData(housingfund[i], "PEPROPORTION")#个人存缴比例
  832. df.loc[i, 7] = utils.replaceAmt(self.getNodeData(housingfund[i], "MONTHMONEY"))#月缴存额
  833. df.loc[i, 8] = self.getNodeData(housingfund[i], "COMPANY")#缴费单位
  834. df.loc[i, 9] = self.getNodeData(housingfund[i], "UPDATEDATE")#信息更新日期
  835. lastHousingFundRcdDf = df.sort_values(by=9, ascending=(False)).reset_index(drop=True)
  836. lastHousingFundRcdDf = lastHousingFundRcdDf[0:1] # 最新
  837. row1 = lastHousingFundRcdDf.loc[0, :].dropna().reset_index(drop=True)
  838. housingFundRcdDf.loc[housingFundRcdIndex, '参缴地'] = row1[0]
  839. housingFundRcdDf.loc[housingFundRcdIndex, '参缴日期'] = row1[1]
  840. housingFundRcdDf.loc[housingFundRcdIndex, '初缴月份'] = row1[3] # 初缴日期
  841. housingFundRcdDf.loc[housingFundRcdIndex, '缴至月份'] = row1[4]
  842. housingFundRcdDf.loc[housingFundRcdIndex, '缴费状态'] = row1[2]
  843. housingFundRcdDf.loc[housingFundRcdIndex, '月缴存额'] = row1[7]
  844. housingFundRcdDf.loc[housingFundRcdIndex, '个人存缴比例'] = row1[6]
  845. housingFundRcdDf.loc[housingFundRcdIndex, '单位存缴比例'] = row1[5]
  846. housingFundRcdDf.loc[housingFundRcdIndex, '缴费单位'] = row1[8] # 扣缴单位
  847. housingFundRcdDf.loc[housingFundRcdIndex, '信息更新日期'] = row1[9]
  848. lastDateStr = utils.getLastMonthDate(reportTime, 12)
  849. avgHousingFundDf = df[df[4] >= lastDateStr]
  850. housingFundRcdDf.loc[housingFundRcdIndex, '最近1年公积金平均值'] = round(np.mean(avgHousingFundDf[7]), 2)
  851. lastDateStr = utils.getLastMonthDate(reportTime, 12 * 3)
  852. avgHousingFundDf = df[df[4] >= lastDateStr]
  853. housingFundRcdDf.loc[housingFundRcdIndex, '最近3年公积金平均值'] = round(np.mean(avgHousingFundDf[7]), 2)
  854. # print(housingFundRcdDf.to_json(orient="index", force_ascii=False))
  855. # 合并被追偿信息
  856. def mergeRecoveryInfoDf(self, reportTime,docXml):
  857. tmpNode = docXml.documentElement.getElementsByTagName("FORCEDREPAYINFOBOLS");
  858. recoveryInfoMergeDf = pd.DataFrame(columns=dfParser.dfHeaderRecoveryInfo)#合并df
  859. if len(tmpNode)>0:
  860. forcedrepayinfobols = docXml.documentElement.getElementsByTagName("FORCEDREPAYINFOBOLS")[0]
  861. creditacctinfobo = forcedrepayinfobols.getElementsByTagName("CREDITACCTINFOBO");
  862. for i in range(0,len(creditacctinfobo)):
  863. creditbaseinfobo = creditacctinfobo[i].getElementsByTagName("CREDITBASEINFOBO")[0]
  864. newperformancebo = creditacctinfobo[i].getElementsByTagName("NEWPERFORMANCEBO")[0]
  865. # latemonthlyperformancebo = creditacctinfobo[i].getElementsByTagName("LATEMONTHLYPERFORMANCEBO")
  866. # latemonthlyperformancebo = latemonthlyperformancebo[0]
  867. specialtradebaseinfosg = creditacctinfobo[i].getElementsByTagName("SPECIALTRADEBASEINFOSG")
  868. recoveryInfoDf = pd.DataFrame(columns=dfParser.dfHeaderCreditCard, index=[0])
  869. recoveryInfoDf.loc[0, '账户编号'] = self.getNodeData(creditbaseinfobo,"ACCTNO")
  870. recoveryInfoDf.loc[0, '管理机构'] = self.getNodeData(creditbaseinfobo,"BUSIORGCODE")
  871. recoveryInfoDf.loc[0, '业务种类'] = self.getNodeData(creditbaseinfobo,"LOANTYPEDESC")
  872. recoveryInfoDf.loc[0, '债权接收日期'] = self.getNodeData(creditbaseinfobo,"OPENDATE")
  873. recoveryInfoDf.loc[0, '债权金额'] = utils.replaceAmt(self.getNodeData(creditbaseinfobo,"LOANAMT"))
  874. recoveryInfoDf.loc[0, '债权转移时的还款状态'] = self.getNodeData(creditbaseinfobo,"RPYACCOUNTSTATUSDESC")
  875. recoveryInfoDf.loc[0, '账户状态'] = self.getNodeData(newperformancebo,"ACCTSTATUSDESC")
  876. accountStatus = self.getNodeData(newperformancebo,"ACCTSTATUSDESC")# 账户状态
  877. # if accountStatus == "":
  878. # accountStatus = self.getNodeData(latemonthlyperformancebo, "ACCTSTATUDESC")
  879. if len(specialtradebaseinfosg)>0:
  880. recoveryInfoDf.loc[0, '特殊交易类型'] = self.getNodeData(specialtradebaseinfosg[0],"TRANTYPEDESC")
  881. recoveryInfoDf.loc[0, '发生日期'] = self.getNodeData(specialtradebaseinfosg[0],"TRANDATE")
  882. recoveryInfoDf.loc[0, '变更月份'] = utils.toInt(self.getNodeData(specialtradebaseinfosg[0],"TRANMONTH"))
  883. recoveryInfoDf.loc[0, '发生金额'] = utils.replaceAmt(self.getNodeData(specialtradebaseinfosg[0],"TRANAMT"))
  884. recoveryInfoDf.loc[0, '明细记录'] = self.getNodeData(specialtradebaseinfosg[0],"DETRECORD")
  885. if accountStatus == "催收":
  886. recoveryInfoDf.loc[0, '余额'] = utils.replaceAmt(self.getNodeData(newperformancebo,"BALANCE"))
  887. recoveryInfoDf.loc[0, '最近一次还款日期'] =self.getNodeData(newperformancebo, "REPAYDATE");
  888. else:
  889. recoveryInfoDf.loc[0, '账户关闭日期'] = self.getNodeData(newperformancebo,"SETTLEDATE")
  890. # recoveryInfoDf.loc[0, '截至日期'] = self.getNodeData(newperformancebo,"DUEDATE")
  891. recoveryInfoMergeDf = pd.concat([recoveryInfoMergeDf, recoveryInfoDf], axis=0,ignore_index=True);
  892. return recoveryInfoMergeDf
  893. # 合并贷款记录dataframe为宽表
  894. def mergeLoanDf(self, reportTime,docXml,type):
  895. tmpNode = docXml.documentElement.getElementsByTagName(type)
  896. loanAccountDfs = []
  897. if len(tmpNode)>0:
  898. noloopcreditaccountbols = docXml.documentElement.getElementsByTagName(type)[0]
  899. creditacctinfobo = noloopcreditaccountbols.getElementsByTagName("CREDITACCTINFOBO");
  900. for i in range(0, len(creditacctinfobo)):
  901. dfObj = {}
  902. loanDf = pd.DataFrame(columns=dfParser.dfHeaderLoan, index=[0])
  903. loanDfObj = loanDf.to_json(orient="index",force_ascii=False)
  904. loanDfObj = json.loads(loanDfObj)['0']
  905. creditbaseinfobo = creditacctinfobo[i].getElementsByTagName("CREDITBASEINFOBO")[0]
  906. newperformancebo = creditacctinfobo[i].getElementsByTagName("NEWPERFORMANCEBO")[0]
  907. latemonthlyperformancebo = creditacctinfobo[i].getElementsByTagName("LATEMONTHLYPERFORMANCEBO")
  908. latemonthlyperformancebo = latemonthlyperformancebo[0]
  909. specialtradebaseinfosg = creditacctinfobo[i].getElementsByTagName("SPECIALTRADEBASEINFOSG")
  910. fiveyearhisrpyinfols = creditacctinfobo[i].getElementsByTagName("FIVEYEARHISRPYINFOSG")
  911. loanDfObj['账户编号'] = self.getNodeData(creditbaseinfobo, "ACCTNO")
  912. loanDfObj['管理机构'] = self.getNodeData(creditbaseinfobo, "BUSIORGCODE")
  913. loanDfObj['账户标识'] = self.getNodeData(creditbaseinfobo, "ACCTCODE")
  914. loanDfObj['开立日期'] = self.getNodeData(creditbaseinfobo, "OPENDATE")
  915. loanDfObj['到期日期'] = self.getNodeData(creditbaseinfobo, "DUEDATE")
  916. if type=='LOOPCREDITACCOUNTBOLS':#循环贷款账户
  917. loanDfObj['借款金额(本金)'] = utils.replaceAmt(self.getNodeData(creditbaseinfobo, "ACCTCREDLINE"))
  918. else:
  919. loanDfObj['借款金额(本金)'] = utils.replaceAmt(self.getNodeData(creditbaseinfobo, "LOANAMT"))
  920. loanDfObj['账户币种'] = self.getNodeData(creditbaseinfobo, "MONEYTYPEDESC")
  921. loanDfObj['业务种类'] = self.getNodeData(creditbaseinfobo, "LOANTYPEDESC")
  922. loanDfObj['担保方式'] = self.getNodeData(creditbaseinfobo, "GUARMODEDESC")
  923. loanDfObj['还款期数'] = utils.toInt(self.getNodeData(creditbaseinfobo, "REPAYPRD"))
  924. loanDfObj['还款频率'] = self.getNodeData(creditbaseinfobo, "REPAYFREQCYDESC")
  925. loanDfObj['还款方式'] = self.getNodeData(creditbaseinfobo, "REPAYDESC")
  926. loanDfObj['共同借款标志'] = self.getNodeData(creditbaseinfobo, "COMMBORROWERMAKERDESC")
  927. # loanDfObj['截至日期'] = formatDateJz(df4[0]);
  928. accountStatus = self.getNodeData(latemonthlyperformancebo, "ACCTSTATUDESC")
  929. if accountStatus == "":
  930. accountStatus = self.getNodeData(newperformancebo,"ACCTSTATUSDESC")
  931. loanDfObj['账户状态'] = accountStatus;
  932. if accountStatus != "结清" and accountStatus != "呆账" and accountStatus != "转出":
  933. loanDfObj['五级分类'] = self.getNodeData(latemonthlyperformancebo, "FIVECATEDESC");
  934. loanDfObj['余额(本金)'] = utils.replaceAmt(self.getNodeData(latemonthlyperformancebo, "BUSIBAL"))
  935. loanDfObj['剩余还款期数'] = utils.toInt(self.getNodeData(latemonthlyperformancebo, "REMREPPRD"))
  936. loanDfObj['本月应还款'] = utils.replaceAmt(self.getNodeData(latemonthlyperformancebo, "CURRPYAMT"))
  937. loanDfObj['应还款日'] = self.getNodeData(latemonthlyperformancebo, "SETTDATE");
  938. loanDfObj['本月实还款'] = utils.replaceAmt(self.getNodeData(latemonthlyperformancebo, "ACTRPYAMT"))
  939. loanDfObj['最近一次还款日期'] = self.getNodeData(latemonthlyperformancebo, "LATRPYDATE");
  940. loanDfObj['当前逾期期数'] = utils.toInt(self.getNodeData(latemonthlyperformancebo, "OVERDPRD"))
  941. loanDfObj['当前逾期总额'] = utils.replaceAmt(self.getNodeData(latemonthlyperformancebo, "TOTOVERD"))
  942. loanDfObj['逾期31-60天未还本金'] = utils.replaceAmt(self.getNodeData(latemonthlyperformancebo, "OVERD3160PRINC"))
  943. loanDfObj['逾期61-90天未还本金'] = utils.replaceAmt(self.getNodeData(latemonthlyperformancebo, "OVERD6190PRINC"))
  944. loanDfObj['逾期91-180天未还本金'] = utils.replaceAmt(self.getNodeData(latemonthlyperformancebo, "OVERD91180PRINC"))
  945. loanDfObj['逾期180天以上未还本金'] = utils.replaceAmt(self.getNodeData(latemonthlyperformancebo, "OVERDPRINCOVE180"))
  946. # loanDfObj['截至日期月份'] = utils.difMonthReportTime(formatDateJz(df4[0]), reportTime); # 截止日期离报告时间月份
  947. elif accountStatus == "结清":
  948. loanDfObj['账户关闭日期'] = self.getNodeData(newperformancebo,"SETTLEDATE")
  949. elif accountStatus == "转出":
  950. loanDfObj['转出月份'] = self.getNodeData(newperformancebo,"ROLLOUTDATE")
  951. elif accountStatus == "呆账":
  952. loanDfObj['余额(本金)'] = utils.replaceAmt(self.getNodeData(newperformancebo,"BALANCE"))
  953. loanDfObj['最近一次还款日期'] = self.getNodeData(newperformancebo, "REPAYDATE")
  954. loanDfObj['管理机构类型'] = self.getNodeData(creditbaseinfobo, "MANAGEORGTYPEDESC")
  955. # loanDf = pd.DataFrame(loanDfObj)
  956. dfObj["loanDf"] = loanDfObj;
  957. #计算流动负债,汇算才需要计算
  958. # try:
  959. # self.getDebt(loanDf,reportTime)
  960. # except Exception:
  961. # logger.error(traceback.print_exc())
  962. # logger.error(traceback.format_exc())
  963. # 解析还款记录
  964. loanPayRecord = pd.DataFrame()
  965. # 特殊交易
  966. specialTradeDf = pd.DataFrame()
  967. # if(len(fiveyearhisrpyinfols)>0):
  968. # fiveyearhisrpyinfols = fiveyearhisrpyinfols[0]
  969. if accountStatus == "正常": # 正常
  970. recordIndexBegin = 11
  971. loanPayRecord = self.mergeLoanPayRecordDf(fiveyearhisrpyinfols, loanPayRecord)
  972. specialTradeDf = self.mergeLoanSpecialTrade(specialtradebaseinfosg, specialTradeDf)
  973. elif accountStatus == "逾期": # 如果长度小于12后续无需处理
  974. # 14 11 有提前最新还款记录的为14
  975. recordIndexBegin = 11
  976. loanPayRecord = self.mergeLoanPayRecordDf(fiveyearhisrpyinfols, loanPayRecord)
  977. specialTradeDf = self.mergeLoanSpecialTrade(specialtradebaseinfosg, specialTradeDf)
  978. elif accountStatus == "结清":
  979. recordIndexBegin = 9
  980. loanPayRecord = self.mergeLoanPayRecordDf(fiveyearhisrpyinfols, loanPayRecord)
  981. specialTradeDf = self.mergeLoanSpecialTrade(specialtradebaseinfosg, specialTradeDf)
  982. elif accountStatus == "呆账" or accountStatus == "转出":
  983. recordIndexBegin = 9
  984. loanPayRecord = self.mergeLoanPayRecordDf(fiveyearhisrpyinfols, loanPayRecord)
  985. specialTradeDf = self.mergeLoanSpecialTrade(specialtradebaseinfosg, specialTradeDf)
  986. else:
  987. print("===================还款状态不满足条件===================#"+self.getNodeData(creditbaseinfobo, "ACCTNO")+"#"+accountStatus)
  988. dfObj["loanPayRecordDf"] = loanPayRecord
  989. dfObj["specialTradeDf"] = specialTradeDf
  990. loanAccountDfs.append(dfObj)
  991. return loanAccountDfs
  992. #计算流动负债
  993. def getDebt(self, loanDf, reportTime):
  994. if loanDf.loc[0, '账户状态'] != '结清' and loanDf.loc[0, '业务种类'] != '个人住房商业贷款' \
  995. and loanDf.loc[0, '业务种类'] != '个人商用房(含商住两用)贷款' and loanDf.loc[0, '业务种类'] != '个人住房公积金贷款' and loanDf.loc[
  996. 0, '业务种类'] != '个人汽车消费贷款':
  997. # term1 / term2 / term3
  998. term1 = None
  999. term2 = None
  1000. term3 = None
  1001. debt_f12 = 0
  1002. payRate = loanDf.loc[0, '还款频率']
  1003. payDue = loanDf.loc[0, '还款期数']
  1004. payRemainderDue = loanDf.loc[0, '剩余还款期数']
  1005. openDate = loanDf.loc[0, '开立日期']
  1006. expireDate = loanDf.loc[0, '到期日期']
  1007. payoutAmt = loanDf.loc[0, '借款金额(本金)'] # 放款金额
  1008. balance = loanDf.loc[0, '余额(本金)']
  1009. # Step1 - 基础变量计算
  1010. if payRate == '月':
  1011. if str(payDue) != "nan" and payDue > 0:
  1012. term1 = payDue
  1013. else:
  1014. term1 = utils.difMonthReportTimeFloor(openDate, expireDate)
  1015. if str(payRemainderDue) != "nan" and payRemainderDue > 0:
  1016. term2 = payRemainderDue
  1017. else:
  1018. term2 = utils.difMonthReportTimeFloor(reportTime, expireDate)
  1019. term3 = term1 - term2
  1020. else:
  1021. term1 = utils.difMonthReportTimeFloor(openDate, expireDate)
  1022. term2 = utils.difMonthReportTimeFloor(reportTime, expireDate)
  1023. term3 = term1 - term2
  1024. if term1 <= 0 or term2 <= 0 or term1 < term2 or openDate == None or expireDate == None:
  1025. tag0 = 1
  1026. else:
  1027. tag0 = 0
  1028. payloan = utils.null2Zero(payoutAmt) - utils.null2Zero(balance)
  1029. payloan = max(0, payloan)
  1030. termpct_12 = max(0, 1 - 0.25 * int((term2 - 1) / 3))
  1031. if loanDf.loc[0, '担保方式'] == '抵押':
  1032. tag1 = 1
  1033. else:
  1034. tag1 = 0
  1035. curActualPay = loanDf.loc[0, '本月实还款']
  1036. curShouldPay = loanDf.loc[0, '本月应还款']
  1037. if str(curActualPay) != "nan" and str(curShouldPay) != "nan":
  1038. if max(curShouldPay, curActualPay) * term1 >= payoutAmt * 1.5:
  1039. tag2 = 1
  1040. elif max(curShouldPay, curActualPay) * term2 >= balance * 1.5:
  1041. tag2 = 1
  1042. elif term2 > 0 and term3 > 0 and payloan / term3 >= 1.5 * (balance / term2):
  1043. tag2 = 1
  1044. elif term2 > 0 and term3 > 0 and balance / term2 >= 1.5 * (payloan / term3):
  1045. tag2 = 1
  1046. elif payoutAmt < balance:
  1047. tag2 = 1
  1048. else:
  1049. tag2 = 0
  1050. if tag1 == 1:
  1051. pay_rat = 0.0036
  1052. else:
  1053. pay_rat = 0.0083
  1054. if tag1 == 1:
  1055. mthly_intr = 0.07 / 12
  1056. else:
  1057. mthly_intr = 0.18 / 12
  1058. totpayment1 = payoutAmt * mthly_intr * term1 + payoutAmt
  1059. totpayment2 = balance * mthly_intr * term2 + balance
  1060. # Step2-贷款分流负债统计
  1061. if tag0 == 1:
  1062. debt_f12 = balance * (1 + pay_rat * 12)
  1063. elif tag1 == 1:
  1064. debt_f12 = payoutAmt * pay_rat * 12
  1065. elif payRate != '月' or payRate == None:
  1066. monthy_pay_ref1 = totpayment1 / term1;
  1067. monthy_pay_ref2 = totpayment2 / term2;
  1068. monthy_pay_final = max(monthy_pay_ref1, monthy_pay_ref2);
  1069. debt_f12 = min(monthy_pay_final * 12, totpayment1, totpayment2);
  1070. elif tag2 == 1:
  1071. debt_f12 = min(balance * mthly_intr * min(term2, 12) + termpct_12 * balance, totpayment1, totpayment2);
  1072. else:
  1073. monthy_pay_ref1 = ((pay_rat * term1 + 1) * payoutAmt) / term1
  1074. if term2 == 0:
  1075. print(loanDf.loc[0, '账户编号'])
  1076. monthy_pay_ref2 = ((pay_rat * term2 + 1) * balance) / term2
  1077. monthy_pay_final = max(curShouldPay, monthy_pay_ref1, monthy_pay_ref2);
  1078. debt_f12 = min(monthy_pay_final * 12, balance * (1 + pay_rat * 12), balance * (1 + mthly_intr * term2));
  1079. loanDf.loc[0, '贷款负债'] = debt_f12
  1080. def mergeCreditCardDf(self,reportTime,docXml):
  1081. creditCardAccountDfs = []
  1082. tmpNode = docXml.documentElement.getElementsByTagName("CREDITCARDACCOUNTBOLS");
  1083. if len(tmpNode)>0:
  1084. noloopcreditaccountbols = docXml.documentElement.getElementsByTagName("CREDITCARDACCOUNTBOLS")[0]
  1085. creditacctinfobo = noloopcreditaccountbols.getElementsByTagName("CREDITACCTINFOBO");
  1086. for i in range(0, len(creditacctinfobo)):
  1087. dfObj = {}
  1088. creditCardDf = pd.DataFrame(columns=dfParser.dfHeaderCreditCard, index=[0])
  1089. creditbaseinfobo = creditacctinfobo[i].getElementsByTagName("CREDITBASEINFOBO")[0]
  1090. newperformancebo = creditacctinfobo[i].getElementsByTagName("NEWPERFORMANCEBO")[0]
  1091. latemonthlyperformancebo = creditacctinfobo[i].getElementsByTagName("LATEMONTHLYPERFORMANCEBO")
  1092. latemonthlyperformancebo = latemonthlyperformancebo[0]
  1093. bigquotabaselnfosg = creditacctinfobo[i].getElementsByTagName("BIGQUOTABASELNFOSG")
  1094. fiveyearhisrpyinfols = creditacctinfobo[i].getElementsByTagName("FIVEYEARHISRPYINFOSG")
  1095. creditCardDf.loc[0, '账户编号'] = self.getNodeData(creditbaseinfobo, "ACCTNO")
  1096. creditCardDf.loc[0, '发卡机构'] = self.getNodeData(creditbaseinfobo, "BUSIORGCODE")
  1097. creditCardDf.loc[0, '账户标识'] = self.getNodeData(creditbaseinfobo, "ACCTCODE")
  1098. creditCardDf.loc[0, '开立日期'] = self.getNodeData(creditbaseinfobo, "OPENDATE")
  1099. creditCardDf.loc[0, '账户授信额度'] = utils.replaceAmt(self.getNodeData(creditbaseinfobo, "ACCTCREDLINE"))
  1100. creditCardDf.loc[0, '共享授信额度'] = utils.replaceAmt(self.getNodeData(creditbaseinfobo, "ORGCREDLINE"))
  1101. # 排除美元027
  1102. MONEYTYPEDESC = self.getNodeData(creditbaseinfobo, "MONEYTYPEDESC")
  1103. if MONEYTYPEDESC.find('人民币')<0:
  1104. continue
  1105. # if MONEYTYPEDESC.find('美元')>= 0:
  1106. # continue
  1107. creditCardDf.loc[0, '币种'] = self.getNodeData(creditbaseinfobo, "MONEYTYPEDESC")
  1108. creditCardDf.loc[0, '业务种类'] = self.getNodeData(creditbaseinfobo, "LOANTYPEDESC")
  1109. creditCardDf.loc[0, '担保方式'] = self.getNodeData(creditbaseinfobo, "GUARMODEDESC")
  1110. accountStatus = self.getNodeData(latemonthlyperformancebo, "ACCTSTATUDESC")
  1111. if accountStatus == "":
  1112. accountStatus = self.getNodeData(newperformancebo,"ACCTSTATUSDESC")
  1113. if accountStatus.find('未激活') < 0: # 非未激活
  1114. if accountStatus == "呆账":
  1115. creditCardDf.loc[0, '账户状态'] = accountStatus
  1116. creditCardDf.loc[0, '余额'] = utils.replaceAmt(self.getNodeData(newperformancebo, "BALANCE"))
  1117. creditCardDf.loc[0, '最近一次还款日期'] = self.getNodeData(newperformancebo, "REPAYDATE")
  1118. elif accountStatus != '销户':
  1119. try:
  1120. creditCardDf.loc[0, '账户状态'] =accountStatus
  1121. creditCardDf.loc[0, '余额'] = utils.replaceAmt(self.getNodeData(latemonthlyperformancebo, "BUSIBAL"))
  1122. creditCardDf.loc[0, '已用额度'] = utils.replaceAmt(self.getNodeData(latemonthlyperformancebo, "ACCTBAL"))
  1123. dividePeriodBalance = self.getNodeData(latemonthlyperformancebo, "INSTBAL") # 未出单的大额专项分期余额
  1124. creditCardDf.loc[0, '未出单的大额专项分期余额'] = utils.replaceAmt(self.getNodeData(latemonthlyperformancebo, "INSTBAL"))
  1125. creditCardDf.loc[0, '剩余分期期数'] = utils.toInt(self.getNodeData(latemonthlyperformancebo, "REMREPPRD"))
  1126. creditCardDf.loc[0, '最近6个月平均使用额度'] = utils.replaceAmt(self.getNodeData(latemonthlyperformancebo, "AVGUSEAMOUNT"))
  1127. creditCardDf.loc[0, '最大使用额'] = utils.replaceAmt(self.getNodeData(latemonthlyperformancebo, "MAXUSEAMOUNT"))
  1128. creditCardDf.loc[0, '账单日'] = self.getNodeData(latemonthlyperformancebo, "SETTDATE")
  1129. creditCardDf.loc[0, '本月应还款'] = utils.replaceAmt(self.getNodeData(latemonthlyperformancebo, "CURRPYAMT"))
  1130. creditCardDf.loc[0, '本月实还款'] = utils.replaceAmt(self.getNodeData(latemonthlyperformancebo, "ACTRPYAMT"))
  1131. creditCardDf.loc[0, '最近一次还款日期'] = self.getNodeData(latemonthlyperformancebo, "LATRPYDATE");
  1132. creditCardDf.loc[0, '当前逾期期数'] = utils.toInt(self.getNodeData(latemonthlyperformancebo,"OVERDPRD"))
  1133. creditCardDf.loc[0, '当前逾期总额'] = utils.replaceAmt(self.getNodeData(latemonthlyperformancebo,"TOTOVERD"))
  1134. except Exception:
  1135. logger.info("解析贷记卡异常-" + i)
  1136. info = sys.exc_info()
  1137. logger.error(info[0])
  1138. logger.error(info[1])
  1139. logger.error(traceback.extract_tb(info[2]))
  1140. if len(bigquotabaselnfosg) >0:
  1141. bigquotabaselnfosg = bigquotabaselnfosg[0]
  1142. # '大额专项分期额度','分期额度生效日期','分期额度到期日期','已用分期金额']
  1143. creditCardDf.loc[0, '大额专项分期额度'] = utils.replaceAmt(self.getNodeData(bigquotabaselnfosg, "SPECLINE"))
  1144. creditCardDf.loc[0, '分期额度生效日期'] = self.getNodeData(bigquotabaselnfosg, "SPECLINE")
  1145. creditCardDf.loc[0, '分期额度到期日期'] = self.getNodeData(bigquotabaselnfosg, "SPECENDDATE")
  1146. creditCardDf.loc[0, '已用分期金额'] = utils.replaceAmt(self.getNodeData(bigquotabaselnfosg, "INSTAMT"))
  1147. else:
  1148. accountStatus = '销户'
  1149. creditCardDf.loc[0, '账户状态'] = '销户'
  1150. else: # 未激活
  1151. creditCardDf.loc[0, '账户状态'] = '未激活'
  1152. accountStatus = '未激活'
  1153. dfObj["creditCardDf"] = creditCardDf;
  1154. # 解析还款记录
  1155. creditCardPayRecord = pd.DataFrame()
  1156. if accountStatus == "正常" or accountStatus == "冻结" or accountStatus == "止付": # 正常
  1157. recordIndexBegin = 9;
  1158. creditCardPayRecord = self.mergeCreditCardPayRecordDf(fiveyearhisrpyinfols,creditCardPayRecord)
  1159. elif accountStatus == "未激活":
  1160. recordIndexBegin = 0;
  1161. elif accountStatus == "销户" or accountStatus == "呆账":
  1162. recordIndexBegin = 7;
  1163. creditCardPayRecord = self.mergeCreditCardPayRecordDf(fiveyearhisrpyinfols,creditCardPayRecord)
  1164. else:
  1165. print(self.getNodeData(creditbaseinfobo, "ACCTNO")+"===================还款状态不满足条件==================="+"#"+accountStatus)
  1166. dfObj["creditCardPayRecordDf"] = creditCardPayRecord;
  1167. creditCardAccountDfs.append(dfObj)
  1168. return creditCardAccountDfs;
  1169. def mergeCreditCardDfZ(self,reportTime,docXml):
  1170. tmpNode = docXml.documentElement.getElementsByTagName("PASSCREDITCARDACCOUNTBOLS");
  1171. creditCardAccountDfsZ = []
  1172. if len(tmpNode)>0:
  1173. noloopcreditaccountbols = docXml.documentElement.getElementsByTagName("PASSCREDITCARDACCOUNTBOLS")[0]
  1174. creditacctinfobo = noloopcreditaccountbols.getElementsByTagName("CREDITACCTINFOBO");
  1175. for i in range(0, len(creditacctinfobo)):
  1176. dfObj = {}
  1177. creditCardDf = pd.DataFrame(columns=dfParser.dfHeaderCreditCardZ, index=[0])
  1178. creditbaseinfobo = creditacctinfobo[i].getElementsByTagName("CREDITBASEINFOBO")[0]
  1179. newperformancebo = creditacctinfobo[i].getElementsByTagName("NEWPERFORMANCEBO")[0]
  1180. latemonthlyperformancebo = creditacctinfobo[i].getElementsByTagName("LATEMONTHLYPERFORMANCEBO")
  1181. latemonthlyperformancebo = latemonthlyperformancebo[0]
  1182. fiveyearhisrpyinfols = creditacctinfobo[i].getElementsByTagName("FIVEYEARHISRPYINFOSG")
  1183. creditCardDf.loc[0, '账户编号'] = self.getNodeData(creditbaseinfobo, "ACCTNO")
  1184. creditCardDf.loc[0, '发卡机构'] = self.getNodeData(creditbaseinfobo, "BUSIORGCODE")
  1185. creditCardDf.loc[0, '账户标识'] = self.getNodeData(creditbaseinfobo, "ACCTCODE")
  1186. creditCardDf.loc[0, '开立日期'] = self.getNodeData(creditbaseinfobo, "OPENDATE")
  1187. creditCardDf.loc[0, '账户授信额度'] = utils.replaceAmt(self.getNodeData(creditbaseinfobo, "ACCTCREDLINE"))
  1188. creditCardDf.loc[0, '共享授信额度'] = utils.replaceAmt(self.getNodeData(creditbaseinfobo, "ORGCREDLINE"))
  1189. creditCardDf.loc[0, '币种'] = self.getNodeData(creditbaseinfobo, "MONEYTYPEDESC")
  1190. creditCardDf.loc[0, '担保方式'] = self.getNodeData(creditbaseinfobo, "GUARMODEDESC")
  1191. MONEYTYPEDESC = self.getNodeData(creditbaseinfobo, "MONEYTYPEDESC")
  1192. if MONEYTYPEDESC.find('人民币') < 0:
  1193. continue
  1194. # if self.getNodeData(creditbaseinfobo, "MONEYTYPEDESC").find('美元') >= 0:
  1195. # continue
  1196. accountStatus = self.getNodeData(latemonthlyperformancebo, "ACCTSTATUDESC")
  1197. if accountStatus == "":
  1198. accountStatus =self.getNodeData(newperformancebo,"ACCTSTATUSDESC")
  1199. if accountStatus.find('未激活') < 0: # 非未激活
  1200. if accountStatus == "呆账":
  1201. creditCardDf.loc[0, '账户状态'] = accountStatus
  1202. creditCardDf.loc[0, '余额'] = utils.replaceAmt(self.getNodeData(newperformancebo, "BALANCE"))
  1203. creditCardDf.loc[0, '透支余额'] = utils.replaceAmt(self.getNodeData(newperformancebo, "BALANCE"))
  1204. creditCardDf.loc[0, '最近一次还款日期'] = self.getNodeData(newperformancebo, "REPAYDATE")
  1205. elif accountStatus != '销户':
  1206. try:
  1207. creditCardDf.loc[0, '账户状态'] = accountStatus
  1208. creditCardDf.loc[0, '透支余额'] = utils.replaceAmt(self.getNodeData(latemonthlyperformancebo, "BUSIBAL"))
  1209. creditCardDf.loc[0, '最近6个月平均透支余额'] = utils.replaceAmt(self.getNodeData(latemonthlyperformancebo, "LATSIXMNAVGOVDFTBAL"))
  1210. creditCardDf.loc[0, '最大透支余额'] = utils.replaceAmt(self.getNodeData(latemonthlyperformancebo, "MAXOVERDRAFTBAL"))
  1211. creditCardDf.loc[0, '账单日'] = self.getNodeData(latemonthlyperformancebo, "SETTDATE")
  1212. creditCardDf.loc[0, '本月实还款'] = utils.replaceAmt(self.getNodeData(latemonthlyperformancebo, "ACTRPYAMT"))
  1213. creditCardDf.loc[0, '最近一次还款日期'] = self.getNodeData(latemonthlyperformancebo, "LATRPYDATE");
  1214. creditCardDf.loc[0, '透支180天以上未付余额'] = utils.replaceAmt(self.getNodeData(latemonthlyperformancebo, "OVERDRAWBAOVE180"))
  1215. except:
  1216. logger.info("解析准贷记卡异常-" + i);
  1217. else:
  1218. accountStatus = '销户'
  1219. creditCardDf.loc[0, '账户状态'] = '销户'
  1220. creditCardDf.loc[0, '最近一次还款日期'] = ""
  1221. else: # 未激活
  1222. creditCardDf.loc[0, '账户状态'] = '未激活'
  1223. accountStatus = '未激活'
  1224. creditCardDf.loc[0, '最近一次还款日期'] = ""
  1225. dfObj["creditCardDfZ"] = creditCardDf;
  1226. # 解析还款记录
  1227. creditCardPayRecord = pd.DataFrame()
  1228. if accountStatus == "正常" or accountStatus == "冻结" or accountStatus == "止付": # 正常
  1229. recordIndexBegin = 9;
  1230. creditCardPayRecord = self.mergeCreditCardPayRecordDf(fiveyearhisrpyinfols,creditCardPayRecord)
  1231. elif accountStatus == "未激活":
  1232. recordIndexBegin = 0;
  1233. elif accountStatus == "销户" or accountStatus == "呆账":
  1234. recordIndexBegin = 7;
  1235. creditCardPayRecord = self.mergeCreditCardPayRecordDf(fiveyearhisrpyinfols,creditCardPayRecord)
  1236. else:
  1237. print("账户#" + str(i + 1) + "#" + self.getNodeData(creditbaseinfobo, "ACCTNO")+"===================还款状态不满足条件==================="+"#"+accountStatus)
  1238. dfObj["creditCardPayRecordDfZ"] = creditCardPayRecord;
  1239. creditCardAccountDfsZ.append(dfObj)
  1240. return creditCardAccountDfsZ;
  1241. # 合并贷款还款记录明细
  1242. def mergeLoanPayRecordDf(self,fiveyearhisrpyinfols, loanPayRecord):
  1243. # for i in range(0, len(fiveyearhisrpyinfols)):
  1244. # loanPayRecordTmp = pd.DataFrame(columns=dfParser.dfHeaderLoanPayRecord, index=[0])
  1245. # loanPayRecordTmp.loc[0, '账户编号'] = self.getNodeData(fiveyearhisrpyinfols[i], "ACCTNO");
  1246. # loanPayRecordTmp.loc[0, '还款日期'] = self.getNodeData(fiveyearhisrpyinfols[i], "OVERDMON")+"-01";
  1247. # loanPayRecordTmp.loc[0, '还款状态值'] = utils.replaceAmt(self.getNodeData(fiveyearhisrpyinfols[i], "TOTACCTBAL"))
  1248. # loanPayRecordTmp.loc[0, '还款状态'] = self.getNodeData(fiveyearhisrpyinfols[i], "OVERDSTATUSCODE");
  1249. # loanPayRecord = pd.concat([loanPayRecord, loanPayRecordTmp], axis=0, ignore_index=True);
  1250. # return loanPayRecord;
  1251. ds = []
  1252. loanPayRecordTmp = pd.DataFrame(columns=dfParser.dfHeaderLoanPayRecord, index=[0])
  1253. for i in range(0, len(fiveyearhisrpyinfols)):
  1254. dsObj = {}
  1255. # loanPayRecordTmp = pd.DataFrame(columns=dfParser.dfHeaderLoanPayRecord, index=[0])
  1256. # loanPayRecordTmp.loc[0, '账户编号'] = self.getNodeData(fiveyearhisrpyinfols[i], "ACCTNO");
  1257. # loanPayRecordTmp.loc[0, '还款日期'] = self.getNodeData(fiveyearhisrpyinfols[i], "OVERDMON") + "-01";
  1258. # loanPayRecordTmp.loc[0, '还款状态值'] = utils.replaceAmt(self.getNodeData(fiveyearhisrpyinfols[i], "TOTACCTBAL"))
  1259. # loanPayRecordTmp.loc[0, '还款状态'] = self.getNodeData(fiveyearhisrpyinfols[i], "OVERDSTATUSCODE");
  1260. # loanPayRecord = pd.concat([loanPayRecord, loanPayRecordTmp], axis=0, ignore_index=True);
  1261. dsObj["账户编号"] = self.getNodeData(fiveyearhisrpyinfols[i], "ACCTNO");
  1262. dsObj["还款日期"] = self.getNodeData(fiveyearhisrpyinfols[i], "OVERDMON") + "-01";
  1263. dsObj["还款状态值"] = utils.replaceAmt(self.getNodeData(fiveyearhisrpyinfols[i], "TOTACCTBAL"))
  1264. dsObj["还款状态"] = self.getNodeData(fiveyearhisrpyinfols[i], "OVERDSTATUSCODE");
  1265. ds.append(dsObj)
  1266. # if len(ds)>0:
  1267. # loanPayRecordTmp = pd.DataFrame(ds)
  1268. return ds;
  1269. # 合并贷款还款记录明细
  1270. def mergeCreditCardPayRecordDf(self, fiveyearhisrpyinfols, loanPayRecord):
  1271. # for i in range(0, len(fiveyearhisrpyinfols)):
  1272. # loanPayRecordTmp = pd.DataFrame(columns=dfParser.dfHeaderLoanPayRecord, index=[0])
  1273. # loanPayRecordTmp.loc[0, '账户编号'] = self.getNodeData(fiveyearhisrpyinfols[i], "ACCTNO");
  1274. # loanPayRecordTmp.loc[0, '还款日期'] = self.getNodeData(fiveyearhisrpyinfols[i], "OVERDMON") + "-01";
  1275. # loanPayRecordTmp.loc[0, '还款状态值'] = utils.replaceAmt(self.getNodeData(fiveyearhisrpyinfols[i], "TOTACCTBAL"))
  1276. # loanPayRecordTmp.loc[0, '还款状态'] = self.getNodeData(fiveyearhisrpyinfols[i], "OVERDSTATUSCODE");
  1277. # loanPayRecord = pd.concat([loanPayRecord, loanPayRecordTmp], axis=0, ignore_index=True);
  1278. # return loanPayRecord;
  1279. ds = []
  1280. loanPayRecordTmp = pd.DataFrame(columns=dfParser.dfHeaderLoanPayRecord, index=[0])
  1281. for i in range(0, len(fiveyearhisrpyinfols)):
  1282. dsObj = {}
  1283. # loanPayRecordTmp = pd.DataFrame(columns=dfParser.dfHeaderLoanPayRecord, index=[0])
  1284. # loanPayRecordTmp.loc[0, '账户编号'] = self.getNodeData(fiveyearhisrpyinfols[i], "ACCTNO");
  1285. # loanPayRecordTmp.loc[0, '还款日期'] = self.getNodeData(fiveyearhisrpyinfols[i], "OVERDMON") + "-01";
  1286. # loanPayRecordTmp.loc[0, '还款状态值'] = utils.replaceAmt(self.getNodeData(fiveyearhisrpyinfols[i], "TOTACCTBAL"))
  1287. # loanPayRecordTmp.loc[0, '还款状态'] = self.getNodeData(fiveyearhisrpyinfols[i], "OVERDSTATUSCODE");
  1288. # loanPayRecord = pd.concat([loanPayRecord, loanPayRecordTmp], axis=0, ignore_index=True);
  1289. dsObj["账户编号"] = self.getNodeData(fiveyearhisrpyinfols[i], "ACCTNO");
  1290. dsObj["还款日期"] = self.getNodeData(fiveyearhisrpyinfols[i], "OVERDMON") + "-01";
  1291. dsObj["还款状态值"] = utils.replaceAmt(self.getNodeData(fiveyearhisrpyinfols[i], "TOTACCTBAL"))
  1292. dsObj["还款状态"] = self.getNodeData(fiveyearhisrpyinfols[i], "OVERDSTATUSCODE");
  1293. ds.append(dsObj)
  1294. if len(ds)>0:
  1295. loanPayRecordTmp = pd.DataFrame(ds)
  1296. return loanPayRecordTmp;
  1297. # 合并贷款还款记录明细
  1298. #合并特殊交易
  1299. def mergeLoanSpecialTrade(self,specialtradebaseinfosg, specialTradeDf):
  1300. for i in range(0,len(specialtradebaseinfosg)):
  1301. specialTradeDfTmp = pd.DataFrame(columns = dfParser.dfHeaderLoanSpecialTrade, index=[0])
  1302. specialTradeDfTmp.loc[0, '账户编号'] = self.getNodeData(specialtradebaseinfosg[i], "ACCTNO");
  1303. specialTradeDfTmp.loc[0, '特殊交易类型'] = self.getNodeData(specialtradebaseinfosg[i], "TRANTYPEDESC");
  1304. specialTradeDfTmp.loc[0, '发生日期'] = self.getNodeData(specialtradebaseinfosg[i], "TRANDATE");
  1305. specialTradeDfTmp.loc[0, '变更月数'] = utils.toInt(self.getNodeData(specialtradebaseinfosg[i], "TRANMONTH"))
  1306. specialTradeDfTmp.loc[0, '发生金额'] = utils.replaceAmt(self.getNodeData(specialtradebaseinfosg[i], "TRANAMT"))
  1307. specialTradeDfTmp.loc[0, '明细记录'] = self.getNodeData(specialtradebaseinfosg[i], "DETRECORD");
  1308. tradeType = self.getNodeData(specialtradebaseinfosg[i], "TRANTYPEDESC");
  1309. content = self.getNodeData(specialtradebaseinfosg[i], "DETRECORD");
  1310. # TODO 加工严重程度 逻辑待确认
  1311. severity = None
  1312. if tradeType == '提前还款' or tradeType == '提前结清':
  1313. severity = 0
  1314. elif tradeType == '其他' and content.find("提前") >= 0:
  1315. severity = 0
  1316. elif tradeType == '担保人(第三方)代偿':
  1317. severity = 1
  1318. # elif tradeType == "其他" and content.find("担保人代还取消")<0 and content.find("合同展期")<0:
  1319. # severity = 2
  1320. # 同时出现代还和取消
  1321. elif tradeType == "其他" and (content.find("代还") < 0 or content.find("代偿") < 0) and content.find(
  1322. "取消") < 0 and content.find("合同展期") < 0:
  1323. severity = 2
  1324. elif (tradeType == "展期" or tradeType.find('延期') >= 0) and content.find("专升本或研究生入学展期") >= 0:
  1325. severity = 2
  1326. # elif tradeType == "其他" and (content.find("担保人代还取消")>=0 or content.find("合同展期")>=0):
  1327. # severity = 3
  1328. elif tradeType == "其他" and (
  1329. ((content.find("代还") < 0 or content.find("代偿") < 0) and content.find("取消") >= 0) or (
  1330. content.find("合同展期") >= 0)):
  1331. severity = 3
  1332. elif (tradeType == "展期" or tradeType.find('延期') >= 0) and content.find("专升本或研究生入学展期") < 0:
  1333. severity = 3
  1334. elif tradeType == "以资抵债":
  1335. severity = 4
  1336. specialTradeDfTmp.loc[0, '严重程度'] = severity
  1337. specialTradeDf = pd.concat([specialTradeDf, specialTradeDfTmp], axis=0, ignore_index=True);
  1338. return specialTradeDf;
  1339. # 解析被追偿信息汇总
  1340. def parseRecoveryInfoMergeDf(self,df):
  1341. if not df.empty:
  1342. recoveryMaxPayDf = df[df['债权转移时的还款状态'] != '']
  1343. recoveryStatusCs = df[df['账户状态'] == '催收']
  1344. if not recoveryMaxPayDf.empty:
  1345. briefInfoDf_recoveryInfoSum.loc[recoveryInfoSumIndex, '债权转移时的最大还款状态'] = np.max(
  1346. recoveryMaxPayDf['债权转移时的还款状态']);
  1347. briefInfoDf_recoveryInfoSum.loc[recoveryInfoSumIndex, '债权转移时属于催收状态的账户数'] = recoveryStatusCs.index.size;
  1348. briefInfoDf_recoveryInfoSum.loc[recoveryInfoSumIndex, '债权转移时属于催收状态的账户数/被追偿信息总数'] = round(
  1349. recoveryStatusCs.index.size / df.index.size, 2);
  1350. # creditTradeDetailDf_recoveryInfo
  1351. # 被追偿账户总数
  1352. creditTradeDetailDf_recoveryInfo.loc[recoveryInfoIndex, '被追偿账户总数'] = df.index.size;
  1353. creditTradeDetailDf_recoveryInfo.loc[recoveryInfoIndex, '被追偿业务种类'] = df['业务种类'].unique().size;
  1354. creditTradeDetailDf_recoveryInfo.loc[recoveryInfoIndex, '最新一笔被追偿债券接收时间'] = np.max(df['债权接收日期']);
  1355. creditTradeDetailDf_recoveryInfo.loc[recoveryInfoIndex, '总债权金额'] = np.max(df['债权金额']);
  1356. creditTradeDetailDf_recoveryInfo.loc[recoveryInfoIndex, '债权转移时的最大还款状态'] = np.max(
  1357. recoveryMaxPayDf['债权转移时的还款状态']);
  1358. # 解析信贷交易明细-特殊交易
  1359. def parseSpecialTrade(self,df):
  1360. if not df.empty:
  1361. creditTradeDetailHeader_specialTrade.loc[specialTradeIndex, '当前用户发生特殊交易的严重程度'] = np.max(df['严重程度']) # 加工的指标
  1362. maxChangeMonthIndex = np.argmax(np.abs(df['变更月数']))
  1363. meanMonthValue = np.mean(np.abs(df['变更月数']))
  1364. row0 = df.loc[maxChangeMonthIndex, :]
  1365. settleDf = df[(df['特殊交易类型'] == '提前结清') | (df['特殊交易类型'] == '提前还款')]
  1366. debtDf = df[(df['特殊交易类型'] == '以资抵债')]
  1367. creditTradeDetailHeader_specialTrade.loc[specialTradeIndex, '用户发生特殊交易变更月数的最大差值'] = row0[3]
  1368. creditTradeDetailHeader_specialTrade.loc[specialTradeIndex, '用户发生特殊交易变更月数的平均差值'] = round(meanMonthValue, 2)
  1369. creditTradeDetailHeader_specialTrade.loc[specialTradeIndex, '用户特殊交易涉及的发生金额的最大值'] = np.max(df['发生金额'])
  1370. creditTradeDetailHeader_specialTrade.loc[specialTradeIndex, '用户特殊交易涉及的发生金额的平均值'] = round(np.mean(df['发生金额']), 2)
  1371. creditTradeDetailHeader_specialTrade.loc[specialTradeIndex, '用户所有帐户发生提前还款交易的次数统计'] = settleDf.index.size
  1372. creditTradeDetailHeader_specialTrade.loc[specialTradeIndex, '用户所有帐户发生不良特殊交易的次数统计'] = debtDf.index.size;
  1373. # 信贷交易明细-非循环贷账户
  1374. def parseLoanAccountInfo(self,df):
  1375. if not df.empty:
  1376. loanAccountNum = int(briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '非循环贷账户账户数'])
  1377. normalDf = df[(df['账户状态'] != '结清') & (df['账户状态'] != '转出') & (df['账户状态'] != '呆账')].reset_index(drop=True)
  1378. normalDf = normalDf[0:loanAccountNum] # 根据非循环贷账户数进行计算进行截取
  1379. creditTradeDetailDf_loanAccountInfo.loc[loanInfoIndex, '本月应还款(合计)'] = np.sum(normalDf['本月应还款'])
  1380. creditTradeDetailDf_loanAccountInfo.loc[loanInfoIndex, '本月实还款(合计)'] = np.sum(normalDf['本月实还款'])
  1381. creditTradeDetailDf_loanAccountInfo.loc[loanInfoIndex, '最近一次还款日期'] = np.max(normalDf['最近一次还款日期'])
  1382. creditTradeDetailDf_loanAccountInfo.loc[loanInfoIndex, '当前一共逾期期数'] = np.sum(normalDf['当前逾期期数'])
  1383. creditTradeDetailDf_loanAccountInfo.loc[loanInfoIndex, '当前一共逾期总额'] = np.sum(normalDf['当前逾期总额'])
  1384. creditTradeDetailDf_loanAccountInfo.loc[loanInfoIndex, '逾期31-60天未还本金(合计)'] = np.sum(
  1385. normalDf['逾期31-60天未还本金'])
  1386. creditTradeDetailDf_loanAccountInfo.loc[loanInfoIndex, '逾期61-90天未还本金(合计)'] = np.sum(
  1387. normalDf['逾期61-90天未还本金'])
  1388. creditTradeDetailDf_loanAccountInfo.loc[loanInfoIndex, '逾期91-180天未还本金(合计)'] = np.sum(
  1389. normalDf['逾期91-180天未还本金'])
  1390. creditTradeDetailDf_loanAccountInfo.loc[loanInfoIndex, '逾期180天以上未还本金(合计)'] = np.sum(
  1391. normalDf['逾期180天以上未还本金'])
  1392. # 信贷交易明细-循环额度分账户
  1393. def parseCycleCreditAccountInfo(self,df):
  1394. if not df.empty:
  1395. normalDf = df[(df['账户状态'] != '结清') & (df['账户状态'] != '转出') & (df['账户状态'] != '呆账')].reset_index(drop=True)
  1396. loanAccountNum = int(briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '非循环贷账户账户数'])
  1397. cycleCreditAccountNum = int(briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '循环额度下分账户账户数'])
  1398. normalDf = normalDf[loanAccountNum:(loanAccountNum + cycleCreditAccountNum)]
  1399. if not normalDf.empty:
  1400. creditTradeDetailDf_cycleCreditAccountInfo.loc[cycleCreditAccountInfoIndex, '本月应还款(合计)'] = np.sum(
  1401. normalDf['本月应还款'])
  1402. creditTradeDetailDf_cycleCreditAccountInfo.loc[cycleCreditAccountInfoIndex, '本月实还款(合计)'] = np.sum(
  1403. normalDf['本月实还款'])
  1404. creditTradeDetailDf_cycleCreditAccountInfo.loc[cycleCreditAccountInfoIndex, '最近一次还款日期'] = np.max(
  1405. normalDf['最近一次还款日期'])
  1406. creditTradeDetailDf_cycleCreditAccountInfo.loc[cycleCreditAccountInfoIndex, '当前一共逾期期数'] = np.sum(
  1407. normalDf['当前逾期期数'])
  1408. creditTradeDetailDf_cycleCreditAccountInfo.loc[cycleCreditAccountInfoIndex, '当前一共逾期总额'] = np.sum(
  1409. normalDf['当前逾期总额'])
  1410. creditTradeDetailDf_cycleCreditAccountInfo.loc[
  1411. cycleCreditAccountInfoIndex, '逾期31-60天未还本金(合计)'] = np.sum(normalDf['逾期31-60天未还本金'])
  1412. creditTradeDetailDf_cycleCreditAccountInfo.loc[
  1413. cycleCreditAccountInfoIndex, '逾期61-90天未还本金(合计)'] = np.sum(normalDf['逾期61-90天未还本金'])
  1414. creditTradeDetailDf_cycleCreditAccountInfo.loc[
  1415. cycleCreditAccountInfoIndex, '逾期91-180天未还本金(合计)'] = np.sum(normalDf['逾期91-180天未还本金'])
  1416. creditTradeDetailDf_cycleCreditAccountInfo.loc[
  1417. cycleCreditAccountInfoIndex, '逾期180天以上未还本金(合计)'] = np.sum(normalDf['逾期180天以上未还本金'])
  1418. # 信贷交易明细-循环贷账户
  1419. def parseCycleLoanAccountInfo(self,df):
  1420. if not df.empty:
  1421. normalDf = df[(df['账户状态'] != '结清') & (df['账户状态'] != '转出') & (df['账户状态'] != '呆账')]
  1422. loanAccountNum = int(briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '非循环贷账户账户数'])
  1423. cycleCreditAccountNum = int(briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '循环额度下分账户账户数'])
  1424. cycleAccountNum = int(briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '循环贷账户账户数'])
  1425. normalDf = normalDf[(loanAccountNum + cycleCreditAccountNum):normalDf.index.size]
  1426. if not normalDf.empty:
  1427. creditTradeDetailDf_cycleLoanAccountInfo.loc[cycleLoanAccountInfoIndex, '本月应还款(合计)'] = np.sum(
  1428. normalDf['本月应还款'])
  1429. creditTradeDetailDf_cycleLoanAccountInfo.loc[cycleLoanAccountInfoIndex, '本月实还款(合计)'] = np.sum(
  1430. normalDf['本月实还款'])
  1431. creditTradeDetailDf_cycleLoanAccountInfo.loc[cycleLoanAccountInfoIndex, '最近一次还款日期'] = np.max(
  1432. normalDf['最近一次还款日期'])
  1433. creditTradeDetailDf_cycleLoanAccountInfo.loc[cycleLoanAccountInfoIndex, '当前一共逾期期数'] = np.sum(
  1434. normalDf['当前逾期期数'])
  1435. creditTradeDetailDf_cycleLoanAccountInfo.loc[cycleLoanAccountInfoIndex, '当前一共逾期总额'] = np.sum(
  1436. normalDf['当前逾期总额'])
  1437. creditTradeDetailDf_cycleLoanAccountInfo.loc[cycleLoanAccountInfoIndex, '逾期31-60天未还本金(合计)'] = np.sum(
  1438. normalDf['逾期31-60天未还本金'])
  1439. creditTradeDetailDf_cycleLoanAccountInfo.loc[cycleLoanAccountInfoIndex, '逾期61-90天未还本金(合计)'] = np.sum(
  1440. normalDf['逾期61-90天未还本金'])
  1441. creditTradeDetailDf_cycleLoanAccountInfo.loc[cycleLoanAccountInfoIndex, '逾期91-180天未还本金(合计)'] = np.sum(
  1442. normalDf['逾期91-180天未还本金'])
  1443. creditTradeDetailDf_cycleLoanAccountInfo.loc[cycleLoanAccountInfoIndex, '逾期180天以上未还本金(合计)'] = np.sum(
  1444. normalDf['逾期180天以上未还本金'])
  1445. # 解析贷款账户信息指标
  1446. def parseLoanMergeDf(self,df,reportTime):
  1447. if not df.empty:
  1448. sortDf = df.sort_values(by=["账户关闭日期", "借款金额(本金)"], ascending=(False, False))
  1449. sortDf = sortDf[sortDf['账户状态'] == '结清'];
  1450. sortDf = sortDf.reset_index(drop=True)
  1451. if not sortDf.empty:
  1452. row0 = sortDf.loc[0, :]
  1453. loanAccountInfoDf.loc[loanAccountInfoIndex, '最近一笔结清贷款的贷款金额'] = row0['借款金额(本金)']
  1454. openDate = dfParser.formatDate(row0['开立日期'])
  1455. loanAccountInfoDf.loc[loanAccountInfoIndex, '最近一笔结清贷款的发放距今月数'] = utils.difMonthReportTime(openDate,
  1456. reportTime)
  1457. settleDate = dfParser.formatDate(row0['账户关闭日期'])
  1458. loanAccountInfoDf.loc[loanAccountInfoIndex, '最近一笔结清贷款的结清距今月数'] = utils.difMonthReportTime(settleDate,
  1459. reportTime)
  1460. loanAccountInfoDf.loc[loanAccountInfoIndex, '历史贷款总法人机构数'] = df['管理机构'].unique().size
  1461. #1112 汇算
  1462. notSettleDf = df[df['账户状态'] != '结清'];
  1463. otherDf.loc[otherIndex, '未结清贷款机构数'] = notSettleDf['管理机构'].unique().size
  1464. loanAccountInfoDf.loc[loanAccountInfoIndex, '当前同时在用的贷款机构数'] = df[df['余额(本金)'] > 0]['管理机构'].unique().size
  1465. statusDf = df[(df['账户状态'] != '结清') & (df['账户状态'] != '转出')]
  1466. bankDf = statusDf[statusDf['管理机构'].str.contains('银行')]
  1467. # 没有记录
  1468. if statusDf.index.size == 0:
  1469. isNotBankCust = -1
  1470. else:
  1471. if bankDf.index.size > 0: # 有一条以上不为结清,请包含银行
  1472. isNotBankCust = 1;
  1473. else:
  1474. isNotBankCust = 0;
  1475. loanAccountInfoDf.loc[loanAccountInfoIndex, '是否有非银行贷款客户'] = isNotBankCust
  1476. # 最严重的五级分类
  1477. # fiveType = ""
  1478. # for fiveTypeTmp in consts.fiveType:
  1479. # fiveTypeDf = statusDf[statusDf['五级分类']==fiveTypeTmp];
  1480. # if not fiveTypeDf.empty:
  1481. # fiveType = fiveTypeTmp;
  1482. # break;
  1483. # loanAccountInfoDf.loc[loanAccountInfoIndex, '贷款五级分类'] = fiveType
  1484. # 当前贷款LTV
  1485. # 从“贷款信息”中提取,剔除“账户状态”为结清及转出,并剔除“账户状态”为呆账且本金余额 = 0
  1486. # 的记录后,SUM(本金余额) / SUM(贷款本金)
  1487. # 如本金余额为空和贷款本金为0或为空,则当条记录不计算
  1488. loanLtvDf = df[(df['账户状态'] != '结清') & (df['账户状态'] != '转出') & (df['借款金额(本金)'] > 0) & (df['余额(本金)'] != '')]
  1489. badSetDf = loanLtvDf[~((loanLtvDf['账户状态'] == '呆账') & (loanLtvDf['余额(本金)'] == 0))]
  1490. balanceSum = np.sum(badSetDf['余额(本金)'].astype('int'))
  1491. loanAmtSum = np.sum(badSetDf['借款金额(本金)'].astype('int'))
  1492. if (loanAmtSum != 0):
  1493. loanAccountInfoDf.loc[loanAccountInfoIndex, '当前贷款LTV'] = round(np.divide(balanceSum, loanAmtSum), 2)
  1494. loanAccountInfoDf.loc[loanAccountInfoIndex, '当前贷款最高LTV'] = round(
  1495. np.max(np.divide(badSetDf['余额(本金)'].astype('int'), badSetDf['借款金额(本金)'].astype('int'))), 2)
  1496. loanAccountInfoDf.loc[loanAccountInfoIndex, '当前贷款最低LTV'] = round(
  1497. np.min(np.divide(badSetDf['余额(本金)'].astype('int'), badSetDf['借款金额(本金)'].astype('int'))), 2)
  1498. loanAccountInfoDf.loc[loanAccountInfoIndex, '当前贷款平均LTV'] = round(np.mean(np.divide(badSetDf['余额(本金)'].astype('int'), badSetDf['借款金额(本金)'].astype('int'))), 2)
  1499. # ['个人住房商业贷款','个人商用房(含商住两用)贷款','个人住房公积金贷款','房'],
  1500. houseLtvList = consts.houseLtvList;# ['个人住房商业贷款','个人商用房(含商住两用)贷款','个人住房公积金贷款','房'],
  1501. # houseLtvDf = badSetDf[badSetDf['业务种类'].isin(houseLtvList)]
  1502. # if not houseLtvDf.empty:
  1503. # loanAccountInfoDf.loc[loanAccountInfoIndex, '当前房贷LTV'] = round(np.divide(np.sum(houseLtvDf['余额(本金)'].astype('int')),np.sum(houseLtvDf['借款金额(本金)'].astype('int'))), 2)
  1504. # ['个人住房贷款','个人商用房(包括商住两用)贷款']
  1505. loanAccountInfoDf.loc[loanAccountInfoIndex, '当前房贷LTV'] = lip.getCurLtv(badSetDf, houseLtvList)
  1506. loanAccountInfoDf.loc[loanAccountInfoIndex, '当前贷款机构数量'] = loanLtvDf['管理机构'].unique().size
  1507. cardLtvList = ['个人汽车消费贷款']#, '车'
  1508. loanAccountInfoDf.loc[loanAccountInfoIndex, '当前车贷LTV'] = lip.getCurLtv(badSetDf, cardLtvList)
  1509. operateLtvList = ['个人经营性贷款']
  1510. loanAccountInfoDf.loc[loanAccountInfoIndex, '当前经营贷LTV'] = lip.getCurLtv(badSetDf, operateLtvList)
  1511. consumeLtvList = ['其他个人消费贷款']
  1512. loanAccountInfoDf.loc[loanAccountInfoIndex, '当前消费贷LTV'] = lip.getCurLtv(badSetDf, consumeLtvList)
  1513. bankLtvList = ['商业银行', '外资银行', '村镇银行', '住房储蓄银行', '财务公司']
  1514. loanAccountInfoDf.loc[loanAccountInfoIndex, '当前银行贷LTV'] = lip.getCurBankLtv(badSetDf, bankLtvList)
  1515. bankLtvList = ['消费金融公司', '汽车金融公司', '信托公司'] # TODO
  1516. loanAccountInfoDf.loc[loanAccountInfoIndex, '当前消金贷LTV'] = lip.getCurBankLtv(badSetDf, bankLtvList)
  1517. smallLoanLtvList = ['小额信贷公司']
  1518. loanAccountInfoDf.loc[loanAccountInfoIndex, '当前小贷LTV'] = lip.getCurBankLtv(badSetDf, smallLoanLtvList)
  1519. # 当前贷款最大逾期期数
  1520. # 从“贷款信息”中提取,剔除“账户状态”为结清、转出、呆账、呆帐后,MAX(每笔贷款的当前逾期期数)
  1521. loanOverdueLtvDf = df[(df['账户状态'] != '结清') & (df['账户状态'] != '转出') & (df['账户状态'] != '呆账')]
  1522. if not loanOverdueLtvDf.empty:
  1523. loanAccountInfoDf.loc[loanAccountInfoIndex, '当前贷款最大逾期期数'] = np.max(loanOverdueLtvDf['当前逾期期数'])
  1524. loanAccountInfoDf.loc[loanAccountInfoIndex, '当前贷款最大逾期金额'] = np.max(loanOverdueLtvDf['当前逾期总额'])
  1525. loanOverdueLtvDf = loanOverdueLtvDf.reset_index(drop=True)
  1526. maxOverdueIndex = np.argmax(loanOverdueLtvDf['当前逾期期数'])
  1527. loanAccountInfoDf.loc[loanAccountInfoIndex, '当前贷款最大逾期期数对应的最大逾期金额'] = \
  1528. loanOverdueLtvDf.loc[maxOverdueIndex, :]['当前逾期总额']
  1529. loanAccountInfoDf.loc[loanAccountInfoIndex, '近3月开户最高贷款本金'] = lip.getLastLoanAmtMax(df,
  1530. reportTime,
  1531. 3) # 贷款指标加工单独放到一个文件里
  1532. loanAccountInfoDf.loc[loanAccountInfoIndex, '近3月开户最低贷款本金'] = lip.getLastLoanAmtMin(df,
  1533. reportTime,
  1534. 3)
  1535. loanAccountInfoDf.loc[loanAccountInfoIndex, '近3月开户平均贷款本金'] = lip.getLastLoanAmtAvg(df,
  1536. reportTime,
  1537. 3)
  1538. loanAccountInfoDf.loc[loanAccountInfoIndex, '近6月开户最高贷款本金'] = lip.getLastLoanAmtMax(df,
  1539. reportTime,
  1540. 6)
  1541. loanAccountInfoDf.loc[loanAccountInfoIndex, '近6月开户最低贷款本金'] = lip.getLastLoanAmtMin(df,
  1542. reportTime,
  1543. 6)
  1544. loanAccountInfoDf.loc[loanAccountInfoIndex, '近6月开户平均贷款本金'] = lip.getLastLoanAmtAvg(df,
  1545. reportTime,
  1546. 6)
  1547. loanAccountInfoDf.loc[loanAccountInfoIndex, '近12月开户最高贷款本金'] = lip.getLastLoanAmtMax(df,
  1548. reportTime,
  1549. 12)
  1550. loanAccountInfoDf.loc[loanAccountInfoIndex, '近12月开户最低贷款本金'] = lip.getLastLoanAmtMin(df,
  1551. reportTime,
  1552. 12)
  1553. loanAccountInfoDf.loc[loanAccountInfoIndex, '近12月开户平均贷款本金'] = lip.getLastLoanAmtAvg(df,
  1554. reportTime,
  1555. 12)
  1556. lastLoanDf = loanOverdueLtvDf;
  1557. if not lastLoanDf.empty:
  1558. loanAccountInfoDf.loc[loanAccountInfoIndex, '贷款最近一次还款日期距今时长'] = lip.getLastPayDateMinDays(lastLoanDf,reportTime)
  1559. normalDf = df[(df['账户状态'] == '正常') & (df['当前逾期期数'] == 0)]
  1560. # 未结清贷款总账户数:账户状态不等于结清和转出的记录数
  1561. notSettleDf = df[(df['账户状态'] != '结清') & (df['账户状态'] != '转出')]
  1562. #1113 汇算
  1563. cardLoanCountDf = df[df['业务种类'].isin(cardLtvList)]
  1564. otherDf.loc[otherIndex, '车贷发放笔数'] = cardLoanCountDf.index.size
  1565. #count(贷款账户) where 五级分类 in ('关注','次级','可疑','损失')
  1566. fiveDf = df[df['五级分类'].isin(['关注','次级','可疑','损失'])]
  1567. otherDf.loc[otherIndex, "贷款五级分类命中('关注','次级','可疑','损失')的账户数"] = fiveDf.index.size
  1568. loanStatusDf = df[df['账户状态'].isin(['逾期','呆账','转出','担保物不足','强制平仓','司法追偿'])]
  1569. otherDf.loc[otherIndex, "贷款状态为('逾期','呆账','转出','担保物不足','强制平仓','司法追偿')的账户数"] = loanStatusDf.index.size
  1570. #近12个月信贷最大授信额度
  1571. #max(放款金额) where 担保方式 in ("信用/免担保") and 业务种类 not in ("个人住房商业贷款","个人商用房(含商住两用)贷款","个人住房公积金贷款","个人汽车消费贷款") and (报告日期-开立日期)<=360天
  1572. loanCreditAmtDf = df[df['担保方式'].isin(['信用/免担保'])]
  1573. loanCreditAmtDf = loanCreditAmtDf[(~loanCreditAmtDf['业务种类'].isin(consts.notMortgageList))]
  1574. creditDate = utils.getLastMonthDate(reportTime,12)
  1575. loanCreditAmtDf = loanCreditAmtDf[loanCreditAmtDf["开立日期"]>=creditDate]
  1576. if not loanCreditAmtDf.empty:
  1577. otherDf.loc[otherIndex, "近12个月信贷最大授信额度"] = np.max(loanCreditAmtDf['借款金额(本金)'])
  1578. if not notSettleDf.empty:
  1579. loanAccountInfoDf.loc[loanAccountInfoIndex, '当前正常贷款账户数'] = normalDf.index.size
  1580. loanAccountInfoDf.loc[loanAccountInfoIndex, '当前正常贷款账户数占比'] = round(
  1581. normalDf.index.size / notSettleDf.index.size, 2)
  1582. # 当前未结清贷款余额总和
  1583. # ltvDf = tmpDf[tmpDf['业务种类'].isin(bizTypeList)]
  1584. loanAccountInfoDf.loc[loanAccountInfoIndex, '当前未结清贷款余额总和'] = np.sum(notSettleDf['余额(本金)'])
  1585. # loanAccountInfoDf.loc[loanAccountInfoIndex, '当前未结清贷款余额总和'] = np.sum(notSettleDf['余额(本金)'])
  1586. # 当前未结清住房贷款余额总和
  1587. houseDf = notSettleDf[notSettleDf['业务种类'].isin(houseLtvList)]
  1588. loanAccountInfoDf.loc[loanAccountInfoIndex, '当前未结清住房贷款余额总和'] = np.sum(houseDf['余额(本金)'])
  1589. # 当前未结清汽车贷款余额总和
  1590. cardDf = notSettleDf[notSettleDf['业务种类'].isin(cardLtvList)]
  1591. loanAccountInfoDf.loc[loanAccountInfoIndex, '当前未结清汽车贷款余额总和'] = np.sum(cardDf['余额(本金)'])
  1592. # 当前未结清个人经营性贷款余额总和
  1593. operateLtvDf = notSettleDf[notSettleDf['业务种类'].isin(operateLtvList)]
  1594. loanAccountInfoDf.loc[loanAccountInfoIndex, '当前未结清个人经营性贷款余额总和'] = np.sum(operateLtvDf['余额(本金)'])
  1595. # 当前平均每月贷款余额总和
  1596. loanAccountInfoDf.loc[loanAccountInfoIndex, '当前平均每月贷款余额总和'] = round(np.sum(notSettleDf['余额(本金)']) / 12,
  1597. 2)
  1598. # 当前正常贷款账户余额
  1599. loanAccountInfoDf.loc[loanAccountInfoIndex, '当前正常贷款账户余额'] = np.sum(normalDf['余额(本金)'])
  1600. # "从“贷款信息”中提取,剔除结清、转出,当前正常贷款账户余额/未结清贷款总余额(本金余额加总)
  1601. if np.sum(notSettleDf['余额(本金)']) > 0:
  1602. loanAccountInfoDf.loc[loanAccountInfoIndex, '当前正常贷款账户余额占总余额比'] = round(
  1603. np.sum(normalDf['余额(本金)']) / np.sum(notSettleDf['余额(本金)']), 2)
  1604. #1113 汇算
  1605. #sum(本月应还款) where 业务种类 in ("个人住房商业贷款","个人商用房(含商住两用)贷款","个人住房公积金贷款") and 账户状态 not in("结清","转出","呆账")
  1606. housePayDf = notSettleDf[notSettleDf['业务种类'].isin(consts.houseLtvList)]
  1607. otherDf.loc[otherIndex, '房贷月还总额']=np.sum(housePayDf['本月应还款'])
  1608. cardPayMonthDf = notSettleDf[notSettleDf['业务种类'].isin(cardLtvList)]
  1609. otherDf.loc[otherIndex, '车贷月还总额'] = np.sum(cardPayMonthDf['本月应还款'])
  1610. #小额贷款笔数
  1611. smallLoanDf = notSettleDf[notSettleDf['借款金额(本金)']<=20000]
  1612. otherDf.loc[otherIndex, '小额贷款笔数'] = smallLoanDf.index.size
  1613. settleDf = df[(df['账户状态'] == '结清')]
  1614. loanAccountInfoDf.loc[loanAccountInfoIndex, '当前正常结清贷款账户数'] = settleDf.index.size
  1615. loanAccountInfoDf.loc[loanAccountInfoIndex, '当前正常结清贷款账户数占比'] = round(settleDf.index.size / df.index.size, 2)
  1616. # 贷款24期还款记录次数 TODO
  1617. # 最近3个月个人消费贷款发放额度
  1618. loanAccountInfoDf.loc[loanAccountInfoIndex, '贷款本月实还款金额'] = np.sum(loanOverdueLtvDf['本月应还款'])
  1619. loanAccountInfoDf.loc[loanAccountInfoIndex, '最近3个月个人消费贷款发放额度'] = lip.getLastPerConsumeAmt(df, 3, reportTime)
  1620. loanAccountInfoDf.loc[loanAccountInfoIndex, '最近6个月个人消费贷款发放额度'] = lip.getLastPerConsumeAmt(df, 6, reportTime)
  1621. loanAccountInfoDf.loc[loanAccountInfoIndex, '最近12个月个人消费贷款发放额度'] = lip.getLastPerConsumeAmt(df, 12, reportTime)
  1622. # 未结清贷款平均剩余还款期数
  1623. payPieDf = notSettleDf[notSettleDf['还款期数'] != '']
  1624. if payPieDf.index.size != 0:
  1625. loanAccountInfoDf.loc[loanAccountInfoIndex, '未结清贷款平均剩余还款期数'] = round(
  1626. np.sum(payPieDf['剩余还款期数']) / payPieDf.index.size, 2)
  1627. # 当前贷款本月应还金额总和
  1628. loanAccountInfoDf.loc[loanAccountInfoIndex, '当前贷款本月应还金额总和'] = np.sum(notSettleDf['本月应还款'])
  1629. # 当前贷款本月实还金额总额
  1630. loanAccountInfoDf.loc[loanAccountInfoIndex, '当前贷款本月实还金额总额'] = np.sum(notSettleDf['本月实还款'])
  1631. #1112汇算 非抵押类贷款授信总额
  1632. #sum(放款金额) where 业务种类 not in ("个人住房商业贷款","个人商用房(含商住两用)贷款","个人住房公积金贷款","个人汽车消费贷款")
  1633. # and 担保方式 not in ("抵押") and 账户状态不等于"结清" TODO
  1634. notMortgageList = consts.notMortgageList
  1635. notMortgageSettleDf = df[(df['担保方式'] != '抵押') & (df['账户状态'] != '结清')]
  1636. notMortgageSettleDf = notMortgageSettleDf[(~notMortgageSettleDf['业务种类'].isin(notMortgageList))]
  1637. otherDf.loc[otherIndex,"非抵押类贷款授信总额"]=np.sum(notMortgageSettleDf['借款金额(本金)'])
  1638. otherDf.loc[otherIndex, "未结清非抵押贷款笔数"] = notMortgageSettleDf.index.size
  1639. otherDf.loc[otherIndex, "未结清非抵押类贷款本金余额"] = np.sum(notMortgageSettleDf['余额(本金)'])
  1640. notMortgageDf = df[(df['担保方式'] != '抵押') & (df['账户状态'] != '结清') & (df['账户状态'] != '呆账') & (df['账户状态'] != '转出')]
  1641. notMortgageDf = notMortgageDf[(~notMortgageDf['业务种类'].isin(notMortgageList))]
  1642. otherDf.loc[otherIndex, "未结清非抵押类贷款月还总额"] = np.sum(notMortgageDf['本月应还款'])
  1643. sanshouDf.loc[sanshouIndex,"最大贷款余额"]= np.max(notSettleDf["余额(本金)"])
  1644. sanshouDf.loc[sanshouIndex, "未结清所有贷款合同总额"] = np.sum(notSettleDf["借款金额(本金)"])
  1645. # 解析贷记卡账户信息指标
  1646. def parseCreditCardMergeDf(self,df,reportTime):
  1647. if not df.empty:
  1648. # 历史信用卡总法人机构数
  1649. # creditCardAccountInfoDf.loc[creditCardAccountInfoIndex,'历史信用卡总法人机构数'] = df['发卡机构'].unique().size
  1650. # creditCardUseDf = df[df['已用额度']>0];
  1651. # creditCardAccountInfoDf.loc[creditCardAccountInfoIndex,'当前同时在用的信用卡机构数'] = creditCardUseDf['发卡机构'].unique().size
  1652. fstDate = np.min(df['开立日期']);
  1653. sanshouDf.loc[sanshouIndex, '最早信用卡发卡天数'] = utils.difDateReportTime(reportTime,fstDate)
  1654. # 统一排除
  1655. creditDf = df[(df['币种'] == '人民币元') & (df['账户状态'] != '未激活') & (df['账户状态'] != '销户') & (df['账户状态'] != '呆账')]
  1656. totalAmtDf = df[(df['币种'] == '人民币元') & (df['账户状态'] != '未激活') & (df['账户状态'] != '销户') & (df['账户状态'] != '呆账')]
  1657. # 大额专项分期额度(合计)
  1658. # 已用分期金额(合计)
  1659. creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '大额专项分期额度(合计)'] = np.sum(creditDf['大额专项分期额度'])
  1660. creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '已用分期金额(合计)'] = np.sum(creditDf['已用分期金额'])
  1661. # creditCardAccountInfoDf.loc[creditCardAccountInfoIndex,'贷记卡账户当前总额度'] = cip.getMaxCreditAmt(creditDf)
  1662. creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '最近新发放的3张贷记卡平均额度'] = cip.getAvgCreditAmt(creditDf)
  1663. creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '贷记卡额度使用率超过90%的机构数占比'] = cip.getUseRate(creditDf,
  1664. df, 0.9)
  1665. creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '贷记卡额度使用率超过100%的机构数占比'] = cip.getUseRate(creditDf,
  1666. totalAmtDf,
  1667. 1)
  1668. # 从“贷记卡信息”中提取,计算授信额度时剔除销户,计算已用额度时剔除呆账、呆帐、销户后,SUM(各账户已用额度) / SUM(各账户授信额度)
  1669. useCreditDf = df[(df['币种'] == '人民币元') & (df['账户状态'] != '销户') & (df['账户状态'] != '呆账')]
  1670. totalCreditDf = df[(df['币种'] == '人民币元') & (df['账户状态'] != '销户')]
  1671. totalCreditAmt = np.sum(totalCreditDf['账户授信额度'])
  1672. if totalCreditAmt != 0: # 授信额度不能为0
  1673. creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '贷记卡账户当前总额度使用率'] = round(
  1674. np.sum(useCreditDf['已用额度']) / np.sum(totalCreditDf['账户授信额度']), 2)
  1675. creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '贷记卡账户最高使用额度总的使用率'] = round(
  1676. np.sum(useCreditDf['最大使用额']) / np.sum(totalCreditDf['账户授信额度']), 2)
  1677. creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '贷记卡账户近6月平均额度总的使用率'] = round(
  1678. np.sum(useCreditDf['最近6个月平均使用额度']) / np.sum(totalCreditDf['账户授信额度']), 2)
  1679. creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '当前贷记卡最大逾期期数'] = np.max(creditDf['当前逾期期数']) # 用于计算
  1680. creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '当前贷记卡最大逾期金额'] = np.max(creditDf['当前逾期总额'])
  1681. #1112 修改
  1682. otherDf.loc[otherIndex, '贷记卡当前逾期金额'] = np.sum(creditDf['当前逾期总额'])
  1683. if not creditDf.empty:
  1684. creditDf = creditDf.reset_index(drop=True)
  1685. maxOverdueIndex = np.argmax(creditDf['当前逾期期数'])
  1686. creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '当前贷记卡最大逾期期数对应的最大逾期金额'] = \
  1687. creditDf.loc[maxOverdueIndex, :]['当前逾期总额']
  1688. creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '近3月开卡最高额度'] = cip.getLastMonthMaxCreditAmt(df,
  1689. reportTime,
  1690. 3)
  1691. creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '近3月开卡最低额度'] = cip.getLastMonthMinCreditAmt(df,
  1692. reportTime,
  1693. 3)
  1694. creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '近3月开卡平均额度'] = cip.getLastMonthAvgCreditAmt(df,
  1695. reportTime,
  1696. 3)
  1697. creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '近6月开卡最高额度'] = cip.getLastMonthMaxCreditAmt(df,
  1698. reportTime,
  1699. 6)
  1700. creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '近6月开卡最低额度'] = cip.getLastMonthMinCreditAmt(df,
  1701. reportTime,
  1702. 6)
  1703. creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '近6月开卡平均额度'] = cip.getLastMonthAvgCreditAmt(df,
  1704. reportTime,
  1705. 6)
  1706. creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '近12月开卡最高额度'] = cip.getLastMonthMaxCreditAmt(df,
  1707. reportTime,
  1708. 12)
  1709. creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '近12月开卡最低额度'] = cip.getLastMonthMinCreditAmt(df,
  1710. reportTime,
  1711. 12)
  1712. creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '近12月开卡平均额度'] = cip.getLastMonthAvgCreditAmt(df,
  1713. reportTime,
  1714. 12)
  1715. if not creditDf.empty:
  1716. creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '贷记卡最近一次还款日期距今时长'] = cip.getLastPayDateMinDays(
  1717. creditDf, reportTime)
  1718. paySo = np.sum(creditDf['本月应还款'])
  1719. if (paySo) != 0:
  1720. creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '贷记卡还款比例'] = round(
  1721. np.sum(creditDf['本月实还款']) / np.sum(creditDf['本月应还款']), 2)
  1722. creditDfTmp = creditDf[creditDf['本月应还款'] > 0]
  1723. creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '贷记卡最高还款比例'] = round(
  1724. np.max(np.divide(creditDfTmp['本月实还款'], creditDfTmp['本月应还款'])), 2)
  1725. creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '贷记卡最低还款比例'] = round(
  1726. np.min(np.divide(creditDfTmp['本月实还款'], creditDfTmp['本月应还款'])), 2)
  1727. #贷记卡疑似分期笔数 汇算
  1728. installmentDf = creditDf[(creditDf['本月实还款']>0) & (creditDf['本月应还款']>200) &(creditDf['本月实还款']< creditDf['本月应还款']/9)]
  1729. otherDf.loc[otherIndex, '贷记卡疑似分期笔数'] = installmentDf.index.size
  1730. normalDf = df[(df['币种'] == '人民币元') & (df['账户状态'] == '正常') & (df['当前逾期期数'] == 0)];
  1731. activeDf = df[(df['币种'] == '人民币元') & (df['账户状态'] == '正常')];
  1732. notCloseDf = df[(df['账户状态'] != '销户')]
  1733. creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '当前正常贷记卡账户数'] = normalDf.index.size
  1734. if not notCloseDf.empty and not normalDf.empty:
  1735. creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '当前正常贷记卡账户数占比'] = round(
  1736. normalDf.index.size / notCloseDf.index.size, 2)
  1737. creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '当前正常贷记卡已用额度'] = np.sum(normalDf['已用额度'])
  1738. creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '当前正常且有余额的贷记卡账户数'] = normalDf[
  1739. normalDf['已用额度'] > 0].index.size
  1740. if not creditDf.empty:
  1741. creditUseAmt = np.sum(creditDf['已用额度'])
  1742. if creditUseAmt != 0:
  1743. creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '当前正常贷记卡账户余额占总余额比'] = round(
  1744. np.sum(normalDf['已用额度']) / np.sum(creditDf['已用额度']), 2)
  1745. if notCloseDf.empty:
  1746. creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '当前正常且有余额的贷记卡账户数占比'] = -99
  1747. else:
  1748. creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '当前正常且有余额的贷记卡账户数占比'] = \
  1749. round(creditCardAccountInfoDf.loc[
  1750. creditCardAccountInfoIndex, '当前正常且有余额的贷记卡账户数'] / notCloseDf.index.size, 3)
  1751. # 当前正常贷记卡账户余额占总余额比
  1752. creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '当前贷记卡本月实还金额总和'] = np.sum(creditDf['本月实还款'])
  1753. creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '当前贷记卡本月应还金额总和'] = np.sum(creditDf['本月应还款'])
  1754. maxAmtDf = df[(df['币种'] == '人民币元')]
  1755. if not maxAmtDf.empty:
  1756. maxAmtDf = maxAmtDf.reset_index(drop=True)
  1757. maxAmtIndex = np.argmax(maxAmtDf['账户授信额度'])
  1758. maxOpenDate = maxAmtDf.loc[maxAmtIndex, :]['开立日期'];
  1759. creditCardAccountInfoDf.loc[
  1760. creditCardAccountInfoIndex, '额度最高的人民币贷记卡开卡距今月份数'] = utils.difMonthReportTime(maxOpenDate,reportTime);
  1761. # 名下贷记卡数量-状态正常
  1762. creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '名下贷记卡数量-状态正常'] = df[
  1763. (df['账户状态'] != '销户')].index.size
  1764. # 名下贷记卡数量-状态未激活
  1765. creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '名下贷记卡数量-状态未激活'] = df[
  1766. (df['账户状态'] == '未激活')].index.size
  1767. # 名下贷记卡数量-状态异常异常包含(2-冻结,3-止付,5-呆帐,10-其他)
  1768. abnormalList = ['冻结', '止付', '呆账', '司法追偿']#原来为其他
  1769. creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '名下贷记卡数量-状态异常'] = df[(df['账户状态'].isin(abnormalList))].index.size
  1770. # 名下贷记卡比例-状态正常
  1771. creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '名下贷记卡比例-状态正常'] = round(
  1772. creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '名下贷记卡数量-状态正常'] / df.index.size, 2)
  1773. # 名下贷记卡比例-状态未激活
  1774. creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '名下贷记卡比例-状态未激活'] = round(
  1775. creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '名下贷记卡数量-状态未激活'] / df.index.size, 2)
  1776. # 名下贷记卡比例-状态异常
  1777. creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '名下贷记卡比例-状态异常'] = round(
  1778. creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '名下贷记卡数量-状态异常'] / df.index.size, 2)
  1779. #1113汇算
  1780. abnormalList = ['冻结', '止付', '呆账', '司法追偿']
  1781. otherDf.loc[otherIndex, "贷记卡状态为('呆账','冻结','止付','司法追偿')的账户数"] = df[(df['账户状态'].isin(abnormalList))].index.size
  1782. availableCreditDf = activeDf[activeDf['最近6个月平均使用额度'] > 500] #正常的信用卡
  1783. otherDf.loc[otherIndex, '有效信用卡张数'] = availableCreditDf.index.size
  1784. #使用中的所有贷记卡中发卡时间距征信查询时间的最大天数 0111三寿
  1785. if not activeDf.empty:
  1786. fstDate = np.min(activeDf['开立日期']);
  1787. sanshouDf.loc[sanshouIndex,"使用中贷记卡最早发卡天数"]=utils.difDateReportTime(reportTime, fstDate)
  1788. # 解析准贷记卡账户信息指标
  1789. def parseCreditCardMergeDfZ(self,df, payRcd):
  1790. if not df.empty:
  1791. overdueCreditCardRcdDf = payRcd[payRcd['账户编号'].isin(df['账户编号'].values)];
  1792. overdueCreditCardRcdDf = utils.replacePayRcdStatusOverdue(overdueCreditCardRcdDf)
  1793. creditCardAccountInfoDfZ.loc[creditCardAccountInfoIndexZ, '本月应还款(合计)'] = np.nansum(df['透支余额'])
  1794. creditCardAccountInfoDfZ.loc[creditCardAccountInfoIndexZ, '本月实还款(合计)'] = np.nansum(df['本月实还款'])
  1795. creditCardAccountInfoDfZ.loc[creditCardAccountInfoIndexZ, '最近一次还款日期'] = np.nanmax(df['最近一次还款日期'])
  1796. creditCardAccountInfoDfZ.loc[creditCardAccountInfoIndexZ, '当前一共透支期数'] = cip.getCurOverdueNum(
  1797. overdueCreditCardRcdDf);
  1798. creditCardAccountInfoDfZ.loc[creditCardAccountInfoIndexZ, '当前一共透支总额'] = np.nansum(df['透支余额'])
  1799. creditCardAccountInfoDfZ.loc[creditCardAccountInfoIndexZ, '透支180天以上未支付余额(合计)'] = np.nansum(
  1800. df['透支180天以上未付余额'])
  1801. # 名下贷记卡数量-状态异常异常包含(2-冻结,3-止付,5-呆帐,10-其他)
  1802. abnormalList = ['冻结', '止付', '呆账', '其他']
  1803. creditCardAccountInfoDfZ.loc[creditCardAccountInfoIndexZ, '名下准贷记卡数量-状态异常'] = df[(df['账户状态'].isin(abnormalList))].index.size
  1804. creditDf = df[(df['账户状态'] != '未激活') & (df['账户状态'] != '销户')]
  1805. if not creditDf.empty:
  1806. totalAmt = np.nansum(creditDf['账户授信额度'])
  1807. creditAmt = np.nansum(creditDf['透支余额'])
  1808. if totalAmt != 0:
  1809. # 从“贷记卡信息”中提取,剔除未激活、销户后,所有账户透支金额/所有账户账户授信额度。
  1810. creditCardAccountInfoDfZ.loc[creditCardAccountInfoIndexZ, '全部准贷记卡账户当前总额度使用率'] = round(
  1811. creditAmt / totalAmt, 2)
  1812. # 从“贷记卡信息”中提取,剔除未激活、销户后,MAX(单账户最高透支金额/单账户授信额度)
  1813. creditMaxDf = creditDf[creditDf['账户授信额度'] > 0]
  1814. if not creditMaxDf.empty:
  1815. creditMaxDf = creditMaxDf.fillna(0.0)
  1816. creditCardAccountInfoDfZ.loc[creditCardAccountInfoIndexZ, '准贷记卡账户最高使用额度总的使用率'] = round(
  1817. np.max(np.divide(creditMaxDf['最大透支余额'], creditMaxDf['账户授信额度'])), 2)
  1818. creditMaxDf = creditDf[creditDf['最大透支余额'] > 0]
  1819. if not creditMaxDf.empty:
  1820. creditCardAccountInfoDfZ.loc[creditCardAccountInfoIndexZ, '当前准贷记卡最大透支金额'] = np.max(
  1821. creditMaxDf['最大透支余额'])
  1822. # 从“贷记卡信息”中提取,剔除未激活、销户后,当前透支准贷记卡账户数/总准贷记卡账户数,透支账户判断:透支余额不为0的账户
  1823. creditDfTmp = creditDf[creditDf['透支余额'] > 0]
  1824. creditCardAccountInfoDfZ.loc[creditCardAccountInfoIndexZ, '当前准贷记卡透支账户数占比'] = round(
  1825. creditDfTmp.index.size / creditDf.index.size, 2)
  1826. creditCardAccountInfoDfZ.loc[creditCardAccountInfoIndexZ, '当前准贷记卡本月应还金额总和'] = np.nansum(df['透支余额'])
  1827. creditCardAccountInfoDfZ.loc[creditCardAccountInfoIndexZ, '当前准贷记卡本月实还金额总和'] = np.nansum(df['本月实还款'])
  1828. # 解析使用率 TODO 使用汇总计算还是使用明细计算
  1829. def parseUseRate(self):
  1830. # useRateDf.loc[useRateIndex, '贷记卡账户使用率(已用额度/授信总额)']
  1831. # 从“信贷交易授信及负债信息概要”中“非循环贷账户信息汇总”、“循环额度下分账户信息汇总”、“循环贷账户信息汇总”、“贷记卡账户信息汇总”和“准贷记卡账户信息汇总”里提取,SUM(
  1832. # 所有“余额”、“已用额度”和“透支余额”) / SUM(所有“授信总额”和“授信额度”)
  1833. loanUseAmt = briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '非循环贷账户余额']
  1834. cycleCreditUseAmt = briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '循环额度下分账户余额']
  1835. cycleUseAmt = briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '循环贷账户余额']
  1836. creditUseAmt = briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '贷记卡已用额度']
  1837. creditAmtUseZ = briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '准贷记卡已用额度']
  1838. loanTotalAmt = briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '非循环贷账户授信总额']
  1839. cycleCreditTotalAmt = briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '循环额度下分账户授信总额']
  1840. cycleTotalAmt = briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '循环贷账户授信总额']
  1841. creditTotalAmt = briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '贷记卡授信总额']
  1842. creditAmtTotalZ = briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '准贷记卡授信总额']
  1843. # if str(loanUseAmt)=="nan":
  1844. # loanUseAmt = 0;
  1845. # if str(cycleCreditUseAmt) == "nan":
  1846. # loanUseAmt = 0;
  1847. # if str(cycleCreditUseAmt) == "nan":
  1848. # loanUseAmt = 0;
  1849. useAmt = loanUseAmt + cycleCreditUseAmt + cycleUseAmt + creditUseAmt + creditAmtUseZ
  1850. totalAmt = loanTotalAmt + cycleCreditTotalAmt + cycleTotalAmt + creditTotalAmt + creditAmtTotalZ
  1851. if totalAmt != 0:
  1852. useRateDf.loc[useRateIndex, '全账户使用率(已用额度/授信总额)'] = round(useAmt / totalAmt, 2)
  1853. if loanTotalAmt != 0:
  1854. useRateDf.loc[useRateIndex, '非循环贷账户使用率(已用额度/授信总额)'] = round(loanUseAmt / loanTotalAmt, 2)
  1855. if cycleCreditTotalAmt != 0:
  1856. useRateDf.loc[useRateIndex, '循环额度下分账户使用率(已用额度/授信总额)'] = round(cycleCreditTotalAmt / cycleCreditTotalAmt, 2)
  1857. if cycleTotalAmt != 0:
  1858. useRateDf.loc[useRateIndex, '循环贷账户使用率(已用额度/授信总额)'] = round(cycleUseAmt / cycleTotalAmt, 2)
  1859. if creditTotalAmt != 0:
  1860. useRateDf.loc[useRateIndex, '贷记卡账户使用率(已用额度/授信总额)'] = round(creditUseAmt / creditTotalAmt, 2)
  1861. if creditAmtTotalZ != 0:
  1862. useRateDf.loc[useRateIndex, '准贷记卡账户使用率(已用额度/授信总额)'] = round(creditAmtUseZ / creditAmtTotalZ, 2)
  1863. # 解析开户数
  1864. def parseOpenAccount(self,loanDf, creditCardDf, creditCardDfZ, recoveryInfoMergeDf, loanPayRecordMergeDf,
  1865. creditCardPayRecordMergeDf, creditCardPayRecordMergeDfZ,reportTime):
  1866. openAccountDf.loc[openAccountIndex, '近3个月全账户开户数'] = cip.getOpenAccount(loanDf, reportTime,
  1867. 3) + cip.getOpenAccount(creditCardDf,
  1868. reportTime,
  1869. 3) + cip.getOpenAccount(
  1870. creditCardDfZ, reportTime, 3)
  1871. openAccountDf.loc[openAccountIndex, '近6个月全账户开户数'] = cip.getOpenAccount(loanDf, reportTime,
  1872. 6) + cip.getOpenAccount(creditCardDf,
  1873. reportTime,
  1874. 6) + cip.getOpenAccount(
  1875. creditCardDfZ, reportTime, 6)
  1876. openAccountDf.loc[openAccountIndex, '近9个月全账户开户数'] = cip.getOpenAccount(loanDf, reportTime,
  1877. 9) + cip.getOpenAccount(creditCardDf,
  1878. reportTime,
  1879. 9) + cip.getOpenAccount(
  1880. creditCardDfZ, reportTime, 9)
  1881. openAccountDf.loc[openAccountIndex, '近12个月全账户开户数'] = cip.getOpenAccount(loanDf, reportTime,
  1882. 12) + cip.getOpenAccount(creditCardDf,
  1883. reportTime,
  1884. 12) + cip.getOpenAccount(
  1885. creditCardDfZ, reportTime, 12)
  1886. openAccountDf.loc[openAccountIndex, '近24个月全账户开户数'] = cip.getOpenAccount(loanDf, reportTime,
  1887. 24) + cip.getOpenAccount(creditCardDf,
  1888. reportTime,
  1889. 24) + cip.getOpenAccount(
  1890. creditCardDfZ, reportTime, 24)
  1891. openAccountDf.loc[openAccountIndex, '近3个月消费金融类账户开户数'] = lip.getOpenAccount(loanDf, reportTime, 3,
  1892. consts.bankList)
  1893. openAccountDf.loc[openAccountIndex, '近6个月消费金融类账户开户数'] = lip.getOpenAccount(loanDf, reportTime, 6,
  1894. consts.bankList)
  1895. openAccountDf.loc[openAccountIndex, '近9个月消费金融类账户开户数'] = lip.getOpenAccount(loanDf, reportTime, 9,
  1896. consts.bankList)
  1897. openAccountDf.loc[openAccountIndex, '近12个月消费金融类账户开户数'] = lip.getOpenAccount(loanDf, reportTime, 12,
  1898. consts.bankList)
  1899. openAccountDf.loc[openAccountIndex, '近24个月消费金融类账户开户数'] = lip.getOpenAccount(loanDf, reportTime, 24,
  1900. consts.bankList)
  1901. openAccountDf.loc[openAccountIndex, '近3个月贷款账户开户数'] = lip.getOpenAccount(loanDf, reportTime, 3, "")
  1902. openAccountDf.loc[openAccountIndex, '近6个月贷款账户开户数'] = lip.getOpenAccount(loanDf, reportTime, 6, "")
  1903. openAccountDf.loc[openAccountIndex, '近9个月贷款账户开户数'] = lip.getOpenAccount(loanDf, reportTime, 9, "")
  1904. openAccountDf.loc[openAccountIndex, '近12个月贷款账户开户数'] = lip.getOpenAccount(loanDf, reportTime, 12, "")
  1905. openAccountDf.loc[openAccountIndex, '近24个月贷款账户开户数'] = lip.getOpenAccount(loanDf, reportTime, 24, "")
  1906. openAccountDf.loc[openAccountIndex, '近3个月贷记卡账户开户数'] = cip.getOpenAccount(creditCardDf, reportTime, 3)
  1907. openAccountDf.loc[openAccountIndex, '近6个月贷记卡账户开户数'] = cip.getOpenAccount(creditCardDf, reportTime, 6)
  1908. openAccountDf.loc[openAccountIndex, '近9个月贷记卡账户开户数'] = cip.getOpenAccount(creditCardDf, reportTime, 9)
  1909. openAccountDf.loc[openAccountIndex, '近12个月贷记卡账户开户数'] = cip.getOpenAccount(creditCardDf, reportTime, 12)
  1910. openAccountDf.loc[openAccountIndex, '近24个月贷记卡账户开户数'] = cip.getOpenAccount(creditCardDf, reportTime, 24)
  1911. openAccountDf.loc[openAccountIndex, '近3个月准贷记卡账户开户数'] = cip.getOpenAccount(creditCardDfZ, reportTime, 3)
  1912. openAccountDf.loc[openAccountIndex, '近6个月准贷记卡账户开户数'] = cip.getOpenAccount(creditCardDfZ, reportTime, 6)
  1913. openAccountDf.loc[openAccountIndex, '近9个月准贷记卡账户开户数'] = cip.getOpenAccount(creditCardDfZ, reportTime, 9)
  1914. openAccountDf.loc[openAccountIndex, '近12个月准贷记卡账户开户数'] = cip.getOpenAccount(creditCardDfZ, reportTime, 12)
  1915. openAccountDf.loc[openAccountIndex, '近24个月准贷记卡账户开户数'] = cip.getOpenAccount(creditCardDfZ, reportTime, 24)
  1916. #三寿
  1917. sanshouDf.loc[sanshouIndex, '最近24M发卡数量'] = cip.getOpenAccount(creditCardDf, reportTime, 24)+cip.getOpenAccount(creditCardDfZ, reportTime, 24)
  1918. # 从“信贷交易信息明细”中“非循环贷账户”、“循环额度下分账户”、“循环贷账户”、“贷记卡账户”和“准贷记卡账户”里提取,5年里账户还款状态出现“1、2、3、4、5、6、7、D、Z、G、B”的账户数/所有账户数
  1919. overdueLoanPayRcdDf = loanPayRecordMergeDf[loanPayRecordMergeDf['账户编号'].isin(loanDf['账户编号'].values)]
  1920. overdueLoanPayRcdDf = utils.replacePayRcdStatusOverdue(overdueLoanPayRcdDf)
  1921. overdueLoanPayRcdDf = overdueLoanPayRcdDf[overdueLoanPayRcdDf['还款状态'] > 0]
  1922. overdueCreditPayRcdDf = creditCardPayRecordMergeDf[
  1923. creditCardPayRecordMergeDf['账户编号'].isin(creditCardDf['账户编号'].values)]
  1924. overdueCreditPayRcdDf = utils.replacePayRcdStatusOverdue(overdueCreditPayRcdDf)
  1925. overdueCreditPayRcdDf = overdueCreditPayRcdDf[overdueCreditPayRcdDf['还款状态'] > 0]
  1926. overdueCreditPayRcdDfZ = creditCardPayRecordMergeDfZ[
  1927. creditCardPayRecordMergeDfZ['账户编号'].isin(creditCardDfZ['账户编号'].values)]
  1928. overdueCreditPayRcdDfZ = utils.replacePayRcdStatusOverdue(overdueCreditPayRcdDfZ)
  1929. overdueCreditPayRcdDfZ = overdueCreditPayRcdDfZ[overdueCreditPayRcdDfZ['还款状态'] > 0]
  1930. loanAccountNum = loanPayRecordMergeDf['账户编号'].unique().size
  1931. creditAccountNum = creditCardPayRecordMergeDf['账户编号'].unique().size
  1932. creditAccountNumZ = creditCardPayRecordMergeDfZ['账户编号'].unique().size
  1933. overdueLoanNum = overdueLoanPayRcdDf['账户编号'].unique().size
  1934. overdueCreditNum = overdueCreditPayRcdDf['账户编号'].unique().size
  1935. overdueCreditNumZ = overdueCreditPayRcdDfZ['账户编号'].unique().size
  1936. if (loanAccountNum + creditAccountNum + creditAccountNumZ) > 0:
  1937. openAccountDf.loc[openAccountIndex, '有过逾期记录的账户/全账户数'] = round(
  1938. (overdueLoanNum + overdueCreditNum + overdueCreditNumZ) / (
  1939. loanAccountNum + creditAccountNum + creditAccountNumZ), 2)
  1940. otherPerLoanDf = loanDf[loanDf['业务种类'].isin(consts.bankList)]
  1941. otherPerLoanNum = otherPerLoanDf.index.size;
  1942. overdueOtherPerLoanNum = otherPerLoanDf[
  1943. otherPerLoanDf['账户编号'].isin(overdueLoanPayRcdDf['账户编号'].values)].index.size;
  1944. if otherPerLoanNum != 0:
  1945. openAccountDf.loc[openAccountIndex, '有过逾期记录的消费金融类账户/全消费金融类账户数'] = round(
  1946. overdueOtherPerLoanNum / otherPerLoanNum, 2)
  1947. if loanAccountNum != 0:
  1948. openAccountDf.loc[openAccountIndex, '有过逾期记录的贷款账户/全贷款账户数'] = round(overdueLoanNum / loanAccountNum, 2)
  1949. if creditAccountNum != 0:
  1950. openAccountDf.loc[openAccountIndex, '有过逾期记录的贷记卡账户/全贷记卡账户数'] = round(overdueCreditNum / creditAccountNum, 2)
  1951. if creditAccountNumZ != 0:
  1952. openAccountDf.loc[openAccountIndex, '有过透支记录的准贷记卡账户/全准贷记卡账户数'] = round(overdueCreditNumZ / creditAccountNumZ,
  1953. 2)
  1954. # 0525新增
  1955. pledgeLoanDf = loanDf[loanDf['担保方式'] == '抵押']
  1956. pledgeCreditCardDf = creditCardDf[creditCardDf['担保方式'] == '抵押']
  1957. pledgeCreditCardDfZ = creditCardDfZ[creditCardDfZ['担保方式'] == '抵押']
  1958. isPledge = "否"
  1959. if pledgeLoanDf.index.size + pledgeCreditCardDf.index.size + pledgeCreditCardDfZ.index.size > 0:
  1960. isPledge = "是"
  1961. creditLoanDf = loanDf[loanDf['担保方式'] == '信用/免担保']
  1962. creditCreditCardDf = creditCardDf[creditCardDf['担保方式'] == '信用/免担保']
  1963. creditCreditCardDfZ = creditCardDfZ[creditCardDfZ['担保方式'] == '信用/免担保']
  1964. isCredit = 0
  1965. if creditLoanDf.index.size + creditCreditCardDf.index.size + creditCreditCardDfZ.index.size > 0:
  1966. isCredit = creditLoanDf.index.size + creditCreditCardDf.index.size + creditCreditCardDfZ.index.size
  1967. briefInfoDf_loanTradeInfo.loc[loanTradeInfoIndex, '是否存在担保方式为抵押的贷款'] = isPledge
  1968. briefInfoDf_loanTradeInfo.loc[loanTradeInfoIndex, '担保方式为信用的贷款数量'] = isCredit
  1969. #使用中贷记卡平均发卡天数
  1970. try:
  1971. sanshouDf.loc[sanshouIndex, '使用中贷记卡平均发卡天数'] = cip.getAvgUseCreditCardDay(creditCardDf,creditCardDfZ,reportTime)
  1972. sanshouDf.loc[sanshouIndex, '最大信用账户天数(贷款&贷记卡人民账户)'] = cip.getMaxAmtAccountDay(loanDf,creditCardDf,creditCardDfZ ,reportTime)
  1973. sanshouDf.loc[sanshouIndex, '额度使用>=50%的贷记卡数'] = cip.getUseRateCount(creditCardDf,creditCardDfZ,0.5)
  1974. sanshouDf.loc[sanshouIndex, '额度使用>=75%的贷记卡数'] = cip.getUseRateCount(creditCardDf, creditCardDfZ, 0.75)
  1975. sanshouDf.loc[sanshouIndex, '额度使用>=100%的贷记卡数'] = cip.getUseRateCount(creditCardDf, creditCardDfZ, 1)
  1976. minMonthStr = ""
  1977. if otherDf.loc[otherIndex, '首笔贷款发放月份']=='' and otherDf.loc[otherIndex, '首张贷记卡发卡月份']!='':
  1978. minMonthStr = otherDf.loc[otherIndex, '首张贷记卡发卡月份']
  1979. elif otherDf.loc[otherIndex, '首笔贷款发放月份']!='' and otherDf.loc[otherIndex, '首张贷记卡发卡月份']!='':
  1980. minMonth = [otherDf.loc[otherIndex, '首笔贷款发放月份'], otherDf.loc[otherIndex, '首张贷记卡发卡月份']]
  1981. minMonthStr = min(minMonth)
  1982. elif otherDf.loc[otherIndex, '首笔贷款发放月份']!='' and otherDf.loc[otherIndex, '首张贷记卡发卡月份']=='':
  1983. minMonthStr = otherDf.loc[otherIndex, '首笔贷款发放月份']
  1984. sanshouDf.loc[sanshouIndex, '贷款、贷记卡最大天数'] = utils.difDateReportTime(reportTime, minMonthStr)
  1985. if not loanDf.empty:
  1986. openAccount3MDf = loanDf[loanDf['开立日期'] < utils.getLastMonthDate(reportTime, 6)]
  1987. sanshouDf.loc[sanshouIndex, '开户180天以上的贷款笔数'] = openAccount3MDf.index.size
  1988. if not creditCardDf.empty:
  1989. sanshouDf.loc[sanshouIndex, '开户1年以内历史逾期90+贷记卡和准贷记卡数'] =cip.getOverDueCount(creditCardDf,creditCardPayRecordMergeDf,reportTime,3,12)\
  1990. +cip.getOverDueCount(creditCardDfZ,creditCardPayRecordMergeDfZ,reportTime,3,12)
  1991. sanshouDf.loc[sanshouIndex, '开户1年以内历史逾期贷记卡和准贷记卡数'] = cip.getOverDueCount(creditCardDf,creditCardPayRecordMergeDf,reportTime, 1, 12)\
  1992. +cip.getOverDueCount(creditCardDfZ, creditCardPayRecordMergeDfZ, reportTime, 1, 12)
  1993. sanshouDf.loc[sanshouIndex, '开户2年以内历史逾期贷记卡数'] = cip.getOverDueCount(creditCardDf,creditCardPayRecordMergeDf,reportTime, 1, 24)
  1994. except:
  1995. logger.error(traceback.print_exc())
  1996. logger.error(traceback.format_exc())
  1997. # 解析24期还款状态指标
  1998. def parsePayRcdStatus(self,loanMergeDf, creditCardMergeDf, creditCardMergeDfZ, loanPayRecordMergeDf,
  1999. creditCardPayRecordMergeDf, creditCardPayRecordMergeDfZ,reportTime):
  2000. # creditCardPayRecordMergeDf
  2001. # 去掉外币
  2002. creditCardMergeDf = creditCardMergeDf[creditCardMergeDf['币种'] == '人民币元']
  2003. creditCardPayRecordMergeDf = creditCardPayRecordMergeDf[
  2004. creditCardPayRecordMergeDf['账户编号'].isin(creditCardMergeDf['账户编号'].values)]
  2005. reportTime = str(np.datetime64(reportTime, "M")) + "-02" # 06-02,统计24期还款状态报告期,按每月的2号,避免chu'xian
  2006. payRcdStatusDf.loc[payRcdStatusIndex, '贷款账户近3月逾期期数大于或等于“1”的次数'] = prp.getLoanOverdueTimes(loanPayRecordMergeDf,
  2007. reportTime, 1, 3)
  2008. payRcdStatusDf.loc[payRcdStatusIndex, '贷款账户近6月逾期期数大于或等于“1”的次数'] = prp.getLoanOverdueTimes(loanPayRecordMergeDf,
  2009. reportTime, 1, 6)
  2010. payRcdStatusDf.loc[payRcdStatusIndex, '贷款账户近12月逾期期数大于或等于“1”的次数'] = prp.getLoanOverdueTimes(loanPayRecordMergeDf,
  2011. reportTime, 1, 12)
  2012. payRcdStatusDf.loc[payRcdStatusIndex, '贷款账户近24月逾期期数大于或等于“1”的次数'] = prp.getLoanOverdueTimes(loanPayRecordMergeDf,
  2013. reportTime, 1, 24)
  2014. payRcdStatusDf.loc[payRcdStatusIndex, '贷款账户近6月逾期期数大于或等于“2”的次数'] = prp.getLoanOverdueTimes(loanPayRecordMergeDf,
  2015. reportTime, 2, 6)
  2016. payRcdStatusDf.loc[payRcdStatusIndex, '贷款账户近12月逾期期数大于或等于“2”的次数'] = prp.getLoanOverdueTimes(loanPayRecordMergeDf,
  2017. reportTime, 2, 12)
  2018. payRcdStatusDf.loc[payRcdStatusIndex, '贷款账户近24月逾期期数大于或等于“2”的次数'] = prp.getLoanOverdueTimes(loanPayRecordMergeDf,
  2019. reportTime, 2, 24)
  2020. payRcdStatusDf.loc[payRcdStatusIndex, '贷款账户近6月逾期期数大于或等于“3”的次数'] = prp.getLoanOverdueTimes(loanPayRecordMergeDf,
  2021. reportTime, 3, 6)
  2022. payRcdStatusDf.loc[payRcdStatusIndex, '贷款账户近12月逾期期数大于或等于“3”的次数'] = prp.getLoanOverdueTimes(loanPayRecordMergeDf,
  2023. reportTime, 3, 12)
  2024. payRcdStatusDf.loc[payRcdStatusIndex, '贷款账户近24月逾期期数大于或等于“3”的次数'] = prp.getLoanOverdueTimes(loanPayRecordMergeDf,
  2025. reportTime, 3, 24)
  2026. payRcdStatusDf.loc[payRcdStatusIndex, '贷款账户近12月逾期期数大于或大等于“4”的次数'] = prp.getLoanOverdueTimes(
  2027. loanPayRecordMergeDf, reportTime, 4, 12)
  2028. payRcdStatusDf.loc[payRcdStatusIndex, '贷款账户近24月逾期期数大于或等于“4”的次数'] = prp.getLoanOverdueTimes(loanPayRecordMergeDf,
  2029. reportTime, 4, 24)
  2030. payRcdStatusDf.loc[payRcdStatusIndex, '贷记卡账户近3月逾期期数大于或等于“1”的次数'] = cip.getLoanOverdueTimes(
  2031. creditCardPayRecordMergeDf, reportTime, 1, 3)
  2032. payRcdStatusDf.loc[payRcdStatusIndex, '贷记卡账户近6月逾期期数大于或等于“1”的次数'] = cip.getLoanOverdueTimes(
  2033. creditCardPayRecordMergeDf, reportTime, 1, 6)
  2034. payRcdStatusDf.loc[payRcdStatusIndex, '贷记卡账户近12月逾期期数大于或等于“1”的次数'] = cip.getLoanOverdueTimes(
  2035. creditCardPayRecordMergeDf, reportTime, 1, 12)
  2036. payRcdStatusDf.loc[payRcdStatusIndex, '贷记卡账户近24月逾期期数大于或等于“1”的次数'] = cip.getLoanOverdueTimes(
  2037. creditCardPayRecordMergeDf, reportTime, 1, 24)
  2038. payRcdStatusDf.loc[payRcdStatusIndex, '贷记卡账户近6月逾期期数大于或等于“2”的次数'] = cip.getLoanOverdueTimes(
  2039. creditCardPayRecordMergeDf, reportTime, 2, 6)
  2040. payRcdStatusDf.loc[payRcdStatusIndex, '贷记卡账户近12月逾期期数大于或等于“2”的次数'] = cip.getLoanOverdueTimes(
  2041. creditCardPayRecordMergeDf, reportTime, 2, 12)
  2042. payRcdStatusDf.loc[payRcdStatusIndex, '贷记卡账户近24月逾期期数大于或等于“2”的次数'] = cip.getLoanOverdueTimes(
  2043. creditCardPayRecordMergeDf, reportTime, 2, 24)
  2044. payRcdStatusDf.loc[payRcdStatusIndex, '贷记卡账户近6月逾期期数大于或等于“3”的次数'] = cip.getLoanOverdueTimes(
  2045. creditCardPayRecordMergeDf, reportTime, 3, 6)
  2046. payRcdStatusDf.loc[payRcdStatusIndex, '贷记卡账户近12月逾期期数大于或等于“3”的次数'] = cip.getLoanOverdueTimes(
  2047. creditCardPayRecordMergeDf, reportTime, 3, 12)
  2048. payRcdStatusDf.loc[payRcdStatusIndex, '贷记卡账户近24月逾期期数大于或等于“3”的次数'] = cip.getLoanOverdueTimes(
  2049. creditCardPayRecordMergeDf, reportTime, 3, 24)
  2050. payRcdStatusDf.loc[payRcdStatusIndex, '贷记卡账户近12月逾期期数大于或等于“4”的次数'] = cip.getLoanOverdueTimes(
  2051. creditCardPayRecordMergeDf, reportTime, 4, 12)
  2052. payRcdStatusDf.loc[payRcdStatusIndex, '贷记卡账户近24月逾期期数大于或等于“4”的次数'] = cip.getLoanOverdueTimes(
  2053. creditCardPayRecordMergeDf, reportTime, 4, 24)
  2054. payRcdStatusDf.loc[payRcdStatusIndex, '准贷记卡账户近6月逾期期数大于或等于“3”的次数'] = cip.getLoanOverdueTimes(
  2055. creditCardPayRecordMergeDfZ, reportTime, 3, 6)
  2056. payRcdStatusDf.loc[payRcdStatusIndex, '准贷记卡账户近12月逾期期数大于或等于“3”的次数'] = cip.getLoanOverdueTimes(
  2057. creditCardPayRecordMergeDfZ, reportTime, 3, 12)
  2058. payRcdStatusDf.loc[payRcdStatusIndex, '准贷记卡账户近24月逾期期数大于或等于“3”的次数'] = cip.getLoanOverdueTimes(
  2059. creditCardPayRecordMergeDfZ, reportTime, 3, 24)
  2060. payRcdStatusDf.loc[payRcdStatusIndex, '准贷记卡账户近6月逾期期数大于或等于“4”的次数'] = cip.getLoanOverdueTimes(
  2061. creditCardPayRecordMergeDfZ, reportTime, 4, 6)
  2062. payRcdStatusDf.loc[payRcdStatusIndex, '准贷记卡账户近12月逾期期数大于或等于“4”的次数'] = cip.getLoanOverdueTimes(
  2063. creditCardPayRecordMergeDfZ, reportTime, 4, 12)
  2064. payRcdStatusDf.loc[payRcdStatusIndex, '准贷记卡账户近24月逾期期数大于或等于“4”的次数'] = cip.getLoanOverdueTimes(
  2065. creditCardPayRecordMergeDfZ, reportTime, 4, 24)
  2066. payRcdStatusDf.loc[payRcdStatusIndex, '全账户近3月逾期期数大于或等于“1”的次数'] = prp.getLoanOverdueTimes(loanPayRecordMergeDf,
  2067. reportTime, 1, 3) \
  2068. + cip.getLoanOverdueTimes(
  2069. creditCardPayRecordMergeDf, reportTime, 1, 3) + cip.getLoanOverdueTimes(creditCardPayRecordMergeDfZ,
  2070. reportTime, 1, 3)
  2071. payRcdStatusDf.loc[payRcdStatusIndex, '全账户近6月逾期期数大于或等于“1”的次数'] = \
  2072. prp.getLoanOverdueTimes(loanPayRecordMergeDf, reportTime, 1, 6) + cip.getLoanOverdueTimes(
  2073. creditCardPayRecordMergeDf, reportTime, 1, 6) \
  2074. + cip.getLoanOverdueTimes(creditCardPayRecordMergeDfZ, reportTime, 1, 6)
  2075. payRcdStatusDf.loc[payRcdStatusIndex, '全账户近12月逾期期数大于或等于“1”的次数'] = \
  2076. prp.getLoanOverdueTimes(loanPayRecordMergeDf, reportTime, 1, 12) + cip.getLoanOverdueTimes(
  2077. creditCardPayRecordMergeDf, reportTime, 1, 12) \
  2078. + cip.getLoanOverdueTimes(creditCardPayRecordMergeDfZ, reportTime, 1, 12)
  2079. payRcdStatusDf.loc[payRcdStatusIndex, '全账户近24月逾期期数大于或等于“1”的次数'] = \
  2080. prp.getLoanOverdueTimes(loanPayRecordMergeDf, reportTime, 1, 24) + cip.getLoanOverdueTimes(
  2081. creditCardPayRecordMergeDf, reportTime, 1, 24) \
  2082. + cip.getLoanOverdueTimes(creditCardPayRecordMergeDfZ, reportTime, 1, 24)
  2083. payRcdStatusDf.loc[payRcdStatusIndex, '全账户近6月逾期期数大于或等于“2”的次数'] = \
  2084. prp.getLoanOverdueTimes(loanPayRecordMergeDf, reportTime, 2, 6) + cip.getLoanOverdueTimes(
  2085. creditCardPayRecordMergeDf, reportTime, 2, 6) \
  2086. + cip.getLoanOverdueTimes(creditCardPayRecordMergeDfZ, reportTime, 2, 6)
  2087. payRcdStatusDf.loc[payRcdStatusIndex, '全账户近12月逾期期数大于或等于“2”的次数'] = \
  2088. prp.getLoanOverdueTimes(loanPayRecordMergeDf, reportTime, 2, 12) + cip.getLoanOverdueTimes(
  2089. creditCardPayRecordMergeDf, reportTime, 2, 12) \
  2090. + cip.getLoanOverdueTimes(creditCardPayRecordMergeDfZ, reportTime, 2, 12)
  2091. payRcdStatusDf.loc[payRcdStatusIndex, '全账户近24月逾期期数大于或等于“2”的次数'] = \
  2092. prp.getLoanOverdueTimes(loanPayRecordMergeDf, reportTime, 2, 24) + cip.getLoanOverdueTimes(
  2093. creditCardPayRecordMergeDf, reportTime, 2, 24) \
  2094. + cip.getLoanOverdueTimes(creditCardPayRecordMergeDfZ, reportTime, 2, 24)
  2095. payRcdStatusDf.loc[payRcdStatusIndex, '全账户近6月逾期期数大于或等于“3”的次数'] = \
  2096. prp.getLoanOverdueTimes(loanPayRecordMergeDf, reportTime, 3, 6) + cip.getLoanOverdueTimes(
  2097. creditCardPayRecordMergeDf, reportTime, 3, 6) \
  2098. + cip.getLoanOverdueTimes(creditCardPayRecordMergeDfZ, reportTime, 3, 6)
  2099. payRcdStatusDf.loc[payRcdStatusIndex, '全账户近12月逾期期数大于或等于“3”的次数'] = \
  2100. prp.getLoanOverdueTimes(loanPayRecordMergeDf, reportTime, 3, 12) + cip.getLoanOverdueTimes(
  2101. creditCardPayRecordMergeDf, reportTime, 3, 12) \
  2102. + cip.getLoanOverdueTimes(creditCardPayRecordMergeDfZ, reportTime, 3, 12)
  2103. payRcdStatusDf.loc[payRcdStatusIndex, '全账户近24月逾期期数大于或等于“3”的次数'] = \
  2104. prp.getLoanOverdueTimes(loanPayRecordMergeDf, reportTime, 3, 24) + cip.getLoanOverdueTimes(
  2105. creditCardPayRecordMergeDf, reportTime, 3, 24) \
  2106. + cip.getLoanOverdueTimes(creditCardPayRecordMergeDfZ, reportTime, 3, 24)
  2107. payRcdStatusDf.loc[payRcdStatusIndex, '全账户近12月逾期期数大于或等于“4”的次数'] = \
  2108. prp.getLoanOverdueTimes(loanPayRecordMergeDf, reportTime, 4, 12) + cip.getLoanOverdueTimes(
  2109. creditCardPayRecordMergeDf, reportTime, 4, 12) \
  2110. + cip.getLoanOverdueTimes(creditCardPayRecordMergeDfZ, reportTime, 4, 12)
  2111. payRcdStatusDf.loc[payRcdStatusIndex, '全账户近24月逾期期数大于或等于“4”的次数'] = \
  2112. prp.getLoanOverdueTimes(loanPayRecordMergeDf, reportTime, 4, 24) + cip.getLoanOverdueTimes(
  2113. creditCardPayRecordMergeDf, reportTime, 4, 24) \
  2114. + cip.getLoanOverdueTimes(creditCardPayRecordMergeDfZ, reportTime, 4, 24)
  2115. payRcdStatusDf.loc[payRcdStatusIndex, '贷款账户近24个月是否出现"G"'] = prp.isExistsInd(loanPayRecordMergeDf, reportTime,
  2116. "G", 24)
  2117. payRcdStatusDf.loc[payRcdStatusIndex, '贷记卡账户近24个月是否出现"G"'] = prp.isExistsInd(creditCardPayRecordMergeDf,
  2118. reportTime, "G", 24)
  2119. payRcdStatusDf.loc[payRcdStatusIndex, '准贷记卡账户近24个月是否出现"G"'] = prp.isExistsInd(creditCardPayRecordMergeDfZ,
  2120. reportTime, "G", 24)
  2121. payRcdStatusDf.loc[payRcdStatusIndex, '贷款账户近24个月是否出现"Z"'] = prp.isExistsInd(loanPayRecordMergeDf, reportTime,
  2122. "Z", 24)
  2123. payRcdStatusDf.loc[payRcdStatusIndex, '用户所有贷款账户过去24个月存在逾期的账户数目'] = prp.getLoanOverdueCount(loanPayRecordMergeDf,
  2124. reportTime, 24)
  2125. payRcdStatusDf.loc[payRcdStatusIndex, '用户所有贷款账户过去24个月状态正常账户数目'] = prp.getLoanNormalCount(loanPayRecordMergeDf,
  2126. reportTime, 24)
  2127. payRcdStatusDf.loc[payRcdStatusIndex, '用户所有贷记卡账户过去24个月存在逾期的账户数目'] = prp.getLoanOverdueCount(
  2128. creditCardPayRecordMergeDf, reportTime, 24)
  2129. payRcdStatusDf.loc[payRcdStatusIndex, '用户所有贷记卡账户过去24个月状态正常的账户数目'] = prp.getLoanNormalCount(
  2130. creditCardPayRecordMergeDf, reportTime, 24)
  2131. payRcdStatusDf.loc[payRcdStatusIndex, '用户所有准贷记卡账户过去24个月存在逾期的账户数目'] = prp.getLoanOverdueCount(
  2132. creditCardPayRecordMergeDfZ, reportTime, 24)
  2133. payRcdStatusDf.loc[payRcdStatusIndex, '用户所有准贷记卡账户过去24个月状态正常的账户数目'] = prp.getLoanNormalCount(
  2134. creditCardPayRecordMergeDfZ, reportTime, 24)
  2135. payRcdStatusDf.loc[payRcdStatusIndex, '用户过去3个月最大逾期期数'] = prp.getPayRcdMaxOverdueNumAllAccout(
  2136. loanPayRecordMergeDf, creditCardPayRecordMergeDf, creditCardPayRecordMergeDfZ, reportTime, 3)
  2137. payRcdStatusDf.loc[payRcdStatusIndex, '用户过去6个月最大逾期期数'] = prp.getPayRcdMaxOverdueNumAllAccout(
  2138. loanPayRecordMergeDf, creditCardPayRecordMergeDf, creditCardPayRecordMergeDfZ, reportTime, 6)
  2139. payRcdStatusDf.loc[payRcdStatusIndex, '用户过去12个月最大逾期期数'] = prp.getPayRcdMaxOverdueNumAllAccout(
  2140. loanPayRecordMergeDf, creditCardPayRecordMergeDf, creditCardPayRecordMergeDfZ, reportTime, 12)
  2141. payRcdStatusDf.loc[payRcdStatusIndex, '用户过去24个月最大逾期期数'] = prp.getPayRcdMaxOverdueNumAllAccout(
  2142. loanPayRecordMergeDf, creditCardPayRecordMergeDf, creditCardPayRecordMergeDfZ, reportTime, 24)
  2143. # 概要信息里的字段,从还款状态计算
  2144. briefInfoDf_overdueInfoSum.loc[overdueInfoSumIndex, '该用户过去5年出现逾期的所有账户数目'] = \
  2145. prp.getLoanOverdueCount(loanPayRecordMergeDf, reportTime, 24 * 5) + prp.getLoanOverdueCount(
  2146. creditCardPayRecordMergeDf, reportTime, 24 * 5) \
  2147. + prp.getLoanOverdueCount(creditCardPayRecordMergeDfZ, reportTime, 24 * 5)
  2148. #1112
  2149. otherDf.loc[otherIndex, '近12个月最大逾期期数'] = prp.getPayRcdMaxOverdueNumAccout(
  2150. loanPayRecordMergeDf, creditCardPayRecordMergeDf, reportTime, 12)
  2151. # 解析贷记卡还款记录指标
  2152. def parseCreditCardMergeAndPayRecordDf(self,df, payRcdDf,reportTime):
  2153. if not df.empty and not payRcdDf.empty:
  2154. # 正常
  2155. normalDf = df[(df['账户状态'] != '未激活') & (df['账户状态'] != '销户') & (df['账户状态'] != '呆账')]
  2156. if not normalDf.empty:
  2157. overduePayRcdDf = payRcdDf[payRcdDf['账户编号'].isin(normalDf['账户编号'].values)]
  2158. overduePayRcdDf = utils.replacePayRcdStatus(overduePayRcdDf)
  2159. # 计算当前贷款,为还款记录的最后一期 0529
  2160. curOverduePayRcdDf = overduePayRcdDf.sort_values(by=["账户编号", "还款日期"], ascending=(True, False))
  2161. curOverduePayRcdDf = curOverduePayRcdDf.groupby(['账户编号']).head(1)
  2162. curOverduePayRcdDf = curOverduePayRcdDf[curOverduePayRcdDf['还款状态'] > 0]
  2163. # 临时保存,不用过滤还款状态为0的
  2164. payRcdMaxOverdueDf = overduePayRcdDf;
  2165. # overduePayRcdDf = overduePayRcdDf[overduePayRcdDf['还款状态'] > 0]
  2166. # creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '当前贷记卡逾期账户数'] = curOverduePayRcdDf['账户编号'].unique().size
  2167. # 从“贷记卡信息”中提取,剔除“账户状态”为未激活、销户、呆账、呆帐后,“当前信用卡逾期账户数”/未销户贷记卡账户数(剔除“账户状态”为未激活、销户、呆账、呆帐后记录条数)
  2168. creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '当前贷记卡逾期账户数占比'] = round(
  2169. curOverduePayRcdDf['账户编号'].unique().size / normalDf.index.size, 2)
  2170. # 从“贷记卡信息”中提取,剔除“账户状态”为未激活、销户、呆账、呆帐后,对(当前信用卡逾期账户数)按“开户机构代码”去重统计账户状态为逾期,按按“开户机构代码”去重后的记录条数
  2171. overdueCreditCardDf = normalDf[normalDf['账户编号'].isin(curOverduePayRcdDf['账户编号'].values)]
  2172. creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '当前贷记卡逾期机构数'] = overdueCreditCardDf[
  2173. '发卡机构'].unique().size
  2174. creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '当前贷记卡逾期机构数占比'] = round(
  2175. creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '当前贷记卡逾期机构数'] / normalDf[
  2176. '发卡机构'].unique().size, 2)
  2177. creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '近3月贷记卡最大逾期期数'] = cip.getPayRcdMaxOverdueNum(
  2178. payRcdMaxOverdueDf, 3);
  2179. creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '近6月贷记卡最大逾期期数'] = cip.getPayRcdMaxOverdueNum(
  2180. payRcdMaxOverdueDf, 6);
  2181. creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '近9月贷记卡最大逾期期数'] = cip.getPayRcdMaxOverdueNum(
  2182. payRcdMaxOverdueDf, 9);
  2183. creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '近12月贷记卡最大逾期期数'] = cip.getPayRcdMaxOverdueNum(
  2184. payRcdMaxOverdueDf, 12);
  2185. creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '近24月贷记卡最大逾期期数'] = cip.getPayRcdMaxOverdueNum(
  2186. payRcdMaxOverdueDf, 24);
  2187. creditCardAccountInfoDf.loc[
  2188. creditCardAccountInfoIndex, '近24月贷记卡最大逾期距离现在的月数'] = cip.getPayRcdMaxOverdueNumMonth(
  2189. payRcdMaxOverdueDf, normalDf, reportTime, 24);
  2190. creditCardAccountInfoDf.loc[
  2191. creditCardAccountInfoIndex, '最近3个月贷记卡最大连续逾期月份数'] = cip.getContinuousOverdueMonth(payRcdMaxOverdueDf,
  2192. normalDf, 3);
  2193. creditCardAccountInfoDf.loc[
  2194. creditCardAccountInfoIndex, '最近6个月贷记卡最大连续逾期月份数'] = cip.getContinuousOverdueMonth(payRcdMaxOverdueDf,
  2195. normalDf, 6);
  2196. creditCardAccountInfoDf.loc[
  2197. creditCardAccountInfoIndex, '最近9个月贷记卡最大连续逾期月份数'] = cip.getContinuousOverdueMonth(payRcdMaxOverdueDf,
  2198. normalDf, 9);
  2199. creditCardAccountInfoDf.loc[
  2200. creditCardAccountInfoIndex, '最近12个月贷记卡最大连续逾期月份数'] = cip.getContinuousOverdueMonth(
  2201. payRcdMaxOverdueDf, normalDf, 12);
  2202. creditCardAccountInfoDf.loc[
  2203. creditCardAccountInfoIndex, '最近24个月贷记卡最大连续逾期月份数'] = cip.getContinuousOverdueMonth(
  2204. payRcdMaxOverdueDf, normalDf, 24);
  2205. # payRcdTimesDf = payRcdDf[payRcdDf['账户编号'].isin(normalDf['账户编号'].values)]
  2206. # payRcdTimesDf = payRcdTimesDf.sort_values(by=["账户编号", "还款日期"], ascending=(True, False))
  2207. # payRcdTimesDf = payRcdTimesDf.groupby(['账户编号']).head(24)
  2208. # payStatus = ["G", "D", "C", "N", "M", "1", "2", "3", "4", "5", "6", "7"]
  2209. # payRcdTimesDf = payRcdTimesDf[payRcdTimesDf['还款状态'].isin(payStatus)]
  2210. # payRcdTimes = payRcdTimesDf.groupby(['账户编号'])['还款状态'].count()
  2211. # # 从“贷记卡信息”中提取,剔除未激活、销户、呆账、呆帐后,各账户的还款次数统计“24个月(账户)还款状态”包含"G","D","C","N","M"及数字的个数
  2212. # creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '贷记卡24期还款记录次数'] = np.max(payRcdTimes)
  2213. creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '贷记卡24期还款记录次数'] = cip.getPayRcdCount(payRcdDf,normalDf,24)
  2214. otherDf.loc[otherIndex, '近6个月有贷记卡还款记录的月份数'] = cip.getPayRcdCountNew(payRcdDf,reportTime,6)
  2215. otherDf.loc[otherIndex, '近12个月有贷记卡还款记录的月份数'] = cip.getPayRcdCountNew(payRcdDf, reportTime, 12)
  2216. # 解析贷款还款记录指标
  2217. def parseLoanMergeAndPayRecordDf(self,df, payRcdDf,reportTime):
  2218. if not df.empty and not payRcdDf.empty:
  2219. # 正常
  2220. normalDf = df[(df['账户状态'] != '结清') & (df['账户状态'] != '转出') & (df['账户状态'] != '呆账')]
  2221. overduePayRcdDf = payRcdDf[payRcdDf['账户编号'].isin(normalDf['账户编号'].values)]
  2222. overduePayRcdDf = utils.replacePayRcdStatus(overduePayRcdDf)
  2223. # 计算当前贷款,为还款记录的最后一期 0529
  2224. curOverduePayRcdDf = overduePayRcdDf.sort_values(by=["账户编号", "还款日期"], ascending=(True, False))
  2225. curOverduePayRcdDf = curOverduePayRcdDf.groupby(['账户编号']).head(1)
  2226. curOverduePayRcdDf = curOverduePayRcdDf[curOverduePayRcdDf['还款状态'] > 0]
  2227. # 临时保存,不用过滤还款状态为0的
  2228. payRcdMaxOverdueDf = overduePayRcdDf;
  2229. # 所有逾期的记录
  2230. # overduePayRcdDf = overduePayRcdDf[overduePayRcdDf['还款状态']>0]
  2231. loanAccountInfoDf.loc[loanAccountInfoIndex, '当前贷款逾期账户数'] = curOverduePayRcdDf['账户编号'].unique().size
  2232. if normalDf.index.size > 0:
  2233. loanAccountInfoDf.loc[loanAccountInfoIndex, '当前贷款逾期账户数占比'] = round(
  2234. loanAccountInfoDf.loc[loanAccountInfoIndex, '当前贷款逾期账户数'] / normalDf.index.size, 3)
  2235. # 存在逾期的贷款账户 非结清的过滤出逾期的账户号
  2236. overdueLoanDf = normalDf[normalDf['账户编号'].isin(curOverduePayRcdDf['账户编号'].values)]
  2237. loanAccountInfoDf.loc[loanAccountInfoIndex, '当前贷款逾期机构数'] = overdueLoanDf['管理机构'].unique().size
  2238. if normalDf['管理机构'].unique().size > 0:
  2239. loanAccountInfoDf.loc[loanAccountInfoIndex, '当前贷款逾期机构数占比'] = round(
  2240. loanAccountInfoDf.loc[loanAccountInfoIndex, '当前贷款逾期机构数'] / normalDf['管理机构'].unique().size, 2)
  2241. # 还款记录按日期排序最近3笔的最大逾期期数
  2242. loanAccountInfoDf.loc[loanAccountInfoIndex, '近1月贷款的最大逾期期数'] = prp.getPayRcdMaxOverdueNum(payRcdMaxOverdueDf,
  2243. 1);
  2244. loanAccountInfoDf.loc[loanAccountInfoIndex, '近3月贷款的最大逾期期数'] = prp.getPayRcdMaxOverdueNum(payRcdMaxOverdueDf,
  2245. 3);
  2246. loanAccountInfoDf.loc[loanAccountInfoIndex, '近6月贷款的最大逾期期数'] = prp.getPayRcdMaxOverdueNum(payRcdMaxOverdueDf,
  2247. 6);
  2248. loanAccountInfoDf.loc[loanAccountInfoIndex, '近9月贷款的最大逾期期数'] = prp.getPayRcdMaxOverdueNum(payRcdMaxOverdueDf,
  2249. 9);
  2250. loanAccountInfoDf.loc[loanAccountInfoIndex, '近12月贷款的最大逾期期数'] = prp.getPayRcdMaxOverdueNum(
  2251. payRcdMaxOverdueDf, 12);
  2252. loanAccountInfoDf.loc[loanAccountInfoIndex, '近24月贷款的最大逾期期数'] = prp.getPayRcdMaxOverdueNum(
  2253. payRcdMaxOverdueDf, 24);
  2254. loanAccountInfoDf.loc[loanAccountInfoIndex, '近24月贷款最大逾期距离现在的月数'] = prp.getPayRcdMaxOverdueNumMonth(
  2255. payRcdMaxOverdueDf, normalDf, reportTime, 24);
  2256. payStatus = ["G", "D", "C", "N", "M", "1", "2", "3", "4", "5", "6", "7"]
  2257. # 贷款24期还款记录次数 剔除结清 转出 呆账
  2258. # payRcdTimesDf = payRcdDf[payRcdDf['账户编号'].isin(normalDf['账户编号'].values)]
  2259. # payRcdTimesDf = payRcdTimesDf.sort_values(by=["账户编号", "还款日期"], ascending=(True, False))
  2260. # payRcdTimesDf = payRcdTimesDf.groupby(['账户编号']).head(24)
  2261. # # 从“贷款信息”中提取,剔除“账户状态”为结清、转出、呆账、呆帐后,各账户的还款次数统计“24个月(账户)还款状态”包含"G","D","C","N","M"及数字的个数,MAX(各账户的还款次数)
  2262. # payRcdTimesDf = payRcdTimesDf[payRcdTimesDf['还款状态'].isin(payStatus)]
  2263. # payRcdTimes = payRcdTimesDf.groupby(['账户编号'])['还款状态'].count()
  2264. #loanAccountInfoDf.loc[loanAccountInfoIndex, '贷款24期还款记录次数'] = np.max(payRcdTimes)
  2265. loanAccountInfoDf.loc[loanAccountInfoIndex, '贷款24期还款记录次数'] = prp.getPayRcdCount(payRcdDf,normalDf,24);
  2266. otherDf.loc[otherIndex, '最近6个月有贷款还款记录的月份数'] = prp.getPayRcdCountNew(payRcdDf, reportTime, 6);
  2267. otherDf.loc[otherIndex, '最近12个月有贷款还款记录的月份数'] = prp.getPayRcdCountNew(payRcdDf, reportTime, 12);
  2268. #最近一次逾期距今月份数
  2269. def getLastOverdueMonth(self, loanMergeDf, creditCardMergeDf, loanPayRecordMergeDf, creditCardPayRecordMergeDf,
  2270. reportTime):
  2271. result = 120;
  2272. if np.sum(loanMergeDf['当前逾期期数']) > 0 or np.sum(creditCardMergeDf['当前逾期期数']) > 0:
  2273. result = 0
  2274. else:
  2275. payRcdDf = loanPayRecordMergeDf.sort_values(by=["账户编号", "还款日期"], ascending=(True, False))
  2276. payRcdDf = payRcdDf.groupby(['账户编号']).head(60)
  2277. payRcdDf = utils.replacePayRcdStatusOverdue(payRcdDf) # 替换逾期
  2278. payRcdDf = payRcdDf[payRcdDf['还款状态'] > 0]
  2279. payRcdDf = utils.replacePayRcdStatusOverdue(payRcdDf) # 替换逾期
  2280. loanOverdueDate = np.max(payRcdDf['还款日期'])
  2281. payRcdDfCredit = creditCardPayRecordMergeDf.sort_values(by=["账户编号", "还款日期"], ascending=(True, False))
  2282. payRcdDfCredit = utils.replacePayRcdStatusOverdue(payRcdDfCredit) # 替换逾期
  2283. payRcdDfCredit = payRcdDfCredit.groupby(['账户编号']).head(60)
  2284. payRcdDfCredit = payRcdDfCredit[payRcdDfCredit['还款状态'] > 0]
  2285. if not payRcdDf.empty or not payRcdDfCredit.empty:
  2286. creditOverdueDate = np.max(payRcdDfCredit['还款日期'])
  2287. # reportTime = str(np.datetime64(reportTime, "M")) + "-02"
  2288. reportTime = utils.get_last_month_first_day_v2(reportTime)
  2289. overdueDate = None
  2290. if str(loanOverdueDate) != "nan" and str(creditOverdueDate) != "nan":
  2291. overdueDate = max([loanOverdueDate, creditOverdueDate])
  2292. elif str(loanOverdueDate) == "nan" and str(creditOverdueDate) != "nan":
  2293. overdueDate = creditOverdueDate
  2294. elif str(loanOverdueDate) != "nan" and str(creditOverdueDate) == "nan":
  2295. overdueDate = loanOverdueDate
  2296. if overdueDate != None:
  2297. result = utils.difMonthReportTime(overdueDate, reportTime)
  2298. otherDf.loc[otherIndex, "最近一次逾期距今月份数"] = result
  2299. #近12个月贷款和贷记卡还款状态异常次数 慧算1112
  2300. #count(三类贷款账户m1-m12中D/Z/B/G的个数)+count(贷记卡m1-m12中D/Z/B/G的个数)
  2301. def calcPayRcdStatus(self,loanPayRecordMergeDf,creditCardPayRecordMergeDf,reportTime):
  2302. reportTime = str(np.datetime64(reportTime, "M")) + "-02"
  2303. statusList =['G','B','Z','D']
  2304. payDate = utils.getLastMonthDate(reportTime, 12)
  2305. loanPayRcdTmpDf = loanPayRecordMergeDf[loanPayRecordMergeDf['还款日期']>=payDate]
  2306. loanTimes = loanPayRcdTmpDf[(loanPayRcdTmpDf['还款状态'].isin(statusList))].index.size
  2307. creditPayRcdTmpDf = creditCardPayRecordMergeDf[creditCardPayRecordMergeDf['还款日期']>=payDate]
  2308. creditTimes = creditPayRcdTmpDf[(creditPayRcdTmpDf['还款状态'].isin(statusList))].index.size
  2309. result = loanTimes+creditTimes
  2310. otherDf.loc[otherIndex, "近12个月贷款和贷记卡还款状态异常次数"] = result