1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428 |
- #!/usr/bin/env Python
- # coding=utf-8
- import json
- from xml.dom import minidom
- import consts;
- import pandas as pd
- import numpy as np;
- import time
- import log
- logger = log.logger
- import utils
- import loanIndexParser as lip;
- import payRcdIndexParser as prp;
- import creditCardIndexParser as cip
- import queryInfoIndexParser as qip
- import requests
- import dfParser
- import sys
- import traceback
- import timeit
- from mailUtil import MailUtil
- #身份信息
- identityInfoIndex = '身份信息'
- identityInfoDf = pd.DataFrame(columns=consts.identityInfoHeader,index=[identityInfoIndex])
- #配偶信息
- mateInfoIndex = '配偶信息'
- mateInfoDf = pd.DataFrame(columns=consts.mateInfoHeader,index=[mateInfoIndex])
- #居住信息
- liveInfoIndex = '居住信息'
- liveInfoDf = pd.DataFrame(columns=consts.liveInfoHeader,index=[liveInfoIndex])
- #职业信息
- occupationInfoIndex = '职业信息'
- occupationInfoDf = pd.DataFrame(columns=consts.occupationInfoHeader,index=[occupationInfoIndex])
- #信贷交易信息提示
- loanTradeInfoIndex = '信贷交易信息提示'
- briefInfoDf_loanTradeInfo = pd.DataFrame(columns=consts.briefInfoHeader_loanTradeInfo,index=[loanTradeInfoIndex])
- #被追偿信息汇总及呆账信息汇总
- recoveryInfoSumIndex = '信贷交易违约信息概要'
- briefInfoDf_recoveryInfoSum = pd.DataFrame(columns=consts.briefInfoHeader_recoveryInfo,index=[recoveryInfoSumIndex])
- #呆账信息汇总
- badDebtsInfoIndex = '呆账信息汇总'
- briefInfoDf_badDebtsInfoSum = pd.DataFrame(columns=consts.briefInfoHeader_badDebtsInfoSum,index=[badDebtsInfoIndex])
- #逾期(透支)信息汇总
- overdueInfoSumIndex='逾期(透支)信息汇总'
- briefInfoDf_overdueInfoSum = pd.DataFrame(columns=consts.briefInfoHeader_overdueInfoSum,index=[overdueInfoSumIndex])
- #信贷交易授信及负债信息概要
- loanTradeCreditInfoIndex='信贷交易授信及负债信息概要'
- briefInfoDf_loanTradeCreditInfo = pd.DataFrame(columns=consts.briefInfoHeader_loanTradeCreditInfo,index=[loanTradeCreditInfoIndex]).fillna(0.0)
- #公共信息概要
- publicInfoBriefIndex = '公共信息概要'
- publicInfoBriefDf = pd.DataFrame(columns=consts.publicInfoBriefHeader,index=[publicInfoBriefIndex])
- #查询记录汇总
- queryRecordSumIndex = '查询记录汇总'
- queryRecordSumDf = pd.DataFrame(columns=consts.queryRecordSumHeader,index=[queryRecordSumIndex])
- #信贷交易明细-被追偿信息
- recoveryInfoIndex='被追偿信息'
- creditTradeDetailDf_recoveryInfo = pd.DataFrame(columns=consts.creditTradeDetailHeader_recoveryInfo,index=[recoveryInfoIndex])
- #信贷交易明细-特殊交易
- specialTradeIndex='特殊交易'
- creditTradeDetailHeader_specialTrade = pd.DataFrame(columns=consts.creditTradeDetailHeader_specialTrade,index=[specialTradeIndex])
- #信贷交易明细
- #非循环贷账户
- loanInfoIndex='非循环贷账户'
- creditTradeDetailDf_loanAccountInfo = pd.DataFrame(columns=consts.creditTradeDetailHeader_loanAccountInfo,index=[loanInfoIndex])
- #循环额度下分账户
- cycleCreditAccountInfoIndex='循环额度下分账户'
- creditTradeDetailDf_cycleCreditAccountInfo = pd.DataFrame(columns=consts.creditTradeDetailHeader_cycleCreditAccountInfo,index=[cycleCreditAccountInfoIndex])
- #循环贷账户
- cycleLoanAccountInfoIndex='循环贷账户'
- creditTradeDetailDf_cycleLoanAccountInfo = pd.DataFrame(columns=consts.creditTradeDetailHeader_cycleLoanAccountInfo,index=[cycleLoanAccountInfoIndex])
- #贷款信息
- loanAccountInfoIndex='贷款信息'
- loanAccountInfoDf = pd.DataFrame(columns=consts.loanAccountInfoHeader,index=[loanAccountInfoIndex])
- #贷记卡信息
- creditCardAccountInfoIndex = '贷记卡账户'
- creditCardAccountInfoDf = pd.DataFrame(columns=consts.creditCardAccountInfoHeader,index=[creditCardAccountInfoIndex])
- #准贷记卡
- creditCardAccountInfoIndexZ = '准贷记卡账户'
- creditCardAccountInfoDfZ = pd.DataFrame(columns=consts.creditCardAccountInfoHeaderZ,index=[creditCardAccountInfoIndexZ])
- useRateIndex = '使用率'
- useRateDf = pd.DataFrame(columns=consts.creditTradeDetailHeader_useRate,index=[useRateIndex])
- openAccountIndex = '开户数'
- openAccountDf = pd.DataFrame(columns=consts.creditTradeDetailHeader_openAccount,index=[openAccountIndex])
- payRcdStatusIndex = '24期还款状态'
- payRcdStatusDf = pd.DataFrame(columns=consts.creditTradeDetailHeader_payRcdStatus,index=[payRcdStatusIndex])
- #查询记录明细指标
- queryRecordDetailIndex = '信贷审批查询记录明细'
- queryRecordDetailDf = pd.DataFrame(columns=consts.queryRecordDetailHeader,index=[queryRecordDetailIndex])
- #住房公积金
- housingFundRcdIndex = '住房公积金参缴记录'
- housingFundRcdDf = pd.DataFrame(columns=consts.housingFundRcdHeader,index=[housingFundRcdIndex])
- #汇算-其他
- otherIndex = '慧算账新增'
- otherDf = pd.DataFrame(columns=consts.otherHeader,index=[otherIndex])
- sanshouIndex = '恒昌新增'
- sanshouDf = pd.DataFrame(columns=consts.sanShouHeader,index=[sanshouIndex])
- class XmlParser(object):
- def getNodeData(self,node, key):
- data = ""
- try:
- if len(node.getElementsByTagName(key)) > 0:
- nodeValue = node.getElementsByTagName(key)[0].childNodes
- if len(nodeValue)>0:
- data = nodeValue[0].data
- except Exception:
- logger.error("getNodeData error")
- info = sys.exc_info()
- logger.error(info[0])
- logger.error(info[1])
- logger.error(traceback.extract_tb(info[2], 1))
- return data;
- def parse(self, xmlData):
- result = "{"
- try:
- docXml = minidom.parseString(xmlData)
- queryInfo = self.parseQueryInfo(docXml)
- reportTime = queryInfo["reportTime"];
- self.parseIdentity(reportTime,docXml)
- self.parseLiveInfo(docXml)
- self.parseOccupationInfoDf(reportTime,docXml)
- self.parseLoanTradeInfo(docXml)
- self.parseRecoveryInfoSum(docXml)
- self.parseBadDebtsInfoSumDf(docXml)
- self.parseOverdueInfoSum(docXml)
- self.parseLoanAccountInfoSum(docXml)
- self.parseCycleCreditAccountInfoSum(docXml);
- self.parseCyleLoanAccountInfoSum(docXml);
- self.parseCreditCardInfoSum(docXml)
- self.parseCreditCardInfoSumZ(docXml)
- self.parseRepaymentSum(docXml)
- self.parsePublicInfoBrief(docXml)
- self.parseQueryRecordSum(docXml)
- self.parseQueryInfoDetail(reportTime,docXml)
- self.parseHousingFundRcd(reportTime,docXml)
- loanAccountDfs = []
- start = timeit.default_timer();
- logger.info(queryInfo["queryInfoCardId"]+"贷款解析开始")
- # 非循环
- noloopcreditaccountbols = self.mergeLoanDf(reportTime, docXml, "NOLOOPCREDITACCOUNTBOLS")
- # 循环额度
- loopquotaaccountbols = self.mergeLoanDf(reportTime, docXml, "LOOPQUOTAACCOUNTBOLS")
- # 循环贷账户
- loopcreditaccountbols = self.mergeLoanDf(reportTime, docXml, "LOOPCREDITACCOUNTBOLS")
- loanAccountDfs = noloopcreditaccountbols + loopquotaaccountbols + loopcreditaccountbols
- print(len(loanAccountDfs))
- s = timeit.default_timer() - start
- logger.info(str(s) + " 秒")
- logger.info(queryInfo["queryInfoCardId"] + "贷款解析完成")
- start = timeit.default_timer();
- logger.info(queryInfo["queryInfoCardId"] + "信用卡解析开始")
- creditCardAccountDfs = self.mergeCreditCardDf(reportTime, docXml)
- print(len(creditCardAccountDfs))
- creditCardAccountDfsZ = self.mergeCreditCardDfZ(reportTime, docXml)
- print(len(creditCardAccountDfsZ))
- # 合并贷款
- loanMergeDf = pd.DataFrame(columns=dfParser.dfHeaderLoan)
- loanPayRecordMergeDf = pd.DataFrame(columns=dfParser.dfHeaderLoanPayRecord)
- loanSpecialTradeMergeDf = pd.DataFrame(columns=dfParser.dfHeaderLoanSpecialTrade) # 特殊交易
- loanMergeDfDs = []
- loanPayRecordMergeDfDs = []
- # for loanDfObj in loanAccountDfs:
- # loanMergeDf = pd.concat([loanMergeDf, loanDfObj["loanDf"]], axis=0, ignore_index=True);
- # loanPayRecordMergeDf = pd.concat([loanPayRecordMergeDf, loanDfObj["loanPayRecordDf"]], axis=0,ignore_index=True);
- # loanSpecialTradeMergeDf = pd.concat([loanSpecialTradeMergeDf, loanDfObj["specialTradeDf"]], axis=0,ignore_index=True);
- for loanDfObj in loanAccountDfs:
- loanMergeDfDs.append(loanDfObj["loanDf"])
- loanPayRecordMergeDfDs.extend(loanDfObj["loanPayRecordDf"])
- loanSpecialTradeMergeDf = pd.concat([loanSpecialTradeMergeDf, loanDfObj["specialTradeDf"]], axis=0,ignore_index=True);
- loanMergeDf = pd.DataFrame(loanMergeDfDs)
- loanPayRecordMergeDf = pd.DataFrame(loanPayRecordMergeDfDs)
- # 合并贷记卡
- creditCardMergeDf = pd.DataFrame(columns=dfParser.dfHeaderCreditCard)
- creditCardPayRecordMergeDf = pd.DataFrame(columns=dfParser.dfHeaderCreditCardPayRecord)
- for creditCardDfObj in creditCardAccountDfs:
- creditCardMergeDf = pd.concat([creditCardMergeDf, creditCardDfObj["creditCardDf"]], axis=0,ignore_index=True);
- creditCardPayRecordMergeDf = pd.concat([creditCardPayRecordMergeDf, creditCardDfObj["creditCardPayRecordDf"]], axis=0, ignore_index=True);
- # 准贷记卡合并df
- creditCardMergeDfZ = pd.DataFrame(columns=dfParser.dfHeaderCreditCardZ)
- creditCardPayRecordMergeDfZ = pd.DataFrame(columns=dfParser.dfHeaderCreditCardPayRecordZ)
- for creditCardDfObj in creditCardAccountDfsZ:
- creditCardMergeDfZ = pd.concat([creditCardMergeDfZ, creditCardDfObj["creditCardDfZ"]], axis=0,ignore_index=True);
- creditCardPayRecordMergeDfZ = pd.concat([creditCardPayRecordMergeDfZ, creditCardDfObj["creditCardPayRecordDfZ"]], axis=0,ignore_index=True);
- s = timeit.default_timer() - start
- logger.info(str(s) + " 秒")
- logger.info(queryInfo["queryInfoCardId"] + "信用卡解析完成")
- result += utils.toJson(identityInfoDf) + ","
- result += utils.toJson(mateInfoDf) + ","
- result += utils.toJson(liveInfoDf) + ","
- result += utils.toJson(occupationInfoDf) + ","
- result += "briefInfoDf_loanTradeInfo" + "," # 占位符
- result += "briefInfoDf_recoveryInfoSum" + "," # 占位符
- result += "briefInfoDf_overdueInfoSum" + ","
- result += utils.toJson(briefInfoDf_badDebtsInfoSum) + ","
- result += utils.toJson(briefInfoDf_loanTradeCreditInfo) + ","
- result += utils.toJson(publicInfoBriefDf) + ","
- result += utils.toJson(queryRecordSumDf) + ","
- # 合并被追偿信息DF
- recoveryInfoMergeDf = self.mergeRecoveryInfoDf(reportTime, docXml)
- self.parseRecoveryInfoMergeDf(recoveryInfoMergeDf)
- result = result.replace("briefInfoDf_recoveryInfoSum", utils.toJson(briefInfoDf_recoveryInfoSum)) # 替换汇总中的指标
- result += utils.toJson(creditTradeDetailDf_recoveryInfo) + "," # 设置占位符,由于存在概要的指标在明细中计算
- # 特殊交易
- self.parseSpecialTrade(loanSpecialTradeMergeDf)
- result += utils.toJson(creditTradeDetailHeader_specialTrade) + ","
- # 信贷交易明细-解析非循环贷账户
- self.parseLoanAccountInfo(loanMergeDf);
- result += utils.toJson(creditTradeDetailDf_loanAccountInfo) + ","
- # 循环额度分账户
- self.parseCycleCreditAccountInfo(loanMergeDf);
- result += utils.toJson(creditTradeDetailDf_cycleCreditAccountInfo) + ","
- # 循环贷
- self.parseCycleLoanAccountInfo(loanMergeDf);
- result += utils.toJson(creditTradeDetailDf_cycleLoanAccountInfo) + ","
- # 解析贷款账户指标
- start = timeit.default_timer();
- self.parseLoanMergeDf(loanMergeDf,reportTime);
- s = timeit.default_timer() - start
- logger.info("解析贷款账户指标 " + str(s) + " 秒")
- # 解析还款记录相关指标
- start = timeit.default_timer();
- self.parseLoanMergeAndPayRecordDf(loanMergeDf, loanPayRecordMergeDf,reportTime);
- s = timeit.default_timer() - start
- logger.info("解析还款记录相关指标 " + str(s) + " 秒")
- result += utils.toJson(loanAccountInfoDf) + ","
- # 解析贷记卡账户指标
- self.parseCreditCardMergeDf(creditCardMergeDf,reportTime);
- self.parseCreditCardMergeAndPayRecordDf(creditCardMergeDf, creditCardPayRecordMergeDf,reportTime)
- # 解析准贷记卡相关指标
- self.parseCreditCardMergeDfZ(creditCardMergeDfZ, creditCardPayRecordMergeDfZ);
- result += utils.toJson(creditCardAccountInfoDf) + ","
- result += utils.toJson(creditCardAccountInfoDfZ) + ","
- # 使用率
- self.parseUseRate()
- result += utils.toJson(useRateDf) + ","
- # 开户数
- self.parseOpenAccount(loanMergeDf, creditCardMergeDf, creditCardMergeDfZ, recoveryInfoMergeDf, loanPayRecordMergeDf,creditCardPayRecordMergeDf, creditCardPayRecordMergeDfZ,reportTime)
- result += utils.toJson(openAccountDf) + ","
- # 24期还款状态
- start = timeit.default_timer();
- self.parsePayRcdStatus(loanMergeDf, creditCardMergeDf, creditCardMergeDfZ, loanPayRecordMergeDf,creditCardPayRecordMergeDf, creditCardPayRecordMergeDfZ,reportTime)
- s = timeit.default_timer() - start
- logger.info("24期还款状态 " + str(s) + " 秒")
- result += utils.toJson(payRcdStatusDf) + ","
- # 由于逾期汇总的指标再还款状态之后需要替换占位 TODO
- result = result.replace("briefInfoDf_overdueInfoSum", utils.toJson(briefInfoDf_overdueInfoSum))
- # 0525 由于在开户数后,统计信贷信息概要的指标,替换占位符
- result = result.replace("briefInfoDf_loanTradeInfo", utils.toJson(briefInfoDf_loanTradeInfo))
- # 公积金
- result += utils.toJson(housingFundRcdDf) + ","
- result += utils.toJson(queryRecordDetailDf) + ","
- #1112修改慧算账需求
- # otherDf.loc[otherIndex, "贷款当前逾期金额"] = utils.null2Zero(
- # creditTradeDetailDf_loanAccountInfo.loc[loanInfoIndex, '当前一共逾期总额']) + \
- # utils.null2Zero(creditTradeDetailDf_cycleCreditAccountInfo.loc[
- # cycleCreditAccountInfoIndex, '当前一共逾期总额']) \
- # + utils.null2Zero(
- # creditTradeDetailDf_cycleLoanAccountInfo.loc[cycleLoanAccountInfoIndex, '当前一共逾期总额'])
- # otherDf.loc[otherIndex,"当前逾期金额"] = utils.null2Zero( otherDf.loc[otherIndex, "贷款当前逾期金额"])+\
- # utils.null2Zero(otherDf.loc[otherIndex, '贷记卡当前逾期金额'])
- #
- # otherDf.loc[otherIndex, "历史最大逾期金额"] = np.max([ utils.null2Zero(briefInfoDf_overdueInfoSum.loc[overdueInfoSumIndex, '非循环贷帐户单月最高逾期总额']),
- # utils.null2Zero(briefInfoDf_overdueInfoSum.loc[overdueInfoSumIndex, '循环额度下分账户单月最高逾期总额']),
- # utils.null2Zero(briefInfoDf_overdueInfoSum.loc[overdueInfoSumIndex, '贷记卡账户单月逾期总额']) ])
- # otherDf.loc[otherIndex, "贷款历史最大逾期期数"] = utils.null2Zero(briefInfoDf_overdueInfoSum.loc[overdueInfoSumIndex, '非循环贷帐户最长逾期月数'])+\
- # utils.null2Zero(briefInfoDf_overdueInfoSum.loc[overdueInfoSumIndex, '循环额度下分账户最长逾期月数'])+ \
- # utils.null2Zero(briefInfoDf_overdueInfoSum.loc[
- # overdueInfoSumIndex, '循环贷账户最长逾期月数'])
- # otherDf.loc[otherIndex, "近3个月M1及以上次数"] = utils.null2Zero(payRcdStatusDf.loc[payRcdStatusIndex, '贷款账户近3月逾期期数大于或等于“1”的次数'])+\
- # utils.null2Zero(payRcdStatusDf.loc[payRcdStatusIndex, '贷记卡账户近3月逾期期数大于或等于“1”的次数'])
- # otherDf.loc[otherIndex, "近6个月M1及以上次数"] = utils.null2Zero(
- # payRcdStatusDf.loc[payRcdStatusIndex, '贷款账户近6月逾期期数大于或等于“1”的次数']) + \
- # utils.null2Zero(payRcdStatusDf.loc[
- # payRcdStatusIndex, '贷记卡账户近6月逾期期数大于或等于“1”的次数'])
- # otherDf.loc[otherIndex, "近12个月M1及以上次数"] = utils.null2Zero(
- # payRcdStatusDf.loc[payRcdStatusIndex, '贷款账户近12月逾期期数大于或等于“1”的次数']) + \
- # utils.null2Zero(payRcdStatusDf.loc[
- # payRcdStatusIndex, '贷记卡账户近12月逾期期数大于或等于“1”的次数'])
- # otherDf.loc[otherIndex, "近24个月M1及以上次数"] = utils.null2Zero(
- # payRcdStatusDf.loc[payRcdStatusIndex, '贷款账户近24月逾期期数大于或等于“1”的次数']) + \
- # utils.null2Zero(payRcdStatusDf.loc[
- # payRcdStatusIndex, '贷记卡账户近24月逾期期数大于或等于“1”的次数'])
- # otherDf.loc[otherIndex, "近6个月M2及以上次数"] = utils.null2Zero(
- # payRcdStatusDf.loc[payRcdStatusIndex, '贷款账户近6月逾期期数大于或等于“2”的次数']) + \
- # utils.null2Zero(payRcdStatusDf.loc[
- # payRcdStatusIndex, '贷记卡账户近6月逾期期数大于或等于“2”的次数'])
- # otherDf.loc[otherIndex, "近12个月M2及以上次数"] = utils.null2Zero(
- # payRcdStatusDf.loc[payRcdStatusIndex, '贷款账户近12月逾期期数大于或等于“2”的次数']) + \
- # utils.null2Zero(payRcdStatusDf.loc[
- # payRcdStatusIndex, '贷记卡账户近12月逾期期数大于或等于“2”的次数'])
- # otherDf.loc[otherIndex, "近12个月M3及以上次数"] = utils.null2Zero(
- # payRcdStatusDf.loc[payRcdStatusIndex, '贷款账户近12月逾期期数大于或等于“3”的次数']) + \
- # utils.null2Zero(payRcdStatusDf.loc[
- # payRcdStatusIndex, '贷记卡账户近12月逾期期数大于或等于“3”的次数'])
- #
- # otherDf.loc[otherIndex, "近24个月M4及以上次数"] = utils.null2Zero(
- # payRcdStatusDf.loc[payRcdStatusIndex, '贷款账户近24月逾期期数大于或等于“4”的次数']) + \
- # utils.null2Zero(payRcdStatusDf.loc[
- # payRcdStatusIndex, '贷记卡账户近24月逾期期数大于或等于“4”的次数'])
- # otherDf.loc[otherIndex, "贷款发放笔数"] = utils.null2Zero(briefInfoDf_loanTradeInfo.loc[loanTradeInfoIndex, '个人住房贷款账户数'])+ \
- # utils.null2Zero(
- # briefInfoDf_loanTradeInfo.loc[loanTradeInfoIndex, '个人商用房贷款(包括商住两用)账户数']) + \
- # utils.null2Zero(
- # briefInfoDf_loanTradeInfo.loc[loanTradeInfoIndex, '其他类贷款账户数'])
- # otherDf.loc[otherIndex, "贷款授信总额"] = utils.null2Zero(briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '非循环贷账户授信总额'])+\
- # briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '循环额度下分账户授信总额']\
- # +briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '循环贷账户授信总额']
- # otherDf.loc[otherIndex, "未结清贷款最近6个月平均应还款"]=utils.null2Zero(briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '非循环贷账户6月平均应还款'])+\
- # utils.null2Zero(briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '循环额度下分账户6月平均应还款'])+\
- # utils.null2Zero(briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '循环贷账户6月平均应还款'])
- # otherDf.loc[otherIndex, "房贷发放笔数"] = utils.null2Zero(briefInfoDf_loanTradeInfo.loc[loanTradeInfoIndex, '个人住房贷款账户数'])+ \
- # utils.null2Zero(
- # briefInfoDf_loanTradeInfo.loc[loanTradeInfoIndex, '个人商用房贷款(包括商住两用)账户数'])
- # otherDf.loc[otherIndex, "近3个月新增贷款授信总额"] = utils.null2Zero(openAccountDf.loc[openAccountIndex, '近3个月贷款账户开户数'])\
- # *utils.null2Zero(loanAccountInfoDf.loc[loanAccountInfoIndex, '近3月开户平均贷款本金'])
- # otherDf.loc[otherIndex, "近6个月新增贷款授信总额"] = utils.null2Zero(
- # openAccountDf.loc[openAccountIndex, '近6个月贷款账户开户数']) * utils.null2Zero(
- # loanAccountInfoDf.loc[loanAccountInfoIndex, '近6月开户平均贷款本金'])
- # otherDf.loc[otherIndex, "近12个月新增贷款授信总额"] = utils.null2Zero(
- # openAccountDf.loc[openAccountIndex, '近12个月贷款账户开户数']) * utils.null2Zero(
- # loanAccountInfoDf.loc[loanAccountInfoIndex, '近12月开户平均贷款本金'])
- # otherDf.loc[otherIndex, "近3个月新授信贷记卡总额度"] = utils.null2Zero(openAccountDf.loc[openAccountIndex, '近3个月贷记卡账户开户数'])*\
- # utils.null2Zero(creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '近3月开卡平均额度'])
- # otherDf.loc[otherIndex, "近1个月贷款和信用卡审批查询次数"] = utils.null2Zero(queryRecordSumDf.loc[queryRecordSumIndex, '近1月内的查询次数-贷款审批'])+ \
- # utils.null2Zero(queryRecordSumDf.loc[
- # queryRecordSumIndex, '近1月内的查询次数-信用卡审批'])
- # otherDf.loc[otherIndex, "近3个月贷款和信用卡审批查询次数"] = utils.null2Zero(
- # queryRecordDetailDf.loc[queryRecordDetailIndex, '近3月查询次数贷款审批']) + \
- # utils.null2Zero(queryRecordDetailDf.loc[
- # queryRecordDetailIndex, '近3月查询次数信用卡审批'])
- # otherDf.loc[otherIndex, "近6个月贷款和信用卡审批查询次数"]= utils.null2Zero(
- # queryRecordDetailDf.loc[queryRecordDetailIndex, '近6月查询次数贷款审批']) + \
- # utils.null2Zero(queryRecordDetailDf.loc[
- # queryRecordDetailIndex, '近6月查询次数信用卡审批'])
- # otherDf.loc[otherIndex, "近12个月贷款和信用卡审批查询次数"] = utils.null2Zero(
- # queryRecordDetailDf.loc[queryRecordDetailIndex, '近12月查询次数贷款审批']) + \
- # utils.null2Zero(queryRecordDetailDf.loc[
- # queryRecordDetailIndex, '近12月查询次数信用卡审批'])
- # otherDf.loc[otherIndex, "未来12个月负债总计"] = round(np.sum(loanMergeDf["贷款负债"]),2)+creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '大额专项分期额度(合计)']
- #1112end 慧算账
- # try:
- # # self.getLastOverdueMonth(loanMergeDf,creditCardMergeDf,loanPayRecordMergeDf,creditCardPayRecordMergeDf,reportTime)
- # # self.calcPayRcdStatus(loanPayRecordMergeDf,creditCardPayRecordMergeDf,reportTime)
- # # except Exception:
- # # logger.error(traceback.print_exc())
- # # logger.error(traceback.format_exc())
- result += utils.toJson(otherDf) + ","
- #三寿新增
- result += utils.toJson(sanshouDf) + ""
- result += "}"
- except Exception:
- info = sys.exc_info()
- # logger.error(str(Exception))
- logger.error(queryInfo["queryInfoCardId"]+" error")
- logger.error(info[0])
- logger.error(info[1])
- logger.error(traceback.extract_tb(info[2], 1))
- # logger.error( 'str(Exception):\t', str(Exception))
- # logger.error('str(e):\t\t', str(e))
- # logger.error('repr(e):\t', repr(e))
- # logger.error('e.message:\t', e.message)
- logger.error(traceback.print_exc())
- logger.error(traceback.format_exc())
- mailUtil = MailUtil();
- webhook = 'https://oapi.dingtalk.com/robot/send?access_token=64d8b2c7fed4949e9433b807c7c5559939f1517af8f77c1dacb4de19c6910b56'
- mailUtil.dingtalk("号码:"+queryInfo["queryInfoCardId"]+" 解析错误 "+traceback.format_exc(),webhook)
- return result;
- # 解析被查询信息指标
- def parseQueryInfo(self,docXml):
- headbo = docXml.documentElement.getElementsByTagName("HEADBO")[0]
- reportTime= self.getNodeData(headbo,"RPTTIME")
- queryInfo = {};
- queryInfoCardId = self.getNodeData(headbo,"CRENUMBER")
- queryInfo["reportTime"] = reportTime.replace("T"," ")
- queryInfo["queryInfoCardId"] = queryInfoCardId; # 被查询者证件号码
- otherDf.loc[otherIndex, '报告查询日期'] = queryInfo["reportTime"];
- sanshouDf.loc[sanshouIndex,"身份证号前两位"]=queryInfoCardId[0:2]
- print(queryInfo)
- return queryInfo;
- def parseIdentity(self,reportTime,docXml):
- tmpNode =docXml.documentElement.getElementsByTagName("BASEINFO")
- if len(tmpNode)>0:
- baseInfo = docXml.documentElement.getElementsByTagName("BASEINFO")[0]
- tmpNode = docXml.documentElement.getElementsByTagName("MARRIAGEINFOSG")
- identityInfoDf.loc[identityInfoIndex, '性别'] = self.getNodeData(baseInfo,"SEXDESC")
- identityInfoDf.loc[identityInfoIndex, '出生日期'] = self.getNodeData(baseInfo,"BIRTHDAY")
- identityInfoDf.loc[identityInfoIndex, '国籍'] = self.getNodeData(baseInfo,"NATIONDESC")
- identityInfoDf.loc[identityInfoIndex, '户籍地址'] = self.getNodeData(baseInfo,"ADDRESS")
- if len(tmpNode)>0:
- marriageinfosg = docXml.documentElement.getElementsByTagName("MARRIAGEINFOSG")[0]
- self.parseMate(marriageinfosg)
- identityInfoDf.loc[identityInfoIndex, '婚姻状况'] = self.getNodeData(marriageinfosg,"MARSTATUDESC")
- identityInfoDf.loc[identityInfoIndex, '学历'] = self.getNodeData(baseInfo,"DEGREEDESC")
- identityInfoDf.loc[identityInfoIndex, '学位'] = self.getNodeData(baseInfo,"DEGREEDESC")
- identityInfoDf.loc[identityInfoIndex, '通讯地址'] = self.getNodeData(baseInfo,"COMMUADDRESS")
- identityInfoDf.loc[identityInfoIndex, '就业状况'] = self.getNodeData(baseInfo,"WORKSTATUSDESC")
- mobiles = docXml.documentElement.getElementsByTagName("TELEPHONEINFOSGLS")
- if len(mobiles)>0:
- telephoneinfosgls = docXml.documentElement.getElementsByTagName("TELEPHONEINFOSGLS")[0]
- telephoneinfosg = telephoneinfosgls.getElementsByTagName("TELEPHONEINFOSG");
- identityInfoDf.loc[identityInfoIndex, '历史手机号码数'] = len(telephoneinfosg)
- identityInfoDf.loc[identityInfoIndex, '近3个月手机号码数'] = self.getLastMonthMobileCount(telephoneinfosg, 3, reportTime)
- identityInfoDf.loc[identityInfoIndex, '近6个月手机号码数'] = self.getLastMonthMobileCount(telephoneinfosg, 6, reportTime)
- identityInfoDf.loc[identityInfoIndex, '近12个月手机号码数'] = self.getLastMonthMobileCount(telephoneinfosg, 12, reportTime)
- identityInfoDf.loc[identityInfoIndex, '近24个月手机号码数'] = self.getLastMonthMobileCount(telephoneinfosg, 24, reportTime)
- # print(identityInfoDf.to_json(orient="index",force_ascii=False))
- def getLastMonthMobileCount(self,telephoneinfosg, month, reportTime):
- df = pd.DataFrame()
- for i in range(0,len(telephoneinfosg)):
- telephone = self.getNodeData(telephoneinfosg[i],"TELEPHONE")
- updatedateinfo= self.getNodeData(telephoneinfosg[i],"UPDATEDATEINFO")
- df.loc[i,0] = telephone
- df.loc[i,1] = updatedateinfo
- # 当前日期
- last1MonthDateStr = reportTime
- # 最近一个月
- lastMonthDate = np.datetime64(last1MonthDateStr, "D") - np.timedelta64(30 * month, 'D')
- lastMonthMobileDf = df[df[1] >= str(lastMonthDate)]
- return lastMonthMobileDf.shape[0];
- def parseMate(self,marriageinfosg):
- mateInfoDf.loc[mateInfoIndex, '姓名'] = self.getNodeData(marriageinfosg,"SPUOSENAME")
- mateInfoDf.loc[mateInfoIndex, '证件号码'] = self.getNodeData(marriageinfosg,"CERTNUM")
- mateInfoDf.loc[mateInfoIndex, '工作单位'] = self.getNodeData(marriageinfosg,"COMPANY")
- mateInfoDf.loc[mateInfoIndex, '联系电话'] = self.getNodeData(marriageinfosg,"TELNUM")
- # print(mateInfoDf.to_json(orient="index", force_ascii=False))
- # 解析居住信息
- def parseLiveInfo(self,docXml):
- # residenceinfosgls = docXml.documentElement.getElementsByTagName("RESIDENCEINFOSGLS")
- residenceinfosg = docXml.documentElement.getElementsByTagName("RESIDENCEINFOSG");
- df = pd.DataFrame()
- for i in range(0, len(residenceinfosg)):
- resistatusdesc = self.getNodeData(residenceinfosg[i], "RESISTATUSDESC")
- address = self.getNodeData(residenceinfosg[i], "ADDRESS")
- telnum = self.getNodeData(residenceinfosg[i], "TELNUM")
- updatedateinfo = self.getNodeData(residenceinfosg[i], "UPDATEDATEINFO")
- df.loc[i, 0] = resistatusdesc
- df.loc[i, 1] = address
- df.loc[i, 2] = telnum
- df.loc[i, 3] = updatedateinfo
- if len(residenceinfosg)>0:
- liveInfoDf.loc[liveInfoIndex, '居住地址'] = self.getNodeData(residenceinfosg[0],"ADDRESS")
- liveInfoDf.loc[liveInfoIndex, '住宅电话'] = self.getNodeData(residenceinfosg[0],"TELNUM")
- liveInfoDf.loc[liveInfoIndex, '历史居住地址个数'] = len(residenceinfosg);
- curDate = np.datetime64(time.strftime("%Y-%m-%d"));
- last3year = str(curDate)[0:4]
- last3yearDate = str(int(last3year) - 3) + str(curDate)[4:10]
- lastLiveDf = df[df[3] >= last3yearDate];
- liveInfoDf.loc[liveInfoIndex, '最近3年内居住地址个数'] = lastLiveDf.index.size ;
- houseIndex = df[df[0] == '自置'].index.size > 0
- if (houseIndex):
- houseStr = '是'
- else:
- houseStr = '否'
- liveInfoDf.loc[liveInfoIndex, '当前居住状况-是否具有自有住房'] = houseStr;
- liveInfoDf.loc[liveInfoIndex, '居住状况'] = self.getNodeData(residenceinfosg[0],"RESISTATUSDESC")
- liveInfoDf.loc[liveInfoIndex, '信息更新日期'] = self.getNodeData(residenceinfosg[0],"UPDATEDATEINFO")
- # print(liveInfoDf.to_json(orient="index", force_ascii=False))
- # 解析职业信息
- def parseOccupationInfoDf(self,reportTime,docXml):
- vocationinfosg = docXml.documentElement.getElementsByTagName("VOCATIONINFOSG");
- df = pd.DataFrame()
- if len(vocationinfosg)>0:
- for i in range(0, len(vocationinfosg)):
- # df.loc[i, 0] = self.getNodeData(vocationinfosg[i], "WORDSTATUSDESC")
- df.loc[i, 0] = self.getNodeData(vocationinfosg[i], "CPNTYPEDESC")
- df.loc[i, 1] = self.getNodeData(vocationinfosg[i], "TRADEDESC")
- df.loc[i, 2] = self.getNodeData(vocationinfosg[i], "VOCATIONDESC")
- df.loc[i, 3] = self.getNodeData(vocationinfosg[i], "VOCATIONTITLEDESC")
- df.loc[i, 4] = self.getNodeData(vocationinfosg[i], "COMPANY")
- df.loc[i, 5] = self.getNodeData(vocationinfosg[i], "CPNADDRESS")
- df.loc[i, 6] = self.getNodeData(vocationinfosg[i], "CPNTELNUM")
- df.loc[i, 7] = self.getNodeData(vocationinfosg[i], "BEGINYEAR")
- df.loc[i, 8] = self.getNodeData(vocationinfosg[i], "INFOUPDATEDATE")
- occupationInfoDf.loc[occupationInfoIndex, '工作单位'] = self.getNodeData(vocationinfosg[0], "COMPANY")
- last3yearDate = utils.getLastMonthDate(reportTime, 12 * 3)
- last3yearOccDf = df[df[8] >= last3yearDate]
- occupationInfoDf.loc[occupationInfoIndex, '最近3年内工作单位数'] = last3yearOccDf.index.size;
- occupationInfoDf.loc[occupationInfoIndex, '单位电话'] = self.getNodeData(vocationinfosg[0], "CPNTELNUM")
- try:
- minDateIndex = np.argmin(df[7]);
- maxDateIndex = np.argmax(df[7]);
- rowYearMin = df.loc[minDateIndex, :].dropna()
- rowYearMax = df.loc[maxDateIndex, :].dropna()
- if rowYearMin[7] != "":
- occupationInfoDf.loc[occupationInfoIndex, '最早进入本单位年份距报告日期时长'] = int(
- str(np.datetime64(reportTime, "Y"))) - int(rowYearMin[7])
- if rowYearMax[7] != "":
- occupationInfoDf.loc[occupationInfoIndex, '最新进入本单位年份距报告日期时长'] = int(
- str(np.datetime64(reportTime, "Y"))) - int(rowYearMax[7])
- except:
- logger.error("最早进入本单位年份距报告日期时长解析异常")
- occupationInfoDf.loc[occupationInfoIndex, '单位性质'] = self.getNodeData(vocationinfosg[0], "CPNTYPEDESC")
- occupationInfoDf.loc[occupationInfoIndex, '单位地址'] = self.getNodeData(vocationinfosg[0], "CPNADDRESS")
- occupationInfoDf.loc[occupationInfoIndex, '职业'] = self.getNodeData(vocationinfosg[0], "VOCATIONDESC")
- occupationInfoDf.loc[occupationInfoIndex, '行业'] = self.getNodeData(vocationinfosg[0], "TRADEDESC")
- occupationInfoDf.loc[occupationInfoIndex, '职务'] = self.getNodeData(vocationinfosg[0], "TITLEDESC")
- occupationInfoDf.loc[occupationInfoIndex, '职称'] = self.getNodeData(vocationinfosg[0], "VOCATIONTITLEDESC")
- occupationInfoDf.loc[occupationInfoIndex, '进入本单位年份'] =self.getNodeData(vocationinfosg[0], "BEGINYEAR")
- occupationInfoDf.loc[occupationInfoIndex, '信息更新日期'] = self.getNodeData(vocationinfosg[0], "INFOUPDATEDATE")
- occupationInfoDf.loc[occupationInfoIndex, '历史工作单位数'] = len(vocationinfosg)
- # print(occupationInfoDf.to_json(orient="index", force_ascii=False))
- # 信贷交易明细汇总
- def parseLoanTradeInfo(self,docXml):
- credittipsinfo = docXml.documentElement.getElementsByTagName("CREDITTIPSINFO");
- if len(credittipsinfo)>0:
- briefInfoDf_loanTradeInfo.loc[loanTradeInfoIndex, '个人住房贷款账户数'] = utils.toInt(self.getNodeData(credittipsinfo[0],"ACCOUNTNUM"))
- briefInfoDf_loanTradeInfo.loc[loanTradeInfoIndex, '个人商用房贷款(包括商住两用)账户数'] = utils.toInt(self.getNodeData(credittipsinfo[1],"ACCOUNTNUM"))
- briefInfoDf_loanTradeInfo.loc[loanTradeInfoIndex, '其他类贷款账户数'] = utils.toInt(self.getNodeData(credittipsinfo[2],"ACCOUNTNUM"))
- briefInfoDf_loanTradeInfo.loc[loanTradeInfoIndex, '贷记卡账户数'] = utils.toInt(self.getNodeData(credittipsinfo[3],"ACCOUNTNUM"))
- briefInfoDf_loanTradeInfo.loc[loanTradeInfoIndex, '准贷记卡账户数'] = utils.toInt(self.getNodeData(credittipsinfo[4],"ACCOUNTNUM"))
- #汇算
- moths = [self.getNodeData(credittipsinfo[0], "FIRSTBUSMONTH"),
- self.getNodeData(credittipsinfo[1], "FIRSTBUSMONTH"),self.getNodeData(credittipsinfo[2], "FIRSTBUSMONTH")]
- moths=utils.get_real_arr(moths)
- if len(moths)>0:
- otherDf.loc[otherIndex, '首笔贷款发放月份'] = min(moths)
- otherDf.loc[otherIndex, '首张贷记卡发卡月份'] = self.getNodeData(credittipsinfo[3], "FIRSTBUSMONTH")
- # print(briefInfoDf_loanTradeInfo.to_json(orient="index", force_ascii=False))
- # 解析被追偿信息汇总
- def parseRecoveryInfoSum(self,docXml):
- recoveredinfosumsmry = docXml.documentElement.getElementsByTagName("RECOVEREDINFOSUMSMRY");
- recorinfosumsg = docXml.documentElement.getElementsByTagName("RECORINFOSUMSG")
- if len(recoveredinfosumsmry)>0:
- if len(recorinfosumsg)>0:
- briefInfoDf_recoveryInfoSum.loc[recoveryInfoSumIndex, '资产处置业务账户数'] = utils.toInt(self.getNodeData(recorinfosumsg[0],"ACCOUNTNUM"))
- briefInfoDf_recoveryInfoSum.loc[recoveryInfoSumIndex, '资产处置业务余额'] = utils.replaceAmt(self.getNodeData(recorinfosumsg[0],"BALANCE"))
- briefInfoDf_recoveryInfoSum.loc[recoveryInfoSumIndex, '垫款业务账户数'] = utils.toInt(self.getNodeData(recorinfosumsg[1],"ACCOUNTNUM"))
- briefInfoDf_recoveryInfoSum.loc[recoveryInfoSumIndex, '垫款业务余额'] = utils.replaceAmt(self.getNodeData(recorinfosumsg[1],"BALANCE"))
- briefInfoDf_recoveryInfoSum.loc[recoveryInfoSumIndex, '合计总账户数'] = utils.toInt(self.getNodeData(recoveredinfosumsmry[0],"ACCOUNTNUMSUM"))
- briefInfoDf_recoveryInfoSum.loc[recoveryInfoSumIndex, '合计总余额'] = utils.replaceAmt(self.getNodeData(recoveredinfosumsmry[0],"BALANCESUM"))
- # print(briefInfoDf_recoveryInfoSum.to_json(orient="index", force_ascii=False))
- # 解析呆账信息汇总
- def parseBadDebtsInfoSumDf(self,docXml):
- baddebtssmry = docXml.documentElement.getElementsByTagName("BADDEBTSSMRY");
- if len(baddebtssmry)>0:
- briefInfoDf_badDebtsInfoSum.loc[badDebtsInfoIndex, '账户数'] = utils.toInt(self.getNodeData(baddebtssmry[0],"ACCOUNTNUM"))
- briefInfoDf_badDebtsInfoSum.loc[badDebtsInfoIndex, '余额'] = utils.replaceAmt(self.getNodeData(baddebtssmry[0],"BALANCE"));
- # print(briefInfoDf_badDebtsInfoSum.to_json(orient="index", force_ascii=False))
- #透支及逾期信息汇总
- def parseOverdueInfoSum(self,docXml):
- overdraftsumsg = docXml.documentElement.getElementsByTagName("OVERDRAFTSUMSG");
- df = pd.DataFrame()
- if len(overdraftsumsg)>0:
- for i in range(0, len(overdraftsumsg)):
- df.loc[i, 0] = self.getNodeData(overdraftsumsg[i], "ACCTYPEDESC")
- df.loc[i, 1] = self.getNodeData(overdraftsumsg[i], "ACCSUM")
- df.loc[i, 2] = self.getNodeData(overdraftsumsg[i], "MONTHSUM")
- df.loc[i, 3] = self.getNodeData(overdraftsumsg[i], "OVERDRAFTMAX")
- df.loc[i, 4] = self.getNodeData(overdraftsumsg[i], "OVERMONTH")
- if len(overdraftsumsg)>0:
- briefInfoDf_overdueInfoSum.loc[overdueInfoSumIndex, '非循环贷帐户账户数'] = utils.toInt(self.getNodeData(overdraftsumsg[0],"ACCSUM"));
- briefInfoDf_overdueInfoSum.loc[overdueInfoSumIndex, '非循环贷帐户月份数'] = utils.toInt(self.getNodeData(overdraftsumsg[0],"MONTHSUM"));
- briefInfoDf_overdueInfoSum.loc[overdueInfoSumIndex, '非循环贷帐户单月最高逾期总额'] = utils.replaceAmt(self.getNodeData(overdraftsumsg[0],"OVERDRAFTMAX"));
- briefInfoDf_overdueInfoSum.loc[overdueInfoSumIndex, '非循环贷帐户最长逾期月数'] = utils.toInt(self.getNodeData(overdraftsumsg[0],"OVERMONTH"));
- briefInfoDf_overdueInfoSum.loc[overdueInfoSumIndex, '循环额度下分账户账户数'] = utils.toInt(self.getNodeData(overdraftsumsg[1],"ACCSUM"));
- briefInfoDf_overdueInfoSum.loc[overdueInfoSumIndex, '循环额度下分账户月份数'] = utils.toInt(self.getNodeData(overdraftsumsg[1],"MONTHSUM"));
- briefInfoDf_overdueInfoSum.loc[overdueInfoSumIndex, '循环额度下分账户单月最高逾期总额'] = utils.replaceAmt(self.getNodeData(overdraftsumsg[1],"OVERDRAFTMAX"));
- briefInfoDf_overdueInfoSum.loc[overdueInfoSumIndex, '循环额度下分账户最长逾期月数'] = utils.toInt(self.getNodeData(overdraftsumsg[1],"OVERMONTH"));
- briefInfoDf_overdueInfoSum.loc[overdueInfoSumIndex, '循环贷账户账户数'] = utils.toInt(self.getNodeData(overdraftsumsg[2],"ACCSUM"));
- briefInfoDf_overdueInfoSum.loc[overdueInfoSumIndex, '循环贷账户月份数'] = utils.toInt(self.getNodeData(overdraftsumsg[2],"MONTHSUM"));
- briefInfoDf_overdueInfoSum.loc[overdueInfoSumIndex, '循环贷账户单月最高逾期总额'] = utils.replaceAmt(self.getNodeData(overdraftsumsg[2],"OVERDRAFTMAX"));
- briefInfoDf_overdueInfoSum.loc[overdueInfoSumIndex, '循环贷账户最长逾期月数'] = utils.toInt(self.getNodeData(overdraftsumsg[2],"OVERMONTH"));
- briefInfoDf_overdueInfoSum.loc[overdueInfoSumIndex, '贷记卡账户账户数'] = utils.toInt(self.getNodeData(overdraftsumsg[3],"ACCSUM"));
- briefInfoDf_overdueInfoSum.loc[overdueInfoSumIndex, '贷记卡账户月份数'] = utils.toInt(self.getNodeData(overdraftsumsg[3],"MONTHSUM"));
- briefInfoDf_overdueInfoSum.loc[overdueInfoSumIndex, '贷记卡账户单月逾期总额'] = utils.replaceAmt(self.getNodeData(overdraftsumsg[3],"OVERDRAFTMAX"));
- briefInfoDf_overdueInfoSum.loc[overdueInfoSumIndex, '贷记卡账户最长逾期月数'] = utils.toInt(self.getNodeData(overdraftsumsg[3],"OVERMONTH"));
- briefInfoDf_overdueInfoSum.loc[overdueInfoSumIndex, '准贷记卡账户账户数'] = utils.toInt(self.getNodeData(overdraftsumsg[4],"ACCSUM"));
- briefInfoDf_overdueInfoSum.loc[overdueInfoSumIndex, '准贷记卡账户月份数'] = utils.toInt(self.getNodeData(overdraftsumsg[4],"MONTHSUM"));
- briefInfoDf_overdueInfoSum.loc[overdueInfoSumIndex, '准贷记卡账户单月透支总额'] = utils.replaceAmt(self.getNodeData(overdraftsumsg[4],"OVERDRAFTMAX"));
- briefInfoDf_overdueInfoSum.loc[overdueInfoSumIndex, '准贷记卡账户最长透支月数'] = utils.toInt(self.getNodeData(overdraftsumsg[4],"OVERMONTH"));
- overdueInfoAccountDf = df[df[1] != ''];
- briefInfoDf_overdueInfoSum.loc[overdueInfoSumIndex, '该用户所有逾期账户最长逾期/透支月数最大值'] = np.max(overdueInfoAccountDf[4].astype('int'))
- briefInfoDf_overdueInfoSum.loc[overdueInfoSumIndex, '该用户所有逾期账户数加总'] = np.sum(overdueInfoAccountDf[1].astype('int')) # TODO
- # briefInfoDf_overdueInfoSum.loc[overdueInfoSumIndex, '该用户过去5年出现逾期的所有账户数目']=None# TODO
- # print(briefInfoDf_overdueInfoSum.to_json(orient="index", force_ascii=False))
- # 非循环贷账户信息汇总
- def parseLoanAccountInfoSum(self,docXml):
- noncyclicalsmry = docXml.documentElement.getElementsByTagName("NONCYCLICALSMRY");
- if len(noncyclicalsmry)>0:
- # loanAccountInfoSumDf = doFilterCalc(loanAccountInfoSumDf); # 替换为0
- #TODO 需要检查是否都有值
- # loanAccountInfoSumDf = loanAccountInfoSumDf.reset_index(drop=True)
- # row0 = loanAccountInfoSumDf.loc[0, :]
- briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '非循环贷账户管理机构数'] = int(self.getNodeData(noncyclicalsmry[0],"MANAGEORGNUM"))
- briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '非循环贷账户账户数'] = int(self.getNodeData(noncyclicalsmry[0],"ACCSUM"))
- briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '非循环贷账户授信总额'] = utils.replaceAmt(self.getNodeData(noncyclicalsmry[0],"CREDITSUM"))
- briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '非循环贷账户余额'] = utils.replaceAmt(self.getNodeData(noncyclicalsmry[0],"BALANCE"))
- briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '非循环贷账户6月平均应还款'] = utils.replaceAmt(self.getNodeData(noncyclicalsmry[0],"LATELY6MON"))
- # print(briefInfoDf_loanTradeCreditInfo.to_json(orient="index", force_ascii=False))
- # 循环额度下分账户
- def parseCycleCreditAccountInfoSum(self,docXml):
- cybranchaccsmry = docXml.documentElement.getElementsByTagName("CYBRANCHACCSMRY");
- if len(cybranchaccsmry) > 0:
- briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '循环额度下分账户管理机构数'] = int(self.getNodeData(cybranchaccsmry[0],"MANAGEORGNUM"))
- briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '循环额度下分账户账户数'] = int(self.getNodeData(cybranchaccsmry[0],"ACCSUM"))
- briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '循环额度下分账户授信总额'] = utils.replaceAmt(self.getNodeData(cybranchaccsmry[0],"CREDITSUM"))
- briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '循环额度下分账户余额'] = utils.replaceAmt(self.getNodeData(cybranchaccsmry[0],"BALANCE"))
- briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '循环额度下分账户6月平均应还款'] = utils.replaceAmt(self.getNodeData(cybranchaccsmry[0],"LATELY6MON"))
- # print(briefInfoDf_loanTradeCreditInfo.to_json(orient="index", force_ascii=False))
- # 循环贷账户信息
- def parseCyleLoanAccountInfoSum(self,docXml):
- cyclicalloansmry = docXml.documentElement.getElementsByTagName("CYCLICALLOANSMRY");
- if len(cyclicalloansmry) > 0:
- briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '循环贷账户管理机构数'] = int(self.getNodeData(cyclicalloansmry[0],"MANAGEORGNUM"))
- briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '循环贷账户账户数'] = int(self.getNodeData(cyclicalloansmry[0],"ACCSUM"))
- briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '循环贷账户授信总额'] = utils.replaceAmt(self.getNodeData(cyclicalloansmry[0],"CREDITSUM"))
- briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '循环贷账户余额'] = utils.replaceAmt(self.getNodeData(cyclicalloansmry[0],"BALANCE"))
- briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '循环贷账户6月平均应还款'] = utils.replaceAmt(self.getNodeData(cyclicalloansmry[0],"LATELY6MON"))
- # 解析贷记卡信息汇总,包含准贷记卡
- def parseCreditCardInfoSum(self,docXml):
- debitcardaccsmry = docXml.documentElement.getElementsByTagName("DEBITCARDACCSMRY");
- if len(debitcardaccsmry) > 0:
- briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '贷记卡发卡机构数'] = int(self.getNodeData(debitcardaccsmry[0],"CARDISSUERNUM"))
- briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '贷记卡账户数'] =int(self.getNodeData(debitcardaccsmry[0],"ACCSUM"))
- briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '贷记卡授信总额'] = utils.replaceAmt(self.getNodeData(debitcardaccsmry[0],"CREDITSUM"))
- briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '贷记卡单家机构最高授信额'] = utils.replaceAmt(self.getNodeData(debitcardaccsmry[0],"CRAMOUNTMAX"))
- briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '贷记卡单家机构最低授信额'] =utils.replaceAmt(self.getNodeData(debitcardaccsmry[0],"CRAMOUNTMIN"))
- briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '贷记卡已用额度'] = utils.replaceAmt(self.getNodeData(debitcardaccsmry[0],"ALREADYUSED"))
- briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '贷记卡最近6个月平均使用额度'] = utils.replaceAmt(self.getNodeData(debitcardaccsmry[0],"LATELY6MONUSE"))
- # 解析贷记卡信息汇总,包含准贷记卡
- def parseCreditCardInfoSumZ(self,docXml):
- zdebitcardaccsmry = docXml.documentElement.getElementsByTagName("ZDEBITCARDACCSMRY");
- if len(zdebitcardaccsmry) > 0:
- briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '准贷记卡发卡机构数'] = int(self.getNodeData(zdebitcardaccsmry[0],"CARDISSUERNUM"))
- briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '准贷记卡账户数'] =int(self.getNodeData(zdebitcardaccsmry[0],"ACCSUM"))
- briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '准贷记卡授信总额'] = utils.replaceAmt(self.getNodeData(zdebitcardaccsmry[0],"CREDITSUM"))
- briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '准贷记卡单家机构最高授信额'] = utils.replaceAmt(self.getNodeData(zdebitcardaccsmry[0],"CRAMOUNTMAX"))
- briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '准贷记卡单家机构最低授信额'] = utils.replaceAmt(self.getNodeData(zdebitcardaccsmry[0],"CRAMOUNTMIN"))
- briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '准贷记卡已用额度'] = utils.replaceAmt(self.getNodeData(zdebitcardaccsmry[0],"OVERDRAFT"))
- briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '准贷记卡最近6个月平均使用额度'] = utils.replaceAmt(self.getNodeData(zdebitcardaccsmry[0],"LATELY6MONDRAFT"))
- # 相关还款责任
- def parseRepaymentSum(self,docXml):
- repaymentinfosmry = docXml.documentElement.getElementsByTagName("REPAYMENTINFOSMRY");
- if len(repaymentinfosmry)>0:
- perAccountNum = 0; # 个人账户数
- orgAccountNum = 0; # 企业账户数
- totalAccountNum = 0; # 总账户数
- guaranteeAccountNum = 0; # 相关还款责任总账户数-担保责任
- otherAccountNum = 0; # 相关还款责任总账户数-其他
- perGuaranteeAmt = 0 # 个人担保金额及其他
- orgGuaranteeAmt = 0 # 企业担保金额及其他
- totalGuaranteeAmt = 0; # 总担保金额
- guaranteeAmt = 0; # 相关还款责任总担保金额
- otherPaymentAmt = 0; # 其他还款责任金额
- perGuaranteeBalance = 0 # 个人担保余额及其他
- orgGuaranteeBalance = 0 # 企业担保余额及其他
- totalGuaranteeBalance = 0; # 总担保余额
- guaranteeBalance = 0; # 相关还款责任总担保余额
- otherPaymentBalance = 0; # 其他还款责任余额
- perGuaranteeNum = self.getNodeData(repaymentinfosmry[0],"ACCSUM")
- perGuaranteeAmtStr = self.getNodeData(repaymentinfosmry[0], "RELPAYRESPSUM")
- perGuaranteeBalanceStr = self.getNodeData(repaymentinfosmry[0], "BALANCE")
- perOtherNum = self.getNodeData(repaymentinfosmry[1], "ACCSUM")
- perOtherAmt = self.getNodeData(repaymentinfosmry[1], "RELPAYRESPSUM")
- perOtherBalance = self.getNodeData(repaymentinfosmry[1], "BALANCE")
- enGuaranteeNum = ""
- enGuaranteeAmt = ""
- enGuaranBalance = ""
- enOtherNum = ""
- enOtherAmt = ""
- enOtherBalance= ""
- if len(repaymentinfosmry)>=3:
- enGuaranteeNum = self.getNodeData(repaymentinfosmry[2], "ACCSUM")
- enGuaranteeAmt = self.getNodeData(repaymentinfosmry[2], "RELPAYRESPSUM")
- enGuaranBalance = self.getNodeData(repaymentinfosmry[2], "BALANCE")
- if len(repaymentinfosmry) >= 4:
- enOtherNum = self.getNodeData(repaymentinfosmry[3], "ACCSUM")
- enOtherAmt = self.getNodeData(repaymentinfosmry[3], "RELPAYRESPSUM")
- enOtherBalance = self.getNodeData(repaymentinfosmry[3], "BALANCE")
- # 计算总账户数
- if perGuaranteeNum != "":
- perAccountNum = perAccountNum + utils.toInt(perGuaranteeNum)
- guaranteeAccountNum = guaranteeAccountNum + utils.toInt(perGuaranteeNum) # 个人担保责任账户数
- if perOtherNum != "":
- perAccountNum = perAccountNum + utils.toInt(perOtherNum) # 其他
- otherAccountNum = otherAccountNum + utils.toInt(perOtherNum) # 其他
- if enGuaranteeNum != None:
- if enGuaranteeNum != "":
- orgAccountNum = orgAccountNum + utils.toInt(enGuaranteeNum)
- guaranteeAccountNum = guaranteeAccountNum + utils.toInt(enGuaranteeNum) # 企业担保责任账户数
- if enOtherNum != "":
- orgAccountNum = orgAccountNum + utils.toInt(enOtherNum) # 其他
- otherAccountNum = otherAccountNum + utils.toInt(enOtherNum) # 其他
- totalAccountNum = perAccountNum + orgAccountNum
- # 计算担保金额
- if perGuaranteeAmtStr != "":
- perGuaranteeAmt = perGuaranteeAmt + utils.replaceAmt(perGuaranteeAmtStr) # 担保
- guaranteeAmt = guaranteeAmt + utils.replaceAmt(perGuaranteeAmtStr) # 担保
- if perOtherAmt != "":
- perGuaranteeAmt = perGuaranteeAmt + utils.replaceAmt(perOtherAmt) # 其他
- otherPaymentAmt = otherPaymentAmt + utils.replaceAmt(perOtherAmt) # 其他
- if enGuaranteeAmt != None:
- if enGuaranteeAmt != "":
- orgGuaranteeAmt = orgGuaranteeAmt + utils.replaceAmt(enGuaranteeAmt) # 担保
- guaranteeAmt = guaranteeAmt + utils.replaceAmt(enGuaranteeAmt) # 担保
- if enOtherAmt != "":
- orgGuaranteeAmt = orgGuaranteeAmt + utils.replaceAmt(enOtherAmt) # 其他
- otherPaymentAmt = otherPaymentAmt + utils.replaceAmt(enOtherAmt) # 其他
- totalGuaranteeAmt = perGuaranteeAmt + orgGuaranteeAmt
- # 计算余额
- if perGuaranteeBalanceStr != "":
- perGuaranteeBalance = perGuaranteeBalance + utils.replaceAmt(perGuaranteeBalanceStr)
- guaranteeBalance = guaranteeBalance + utils.replaceAmt(perGuaranteeBalanceStr) # 个人担保余额
- if perOtherBalance != "":
- perGuaranteeBalance = perGuaranteeBalance + utils.replaceAmt(perOtherBalance) # 其他
- otherPaymentBalance = otherPaymentBalance + utils.replaceAmt(perOtherBalance) # 其他
- if enGuaranBalance != None:
- if enGuaranBalance != "":
- orgGuaranteeBalance = orgGuaranteeBalance + utils.replaceAmt(enGuaranBalance)
- guaranteeBalance = guaranteeBalance + utils.replaceAmt(enGuaranBalance) # 企业担保余额
- if enOtherBalance != "":
- orgGuaranteeBalance = orgGuaranteeBalance + utils.replaceAmt(enOtherBalance)
- otherPaymentBalance = otherPaymentBalance + utils.replaceAmt(enOtherBalance) # 其他
- totalGuaranteeBalance = perGuaranteeBalance + orgGuaranteeBalance
- briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '相关还款责任总账户数(担保+其他+个人+企业)'] = totalAccountNum
- briefInfoDf_loanTradeCreditInfo.loc[
- loanTradeCreditInfoIndex, '相关还款责任总担保金额+总还款责任金额(个人+企业)'] = totalGuaranteeAmt
- briefInfoDf_loanTradeCreditInfo.loc[
- loanTradeCreditInfoIndex, '相关还款责任账户总担保余额+总其他余额(个人+企业)'] = totalGuaranteeBalance
- if totalGuaranteeAmt != 0:
- briefInfoDf_loanTradeCreditInfo.loc[
- loanTradeCreditInfoIndex, '相关还款责任账户总担保余额+总其他余额(个人+企业)/相关还款责任账户总担保金额+总其他金额(个人+企业)'] = \
- round(totalGuaranteeBalance / totalGuaranteeAmt, 2)
- briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '相关还款责任担保总账户数-个人'] = perAccountNum
- briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '相关还款责任总担保金额-个人'] = perGuaranteeAmt
- briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '相关还款责任总担保余额-个人'] = perGuaranteeBalance
- if perGuaranteeBalance != 0:
- briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '相关还款责任总担保余额-个人/相关还款责任总担保金额-个人'] = round(
- perGuaranteeBalance / perGuaranteeBalance, 2)
- briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '相关还款责任总账户数-企业'] = orgAccountNum
- briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '相关还款责任总担保金额-企业'] = orgGuaranteeAmt
- briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '相关还款责任总担保余额-企业'] = orgGuaranteeBalance
- if orgGuaranteeAmt != 0:
- briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '相关还款责任总担保余额-企业/相关还款责任总担保金额-企业'] = round(
- orgGuaranteeBalance / orgGuaranteeAmt, 2)
- briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '相关还款责任总账户数-担保责任'] = guaranteeAccountNum
- briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '相关还款责任总担保金额-担保责任'] = guaranteeAmt
- briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '相关还款责任账户总担保余额-担保责任'] = guaranteeBalance
- if guaranteeAmt != 0:
- briefInfoDf_loanTradeCreditInfo.loc[
- loanTradeCreditInfoIndex, '相关还款责任总担保余额-担保责任/相关还款责任总担保金额-担保责任'] = round(
- guaranteeBalance / guaranteeAmt, 2)
- briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '相关还款责任总账户数-其他'] = otherAccountNum
- briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '相关还款责任总担保金额-其他'] = otherPaymentAmt
- briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '相关还款责任总担保余额-其他'] = otherPaymentBalance
- if otherPaymentAmt != 0:
- briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '相关还款责任账户总担保余额-其他/相关还款责任账户总担保金额-其他'] = round(otherPaymentBalance / otherPaymentAmt, 2)
- # print(briefInfoDf_loanTradeCreditInfo.to_json(orient="index", force_ascii=False))
- #解析公共信息汇总
- def parsePublicInfoBrief(self,docXml):
- comminfosmry = docXml.documentElement.getElementsByTagName("COMMINFOSMRY")
- if len(comminfosmry)>0:
- publicInfoBriefDf.loc[publicInfoBriefIndex, '欠税信息-记录数'] = utils.toInt(self.getNodeData(comminfosmry[0],"RECORDNUM"))
- publicInfoBriefDf.loc[publicInfoBriefIndex, '欠税信息-涉及金额'] = utils.replaceAmt(self.getNodeData(comminfosmry[0],"INVOLVEMONEY"))
- publicInfoBriefDf.loc[publicInfoBriefIndex, '民事判决信息-记录数'] = utils.toInt(self.getNodeData(comminfosmry[1],"RECORDNUM"))
- publicInfoBriefDf.loc[publicInfoBriefIndex, '民事判决信息-涉及金额'] = utils.replaceAmt(self.getNodeData(comminfosmry[1],"INVOLVEMONEY"))
- publicInfoBriefDf.loc[publicInfoBriefIndex, '强制执行信息-记录数'] = utils.toInt(self.getNodeData(comminfosmry[2],"RECORDNUM"))
- publicInfoBriefDf.loc[publicInfoBriefIndex, '强制执行信息-涉及金额'] = utils.replaceAmt(self.getNodeData(comminfosmry[2],"INVOLVEMONEY"))
- publicInfoBriefDf.loc[publicInfoBriefIndex, '行政处罚信息-记录数'] = utils.toInt(self.getNodeData(comminfosmry[3],"RECORDNUM"))
- publicInfoBriefDf.loc[publicInfoBriefIndex, '行政处罚信息-涉及金额'] = utils.replaceAmt(self.getNodeData(comminfosmry[3],"INVOLVEMONEY"))
- # 解析查询信息汇总
- def parseQueryRecordSum(self,docXml):
- queryrecordsumsg = docXml.documentElement.getElementsByTagName("QUERYRECORDSUMSG")
- if len(queryrecordsumsg) > 0:
- queryRecordSumDf.loc[queryRecordSumIndex, '近1月内的查询机构数-贷款审批'] = int(self.getNodeData(queryrecordsumsg[0],"LAST1ORGSP"))
- queryRecordSumDf.loc[queryRecordSumIndex, '近1月内的查询机构数-信用卡审批'] = int(self.getNodeData(queryrecordsumsg[0],"LAST1CREDITSP"))
- queryRecordSumDf.loc[queryRecordSumIndex, '近1月内的查询次数-贷款审批'] = int(self.getNodeData(queryrecordsumsg[0],"NUMSP"))
- queryRecordSumDf.loc[queryRecordSumIndex, '近1月内的查询次数-信用卡审批'] = int(self.getNodeData(queryrecordsumsg[0],"NUMCREDITSP"))
- queryRecordSumDf.loc[queryRecordSumIndex, '近1月内的查询次数-本人查询'] = int(self.getNodeData(queryrecordsumsg[0],"LAST1NUMSELF"))
- queryRecordSumDf.loc[queryRecordSumIndex, '近2年内的查询次数-贷后管理'] = int(self.getNodeData(queryrecordsumsg[0],"L2YNUMDH"))
- queryRecordSumDf.loc[queryRecordSumIndex, '近2年内的查询次数-担保资格审查'] = int(self.getNodeData(queryrecordsumsg[0],"L2YNUMDBZG"))
- # print(queryRecordSumDf.to_json(orient="index", force_ascii=False))
- # 解析查询记录明细
- def parseQueryInfoDetail(self,reportTime,docXml):
- queryRecordsg = docXml.documentElement.getElementsByTagName("QUERYRECORDSG");
- if len(queryRecordsg)>0:
- df = pd.DataFrame()
- for i in range(0, len(queryRecordsg)):
- df.loc[i, 1] = self.getNodeData(queryRecordsg[i], "QUERYDATE")
- df.loc[i, 2] = self.getNodeData(queryRecordsg[i], "QUERYORG")
- queryReson = self.getNodeData(queryRecordsg[i], "QUERYREASONDESC")
- df.loc[i, 3] = queryReson
- queryRecordDetailDf.loc[queryRecordDetailIndex, '近1月查询次数'] =qip.getLastMonthQueryTimes(df, 1, "",reportTime)
- queryRecordDetailDf.loc[queryRecordDetailIndex, '近3月查询次数'] =qip.getLastMonthQueryTimes(df, 3, "",reportTime)
- queryRecordDetailDf.loc[queryRecordDetailIndex, '近6月查询次数'] =qip.getLastMonthQueryTimes(df, 6, "",reportTime)
- queryRecordDetailDf.loc[queryRecordDetailIndex, '近12月查询次数'] =qip.getLastMonthQueryTimes(df, 12, "",reportTime)
- queryRecordDetailDf.loc[queryRecordDetailIndex, '最近1个月查询机构数'] =qip.getLastMonthQueryOrgTimes(df, 1, "", reportTime)
- queryRecordDetailDf.loc[queryRecordDetailIndex, '最近3个月查询机构数'] =qip.getLastMonthQueryOrgTimes(df, 3, "", reportTime)
- queryRecordDetailDf.loc[queryRecordDetailIndex, '最近6个月查询机构数'] =qip.getLastMonthQueryOrgTimes(df, 6, "", reportTime)
- queryRecordDetailDf.loc[queryRecordDetailIndex, '最近12个月查询机构数'] =qip.getLastMonthQueryOrgTimes(df, 12, "", reportTime)
- queryRecordDetailDf.loc[queryRecordDetailIndex, '最近24个月查询机构数'] =qip.getLastMonthQueryOrgTimes(df, 24, "", reportTime)
- queryRecordDetailDf.loc[queryRecordDetailIndex, '近3月查询次数贷款审批'] =qip.getLastMonthQueryTimes(df, 3, consts.loanApprove, reportTime)
- queryRecordDetailDf.loc[queryRecordDetailIndex, '近3月查询次数信用卡审批'] =qip.getLastMonthQueryTimes(df, 3, consts.creditCard, reportTime)
- queryRecordDetailDf.loc[queryRecordDetailIndex, '近6月查询次数贷款审批'] =qip.getLastMonthQueryTimes(df, 6, consts.loanApprove, reportTime)
- queryRecordDetailDf.loc[queryRecordDetailIndex, '近6月查询次数信用卡审批'] = qip.getLastMonthQueryTimes(df, 6, consts.creditCard, reportTime)
- queryRecordDetailDf.loc[queryRecordDetailIndex, '近12月查询次数贷款审批'] = qip.getLastMonthQueryTimes(df, 12, consts.loanApprove, reportTime)
- queryRecordDetailDf.loc[queryRecordDetailIndex, '近12月查询次数信用卡审批'] =qip.getLastMonthQueryTimes(df, 12, consts.creditCard, reportTime)
- queryRecordDetailDf.loc[queryRecordDetailIndex, '近3月查询机构数贷款审批'] =qip.getLastMonthQueryOrgTimes(df, 3, consts.loanApprove, reportTime)
- queryRecordDetailDf.loc[queryRecordDetailIndex, '近3月查询机构数信用卡审批'] =qip.getLastMonthQueryOrgTimes(df, 3, consts.creditCard, reportTime)
- queryRecordDetailDf.loc[queryRecordDetailIndex, '近6月查询机构数贷款审批'] =qip.getLastMonthQueryOrgTimes(df, 6, consts.loanApprove, reportTime)
- queryRecordDetailDf.loc[queryRecordDetailIndex, '近6月查询机构数信用卡审批'] = qip.getLastMonthQueryOrgTimes(df, 6, consts.creditCard,reportTime)
- queryRecordDetailDf.loc[queryRecordDetailIndex, '近12月查询机构数贷款审批'] = qip.getLastMonthQueryOrgTimes(df, 12, consts.loanApprove, reportTime)
- queryRecordDetailDf.loc[queryRecordDetailIndex, '近12月查询机构数信用卡审批'] = qip.getLastMonthQueryOrgTimes(df, 12, consts.creditCard,reportTime)
- queryRecordDetailDf.loc[queryRecordDetailIndex, '最近3个月担保资格审查查询次数'] = qip.getLastMonthQueryTimes(df, 3, consts.insuranceAprove,reportTime)
- queryRecordDetailDf.loc[queryRecordDetailIndex, '最近6个月担保资格审查查询次数'] = qip.getLastMonthQueryTimes(df, 6, consts.insuranceAprove,reportTime)
- queryRecordDetailDf.loc[queryRecordDetailIndex, '近12个月担保资格审查查询次数'] = qip.getLastMonthQueryTimes(df, 12, consts.insuranceAprove,reportTime)
- queryRecordDetailDf.loc[queryRecordDetailIndex, '最近6个月贷后管理查询次数'] = qip.getLastMonthQueryTimes(df, 6, consts.loanAfterMgr,reportTime)
- queryRecordDetailDf.loc[queryRecordDetailIndex, '最近12个月贷后管理查询次数'] = qip.getLastMonthQueryTimes(df, 12, consts.loanAfterMgr,reportTime)
- queryRecordDetailDf.loc[queryRecordDetailIndex, '最后一次查询距离现在的月数贷款审批'] = qip.getLastTimeQueryMonth(df, consts.loanApprove,reportTime)
- queryRecordDetailDf.loc[queryRecordDetailIndex, '最近24个月贷后管理查询次数'] = qip.getLastMonthQueryTimes(df, 24, consts.loanAfterMgr, reportTime)
- queryRecordDetailDf.loc[queryRecordDetailIndex, '最近24个月贷款审批审批次数'] = qip.getLastMonthQueryTimes(df, 24, consts.loanApprove, reportTime)
- queryRecordDetailDf.loc[queryRecordDetailIndex, '最近24个月信用卡审批查询次数'] = qip.getLastMonthQueryTimes(df, 24, consts.creditCard,reportTime)
- queryRecordDetailDf.loc[queryRecordDetailIndex, '最近24个月担保资格审查查询次数'] = qip.getLastMonthQueryTimes(df, 24, consts.insuranceAprove,reportTime)
- #三寿 100年所有信用卡审批
- sanshouDf.loc[sanshouIndex, '贷后管理最近3个月内的机构查询次数'] = qip.getLastMonthQueryTimes(df, 3, consts.loanAfterMgr,reportTime)
- sanshouDf.loc[sanshouIndex, '信用卡审批所有机构查询次数'] =qip.getLastMonthQueryTimes(df, 12*100, consts.creditCard, reportTime)
- sanshouDf.loc[sanshouIndex, '所有本人查询次数'] = qip.getSelfLastMonthQueryTimes(df, 12 * 100,reportTime)
- sanshouDf.loc[sanshouIndex, '最近1年内本人查询次数'] = qip.getSelfLastMonthQueryTimes(df, 12, reportTime)
- sanshouDf.loc[sanshouIndex, '最近2年内本人查询次数'] = qip.getSelfLastMonthQueryTimes(df, 24, reportTime)
- # print(queryRecordDetailDf.to_json(orient="index", force_ascii=False))
- def parseHousingFundRcd(self,reportTime,docXml):
- housingfund = docXml.documentElement.getElementsByTagName("HOUSINGFUND");
- if len(housingfund) >0 :
- df = pd.DataFrame()
- for i in range(0, len(housingfund)):
- df.loc[i, 0] = self.getNodeData(housingfund[i], "ADDRESSDESC")#参缴地
- df.loc[i, 1] = self.getNodeData(housingfund[i], "PAYDATE")#参缴日期
- df.loc[i, 2] = self.getNodeData(housingfund[i], "STATUSDESC")#缴费状态
- df.loc[i, 3] = self.getNodeData(housingfund[i], "BEGINMONTH")#初缴月份
- df.loc[i, 4] = self.getNodeData(housingfund[i], "ENDMONTH")#缴至月份
- df.loc[i, 5] = self.getNodeData(housingfund[i], "COMPROPORTION")#个人存缴比例
- df.loc[i, 6] = self.getNodeData(housingfund[i], "PEPROPORTION")#个人存缴比例
- df.loc[i, 7] = utils.replaceAmt(self.getNodeData(housingfund[i], "MONTHMONEY"))#月缴存额
- df.loc[i, 8] = self.getNodeData(housingfund[i], "COMPANY")#缴费单位
- df.loc[i, 9] = self.getNodeData(housingfund[i], "UPDATEDATE")#信息更新日期
- lastHousingFundRcdDf = df.sort_values(by=9, ascending=(False)).reset_index(drop=True)
- lastHousingFundRcdDf = lastHousingFundRcdDf[0:1] # 最新
- row1 = lastHousingFundRcdDf.loc[0, :].dropna().reset_index(drop=True)
- housingFundRcdDf.loc[housingFundRcdIndex, '参缴地'] = row1[0]
- housingFundRcdDf.loc[housingFundRcdIndex, '参缴日期'] = row1[1]
- housingFundRcdDf.loc[housingFundRcdIndex, '初缴月份'] = row1[3] # 初缴日期
- housingFundRcdDf.loc[housingFundRcdIndex, '缴至月份'] = row1[4]
- housingFundRcdDf.loc[housingFundRcdIndex, '缴费状态'] = row1[2]
- housingFundRcdDf.loc[housingFundRcdIndex, '月缴存额'] = row1[7]
- housingFundRcdDf.loc[housingFundRcdIndex, '个人存缴比例'] = row1[6]
- housingFundRcdDf.loc[housingFundRcdIndex, '单位存缴比例'] = row1[5]
- housingFundRcdDf.loc[housingFundRcdIndex, '缴费单位'] = row1[8] # 扣缴单位
- housingFundRcdDf.loc[housingFundRcdIndex, '信息更新日期'] = row1[9]
- lastDateStr = utils.getLastMonthDate(reportTime, 12)
- avgHousingFundDf = df[df[4] >= lastDateStr]
- housingFundRcdDf.loc[housingFundRcdIndex, '最近1年公积金平均值'] = round(np.mean(avgHousingFundDf[7]), 2)
- lastDateStr = utils.getLastMonthDate(reportTime, 12 * 3)
- avgHousingFundDf = df[df[4] >= lastDateStr]
- housingFundRcdDf.loc[housingFundRcdIndex, '最近3年公积金平均值'] = round(np.mean(avgHousingFundDf[7]), 2)
- # print(housingFundRcdDf.to_json(orient="index", force_ascii=False))
- # 合并被追偿信息
- def mergeRecoveryInfoDf(self, reportTime,docXml):
- tmpNode = docXml.documentElement.getElementsByTagName("FORCEDREPAYINFOBOLS");
- recoveryInfoMergeDf = pd.DataFrame(columns=dfParser.dfHeaderRecoveryInfo)#合并df
- if len(tmpNode)>0:
- forcedrepayinfobols = docXml.documentElement.getElementsByTagName("FORCEDREPAYINFOBOLS")[0]
- creditacctinfobo = forcedrepayinfobols.getElementsByTagName("CREDITACCTINFOBO");
- for i in range(0,len(creditacctinfobo)):
- creditbaseinfobo = creditacctinfobo[i].getElementsByTagName("CREDITBASEINFOBO")[0]
- newperformancebo = creditacctinfobo[i].getElementsByTagName("NEWPERFORMANCEBO")[0]
- # latemonthlyperformancebo = creditacctinfobo[i].getElementsByTagName("LATEMONTHLYPERFORMANCEBO")
- # latemonthlyperformancebo = latemonthlyperformancebo[0]
- specialtradebaseinfosg = creditacctinfobo[i].getElementsByTagName("SPECIALTRADEBASEINFOSG")
- recoveryInfoDf = pd.DataFrame(columns=dfParser.dfHeaderCreditCard, index=[0])
- recoveryInfoDf.loc[0, '账户编号'] = self.getNodeData(creditbaseinfobo,"ACCTNO")
- recoveryInfoDf.loc[0, '管理机构'] = self.getNodeData(creditbaseinfobo,"BUSIORGCODE")
- recoveryInfoDf.loc[0, '业务种类'] = self.getNodeData(creditbaseinfobo,"LOANTYPEDESC")
- recoveryInfoDf.loc[0, '债权接收日期'] = self.getNodeData(creditbaseinfobo,"OPENDATE")
- recoveryInfoDf.loc[0, '债权金额'] = utils.replaceAmt(self.getNodeData(creditbaseinfobo,"LOANAMT"))
- recoveryInfoDf.loc[0, '债权转移时的还款状态'] = self.getNodeData(creditbaseinfobo,"RPYACCOUNTSTATUSDESC")
- recoveryInfoDf.loc[0, '账户状态'] = self.getNodeData(newperformancebo,"ACCTSTATUSDESC")
- accountStatus = self.getNodeData(newperformancebo,"ACCTSTATUSDESC")# 账户状态
- # if accountStatus == "":
- # accountStatus = self.getNodeData(latemonthlyperformancebo, "ACCTSTATUDESC")
- if len(specialtradebaseinfosg)>0:
- recoveryInfoDf.loc[0, '特殊交易类型'] = self.getNodeData(specialtradebaseinfosg[0],"TRANTYPEDESC")
- recoveryInfoDf.loc[0, '发生日期'] = self.getNodeData(specialtradebaseinfosg[0],"TRANDATE")
- recoveryInfoDf.loc[0, '变更月份'] = utils.toInt(self.getNodeData(specialtradebaseinfosg[0],"TRANMONTH"))
- recoveryInfoDf.loc[0, '发生金额'] = utils.replaceAmt(self.getNodeData(specialtradebaseinfosg[0],"TRANAMT"))
- recoveryInfoDf.loc[0, '明细记录'] = self.getNodeData(specialtradebaseinfosg[0],"DETRECORD")
- if accountStatus == "催收":
- recoveryInfoDf.loc[0, '余额'] = utils.replaceAmt(self.getNodeData(newperformancebo,"BALANCE"))
- recoveryInfoDf.loc[0, '最近一次还款日期'] =self.getNodeData(newperformancebo, "REPAYDATE");
- else:
- recoveryInfoDf.loc[0, '账户关闭日期'] = self.getNodeData(newperformancebo,"SETTLEDATE")
- # recoveryInfoDf.loc[0, '截至日期'] = self.getNodeData(newperformancebo,"DUEDATE")
- recoveryInfoMergeDf = pd.concat([recoveryInfoMergeDf, recoveryInfoDf], axis=0,ignore_index=True);
- return recoveryInfoMergeDf
- # 合并贷款记录dataframe为宽表
- def mergeLoanDf(self, reportTime,docXml,type):
- tmpNode = docXml.documentElement.getElementsByTagName(type)
- loanAccountDfs = []
- if len(tmpNode)>0:
- noloopcreditaccountbols = docXml.documentElement.getElementsByTagName(type)[0]
- creditacctinfobo = noloopcreditaccountbols.getElementsByTagName("CREDITACCTINFOBO");
- for i in range(0, len(creditacctinfobo)):
- dfObj = {}
- loanDf = pd.DataFrame(columns=dfParser.dfHeaderLoan, index=[0])
- loanDfObj = loanDf.to_json(orient="index",force_ascii=False)
- loanDfObj = json.loads(loanDfObj)['0']
- creditbaseinfobo = creditacctinfobo[i].getElementsByTagName("CREDITBASEINFOBO")[0]
- newperformancebo = creditacctinfobo[i].getElementsByTagName("NEWPERFORMANCEBO")[0]
- latemonthlyperformancebo = creditacctinfobo[i].getElementsByTagName("LATEMONTHLYPERFORMANCEBO")
- latemonthlyperformancebo = latemonthlyperformancebo[0]
- specialtradebaseinfosg = creditacctinfobo[i].getElementsByTagName("SPECIALTRADEBASEINFOSG")
- fiveyearhisrpyinfols = creditacctinfobo[i].getElementsByTagName("FIVEYEARHISRPYINFOSG")
- loanDfObj['账户编号'] = self.getNodeData(creditbaseinfobo, "ACCTNO")
- loanDfObj['管理机构'] = self.getNodeData(creditbaseinfobo, "BUSIORGCODE")
- loanDfObj['账户标识'] = self.getNodeData(creditbaseinfobo, "ACCTCODE")
- loanDfObj['开立日期'] = self.getNodeData(creditbaseinfobo, "OPENDATE")
- loanDfObj['到期日期'] = self.getNodeData(creditbaseinfobo, "DUEDATE")
- if type=='LOOPCREDITACCOUNTBOLS':#循环贷款账户
- loanDfObj['借款金额(本金)'] = utils.replaceAmt(self.getNodeData(creditbaseinfobo, "ACCTCREDLINE"))
- else:
- loanDfObj['借款金额(本金)'] = utils.replaceAmt(self.getNodeData(creditbaseinfobo, "LOANAMT"))
- loanDfObj['账户币种'] = self.getNodeData(creditbaseinfobo, "MONEYTYPEDESC")
- loanDfObj['业务种类'] = self.getNodeData(creditbaseinfobo, "LOANTYPEDESC")
- loanDfObj['担保方式'] = self.getNodeData(creditbaseinfobo, "GUARMODEDESC")
- loanDfObj['还款期数'] = utils.toInt(self.getNodeData(creditbaseinfobo, "REPAYPRD"))
- loanDfObj['还款频率'] = self.getNodeData(creditbaseinfobo, "REPAYFREQCYDESC")
- loanDfObj['还款方式'] = self.getNodeData(creditbaseinfobo, "REPAYDESC")
- loanDfObj['共同借款标志'] = self.getNodeData(creditbaseinfobo, "COMMBORROWERMAKERDESC")
- # loanDfObj['截至日期'] = formatDateJz(df4[0]);
- accountStatus = self.getNodeData(latemonthlyperformancebo, "ACCTSTATUDESC")
- if accountStatus == "":
- accountStatus = self.getNodeData(newperformancebo,"ACCTSTATUSDESC")
- loanDfObj['账户状态'] = accountStatus;
- if accountStatus != "结清" and accountStatus != "呆账" and accountStatus != "转出":
- loanDfObj['五级分类'] = self.getNodeData(latemonthlyperformancebo, "FIVECATEDESC");
- loanDfObj['余额(本金)'] = utils.replaceAmt(self.getNodeData(latemonthlyperformancebo, "BUSIBAL"))
- loanDfObj['剩余还款期数'] = utils.toInt(self.getNodeData(latemonthlyperformancebo, "REMREPPRD"))
- loanDfObj['本月应还款'] = utils.replaceAmt(self.getNodeData(latemonthlyperformancebo, "CURRPYAMT"))
- loanDfObj['应还款日'] = self.getNodeData(latemonthlyperformancebo, "SETTDATE");
- loanDfObj['本月实还款'] = utils.replaceAmt(self.getNodeData(latemonthlyperformancebo, "ACTRPYAMT"))
- loanDfObj['最近一次还款日期'] = self.getNodeData(latemonthlyperformancebo, "LATRPYDATE");
- loanDfObj['当前逾期期数'] = utils.toInt(self.getNodeData(latemonthlyperformancebo, "OVERDPRD"))
- loanDfObj['当前逾期总额'] = utils.replaceAmt(self.getNodeData(latemonthlyperformancebo, "TOTOVERD"))
- loanDfObj['逾期31-60天未还本金'] = utils.replaceAmt(self.getNodeData(latemonthlyperformancebo, "OVERD3160PRINC"))
- loanDfObj['逾期61-90天未还本金'] = utils.replaceAmt(self.getNodeData(latemonthlyperformancebo, "OVERD6190PRINC"))
- loanDfObj['逾期91-180天未还本金'] = utils.replaceAmt(self.getNodeData(latemonthlyperformancebo, "OVERD91180PRINC"))
- loanDfObj['逾期180天以上未还本金'] = utils.replaceAmt(self.getNodeData(latemonthlyperformancebo, "OVERDPRINCOVE180"))
- # loanDfObj['截至日期月份'] = utils.difMonthReportTime(formatDateJz(df4[0]), reportTime); # 截止日期离报告时间月份
- elif accountStatus == "结清":
- loanDfObj['账户关闭日期'] = self.getNodeData(newperformancebo,"SETTLEDATE")
- elif accountStatus == "转出":
- loanDfObj['转出月份'] = self.getNodeData(newperformancebo,"ROLLOUTDATE")
- elif accountStatus == "呆账":
- loanDfObj['余额(本金)'] = utils.replaceAmt(self.getNodeData(newperformancebo,"BALANCE"))
- loanDfObj['最近一次还款日期'] = self.getNodeData(newperformancebo, "REPAYDATE")
- loanDfObj['管理机构类型'] = self.getNodeData(creditbaseinfobo, "MANAGEORGTYPEDESC")
- # loanDf = pd.DataFrame(loanDfObj)
- dfObj["loanDf"] = loanDfObj;
- #计算流动负债,汇算才需要计算
- # try:
- # self.getDebt(loanDf,reportTime)
- # except Exception:
- # logger.error(traceback.print_exc())
- # logger.error(traceback.format_exc())
- # 解析还款记录
- loanPayRecord = pd.DataFrame()
- # 特殊交易
- specialTradeDf = pd.DataFrame()
- # if(len(fiveyearhisrpyinfols)>0):
- # fiveyearhisrpyinfols = fiveyearhisrpyinfols[0]
- if accountStatus == "正常": # 正常
- recordIndexBegin = 11
- loanPayRecord = self.mergeLoanPayRecordDf(fiveyearhisrpyinfols, loanPayRecord)
- specialTradeDf = self.mergeLoanSpecialTrade(specialtradebaseinfosg, specialTradeDf)
- elif accountStatus == "逾期": # 如果长度小于12后续无需处理
- # 14 11 有提前最新还款记录的为14
- recordIndexBegin = 11
- loanPayRecord = self.mergeLoanPayRecordDf(fiveyearhisrpyinfols, loanPayRecord)
- specialTradeDf = self.mergeLoanSpecialTrade(specialtradebaseinfosg, specialTradeDf)
- elif accountStatus == "结清":
- recordIndexBegin = 9
- loanPayRecord = self.mergeLoanPayRecordDf(fiveyearhisrpyinfols, loanPayRecord)
- specialTradeDf = self.mergeLoanSpecialTrade(specialtradebaseinfosg, specialTradeDf)
- elif accountStatus == "呆账" or accountStatus == "转出":
- recordIndexBegin = 9
- loanPayRecord = self.mergeLoanPayRecordDf(fiveyearhisrpyinfols, loanPayRecord)
- specialTradeDf = self.mergeLoanSpecialTrade(specialtradebaseinfosg, specialTradeDf)
- else:
- print("===================还款状态不满足条件===================#"+self.getNodeData(creditbaseinfobo, "ACCTNO")+"#"+accountStatus)
- dfObj["loanPayRecordDf"] = loanPayRecord
- dfObj["specialTradeDf"] = specialTradeDf
- loanAccountDfs.append(dfObj)
- return loanAccountDfs
- #计算流动负债
- def getDebt(self, loanDf, reportTime):
- if loanDf.loc[0, '账户状态'] != '结清' and loanDf.loc[0, '业务种类'] != '个人住房商业贷款' \
- and loanDf.loc[0, '业务种类'] != '个人商用房(含商住两用)贷款' and loanDf.loc[0, '业务种类'] != '个人住房公积金贷款' and loanDf.loc[
- 0, '业务种类'] != '个人汽车消费贷款':
- # term1 / term2 / term3
- term1 = None
- term2 = None
- term3 = None
- debt_f12 = 0
- payRate = loanDf.loc[0, '还款频率']
- payDue = loanDf.loc[0, '还款期数']
- payRemainderDue = loanDf.loc[0, '剩余还款期数']
- openDate = loanDf.loc[0, '开立日期']
- expireDate = loanDf.loc[0, '到期日期']
- payoutAmt = loanDf.loc[0, '借款金额(本金)'] # 放款金额
- balance = loanDf.loc[0, '余额(本金)']
- # Step1 - 基础变量计算
- if payRate == '月':
- if str(payDue) != "nan" and payDue > 0:
- term1 = payDue
- else:
- term1 = utils.difMonthReportTimeFloor(openDate, expireDate)
- if str(payRemainderDue) != "nan" and payRemainderDue > 0:
- term2 = payRemainderDue
- else:
- term2 = utils.difMonthReportTimeFloor(reportTime, expireDate)
- term3 = term1 - term2
- else:
- term1 = utils.difMonthReportTimeFloor(openDate, expireDate)
- term2 = utils.difMonthReportTimeFloor(reportTime, expireDate)
- term3 = term1 - term2
- if term1 <= 0 or term2 <= 0 or term1 < term2 or openDate == None or expireDate == None:
- tag0 = 1
- else:
- tag0 = 0
- payloan = utils.null2Zero(payoutAmt) - utils.null2Zero(balance)
- payloan = max(0, payloan)
- termpct_12 = max(0, 1 - 0.25 * int((term2 - 1) / 3))
- if loanDf.loc[0, '担保方式'] == '抵押':
- tag1 = 1
- else:
- tag1 = 0
- curActualPay = loanDf.loc[0, '本月实还款']
- curShouldPay = loanDf.loc[0, '本月应还款']
- if str(curActualPay) != "nan" and str(curShouldPay) != "nan":
- if max(curShouldPay, curActualPay) * term1 >= payoutAmt * 1.5:
- tag2 = 1
- elif max(curShouldPay, curActualPay) * term2 >= balance * 1.5:
- tag2 = 1
- elif term2 > 0 and term3 > 0 and payloan / term3 >= 1.5 * (balance / term2):
- tag2 = 1
- elif term2 > 0 and term3 > 0 and balance / term2 >= 1.5 * (payloan / term3):
- tag2 = 1
- elif payoutAmt < balance:
- tag2 = 1
- else:
- tag2 = 0
- if tag1 == 1:
- pay_rat = 0.0036
- else:
- pay_rat = 0.0083
- if tag1 == 1:
- mthly_intr = 0.07 / 12
- else:
- mthly_intr = 0.18 / 12
- totpayment1 = payoutAmt * mthly_intr * term1 + payoutAmt
- totpayment2 = balance * mthly_intr * term2 + balance
- # Step2-贷款分流负债统计
- if tag0 == 1:
- debt_f12 = balance * (1 + pay_rat * 12)
- elif tag1 == 1:
- debt_f12 = payoutAmt * pay_rat * 12
- elif payRate != '月' or payRate == None:
- monthy_pay_ref1 = totpayment1 / term1;
- monthy_pay_ref2 = totpayment2 / term2;
- monthy_pay_final = max(monthy_pay_ref1, monthy_pay_ref2);
- debt_f12 = min(monthy_pay_final * 12, totpayment1, totpayment2);
- elif tag2 == 1:
- debt_f12 = min(balance * mthly_intr * min(term2, 12) + termpct_12 * balance, totpayment1, totpayment2);
- else:
- monthy_pay_ref1 = ((pay_rat * term1 + 1) * payoutAmt) / term1
- if term2 == 0:
- print(loanDf.loc[0, '账户编号'])
- monthy_pay_ref2 = ((pay_rat * term2 + 1) * balance) / term2
- monthy_pay_final = max(curShouldPay, monthy_pay_ref1, monthy_pay_ref2);
- debt_f12 = min(monthy_pay_final * 12, balance * (1 + pay_rat * 12), balance * (1 + mthly_intr * term2));
- loanDf.loc[0, '贷款负债'] = debt_f12
- def mergeCreditCardDf(self,reportTime,docXml):
- creditCardAccountDfs = []
- tmpNode = docXml.documentElement.getElementsByTagName("CREDITCARDACCOUNTBOLS");
- if len(tmpNode)>0:
- noloopcreditaccountbols = docXml.documentElement.getElementsByTagName("CREDITCARDACCOUNTBOLS")[0]
- creditacctinfobo = noloopcreditaccountbols.getElementsByTagName("CREDITACCTINFOBO");
- for i in range(0, len(creditacctinfobo)):
- dfObj = {}
- creditCardDf = pd.DataFrame(columns=dfParser.dfHeaderCreditCard, index=[0])
- creditbaseinfobo = creditacctinfobo[i].getElementsByTagName("CREDITBASEINFOBO")[0]
- newperformancebo = creditacctinfobo[i].getElementsByTagName("NEWPERFORMANCEBO")[0]
- latemonthlyperformancebo = creditacctinfobo[i].getElementsByTagName("LATEMONTHLYPERFORMANCEBO")
- latemonthlyperformancebo = latemonthlyperformancebo[0]
- bigquotabaselnfosg = creditacctinfobo[i].getElementsByTagName("BIGQUOTABASELNFOSG")
- fiveyearhisrpyinfols = creditacctinfobo[i].getElementsByTagName("FIVEYEARHISRPYINFOSG")
- creditCardDf.loc[0, '账户编号'] = self.getNodeData(creditbaseinfobo, "ACCTNO")
- creditCardDf.loc[0, '发卡机构'] = self.getNodeData(creditbaseinfobo, "BUSIORGCODE")
- creditCardDf.loc[0, '账户标识'] = self.getNodeData(creditbaseinfobo, "ACCTCODE")
- creditCardDf.loc[0, '开立日期'] = self.getNodeData(creditbaseinfobo, "OPENDATE")
- creditCardDf.loc[0, '账户授信额度'] = utils.replaceAmt(self.getNodeData(creditbaseinfobo, "ACCTCREDLINE"))
- creditCardDf.loc[0, '共享授信额度'] = utils.replaceAmt(self.getNodeData(creditbaseinfobo, "ORGCREDLINE"))
- # 排除美元027
- MONEYTYPEDESC = self.getNodeData(creditbaseinfobo, "MONEYTYPEDESC")
- if MONEYTYPEDESC.find('人民币')<0:
- continue
- # if MONEYTYPEDESC.find('美元')>= 0:
- # continue
- creditCardDf.loc[0, '币种'] = self.getNodeData(creditbaseinfobo, "MONEYTYPEDESC")
- creditCardDf.loc[0, '业务种类'] = self.getNodeData(creditbaseinfobo, "LOANTYPEDESC")
- creditCardDf.loc[0, '担保方式'] = self.getNodeData(creditbaseinfobo, "GUARMODEDESC")
- accountStatus = self.getNodeData(latemonthlyperformancebo, "ACCTSTATUDESC")
- if accountStatus == "":
- accountStatus = self.getNodeData(newperformancebo,"ACCTSTATUSDESC")
- if accountStatus.find('未激活') < 0: # 非未激活
- if accountStatus == "呆账":
- creditCardDf.loc[0, '账户状态'] = accountStatus
- creditCardDf.loc[0, '余额'] = utils.replaceAmt(self.getNodeData(newperformancebo, "BALANCE"))
- creditCardDf.loc[0, '最近一次还款日期'] = self.getNodeData(newperformancebo, "REPAYDATE")
- elif accountStatus != '销户':
- try:
- creditCardDf.loc[0, '账户状态'] =accountStatus
- creditCardDf.loc[0, '余额'] = utils.replaceAmt(self.getNodeData(latemonthlyperformancebo, "BUSIBAL"))
- creditCardDf.loc[0, '已用额度'] = utils.replaceAmt(self.getNodeData(latemonthlyperformancebo, "ACCTBAL"))
- dividePeriodBalance = self.getNodeData(latemonthlyperformancebo, "INSTBAL") # 未出单的大额专项分期余额
- creditCardDf.loc[0, '未出单的大额专项分期余额'] = utils.replaceAmt(self.getNodeData(latemonthlyperformancebo, "INSTBAL"))
- creditCardDf.loc[0, '剩余分期期数'] = utils.toInt(self.getNodeData(latemonthlyperformancebo, "REMREPPRD"))
- creditCardDf.loc[0, '最近6个月平均使用额度'] = utils.replaceAmt(self.getNodeData(latemonthlyperformancebo, "AVGUSEAMOUNT"))
- creditCardDf.loc[0, '最大使用额'] = utils.replaceAmt(self.getNodeData(latemonthlyperformancebo, "MAXUSEAMOUNT"))
- creditCardDf.loc[0, '账单日'] = self.getNodeData(latemonthlyperformancebo, "SETTDATE")
- creditCardDf.loc[0, '本月应还款'] = utils.replaceAmt(self.getNodeData(latemonthlyperformancebo, "CURRPYAMT"))
- creditCardDf.loc[0, '本月实还款'] = utils.replaceAmt(self.getNodeData(latemonthlyperformancebo, "ACTRPYAMT"))
- creditCardDf.loc[0, '最近一次还款日期'] = self.getNodeData(latemonthlyperformancebo, "LATRPYDATE");
- creditCardDf.loc[0, '当前逾期期数'] = utils.toInt(self.getNodeData(latemonthlyperformancebo,"OVERDPRD"))
- creditCardDf.loc[0, '当前逾期总额'] = utils.replaceAmt(self.getNodeData(latemonthlyperformancebo,"TOTOVERD"))
- except Exception:
- logger.info("解析贷记卡异常-" + i)
- info = sys.exc_info()
- logger.error(info[0])
- logger.error(info[1])
- logger.error(traceback.extract_tb(info[2]))
- if len(bigquotabaselnfosg) >0:
- bigquotabaselnfosg = bigquotabaselnfosg[0]
- # '大额专项分期额度','分期额度生效日期','分期额度到期日期','已用分期金额']
- creditCardDf.loc[0, '大额专项分期额度'] = utils.replaceAmt(self.getNodeData(bigquotabaselnfosg, "SPECLINE"))
- creditCardDf.loc[0, '分期额度生效日期'] = self.getNodeData(bigquotabaselnfosg, "SPECLINE")
- creditCardDf.loc[0, '分期额度到期日期'] = self.getNodeData(bigquotabaselnfosg, "SPECENDDATE")
- creditCardDf.loc[0, '已用分期金额'] = utils.replaceAmt(self.getNodeData(bigquotabaselnfosg, "INSTAMT"))
- else:
- accountStatus = '销户'
- creditCardDf.loc[0, '账户状态'] = '销户'
- else: # 未激活
- creditCardDf.loc[0, '账户状态'] = '未激活'
- accountStatus = '未激活'
- dfObj["creditCardDf"] = creditCardDf;
- # 解析还款记录
- creditCardPayRecord = pd.DataFrame()
- if accountStatus == "正常" or accountStatus == "冻结" or accountStatus == "止付": # 正常
- recordIndexBegin = 9;
- creditCardPayRecord = self.mergeCreditCardPayRecordDf(fiveyearhisrpyinfols,creditCardPayRecord)
- elif accountStatus == "未激活":
- recordIndexBegin = 0;
- elif accountStatus == "销户" or accountStatus == "呆账":
- recordIndexBegin = 7;
- creditCardPayRecord = self.mergeCreditCardPayRecordDf(fiveyearhisrpyinfols,creditCardPayRecord)
- else:
- print(self.getNodeData(creditbaseinfobo, "ACCTNO")+"===================还款状态不满足条件==================="+"#"+accountStatus)
- dfObj["creditCardPayRecordDf"] = creditCardPayRecord;
- creditCardAccountDfs.append(dfObj)
- return creditCardAccountDfs;
- def mergeCreditCardDfZ(self,reportTime,docXml):
- tmpNode = docXml.documentElement.getElementsByTagName("PASSCREDITCARDACCOUNTBOLS");
- creditCardAccountDfsZ = []
- if len(tmpNode)>0:
- noloopcreditaccountbols = docXml.documentElement.getElementsByTagName("PASSCREDITCARDACCOUNTBOLS")[0]
- creditacctinfobo = noloopcreditaccountbols.getElementsByTagName("CREDITACCTINFOBO");
- for i in range(0, len(creditacctinfobo)):
- dfObj = {}
- creditCardDf = pd.DataFrame(columns=dfParser.dfHeaderCreditCardZ, index=[0])
- creditbaseinfobo = creditacctinfobo[i].getElementsByTagName("CREDITBASEINFOBO")[0]
- newperformancebo = creditacctinfobo[i].getElementsByTagName("NEWPERFORMANCEBO")[0]
- latemonthlyperformancebo = creditacctinfobo[i].getElementsByTagName("LATEMONTHLYPERFORMANCEBO")
- latemonthlyperformancebo = latemonthlyperformancebo[0]
- fiveyearhisrpyinfols = creditacctinfobo[i].getElementsByTagName("FIVEYEARHISRPYINFOSG")
- creditCardDf.loc[0, '账户编号'] = self.getNodeData(creditbaseinfobo, "ACCTNO")
- creditCardDf.loc[0, '发卡机构'] = self.getNodeData(creditbaseinfobo, "BUSIORGCODE")
- creditCardDf.loc[0, '账户标识'] = self.getNodeData(creditbaseinfobo, "ACCTCODE")
- creditCardDf.loc[0, '开立日期'] = self.getNodeData(creditbaseinfobo, "OPENDATE")
- creditCardDf.loc[0, '账户授信额度'] = utils.replaceAmt(self.getNodeData(creditbaseinfobo, "ACCTCREDLINE"))
- creditCardDf.loc[0, '共享授信额度'] = utils.replaceAmt(self.getNodeData(creditbaseinfobo, "ORGCREDLINE"))
- creditCardDf.loc[0, '币种'] = self.getNodeData(creditbaseinfobo, "MONEYTYPEDESC")
- creditCardDf.loc[0, '担保方式'] = self.getNodeData(creditbaseinfobo, "GUARMODEDESC")
- MONEYTYPEDESC = self.getNodeData(creditbaseinfobo, "MONEYTYPEDESC")
- if MONEYTYPEDESC.find('人民币') < 0:
- continue
- # if self.getNodeData(creditbaseinfobo, "MONEYTYPEDESC").find('美元') >= 0:
- # continue
- accountStatus = self.getNodeData(latemonthlyperformancebo, "ACCTSTATUDESC")
- if accountStatus == "":
- accountStatus =self.getNodeData(newperformancebo,"ACCTSTATUSDESC")
- if accountStatus.find('未激活') < 0: # 非未激活
- if accountStatus == "呆账":
- creditCardDf.loc[0, '账户状态'] = accountStatus
- creditCardDf.loc[0, '余额'] = utils.replaceAmt(self.getNodeData(newperformancebo, "BALANCE"))
- creditCardDf.loc[0, '透支余额'] = utils.replaceAmt(self.getNodeData(newperformancebo, "BALANCE"))
- creditCardDf.loc[0, '最近一次还款日期'] = self.getNodeData(newperformancebo, "REPAYDATE")
- elif accountStatus != '销户':
- try:
- creditCardDf.loc[0, '账户状态'] = accountStatus
- creditCardDf.loc[0, '透支余额'] = utils.replaceAmt(self.getNodeData(latemonthlyperformancebo, "BUSIBAL"))
- creditCardDf.loc[0, '最近6个月平均透支余额'] = utils.replaceAmt(self.getNodeData(latemonthlyperformancebo, "LATSIXMNAVGOVDFTBAL"))
- creditCardDf.loc[0, '最大透支余额'] = utils.replaceAmt(self.getNodeData(latemonthlyperformancebo, "MAXOVERDRAFTBAL"))
- creditCardDf.loc[0, '账单日'] = self.getNodeData(latemonthlyperformancebo, "SETTDATE")
- creditCardDf.loc[0, '本月实还款'] = utils.replaceAmt(self.getNodeData(latemonthlyperformancebo, "ACTRPYAMT"))
- creditCardDf.loc[0, '最近一次还款日期'] = self.getNodeData(latemonthlyperformancebo, "LATRPYDATE");
- creditCardDf.loc[0, '透支180天以上未付余额'] = utils.replaceAmt(self.getNodeData(latemonthlyperformancebo, "OVERDRAWBAOVE180"))
- except:
- logger.info("解析准贷记卡异常-" + i);
- else:
- accountStatus = '销户'
- creditCardDf.loc[0, '账户状态'] = '销户'
- creditCardDf.loc[0, '最近一次还款日期'] = ""
- else: # 未激活
- creditCardDf.loc[0, '账户状态'] = '未激活'
- accountStatus = '未激活'
- creditCardDf.loc[0, '最近一次还款日期'] = ""
- dfObj["creditCardDfZ"] = creditCardDf;
- # 解析还款记录
- creditCardPayRecord = pd.DataFrame()
- if accountStatus == "正常" or accountStatus == "冻结" or accountStatus == "止付": # 正常
- recordIndexBegin = 9;
- creditCardPayRecord = self.mergeCreditCardPayRecordDf(fiveyearhisrpyinfols,creditCardPayRecord)
- elif accountStatus == "未激活":
- recordIndexBegin = 0;
- elif accountStatus == "销户" or accountStatus == "呆账":
- recordIndexBegin = 7;
- creditCardPayRecord = self.mergeCreditCardPayRecordDf(fiveyearhisrpyinfols,creditCardPayRecord)
- else:
- print("账户#" + str(i + 1) + "#" + self.getNodeData(creditbaseinfobo, "ACCTNO")+"===================还款状态不满足条件==================="+"#"+accountStatus)
- dfObj["creditCardPayRecordDfZ"] = creditCardPayRecord;
- creditCardAccountDfsZ.append(dfObj)
- return creditCardAccountDfsZ;
- # 合并贷款还款记录明细
- def mergeLoanPayRecordDf(self,fiveyearhisrpyinfols, loanPayRecord):
- # for i in range(0, len(fiveyearhisrpyinfols)):
- # loanPayRecordTmp = pd.DataFrame(columns=dfParser.dfHeaderLoanPayRecord, index=[0])
- # loanPayRecordTmp.loc[0, '账户编号'] = self.getNodeData(fiveyearhisrpyinfols[i], "ACCTNO");
- # loanPayRecordTmp.loc[0, '还款日期'] = self.getNodeData(fiveyearhisrpyinfols[i], "OVERDMON")+"-01";
- # loanPayRecordTmp.loc[0, '还款状态值'] = utils.replaceAmt(self.getNodeData(fiveyearhisrpyinfols[i], "TOTACCTBAL"))
- # loanPayRecordTmp.loc[0, '还款状态'] = self.getNodeData(fiveyearhisrpyinfols[i], "OVERDSTATUSCODE");
- # loanPayRecord = pd.concat([loanPayRecord, loanPayRecordTmp], axis=0, ignore_index=True);
- # return loanPayRecord;
- ds = []
- loanPayRecordTmp = pd.DataFrame(columns=dfParser.dfHeaderLoanPayRecord, index=[0])
- for i in range(0, len(fiveyearhisrpyinfols)):
- dsObj = {}
- # loanPayRecordTmp = pd.DataFrame(columns=dfParser.dfHeaderLoanPayRecord, index=[0])
- # loanPayRecordTmp.loc[0, '账户编号'] = self.getNodeData(fiveyearhisrpyinfols[i], "ACCTNO");
- # loanPayRecordTmp.loc[0, '还款日期'] = self.getNodeData(fiveyearhisrpyinfols[i], "OVERDMON") + "-01";
- # loanPayRecordTmp.loc[0, '还款状态值'] = utils.replaceAmt(self.getNodeData(fiveyearhisrpyinfols[i], "TOTACCTBAL"))
- # loanPayRecordTmp.loc[0, '还款状态'] = self.getNodeData(fiveyearhisrpyinfols[i], "OVERDSTATUSCODE");
- # loanPayRecord = pd.concat([loanPayRecord, loanPayRecordTmp], axis=0, ignore_index=True);
- dsObj["账户编号"] = self.getNodeData(fiveyearhisrpyinfols[i], "ACCTNO");
- dsObj["还款日期"] = self.getNodeData(fiveyearhisrpyinfols[i], "OVERDMON") + "-01";
- dsObj["还款状态值"] = utils.replaceAmt(self.getNodeData(fiveyearhisrpyinfols[i], "TOTACCTBAL"))
- dsObj["还款状态"] = self.getNodeData(fiveyearhisrpyinfols[i], "OVERDSTATUSCODE");
- ds.append(dsObj)
- # if len(ds)>0:
- # loanPayRecordTmp = pd.DataFrame(ds)
- return ds;
- # 合并贷款还款记录明细
- def mergeCreditCardPayRecordDf(self, fiveyearhisrpyinfols, loanPayRecord):
- # for i in range(0, len(fiveyearhisrpyinfols)):
- # loanPayRecordTmp = pd.DataFrame(columns=dfParser.dfHeaderLoanPayRecord, index=[0])
- # loanPayRecordTmp.loc[0, '账户编号'] = self.getNodeData(fiveyearhisrpyinfols[i], "ACCTNO");
- # loanPayRecordTmp.loc[0, '还款日期'] = self.getNodeData(fiveyearhisrpyinfols[i], "OVERDMON") + "-01";
- # loanPayRecordTmp.loc[0, '还款状态值'] = utils.replaceAmt(self.getNodeData(fiveyearhisrpyinfols[i], "TOTACCTBAL"))
- # loanPayRecordTmp.loc[0, '还款状态'] = self.getNodeData(fiveyearhisrpyinfols[i], "OVERDSTATUSCODE");
- # loanPayRecord = pd.concat([loanPayRecord, loanPayRecordTmp], axis=0, ignore_index=True);
- # return loanPayRecord;
- ds = []
- loanPayRecordTmp = pd.DataFrame(columns=dfParser.dfHeaderLoanPayRecord, index=[0])
- for i in range(0, len(fiveyearhisrpyinfols)):
- dsObj = {}
- # loanPayRecordTmp = pd.DataFrame(columns=dfParser.dfHeaderLoanPayRecord, index=[0])
- # loanPayRecordTmp.loc[0, '账户编号'] = self.getNodeData(fiveyearhisrpyinfols[i], "ACCTNO");
- # loanPayRecordTmp.loc[0, '还款日期'] = self.getNodeData(fiveyearhisrpyinfols[i], "OVERDMON") + "-01";
- # loanPayRecordTmp.loc[0, '还款状态值'] = utils.replaceAmt(self.getNodeData(fiveyearhisrpyinfols[i], "TOTACCTBAL"))
- # loanPayRecordTmp.loc[0, '还款状态'] = self.getNodeData(fiveyearhisrpyinfols[i], "OVERDSTATUSCODE");
- # loanPayRecord = pd.concat([loanPayRecord, loanPayRecordTmp], axis=0, ignore_index=True);
- dsObj["账户编号"] = self.getNodeData(fiveyearhisrpyinfols[i], "ACCTNO");
- dsObj["还款日期"] = self.getNodeData(fiveyearhisrpyinfols[i], "OVERDMON") + "-01";
- dsObj["还款状态值"] = utils.replaceAmt(self.getNodeData(fiveyearhisrpyinfols[i], "TOTACCTBAL"))
- dsObj["还款状态"] = self.getNodeData(fiveyearhisrpyinfols[i], "OVERDSTATUSCODE");
- ds.append(dsObj)
- if len(ds)>0:
- loanPayRecordTmp = pd.DataFrame(ds)
- return loanPayRecordTmp;
- # 合并贷款还款记录明细
- #合并特殊交易
- def mergeLoanSpecialTrade(self,specialtradebaseinfosg, specialTradeDf):
- for i in range(0,len(specialtradebaseinfosg)):
- specialTradeDfTmp = pd.DataFrame(columns = dfParser.dfHeaderLoanSpecialTrade, index=[0])
- specialTradeDfTmp.loc[0, '账户编号'] = self.getNodeData(specialtradebaseinfosg[i], "ACCTNO");
- specialTradeDfTmp.loc[0, '特殊交易类型'] = self.getNodeData(specialtradebaseinfosg[i], "TRANTYPEDESC");
- specialTradeDfTmp.loc[0, '发生日期'] = self.getNodeData(specialtradebaseinfosg[i], "TRANDATE");
- specialTradeDfTmp.loc[0, '变更月数'] = utils.toInt(self.getNodeData(specialtradebaseinfosg[i], "TRANMONTH"))
- specialTradeDfTmp.loc[0, '发生金额'] = utils.replaceAmt(self.getNodeData(specialtradebaseinfosg[i], "TRANAMT"))
- specialTradeDfTmp.loc[0, '明细记录'] = self.getNodeData(specialtradebaseinfosg[i], "DETRECORD");
- tradeType = self.getNodeData(specialtradebaseinfosg[i], "TRANTYPEDESC");
- content = self.getNodeData(specialtradebaseinfosg[i], "DETRECORD");
- # TODO 加工严重程度 逻辑待确认
- severity = None
- if tradeType == '提前还款' or tradeType == '提前结清':
- severity = 0
- elif tradeType == '其他' and content.find("提前") >= 0:
- severity = 0
- elif tradeType == '担保人(第三方)代偿':
- severity = 1
- # elif tradeType == "其他" and content.find("担保人代还取消")<0 and content.find("合同展期")<0:
- # severity = 2
- # 同时出现代还和取消
- elif tradeType == "其他" and (content.find("代还") < 0 or content.find("代偿") < 0) and content.find(
- "取消") < 0 and content.find("合同展期") < 0:
- severity = 2
- elif (tradeType == "展期" or tradeType.find('延期') >= 0) and content.find("专升本或研究生入学展期") >= 0:
- severity = 2
- # elif tradeType == "其他" and (content.find("担保人代还取消")>=0 or content.find("合同展期")>=0):
- # severity = 3
- elif tradeType == "其他" and (
- ((content.find("代还") < 0 or content.find("代偿") < 0) and content.find("取消") >= 0) or (
- content.find("合同展期") >= 0)):
- severity = 3
- elif (tradeType == "展期" or tradeType.find('延期') >= 0) and content.find("专升本或研究生入学展期") < 0:
- severity = 3
- elif tradeType == "以资抵债":
- severity = 4
- specialTradeDfTmp.loc[0, '严重程度'] = severity
- specialTradeDf = pd.concat([specialTradeDf, specialTradeDfTmp], axis=0, ignore_index=True);
- return specialTradeDf;
- # 解析被追偿信息汇总
- def parseRecoveryInfoMergeDf(self,df):
- if not df.empty:
- recoveryMaxPayDf = df[df['债权转移时的还款状态'] != '']
- recoveryStatusCs = df[df['账户状态'] == '催收']
- if not recoveryMaxPayDf.empty:
- briefInfoDf_recoveryInfoSum.loc[recoveryInfoSumIndex, '债权转移时的最大还款状态'] = np.max(
- recoveryMaxPayDf['债权转移时的还款状态']);
- briefInfoDf_recoveryInfoSum.loc[recoveryInfoSumIndex, '债权转移时属于催收状态的账户数'] = recoveryStatusCs.index.size;
- briefInfoDf_recoveryInfoSum.loc[recoveryInfoSumIndex, '债权转移时属于催收状态的账户数/被追偿信息总数'] = round(
- recoveryStatusCs.index.size / df.index.size, 2);
- # creditTradeDetailDf_recoveryInfo
- # 被追偿账户总数
- creditTradeDetailDf_recoveryInfo.loc[recoveryInfoIndex, '被追偿账户总数'] = df.index.size;
- creditTradeDetailDf_recoveryInfo.loc[recoveryInfoIndex, '被追偿业务种类'] = df['业务种类'].unique().size;
- creditTradeDetailDf_recoveryInfo.loc[recoveryInfoIndex, '最新一笔被追偿债券接收时间'] = np.max(df['债权接收日期']);
- creditTradeDetailDf_recoveryInfo.loc[recoveryInfoIndex, '总债权金额'] = np.max(df['债权金额']);
- creditTradeDetailDf_recoveryInfo.loc[recoveryInfoIndex, '债权转移时的最大还款状态'] = np.max(
- recoveryMaxPayDf['债权转移时的还款状态']);
- # 解析信贷交易明细-特殊交易
- def parseSpecialTrade(self,df):
- if not df.empty:
- creditTradeDetailHeader_specialTrade.loc[specialTradeIndex, '当前用户发生特殊交易的严重程度'] = np.max(df['严重程度']) # 加工的指标
- maxChangeMonthIndex = np.argmax(np.abs(df['变更月数']))
- meanMonthValue = np.mean(np.abs(df['变更月数']))
- row0 = df.loc[maxChangeMonthIndex, :]
- settleDf = df[(df['特殊交易类型'] == '提前结清') | (df['特殊交易类型'] == '提前还款')]
- debtDf = df[(df['特殊交易类型'] == '以资抵债')]
- creditTradeDetailHeader_specialTrade.loc[specialTradeIndex, '用户发生特殊交易变更月数的最大差值'] = row0[3]
- creditTradeDetailHeader_specialTrade.loc[specialTradeIndex, '用户发生特殊交易变更月数的平均差值'] = round(meanMonthValue, 2)
- creditTradeDetailHeader_specialTrade.loc[specialTradeIndex, '用户特殊交易涉及的发生金额的最大值'] = np.max(df['发生金额'])
- creditTradeDetailHeader_specialTrade.loc[specialTradeIndex, '用户特殊交易涉及的发生金额的平均值'] = round(np.mean(df['发生金额']), 2)
- creditTradeDetailHeader_specialTrade.loc[specialTradeIndex, '用户所有帐户发生提前还款交易的次数统计'] = settleDf.index.size
- creditTradeDetailHeader_specialTrade.loc[specialTradeIndex, '用户所有帐户发生不良特殊交易的次数统计'] = debtDf.index.size;
- # 信贷交易明细-非循环贷账户
- def parseLoanAccountInfo(self,df):
- if not df.empty:
- loanAccountNum = int(briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '非循环贷账户账户数'])
- normalDf = df[(df['账户状态'] != '结清') & (df['账户状态'] != '转出') & (df['账户状态'] != '呆账')].reset_index(drop=True)
- normalDf = normalDf[0:loanAccountNum] # 根据非循环贷账户数进行计算进行截取
- creditTradeDetailDf_loanAccountInfo.loc[loanInfoIndex, '本月应还款(合计)'] = np.sum(normalDf['本月应还款'])
- creditTradeDetailDf_loanAccountInfo.loc[loanInfoIndex, '本月实还款(合计)'] = np.sum(normalDf['本月实还款'])
- creditTradeDetailDf_loanAccountInfo.loc[loanInfoIndex, '最近一次还款日期'] = np.max(normalDf['最近一次还款日期'])
- creditTradeDetailDf_loanAccountInfo.loc[loanInfoIndex, '当前一共逾期期数'] = np.sum(normalDf['当前逾期期数'])
- creditTradeDetailDf_loanAccountInfo.loc[loanInfoIndex, '当前一共逾期总额'] = np.sum(normalDf['当前逾期总额'])
- creditTradeDetailDf_loanAccountInfo.loc[loanInfoIndex, '逾期31-60天未还本金(合计)'] = np.sum(
- normalDf['逾期31-60天未还本金'])
- creditTradeDetailDf_loanAccountInfo.loc[loanInfoIndex, '逾期61-90天未还本金(合计)'] = np.sum(
- normalDf['逾期61-90天未还本金'])
- creditTradeDetailDf_loanAccountInfo.loc[loanInfoIndex, '逾期91-180天未还本金(合计)'] = np.sum(
- normalDf['逾期91-180天未还本金'])
- creditTradeDetailDf_loanAccountInfo.loc[loanInfoIndex, '逾期180天以上未还本金(合计)'] = np.sum(
- normalDf['逾期180天以上未还本金'])
- # 信贷交易明细-循环额度分账户
- def parseCycleCreditAccountInfo(self,df):
- if not df.empty:
- normalDf = df[(df['账户状态'] != '结清') & (df['账户状态'] != '转出') & (df['账户状态'] != '呆账')].reset_index(drop=True)
- loanAccountNum = int(briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '非循环贷账户账户数'])
- cycleCreditAccountNum = int(briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '循环额度下分账户账户数'])
- normalDf = normalDf[loanAccountNum:(loanAccountNum + cycleCreditAccountNum)]
- if not normalDf.empty:
- creditTradeDetailDf_cycleCreditAccountInfo.loc[cycleCreditAccountInfoIndex, '本月应还款(合计)'] = np.sum(
- normalDf['本月应还款'])
- creditTradeDetailDf_cycleCreditAccountInfo.loc[cycleCreditAccountInfoIndex, '本月实还款(合计)'] = np.sum(
- normalDf['本月实还款'])
- creditTradeDetailDf_cycleCreditAccountInfo.loc[cycleCreditAccountInfoIndex, '最近一次还款日期'] = np.max(
- normalDf['最近一次还款日期'])
- creditTradeDetailDf_cycleCreditAccountInfo.loc[cycleCreditAccountInfoIndex, '当前一共逾期期数'] = np.sum(
- normalDf['当前逾期期数'])
- creditTradeDetailDf_cycleCreditAccountInfo.loc[cycleCreditAccountInfoIndex, '当前一共逾期总额'] = np.sum(
- normalDf['当前逾期总额'])
- creditTradeDetailDf_cycleCreditAccountInfo.loc[
- cycleCreditAccountInfoIndex, '逾期31-60天未还本金(合计)'] = np.sum(normalDf['逾期31-60天未还本金'])
- creditTradeDetailDf_cycleCreditAccountInfo.loc[
- cycleCreditAccountInfoIndex, '逾期61-90天未还本金(合计)'] = np.sum(normalDf['逾期61-90天未还本金'])
- creditTradeDetailDf_cycleCreditAccountInfo.loc[
- cycleCreditAccountInfoIndex, '逾期91-180天未还本金(合计)'] = np.sum(normalDf['逾期91-180天未还本金'])
- creditTradeDetailDf_cycleCreditAccountInfo.loc[
- cycleCreditAccountInfoIndex, '逾期180天以上未还本金(合计)'] = np.sum(normalDf['逾期180天以上未还本金'])
- # 信贷交易明细-循环贷账户
- def parseCycleLoanAccountInfo(self,df):
- if not df.empty:
- normalDf = df[(df['账户状态'] != '结清') & (df['账户状态'] != '转出') & (df['账户状态'] != '呆账')]
- loanAccountNum = int(briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '非循环贷账户账户数'])
- cycleCreditAccountNum = int(briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '循环额度下分账户账户数'])
- cycleAccountNum = int(briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '循环贷账户账户数'])
- normalDf = normalDf[(loanAccountNum + cycleCreditAccountNum):normalDf.index.size]
- if not normalDf.empty:
- creditTradeDetailDf_cycleLoanAccountInfo.loc[cycleLoanAccountInfoIndex, '本月应还款(合计)'] = np.sum(
- normalDf['本月应还款'])
- creditTradeDetailDf_cycleLoanAccountInfo.loc[cycleLoanAccountInfoIndex, '本月实还款(合计)'] = np.sum(
- normalDf['本月实还款'])
- creditTradeDetailDf_cycleLoanAccountInfo.loc[cycleLoanAccountInfoIndex, '最近一次还款日期'] = np.max(
- normalDf['最近一次还款日期'])
- creditTradeDetailDf_cycleLoanAccountInfo.loc[cycleLoanAccountInfoIndex, '当前一共逾期期数'] = np.sum(
- normalDf['当前逾期期数'])
- creditTradeDetailDf_cycleLoanAccountInfo.loc[cycleLoanAccountInfoIndex, '当前一共逾期总额'] = np.sum(
- normalDf['当前逾期总额'])
- creditTradeDetailDf_cycleLoanAccountInfo.loc[cycleLoanAccountInfoIndex, '逾期31-60天未还本金(合计)'] = np.sum(
- normalDf['逾期31-60天未还本金'])
- creditTradeDetailDf_cycleLoanAccountInfo.loc[cycleLoanAccountInfoIndex, '逾期61-90天未还本金(合计)'] = np.sum(
- normalDf['逾期61-90天未还本金'])
- creditTradeDetailDf_cycleLoanAccountInfo.loc[cycleLoanAccountInfoIndex, '逾期91-180天未还本金(合计)'] = np.sum(
- normalDf['逾期91-180天未还本金'])
- creditTradeDetailDf_cycleLoanAccountInfo.loc[cycleLoanAccountInfoIndex, '逾期180天以上未还本金(合计)'] = np.sum(
- normalDf['逾期180天以上未还本金'])
- # 解析贷款账户信息指标
- def parseLoanMergeDf(self,df,reportTime):
- if not df.empty:
- sortDf = df.sort_values(by=["账户关闭日期", "借款金额(本金)"], ascending=(False, False))
- sortDf = sortDf[sortDf['账户状态'] == '结清'];
- sortDf = sortDf.reset_index(drop=True)
- if not sortDf.empty:
- row0 = sortDf.loc[0, :]
- loanAccountInfoDf.loc[loanAccountInfoIndex, '最近一笔结清贷款的贷款金额'] = row0['借款金额(本金)']
- openDate = dfParser.formatDate(row0['开立日期'])
- loanAccountInfoDf.loc[loanAccountInfoIndex, '最近一笔结清贷款的发放距今月数'] = utils.difMonthReportTime(openDate,
- reportTime)
- settleDate = dfParser.formatDate(row0['账户关闭日期'])
- loanAccountInfoDf.loc[loanAccountInfoIndex, '最近一笔结清贷款的结清距今月数'] = utils.difMonthReportTime(settleDate,
- reportTime)
- loanAccountInfoDf.loc[loanAccountInfoIndex, '历史贷款总法人机构数'] = df['管理机构'].unique().size
- #1112 汇算
- notSettleDf = df[df['账户状态'] != '结清'];
- otherDf.loc[otherIndex, '未结清贷款机构数'] = notSettleDf['管理机构'].unique().size
- loanAccountInfoDf.loc[loanAccountInfoIndex, '当前同时在用的贷款机构数'] = df[df['余额(本金)'] > 0]['管理机构'].unique().size
- statusDf = df[(df['账户状态'] != '结清') & (df['账户状态'] != '转出')]
- bankDf = statusDf[statusDf['管理机构'].str.contains('银行')]
- # 没有记录
- if statusDf.index.size == 0:
- isNotBankCust = -1
- else:
- if bankDf.index.size > 0: # 有一条以上不为结清,请包含银行
- isNotBankCust = 1;
- else:
- isNotBankCust = 0;
- loanAccountInfoDf.loc[loanAccountInfoIndex, '是否有非银行贷款客户'] = isNotBankCust
- # 最严重的五级分类
- # fiveType = ""
- # for fiveTypeTmp in consts.fiveType:
- # fiveTypeDf = statusDf[statusDf['五级分类']==fiveTypeTmp];
- # if not fiveTypeDf.empty:
- # fiveType = fiveTypeTmp;
- # break;
- # loanAccountInfoDf.loc[loanAccountInfoIndex, '贷款五级分类'] = fiveType
- # 当前贷款LTV
- # 从“贷款信息”中提取,剔除“账户状态”为结清及转出,并剔除“账户状态”为呆账且本金余额 = 0
- # 的记录后,SUM(本金余额) / SUM(贷款本金)
- # 如本金余额为空和贷款本金为0或为空,则当条记录不计算
- loanLtvDf = df[(df['账户状态'] != '结清') & (df['账户状态'] != '转出') & (df['借款金额(本金)'] > 0) & (df['余额(本金)'] != '')]
- badSetDf = loanLtvDf[~((loanLtvDf['账户状态'] == '呆账') & (loanLtvDf['余额(本金)'] == 0))]
- balanceSum = np.sum(badSetDf['余额(本金)'].astype('int'))
- loanAmtSum = np.sum(badSetDf['借款金额(本金)'].astype('int'))
- if (loanAmtSum != 0):
- loanAccountInfoDf.loc[loanAccountInfoIndex, '当前贷款LTV'] = round(np.divide(balanceSum, loanAmtSum), 2)
- loanAccountInfoDf.loc[loanAccountInfoIndex, '当前贷款最高LTV'] = round(
- np.max(np.divide(badSetDf['余额(本金)'].astype('int'), badSetDf['借款金额(本金)'].astype('int'))), 2)
- loanAccountInfoDf.loc[loanAccountInfoIndex, '当前贷款最低LTV'] = round(
- np.min(np.divide(badSetDf['余额(本金)'].astype('int'), badSetDf['借款金额(本金)'].astype('int'))), 2)
- loanAccountInfoDf.loc[loanAccountInfoIndex, '当前贷款平均LTV'] = round(np.mean(np.divide(badSetDf['余额(本金)'].astype('int'), badSetDf['借款金额(本金)'].astype('int'))), 2)
- # ['个人住房商业贷款','个人商用房(含商住两用)贷款','个人住房公积金贷款','房'],
- houseLtvList = consts.houseLtvList;# ['个人住房商业贷款','个人商用房(含商住两用)贷款','个人住房公积金贷款','房'],
- # houseLtvDf = badSetDf[badSetDf['业务种类'].isin(houseLtvList)]
- # if not houseLtvDf.empty:
- # loanAccountInfoDf.loc[loanAccountInfoIndex, '当前房贷LTV'] = round(np.divide(np.sum(houseLtvDf['余额(本金)'].astype('int')),np.sum(houseLtvDf['借款金额(本金)'].astype('int'))), 2)
- # ['个人住房贷款','个人商用房(包括商住两用)贷款']
- loanAccountInfoDf.loc[loanAccountInfoIndex, '当前房贷LTV'] = lip.getCurLtv(badSetDf, houseLtvList)
- loanAccountInfoDf.loc[loanAccountInfoIndex, '当前贷款机构数量'] = loanLtvDf['管理机构'].unique().size
- cardLtvList = ['个人汽车消费贷款']#, '车'
- loanAccountInfoDf.loc[loanAccountInfoIndex, '当前车贷LTV'] = lip.getCurLtv(badSetDf, cardLtvList)
- operateLtvList = ['个人经营性贷款']
- loanAccountInfoDf.loc[loanAccountInfoIndex, '当前经营贷LTV'] = lip.getCurLtv(badSetDf, operateLtvList)
- consumeLtvList = ['其他个人消费贷款']
- loanAccountInfoDf.loc[loanAccountInfoIndex, '当前消费贷LTV'] = lip.getCurLtv(badSetDf, consumeLtvList)
- bankLtvList = ['商业银行', '外资银行', '村镇银行', '住房储蓄银行', '财务公司']
- loanAccountInfoDf.loc[loanAccountInfoIndex, '当前银行贷LTV'] = lip.getCurBankLtv(badSetDf, bankLtvList)
- bankLtvList = ['消费金融公司', '汽车金融公司', '信托公司'] # TODO
- loanAccountInfoDf.loc[loanAccountInfoIndex, '当前消金贷LTV'] = lip.getCurBankLtv(badSetDf, bankLtvList)
- smallLoanLtvList = ['小额信贷公司']
- loanAccountInfoDf.loc[loanAccountInfoIndex, '当前小贷LTV'] = lip.getCurBankLtv(badSetDf, smallLoanLtvList)
- # 当前贷款最大逾期期数
- # 从“贷款信息”中提取,剔除“账户状态”为结清、转出、呆账、呆帐后,MAX(每笔贷款的当前逾期期数)
- loanOverdueLtvDf = df[(df['账户状态'] != '结清') & (df['账户状态'] != '转出') & (df['账户状态'] != '呆账')]
- if not loanOverdueLtvDf.empty:
- loanAccountInfoDf.loc[loanAccountInfoIndex, '当前贷款最大逾期期数'] = np.max(loanOverdueLtvDf['当前逾期期数'])
- loanAccountInfoDf.loc[loanAccountInfoIndex, '当前贷款最大逾期金额'] = np.max(loanOverdueLtvDf['当前逾期总额'])
- loanOverdueLtvDf = loanOverdueLtvDf.reset_index(drop=True)
- maxOverdueIndex = np.argmax(loanOverdueLtvDf['当前逾期期数'])
- loanAccountInfoDf.loc[loanAccountInfoIndex, '当前贷款最大逾期期数对应的最大逾期金额'] = \
- loanOverdueLtvDf.loc[maxOverdueIndex, :]['当前逾期总额']
- loanAccountInfoDf.loc[loanAccountInfoIndex, '近3月开户最高贷款本金'] = lip.getLastLoanAmtMax(df,
- reportTime,
- 3) # 贷款指标加工单独放到一个文件里
- loanAccountInfoDf.loc[loanAccountInfoIndex, '近3月开户最低贷款本金'] = lip.getLastLoanAmtMin(df,
- reportTime,
- 3)
- loanAccountInfoDf.loc[loanAccountInfoIndex, '近3月开户平均贷款本金'] = lip.getLastLoanAmtAvg(df,
- reportTime,
- 3)
- loanAccountInfoDf.loc[loanAccountInfoIndex, '近6月开户最高贷款本金'] = lip.getLastLoanAmtMax(df,
- reportTime,
- 6)
- loanAccountInfoDf.loc[loanAccountInfoIndex, '近6月开户最低贷款本金'] = lip.getLastLoanAmtMin(df,
- reportTime,
- 6)
- loanAccountInfoDf.loc[loanAccountInfoIndex, '近6月开户平均贷款本金'] = lip.getLastLoanAmtAvg(df,
- reportTime,
- 6)
- loanAccountInfoDf.loc[loanAccountInfoIndex, '近12月开户最高贷款本金'] = lip.getLastLoanAmtMax(df,
- reportTime,
- 12)
- loanAccountInfoDf.loc[loanAccountInfoIndex, '近12月开户最低贷款本金'] = lip.getLastLoanAmtMin(df,
- reportTime,
- 12)
- loanAccountInfoDf.loc[loanAccountInfoIndex, '近12月开户平均贷款本金'] = lip.getLastLoanAmtAvg(df,
- reportTime,
- 12)
- lastLoanDf = loanOverdueLtvDf;
- if not lastLoanDf.empty:
- loanAccountInfoDf.loc[loanAccountInfoIndex, '贷款最近一次还款日期距今时长'] = lip.getLastPayDateMinDays(lastLoanDf,reportTime)
- normalDf = df[(df['账户状态'] == '正常') & (df['当前逾期期数'] == 0)]
- # 未结清贷款总账户数:账户状态不等于结清和转出的记录数
- notSettleDf = df[(df['账户状态'] != '结清') & (df['账户状态'] != '转出')]
- #1113 汇算
- cardLoanCountDf = df[df['业务种类'].isin(cardLtvList)]
- otherDf.loc[otherIndex, '车贷发放笔数'] = cardLoanCountDf.index.size
- #count(贷款账户) where 五级分类 in ('关注','次级','可疑','损失')
- fiveDf = df[df['五级分类'].isin(['关注','次级','可疑','损失'])]
- otherDf.loc[otherIndex, "贷款五级分类命中('关注','次级','可疑','损失')的账户数"] = fiveDf.index.size
- loanStatusDf = df[df['账户状态'].isin(['逾期','呆账','转出','担保物不足','强制平仓','司法追偿'])]
- otherDf.loc[otherIndex, "贷款状态为('逾期','呆账','转出','担保物不足','强制平仓','司法追偿')的账户数"] = loanStatusDf.index.size
- #近12个月信贷最大授信额度
- #max(放款金额) where 担保方式 in ("信用/免担保") and 业务种类 not in ("个人住房商业贷款","个人商用房(含商住两用)贷款","个人住房公积金贷款","个人汽车消费贷款") and (报告日期-开立日期)<=360天
- loanCreditAmtDf = df[df['担保方式'].isin(['信用/免担保'])]
- loanCreditAmtDf = loanCreditAmtDf[(~loanCreditAmtDf['业务种类'].isin(consts.notMortgageList))]
- creditDate = utils.getLastMonthDate(reportTime,12)
- loanCreditAmtDf = loanCreditAmtDf[loanCreditAmtDf["开立日期"]>=creditDate]
- if not loanCreditAmtDf.empty:
- otherDf.loc[otherIndex, "近12个月信贷最大授信额度"] = np.max(loanCreditAmtDf['借款金额(本金)'])
- if not notSettleDf.empty:
- loanAccountInfoDf.loc[loanAccountInfoIndex, '当前正常贷款账户数'] = normalDf.index.size
- loanAccountInfoDf.loc[loanAccountInfoIndex, '当前正常贷款账户数占比'] = round(
- normalDf.index.size / notSettleDf.index.size, 2)
- # 当前未结清贷款余额总和
- # ltvDf = tmpDf[tmpDf['业务种类'].isin(bizTypeList)]
- loanAccountInfoDf.loc[loanAccountInfoIndex, '当前未结清贷款余额总和'] = np.sum(notSettleDf['余额(本金)'])
- # loanAccountInfoDf.loc[loanAccountInfoIndex, '当前未结清贷款余额总和'] = np.sum(notSettleDf['余额(本金)'])
- # 当前未结清住房贷款余额总和
- houseDf = notSettleDf[notSettleDf['业务种类'].isin(houseLtvList)]
- loanAccountInfoDf.loc[loanAccountInfoIndex, '当前未结清住房贷款余额总和'] = np.sum(houseDf['余额(本金)'])
- # 当前未结清汽车贷款余额总和
- cardDf = notSettleDf[notSettleDf['业务种类'].isin(cardLtvList)]
- loanAccountInfoDf.loc[loanAccountInfoIndex, '当前未结清汽车贷款余额总和'] = np.sum(cardDf['余额(本金)'])
- # 当前未结清个人经营性贷款余额总和
- operateLtvDf = notSettleDf[notSettleDf['业务种类'].isin(operateLtvList)]
- loanAccountInfoDf.loc[loanAccountInfoIndex, '当前未结清个人经营性贷款余额总和'] = np.sum(operateLtvDf['余额(本金)'])
- # 当前平均每月贷款余额总和
- loanAccountInfoDf.loc[loanAccountInfoIndex, '当前平均每月贷款余额总和'] = round(np.sum(notSettleDf['余额(本金)']) / 12,
- 2)
- # 当前正常贷款账户余额
- loanAccountInfoDf.loc[loanAccountInfoIndex, '当前正常贷款账户余额'] = np.sum(normalDf['余额(本金)'])
- # "从“贷款信息”中提取,剔除结清、转出,当前正常贷款账户余额/未结清贷款总余额(本金余额加总)
- if np.sum(notSettleDf['余额(本金)']) > 0:
- loanAccountInfoDf.loc[loanAccountInfoIndex, '当前正常贷款账户余额占总余额比'] = round(
- np.sum(normalDf['余额(本金)']) / np.sum(notSettleDf['余额(本金)']), 2)
- #1113 汇算
- #sum(本月应还款) where 业务种类 in ("个人住房商业贷款","个人商用房(含商住两用)贷款","个人住房公积金贷款") and 账户状态 not in("结清","转出","呆账")
- housePayDf = notSettleDf[notSettleDf['业务种类'].isin(consts.houseLtvList)]
- otherDf.loc[otherIndex, '房贷月还总额']=np.sum(housePayDf['本月应还款'])
- cardPayMonthDf = notSettleDf[notSettleDf['业务种类'].isin(cardLtvList)]
- otherDf.loc[otherIndex, '车贷月还总额'] = np.sum(cardPayMonthDf['本月应还款'])
- #小额贷款笔数
- smallLoanDf = notSettleDf[notSettleDf['借款金额(本金)']<=20000]
- otherDf.loc[otherIndex, '小额贷款笔数'] = smallLoanDf.index.size
- settleDf = df[(df['账户状态'] == '结清')]
- loanAccountInfoDf.loc[loanAccountInfoIndex, '当前正常结清贷款账户数'] = settleDf.index.size
- loanAccountInfoDf.loc[loanAccountInfoIndex, '当前正常结清贷款账户数占比'] = round(settleDf.index.size / df.index.size, 2)
- # 贷款24期还款记录次数 TODO
- # 最近3个月个人消费贷款发放额度
- loanAccountInfoDf.loc[loanAccountInfoIndex, '贷款本月实还款金额'] = np.sum(loanOverdueLtvDf['本月应还款'])
- loanAccountInfoDf.loc[loanAccountInfoIndex, '最近3个月个人消费贷款发放额度'] = lip.getLastPerConsumeAmt(df, 3, reportTime)
- loanAccountInfoDf.loc[loanAccountInfoIndex, '最近6个月个人消费贷款发放额度'] = lip.getLastPerConsumeAmt(df, 6, reportTime)
- loanAccountInfoDf.loc[loanAccountInfoIndex, '最近12个月个人消费贷款发放额度'] = lip.getLastPerConsumeAmt(df, 12, reportTime)
- # 未结清贷款平均剩余还款期数
- payPieDf = notSettleDf[notSettleDf['还款期数'] != '']
- if payPieDf.index.size != 0:
- loanAccountInfoDf.loc[loanAccountInfoIndex, '未结清贷款平均剩余还款期数'] = round(
- np.sum(payPieDf['剩余还款期数']) / payPieDf.index.size, 2)
- # 当前贷款本月应还金额总和
- loanAccountInfoDf.loc[loanAccountInfoIndex, '当前贷款本月应还金额总和'] = np.sum(notSettleDf['本月应还款'])
- # 当前贷款本月实还金额总额
- loanAccountInfoDf.loc[loanAccountInfoIndex, '当前贷款本月实还金额总额'] = np.sum(notSettleDf['本月实还款'])
- #1112汇算 非抵押类贷款授信总额
- #sum(放款金额) where 业务种类 not in ("个人住房商业贷款","个人商用房(含商住两用)贷款","个人住房公积金贷款","个人汽车消费贷款")
- # and 担保方式 not in ("抵押") and 账户状态不等于"结清" TODO
- notMortgageList = consts.notMortgageList
- notMortgageSettleDf = df[(df['担保方式'] != '抵押') & (df['账户状态'] != '结清')]
- notMortgageSettleDf = notMortgageSettleDf[(~notMortgageSettleDf['业务种类'].isin(notMortgageList))]
- otherDf.loc[otherIndex,"非抵押类贷款授信总额"]=np.sum(notMortgageSettleDf['借款金额(本金)'])
- otherDf.loc[otherIndex, "未结清非抵押贷款笔数"] = notMortgageSettleDf.index.size
- otherDf.loc[otherIndex, "未结清非抵押类贷款本金余额"] = np.sum(notMortgageSettleDf['余额(本金)'])
- notMortgageDf = df[(df['担保方式'] != '抵押') & (df['账户状态'] != '结清') & (df['账户状态'] != '呆账') & (df['账户状态'] != '转出')]
- notMortgageDf = notMortgageDf[(~notMortgageDf['业务种类'].isin(notMortgageList))]
- otherDf.loc[otherIndex, "未结清非抵押类贷款月还总额"] = np.sum(notMortgageDf['本月应还款'])
- sanshouDf.loc[sanshouIndex,"最大贷款余额"]= np.max(notSettleDf["余额(本金)"])
- sanshouDf.loc[sanshouIndex, "未结清所有贷款合同总额"] = np.sum(notSettleDf["借款金额(本金)"])
- # 解析贷记卡账户信息指标
- def parseCreditCardMergeDf(self,df,reportTime):
- if not df.empty:
- # 历史信用卡总法人机构数
- # creditCardAccountInfoDf.loc[creditCardAccountInfoIndex,'历史信用卡总法人机构数'] = df['发卡机构'].unique().size
- # creditCardUseDf = df[df['已用额度']>0];
- # creditCardAccountInfoDf.loc[creditCardAccountInfoIndex,'当前同时在用的信用卡机构数'] = creditCardUseDf['发卡机构'].unique().size
- fstDate = np.min(df['开立日期']);
- sanshouDf.loc[sanshouIndex, '最早信用卡发卡天数'] = utils.difDateReportTime(reportTime,fstDate)
- # 统一排除
- creditDf = df[(df['币种'] == '人民币元') & (df['账户状态'] != '未激活') & (df['账户状态'] != '销户') & (df['账户状态'] != '呆账')]
- totalAmtDf = df[(df['币种'] == '人民币元') & (df['账户状态'] != '未激活') & (df['账户状态'] != '销户') & (df['账户状态'] != '呆账')]
- # 大额专项分期额度(合计)
- # 已用分期金额(合计)
- creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '大额专项分期额度(合计)'] = np.sum(creditDf['大额专项分期额度'])
- creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '已用分期金额(合计)'] = np.sum(creditDf['已用分期金额'])
- # creditCardAccountInfoDf.loc[creditCardAccountInfoIndex,'贷记卡账户当前总额度'] = cip.getMaxCreditAmt(creditDf)
- creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '最近新发放的3张贷记卡平均额度'] = cip.getAvgCreditAmt(creditDf)
- creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '贷记卡额度使用率超过90%的机构数占比'] = cip.getUseRate(creditDf,
- df, 0.9)
- creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '贷记卡额度使用率超过100%的机构数占比'] = cip.getUseRate(creditDf,
- totalAmtDf,
- 1)
- # 从“贷记卡信息”中提取,计算授信额度时剔除销户,计算已用额度时剔除呆账、呆帐、销户后,SUM(各账户已用额度) / SUM(各账户授信额度)
- useCreditDf = df[(df['币种'] == '人民币元') & (df['账户状态'] != '销户') & (df['账户状态'] != '呆账')]
- totalCreditDf = df[(df['币种'] == '人民币元') & (df['账户状态'] != '销户')]
- totalCreditAmt = np.sum(totalCreditDf['账户授信额度'])
- if totalCreditAmt != 0: # 授信额度不能为0
- creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '贷记卡账户当前总额度使用率'] = round(
- np.sum(useCreditDf['已用额度']) / np.sum(totalCreditDf['账户授信额度']), 2)
- creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '贷记卡账户最高使用额度总的使用率'] = round(
- np.sum(useCreditDf['最大使用额']) / np.sum(totalCreditDf['账户授信额度']), 2)
- creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '贷记卡账户近6月平均额度总的使用率'] = round(
- np.sum(useCreditDf['最近6个月平均使用额度']) / np.sum(totalCreditDf['账户授信额度']), 2)
- creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '当前贷记卡最大逾期期数'] = np.max(creditDf['当前逾期期数']) # 用于计算
- creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '当前贷记卡最大逾期金额'] = np.max(creditDf['当前逾期总额'])
- #1112 修改
- otherDf.loc[otherIndex, '贷记卡当前逾期金额'] = np.sum(creditDf['当前逾期总额'])
- if not creditDf.empty:
- creditDf = creditDf.reset_index(drop=True)
- maxOverdueIndex = np.argmax(creditDf['当前逾期期数'])
- creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '当前贷记卡最大逾期期数对应的最大逾期金额'] = \
- creditDf.loc[maxOverdueIndex, :]['当前逾期总额']
- creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '近3月开卡最高额度'] = cip.getLastMonthMaxCreditAmt(df,
- reportTime,
- 3)
- creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '近3月开卡最低额度'] = cip.getLastMonthMinCreditAmt(df,
- reportTime,
- 3)
- creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '近3月开卡平均额度'] = cip.getLastMonthAvgCreditAmt(df,
- reportTime,
- 3)
- creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '近6月开卡最高额度'] = cip.getLastMonthMaxCreditAmt(df,
- reportTime,
- 6)
- creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '近6月开卡最低额度'] = cip.getLastMonthMinCreditAmt(df,
- reportTime,
- 6)
- creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '近6月开卡平均额度'] = cip.getLastMonthAvgCreditAmt(df,
- reportTime,
- 6)
- creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '近12月开卡最高额度'] = cip.getLastMonthMaxCreditAmt(df,
- reportTime,
- 12)
- creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '近12月开卡最低额度'] = cip.getLastMonthMinCreditAmt(df,
- reportTime,
- 12)
- creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '近12月开卡平均额度'] = cip.getLastMonthAvgCreditAmt(df,
- reportTime,
- 12)
- if not creditDf.empty:
- creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '贷记卡最近一次还款日期距今时长'] = cip.getLastPayDateMinDays(
- creditDf, reportTime)
- paySo = np.sum(creditDf['本月应还款'])
- if (paySo) != 0:
- creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '贷记卡还款比例'] = round(
- np.sum(creditDf['本月实还款']) / np.sum(creditDf['本月应还款']), 2)
- creditDfTmp = creditDf[creditDf['本月应还款'] > 0]
- creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '贷记卡最高还款比例'] = round(
- np.max(np.divide(creditDfTmp['本月实还款'], creditDfTmp['本月应还款'])), 2)
- creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '贷记卡最低还款比例'] = round(
- np.min(np.divide(creditDfTmp['本月实还款'], creditDfTmp['本月应还款'])), 2)
- #贷记卡疑似分期笔数 汇算
- installmentDf = creditDf[(creditDf['本月实还款']>0) & (creditDf['本月应还款']>200) &(creditDf['本月实还款']< creditDf['本月应还款']/9)]
- otherDf.loc[otherIndex, '贷记卡疑似分期笔数'] = installmentDf.index.size
- normalDf = df[(df['币种'] == '人民币元') & (df['账户状态'] == '正常') & (df['当前逾期期数'] == 0)];
- activeDf = df[(df['币种'] == '人民币元') & (df['账户状态'] == '正常')];
- notCloseDf = df[(df['账户状态'] != '销户')]
- creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '当前正常贷记卡账户数'] = normalDf.index.size
- if not notCloseDf.empty and not normalDf.empty:
- creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '当前正常贷记卡账户数占比'] = round(
- normalDf.index.size / notCloseDf.index.size, 2)
- creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '当前正常贷记卡已用额度'] = np.sum(normalDf['已用额度'])
- creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '当前正常且有余额的贷记卡账户数'] = normalDf[
- normalDf['已用额度'] > 0].index.size
- if not creditDf.empty:
- creditUseAmt = np.sum(creditDf['已用额度'])
- if creditUseAmt != 0:
- creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '当前正常贷记卡账户余额占总余额比'] = round(
- np.sum(normalDf['已用额度']) / np.sum(creditDf['已用额度']), 2)
- if notCloseDf.empty:
- creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '当前正常且有余额的贷记卡账户数占比'] = -99
- else:
- creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '当前正常且有余额的贷记卡账户数占比'] = \
- round(creditCardAccountInfoDf.loc[
- creditCardAccountInfoIndex, '当前正常且有余额的贷记卡账户数'] / notCloseDf.index.size, 3)
- # 当前正常贷记卡账户余额占总余额比
- creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '当前贷记卡本月实还金额总和'] = np.sum(creditDf['本月实还款'])
- creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '当前贷记卡本月应还金额总和'] = np.sum(creditDf['本月应还款'])
- maxAmtDf = df[(df['币种'] == '人民币元')]
- if not maxAmtDf.empty:
- maxAmtDf = maxAmtDf.reset_index(drop=True)
- maxAmtIndex = np.argmax(maxAmtDf['账户授信额度'])
- maxOpenDate = maxAmtDf.loc[maxAmtIndex, :]['开立日期'];
- creditCardAccountInfoDf.loc[
- creditCardAccountInfoIndex, '额度最高的人民币贷记卡开卡距今月份数'] = utils.difMonthReportTime(maxOpenDate,reportTime);
- # 名下贷记卡数量-状态正常
- creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '名下贷记卡数量-状态正常'] = df[
- (df['账户状态'] != '销户')].index.size
- # 名下贷记卡数量-状态未激活
- creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '名下贷记卡数量-状态未激活'] = df[
- (df['账户状态'] == '未激活')].index.size
- # 名下贷记卡数量-状态异常异常包含(2-冻结,3-止付,5-呆帐,10-其他)
- abnormalList = ['冻结', '止付', '呆账', '司法追偿']#原来为其他
- creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '名下贷记卡数量-状态异常'] = df[(df['账户状态'].isin(abnormalList))].index.size
- # 名下贷记卡比例-状态正常
- creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '名下贷记卡比例-状态正常'] = round(
- creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '名下贷记卡数量-状态正常'] / df.index.size, 2)
- # 名下贷记卡比例-状态未激活
- creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '名下贷记卡比例-状态未激活'] = round(
- creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '名下贷记卡数量-状态未激活'] / df.index.size, 2)
- # 名下贷记卡比例-状态异常
- creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '名下贷记卡比例-状态异常'] = round(
- creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '名下贷记卡数量-状态异常'] / df.index.size, 2)
- #1113汇算
- abnormalList = ['冻结', '止付', '呆账', '司法追偿']
- otherDf.loc[otherIndex, "贷记卡状态为('呆账','冻结','止付','司法追偿')的账户数"] = df[(df['账户状态'].isin(abnormalList))].index.size
- availableCreditDf = activeDf[activeDf['最近6个月平均使用额度'] > 500] #正常的信用卡
- otherDf.loc[otherIndex, '有效信用卡张数'] = availableCreditDf.index.size
- #使用中的所有贷记卡中发卡时间距征信查询时间的最大天数 0111三寿
- if not activeDf.empty:
- fstDate = np.min(activeDf['开立日期']);
- sanshouDf.loc[sanshouIndex,"使用中贷记卡最早发卡天数"]=utils.difDateReportTime(reportTime, fstDate)
- # 解析准贷记卡账户信息指标
- def parseCreditCardMergeDfZ(self,df, payRcd):
- if not df.empty:
- overdueCreditCardRcdDf = payRcd[payRcd['账户编号'].isin(df['账户编号'].values)];
- overdueCreditCardRcdDf = utils.replacePayRcdStatusOverdue(overdueCreditCardRcdDf)
- creditCardAccountInfoDfZ.loc[creditCardAccountInfoIndexZ, '本月应还款(合计)'] = np.nansum(df['透支余额'])
- creditCardAccountInfoDfZ.loc[creditCardAccountInfoIndexZ, '本月实还款(合计)'] = np.nansum(df['本月实还款'])
- creditCardAccountInfoDfZ.loc[creditCardAccountInfoIndexZ, '最近一次还款日期'] = np.nanmax(df['最近一次还款日期'])
- creditCardAccountInfoDfZ.loc[creditCardAccountInfoIndexZ, '当前一共透支期数'] = cip.getCurOverdueNum(
- overdueCreditCardRcdDf);
- creditCardAccountInfoDfZ.loc[creditCardAccountInfoIndexZ, '当前一共透支总额'] = np.nansum(df['透支余额'])
- creditCardAccountInfoDfZ.loc[creditCardAccountInfoIndexZ, '透支180天以上未支付余额(合计)'] = np.nansum(
- df['透支180天以上未付余额'])
- # 名下贷记卡数量-状态异常异常包含(2-冻结,3-止付,5-呆帐,10-其他)
- abnormalList = ['冻结', '止付', '呆账', '其他']
- creditCardAccountInfoDfZ.loc[creditCardAccountInfoIndexZ, '名下准贷记卡数量-状态异常'] = df[(df['账户状态'].isin(abnormalList))].index.size
- creditDf = df[(df['账户状态'] != '未激活') & (df['账户状态'] != '销户')]
- if not creditDf.empty:
- totalAmt = np.nansum(creditDf['账户授信额度'])
- creditAmt = np.nansum(creditDf['透支余额'])
- if totalAmt != 0:
- # 从“贷记卡信息”中提取,剔除未激活、销户后,所有账户透支金额/所有账户账户授信额度。
- creditCardAccountInfoDfZ.loc[creditCardAccountInfoIndexZ, '全部准贷记卡账户当前总额度使用率'] = round(
- creditAmt / totalAmt, 2)
- # 从“贷记卡信息”中提取,剔除未激活、销户后,MAX(单账户最高透支金额/单账户授信额度)
- creditMaxDf = creditDf[creditDf['账户授信额度'] > 0]
- if not creditMaxDf.empty:
- creditMaxDf = creditMaxDf.fillna(0.0)
- creditCardAccountInfoDfZ.loc[creditCardAccountInfoIndexZ, '准贷记卡账户最高使用额度总的使用率'] = round(
- np.max(np.divide(creditMaxDf['最大透支余额'], creditMaxDf['账户授信额度'])), 2)
- creditMaxDf = creditDf[creditDf['最大透支余额'] > 0]
- if not creditMaxDf.empty:
- creditCardAccountInfoDfZ.loc[creditCardAccountInfoIndexZ, '当前准贷记卡最大透支金额'] = np.max(
- creditMaxDf['最大透支余额'])
- # 从“贷记卡信息”中提取,剔除未激活、销户后,当前透支准贷记卡账户数/总准贷记卡账户数,透支账户判断:透支余额不为0的账户
- creditDfTmp = creditDf[creditDf['透支余额'] > 0]
- creditCardAccountInfoDfZ.loc[creditCardAccountInfoIndexZ, '当前准贷记卡透支账户数占比'] = round(
- creditDfTmp.index.size / creditDf.index.size, 2)
- creditCardAccountInfoDfZ.loc[creditCardAccountInfoIndexZ, '当前准贷记卡本月应还金额总和'] = np.nansum(df['透支余额'])
- creditCardAccountInfoDfZ.loc[creditCardAccountInfoIndexZ, '当前准贷记卡本月实还金额总和'] = np.nansum(df['本月实还款'])
- # 解析使用率 TODO 使用汇总计算还是使用明细计算
- def parseUseRate(self):
- # useRateDf.loc[useRateIndex, '贷记卡账户使用率(已用额度/授信总额)']
- # 从“信贷交易授信及负债信息概要”中“非循环贷账户信息汇总”、“循环额度下分账户信息汇总”、“循环贷账户信息汇总”、“贷记卡账户信息汇总”和“准贷记卡账户信息汇总”里提取,SUM(
- # 所有“余额”、“已用额度”和“透支余额”) / SUM(所有“授信总额”和“授信额度”)
- loanUseAmt = briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '非循环贷账户余额']
- cycleCreditUseAmt = briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '循环额度下分账户余额']
- cycleUseAmt = briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '循环贷账户余额']
- creditUseAmt = briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '贷记卡已用额度']
- creditAmtUseZ = briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '准贷记卡已用额度']
- loanTotalAmt = briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '非循环贷账户授信总额']
- cycleCreditTotalAmt = briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '循环额度下分账户授信总额']
- cycleTotalAmt = briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '循环贷账户授信总额']
- creditTotalAmt = briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '贷记卡授信总额']
- creditAmtTotalZ = briefInfoDf_loanTradeCreditInfo.loc[loanTradeCreditInfoIndex, '准贷记卡授信总额']
- # if str(loanUseAmt)=="nan":
- # loanUseAmt = 0;
- # if str(cycleCreditUseAmt) == "nan":
- # loanUseAmt = 0;
- # if str(cycleCreditUseAmt) == "nan":
- # loanUseAmt = 0;
- useAmt = loanUseAmt + cycleCreditUseAmt + cycleUseAmt + creditUseAmt + creditAmtUseZ
- totalAmt = loanTotalAmt + cycleCreditTotalAmt + cycleTotalAmt + creditTotalAmt + creditAmtTotalZ
- if totalAmt != 0:
- useRateDf.loc[useRateIndex, '全账户使用率(已用额度/授信总额)'] = round(useAmt / totalAmt, 2)
- if loanTotalAmt != 0:
- useRateDf.loc[useRateIndex, '非循环贷账户使用率(已用额度/授信总额)'] = round(loanUseAmt / loanTotalAmt, 2)
- if cycleCreditTotalAmt != 0:
- useRateDf.loc[useRateIndex, '循环额度下分账户使用率(已用额度/授信总额)'] = round(cycleCreditTotalAmt / cycleCreditTotalAmt, 2)
- if cycleTotalAmt != 0:
- useRateDf.loc[useRateIndex, '循环贷账户使用率(已用额度/授信总额)'] = round(cycleUseAmt / cycleTotalAmt, 2)
- if creditTotalAmt != 0:
- useRateDf.loc[useRateIndex, '贷记卡账户使用率(已用额度/授信总额)'] = round(creditUseAmt / creditTotalAmt, 2)
- if creditAmtTotalZ != 0:
- useRateDf.loc[useRateIndex, '准贷记卡账户使用率(已用额度/授信总额)'] = round(creditAmtUseZ / creditAmtTotalZ, 2)
- # 解析开户数
- def parseOpenAccount(self,loanDf, creditCardDf, creditCardDfZ, recoveryInfoMergeDf, loanPayRecordMergeDf,
- creditCardPayRecordMergeDf, creditCardPayRecordMergeDfZ,reportTime):
- openAccountDf.loc[openAccountIndex, '近3个月全账户开户数'] = cip.getOpenAccount(loanDf, reportTime,
- 3) + cip.getOpenAccount(creditCardDf,
- reportTime,
- 3) + cip.getOpenAccount(
- creditCardDfZ, reportTime, 3)
- openAccountDf.loc[openAccountIndex, '近6个月全账户开户数'] = cip.getOpenAccount(loanDf, reportTime,
- 6) + cip.getOpenAccount(creditCardDf,
- reportTime,
- 6) + cip.getOpenAccount(
- creditCardDfZ, reportTime, 6)
- openAccountDf.loc[openAccountIndex, '近9个月全账户开户数'] = cip.getOpenAccount(loanDf, reportTime,
- 9) + cip.getOpenAccount(creditCardDf,
- reportTime,
- 9) + cip.getOpenAccount(
- creditCardDfZ, reportTime, 9)
- openAccountDf.loc[openAccountIndex, '近12个月全账户开户数'] = cip.getOpenAccount(loanDf, reportTime,
- 12) + cip.getOpenAccount(creditCardDf,
- reportTime,
- 12) + cip.getOpenAccount(
- creditCardDfZ, reportTime, 12)
- openAccountDf.loc[openAccountIndex, '近24个月全账户开户数'] = cip.getOpenAccount(loanDf, reportTime,
- 24) + cip.getOpenAccount(creditCardDf,
- reportTime,
- 24) + cip.getOpenAccount(
- creditCardDfZ, reportTime, 24)
- openAccountDf.loc[openAccountIndex, '近3个月消费金融类账户开户数'] = lip.getOpenAccount(loanDf, reportTime, 3,
- consts.bankList)
- openAccountDf.loc[openAccountIndex, '近6个月消费金融类账户开户数'] = lip.getOpenAccount(loanDf, reportTime, 6,
- consts.bankList)
- openAccountDf.loc[openAccountIndex, '近9个月消费金融类账户开户数'] = lip.getOpenAccount(loanDf, reportTime, 9,
- consts.bankList)
- openAccountDf.loc[openAccountIndex, '近12个月消费金融类账户开户数'] = lip.getOpenAccount(loanDf, reportTime, 12,
- consts.bankList)
- openAccountDf.loc[openAccountIndex, '近24个月消费金融类账户开户数'] = lip.getOpenAccount(loanDf, reportTime, 24,
- consts.bankList)
- openAccountDf.loc[openAccountIndex, '近3个月贷款账户开户数'] = lip.getOpenAccount(loanDf, reportTime, 3, "")
- openAccountDf.loc[openAccountIndex, '近6个月贷款账户开户数'] = lip.getOpenAccount(loanDf, reportTime, 6, "")
- openAccountDf.loc[openAccountIndex, '近9个月贷款账户开户数'] = lip.getOpenAccount(loanDf, reportTime, 9, "")
- openAccountDf.loc[openAccountIndex, '近12个月贷款账户开户数'] = lip.getOpenAccount(loanDf, reportTime, 12, "")
- openAccountDf.loc[openAccountIndex, '近24个月贷款账户开户数'] = lip.getOpenAccount(loanDf, reportTime, 24, "")
- openAccountDf.loc[openAccountIndex, '近3个月贷记卡账户开户数'] = cip.getOpenAccount(creditCardDf, reportTime, 3)
- openAccountDf.loc[openAccountIndex, '近6个月贷记卡账户开户数'] = cip.getOpenAccount(creditCardDf, reportTime, 6)
- openAccountDf.loc[openAccountIndex, '近9个月贷记卡账户开户数'] = cip.getOpenAccount(creditCardDf, reportTime, 9)
- openAccountDf.loc[openAccountIndex, '近12个月贷记卡账户开户数'] = cip.getOpenAccount(creditCardDf, reportTime, 12)
- openAccountDf.loc[openAccountIndex, '近24个月贷记卡账户开户数'] = cip.getOpenAccount(creditCardDf, reportTime, 24)
- openAccountDf.loc[openAccountIndex, '近3个月准贷记卡账户开户数'] = cip.getOpenAccount(creditCardDfZ, reportTime, 3)
- openAccountDf.loc[openAccountIndex, '近6个月准贷记卡账户开户数'] = cip.getOpenAccount(creditCardDfZ, reportTime, 6)
- openAccountDf.loc[openAccountIndex, '近9个月准贷记卡账户开户数'] = cip.getOpenAccount(creditCardDfZ, reportTime, 9)
- openAccountDf.loc[openAccountIndex, '近12个月准贷记卡账户开户数'] = cip.getOpenAccount(creditCardDfZ, reportTime, 12)
- openAccountDf.loc[openAccountIndex, '近24个月准贷记卡账户开户数'] = cip.getOpenAccount(creditCardDfZ, reportTime, 24)
- #三寿
- sanshouDf.loc[sanshouIndex, '最近24M发卡数量'] = cip.getOpenAccount(creditCardDf, reportTime, 24)+cip.getOpenAccount(creditCardDfZ, reportTime, 24)
- # 从“信贷交易信息明细”中“非循环贷账户”、“循环额度下分账户”、“循环贷账户”、“贷记卡账户”和“准贷记卡账户”里提取,5年里账户还款状态出现“1、2、3、4、5、6、7、D、Z、G、B”的账户数/所有账户数
- overdueLoanPayRcdDf = loanPayRecordMergeDf[loanPayRecordMergeDf['账户编号'].isin(loanDf['账户编号'].values)]
- overdueLoanPayRcdDf = utils.replacePayRcdStatusOverdue(overdueLoanPayRcdDf)
- overdueLoanPayRcdDf = overdueLoanPayRcdDf[overdueLoanPayRcdDf['还款状态'] > 0]
- overdueCreditPayRcdDf = creditCardPayRecordMergeDf[
- creditCardPayRecordMergeDf['账户编号'].isin(creditCardDf['账户编号'].values)]
- overdueCreditPayRcdDf = utils.replacePayRcdStatusOverdue(overdueCreditPayRcdDf)
- overdueCreditPayRcdDf = overdueCreditPayRcdDf[overdueCreditPayRcdDf['还款状态'] > 0]
- overdueCreditPayRcdDfZ = creditCardPayRecordMergeDfZ[
- creditCardPayRecordMergeDfZ['账户编号'].isin(creditCardDfZ['账户编号'].values)]
- overdueCreditPayRcdDfZ = utils.replacePayRcdStatusOverdue(overdueCreditPayRcdDfZ)
- overdueCreditPayRcdDfZ = overdueCreditPayRcdDfZ[overdueCreditPayRcdDfZ['还款状态'] > 0]
- loanAccountNum = loanPayRecordMergeDf['账户编号'].unique().size
- creditAccountNum = creditCardPayRecordMergeDf['账户编号'].unique().size
- creditAccountNumZ = creditCardPayRecordMergeDfZ['账户编号'].unique().size
- overdueLoanNum = overdueLoanPayRcdDf['账户编号'].unique().size
- overdueCreditNum = overdueCreditPayRcdDf['账户编号'].unique().size
- overdueCreditNumZ = overdueCreditPayRcdDfZ['账户编号'].unique().size
- if (loanAccountNum + creditAccountNum + creditAccountNumZ) > 0:
- openAccountDf.loc[openAccountIndex, '有过逾期记录的账户/全账户数'] = round(
- (overdueLoanNum + overdueCreditNum + overdueCreditNumZ) / (
- loanAccountNum + creditAccountNum + creditAccountNumZ), 2)
- otherPerLoanDf = loanDf[loanDf['业务种类'].isin(consts.bankList)]
- otherPerLoanNum = otherPerLoanDf.index.size;
- overdueOtherPerLoanNum = otherPerLoanDf[
- otherPerLoanDf['账户编号'].isin(overdueLoanPayRcdDf['账户编号'].values)].index.size;
- if otherPerLoanNum != 0:
- openAccountDf.loc[openAccountIndex, '有过逾期记录的消费金融类账户/全消费金融类账户数'] = round(
- overdueOtherPerLoanNum / otherPerLoanNum, 2)
- if loanAccountNum != 0:
- openAccountDf.loc[openAccountIndex, '有过逾期记录的贷款账户/全贷款账户数'] = round(overdueLoanNum / loanAccountNum, 2)
- if creditAccountNum != 0:
- openAccountDf.loc[openAccountIndex, '有过逾期记录的贷记卡账户/全贷记卡账户数'] = round(overdueCreditNum / creditAccountNum, 2)
- if creditAccountNumZ != 0:
- openAccountDf.loc[openAccountIndex, '有过透支记录的准贷记卡账户/全准贷记卡账户数'] = round(overdueCreditNumZ / creditAccountNumZ,
- 2)
- # 0525新增
- pledgeLoanDf = loanDf[loanDf['担保方式'] == '抵押']
- pledgeCreditCardDf = creditCardDf[creditCardDf['担保方式'] == '抵押']
- pledgeCreditCardDfZ = creditCardDfZ[creditCardDfZ['担保方式'] == '抵押']
- isPledge = "否"
- if pledgeLoanDf.index.size + pledgeCreditCardDf.index.size + pledgeCreditCardDfZ.index.size > 0:
- isPledge = "是"
- creditLoanDf = loanDf[loanDf['担保方式'] == '信用/免担保']
- creditCreditCardDf = creditCardDf[creditCardDf['担保方式'] == '信用/免担保']
- creditCreditCardDfZ = creditCardDfZ[creditCardDfZ['担保方式'] == '信用/免担保']
- isCredit = 0
- if creditLoanDf.index.size + creditCreditCardDf.index.size + creditCreditCardDfZ.index.size > 0:
- isCredit = creditLoanDf.index.size + creditCreditCardDf.index.size + creditCreditCardDfZ.index.size
- briefInfoDf_loanTradeInfo.loc[loanTradeInfoIndex, '是否存在担保方式为抵押的贷款'] = isPledge
- briefInfoDf_loanTradeInfo.loc[loanTradeInfoIndex, '担保方式为信用的贷款数量'] = isCredit
- #使用中贷记卡平均发卡天数
- try:
- sanshouDf.loc[sanshouIndex, '使用中贷记卡平均发卡天数'] = cip.getAvgUseCreditCardDay(creditCardDf,creditCardDfZ,reportTime)
- sanshouDf.loc[sanshouIndex, '最大信用账户天数(贷款&贷记卡人民账户)'] = cip.getMaxAmtAccountDay(loanDf,creditCardDf,creditCardDfZ ,reportTime)
- sanshouDf.loc[sanshouIndex, '额度使用>=50%的贷记卡数'] = cip.getUseRateCount(creditCardDf,creditCardDfZ,0.5)
- sanshouDf.loc[sanshouIndex, '额度使用>=75%的贷记卡数'] = cip.getUseRateCount(creditCardDf, creditCardDfZ, 0.75)
- sanshouDf.loc[sanshouIndex, '额度使用>=100%的贷记卡数'] = cip.getUseRateCount(creditCardDf, creditCardDfZ, 1)
- minMonthStr = ""
- if otherDf.loc[otherIndex, '首笔贷款发放月份']=='' and otherDf.loc[otherIndex, '首张贷记卡发卡月份']!='':
- minMonthStr = otherDf.loc[otherIndex, '首张贷记卡发卡月份']
- elif otherDf.loc[otherIndex, '首笔贷款发放月份']!='' and otherDf.loc[otherIndex, '首张贷记卡发卡月份']!='':
- minMonth = [otherDf.loc[otherIndex, '首笔贷款发放月份'], otherDf.loc[otherIndex, '首张贷记卡发卡月份']]
- minMonthStr = min(minMonth)
- elif otherDf.loc[otherIndex, '首笔贷款发放月份']!='' and otherDf.loc[otherIndex, '首张贷记卡发卡月份']=='':
- minMonthStr = otherDf.loc[otherIndex, '首笔贷款发放月份']
- sanshouDf.loc[sanshouIndex, '贷款、贷记卡最大天数'] = utils.difDateReportTime(reportTime, minMonthStr)
- if not loanDf.empty:
- openAccount3MDf = loanDf[loanDf['开立日期'] < utils.getLastMonthDate(reportTime, 6)]
- sanshouDf.loc[sanshouIndex, '开户180天以上的贷款笔数'] = openAccount3MDf.index.size
- if not creditCardDf.empty:
- sanshouDf.loc[sanshouIndex, '开户1年以内历史逾期90+贷记卡和准贷记卡数'] =cip.getOverDueCount(creditCardDf,creditCardPayRecordMergeDf,reportTime,3,12)\
- +cip.getOverDueCount(creditCardDfZ,creditCardPayRecordMergeDfZ,reportTime,3,12)
- sanshouDf.loc[sanshouIndex, '开户1年以内历史逾期贷记卡和准贷记卡数'] = cip.getOverDueCount(creditCardDf,creditCardPayRecordMergeDf,reportTime, 1, 12)\
- +cip.getOverDueCount(creditCardDfZ, creditCardPayRecordMergeDfZ, reportTime, 1, 12)
- sanshouDf.loc[sanshouIndex, '开户2年以内历史逾期贷记卡数'] = cip.getOverDueCount(creditCardDf,creditCardPayRecordMergeDf,reportTime, 1, 24)
- except:
- logger.error(traceback.print_exc())
- logger.error(traceback.format_exc())
- # 解析24期还款状态指标
- def parsePayRcdStatus(self,loanMergeDf, creditCardMergeDf, creditCardMergeDfZ, loanPayRecordMergeDf,
- creditCardPayRecordMergeDf, creditCardPayRecordMergeDfZ,reportTime):
- # creditCardPayRecordMergeDf
- # 去掉外币
- creditCardMergeDf = creditCardMergeDf[creditCardMergeDf['币种'] == '人民币元']
- creditCardPayRecordMergeDf = creditCardPayRecordMergeDf[
- creditCardPayRecordMergeDf['账户编号'].isin(creditCardMergeDf['账户编号'].values)]
- reportTime = str(np.datetime64(reportTime, "M")) + "-02" # 06-02,统计24期还款状态报告期,按每月的2号,避免chu'xian
- payRcdStatusDf.loc[payRcdStatusIndex, '贷款账户近3月逾期期数大于或等于“1”的次数'] = prp.getLoanOverdueTimes(loanPayRecordMergeDf,
- reportTime, 1, 3)
- payRcdStatusDf.loc[payRcdStatusIndex, '贷款账户近6月逾期期数大于或等于“1”的次数'] = prp.getLoanOverdueTimes(loanPayRecordMergeDf,
- reportTime, 1, 6)
- payRcdStatusDf.loc[payRcdStatusIndex, '贷款账户近12月逾期期数大于或等于“1”的次数'] = prp.getLoanOverdueTimes(loanPayRecordMergeDf,
- reportTime, 1, 12)
- payRcdStatusDf.loc[payRcdStatusIndex, '贷款账户近24月逾期期数大于或等于“1”的次数'] = prp.getLoanOverdueTimes(loanPayRecordMergeDf,
- reportTime, 1, 24)
- payRcdStatusDf.loc[payRcdStatusIndex, '贷款账户近6月逾期期数大于或等于“2”的次数'] = prp.getLoanOverdueTimes(loanPayRecordMergeDf,
- reportTime, 2, 6)
- payRcdStatusDf.loc[payRcdStatusIndex, '贷款账户近12月逾期期数大于或等于“2”的次数'] = prp.getLoanOverdueTimes(loanPayRecordMergeDf,
- reportTime, 2, 12)
- payRcdStatusDf.loc[payRcdStatusIndex, '贷款账户近24月逾期期数大于或等于“2”的次数'] = prp.getLoanOverdueTimes(loanPayRecordMergeDf,
- reportTime, 2, 24)
- payRcdStatusDf.loc[payRcdStatusIndex, '贷款账户近6月逾期期数大于或等于“3”的次数'] = prp.getLoanOverdueTimes(loanPayRecordMergeDf,
- reportTime, 3, 6)
- payRcdStatusDf.loc[payRcdStatusIndex, '贷款账户近12月逾期期数大于或等于“3”的次数'] = prp.getLoanOverdueTimes(loanPayRecordMergeDf,
- reportTime, 3, 12)
- payRcdStatusDf.loc[payRcdStatusIndex, '贷款账户近24月逾期期数大于或等于“3”的次数'] = prp.getLoanOverdueTimes(loanPayRecordMergeDf,
- reportTime, 3, 24)
- payRcdStatusDf.loc[payRcdStatusIndex, '贷款账户近12月逾期期数大于或大等于“4”的次数'] = prp.getLoanOverdueTimes(
- loanPayRecordMergeDf, reportTime, 4, 12)
- payRcdStatusDf.loc[payRcdStatusIndex, '贷款账户近24月逾期期数大于或等于“4”的次数'] = prp.getLoanOverdueTimes(loanPayRecordMergeDf,
- reportTime, 4, 24)
- payRcdStatusDf.loc[payRcdStatusIndex, '贷记卡账户近3月逾期期数大于或等于“1”的次数'] = cip.getLoanOverdueTimes(
- creditCardPayRecordMergeDf, reportTime, 1, 3)
- payRcdStatusDf.loc[payRcdStatusIndex, '贷记卡账户近6月逾期期数大于或等于“1”的次数'] = cip.getLoanOverdueTimes(
- creditCardPayRecordMergeDf, reportTime, 1, 6)
- payRcdStatusDf.loc[payRcdStatusIndex, '贷记卡账户近12月逾期期数大于或等于“1”的次数'] = cip.getLoanOverdueTimes(
- creditCardPayRecordMergeDf, reportTime, 1, 12)
- payRcdStatusDf.loc[payRcdStatusIndex, '贷记卡账户近24月逾期期数大于或等于“1”的次数'] = cip.getLoanOverdueTimes(
- creditCardPayRecordMergeDf, reportTime, 1, 24)
- payRcdStatusDf.loc[payRcdStatusIndex, '贷记卡账户近6月逾期期数大于或等于“2”的次数'] = cip.getLoanOverdueTimes(
- creditCardPayRecordMergeDf, reportTime, 2, 6)
- payRcdStatusDf.loc[payRcdStatusIndex, '贷记卡账户近12月逾期期数大于或等于“2”的次数'] = cip.getLoanOverdueTimes(
- creditCardPayRecordMergeDf, reportTime, 2, 12)
- payRcdStatusDf.loc[payRcdStatusIndex, '贷记卡账户近24月逾期期数大于或等于“2”的次数'] = cip.getLoanOverdueTimes(
- creditCardPayRecordMergeDf, reportTime, 2, 24)
- payRcdStatusDf.loc[payRcdStatusIndex, '贷记卡账户近6月逾期期数大于或等于“3”的次数'] = cip.getLoanOverdueTimes(
- creditCardPayRecordMergeDf, reportTime, 3, 6)
- payRcdStatusDf.loc[payRcdStatusIndex, '贷记卡账户近12月逾期期数大于或等于“3”的次数'] = cip.getLoanOverdueTimes(
- creditCardPayRecordMergeDf, reportTime, 3, 12)
- payRcdStatusDf.loc[payRcdStatusIndex, '贷记卡账户近24月逾期期数大于或等于“3”的次数'] = cip.getLoanOverdueTimes(
- creditCardPayRecordMergeDf, reportTime, 3, 24)
- payRcdStatusDf.loc[payRcdStatusIndex, '贷记卡账户近12月逾期期数大于或等于“4”的次数'] = cip.getLoanOverdueTimes(
- creditCardPayRecordMergeDf, reportTime, 4, 12)
- payRcdStatusDf.loc[payRcdStatusIndex, '贷记卡账户近24月逾期期数大于或等于“4”的次数'] = cip.getLoanOverdueTimes(
- creditCardPayRecordMergeDf, reportTime, 4, 24)
- payRcdStatusDf.loc[payRcdStatusIndex, '准贷记卡账户近6月逾期期数大于或等于“3”的次数'] = cip.getLoanOverdueTimes(
- creditCardPayRecordMergeDfZ, reportTime, 3, 6)
- payRcdStatusDf.loc[payRcdStatusIndex, '准贷记卡账户近12月逾期期数大于或等于“3”的次数'] = cip.getLoanOverdueTimes(
- creditCardPayRecordMergeDfZ, reportTime, 3, 12)
- payRcdStatusDf.loc[payRcdStatusIndex, '准贷记卡账户近24月逾期期数大于或等于“3”的次数'] = cip.getLoanOverdueTimes(
- creditCardPayRecordMergeDfZ, reportTime, 3, 24)
- payRcdStatusDf.loc[payRcdStatusIndex, '准贷记卡账户近6月逾期期数大于或等于“4”的次数'] = cip.getLoanOverdueTimes(
- creditCardPayRecordMergeDfZ, reportTime, 4, 6)
- payRcdStatusDf.loc[payRcdStatusIndex, '准贷记卡账户近12月逾期期数大于或等于“4”的次数'] = cip.getLoanOverdueTimes(
- creditCardPayRecordMergeDfZ, reportTime, 4, 12)
- payRcdStatusDf.loc[payRcdStatusIndex, '准贷记卡账户近24月逾期期数大于或等于“4”的次数'] = cip.getLoanOverdueTimes(
- creditCardPayRecordMergeDfZ, reportTime, 4, 24)
- payRcdStatusDf.loc[payRcdStatusIndex, '全账户近3月逾期期数大于或等于“1”的次数'] = prp.getLoanOverdueTimes(loanPayRecordMergeDf,
- reportTime, 1, 3) \
- + cip.getLoanOverdueTimes(
- creditCardPayRecordMergeDf, reportTime, 1, 3) + cip.getLoanOverdueTimes(creditCardPayRecordMergeDfZ,
- reportTime, 1, 3)
- payRcdStatusDf.loc[payRcdStatusIndex, '全账户近6月逾期期数大于或等于“1”的次数'] = \
- prp.getLoanOverdueTimes(loanPayRecordMergeDf, reportTime, 1, 6) + cip.getLoanOverdueTimes(
- creditCardPayRecordMergeDf, reportTime, 1, 6) \
- + cip.getLoanOverdueTimes(creditCardPayRecordMergeDfZ, reportTime, 1, 6)
- payRcdStatusDf.loc[payRcdStatusIndex, '全账户近12月逾期期数大于或等于“1”的次数'] = \
- prp.getLoanOverdueTimes(loanPayRecordMergeDf, reportTime, 1, 12) + cip.getLoanOverdueTimes(
- creditCardPayRecordMergeDf, reportTime, 1, 12) \
- + cip.getLoanOverdueTimes(creditCardPayRecordMergeDfZ, reportTime, 1, 12)
- payRcdStatusDf.loc[payRcdStatusIndex, '全账户近24月逾期期数大于或等于“1”的次数'] = \
- prp.getLoanOverdueTimes(loanPayRecordMergeDf, reportTime, 1, 24) + cip.getLoanOverdueTimes(
- creditCardPayRecordMergeDf, reportTime, 1, 24) \
- + cip.getLoanOverdueTimes(creditCardPayRecordMergeDfZ, reportTime, 1, 24)
- payRcdStatusDf.loc[payRcdStatusIndex, '全账户近6月逾期期数大于或等于“2”的次数'] = \
- prp.getLoanOverdueTimes(loanPayRecordMergeDf, reportTime, 2, 6) + cip.getLoanOverdueTimes(
- creditCardPayRecordMergeDf, reportTime, 2, 6) \
- + cip.getLoanOverdueTimes(creditCardPayRecordMergeDfZ, reportTime, 2, 6)
- payRcdStatusDf.loc[payRcdStatusIndex, '全账户近12月逾期期数大于或等于“2”的次数'] = \
- prp.getLoanOverdueTimes(loanPayRecordMergeDf, reportTime, 2, 12) + cip.getLoanOverdueTimes(
- creditCardPayRecordMergeDf, reportTime, 2, 12) \
- + cip.getLoanOverdueTimes(creditCardPayRecordMergeDfZ, reportTime, 2, 12)
- payRcdStatusDf.loc[payRcdStatusIndex, '全账户近24月逾期期数大于或等于“2”的次数'] = \
- prp.getLoanOverdueTimes(loanPayRecordMergeDf, reportTime, 2, 24) + cip.getLoanOverdueTimes(
- creditCardPayRecordMergeDf, reportTime, 2, 24) \
- + cip.getLoanOverdueTimes(creditCardPayRecordMergeDfZ, reportTime, 2, 24)
- payRcdStatusDf.loc[payRcdStatusIndex, '全账户近6月逾期期数大于或等于“3”的次数'] = \
- prp.getLoanOverdueTimes(loanPayRecordMergeDf, reportTime, 3, 6) + cip.getLoanOverdueTimes(
- creditCardPayRecordMergeDf, reportTime, 3, 6) \
- + cip.getLoanOverdueTimes(creditCardPayRecordMergeDfZ, reportTime, 3, 6)
- payRcdStatusDf.loc[payRcdStatusIndex, '全账户近12月逾期期数大于或等于“3”的次数'] = \
- prp.getLoanOverdueTimes(loanPayRecordMergeDf, reportTime, 3, 12) + cip.getLoanOverdueTimes(
- creditCardPayRecordMergeDf, reportTime, 3, 12) \
- + cip.getLoanOverdueTimes(creditCardPayRecordMergeDfZ, reportTime, 3, 12)
- payRcdStatusDf.loc[payRcdStatusIndex, '全账户近24月逾期期数大于或等于“3”的次数'] = \
- prp.getLoanOverdueTimes(loanPayRecordMergeDf, reportTime, 3, 24) + cip.getLoanOverdueTimes(
- creditCardPayRecordMergeDf, reportTime, 3, 24) \
- + cip.getLoanOverdueTimes(creditCardPayRecordMergeDfZ, reportTime, 3, 24)
- payRcdStatusDf.loc[payRcdStatusIndex, '全账户近12月逾期期数大于或等于“4”的次数'] = \
- prp.getLoanOverdueTimes(loanPayRecordMergeDf, reportTime, 4, 12) + cip.getLoanOverdueTimes(
- creditCardPayRecordMergeDf, reportTime, 4, 12) \
- + cip.getLoanOverdueTimes(creditCardPayRecordMergeDfZ, reportTime, 4, 12)
- payRcdStatusDf.loc[payRcdStatusIndex, '全账户近24月逾期期数大于或等于“4”的次数'] = \
- prp.getLoanOverdueTimes(loanPayRecordMergeDf, reportTime, 4, 24) + cip.getLoanOverdueTimes(
- creditCardPayRecordMergeDf, reportTime, 4, 24) \
- + cip.getLoanOverdueTimes(creditCardPayRecordMergeDfZ, reportTime, 4, 24)
- payRcdStatusDf.loc[payRcdStatusIndex, '贷款账户近24个月是否出现"G"'] = prp.isExistsInd(loanPayRecordMergeDf, reportTime,
- "G", 24)
- payRcdStatusDf.loc[payRcdStatusIndex, '贷记卡账户近24个月是否出现"G"'] = prp.isExistsInd(creditCardPayRecordMergeDf,
- reportTime, "G", 24)
- payRcdStatusDf.loc[payRcdStatusIndex, '准贷记卡账户近24个月是否出现"G"'] = prp.isExistsInd(creditCardPayRecordMergeDfZ,
- reportTime, "G", 24)
- payRcdStatusDf.loc[payRcdStatusIndex, '贷款账户近24个月是否出现"Z"'] = prp.isExistsInd(loanPayRecordMergeDf, reportTime,
- "Z", 24)
- payRcdStatusDf.loc[payRcdStatusIndex, '用户所有贷款账户过去24个月存在逾期的账户数目'] = prp.getLoanOverdueCount(loanPayRecordMergeDf,
- reportTime, 24)
- payRcdStatusDf.loc[payRcdStatusIndex, '用户所有贷款账户过去24个月状态正常账户数目'] = prp.getLoanNormalCount(loanPayRecordMergeDf,
- reportTime, 24)
- payRcdStatusDf.loc[payRcdStatusIndex, '用户所有贷记卡账户过去24个月存在逾期的账户数目'] = prp.getLoanOverdueCount(
- creditCardPayRecordMergeDf, reportTime, 24)
- payRcdStatusDf.loc[payRcdStatusIndex, '用户所有贷记卡账户过去24个月状态正常的账户数目'] = prp.getLoanNormalCount(
- creditCardPayRecordMergeDf, reportTime, 24)
- payRcdStatusDf.loc[payRcdStatusIndex, '用户所有准贷记卡账户过去24个月存在逾期的账户数目'] = prp.getLoanOverdueCount(
- creditCardPayRecordMergeDfZ, reportTime, 24)
- payRcdStatusDf.loc[payRcdStatusIndex, '用户所有准贷记卡账户过去24个月状态正常的账户数目'] = prp.getLoanNormalCount(
- creditCardPayRecordMergeDfZ, reportTime, 24)
- payRcdStatusDf.loc[payRcdStatusIndex, '用户过去3个月最大逾期期数'] = prp.getPayRcdMaxOverdueNumAllAccout(
- loanPayRecordMergeDf, creditCardPayRecordMergeDf, creditCardPayRecordMergeDfZ, reportTime, 3)
- payRcdStatusDf.loc[payRcdStatusIndex, '用户过去6个月最大逾期期数'] = prp.getPayRcdMaxOverdueNumAllAccout(
- loanPayRecordMergeDf, creditCardPayRecordMergeDf, creditCardPayRecordMergeDfZ, reportTime, 6)
- payRcdStatusDf.loc[payRcdStatusIndex, '用户过去12个月最大逾期期数'] = prp.getPayRcdMaxOverdueNumAllAccout(
- loanPayRecordMergeDf, creditCardPayRecordMergeDf, creditCardPayRecordMergeDfZ, reportTime, 12)
- payRcdStatusDf.loc[payRcdStatusIndex, '用户过去24个月最大逾期期数'] = prp.getPayRcdMaxOverdueNumAllAccout(
- loanPayRecordMergeDf, creditCardPayRecordMergeDf, creditCardPayRecordMergeDfZ, reportTime, 24)
- # 概要信息里的字段,从还款状态计算
- briefInfoDf_overdueInfoSum.loc[overdueInfoSumIndex, '该用户过去5年出现逾期的所有账户数目'] = \
- prp.getLoanOverdueCount(loanPayRecordMergeDf, reportTime, 24 * 5) + prp.getLoanOverdueCount(
- creditCardPayRecordMergeDf, reportTime, 24 * 5) \
- + prp.getLoanOverdueCount(creditCardPayRecordMergeDfZ, reportTime, 24 * 5)
- #1112
- otherDf.loc[otherIndex, '近12个月最大逾期期数'] = prp.getPayRcdMaxOverdueNumAccout(
- loanPayRecordMergeDf, creditCardPayRecordMergeDf, reportTime, 12)
- # 解析贷记卡还款记录指标
- def parseCreditCardMergeAndPayRecordDf(self,df, payRcdDf,reportTime):
- if not df.empty and not payRcdDf.empty:
- # 正常
- normalDf = df[(df['账户状态'] != '未激活') & (df['账户状态'] != '销户') & (df['账户状态'] != '呆账')]
- if not normalDf.empty:
- overduePayRcdDf = payRcdDf[payRcdDf['账户编号'].isin(normalDf['账户编号'].values)]
- overduePayRcdDf = utils.replacePayRcdStatus(overduePayRcdDf)
- # 计算当前贷款,为还款记录的最后一期 0529
- curOverduePayRcdDf = overduePayRcdDf.sort_values(by=["账户编号", "还款日期"], ascending=(True, False))
- curOverduePayRcdDf = curOverduePayRcdDf.groupby(['账户编号']).head(1)
- curOverduePayRcdDf = curOverduePayRcdDf[curOverduePayRcdDf['还款状态'] > 0]
- # 临时保存,不用过滤还款状态为0的
- payRcdMaxOverdueDf = overduePayRcdDf;
- # overduePayRcdDf = overduePayRcdDf[overduePayRcdDf['还款状态'] > 0]
- # creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '当前贷记卡逾期账户数'] = curOverduePayRcdDf['账户编号'].unique().size
- # 从“贷记卡信息”中提取,剔除“账户状态”为未激活、销户、呆账、呆帐后,“当前信用卡逾期账户数”/未销户贷记卡账户数(剔除“账户状态”为未激活、销户、呆账、呆帐后记录条数)
- creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '当前贷记卡逾期账户数占比'] = round(
- curOverduePayRcdDf['账户编号'].unique().size / normalDf.index.size, 2)
- # 从“贷记卡信息”中提取,剔除“账户状态”为未激活、销户、呆账、呆帐后,对(当前信用卡逾期账户数)按“开户机构代码”去重统计账户状态为逾期,按按“开户机构代码”去重后的记录条数
- overdueCreditCardDf = normalDf[normalDf['账户编号'].isin(curOverduePayRcdDf['账户编号'].values)]
- creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '当前贷记卡逾期机构数'] = overdueCreditCardDf[
- '发卡机构'].unique().size
- creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '当前贷记卡逾期机构数占比'] = round(
- creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '当前贷记卡逾期机构数'] / normalDf[
- '发卡机构'].unique().size, 2)
- creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '近3月贷记卡最大逾期期数'] = cip.getPayRcdMaxOverdueNum(
- payRcdMaxOverdueDf, 3);
- creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '近6月贷记卡最大逾期期数'] = cip.getPayRcdMaxOverdueNum(
- payRcdMaxOverdueDf, 6);
- creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '近9月贷记卡最大逾期期数'] = cip.getPayRcdMaxOverdueNum(
- payRcdMaxOverdueDf, 9);
- creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '近12月贷记卡最大逾期期数'] = cip.getPayRcdMaxOverdueNum(
- payRcdMaxOverdueDf, 12);
- creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '近24月贷记卡最大逾期期数'] = cip.getPayRcdMaxOverdueNum(
- payRcdMaxOverdueDf, 24);
- creditCardAccountInfoDf.loc[
- creditCardAccountInfoIndex, '近24月贷记卡最大逾期距离现在的月数'] = cip.getPayRcdMaxOverdueNumMonth(
- payRcdMaxOverdueDf, normalDf, reportTime, 24);
- creditCardAccountInfoDf.loc[
- creditCardAccountInfoIndex, '最近3个月贷记卡最大连续逾期月份数'] = cip.getContinuousOverdueMonth(payRcdMaxOverdueDf,
- normalDf, 3);
- creditCardAccountInfoDf.loc[
- creditCardAccountInfoIndex, '最近6个月贷记卡最大连续逾期月份数'] = cip.getContinuousOverdueMonth(payRcdMaxOverdueDf,
- normalDf, 6);
- creditCardAccountInfoDf.loc[
- creditCardAccountInfoIndex, '最近9个月贷记卡最大连续逾期月份数'] = cip.getContinuousOverdueMonth(payRcdMaxOverdueDf,
- normalDf, 9);
- creditCardAccountInfoDf.loc[
- creditCardAccountInfoIndex, '最近12个月贷记卡最大连续逾期月份数'] = cip.getContinuousOverdueMonth(
- payRcdMaxOverdueDf, normalDf, 12);
- creditCardAccountInfoDf.loc[
- creditCardAccountInfoIndex, '最近24个月贷记卡最大连续逾期月份数'] = cip.getContinuousOverdueMonth(
- payRcdMaxOverdueDf, normalDf, 24);
- # payRcdTimesDf = payRcdDf[payRcdDf['账户编号'].isin(normalDf['账户编号'].values)]
- # payRcdTimesDf = payRcdTimesDf.sort_values(by=["账户编号", "还款日期"], ascending=(True, False))
- # payRcdTimesDf = payRcdTimesDf.groupby(['账户编号']).head(24)
- # payStatus = ["G", "D", "C", "N", "M", "1", "2", "3", "4", "5", "6", "7"]
- # payRcdTimesDf = payRcdTimesDf[payRcdTimesDf['还款状态'].isin(payStatus)]
- # payRcdTimes = payRcdTimesDf.groupby(['账户编号'])['还款状态'].count()
- # # 从“贷记卡信息”中提取,剔除未激活、销户、呆账、呆帐后,各账户的还款次数统计“24个月(账户)还款状态”包含"G","D","C","N","M"及数字的个数
- # creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '贷记卡24期还款记录次数'] = np.max(payRcdTimes)
- creditCardAccountInfoDf.loc[creditCardAccountInfoIndex, '贷记卡24期还款记录次数'] = cip.getPayRcdCount(payRcdDf,normalDf,24)
- otherDf.loc[otherIndex, '近6个月有贷记卡还款记录的月份数'] = cip.getPayRcdCountNew(payRcdDf,reportTime,6)
- otherDf.loc[otherIndex, '近12个月有贷记卡还款记录的月份数'] = cip.getPayRcdCountNew(payRcdDf, reportTime, 12)
- # 解析贷款还款记录指标
- def parseLoanMergeAndPayRecordDf(self,df, payRcdDf,reportTime):
- if not df.empty and not payRcdDf.empty:
- # 正常
- normalDf = df[(df['账户状态'] != '结清') & (df['账户状态'] != '转出') & (df['账户状态'] != '呆账')]
- overduePayRcdDf = payRcdDf[payRcdDf['账户编号'].isin(normalDf['账户编号'].values)]
- overduePayRcdDf = utils.replacePayRcdStatus(overduePayRcdDf)
- # 计算当前贷款,为还款记录的最后一期 0529
- curOverduePayRcdDf = overduePayRcdDf.sort_values(by=["账户编号", "还款日期"], ascending=(True, False))
- curOverduePayRcdDf = curOverduePayRcdDf.groupby(['账户编号']).head(1)
- curOverduePayRcdDf = curOverduePayRcdDf[curOverduePayRcdDf['还款状态'] > 0]
- # 临时保存,不用过滤还款状态为0的
- payRcdMaxOverdueDf = overduePayRcdDf;
- # 所有逾期的记录
- # overduePayRcdDf = overduePayRcdDf[overduePayRcdDf['还款状态']>0]
- loanAccountInfoDf.loc[loanAccountInfoIndex, '当前贷款逾期账户数'] = curOverduePayRcdDf['账户编号'].unique().size
- if normalDf.index.size > 0:
- loanAccountInfoDf.loc[loanAccountInfoIndex, '当前贷款逾期账户数占比'] = round(
- loanAccountInfoDf.loc[loanAccountInfoIndex, '当前贷款逾期账户数'] / normalDf.index.size, 3)
- # 存在逾期的贷款账户 非结清的过滤出逾期的账户号
- overdueLoanDf = normalDf[normalDf['账户编号'].isin(curOverduePayRcdDf['账户编号'].values)]
- loanAccountInfoDf.loc[loanAccountInfoIndex, '当前贷款逾期机构数'] = overdueLoanDf['管理机构'].unique().size
- if normalDf['管理机构'].unique().size > 0:
- loanAccountInfoDf.loc[loanAccountInfoIndex, '当前贷款逾期机构数占比'] = round(
- loanAccountInfoDf.loc[loanAccountInfoIndex, '当前贷款逾期机构数'] / normalDf['管理机构'].unique().size, 2)
- # 还款记录按日期排序最近3笔的最大逾期期数
- loanAccountInfoDf.loc[loanAccountInfoIndex, '近1月贷款的最大逾期期数'] = prp.getPayRcdMaxOverdueNum(payRcdMaxOverdueDf,
- 1);
- loanAccountInfoDf.loc[loanAccountInfoIndex, '近3月贷款的最大逾期期数'] = prp.getPayRcdMaxOverdueNum(payRcdMaxOverdueDf,
- 3);
- loanAccountInfoDf.loc[loanAccountInfoIndex, '近6月贷款的最大逾期期数'] = prp.getPayRcdMaxOverdueNum(payRcdMaxOverdueDf,
- 6);
- loanAccountInfoDf.loc[loanAccountInfoIndex, '近9月贷款的最大逾期期数'] = prp.getPayRcdMaxOverdueNum(payRcdMaxOverdueDf,
- 9);
- loanAccountInfoDf.loc[loanAccountInfoIndex, '近12月贷款的最大逾期期数'] = prp.getPayRcdMaxOverdueNum(
- payRcdMaxOverdueDf, 12);
- loanAccountInfoDf.loc[loanAccountInfoIndex, '近24月贷款的最大逾期期数'] = prp.getPayRcdMaxOverdueNum(
- payRcdMaxOverdueDf, 24);
- loanAccountInfoDf.loc[loanAccountInfoIndex, '近24月贷款最大逾期距离现在的月数'] = prp.getPayRcdMaxOverdueNumMonth(
- payRcdMaxOverdueDf, normalDf, reportTime, 24);
- payStatus = ["G", "D", "C", "N", "M", "1", "2", "3", "4", "5", "6", "7"]
- # 贷款24期还款记录次数 剔除结清 转出 呆账
- # payRcdTimesDf = payRcdDf[payRcdDf['账户编号'].isin(normalDf['账户编号'].values)]
- # payRcdTimesDf = payRcdTimesDf.sort_values(by=["账户编号", "还款日期"], ascending=(True, False))
- # payRcdTimesDf = payRcdTimesDf.groupby(['账户编号']).head(24)
- # # 从“贷款信息”中提取,剔除“账户状态”为结清、转出、呆账、呆帐后,各账户的还款次数统计“24个月(账户)还款状态”包含"G","D","C","N","M"及数字的个数,MAX(各账户的还款次数)
- # payRcdTimesDf = payRcdTimesDf[payRcdTimesDf['还款状态'].isin(payStatus)]
- # payRcdTimes = payRcdTimesDf.groupby(['账户编号'])['还款状态'].count()
- #loanAccountInfoDf.loc[loanAccountInfoIndex, '贷款24期还款记录次数'] = np.max(payRcdTimes)
- loanAccountInfoDf.loc[loanAccountInfoIndex, '贷款24期还款记录次数'] = prp.getPayRcdCount(payRcdDf,normalDf,24);
- otherDf.loc[otherIndex, '最近6个月有贷款还款记录的月份数'] = prp.getPayRcdCountNew(payRcdDf, reportTime, 6);
- otherDf.loc[otherIndex, '最近12个月有贷款还款记录的月份数'] = prp.getPayRcdCountNew(payRcdDf, reportTime, 12);
- #最近一次逾期距今月份数
- def getLastOverdueMonth(self, loanMergeDf, creditCardMergeDf, loanPayRecordMergeDf, creditCardPayRecordMergeDf,
- reportTime):
- result = 120;
- if np.sum(loanMergeDf['当前逾期期数']) > 0 or np.sum(creditCardMergeDf['当前逾期期数']) > 0:
- result = 0
- else:
- payRcdDf = loanPayRecordMergeDf.sort_values(by=["账户编号", "还款日期"], ascending=(True, False))
- payRcdDf = payRcdDf.groupby(['账户编号']).head(60)
- payRcdDf = utils.replacePayRcdStatusOverdue(payRcdDf) # 替换逾期
- payRcdDf = payRcdDf[payRcdDf['还款状态'] > 0]
- payRcdDf = utils.replacePayRcdStatusOverdue(payRcdDf) # 替换逾期
- loanOverdueDate = np.max(payRcdDf['还款日期'])
- payRcdDfCredit = creditCardPayRecordMergeDf.sort_values(by=["账户编号", "还款日期"], ascending=(True, False))
- payRcdDfCredit = utils.replacePayRcdStatusOverdue(payRcdDfCredit) # 替换逾期
- payRcdDfCredit = payRcdDfCredit.groupby(['账户编号']).head(60)
- payRcdDfCredit = payRcdDfCredit[payRcdDfCredit['还款状态'] > 0]
- if not payRcdDf.empty or not payRcdDfCredit.empty:
- creditOverdueDate = np.max(payRcdDfCredit['还款日期'])
- # reportTime = str(np.datetime64(reportTime, "M")) + "-02"
- reportTime = utils.get_last_month_first_day_v2(reportTime)
- overdueDate = None
- if str(loanOverdueDate) != "nan" and str(creditOverdueDate) != "nan":
- overdueDate = max([loanOverdueDate, creditOverdueDate])
- elif str(loanOverdueDate) == "nan" and str(creditOverdueDate) != "nan":
- overdueDate = creditOverdueDate
- elif str(loanOverdueDate) != "nan" and str(creditOverdueDate) == "nan":
- overdueDate = loanOverdueDate
- if overdueDate != None:
- result = utils.difMonthReportTime(overdueDate, reportTime)
- otherDf.loc[otherIndex, "最近一次逾期距今月份数"] = result
- #近12个月贷款和贷记卡还款状态异常次数 慧算1112
- #count(三类贷款账户m1-m12中D/Z/B/G的个数)+count(贷记卡m1-m12中D/Z/B/G的个数)
- def calcPayRcdStatus(self,loanPayRecordMergeDf,creditCardPayRecordMergeDf,reportTime):
- reportTime = str(np.datetime64(reportTime, "M")) + "-02"
- statusList =['G','B','Z','D']
- payDate = utils.getLastMonthDate(reportTime, 12)
- loanPayRcdTmpDf = loanPayRecordMergeDf[loanPayRecordMergeDf['还款日期']>=payDate]
- loanTimes = loanPayRcdTmpDf[(loanPayRcdTmpDf['还款状态'].isin(statusList))].index.size
- creditPayRcdTmpDf = creditCardPayRecordMergeDf[creditCardPayRecordMergeDf['还款日期']>=payDate]
- creditTimes = creditPayRcdTmpDf[(creditPayRcdTmpDf['还款状态'].isin(statusList))].index.size
- result = loanTimes+creditTimes
- otherDf.loc[otherIndex, "近12个月贷款和贷记卡还款状态异常次数"] = result
|