feat: 仕様変更対応
This commit is contained in:
parent
607784bc50
commit
0421aa8ccd
@ -55,76 +55,128 @@ def _set_disabled_dct_inst_merge(db: Database):
|
||||
_update_dcf_inst_cd_new(db, row['dcf_inst_cd'], row['dup_opp_cd'], '戻し')
|
||||
|
||||
|
||||
def _select_ult_ident_presc_ta_cd(db: Database, dcf_inst_cd: str) -> list[dict]:
|
||||
# 納入先処方元マスタから、DCF施設コードに対応した領域コードの取得
|
||||
try:
|
||||
sql = """
|
||||
SELECT
|
||||
ta_cd
|
||||
FROM
|
||||
src05.ult_ident_presc
|
||||
WHERE
|
||||
presc_cd = :dcf_inst_cd
|
||||
AND (SELECT ht.syor_date FROM src05.hdke_tbl AS ht) < end_date
|
||||
"""
|
||||
params = {'dcf_inst_cd': dcf_inst_cd}
|
||||
ult_ident_presc_ta_cd_records = db.execute_select(sql, params)
|
||||
logging_sql(logger, sql)
|
||||
logger.info('納入先処方元マスタから領域コードの取得に成功')
|
||||
except Exception as e:
|
||||
logger.debug('納入先処方元マスタから領域コードの取得に失敗')
|
||||
raise e
|
||||
|
||||
return ult_ident_presc_ta_cd_records
|
||||
|
||||
|
||||
def _add_ult_ident_presc(db: Database, enabled_dst_inst_merge_records: list[dict]):
|
||||
# 納入先処方元マスタの追加
|
||||
logger.info('納入先処方元マスタの登録 開始')
|
||||
for data_inst_cnt, enabled_merge_record in enumerate(enabled_dst_inst_merge_records, start=1):
|
||||
tekiyo_month_first_day = _get_first_day_of_month(enabled_merge_record['tekiyo_month'])
|
||||
ult_ident_presc_ta_cd_records = _select_ult_ident_presc_ta_cd(db, enabled_merge_record['dcf_inst_cd'])
|
||||
for ult_ident_presc_ta_cd_record in ult_ident_presc_ta_cd_records:
|
||||
ult_ident_presc_records = _select_ult_ident_presc(db, enabled_merge_record['dcf_inst_cd'],
|
||||
enabled_merge_record['dup_opp_cd'],
|
||||
ult_ident_presc_ta_cd_record['ta_cd'])
|
||||
for data_cnt, ult_ident_presc_row in enumerate(ult_ident_presc_records, start=1):
|
||||
logger.info(f'{data_inst_cnt}件目の移行施設の{data_cnt}レコード目処理 開始')
|
||||
# 処方元コード=重複時相手先コードが発生した場合
|
||||
if ult_ident_presc_row['opp_count'] > 0:
|
||||
continue
|
||||
|
||||
ult_ident_presc_records = _select_ult_ident_presc(db, enabled_merge_record['dcf_inst_cd'],
|
||||
enabled_merge_record['dup_opp_cd'])
|
||||
for data_cnt, ult_ident_presc_row in enumerate(ult_ident_presc_records, start=1):
|
||||
logger.info(f'{data_inst_cnt}件目の移行施設の{data_cnt}レコード目処理 開始')
|
||||
# 処方元コード=重複時相手先コードが発生した場合
|
||||
if ult_ident_presc_row['opp_count'] > 0:
|
||||
break
|
||||
start_date = _str_to_date_time(ult_ident_presc_row['start_date'])
|
||||
set_start_date = start_date \
|
||||
if start_date > tekiyo_month_first_day else tekiyo_month_first_day
|
||||
set_start_date = _date_time_to_str(set_start_date)
|
||||
is_exists_duplicate_key = False
|
||||
if _count_duplicate_ult_ident_presc(db, set_start_date, ult_ident_presc_row) > 0:
|
||||
_delete_ult_ident_presc(db, set_start_date, ult_ident_presc_row,
|
||||
'納入先処方元マスタの重複予定データの削除')
|
||||
is_exists_duplicate_key = True
|
||||
else:
|
||||
logger.info('納入先処方元マスタの重複予定データなし')
|
||||
_insert_ult_ident_presc(db, set_start_date, enabled_merge_record['dup_opp_cd'], ult_ident_presc_row)
|
||||
|
||||
start_date = _str_to_date_time(ult_ident_presc_row['start_date'])
|
||||
set_start_date = start_date \
|
||||
if start_date > tekiyo_month_first_day else tekiyo_month_first_day
|
||||
set_start_date = _date_time_to_str(set_start_date)
|
||||
is_exists_duplicate_key = False
|
||||
if _count_duplicate_ult_ident_presc(db, set_start_date, ult_ident_presc_row) > 0:
|
||||
_delete_ult_ident_presc(db, set_start_date, ult_ident_presc_row,
|
||||
'納入先処方元マスタの重複予定データの削除')
|
||||
is_exists_duplicate_key = True
|
||||
else:
|
||||
logger.info('納入先処方元マスタの重複予定データなし')
|
||||
_insert_ult_ident_presc(db, set_start_date, enabled_merge_record['dup_opp_cd'], ult_ident_presc_row)
|
||||
|
||||
# 適用終了日 < 適用開始日の場合
|
||||
if _str_to_date_time(ult_ident_presc_row['end_date']) < start_date:
|
||||
# 対象レコードを物理削除する
|
||||
_delete_ult_ident_presc(db, ult_ident_presc_row['start_date'], ult_ident_presc_row,
|
||||
'開始月>適用開始日のため物理削除')
|
||||
continue
|
||||
# 重複予定データが存在しない、且つ、適用終了日 ≧ 適用開始日の場合
|
||||
if not is_exists_duplicate_key:
|
||||
last_end_date = tekiyo_month_first_day - timedelta(days=1)
|
||||
# 適用終了日を、DCF施設統合マスタの適用月度の前月末日で更新
|
||||
_update_ult_ident_presc_end_date(db, _date_time_to_str(last_end_date), ult_ident_presc_row)
|
||||
# 適用終了日 < 適用開始日の場合
|
||||
if _str_to_date_time(ult_ident_presc_row['end_date']) < start_date:
|
||||
# 対象レコードを物理削除する
|
||||
_delete_ult_ident_presc(db, ult_ident_presc_row['start_date'], ult_ident_presc_row,
|
||||
'開始月>適用開始日のため物理削除')
|
||||
continue
|
||||
# 重複予定データが存在しない、且つ、適用終了日 ≧ 適用開始日の場合
|
||||
if not is_exists_duplicate_key:
|
||||
last_end_date = tekiyo_month_first_day - timedelta(days=1)
|
||||
# 適用終了日を、DCF施設統合マスタの適用月度の前月末日で更新
|
||||
_update_ult_ident_presc_end_date(db, _date_time_to_str(last_end_date), ult_ident_presc_row)
|
||||
|
||||
logger.info('納入先処方元マスタの登録 終了')
|
||||
|
||||
|
||||
def _select_emp_chg_inst_ta_cd(db: Database, dcf_inst_cd: str) -> list[dict]:
|
||||
# 従業員担当施設マスタから、DCF施設コードに対応した領域コードの取得
|
||||
try:
|
||||
sql = """
|
||||
SELECT
|
||||
ta_cd
|
||||
FROM
|
||||
src05.emp_chg_inst
|
||||
WHERE
|
||||
inst_cd = :dcf_inst_cd
|
||||
AND enabled_flg = 'Y'
|
||||
AND (SELECT ht.syor_date FROM src05.hdke_tbl AS ht) < end_date
|
||||
"""
|
||||
params = {'dcf_inst_cd': dcf_inst_cd}
|
||||
emp_chg_inst_ta_cd_records = db.execute_select(sql, params)
|
||||
logging_sql(logger, sql)
|
||||
logger.info('従業員担当施設マスタから領域コードの取得に成功')
|
||||
except Exception as e:
|
||||
logger.debug('従業員担当施設マスタから領域コードの取得に失敗')
|
||||
raise e
|
||||
|
||||
return emp_chg_inst_ta_cd_records
|
||||
|
||||
|
||||
def _add_emp_chg_inst(db: Database, enabled_dst_inst_merge_records: list[dict]):
|
||||
# 従業員担当施設マスタの登録
|
||||
logger.info('従業員担当施設マスタの登録 開始')
|
||||
for enabled_merge_record in enabled_dst_inst_merge_records:
|
||||
tekiyo_month_first_day = _get_first_day_of_month(enabled_merge_record['tekiyo_month'])
|
||||
emp_chg_inst_records = _select_emp_chg_inst(db, enabled_merge_record['dcf_inst_cd'], enabled_merge_record['dup_opp_cd'])
|
||||
for emp_chg_inst_row in emp_chg_inst_records:
|
||||
# 重複時相手先コードが存在したかのチェック
|
||||
if emp_chg_inst_row['opp_count'] > 0:
|
||||
break
|
||||
emp_chg_inst_ta_cd_records = _select_emp_chg_inst_ta_cd(db, enabled_merge_record['dcf_inst_cd'])
|
||||
for emp_chg_inst_ta_cd_record in emp_chg_inst_ta_cd_records:
|
||||
emp_chg_inst_records = _select_emp_chg_inst(db, enabled_merge_record['dcf_inst_cd'], enabled_merge_record['dup_opp_cd'],
|
||||
emp_chg_inst_ta_cd_record['ta_cd'])
|
||||
for emp_chg_inst_row in emp_chg_inst_records:
|
||||
# 重複時相手先コードが存在したかのチェック
|
||||
if emp_chg_inst_row['opp_count'] > 0:
|
||||
continue
|
||||
|
||||
start_date = _str_to_date_time(emp_chg_inst_row['start_date'])
|
||||
set_start_date = start_date \
|
||||
if start_date > tekiyo_month_first_day else tekiyo_month_first_day
|
||||
start_date = _str_to_date_time(emp_chg_inst_row['start_date'])
|
||||
set_start_date = start_date \
|
||||
if start_date > tekiyo_month_first_day else tekiyo_month_first_day
|
||||
|
||||
_insert_emp_chg_inst(db, enabled_merge_record['dup_opp_cd'], _date_time_to_str(set_start_date),
|
||||
emp_chg_inst_row)
|
||||
_insert_emp_chg_inst(db, enabled_merge_record['dup_opp_cd'], _date_time_to_str(set_start_date),
|
||||
emp_chg_inst_row)
|
||||
|
||||
# 適用開始日 < DCF施設統合マスタの適用月度の1日の場合
|
||||
if start_date < tekiyo_month_first_day:
|
||||
# DCF施設統合マスタの適用月度の前月末日で、適用終了日を更新する
|
||||
last_end_date = tekiyo_month_first_day - timedelta(days=1)
|
||||
_update_emp_chg_inst_end_date(db, enabled_merge_record['dcf_inst_cd'], _date_time_to_str(last_end_date),
|
||||
emp_chg_inst_row)
|
||||
continue
|
||||
# 適用開始日 ≧ DCF施設統合マスタの適用月度の1日の場合、N(論理削除レコード)に設定する
|
||||
_update_emp_chg_inst_disabled(db, enabled_merge_record['dcf_inst_cd'], emp_chg_inst_row['ta_cd'],
|
||||
emp_chg_inst_row['start_date'])
|
||||
# 適用開始日 < DCF施設統合マスタの適用月度の1日の場合
|
||||
if start_date < tekiyo_month_first_day:
|
||||
# DCF施設統合マスタの適用月度の前月末日で、適用終了日を更新する
|
||||
last_end_date = tekiyo_month_first_day - timedelta(days=1)
|
||||
_update_emp_chg_inst_end_date(db, enabled_merge_record['dcf_inst_cd'], _date_time_to_str(last_end_date),
|
||||
emp_chg_inst_row)
|
||||
continue
|
||||
# 適用開始日 ≧ DCF施設統合マスタの適用月度の1日の場合、N(論理削除レコード)に設定する
|
||||
_update_emp_chg_inst_disabled(db, enabled_merge_record['dcf_inst_cd'], emp_chg_inst_row['ta_cd'],
|
||||
emp_chg_inst_row['start_date'])
|
||||
|
||||
logger.info('従業員担当施設マスタの登録 終了')
|
||||
|
||||
@ -468,7 +520,7 @@ def _insert_ult_ident_presc(db: Database, set_Start_Date: str, dup_opp_cd: str,
|
||||
raise e
|
||||
|
||||
|
||||
def _select_emp_chg_inst(db: Database, dcf_inst_cd: str, dup_opp_cd: str) -> list[dict]:
|
||||
def _select_emp_chg_inst(db: Database, dcf_inst_cd: str, dup_opp_cd: str, ta_cd: str) -> list[dict]:
|
||||
# emp_chg_instからSELECT
|
||||
try:
|
||||
sql = """
|
||||
@ -487,16 +539,18 @@ def _select_emp_chg_inst(db: Database, dcf_inst_cd: str, dup_opp_cd: str) -> lis
|
||||
FROM
|
||||
src05.emp_chg_inst AS eciopp
|
||||
WHERE
|
||||
eciopp.inst_cd = :dup_opp_cd
|
||||
eciopp.inst_cd = :dup_opp_cd
|
||||
AND eciopp.ta_cd = :ta_cd
|
||||
) AS opp_count
|
||||
FROM
|
||||
src05.emp_chg_inst AS eci
|
||||
WHERE
|
||||
eci.inst_cd = :dcf_inst_cd
|
||||
AND eci.ta_cd = :ta_cd
|
||||
AND eci.enabled_flg = 'Y'
|
||||
AND (SELECT ht.syor_date FROM src05.hdke_tbl AS ht) < eci.end_date
|
||||
"""
|
||||
params = {'dcf_inst_cd': dcf_inst_cd, 'dup_opp_cd': dup_opp_cd}
|
||||
params = {'dcf_inst_cd': dcf_inst_cd, 'dup_opp_cd': dup_opp_cd, 'ta_cd': ta_cd}
|
||||
emp_chg_inst_records = db.execute_select(sql, params)
|
||||
logging_sql(logger, sql)
|
||||
logger.info('従業員担当施設マスタの取得 成功')
|
||||
@ -506,7 +560,7 @@ def _select_emp_chg_inst(db: Database, dcf_inst_cd: str, dup_opp_cd: str) -> lis
|
||||
return emp_chg_inst_records
|
||||
|
||||
|
||||
def _select_ult_ident_presc(db: Database, dcf_inst_cd: str, dup_opp_cd: str) -> list[dict]:
|
||||
def _select_ult_ident_presc(db: Database, dcf_inst_cd: str, dup_opp_cd: str, ta_cd: str) -> list[dict]:
|
||||
# ult_ident_prescからSELECT
|
||||
try:
|
||||
sql = """
|
||||
@ -522,15 +576,17 @@ def _select_ult_ident_presc(db: Database, dcf_inst_cd: str, dup_opp_cd: str) ->
|
||||
FROM
|
||||
src05.ult_ident_presc AS uipopp
|
||||
WHERE
|
||||
uipopp.presc_cd = :dup_opp_cd
|
||||
uipopp.presc_cd = :dup_opp_cd
|
||||
AND uipopp.ta_cd = :ta_cd
|
||||
) AS opp_count
|
||||
FROM
|
||||
src05.ult_ident_presc AS uip
|
||||
WHERE
|
||||
uip.presc_cd = :dcf_inst_cd
|
||||
AND uip.ta_cd = :ta_cd
|
||||
AND (SELECT ht.syor_date FROM src05.hdke_tbl AS ht) < uip.end_date
|
||||
"""
|
||||
params = {'dcf_inst_cd': dcf_inst_cd, 'dup_opp_cd': dup_opp_cd}
|
||||
params = {'dcf_inst_cd': dcf_inst_cd, 'dup_opp_cd': dup_opp_cd, 'ta_cd': ta_cd}
|
||||
ult_ident_presc_records = db.execute_select(sql, params)
|
||||
logging_sql(logger, sql)
|
||||
logger.info('納入先処方元マスタの取得 成功')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user