#!/usr/bin/env Python # coding=utf-8 import json from xml.dom import minidom import consts; import constsBase 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 from dbController import DbController #身份信息 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]) #0916 juziIndex = '桔子新增' juziDf = pd.DataFrame(columns=consts.juziHeader,index=[juziIndex]) #基础信息字段补充,从欠税记录到查询记录(已补完),中间略去本人声明和异注声明 #基础身份信息 baseIdentityInfo = "基础身份信息" baseIdentityInfoDf = pd.DataFrame(columns=constsBase.identityInfo,index=[baseIdentityInfo]) #基础配偶信息 baseMateInfo = "基础配偶信息" baseMateInfoDf = pd.DataFrame(columns=constsBase.mateInfo,index=[baseMateInfo]) #基础居住信息 baseLiveInfo = "基础居住信息" baseLiveInfoDf = pd.DataFrame(columns=constsBase.liveInfo,index=[baseLiveInfo]) #基础职业信息 baseOccupationInfo = "基础职业信息" baseOccupationInfoDf = pd.DataFrame(columns=constsBase.occupationInfo,index=[baseOccupationInfo]) #个人信用报告"数字解读" personalCreditInfo = "个人信用报告'数字解读'" personalCreditInfoDf = pd.DataFrame(columns=constsBase.personalCreditInfo,index=[personalCreditInfo]) #信贷交易信息提示 briefInfoHeaderLoanTradeInfo = "信贷交易信息提示" briefInfoHeaderLoanTradeInfoDf = pd.DataFrame(columns=constsBase.briefInfoHeaderLoanTradeInfo,index=[briefInfoHeaderLoanTradeInfo]) #被追偿信息汇总 recoveryInfoSumIndexY = '信贷交易违约信息概要' briefInfoDf_recoveryInfoSumY = pd.DataFrame(columns=constsBase.briefInfoHeader_recoveryInfoY,index=[recoveryInfoSumIndexY]) #呆账信息汇总 badDebtsInfoIndexY = '呆账信息汇总' briefInfoDf_badDebtsInfoSumY = pd.DataFrame(columns=constsBase.briefInfoHeader_badDebtsInfoSumY,index=[badDebtsInfoIndexY]) #逾期(透支)信息汇总 overdueInfoSumIndexY='逾期(透支)信息汇总' briefInfoDf_overdueInfoSumY = pd.DataFrame(columns=constsBase.briefInfoHeader_overdueInfoSumY,index=[overdueInfoSumIndexY]) #信贷交易授信及负债信息概要 creditTransactionCredit = "信贷交易授信及负债信息概要" creditTransactionCreditDf = pd.DataFrame(columns=constsBase.creditTransactionCredit,index=[creditTransactionCredit]) #非信贷交易信息概要 nonCreditTransactions = "非信贷交易信息概要" nonCreditTransactionsDf = pd.DataFrame(columns=constsBase.nonCreditTransactions,index=[nonCreditTransactions]) #公共信息概要 publicInformation = "公共信息概要" publicInformationDf = pd.DataFrame(columns=constsBase.publicInformation,index=[publicInformation]) #查询记录概要 queryRecord = "查询记录概要" queryRecordDf = pd.DataFrame(columns=constsBase.queryRecord,index=[queryRecord]) # #被追偿信息已拆分 # recoveryInformation = "被追偿信息" # recoveryInformationDf = pd.DataFrame(columns=constsBase.recoveryInformation,index=[recoveryInformation]) # 被追偿账户基本信息 recoveryBaseInfo = "被追偿账户基本信息" recoveryBaseInfoDf = pd.DataFrame(columns=constsBase.recoveryBaseInfo,index=[recoveryBaseInfo]) #被追偿账户最新表现信息 recoveryLatest = "被追偿账户基本信息" recoveryLatestDf = pd.DataFrame(columns=constsBase.recoveryLatest,index=[recoveryLatest]) #被追偿账户特殊交易信息 recoverySpecial = "被追偿账户基本信息" recoverySpecialDf = pd.DataFrame(columns=constsBase.recoverySpecial,index=[recoverySpecial]) #被追偿账户标注及声明信息 recoveryMark = "被追偿账户基本信息" recoveryMarkDf = pd.DataFrame(columns=constsBase.recoveryMark,index=[recoveryMark]) # #非循环贷账户已拆分 # nonRevolvingLoan = "非循环贷账户" # nonRevolvingLoanDf = pd.DataFrame(columns=constsBase.nonRevolvingLoan,index=[nonRevolvingLoan]) # 非循环贷账户基本信息 noLoopLoanBase = "非循环贷账户基本信息" noLoopLoanBaseDf = pd.DataFrame(columns=constsBase.noLoopLoanBase,index=[noLoopLoanBase]) # 非循环贷账户最近一次月度表现信息 noLoopLoanLastMonth = "非循环贷账户最近一次月度表现信息" noLoopLoanLastMonthDf = pd.DataFrame(columns=constsBase.noLoopLoanLastMonth,index=[noLoopLoanLastMonth]) # 非循环贷账户最新表现信息 noLoopLoanLatest = "非循环贷账户最新表现信息" noLoopLoanLatestDf = pd.DataFrame(columns=constsBase.noLoopLoanLatest,index=[noLoopLoanLatest]) # 非循环贷账户最近 5 年内的历史表现信息 noLoopLoan5Year = "非循环贷账户最近 5 年内的历史表现信息" noLoopLoan5YearDf = pd.DataFrame(columns=constsBase.noLoopLoan5Year,index=[noLoopLoan5Year]) # 非循环贷账户特殊交易信息 noLoopLoanSpecial = "非循环贷账户特殊交易信息" noLoopLoanSpecialDf = pd.DataFrame(columns=constsBase.noLoopLoanSpecial,index=[noLoopLoanSpecial]) # 非循环贷账户标注及声明日期 noLoopLoanMark = "非循环贷账户标注及声明日期" noLoopLoanMarkDf = pd.DataFrame(columns=constsBase.noLoopLoanMark,index=[noLoopLoanMark]) # #循环额度下分账户已拆分 # revolvingLoneSubAccount = "循环额度下分账户" # revolvingLoneSubAccountDf = pd.DataFrame(columns=constsBase.revolvingLoneSubAccount,index=[revolvingLoneSubAccount]) # 循环额度下分账户基本信息 LoopSubAccountBase = "循环额度下分账户基本信息" LoopSubAccountBaseDf = pd.DataFrame(columns=constsBase.LoopSubAccountBase,index=[LoopSubAccountBase]) # 循环额度下分账户最近一次月度表现信息 LoopSubAccountLastMonth = "循环额度下分账户最近一次月度表现信息" LoopSubAccountLastMonthDf = pd.DataFrame(columns=constsBase.LoopSubAccountLastMonth,index=[LoopSubAccountLastMonth]) # 循环额度下分账户最近 5 年内的历史表现信息 LoopSubAccount5Year = "循环额度下分账户最近 5 年内的历史表现信息" LoopSubAccount5YearDf = pd.DataFrame(columns=constsBase.LoopSubAccount5Year,index=[LoopSubAccount5Year]) # 循环额度下分帐户特殊交易信息 LoopSubAccountSpecial = "循环额度下分帐户特殊交易信息" LoopSubAccountSpecialDf = pd.DataFrame(columns=constsBase.LoopSubAccountSpecial,index=[LoopSubAccountSpecial]) # 循环额度下分帐户标注及声明日期 LoopSubAccountMark = "循环额度下分帐户标注及声明日期" LoopSubAccountMarkDf = pd.DataFrame(columns=constsBase.LoopSubAccountMark,index=[LoopSubAccountMark]) # #循环贷账户已拆分 # revolvingLone = "循环贷账户" # revolvingLoneDf = pd.DataFrame(columns=constsBase.revolvingLone,index=[revolvingLone]) # 循环贷账户基本信息 LoopLoanBase = "循环贷账户基本信息" LoopLoanBaseDf = pd.DataFrame(columns=constsBase.LoopLoanBase,index=[LoopLoanBase]) # 循环贷账户最近一次月度表现信息 LoopLoanLastMonth = "循环贷账户最近一次月度表现信息" LoopLoanLastMonthDf = pd.DataFrame(columns=constsBase.LoopLoanLastMonth,index=[LoopLoanLastMonth]) # 循环贷账户最新表现信息 LoopLoanLatest = "循环贷账户最新表现信息" LoopLoanLatestDf = pd.DataFrame(columns=constsBase.LoopLoanLatest,index=[LoopLoanLatest]) # 循环贷账户最近 5 年内的历史表现信息 LoopLoan5Year = "循环贷账户最近 5 年内的历史表现信息" LoopLoan5YearDf = pd.DataFrame(columns=constsBase.LoopLoan5Year,index=[LoopLoan5Year]) # 循环贷账户特殊交易信息 LoopLoanSpecial = "循环贷账户特殊交易信息" LoopLoanSpecialDf = pd.DataFrame(columns=constsBase.LoopLoanSpecial,index=[LoopLoanSpecial]) # 循环贷账户标注及声明日期 LoopLoanMark= "循环贷账户标注及声明日期" LoopLoanMarkDf = pd.DataFrame(columns=constsBase.LoopLoanMark,index=[LoopLoanMark]) # #贷记卡账户已拆分 # creditCard = "贷记卡账户" # creditCardDf = pd.DataFrame(columns=constsBase.creditCard,index=[creditCard]) # 贷记卡账户基本信息 creditCardBase = "贷记卡账户基本信息" creditCardBaseDf = pd.DataFrame(columns=constsBase.creditCardBase,index=[creditCardBase]) # 贷记卡账户最近一次月度表现信息 creditCardLastMonth = "贷记卡账户最近一次月度表现信息" creditCardLastMonthDf = pd.DataFrame(columns=constsBase.creditCardLastMonth,index=[creditCardLastMonth]) # 贷记卡账户最新表现信息 creditCardLatest = "贷记卡账户最新表现信息" creditCardLatestDf = pd.DataFrame(columns=constsBase.creditCardLatest,index=[creditCardLatest]) # 贷记卡账户大额专项分期信息 creditCardBig = "贷记卡账户大额专项分期信息" creditCardBigDf = pd.DataFrame(columns=constsBase.creditCardBig,index=[creditCardBig]) # 贷记卡账户最近 5 年内的历史表现信息 creditCard5Year = "贷记卡账户最近 5 年内的历史表现信息" creditCard5YearDf = pd.DataFrame(columns=constsBase.creditCard5Year,index=[creditCard5Year]) # 贷记卡账户特殊事件信息 creditCardSpecial = "贷记卡账户特殊事件信息" creditCardSpecialDf = pd.DataFrame(columns=constsBase.creditCardSpecial,index=[creditCardSpecial]) # 贷记卡账户特殊交易说明 creditCardSpecialMent = "贷记卡账户特殊交易说明" creditCardSpecialMentDf = pd.DataFrame(columns=constsBase.creditCardSpecialMent,index=[creditCardSpecialMent]) # 贷记卡账户标注及声明日期 creditCardMark = "贷记卡账户标注及声明日期" creditCardMarkDf = pd.DataFrame(columns=constsBase.creditCardMark,index=[creditCardMark]) # #准贷记卡账户已拆分 # quasiCreditCard = "准贷记卡账户" # quasiCreditCardDf = pd.DataFrame(columns=constsBase.quasiCreditCard,index=[quasiCreditCard]) # 准贷记卡账户基本信息 quasiCreditCardBase = "准贷记卡账户基本信息" quasiCreditCardBaseDf = pd.DataFrame(columns=constsBase.quasiCreditCardBase,index=[quasiCreditCardBase]) # 准贷记卡账户最近一次月度表现信息 quasiCreditCardLastMonth = "准贷记卡账户最近一次月度表现信息" quasiCreditCardLastMonthDf = pd.DataFrame(columns=constsBase.quasiCreditCardLastMonth,index=[quasiCreditCardLastMonth]) # 准贷记卡账户最新表现信息 quasiCreditCardLatest = "准贷记卡账户最新表现信息" quasiCreditCardLatestDf = pd.DataFrame(columns=constsBase.quasiCreditCardLatest,index=[quasiCreditCardLatest]) # 准贷记卡账户最近 5 年内的历史表现信息 quasiCreditCard5Year = "准贷记卡账户最近 5 年内的历史表现信息" quasiCreditCard5YearDf = pd.DataFrame(columns=constsBase.quasiCreditCard5Year,index=[quasiCreditCard5Year]) # 准贷记卡账户特殊交易信息 quasiCreditCardSpecial = "准贷记卡账户特殊交易信息" quasiCreditCardSpecialDf = pd.DataFrame(columns=constsBase.quasiCreditCardSpecial,index=[quasiCreditCardSpecial]) # 准贷记卡账户标注及声明日期 quasiCreditCardMark = "准贷记卡账户标注及声明日期" quasiCreditCardMarkDf = pd.DataFrame(columns=constsBase.quasiCreditCardMark,index=[quasiCreditCardMark]) #相关还款责任信息 relevantRepaymentLiability = "相关还款责任信息" relevantRepaymentLiabilityDf = pd.DataFrame(columns=constsBase.relevantRepaymentLiability,index=[relevantRepaymentLiability]) #授信协议信息 creditAgreement = "授信协议信息" creditAgreementDf = pd.DataFrame(columns=constsBase.creditAgreement,index=[creditAgreement]) #后付费记录(未开发) postPaidRecord = "后付费记录" postPaidRecordDf = pd.DataFrame(columns=constsBase.postPaidRecord,index=[postPaidRecord]) #欠税记录 taxArrearsIndex = '欠税记录' taxArrearsDf = pd.DataFrame(columns=constsBase.taxArrears,index=[taxArrearsIndex]) #民事判决记录 civilJudgmentIndex = '民事判决记录' civilJudgmentDf = pd.DataFrame(columns=constsBase.civilJudgment,index=[civilJudgmentIndex]) #强制执行记录 enforceIndex = '强制执行记录' enforceDf = pd.DataFrame(columns=constsBase.enforce,index=[enforceIndex]) #行政处罚记录 administrativePunishmentIndex = '行政处罚记录' administrativePunishmentDf = pd.DataFrame(columns=constsBase.administrativePunishment,index=[administrativePunishmentIndex]) #住房公积金参缴记录 housingProvidentFundParticipationIndex = '住房公积金参缴记录' housingProvidentFundParticipationIndexDf = pd.DataFrame(columns=constsBase.housingProvidentFundParticipation,index=[housingProvidentFundParticipationIndex]) #低保救助记录 subsistenceAllowanceAssistanceIndex = '低保救助记录' subsistenceAllowanceAssistanceDf = pd.DataFrame(columns=constsBase.subsistenceAllowanceAssistance,index=[subsistenceAllowanceAssistanceIndex]) #执业资格记录 practiceQualificationIndex = '执业资格记录' practiceQualificationDf = pd.DataFrame(columns=constsBase.practiceQualification,index=[practiceQualificationIndex]) #行政奖励记录 administrativeIncentiveIndex = '行政奖励记录' administrativeIncentiveDf = pd.DataFrame(columns=constsBase.administrativeIncentive,index=[administrativeIncentiveIndex]) #本人声明 personalDeclaration = "本人声明" personalDeclarationDf = pd.DataFrame(columns=constsBase.personalDeclaration,index=[personalDeclaration]) #异议标注 objectionMarking = "异议标注" objectionMarkingDf = pd.DataFrame(columns=constsBase.objectionMarking,index=[objectionMarking]) #查询记录 queryRecordIndexY = '查询记录' queryRecordDfY = pd.DataFrame(columns=constsBase.queryRecordY,index=[queryRecordIndexY]) #待执行的sql语句 sqlMap = [] 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) # print("xmlData" + xmlData) # print("docXml" +docXml) queryInfo = self.parseQueryInfo(docXml) reportTime = queryInfo["reportTime"]; start = timeit.default_timer(); logger.info(queryInfo["queryInfoCardId"] + "基本信息解析开始") 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) # yuan # self.parseBaseIdentity(reportTime, docXml) # self.parseBaseLiveInfo( docXml) # self.parseBaseOccupationInfoDf(docXml) # self.personalCreditInfo(docXml) # self.parseBriefInfoHeaderLoanTradeInfo(docXml) # self.parseCreditTransactionDefaultY(docXml) # self.parseBadDebtsInfoSumDfY(docXml) # self.parseOverdueInfoSumY(docXml) # self.parseLoanAccountInfoSumY(docXml) # self.parseCycleCreditAccountInfoSumY(docXml) # self.parseCyleLoanAccountInfoSumY(docXml) # self.parseCreditCardInfoSumY(docXml) # self.parseCreditCardInfoSumZY(docXml) # self.parsePublicInfoBriefY(docXml) # self.parseQueryRecordSumY(docXml) # self.parseRecoveryInfo(docXml) # # self.parseNoLoopLoan(docXml) # self.parseLoopSubAccount(docXml) # self.parseLoopLoan(docXml) # self.parseCreditCard(docXml) # self.parseQuasiquasiCreditCard(docXml) # self.parseRelevantRepaymentLiability(docXml) # self.parseCreditAgreement(docXml) # self.parseTaxArrears(docXml, reportTime) # self.parseCivilJudgment(docXml) # self.parseEnforce(docXml) # self.parseAdministrativePunishment(docXml, reportTime) # self.parseHousingProvidentFundParticipation(docXml) # self.parseSubsistenceAllowanceAssistance(docXml) # self.parsePracticeQualification(docXml) # self.parseAdministrativeIncentive(docXml, reportTime) # self.parseQueryRecordY(docXml) s = timeit.default_timer() - start logger.info(str(s) + " 秒") logger.info(queryInfo["queryInfoCardId"] + "基本信息解析完成") 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"]) if loanDfObj["loanPayRecordDf"]!=None: loanPayRecordMergeDfDs.extend(loanDfObj["loanPayRecordDf"]) loanSpecialTradeMergeDf = pd.concat([loanSpecialTradeMergeDf, loanDfObj["specialTradeDf"]], axis=0,ignore_index=True); if len(loanMergeDfDs)>0: loanMergeDf = pd.DataFrame(loanMergeDfDs) if len(loanPayRecordMergeDfDs)>0: 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) + "," #取消汇算帐 result += utils.toJson(otherDf) + "," #三寿新增 result += utils.toJson(sanshouDf) + "," self.calcFirstBusMonth(reportTime) self.getLastOverdueMonthJz(loanMergeDf,creditCardMergeDf,loanPayRecordMergeDf,creditCardPayRecordMergeDf,reportTime) result += utils.toJson(juziDf) # # yuan # result += utils.toJson(baseIdentityInfoDf) + "," # result += utils.toJson(baseMateInfoDf) + "," # result += utils.toJson(baseLiveInfoDf) + "," # result += utils.toJson(baseOccupationInfoDf) + "," # result += utils.toJson(personalCreditInfoDf) + "," # result += utils.toJson(briefInfoHeaderLoanTradeInfoDf) + "," # result += utils.toJson(briefInfoDf_recoveryInfoSumY) + "," # result += utils.toJson(briefInfoDf_badDebtsInfoSumY) + "," # result += utils.toJson(briefInfoDf_overdueInfoSumY) + "," # result += utils.toJson(creditTransactionCreditDf) + "," # result += utils.toJson(nonCreditTransactionsDf) + "," # result += utils.toJson(publicInformationDf) + "," # result += utils.toJson(queryRecordDf) + "," # result += utils.toJson(recoveryBaseInfoDf) + "," # result += utils.toJson(recoveryLatestDf) + "," # result += utils.toJson(recoverySpecialDf) + "," # result += utils.toJson(recoveryMarkDf) + "," # result += utils.toJson(noLoopLoanBaseDf) + "," # result += utils.toJson(noLoopLoanLastMonthDf) + "," # result += utils.toJson(noLoopLoanLatestDf) + "," # result += utils.toJson(noLoopLoan5YearDf) + "," # result += utils.toJson(noLoopLoanSpecialDf) + "," # result += utils.toJson(LoopSubAccountBaseDf) + "," # result += utils.toJson(LoopSubAccountLastMonthDf) + "," # result += utils.toJson(LoopSubAccount5YearDf) + "," # result += utils.toJson(LoopSubAccountSpecialDf) + "," # result += utils.toJson(LoopLoanBaseDf) + "," # result += utils.toJson(LoopLoanLastMonthDf) + "," # result += utils.toJson(LoopLoanLatestDf) + "," # result += utils.toJson(LoopLoan5YearDf) + "," # result += utils.toJson(LoopLoanSpecialDf) + "," # result += utils.toJson(creditCardBaseDf) + "," # # result += utils.toJson(creditCardLastMonthDf) + "," # result += utils.toJson(creditCardLatestDf) + "," # result += utils.toJson(creditCardBigDf) + "," # result += utils.toJson(creditCard5YearDf) + "," # result += utils.toJson(creditCardSpecialDf) + "," # result += utils.toJson(creditCardSpecialMentDf) + "," # result += utils.toJson(quasiCreditCardBaseDf) + "," # result += utils.toJson(quasiCreditCardLastMonthDf) + "," # result += utils.toJson(quasiCreditCardLatestDf) + "," # result += utils.toJson(quasiCreditCard5YearDf) + "," # result += utils.toJson(quasiCreditCardSpecialDf) + "," # result += utils.toJson(relevantRepaymentLiabilityDf) + "," # result += utils.toJson(creditAgreementDf) + "," # result += utils.toJson(postPaidRecordDf) + "," # result += utils.toJson(taxArrearsDf) + "," # result += utils.toJson(civilJudgmentDf) + "," # # # result += utils.toJson(enforceDf) + "," # result += utils.toJson(administrativePunishmentDf) + "," # result += utils.toJson(housingProvidentFundParticipationIndexDf) + "," # result += utils.toJson(subsistenceAllowanceAssistanceDf) + "," # result += utils.toJson(practiceQualificationDf) + "," # result += utils.toJson(administrativeIncentiveDf) + "," # # result += utils.toJson(personalDeclarationDf) + "," # result += utils.toJson(objectionMarkingDf) + "," # result += utils.toJson(queryRecordDfY) 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,sqlMap; # 解析被查询信息指标 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) RPTNO = self.getNodeData(headbo, "RPTNO") self.RPTNO = RPTNO self.saveNode(headbo) return queryInfo; #xml节点入库 def saveNode(self,node): try: RPTNO = self.RPTNO if node.nodeName == "HEADBO": sql = "insert into "+node.nodeName+"(" # 保存根节点 childNodes = node.childNodes; for child in childNodes: sql += child.nodeName+"," sql=sql[:-1] sql += ")" sql+="values(" for child in childNodes: if len(child.childNodes) == 1: sql +="'"+ child.childNodes[0].data + "'," else: sql += "'" + "" + "'," if sql.endswith(","): sql = sql[:-1] sql += ")" else:#保存其它节点 sql = "insert into " + node.nodeName + "(RPTNO," # 保存根节点 childNodes = node.childNodes; for child in childNodes: if child.nodeName=='RINFOLS': continue sql += child.nodeName + "," sql = sql[:-1] sql += ")" sql += "values("+"'"+RPTNO+"'," for child in childNodes: if child.nodeName=='RINFOLS': continue if len(child.childNodes) == 1: sql += "'" + child.childNodes[0].data + "'," else: sql += "'" + "" + "'," if sql.endswith(","): sql = sql[:-1] sql += ")" sqlMap.append(sql) except: logger.error(traceback.print_exc()) logger.error(traceback.format_exc()) def saveNodeWithType(self,node,TYPE): try: RPTNO = self.RPTNO sql = "insert into " + node.nodeName + "(TYPE,RPTNO," # 保存根节点 childNodes = node.childNodes; for child in childNodes: if child.nodeName=='RINFOLS': continue sql += child.nodeName + "," sql = sql[:-1] sql += ")" sql += "values("+"'"+TYPE+"','"+RPTNO+"'," for child in childNodes: if child.nodeName=='RINFOLS': continue if len(child.childNodes) == 1: sql += "'" + child.childNodes[0].data + "'," else: sql += "'" + "" + "'," if sql.endswith(","): sql = sql[:-1] sql += ")" sqlMap.append(sql) except: logger.error(traceback.print_exc()) logger.error(traceback.format_exc()) def parseIdentity(self,reportTime,docXml): tmpNode =docXml.documentElement.getElementsByTagName("BASEINFO") if len(tmpNode)>0: baseInfo = docXml.documentElement.getElementsByTagName("BASEINFO")[0] print(str(baseInfo)) self.saveNode(baseInfo) 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)): self.saveNode(telephoneinfosg[i]) 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): self.saveNode(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)): self.saveNode(residenceinfosg[i]) 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") self.saveNode(vocationinfosg[i]) 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")) self.saveNode(credittipsinfo[0]) briefInfoDf_loanTradeInfo.loc[loanTradeInfoIndex, '个人商用房贷款(包括商住两用)账户数'] = utils.toInt(self.getNodeData(credittipsinfo[1],"ACCOUNTNUM")) self.saveNode(credittipsinfo[1]) briefInfoDf_loanTradeInfo.loc[loanTradeInfoIndex, '其他类贷款账户数'] = utils.toInt(self.getNodeData(credittipsinfo[2],"ACCOUNTNUM")) self.saveNode(credittipsinfo[2]) briefInfoDf_loanTradeInfo.loc[loanTradeInfoIndex, '贷记卡账户数'] = utils.toInt(self.getNodeData(credittipsinfo[3],"ACCOUNTNUM")) self.saveNode(credittipsinfo[3]) briefInfoDf_loanTradeInfo.loc[loanTradeInfoIndex, '准贷记卡账户数'] = utils.toInt(self.getNodeData(credittipsinfo[4],"ACCOUNTNUM")) self.saveNode(credittipsinfo[4]) #汇算 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)) #贷款首次交易或者第一张贷记卡开卡日期距今月份数 #juzi def calcFirstBusMonth(self,reportTime): try: firstLoanMonth = str(otherDf.loc[otherIndex, '首笔贷款发放月份']) firstCreditMonth = str(otherDf.loc[otherIndex, '首张贷记卡发卡月份']) dateStr = "" if str(firstLoanMonth) == "nan": firstLoanMonth = "" if firstCreditMonth == "nan": firstCreditMonth = "" if firstLoanMonth == "" and firstCreditMonth !="": dateStr = firstCreditMonth elif firstCreditMonth == "" and firstLoanMonth !="": dateStr = firstLoanMonth elif firstCreditMonth == "" and firstLoanMonth =="": dateStr = "" else: dateStr = min(firstCreditMonth,firstLoanMonth) if dateStr !="": juziDf.loc[juziIndex, '贷款首次交易或者第一张贷记卡开卡日期距今月份数'] = utils.difMonthReportTime(dateStr,reportTime) except: logger.error(traceback.print_exc()) logger.error(traceback.format_exc()) mailUtil = MailUtil(); webhook = 'https://oapi.dingtalk.com/robot/send?access_token=64d8b2c7fed4949e9433b807c7c5559939f1517af8f77c1dacb4de19c6910b56' mailUtil.dingtalk("号码:" + " 解析错误 " + traceback.format_exc(), webhook) # 最近一次逾期距今月份数 juzi def getLastOverdueMonthJz(self, loanMergeDf, creditCardMergeDf, loanPayRecordMergeDf, creditCardPayRecordMergeDf, reportTime): try: result = None; 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) juziDf.loc[juziIndex, "用户贷记卡或者贷款最近逾期距今月份数"] = result except: logger.error(traceback.print_exc()) logger.error(traceback.format_exc()) mailUtil = MailUtil(); webhook = 'https://oapi.dingtalk.com/robot/send?access_token=64d8b2c7fed4949e9433b807c7c5559939f1517af8f77c1dacb4de19c6910b56' mailUtil.dingtalk("号码:" + " 解析错误 " + traceback.format_exc(), webhook) def encodeJuzi(self,value): result = "" if value == None: result = 'A' elif value >=1 and value <3: result = 'B' elif value >=3 and value <5: result = 'C' elif value >= 3 and value < 5: result = 'C' elif value >= 5 and value < 7: result = 'D' elif value >= 7 and value < 10: result = 'E' elif value >= 10 and value < 12: result = 'F' elif value >= 12 and value < 15: result = 'G' elif value >= 15 and value < 17: result = 'H' elif value >= 17 and value < 20: result = 'I' elif value >= 20 and value < 24: result = 'J' elif value >= 24 and value < 30: result = 'K' elif value >= 30 and value < 36: result = 'L' elif value >= 36 and value < 48: result = 'M' elif value >= 48: result = 'N' return result # 解析被追偿信息汇总 def parseRecoveryInfoSum(self,docXml): recoveredinfosumsmry = docXml.documentElement.getElementsByTagName("RECOVEREDINFOSUMSMRY"); recorinfosumsg = docXml.documentElement.getElementsByTagName("RECORINFOSUMSG") if len(recoveredinfosumsmry)>0: if len(recorinfosumsg)>0: self.saveNode(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")) self.saveNode(recorinfosumsg[1]) briefInfoDf_recoveryInfoSum.loc[recoveryInfoSumIndex, '合计总账户数'] = utils.toInt(self.getNodeData(recoveredinfosumsmry[0],"ACCOUNTNUMSUM")) briefInfoDf_recoveryInfoSum.loc[recoveryInfoSumIndex, '合计总余额'] = utils.replaceAmt(self.getNodeData(recoveredinfosumsmry[0],"BALANCESUM")) self.saveNode(recoveredinfosumsmry[0]) # 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")); self.saveNode(baddebtssmry[0]) # 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") self.saveNode(overdraftsumsg[i]) 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")) self.saveNode(noncyclicalsmry[0]) # 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")) self.saveNode(cybranchaccsmry[0]) # 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")) self.saveNode(cyclicalloansmry[0]) # 解析贷记卡信息汇总,包含准贷记卡 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")) self.saveNode(debitcardaccsmry[0]) # 解析贷记卡信息汇总,包含准贷记卡 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")) self.saveNode(zdebitcardaccsmry[0]) # 相关还款责任 def parseRepaymentSum(self,docXml): repaymentinfosmry = docXml.documentElement.getElementsByTagName("REPAYMENTINFOSMRY"); for item in repaymentinfosmry: self.saveNode(item) 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") for item in comminfosmry: self.saveNode(item) 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: self.saveNode(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)): self.saveNode(queryRecordsg[i]) 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)): self.saveNode(housingfund[i]) 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] self.saveNodeWithType(creditbaseinfobo,"FORCEDREPAYINFOBOLS") newperformancebo = creditacctinfobo[i].getElementsByTagName("NEWPERFORMANCEBO")[0] self.saveNodeWithType(newperformancebo,"FORCEDREPAYINFOBOLS") # 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: self.saveNodeWithType(specialtradebaseinfosg[0],"FORCEDREPAYINFOBOLS") 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"); loanDf = pd.DataFrame(columns=dfParser.dfHeaderLoan, index=[0]) for i in range(0, len(creditacctinfobo)): dfObj = {} loanDfObj = loanDf.to_json(orient="index",force_ascii=False) loanDfObj = json.loads(loanDfObj)['0'] creditbaseinfobo = creditacctinfobo[i].getElementsByTagName("CREDITBASEINFOBO")[0] self.saveNodeWithType(creditbaseinfobo,type) newperformancebo = creditacctinfobo[i].getElementsByTagName("NEWPERFORMANCEBO")[0] self.saveNodeWithType(newperformancebo,type) latemonthlyperformancebo = creditacctinfobo[i].getElementsByTagName("LATEMONTHLYPERFORMANCEBO") latemonthlyperformancebo = latemonthlyperformancebo[0] self.saveNodeWithType(latemonthlyperformancebo,type) 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 = None # 特殊交易 specialTradeDf = None # 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: loanPayRecord = self.mergeLoanPayRecordDf(fiveyearhisrpyinfols, loanPayRecord) specialTradeDf = self.mergeLoanSpecialTrade(specialtradebaseinfosg, specialTradeDf) 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] self.saveNodeWithType(creditbaseinfobo,"CREDITCARDACCOUNTBOLS") newperformancebo = creditacctinfobo[i].getElementsByTagName("NEWPERFORMANCEBO")[0] self.saveNodeWithType(newperformancebo,"CREDITCARDACCOUNTBOLS") latemonthlyperformancebo = creditacctinfobo[i].getElementsByTagName("LATEMONTHLYPERFORMANCEBO") latemonthlyperformancebo = latemonthlyperformancebo[0] self.saveNodeWithType(latemonthlyperformancebo,"CREDITCARDACCOUNTBOLS") 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] self.saveNodeWithType(bigquotabaselnfosg,"CREDITCARDACCOUNTBOLS") # '大额专项分期额度','分期额度生效日期','分期额度到期日期','已用分期金额'] 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 == "止付" 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: creditCardPayRecord = self.mergeCreditCardPayRecordDf(fiveyearhisrpyinfols, creditCardPayRecord) 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] self.saveNodeWithType(creditbaseinfobo,"PASSCREDITCARDACCOUNTBOLS") newperformancebo = creditacctinfobo[i].getElementsByTagName("NEWPERFORMANCEBO")[0] self.saveNodeWithType(newperformancebo,"PASSCREDITCARDACCOUNTBOLS") latemonthlyperformancebo = creditacctinfobo[i].getElementsByTagName("LATEMONTHLYPERFORMANCEBO") latemonthlyperformancebo = latemonthlyperformancebo[0] self.saveNodeWithType(latemonthlyperformancebo,"PASSCREDITCARDACCOUNTBOLS") 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 == "止付" 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: creditCardPayRecord = self.mergeCreditCardPayRecordDf(fiveyearhisrpyinfols, creditCardPayRecord) 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) self.saveNodeWithType(fiveyearhisrpyinfols[i],"LOAN") # 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]) loanPayRecordTmp = None 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"); self.saveNodeWithType(fiveyearhisrpyinfols[i],"CREDITCARD") 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)): self.saveNode(specialtradebaseinfosg[i]) 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(['关注','次级','可疑','损失'])] juziDf.loc[juziIndex, "贷款五级分类命中('关注','次级','可疑','损失')的账户数"] = fiveDf.index.size loanStatusDf = df[df['账户状态'].isin(['逾期','呆账','转出','担保物不足','强制平仓','司法追偿'])] juziDf.loc[juziIndex, "贷款状态为('逾期','呆账','转出','担保物不足','强制平仓','司法追偿')的账户数"] = 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 = "" fstLoanMon = str(otherDf.loc[otherIndex, '首笔贷款发放月份']) fstCreditCardMonth = str(otherDf.loc[otherIndex, '首张贷记卡发卡月份']) if fstLoanMon=="nan": fstLoanMon = "" if fstCreditCardMonth=="nan": fstCreditCardMonth = "" if fstLoanMon=='' and fstCreditCardMonth!='': minMonthStr = otherDf.loc[otherIndex, '首张贷记卡发卡月份'] elif fstLoanMon!='' and fstCreditCardMonth!='': minMonth = [otherDf.loc[otherIndex, '首笔贷款发放月份'], otherDf.loc[otherIndex, '首张贷记卡发卡月份']] minMonthStr = min(minMonth) elif fstLoanMon!='' and fstCreditCardMonth=='': minMonthStr = otherDf.loc[otherIndex, '首笔贷款发放月份'] if minMonthStr != '': 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 #yuan新开发部分 #yuan新开发部分,暂时不存入数据库 #基础个人信息1 def parseBaseIdentity(self,reportTime,docXml): tmpNode =docXml.documentElement.getElementsByTagName("BASEINFO") if len(tmpNode)>0: baseInfo = docXml.documentElement.getElementsByTagName("BASEINFO")[0] # print(str(baseInfo)) # self.saveNode(baseInfo) tmpNode = docXml.documentElement.getElementsByTagName("MARRIAGEINFOSG") baseIdentityInfoDf.loc[baseIdentityInfo, '性别'] = self.getNodeData(baseInfo,"SEXDESC") baseIdentityInfoDf.loc[baseIdentityInfo, '出生日期'] = self.getNodeData(baseInfo,"BIRTHDAY") baseIdentityInfoDf.loc[baseIdentityInfo, '国籍'] = self.getNodeData(baseInfo,"NATIONDESC") baseIdentityInfoDf.loc[baseIdentityInfo, '户籍地址'] = self.getNodeData(baseInfo,"ADDRESS") if len(tmpNode)>0: marriageinfosg = docXml.documentElement.getElementsByTagName("MARRIAGEINFOSG")[0] self.parseBaseMate(marriageinfosg) baseIdentityInfoDf.loc[baseIdentityInfo, '婚姻状况'] = self.getNodeData(marriageinfosg,"MARSTATUDESC") baseIdentityInfoDf.loc[baseIdentityInfo, '学历'] = self.getNodeData(baseInfo,"DEGREEDESC") baseIdentityInfoDf.loc[baseIdentityInfo, '学位'] = self.getNodeData(baseInfo,"DEGREEDESC") baseIdentityInfoDf.loc[baseIdentityInfo, '通讯地址'] = self.getNodeData(baseInfo,"COMMUADDRESS") baseIdentityInfoDf.loc[baseIdentityInfo, '就业状况'] = 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)) #基础配偶信息2 def parseBaseMate(self,marriageinfosg): self.saveNode(marriageinfosg) baseMateInfoDf.loc[baseMateInfo, '姓名'] = self.getNodeData(marriageinfosg,"SPUOSENAME") baseMateInfoDf.loc[baseMateInfo, '证件号码'] = self.getNodeData(marriageinfosg,"CERTNUM") baseMateInfoDf.loc[baseMateInfo, '工作单位'] = self.getNodeData(marriageinfosg,"COMPANY") baseMateInfoDf.loc[baseMateInfo, '联系电话'] = self.getNodeData(marriageinfosg,"TELNUM") # print(mateInfoDf.to_json(orient="index", force_ascii=False)) # 基础居住信息3 def parseBaseLiveInfo(self,docXml): # residenceinfosgls = docXml.documentElement.getElementsByTagName("RESIDENCEINFOSGLS") residenceinfosg = docXml.documentElement.getElementsByTagName("RESIDENCEINFOSG"); df = pd.DataFrame() for i in range(0, len(residenceinfosg)): # self.saveNode(residenceinfosg[i]) 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: baseLiveInfoDf.loc[baseLiveInfo, '居住地址'] = self.getNodeData(residenceinfosg[0],"ADDRESS") baseLiveInfoDf.loc[baseLiveInfo, '住宅电话'] = self.getNodeData(residenceinfosg[0],"TELNUM") # baseLiveInfoDf.loc[baseLiveInfo, '历史居住地址个数'] = 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; baseLiveInfoDf.loc[baseLiveInfo, '居住状况'] = self.getNodeData(residenceinfosg[0],"RESISTATUSDESC") baseLiveInfoDf.loc[baseLiveInfo, '信息更新日期'] = self.getNodeData(residenceinfosg[0],"UPDATEDATEINFO") # print(liveInfoDf.to_json(orient="index", force_ascii=False)) # 基础职业信息4 def parseBaseOccupationInfoDf(self,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") # self.saveNode(vocationinfosg[i]) 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") baseOccupationInfoDf.loc[baseOccupationInfo, '工作单位'] = self.getNodeData(vocationinfosg[0], "COMPANY") baseOccupationInfoDf.loc[baseOccupationInfo, '单位电话'] = self.getNodeData(vocationinfosg[0], "CPNTELNUM") baseOccupationInfoDf.loc[baseOccupationInfo, '单位性质'] = self.getNodeData(vocationinfosg[0], "CPNTYPEDESC") baseOccupationInfoDf.loc[baseOccupationInfo, '单位地址'] = self.getNodeData(vocationinfosg[0], "CPNADDRESS") baseOccupationInfoDf.loc[baseOccupationInfo, '职业'] = self.getNodeData(vocationinfosg[0], "VOCATIONDESC") baseOccupationInfoDf.loc[baseOccupationInfo, '行业'] = self.getNodeData(vocationinfosg[0], "TRADEDESC") baseOccupationInfoDf.loc[baseOccupationInfo, '职务'] = self.getNodeData(vocationinfosg[0], "TITLEDESC") baseOccupationInfoDf.loc[baseOccupationInfo, '职称'] = self.getNodeData(vocationinfosg[0], "VOCATIONTITLEDESC") baseOccupationInfoDf.loc[baseOccupationInfo, '进入本单位年份'] = self.getNodeData(vocationinfosg[0], "BEGINYEAR") baseOccupationInfoDf.loc[baseOccupationInfo, '信息更新日期'] = self.getNodeData(vocationinfosg[0], "INFOUPDATEDATE") # occupationInfoDf.loc[occupationInfoIndex, '历史工作单位数'] = len(vocationinfosg) # print(occupationInfoDf.to_json(orient="index", force_ascii=False)) # 个人信用报告"数字解读"5 def personalCreditInfo(self,docXml): tmpNode =docXml.documentElement.getElementsByTagName("GRADEINFOSMRY") if len(tmpNode)>0: personalCreditInfo = docXml.documentElement.getElementsByTagName("GRADEINFOSMRY")[0] personalCreditInfoDf.loc[baseMateInfo, '数字解读'] = self.getNodeData(personalCreditInfo,"NUMBERREAD") personalCreditInfoDf.loc[baseMateInfo, '相对位置'] = self.getNodeData(personalCreditInfo,"RELPOSITION") personalCreditInfoDf.loc[baseMateInfo, '说明'] = self.getNodeData(personalCreditInfo,"SCOREEXPLAINNUM") # 信贷交易信息提示6 def parseBriefInfoHeaderLoanTradeInfo(self,docXml): credittipsinfo = docXml.documentElement.getElementsByTagName("CREDITTIPSINFO"); if len(credittipsinfo)>0: briefInfoHeaderLoanTradeInfoDf.loc[briefInfoHeaderLoanTradeInfo, '个人住房贷款账户数'] = utils.toInt(self.getNodeData(credittipsinfo[0],"ACCOUNTNUM")) briefInfoHeaderLoanTradeInfoDf.loc[briefInfoHeaderLoanTradeInfo, '个人住房贷款首笔业务发放月份'] = self.getNodeData(credittipsinfo[0],"FIRSTBUSMONTH") # self.saveNode(credittipsinfo[0]) briefInfoHeaderLoanTradeInfoDf.loc[briefInfoHeaderLoanTradeInfo, '个人商用房贷款(包括商住两用)账户数'] = utils.toInt(self.getNodeData(credittipsinfo[1],"ACCOUNTNUM")) briefInfoHeaderLoanTradeInfoDf.loc[briefInfoHeaderLoanTradeInfo, '个人商用房贷款(包括商住两用)首笔业务发放月份'] = self.getNodeData(credittipsinfo[1],"FIRSTBUSMONTH") # self.saveNode(credittipsinfo[1]) briefInfoHeaderLoanTradeInfoDf.loc[briefInfoHeaderLoanTradeInfo, '其他类贷款账户数'] = utils.toInt(self.getNodeData(credittipsinfo[2],"ACCOUNTNUM")) briefInfoHeaderLoanTradeInfoDf.loc[briefInfoHeaderLoanTradeInfo, '其他类贷款首笔业务发放月份'] = self.getNodeData(credittipsinfo[2],"FIRSTBUSMONTH") # self.saveNode(credittipsinfo[2]) briefInfoHeaderLoanTradeInfoDf.loc[briefInfoHeaderLoanTradeInfo, '贷记卡账户数'] = utils.toInt(self.getNodeData(credittipsinfo[3],"ACCOUNTNUM")) briefInfoHeaderLoanTradeInfoDf.loc[briefInfoHeaderLoanTradeInfo, '贷记卡首笔业务发放月份'] = self.getNodeData(credittipsinfo[3],"FIRSTBUSMONTH") # self.saveNode(credittipsinfo[3]) briefInfoHeaderLoanTradeInfoDf.loc[briefInfoHeaderLoanTradeInfo, '准贷记卡账户数'] = utils.toInt(self.getNodeData(credittipsinfo[4],"ACCOUNTNUM")) briefInfoHeaderLoanTradeInfoDf.loc[briefInfoHeaderLoanTradeInfo, '准贷记卡首笔业务发放月份'] = self.getNodeData(credittipsinfo[4],"FIRSTBUSMONTH") # self.saveNode(credittipsinfo[4]) #汇算 # 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") #信贷交易违约信息概要包括7.8.9 # 被追偿信息汇总7 def parseCreditTransactionDefaultY(self,docXml): recoveredinfosumsmry = docXml.documentElement.getElementsByTagName("RECOVEREDINFOSUMSMRY"); recorinfosumsg = docXml.documentElement.getElementsByTagName("RECORINFOSUMSG") if len(recoveredinfosumsmry)>0: if len(recorinfosumsg)>0: self.saveNode(recorinfosumsg[0]) briefInfoDf_recoveryInfoSumY.loc[recoveryInfoSumIndexY, '资产处置业务账户数'] = utils.toInt(self.getNodeData(recorinfosumsg[0],"ACCOUNTNUM")) briefInfoDf_recoveryInfoSumY.loc[recoveryInfoSumIndexY, '资产处置业务余额'] = utils.replaceAmt(self.getNodeData(recorinfosumsg[0],"BALANCE")) briefInfoDf_recoveryInfoSumY.loc[recoveryInfoSumIndexY, '垫款业务账户数'] = utils.toInt(self.getNodeData(recorinfosumsg[1],"ACCOUNTNUM")) briefInfoDf_recoveryInfoSumY.loc[recoveryInfoSumIndexY, '垫款业务余额'] = utils.replaceAmt(self.getNodeData(recorinfosumsg[1],"BALANCE")) briefInfoDf_recoveryInfoSumY.loc[recoveryInfoSumIndexY, '合计总账户数'] = utils.toInt(self.getNodeData(recoveredinfosumsmry[0],"ACCOUNTNUMSUM")) briefInfoDf_recoveryInfoSumY.loc[recoveryInfoSumIndexY, '合计总余额'] = utils.replaceAmt(self.getNodeData(recoveredinfosumsmry[0],"BALANCESUM")) # 解析呆账信息汇总8 def parseBadDebtsInfoSumDfY(self,docXml): baddebtssmry = docXml.documentElement.getElementsByTagName("BADDEBTSSMRY"); if len(baddebtssmry)>0: briefInfoDf_badDebtsInfoSumY.loc[badDebtsInfoIndexY, '账户数'] = utils.toInt(self.getNodeData(baddebtssmry[0],"ACCOUNTNUM")) briefInfoDf_badDebtsInfoSumY.loc[badDebtsInfoIndexY, '余额'] = utils.replaceAmt(self.getNodeData(baddebtssmry[0],"BALANCE")); # self.saveNode(baddebtssmry[0]) # print(briefInfoDf_badDebtsInfoSum.to_json(orient="index", force_ascii=False)) #透支及逾期信息汇总9 def parseOverdueInfoSumY(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_overdueInfoSumY.loc[overdueInfoSumIndexY, '非循环贷帐户账户数'] = utils.toInt(self.getNodeData(overdraftsumsg[0],"ACCSUM")); briefInfoDf_overdueInfoSumY.loc[overdueInfoSumIndexY, '非循环贷帐户月份数'] = utils.toInt(self.getNodeData(overdraftsumsg[0],"MONTHSUM")); briefInfoDf_overdueInfoSumY.loc[overdueInfoSumIndexY, '非循环贷帐户单月最高逾期总额'] = utils.replaceAmt(self.getNodeData(overdraftsumsg[0],"OVERDRAFTMAX")); briefInfoDf_overdueInfoSumY.loc[overdueInfoSumIndexY, '非循环贷帐户最长逾期月数'] = utils.toInt(self.getNodeData(overdraftsumsg[0],"OVERMONTH")); briefInfoDf_overdueInfoSumY.loc[overdueInfoSumIndexY, '循环额度下分账户账户数'] = utils.toInt(self.getNodeData(overdraftsumsg[1],"ACCSUM")); briefInfoDf_overdueInfoSumY.loc[overdueInfoSumIndexY, '循环额度下分账户月份数'] = utils.toInt(self.getNodeData(overdraftsumsg[1],"MONTHSUM")); briefInfoDf_overdueInfoSumY.loc[overdueInfoSumIndexY, '循环额度下分账户单月最高逾期总额'] = utils.replaceAmt(self.getNodeData(overdraftsumsg[1],"OVERDRAFTMAX")); briefInfoDf_overdueInfoSumY.loc[overdueInfoSumIndexY, '循环额度下分账户最长逾期月数'] = utils.toInt(self.getNodeData(overdraftsumsg[1],"OVERMONTH")); briefInfoDf_overdueInfoSumY.loc[overdueInfoSumIndexY, '循环贷账户账户数'] = utils.toInt(self.getNodeData(overdraftsumsg[2],"ACCSUM")); briefInfoDf_overdueInfoSumY.loc[overdueInfoSumIndexY, '循环贷账户月份数'] = utils.toInt(self.getNodeData(overdraftsumsg[2],"MONTHSUM")); briefInfoDf_overdueInfoSumY.loc[overdueInfoSumIndexY, '循环贷账户单月最高逾期总额'] = utils.replaceAmt(self.getNodeData(overdraftsumsg[2],"OVERDRAFTMAX")); briefInfoDf_overdueInfoSumY.loc[overdueInfoSumIndexY, '循环贷账户最长逾期月数'] = utils.toInt(self.getNodeData(overdraftsumsg[2],"OVERMONTH")); briefInfoDf_overdueInfoSumY.loc[overdueInfoSumIndexY, '贷记卡账户账户数'] = utils.toInt(self.getNodeData(overdraftsumsg[3],"ACCSUM")); briefInfoDf_overdueInfoSumY.loc[overdueInfoSumIndexY, '贷记卡账户月份数'] = utils.toInt(self.getNodeData(overdraftsumsg[3],"MONTHSUM")); briefInfoDf_overdueInfoSumY.loc[overdueInfoSumIndexY, '贷记卡账户单月逾期总额'] = utils.replaceAmt(self.getNodeData(overdraftsumsg[3],"OVERDRAFTMAX")); briefInfoDf_overdueInfoSumY.loc[overdueInfoSumIndexY, '贷记卡账户最长逾期月数'] = utils.toInt(self.getNodeData(overdraftsumsg[3],"OVERMONTH")); briefInfoDf_overdueInfoSumY.loc[overdueInfoSumIndexY, '准贷记卡账户账户数'] = utils.toInt(self.getNodeData(overdraftsumsg[4],"ACCSUM")); briefInfoDf_overdueInfoSumY.loc[overdueInfoSumIndexY, '准贷记卡账户月份数'] = utils.toInt(self.getNodeData(overdraftsumsg[4],"MONTHSUM")); briefInfoDf_overdueInfoSumY.loc[overdueInfoSumIndexY, '准贷记卡账户单月透支总额'] = utils.replaceAmt(self.getNodeData(overdraftsumsg[4],"OVERDRAFTMAX")); briefInfoDf_overdueInfoSum.loc[overdueInfoSumIndexY, '准贷记卡账户最长透支月数'] = utils.toInt(self.getNodeData(overdraftsumsg[4],"OVERMONTH")); #3.5⏹ # 信贷交易授信及负债信息概10:非循环贷账户信息汇总10 def parseLoanAccountInfoSumY(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, :] creditTransactionCreditDf.loc[creditTransactionCredit, '非循环贷账户管理机构数'] = int(self.getNodeData(noncyclicalsmry[0],"MANAGEORGNUM")) creditTransactionCreditDf.loc[creditTransactionCredit, '非循环贷账户账户数'] = int(self.getNodeData(noncyclicalsmry[0],"ACCSUM")) creditTransactionCreditDf.loc[creditTransactionCredit, '非循环贷账户授信总额'] = utils.replaceAmt(self.getNodeData(noncyclicalsmry[0],"CREDITSUM")) creditTransactionCreditDf.loc[creditTransactionCredit, '非循环贷账户余额'] = utils.replaceAmt(self.getNodeData(noncyclicalsmry[0],"BALANCE")) creditTransactionCreditDf.loc[creditTransactionCredit, '非循环贷账户6月平均应还款'] = utils.replaceAmt(self.getNodeData(noncyclicalsmry[0],"LATELY6MON")) self.saveNode(noncyclicalsmry[0]) # print(briefInfoDf_loanTradeCreditInfo.to_json(orient="index", force_ascii=False)) # 循环额度下分账户10 def parseCycleCreditAccountInfoSumY(self,docXml): cybranchaccsmry = docXml.documentElement.getElementsByTagName("CYBRANCHACCSMRY"); if len(cybranchaccsmry) > 0: creditTransactionCreditDf.loc[creditTransactionCredit, '循环额度下分账户管理机构数'] = int(self.getNodeData(cybranchaccsmry[0],"MANAGEORGNUM")) creditTransactionCreditDf.loc[creditTransactionCredit, '循环额度下分账户账户数'] = int(self.getNodeData(cybranchaccsmry[0],"ACCSUM")) creditTransactionCreditDf.loc[creditTransactionCredit, '循环额度下分账户授信总额'] = utils.replaceAmt(self.getNodeData(cybranchaccsmry[0],"CREDITSUM")) creditTransactionCreditDf.loc[creditTransactionCredit, '循环额度下分账户余额'] = utils.replaceAmt(self.getNodeData(cybranchaccsmry[0],"BALANCE")) creditTransactionCreditDf.loc[creditTransactionCredit, '循环额度下分账户6月平均应还款'] = utils.replaceAmt(self.getNodeData(cybranchaccsmry[0],"LATELY6MON")) self.saveNode(cybranchaccsmry[0]) # print(briefInfoDf_loanTradeCreditInfo.to_json(orient="index", force_ascii=False)) # 循环贷账户信息10 def parseCyleLoanAccountInfoSumY(self,docXml): cyclicalloansmry = docXml.documentElement.getElementsByTagName("CYCLICALLOANSMRY"); if len(cyclicalloansmry) > 0: creditTransactionCreditDf.loc[creditTransactionCredit, '循环贷账户管理机构数'] = int(self.getNodeData(cyclicalloansmry[0],"MANAGEORGNUM")) creditTransactionCreditDf.loc[creditTransactionCredit, '循环贷账户账户数'] = int(self.getNodeData(cyclicalloansmry[0],"ACCSUM")) creditTransactionCreditDf.loc[creditTransactionCredit, '循环贷账户授信总额'] = utils.replaceAmt(self.getNodeData(cyclicalloansmry[0],"CREDITSUM")) creditTransactionCreditDf.loc[creditTransactionCredit, '循环贷账户余额'] = utils.replaceAmt(self.getNodeData(cyclicalloansmry[0],"BALANCE")) creditTransactionCreditDf.loc[creditTransactionCredit, '循环贷账户6月平均应还款'] = utils.replaceAmt(self.getNodeData(cyclicalloansmry[0],"LATELY6MON")) self.saveNode(cyclicalloansmry[0]) # 解析贷记卡信息汇总10 def parseCreditCardInfoSumY(self,docXml): debitcardaccsmry = docXml.documentElement.getElementsByTagName("DEBITCARDACCSMRY"); if len(debitcardaccsmry) > 0: creditTransactionCreditDf.loc[creditTransactionCredit, '贷记卡发卡机构数'] = int(self.getNodeData(debitcardaccsmry[0],"CARDISSUERNUM")) creditTransactionCreditDf.loc[creditTransactionCredit, '贷记卡账户数'] =int(self.getNodeData(debitcardaccsmry[0],"ACCSUM")) creditTransactionCreditDf.loc[creditTransactionCredit, '贷记卡授信总额'] = utils.replaceAmt(self.getNodeData(debitcardaccsmry[0],"CREDITSUM")) creditTransactionCreditDf.loc[creditTransactionCredit, '贷记卡单家机构最高授信额'] = utils.replaceAmt(self.getNodeData(debitcardaccsmry[0],"CRAMOUNTMAX")) creditTransactionCreditDf.loc[creditTransactionCredit, '贷记卡单家机构最低授信额'] =utils.replaceAmt(self.getNodeData(debitcardaccsmry[0],"CRAMOUNTMIN")) creditTransactionCreditDf.loc[creditTransactionCredit, '贷记卡已用额度'] = utils.replaceAmt(self.getNodeData(debitcardaccsmry[0],"ALREADYUSED")) creditTransactionCreditDf.loc[creditTransactionCredit, '贷记卡最近6个月平均使用额度'] = utils.replaceAmt(self.getNodeData(debitcardaccsmry[0],"LATELY6MONUSE")) self.saveNode(debitcardaccsmry[0]) # 解析准贷记卡信息汇总10 def parseCreditCardInfoSumZY(self,docXml): zdebitcardaccsmry = docXml.documentElement.getElementsByTagName("ZDEBITCARDACCSMRY"); if len(zdebitcardaccsmry) > 0: creditTransactionCreditDf.loc[creditTransactionCredit, '准贷记卡发卡机构数'] = int(self.getNodeData(zdebitcardaccsmry[0],"CARDISSUERNUM")) creditTransactionCreditDf.loc[creditTransactionCredit, '准贷记卡账户数'] =int(self.getNodeData(zdebitcardaccsmry[0],"ACCSUM")) creditTransactionCreditDf.loc[creditTransactionCredit, '准贷记卡授信总额'] = utils.replaceAmt(self.getNodeData(zdebitcardaccsmry[0],"CREDITSUM")) creditTransactionCreditDf.loc[creditTransactionCredit, '准贷记卡单家机构最高授信额'] = utils.replaceAmt(self.getNodeData(zdebitcardaccsmry[0],"CRAMOUNTMAX")) creditTransactionCreditDf.loc[creditTransactionCredit, '准贷记卡单家机构最低授信额'] = utils.replaceAmt(self.getNodeData(zdebitcardaccsmry[0],"CRAMOUNTMIN")) creditTransactionCreditDf.loc[creditTransactionCredit, '准贷记卡已用额度'] = utils.replaceAmt(self.getNodeData(zdebitcardaccsmry[0],"OVERDRAFT")) creditTransactionCreditDf.loc[creditTransactionCredit, '准贷记卡最近6个月平均使用额度'] = utils.replaceAmt(self.getNodeData(zdebitcardaccsmry[0],"LATELY6MONDRAFT")) self.saveNode(zdebitcardaccsmry[0]) # # 非信贷交易信息概要11 ?暂不明确 # def parsePublicInformation(self,docXml): # tmpNode =docXml.documentElement.getElementsByTagName("POSTPAYSMRYLS") # if len(tmpNode)>0: # personalCreditInfo = docXml.documentElement.getElementsByTagName("POSTPAYSMRY")[0] #公共信息概要12 def parsePublicInfoBriefY(self,docXml): comminfosmry = docXml.documentElement.getElementsByTagName("COMMINFOSMRY") # for item in comminfosmry: # self.saveNode(item) if len(comminfosmry)>0: publicInformationDf.loc[publicInformation, '欠税信息记录数'] = utils.toInt(self.getNodeData(comminfosmry[0],"RECORDNUM")) publicInformationDf.loc[publicInformation, '欠税信息涉及金额'] = utils.replaceAmt(self.getNodeData(comminfosmry[0],"INVOLVEMONEY")) publicInformationDf.loc[publicInformation, '民事判决信息记录数'] = utils.toInt(self.getNodeData(comminfosmry[1],"RECORDNUM")) publicInformationDf.loc[publicInformation, '民事判决信息涉及金额'] = utils.replaceAmt(self.getNodeData(comminfosmry[1],"INVOLVEMONEY")) publicInformationDf.loc[publicInformation, '强制执行信息记录数'] = utils.toInt(self.getNodeData(comminfosmry[2],"RECORDNUM")) publicInformationDf.loc[publicInformation, '强制执行信息涉及金额'] = utils.replaceAmt(self.getNodeData(comminfosmry[2],"INVOLVEMONEY")) publicInformationDf.loc[publicInformation, '行政处罚信息记录数'] = utils.toInt(self.getNodeData(comminfosmry[3],"RECORDNUM")) publicInformationDf.loc[publicInformation, '行政处罚信息涉及金额'] = utils.replaceAmt(self.getNodeData(comminfosmry[3],"INVOLVEMONEY")) # 查询记录概要13 def parseQueryRecordSumY(self,docXml): laseQuery = docXml.documentElement.getElementsByTagName("LASTQUERYRECORDSG") queryrecordsumsg = docXml.documentElement.getElementsByTagName("QUERYRECORDSUMSG") if len(laseQuery) > 0: queryRecordDf.loc[queryRecord, '上一次查询日期'] = int(self.getNodeData(laseQuery[0],"LASTQUERYDATE")) queryRecordDf.loc[queryRecord, '上一次查询机构名称'] = int(self.getNodeData(laseQuery[0],"LASTORGCODE")) queryRecordDf.loc[queryRecord, '上一次查询原因'] = int(self.getNodeData(laseQuery[0],"LASTQUERYREASONCODE")) if len(queryrecordsumsg) > 0: # self.saveNode(queryrecordsumsg[0]) queryRecordDf.loc[queryRecord, '近1月内的查询机构数-贷款审批'] = int(self.getNodeData(queryrecordsumsg[0],"LAST1ORGSP")) queryRecordDf.loc[queryRecord, '近1月内的查询机构数-信用卡审批'] = int(self.getNodeData(queryrecordsumsg[0],"LAST1CREDITSP")) queryRecordDf.loc[queryRecord, '近1月内的查询次数-贷款审批'] = int(self.getNodeData(queryrecordsumsg[0],"NUMSP")) queryRecordDf.loc[queryRecord, '近1月内的查询次数-信用卡审批'] = int(self.getNodeData(queryrecordsumsg[0],"NUMCREDITSP")) queryRecordDf.loc[queryRecord, '近1月内的查询次数-本人查询'] = int(self.getNodeData(queryrecordsumsg[0],"LAST1NUMSELF")) queryRecordDf.loc[queryRecord, '近2年内的查询次数-贷后管理'] = int(self.getNodeData(queryrecordsumsg[0],"L2YNUMDH")) queryRecordDf.loc[queryRecord, '近2年内的查询次数-担保资格审查'] = int(self.getNodeData(queryrecordsumsg[0],"L2YNUMDBZG")) queryRecordDf.loc[queryRecord, '近2年内的查询次数-特约商户实名审查'] = int(self.getNodeData(queryrecordsumsg[0],"L2NUMTYSH")) # 三 信贷交易信息明细 # 被追偿账户基本信息 def parseRecoveryInfo(self,docXml): forcedrepayinfobols = docXml.documentElement.getElementsByTagName("FORCEDREPAYINFOBOLS") if len(forcedrepayinfobols)>0: force = docXml.documentElement.getElementsByTagName("FORCEDREPAYINFOBOLS")[0] base = force.getElementsByTagName("CREDITACCTINFOBO"); recoveryBaseInfoDf.loc[recoveryBaseInfo, '管理机构'] = self.getNodeData(base[0],"MANAGEORGTYPECODE") recoveryBaseInfoDf.loc[recoveryBaseInfo, '业务种类'] = self.getNodeData(base[0],"LOANTYPECODE") recoveryBaseInfoDf.loc[recoveryBaseInfo, '债权转移时的还款状态代码'] = self.getNodeData(base[0],"RPYACCOUNTSTATUSCODE") #最新表现信息 latest = force.getElementsByTagName("NEWPERFORMANCEBO"); # if len(latest)>0: recoveryLatestDf.loc[recoveryLatest, '账户状态'] = self.getNodeData(latest[0],"ACCTSTATUSCODE") recoveryLatestDf.loc[recoveryLatest, '余额'] = self.getNodeData(latest[0],"BALANCE") recoveryLatestDf.loc[recoveryLatest, '最近一次还款日期'] = self.getNodeData(latest[0],"REPAYDATE") recoveryLatestDf.loc[recoveryLatest, '账户关闭日期'] = self.getNodeData(latest[0],"SETTLEDATE") #特殊交易信息 special = force.getElementsByTagName("SPECIALTRADEBASEINFOSG"); # if len(special)>0: recoverySpecialDf.loc[recoverySpecial, '特殊交易类型'] = self.getNodeData(special[0],"TRANTYPECODE") recoverySpecialDf.loc[recoverySpecial, '发生日期'] = self.getNodeData(special[0],"TRANDATE") recoverySpecialDf.loc[recoverySpecial, '变更月数'] = self.getNodeData(special[0],"TRANMONTH") recoverySpecialDf.loc[recoverySpecial, '发生金额'] = self.getNodeData(special[0],"TRANAMT") recoverySpecialDf.loc[recoverySpecial, '明细记录'] = self.getNodeData(special[0],"DETRECORD") # 非循环贷账户 def parseNoLoopLoan(self,docXml): noloopCredit = docXml.documentElement.getElementsByTagName("NOLOOPCREDITACCOUNTBOLS") #基本信息 if len(noloopCredit)>0: noloop = docXml.documentElement.getElementsByTagName("NOLOOPCREDITACCOUNTBOLS")[0] base = noloop.getElementsByTagName("CREDITACCTINFOBO"); noLoopLoanBaseDf.loc[noLoopLoanBase, '管理机构'] = self.getNodeData(base[0],"MANAGEORGTYPECODE") noLoopLoanBaseDf.loc[noLoopLoanBase, '账户标识'] = self.getNodeData(base[0],"ACCTCODE") noLoopLoanBaseDf.loc[noLoopLoanBase, '开立日期'] = self.getNodeData(base[0],"OPENDATE") noLoopLoanBaseDf.loc[noLoopLoanBase, '到期日期'] = self.getNodeData(base[0],"DUEDATE") noLoopLoanBaseDf.loc[noLoopLoanBase, '借款金额'] = self.getNodeData(base[0],"LOANAMT") noLoopLoanBaseDf.loc[noLoopLoanBase, '账户币种'] = self.getNodeData(base[0],"MONEYTYPECODE") noLoopLoanBaseDf.loc[noLoopLoanBase, '业务种类'] = self.getNodeData(base[0],"LOANTYPECODE") noLoopLoanBaseDf.loc[noLoopLoanBase, '担保方式'] = self.getNodeData(base[0],"GUARMODECODE") noLoopLoanBaseDf.loc[noLoopLoanBase, '还款期数'] = self.getNodeData(base[0],"REPAYPRD") noLoopLoanBaseDf.loc[noLoopLoanBase, '还款频率'] = self.getNodeData(base[0],"REPAYFREQCYCODE") noLoopLoanBaseDf.loc[noLoopLoanBase, '还款方式'] = self.getNodeData(base[0],"REPAYCODE") noLoopLoanBaseDf.loc[noLoopLoanBase, '共同借款标志'] = self.getNodeData(base[0],"COMMBORROWERMAKERCODE") #最近一次月度表现信息 LastMonth = noloop.getElementsByTagName("LATEMONTHLYPERFORMANCEBO") # if len(LastMonth)>0: noLoopLoanLastMonthDf.loc[noLoopLoanLastMonth, '账户状态'] = self.getNodeData(LastMonth[0],"ACCTSTATUCODE") noLoopLoanLastMonthDf.loc[noLoopLoanLastMonth, '五级分类'] = self.getNodeData(LastMonth[0],"FIVECATECODE") noLoopLoanLastMonthDf.loc[noLoopLoanLastMonth, '余额'] = self.getNodeData(LastMonth[0],"BUSIBAL") noLoopLoanLastMonthDf.loc[noLoopLoanLastMonth, '剩余还款期数'] = self.getNodeData(LastMonth[0],"REMREPPRD") noLoopLoanLastMonthDf.loc[noLoopLoanLastMonth, '结算/应还款日'] = self.getNodeData(LastMonth[0],"SETTDATE") noLoopLoanLastMonthDf.loc[noLoopLoanLastMonth, '本月应还款'] = self.getNodeData(LastMonth[0],"CURRPYAMT") noLoopLoanLastMonthDf.loc[noLoopLoanLastMonth, '本月实还款'] = self.getNodeData(LastMonth[0],"ACTRPYAMT") noLoopLoanLastMonthDf.loc[noLoopLoanLastMonth, '最近一次还款日期'] = self.getNodeData(LastMonth[0],"LATRPYDATE") noLoopLoanLastMonthDf.loc[noLoopLoanLastMonth, '当前逾期期数'] = self.getNodeData(LastMonth[0],"OVERDPRD") noLoopLoanLastMonthDf.loc[noLoopLoanLastMonth, '当前逾期总额'] = self.getNodeData(LastMonth[0],"TOTOVERD") noLoopLoanLastMonthDf.loc[noLoopLoanLastMonth, '逾期 31—60 天未还本金'] = self.getNodeData(LastMonth[0],"OVERD3160PRINC") noLoopLoanLastMonthDf.loc[noLoopLoanLastMonth, '逾期 61-90 天未还本金'] = self.getNodeData(LastMonth[0],"OVERD6190PRINC") noLoopLoanLastMonthDf.loc[noLoopLoanLastMonth, '逾期 91-180 天未还本金'] = self.getNodeData(LastMonth[0],"OVERD91180PRINC") noLoopLoanLastMonthDf.loc[noLoopLoanLastMonth, '逾期 180 天以上未还本金'] = self.getNodeData(LastMonth[0],"OVERDPRINCOVE180") #最新表现信息 latest = noloop.getElementsByTagName("NEWPERFORMANCEBO"); # if len(latest)>0: noLoopLoanLatestDf.loc[noLoopLoanLatest, '余额'] = self.getNodeData(latest[0],"BALANCE") noLoopLoanLatestDf.loc[noLoopLoanLatest, '五级分类'] = self.getNodeData(latest[0],"FIVECATECODE") noLoopLoanLatestDf.loc[noLoopLoanLatest, '最近一次还款日期'] = self.getNodeData(latest[0],"REPAYDATE") noLoopLoanLatestDf.loc[noLoopLoanLatest, '最近一次还款金额'] = self.getNodeData(latest[0],"REPAYAMT") noLoopLoanLatestDf.loc[noLoopLoanLatest, '当前还款状态'] = self.getNodeData(latest[0],"RPYSTATUSCODE") noLoopLoanLatestDf.loc[noLoopLoanLatest, '信息报告日期'] = self.getNodeData(latest[0],"REPORTDATEINFO") noLoopLoanLatestDf.loc[noLoopLoanLatest, '账户状态'] = self.getNodeData(latest[0],"ACCTSTATUSCODE") noLoopLoanLatestDf.loc[noLoopLoanLatest, '转出月份'] = self.getNodeData(latest[0],"ROLLOUTDATE") noLoopLoanLatestDf.loc[noLoopLoanLatest, '账户关闭日期'] = self.getNodeData(latest[0],"SETTLEDATE") #最近 5 年内的历史表现信息 fiveYear = noloop.getElementsByTagName("FIVEYEARPERFORMANCESG"); fiveYearHis = noloop.getElementsByTagName("FIVEYEARHISRPYINFOSG") # if len(fiveYear)>0: fiveYearM = noloop.getElementsByTagName("FIVEYEARPERFORMANCESG") fiveYearHis = noloop.getElementsByTagName("FIVEYEARHISRPYINFOSG") noLoopLoan5YearDf.loc[noLoopLoan5Year, '起始年月'] = self.getNodeData(fiveYearM[0],"STARTYEARMONTH") noLoopLoan5YearDf.loc[noLoopLoan5Year, '截止年月'] = self.getNodeData(fiveYearM[0],"ENDYEARMONTH") # if len(fiveYearHis)>0: noLoopLoan5YearDf.loc[noLoopLoan5Year, '月份'] = self.getNodeData(fiveYearHis[0], "OVERDMON") noLoopLoan5YearDf.loc[noLoopLoan5Year, '还款状态'] = self.getNodeData(fiveYearHis[0],"OVERDSTATUSCODE") noLoopLoan5YearDf.loc[noLoopLoan5Year, '逾期(透支)总额'] = self.getNodeData(fiveYearHis[0],"TOTACCTBAL") #特殊交易信息 special = noloop.getElementsByTagName("SPECIALTRADEBASEINFOSG"); # if len(special)>0: noLoopLoan5YearDf.loc[noLoopLoan5Year, '特殊交易类型'] = self.getNodeData(special[0],"TRANTYPECODE") noLoopLoan5YearDf.loc[noLoopLoan5Year, '发生日期'] = self.getNodeData(special[0],"TRANDATE") noLoopLoan5YearDf.loc[noLoopLoan5Year, '变更月数'] = self.getNodeData(special[0],"TRANMONTH") noLoopLoan5YearDf.loc[noLoopLoan5Year, '发生金额'] = self.getNodeData(special[0],"TRANAMT") noLoopLoan5YearDf.loc[noLoopLoan5Year, '明细记录'] = self.getNodeData(special[0],"DETRECORD") # 循环额度下分账户 def parseLoopSubAccount(self,docXml): loopQuata = docXml.documentElement.getElementsByTagName("LOOPQUOTAACCOUNTBOLS") #循环额度下分账户基本信息 if len(loopQuata)>0: loop = docXml.documentElement.getElementsByTagName("LOOPQUOTAACCOUNTBOLS")[0] base = loop.getElementsByTagName("CREDITACCTINFOBO"); LoopSubAccountBaseDf.loc[LoopSubAccountBase, '管理机构'] = self.getNodeData(base[0],"MANAGEORGTYPECODE") LoopSubAccountBaseDf.loc[LoopSubAccountBase, '账户标识'] = self.getNodeData(base[0],"ACCTCODE") LoopSubAccountBaseDf.loc[LoopSubAccountBase, '开立日期'] = self.getNodeData(base[0],"OPENDATE") LoopSubAccountBaseDf.loc[LoopSubAccountBase, '到期日期'] = self.getNodeData(base[0],"DUEDATE") LoopSubAccountBaseDf.loc[LoopSubAccountBase, '借款金额'] = self.getNodeData(base[0],"LOANAMT") LoopSubAccountBaseDf.loc[LoopSubAccountBase, '账户币种'] = self.getNodeData(base[0],"MONEYTYPECODE") LoopSubAccountBaseDf.loc[LoopSubAccountBase, '业务种类'] = self.getNodeData(base[0],"LOANTYPECODE") LoopSubAccountBaseDf.loc[LoopSubAccountBase, '担保方式'] = self.getNodeData(base[0],"GUARMODECODE") LoopSubAccountBaseDf.loc[LoopSubAccountBase, '还款期数'] = self.getNodeData(base[0],"REPAYPRD") LoopSubAccountBaseDf.loc[LoopSubAccountBase, '还款频率'] = self.getNodeData(base[0],"REPAYFREQCYCODE") LoopSubAccountBaseDf.loc[LoopSubAccountBase, '还款方式'] = self.getNodeData(base[0],"REPAYCODE") LoopSubAccountBaseDf.loc[LoopSubAccountBase, '共同借款标志'] = self.getNodeData(base[0],"COMMBORROWERMAKERCODE") #循环额度下分账户最近一次月度表现信息 LastMonth = loop.getElementsByTagName("LATEMONTHLYPERFORMANCEBO") # if len(LastMonth)>0: LoopSubAccountLastMonthDf.loc[LoopSubAccountLastMonth, '账户状态'] = self.getNodeData(LastMonth[0],"ACCTSTATUCODE") LoopSubAccountLastMonthDf.loc[LoopSubAccountLastMonth, '五级分类'] = self.getNodeData(LastMonth[0],"FIVECATECODE") LoopSubAccountLastMonthDf.loc[LoopSubAccountLastMonth, '余额'] = self.getNodeData(LastMonth[0],"BUSIBAL") LoopSubAccountLastMonthDf.loc[LoopSubAccountLastMonth, '剩余还款期数'] = self.getNodeData(LastMonth[0],"REMREPPRD") LoopSubAccountLastMonthDf.loc[LoopSubAccountLastMonth, '本月应还款'] = self.getNodeData(LastMonth[0],"CURRPYAMT") LoopSubAccountLastMonthDf.loc[LoopSubAccountLastMonth, '应还款日'] = self.getNodeData(LastMonth[0],"SETTDATE") LoopSubAccountLastMonthDf.loc[LoopSubAccountLastMonth, '本月实还款'] = self.getNodeData(LastMonth[0],"ACTRPYAMT") LoopSubAccountLastMonthDf.loc[LoopSubAccountLastMonth, '最近一次还款日期'] = self.getNodeData(LastMonth[0],"LATRPYDATE") LoopSubAccountLastMonthDf.loc[LoopSubAccountLastMonth, '当前逾期期数'] = self.getNodeData(LastMonth[0],"OVERDPRD") LoopSubAccountLastMonthDf.loc[LoopSubAccountLastMonth, '当前逾期总额'] = self.getNodeData(LastMonth[0],"TOTOVERD") LoopSubAccountLastMonthDf.loc[LoopSubAccountLastMonth, '逾期 31—60 天未还本金'] = self.getNodeData(LastMonth[0],"OVERD3160PRINC") LoopSubAccountLastMonthDf.loc[LoopSubAccountLastMonth, '逾期 61-90 天未还本金'] = self.getNodeData(LastMonth[0],"OVERD6190PRINC") LoopSubAccountLastMonthDf.loc[LoopSubAccountLastMonth, '逾期 91-180 天未还本金'] = self.getNodeData(LastMonth[0],"OVERD91180PRINC") LoopSubAccountLastMonthDf.loc[LoopSubAccountLastMonth, '逾期 180 天以上未还本金'] = self.getNodeData(LastMonth[0],"OVERDPRINCOVE180") # 循环额度下分账户最近 5 年内的历史表现信息 fiveYear = loop.getElementsByTagName("FIVEYEARPERFORMANCESG"); fiveYearHis = fiveYear.getElementsByTagName("FIVEYEARHISRPYINFOSG") # if len(fiveYear)>0: LoopSubAccount5YearDf.loc[LoopSubAccount5Year, '起始年月'] = self.getNodeData(fiveYear[0],"STARTYEARMONTH") LoopSubAccount5YearDf.loc[LoopSubAccount5Year, '截止年月'] = self.getNodeData(fiveYear[0],"ENDYEARMONTH") if len(fiveYearHis)>0: LoopSubAccount5YearDf.loc[LoopSubAccount5Year, '月份'] = self.getNodeData(fiveYearHis[0], "OVERDMON") LoopSubAccount5YearDf.loc[LoopSubAccount5Year, '还款状态'] = self.getNodeData(fiveYearHis[0],"OVERDSTATUSCODE") LoopSubAccount5YearDf.loc[LoopSubAccount5Year, '逾期(透支)总额'] = self.getNodeData(fiveYearHis[0],"TOTACCTBAL") #循环额度下分帐户特殊交易信息 special = loop.getElementsByTagName("SPECIALTRADEBASEINFOSG"); # if len(special)>0: LoopSubAccountSpecialDf.loc[LoopSubAccountSpecial, '特殊交易类型'] = self.getNodeData(special[0],"TRANTYPECODE") LoopSubAccountSpecialDf.loc[LoopSubAccountSpecial, '发生日期'] = self.getNodeData(special[0],"TRANDATE") LoopSubAccountSpecialDf.loc[LoopSubAccountSpecial, '变更月数'] = self.getNodeData(special[0],"TRANMONTH") LoopSubAccountSpecialDf.loc[LoopSubAccountSpecial, '发生金额'] = self.getNodeData(special[0],"TRANAMT") LoopSubAccountSpecialDf.loc[LoopSubAccountSpecial, '明细记录'] = self.getNodeData(special[0],"DETRECORD") # 循环贷账户 def parseLoopLoan(self,docXml): loopCredit = docXml.documentElement.getElementsByTagName("LOOPCREDITACCOUNTBOLS") #基本信息 # base = loop.getElementsByTagName("CREDITACCTINFOBO"); if len(loopCredit)>0: loop = docXml.documentElement.getElementsByTagName("LOOPCREDITACCOUNTBOLS")[0] base = loop.getElementsByTagName("CREDITACCTINFOBO"); LoopLoanBaseDf.loc[LoopLoanBase, '管理机构'] = self.getNodeData(base[0],"MANAGEORGTYPECODE") LoopLoanBaseDf.loc[LoopLoanBase, '账户标识'] = self.getNodeData(base[0],"ACCTCODE") LoopLoanBaseDf.loc[LoopLoanBase, '开立日期'] = self.getNodeData(base[0],"OPENDATE") LoopLoanBaseDf.loc[LoopLoanBase, '到期日期'] = self.getNodeData(base[0],"DUEDATE") LoopLoanBaseDf.loc[LoopLoanBase, '账户授信额度'] = self.getNodeData(base[0],"ACCTCREDLINE") LoopLoanBaseDf.loc[LoopLoanBase, '账户币种'] = self.getNodeData(base[0],"MONEYTYPECODE") LoopLoanBaseDf.loc[LoopLoanBase, '业务种类'] = self.getNodeData(base[0],"LOANTYPECODE") LoopLoanBaseDf.loc[LoopLoanBase, '担保方式'] = self.getNodeData(base[0],"GUARMODECODE") LoopLoanBaseDf.loc[LoopLoanBase, '还款期数'] = self.getNodeData(base[0],"REPAYPRD") LoopLoanBaseDf.loc[LoopLoanBase, '还款频率'] = self.getNodeData(base[0],"REPAYFREQCYCODE") LoopLoanBaseDf.loc[LoopLoanBase, '还款方式'] = self.getNodeData(base[0],"REPAYCODE") LoopLoanBaseDf.loc[LoopLoanBase, '共同借款标志'] = self.getNodeData(base[0],"COMMBORROWERMAKERCODE") #最近一次月度表现信息 LastMonth = loop.getElementsByTagName("LATEMONTHLYPERFORMANCEBO") # if len(LastMonth)>0: LoopLoanLastMonthDf.loc[LoopLoanLastMonth, '账户状态'] = self.getNodeData(LastMonth[0],"ACCTSTATUCODE") LoopLoanLastMonthDf.loc[LoopLoanLastMonth, '五级分类'] = self.getNodeData(LastMonth[0],"FIVECATECODE") LoopLoanLastMonthDf.loc[LoopLoanLastMonth, '余额'] = self.getNodeData(LastMonth[0],"BUSIBAL") LoopLoanLastMonthDf.loc[LoopLoanLastMonth, '剩余还款期数'] = self.getNodeData(LastMonth[0],"REMREPPRD") LoopLoanLastMonthDf.loc[LoopLoanLastMonth, '结算/应还款日'] = self.getNodeData(LastMonth[0],"SETTDATE") LoopLoanLastMonthDf.loc[LoopLoanLastMonth, '本月应还款'] = self.getNodeData(LastMonth[0],"CURRPYAMT") LoopLoanLastMonthDf.loc[LoopLoanLastMonth, '本月实还款'] = self.getNodeData(LastMonth[0],"ACTRPYAMT") LoopLoanLastMonthDf.loc[LoopLoanLastMonth, '最近一次还款日期'] = self.getNodeData(LastMonth[0],"LATRPYDATE") LoopLoanLastMonthDf.loc[LoopLoanLastMonth, '当前逾期期数'] = self.getNodeData(LastMonth[0],"OVERDPRD") LoopLoanLastMonthDf.loc[LoopLoanLastMonth, '当前逾期总额'] = self.getNodeData(LastMonth[0],"TOTOVERD") LoopLoanLastMonthDf.loc[LoopLoanLastMonth, '逾期 31—60 天未还本金'] = self.getNodeData(LastMonth[0],"OVERD3160PRINC") LoopLoanLastMonthDf.loc[LoopLoanLastMonth, '逾期 61-90 天未还本金'] = self.getNodeData(LastMonth[0],"OVERD6190PRINC") LoopLoanLastMonthDf.loc[LoopLoanLastMonth, '逾期 91-180 天未还本金'] = self.getNodeData(LastMonth[0],"OVERD91180PRINC") LoopLoanLastMonthDf.loc[LoopLoanLastMonth, '逾期 180 天以上未还本金'] = self.getNodeData(LastMonth[0],"OVERDPRINCOVE180") #最新表现信息 latest = loop.getElementsByTagName("NEWPERFORMANCEBO"); # if len(latest)>0: LoopLoanLatestDf.loc[LoopLoanLatest, '余额'] = self.getNodeData(latest[0],"BALANCE") LoopLoanLatestDf.loc[LoopLoanLatest, '五级分类'] = self.getNodeData(latest[0],"FIVECATECODE") LoopLoanLatestDf.loc[LoopLoanLatest, '最近一次还款日期'] = self.getNodeData(latest[0],"REPAYDATE") LoopLoanLatestDf.loc[LoopLoanLatest, '最近一次还款金额'] = self.getNodeData(latest[0],"REPAYAMT") LoopLoanLatestDf.loc[LoopLoanLatest, '当前还款状态'] = self.getNodeData(latest[0],"RPYSTATUSCODE") LoopLoanLatestDf.loc[LoopLoanLatest, '信息报告日期'] = self.getNodeData(latest[0],"REPORTDATEINFO") LoopLoanLatestDf.loc[LoopLoanLatest, '账户状态'] = self.getNodeData(latest[0],"ACCTSTATUSCODE") LoopLoanLatestDf.loc[LoopLoanLatest, '账户关闭日期'] = self.getNodeData(latest[0],"SETTLEDATE") #最近 5 年内的历史表现信息 fiveYear = loop.getElementsByTagName("FIVEYEARPERFORMANCESG"); fiveYearHis = fiveYear.getElementsByTagName("FIVEYEARHISRPYINFOSG") # if len(fiveYear)>0: LoopLoan5YearDf.loc[LoopLoan5Year, '起始年月'] = self.getNodeData(fiveYear[0],"STARTYEARMONTH") LoopLoan5YearDf.loc[LoopLoan5Year, '截止年月'] = self.getNodeData(fiveYear[0],"ENDYEARMONTH") if len(fiveYearHis)>0: LoopLoan5YearDf.loc[LoopLoan5Year, '月份'] = self.getNodeData(fiveYearHis[0], "OVERDMON") LoopLoan5YearDf.loc[LoopLoan5Year, '还款状态'] = self.getNodeData(fiveYearHis[0],"OVERDSTATUSCODE") LoopLoan5YearDf.loc[LoopLoan5Year, '逾期(透支)总额'] = self.getNodeData(fiveYearHis[0],"TOTACCTBAL") #特殊交易信息 special = loop.getElementsByTagName("SPECIALTRADEBASEINFOSG"); # if len(special)>0: LoopLoanSpecialDf.loc[LoopLoanSpecial, '特殊交易类型'] = self.getNodeData(special[0],"TRANTYPECODE") LoopLoanSpecialDf.loc[LoopLoanSpecial, '发生日期'] = self.getNodeData(special[0],"TRANDATE") LoopLoanSpecialDf.loc[LoopLoanSpecial, '变更月数'] = self.getNodeData(special[0],"TRANMONTH") LoopLoanSpecialDf.loc[LoopLoanSpecial, '发生金额'] = self.getNodeData(special[0],"TRANAMT") LoopLoanSpecialDf.loc[LoopLoanSpecial, '明细记录'] = self.getNodeData(special[0],"DETRECORD") # 贷记卡账户 def parseCreditCard(self,docXml): creditCard = docXml.documentElement.getElementsByTagName("CREDITCARDACCOUNTBOLS") #基本信息 # base = credit.getElementsByTagName("CREDITACCTINFOBO"); if len(creditCard)>0: credit = docXml.documentElement.getElementsByTagName("CREDITCARDACCOUNTBOLS")[0] base = credit.getElementsByTagName("CREDITACCTINFOBO"); # LoopLoanBaseDf.loc[LoopLoanBase, '发卡机构'] = self.getNodeData(base[0],"MANAGEORGTYPECODE") creditCardBaseDf.loc[creditCardBase, '账户标识'] = self.getNodeData(base[0],"ACCTCODE") creditCardBaseDf.loc[creditCardBase, '开立日期'] = self.getNodeData(base[0],"OPENDATE") creditCardBaseDf.loc[creditCardBase, '账户授信额度'] = self.getNodeData(base[0],"ACCTCREDLINE") creditCardBaseDf.loc[creditCardBase, '共享授信额度'] = self.getNodeData(base[0],"ORGCREDLINE") creditCardBaseDf.loc[creditCardBase, '账户币种'] = self.getNodeData(base[0],"MONEYTYPECODE") creditCardBaseDf.loc[creditCardBase, '业务种类'] = self.getNodeData(base[0],"LOANTYPECODE") creditCardBaseDf.loc[creditCardBase, '担保方式'] = self.getNodeData(base[0],"GUARMODECODE") #最近一次月度表现信息 LastMonth = credit.getElementsByTagName("LATEMONTHLYPERFORMANCEBO") # if len(LastMonth)>0: creditCardLastMonthDf.loc[creditCardLastMonth, '账户状态'] = self.getNodeData(LastMonth[0],"ACCTSTATUCODE") # creditCardLastMonthDf.loc[creditCardLastMonth, '五级分类'] = self.getNodeData(LastMonth[0],"FIVECATECODE") creditCardLastMonthDf.loc[creditCardLastMonth, '余额'] = self.getNodeData(LastMonth[0],"BUSIBAL") # creditCardLastMonthDf.loc[creditCardLastMonth, '剩余还款期数'] = self.getNodeData(LastMonth[0],"REMREPPRD") # creditCardLastMonthDf.loc[creditCardLastMonth, '剩余分期期数'] = self.getNodeData(LastMonth[0],"REMREPPRD") creditCardLastMonthDf.loc[creditCardLastMonth, '本月应还款'] = self.getNodeData(LastMonth[0],"CURRPYAMT") creditCardLastMonthDf.loc[creditCardLastMonth, '本月实还款'] = self.getNodeData(LastMonth[0],"ACTRPYAMT") creditCardLastMonthDf.loc[creditCardLastMonth, '最近一次还款日期'] = self.getNodeData(LastMonth[0],"LATRPYDATE") creditCardLastMonthDf.loc[creditCardLastMonth, '已用额度'] = self.getNodeData(LastMonth[0],"ACCTBAL") creditCardLastMonthDf.loc[creditCardLastMonth, '未出单的大额专项分期余额'] = self.getNodeData(LastMonth[0],"INSTBAL") creditCardLastMonthDf.loc[creditCardLastMonth, '当前逾期期数'] = self.getNodeData(LastMonth[0],"OVERDPRD") creditCardLastMonthDf.loc[creditCardLastMonth, '当前逾期总额'] = self.getNodeData(LastMonth[0],"TOTOVERD") creditCardLastMonthDf.loc[creditCardLastMonth, '最近6个月平均使用额度'] = self.getNodeData(LastMonth[0],"AVGUSEAMOUNT") creditCardLastMonthDf.loc[creditCardLastMonth, '最大使用额度'] = self.getNodeData(LastMonth[0],"MAXUSEAMOUNT") # creditCardLastMonthDf.loc[creditCardLastMonth, '逾期 91-180 天未还本金'] = self.getNodeData(LastMonth[0],"OVERD91180PRINC") # creditCardLastMonthDf.loc[creditCardLastMonth, '逾期 180 天以上未还本金'] = self.getNodeData(LastMonth[0],"OVERDPRINCOVE180") #最新表现信息 latest = credit.getElementsByTagName("NEWPERFORMANCEBO"); # if len(latest)>0: creditCardLatestDf.loc[creditCardLatest, '余额'] = self.getNodeData(latest[0],"BALANCE") creditCardLatestDf.loc[creditCardLatest, '最近一次还款日期'] = self.getNodeData(latest[0],"REPAYDATE") creditCardLatestDf.loc[creditCardLatest, '最近一次还款金额'] = self.getNodeData(latest[0],"REPAYAMT") creditCardLatestDf.loc[creditCardLatest, '当前还款状态'] = self.getNodeData(latest[0],"RPYSTATUSCODE") # creditCardLatestDf.loc[creditCardLatest, '信息报告日期'] = self.getNodeData(latest[0],"REPORTDATEINFO") creditCardLatestDf.loc[creditCardLatest, '账户状态'] = self.getNodeData(latest[0],"ACCTSTATUSCODE") creditCardLatestDf.loc[creditCardLatest, '账户关闭日期'] = self.getNodeData(latest[0],"SETTLEDATE") #yuan 3.12 新增加大额专项 #最近 5 年内的历史表现信息 fiveYear = credit.getElementsByTagName("FIVEYEARPERFORMANCESG"); fiveYearHis = fiveYear.getElementsByTagName("FIVEYEARHISRPYINFOSG") # if len(fiveYear)>0: creditCard5YearDf.loc[creditCard5Year, '起始年月'] = self.getNodeData(fiveYear[0],"STARTYEARMONTH") creditCard5YearDf.loc[creditCard5Year, '截止年月'] = self.getNodeData(fiveYear[0],"ENDYEARMONTH") if len(fiveYearHis)>0: creditCard5YearDf.loc[creditCard5Year, '月份'] = self.getNodeData(fiveYearHis[0], "OVERDMON") creditCard5YearDf.loc[creditCard5Year, '还款状态'] = self.getNodeData(fiveYearHis[0],"OVERDSTATUSCODE") creditCard5YearDf.loc[creditCard5Year, '逾期(透支)总额'] = self.getNodeData(fiveYearHis[0],"TOTACCTBAL") #贷记卡账户特殊交易说明 special = credit.getElementsByTagName("SPECIALEVENTBASEINFOSG"); # if len(special)>0: creditCardSpecialDf.loc[creditCardSpecial, '特殊事件类型'] = self.getNodeData(special[0],"SPECIALEVENTTYPECODE") creditCardSpecialDf.loc[creditCardSpecial, '特殊事件发生月份'] = self.getNodeData(special[0],"SPECIALEVENTMON") #贷记卡账户标注及声明信息 specialMent = credit.getElementsByTagName("SPECIALTRADEBASEINFOSG"); # if len(special)>0: creditCardSpecialMentDf.loc[creditCardSpecialMent, '特殊交易类型'] = self.getNodeData(specialMent[0],"TRANTYPECODE") creditCardSpecialMentDf.loc[creditCardSpecialMent, '发生日期'] = self.getNodeData(specialMent[0],"TRANDATE") creditCardSpecialMentDf.loc[creditCardSpecialMent, '变更月数'] = self.getNodeData(specialMent[0],"TRANMONTH") creditCardSpecialMentDf.loc[creditCardSpecialMent, '发生金额'] = self.getNodeData(specialMent[0],"TRANAMT") creditCardSpecialMentDf.loc[creditCardSpecialMent, '明细记录'] = self.getNodeData(specialMent[0],"DETRECORD") # 准贷记卡账户 def parseQuasiquasiCreditCard(self,docXml): quasiCredit = docXml.documentElement.getElementsByTagName("PASSquasiCreditCardACCOUNTBOLS") #基本信息 # base = quasi.getElementsByTagName("CREDITACCTINFOBO"); if len(quasiCredit)>0: quasi = docXml.documentElement.getElementsByTagName("PASSquasiCreditCardACCOUNTBOLS")[0] base = quasi.getElementsByTagName("CREDITACCTINFOBO"); quasiCreditCardBaseDf.loc[quasiCreditCardBase, '账户标识'] = self.getNodeData(base[0],"ACCTCODE") quasiCreditCardBaseDf.loc[quasiCreditCardBase, '开立日期'] = self.getNodeData(base[0],"OPENDATE") quasiCreditCardBaseDf.loc[quasiCreditCardBase, '账户授信额度'] = self.getNodeData(base[0],"ACCTCREDLINE") quasiCreditCardBaseDf.loc[quasiCreditCardBase, '共享授信额度'] = self.getNodeData(base[0],"ORGCREDLINE") quasiCreditCardBaseDf.loc[quasiCreditCardBase, '账户币种'] = self.getNodeData(base[0],"MONEYTYPECODE") quasiCreditCardBaseDf.loc[quasiCreditCardBase, '担保方式'] = self.getNodeData(base[0],"GUARMODECODE") #最近一次月度表现信息 LastMonth = quasi.getElementsByTagName("LATEMONTHLYPERFORMANCEBO") # if len(LastMonth)>0: quasiCreditCardLastMonthDf.loc[quasiCreditCardLastMonth, '账户状态'] = self.getNodeData(LastMonth[0],"ACCTSTATUCODE") quasiCreditCardLastMonthDf.loc[quasiCreditCardLastMonth, '余额'] = self.getNodeData(LastMonth[0],"BUSIBAL") # quasiCreditCardLastMonthDf.loc[quasiCreditCardLastMonth, '透支余额'] = self.getNodeData(LastMonth[0],"REMREPPRD") quasiCreditCardLastMonthDf.loc[quasiCreditCardLastMonth, '最大透支余额'] = self.getNodeData(LastMonth[0],"MAXOVERDRAFTBAL") quasiCreditCardLastMonthDf.loc[quasiCreditCardLastMonth, '本月应还款'] = self.getNodeData(LastMonth[0],"CURRPYAMT") quasiCreditCardLastMonthDf.loc[quasiCreditCardLastMonth, '本月实还款'] = self.getNodeData(LastMonth[0],"ACTRPYAMT") quasiCreditCardLastMonthDf.loc[quasiCreditCardLastMonth, '最近一次还款日期'] = self.getNodeData(LastMonth[0],"LATRPYDATE") quasiCreditCardLastMonthDf.loc[quasiCreditCardLastMonth, '已用额度'] = self.getNodeData(LastMonth[0],"ACCTBAL") quasiCreditCardLastMonthDf.loc[quasiCreditCardLastMonth, '剩余分期期数'] = self.getNodeData(LastMonth[0],"REMREPPRD") quasiCreditCardLastMonthDf.loc[quasiCreditCardLastMonth, '最近 6 个月 平均透支余额'] = self.getNodeData(LastMonth[0],"LATSIXMNAVGOVDFTBAL") quasiCreditCardLastMonthDf.loc[quasiCreditCardLastMonth, '透支 180 天以上未付余额'] = self.getNodeData(LastMonth[0],"OVERDRAWBAOVE180") #最新表现信息 latest = quasi.getElementsByTagName("NEWPERFORMANCEBO"); # if len(latest)>0: quasiCreditCardLatestDf.loc[quasiCreditCardLatest, '余额'] = self.getNodeData(latest[0],"BALANCE") quasiCreditCardLatestDf.loc[quasiCreditCardLatest, '最近一次还款日期'] = self.getNodeData(latest[0],"REPAYDATE") quasiCreditCardLatestDf.loc[quasiCreditCardLatest, '最近一次还款金额'] = self.getNodeData(latest[0],"REPAYAMT") quasiCreditCardLatestDf.loc[quasiCreditCardLatest, '当前还款状态'] = self.getNodeData(latest[0],"RPYSTATUSCODE") quasiCreditCardLatestDf.loc[quasiCreditCardLatest, '信息报告日期'] = self.getNodeData(latest[0],"REPORTDATEINFO") quasiCreditCardLatestDf.loc[quasiCreditCardLatest, '账户状态'] = self.getNodeData(latest[0],"ACCTSTATUSCODE") quasiCreditCardLatestDf.loc[quasiCreditCardLatest, '账户关闭日期'] = self.getNodeData(latest[0],"SETTLEDATE") #最近 5 年内的历史表现信息 fiveYear = quasi.getElementsByTagName("FIVEYEARPERFORMANCESG"); fiveYearHis = fiveYear.getElementsByTagName("FIVEYEARHISRPYINFOSG") # if len(fiveYear)>0: quasiCreditCard5YearDf.loc[quasiCreditCard5Year, '起始年月'] = self.getNodeData(fiveYear[0],"STARTYEARMONTH") quasiCreditCard5YearDf.loc[quasiCreditCard5Year, '截止年月'] = self.getNodeData(fiveYear[0],"ENDYEARMONTH") if len(fiveYearHis)>0: quasiCreditCard5YearDf.loc[quasiCreditCard5Year, '月份'] = self.getNodeData(fiveYearHis[0], "OVERDMON") quasiCreditCard5YearDf.loc[quasiCreditCard5Year, '还款状态'] = self.getNodeData(fiveYearHis[0],"OVERDSTATUSCODE") quasiCreditCard5YearDf.loc[quasiCreditCard5Year, '逾期(透支)总额'] = self.getNodeData(fiveYearHis[0],"TOTACCTBAL") #特殊交易信息 special = quasi.getElementsByTagName("SPECIALTRADEBASEINFOSG"); # if len(special)>0: quasiCreditCardSpecialDf.loc[quasiCreditCardSpecial, '特殊交易类型'] = self.getNodeData(special[0],"TRANTYPECODE") quasiCreditCardSpecialDf.loc[quasiCreditCardSpecial, '发生日期'] = self.getNodeData(special[0],"TRANDATE") quasiCreditCardSpecialDf.loc[quasiCreditCardSpecial, '变更月数'] = self.getNodeData(special[0],"TRANMONTH") quasiCreditCardSpecialDf.loc[quasiCreditCardSpecial, '发生金额'] = self.getNodeData(special[0],"TRANAMT") quasiCreditCardSpecialDf.loc[quasiCreditCardSpecial, '明细记录'] = self.getNodeData(special[0],"DETRECORD") # 相关还款责任信息 def parseRelevantRepaymentLiability(self,docXml): about = docXml.documentElement.getElementsByTagName("ABOUTREPAYDUTYBASEINFOSG") if len(about)>0: relevantRepaymentLiabilityDf.loc[relevantRepaymentLiability, '管理机构'] = self.getNodeData(about[0],"MAINBUSIORGNAME") relevantRepaymentLiabilityDf.loc[relevantRepaymentLiability, '业务种类'] = self.getNodeData(about[0],"BUSILINESCODE") relevantRepaymentLiabilityDf.loc[relevantRepaymentLiability, '开立日期'] = self.getNodeData(about[0],"MAINBUSIOPENDATE") relevantRepaymentLiabilityDf.loc[relevantRepaymentLiability, '到期日期'] = self.getNodeData(about[0],"MAINBUSIDUEDATE") relevantRepaymentLiabilityDf.loc[relevantRepaymentLiability, '责任人类型'] = self.getNodeData(about[0],"ARLPTYPECODE") relevantRepaymentLiabilityDf.loc[relevantRepaymentLiability, '还款责任金额'] = self.getNodeData(about[0],"RPYRESAMT") relevantRepaymentLiabilityDf.loc[relevantRepaymentLiability, '币种'] = self.getNodeData(about[0],"MONEYTYPECODE") relevantRepaymentLiabilityDf.loc[relevantRepaymentLiability, '保证合同编号'] = self.getNodeData(about[0],"GUARCONNUM") relevantRepaymentLiabilityDf.loc[relevantRepaymentLiability, '余额'] = self.getNodeData(about[0],"MAINBUSIBAL") relevantRepaymentLiabilityDf.loc[relevantRepaymentLiability, '五级分类'] = self.getNodeData(about[0],"FIVECATECODE") relevantRepaymentLiabilityDf.loc[relevantRepaymentLiability, '还款状态'] = self.getNodeData(about[0],"MAINRPYSTATUSCODE") relevantRepaymentLiabilityDf.loc[relevantRepaymentLiability, '逾期月数'] = self.getNodeData(about[0],"BUSIMONTH") relevantRepaymentLiabilityDf.loc[relevantRepaymentLiability, '账户类型'] = self.getNodeData(about[0],"ACCTYPECODE") # 授信协议信息 def parseCreditAgreement(self,docXml): cont = docXml.documentElement.getElementsByTagName("CONTRACTBASEINFOSG") if len(cont)>0: creditAgreementDf.loc[creditAgreement, '管理机构'] = self.getNodeData(cont[0],"MANAGEORGCODE") creditAgreementDf.loc[creditAgreement, '授信协议标识'] = self.getNodeData(cont[0],"CONTXTCODE") creditAgreementDf.loc[creditAgreement, '生效日期'] = self.getNodeData(cont[0],"CONEFFDATE") creditAgreementDf.loc[creditAgreement, '到期日期'] = self.getNodeData(cont[0],"CONEXPDATE") creditAgreementDf.loc[creditAgreement, '授信额度用途'] = self.getNodeData(cont[0],"LIMITPURPOSECODE") creditAgreementDf.loc[creditAgreement, '授信额度'] = self.getNodeData(cont[0],"CCAMOUNT") creditAgreementDf.loc[creditAgreement, '授信限额'] = self.getNodeData(cont[0],"CREDITLIMIT") creditAgreementDf.loc[creditAgreement, '授信限额编号'] = self.getNodeData(cont[0],"CREDITLIMITNUM") creditAgreementDf.loc[creditAgreement, '已用额度'] = self.getNodeData(cont[0],"USELIMIT") creditAgreementDf.loc[creditAgreement, '币种'] = self.getNodeData(cont[0],"MONEYTYPECODE") # /三 信贷交易信息明细 #后付费记录 def parsePostPaidRecord(self,docXml): post = docXml.documentElement.getElementsByTagName("AFTERPAYMONEYINFOSG") if len(post)>0: postPaidRecordDf.loc[postPaidRecord, '机构名称'] = self.getNodeData(post[0],"ORGANIZATIONNAME") postPaidRecordDf.loc[postPaidRecord, '业务类型'] = self.getNodeData(post[0],"PAYBUSITYPECODE") postPaidRecordDf.loc[postPaidRecord, '业务开通日期'] = self.getNodeData(post[0],"BUSIOPENDATE") postPaidRecordDf.loc[postPaidRecord, '当前缴费状态'] = self.getNodeData(post[0],"PAYMENTSTATUSCODE") postPaidRecordDf.loc[postPaidRecord, '当前欠费金额'] = self.getNodeData(post[0],"OWEAMOUNT") postPaidRecordDf.loc[postPaidRecord, '记账年月'] = self.getNodeData(post[0],"ACCOUNTYEARMONTH") #欠税记录 def parseTaxArrears(self,docXml,reportTime): tax = docXml.documentElement.getElementsByTagName("OWINGTAXES") if len(tax)>0: taxArrearsDf.loc[taxArrearsIndex, '主管税务机关'] = self.getNodeData(tax[0],"TAXAUTHORITY") taxArrearsDf.loc[taxArrearsIndex, '欠税总额'] = self.getNodeData(tax[0],"OWINGTAXESTOTAL") taxArrearsDf.loc[taxArrearsIndex, '欠税统计日期'] = self.getNodeData(tax[0],"OWINGTAXESDATE") # 民事判决记录 def parseCivilJudgment(self,docXml): civil = docXml.documentElement.getElementsByTagName("CIVIL") # for item in civil: # self.saveNode(item) if len(civil)>0: civilJudgmentDf.loc[civilJudgmentIndex, '立案法院'] = self.getNodeData(civil[0],"COURT") civilJudgmentDf.loc[civilJudgmentIndex, '案由'] = self.getNodeData(civil[0],"CAUSEOFACTION") civilJudgmentDf.loc[civilJudgmentIndex, '立案日期'] = self.getNodeData(civil[0],"FILINGDATE") civilJudgmentDf.loc[civilJudgmentIndex, '结案方式代码'] = self.getNodeData(civil[0],"CLOSEMCODE") civilJudgmentDf.loc[civilJudgmentIndex, '结案方式描述'] = self.getNodeData(civil[0],"CLOSEMDESC") civilJudgmentDf.loc[civilJudgmentIndex, '判决/调解结果'] = self.getNodeData(civil[0],"JUDRESULT") civilJudgmentDf.loc[civilJudgmentIndex, '判决/调解生效日期'] = self.getNodeData(civil[0],"JUDDATE") civilJudgmentDf.loc[civilJudgmentIndex, '诉讼标的'] = self.getNodeData(civil[0],"OBJECTOFACTION") civilJudgmentDf.loc[civilJudgmentIndex, '诉讼标的金额'] = self.getNodeData(civil[0],"OBJOFACTMONEY") #还有近24个月的属性值 由衍生字段添加 # 强制执行记录 def parseEnforce(self,docXml): enforce = docXml.documentElement.getElementsByTagName("ENFORCEMENT") # for item in civil: # self.saveNode(item) if len(enforce)>0: enforceDf.loc[enforceIndex, '执行法院'] = self.getNodeData(enforce[0],"EXECOURT") enforceDf.loc[enforceIndex, '执行案由'] = self.getNodeData(enforce[0],"EXECAUOFACTION") enforceDf.loc[enforceIndex, '立案日期'] = self.getNodeData(enforce[0],"FILINGDATE") enforceDf.loc[enforceIndex, '结案方式代码'] = self.getNodeData(enforce[0],"CLOSEMCODE") # enforceDf.loc[enforceIndex, '结案方式描述'] = self.getNodeData(enforce[0],"CLOSEMDESC") enforceDf.loc[enforceIndex, '案件状态'] = self.getNodeData(enforce[0],"CASESTATUS") enforceDf.loc[enforceIndex, '结案日期'] = self.getNodeData(enforce[0],"CLOSINGDATE") enforceDf.loc[enforceIndex, '申请执行标的'] = self.getNodeData(enforce[0],"ASKEXESUB") enforceDf.loc[enforceIndex, '申请执行标的金额'] = self.getNodeData(enforce[0],"ASKEXEMONEY") enforceDf.loc[enforceIndex, '已执行标的'] = self.getNodeData(enforce[0],"EXEDOBJ") enforceDf.loc[enforceIndex, '已执行标的金额'] = self.getNodeData(enforce[0],"EXEDOBJMONEY") #行政处罚记录 def parseAdministrativePunishment(self,docXml,reportTime): punish = docXml.documentElement.getElementsByTagName("PENALTY") # for item in civil: # self.saveNode(item) if len(punish)>0: administrativePunishmentDf.loc[administrativePunishmentIndex, '处罚机构'] = self.getNodeData(punish[0],"PUNISHORG") administrativePunishmentDf.loc[administrativePunishmentIndex, '处罚内容'] = self.getNodeData(punish[0],"PUNISHCON") administrativePunishmentDf.loc[administrativePunishmentIndex, '处罚金额'] = self.getNodeData(punish[0],"PUNISHMONEY") administrativePunishmentDf.loc[administrativePunishmentIndex, '处罚生效日期'] = self.getNodeData(punish[0],"PUNSTARTDATE") administrativePunishmentDf.loc[administrativePunishmentIndex, '处罚截止日期'] = self.getNodeData(punish[0],"PUNENDDATE") administrativePunishmentDf.loc[administrativePunishmentIndex, '行政复议结果'] = self.getNodeData(punish[0],"RECRESULT") # 住房公积金参缴记录 def parseHousingProvidentFundParticipation(self,docXml): houseFund = docXml.documentElement.getElementsByTagName("HOUSINGFUND") # for item in civil: # self.saveNode(item) if len(houseFund)>0: housingProvidentFundParticipationIndexDf.loc[housingProvidentFundParticipationIndex, '参缴地代码'] = self.getNodeData(houseFund[0],"ADDRESSCODE") # housingProvidentFundParticipationIndexDf.loc[housingProvidentFundParticipationIndex, '参缴地描述'] = self.getNodeData(houseFund[0],"ADDRESSDESC") housingProvidentFundParticipationIndexDf.loc[housingProvidentFundParticipationIndex, '参缴日期'] = self.getNodeData(houseFund[0],"PAYDATE") housingProvidentFundParticipationIndexDf.loc[housingProvidentFundParticipationIndex, '缴费状态代码'] = self.getNodeData(houseFund[0],"STATUSCODE") # housingProvidentFundParticipationIndexDf.loc[housingProvidentFundParticipationIndex, '缴费状态描述'] = self.getNodeData(houseFund[0],"STATUSDESC") housingProvidentFundParticipationIndexDf.loc[housingProvidentFundParticipationIndex, '初缴月份'] = self.getNodeData(houseFund[0],"BEGINMONTH") housingProvidentFundParticipationIndexDf.loc[housingProvidentFundParticipationIndex, '缴至月份'] = self.getNodeData(houseFund[0],"ENDMONTH") housingProvidentFundParticipationIndexDf.loc[housingProvidentFundParticipationIndex, '单位缴存比例'] = self.getNodeData(houseFund[0],"COMPROPORTION") housingProvidentFundParticipationIndexDf.loc[housingProvidentFundParticipationIndex, '个人缴存比例'] = self.getNodeData(houseFund[0],"PEPROPORTION") housingProvidentFundParticipationIndexDf.loc[housingProvidentFundParticipationIndex, '月缴存额'] = self.getNodeData(houseFund[0],"MONTHMONEY") housingProvidentFundParticipationIndexDf.loc[housingProvidentFundParticipationIndex, '缴费单位'] = self.getNodeData(houseFund[0],"COMPANY") housingProvidentFundParticipationIndexDf.loc[housingProvidentFundParticipationIndex, '信息更新日期'] = self.getNodeData(houseFund[0],"UPDATEDATE") # 低保救助记录 def parseSubsistenceAllowanceAssistance(self,docXml): assistance = docXml.documentElement.getElementsByTagName("ALLOWANC") # for item in civil: # self.saveNode(item) if len(assistance)>0: subsistenceAllowanceAssistanceDf.loc[subsistenceAllowanceAssistanceIndex, '人员类别代码'] = self.getNodeData(assistance[0],"PERTYPECODE") # subsistenceAllowanceAssistanceDf.loc[subsistenceAllowanceAssistanceIndex, '人员类别描述'] = self.getNodeData(assistance[0],"PERTYPEDESC") subsistenceAllowanceAssistanceDf.loc[subsistenceAllowanceAssistanceIndex, '所在地代码'] = self.getNodeData(assistance[0],"ADDRESSCODE") # subsistenceAllowanceAssistanceDf.loc[subsistenceAllowanceAssistanceIndex, '所在地描述'] = self.getNodeData(assistance[0],"ADDRESSDESC") subsistenceAllowanceAssistanceDf.loc[subsistenceAllowanceAssistanceIndex, '工作单位'] = self.getNodeData(assistance[0],"WORKUNIT") subsistenceAllowanceAssistanceDf.loc[subsistenceAllowanceAssistanceIndex, '家庭月收入'] = self.getNodeData(assistance[0],"FAMILYINCOME") subsistenceAllowanceAssistanceDf.loc[subsistenceAllowanceAssistanceIndex, '申请日期'] = self.getNodeData(assistance[0],"APPLYDATE") subsistenceAllowanceAssistanceDf.loc[subsistenceAllowanceAssistanceIndex, '批准日期'] = self.getNodeData(assistance[0],"APPROVEDATE") subsistenceAllowanceAssistanceDf.loc[subsistenceAllowanceAssistanceIndex, '信息更新日期'] = self.getNodeData(assistance[0],"UPDATEDATE") # 执业资格记录 def parsePracticeQualification(self,docXml): qualification = docXml.documentElement.getElementsByTagName("PRACTISING") # for item in civil: # self.saveNode(item) if len(qualification)>0: practiceQualificationDf.loc[practiceQualificationIndex, '执业资格名称'] = self.getNodeData(qualification[0],"NAME") practiceQualificationDf.loc[practiceQualificationIndex, '颁发机构'] = self.getNodeData(qualification[0],"ISSUER") practiceQualificationDf.loc[practiceQualificationIndex, '等级代码'] = self.getNodeData(qualification[0],"LEVELCODE") # practiceQualificationDf.loc[practiceQualificationIndex, '等级描述'] = self.getNodeData(qualification[0],"LEVELDESC") practiceQualificationDf.loc[practiceQualificationIndex, '机构所在地代码'] = self.getNodeData(qualification[0],"INSLOCATIONCODE") # practiceQualificationDf.loc[practiceQualificationIndex, '机构所在地描述'] = self.getNodeData(qualification[0],"INSLOCATIONDESC") practiceQualificationDf.loc[practiceQualificationIndex, '获得年月'] = self.getNodeData(qualification[0],"YEARMONTH") practiceQualificationDf.loc[practiceQualificationIndex, '到期年月'] = self.getNodeData(qualification[0],"EXPIREYEMON") practiceQualificationDf.loc[practiceQualificationIndex, '吊销年月'] = self.getNodeData(qualification[0],"REVOKEYEMON") #行政奖励记录 def parseAdministrativeIncentive(self,docXml,reportTime): incentive = docXml.documentElement.getElementsByTagName("OWINGTAXES") # for item in civil: # self.saveNode(item) if len(incentive)>0: administrativeIncentiveDf.loc[administrativeIncentiveIndex, '奖励机构'] = self.getNodeData(incentive[0],"REWARDINS") administrativeIncentiveDf.loc[administrativeIncentiveIndex, '奖励内容'] = self.getNodeData(incentive[0],"REWARDCON") administrativeIncentiveDf.loc[administrativeIncentiveIndex, '生效年月'] = self.getNodeData(incentive[0],"EFFECTIVEMONTH") administrativeIncentiveDf.loc[administrativeIncentiveIndex, '截止年月'] = self.getNodeData(incentive[0],"DEADLINEMONTH") # 查询记录 def parseQueryRecordY(self,docXml): record = docXml.documentElement.getElementsByTagName("QUERYRECORDSG") if len(record)>0: queryRecordDfY.loc[queryRecordIndexY, '查询日期'] = self.getNodeData(record[0],"QUERYDATE") queryRecordDfY.loc[queryRecordIndexY, '查询机构类型代码'] = self.getNodeData(record[0],"QORGTYPECODE") # queryRecordDfY.loc[queryRecordIndexY, '查询机构类型描述'] = self.getNodeData(record[0],"QORGTYPEDESC") queryRecordDfY.loc[queryRecordIndexY, '查询机构'] = self.getNodeData(record[0],"QUERYORG") queryRecordDfY.loc[queryRecordIndexY, '查询原因'] = self.getNodeData(record[0],"QUERYREASONCODE") # queryRecordDfY.loc[queryRecordIndexY, '查询原因描述'] = self.getNodeData(record[0],"QUERYREASONDESC")