アルトマーク施設マスタのinsertの実装
This commit is contained in:
parent
ed55a30bf1
commit
f5953877fc
@ -19,6 +19,7 @@ from src.system_var import environment
|
||||
|
||||
logger = get_logger('メルク施設マスタ作成')
|
||||
|
||||
|
||||
class MstInstAll(JskultBatchEntrypoint):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
@ -35,7 +36,8 @@ class MstInstAll(JskultBatchEntrypoint):
|
||||
logger.info("メルク施設マスタ作成処理を開始します。")
|
||||
jskult_hdke_tbl_manager = JskultHdkeTblManager()
|
||||
jskult_batch_run_manager = JskultBatchRunManager(
|
||||
environment.BATCH_EXECUTION_ID)
|
||||
self.environment.BATCH_MANAGE_DYNAMODB_TABLE_NAME,
|
||||
self.environment.BATCH_BATCH_EXECUTION_ID)
|
||||
if not jskult_hdke_tbl_manager.can_run_process():
|
||||
logger.error(
|
||||
'日次バッチ処理中またはdump取得が正常終了していないため、メルク施設マスタ作成処理を終了します。')
|
||||
@ -93,22 +95,21 @@ class MstInstAll(JskultBatchEntrypoint):
|
||||
self._db = Database.get_instance()
|
||||
self._db.connect()
|
||||
logger.debug('メルク施設マスタ作成処理開始')
|
||||
# mst_instをTruncate
|
||||
self._truncate_mst_inst(self._db)
|
||||
# fcl_mst_vから、mst_instへInsert
|
||||
self._insert_mst_inst_from_fcl_mst_v(self._db)
|
||||
# com_instから、mst_instへInsert
|
||||
self._insert_mst_inst_from_com_inst(self._db)
|
||||
# mst_inst_allをTruncate
|
||||
self._truncate_mst_inst_all(self._db)
|
||||
# com_pharmから、mst_inst_allへInsert
|
||||
self._insert_mst_inst_all_from_com_pharm(self._db)
|
||||
# com_instから、mst_inst_allへInsert
|
||||
self._insert_mst_inst_all_from_com_inst(self._db)
|
||||
logger.debug('メルク施設マスタ作成処理終了')
|
||||
except Exception as e:
|
||||
raise BatchOperationException(e)
|
||||
finally:
|
||||
self._db.disconnect()
|
||||
|
||||
|
||||
def _truncate_mst_inst(db: Database):
|
||||
def _truncate_mst_inst_all(self, db: Database):
|
||||
try:
|
||||
db.execute("TRUNCATE TABLE src05.mst_inst")
|
||||
db.execute("TRUNCATE TABLE src07.mst_inst_all")
|
||||
except Exception as e:
|
||||
logger.debug("メルク施設マスタの全件削除に失敗")
|
||||
raise e
|
||||
@ -116,13 +117,12 @@ class MstInstAll(JskultBatchEntrypoint):
|
||||
logger.debug("メルク施設マスタの全件削除に成功")
|
||||
return
|
||||
|
||||
|
||||
def _insert_mst_inst_from_fcl_mst_v(db: Database):
|
||||
# fcl_mst_vから、mst_instへInsert
|
||||
def _insert_mst_inst_all_from_com_pharm(self, db: Database):
|
||||
# com_pharmから、mst_inst_allへInsert
|
||||
try:
|
||||
sql = """
|
||||
INSERT INTO
|
||||
src05.mst_inst (
|
||||
src07.mst_inst_all (
|
||||
inst_cd,
|
||||
inst_clas_cd,
|
||||
inst_name_form,
|
||||
@ -191,15 +191,14 @@ class MstInstAll(JskultBatchEntrypoint):
|
||||
AND fmv1.rec_sts_kbn != '9'
|
||||
"""
|
||||
res = db.execute(sql)
|
||||
logger.info(f'V施設マスタからメルク施設マスタに登録成功')
|
||||
logger.info(f'COM_薬局からメルク施設マスタに登録成功')
|
||||
except Exception as e:
|
||||
logger.debug("V施設マスタからメルク施設マスタに登録失敗")
|
||||
logger.debug("COM_薬局からメルク施設マスタに登録失敗")
|
||||
raise e
|
||||
|
||||
return
|
||||
|
||||
|
||||
def _insert_mst_inst_from_com_inst(db: Database):
|
||||
def _insert_mst_inst_all_from_com_inst(self, db: Database):
|
||||
# オプティマイザのderived_mergeフラグをoffにする
|
||||
try:
|
||||
sql = """
|
||||
@ -211,11 +210,11 @@ class MstInstAll(JskultBatchEntrypoint):
|
||||
logger.debug("オプティマイザのderived_mergeフラグの値変更に失敗")
|
||||
raise e
|
||||
|
||||
# com_instから、mst_instへInsert
|
||||
# com_instから、mst_inst_allへInsert
|
||||
try:
|
||||
sql = """
|
||||
INSERT INTO
|
||||
src05.mst_inst (
|
||||
src07.mst_inst_all (
|
||||
inst_cd,
|
||||
inst_clas_cd,
|
||||
inst_name_form,
|
||||
@ -233,7 +232,6 @@ class MstInstAll(JskultBatchEntrypoint):
|
||||
delete_date,
|
||||
inst_div_cd,
|
||||
inst_div_name,
|
||||
v_inst_cd,
|
||||
creater,
|
||||
create_date,
|
||||
updater,
|
||||
@ -257,7 +255,6 @@ class MstInstAll(JskultBatchEntrypoint):
|
||||
ci.abolish_ymd,
|
||||
ci.inst_div_cd,
|
||||
LEFT(cid.inst_div_name, 40),
|
||||
mcmv.hco_vid_v,
|
||||
ci.create_user,
|
||||
ci.regist_date,
|
||||
ci.update_user,
|
||||
@ -273,60 +270,6 @@ class MstInstAll(JskultBatchEntrypoint):
|
||||
ON ci.manage_cd = cm.manage_cd
|
||||
LEFT OUTER JOIN src05.com_inst_div AS cid
|
||||
ON ci.inst_div_cd = cid.inst_div_cd
|
||||
LEFT OUTER JOIN ( -- MDBコード変換表を使用してV施設コードを取得するためのテーブル結合
|
||||
SELECT
|
||||
mcmv4.*
|
||||
FROM (
|
||||
SELECT
|
||||
mcmv1.*
|
||||
FROM
|
||||
src05.mdb_cnv_mst_v AS mcmv1
|
||||
INNER JOIN (
|
||||
SELECT
|
||||
mcmv2.hco_vid_v,
|
||||
MAX(mcmv2.sub_num) AS sno -- MDBコード変換データの枝番MAX
|
||||
FROM
|
||||
src05.mdb_cnv_mst_v mcmv2
|
||||
WHERE
|
||||
mcmv2.rec_sts_kbn != '9' -- 状態区分9(削除)以外 and 適用開始≦日付テーブル.処理日
|
||||
AND src05.get_syor_date() >= mcmv2.start_date
|
||||
GROUP BY
|
||||
mcmv2.hco_vid_v
|
||||
) AS mcmv3
|
||||
ON mcmv1.hco_vid_v = mcmv3.hco_vid_v
|
||||
AND mcmv1.sub_num = mcmv3.sno
|
||||
) AS mcmv4
|
||||
INNER JOIN (
|
||||
SELECT
|
||||
MIN(mcmv8.hco_vid_v) AS hvv, -- 1つのMDBコードに対し、複数のV施設コードが割り当てられている場合、最小のV施設コードを選択する
|
||||
mcmv8.mdb_cd
|
||||
FROM (
|
||||
SELECT
|
||||
mcmv5.*
|
||||
FROM
|
||||
src05.mdb_cnv_mst_v AS mcmv5
|
||||
INNER JOIN (
|
||||
SELECT
|
||||
mcmv6.hco_vid_v,
|
||||
MAX(mcmv6.sub_num) AS sno -- MDBコード変換データの枝番MAX
|
||||
FROM
|
||||
src05.mdb_cnv_mst_v AS mcmv6
|
||||
WHERE
|
||||
mcmv6.rec_sts_kbn != '9' -- 状態区分9(削除)以外 and 適用開始≦日付テーブル.処理日
|
||||
AND src05.get_syor_date() >= mcmv6.start_date
|
||||
GROUP BY
|
||||
mcmv6.hco_vid_v
|
||||
) AS mcmv7
|
||||
ON mcmv5.hco_vid_v = mcmv7.hco_vid_v
|
||||
AND mcmv5.sub_num = mcmv7.sno
|
||||
) AS mcmv8
|
||||
GROUP BY
|
||||
mcmv8.mdb_cd
|
||||
) AS mcmv9
|
||||
ON mcmv4.mdb_cd = mcmv9.mdb_cd
|
||||
AND mcmv4.hco_vid_v = mcmv9.hvv
|
||||
) AS mcmv
|
||||
ON ci.dcf_dsf_inst_cd = mcmv.mdb_cd
|
||||
"""
|
||||
res = db.execute(sql)
|
||||
logger.info(f'COM施設からメルク施設マスタに登録成功')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user