From bb00b9d9d42c10614d7e710a9344255b3bd1279f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AB=98=E6=9C=A8=E8=A6=81?= Date: Tue, 25 Apr 2023 17:08:38 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=E7=B4=8D=E5=85=A5=E5=85=88?= =?UTF-8?q?=E5=87=A6=E6=96=B9=E5=85=83=E3=83=9E=E3=82=B9=E3=82=BF=E6=B4=97?= =?UTF-8?q?=E6=9B=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../create_inst_presc_for_laundering.py | 144 ++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 ecs/jskult-batch-daily/src/batch/laundering/create_inst_presc_for_laundering.py diff --git a/ecs/jskult-batch-daily/src/batch/laundering/create_inst_presc_for_laundering.py b/ecs/jskult-batch-daily/src/batch/laundering/create_inst_presc_for_laundering.py new file mode 100644 index 00000000..c154bcdf --- /dev/null +++ b/ecs/jskult-batch-daily/src/batch/laundering/create_inst_presc_for_laundering.py @@ -0,0 +1,144 @@ +from src.batch.batch_functions import logging_sql +from src.batch.common.batch_context import BatchContext +from src.db.database import Database +from src.error.exceptions import BatchOperationException +from src.logging.get_logger import get_logger +from src.time.elapsed_time import ElapsedTime + +logger = get_logger('納入先処方元マスタ洗替') +batch_context = BatchContext.get_instance() + + +def exec(): + db = Database.get_instance() + try: + db.connect() + logger.debug('納入先処方元マスタの洗替処理開始') + # ult_ident_presc_lauをTruncate + _truncate_ult_ident_presc_lau(db) + # トランザクション開始 + db.begin() + # ult_ident_presc から、ult_ident_presc_lauへInsert + _insert_into_ult_ident_presc_lau_from_ult_ident_presc(db) + # v_inst_merge_tから、ult_ident_presc_lauをUpdate + _update_ult_ident_presc_lau_from_v_inst_merge_t(db) + # inst_merge_tから、ult_ident_presc_lauをUpdate + _update_ult_ident_presc_lau_from_inst_merge_t(db) + # コミット + db.commit() + logger.debug('納入先処方元マスタの洗替処理製造終了') + except Exception as e: + db.rollback() + raise BatchOperationException(e) + finally: + db.disconnect() + + +def _truncate_ult_ident_presc_lau(db: Database): + try: + db.execute("TRUNCATE TABLE ult_ident_presc_lau") + except Exception as e: + logger.debug("納入先処方元マスタ(洗替後)の全件削除に失敗") + raise e + + logger.debug("納入先処方元マスタ(洗替後)の全件削除に成功") + return + + +def _insert_into_ult_ident_presc_lau_from_ult_ident_presc(db: Database): + try: + elapsed_time = ElapsedTime() + sql = "INSERT INTO ult_ident_presc_lau SELECT *, null FROM ult_ident_presc" + res = db.execute(sql) + logging_sql(logger, sql) + logger.info(f'処方元マスタから処方元マスタ(洗替後)に全件コピーに成功, {res.rowcount} 行更新 ({elapsed_time.of})') + except Exception as e: + logger.debug("処方元マスタから処方元マスタ(洗替後)に全件コピーに失敗") + raise e + + return + + +def _update_ult_ident_presc_lau_from_v_inst_merge_t(db: Database): + # v_inst_merge_tの元となるvop_hco_merge_vはデータが作られないため、この洗い替え処理は基本空振りする + try: + select_result = db.execute_select( + """ + SELECT + COUNT(v_inst_cd) AS row_count + FROM + internal05.v_inst_merge_t + """ + ) + except Exception as e: + logger.debug("V施設統合マスタ(洗替処理一時テーブル)からの移行対象施設件数取得失敗") + raise e + count = [row for row in select_result][0]['row_count'] + if count == 0: + logger.info('V施設統合マスタ(洗替処理一時テーブル)からの移行対象施設が存在しません') + return + + logger.info(f'V施設統合マスタ(洗替処理一時テーブル)からの移行対象施設件数取得成功 移行対象施設件数={count}') + + try: + elapsed_time = ElapsedTime() + update_sql = """ + UPDATE + src05.ult_ident_presc_lau uipl, internal05.v_inst_merge_t vimt + SET + uipl.ult_ident_cd = vimt.v_inst_cd_merge, + uipl.lau_ope_dt = SYSDATE() + WHERE + uipl.ult_ident_cd = vimt.v_inst_cd + """ + res = db.execute(update_sql) + logging_sql(logger, update_sql) + logger.info(f'納入先処方元マスタの納入先コードを施設コード移行先に更新成功, {res.rowcount} 行更新 ({elapsed_time.of})') + except Exception as e: + logger.debug("納入先処方元マスタの納入先コードを施設コード移行先に更新失敗") + raise e + + return + + +def _update_ult_ident_presc_lau_from_inst_merge_t(db: Database): + # inst_merge_tから、ult_ident_presc_lauをUpdate + try: + select_result = db.execute_select( + """ + SELECT + COUNT(dcf_dsf_inst_cd) AS row_count + FROM + internal05.inst_merge_t + """ + ) + except Exception as e: + logger.debug("施設統合マスタ(洗替処理一時テーブル)からの移行対象施設件数取得失敗") + raise e + + count = [row for row in select_result][0]['row_count'] + if count == 0: + logger.info('施設統合マスタ(洗替処理一時テーブル)からの移行対象施設が存在しません') + return + + logger.info(f'施設統合マスタ(洗替処理一時テーブル)からの移行対象施設件数取得成功 移行対象施設件数={count}') + # inst_merge_tから、ult_ident_presc_lauをUpdate + try: + elapsed_time = ElapsedTime() + update_sql = """ + UPDATE + src05.ult_ident_presc_lau uipl, internal05.inst_merge_t imt + SET + uipl.presc_cd = imt.dup_opp_cd, + uipl.lau_ope_dt = SYSDATE() + WHERE + uipl.presc_cd = imt.dcf_dsf_inst_cd + """ + res = db.execute(update_sql) + logging_sql(logger, update_sql) + logger.info(f'納入先処方元マスタの処方元コードを施設コード移行先に更新成功, {res.rowcount} 行更新 ({elapsed_time.of})') + except Exception as e: + logger.debug("納入先処方元マスタの処方元コードを施設コード移行先に更新失敗") + raise e + + return From f1641b273933f935b45679e99a098a9b62770b69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AB=98=E6=9C=A8=E8=A6=81?= Date: Wed, 26 Apr 2023 13:57:37 +0900 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20=E3=83=AC=E3=83=93=E3=83=A5?= =?UTF-8?q?=E3=83=BC=E6=8C=87=E6=91=98=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ecs/jskult-batch-daily/src/batch/jissekiaraigae.py | 14 -------------- .../laundering/create_inst_merge_for_laundering.py | 4 ++-- .../src/batch/laundering/sales_laundering.py | 7 +++++-- ...laundering.py => ult_ident_presc_laundering.py} | 9 ++------- 4 files changed, 9 insertions(+), 25 deletions(-) delete mode 100644 ecs/jskult-batch-daily/src/batch/jissekiaraigae.py rename ecs/jskult-batch-daily/src/batch/laundering/{create_inst_presc_for_laundering.py => ult_ident_presc_laundering.py} (92%) diff --git a/ecs/jskult-batch-daily/src/batch/jissekiaraigae.py b/ecs/jskult-batch-daily/src/batch/jissekiaraigae.py deleted file mode 100644 index be7e6384..00000000 --- a/ecs/jskult-batch-daily/src/batch/jissekiaraigae.py +++ /dev/null @@ -1,14 +0,0 @@ -from src.batch.datachange import emp_chg_inst_lau -from src.batch.datachange import create_inst_merge_for_laundering -from src.logging.get_logger import get_logger - -logger = get_logger('実績洗替') - - -def batch_process(): - """実績洗替処理""" - logger.info('Start Jisseki Araigae Batch PGM.') - # 洗替用マスタ作成 - create_inst_merge_for_laundering.batch_process() - # 施設担当者洗替 - emp_chg_inst_lau.batch_process() diff --git a/ecs/jskult-batch-daily/src/batch/laundering/create_inst_merge_for_laundering.py b/ecs/jskult-batch-daily/src/batch/laundering/create_inst_merge_for_laundering.py index f631d460..2c9d7353 100644 --- a/ecs/jskult-batch-daily/src/batch/laundering/create_inst_merge_for_laundering.py +++ b/ecs/jskult-batch-daily/src/batch/laundering/create_inst_merge_for_laundering.py @@ -5,7 +5,7 @@ from src.logging.get_logger import get_logger logger = get_logger('洗替用マスタ作成') -def batch_process(): +def exec(): db = Database.get_instance() try: @@ -17,7 +17,7 @@ def batch_process(): logger.debug('処理終了') except Exception as e: raise BatchOperationException(e) - finally: + finally: db.disconnect() diff --git a/ecs/jskult-batch-daily/src/batch/laundering/sales_laundering.py b/ecs/jskult-batch-daily/src/batch/laundering/sales_laundering.py index cb95b702..f6d682b4 100644 --- a/ecs/jskult-batch-daily/src/batch/laundering/sales_laundering.py +++ b/ecs/jskult-batch-daily/src/batch/laundering/sales_laundering.py @@ -1,5 +1,5 @@ from src.batch.common.batch_context import BatchContext -from src.batch.laundering import emp_chg_inst_laundering +from src.batch.laundering import create_inst_merge_for_laundering, emp_chg_inst_laundering, ult_ident_presc_laundering from src.logging.get_logger import get_logger batch_context = BatchContext.get_instance() @@ -14,9 +14,12 @@ def exec(): if batch_context.is_not_business_day: logger.info('営業日ではないため、実績洗替処理をスキップします。') return - + # 洗替用マスタ作成 + create_inst_merge_for_laundering.exec() # 施設担当者洗替 emp_chg_inst_laundering.exec() + # 納入先処方元マスタ洗替 + ult_ident_presc_laundering.exec() # # 並列処理のテスト用コード # import time diff --git a/ecs/jskult-batch-daily/src/batch/laundering/create_inst_presc_for_laundering.py b/ecs/jskult-batch-daily/src/batch/laundering/ult_ident_presc_laundering.py similarity index 92% rename from ecs/jskult-batch-daily/src/batch/laundering/create_inst_presc_for_laundering.py rename to ecs/jskult-batch-daily/src/batch/laundering/ult_ident_presc_laundering.py index c154bcdf..b7434967 100644 --- a/ecs/jskult-batch-daily/src/batch/laundering/create_inst_presc_for_laundering.py +++ b/ecs/jskult-batch-daily/src/batch/laundering/ult_ident_presc_laundering.py @@ -16,19 +16,14 @@ def exec(): logger.debug('納入先処方元マスタの洗替処理開始') # ult_ident_presc_lauをTruncate _truncate_ult_ident_presc_lau(db) - # トランザクション開始 - db.begin() # ult_ident_presc から、ult_ident_presc_lauへInsert _insert_into_ult_ident_presc_lau_from_ult_ident_presc(db) # v_inst_merge_tから、ult_ident_presc_lauをUpdate _update_ult_ident_presc_lau_from_v_inst_merge_t(db) # inst_merge_tから、ult_ident_presc_lauをUpdate _update_ult_ident_presc_lau_from_inst_merge_t(db) - # コミット - db.commit() logger.debug('納入先処方元マスタの洗替処理製造終了') except Exception as e: - db.rollback() raise BatchOperationException(e) finally: db.disconnect() @@ -36,7 +31,7 @@ def exec(): def _truncate_ult_ident_presc_lau(db: Database): try: - db.execute("TRUNCATE TABLE ult_ident_presc_lau") + db.execute("TRUNCATE TABLE src05.ult_ident_presc_lau") except Exception as e: logger.debug("納入先処方元マスタ(洗替後)の全件削除に失敗") raise e @@ -48,7 +43,7 @@ def _truncate_ult_ident_presc_lau(db: Database): def _insert_into_ult_ident_presc_lau_from_ult_ident_presc(db: Database): try: elapsed_time = ElapsedTime() - sql = "INSERT INTO ult_ident_presc_lau SELECT *, null FROM ult_ident_presc" + sql = "INSERT INTO src05.ult_ident_presc_lau SELECT *, NULL FROM src05.ult_ident_presc" res = db.execute(sql) logging_sql(logger, sql) logger.info(f'処方元マスタから処方元マスタ(洗替後)に全件コピーに成功, {res.rowcount} 行更新 ({elapsed_time.of})')