Merge branch 'feature-NEWDWH2021-1507' into develop-emp-chg-inst

This commit is contained in:
nik.n 2024-04-18 13:07:00 +09:00
commit 87d7e2d305
6 changed files with 153 additions and 28 deletions

View File

@ -10,6 +10,7 @@ from src.repositories.mst_inst_repository import MstInstRepository
from src.repositories.bu_master_cd_repository import BuMasterRepository
from src.repositories.emp_master_repository import EmpMasterRepository
from src.repositories.emp_chg_inst_repository import EmpChgInstRepository
from src.repositories.generic_kbn_mst_repository import GenericKbnMstRepository
from src.logging.get_logger import get_logger
logger = get_logger('マスターメンテ')
@ -24,6 +25,7 @@ class MasterMainteCSVItem(metaclass=ABCMeta):
emp_master_repository: EmpMasterRepository
bu_master_repository: BuMasterRepository
emp_chginst_repository: EmpChgInstRepository
generic_kbn_mst_repository: GenericKbnMstRepository
def __init__(
self,
@ -33,7 +35,8 @@ class MasterMainteCSVItem(metaclass=ABCMeta):
mst_inst_repository: MstInstRepository,
emp_master_repository: EmpMasterRepository,
bu_master_repository: BuMasterRepository,
emp_chginst_repository: EmpChgInstRepository
emp_chginst_repository: EmpChgInstRepository,
generic_kbn_mst_repository: GenericKbnMstRepository
):
self.csv_row = csv_row
self.table_name = table_name
@ -42,6 +45,7 @@ class MasterMainteCSVItem(metaclass=ABCMeta):
self.emp_master_repository = emp_master_repository
self.bu_master_repository = bu_master_repository
self.emp_chginst_repository = emp_chginst_repository
self.generic_kbn_mst_repository = generic_kbn_mst_repository
def validate(self) -> list[str]:
"""
@ -57,6 +61,10 @@ class MasterMainteCSVItem(metaclass=ABCMeta):
error_list.extend(self.check_require())
# 施設コード存在チェック
error_list.extend(self.check_inst_cd_exists())
# 担当者種別コード存在チェック
error_list.extend(self.check_emp_chg_type_cd_exists())
# 領域コード存在チェック
error_list.extend(self.check_ta_cd_exists())
# MUID存在チェック
error_list.extend(self.check_emp_cd_exists())
# BuCd存在チェック
@ -91,6 +99,12 @@ class MasterMainteCSVItem(metaclass=ABCMeta):
def is_exist_inst_cd(self) -> bool:
return True if self.mst_inst_repository.fetch_count(self.inst_cd) > 0 else False
def is_exist_emp_chg_type_cd(self, start_date: str) -> bool:
return True if self.generic_kbn_mst_repository.fetch_count('emp_chg_type_cd', self.emp_chg_type_cd, start_date) > 0 else False
def is_exist_ta_cd(self, start_date: str) -> bool:
return True if self.generic_kbn_mst_repository.fetch_count('ta_cd', self.ta_cd, start_date) > 0 else False
def is_exist_bu_cd(self) -> bool:
return True if self.bu_master_repository.fetch_count(self.bu_cd) > 0 else False
@ -160,6 +174,18 @@ class MasterMainteCSVItem(metaclass=ABCMeta):
pass
...
@abstractmethod
def check_emp_chg_type_cd_exists(self) -> list[str]:
"""担当者種別コード存在チェック"""
pass
...
@abstractmethod
def check_ta_cd_exists(self) -> list[str]:
"""領域コード存在チェック"""
pass
...
@abstractmethod
def check_emp_cd_exists(self) -> list[str]:
"""MUID存在チェック"""
@ -205,7 +231,8 @@ class MasterMainteNewInstEmpCSVItem(MasterMainteCSVItem):
mst_inst_repository: MstInstRepository,
emp_master_repository: EmpMasterRepository,
bu_master_repository: BuMasterRepository,
emp_chginst_repository: EmpChgInstRepository
emp_chginst_repository: EmpChgInstRepository,
generic_kbn_mst_repository: GenericKbnMstRepository
):
super().__init__(
csv_row,
@ -214,11 +241,13 @@ class MasterMainteNewInstEmpCSVItem(MasterMainteCSVItem):
mst_inst_repository,
emp_master_repository,
bu_master_repository,
emp_chginst_repository
emp_chginst_repository,
generic_kbn_mst_repository
)
self.inst_cd = super().get_csv_value(constants.CSV_NEW_INST_CD_COL_NO)
self.inst_name = super().get_csv_value(constants.CSV_NEW_INST_NAME_COL_NO)
self.ta_cd = super().get_csv_value(constants.CSV_NEW_TA_CD_COL_NO)
self.emp_chg_type_cd = super().get_csv_value(constants.CSV_NEW_EMP_CHG_TYPE_CD_COL_NO)
self.emp_cd = super().get_csv_value(constants.CSV_NEW_EMP_CD_COL_NO)
self.emp_name_family = super().get_csv_value(constants.CSV_NEW_EMP_NAME_FAMILY_COL_NO)
self.emp_name_first = super().get_csv_value(constants.CSV_NEW_EMP_NAME_FIRST_COL_NO)
@ -237,6 +266,9 @@ class MasterMainteNewInstEmpCSVItem(MasterMainteCSVItem):
if len(self.ta_cd) == 0:
error_list.append(self.make_require_error_message(
self.line_num, constants.NEW_INST_EMP_CSV_LOGICAL_NAMES[constants.CSV_NEW_TA_CD_COL_NO]))
if len(self.emp_chg_type_cd) == 0:
error_list.append(self.make_require_error_message(
self.line_num, constants.NEW_INST_EMP_CSV_LOGICAL_NAMES[constants.CSV_NEW_EMP_CHG_TYPE_CD_COL_NO]))
if len(self.emp_cd) == 0:
error_list.append(self.make_require_error_message(
self.line_num, constants.NEW_INST_EMP_CSV_LOGICAL_NAMES[constants.CSV_NEW_EMP_CD_COL_NO]))
@ -271,6 +303,20 @@ class MasterMainteNewInstEmpCSVItem(MasterMainteCSVItem):
は従業員マスタに存在しない もしくは 適用期間外のIDです')
return error_list
def check_emp_chg_type_cd_exists(self) -> list[str]:
error_list = []
if is_not_empty(self.emp_chg_type_cd) and super().is_exist_emp_chg_type_cd(self.start_date) is False:
error_list.append(f'{self.line_num}行目の{constants.NEW_INST_EMP_CSV_LOGICAL_NAMES[constants.CSV_NEW_EMP_CHG_TYPE_CD_COL_NO]}\
は汎用区分マスタに存在しない もしくは 適用期間外のコードです')
return error_list
def check_ta_cd_exists(self) -> list[str]:
error_list = []
if is_not_empty(self.ta_cd) and super().is_exist_ta_cd(self.start_date) is False:
error_list.append(f'{self.line_num}行目の{constants.NEW_INST_EMP_CSV_LOGICAL_NAMES[constants.CSV_NEW_TA_CD_COL_NO]}\
は汎用区分マスタに存在しない もしくは 適用期間外のコードです')
return error_list
def check_bu_cd_exists(self) -> list[str]:
error_list = []
@ -329,7 +375,8 @@ class MasterMainteChangeInstEmpCSVItem(MasterMainteCSVItem):
mst_inst_repository: MstInstRepository,
emp_master_repository: EmpMasterRepository,
bu_master_repository: BuMasterRepository,
emp_chginst_repository: EmpChgInstRepository
emp_chginst_repository: EmpChgInstRepository,
generic_kbn_mst_repository: GenericKbnMstRepository
):
super().__init__(
csv_row,
@ -338,7 +385,8 @@ class MasterMainteChangeInstEmpCSVItem(MasterMainteCSVItem):
mst_inst_repository,
emp_master_repository,
bu_master_repository,
emp_chginst_repository
emp_chginst_repository,
generic_kbn_mst_repository
)
self.bu_cd = super().get_csv_value(constants.CSV_CHANGE_BU_CD_COL_NO)
self.bu_name = super().get_csv_value(constants.CSV_CHANGE_BU_NAME_COL_NO)
@ -348,6 +396,7 @@ class MasterMainteChangeInstEmpCSVItem(MasterMainteCSVItem):
self.inst_name = super().get_csv_value(constants.CSV_CHANGE_INST_NAME_COL_NO)
self.ta_cd = super().get_csv_value(constants.CSV_CHANGE_TA_CD_COL_NO)
self.explain = super().get_csv_value(constants.CSV_CHANGE_EXPLAIN_COL_NO)
self.emp_chg_type_cd = super().get_csv_value(constants.CSV_CHANGE_EMP_CHG_TYPE_CD_COL_NO)
self.emp_cd = super().get_csv_value(constants.CSV_CHANGE_EMP_CD_COL_NO)
self.emp_full_name = super().get_csv_value(constants.CSV_CHANGE_EMP_FULL_NAME_COL_NO)
self.inst_emp_start_date = super().get_csv_value(constants.CSV_CHANGE_INST_EMP_START_DATE_COL_NO)
@ -370,6 +419,9 @@ class MasterMainteChangeInstEmpCSVItem(MasterMainteCSVItem):
if len(self.ta_cd) == 0:
error_list.append(self.make_require_error_message(
self.line_num, constants.CHANGE_INST_CSV_LOGICAL_NAMES[constants.CSV_CHANGE_TA_CD_COL_NO]))
if len(self.emp_chg_type_cd) == 0:
error_list.append(self.make_require_error_message(
self.line_num, constants.CHANGE_INST_CSV_LOGICAL_NAMES[constants.CSV_CHANGE_EMP_CHG_TYPE_CD_COL_NO]))
if len(self.emp_cd) == 0:
error_list.append(self.make_require_error_message(
self.line_num, constants.CHANGE_INST_CSV_LOGICAL_NAMES[constants.CSV_CHANGE_EMP_CD_COL_NO]))
@ -435,6 +487,21 @@ class MasterMainteChangeInstEmpCSVItem(MasterMainteCSVItem):
は従業員マスタに存在しない もしくは 適用期間外のIDです')
return error_list
def check_emp_chg_type_cd_exists(self) -> list[str]:
error_list = []
if is_not_empty(self.emp_chg_type_cd) and super().is_exist_emp_chg_type_cd(self.inst_emp_start_date) is False:
error_list.append(f'{self.line_num}行目の{constants.CHANGE_INST_CSV_LOGICAL_NAMES[constants.CSV_CHANGE_EMP_CHG_TYPE_CD_COL_NO]}\
は汎用区分マスタに存在しない もしくは 適用期間外のコードです')
return error_list
def check_ta_cd_exists(self) -> list[str]:
error_list = []
if is_not_empty(self.ta_cd) and super().is_exist_ta_cd(self.inst_emp_start_date) is False:
error_list.append(f'{self.line_num}行目の{constants.CHANGE_INST_CSV_LOGICAL_NAMES[constants.CSV_CHANGE_TA_CD_COL_NO]}\
は汎用区分マスタに存在しない もしくは 適用期間外のコードです')
return error_list
def check_bu_cd_exists(self) -> list[str]:
error_list = []
@ -525,7 +592,8 @@ class MasterMainteCSVItems:
mst_inst_repository: MstInstRepository,
emp_master_repository: EmpMasterRepository,
bu_master_repository: BuMasterRepository,
emp_chginst_repository: EmpChgInstRepository
emp_chginst_repository: EmpChgInstRepository,
generic_kbn_mst_repository: GenericKbnMstRepository
) -> None:
reader = csv.reader(file)
csv_rows = []
@ -540,7 +608,9 @@ class MasterMainteCSVItems:
mst_inst_repository,
emp_master_repository,
bu_master_repository,
emp_chginst_repository))
emp_chginst_repository,
generic_kbn_mst_repository
))
self.lines = csv_rows
def __select_function(self,
@ -551,7 +621,8 @@ class MasterMainteCSVItems:
mst_inst_repository: MstInstRepository,
emp_master_repository: EmpMasterRepository,
bu_master_repository: BuMasterRepository,
emp_chginst_repository: EmpChgInstRepository) -> MasterMainteCSVItem:
emp_chginst_repository: EmpChgInstRepository,
generic_kbn_mst_repository: GenericKbnMstRepository) -> MasterMainteCSVItem:
if function_type == 'new':
return MasterMainteNewInstEmpCSVItem(
row,
@ -560,7 +631,8 @@ class MasterMainteCSVItems:
mst_inst_repository,
emp_master_repository,
bu_master_repository,
emp_chginst_repository)
emp_chginst_repository,
generic_kbn_mst_repository)
elif function_type == 'change':
return MasterMainteChangeInstEmpCSVItem(
row,
@ -569,4 +641,5 @@ class MasterMainteCSVItems:
mst_inst_repository,
emp_master_repository,
bu_master_repository,
emp_chginst_repository)
emp_chginst_repository,
generic_kbn_mst_repository)

View File

@ -29,8 +29,8 @@ class MasterMainteEmpChgInstFunction(metaclass=ABCMeta):
def save(self):
error_list = []
try:
self.emp_chginst_repository.to_jst()
self.emp_chginst_repository.begin()
self.emp_chginst_repository.to_jst()
(result_message, error_list) = self.write_emp_chg_inst_table()
if len(error_list) > 0:
self.emp_chginst_repository.rollback()
@ -46,6 +46,7 @@ class MasterMainteEmpChgInstFunction(metaclass=ABCMeta):
self.emp_chginst_repository.insert_emp_chg_inst(
data['施設コード'],
data['領域コード'],
data['担当者種別コード'],
data['MUID'],
data['ビジネスユニットコード'],
start_date,
@ -148,6 +149,7 @@ class ChangeEmpChgInstFunction(MasterMainteEmpChgInstFunction):
self.emp_chginst_repository.end_emp_chg_inst(
data['施設コード'],
data['領域コード'],
data['担当者種別コード'],
data['施設担当_開始日'],
data['終了日の変更'],
self.user_name,
@ -158,6 +160,7 @@ class ChangeEmpChgInstFunction(MasterMainteEmpChgInstFunction):
data['施設コード'],
data['領域コード'],
data['施設担当_開始日'],
data['担当者種別コード'],
data['MUID'],
self.user_name,
self.table_name)

View File

@ -28,6 +28,7 @@ class EmpChgInstRepository(BaseRepository):
(
inst_cd,
ta_cd,
emp_chg_type_cd,
emp_cd,
bu_cd,
start_date,
@ -42,6 +43,7 @@ class EmpChgInstRepository(BaseRepository):
VALUES (
:inst_cd,
:ta_cd,
:emp_chg_type_cd,
:emp_cd,
:bu_cd,
:start_date,
@ -55,13 +57,14 @@ class EmpChgInstRepository(BaseRepository):
)
"""
def insert_emp_chg_inst(self, inst_cd, ta_cd, emp_cd, bu_cd, start_date,
def insert_emp_chg_inst(self, inst_cd, ta_cd, emp_chg_type_cd, emp_cd, bu_cd, start_date,
end_date, create_user_name, table_name):
try:
query = self.INSERT_SQL.format(table_name=table_name)
self._database.execute(query, {
'inst_cd': inst_cd,
'ta_cd': ta_cd,
'emp_chg_type_cd': emp_chg_type_cd,
'emp_cd': emp_cd,
'bu_cd': bu_cd,
'start_date': start_date,
@ -86,13 +89,14 @@ class EmpChgInstRepository(BaseRepository):
and start_date = :start_date
"""
def end_emp_chg_inst(self, inst_cd, ta_cd, start_date,
def end_emp_chg_inst(self, inst_cd, ta_cd, emp_chg_type_cd, start_date,
end_date, update_user_name, table_name):
try:
query = self.UPDATE_END_DATE_SQL.format(table_name=table_name)
self._database.execute(query, {
'inst_cd': inst_cd,
'ta_cd': ta_cd,
'emp_chg_type_cd': emp_chg_type_cd,
'start_date': start_date,
'end_date': end_date,
'update_user_name': update_user_name
@ -114,12 +118,13 @@ class EmpChgInstRepository(BaseRepository):
and start_date = :start_date
"""
def modify_emp_chg_inst(self, inst_cd, ta_cd, start_date, emp_cd, update_user_name, table_name):
def modify_emp_chg_inst(self, inst_cd, ta_cd, start_date, emp_chg_type_cd, emp_cd, update_user_name, table_name):
try:
query = self.UPDATE_EMP_CD_SQL.format(table_name=table_name)
self._database.execute(query, {
'inst_cd': inst_cd,
'ta_cd': ta_cd,
'emp_chg_type_cd': emp_chg_type_cd,
'start_date': start_date,
'emp_cd': emp_cd,
'update_user_name': update_user_name

View File

@ -0,0 +1,33 @@
from src.repositories.base_repository import BaseRepository
from src.model.db.master_mente_count import MasterMenteCountModel
from src.logging.get_logger import get_logger
logger = get_logger('汎用区分マスタ')
class GenericKbnMstRepository(BaseRepository):
FETCH_SQL = """\
SELECT
COUNT(*) AS count
FROM
src05.generic_kbn_mst
WHERE
generic_kbn_mst.generic_kbn_cd = :generic_kbn_cd
AND
generic_kbn_mst.kbn_cd = :kbn_cd
AND
STR_TO_DATE( :start_date , '%Y%m%d') BETWEEN generic_kbn_mst.start_date AND generic_kbn_mst.end_date\
"""
def fetch_count(self, generic_kbn_cd: str, kbn_cd: str, start_date: str) -> MasterMenteCountModel:
try:
query = self.FETCH_SQL
result = self._database.execute_select(query, {'generic_kbn_cd': generic_kbn_cd, 'kbn_cd': kbn_cd, 'start_date' : start_date})
models = [MasterMenteCountModel(**r) for r in result]
if len(models) == 0:
return 0
return models[0].count
except Exception as e:
logger.error(f"DB Error : Exception={e.args}")
raise e

View File

@ -19,6 +19,7 @@ from src.repositories.mst_inst_repository import MstInstRepository
from src.repositories.bu_master_cd_repository import BuMasterRepository
from src.repositories.emp_master_repository import EmpMasterRepository
from src.repositories.emp_chg_inst_repository import EmpChgInstRepository
from src.repositories.generic_kbn_mst_repository import GenericKbnMstRepository
from src.model.internal.master_mainte_csv import MasterMainteCSVItems
from src.model.internal.master_mainte_emp_chg_inst_function import NewEmpChgInstFunction
from src.model.internal.master_mainte_emp_chg_inst_function import ChangeEmpChgInstFunction
@ -38,6 +39,7 @@ class MasterMainteService(BaseService):
'emp_master_repository': EmpMasterRepository,
'bu_master_repository': BuMasterRepository,
'emp_chginst_repository': EmpChgInstRepository,
'generic_kbn_mst_repository': GenericKbnMstRepository,
}
CLIENTS = {
@ -48,6 +50,7 @@ class MasterMainteService(BaseService):
emp_master_repository: EmpMasterRepository
bu_master_repository: BuMasterRepository
emp_chginst_repository: EmpChgInstRepository
generic_kbn_mst_repository: GenericKbnMstRepository
s3_client: S3Client
def __init__(self, repositories: dict[str, BaseRepository], clients: dict[str, AWSAPIClient]) -> None:
@ -56,6 +59,7 @@ class MasterMainteService(BaseService):
self.emp_master_repository = repositories['emp_master_repository']
self.bu_master_repository = repositories['bu_master_repository']
self.emp_chginst_repository = repositories['emp_chginst_repository']
self.generic_kbn_mst_repository = repositories['generic_kbn_mst_repository']
self.s3_client = clients['s3_client']
def prepare_mainte_csv_up_view(self,
@ -77,7 +81,8 @@ class MasterMainteService(BaseService):
self.mst_inst_repository,
self.emp_master_repository,
self.bu_master_repository,
self.emp_chginst_repository
self.emp_chginst_repository,
self.generic_kbn_mst_repository
)
error_message_list = []
@ -148,8 +153,8 @@ class MasterMainteService(BaseService):
def copy_data_real_to_dummy(self) -> TableOverrideViewModel:
try:
self.emp_chginst_repository.to_jst()
self.emp_chginst_repository.begin()
self.emp_chginst_repository.to_jst()
self.emp_chginst_repository.delete_dummy_table()
self.emp_chginst_repository.copy_real_to_dummy()
self.emp_chginst_repository.commit()

View File

@ -82,6 +82,7 @@ NEW_INST_EMP_CSV_LOGICAL_NAMES = [
'施設コード',
'施設名',
'領域コード',
'担当者種別コード',
'MUID',
'担当者名(姓)',
'担当者名(名)',
@ -95,18 +96,20 @@ CSV_NEW_INST_CD_COL_NO = 0
CSV_NEW_INST_NAME_COL_NO = 1
# 領域コードの列No
CSV_NEW_TA_CD_COL_NO = 2
# 担当者種別コードの列No
CSV_NEW_EMP_CHG_TYPE_CD_COL_NO = 3
# MUIDの列No
CSV_NEW_EMP_CD_COL_NO = 3
CSV_NEW_EMP_CD_COL_NO = 4
# 担当者名の列No
CSV_NEW_EMP_NAME_FAMILY_COL_NO = 4
CSV_NEW_EMP_NAME_FAMILY_COL_NO = 5
# 担当者名の列No
CSV_NEW_EMP_NAME_FIRST_COL_NO = 5
CSV_NEW_EMP_NAME_FIRST_COL_NO = 6
# ビジネスユニットコードの列No
CSV_NEW_BU_CD_COL_NO = 6
CSV_NEW_BU_CD_COL_NO = 7
# 適用開始日の列No
CSV_NEW_START_DATE = 7
CSV_NEW_START_DATE = 8
# 適用終了日の列No
CSV_NEW_END_DATE = 8
CSV_NEW_END_DATE = 9
# 施設担当者変更登録CSV(マスターメンテ)
CHANGE_INST_CSV_LOGICAL_NAMES = [
@ -118,6 +121,7 @@ CHANGE_INST_CSV_LOGICAL_NAMES = [
'施設名',
'領域コード',
'説明',
'担当者種別コード',
'MUID',
'担当者名',
'施設担当_開始日',
@ -141,18 +145,20 @@ CSV_CHANGE_INST_NAME_COL_NO = 5
CSV_CHANGE_TA_CD_COL_NO = 6
# 説明の列No
CSV_CHANGE_EXPLAIN_COL_NO = 7
# 担当者種別コード
CSV_CHANGE_EMP_CHG_TYPE_CD_COL_NO = 8
# MUIDの列No
CSV_CHANGE_EMP_CD_COL_NO = 8
CSV_CHANGE_EMP_CD_COL_NO = 9
# 担当者名の列No
CSV_CHANGE_EMP_FULL_NAME_COL_NO = 9
CSV_CHANGE_EMP_FULL_NAME_COL_NO = 10
# 施設担当_開始日の列No
CSV_CHANGE_INST_EMP_START_DATE_COL_NO = 10
CSV_CHANGE_INST_EMP_START_DATE_COL_NO = 11
# 施設担当_終了日の列No
CSV_CHANGE_INST_EMP_END_DATE_COL_NO = 11
CSV_CHANGE_INST_EMP_END_DATE_COL_NO = 12
# 終了日の変更の列No
CSV_CHANGE_CHANGE_END_DATE_COL_NO = 12
CSV_CHANGE_CHANGE_END_DATE_COL_NO = 13
# コメントの列No
CSV_CHANGE_COMMENT = 13
CSV_CHANGE_COMMENT = 14
# CSVアップロードテーブル名(マスターメンテ)
CSV_REAL_TABLE_NAME = '本番テーブル'