Merge pull request #385 feature-NEWDWH2021-1540 into develop-emp-chg-inst

This commit is contained in:
下田雅人 2024-04-24 11:12:39 +09:00
commit fa23ae3964

View File

@ -1,17 +1,17 @@
import csv
import json
from io import TextIOWrapper
from datetime import datetime
from abc import ABCMeta, abstractmethod
from datetime import datetime
from io import TextIOWrapper
from src.logging.get_logger import get_logger
from src.repositories.bu_master_cd_repository import BuMasterRepository
from src.repositories.emp_chg_inst_repository import EmpChgInstRepository
from src.repositories.emp_master_repository import EmpMasterRepository
from src.repositories.generic_kbn_mst_repository import GenericKbnMstRepository
from src.repositories.mst_inst_repository import MstInstRepository
from src.system_var import constants
from src.util.string_util import is_not_empty
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('マスターメンテ')
@ -98,7 +98,7 @@ 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:
if start_date is None or len(start_date) == 0:
return False
@ -119,6 +119,16 @@ class MasterMainteCSVItem(metaclass=ABCMeta):
def make_require_error_message(self, line_num: str, col_name: str) -> str:
return f'{line_num}行目の{col_name}が入力されておりません。'
def make_data_exist_error_message(self, line_num: str, primary_key_col_names: list[str]) -> str:
return self.__make_check_data_exists_error_message(line_num, primary_key_col_names, 'がすべて同一のデータが既に登録されています。')
def make_data_not_exist_error_message(self, line_num: str, primary_key_col_names: list[str]) -> str:
return self.__make_check_data_exists_error_message(line_num, primary_key_col_names, 'がすべて同一のデータが存在しないため更新できません。')
def __make_check_data_exists_error_message(self, line_num: str, primary_key_col_names: list[str], suffix_message: str) -> str:
primary_key_logical_names = ''.join(primary_key_col_names)
return f'{line_num}行目の{primary_key_logical_names}{suffix_message}'
def __parse_str_to_date(self, check_date: str) -> tuple[bool, datetime]:
try:
check_date_time: datetime = datetime.strptime(check_date, '%Y%m%d')
@ -325,7 +335,7 @@ class MasterMainteNewInstEmpCSVItem(MasterMainteCSVItem):
error_list = []
if not self.start_date or not self.ta_cd:
return 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]}\
は汎用区分マスタに存在しない もしくは 適用期間外のコードです')
@ -363,7 +373,15 @@ class MasterMainteNewInstEmpCSVItem(MasterMainteCSVItem):
def check_data_exists(self) -> list[str]:
error_list = []
if super().emp_chg_inst_count(self.start_date) > 0:
error_list.append(f'{self.line_num}行目の施設コード、領域コード、適用開始日がすべて同一のデータが既に登録されています。')
error_list.append(super().make_data_exist_error_message(
self.line_num,
primary_key_col_names=[
constants.NEW_INST_EMP_CSV_LOGICAL_NAMES[constants.CSV_NEW_INST_CD_COL_NO],
constants.NEW_INST_EMP_CSV_LOGICAL_NAMES[constants.CSV_NEW_TA_CD_COL_NO],
constants.NEW_INST_EMP_CSV_LOGICAL_NAMES[constants.CSV_NEW_EMP_CHG_TYPE_CD_COL_NO],
constants.NEW_INST_EMP_CSV_LOGICAL_NAMES[constants.CSV_NEW_START_DATE]
]
))
return error_list
@ -507,7 +525,7 @@ class MasterMainteChangeInstEmpCSVItem(MasterMainteCSVItem):
error_list.append(f'{self.line_num}行目の{constants.CHANGE_INST_CSV_LOGICAL_NAMES[constants.CSV_CHANGE_EMP_CD_COL_NO]}\
は従業員マスタに存在しない もしくは 適用期間外のIDです')
return error_list
def check_emp_chg_type_cd_exists(self) -> list[str]:
error_list = []
@ -518,7 +536,7 @@ class MasterMainteChangeInstEmpCSVItem(MasterMainteCSVItem):
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 = []
@ -579,10 +597,26 @@ class MasterMainteChangeInstEmpCSVItem(MasterMainteCSVItem):
error_list = []
emp_chg_inst_count = super().emp_chg_inst_count(self.inst_emp_start_date)
if self.comment == '追加' and emp_chg_inst_count > 0:
error_list.append(f'{self.line_num}行目の施設コード、領域コード、担当者種別コード、施設担当_開始日がすべて同一のデータが既に登録されています。')
error_list.append(super().make_data_exist_error_message(
self.line_num,
primary_key_col_names=[
constants.CHANGE_INST_CSV_LOGICAL_NAMES[constants.CSV_CHANGE_INST_CD_COL_NO],
constants.CHANGE_INST_CSV_LOGICAL_NAMES[constants.CSV_CHANGE_TA_CD_COL_NO],
constants.CHANGE_INST_CSV_LOGICAL_NAMES[constants.CSV_CHANGE_EMP_CHG_TYPE_CD_COL_NO],
constants.CHANGE_INST_CSV_LOGICAL_NAMES[constants.CSV_CHANGE_INST_EMP_START_DATE_COL_NO]
]
))
elif (self.comment == '終了' or self.comment == '担当者修正') and emp_chg_inst_count == 0:
error_list.append(f'{self.line_num}行目の施設コード、領域コード、担当者種別コード、施設担当_開始日がすべて同一のデータが存在しないため更新できません。')
error_list.append(super().make_data_not_exist_error_message(
self.line_num,
primary_key_col_names=[
constants.CHANGE_INST_CSV_LOGICAL_NAMES[constants.CSV_CHANGE_INST_CD_COL_NO],
constants.CHANGE_INST_CSV_LOGICAL_NAMES[constants.CSV_CHANGE_TA_CD_COL_NO],
constants.CHANGE_INST_CSV_LOGICAL_NAMES[constants.CSV_CHANGE_EMP_CHG_TYPE_CD_COL_NO],
constants.CHANGE_INST_CSV_LOGICAL_NAMES[constants.CSV_CHANGE_INST_EMP_START_DATE_COL_NO]
]
))
return error_list