feat: 全件卸販売実績洗替
This commit is contained in:
parent
359b8a4085
commit
ea78a31ec5
@ -1,25 +1,25 @@
|
||||
"""バッチ処理の共通関数"""
|
||||
import logging
|
||||
import textwrap
|
||||
from datetime import datetime
|
||||
|
||||
from src.db.database import Database
|
||||
from src.error.exceptions import BatchOperationException, DBException
|
||||
from src.system_var import constants
|
||||
|
||||
|
||||
def get_batch_statuses() -> tuple[str, str]:
|
||||
"""日付テーブルから、以下を取得して返す。
|
||||
- バッチ処理中フラグ
|
||||
- 処理日(YYYY/MM/DD)
|
||||
- dump取得状況区分
|
||||
|
||||
Raises:
|
||||
BatchOperationException: 日付テーブルが取得できないとき、何らかのエラーが発生したとき
|
||||
|
||||
Returns:
|
||||
tuple[str, str]: [0]バッチ処理中フラグ,[1]処理日
|
||||
tuple[str, str]: [0]バッチ処理中フラグ,[1]dump取得状況区分
|
||||
"""
|
||||
db = Database.get_instance()
|
||||
sql = 'SELECT bch_actf, src05.get_syor_date() AS syor_date FROM src05.hdke_tbl'
|
||||
sql = 'SELECT bch_actf, dump_sts_kbn FROM src05.hdke_tbl'
|
||||
try:
|
||||
db.connect()
|
||||
hdke_tbl_result = db.execute_select(sql)
|
||||
@ -34,11 +34,78 @@ def get_batch_statuses() -> tuple[str, str]:
|
||||
# 必ず1件取れる
|
||||
hdke_tbl_record = hdke_tbl_result[0]
|
||||
batch_processing_flag = hdke_tbl_record['bch_actf']
|
||||
syor_date = hdke_tbl_record['syor_date']
|
||||
# 処理日を文字列に変換する
|
||||
syor_date_str = datetime.strftime(syor_date, '%Y/%m/%d')
|
||||
dump_status_kbn = hdke_tbl_record['dump_sts_kbn']
|
||||
|
||||
return batch_processing_flag, syor_date_str
|
||||
return batch_processing_flag, dump_status_kbn
|
||||
|
||||
|
||||
def update_dump_status_kbn_in_processing() -> None:
|
||||
"""dump取得状況区分を処理中に更新する
|
||||
|
||||
Raises:
|
||||
BatchOperationException: DB操作の何らかのエラー
|
||||
"""
|
||||
db = Database.get_instance()
|
||||
sql = 'UPDATE src05.hdke_tbl SET dump_sts_kbn = :in_processing'
|
||||
try:
|
||||
db.connect()
|
||||
db.execute(sql, {'in_processing': constants.BATCH_ACTF_BATCH_IN_PROCESSING})
|
||||
except DBException as e:
|
||||
raise BatchOperationException(e)
|
||||
finally:
|
||||
db.disconnect()
|
||||
|
||||
return
|
||||
|
||||
|
||||
def update_dump_status_kbn_error() -> None:
|
||||
"""dump取得状況区分をエラーに更新する
|
||||
|
||||
Raises:
|
||||
BatchOperationException: DB操作の何らかのエラー
|
||||
"""
|
||||
db = Database.get_instance()
|
||||
sql = """\
|
||||
UPDATE src05.hdke_tbl
|
||||
SET
|
||||
dump_sts_kbn = :dump_unprocessed
|
||||
"""
|
||||
try:
|
||||
db.connect()
|
||||
db.execute(sql, {
|
||||
'dump_unprocessed': constants.DUMP_STATUS_KBN_ERROR
|
||||
})
|
||||
except DBException as e:
|
||||
raise BatchOperationException(e)
|
||||
finally:
|
||||
db.disconnect()
|
||||
|
||||
return
|
||||
|
||||
|
||||
def update_dump_status_kbn_complete() -> None:
|
||||
"""dump取得状況区分を正常終了に更新する
|
||||
|
||||
Raises:
|
||||
BatchOperationException: DB操作の何らかのエラー
|
||||
"""
|
||||
db = Database.get_instance()
|
||||
sql = """\
|
||||
UPDATE src05.hdke_tbl
|
||||
SET
|
||||
dump_sts_kbn = :dump_unprocessed
|
||||
"""
|
||||
try:
|
||||
db.connect()
|
||||
db.execute(sql, {
|
||||
'dump_unprocessed': constants.DUMP_STATUS_KBN_COMPLETE
|
||||
})
|
||||
except DBException as e:
|
||||
raise BatchOperationException(e)
|
||||
finally:
|
||||
db.disconnect()
|
||||
|
||||
return
|
||||
|
||||
|
||||
def logging_sql(logger: logging.Logger, sql: str) -> None:
|
||||
|
||||
@ -1,32 +0,0 @@
|
||||
from src.system_var import constants
|
||||
|
||||
|
||||
class CalendarFile:
|
||||
"""カレンダーファイル"""
|
||||
|
||||
__calendar_file_lines: list[str]
|
||||
|
||||
def __init__(self, calendar_file_path):
|
||||
with open(calendar_file_path) as f:
|
||||
self.__calendar_file_lines: list[str] = f.readlines()
|
||||
|
||||
def compare_date(self, date_str: str) -> bool:
|
||||
"""与えられた日付がカレンダーファイル内に含まれているかどうか
|
||||
カレンダーファイル内の日付はyyyy/mm/ddで書かれている前提
|
||||
コメント(#)が含まれている行は無視される
|
||||
|
||||
Args:
|
||||
date_str (str): yyyy/mm/dd文字列
|
||||
|
||||
Returns:
|
||||
bool: 含まれていればTrue
|
||||
"""
|
||||
for calendar_date in self.__calendar_file_lines:
|
||||
# コメント行が含まれている場合はスキップ
|
||||
if constants.CALENDAR_COMMENT_SYMBOL in calendar_date:
|
||||
continue
|
||||
|
||||
if date_str in calendar_date:
|
||||
return True
|
||||
|
||||
return False
|
||||
@ -1,6 +1,5 @@
|
||||
"""実消化&アルトマーク実績洗替処理"""
|
||||
from src.batch.batch_functions import get_batch_statuses
|
||||
from src.batch.common.batch_context import BatchContext
|
||||
from src.error.exceptions import BatchOperationException
|
||||
from src.logging.get_logger import get_logger
|
||||
from src.system_var import constants
|
||||
@ -12,12 +11,29 @@ logger = get_logger('実消化&アルトマーク実績洗替処理')
|
||||
|
||||
def exec():
|
||||
try:
|
||||
logger.debug('処理開始')
|
||||
logger.info('週次バッチ:開始')
|
||||
try:
|
||||
# 日次バッチ処置中フラグ、dump処理状態区分、処理日を取得
|
||||
batch_processing_flag, dump_status_kbn = get_batch_statuses()
|
||||
except BatchOperationException as e:
|
||||
logger.exception(f'日付テーブル取得(異常終了){e}')
|
||||
return constants.BATCH_EXIT_CODE_SUCCESS
|
||||
|
||||
# 日次バッチ処理中の場合、後続の処理は行わない
|
||||
if batch_processing_flag == constants.BATCH_ACTF_BATCH_IN_PROCESSING:
|
||||
logger.warning('日次バッチ処理中のため、実消化&アルトマーク実績洗替処理を終了します。')
|
||||
return constants.BATCH_EXIT_CODE_SUCCESS
|
||||
|
||||
# dump取得が正常終了していない場合、後続の処理は行わない
|
||||
if dump_status_kbn != constants.DUMP_STATUS_KBN_UNPROCESSED:
|
||||
logger.warning('dump取得が正常終了していないため、実消化&アルトマーク実績洗替処理を終了します。')
|
||||
return constants.BATCH_EXIT_CODE_SUCCESS
|
||||
|
||||
# 洗替用マスタ作成
|
||||
create_inst_merge_for_laundering.exec()
|
||||
# 卸販売実績全件洗替
|
||||
sales_results_laundering.exec()
|
||||
logger.debug('処理終了')
|
||||
except BatchOperationException as e:
|
||||
logger.exception(f'(異常終了){e}')
|
||||
logger.info('週次バッチ:終了')
|
||||
except Exception as e:
|
||||
logger.exception(f'実消化&アルトマーク実績洗替処理中に想定外のエラーが発生しました {e}')
|
||||
return constants.BATCH_EXIT_CODE_SUCCESS
|
||||
|
||||
@ -4,5 +4,5 @@ BATCH_EXIT_CODE_SUCCESS = 0
|
||||
# バッチ処理中フラグ:処理中
|
||||
BATCH_ACTF_BATCH_IN_PROCESSING = '1'
|
||||
|
||||
# カレンダーファイルのコメントシンボル
|
||||
CALENDAR_COMMENT_SYMBOL = '#'
|
||||
# dump取得状態区分:未処理
|
||||
DUMP_STATUS_KBN_UNPROCESSED = '0'
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user