Merge pull request #244 feature-NEWDWH2021-1166 into develop

This commit is contained in:
朝倉 明日香 2023-08-02 11:02:57 +09:00
commit da5c74ad48
38 changed files with 69 additions and 33 deletions

View File

@ -1,6 +1,7 @@
import gzip
import os
import os.path as path
import tarfile
import shutil
import tempfile
import boto3
@ -134,14 +135,14 @@ class VjskReceiveBucket(S3Bucket):
return temporary_file_path
def unzip_data_file(self, filename: str):
ret = []
with tarfile.open(filename) as tar:
temp_dir = os.path.dirname(filename)
tar.extractall(path=temp_dir)
extracted_files = tar.getnames()
for extracted_file in extracted_files:
file = os.path.join(temp_dir, extracted_file)
ret.append(file)
temp_dir = os.path.dirname(filename)
decompress_filename = os.path.basename(filename).replace('.gz', '')
decompress_file_path = os.path.join(temp_dir, decompress_filename)
with gzip.open(filename, 'rb') as gz:
with open(decompress_file_path, 'wb') as decompressed_file:
shutil.copyfileobj(gz, decompressed_file)
ret = [decompress_file_path]
return ret
def backup_dat_file(self, target_files: list, datetime_key: str):

View File

@ -60,6 +60,7 @@ def update_batch_processing_flag_in_processing() -> None:
"""
try:
db.connect()
db.to_jst()
db.execute(sql, {'in_processing': constants.BATCH_ACTF_BATCH_IN_PROCESSING})
except DBException as e:
raise BatchOperationException(e)
@ -87,6 +88,7 @@ def update_batch_process_complete() -> None:
"""
try:
db.connect()
db.to_jst()
db.execute(sql, {
'batch_complete': constants.BATCH_ACTF_BATCH_UNPROCESSED,
'dump_unprocessed': constants.DUMP_STATUS_KBN_UNPROCESSED

View File

@ -20,6 +20,7 @@ def exec():
db = Database.get_instance()
try:
db.connect()
db.to_jst()
db.begin()
logger.debug('DCF施設統合マスタ作成処理開始')
# COM施設からDCF施設統合マスタに登録

View File

@ -14,6 +14,7 @@ def exec():
db = Database.get_instance()
try:
db.connect()
db.to_jst()
db.begin()
logger.debug('DCF施設統合マスタ日次更新処理開始')
# DCF施設統合マスタ移行先コードのセット(無効フラグが『0(有効)』)

View File

@ -13,6 +13,7 @@ def exec():
db = Database.get_instance()
try:
db.connect()
db.to_jst()
logger.debug('##########################')
logger.debug('START Changing Employee in charge of institution PGM.')
# `emp_chg_inst_lau`をTruncate

View File

@ -11,6 +11,7 @@ def exec():
db = Database.get_instance(autocommit=True)
try:
db.connect()
db.to_jst()
logger.debug('処理開始')
# 卸販売実績テーブル(洗替後)過去5年以前のデータ削除
_call_sales_lau_delete(db)

View File

@ -13,6 +13,7 @@ def exec():
db = Database.get_instance()
try:
db.connect()
db.to_jst()
logger.debug('納入先処方元マスタの洗替処理開始')
# ult_ident_presc_lauをTruncate
_truncate_ult_ident_presc_lau(db)

View File

@ -37,6 +37,7 @@ class VjskDataLoadManager:
try:
# データベース接続
db.connect()
db.to_jst()
db.execute("SET SESSION sql_mode = 'TRADITIONAL';")
# orgをtruncate

View File

@ -333,7 +333,7 @@ class VjskReceiveFileMapper:
,t.dsp_odr
,t.rec_sts_kbn
,nullif(t.ins_dt, 0) -- 受領データがブランクだった場合にゼロ日付で取得されるので明示的にNULL値に変換する
,t.upd_dt
,nullif(t.upd_dt, 0) -- 受領データがブランクだった場合にゼロ日付で取得されるので明示的にNULL値に変換する
,SYSDATE()
FROM org05.hld_mst_v AS t
ON DUPLICATE KEY UPDATE
@ -347,7 +347,7 @@ class VjskReceiveFileMapper:
,dsp_odr=t.dsp_odr
,rec_sts_kbn=t.rec_sts_kbn
,ins_dt=nullif(t.ins_dt, 0)
,upd_dt=t.upd_dt
,upd_dt=nullif(t.upd_dt, 0) -- 受領データがブランクだった場合にゼロ日付で取得されるので明示的にNULL値に変換する
,dwh_upd_dt=SYSDATE()
;
""")
@ -397,7 +397,7 @@ class VjskReceiveFileMapper:
,t.dsp_odr
,t.rec_sts_kbn
,nullif(t.ins_dt, 0) -- 受領データがブランクだった場合にゼロ日付で取得されるので明示的にNULL値に変換する
,t.upd_dt
,nullif(t.upd_dt, 0) -- 受領データがブランクだった場合にゼロ日付で取得されるので明示的にNULL値に変換する
,SYSDATE()
FROM org05.whs_mst_v AS t
ON DUPLICATE KEY UPDATE
@ -416,7 +416,7 @@ class VjskReceiveFileMapper:
,dsp_odr=t.dsp_odr
,rec_sts_kbn=t.rec_sts_kbn
,ins_dt=nullif(t.ins_dt, 0)
,upd_dt=t.upd_dt
,upd_dt=nullif(t.upd_dt, 0)
,dwh_upd_dt=SYSDATE()
;
""")
@ -526,7 +526,7 @@ class VjskReceiveFileMapper:
,t.end_date
,t.rec_sts_kbn
,nullif(t.ins_dt, 0) -- 受領データがブランクだった場合にゼロ日付で取得されるので明示的にNULL値に変換する
,t.upd_dt
,nullif(t.upd_dt, 0) -- 受領データがブランクだった場合にゼロ日付で取得されるので明示的にNULL値に変換する
,SYSDATE()
FROM org05.mkr_org_horizon_v AS t
ON DUPLICATE KEY UPDATE
@ -575,7 +575,7 @@ class VjskReceiveFileMapper:
,end_date=t.end_date
,rec_sts_kbn=t.rec_sts_kbn
,ins_dt=nullif(t.ins_dt, 0)
,upd_dt=t.upd_dt
,upd_dt=nullif(t.upd_dt, 0)
,dwh_upd_dt=SYSDATE()
;
""")
@ -615,7 +615,7 @@ class VjskReceiveFileMapper:
,t.dsp_odr
,t.rec_sts_kbn
,nullif(t.ins_dt, 0) -- 受領データがブランクだった場合にゼロ日付で取得されるので明示的にNULL値に変換する
,t.upd_dt
,nullif(t.upd_dt, 0) -- 受領データがブランクだった場合にゼロ日付で取得されるので明示的にNULL値に変換する
,SYSDATE()
FROM org05.org_cnv_mst_v AS t
ON DUPLICATE KEY UPDATE
@ -629,7 +629,7 @@ class VjskReceiveFileMapper:
,dsp_odr=t.dsp_odr
,rec_sts_kbn=t.rec_sts_kbn
,ins_dt=nullif(t.ins_dt, 0)
,upd_dt=t.upd_dt
,upd_dt=nullif(t.upd_dt, 0)
,dwh_upd_dt=SYSDATE()
;
""")
@ -665,7 +665,7 @@ class VjskReceiveFileMapper:
,t.dsp_odr
,t.rec_sts_kbn
,nullif(t.ins_dt, 0) -- 受領データがブランクだった場合にゼロ日付で取得されるので明示的にNULL値に変換する
,t.upd_dt
,nullif(t.upd_dt, 0) -- 受領データがブランクだった場合にゼロ日付で取得されるので明示的にNULL値に変換する
,SYSDATE()
FROM org05.tran_kbn_mst_v AS t
ON DUPLICATE KEY UPDATE
@ -677,7 +677,7 @@ class VjskReceiveFileMapper:
,dsp_odr=t.dsp_odr
,rec_sts_kbn=t.rec_sts_kbn
,ins_dt=nullif(t.ins_dt, 0)
,upd_dt=t.upd_dt
,upd_dt=nullif(t.upd_dt, 0)
,dwh_upd_dt=SYSDATE()
;
""")
@ -743,7 +743,7 @@ class VjskReceiveFileMapper:
,t.fcl_type
,t.rec_sts_kbn
,nullif(t.ins_dt, 0) -- 受領データがブランクだった場合にゼロ日付で取得されるので明示的にNULL値に変換する
,t.upd_dt
,nullif(t.upd_dt, 0) -- 受領データがブランクだった場合にゼロ日付で取得されるので明示的にNULL値に変換する
,SYSDATE()
FROM org05.fcl_mst_v AS t
ON DUPLICATE KEY UPDATE
@ -770,7 +770,7 @@ class VjskReceiveFileMapper:
,fcl_type=t.fcl_type
,rec_sts_kbn=t.rec_sts_kbn
,ins_dt=nullif(t.ins_dt, 0)
,upd_dt=t.upd_dt
,upd_dt=nullif(t.upd_dt, 0)
,dwh_upd_dt=SYSDATE()
;
""")
@ -844,7 +844,7 @@ class VjskReceiveFileMapper:
,t.dsp_odr
,t.rec_sts_kbn
,nullif(t.ins_dt, 0) -- 受領データがブランクだった場合にゼロ日付で取得されるので明示的にNULL値に変換する
,t.upd_dt
,nullif(t.upd_dt, 0) -- 受領データがブランクだった場合にゼロ日付で取得されるので明示的にNULL値に変換する
,SYSDATE()
FROM org05.phm_prd_mst_v AS t
ON DUPLICATE KEY UPDATE
@ -875,7 +875,7 @@ class VjskReceiveFileMapper:
,dsp_odr=t.dsp_odr
,rec_sts_kbn=t.rec_sts_kbn
,ins_dt=nullif(t.ins_dt, 0)
,upd_dt=t.upd_dt
,upd_dt=nullif(t.upd_dt, 0)
,dwh_upd_dt=SYSDATE()
;
""")
@ -913,7 +913,7 @@ class VjskReceiveFileMapper:
,t.dsp_odr
,t.rec_sts_kbn
,nullif(t.ins_dt, 0) -- 受領データがブランクだった場合にゼロ日付で取得されるので明示的にNULL値に変換する
,t.upd_dt
,nullif(t.upd_dt, 0) -- 受領データがブランクだった場合にゼロ日付で取得されるので明示的にNULL値に変換する
,SYSDATE()
FROM org05.phm_price_mst_v AS t
ON DUPLICATE KEY UPDATE
@ -926,7 +926,7 @@ class VjskReceiveFileMapper:
,dsp_odr=t.dsp_odr
,rec_sts_kbn=t.rec_sts_kbn
,ins_dt=nullif(t.ins_dt, 0)
,upd_dt=t.upd_dt
,upd_dt=nullif(t.upd_dt, 0)
,dwh_upd_dt=SYSDATE()
;
""")
@ -1011,7 +1011,7 @@ class VjskReceiveFileMapper:
,t.tel_num
,t.rec_sts_kbn
,nullif(t.ins_dt, 0) -- 受領データがブランクだった場合にゼロ日付で取得されるので明示的にNULL値に変換する
,t.upd_dt
,nullif(t.upd_dt, 0) -- 受領データがブランクだった場合にゼロ日付で取得されるので明示的にNULL値に変換する
,SYSDATE()
FROM org05.whs_customer_mst_v AS t
ON DUPLICATE KEY UPDATE
@ -1031,7 +1031,7 @@ class VjskReceiveFileMapper:
,tel_num=t.tel_num
,rec_sts_kbn=t.rec_sts_kbn
,ins_dt=nullif(t.ins_dt, 0)
,upd_dt=t.upd_dt
,upd_dt=nullif(t.upd_dt, 0)
,dwh_upd_dt=SYSDATE()
;
""")
@ -1065,7 +1065,7 @@ class VjskReceiveFileMapper:
,t.start_date
,t.rec_sts_kbn
,nullif(t.ins_dt, 0) -- 受領データがブランクだった場合にゼロ日付で取得されるので明示的にNULL値に変換する
,t.upd_dt
,nullif(t.upd_dt, 0) -- 受領データがブランクだった場合にゼロ日付で取得されるので明示的にNULL値に変換する
,SYSDATE()
FROM org05.mdb_cnv_mst_v AS t
ON DUPLICATE KEY UPDATE
@ -1076,7 +1076,7 @@ class VjskReceiveFileMapper:
,start_date=t.start_date
,rec_sts_kbn=t.rec_sts_kbn
,ins_dt=nullif(t.ins_dt, 0)
,upd_dt=t.upd_dt
,upd_dt=nullif(t.upd_dt, 0)
,dwh_upd_dt=SYSDATE()
;
""")

View File

@ -180,6 +180,9 @@ class Database:
self.__connection.close()
self.__connection = None
def to_jst(self):
self.execute('SET time_zone = "+9:00"')
def __execute_with_transaction(self, query: str, parameters: dict):
# トランザクションを開始してクエリを実行する
with self.__connection.begin():

View File

@ -39,6 +39,7 @@ class TestImportFileToDb:
self.db = database
self.db.connect()
self.db.execute("set sql_mode = 'TRADITIONAL';")
self.db.to_jst()
# self.db.begin()
# testing
@ -1159,7 +1160,7 @@ class TestImportFileToDb:
_import_file_to_db(received_s3_files)
# 検証
assert str(e.value) == "file could not be opened successfully"
assert str(e.value) == "Not a gzipped file (b'7z')"
# teardown
for test_file in test_files:

View File

@ -12,6 +12,7 @@ def exec():
db = Database.get_instance()
try:
db.connect()
db.to_jst()
logger.debug('処理開始')
# 卸販売実績テーブル(洗替後)作成
_call_sales_lau_upsert(db)

View File

@ -180,6 +180,9 @@ class Database:
self.__connection.close()
self.__connection = None
def to_jst(self):
self.execute('SET time_zone = "+9:00"')
def __execute_with_transaction(self, query: str, parameters: dict):
# トランザクションを開始してクエリを実行する
with self.__connection.begin():

View File

@ -30,6 +30,8 @@ def exec():
except Exception as e:
logger.info('DB接続エラーです')
raise e
# タイムゾーンをJSTに変更
db.to_jst()
# トランザクションの開始
db.begin()

View File

@ -167,6 +167,9 @@ class Database:
self.__connection.close()
self.__connection = None
def to_jst(self):
self.execute('SET time_zone = "+9:00"')
def __execute_with_transaction(self, query: str, parameters: dict):
# トランザクションを開始してクエリを実行する
with self.__connection.begin():

View File

@ -1,4 +1,4 @@
FROM python:3.9
FROM python:3.9-bullseye
ENV TZ="Asia/Tokyo"

View File

@ -55,6 +55,7 @@ def update_dump_status_kbn_in_processing() -> None:
"""
try:
db.connect()
db.to_jst()
db.execute(sql, {'in_processing': constants.BATCH_ACTF_BATCH_IN_PROCESSING})
except DBException as e:
raise BatchOperationException(e)
@ -80,6 +81,7 @@ def update_dump_status_kbn_error() -> None:
"""
try:
db.connect()
db.to_jst()
db.execute(sql, {
'dump_unprocessed': constants.DUMP_STATUS_KBN_ERROR
})
@ -107,6 +109,7 @@ def update_dump_status_kbn_complete() -> None:
"""
try:
db.connect()
db.to_jst()
db.execute(sql, {
'dump_unprocessed': constants.DUMP_STATUS_KBN_COMPLETE
})

View File

@ -165,6 +165,9 @@ class Database:
self.__connection.close()
self.__connection = None
def to_jst(self):
self.execute('SET time_zone = "+9:00"')
def __execute_with_transaction(self, query: str, parameters: dict):
# トランザクションを開始してクエリを実行する
with self.__connection.begin():

View File

@ -1,4 +1,4 @@
FROM python:3.9
FROM python:3.9-bullseye
ENV TZ="Asia/Tokyo"

View File

@ -180,6 +180,9 @@ class Database:
self.__connection.close()
self.__connection = None
def to_jst(self):
self.execute('SET time_zone = "+9:00"')
def __execute_with_transaction(self, query: str, parameters: dict):
# トランザクションを開始してクエリを実行する
with self.__connection.begin():

View File

@ -30,6 +30,7 @@ class MasterMainteEmpChgInstFunction(metaclass=ABCMeta):
error_list = []
try:
self.emp_chginst_repository.connect()
self.emp_chginst_repository.to_jst()
self.emp_chginst_repository.begin()
(result_message, error_list) = self.write_emp_chg_inst_table()
if len(error_list) > 0:

View File

@ -13,6 +13,9 @@ class EmpChgInstRepository(BaseRepository):
def connect(self):
self._database.connect()
def to_jst(self):
self._database.to_jst()
def begin(self):
self._database.begin()
@ -110,7 +113,7 @@ class EmpChgInstRepository(BaseRepository):
SET
emp_cd = :emp_cd,
updater = :update_user_name,
update_date = now()
update_date = NOW()
where
inst_cd = :inst_cd
and ta_cd = :ta_cd

View File

@ -149,6 +149,7 @@ class MasterMainteService(BaseService):
def copy_data_real_to_dummy(self) -> TableOverrideViewModel:
try:
self.emp_chginst_repository.connect()
self.emp_chginst_repository.to_jst()
self.emp_chginst_repository.begin()
self.emp_chginst_repository.delete_dummy_table()
self.emp_chginst_repository.copy_real_to_dummy()