updated config
This commit is contained in:
+1
-1
@@ -24,7 +24,7 @@ class UPIInwardRecord:
|
|||||||
"TXN_TYPE": self.txn_type, # converted to CR before insert
|
"TXN_TYPE": self.txn_type, # converted to CR before insert
|
||||||
"BENEFICIARY_ACCOUNT": self.credit_account,
|
"BENEFICIARY_ACCOUNT": self.credit_account,
|
||||||
"STATUS": self.status,
|
"STATUS": self.status,
|
||||||
"NOTE": self.note,
|
"NARRATION": self.note,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+109
-7
@@ -88,24 +88,24 @@ class Repository:
|
|||||||
logger.info(batch_data)
|
logger.info(batch_data)
|
||||||
|
|
||||||
insert_sql = """
|
insert_sql = """
|
||||||
INSERT INTO pacs_db.upi_inward_api_log (
|
INSERT INTO pacs_db.inward_upi_api_log (
|
||||||
BANKCODE,
|
BANKCODE,
|
||||||
RRN,
|
RRN,
|
||||||
TXN_DATE,
|
TXN_DATE,
|
||||||
TXN_AMT,
|
TXN_AMT,
|
||||||
TXN_TYPE,
|
TXN_TYPE,
|
||||||
CREDIT_ACCOUNT,
|
BENEFICIARY_ACCOUNT,
|
||||||
STATUS,
|
STATUS,
|
||||||
NOTE
|
NARRATION
|
||||||
) VALUES (
|
) VALUES (
|
||||||
:BANKCODE,
|
:BANKCODE,
|
||||||
:RRN,
|
:RRN,
|
||||||
:TXN_DATE,
|
:TXN_DATE,
|
||||||
:TXN_AMT,
|
:TXN_AMT,
|
||||||
:TXN_TYPE,
|
:TXN_TYPE,
|
||||||
:CREDIT_ACCOUNT,
|
:BENEFICIARY_ACCOUNT,
|
||||||
:STATUS,
|
:STATUS,
|
||||||
:NOTE
|
:NARRATION
|
||||||
)
|
)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@@ -144,7 +144,7 @@ class Repository:
|
|||||||
cursor.execute(
|
cursor.execute(
|
||||||
"""
|
"""
|
||||||
SELECT COUNT(*)
|
SELECT COUNT(*)
|
||||||
FROM neft_processed_files
|
FROM upi_processed_files
|
||||||
WHERE filename = :filename
|
WHERE filename = :filename
|
||||||
AND bankcode = :bankcode
|
AND bankcode = :bankcode
|
||||||
""",
|
""",
|
||||||
@@ -173,7 +173,7 @@ class Repository:
|
|||||||
file_data = processed_file.to_dict()
|
file_data = processed_file.to_dict()
|
||||||
|
|
||||||
insert_sql = """
|
insert_sql = """
|
||||||
INSERT INTO neft_processed_files (
|
INSERT INTO upi_processed_files (
|
||||||
filename, bankcode, file_path, transaction_count,
|
filename, bankcode, file_path, transaction_count,
|
||||||
status, error_message, processed_at
|
status, error_message, processed_at
|
||||||
) VALUES (
|
) VALUES (
|
||||||
@@ -198,3 +198,105 @@ class Repository:
|
|||||||
if cursor:
|
if cursor:
|
||||||
cursor.close()
|
cursor.close()
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
def get_processed_files(self, bankcode: Optional[str] = None) -> List[str]:
|
||||||
|
conn = self.connector.get_connection()
|
||||||
|
cursor = None
|
||||||
|
try:
|
||||||
|
cursor = conn.cursor()
|
||||||
|
|
||||||
|
if bankcode:
|
||||||
|
cursor.execute(
|
||||||
|
"""
|
||||||
|
SELECT filename
|
||||||
|
FROM upi_processed_files
|
||||||
|
WHERE bankcode = :bankcode
|
||||||
|
ORDER BY processed_at DESC
|
||||||
|
""",
|
||||||
|
{'bankcode': bankcode}
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
cursor.execute(
|
||||||
|
"""
|
||||||
|
SELECT filename
|
||||||
|
FROM upi_processed_files
|
||||||
|
ORDER BY processed_at DESC
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
|
filenames = [row[0] for row in cursor.fetchall()]
|
||||||
|
return filenames
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Error retrieving processed files: {e}", exc_info=True)
|
||||||
|
return []
|
||||||
|
finally:
|
||||||
|
if cursor:
|
||||||
|
cursor.close()
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
# def call_neft_api_txn_post(self) -> bool:
|
||||||
|
# conn = self.connector.get_connection()
|
||||||
|
# cursor = None
|
||||||
|
# try:
|
||||||
|
# cursor = conn.cursor()
|
||||||
|
# logger.info("Calling neft_api_txn_post procedure to process all inserted transactions...")
|
||||||
|
|
||||||
|
# try:
|
||||||
|
# cursor.callproc('neft_api_txn_post')
|
||||||
|
# except Exception:
|
||||||
|
# cursor.execute("BEGIN neft_api_txn_post; END;")
|
||||||
|
|
||||||
|
# conn.commit()
|
||||||
|
# logger.info("neft_api_txn_post procedure executed successfully")
|
||||||
|
# return True
|
||||||
|
# except Exception as e:
|
||||||
|
# logger.error(f"Error calling neft_api_txn_post procedure: {e}", exc_info=True)
|
||||||
|
# return False
|
||||||
|
# finally:
|
||||||
|
# if cursor:
|
||||||
|
# cursor.close()
|
||||||
|
# conn.close()
|
||||||
|
|
||||||
|
def verify_tables_exist(self):
|
||||||
|
conn = self.connector.get_connection()
|
||||||
|
cursor = None
|
||||||
|
try:
|
||||||
|
cursor = conn.cursor()
|
||||||
|
|
||||||
|
try:
|
||||||
|
cursor.execute("SELECT COUNT(*) FROM inward_upi_api_log WHERE ROWNUM = 1")
|
||||||
|
logger.info("✓ inward_upi_api_log table exists")
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"✗ inward_upi_api_log table not found: {e}")
|
||||||
|
raise SystemExit(
|
||||||
|
"FATAL: inward_upi_api_log table must be created manually before running this application"
|
||||||
|
)
|
||||||
|
|
||||||
|
try:
|
||||||
|
cursor.execute("SELECT COUNT(*) FROM upi_processed_files WHERE ROWNUM = 1")
|
||||||
|
logger.info("✓ upi_processed_files table exists")
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"✗ upi_processed_files table not found: {e}")
|
||||||
|
raise SystemExit(
|
||||||
|
"FATAL: upi_processed_files table must be created manually before running this application"
|
||||||
|
)
|
||||||
|
|
||||||
|
logger.info("Database tables verified successfully")
|
||||||
|
|
||||||
|
except SystemExit:
|
||||||
|
raise
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Error verifying tables: {e}", exc_info=True)
|
||||||
|
raise SystemExit(f"FATAL: Error verifying database tables: {e}")
|
||||||
|
finally:
|
||||||
|
if cursor:
|
||||||
|
cursor.close()
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ class FileMonitor:
|
|||||||
for bank_code in self.config.bank_codes:
|
for bank_code in self.config.bank_codes:
|
||||||
remote_path = f"{self.config.sftp_base_path}/{bank_code}/UPI"
|
remote_path = f"{self.config.sftp_base_path}/{bank_code}/UPI"
|
||||||
|
|
||||||
# ✅ Pattern for UPI files
|
# Pattern for UPI files
|
||||||
files = self.sftp_client.list_files(
|
files = self.sftp_client.list_files(
|
||||||
remote_path,
|
remote_path,
|
||||||
pattern='*_UPI.txt.gz'
|
pattern='*_UPI.txt.gz'
|
||||||
|
|||||||
+3
-3
@@ -176,7 +176,7 @@ class UPIParser:
|
|||||||
by_type[txn_type]["count"] += 1
|
by_type[txn_type]["count"] += 1
|
||||||
by_type[txn_type]["amount"] += amt
|
by_type[txn_type]["amount"] += amt
|
||||||
|
|
||||||
# Convert Decimal → string
|
# Convert Decimal → string
|
||||||
by_status_final = {
|
by_status_final = {
|
||||||
k: {"count": v["count"], "amount": f"{v['amount']:.2f}"}
|
k: {"count": v["count"], "amount": f"{v['amount']:.2f}"}
|
||||||
for k, v in by_status.items()
|
for k, v in by_status.items()
|
||||||
@@ -257,9 +257,9 @@ def print_summary(summary: Dict):
|
|||||||
# -------------------------
|
# -------------------------
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
||||||
file_path = r"C:\Users\2780475\Desktop\Test\TUMLUK_31052026_8C_UPI.txt.gz"
|
file_path = r"C:\Users\2780475\Desktop\upi_file_based\TUMLUK_05062026_8C_UPI.txt"
|
||||||
|
|
||||||
parser = UPISwitchParser(file_path)
|
parser = UPIParser(file_path)
|
||||||
|
|
||||||
transactions, metadata, summary = parser.parse()
|
transactions, metadata, summary = parser.parse()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user