ログとかコメントの整理
This commit is contained in:
parent
0962172f4d
commit
62ec4ddebb
@ -110,8 +110,7 @@ class UltmarcBackupBucket(JskUltBackupBucket):
|
||||
_folder = environment.ULTMARC_BACKUP_FOLDER
|
||||
|
||||
|
||||
class VjskBucket(S3Bucket):
|
||||
# TODO:V実消化バケットから見たり取ってきたりする実装をやる
|
||||
class VjskRecieveBucket(S3Bucket):
|
||||
_bucket_name = environment.JSKULT_DATA_BUCKET
|
||||
_recv_folder = environment.JSKULT_DATA_FOLDER_RECV
|
||||
|
||||
|
||||
@ -12,6 +12,8 @@ class JjskDataLoadManager:
|
||||
pass
|
||||
|
||||
def _import_to_db(src_file_name: str, condkey: str):
|
||||
logger.debug(f"_import_to_db start (src_file_name : {src_file_name}, condkey : {condkey})")
|
||||
|
||||
db = Database.get_instance()
|
||||
table_name_org = mapper.get_org_table(condkey)
|
||||
upsert_sql = mapper.get_upsert_sql(condkey)
|
||||
@ -40,6 +42,8 @@ class JjskDataLoadManager:
|
||||
raise e
|
||||
finally:
|
||||
db.disconnect()
|
||||
|
||||
logger.debug("_import_to_db end")
|
||||
return
|
||||
|
||||
@classmethod
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
from src.aws.s3 import ConfigBucket, VjskBucket
|
||||
from src.aws.s3 import ConfigBucket, VjskRecieveBucket
|
||||
from src.batch.common.batch_context import BatchContext
|
||||
from src.batch.common.calendar_wholestocksaler_file import \
|
||||
CalendarWholwSalerStockFile
|
||||
@ -7,108 +7,116 @@ from src.batch.vjsk.vjsk_recv_file_mapper import VjskRecvFileMapper
|
||||
from src.error.exceptions import BatchOperationException
|
||||
from src.logging.get_logger import get_logger
|
||||
|
||||
# from src.batch.datachange import emp_chg_inst_lau
|
||||
|
||||
_logger = get_logger('V実消化データ取込')
|
||||
logger = get_logger('V実消化データ取込')
|
||||
batch_context = BatchContext.get_instance()
|
||||
vjsk_recv_bucket = VjskBucket()
|
||||
vjsk_recv_bucket = VjskRecieveBucket()
|
||||
vjsk_mapper = VjskRecvFileMapper()
|
||||
|
||||
|
||||
def _check_if_file_exists(src_list: list, key: str) -> bool:
|
||||
pref = vjsk_mapper.get_file_prefix(key)
|
||||
suff = vjsk_mapper.get_file_suffix(key)
|
||||
def _check_if_file_exists(src_list: list, condkey: str) -> bool:
|
||||
logger.debug(f"_check_if_file_exists start (src_list : {src_list} , condkey : {condkey})")
|
||||
# ファイル接頭辞と拡張子が一致するかで判定する
|
||||
ret = False
|
||||
pref = vjsk_mapper.get_file_prefix(condkey)
|
||||
suff = vjsk_mapper.get_file_suffix(condkey)
|
||||
|
||||
for idx, elem in enumerate(src_list):
|
||||
buf = elem.get("filename")
|
||||
filename = buf[buf.rfind("/") + 1:]
|
||||
if filename.startswith(pref) and filename.endswith(suff):
|
||||
return True
|
||||
return False
|
||||
ret = True
|
||||
break
|
||||
|
||||
logger.debug(f"_check_if_file_exists end (return : {ret})")
|
||||
return ret
|
||||
|
||||
|
||||
def _check_received_files():
|
||||
"""V実消化連携データ存在確認処理"""
|
||||
_logger.debug('V実消化連携データ存在確認処理:開始')
|
||||
"""V実消化連携データファイル受領確認処理"""
|
||||
logger.debug('_check_received_files start')
|
||||
|
||||
# 実消化&アルトマーク V実消化データ受領バケットにあるファイル一覧を取得
|
||||
received_files = vjsk_recv_bucket.get_s3_file_list()
|
||||
_logger.debug(f'ファイル一覧{received_files}')
|
||||
# S3バケット「実消化&アルトマーク V実消化データ受領バケット」にある受領ファイル一覧を取得
|
||||
received_s3_files = vjsk_recv_bucket.get_s3_file_list()
|
||||
logger.debug(f'ファイル一覧{received_s3_files}')
|
||||
|
||||
# ファイル存在確認 卸在庫データファイル(卸在庫データ処理対象日のみ実施)
|
||||
if batch_context.is_import_target_vjsk_stockslipdata:
|
||||
if not _check_if_file_exists(received_files, vjsk_mapper.CONDKEY_STOCK_SLIP_DATA):
|
||||
raise BatchOperationException(f'卸在庫データファイルがありません ファイル一覧:{received_files}')
|
||||
if not _check_if_file_exists(received_s3_files, vjsk_mapper.CONDKEY_STOCK_SLIP_DATA):
|
||||
raise BatchOperationException(f'卸在庫データファイルがありません ファイル一覧:{received_s3_files}')
|
||||
|
||||
# ファイル存在確認 卸販売データ
|
||||
if not _check_if_file_exists(received_files, vjsk_mapper.CONDKEY_SLIP_DATA):
|
||||
raise BatchOperationException(f'卸販売データファイルがありません ファイル一覧:{received_files}')
|
||||
if not _check_if_file_exists(received_s3_files, vjsk_mapper.CONDKEY_SLIP_DATA):
|
||||
raise BatchOperationException(f'卸販売データファイルがありません ファイル一覧:{received_s3_files}')
|
||||
|
||||
# ファイル存在確認 卸組織変換マスタ
|
||||
if not _check_if_file_exists(received_files, vjsk_mapper.CONDKEY_ORG_CNV_MST):
|
||||
raise BatchOperationException(f'卸組織変換マスタファイルがありません ファイル一覧:{received_files}')
|
||||
if not _check_if_file_exists(received_s3_files, vjsk_mapper.CONDKEY_ORG_CNV_MST):
|
||||
raise BatchOperationException(f'卸組織変換マスタファイルがありません ファイル一覧:{received_s3_files}')
|
||||
|
||||
# ファイル存在確認 施設統合マスタ
|
||||
if not _check_if_file_exists(received_files, vjsk_mapper.CONDKEY_VOP_HCO_MERGE):
|
||||
raise BatchOperationException(f'施設統合マスタファイルがありません ファイル一覧:{received_files}')
|
||||
if not _check_if_file_exists(received_s3_files, vjsk_mapper.CONDKEY_VOP_HCO_MERGE):
|
||||
raise BatchOperationException(f'施設統合マスタファイルがありません ファイル一覧:{received_s3_files}')
|
||||
|
||||
# ファイル存在確認 卸マスタ
|
||||
if not _check_if_file_exists(received_files, vjsk_mapper.CONDKEY_WHS_MST):
|
||||
raise BatchOperationException(f'卸マスタファイルがありません ファイル一覧:{received_files}')
|
||||
if not _check_if_file_exists(received_s3_files, vjsk_mapper.CONDKEY_WHS_MST):
|
||||
raise BatchOperationException(f'卸マスタファイルがありません ファイル一覧:{received_s3_files}')
|
||||
|
||||
# ファイル存在確認 卸ホールディングスマスタ
|
||||
if not _check_if_file_exists(received_files, vjsk_mapper.CONDKEY_HLD_MST):
|
||||
raise BatchOperationException(f'卸ホールディングスマスタファイルがありません ファイル一覧:{received_files}')
|
||||
if not _check_if_file_exists(received_s3_files, vjsk_mapper.CONDKEY_HLD_MST):
|
||||
raise BatchOperationException(f'卸ホールディングスマスタファイルがありません ファイル一覧:{received_s3_files}')
|
||||
|
||||
# ファイル存在確認 施設マスタ
|
||||
if not _check_if_file_exists(received_files, vjsk_mapper.CONDKEY_FCL_MST):
|
||||
raise BatchOperationException(f'施設マスタファイルがありません ファイル一覧:{received_files}')
|
||||
if not _check_if_file_exists(received_s3_files, vjsk_mapper.CONDKEY_FCL_MST):
|
||||
raise BatchOperationException(f'施設マスタファイルがありません ファイル一覧:{received_s3_files}')
|
||||
|
||||
# ファイル存在確認 メーカー卸組織展開表
|
||||
if not _check_if_file_exists(received_files, vjsk_mapper.CONDKEY_MKR_ORG_HORIZON):
|
||||
raise BatchOperationException(f'メーカー卸組織展開表ファイルがありません ファイル一覧:{received_files}')
|
||||
if not _check_if_file_exists(received_s3_files, vjsk_mapper.CONDKEY_MKR_ORG_HORIZON):
|
||||
raise BatchOperationException(f'メーカー卸組織展開表ファイルがありません ファイル一覧:{received_s3_files}')
|
||||
|
||||
# ファイル存在確認 取引区分マスタ
|
||||
if not _check_if_file_exists(received_files, vjsk_mapper.CONDKEY_TRAN_KBN_MST):
|
||||
raise BatchOperationException(f'取引区分マスタファイルがありません ファイル一覧:{received_files}')
|
||||
if not _check_if_file_exists(received_s3_files, vjsk_mapper.CONDKEY_TRAN_KBN_MST):
|
||||
raise BatchOperationException(f'取引区分マスタファイルがありません ファイル一覧:{received_s3_files}')
|
||||
|
||||
# ファイル存在確認 製品マスタ
|
||||
if not _check_if_file_exists(received_files, vjsk_mapper.CONDKEY_PHM_PRD_MST):
|
||||
raise BatchOperationException(f'製品マスタファイルがありません ファイル一覧:{received_files}')
|
||||
if not _check_if_file_exists(received_s3_files, vjsk_mapper.CONDKEY_PHM_PRD_MST):
|
||||
raise BatchOperationException(f'製品マスタファイルがありません ファイル一覧:{received_s3_files}')
|
||||
|
||||
# ファイル存在確認 製品価格マスタ
|
||||
if not _check_if_file_exists(received_files, vjsk_mapper.CONDKEY_PHM_PRICE_MST):
|
||||
raise BatchOperationException(f'製品価格マスタファイルがありません ファイル一覧:{received_files}')
|
||||
if not _check_if_file_exists(received_s3_files, vjsk_mapper.CONDKEY_PHM_PRICE_MST):
|
||||
raise BatchOperationException(f'製品価格マスタファイルがありません ファイル一覧:{received_s3_files}')
|
||||
|
||||
# ファイル存在確認 卸得意先情報マスタ
|
||||
if not _check_if_file_exists(received_files, vjsk_mapper.CONDKEY_WHS_CUSTOMER_MST):
|
||||
raise BatchOperationException(f'卸得意先情報マスタファイルがありません ファイル一覧:{received_files}')
|
||||
if not _check_if_file_exists(received_s3_files, vjsk_mapper.CONDKEY_WHS_CUSTOMER_MST):
|
||||
raise BatchOperationException(f'卸得意先情報マスタファイルがありません ファイル一覧:{received_s3_files}')
|
||||
|
||||
# ファイル存在確認 MDBコード変換マスタ
|
||||
if not _check_if_file_exists(received_files, vjsk_mapper.CONDKEY_MDB_CONV_MST):
|
||||
raise BatchOperationException(f'MDBコード変換マスタファイルがありません ファイル一覧:{received_files}')
|
||||
if not _check_if_file_exists(received_s3_files, vjsk_mapper.CONDKEY_MDB_CONV_MST):
|
||||
raise BatchOperationException(f'MDBコード変換マスタファイルがありません ファイル一覧:{received_s3_files}')
|
||||
|
||||
_logger.debug('V実消化連携データ存在確認処理:終了')
|
||||
logger.debug('_check_received_files end')
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def _import_file_to_db():
|
||||
_logger.debug('V実消化取込処理:開始')
|
||||
"""V実消化連携データ取込処理"""
|
||||
logger.debug('_import_file_to_db start')
|
||||
|
||||
# 実消化&アルトマーク V実消化データ受領バケットにあるファイルパス一覧を取得
|
||||
# S3バケット「実消化&アルトマーク V実消化データ受領バケット」にある受領ファイル一覧を取得
|
||||
received_s3_files = vjsk_recv_bucket.get_s3_file_list()
|
||||
|
||||
# ファイルパス一覧にマッピング情報を参照するためのキーを持たせて辞書可する
|
||||
# S3バケット「実消化&アルトマーク V実消化データ受領バケット」の受領ファイルをローカルストレージにdownloadして辞書化する
|
||||
target_dict = {}
|
||||
for s3_file_path in received_s3_files:
|
||||
# S3バケットにある受領ファイルをローカルストレージにdownloadする
|
||||
local_file_path = vjsk_recv_bucket.download_data_file(s3_file_path.get('filename'))
|
||||
|
||||
# データファイル名に該当する辞書アクセス用のキーを取得する
|
||||
key = vjsk_mapper.get_condkey_by_s3_file_path(s3_file_path.get('filename'))
|
||||
|
||||
# 想定されたデータファイルであれば辞書登録する
|
||||
if key is not None:
|
||||
target_dict[key] = {"condkey": key, "src_file_path": local_file_path}
|
||||
_logger.debug(f'S3ファイルパス辞書{target_dict}')
|
||||
|
||||
# TODO: diff_upsertに変わるやつを呼び出す
|
||||
# TODO: emp_chg_inst_lau.batch_process() みたいに
|
||||
logger.debug(f'取込対象データファイル辞書{target_dict}')
|
||||
|
||||
# DB登録 卸在庫データファイル(卸在庫データ処理対象日のみ実施)
|
||||
if batch_context.is_import_target_vjsk_stockslipdata:
|
||||
@ -150,51 +158,60 @@ def _import_file_to_db():
|
||||
# DB登録 MDBコード変換マスタ
|
||||
JjskDataLoadManager.Load(target_dict[vjsk_mapper.CONDKEY_MDB_CONV_MST])
|
||||
|
||||
_logger.debug('V実消化取込処理:終了')
|
||||
logger.debug('_import_file_to_db end')
|
||||
|
||||
|
||||
def _determine_today_is_stockslipdata_target():
|
||||
"""設定ファイル「V実消化卸在庫データ連携日ファイル」の内容を取得して、処理日が該当していればTrueを返却する"""
|
||||
"""設定ファイル「V実消化卸在庫データ連携日ファイル」の内容を取得して、処理日付が該当していればTrueを返却する"""
|
||||
logger.debug("_determine_today_is_stockslipdata_target start")
|
||||
try:
|
||||
# 処理日付を取得する
|
||||
today = batch_context.syor_date
|
||||
|
||||
holiday_list_file_path = ConfigBucket().download_wholesaler_stock_list()
|
||||
targetdays = CalendarWholwSalerStockFile(holiday_list_file_path)
|
||||
ret = targetdays.compare_date(today)
|
||||
# S3バケット上の設定ファイル「V実消化卸在庫データ連携日ファイル」をローカルストレージにdownloadする
|
||||
config_file_path = ConfigBucket().download_wholesaler_stock_list()
|
||||
|
||||
# 設定ファイル「V実消化卸在庫データ連携日ファイル」の定義内容を取得する
|
||||
target_days = CalendarWholwSalerStockFile(config_file_path)
|
||||
|
||||
# 処理日付が、設定ファイル「V実消化卸在庫データ連携日ファイル」の定義に該当するかを判定する
|
||||
ret = target_days.compare_date(today)
|
||||
except Exception as e:
|
||||
_logger.error(f'{e}')
|
||||
logger.error(f'{e}')
|
||||
raise e
|
||||
logger.debug("_determine_today_is_stockslipdata_target end")
|
||||
return ret
|
||||
|
||||
|
||||
def exec():
|
||||
"""V実消化データ取込"""
|
||||
_logger.info('Start Jitsusyouka Torikomi PGM.')
|
||||
"""V実消化データ取込処理"""
|
||||
logger.info('Start Jitsusyouka Torikomi PGM.')
|
||||
|
||||
# 卸在庫データ取込対象日であれば、卸在庫データ処理対象フラグを立てる
|
||||
_logger.debug('卸在庫データ取込対象日であるかを判定')
|
||||
logger.debug('卸在庫データ取込対象日であるかを判定')
|
||||
batch_context.is_import_target_vjsk_stockslipdata = _determine_today_is_stockslipdata_target()
|
||||
_logger.debug(f'判定結果 : {batch_context.is_import_target_vjsk_stockslipdata}')
|
||||
logger.debug(f'判定結果 : {batch_context.is_import_target_vjsk_stockslipdata}')
|
||||
if batch_context.is_import_target_vjsk_stockslipdata:
|
||||
_logger.info('卸在庫データ取込対象日です')
|
||||
logger.info('卸在庫データ取込対象日です')
|
||||
|
||||
# V実消化データファイル受領チェック
|
||||
_logger.debug('V実消化データファイル受領チェック:開始')
|
||||
logger.debug('V実消化データファイル受領チェック:開始')
|
||||
try:
|
||||
# S3バケット上でV実消化データファイルの存在チェックをする
|
||||
# S3バケットにある受領済のV実消化データファイルの存在チェックをする
|
||||
_check_received_files()
|
||||
|
||||
except BatchOperationException as e:
|
||||
_logger.error('受領したV実消化データファイルに欠落があります')
|
||||
logger.error('受領したV実消化データファイルに未受領もものがあります')
|
||||
raise e
|
||||
_logger.debug('V実消化データファイル受領チェック:終了')
|
||||
logger.debug('V実消化データファイル受領チェック:終了')
|
||||
|
||||
# データベース取込
|
||||
_logger.debug('V実消化データ取込:開始')
|
||||
logger.debug('V実消化データ取込:開始')
|
||||
try:
|
||||
# S3バケットにある受領済のV実消化データファイルをデータベースに登録する
|
||||
_import_file_to_db()
|
||||
except Exception as e:
|
||||
_logger.error(f'データベース登録失敗 {e}')
|
||||
logger.error(f'データベース登録失敗 {e}')
|
||||
raise e
|
||||
|
||||
_logger.debug('V実消化データ取込:終了')
|
||||
logger.debug('V実消化データ取込:終了')
|
||||
|
||||
@ -1,60 +0,0 @@
|
||||
# import csv
|
||||
# from io import TextIOWrapper
|
||||
|
||||
|
||||
# class VjskRecvFileManager:
|
||||
# layout_class: str
|
||||
# records: list[str]
|
||||
|
||||
# def __init__(self, dat_line: list[str]) -> None:
|
||||
# self.layout_class = dat_line[0]
|
||||
# self.records = dat_line
|
||||
|
||||
|
||||
# class VjskDatFile:
|
||||
# """V実消化データファイル"""
|
||||
|
||||
# lines: list[VjskRecvFileManager]
|
||||
# success_count: int = 0
|
||||
# error_count: int = 0
|
||||
# total_count: int = 0
|
||||
# __i: int = 0
|
||||
|
||||
# def __iter__(self):
|
||||
# return self
|
||||
|
||||
# def __next__(self) -> VjskRecvFileManager:
|
||||
# if self.__i == len(self.lines):
|
||||
# raise StopIteration()
|
||||
# line = self.lines[self.__i]
|
||||
# self.__i += 1
|
||||
# return line
|
||||
|
||||
# def __init__(self, file: TextIOWrapper) -> None:
|
||||
# reader = csv.reader(file)
|
||||
# csv_rows = [VjskRecvFileManager(row) for row in reader]
|
||||
|
||||
# self.lines = csv_rows
|
||||
# self.total_count = len(csv_rows)
|
||||
|
||||
# def count_up_success(self):
|
||||
# self.success_count += 1
|
||||
|
||||
# def count_up_error(self):
|
||||
# self.error_count += 1
|
||||
|
||||
# @classmethod
|
||||
# def retrieve_from_file(cls, local_file_path: str):
|
||||
# """V実消化データファイルを読み込み、新しいインスタンスを作成する
|
||||
|
||||
# Args:
|
||||
# local_file_path (str): ローカルのファイルパス
|
||||
|
||||
# Returns:
|
||||
# VjskDatFile: このクラスのインスタンス
|
||||
# """
|
||||
# # cp932(Shift-JIS Windows拡張)でファイルを読み込む
|
||||
# file = open(local_file_path, encoding='cp932')
|
||||
# instance = cls(file)
|
||||
# file.close()
|
||||
# return instance
|
||||
Loading…
x
Reference in New Issue
Block a user