109 lines
7.4 KiB
Python
109 lines
7.4 KiB
Python
from app import db
|
|
from flask import current_app as my_app
|
|
from datetime import datetime
|
|
from time import time
|
|
|
|
# from Models.op_sanction_amount_frequency import Op_sanction_amount_frequency
|
|
# from Models.op_rtr_summary_of_active_loans import Op_rtr_summary_of_active_loans
|
|
# from Models.op_snapshot_of_closed_loans import Op_snapshot_of_closed_loans
|
|
from Models.op_enquiry import EnquiryParent,EnquiryChild
|
|
from Models.op_sanction import SanctionParent,SanctionChild
|
|
|
|
|
|
class CibilSummaryDataUpdateService :
|
|
|
|
|
|
def updateActiveOrClosedLoans(dataSet):
|
|
# obj = Op_rtr_summary_of_active_loans(los_id=data['los_id'],ref_no=data['ref_no'],consumer_name=data['consumer_name'],account_type=data['account_type'],reported_and_certified_date=data['reported_and_certified_date'],opened_date=data['opened_date'],sanctioned_amount=data['sanctioned_amount'],current_balance=data['current_balance'],emi_amount=data['emi_amount'],overdue_amount=data['overdue_amount'],repayment_tenure=data['repayment_tenure'],status=data['status'],ownership=data['ownership'],current_dpd=data['current_dpd'],dpd0_6=data['dpd0_6'],dpd7_12=data['dpd7_12'],dpd13_24=data['dpd13_24'],dpd25_36=data['dpd25_36'],is_active=data['is_active'],createdAt=data['createdAt'],updatedAt=data['updatedAt'],createdby=data['createdby'],updatedby=data['updatedby'])
|
|
# db.session.add(dataSet)
|
|
# db.session.add_all(dataSet)
|
|
|
|
db.session.bulk_save_objects(dataSet,return_defaults = True)
|
|
db.session.commit()
|
|
logText = str(len(dataSet)) + ' - Active Closed loans Saved'
|
|
print(logText)
|
|
return str(len(dataSet))
|
|
|
|
|
|
def updateSanctionedSummaryAndOverallOpenedClosedLoans(sanctioned_amt_details,reference_number,los_id,cibil_type,output_type):
|
|
print('updateSanctionedSummaryAndOverallOpenedClosedLoans',len(sanctioned_amt_details))
|
|
parent_inserted_count = 0
|
|
# over_start_time = time()
|
|
if len(sanctioned_amt_details) > 0:
|
|
# over_all_enquiry_data = []
|
|
|
|
for index,sanctioned_amt in enumerate(sanctioned_amt_details):
|
|
# print(index,sanctioned_amt,sanctioned_amt_details[sanctioned_amt])
|
|
# print('*********************************')
|
|
parent = SanctionParent(output_type=output_type,losid=los_id,ref_no=reference_number,facility_type=sanctioned_amt,createdAt=datetime.now().strftime("%Y-%m-%d %H:%M:%S"),updatedAt=datetime.now().strftime("%Y-%m-%d %H:%M:%S"),createdby=1,updatedby=1,total_amt=sanctioned_amt_details[sanctioned_amt]['total_amt'],total_count=sanctioned_amt_details[sanctioned_amt]['total_count'],open_total_amt=sanctioned_amt_details[sanctioned_amt]['open_total_amt'],open_total_count=sanctioned_amt_details[sanctioned_amt]['open_total_count'],closed_total_amt=sanctioned_amt_details[sanctioned_amt]['closed_total_amt'],closed_total_count=sanctioned_amt_details[sanctioned_amt]['closed_total_count'])
|
|
start_time = time()
|
|
db.session.add(parent)
|
|
|
|
|
|
# Child(months_range="bar",amt=10,count=12,is_active=1,parent=parent)
|
|
|
|
db.session.commit()
|
|
# print("--- %s Parent insert time seconds ---" %(time() - start_time))
|
|
if parent.id: parent_inserted_count += 1
|
|
childDataSet = []
|
|
for idx,sanction_child_data in enumerate(sanctioned_amt_details[sanctioned_amt]):
|
|
if sanction_child_data != "total_amt" and sanction_child_data != "total_count" and sanction_child_data != "open_total_amt" and sanction_child_data != "open_total_count" and sanction_child_data != "closed_total_amt" and sanction_child_data != "closed_total_count":
|
|
# print(sanction_child_data,sanctioned_amt_details[sanctioned_amt][sanction_child_data])
|
|
child = SanctionChild(sanction_amt_id=parent.id,months_range=sanction_child_data,amt=sanctioned_amt_details[sanctioned_amt][sanction_child_data]['amt'],count=sanctioned_amt_details[sanctioned_amt][sanction_child_data]['count'],opening_amt=sanctioned_amt_details[sanctioned_amt][sanction_child_data]['openamt'],opening_count=sanctioned_amt_details[sanctioned_amt][sanction_child_data]['opencount'],closing_amt=sanctioned_amt_details[sanctioned_amt][sanction_child_data]['closeamt'],closing_count=sanctioned_amt_details[sanctioned_amt][sanction_child_data]['closecount'],createdAt=datetime.now().strftime("%Y-%m-%d %H:%M:%S"),updatedAt=datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
|
|
childDataSet.append(child)
|
|
# print(childDataSet)
|
|
db.session.bulk_save_objects(childDataSet)
|
|
db.session.commit()
|
|
# print("--- %s Child insert time seconds ---" %(time() - start_time))
|
|
|
|
# print("--- %s overall time ---" %(time() - over_start_time))
|
|
return parent_inserted_count
|
|
|
|
|
|
|
|
def updateEnquirySummaryData(enquiry_details,reference_number,los_id,cibil_type,output_type):
|
|
print('updateEnquirySummaryData', len(enquiry_details))
|
|
parent_inserted_count = 0
|
|
# raise Exception('tata')
|
|
if len(enquiry_details) > 0:
|
|
# over_all_enquiry_data = []
|
|
for index,enquiry_detail in enumerate(enquiry_details):
|
|
# over_all_enquiry_data.append(EnquiryParent(los_id='MWTEST',ref_no='TESTREF',facility_type=enquiry_detail,is_active=1,createdAt=datetime.now().strftime("%Y-%m-%d %H:%M:%S"),updatedAt=datetime.now().strftime("%Y-%m-%d %H:%M:%S"),createdby=1,updatedby=1,total=enquiry_details[enquiry_detail]['total']))
|
|
|
|
# print(index,enquiry_detail,enquiry_details[enquiry_detail])
|
|
# print('*********************************')
|
|
# print(over_all_enquiry_data)
|
|
parent = EnquiryParent(output_type=output_type,losid=los_id,ref_no=reference_number,facility_type=enquiry_detail,is_active=1,createdAt=datetime.now().strftime("%Y-%m-%d %H:%M:%S"),updatedAt=datetime.now().strftime("%Y-%m-%d %H:%M:%S"),createdby=1,updatedby=1,total_amt=enquiry_details[enquiry_detail]['total_amt'],total_count=enquiry_details[enquiry_detail]['total_count'])
|
|
start_time = time()
|
|
db.session.add(parent)
|
|
|
|
|
|
# Child(months_range="bar",amt=10,count=12,is_active=1,parent=parent)
|
|
|
|
db.session.commit()
|
|
# print("--- %s Parent insert time seconds ---" %(time() - start_time))
|
|
if parent.id: parent_inserted_count += 1
|
|
childDataSet = []
|
|
for idx,enquiry_child_data in enumerate(enquiry_details[enquiry_detail]):
|
|
if enquiry_child_data != "total_amt" and enquiry_child_data != "total_count":
|
|
# print(enquiry_child_data,enquiry_details[enquiry_detail][enquiry_child_data])
|
|
child = EnquiryChild(enquiry_amount_id=parent.id,months_range=enquiry_child_data,amt=enquiry_details[enquiry_detail][enquiry_child_data]['amt'],count=enquiry_details[enquiry_detail][enquiry_child_data]['count'],is_active=1,createdAt=datetime.now().strftime("%Y-%m-%d %H:%M:%S"),updatedAt=datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
|
|
childDataSet.append(child)
|
|
|
|
# print(childDataSet)
|
|
db.session.bulk_save_objects(childDataSet)
|
|
db.session.commit()
|
|
# print("--- %s Child insert time seconds ---" %(time() - start_time))
|
|
|
|
return parent_inserted_count
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|